-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.go
63 lines (53 loc) · 1.31 KB
/
types.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
package ling
import (
"bytes"
)
type Document struct {
Text string `json:"text"`
Tokens []*Token `json:"tokens"`
Spans []*Span `json:"spans"`
Lang string `json:"lang"`
Langs []string `json:"langs"`
}
type TokenType byte
//go:generate jsonenums -type=TokenType
//go:generate stringer -type=TokenType
const (
EOF TokenType = iota
Space
Symbol
Number
Letters
Punct
Word
)
type Token struct {
Doc *Document `json:"-"`
Text string `json:"text"`
Type TokenType `json:"type"`
Script string `json:"script"`
I int `json:"i"`
StartByte int `json:"start_byte"`
EndByte int `json:"end_byte"`
Annotations map[string]string `json:"annotations"`
}
func (t *Token) String() string {
return t.Text
}
type Span struct {
Doc *Document `json:"-"`
Start int `json:"start"`
End int `json:"end"`
Annotations map[string]interface{} `json:"annotations"`
}
func (s *Span) String() string {
output := bytes.Buffer{}
for i := s.Start; i < s.End; i++ {
output.WriteString(s.Doc.Tokens[i].String())
}
return output.String()
}
type Processor interface {
Process(d *Document) error
}
var Processors = make(map[string]Processor)