Search in sources :

Example 1 with AnnotationException

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException in project webanno by webanno.

the class AnnotationDetailEditorPanel method loadFeatureEditorModels.

public void loadFeatureEditorModels(AjaxRequestTarget aTarget) throws AnnotationException {
    try {
        JCas annotationCas = getEditorCas();
        loadFeatureEditorModels(annotationCas, aTarget);
    } catch (AnnotationException e) {
        throw e;
    } catch (Exception e) {
        throw new AnnotationException(e);
    }
}
Also used : JCas(org.apache.uima.jcas.JCas) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) NoResultException(javax.persistence.NoResultException) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 2 with AnnotationException

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException in project webanno by webanno.

the class AnnotationDetailEditorPanel method createNewChainElement.

private void createNewChainElement(ChainAdapter aAdapter, JCas aJCas) throws AnnotationException {
    LOG.trace("createNewChainElement()");
    AnnotatorState state = getModelObject();
    Selection selection = state.getSelection();
    List<FeatureState> featureStates = state.getFeatureStates();
    for (FeatureState featureState : featureStates) {
        Serializable spanValue = aAdapter.getSpan(aJCas, selection.getBegin(), selection.getEnd(), featureState.feature, null);
        if (spanValue != null) {
            // allow modification for forward annotation
            if (state.isForwardAnnotation()) {
                featureState.value = spanValue;
                featureStates.get(0).value = spanValue;
                String selectedTag = annotationFeatureForm.getBindTags().entrySet().stream().filter(e -> e.getValue().equals(spanValue)).map(Map.Entry::getKey).findFirst().orElse(null);
                annotationFeatureForm.setSelectedTag(selectedTag);
            }
        }
    }
    selection.setAnnotation(new VID(aAdapter.addSpan(aJCas, selection.getBegin(), selection.getEnd())));
    selection.setText(aJCas.getDocumentText().substring(selection.getBegin(), selection.getEnd()));
}
Also used : TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) WebAnnoCasUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) LinkMode(de.tudarmstadt.ukp.clarin.webanno.model.LinkMode) StringUtils(org.apache.commons.lang3.StringUtils) Type(org.apache.uima.cas.Type) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AnnotationEditorExtensionRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorExtensionRegistry) Map(java.util.Map) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) WebAnnoCasUtil.isSame(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.isSame) FeatureStructure(org.apache.uima.cas.FeatureStructure) IModel(org.apache.wicket.model.IModel) WebAnnoCasUtil.getSentenceNumber(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getSentenceNumber) UIMAException(org.apache.uima.UIMAException) JCas(org.apache.uima.jcas.JCas) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) MultiValueMode(de.tudarmstadt.ukp.clarin.webanno.model.MultiValueMode) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) Set(java.util.Set) Component(org.apache.wicket.Component) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) IFeedback(org.apache.wicket.feedback.IFeedback) Serializable(java.io.Serializable) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) Objects(java.util.Objects) List(java.util.List) TypeUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) ProjectService(de.tudarmstadt.ukp.clarin.webanno.api.ProjectService) SourceDocumentState(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) WebAnnoCasUtil.selectByAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectByAddr) CAS(org.apache.uima.cas.CAS) Feature(org.apache.uima.cas.Feature) Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) WebAnnoCasUtil.setFeature(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) AjaxFormValidatingBehavior(org.apache.wicket.ajax.form.AjaxFormValidatingBehavior) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) WebAnnoCasUtil.getAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getAddr) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) WebAnnoCasUtil.selectAt(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectAt) CurationDocumentService(de.tudarmstadt.ukp.clarin.webanno.curation.storage.CurationDocumentService) AnnotationActionHandler(de.tudarmstadt.ukp.clarin.webanno.api.annotation.action.AnnotationActionHandler) IOException(java.io.IOException) CasUtil(org.apache.uima.fit.util.CasUtil) Panel(org.apache.wicket.markup.html.panel.Panel) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) ChainAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ChainAdapter) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) RulesIndicator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.RulesIndicator) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) Serializable(java.io.Serializable) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)

Example 3 with AnnotationException

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException in project webanno by webanno.

the class AnnotationDetailEditorPanel method actionFillSlot.

