better indexing and classifier
This commit is contained in:
parent
38c2a72fe0
commit
98b53d3a33
9 changed files with 168 additions and 32 deletions
30
pkg/index/classify.go
Normal file
30
pkg/index/classify.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue