2020-01-07 17:36:49 +01:00
|
|
|
package txt
|
2019-12-13 03:07:26 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2019-12-27 05:18:52 +01:00
|
|
|
var KeywordsRegexp = regexp.MustCompile("[\\p{L}]{3,}")
|
2019-12-13 03:07:26 +01:00
|
|
|
|
2020-01-12 14:00:56 +01:00
|
|
|
// Keywords extracts keywords for indexing and returns them as string slice.
|
2019-12-13 03:07:26 +01:00
|
|
|
func Keywords(s string) (results []string) {
|
|
|
|
all := KeywordsRegexp.FindAllString(s, -1)
|
|
|
|
|
|
|
|
for _, w := range all {
|
|
|
|
w = strings.ToLower(w)
|
|
|
|
|
|
|
|
if _, ok := Stopwords[w]; ok == false {
|
|
|
|
results = append(results, w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results
|
|
|
|
}
|