-
Notifications
You must be signed in to change notification settings - Fork 2
/
step1b.go
113 lines (102 loc) · 3.18 KB
/
step1b.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package gwizo
import "strings"
/*Step1b from "An algorithm for suffix stripping".
Deals with plurals and past participles. The subsequent steps
are much more straightforward.
From the paper:
(m>0) EED -> EE feed -> feed
agreed -> agree
(*v*) ED -> plastered -> plaster
bled -> bled
(*v*) ING -> motoring -> motor
sing -> sing
If the second or third of the rules in Step 1b is successful,
the following is done:
AT -> ATE conflat(ed) -> conflate
BL -> BLE troubl(ed) -> trouble
IZ -> IZE siz(ed) -> size
(*d and not (*L or *S or *Z))
-> single letter
hopp(ing) -> hop
tann(ed) -> tan
fall(ing) -> fall
hiss(ing) -> hiss
fizz(ed) -> fizz
(m=1 and *o) -> E fail(ing) -> fail
fil(ing) -> file
The rule to map to a single letter causes the removal of one of
the double letter pair. The -E is put back on -AT, -BL and -IZ,
so that the suffixes -ATE, -BLE and -IZE can be recognised
later. This E may be removed in step 4.
*/
func Step1b(word string) string {
// Word Measure (m > 0) and EED suffix. EED -> EE
eed := strings.HasSuffix(word, "eed")
if eed {
pre := strings.TrimSuffix(word, "eed")
if MeasureNum(pre) > 0 {
str := pre + "ee"
return str
}
return word
}
// Word has Vowel and ED suffix. ED ->
ed := strings.HasSuffix(word, "ed")
if ed {
pre := strings.TrimSuffix(word, "ed")
if !HasVowel(pre) {
return word
}
word = pre
}
// Word has Vowel and ING suffix. ING ->
ing := strings.HasSuffix(word, "ing")
if ing {
pre := strings.TrimSuffix(word, "ing")
if !HasVowel(pre) {
return word
}
word = pre
}
/*If the second or third of the rules in Step 1b is successful,
the following is done
*/
if ed || ing {
// Word has AT suffix. AT -> ATE
at := strings.HasSuffix(word, "at")
if at {
pre := strings.TrimSuffix(word, "at")
word = pre + "ate"
}
// Word has BL suffix. BL -> BLE
bl := strings.HasSuffix(word, "bl")
if bl {
pre := strings.TrimSuffix(word, "bl")
word = pre + "ble"
}
// Word has IZ suffix. IZ -> IZE
iz := strings.HasSuffix(word, "iz")
if iz {
pre := strings.TrimSuffix(word, "iz")
word = pre + "ize"
}
// (*d and not (*L or *S or *Z)) -> single letter
if HasSameDoubleConsonant(word) {
ll := strings.HasSuffix(word, "ll")
ss := strings.HasSuffix(word, "ss")
zz := strings.HasSuffix(word, "zz")
if ll || ss || zz {
return word
}
wordLen := len(word)
lastLetter := word[(wordLen - 1):]
pre := strings.TrimSuffix(word, lastLetter)
return pre
}
// (m=1 and *o) -> E
if MeasureEqualTo1(word) && HascvcEndLastNotwxy(word) {
word = word + letterE
}
}
return word
}