-
Notifications
You must be signed in to change notification settings - Fork 0
/
nachfeld.go
131 lines (123 loc) · 2.07 KB
/
nachfeld.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
package alpinods
var (
vpCat = map[string]bool{
"inf": true,
"ti": true,
"ssub": true,
"oti": true,
"ppart": true,
}
rHead = map[string]bool{
"hd": true,
"cmp": true,
"mwp": true,
"crd": true,
"rhd": true,
"whd": true,
"nucl": true,
"dp": true,
}
)
func doNachfeld(node *Node, q *context) {
findNachfeld(node, q)
if node.Node != nil {
for _, n := range node.Node {
doNachfeld(n, q)
}
}
}
func findNachfeld(node *Node, q *context) {
if !vpCat[node.Cat] {
return
}
if node.Node == nil || len(node.Node) == 0 {
return
}
// zoek begin van head
headBegin := -1
for _, n := range node.Node {
n = idx(n, q)
if n.Rel == "hd" {
headBegin = n.Begin
break
}
}
if headBegin < 0 {
return
}
// zoek nachfeld
for _, n := range node.Node {
n = idx(n, q)
if n.Rel != "hd" {
setNachfeld(n, headBegin, node, q)
}
}
}
func setNachfeld(node *Node, begin int, vp *Node, q *context) {
if node.Rel != "hd" && node.Rel != "svp" && node.Cat != "inf" && node.Cat != "ppart" {
var skip func(*Node, int) bool
skip = func(current *Node, state int) bool {
current = idx(current, q)
if current == node {
return state == 2
}
switch state {
case 0:
state = 1
case 1:
if vpCat[current.Cat] {
state = 2
}
}
if current.Node != nil {
for _, n := range current.Node {
if skip(n, state) {
return true
}
}
}
return false
}
n2 := make([]*Node, 0)
if node.Node != nil {
for _, nn2 := range node.Node {
nn2 = idx(nn2, q)
if rHead[nn2.Rel] {
n2 = append(n2, nn2)
}
}
}
if len(n2) == 0 {
if begin < node.Begin {
if !skip(vp, 0) {
node.IsNachfeld = "true"
}
return
}
} else {
ok := true
for _, nn2 := range n2 {
if begin >= nn2.Begin {
ok = false
break
}
}
if ok {
if !skip(vp, 0) {
node.IsNachfeld = "true"
}
return
}
}
}
if vpCat[node.Cat] {
return
}
if node.Node == nil {
return
}
for _, n := range node.Node {
n = idx(n, q)
setNachfeld(n, begin, vp, q)
}
}