-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdependencyType.go
48 lines (39 loc) · 1.29 KB
/
dependencyType.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
package lingo
import (
"fmt"
"strings"
)
// DependencyType represents the relation between two words
type DependencyType byte
var dependencyTypeLookup map[string]DependencyType
func init() {
dependencyTypeLookup = make(map[string]DependencyType)
for dt := NoDepType; dt < MAXDEPTYPE; dt++ {
s := dt.String()
dependencyTypeLookup[s] = DependencyType(dt)
dependencyTypeLookup[strings.ToLower(s)] = DependencyType(dt)
}
}
func (dt DependencyType) MarshalText() ([]byte, error) {
return []byte(fmt.Sprintf("%v", dt)), nil
}
func (dt *DependencyType) UnmarshalText(text []byte) error {
str := strings.Trim(string(text), `"`) // for JSON use, if any
deptype, _ := dependencyTypeLookup[str]
*dt = deptype
return nil
}
// list of dependency type functions
func InDepTypes(x DependencyType, set []DependencyType) bool {
for _, v := range set {
if v == x {
return true
}
}
return false
}
func IsModifier(x DependencyType) bool { return InDepTypes(x, Modifiers) }
func IsCompound(x DependencyType) bool { return InDepTypes(x, Compounds) }
func IsDeterminerRel(x DependencyType) bool { return InDepTypes(x, DeterminerRels) }
func IsMultiword(x DependencyType) bool { return InDepTypes(x, MultiWord) }
func IsQuantifier(x DependencyType) bool { return InDepTypes(x, QuantifingMods) }