use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AutomationPage method actionLoadDocument.
@Override
protected void actionLoadDocument(AjaxRequestTarget aTarget) {
LOG.info("BEGIN LOAD_DOCUMENT_ACTION");
AnnotatorState state = getModelObject();
state.setUser(userRepository.getCurrentUser());
state.setDocument(state.getDocument(), getListOfDocs());
try {
// Check if there is an annotation document entry in the database. If there is none,
// create one.
AnnotationDocument annotationDocument = documentService.createOrGetAnnotationDocument(state.getDocument(), state.getUser());
// Read the correction CAS - if it does not exist yet, from the initial CAS
JCas correctionCas;
if (correctionDocumentService.existsCorrectionCas(state.getDocument())) {
correctionCas = correctionDocumentService.readCorrectionCas(state.getDocument());
} else {
correctionCas = documentService.createOrReadInitialCas(state.getDocument());
}
// Read the annotation CAS or create an annotation CAS from the initial CAS by stripping
// annotations
JCas editorCas;
if (documentService.existsCas(state.getDocument(), state.getUser().getUsername())) {
editorCas = documentService.readAnnotationCas(annotationDocument);
} else {
editorCas = documentService.createOrReadInitialCas(state.getDocument());
// In automation mode, we do not remove the existing annotations from the documents
// annotationCas = BratAnnotatorUtility.clearJcasAnnotations(annotationCas,
// state.getDocument(), user, repository);
}
// Update the CASes
annotationService.upgradeCas(editorCas.getCas(), annotationDocument);
correctionDocumentService.upgradeCorrectionCas(correctionCas.getCas(), state.getDocument());
// After creating an new CAS or upgrading the CAS, we need to save it
documentService.writeAnnotationCas(editorCas.getCas().getJCas(), annotationDocument.getDocument(), state.getUser(), false);
correctionDocumentService.writeCorrectionCas(correctionCas, state.getDocument());
// (Re)initialize brat model after potential creating / upgrading CAS
state.reset();
// Load constraints
state.setConstraints(constraintsService.loadConstraints(state.getProject()));
// Load user preferences
PreferencesUtil.loadPreferences(state.getUser().getUsername(), settingsService, projectService, annotationService, state, state.getMode());
// Initialize the visible content
state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(editorCas));
// if project is changed, reset some project specific settings
if (currentprojectId != state.getProject().getId()) {
state.clearRememberedFeatures();
}
currentprojectId = state.getProject().getId();
LOG.debug("Configured BratAnnotatorModel for user [" + state.getUser() + "] f:[" + state.getFirstVisibleUnitIndex() + "] l:[" + state.getLastVisibleUnitIndex() + "] s:[" + state.getFocusUnitIndex() + "]");
gotoPageTextField.setModelObject(1);
setCurationSegmentBeginEnd(editorCas);
suggestionView.init(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
update(aTarget);
// Re-render the whole page because the font size
if (aTarget != null) {
aTarget.add(this);
}
// Update document state
if (state.getDocument().getState().equals(SourceDocumentState.NEW)) {
documentService.transitionSourceDocumentState(state.getDocument(), NEW_TO_ANNOTATION_IN_PROGRESS);
}
// Reset the editor
detailEditor.reset(aTarget);
// Populate the layer dropdown box
detailEditor.loadFeatureEditorModels(editorCas, aTarget);
} catch (Exception e) {
handleException(aTarget, e);
}
LOG.info("END LOAD_DOCUMENT_ACTION");
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AutomationPage method setCurationSegmentBeginEnd.
private void setCurationSegmentBeginEnd(JCas aEditorCas) throws UIMAException, ClassNotFoundException, IOException {
AnnotatorState state = getModelObject();
curationSegment.setBegin(state.getWindowBeginOffset());
curationSegment.setEnd(state.getWindowEndOffset());
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AutomationPage method actionGotoPage.
private void actionGotoPage(AjaxRequestTarget aTarget, Form<?> aForm) throws Exception {
AnnotatorState state = getModelObject();
JCas editorCas = getEditorCas();
List<Sentence> sentences = new ArrayList<>(select(editorCas, Sentence.class));
int selectedSentence = gotoPageTextField.getModelObject();
selectedSentence = Math.min(selectedSentence, sentences.size());
gotoPageTextField.setModelObject(selectedSentence);
state.setFirstVisibleUnit(sentences.get(selectedSentence - 1));
state.setFocusUnitIndex(selectedSentence);
SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
curationContainer = builder.buildCurationContainer(state);
setCurationSegmentBeginEnd(editorCas);
curationContainer.setBratAnnotatorModel(state);
update(aTarget);
aTarget.add(gotoPageTextField);
annotationEditor.requestRender(aTarget);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AutomationPage method getEditorCas.
@Override
protected JCas getEditorCas() throws IOException {
AnnotatorState state = getModelObject();
if (state.getDocument() == null) {
throw new IllegalStateException("Please open a document first!");
}
SourceDocument aDocument = getModelObject().getDocument();
AnnotationDocument annotationDocument = documentService.getAnnotationDocument(aDocument, state.getUser());
// If there is no CAS yet for the annotation document, create one.
return documentService.readAnnotationCas(annotationDocument);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AnnotationPreferencesDialogContent method actionSave.
private void actionSave(AjaxRequestTarget aTarget, Form<Preferences> aForm) {
try {
AnnotatorState state = stateModel.getObject();
commitModel(state);
PreferencesUtil.savePreference(state, projectService);
} catch (IOException e) {
error("Preference file not found");
}
modalWindow.close(aTarget);
}
Aggregations