use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection in project webanno by webanno.
the class AnnotationDetailEditorPanel method createNewRelationAnnotation.
private void createNewRelationAnnotation(ArcAdapter aAdapter, JCas aJCas) throws AnnotationException {
LOG.trace("createNewRelationAnnotation()");
AnnotatorState state = getModelObject();
Selection selection = state.getSelection();
AnnotationFS originFs = selectByAddr(aJCas, selection.getOrigin());
AnnotationFS targetFs = selectByAddr(aJCas, selection.getTarget());
// Creating a relation
AnnotationFS arc = aAdapter.add(originFs, targetFs, aJCas, state.getWindowBeginOffset(), state.getWindowEndOffset());
selection.selectArc(new VID(arc), originFs, targetFs);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection in project webanno by webanno.
the class AnnotationDetailEditorPanel method createNewChainLinkAnnotation.
private void createNewChainLinkAnnotation(ChainAdapter aAdapter, JCas aJCas) {
LOG.trace("createNewChainLinkAnnotation()");
AnnotatorState state = getModelObject();
Selection selection = state.getSelection();
AnnotationFS originFs = selectByAddr(aJCas, selection.getOrigin());
AnnotationFS targetFs = selectByAddr(aJCas, selection.getTarget());
// Creating a new chain link
int addr = aAdapter.addArc(aJCas, originFs, targetFs);
selection.selectArc(new VID(addr), originFs, targetFs);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection 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.model.Selection 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.model.Selection 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();
}
Aggregations