-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconll_test.go
60 lines (46 loc) · 1.08 KB
/
conll_test.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
package conllx
import (
"bufio"
"fmt"
"log"
"strings"
)
func ExampleNewToken() {
// Construct a token using the builder-pattern
token := NewToken().SetForm("apples").SetLemma("apple").SetPosTag("noun")
// Append the token to a sentence.
var sent Sentence
sent = append(sent, *token)
fmt.Println(sent)
// Output: 1 apples apple _ noun _ _ _ _ _
}
func ExampleToken_Features() {
input := `1 test _ _ _ f1:v1|f2:v2`
strReader := strings.NewReader(input)
reader := NewReader(bufio.NewReader(strReader))
sent, err := reader.ReadSentence()
if err != nil {
log.Fatal("Error reading sentence")
}
features, ok := sent[0].Features()
if !ok {
log.Fatal("Token should have features")
}
fmt.Println(features.FeaturesMap()["f1"])
fmt.Println(features.FeaturesMap()["f2"])
// Output:
// v1
// v2
}
func ExampleToken_SetFeatures() {
token := NewToken().SetFeatures(map[string]string{
"num": "sg",
"tense": "past",
})
features, _ := token.Features()
fmt.Println(features.FeaturesMap()["num"])
fmt.Println(features.FeaturesMap()["tense"])
// Output:
// sg
// past
}