1cbb0a6d56
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
26 lines
528 B
Go
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
|
|
}
|