Search in sources :

Example 51 with AnnotationLayer

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

the class AnnotationPreferencesDialogContent method createLayerContainer.

private ListView<AnnotationLayer> createLayerContainer() {
    return new ListView<AnnotationLayer>("annotationLayers") {

        private static final long serialVersionUID = -4040731191748923013L;

        @Override
        protected void populateItem(ListItem<AnnotationLayer> item) {
            // add checkbox
            // get initial state
            AnnotationPreference pref = stateModel.getObject().getPreferences();
            List<Long> hiddenLayerIds = pref.getHiddenAnnotationLayerIds();
            boolean isPreferredToShow = !hiddenLayerIds.contains(item.getModelObject().getId());
            CheckBox layer_cb = new CheckBox("annotationLayerActive", Model.of(isPreferredToShow));
            layer_cb.add(new AjaxEventBehavior("change") {

                private static final long serialVersionUID = 8378489004897115519L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    // check state & live update preferences
                    List<Long> hiddenLayerIds = stateModel.getObject().getPreferences().getHiddenAnnotationLayerIds();
                    // get and switch state of checkbox
                    boolean isPreferredToShow = layer_cb.getModelObject();
                    layer_cb.setModelObject(!isPreferredToShow);
                    // live update preferences
                    if (isPreferredToShow) {
                        // prefer to deactivate layer
                        hiddenLayerIds.add(item.getModelObject().getId());
                    } else {
                        // prefer to activate layer
                        hiddenLayerIds.remove(item.getModelObject().getId());
                    }
                }
            });
            item.add(layer_cb);
            // add coloring strategy combobox
            ChoiceRenderer<ColoringStrategyType> choiceRenderer = new ChoiceRenderer<>("descriptiveName");
            List<ColoringStrategyType> choices = new ArrayList<ColoringStrategyType>(EnumSet.allOf(ColoringStrategyType.class));
            Model<ColoringStrategyType> initialSelected = Model.of(form.getModelObject().colorPerLayer.get(item.getModelObject().getId()));
            DropDownChoice<ColoringStrategyType> layer_color = new DropDownChoice<ColoringStrategyType>("layercoloring", initialSelected, choices, choiceRenderer);
            layer_color.add(new AjaxFormComponentUpdatingBehavior("change") {

                private static final long serialVersionUID = 1060397773470276585L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    AnnotationLayer current_layer = item.getModelObject();
                    ColoringStrategyType selectedColor = layer_color.getModelObject();
                    form.getModelObject().colorPerLayer.put(current_layer.getId(), selectedColor);
                }
            });
            item.add(layer_color);
            // add label
            Label lbl = new Label("annotationLayerDesc", item.getModelObject().getUiName());
            item.add(lbl);
        }
    };
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) CheckBox(org.apache.wicket.markup.html.form.CheckBox) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) ColoringStrategyType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy.ColoringStrategyType)

Example 52 with AnnotationLayer

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

the class CopyAnnotationTest method setup.

@Before
public void setup() {
    project = new Project();
    tokenLayer = new AnnotationLayer(Token.class.getName(), "Token", SPAN_TYPE, null, true);
    tokenPosFeature = new AnnotationFeature();
    tokenPosFeature.setName("pos");
    tokenPosFeature.setEnabled(true);
    tokenPosFeature.setType(POS.class.getName());
    tokenPosFeature.setUiName("pos");
    tokenPosFeature.setLayer(tokenLayer);
    tokenPosFeature.setProject(project);
    tokenPosFeature.setVisible(true);
    posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, project, true);
    posLayer.setAttachType(tokenLayer);
    posLayer.setAttachFeature(tokenPosFeature);
    posFeature = new AnnotationFeature();
    posFeature.setName("PosValue");
    posFeature.setEnabled(true);
    posFeature.setType(CAS.TYPE_NAME_STRING);
    posFeature.setUiName("PosValue");
    posFeature.setLayer(posLayer);
    posFeature.setProject(project);
    posFeature.setVisible(true);
    slotLayer = new AnnotationLayer(DiffUtils.HOST_TYPE, DiffUtils.HOST_TYPE, SPAN_TYPE, project, false);
    slotFeature = new AnnotationFeature();
    slotFeature.setName("links");
    slotFeature.setEnabled(true);
    slotFeature.setType(Token.class.getName());
    slotFeature.setLinkMode(LinkMode.WITH_ROLE);
    slotFeature.setUiName("f1");
    slotFeature.setLayer(slotLayer);
    slotFeature.setProject(project);
    slotFeature.setVisible(true);
    stringFeature = new AnnotationFeature();
    stringFeature.setName("f1");
    stringFeature.setEnabled(true);
    stringFeature.setType(CAS.TYPE_NAME_STRING);
    stringFeature.setUiName("f1");
    stringFeature.setLayer(slotLayer);
    stringFeature.setProject(project);
    stringFeature.setVisible(true);
    annotationSchemaService = new MockUp<AnnotationSchemaService>() {

        @Mock
        List<AnnotationFeature> listAnnotationFeature(AnnotationLayer type) {
            if (type.getName().equals(POS.class.getName())) {
                return asList(posFeature);
            }
            if (type.getName().equals(DiffUtils.HOST_TYPE)) {
                return asList(slotFeature, stringFeature);
            }
            throw new IllegalStateException("Unknown layer type: " + type.getName());
        }

        @Mock
        TypeAdapter getAdapter(AnnotationLayer aLayer) {
            return AnnotationSchemaServiceImpl.getAdapter(annotationSchemaService, featureSupportRegistry, null, aLayer);
        }
    }.getMockInstance();
    featureSupportRegistry = new FeatureSupportRegistryImpl(asList(new PrimitiveUimaFeatureSupport(), new SlotFeatureSupport()));
    featureSupportRegistry.init();
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) SlotFeatureSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.SlotFeatureSupport) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) FeatureSupportRegistryImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistryImpl) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) MockUp(mockit.MockUp) PrimitiveUimaFeatureSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.PrimitiveUimaFeatureSupport) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Before(org.junit.Before)

