-
Notifications
You must be signed in to change notification settings - Fork 0
/
np.go
103 lines (89 loc) · 1.81 KB
/
np.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package alpinods
func doNp(node *Node, q *context) {
q.rels = make(map[int][]string)
prepareNp1(node, q)
prepareNp2(node, q)
}
func prepareNp1(node *Node, q *context) {
if q.rels[node.ID] == nil {
q.rels[node.ID] = make([]string, 0)
}
q.rels[node.ID] = append(q.rels[node.ID], node.Rel)
if n := idx(node, q); n != node {
if q.rels[n.ID] == nil {
q.rels[n.ID] = make([]string, 0)
}
q.rels[n.ID] = append(q.rels[n.ID], node.Rel)
}
if node.Node != nil {
for _, n := range node.Node {
prepareNp1(n, q)
}
}
}
func prepareNp2(node *Node, q *context) {
if isNP(node, q) {
node.IsNp = "true"
}
if node.Node != nil {
for _, n := range node.Node {
doNp(n, q)
}
}
}
func isNP(node *Node, q *context) bool {
if node.Cat == "" && node.Pt == "" {
return false
}
if node.Cat == "np" {
return true
}
if node.Lcat == "np" && otherString(q.rels[node.ID], "hd", "mwp") {
return true
}
if node.Pt == "n" && otherString(q.rels[node.ID], "hd") {
return true
}
if node.Pt == "vnw" && node.Pdtype == "pron" && otherString(q.rels[node.ID], "hd") {
return true
}
if node.Cat == "mwu" && hasString(q.rels[node.ID], "su", "obj1", "obj2", "app") {
return true
}
if node.Node != nil {
for _, n := range node.Node {
if n.Rel != "cnj" {
continue
}
n = idx(n, q)
if isNP(n, q) {
return true
}
}
}
return false
}
// is er een string in ss die gelijk is aan een string in s ?
func hasString(ss []string, s ...string) bool {
for _, s1 := range ss {
for _, s2 := range s {
if s1 == s2 {
return true
}
}
}
return false
}
// is er een string in ss die ongelijk is aan alle strings in s ?
func otherString(ss []string, s ...string) bool {
LOOP:
for _, s1 := range ss {
for _, s2 := range s {
if s1 == s2 {
continue LOOP
}
}
return true
}
return false
}