photoprism/pkg/txt/words.go
Michael Mayer 1cbb0a6d56 Labels: Edit name in overview #212
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-02-02 02:00:47 +01:00

26 lines
528 B
Go

package txt
import (
"regexp"
"strings"
)
var KeywordsRegexp = regexp.MustCompile("[\\p{L}]{3,}")
// Words returns a slice of words with at least 3 characters from a string.
func Words(s string) (results []string) {
return KeywordsRegexp.FindAllString(s, -1)
}
// Keywords returns a slice of keywords without stopwords.
func Keywords(s string) (results []string) {
for _, w := range Words(s) {
w = strings.ToLower(w)
if _, ok := Stopwords[w]; ok == false {
results = append(results, w)
}
}
return results
}