-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradation.go
49 lines (44 loc) · 1.07 KB
/
gradation.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
package neng
import "strings"
// comparative returns a comparative form of an adjective or an adverb
// (good -> better).
func comparative(word *Word) string {
switch word.ft {
case FT_IRREGULAR:
return (*word.irr)[0]
case FT_SUFFIXED:
return sufGrad(word.word, "er")
default:
return "more " + word.word
}
}
// sufGrad returns comparative or superlative form of those adjectives to which
// suffix is appended during gradation process.
func sufGrad(a, suf string) string {
switch a[len(a)-1] {
case 'y':
if strings.HasSuffix(a, "ey") {
return a[:len(a)-2] + "i" + suf
}
return a[:len(a)-1] + "i" + suf
case 'b', 'd', 'g', 'm', 'n', 'p', 't':
if strings.HasSuffix(getSequence(a), "cvc") {
return doubleFinal(a, suf)
}
case 'e':
return a[:len(a)-1] + suf
}
return a + suf
}
// superlative returns a superlative form of an adjective or an adverb
// (good -> best).
func superlative(word *Word) string {
switch word.ft {
case FT_IRREGULAR:
return (*word.irr)[1]
case FT_SUFFIXED:
return sufGrad(word.word, "est")
default:
return "most " + word.word
}
}