TEIMorphImpl.java
4.1 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package ipipan.clarin.tei.impl.entities;
import ipipan.clarin.tei.api.entities.EntitiesFactory;
import ipipan.clarin.tei.api.entities.TEIInterpretation;
import ipipan.clarin.tei.api.entities.TEILex;
import ipipan.clarin.tei.api.entities.TEIMorph;
import ipipan.clarin.tei.api.entities.TEINamedEntity;
import ipipan.clarin.tei.api.entities.TEISegment;
import ipipan.clarin.tei.api.entities.TEIWord;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
*
* @author mlenart
*/
class TEIMorphImpl extends TEIAbstractEntity implements TEIMorph {
private final TEISegment corresp;
private final String orth;
private final boolean nps;
private final List<TEILex> lexems;
private final Map<TEIInterpretation, String> interp2MsdId;
private TEIInterpretation chosenInterp;
public TEIMorphImpl(String id, TEISegment corresp, String orth,
boolean nps, List<TEILex> lexems) {
super(id);
this.corresp = corresp;
this.orth = orth;
this.nps = nps;
this.lexems = lexems;
this.interp2MsdId = new LinkedHashMap<TEIInterpretation, String>();
for (TEILex lex : lexems)
for (Map.Entry<String, String> entry : lex.getMsd().entrySet()) {
String msdId = entry.getKey();
String msd = entry.getValue();
interp2MsdId.put(
EntitiesFactory.getInstance().createInterpretation(
lex.getBase(), lex.getCTag(), msd), msdId);
}
}
TEIMorphImpl(String id, TEISegment seg) {
super(id);
this.corresp = seg;
this.orth = seg.getOrth();
this.nps = seg.hasNps();
this.lexems = Lists.newLinkedList();
this.interp2MsdId = Maps.newHashMap();
}
@Override
public TEISegment getCorrespSegment() {
return corresp;
}
@Override
public String getOrth() {
return orth;
}
@Override
public boolean hasNps() {
return nps;
}
@Override
public List<TEILex> getLexems() {
return lexems;
}
@Override
public List<TEIInterpretation> getAllInterpretations() {
return new LinkedList<TEIInterpretation>(interp2MsdId.keySet());
}
@Override
public TEIInterpretation getChosenInterpretation() {
return chosenInterp;
}
@Override
public void setChosenInterpretation(TEIInterpretation interp) {
if (!getAllInterpretations().contains(interp)) {
addInterpretation(interp);
}
this.chosenInterp = interp;
}
@Override
public void addInterpretation(TEIInterpretation interp) {
TEILex lex = null;
for (TEILex lex1 : lexems) {
if (lex1.getBase().equals(interp.getBase())
&& lex1.getCTag().equals(interp.getCtag())) {
lex = lex1;
}
}
if (lex != null && lex.getMsd().values().contains(interp.getMorph())) {
// do nothing
} else if (lex != null) {
String newMsdId = lex.getId() + "." + (lex.getMsd().size() + 1);
lex.getMsd().put(newMsdId, interp.getMorph());
interp2MsdId.put(interp, newMsdId);
} else {
String newLexId = this.getId() + "."
+ (this.getLexems().size() + 1);
String newMsdId = newLexId + "." + 1;
Map<String, String> msdMap = Maps.newHashMap();
msdMap.put(newMsdId, interp.getMorph());
lex = EntitiesFactory.getInstance().createLex(newLexId,
interp.getBase(), interp.getCtag(), msdMap);
lexems.add(lex);
interp2MsdId.put(interp, newMsdId);
}
}
@Override
public boolean isChosenInterpretation(TEIInterpretation interp) {
return interp.equals(chosenInterp);
}
@Override
public boolean isWord() {
return false;
}
@Override
public boolean isMorph() {
return true;
}
@Override
public boolean isNamedEntity() {
return false;
}
@Override
public String getInterpMsdId(TEIInterpretation interp) {
return interp2MsdId.get(interp);
}
@Override
public String getChosenInterpMsdId() {
return interp2MsdId.get(getChosenInterpretation());
}
@Override
public TEIMorph asMorph() {
return this;
}
@Override
public TEINamedEntity asNamedEntity() {
throw new UnsupportedOperationException(
"Cannot treat morph as named entity");
}
@Override
public TEIWord asWord() {
throw new UnsupportedOperationException("Cannot treat morph as word");
}
public String toString() {
return orth;
}
}