Search in sources :

Example 1 with SentenceOrientedPagingStrategy

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy in project webanno by webanno.

the class AutomationPage method commonInit.

private void commonInit() {
    setVersioned(false);
    setModel(Model.of(new AnnotatorStateImpl(Mode.AUTOMATION)));
    WebMarkupContainer rightSidebar = new WebMarkupContainer("rightSidebar");
    // Override sidebar width from preferencesa
    rightSidebar.add(new AttributeModifier("style", LambdaModel.of(() -> String.format("flex-basis: %d%%;", getModelObject().getPreferences().getSidebarSize()))));
    rightSidebar.setOutputMarkupId(true);
    add(rightSidebar);
    centerArea = new WebMarkupContainer("centerArea");
    centerArea.add(visibleWhen(() -> getModelObject().getDocument() != null));
    centerArea.setOutputMarkupPlaceholderTag(true);
    centerArea.add(new DocumentNamePanel("documentNamePanel", getModel()));
    actionBar = new ActionBar("actionBar");
    centerArea.add(actionBar);
    rightSidebar.add(detailEditor = createDetailEditor());
    annotationEditor = new BratAnnotationEditor("mergeView", getModel(), detailEditor, this::getEditorCas);
    centerArea.add(annotationEditor);
    add(centerArea);
    getModelObject().setPagingStrategy(new SentenceOrientedPagingStrategy());
    centerArea.add(getModelObject().getPagingStrategy().createPositionLabel(MID_NUMBER_OF_PAGES, getModel()).add(visibleWhen(() -> getModelObject().getDocument() != null)).add(LambdaBehavior.onEvent(RenderAnnotationsEvent.class, (c, e) -> e.getRequestHandler().add(c))));
    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("automateView", new ListModel<>(segments)) {

        private static final long serialVersionUID = 2583509126979792202L;

        @Override
        public void onChange(AjaxRequestTarget aTarget) {
            try {
                // update begin/end of the curation segment based on bratAnnotatorModel changes
                // (like sentence change in auto-scroll mode,....
                aTarget.addChildren(getPage(), IFeedback.class);
                AnnotatorState state = AutomationPage.this.getModelObject();
                curationContainer.setState(state);
                CAS editorCas = getEditorCas();
                setCurationSegmentBeginEnd(editorCas);
                suggestionView.requestUpdate(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
                annotationEditor.requestRender(aTarget);
                update(aTarget);
            } catch (Exception e) {
                handleException(aTarget, e);
            }
        }
    };
    centerArea.add(suggestionView);
    curationContainer = new CurationContainer();
    curationContainer.setState(getModelObject());
}
Also used : AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) CurationContainer(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.CurationContainer) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) LinkedList(java.util.LinkedList) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CAS(org.apache.uima.cas.CAS) SuggestionViewPanel(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.SuggestionViewPanel) ListModel(org.apache.wicket.model.util.ListModel) BratAnnotationEditor(de.tudarmstadt.ukp.clarin.webanno.brat.annotation.BratAnnotationEditor) DocumentNamePanel(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.component.DocumentNamePanel) IFeedback(org.apache.wicket.feedback.IFeedback) ActionBar(de.tudarmstadt.ukp.clarin.webanno.api.annotation.actionbar.ActionBar) SentenceOrientedPagingStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Example 2 with SentenceOrientedPagingStrategy

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy in project webanno by webanno.

the class CurationPage method commonInit.

