-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
35 lines (29 loc) · 783 Bytes
/
state.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
package turkishstemmer
type State interface {
AddTransitions(word string, transitions *Transitions, startState State)
NextState(suffix string) State
InitialState() bool
FinalState() bool
Suffixes() []Suffix
}
type BaseState struct {
initialState bool
finalState bool
suffixes []Suffix
}
func (s BaseState) AddTransitions(word string, transitions *Transitions, startState State) {
for _, suffix := range s.Suffixes() {
if suffix.Match(word) {
*transitions = append(*transitions, NewTransition(startState, startState.NextState(suffix.String()), word, suffix))
}
}
}
func (s BaseState) InitialState() bool {
return s.initialState
}
func (s BaseState) FinalState() bool {
return s.finalState
}
func (s BaseState) Suffixes() []Suffix {
return s.suffixes
}