-
Notifications
You must be signed in to change notification settings - Fork 4
/
document.go
50 lines (45 loc) · 883 Bytes
/
document.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
package ling
func NewDocument(text string) *Document {
return &Document{Text: text}
}
func (d *Document) String() string {
return d.Text
}
func (d *Document) NewSpan(start, end int) *Span {
tokenCnt := len(d.Tokens)
if tokenCnt == 0 {
return nil
}
if start < 0 {
start = 0
}
if end > tokenCnt {
end = tokenCnt
}
return &Span{Doc: d, Start: start, End: end}
}
func (d *Document) XTokens(anno string) []string {
var ret []string
for _, token := range d.Tokens {
t, has := token.Annotations[anno]
if !has {
t = token.Annotations["norm"]
}
ret = append(ret, t)
}
return ret
}
func (d *Document) XRealTokens(anno string) []string {
var ret []string
for _, token := range d.Tokens {
if token.Type == Space {
continue
}
t, has := token.Annotations[anno]
if !has {
t = token.Annotations["norm"]
}
ret = append(ret, t)
}
return ret
}