Search in sources :

Example 16 with Sentence

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

the class NoZeroSizeTokensAndSentencesCheck method check.

@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    try {
        boolean ok = true;
        for (Token t : select(aCas.getJCas(), Token.class)) {
            if (t.getBegin() >= t.getEnd()) {
                aMessages.add(new LogMessage(this, LogLevel.ERROR, "Token with illegal span: %s", t));
                ok = false;
            }
        }
        for (Sentence s : select(aCas.getJCas(), Sentence.class)) {
            if (s.getBegin() >= s.getEnd()) {
                aMessages.add(new LogMessage(this, LogLevel.ERROR, "Sentence with illegal span: %s", s));
                ok = false;
            }
        }
        return ok;
    } catch (CASException e) {
        log.error("Unabled to access JCas", e);
        aMessages.add(new LogMessage(this, LogLevel.ERROR, "Unabled to access JCas", e.getMessage()));
        return false;
    }
}
Also used : LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) CASException(org.apache.uima.cas.CASException) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 17 with Sentence

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

the class AnnotatorViewState method moveToFirstPage.

default void moveToFirstPage(JCas aJCas) {
    int firstSentenceAddress = WebAnnoCasUtil.getFirstSentenceAddress(aJCas);
    if (firstSentenceAddress == getFirstVisibleUnitAddress()) {
        throw new IllegalStateException("This is first page!");
    }
    Sentence sentence = selectByAddr(aJCas, Sentence.class, firstSentenceAddress);
    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 18 with Sentence

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

the class AnnotatorViewState method moveToOffset.

default void moveToOffset(JCas aJCas, int aOffset) {
    // Fetch the first sentence on screen or first sentence
    Sentence sentence;
    if (getFirstVisibleUnitAddress() > -1) {
        sentence = selectByAddr(aJCas, Sentence.class, getFirstVisibleUnitAddress());
    } else {
        sentence = getFirstSentence(aJCas);
    }
    // Calculate the first sentence in the window in such a way that the annotation
    // currently selected is in the center of the window
    sentence = findWindowStartCenteringOnSelection(aJCas, sentence, aOffset, getProject(), getDocument(), getPreferences().getWindowSize());
    // Move to it
    setFirstVisibleUnit(sentence);
    // FIXME getSentenceNumber is not a good option... if we aim for the begin offset of the
    // very last unit, then we get (max-units - 1) instead of (max-units). However, this
    // method is used also in curation and I dimly remember that things broke when I tried
    // to fix it. Probably better to move away from it in the long run. -- REC
    setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, aOffset));
}
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 19 with Sentence

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

the class WebAnnoCasUtil method getDisplayWindowBeginningSentenceAddresses.

/**
 * Returns the beginning address of all pages. This is used properly display<b> Page X of Y </b>
 *
 * @param aJcas
 *            the JCas.
 * @param aWindowSize
 *            the window size.
 * @return hum?
 */
public static List<Integer> getDisplayWindowBeginningSentenceAddresses(JCas aJcas, int aWindowSize) {
    List<Integer> beginningAddresses = new ArrayList<>();
    int j = 0;
    for (Sentence sentence : select(aJcas, Sentence.class)) {
        if (j % aWindowSize == 0) {
            beginningAddresses.add(getAddr(sentence));
        }
        j++;
    }
    return beginningAddresses;
}
Also used : ArrayList(java.util.ArrayList) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 20 with Sentence

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

the class WebAnnoCasUtil method getLastSentenceInDisplayWindow.

/**
 * Get the last sentence CAS address in the current display window
 *
 * @param aJcas
 *            the JCas.
 * @param aFirstSentenceAddress
 *            the CAS address of the first sentence in the display window
 * @param aWindowSize
 *            the window size
 * @return The address of the last sentence address in the current display window.
 */
public static Sentence getLastSentenceInDisplayWindow(JCas aJcas, int aFirstSentenceAddress, int aWindowSize) {
    int count = 0;
    FSIterator<Sentence> si = seekByAddress(aJcas, Sentence.class, aFirstSentenceAddress);
    Sentence s = si.get();
    while (count < aWindowSize - 1) {
        si.moveToNext();
        if (si.isValid()) {
            s = si.get();
        } else {
            break;
        }
        count++;
    }
    return s;
}
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