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