Search in sources :

Example 66 with Sentence

use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence 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 67 with Sentence

use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence 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 68 with Sentence

use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.

the class CorrectionPage method actionGotoPage.

private void actionGotoPage(AjaxRequestTarget aTarget, Form<?> aForm) throws Exception {
    AnnotatorState state = getModelObject();
    JCas editorCas = getEditorCas();
    List<Sentence> sentences = new ArrayList<>(select(editorCas, Sentence.class));
    int selectedSentence = gotoPageTextField.getModelObject();
    selectedSentence = Math.min(selectedSentence, sentences.size());
    gotoPageTextField.setModelObject(selectedSentence);
    state.setFirstVisibleUnit(sentences.get(selectedSentence - 1));
    state.setFocusUnitIndex(selectedSentence);
    SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
    curationContainer = builder.buildCurationContainer(state);
    setCurationSegmentBeginEnd(editorCas);
    curationContainer.setBratAnnotatorModel(state);
    update(aTarget);
    aTarget.add(gotoPageTextField);
    annotationEditor.requestRender(aTarget);
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) SuggestionBuilder(de.tudarmstadt.ukp.clarin.webanno.ui.curation.component.model.SuggestionBuilder)

Example 69 with Sentence

use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.

the class CurationPanel method commonUpdate.

private void commonUpdate() throws IOException {
    JCas jCas = curationDocumentService.readCurationCas(state.getDocument());
    // Determine the FIRST visible unit
    final Sentence firstVisibleUnit = selectSentenceAt(jCas, state.getFirstVisibleUnitBegin(), state.getFirstVisibleUnitEnd());
    state.setFirstVisibleUnit(firstVisibleUnit);
    // Determine the LAST visible unit
    List<Sentence> followingUnits = selectFollowing(jCas, Sentence.class, firstVisibleUnit, state.getPreferences().getWindowSize());
    // Check also, when getting the last sentence address in the display window, if this is the
    // last sentence or the ONLY sentence in the document
    Sentence lastVisibleUnit = followingUnits.size() == 0 ? firstVisibleUnit : followingUnits.get(followingUnits.size() - 1);
    curationView.setCurationBegin(firstVisibleUnit.getBegin());
    curationView.setCurationEnd(lastVisibleUnit.getEnd());
    // Determine the number of the first and last visible unit
    int ws = state.getPreferences().getWindowSize();
    Sentence fs = WebAnnoCasUtil.selectSentenceAt(jCas, state.getFirstVisibleUnitBegin(), state.getFirstVisibleUnitEnd());
    Sentence ls = WebAnnoCasUtil.getLastSentenceInDisplayWindow(jCas, getAddr(fs), ws);
    fSn = WebAnnoCasUtil.getSentenceNumber(jCas, fs.getBegin());
    lSn = WebAnnoCasUtil.getSentenceNumber(jCas, ls.getBegin());
}
Also used : JCas(org.apache.uima.jcas.JCas) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 70 with Sentence

use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.

the class SuggestionBuilder method buildCurationContainer.

