-
Notifications
You must be signed in to change notification settings - Fork 0
/
noun.go
73 lines (65 loc) · 1.51 KB
/
noun.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
package neng
import "strings"
// plural returns plural form of a noun.
func plural(word *Word) string {
switch word.ft {
case FT_IRREGULAR:
return (*word.irr)[0]
case FT_PLURAL_ONLY:
return word.word
}
noun := word.word
switch noun[len(noun)-1] {
case 'e':
if endsWithAny(noun, []string{"life", "knife", "wife"}) {
return noun[:len(noun)-2] + "ves"
}
case 'y':
if strings.HasSuffix(getSequence(noun), "v") {
return noun[:len(noun)-1] + "ies"
}
case 's':
if endsWithAny(noun, []string{"ics", "gs"}) {
return noun
}
if endsWithAny(noun, []string{"sis", "xis"}) {
return noun[:len(noun)-2] + "es"
}
if endsWithAny(noun, []string{"cirrus", "cumulus", "nimbus", "stratus"}) {
return noun[:len(noun)-2] + "i"
}
return noun + "es"
case 'f':
if endsWithAny(noun, []string{"leaf", "elf", "arf", "alf", "wolf", "loaf"}) {
return noun[:len(noun)-1] + "ves"
}
case 'x':
if endsWithAny(noun, []string{"dex", "dix", "fex", "pex", "rix", "tex"}) {
return noun[:len(noun)-2] + "ices"
}
return noun + "es"
case 'z':
if strings.HasSuffix(getSequence(noun), "vc") {
return doubleFinal(noun, "es")
}
return noun + "es"
}
switch noun[len(noun)-2:] {
case "um":
return noun[:len(noun)-2] + "a"
case "sh":
if strings.HasSuffix(noun, "fish") {
return noun
}
return noun + "es"
case "ch":
return noun + "es"
}
if strings.HasSuffix(noun, "man") {
return noun[:len(noun)-2] + "en"
}
if strings.HasSuffix(noun, "craft") {
return noun
}
return noun + "s"
}