-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathapi_test.go
63 lines (60 loc) · 1.14 KB
/
api_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
61
62
63
package fmr
import (
"testing"
)
func TestLocalParse(t *testing.T) {
tests := []string{
`柏乡位于河北省`,
}
g := &Grammar{}
for _, c := range tests {
ps, err := g.EarleyParseMaxAll(c, "loc_province", "loc_county")
if err != nil {
t.Error(err)
}
for _, p := range ps {
for _, f := range p.GetFinalStates() {
t.Log(f)
trees := p.GetTrees(f)
t.Log(trees)
for _, tree := range trees {
sem, err := tree.Semantic()
if err != nil {
t.Error(err)
}
t.Log(sem)
}
}
}
}
}
func TestGParse(t *testing.T) {
tests := []string{
`柏乡位于河北省`,
}
grammar := `<loc> = <loc_province> {nf.loc($1)}| <loc_county> {nf.loc($1)};`
g, err := GrammarFromString(grammar, "loc")
if err != nil {
t.Error(err)
}
for _, c := range tests {
ps, err := g.EarleyParseMaxAll(c, "loc")
if err != nil {
t.Error(err)
}
for _, p := range ps {
for _, f := range p.GetFinalStates() {
t.Log(f)
trees := p.GetTrees(f)
t.Log(trees)
for _, tree := range trees {
sem, err := tree.Semantic()
if err != nil {
t.Error(err)
}
t.Log(sem)
}
}
}
}
}