public CurationContainer buildCurationContainer(AnnotatorState aBModel) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
    CurationContainer curationContainer = new CurationContainer();
    // initialize Variables
    SourceDocument sourceDocument = aBModel.getDocument();
    Map<Integer, Integer> segmentBeginEnd = new HashMap<>();
    Map<Integer, Integer> segmentNumber = new HashMap<>();
    Map<String, Map<Integer, Integer>> segmentAdress = new HashMap<>();
    // get annotation documents
    List<AnnotationDocument> finishedAnnotationDocuments = new ArrayList<>();
    for (AnnotationDocument annotationDocument : documentService.listAnnotationDocuments(aBModel.getDocument())) {
        if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
            finishedAnnotationDocuments.add(annotationDocument);
        }
    }
    Map<String, JCas> jCases = new HashMap<>();
    AnnotationDocument randomAnnotationDocument = null;
    JCas mergeJCas;
    // get the correction/automation JCas for the logged in user
    if (aBModel.getMode().equals(Mode.AUTOMATION) || aBModel.getMode().equals(Mode.CORRECTION)) {
        jCases = listJcasesforCorrection(randomAnnotationDocument, sourceDocument, aBModel.getMode());
        mergeJCas = getMergeCas(aBModel, sourceDocument, jCases, randomAnnotationDocument, false);
        String username = jCases.keySet().iterator().next();
        updateSegment(aBModel, segmentBeginEnd, segmentNumber, segmentAdress, jCases.get(username), username, aBModel.getWindowBeginOffset(), aBModel.getWindowEndOffset());
    } else {
        jCases = listJcasesforCuration(finishedAnnotationDocuments, randomAnnotationDocument, aBModel.getMode());
        mergeJCas = getMergeCas(aBModel, sourceDocument, jCases, randomAnnotationDocument, false);
        updateSegment(aBModel, segmentBeginEnd, segmentNumber, segmentAdress, mergeJCas, WebAnnoConst.CURATION_USER, WebAnnoCasUtil.getFirstSentence(mergeJCas).getBegin(), mergeJCas.getDocumentText().length());
    }
    List<Type> entryTypes = null;
    segmentAdress.put(WebAnnoConst.CURATION_USER, new HashMap<>());
    for (Sentence sentence : selectCovered(mergeJCas, Sentence.class, diffRangeBegin, diffRangeEnd)) {
        segmentAdress.get(WebAnnoConst.CURATION_USER).put(sentence.getBegin(), getAddr(sentence));
    }
    if (entryTypes == null) {
        entryTypes = getEntryTypes(mergeJCas, aBModel.getAnnotationLayers(), annotationService);
    }
    // for cross-sentences annotation, update the end of the segment
    if (firstload) {
        long start = System.currentTimeMillis();
        log.debug("Updating cross sentence annotation list...");
        updateCrossSentAnnoList(segmentBeginEnd, segmentNumber, jCases, entryTypes);
        firstload = false;
        log.debug("Cross sentence annotation list complete in {}ms", (System.currentTimeMillis() - start));
    }
    long diffStart = System.currentTimeMillis();
    log.debug("Calculating differences...");
    int count = 0;
    for (Integer begin : segmentBeginEnd.keySet()) {
        Integer end = segmentBeginEnd.get(begin);
        count++;
        if (count % 100 == 0) {
            log.debug("Processing differences: {} of {} sentences...", count, segmentBeginEnd.size());
        }
        DiffResult diff = CasDiff2.doDiffSingle(annotationService, aBModel.getProject(), entryTypes, LinkCompareBehavior.LINK_ROLE_AS_LABEL, jCases, begin, end);
        SourceListView curationSegment = new SourceListView();
        curationSegment.setBegin(begin);
        curationSegment.setEnd(end);
        curationSegment.setSentenceNumber(segmentNumber.get(begin));
        if (diff.hasDifferences() || !diff.getIncompleteConfigurationSets().isEmpty()) {
            // Is this confSet a diff due to stacked annotations (with same configuration)?
            boolean stackedDiff = false;
            stackedDiffSet: for (ConfigurationSet d : diff.getDifferingConfigurationSets().values()) {
                for (Configuration c : d.getConfigurations()) {
                    if (c.getCasGroupIds().size() != d.getCasGroupIds().size()) {
                        stackedDiff = true;
                        break stackedDiffSet;
                    }
                }
            }
            if (stackedDiff) {
                curationSegment.setSentenceState(SentenceState.DISAGREE);
            } else if (!diff.getIncompleteConfigurationSets().isEmpty()) {
                curationSegment.setSentenceState(SentenceState.DISAGREE);
            } else {
                curationSegment.setSentenceState(SentenceState.AGREE);
            }
        } else {
            curationSegment.setSentenceState(SentenceState.AGREE);
        }
        for (String username : segmentAdress.keySet()) {
            curationSegment.getSentenceAddress().put(username, segmentAdress.get(username).get(begin));
        }
        curationContainer.getCurationViewByBegin().put(begin, curationSegment);
    }
    log.debug("Difference calculation completed in {}ms", (System.currentTimeMillis() - diffStart));
    return curationContainer;
}
Also used : Configuration(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.Configuration) HashMap(java.util.HashMap) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet) Type(org.apache.uima.cas.Type) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) HashMap(java.util.HashMap) Map(java.util.Map) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Aggregations

Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)90 JCas (org.apache.uima.jcas.JCas)41 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)34 ArrayList (java.util.ArrayList)22 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)14 Type (org.apache.uima.cas.Type)12 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)12 IOException (java.io.IOException)9 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)8 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 TokenBuilder (org.apache.uima.fit.testing.factory.TokenBuilder)7 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)6 WebAnnoCasUtil.getFirstSentence (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getFirstSentence)6 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)6 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)6 FrequencyDistribution (de.tudarmstadt.ukp.dkpro.core.api.frequency.util.FrequencyDistribution)6 CASException (org.apache.uima.cas.CASException)6 AutomationTypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.AutomationTypeAdapter)5