Search in sources :

Example 21 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState 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 22 with AnnotatorState

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

the class AnnotationPreferencesDialogContent method loadModel.

private Preferences loadModel(AnnotatorState bModel) {
    Preferences model = new Preferences();
    // Import current settings from the annotator
    model.windowSize = bModel.getPreferences().getWindowSize() < 1 ? 1 : bModel.getPreferences().getWindowSize();
    model.sidebarSize = bModel.getPreferences().getSidebarSize();
    model.fontZoom = bModel.getPreferences().getFontZoom();
    model.scrollPage = bModel.getPreferences().isScrollPage();
    model.colorPerLayer = bModel.getPreferences().getColorPerLayer();
    model.readonlyLayerColoringBehaviour = bModel.getPreferences().getReadonlyLayerColoringBehaviour();
    model.rememberLayer = bModel.getPreferences().isRememberLayer();
    String editorId = bModel.getPreferences().getEditor();
    AnnotationEditorFactory editorFactory = annotationEditorRegistry.getEditorFactory(editorId);
    if (editorFactory == null) {
        editorFactory = annotationEditorRegistry.getDefaultEditorFactory();
    }
    model.editor = Pair.of(editorFactory.getBeanName(), editorFactory.getDisplayName());
    model.annotationLayers = annotationService.listAnnotationLayer(bModel.getProject()).stream().filter(layer -> layer.isEnabled()).filter(layer -> !Token.class.getName().equals(layer.getName())).filter(layer -> !(layer.getType().equals(WebAnnoConst.CHAIN_TYPE) && (bModel.getMode().equals(Mode.CORRECTION) || // disable coreference annotation for correction/curation pages
    bModel.getMode().equals(Mode.CURATION)))).collect(Collectors.toList());
    return model;
}
Also used : Form(org.apache.wicket.markup.html.form.Form) ReadonlyColoringBehaviour(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy.ReadonlyColoringBehaviour) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) ProjectService(de.tudarmstadt.ukp.clarin.webanno.api.ProjectService) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) LoggerFactory(org.slf4j.LoggerFactory) Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) CheckBox(org.apache.wicket.markup.html.form.CheckBox) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ArrayList(java.util.ArrayList) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Pair(org.apache.commons.lang3.tuple.Pair) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) Map(java.util.Map) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) PreferencesUtil(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.PreferencesUtil) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) IModel(org.apache.wicket.model.IModel) EnumSet(java.util.EnumSet) ListView(org.apache.wicket.markup.html.list.ListView) Label(org.apache.wicket.markup.html.basic.Label) NumberTextField(org.apache.wicket.markup.html.form.NumberTextField) Logger(org.slf4j.Logger) ListItem(org.apache.wicket.markup.html.list.ListItem) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) Model(org.apache.wicket.model.Model) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) IOException(java.io.IOException) LambdaAjaxButton(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton) Collectors(java.util.stream.Collectors) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) Serializable(java.io.Serializable) Panel(org.apache.wicket.markup.html.panel.Panel) List(java.util.List) AnnotationEditorFactory(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorFactory) LambdaAjaxLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxLink) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ColoringStrategyType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategy.ColoringStrategyType) AnnotationEditorRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorRegistry) AnnotationEditorFactory(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorFactory)

Example 23 with AnnotatorState

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

the class AnnotationSidebar_ImplBase method actionShowSelectedDocument.

/**
 * Show the next document if it exists, starting in a certain begin offset
 */
protected void actionShowSelectedDocument(AjaxRequestTarget aTarget, SourceDocument aDocument, int aBeginOffset) throws IOException {
    annotationPage.actionShowSelectedDocument(aTarget, aDocument);
    AnnotatorState state = getModelObject();
    JCas jCas = annotationPage.getEditorCas();
    int sentenceNumber = WebAnnoCasUtil.getSentenceNumber(jCas, aBeginOffset);
    Sentence sentence = WebAnnoCasUtil.getSentence(jCas, aBeginOffset);
    annotationPage.getGotoPageTextField().setModelObject(sentenceNumber);
    state.setFirstVisibleUnit(sentence);
    state.setFocusUnitIndex(sentenceNumber);
    annotationPage.actionRefreshDocument(aTarget);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 24 with AnnotatorState

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

the class BratAnnotationEditor method actionSpan.

private SpanAnnotationResponse actionSpan(AjaxRequestTarget aTarget, IRequestParameters request, JCas jCas, VID paramId) throws IOException, AnnotationException {
    Offsets offsets = getOffsetsFromRequest(request, jCas, paramId);
    AnnotatorState state = getModelObject();
    Selection selection = state.getSelection();
    if (state.isSlotArmed()) {
        // When filling a slot, the current selection is *NOT* changed. The
        // Span annotation which owns the slot that is being filled remains
        // selected!
        getActionHandler().actionFillSlot(aTarget, jCas, offsets.getBegin(), offsets.getEnd(), paramId);
    } else {
        if (!paramId.isSynthetic()) {
            selection.selectSpan(paramId, jCas, offsets.getBegin(), offsets.getEnd());
            if (selection.getAnnotation().isNotSet()) {
                // Create new annotation
                getActionHandler().actionCreateOrUpdate(aTarget, jCas);
            } else {
                getActionHandler().actionSelect(aTarget, jCas);
            }
        }
    }
    return new SpanAnnotationResponse();
}
Also used : SpanAnnotationResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.SpanAnnotationResponse) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) Offsets(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.Offsets)

Example 25 with AnnotatorState

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

Aggregations

AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)84 JCas (org.apache.uima.jcas.JCas)37 IOException (java.io.IOException)26 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)23 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 UIMAException (org.apache.uima.UIMAException)20 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)16 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)16 ArrayList (java.util.ArrayList)16 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)14 List (java.util.List)13 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)12 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)9 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)9 SuggestionBuilder (de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder)9 Map (java.util.Map)9 NoResultException (javax.persistence.NoResultException)9 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)9 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)8 Selection (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection)8