Search in sources :

Example 56 with Sentence

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

the class AnnotatorViewState method moveToLastPage.

default void moveToLastPage(JCas aJCas) {
    int lastDisplayWindowBeginingSentenceAddress = WebAnnoCasUtil.getLastDisplayWindowFirstSentenceAddress(aJCas, getPreferences().getWindowSize());
    if (lastDisplayWindowBeginingSentenceAddress == getFirstVisibleUnitAddress()) {
        throw new IllegalStateException("This is last page!");
    }
    Sentence sentence = selectByAddr(aJCas, Sentence.class, lastDisplayWindowBeginingSentenceAddress);
    setFirstVisibleUnit(sentence);
    setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin()));
}
Also used : Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) WebAnnoCasUtil.getFirstSentence(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getFirstSentence)

Example 57 with Sentence

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

the class WebAnnoCasUtil method getSentenceAddress.

/**
 * Get Sentence address for this ordinal sentence number. Used to go to specific sentence number
 *
 * @param aJcas
 *            the JCas.
 * @param aSentenceNumber
 *            the sentence number.
 * @return the ID.
 */
public static int getSentenceAddress(JCas aJcas, int aSentenceNumber) {
    int i = 1;
    int address = 0;
    if (aSentenceNumber < 1) {
        return 0;
    }
    for (Sentence sentence : select(aJcas, Sentence.class)) {
        if (i == aSentenceNumber) {
            address = getAddr(sentence);
            break;
        }
        address = getAddr(sentence);
        i++;
    }
    if (aSentenceNumber > i) {
        return 0;
    }
    return address;
}
Also used : Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 58 with Sentence

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

the class WebAnnoCasUtil method findWindowStartCenteringOnSelection.

/**
 * Gets the address of the first sentence visible on screen in such a way that the specified
 * focus offset is centered on screen.
 *
 * @param aJcas
 *            the CAS object
 * @param aSentence
 *            the old sentence
 * @param aFocusOffset
 *            the actual offset of the sentence.
 * @param aProject
 *            the project.
 * @param aDocument
 *            the document.
 * @param aWindowSize
 *            the window size.
 * @return the ID of the first sentence.
 */
public static Sentence findWindowStartCenteringOnSelection(JCas aJcas, Sentence aSentence, int aFocusOffset, Project aProject, SourceDocument aDocument, int aWindowSize) {
    if (aWindowSize == 1) {
        return aSentence;
    }
    // Seek the sentence that contains the current focus
    Sentence s = getSentence(aJcas, aFocusOffset);
    // behave.
    if (s == null) {
        LOG.warn("Focus [{}] is outside any unit, using first unit.", aFocusOffset);
        return aSentence;
    }
    // Center sentence
    FSIterator<Sentence> si = seekByFs(aJcas, Sentence.class, s);
    if (aWindowSize == 2 && s.getBegin() > aSentence.getBegin()) {
        return s;
    }
    int count = 0;
    while (si.isValid() && count < (aWindowSize / 2)) {
        si.moveToPrevious();
        if (si.isValid()) {
            s = si.get();
        }
        count++;
    }
    return s;
}
Also used : Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 59 with Sentence

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

the class SegmentationTest method testTokenize.

@Test
public void testTokenize() throws Exception {
    JCas jcas = JCasFactory.createText("i am one.i am two.", "en");
    new Sentence(jcas, 0, 9).addToIndexes();
    ;
    new Sentence(jcas, 9, 18).addToIndexes();
    ImportExportServiceImpl.tokenize(jcas);
    assertEquals(asList("i am one.", "i am two."), toText(select(jcas, Sentence.class)));
    assertEquals(asList("i", "am", "one", ".", "i", "am", "two", "."), toText(select(jcas, Token.class)));
}
Also used : JCas(org.apache.uima.jcas.JCas) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) Test(org.junit.Test)

Example 60 with Sentence

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

the class AnnotationPage 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);
}
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)

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