Search in sources :

Example 1 with VArc

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc in project webanno by webanno.

the class RelationRenderer method render.

@Override
public void render(final JCas aJcas, List<AnnotationFeature> aFeatures, VDocument aResponse, AnnotatorState aBratAnnotatorModel) {
    List<AnnotationFeature> visibleFeatures = aFeatures.stream().filter(f -> f.isVisible() && f.isEnabled()).collect(Collectors.toList());
    ArcAdapter typeAdapter = getTypeAdapter();
    Type type = getType(aJcas.getCas(), typeAdapter.getAnnotationTypeName());
    int windowBegin = aBratAnnotatorModel.getWindowBeginOffset();
    int windowEnd = aBratAnnotatorModel.getWindowEndOffset();
    Feature dependentFeature = type.getFeatureByBaseName(typeAdapter.getTargetFeatureName());
    Feature governorFeature = type.getFeatureByBaseName(typeAdapter.getSourceFeatureName());
    Type spanType = getType(aJcas.getCas(), typeAdapter.getAttachTypeName());
    Feature arcSpanFeature = spanType.getFeatureByBaseName(typeAdapter.getAttachFeatureName());
    FeatureStructure dependentFs;
    FeatureStructure governorFs;
    Map<Integer, Set<Integer>> relationLinks = getRelationLinks(aJcas, windowBegin, windowEnd, type, dependentFeature, governorFeature, arcSpanFeature);
    // if this is a governor for more than one dependent, avoid duplicate yield
    List<Integer> yieldDeps = new ArrayList<>();
    for (AnnotationFS fs : selectCovered(aJcas.getCas(), type, windowBegin, windowEnd)) {
        if (typeAdapter.getAttachFeatureName() != null) {
            dependentFs = fs.getFeatureValue(dependentFeature).getFeatureValue(arcSpanFeature);
            governorFs = fs.getFeatureValue(governorFeature).getFeatureValue(arcSpanFeature);
        } else {
            dependentFs = fs.getFeatureValue(dependentFeature);
            governorFs = fs.getFeatureValue(governorFeature);
        }
        String bratTypeName = TypeUtil.getUiTypeName(typeAdapter);
        Map<String, String> features = getFeatures(typeAdapter, fs, visibleFeatures);
        if (dependentFs == null || governorFs == null) {
            RequestCycle requestCycle = RequestCycle.get();
            IPageRequestHandler handler = PageRequestHandlerTracker.getLastHandler(requestCycle);
            Page page = (Page) handler.getPage();
            StringBuilder message = new StringBuilder();
            message.append("Relation [" + typeAdapter.getLayer().getName() + "] with id [" + getAddr(fs) + "] has loose ends - cannot render.");
            if (typeAdapter.getAttachFeatureName() != null) {
                message.append("\nRelation [" + typeAdapter.getLayer().getName() + "] attached to feature [" + typeAdapter.getAttachFeatureName() + "].");
            }
            message.append("\nDependent: " + dependentFs);
            message.append("\nGovernor: " + governorFs);
            page.warn(message.toString());
            continue;
        }
        aResponse.add(new VArc(typeAdapter.getLayer(), fs, bratTypeName, governorFs, dependentFs, features));
        // Render errors if required features are missing
        renderRequiredFeatureErrors(visibleFeatures, fs, aResponse);
        if (relationLinks.keySet().contains(getAddr(governorFs)) && !yieldDeps.contains(getAddr(governorFs))) {
            yieldDeps.add(getAddr(governorFs));
            // sort the annotations (begin, end)
            List<Integer> sortedDepFs = new ArrayList<>(relationLinks.get(getAddr(governorFs)));
            sortedDepFs.sort(comparingInt(arg0 -> selectByAddr(aJcas, arg0).getBegin()));
            String cm = getYieldMessage(aJcas, sortedDepFs);
            aResponse.add(new VComment(governorFs, VCommentType.YIELD, cm));
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Page(org.apache.wicket.Page) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) VCommentType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType) WebAnnoCasUtil.selectByAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectByAddr) LoggerFactory(org.slf4j.LoggerFactory) Feature(org.apache.uima.cas.Feature) ArrayList(java.util.ArrayList) Type(org.apache.uima.cas.Type) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Map(java.util.Map) PageRequestHandlerTracker(org.apache.wicket.request.cycle.PageRequestHandlerTracker) FeatureStructure(org.apache.uima.cas.FeatureStructure) JCas(org.apache.uima.jcas.JCas) WebAnnoCasUtil.getAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getAddr) Comparator.comparingInt(java.util.Comparator.comparingInt) Logger(org.slf4j.Logger) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) CasUtil.selectCovered(org.apache.uima.fit.util.CasUtil.selectCovered) List(java.util.List) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) TypeUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) FeatureSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry) Set(java.util.Set) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) ArrayList(java.util.ArrayList) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Page(org.apache.wicket.Page) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) VCommentType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 2 with VArc

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc in project webanno by webanno.