Example 53 with AnnotationLayer

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

the class SuggestionViewPanel method render.

private String render(JCas aJcas, AnnotatorState aBratAnnotatorModel, ColoringStrategy aCurationColoringStrategy) throws IOException {
    List<AnnotationLayer> layersToRender = new ArrayList<>();
    for (AnnotationLayer layer : aBratAnnotatorModel.getAnnotationLayers()) {
        boolean isSegmentationLayer = layer.getName().equals(Token.class.getName()) || layer.getName().equals(Sentence.class.getName());
        boolean isUnsupportedLayer = layer.getType().equals(CHAIN_TYPE);
        if (layer.isEnabled() && !isSegmentationLayer && !isUnsupportedLayer) {
            layersToRender.add(layer);
        }
    }
    VDocument vdoc = new VDocument();
    preRenderer.render(vdoc, aBratAnnotatorModel, aJcas, layersToRender);
    GetDocumentResponse response = new GetDocumentResponse();
    BratRenderer.render(response, aBratAnnotatorModel, vdoc, aJcas, annotationService, aCurationColoringStrategy);
    return JSONUtil.toInterpretableJsonString(response);
}
Also used : GetDocumentResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.GetDocumentResponse) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 54 with AnnotationLayer

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

the class ProjectLayersPanel method onModelChanged.

@Override
protected void onModelChanged() {
    super.onModelChanged();
    layerSelectionForm.getModelObject().layerSelection = null;
    featureSelectionForm.getModelObject().feature = null;
    layerDetailForm.setModelObject(new AnnotationLayer());
    layerDetailForm.setVisible(false);
    featureSelectionForm.setVisible(false);
    featureDetailForm.setModelObject(new AnnotationFeature());
    featureDetailForm.setVisible(false);
}
Also used : AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 55 with AnnotationLayer

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

the class CasDiff2 method getAdapters.

public static List<DiffAdapter> getAdapters(AnnotationSchemaService annotationService, Project project) {
    List<DiffAdapter> adapters = new ArrayList<>();
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(project)) {
        Set<String> labelFeatures = new LinkedHashSet<>();
        for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
            if (!f.isEnabled()) {
                continue;
            }
            // Link features are treated separately from primitive label features
            if (!LinkMode.NONE.equals(f.getLinkMode())) {
                continue;
            }
            labelFeatures.add(f.getName());
        }
        DiffAdapter_ImplBase adpt;
        switch(layer.getType()) {
            case SPAN_TYPE:
                {
                    adpt = new SpanDiffAdapter(layer.getName(), labelFeatures);
                    break;
                }
            case RELATION_TYPE:
                {
                    ArcAdapter typeAdpt = (ArcAdapter) annotationService.getAdapter(layer);
                    adpt = new ArcDiffAdapter(layer.getName(), typeAdpt.getSourceFeatureName(), typeAdpt.getTargetFeatureName(), labelFeatures);
                    break;
                }
            case CHAIN_TYPE:
                // FIXME Currently, these are ignored.
                continue;
            default:
                throw new IllegalStateException("Unknown layer type [" + layer.getType() + "]");
        }
        adapters.add(adpt);
        for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
            if (!f.isEnabled()) {
                continue;
            }
            switch(f.getLinkMode()) {
                case NONE:
                    // Nothing to do here
                    break;
                case SIMPLE:
                    adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), null);
                    break;
                case WITH_ROLE:
                    adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), f.getLinkTypeTargetFeatureName());
                    break;
                default:
                    throw new IllegalStateException("Unknown link mode [" + f.getLinkMode() + "]");
            }
            labelFeatures.add(f.getName());
        }
    }
    return adapters;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) 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