Search in sources :

Example 16 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class AnnotationPage method updateUrlFragment.

private void updateUrlFragment(AjaxRequestTarget aTarget) {
    if (aTarget != null) {
        AnnotatorState state = getModelObject();
        UrlFragment fragment = new UrlFragment(aTarget);
        // Current project
        fragment.putParameter(PAGE_PARAM_PROJECT_ID, state.getDocument().getProject().getId());
        // Current document
        fragment.putParameter(PAGE_PARAM_DOCUMENT_ID, state.getDocument().getId());
        // Current focus unit
        if (state.getFocusUnitIndex() > 0) {
            fragment.putParameter(PAGE_PARAM_FOCUS, state.getFocusUnitIndex());
        } else {
            fragment.removeParameter(PAGE_PARAM_FOCUS);
        }
        // If we do not manually set editedFragment to false, then changing the URL
        // manually or using the back/forward buttons in the browser only works every
        // second time. Might be a but in wicketstuff urlfragment... not sure.
        aTarget.appendJavaScript("try{if(window.UrlUtil){window.UrlUtil.editedFragment = false;}}catch(e){}");
    }
}
Also used : UrlFragment(org.wicketstuff.urlfragment.UrlFragment) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)

Example 17 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class AnnotationPage method getEditorCas.

@Override
public 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);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)

Example 18 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class AnnotationPage method actionCompletePreferencesChange.

private void actionCompletePreferencesChange(AjaxRequestTarget aTarget) {
    try {
        AnnotatorState state = getModelObject();
        JCas jCas = getEditorCas();
        // The number of visible sentences may have changed - let the state recalculate
        // the visible sentences
        Sentence sentence = selectByAddr(jCas, Sentence.class, state.getFirstVisibleUnitAddress());
        state.setFirstVisibleUnit(sentence);
        // The selection of layers may have changed. Update the dropdown
        detailEditor.getAnnotationFeatureForm().updateLayersDropdown();
        AnnotationEditorBase newAnnotationEditor = createAnnotationEditor();
        annotationEditor.replaceWith(newAnnotationEditor);
        annotationEditor = newAnnotationEditor;
        // Reload all AJAX-enabled children of the page but not the page itself!
        WicketUtil.refreshPage(aTarget, getPage());
    } catch (Exception e) {
        LOG.info("Error reading CAS " + e.getMessage());
        error("Error reading CAS " + e.getMessage());
    }
}
Also used : AnnotationEditorBase(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorBase) 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) NoResultException(javax.persistence.NoResultException) IOException(java.io.IOException)

Example 19 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class AnnotationPage method actionLoadDocument.

protected void actionLoadDocument(AjaxRequestTarget aTarget, int aFocus) {
    LOG.info("BEGIN LOAD_DOCUMENT_ACTION at focus " + aFocus);
    AnnotatorState state = getModelObject();
    state.setUser(userRepository.getCurrentUser());
    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 CAS
        JCas editorCas = documentService.readAnnotationCas(annotationDocument);
        // Update the annotation document CAS
        annotationService.upgradeCas(editorCas.getCas(), annotationDocument);
        // After creating an new CAS or upgrading the CAS, we need to save it
        documentService.writeAnnotationCas(editorCas.getCas().getJCas(), annotationDocument, false);
        // (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());
        // if project is changed, reset some project specific settings
        if (currentprojectId != state.getProject().getId()) {
            state.clearRememberedFeatures();
            currentprojectId = state.getProject().getId();
        }
        // Initialize the visible content
        state.moveToUnit(editorCas, aFocus);
        gotoPageTextField.setModelObject(getModelObject().getFirstVisibleUnitIndex());
        // Set the actual editor component. This has to happen *before* any AJAX refreshs are
        // scheduled and *after* the preferences have been loaded (because the current editor
        // type is set in the preferences.
        AnnotationEditorBase newAnnotationEditor = createAnnotationEditor();
        annotationEditor.replaceWith(newAnnotationEditor);
        annotationEditor = newAnnotationEditor;
        // Update document state
        if (SourceDocumentState.NEW.equals(state.getDocument().getState())) {
            documentService.transitionSourceDocumentState(state.getDocument(), NEW_TO_ANNOTATION_IN_PROGRESS);
        }
        // Reset the editor (we reload the page content below, so in order not to schedule
        // a double-update, we pass null here)
        detailEditor.reset(null);
        // Populate the layer dropdown box
        detailEditor.loadFeatureEditorModels(editorCas, null);
        if (aTarget != null) {
            // Update URL for current document
            updateUrlFragment(aTarget);
            WicketUtil.refreshPage(aTarget, getPage());
        }
        applicationEventPublisherHolder.get().publishEvent(new DocumentOpenedEvent(this, editorCas, getModelObject().getDocument(), getModelObject().getUser().getUsername()));
        LOG.debug("Configured BratAnnotatorModel for user [" + state.getUser().getUsername() + "] f:[" + state.getFirstVisibleUnitIndex() + "] l:[" + state.getLastVisibleUnitIndex() + "] s:[" + state.getFocusUnitIndex() + "]");
    } catch (Exception e) {
        handleException(aTarget, e);
    }
    LOG.info("END LOAD_DOCUMENT_ACTION");
}
Also used : AnnotationEditorBase(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorBase) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) DocumentOpenedEvent(de.tudarmstadt.ukp.clarin.webanno.api.annotation.event.DocumentOpenedEvent) NoResultException(javax.persistence.NoResultException) IOException(java.io.IOException)

Example 20 with AnnotatorState

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.

the class AnnotationPageBase method createOrGetResetDocumentLink.

protected ActionBarLink createOrGetResetDocumentLink() {
    if (resetDocumentLink == null) {
        resetDocumentLink = new ActionBarLink("showResetDocumentDialog", t -> resetDocumentDialog.show(t));
        resetDocumentLink.onConfigure(_this -> {
            AnnotatorState state = AnnotationPageBase.this.getModelObject();
            _this.setEnabled(state.getDocument() != null && !documentService.isAnnotationFinished(state.getDocument(), state.getUser()));
        });
    }
    return resetDocumentLink;
}
Also used : TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) StringResourceModel(org.apache.wicket.model.StringResourceModel) LoggerFactory(org.slf4j.LoggerFactory) CAS(org.apache.uima.cas.CAS) WebAnnoCasUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) ActionBarLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.ActionBarLink) ApplicationPageBase(de.tudarmstadt.ukp.clarin.webanno.ui.core.page.ApplicationPageBase) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) ChallengeResponseDialog(de.tudarmstadt.ukp.clarin.webanno.support.dialog.ChallengeResponseDialog) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IModel(org.apache.wicket.model.IModel) JCas(org.apache.uima.jcas.JCas) Label(org.apache.wicket.markup.html.basic.Label) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) CasUtil.select(org.apache.uima.fit.util.CasUtil.select) IOException(java.io.IOException) IFeedback(org.apache.wicket.feedback.IFeedback) Objects(java.util.Objects) List(java.util.List) PropertyModel(org.apache.wicket.model.PropertyModel) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) LambdaModel(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaModel) ActionBarLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.ActionBarLink) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)

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