use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID 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.VID in project webanno by webanno.
the class AnnotationDetailEditorPanel method actionReverse.
@Override
public void actionReverse(AjaxRequestTarget aTarget) throws IOException, AnnotationException {
aTarget.addChildren(getPage(), IFeedback.class);
JCas jCas = getEditorCas();
AnnotatorState state = getModelObject();
AnnotationFS idFs = selectByAddr(jCas, state.getSelection().getAnnotation().getId());
jCas.removeFsFromIndexes(idFs);
AnnotationFS originFs = selectByAddr(jCas, state.getSelection().getOrigin());
AnnotationFS targetFs = selectByAddr(jCas, state.getSelection().getTarget());
List<FeatureState> featureStates = getModelObject().getFeatureStates();
TypeAdapter adapter = annotationService.getAdapter(state.getSelectedAnnotationLayer());
if (adapter instanceof ArcAdapter) {
// If no features, still create arc #256
AnnotationFS arc = ((ArcAdapter) adapter).add(targetFs, originFs, jCas, state.getWindowBeginOffset(), state.getWindowEndOffset());
state.getSelection().setAnnotation(new VID(getAddr(arc)));
for (FeatureState featureState : featureStates) {
adapter.setFeatureValue(state, jCas, getAddr(arc), featureState.feature, featureState.value);
}
} else {
error("chains cannot be reversed");
return;
}
// persist changes
writeEditorCas(jCas);
int sentenceNumber = getSentenceNumber(jCas, originFs.getBegin());
state.setFocusUnitIndex(sentenceNumber);
state.getDocument().setSentenceAccessed(sentenceNumber);
if (state.getPreferences().isScrollPage()) {
autoScroll(jCas, false);
}
info("The arc has been reversed");
state.rememberFeatures();
// in case the user re-reverse it
state.getSelection().reverseArc();
onChange(aTarget);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID 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.VID 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.VID 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());
}
Aggregations