-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordClass.go
49 lines (38 loc) · 985 Bytes
/
wordClass.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 "slices"
// WordClass type helps Generator.Transform differentiate
// parts of speech and process them accordingly.
type WordClass uint8
const (
WC_ADJECTIVE WordClass = iota
WC_ADVERB
WC_NOUN
WC_VERB
)
/* Returns true if wc is compatible with all of the received mods. */
func (wc WordClass) CompatibleWith(mods ...Mod) bool {
for _, m := range mods {
switch m {
case MOD_PLURAL:
if wc == WC_ADJECTIVE || wc == WC_ADVERB {
return false
}
if wc == WC_VERB && !slices.Contains(mods, MOD_PAST_SIMPLE) && !slices.Contains(mods, MOD_PRESENT_SIMPLE) {
return false
}
case MOD_PAST_SIMPLE, MOD_PAST_PARTICIPLE, MOD_PRESENT_SIMPLE, MOD_GERUND:
if wc != WC_VERB {
return false
}
case MOD_COMPARATIVE, MOD_SUPERLATIVE:
if wc != WC_ADJECTIVE && wc != WC_ADVERB {
return false
}
case MOD_CASE_LOWER, MOD_CASE_TITLE, MOD_CASE_UPPER:
continue
default: // Undefined Mod
return false
}
}
return true
}