-
Notifications
You must be signed in to change notification settings - Fork 0
/
vorfeld.go
180 lines (162 loc) · 3.7 KB
/
vorfeld.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package alpinods
func doVorfeld(node *Node, q *context) {
q.vorfeld = make(map[int]map[int]bool)
q.vorfeldSkip = make(map[int]map[int]bool)
prepareVorfeld1(node, q)
prepareVorfeld2(node, q)
prepareVorfeld3(node, q)
}
func prepareVorfeld1(node *Node, q *context) {
q.vorfeld[node.ID] = make(map[int]bool)
q.vorfeldSkip[node.ID] = make(map[int]bool)
if node.Node != nil {
for _, n := range node.Node {
prepareVorfeld1(n, q)
}
}
}
func prepareVorfeld2(node *Node, q *context) {
if node.Cat == "smain" {
smainVorfeld(node, q)
} else if node.Cat == "whq" {
whqVorfeld(node, q)
}
if node.Node != nil {
for _, n := range node.Node {
prepareVorfeld2(n, q)
}
}
}
func prepareVorfeld3(node *Node, q *context) {
if node.Cat != "" || node.Pt != "" {
for id := range q.vorfeld[node.ID] {
if !q.vorfeldSkip[node.ID][id] {
node.IsVorfeld = "true"
break
}
}
}
if node.Node != nil {
for _, n := range node.Node {
prepareVorfeld3(n, q)
}
}
}
func smainVorfeld(node *Node, q *context) {
if node.Node != nil {
for _, n := range node.Node {
if n.Rel == "hd" {
// NIET alleen primary links
n = idx(n, q)
if n.Word != "" {
for _, topic := range findTopic(node, n.Begin, false, q) {
if checkTopic(topic, node, n.Begin, q) {
q.vorfeld[topic.ID][node.ID] = true
} else {
q.vorfeldSkip[topic.ID][node.ID] = true
}
}
}
}
}
}
}
func whqVorfeld(node *Node, q *context) {
if node.Node != nil {
for _, n := range node.Node {
// NIET alleen primary links
rel := n.Rel
n = idx(n, q)
if rel == "body" && n.Cat == "sv1" {
for _, n2 := range n.Node {
if n2.Rel == "hd" {
// NIET alleen primary links
n2 = idx(n2, q)
if n2.Word != "" {
for _, topic := range findTopic(node, n2.Begin, true, q) {
if checkTopic(topic, node, n2.Begin, q) {
q.vorfeld[topic.ID][node.ID] = true
} else {
q.vorfeldSkip[topic.ID][node.ID] = true
}
}
}
}
}
}
}
}
}
func findTopic(node *Node, begin int, needWhd bool, q *context) []*Node {
topics := make([]*Node, 0)
// hier: inclusief topnode
//if isTopic(node, begin) {
// topics = append(topics, node)
//}
if node.Node != nil {
for _, n := range node.Node {
if needWhd && n.Rel != "whd" {
continue
}
// hier: exclusief topnode
if isTopic(n, begin, q) {
topics = append(topics, n)
}
// ALLEEN primary links
for _, topic := range findTopic(n, begin, false, q) {
topics = append(topics, topic)
}
}
}
return topics
}
func isTopic(node *Node, begin int, q *context) bool {
if node.Begin < begin && node.End <= begin {
return true
}
if node.Lemma != "" || node.Cat == "mwu" {
if node.Begin < begin {
return true
}
return false
}
if node.Node != nil {
for _, n := range node.Node {
if n.Rel == "hd" || n.Rel == "cmp" || n.Rel == "crd" {
// NIET alleen primary links
n = idx(n, q)
if (n.Lemma != "" || n.Cat == "mwu") && n.Begin < begin {
return true
}
}
}
}
return false
}
func checkTopic(topic, node *Node, begin int, q *context) bool {
// alle nodes tussen node (exclusief) en topic (exclusief)
nodes := make(map[*Node]bool)
nodePath(node, topic, nodes, q)
for n := range nodes {
if isTopic(n, begin, q) {
return false
}
}
return true
}
func nodePath(top, bottom *Node, nodes map[*Node]bool, q *context) bool {
retval := false
if top.Node != nil {
for _, n := range top.Node {
// NIET alleen primaire links (lijkt niet logisch, maar werkt toch beter)
n = idx(n, q)
if n == bottom {
retval = true
} else if nodePath(n, bottom, nodes, q) {
nodes[n] = true
retval = true
}
}
}
return retval
}