Search in sources :

Example 1 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class AnnotationDetailEditorPanel method internalCommitAnnotation.

private void internalCommitAnnotation(AjaxRequestTarget aTarget, JCas aJCas) throws AnnotationException, IOException {
    AnnotatorState state = getModelObject();
    LOG.trace("actionAnnotate() selectedLayer: {}", state.getSelectedAnnotationLayer().getUiName());
    LOG.trace("actionAnnotate() defaultLayer: {}", state.getDefaultAnnotationLayer().getUiName());
    if (state.getSelectedAnnotationLayer() == null) {
        error("No layer is selected. First select a layer.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    if (state.getSelectedAnnotationLayer().isReadonly()) {
        error("Layer is not editable.");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    // Verify if input is valid according to tagset
    LOG.trace("actionAnnotate() verifying feature values in editors");
    List<FeatureState> featureStates = getModelObject().getFeatureStates();
    for (FeatureState featureState : featureStates) {
        AnnotationFeature feature = featureState.feature;
        if (CAS.TYPE_NAME_STRING.equals(feature.getType())) {
            String value = (String) featureState.value;
            // Check if tag is necessary, set, and correct
            if (value != null && feature.getTagset() != null && !feature.getTagset().isCreateTag() && !annotationService.existsTag(value, feature.getTagset())) {
                error("[" + value + "] is not in the tag list. Please choose from the existing tags");
                return;
            }
        }
    }
    // #186 - After filling a slot, the annotation detail panel is not updated
    aTarget.add(annotationFeatureForm.getFeatureEditorPanel());
    TypeAdapter adapter = annotationService.getAdapter(state.getSelectedAnnotationLayer());
    // If this is an annotation creation action, create the annotation
    if (state.getSelection().getAnnotation().isNotSet()) {
        // Load the feature editors with the remembered values (if any)
        loadFeatureEditorModels(aJCas, aTarget);
        createNewAnnotation(aTarget, adapter, aJCas);
    }
    // Update the features of the selected annotation from the values presently in the
    // feature editors
    writeFeatureEditorModelsToCas(adapter, aJCas);
    // Update progress information
    LOG.trace("actionAnnotate() updating progress information");
    int sentenceNumber = getSentenceNumber(aJCas, state.getSelection().getBegin());
    state.setFocusUnitIndex(sentenceNumber);
    state.getDocument().setSentenceAccessed(sentenceNumber);
    // persist changes
    writeEditorCas(aJCas);
    // Remember the current feature values independently for spans and relations
    LOG.trace("actionAnnotate() remembering feature editor values");
    state.rememberFeatures();
    // Loading feature editor values from CAS
    loadFeatureEditorModels(aJCas, aTarget);
    // onAnnotate callback
    LOG.trace("onAnnotate()");
    onAnnotate(aTarget);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 2 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class AnnotationDetailEditorPanel method writeFeatureEditorModelsToCas.

private void writeFeatureEditorModelsToCas(TypeAdapter aAdapter, JCas aJCas) throws IOException {
    AnnotatorState state = getModelObject();
    List<FeatureState> featureStates = state.getFeatureStates();
    LOG.trace("writeFeatureEditorModelsToCas()");
    List<AnnotationFeature> features = new ArrayList<>();
    for (FeatureState featureState : featureStates) {
        features.add(featureState.feature);
        // For string features with extensible tagsets, extend the tagset
        if (CAS.TYPE_NAME_STRING.equals(featureState.feature.getType())) {
            String value = (String) featureState.value;
            if (value != null && featureState.feature.getTagset() != null && featureState.feature.getTagset().isCreateTag() && !annotationService.existsTag(value, featureState.feature.getTagset())) {
                Tag selectedTag = new Tag();
                selectedTag.setName(value);
                selectedTag.setTagSet(featureState.feature.getTagset());
                annotationService.createTag(selectedTag);
            }
        }
        LOG.trace("writeFeatureEditorModelsToCas() " + featureState.feature.getUiName() + " = " + featureState.value);
        aAdapter.setFeatureValue(state, aJCas, state.getSelection().getAnnotation().getId(), featureState.feature, featureState.value);
    }
    // Generate info message
    if (state.getSelection().getAnnotation().isSet()) {
        String bratLabelText = TypeUtil.getUiLabelText(aAdapter, selectByAddr(aJCas, state.getSelection().getAnnotation().getId()), features);
        info(generateMessage(state.getSelectedAnnotationLayer(), bratLabelText, false));
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) ArrayList(java.util.ArrayList) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 3 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class AnnotationFeatureForm method getBindTags.

Map<String, String> getBindTags() {
    AnnotationFeature f = annotationService.listAnnotationFeature(getModelObject().getSelectedAnnotationLayer()).get(0);
    TagSet tagSet = f.getTagset();
    Map<Character, String> tagNames = new LinkedHashMap<>();
    Map<String, String> bindTag2Key = new LinkedHashMap<>();
    for (Tag tag : annotationService.listTags(tagSet)) {
        if (tagNames.containsKey(tag.getName().toLowerCase().charAt(0))) {
            String oldBinding = tagNames.get(tag.getName().toLowerCase().charAt(0));
            String newBinding = oldBinding + tag.getName().toLowerCase().charAt(0);
            tagNames.put(tag.getName().toLowerCase().charAt(0), newBinding);
            bindTag2Key.put(newBinding, tag.getName());
        } else {
            tagNames.put(tag.getName().toLowerCase().charAt(0), tag.getName().toLowerCase().substring(0, 1));
            bindTag2Key.put(tag.getName().toLowerCase().substring(0, 1), tag.getName());
        }
    }
    return bindTag2Key;
}
Also used : TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature 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 5 with AnnotationFeature

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.

the class BratAnnotationEditor method actionDoAction.

private Object actionDoAction(AjaxRequestTarget aTarget, IRequestParameters request, JCas jCas, VID paramId) throws IOException {
    StringValue layerParam = request.getParameterValue(PARAM_SPAN_TYPE);
    if (!layerParam.isEmpty()) {
        long layerId = Long.parseLong(layerParam.beforeFirst('_'));
        AnnotationLayer layer = annotationService.getLayer(layerId);
        if (!StringUtils.isEmpty(layer.getOnClickJavascriptAction())) {
            // parse the action
            List<AnnotationFeature> features = annotationService.listAnnotationFeature(layer);
            AnnotationFS anno = WebAnnoCasUtil.selectByAddr(jCas, paramId.getId());
            Map<String, Object> functionParams = OnClickActionParser.parse(layer, features, getModelObject().getDocument(), anno);
            // define anonymous function, fill the body and immediately execute
            String js = String.format("(function ($PARAM){ %s })(%s)", layer.getOnClickJavascriptAction(), JSONUtil.toJsonString(functionParams));
            aTarget.appendJavaScript(js);
        }
    }
    return null;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) StringValue(org.apache.wicket.util.string.StringValue) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)73 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)34 Feature (org.apache.uima.cas.Feature)20 ArrayList (java.util.ArrayList)16 Type (org.apache.uima.cas.Type)16 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)15 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 JCas (org.apache.uima.jcas.JCas)10 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)9 File (java.io.File)9 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)8 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)6 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)6 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)6 List (java.util.List)6 FeatureStructure (org.apache.uima.cas.FeatureStructure)6 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)5 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)5 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)5