private void commonInit() {
    setModel(Model.of(new AnnotatorStateImpl(Mode.CURATION)));
    centerArea = new WebMarkupContainer("centerArea");
    centerArea.add(visibleWhen(() -> getModelObject().getDocument() != null));
    centerArea.setOutputMarkupPlaceholderTag(true);
    centerArea.add(new DocumentNamePanel("documentNamePanel", getModel()));
    add(centerArea);
    actionBar = new ActionBar("actionBar");
    centerArea.add(actionBar);
    getModelObject().setPagingStrategy(new SentenceOrientedPagingStrategy());
    centerArea.add(getModelObject().getPagingStrategy().createPositionLabel(MID_NUMBER_OF_PAGES, getModel()).add(visibleWhen(() -> getModelObject().getDocument() != null)).add(LambdaBehavior.onEvent(RenderAnnotationsEvent.class, (c, e) -> e.getRequestHandler().add(c))));
    // Ensure that a user is set
    getModelObject().setUser(new User(CURATION_USER, Role.ROLE_USER));
    curationContainer = new CurationContainer();
    curationContainer.setState(getModelObject());
    WebMarkupContainer sidebarCell = new WebMarkupContainer("rightSidebar");
    sidebarCell.setOutputMarkupPlaceholderTag(true);
    // Override sidebar width from preferences
    sidebarCell.add(new AttributeModifier("style", () -> String.format("flex-basis: %d%%;", getModelObject() != null ? getModelObject().getPreferences().getSidebarSize() : 10)));
    add(sidebarCell);
    curationView = new SourceListView();
    List<UserAnnotationSegment> segments = new LinkedList<>();
    UserAnnotationSegment userAnnotationSegments = new UserAnnotationSegment();
    if (getModelObject() != null) {
        userAnnotationSegments.setSelectionByUsernameAndAddress(annotationSelectionByUsernameAndAddress);
        userAnnotationSegments.setAnnotatorState(getModelObject());
        segments.add(userAnnotationSegments);
    }
    // update source list model only first time.
    sourceListModel = sourceListModel == null ? curationContainer.getCurationViews() : sourceListModel;
    suggestionViewPanel = new SuggestionViewPanel("suggestionViewPanel", new ListModel<>(segments)) {

        private static final long serialVersionUID = 2583509126979792202L;

        @Override
        public void onChange(AjaxRequestTarget aTarget) {
            try {
                // update begin/end of the curationsegment based on annotator state
                // changes
                // (like sentence change in auto-scroll mode,....
                aTarget.addChildren(getPage(), IFeedback.class);
                CurationPage.this.updatePanel(aTarget, curationContainer);
            } catch (UIMAException e) {
                error(ExceptionUtils.getRootCause(e));
            } catch (ClassNotFoundException | AnnotationException | IOException e) {
                error("Error: " + e.getMessage());
            }
        }
    };
    suggestionViewPanel.setOutputMarkupPlaceholderTag(true);
    suggestionViewPanel.add(visibleWhen(() -> getModelObject() != null && getModelObject().getDocument() != null));
    centerArea.add(suggestionViewPanel);
    editor = new AnnotationDetailEditorPanel("annotationDetailEditorPanel", this, getModel()) {

        private static final long serialVersionUID = 2857345299480098279L;

        @Override
        protected void onChange(AjaxRequestTarget aTarget) {
            aTarget.addChildren(getPage(), IFeedback.class);
            try {
                updatePanel(aTarget, curationContainer);
            } 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());
            }
        }

        @Override
        protected void onAutoForward(AjaxRequestTarget aTarget) {
            annotationEditor.requestRender(aTarget);
        }

        @Override
        protected void onConfigure() {
            super.onConfigure();
            setEnabled(getModelObject() != null && getModelObject().getDocument() != null && !documentService.getSourceDocument(getModelObject().getDocument().getProject(), getModelObject().getDocument().getName()).getState().equals(SourceDocumentState.CURATION_FINISHED));
        }

        @Override
        public CAS getEditorCas() throws IOException {
            return CurationPage.this.getEditorCas();
        }
    };
    sidebarCell.add(editor);
    annotationEditor = new BratAnnotationEditor("mergeView", getModel(), editor, this::getEditorCas);
    annotationEditor.setHighlightEnabled(false);
    annotationEditor.add(visibleWhen(() -> getModelObject() != null && getModelObject().getDocument() != null));
    annotationEditor.setOutputMarkupPlaceholderTag(true);
    // reset sentenceAddress and lastSentenceAddress to the orginal once
    centerArea.add(annotationEditor);
    // add container for sentences panel
    sentenceListContainer = new WebMarkupContainer("sentenceListContainer");
    sentenceListContainer.setOutputMarkupPlaceholderTag(true);
    sentenceListContainer.add(visibleWhen(() -> getModelObject() != null && getModelObject().getDocument() != null));
    add(sentenceListContainer);
    // add container for list of sentences panel
    sentenceLinksListView = new WebMarkupContainer("sentenceLinkListView");
    sentenceLinksListView.setOutputMarkupPlaceholderTag(true);
    sentenceLinksListView.add(new ListView<SourceListView>("sentenceLinkList", LoadableDetachableModel.of(() -> curationContainer.getCurationViews())) {

        private static final long serialVersionUID = 8539162089561432091L;

        @Override
        protected void populateItem(ListItem<SourceListView> item) {
            item.add(new SentenceLink("sentenceNumber", item.getModel()));
        }
    });
    sentenceListContainer.add(sentenceLinksListView);
}
Also used : User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) SourceListView(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SourceListView) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AnnotationDetailEditorPanel(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel) DocumentNamePanel(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.component.DocumentNamePanel) IFeedback(org.apache.wicket.feedback.IFeedback) UIMAException(org.apache.uima.UIMAException) ActionBar(de.tudarmstadt.ukp.clarin.webanno.api.annotation.actionbar.ActionBar) SentenceOrientedPagingStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy) CurationContainer(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.CurationContainer) IOException(java.io.IOException) AttributeModifier(org.apache.wicket.AttributeModifier) LinkedList(java.util.LinkedList) NoResultException(javax.persistence.NoResultException) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CAS(org.apache.uima.cas.CAS) SuggestionViewPanel(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.SuggestionViewPanel) ListModel(org.apache.wicket.model.util.ListModel) BratAnnotationEditor(de.tudarmstadt.ukp.clarin.webanno.brat.annotation.BratAnnotationEditor) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Example 3 with SentenceOrientedPagingStrategy

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy in project webanno by webanno.

the class BratRendererTest method thatSentenceOrientedStrategyRenderCorrectly.

