use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel in project webanno by webanno.
the class MergeCas method addSlotArcAnnotation.
private static void addSlotArcAnnotation(SpanAdapter aAdapter, JCas aJcas, String aFSArcaddress, JCas aClickedJCas, AnnotationFS aClickedFS) throws AnnotationException {
List<AnnotationFS> merges = MergeCas.getMergeFS(aClickedFS, aJcas).collect(Collectors.toList());
AnnotationFS targetFs;
if (merges.size() == 0) {
throw new AnnotationException("The base annotation do not exist. Please add it first. ");
}
AnnotationFS mergeFs = merges.get(0);
int fiIndex = Integer.parseInt(aFSArcaddress.split("\\.")[1]);
int liIndex = Integer.parseInt(aFSArcaddress.split("\\.")[2]);
AnnotationFeature slotFeature = null;
LinkWithRoleModel linkRole = null;
int fi = 0;
f: for (AnnotationFeature feat : aAdapter.listFeatures()) {
if (MultiValueMode.ARRAY.equals(feat.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(feat.getLinkMode())) {
List<LinkWithRoleModel> links = aAdapter.getFeatureValue(feat, aClickedFS);
for (int li = 0; li < links.size(); li++) {
LinkWithRoleModel link = links.get(li);
if (fi == fiIndex && li == liIndex) {
slotFeature = feat;
List<AnnotationFS> targets = checkAndGetTargets(aJcas, aClickedJCas, selectByAddr(aClickedJCas, link.targetAddr));
targetFs = targets.get(0);
link.targetAddr = getAddr(targetFs);
linkRole = link;
break f;
}
}
}
fi++;
}
List<LinkWithRoleModel> links = aAdapter.getFeatureValue(slotFeature, mergeFs);
//
LinkWithRoleModel duplicateLink = null;
for (LinkWithRoleModel lr : links) {
if (lr.targetAddr == linkRole.targetAddr) {
duplicateLink = lr;
break;
}
}
links.add(linkRole);
links.remove(duplicateLink);
setFeature(mergeFs, slotFeature, links);
}
Aggregations