use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState 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.AnnotatorState 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.model.AnnotatorState in project webanno by webanno.
the class AnnotationDetailEditorPanel method writeFeatureEditorModelsToCas.
private void writeFeatureEditorModelsToCas(TypeAdapter aAdapter, JCas aJCas) throws IOException {
AnnotatorState state = getModelObject();
List<FeatureState> featureStates = state.getFeatureStates();
LOG.trace("writeFeatureEditorModelsToCas()");
List<AnnotationFeature> features = new ArrayList<>();
for (FeatureState featureState : featureStates) {
features.add(featureState.feature);
// For string features with extensible tagsets, extend the tagset
if (CAS.TYPE_NAME_STRING.equals(featureState.feature.getType())) {
String value = (String) featureState.value;
if (value != null && featureState.feature.getTagset() != null && featureState.feature.getTagset().isCreateTag() && !annotationService.existsTag(value, featureState.feature.getTagset())) {
Tag selectedTag = new Tag();
selectedTag.setName(value);
selectedTag.setTagSet(featureState.feature.getTagset());
annotationService.createTag(selectedTag);
}
}
LOG.trace("writeFeatureEditorModelsToCas() " + featureState.feature.getUiName() + " = " + featureState.value);
aAdapter.setFeatureValue(state, aJCas, state.getSelection().getAnnotation().getId(), featureState.feature, featureState.value);
}
// Generate info message
if (state.getSelection().getAnnotation().isSet()) {
String bratLabelText = TypeUtil.getUiLabelText(aAdapter, selectByAddr(aJCas, state.getSelection().getAnnotation().getId()), features);
info(generateMessage(state.getSelectedAnnotationLayer(), bratLabelText, false));
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState 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.AnnotatorState in project webanno by webanno.
the class AnnotationDetailEditorPanel method internalCompleteAnnotation.
private void internalCompleteAnnotation(AjaxRequestTarget aTarget, JCas aJCas) {
AnnotatorState state = getModelObject();
// Perform auto-scroll if it is enabled
if (state.getPreferences().isScrollPage()) {
autoScroll(aJCas, false);
}
annotationFeatureForm.getForwardAnnotationText().setModelObject(null);
LOG.trace("onChange()");
onChange(aTarget);
// detail panel.
if (state.getSelection().getAnnotation().isNotSet()) {
refresh(state);
}
}
Aggregations