Search in sources :

Example 6 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class AnnotationPageBase method ensureRequiredFeatureValuesSet.

/**
 * Checks if all required features on all annotations are set. If a required feature value is
 * missing, then the method scrolls to that location and schedules a re-rendering. In such
 * a case, an {@link IllegalStateException} is thrown.
 */
protected void ensureRequiredFeatureValuesSet(AjaxRequestTarget aTarget, JCas aJcas) {
    AnnotatorState state = getModelObject();
    CAS editorCas = aJcas.getCas();
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(state.getProject())) {
        TypeAdapter adapter = annotationService.getAdapter(layer);
        List<AnnotationFeature> features = annotationService.listAnnotationFeature(layer);
        // If no feature is required, then we can skip the whole procedure
        if (features.stream().allMatch((f) -> !f.isRequired())) {
            continue;
        }
        // Check each feature structure of this layer
        for (AnnotationFS fs : select(editorCas, adapter.getAnnotationType(editorCas))) {
            for (AnnotationFeature f : features) {
                if (WebAnnoCasUtil.isRequiredFeatureMissing(f, fs)) {
                    // Find the sentence that contains the annotation with the missing
                    // required feature value
                    Sentence s = WebAnnoCasUtil.getSentence(aJcas, fs.getBegin());
                    // Put this sentence into the focus
                    state.setFirstVisibleUnit(s);
                    actionRefreshDocument(aTarget);
                    // Inform the user
                    throw new IllegalStateException("Document cannot be marked as finished. Annotation with ID [" + WebAnnoCasUtil.getAddr(fs) + "] on layer [" + layer.getUiName() + "] is missing value for feature [" + f.getUiName() + "].");
                }
            }
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) CAS(org.apache.uima.cas.CAS) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 7 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class SuggestionViewPanel method mergeArc.

private void mergeArc(IRequestParameters aRequest, UserAnnotationSegment aCurationUserSegment, JCas aJcas) throws AnnotationException, IOException, UIMAException, ClassNotFoundException {
    int addressOriginClicked = aRequest.getParameterValue(PARAM_ORIGIN_SPAN_ID).toInt();
    int addressTargetClicked = aRequest.getParameterValue(PARAM_TARGET_SPAN_ID).toInt();
    String arcType = removePrefix(aRequest.getParameterValue(PARAM_TYPE).toString());
    String fsArcaddress = aRequest.getParameterValue(PARAM_ARC_ID).toString();
    AnnotatorState bModel = aCurationUserSegment.getAnnotatorState();
    SourceDocument sourceDocument = bModel.getDocument();
    // for correction and automation, the lower panel is the clickedJcase, from the suggestions
    JCas clickedJCas;
    if (!aCurationUserSegment.getAnnotatorState().getMode().equals(Mode.CURATION)) {
        clickedJCas = correctionDocumentService.readCorrectionCas(sourceDocument);
    } else {
        User user = userRepository.get(aCurationUserSegment.getUsername());
        AnnotationDocument clickedAnnotationDocument = documentService.getAnnotationDocument(sourceDocument, user);
        clickedJCas = getJCas(bModel, clickedAnnotationDocument);
    }
    long layerId = TypeUtil.getLayerId(arcType);
    AnnotationLayer layer = annotationService.getLayer(layerId);
    TypeAdapter adapter = annotationService.getAdapter(layer);
    int address = Integer.parseInt(fsArcaddress.split("\\.")[0]);
    AnnotationFS clickedFS = selectByAddr(clickedJCas, address);
    if (isCorefType(clickedFS)) {
        throw new AnnotationException(" Coreference Annotation not supported in curation");
    }
    MergeCas.addArcAnnotation(adapter, aJcas, addressOriginClicked, addressTargetClicked, fsArcaddress, clickedJCas, clickedFS);
    writeEditorCas(bModel, aJcas);
    int sentenceNumber = getSentenceNumber(clickedJCas, clickedFS.getBegin());
    bModel.setFocusUnitIndex(sentenceNumber);
    // Update timestamp
    bModel.getDocument().setSentenceAccessed(sentenceNumber);
    if (bModel.getPreferences().isScrollPage()) {
        Sentence sentence = selectSentenceAt(aJcas, bModel.getFirstVisibleUnitBegin(), bModel.getFirstVisibleUnitEnd());
        sentence = findWindowStartCenteringOnSelection(aJcas, sentence, clickedFS.getBegin(), bModel.getProject(), bModel.getDocument(), bModel.getPreferences().getWindowSize());
        bModel.setFirstVisibleUnit(sentence);
    }
}
Also used : User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 8 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class SuggestionViewPanel method addSuggestionColor.

/**
 * For each {@link ConfigurationSet}, where there are some differences in users annotation and
 * the curation annotation.
 */
private void addSuggestionColor(Project aProject, Mode aMode, Map<String, JCas> aCasMap, Map<String, Map<VID, AnnotationState>> aSuggestionColors, Collection<ConfigurationSet> aCfgSet, boolean aI, boolean aAgree) {
    for (ConfigurationSet cs : aCfgSet) {
        boolean use = false;
        for (String u : cs.getCasGroupIds()) {
            Map<VID, AnnotationState> colors = aSuggestionColors.get(u);
            if (colors == null) {
                colors = new HashMap<>();
                aSuggestionColors.put(u, colors);
            }
            for (Configuration c : cs.getConfigurations(u)) {
                FeatureStructure fs = c.getFs(u, aCasMap);
                AnnotationLayer layer = annotationService.getLayer(fs.getType().getName(), aProject);
                TypeAdapter typeAdapter = annotationService.getAdapter(layer);
                VID vid;
                // link FS
                if (c.getPosition().getFeature() != null) {
                    int fi = 0;
                    for (AnnotationFeature f : typeAdapter.listFeatures()) {
                        if (f.getName().equals(c.getPosition().getFeature())) {
                            break;
                        }
                        fi++;
                    }
                    vid = new VID(WebAnnoCasUtil.getAddr(fs), fi, c.getAID(u).index);
                } else {
                    vid = new VID(WebAnnoCasUtil.getAddr(fs));
                }
                if (aAgree) {
                    colors.put(vid, AnnotationState.AGREE);
                    continue;
                }
                // automation and correction projects
                if (!aMode.equals(Mode.CURATION) && !aAgree) {
                    if (cs.getCasGroupIds().size() == 2) {
                        colors.put(vid, AnnotationState.DO_NOT_USE);
                    } else {
                        colors.put(vid, AnnotationState.DISAGREE);
                    }
                    continue;
                }
                // this set agree with the curation annotation
                if (c.getCasGroupIds().contains(CURATION_USER)) {
                    use = true;
                } else {
                    use = false;
                }
                // this curation view
                if (u.equals(CURATION_USER)) {
                    continue;
                }
                if (aAgree) {
                    colors.put(vid, AnnotationState.AGREE);
                } else if (use) {
                    colors.put(vid, AnnotationState.USE);
                } else if (aI) {
                    colors.put(vid, AnnotationState.DISAGREE);
                } else if (!cs.getCasGroupIds().contains(CURATION_USER)) {
                    colors.put(vid, AnnotationState.DISAGREE);
                } else {
                    colors.put(vid, AnnotationState.DO_NOT_USE);
                }
            }
        }
    }
}
Also used : Configuration(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.Configuration) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) FeatureStructure(org.apache.uima.cas.FeatureStructure) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationState(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.AnnotationState) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 9 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class PreRenderer method render.

