-
Notifications
You must be signed in to change notification settings - Fork 1
/
word.go
46 lines (39 loc) · 914 Bytes
/
word.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
package main
type Word struct {
surface string
lemma string
posTag string
cposTag string
idx int
head int
predHead int
children []Word
}
func makeWord(surface string, posTag string, idx int, head int) *Word {
return &Word{surface, surface, posTag, posTag, idx, head, head, make([]Word, 0)}
}
func makeRootWord() *Word {
return makeWord("*ROOT*", "*ROOT*", 0, -1)
}
func (word *Word) appendChild(c *Word) []Word {
word.children = append(word.children, *c)
return word.children
}
func (word *Word) prependChild(c *Word) []Word {
word.children = append([]Word{*c}, word.children...)
return word.children
}
func (word *Word) LeftMostChild() *Word {
if len(word.children) == 0 {
return nil
} else {
return &word.children[0]
}
}
func (word *Word) RightMostChild() *Word {
if len(word.children) == 0 {
return nil
} else {
return &word.children[len(word.children)-1]
}
}