TEIWordImpl.java
2.51 KB
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
package ipipan.clarin.tei.impl.entities;
import ipipan.clarin.tei.api.entities.TEIGroup;
import ipipan.clarin.tei.api.entities.TEIInterpretation;
import ipipan.clarin.tei.api.entities.TEIMorph;
import ipipan.clarin.tei.api.entities.TEIWord;
import ipipan.clarin.tei.api.entities.TEIWordChild;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import com.google.common.collect.Lists;
/**
*
* @author mlenart
*/
class TEIWordImpl extends TEIAbstractEntity implements TEIWord {
private String orth;
private TEIInterpretation interp;
private final List<TEIWordChild> children;
private final List<TEIMorph> leaves;
public TEIWordImpl(String id, String orth, TEIInterpretation interp,
List<TEIWordChild> children) {
super(id);
this.orth = orth;
this.interp = interp;
this.children = children;
this.leaves = new ArrayList<TEIMorph>();
for (TEIWordChild child : children) {
if (child.isMorph())
leaves.add((TEIMorph) child);
else
leaves.addAll(((TEIWord) child).getLeaves());
}
}
@Override
public String getOrth() {
return orth;
}
@Override
public TEIInterpretation getInterpretation() {
return interp;
}
@Override
public List<TEIWordChild> getChildren() {
return children;
}
@Override
public List<TEIMorph> getLeaves() {
List<TEIMorph> res = new LinkedList<TEIMorph>();
for (TEIWordChild child : children) {
if (child.isMorph())
res.add((TEIMorph) child);
else
res.addAll(((TEIWord) child).getLeaves());
}
return res;
}
@Override
public boolean isWord() {
return true;
}
@Override
public boolean isMorph() {
return false;
}
@Override
public boolean isGroup() {
return false;
}
@Override
public List<TEIMorph> getAllMorphs() {
List<TEIMorph> res = new LinkedList<TEIMorph>();
for (TEIWordChild child : getChildren()) {
if (child.isMorph())
res.add((TEIMorph) child);
else
res.addAll(((TEIWord) child).getAllMorphs());
}
return res;
}
@Override
public TEIWord asWord() {
return this;
}
@Override
public TEIGroup asGroup() {
throw new UnsupportedOperationException("Cannot treat word as group");
}
@Override
public TEIMorph asMorph() {
throw new UnsupportedOperationException("Cannot treat word as morph");
}
@Override
public List<TEIWord> getAllDescendingWords() {
List<TEIWord> res = Lists.newLinkedList();
for (TEIWordChild child : getChildren()) {
if (child.isWord()) {
res.add(child.asWord());
res.addAll(child.asWord().getAllDescendingWords());
}
}
return res;
}
}