32 lines
815 B
Go
32 lines
815 B
Go
// Copyright (C) 2019 Marius Schellenberger
|
|
|
|
package index
|
|
|
|
import (
|
|
"regexp"
|
|
)
|
|
|
|
var classes = []class{
|
|
{regexp.MustCompile(`(?i)[^e]rechnung|quittung|beleg|invoice|bill|check`), []string{"invoice", "rechnung"}},
|
|
{regexp.MustCompile(`(?i)steuer|lohn|tax|salary`), []string{"tax", "steuer"}},
|
|
{regexp.MustCompile(`(?i)vertrag|kündigung|vereinbarung|contract|termination|agreement`), []string{"contract", "vertrag"}},
|
|
{regexp.MustCompile(`(?i)versicherung|versichert|insurance|insured`), []string{"insurance", "versicherung"}},
|
|
}
|
|
|
|
type class struct {
|
|
r *regexp.Regexp
|
|
k []string
|
|
}
|
|
|
|
func classify(text string) (keyword []string) {
|
|
keyword = []string{"", ""}
|
|
n := 0
|
|
for _, v := range classes {
|
|
num := len(v.r.FindAllString(text, -1))
|
|
if num > n && num >= 2 {
|
|
keyword = v.k
|
|
n = num
|
|
}
|
|
}
|
|
return
|
|
}
|