Search in sources :

Example 6 with AnnotationLayer

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

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

the class BratAnnotationEditor method getLayersToRender.

private List<AnnotationLayer> getLayersToRender() {
    AnnotatorState state = getModelObject();
    List<AnnotationLayer> layersToRender = new ArrayList<>();
    for (AnnotationLayer layer : state.getAnnotationLayers()) {
        boolean isSegmentationLayer = layer.getName().equals(Token.class.getName()) || layer.getName().equals(Sentence.class.getName());
        boolean isUnsupportedLayer = layer.getType().equals(CHAIN_TYPE) && (state.getMode().equals(Mode.AUTOMATION) || state.getMode().equals(Mode.CORRECTION) || state.getMode().equals(Mode.CURATION));
        if (layer.isEnabled() && !isSegmentationLayer && !isUnsupportedLayer) {
            layersToRender.add(layer);
        }
    }
    return layersToRender;
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 8 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer 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)

Example 9 with AnnotationLayer

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

the class OrthographyLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    AnnotationLayer orthography = new AnnotationLayer(SofaChangeAnnotation.class.getName(), "Orthography Correction", SPAN_TYPE, aProject, true);
    orthography.setAllowStacking(false);
    orthography.setMultipleTokens(false);
    orthography.setLockToTokenOffset(true);
    annotationSchemaService.createLayer(orthography);
    AnnotationFeature correction = new AnnotationFeature();
    correction.setDescription("Correct this token using the specified operation.");
    correction.setName("value");
    correction.setType(CAS.TYPE_NAME_STRING);
    correction.setProject(aProject);
    correction.setUiName("Correction");
    correction.setLayer(orthography);
    annotationSchemaService.createFeature(correction);
    TagSet operationTagset = annotationSchemaService.createTagSet("operation to be done with specified in tokenIDs token/tokens in order to correct", "Operation", "en", new String[] { "replace", "insert_before", "insert_after", "delete" }, new String[] { "replace", "insert before", "insert after", "delete" }, aProject);
    AnnotationFeature operation = new AnnotationFeature();
    operation.setDescription("An operation taken to change this token.");
    operation.setName("operation");
    operation.setType(CAS.TYPE_NAME_STRING);
    operation.setProject(aProject);
    operation.setUiName("Operation");
    operation.setLayer(orthography);
    operation.setVisible(false);
    operation.setTagset(operationTagset);
    annotationSchemaService.createFeature(operation);
}
Also used : SofaChangeAnnotation(de.tudarmstadt.ukp.dkpro.core.api.transform.type.SofaChangeAnnotation) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 10 with AnnotationLayer

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

the class PartOfSpeechLayerInitializer method configure.

@Override
public void configure(Project aProject) throws IOException {
    TagSet posTagSet = JsonImportUtil.importTagSetFromJson(aProject, new ClassPathResource("/tagsets/mul-pos-ud.json").getInputStream(), annotationSchemaService);
    AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), aProject);
    AnnotationLayer posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, aProject, true);
    AnnotationFeature tokenPosFeature = new AnnotationFeature(aProject, tokenLayer, "pos", "pos", POS.class.getName());
    annotationSchemaService.createFeature(tokenPosFeature);
    posLayer.setAttachType(tokenLayer);
    posLayer.setAttachFeature(tokenPosFeature);
    annotationSchemaService.createLayer(posLayer);
    annotationSchemaService.createFeature(new AnnotationFeature(aProject, posLayer, "PosValue", "PosValue", CAS.TYPE_NAME_STRING, "Part-of-speech tag", posTagSet));
}
Also used : POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ClassPathResource(org.springframework.core.io.ClassPathResource) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)67 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)35 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 ArrayList (java.util.ArrayList)14 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)13 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 LogMessage (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage)8 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)7 Type (org.apache.uima.cas.Type)7 JCas (org.apache.uima.jcas.JCas)6 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)5 FeatureStructure (org.apache.uima.cas.FeatureStructure)5 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)5 Test (org.junit.Test)5 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)4 HashMap (java.util.HashMap)4 TypeSystemDescriptionFactory.createTypeSystemDescription (org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription)4 SoftAssertions (org.assertj.core.api.SoftAssertions)4 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)3