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);
}
}
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()));
}
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);
}
}
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());
}
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);
}
Aggregations