-
Notifications
You must be signed in to change notification settings - Fork 0
/
enhance.go
71 lines (62 loc) · 1.53 KB
/
enhance.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
package alpinods
// Features defines a set of flags to pass to the method AlpinoDS.Enhance()
type Features uint
const (
Fnp Features = 1 << iota // Add attribute `is_np`
Fvorfeld // Add attribute `is_vorfeld`
Fnachfeld // Add attribute `is_nachfeld`
Fall Features = Fnp | Fvorfeld | Fnachfeld // All of the above
)
type context struct {
idxnodes map[int]*Node
rels map[int][]string
vorfeld map[int]map[int]bool
vorfeldSkip map[int]map[int]bool
}
// Enhance enriches an AlpinoDS document with structural information
// that is not provided by the Alpino parser.
//
// In addition, it sets the document version to DtdVersion.
//
// Old values for the chosen options are erased.
func (a *AlpinoDS) Enhance(f Features) {
a.Version = DtdVersion
q := &context{
idxnodes: make(map[int]*Node),
}
prepare(a.Node, f, q)
if f&Fnp != 0 {
doNp(a.Node, q)
}
if f&Fvorfeld != 0 {
doVorfeld(a.Node, q)
}
if f&Fnachfeld != 0 {
doNachfeld(a.Node, q)
}
}
func prepare(node *Node, f Features, q *context) {
if f&Fnp != 0 {
node.IsNp = ""
}
if f&Fvorfeld != 0 {
node.IsVorfeld = ""
}
if f&Fnachfeld != 0 {
node.IsNachfeld = ""
}
if node.Index != 0 && (node.Cat != "" || node.Pt != "") {
q.idxnodes[node.Index] = node
}
if node.Node != nil {
for _, n := range node.Node {
prepare(n, f, q)
}
}
}
func idx(node *Node, q *context) *Node {
if n, ok := q.idxnodes[node.Index]; ok {
return n
}
return node
}