@Test
public void thatSentenceOrientedStrategyRenderCorrectly() throws Exception {
    String jsonFilePath = "target/test-output/output-sentence-oriented.json";
    String file = "src/test/resources/tcf04-karin-wl.xml";
    CAS cas = JCasFactory.createJCas().getCas();
    CollectionReader reader = createReader(TcfReader.class, TcfReader.PARAM_SOURCE_LOCATION, file);
    reader.getNext(cas);
    AnnotatorState state = new AnnotatorStateImpl(Mode.ANNOTATION);
    state.setAllAnnotationLayers(schemaService.listAnnotationLayer(project));
    state.setPagingStrategy(new SentenceOrientedPagingStrategy());
    state.getPreferences().setWindowSize(10);
    state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(cas));
    state.setProject(project);
    VDocument vdoc = new VDocument();
    preRenderer.render(vdoc, state.getWindowBeginOffset(), state.getWindowEndOffset(), cas, schemaService.listAnnotationLayer(project));
    GetDocumentResponse response = new GetDocumentResponse();
    BratRenderer renderer = new BratRenderer(schemaService, new ColoringServiceImpl(schemaService));
    renderer.render(response, state, vdoc, cas);
    JSONUtil.generatePrettyJson(response, new File(jsonFilePath));
    assertThat(contentOf(new File("src/test/resources/output-sentence-oriented.json"), UTF_8)).isEqualToNormalizingNewlines(contentOf(new File(jsonFilePath), UTF_8));
}
Also used : BratRenderer(de.tudarmstadt.ukp.clarin.webanno.brat.render.BratRenderer) CollectionReader(org.apache.uima.collection.CollectionReader) CAS(org.apache.uima.cas.CAS) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) File(java.io.File) ColoringServiceImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringServiceImpl) SentenceOrientedPagingStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy) Test(org.junit.Test)

Example 4 with SentenceOrientedPagingStrategy

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy 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);
    rightSidebar.add(detailEditor = createDetailEditor());
    centerArea = new WebMarkupContainer("centerArea");
    centerArea.add(visibleWhen(() -> getModelObject().getDocument() != null));
    centerArea.setOutputMarkupPlaceholderTag(true);
    centerArea.add(createDocumentInfoLabel());
    actionBar = new ActionBar("actionBar");
    centerArea.add(actionBar);
    annotationEditor = new BratAnnotationEditor("mergeView", getModel(), detailEditor, this::getEditorCas);
    centerArea.add(annotationEditor);
    add(centerArea);
    getModelObject().setPagingStrategy(new SentenceOrientedPagingStrategy());
    centerArea.add(getModelObject().getPagingStrategy().createPositionLabel(MID_NUMBER_OF_PAGES, getModel()).add(visibleWhen(() -> getModelObject().getDocument() != null)).add(LambdaBehavior.onEvent(RenderAnnotationsEvent.class, (c, e) -> e.getRequestHandler().add(c))));
    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.setState(state);
                CAS editorCas = getEditorCas();
                setCurationSegmentBeginEnd(editorCas);
                suggestionView.requestUpdate(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
                annotationEditor.requestRender(aTarget);
                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());
            }
        }
    };
    centerArea.add(suggestionView);
    curationContainer = new CurationContainer();
    curationContainer.setState(getModelObject());
}
Also used : AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) CurationContainer(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.CurationContainer) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) LinkedList(java.util.LinkedList) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CAS(org.apache.uima.cas.CAS) SuggestionViewPanel(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.SuggestionViewPanel) ListModel(org.apache.wicket.model.util.ListModel) BratAnnotationEditor(de.tudarmstadt.ukp.clarin.webanno.brat.annotation.BratAnnotationEditor) IFeedback(org.apache.wicket.feedback.IFeedback) UIMAException(org.apache.uima.UIMAException) ActionBar(de.tudarmstadt.ukp.clarin.webanno.api.annotation.actionbar.ActionBar) SentenceOrientedPagingStrategy(de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Aggregations

AnnotatorStateImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl)4 SentenceOrientedPagingStrategy (de.tudarmstadt.ukp.clarin.webanno.api.annotation.paging.SentenceOrientedPagingStrategy)4 CAS (org.apache.uima.cas.CAS)4 ActionBar (de.tudarmstadt.ukp.clarin.webanno.api.annotation.actionbar.ActionBar)3 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)3 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)3 BratAnnotationEditor (de.tudarmstadt.ukp.clarin.webanno.brat.annotation.BratAnnotationEditor)3 SuggestionViewPanel (de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.SuggestionViewPanel)3 CurationContainer (de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.CurationContainer)3 UserAnnotationSegment (de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)3 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 UIMAException (org.apache.uima.UIMAException)3 AttributeModifier (org.apache.wicket.AttributeModifier)3 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)3 IFeedback (org.apache.wicket.feedback.IFeedback)3 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)3 ListModel (org.apache.wicket.model.util.ListModel)3 DocumentNamePanel (de.tudarmstadt.ukp.clarin.webanno.ui.annotation.component.DocumentNamePanel)2 ColoringServiceImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringServiceImpl)1