use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AnnotationSidebar_ImplBase method actionShowSelectedDocumentByTokenPosition.
/**
* Show the next document if it exists, starting in a certain token position
*/
@Deprecated
protected void actionShowSelectedDocumentByTokenPosition(AjaxRequestTarget aTarget, SourceDocument aDocument, int aTokenNumber) throws IOException {
annotationPage.actionShowSelectedDocument(aTarget, aDocument);
AnnotatorState state = getModelObject();
JCas jCas = annotationPage.getEditorCas();
Collection<Token> tokenCollection = JCasUtil.select(jCas, Token.class);
Token[] tokens = tokenCollection.toArray(new Token[tokenCollection.size()]);
int sentenceNumber = WebAnnoCasUtil.getSentenceNumber(jCas, tokens[aTokenNumber].getBegin());
Sentence sentence = WebAnnoCasUtil.getSentence(jCas, tokens[aTokenNumber].getBegin());
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 CurationPage method actionLoadDocument.
/**
* Open a document or to a different document. This method should be used only the first time
* that a document is accessed. It reset the annotator state and upgrades the CAS.
*/
@Override
protected void actionLoadDocument(AjaxRequestTarget aTarget) {
LOG.info("BEGIN LOAD_DOCUMENT_ACTION");
AnnotatorState state = getModelObject();
String username = SecurityContextHolder.getContext().getAuthentication().getName();
User user = userRepository.get(username);
state.setUser(user);
try {
// ANNOTATION_FINISHED
if (!SourceDocumentState.CURATION_FINISHED.equals(state.getDocument().getState())) {
documentService.transitionSourceDocumentState(state.getDocument(), ANNOTATION_IN_PROGRESS_TO_CURATION_IN_PROGRESS);
}
// Load user preferences
PreferencesUtil.loadPreferences(username, settingsService, projectService, annotationService, state, state.getMode());
// Re-render whole page as sidebar size preference may have changed
aTarget.add(CurationPage.this);
List<AnnotationDocument> finishedAnnotationDocuments = new ArrayList<>();
for (AnnotationDocument annotationDocument : documentService.listAnnotationDocuments(state.getDocument())) {
if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
finishedAnnotationDocuments.add(annotationDocument);
}
}
SuggestionBuilder cb = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
AnnotationDocument randomAnnotationDocument = null;
if (finishedAnnotationDocuments.size() > 0) {
randomAnnotationDocument = finishedAnnotationDocuments.get(0);
}
// annotation
for (AnnotationDocument ad : finishedAnnotationDocuments) {
upgradeCasAndSave(ad.getDocument(), ad.getUser());
}
Map<String, JCas> jCases = cb.listJcasesforCuration(finishedAnnotationDocuments, randomAnnotationDocument, state.getMode());
JCas mergeJCas = cb.getMergeCas(state, state.getDocument(), jCases, randomAnnotationDocument, true);
// (Re)initialize brat model after potential creating / upgrading CAS
state.reset();
state.getPreferences().setCurationWindowSize(WebAnnoCasUtil.getSentenceCount(mergeJCas));
// Initialize the visible content
state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(mergeJCas));
// if project is changed, reset some project specific settings
if (currentprojectId != state.getProject().getId()) {
state.clearRememberedFeatures();
}
currentprojectId = state.getProject().getId();
SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
curationContainer = builder.buildCurationContainer(state);
curationContainer.setBratAnnotatorModel(state);
curationPanel.editor.reset(aTarget);
updatePanel(curationContainer, aTarget);
updateSentenceNumber(mergeJCas, state.getFirstVisibleUnitAddress());
curationPanel.init(aTarget, curationContainer);
// curationPanel.updatePanel(aTarget, curationContainer);
// Load constraints
state.setConstraints(constraintsService.loadConstraints(state.getProject()));
aTarget.add(getOrCreatePositionInfoLabel());
aTarget.add(documentNamePanel);
aTarget.add(remergeDocumentLink);
aTarget.add(finishDocumentLink);
} 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 CurationPage method actionCompletePreferencesChange.
private void actionCompletePreferencesChange(AjaxRequestTarget aTarget) {
AnnotatorState state = CurationPage.this.getModelObject();
// Re-render the whole page because the width of the sidebar may have changed
aTarget.add(CurationPage.this);
aTarget.add(getOrCreatePositionInfoLabel());
JCas mergeCas = null;
try {
aTarget.add(getFeedbackPanel());
mergeCas = curationDocumentService.readCurationCas(state.getDocument());
// The number of visible sentences may have changed - let the state recalculate
// the visible sentences
Sentence sentence = selectByAddr(mergeCas, Sentence.class, state.getFirstVisibleUnitAddress());
state.setFirstVisibleUnit(sentence);
curationPanel.updatePanel(aTarget, curationContainer);
updatePanel(curationContainer, aTarget);
updateSentenceNumber(mergeCas, state.getFirstVisibleUnitAddress());
} catch (Exception e) {
handleException(aTarget, e);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class CurationPage method updateSentenceNumber.
private void updateSentenceNumber(JCas aJCas, int aAddress) {
AnnotatorState state = getModelObject();
Sentence sentence = selectByAddr(aJCas, Sentence.class, aAddress);
state.setFirstVisibleUnit(sentence);
state.setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin()));
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class CorrectionPage method commonInit.
private void commonInit() {
setVersioned(false);
setModel(Model.of(new AnnotatorStateImpl(Mode.CORRECTION)));
WebMarkupContainer rightSidebar = new WebMarkupContainer("rightSidebar");
// Override sidebar width from preferences
rightSidebar.add(new AttributeModifier("style", LambdaModel.of(() -> String.format("flex-basis: %d%%;", getModelObject().getPreferences().getSidebarSize()))));
rightSidebar.setOutputMarkupId(true);
add(rightSidebar);
List<UserAnnotationSegment> segments = new LinkedList<>();
UserAnnotationSegment userAnnotationSegment = new UserAnnotationSegment();
if (getModelObject().getDocument() != null) {
userAnnotationSegment.setSelectionByUsernameAndAddress(annotationSelectionByUsernameAndAddress);
userAnnotationSegment.setAnnotatorState(getModelObject());
segments.add(userAnnotationSegment);
}
suggestionView = new SuggestionViewPanel("correctionView", new ListModel<>(segments)) {
private static final long serialVersionUID = 2583509126979792202L;
@Override
public void onChange(AjaxRequestTarget aTarget) {
AnnotatorState state = CorrectionPage.this.getModelObject();
aTarget.addChildren(getPage(), IFeedback.class);
try {
// update begin/end of the curation segment based on bratAnnotatorModel changes
// (like sentence change in auto-scroll mode,....
curationContainer.setBratAnnotatorModel(state);
JCas editorCas = getEditorCas();
setCurationSegmentBeginEnd(editorCas);
suggestionView.updatePanel(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
annotationEditor.requestRender(aTarget);
aTarget.add(getOrCreatePositionInfoLabel());
update(aTarget);
} catch (UIMAException e) {
LOG.error("Error: " + e.getMessage(), e);
error("Error: " + ExceptionUtils.getRootCauseMessage(e));
} catch (Exception e) {
LOG.error("Error: " + e.getMessage(), e);
error("Error: " + e.getMessage());
}
}
};
suggestionView.setOutputMarkupId(true);
add(suggestionView);
rightSidebar.add(detailEditor = createDetailEditor());
annotationEditor = new BratAnnotationEditor("mergeView", getModel(), detailEditor, this::getEditorCas);
add(annotationEditor);
curationContainer = new CurationContainer();
curationContainer.setBratAnnotatorModel(getModelObject());
add(documentNamePanel = createDocumentInfoLabel());
add(getOrCreatePositionInfoLabel());
add(openDocumentsModal = new OpenDocumentDialog("openDocumentsModal", getModel(), getAllowedProjects()) {
private static final long serialVersionUID = 5474030848589262638L;
@Override
public void onDocumentSelected(AjaxRequestTarget aTarget) {
// Reload the page using AJAX. This does not add the project/document ID to the URL,
// but being AJAX it flickers less.
actionLoadDocument(aTarget);
}
});
add(preferencesModal = new AnnotationPreferencesDialog("preferencesDialog", getModel()));
preferencesModal.setOnChangeAction(this::actionCompletePreferencesChange);
add(exportDialog = new ExportDocumentDialog("exportDialog", getModel()));
add(guidelinesDialog = new GuidelinesDialog("guidelinesDialog", getModel()));
Form<Void> gotoPageTextFieldForm = new Form<>("gotoPageTextFieldForm");
gotoPageTextField = new NumberTextField<>("gotoPageText", Model.of(1), Integer.class);
// FIXME minimum and maximum should be obtained from the annotator state
gotoPageTextField.setMinimum(1);
gotoPageTextField.setOutputMarkupId(true);
gotoPageTextFieldForm.add(gotoPageTextField);
LambdaAjaxSubmitLink gotoPageLink = new LambdaAjaxSubmitLink("gotoPageLink", gotoPageTextFieldForm, this::actionGotoPage);
gotoPageTextFieldForm.setDefaultButton(gotoPageLink);
gotoPageTextFieldForm.add(gotoPageLink);
add(gotoPageTextFieldForm);
add(new LambdaAjaxLink("showOpenDocumentModal", this::actionShowOpenDocumentDialog));
add(new LambdaAjaxLink("showPreferencesDialog", this::actionShowPreferencesDialog));
add(new ActionBarLink("showGuidelinesDialog", guidelinesDialog::show));
add(new LambdaAjaxLink("showExportDialog", exportDialog::show) {
private static final long serialVersionUID = -708400631769656072L;
{
setOutputMarkupId(true);
setOutputMarkupPlaceholderTag(true);
}
@Override
protected void onConfigure() {
super.onConfigure();
AnnotatorState state = CorrectionPage.this.getModelObject();
setVisible(state.getProject() != null && (SecurityUtil.isAdmin(state.getProject(), projectService, state.getUser()) || !state.getProject().isDisableExport()));
}
});
add(new LambdaAjaxLink("showPreviousDocument", t -> actionShowPreviousDocument(t)).add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_up }, EventType.click)));
add(new LambdaAjaxLink("showNextDocument", t -> actionShowNextDocument(t)).add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_down }, EventType.click)));
add(new LambdaAjaxLink("showNext", t -> actionShowNextPage(t)).add(new InputBehavior(new KeyType[] { KeyType.Page_down }, EventType.click)));
add(new LambdaAjaxLink("showPrevious", t -> actionShowPreviousPage(t)).add(new InputBehavior(new KeyType[] { KeyType.Page_up }, EventType.click)));
add(new LambdaAjaxLink("showFirst", t -> actionShowFirstPage(t)).add(new InputBehavior(new KeyType[] { KeyType.Home }, EventType.click)));
add(new LambdaAjaxLink("showLast", t -> actionShowLastPage(t)).add(new InputBehavior(new KeyType[] { KeyType.End }, EventType.click)));
add(new LambdaAjaxLink("toggleScriptDirection", this::actionToggleScriptDirection));
add(createOrGetResetDocumentDialog());
add(createOrGetResetDocumentLink());
add(finishDocumentDialog = new ConfirmationDialog("finishDocumentDialog", new StringResourceModel("FinishDocumentDialog.title", this, null), new StringResourceModel("FinishDocumentDialog.text", this, null)));
add(finishDocumentLink = new LambdaAjaxLink("showFinishDocumentDialog", this::actionFinishDocument) {
private static final long serialVersionUID = 874573384012299998L;
@Override
protected void onConfigure() {
super.onConfigure();
AnnotatorState state = CorrectionPage.this.getModelObject();
setEnabled(state.getDocument() != null && !documentService.isAnnotationFinished(state.getDocument(), state.getUser()));
}
});
finishDocumentIcon = new FinishImage("finishImage", getModel());
finishDocumentIcon.setOutputMarkupId(true);
finishDocumentLink.add(finishDocumentIcon);
}
Aggregations