the class ChainRenderer method render.

@Override
public void render(JCas aJcas, List<AnnotationFeature> aFeatures, VDocument aResponse, AnnotatorState aState) {
    List<AnnotationFeature> visibleFeatures = aFeatures.stream().filter(f -> f.isVisible() && f.isEnabled()).collect(Collectors.toList());
    // Find the features for the arc and span labels - it is possible that we do not find a
    // feature for arc/span labels because they may have been disabled.
    AnnotationFeature spanLabelFeature = null;
    AnnotationFeature arcLabelFeature = null;
    for (AnnotationFeature f : visibleFeatures) {
        if (WebAnnoConst.COREFERENCE_TYPE_FEATURE.equals(f.getName())) {
            spanLabelFeature = f;
        }
        if (WebAnnoConst.COREFERENCE_RELATION_FEATURE.equals(f.getName())) {
            arcLabelFeature = f;
        }
    }
    // At this point arc and span feature labels must have been found! If not, the later code
    // will crash.
    ChainAdapter typeAdapter = getTypeAdapter();
    Type chainType = typeAdapter.getAnnotationType(aJcas.getCas());
    Feature chainFirst = chainType.getFeatureByBaseName(typeAdapter.getChainFirstFeatureName());
    int colorIndex = 0;
    // Iterate over the chains
    for (FeatureStructure chainFs : selectFS(aJcas.getCas(), chainType)) {
        AnnotationFS linkFs = (AnnotationFS) chainFs.getFeatureValue(chainFirst);
        AnnotationFS prevLinkFs = null;
        // Iterate over the links of the chain
        while (linkFs != null) {
            Feature linkNext = linkFs.getType().getFeatureByBaseName(typeAdapter.getLinkNextFeatureName());
            AnnotationFS nextLinkFs = (AnnotationFS) linkFs.getFeatureValue(linkNext);
            // Is link after window? If yes, we can skip the rest of the chain
            if (linkFs.getBegin() >= aState.getWindowEndOffset()) {
                // Go to next chain
                break;
            }
            // end within the window
            if (!(linkFs.getBegin() >= aState.getWindowBeginOffset()) && (linkFs.getEnd() <= aState.getWindowEndOffset())) {
                // prevLinkFs remains null until we enter the window
                linkFs = nextLinkFs;
                // Go to next link
                continue;
            }
            String bratTypeName = TypeUtil.getUiTypeName(typeAdapter);
            // Render span
            {
                String bratLabelText = TypeUtil.getUiLabelText(typeAdapter, linkFs, (spanLabelFeature != null) ? asList(spanLabelFeature) : emptyList());
                String bratHoverText = TypeUtil.getUiHoverText(typeAdapter, linkFs, (spanLabelFeature != null) ? asList(spanLabelFeature) : emptyList());
                VRange offsets = new VRange(linkFs.getBegin() - aState.getWindowBeginOffset(), linkFs.getEnd() - aState.getWindowBeginOffset());
                aResponse.add(new VSpan(typeAdapter.getLayer(), linkFs, bratTypeName, offsets, colorIndex, singletonMap("label", bratLabelText), singletonMap("label", bratHoverText)));
            }
            // and last link are within the window ;)
            if (prevLinkFs != null) {
                String bratLabelText = null;
                if (typeAdapter.isLinkedListBehavior() && arcLabelFeature != null) {
                    // Render arc label
                    bratLabelText = TypeUtil.getUiLabelText(typeAdapter, prevLinkFs, asList(arcLabelFeature));
                } else {
                    // Render only chain type
                    bratLabelText = TypeUtil.getUiLabelText(typeAdapter, prevLinkFs, emptyList());
                }
                aResponse.add(new VArc(typeAdapter.getLayer(), new VID(prevLinkFs, 1, VID.NONE, VID.NONE), bratTypeName, prevLinkFs, linkFs, colorIndex, singletonMap("label", bratLabelText)));
            }
            // Render errors if required features are missing
            renderRequiredFeatureErrors(visibleFeatures, linkFs, aResponse);
            // if (BratAjaxCasUtil.isSame(linkFs, nextLinkFs)) {
            // log.error("Loop in CAS detected, aborting rendering of chains");
            // break;
            // }
            prevLinkFs = linkFs;
            linkFs = nextLinkFs;
        }
        // The color index is updated even for chains that have no visible links in the current
        // window because we would like the chain color to be independent of visibility. In
        // particular the color of a chain should not change when switching pages/scrolling.
        colorIndex++;
    }
}
Also used : JCas(org.apache.uima.jcas.JCas) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) Collections.emptyList(java.util.Collections.emptyList) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) Feature(org.apache.uima.cas.Feature) Collectors(java.util.stream.Collectors) Type(org.apache.uima.cas.Type) VSpan(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan) List(java.util.List) TypeUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) VRange(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VRange) Arrays.asList(java.util.Arrays.asList) ChainAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ChainAdapter) Collections.singletonMap(java.util.Collections.singletonMap) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) FeatureStructure(org.apache.uima.cas.FeatureStructure) CasUtil.selectFS(org.apache.uima.fit.util.CasUtil.selectFS) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) FeatureSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry) VSpan(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) FeatureStructure(org.apache.uima.cas.FeatureStructure) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) VRange(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VRange) ChainAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ChainAdapter) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 3 with VArc

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc in project webanno by webanno.

