-
Notifications
You must be signed in to change notification settings - Fork 15
/
POSTag.go
51 lines (43 loc) · 1.36 KB
/
POSTag.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
package lingo
import (
"fmt"
"strings"
)
// POSTag represents a Part of Speech Tag.
type POSTag byte
var posTagLookup map[string]POSTag
func init() {
posTagLookup = make(map[string]POSTag)
for t := X; t < MAXTAG; t++ {
s := t.String()
posTagLookup[s] = POSTag(t)
posTagLookup[strings.ToLower(s)] = POSTag(t)
}
}
func (p POSTag) MarshalText() ([]byte, error) {
return []byte(fmt.Sprintf("%v", p)), nil // add quotes back
}
func (p *POSTag) UnmarshalText(text []byte) error {
str := strings.Trim(string(text), `"`) // for JSON use, if any
tag, _ := posTagLookup[str]
*p = tag
return nil
}
// POSTag related functions
func InPOSTags(x POSTag, set []POSTag) bool {
for _, v := range set {
if v == x {
return true
}
}
return false
}
func IsAdjective(x POSTag) bool { return InPOSTags(x, Adjectives) }
func IsNoun(x POSTag) bool { return InPOSTags(x, Nouns) }
func IsProperNoun(x POSTag) bool { return InPOSTags(x, ProperNouns) }
func IsVerb(x POSTag) bool { return InPOSTags(x, Verbs) }
func IsAdverb(x POSTag) bool { return InPOSTags(x, Adverbs) }
func IsInterrogative(x POSTag) bool { return InPOSTags(x, Interrogatives) }
func IsDeterminer(x POSTag) bool { return InPOSTags(x, Determiners) }
func IsNumber(x POSTag) bool { return InPOSTags(x, Numbers) }
func IsSymbol(x POSTag) bool { return InPOSTags(x, Symbols) }