map.put(value, ne.getList(parent, stream));
}
}
TypeSystem typeSystem = stream.getCas().getTypeSystem();
JCas jcas = stream.getJCas();
List<?> featuresList = structure.getType().getFeatures();
for (int i = 0; i < featuresList.size(); i++) {
Feature targetFeature = (Feature) featuresList.get(i);
String name = targetFeature.getName();
String shortFName = name.substring(name.indexOf(":") + 1, name.length());
List<Number> reIndexes = map.get(shortFName);
if (reIndexes != null && !reIndexes.isEmpty()) {
Type range = targetFeature.getRange();
List<RuleElementMatch> tms = getMatchInfo(match, element, reIndexes);
if (tms.size() == 0) {// do nothing
} else if (tms.size() == 1) {
RuleElementMatch tm = tms.get(0);
List<AnnotationFS> textsMatched = tm.getTextsMatched();
if (textsMatched.size() == 1) {
AnnotationFS fs = textsMatched.get(0);
if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) {
List<AnnotationFS> list = new ArrayList<AnnotationFS>();
list.add(fs);
structure.setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, list));
} else if (typeSystem.subsumes(range, fs.getType())) {
structure.setFeatureValue(targetFeature, fs);
} else {
// search for
Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(fs.getBegin())
.getBeginAnchors(range);
Collection<AnnotationFS> endAnchors = stream.getEndAnchor(fs.getEnd()).getEndAnchors(range);
@SuppressWarnings("unchecked")
Collection<AnnotationFS> intersection = CollectionUtils.intersection(beginAnchors,
endAnchors);
if (intersection.size() >= 1) {
structure.setFeatureValue(targetFeature, intersection.iterator().next());
}
}
}
} else {
List<AnnotationFS> textsMatched = getMatchedText(tms);
if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) {
structure.setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, textsMatched));
} else {
int begin = textsMatched.get(0).getBegin();
int end = textsMatched.get(textsMatched.size() - 1).getEnd();
RutaFrame frame = new RutaFrame(jcas, begin, end);
FSIterator<Annotation> iterator = jcas.getAnnotationIndex(range).iterator(frame);
AnnotationFS newA = null;
while (iterator.isValid()) {
Annotation a = iterator.get();
if (a.getBegin() == begin && a.getEnd() == end
&& jcas.getTypeSystem().subsumes(range, a.getType())) {
newA = a;
} else if (a.getBegin() > begin || a.getEnd() < end) {
break;
}
iterator.moveToNext();
}
if (newA == null) {
newA = jcas.getCas().createAnnotation(range, begin, end);
}
structure.setFeatureValue(targetFeature, newA);
}
}
}