-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitstring.go
44 lines (36 loc) · 1.01 KB
/
splitstring.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Package fts provides ...
package fts
import (
"strings"
)
// DefaultSplitString 默认拆分规则函数
var DefaultSplitString = EnglishSplitString
// EnglishSplitString splits a string
func EnglishSplitString(s string) []string {
// return strings.FieldsFunc(s, func(r rune) bool {
// // Split on any character that is not a letter or a number.
// return !unicode.IsLetter(r) && !unicode.IsNumber(r)
// })
return strings.Split(s, " ")
}
// ChaineseSplitString splits a string
func ChaineseSplitString(s string) []string {
// return strings.FieldsFunc(s, func(r rune) bool {
// // Split on any character that is not a letter or a number.
// return !unicode.IsLetter(r) && !unicode.IsNumber(r)
// })
var res []string
for _, v := range s {
if string(v) == "" {
continue
}
res = append(res, string(v))
}
return res
}
// analyze analyzes the text and returns a slice of tokens.
func analyze(text string) []string {
tokens := DefaultSplitString(text)
tokens = loadFilter(tokens)
return tokens
}