@Override
public void actionFillSlot(AjaxRequestTarget aTarget, JCas aJCas, int aBegin, int aEnd, VID aVID) throws AnnotationException, IOException {
    assert aJCas != null;
    AnnotatorState state = getModelObject();
    // If this method is called when no slot is armed, it must be a bug!
    if (!state.isSlotArmed()) {
        throw new IllegalStateException("No slot is armed.");
    }
    // Fill slot with new annotation (only works if a concrete type is set for the link feature!
    int id;
    if (aVID.isNotSet()) {
        if (!CAS.TYPE_NAME_ANNOTATION.equals(state.getArmedFeature().getType())) {
            SpanAdapter adapter = (SpanAdapter) annotationService.getAdapter(annotationService.getLayer(state.getArmedFeature().getType(), state.getProject()));
            id = adapter.add(state, aJCas, aBegin, aEnd);
        } else {
            throw new AnnotationException("Unable to create annotation of type [" + CAS.TYPE_NAME_ANNOTATION + "]. Please click an annotation in stead of selecting new text.");
        }
    } else {
        id = aVID.getId();
    }
    // Fill the annotation into the slow
    try {
        setSlot(aTarget, aJCas, id);
    } catch (Exception e) {
        handleException(this, aTarget, e);
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) NoResultException(javax.persistence.NoResultException) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 4 with AnnotationException

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException in project webanno by webanno.

the class AnnotationDetailEditorPanel method createNewSpanAnnotation.

private void createNewSpanAnnotation(AjaxRequestTarget aTarget, SpanAdapter aAdapter, JCas aJCas) throws IOException, AnnotationException {
    LOG.trace("createNewSpanAnnotation()");
    AnnotatorState state = getModelObject();
    Selection selection = state.getSelection();
    List<FeatureState> featureStates = state.getFeatureStates();
    if ((aAdapter.isAllowMultipleToken() || aAdapter.isLockToTokenOffsets()) && selection.getBegin() == selection.getEnd()) {
        throw new AnnotationException("Cannot create zero-width annotation on layers that lock to token boundaries.");
    }
    for (FeatureState featureState : featureStates) {
        Serializable spanValue = aAdapter.getSpan(aJCas, selection.getBegin(), selection.getEnd(), featureState.feature, null);
        if (spanValue != null) {
            // allow modification for forward annotation
            if (state.isForwardAnnotation()) {
                featureState.value = spanValue;
                featureStates.get(0).value = spanValue;
                String selectedTag = annotationFeatureForm.getBindTags().entrySet().stream().filter(e -> e.getValue().equals(spanValue)).map(Map.Entry::getKey).findFirst().orElse(null);
                annotationFeatureForm.setSelectedTag(selectedTag);
            } else {
                actionClear(aTarget);
                throw new AnnotationException("Cannot create another annotation of layer [" + state.getSelectedAnnotationLayer().getUiName() + "] at this" + " location - stacking is not enabled for this layer.");
            }
        }
    }
    int annoId = aAdapter.add(state, aJCas, selection.getBegin(), selection.getEnd());
    AnnotationFS annoFs = WebAnnoCasUtil.selectByAddr(aJCas, annoId);
    selection.selectSpan(new VID(annoId), aJCas, annoFs.getBegin(), annoFs.getEnd());
}
Also used : TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) WebAnnoCasUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) LinkMode(de.tudarmstadt.ukp.clarin.webanno.model.LinkMode) StringUtils(org.apache.commons.lang3.StringUtils) Type(org.apache.uima.cas.Type) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AnnotationEditorExtensionRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorExtensionRegistry) Map(java.util.Map) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) WebAnnoCasUtil.isSame(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.isSame) FeatureStructure(org.apache.uima.cas.FeatureStructure) IModel(org.apache.wicket.model.IModel) WebAnnoCasUtil.getSentenceNumber(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getSentenceNumber) UIMAException(org.apache.uima.UIMAException) JCas(org.apache.uima.jcas.JCas) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) MultiValueMode(de.tudarmstadt.ukp.clarin.webanno.model.MultiValueMode) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) Set(java.util.Set) Component(org.apache.wicket.Component) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) IFeedback(org.apache.wicket.feedback.IFeedback) Serializable(java.io.Serializable) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) Objects(java.util.Objects) List(java.util.List) TypeUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.TypeUtil) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) ProjectService(de.tudarmstadt.ukp.clarin.webanno.api.ProjectService) SourceDocumentState(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) WebAnnoCasUtil.selectByAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectByAddr) CAS(org.apache.uima.cas.CAS) Feature(org.apache.uima.cas.Feature) Mode(de.tudarmstadt.ukp.clarin.webanno.model.Mode) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) WebAnnoCasUtil.setFeature(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) AjaxFormValidatingBehavior(org.apache.wicket.ajax.form.AjaxFormValidatingBehavior) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) WebAnnoCasUtil.getAddr(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getAddr) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) WebAnnoCasUtil.selectAt(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectAt) CurationDocumentService(de.tudarmstadt.ukp.clarin.webanno.curation.storage.CurationDocumentService) AnnotationActionHandler(de.tudarmstadt.ukp.clarin.webanno.api.annotation.action.AnnotationActionHandler) IOException(java.io.IOException) CasUtil(org.apache.uima.fit.util.CasUtil) Panel(org.apache.wicket.markup.html.panel.Panel) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) ChainAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ChainAdapter) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) RulesIndicator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.RulesIndicator) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Serializable(java.io.Serializable) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)