the class SpanRenderer method render.

@Override
public void render(JCas aJcas, List<AnnotationFeature> aFeatures, VDocument aResponse, AnnotatorState aBratAnnotatorModel) {
    List<AnnotationFeature> visibleFeatures = aFeatures.stream().filter(f -> f.isVisible() && f.isEnabled()).collect(Collectors.toList());
    SpanAdapter typeAdapter = getTypeAdapter();
    Type type = getType(aJcas.getCas(), typeAdapter.getAnnotationTypeName());
    int windowBegin = aBratAnnotatorModel.getWindowBeginOffset();
    int windowEnd = aBratAnnotatorModel.getWindowEndOffset();
    List<Sentence> visibleSentences = selectCovered(aJcas, Sentence.class, windowBegin, windowEnd);
    for (AnnotationFS fs : selectCovered(aJcas.getCas(), type, windowBegin, windowEnd)) {
        String bratTypeName = TypeUtil.getUiTypeName(typeAdapter);
        Map<String, String> features = getFeatures(typeAdapter, fs, visibleFeatures);
        Map<String, String> hoverFeatures = getHoverFeatures(typeAdapter, fs, aFeatures);
        Sentence beginSent = null;
        Sentence endSent = null;
        // the visible window
        for (Sentence sent : visibleSentences) {
            if (beginSent == null) {
                // offset of the current annotation.
                if (sent.getBegin() <= fs.getBegin() && fs.getBegin() <= sent.getEnd()) {
                    beginSent = sent;
                }
                // second sentence.
                if (fs.getBegin() == fs.getEnd()) {
                    endSent = sent;
                }
            }
            if (endSent == null) {
                if (sent.getBegin() <= fs.getEnd() && fs.getEnd() <= sent.getEnd()) {
                    endSent = sent;
                }
            }
            if (beginSent != null && endSent != null) {
                break;
            }
        }
        if (beginSent == null || endSent == null) {
            throw new IllegalStateException("Unable to determine sentences in which the annotation starts/ends: " + fs);
        }
        List<Sentence> sentences = selectCovered(aJcas, Sentence.class, beginSent.getBegin(), endSent.getEnd());
        List<VRange> ranges = new ArrayList<>();
        if (sentences.size() > 1) {
            for (Sentence sentence : sentences) {
                if (sentence.getBegin() <= fs.getBegin() && fs.getBegin() < sentence.getEnd()) {
                    ranges.add(new VRange(fs.getBegin() - windowBegin, sentence.getEnd() - windowBegin));
                } else if (sentence.getBegin() <= fs.getEnd() && fs.getEnd() <= sentence.getEnd()) {
                    ranges.add(new VRange(sentence.getBegin() - windowBegin, fs.getEnd() - windowBegin));
                } else {
                    ranges.add(new VRange(sentence.getBegin() - windowBegin, sentence.getEnd() - windowBegin));
                }
            }
            aResponse.add(new VSpan(typeAdapter.getLayer(), fs, bratTypeName, ranges, features, hoverFeatures));
        } else {
            // FIXME It should be possible to remove this case and the if clause because
            // the case that a FS is inside a single sentence is just a special case
            aResponse.add(new VSpan(typeAdapter.getLayer(), fs, bratTypeName, new VRange(fs.getBegin() - windowBegin, fs.getEnd() - windowBegin), features, hoverFeatures));
        }
        // Render errors if required features are missing
        renderRequiredFeatureErrors(visibleFeatures, fs, aResponse);
        // Render slots
        int fi = 0;
        for (AnnotationFeature feat : typeAdapter.listFeatures()) {
            if (MultiValueMode.ARRAY.equals(feat.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(feat.getLinkMode())) {
                List<LinkWithRoleModel> links = typeAdapter.getFeatureValue(feat, fs);
                for (int li = 0; li < links.size(); li++) {
                    LinkWithRoleModel link = links.get(li);
                    FeatureStructure targetFS = selectByAddr(fs.getCAS(), link.targetAddr);
                    aResponse.add(new VArc(typeAdapter.getLayer(), new VID(fs, fi, li), bratTypeName, fs, targetFS, link.role, features));
                }
            }
            fi++;
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) WebAnnoCasUtil.selectByAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectByAddr) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) LinkMode(de.tudarmstadt.ukp.clarin.webanno.model.LinkMode) ArrayList(java.util.ArrayList) Type(org.apache.uima.cas.Type) VRange(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VRange) Map(java.util.Map) FeatureStructure(org.apache.uima.cas.FeatureStructure) JCas(org.apache.uima.jcas.JCas) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) MultiValueMode(de.tudarmstadt.ukp.clarin.webanno.model.MultiValueMode) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) Collectors(java.util.stream.Collectors) VSpan(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan) CasUtil.selectCovered(org.apache.uima.fit.util.CasUtil.selectCovered) List(java.util.List) TypeUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) JCasUtil.selectCovered(org.apache.uima.fit.util.JCasUtil.selectCovered) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) FeatureSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) VSpan(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan) ArrayList(java.util.ArrayList) FeatureStructure(org.apache.uima.cas.FeatureStructure) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) VRange(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VRange) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 4 with VArc

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc in project webanno by webanno.

