TEIGroupImpl.java
2.21 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
package ipipan.clarin.tei.impl.entities;
import ipipan.clarin.tei.api.entities.TEIGroup;
import ipipan.clarin.tei.api.entities.TEIMorph;
import ipipan.clarin.tei.api.entities.TEISyntacticEntity;
import ipipan.clarin.tei.api.entities.TEIWord;
import java.util.LinkedList;
import java.util.List;
import com.google.common.collect.Lists;
/**
*
* @author mlenart
*/
public class TEIGroupImpl extends TEIAbstractEntity implements TEIGroup {
private String orth;
private String type;
private TEISyntacticEntity syntacticHead;
private TEISyntacticEntity semanticHead;
private List<TEISyntacticEntity> children;
public TEIGroupImpl(String id, String orth, String type,
TEISyntacticEntity syntacticHead, TEISyntacticEntity semanticHead,
List<TEISyntacticEntity> children) {
super(id);
this.orth = orth;
this.type = type;
this.syntacticHead = syntacticHead;
this.semanticHead = semanticHead;
// Preconditions.require(String.format("Group %s is missing semantic head",
// getId()), semanticHead != null);
// Preconditions.require(String.format("Group %s is missing syntactic head",
// getId()), syntacticHead != null);
this.children = children;
}
@Override
public String getOrth() {
return orth;
}
@Override
public String getType() {
return type;
}
@Override
public TEISyntacticEntity getSyntacticHead() {
return syntacticHead;
}
@Override
public TEISyntacticEntity getSemanticHead() {
return semanticHead;
}
@Override
public List<TEISyntacticEntity> getChildren() {
return children;
}
@Override
public boolean isWord() {
return false;
}
@Override
public boolean isGroup() {
return true;
}
@Override
public List<TEIMorph> getLeaves() {
List<TEIMorph> res = new LinkedList<TEIMorph>();
for (TEISyntacticEntity entity : children)
res.addAll(entity.getLeaves());
return res;
}
@Override
public TEIWord asWord() {
throw new UnsupportedOperationException("Cannot treat word as group");
}
@Override
public TEIGroup asGroup() {
return this;
}
@Override
public List<TEIWord> getAllDescendingWords() {
List<TEIWord> res = Lists.newLinkedList();
for (TEISyntacticEntity entity : getChildren()) {
res.addAll(entity.getAllDescendingWords());
}
return res;
}
}