use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AnnotationPageBase method ensureRequiredFeatureValuesSet.
/**
* Checks if all required features on all annotations are set. If a required feature value is
* missing, then the method scrolls to that location and schedules a re-rendering. In such
* a case, an {@link IllegalStateException} is thrown.
*/
protected void ensureRequiredFeatureValuesSet(AjaxRequestTarget aTarget, JCas aJcas) {
AnnotatorState state = getModelObject();
CAS editorCas = aJcas.getCas();
for (AnnotationLayer layer : annotationService.listAnnotationLayer(state.getProject())) {
TypeAdapter adapter = annotationService.getAdapter(layer);
List<AnnotationFeature> features = annotationService.listAnnotationFeature(layer);
// If no feature is required, then we can skip the whole procedure
if (features.stream().allMatch((f) -> !f.isRequired())) {
continue;
}
// Check each feature structure of this layer
for (AnnotationFS fs : select(editorCas, adapter.getAnnotationType(editorCas))) {
for (AnnotationFeature f : features) {
if (WebAnnoCasUtil.isRequiredFeatureMissing(f, fs)) {
// Find the sentence that contains the annotation with the missing
// required feature value
Sentence s = WebAnnoCasUtil.getSentence(aJcas, fs.getBegin());
// Put this sentence into the focus
state.setFirstVisibleUnit(s);
actionRefreshDocument(aTarget);
// Inform the user
throw new IllegalStateException("Document cannot be marked as finished. Annotation with ID [" + WebAnnoCasUtil.getAddr(fs) + "] on layer [" + layer.getUiName() + "] is missing value for feature [" + f.getUiName() + "].");
}
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AnnotationPreferencesDialogContent method loadModel.
private Preferences loadModel(AnnotatorState bModel) {
Preferences model = new Preferences();
// Import current settings from the annotator
model.windowSize = bModel.getPreferences().getWindowSize() < 1 ? 1 : bModel.getPreferences().getWindowSize();
model.sidebarSize = bModel.getPreferences().getSidebarSize();
model.fontZoom = bModel.getPreferences().getFontZoom();
model.scrollPage = bModel.getPreferences().isScrollPage();
model.colorPerLayer = bModel.getPreferences().getColorPerLayer();
model.readonlyLayerColoringBehaviour = bModel.getPreferences().getReadonlyLayerColoringBehaviour();
model.rememberLayer = bModel.getPreferences().isRememberLayer();
String editorId = bModel.getPreferences().getEditor();
AnnotationEditorFactory editorFactory = annotationEditorRegistry.getEditorFactory(editorId);
if (editorFactory == null) {
editorFactory = annotationEditorRegistry.getDefaultEditorFactory();
}
model.editor = Pair.of(editorFactory.getBeanName(), editorFactory.getDisplayName());
model.annotationLayers = annotationService.listAnnotationLayer(bModel.getProject()).stream().filter(layer -> layer.isEnabled()).filter(layer -> !Token.class.getName().equals(layer.getName())).filter(layer -> !(layer.getType().equals(WebAnnoConst.CHAIN_TYPE) && (bModel.getMode().equals(Mode.CORRECTION) || // disable coreference annotation for correction/curation pages
bModel.getMode().equals(Mode.CURATION)))).collect(Collectors.toList());
return model;
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AnnotationSidebar_ImplBase method actionShowSelectedDocument.
/**
* Show the next document if it exists, starting in a certain begin offset
*/
protected void actionShowSelectedDocument(AjaxRequestTarget aTarget, SourceDocument aDocument, int aBeginOffset) throws IOException {
annotationPage.actionShowSelectedDocument(aTarget, aDocument);
AnnotatorState state = getModelObject();
JCas jCas = annotationPage.getEditorCas();
int sentenceNumber = WebAnnoCasUtil.getSentenceNumber(jCas, aBeginOffset);
Sentence sentence = WebAnnoCasUtil.getSentence(jCas, aBeginOffset);
annotationPage.getGotoPageTextField().setModelObject(sentenceNumber);
state.setFirstVisibleUnit(sentence);
state.setFocusUnitIndex(sentenceNumber);
annotationPage.actionRefreshDocument(aTarget);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState 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();
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class BratAnnotationEditor method getLayersToRender.
private List<AnnotationLayer> getLayersToRender() {
AnnotatorState state = getModelObject();
List<AnnotationLayer> layersToRender = new ArrayList<>();
for (AnnotationLayer layer : state.getAnnotationLayers()) {
boolean isSegmentationLayer = layer.getName().equals(Token.class.getName()) || layer.getName().equals(Sentence.class.getName());
boolean isUnsupportedLayer = layer.getType().equals(CHAIN_TYPE) && (state.getMode().equals(Mode.AUTOMATION) || state.getMode().equals(Mode.CORRECTION) || state.getMode().equals(Mode.CURATION));
if (layer.isEnabled() && !isSegmentationLayer && !isUnsupportedLayer) {
layersToRender.add(layer);
}
}
return layersToRender;
}
Aggregations