the class BratRenderer method render.

/**
 * wrap JSON responses to BRAT visualizer
 *
 * @param aResponse
 *            the response.
 * @param aState
 *            the annotator model.
 * @param aJCas
 *            the JCas.
 * @param aAnnotationService
 *            the annotation service.s
 */
public static void render(GetDocumentResponse aResponse, AnnotatorState aState, VDocument aVDoc, JCas aJCas, AnnotationSchemaService aAnnotationService, ColoringStrategy aColoringStrategy) {
    aResponse.setRtlMode(ScriptDirection.RTL.equals(aState.getScriptDirection()));
    aResponse.setFontZoom(aState.getPreferences().getFontZoom());
    // Render invisible baseline annotations (sentence, tokens)
    renderTokenAndSentence(aJCas, aResponse, aState);
    // Render visible (custom) layers
    Map<String[], Queue<String>> colorQueues = new HashMap<>();
    for (AnnotationLayer layer : aVDoc.getAnnotationLayers()) {
        ColoringStrategy coloringStrategy = aColoringStrategy != null ? aColoringStrategy : ColoringStrategy.getStrategy(aAnnotationService, layer, aState.getPreferences(), colorQueues);
        TypeAdapter typeAdapter = aAnnotationService.getAdapter(layer);
        for (VSpan vspan : aVDoc.spans(layer.getId())) {
            List<Offsets> offsets = toOffsets(vspan.getRanges());
            String bratLabelText = TypeUtil.getUiLabelText(typeAdapter, vspan.getFeatures());
            String bratHoverText = TypeUtil.getUiHoverText(typeAdapter, vspan.getHoverFeatures());
            String color;
            if (vspan.getColorHint() == null) {
                color = getColor(vspan, coloringStrategy, bratLabelText);
            } else {
                color = vspan.getColorHint();
            }
            aResponse.addEntity(new Entity(vspan.getVid(), vspan.getType(), offsets, bratLabelText, color, bratHoverText));
        }
        for (VArc varc : aVDoc.arcs(layer.getId())) {
            String bratLabelText;
            if (varc.getLabelHint() == null) {
                bratLabelText = TypeUtil.getUiLabelText(typeAdapter, varc.getFeatures());
            } else {
                bratLabelText = varc.getLabelHint();
            }
            String color;
            if (varc.getColorHint() == null) {
                color = getColor(varc, coloringStrategy, bratLabelText);
            } else {
                color = varc.getColorHint();
            }
            aResponse.addRelation(new Relation(varc.getVid(), varc.getType(), getArgument(varc.getSource(), varc.getTarget()), bratLabelText, color));
        }
    }
    List<Sentence> sentences = new ArrayList<>(select(aJCas, Sentence.class));
    for (VComment vcomment : aVDoc.comments()) {
        String type;
        switch(vcomment.getCommentType()) {
            case ERROR:
                type = AnnotationComment.ANNOTATION_ERROR;
                break;
            case INFO:
                type = AnnotationComment.ANNOTATOR_NOTES;
                break;
            case YIELD:
                type = "Yield";
                break;
            default:
                type = AnnotationComment.ANNOTATOR_NOTES;
                break;
        }
        AnnotationFS fs;
        if (!vcomment.getVid().isSynthetic() && ((fs = selectByAddr(aJCas, vcomment.getVid().getId())) instanceof Sentence)) {
            int index = sentences.indexOf(fs) + 1;
            aResponse.addComment(new SentenceComment(index, type, vcomment.getComment()));
        } else {
            aResponse.addComment(new AnnotationComment(vcomment.getVid(), type, vcomment.getComment()));
        }
    }
    // Render markers
    for (VMarker vmarker : aVDoc.getMarkers()) {
        if (vmarker instanceof VAnnotationMarker) {
            VAnnotationMarker marker = (VAnnotationMarker) vmarker;
            aResponse.addMarker(new AnnotationMarker(vmarker.getType(), marker.getVid()));
        } else if (vmarker instanceof VSentenceMarker) {
            VSentenceMarker marker = (VSentenceMarker) vmarker;
            aResponse.addMarker(new SentenceMarker(vmarker.getType(), marker.getIndex()));
        } else if (vmarker instanceof VTextMarker) {
            VTextMarker marker = (VTextMarker) vmarker;
            aResponse.addMarker(new TextMarker(marker.getType(), marker.getBegin(), marker.getEnd()));
        } else {
            LOG.warn("Unknown how to render marker: [" + vmarker + "]");
        }
    }
}
Also used : Entity(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Entity) VAnnotationMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VAnnotationMarker) VTextMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VTextMarker) HashMap(java.util.HashMap) AnnotationMarker(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.AnnotationMarker) VAnnotationMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VAnnotationMarker) ArrayList(java.util.ArrayList) ColoringStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Offsets(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Offsets) TextMarker(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.TextMarker) VTextMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VTextMarker) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) VSentenceMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSentenceMarker) SentenceMarker(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.SentenceMarker) Relation(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Relation) Queue(java.util.Queue) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) VSpan(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) AnnotationComment(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.AnnotationComment) VSentenceMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSentenceMarker) VArc(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) SentenceComment(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.SentenceComment) VMarker(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VMarker)

Aggregations

VArc (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc)4 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)4 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)3 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)3 VDocument (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument)3 VSpan (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan)3 TypeUtil (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil)3 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 FeatureStructure (org.apache.uima.cas.FeatureStructure)3 Type (org.apache.uima.cas.Type)3 JCas (org.apache.uima.jcas.JCas)3 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)2 VComment (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment)2 VRange (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VRange)2 WebAnnoCasUtil.selectByAddr (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectByAddr)2 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)2 WebAnnoConst (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst)1