public void render(VDocument aResponse, AnnotatorState aState, JCas aJCas, List<AnnotationLayer> aLayers) {
    // Render (custom) layers
    for (AnnotationLayer layer : aLayers) {
        List<AnnotationFeature> features = annotationService.listAnnotationFeature(layer);
        TypeAdapter adapter = annotationService.getAdapter(layer);
        Renderer renderer = getRenderer(adapter);
        renderer.render(aJCas, features, aResponse, aState);
    }
}
Also used : TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 10 with TypeAdapter

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter in project webanno by webanno.

the class AnnotationDetailEditorPanel method getAttachedLinks.

private Set<AnnotationFS> getAttachedLinks(AnnotationFS aFs, AnnotationLayer aLayer) {
    CAS cas = aFs.getCAS();
    Set<AnnotationFS> attachedLinks = new HashSet<>();
    TypeAdapter adapter = annotationService.getAdapter(aLayer);
    if (adapter instanceof SpanAdapter) {
        for (AnnotationFeature linkFeature : annotationService.listAttachedLinkFeatures(aLayer)) {
            if (MultiValueMode.ARRAY.equals(linkFeature.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(linkFeature.getLinkMode())) {
                // Fetch slot hosts that could link to the current FS and check if any of
                // them actually links to the current FS
                Type linkType = CasUtil.getType(cas, linkFeature.getLayer().getName());
                for (AnnotationFS linkFS : CasUtil.select(cas, linkType)) {
                    List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature, linkFS);
                    for (int li = 0; li < links.size(); li++) {
                        LinkWithRoleModel link = links.get(li);
                        AnnotationFS linkTarget = selectByAddr(cas, AnnotationFS.class, link.targetAddr);
                        // our list of attached links.
                        if (isSame(linkTarget, aFs)) {
                            attachedLinks.add(linkFS);
                        }
                    }
                }
            }
        }
    }
    return attachedLinks;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) CAS(org.apache.uima.cas.CAS) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) HashSet(java.util.HashSet) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)12 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)9 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)7 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)7 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)6 JCas (org.apache.uima.jcas.JCas)4 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)3 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)3 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)3 CAS (org.apache.uima.cas.CAS)3 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)2 VID (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID)2 HashSet (java.util.HashSet)2 Type (org.apache.uima.cas.Type)2 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)1 ColoringStrategy (de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy)1 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)1 VAnnotationMarker (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VAnnotationMarker)1 VArc (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VArc)1 VComment (de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment)1