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;
}
}
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()));
}
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));
}
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;
}
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;
}
Aggregations