Example 5 with AnnotationException

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException in project webanno by webanno.

the class AnnotationDetailEditorPanel method actionCreateForward.

private void actionCreateForward(AjaxRequestTarget aTarget, JCas aJCas, boolean aIsForwarded) throws IOException, AnnotationException {
    LOG.trace("actionForward(isForwarded: {})", aIsForwarded);
    if (isAnnotationFinished()) {
        throw new AnnotationException("This document is already closed. Please ask your " + "project manager to re-open it via the Monitoring page");
    }
    AnnotatorState state = getModelObject();
    // Re-set the selected layer from the drop-down since it might have changed if we
    // have previously created a relation annotation
    state.setSelectedAnnotationLayer(annotationFeatureForm.getLayerSelector().getModelObject());
    internalCommitAnnotation(aTarget, aJCas);
    if (!aIsForwarded) {
        if (state.getSelection().getEnd() >= state.getWindowEndOffset()) {
            autoScroll(aJCas, true);
        }
        List<FeatureState> featureStates = getModelObject().getFeatureStates();
        if (featureStates.get(0).value != null) {
            LOG.info("BEGIN auto-forward annotation for tagset-based annotation");
            AnnotationFS nextToken = WebAnnoCasUtil.getNextToken(aJCas, state.getSelection().getBegin(), state.getSelection().getEnd());
            if (nextToken != null) {
                if (getModelObject().getWindowEndOffset() > nextToken.getBegin()) {
                    state.getSelection().selectSpan(aJCas, nextToken.getBegin(), nextToken.getEnd());
                    actionCreateForward(aTarget, aJCas, true);
                }
            }
            LOG.info("END auto-forward annotation for tagset-based annotation");
        } else {
            LOG.info("BEGIN auto-forward annotation for free-text annotation");
            // remove the entire annotation.
            if (featureStates.get(0).value == null) {
                TypeAdapter adapter = annotationService.getAdapter(state.getSelectedAnnotationLayer());
                AnnotationFS fs = selectByAddr(aJCas, state.getSelection().getAnnotation().getId());
                deleteAnnotation(aJCas, state, fs, featureStates.get(0).feature.getLayer(), adapter);
            }
            AnnotationFS nextToken = WebAnnoCasUtil.getNextToken(aJCas, state.getSelection().getBegin(), state.getSelection().getEnd());
            if (nextToken != null) {
                if (getModelObject().getWindowEndOffset() > nextToken.getBegin()) {
                    state.getSelection().selectSpan(aJCas, nextToken.getBegin(), nextToken.getEnd());
                    actionCreateForward(aTarget, aJCas, true);
                }
            }
            LOG.info("END auto-forward annotation for free-text annotation");
        }
        LOG.trace("onAutoForward()");
        onAutoForward(aTarget);
    }
    aTarget.add(annotationFeatureForm);
    internalCompleteAnnotation(aTarget, aJCas);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)

Aggregations

AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)14 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)11 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)7 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)6 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)6 IOException (java.io.IOException)6 UIMAException (org.apache.uima.UIMAException)6 JCas (org.apache.uima.jcas.JCas)6 NoResultException (javax.persistence.NoResultException)5 Feature (org.apache.uima.cas.Feature)5 Type (org.apache.uima.cas.Type)5 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)4 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)4 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)3 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)3 Selection (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection)3 WebAnnoCasUtil.setFeature (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature)3 AnnotationSchemaService (de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService)2 DocumentService (de.tudarmstadt.ukp.clarin.webanno.api.DocumentService)2 ProjectService (de.tudarmstadt.ukp.clarin.webanno.api.ProjectService)2