use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl in project webanno by webanno.
the class AnnotationPage method commonInit.
private void commonInit() {
setModel(Model.of(new AnnotatorStateImpl(Mode.ANNOTATION)));
// Ensure that a user is set
getModelObject().setUser(userRepository.getCurrentUser());
add(createUrlFragmentBehavior());
add(annotationEditor = createAnnotationEditor());
add(createRightSidebar());
add(createLeftSidebar());
add(createDocumentInfoLabel());
add(getOrCreatePositionInfoLabel());
add(openDocumentsModal = new OpenDocumentDialog("openDocumentsModal", getModel(), getAllowedProjects()) {
private static final long serialVersionUID = 5474030848589262638L;
@Override
public void onDocumentSelected(AjaxRequestTarget aTarget) {
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("initialLoadComplete", this::actionInitialLoadComplete));
add(new LambdaAjaxLink("showOpenDocumentDialog", this::actionShowOpenDocumentDialog));
add(new ActionBarLink("showPreferencesDialog", this::actionShowPreferencesDialog));
add(new ActionBarLink("showGuidelinesDialog", guidelinesDialog::show));
add(new ActionBarLink("showExportDialog", exportDialog::show).onConfigure(_this -> {
AnnotatorState state = AnnotationPage.this.getModelObject();
_this.setVisible(state.getProject() != null && (isAdmin(state.getProject(), projectService, state.getUser()) || !state.getProject().isDisableExport()));
}));
add(new ActionBarLink("showPreviousDocument", t -> actionShowPreviousDocument(t)).add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_up }, EventType.click)));
add(new ActionBarLink("showNextDocument", t -> actionShowNextDocument(t)).add(new InputBehavior(new KeyType[] { KeyType.Shift, KeyType.Page_down }, EventType.click)));
add(new ActionBarLink("showNext", t -> actionShowNextPage(t)).add(new InputBehavior(new KeyType[] { KeyType.Page_down }, EventType.click)));
add(new ActionBarLink("showPrevious", t -> actionShowPreviousPage(t)).add(new InputBehavior(new KeyType[] { KeyType.Page_up }, EventType.click)));
add(new ActionBarLink("showFirst", t -> actionShowFirstPage(t)).add(new InputBehavior(new KeyType[] { KeyType.Home }, EventType.click)));
add(new ActionBarLink("showLast", t -> actionShowLastPage(t)).add(new InputBehavior(new KeyType[] { KeyType.End }, EventType.click)));
add(new ActionBarLink("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 = AnnotationPage.this.getModelObject();
setEnabled(state.getDocument() != null && !documentService.isAnnotationFinished(state.getDocument(), state.getUser()));
}
});
finishDocumentIcon = new FinishImage("finishImage", getModel());
finishDocumentIcon.setOutputMarkupId(true);
finishDocumentLink.add(finishDocumentIcon);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl in project webanno by webanno.
the class CopyAnnotationTest method simpleCopyToDiffExistingAnnoWithNoStackingTest.
@Test
public void simpleCopyToDiffExistingAnnoWithNoStackingTest() throws Exception {
JCas jcas = JCasFactory.createJCas();
Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);
JCas mergeCAs = JCasFactory.createJCas();
AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0);
Feature posValue = type.getFeatureByBaseName("PosValue");
existingFs.setStringValue(posValue, "NE");
mergeCAs.addFsToIndexes(existingFs);
MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService, posLayer, mergeCAs, clickedFs, false);
assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl in project webanno by webanno.
the class CopyAnnotationTest method simpleCopyToSameExistingAnnoTest.
@Test
public void simpleCopyToSameExistingAnnoTest() throws Exception {
JCas jcas = JCasFactory.createJCas();
Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);
JCas mergeCAs = JCasFactory.createJCas();
AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0);
Feature posValue = type.getFeatureByBaseName("PosValue");
existingFs.setStringValue(posValue, "NN");
mergeCAs.addFsToIndexes(existingFs);
exception.expect(AnnotationException.class);
MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService, posLayer, mergeCAs, clickedFs, false);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl 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);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl in project webanno by webanno.
the class CasToBratJsonTest method testGenerateBratJsonGetDocument.
/**
* generate brat JSON data for the document
*/
@Test
public void testGenerateBratJsonGetDocument() throws Exception {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
String jsonFilePath = "target/test-output/output_cas_to_json_document.json";
String file = "src/test/resources/tcf04-karin-wl.xml";
CAS cas = JCasFactory.createJCas().getCas();
CollectionReader reader = CollectionReaderFactory.createReader(TcfReader.class, TcfReader.PARAM_SOURCE_LOCATION, file);
reader.getNext(cas);
JCas jCas = cas.getJCas();
AnnotatorState state = new AnnotatorStateImpl(Mode.ANNOTATION);
state.getPreferences().setWindowSize(10);
state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(jCas));
state.setProject(project);
VDocument vdoc = new VDocument();
preRenderer.render(vdoc, state, jCas, annotationSchemaService.listAnnotationLayer(project));
GetDocumentResponse response = new GetDocumentResponse();
BratRenderer.render(response, state, vdoc, jCas, annotationSchemaService);
JSONUtil.generatePrettyJson(jsonConverter, response, new File(jsonFilePath));
assertThat(linesOf(new File("src/test/resources/output_cas_to_json_document_expected.json"), "UTF-8")).isEqualTo(linesOf(new File(jsonFilePath), "UTF-8"));
}
Aggregations