Search in sources :

Example 71 with AnnotatorState

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);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 72 with AnnotatorState

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");
}
Also used : User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) SuggestionBuilder(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 73 with AnnotatorState

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);
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 74 with AnnotatorState

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()));
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 75 with AnnotatorState

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);
}
Also used : AnnotationPreferencesDialog(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.dialog.AnnotationPreferencesDialog) Form(org.apache.wicket.markup.html.form.Form) ActionBarLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.ActionBarLink) AnnotatorStateImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) LambdaAjaxSubmitLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxSubmitLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ConfirmationDialog(de.tudarmstadt.ukp.clarin.webanno.support.dialog.ConfirmationDialog) LambdaAjaxLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxLink) ExportDocumentDialog(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.dialog.ExportDocumentDialog) IFeedback(org.apache.wicket.feedback.IFeedback) UIMAException(org.apache.uima.UIMAException) StringResourceModel(org.apache.wicket.model.StringResourceModel) InputBehavior(wicket.contrib.input.events.InputBehavior) CurationContainer(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.CurationContainer) AttributeModifier(org.apache.wicket.AttributeModifier) LinkedList(java.util.LinkedList) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) FinishImage(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.component.FinishImage) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) GuidelinesDialog(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.dialog.GuidelinesDialog) SuggestionViewPanel(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.SuggestionViewPanel) ListModel(org.apache.wicket.model.util.ListModel) OpenDocumentDialog(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.dialog.OpenDocumentDialog) BratAnnotationEditor(de.tudarmstadt.ukp.clarin.webanno.brat.annotation.BratAnnotationEditor) UserAnnotationSegment(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.UserAnnotationSegment)

Aggregations

AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)84 JCas (org.apache.uima.jcas.JCas)37 IOException (java.io.IOException)26 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)23 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 UIMAException (org.apache.uima.UIMAException)20 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)16 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)16 ArrayList (java.util.ArrayList)16 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)14 List (java.util.List)13 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)12 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)9 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)9 SuggestionBuilder (de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder)9 Map (java.util.Map)9 NoResultException (javax.persistence.NoResultException)9 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)9 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)8 Selection (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection)8