Search in sources :

Example 31 with Sentence

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

the class CurationPage method actionGotoPage.

private void actionGotoPage(AjaxRequestTarget aTarget, Form<?> aForm) throws Exception {
    AnnotatorState state = getModelObject();
    JCas jcas = getEditorCas();
    List<Sentence> sentences = new ArrayList<>(select(jcas, Sentence.class));
    int selectedSentence = gotoPageTextField.getModelObject();
    selectedSentence = Math.min(selectedSentence, sentences.size());
    gotoPageTextField.setModelObject(selectedSentence);
    state.setFirstVisibleUnit(sentences.get(selectedSentence - 1));
    state.setFocusUnitIndex(selectedSentence);
    actionRefreshDocument(aTarget);
    curationPanel.updatePanel(aTarget, curationContainer);
}
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)

Example 32 with Sentence

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

the class CurationPanel method updateCurationView.

private void updateCurationView(final CurationContainer curationContainer, final SourceListView curationViewItem, AjaxRequestTarget aTarget, JCas jCas) {
    Sentence currentSent = WebAnnoCasUtil.getCurrentSentence(jCas, curationViewItem.getBegin(), curationViewItem.getEnd());
    state.setFirstVisibleUnit(WebAnnoCasUtil.findWindowStartCenteringOnSelection(jCas, currentSent, curationViewItem.getBegin(), state.getProject(), state.getDocument(), state.getPreferences().getWindowSize()));
    curationContainer.setBratAnnotatorModel(state);
    onChange(aTarget);
}
Also used : Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 33 with Sentence

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

the class SuggestionViewPanel method mergeArc.

private void mergeArc(IRequestParameters aRequest, UserAnnotationSegment aCurationUserSegment, JCas aJcas) throws AnnotationException, IOException, UIMAException, ClassNotFoundException {
    int addressOriginClicked = aRequest.getParameterValue(PARAM_ORIGIN_SPAN_ID).toInt();
    int addressTargetClicked = aRequest.getParameterValue(PARAM_TARGET_SPAN_ID).toInt();
    String arcType = removePrefix(aRequest.getParameterValue(PARAM_TYPE).toString());
    String fsArcaddress = aRequest.getParameterValue(PARAM_ARC_ID).toString();
    AnnotatorState bModel = aCurationUserSegment.getAnnotatorState();
    SourceDocument sourceDocument = bModel.getDocument();
    // for correction and automation, the lower panel is the clickedJcase, from the suggestions
    JCas clickedJCas;
    if (!aCurationUserSegment.getAnnotatorState().getMode().equals(Mode.CURATION)) {
        clickedJCas = correctionDocumentService.readCorrectionCas(sourceDocument);
    } else {
        User user = userRepository.get(aCurationUserSegment.getUsername());
        AnnotationDocument clickedAnnotationDocument = documentService.getAnnotationDocument(sourceDocument, user);
        clickedJCas = getJCas(bModel, clickedAnnotationDocument);
    }
    long layerId = TypeUtil.getLayerId(arcType);
    AnnotationLayer layer = annotationService.getLayer(layerId);
    TypeAdapter adapter = annotationService.getAdapter(layer);
    int address = Integer.parseInt(fsArcaddress.split("\\.")[0]);
    AnnotationFS clickedFS = selectByAddr(clickedJCas, address);
    if (isCorefType(clickedFS)) {
        throw new AnnotationException(" Coreference Annotation not supported in curation");
    }
    MergeCas.addArcAnnotation(adapter, aJcas, addressOriginClicked, addressTargetClicked, fsArcaddress, clickedJCas, clickedFS);
    writeEditorCas(bModel, aJcas);
    int sentenceNumber = getSentenceNumber(clickedJCas, clickedFS.getBegin());
    bModel.setFocusUnitIndex(sentenceNumber);
    // Update timestamp
    bModel.getDocument().setSentenceAccessed(sentenceNumber);
    if (bModel.getPreferences().isScrollPage()) {
        Sentence sentence = selectSentenceAt(aJcas, bModel.getFirstVisibleUnitBegin(), bModel.getFirstVisibleUnitEnd());
        sentence = findWindowStartCenteringOnSelection(aJcas, sentence, clickedFS.getBegin(), bModel.getProject(), bModel.getDocument(), bModel.getPreferences().getWindowSize());
        bModel.setFirstVisibleUnit(sentence);
    }
}
Also used : User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 34 with Sentence

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

the class SuggestionViewPanel method createSpan.

private void createSpan(String spanType, AnnotatorState aBModel, JCas aMergeJCas, AnnotationDocument aAnnotationDocument, int aAddress) throws IOException, UIMAException, ClassNotFoundException, AnnotationException {
    JCas clickedJCas = getJCas(aBModel, aAnnotationDocument);
    AnnotationFS fsClicked = selectByAddr(clickedJCas, aAddress);
    if (isCorefType(fsClicked)) {
        throw new AnnotationException("Coreference Annotation not supported in curation");
    }
    long layerId = TypeUtil.getLayerId(spanType);
    AnnotationLayer layer = annotationService.getLayer(layerId);
    MergeCas.addSpanAnnotation(aBModel, annotationService, layer, aMergeJCas, fsClicked, layer.isAllowStacking());
    writeEditorCas(aBModel, aMergeJCas);
    // update timestamp
    int sentenceNumber = getSentenceNumber(clickedJCas, fsClicked.getBegin());
    aBModel.setFocusUnitIndex(sentenceNumber);
    aBModel.getDocument().setSentenceAccessed(sentenceNumber);
    if (aBModel.getPreferences().isScrollPage()) {
        Sentence sentence = selectSentenceAt(aMergeJCas, aBModel.getFirstVisibleUnitBegin(), aBModel.getFirstVisibleUnitEnd());
        sentence = findWindowStartCenteringOnSelection(aMergeJCas, sentence, fsClicked.getBegin(), aBModel.getProject(), aBModel.getDocument(), aBModel.getPreferences().getWindowSize());
        aBModel.setFirstVisibleUnit(sentence);
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) JCas(org.apache.uima.jcas.JCas) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 35 with Sentence

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

the class SuggestionBuilder method getSentenceByAnnoEnd.

/**
 * Get a sentence at the end of an annotation
 */
private static Sentence getSentenceByAnnoEnd(List<Sentence> aSentences, int aEnd) {
    int prevEnd = 0;
    Sentence sent = null;
    for (Sentence sentence : aSentences) {
        if (prevEnd >= aEnd) {
            return sent;
        }
        sent = sentence;
        prevEnd = sent.getEnd();
    }
    return sent;
}
Also used : 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