-
Notifications
You must be signed in to change notification settings - Fork 7
/
stop_tokens.go
53 lines (45 loc) · 866 Bytes
/
stop_tokens.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
45
46
47
48
49
50
51
52
53
package gotokenizer
import (
"bufio"
"io"
"os"
)
// StopTokens records paths and records
type StopTokens struct {
path string
records map[string]bool
IsLoaded bool
}
// NewStopTokens returns a newly initialized StopTokens object
func NewStopTokens() *StopTokens {
return &StopTokens{
records: make(map[string]bool),
}
}
// Load that loads StopToken dict
func (st *StopTokens) Load(path string) error {
if st.IsLoaded {
return nil
}
fi, err := os.Open(path)
if err != nil {
return err
}
defer fi.Close()
br := bufio.NewReader(fi)
for {
a, _, c := br.ReadLine()
if c == io.EOF {
break
}
st.records[string(a)] = true
}
st.records[" "] = true
st.IsLoaded = true
return nil
}
// IsStopToken returns if token is a token
func (st *StopTokens) IsStopToken(token string) bool {
_, found := st.records[token]
return found
}