Search in sources :

Example 11 with LinkWithRoleModel

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);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) LinkedList(java.util.LinkedList) List(java.util.List) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)11 List (java.util.List)7 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)6 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)5 Type (org.apache.uima.cas.Type)5 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)4 ArrayList (java.util.ArrayList)4 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)4 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)3 HashSet (java.util.HashSet)3 UIMAException (org.apache.uima.UIMAException)3 Feature (org.apache.uima.cas.Feature)3 FeatureStructure (org.apache.uima.cas.FeatureStructure)3 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)1 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)1 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)1 VArc (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc)1 VDocument (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument)1 VRange (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VRange)1