GroupBuilder.java
1.95 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
package ipipan.clarin.tei.impl.io.read;
import ipipan.clarin.tei.api.entities.EntitiesFactory;
import ipipan.clarin.tei.api.entities.TEIGroup;
import ipipan.clarin.tei.api.entities.TEISyntacticEntity;
import ipipan.clarin.tei.api.exceptions.TEIException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
*
* @author mlenart
*/
class GroupBuilder {
private final String id;
private String orth;
private String type;
private List<String> ptrs;
private String semhead;
private String synhead;
GroupBuilder(String id) {
this.id = id;
}
TEIGroup getGroup(Map<String, TEISyntacticEntity> ptr2Entity)
throws TEIException {
List<TEISyntacticEntity> children = getChildrenList(ptr2Entity);
TEISyntacticEntity semHead = ptr2Entity.get(semhead);
TEISyntacticEntity synHead = ptr2Entity.get(synhead);
return EntitiesFactory.getInstance().createGroup(id, orth, type,
synHead, semHead, children);
}
private List<TEISyntacticEntity> getChildrenList(
Map<String, TEISyntacticEntity> ptr2Entity) throws TEIException {
List<TEISyntacticEntity> res = new ArrayList<TEISyntacticEntity>();
for (String ptr : ptrs) {
TEISyntacticEntity child = ptr2Entity.get(ptr);
if (child == null)
throw new TEIException("Invalid ptr target: " + ptr);
res.add(child);
}
return res;
}
public void setOrth(String orth) {
this.orth = orth;
}
public void setType(String type) {
this.type = type;
}
public void setPtrs(List<String> ptrs) {
if (ptrs == null)
throw new NullPointerException();
this.ptrs = ptrs;
}
public void setSemHead(String target) {
this.semhead = target;
}
public void setSynHead(String target) {
this.synhead = target;
}
// private TEISyntacticEntity find(List<TEISyntacticEntity> children,
// Map<String, TEISyntacticEntity> ptr2Entity, String id) {
// for (TEISyntacticEntity child : children) {
// if (child.getId().equals(id))
// return child;
// }
// return ptr2Entity.get(id);
// }
}