public int getBegin() { return uimaSentence.getBegin(); }
public int getBegin() { return uimaSentence.getBegin(); }
public static int getSentenceNumber(Sentence sentence, JCas jCas) { ArrayList<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class)); for (int i = 0; i < sentences.size(); i++) { Sentence s = sentences.get(i); if (s.getBegin() == sentence.getBegin()) { return i; } } throw new IllegalStateException(); } }
/** * Get the cureent sentence based on the anotation begin/end offset */ public static Sentence getCurrentSentence(JCas aJCas, int aBegin, int aEnd){ Sentence currentSentence = null; for(Sentence sentence :select(aJCas, Sentence.class)){ if(sentence.getBegin()<=aBegin && sentence.getEnd()>=aEnd){ currentSentence = sentence; break; } } return currentSentence; }
/** * Returns a covering sentence if it starts at the token, null otherwise * * @param t token * @return sentence or null */ public static Sentence sentenceStartsOnToken(Token t) { List<Sentence> sentences = JCasUtil.selectCovering(Sentence.class, t); return (!sentences.isEmpty() && sentences.get(0).getBegin() == t.getBegin()) ? sentences.get(0) : null; }
@Override public void init(JCas aJCas) { text = aJCas.getDocumentText(); sentences = new ArrayList<>(); for (Sentence sent : select(aJCas, Sentence.class)) { Span s = new Span(sent.getBegin(), sent.getEnd()); sentences.add(s); } }
private List<List<String>> extractTags(JCas jCas) { List<List<String>> posTags = new ArrayList<List<String>>(); Collection<Sentence> sentences = JCasUtil.select(jCas, Sentence.class); for (Sentence s : sentences) { List<String> tags = new ArrayList<String>(); List<TextClassificationOutcome> tcos = JCasUtil.selectCovered(jCas, TextClassificationOutcome.class, s.getBegin(), s.getEnd()); for (TextClassificationOutcome tco : tcos) { tags.add(tco.getOutcome()); } posTags.add(tags); } return posTags; }
/** * Check if the start/end offsets of an annotation belongs to the same sentence. * * @return */ public static boolean isSameSentence(JCas aJcas, int aStartOffset, int aEndOffset) { for (Sentence sentence : select(aJcas, Sentence.class)) { if ((sentence.getBegin() <= aStartOffset && sentence.getEnd() > aStartOffset) && aEndOffset <= sentence.getEnd()) { return true; } } return false; }
private static int getLastSentenceAddress(BratAnnotatorModel aBratAnnotatorModel, JCas jCas, JCas userJCas) { Sentence sentence = selectByAddr(userJCas, Sentence.class, aBratAnnotatorModel.getLastSentenceAddress()); List<Sentence> sentences = JCasUtil.selectCovered(jCas, Sentence.class, sentence.getBegin(), sentence.getEnd()); return sentences.get(0).getAddress(); }
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())); }
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())); }
private void updateSentenceNumber(JCas aJCas, int aAddress) { AnnotatorState state = getModelObject(); Sentence sentence = selectByAddr(aJCas, Sentence.class, aAddress); state.setFirstVisibleUnit(sentence); state.setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
private void updateSentenceNumber(JCas aJCas, int aAddress) { AnnotatorState state = getModelObject(); Sentence sentence = selectByAddr(aJCas, Sentence.class, aAddress); state.setFirstVisibleUnit(sentence); state.setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
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())); }
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())); }
/** * Get the sentence address for jCas from userJCas. */ private static int getSentenceAddress(BratAnnotatorModel aBratAnnotatorModel, JCas jCas, JCas userJCas) { int sentenceAddress = BratAjaxCasUtil.selectSentenceAt(userJCas, aBratAnnotatorModel.getSentenceBeginOffset(), aBratAnnotatorModel.getSentenceEndOffset()).getAddress(); Sentence sentence = selectByAddr(userJCas, Sentence.class, sentenceAddress); List<Sentence> sentences = JCasUtil.selectCovered(jCas, Sentence.class, sentence.getBegin(), sentence.getEnd()); return sentences.get(0).getAddress(); }
default void moveToNextPage(JCas aJCas) { int nextSentenceAddress = WebAnnoCasUtil.getNextPageFirstSentenceAddress(aJCas, getFirstVisibleUnitAddress(), getPreferences().getWindowSize()); if (getFirstVisibleUnitAddress() == nextSentenceAddress) { throw new IllegalStateException("This is last page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, nextSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
default void moveToNextPage(JCas aJCas) { int nextSentenceAddress = WebAnnoCasUtil.getNextPageFirstSentenceAddress(aJCas, getFirstVisibleUnitAddress(), getPreferences().getWindowSize()); if (getFirstVisibleUnitAddress() == nextSentenceAddress) { throw new IllegalStateException("This is last page!"); } Sentence sentence = selectByAddr(aJCas, Sentence.class, nextSentenceAddress); setFirstVisibleUnit(sentence); setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin())); }
private void updateSentenceAddressAndOffsets(JCas jCas, int start) { int address = BratAjaxCasUtil.selectSentenceAt(jCas, bratAnnotatorModel.getSentenceBeginOffset(), bratAnnotatorModel.getSentenceEndOffset()).getAddress(); bratAnnotatorModel.setSentenceAddress(BratAjaxCasUtil.getSentenceBeginAddress(jCas, address, start, bratAnnotatorModel.getProject(), bratAnnotatorModel.getDocument(), bratAnnotatorModel.getWindowSize())); Sentence sentence = selectByAddr(jCas, Sentence.class, bratAnnotatorModel.getSentenceAddress()); bratAnnotatorModel.setSentenceBeginOffset(sentence.getBegin()); bratAnnotatorModel.setSentenceEndOffset(sentence.getEnd()); }
private void updateSentenceAddressAndOffsets(JCas jCas, int start) { int address = BratAjaxCasUtil.selectSentenceAt(jCas, bratAnnotatorModel.getSentenceBeginOffset(), bratAnnotatorModel.getSentenceEndOffset()).getAddress(); bratAnnotatorModel.setSentenceAddress(BratAjaxCasUtil.getSentenceBeginAddress(jCas, address, start, bratAnnotatorModel.getProject(), bratAnnotatorModel.getDocument(), bratAnnotatorModel.getWindowSize())); Sentence sentence = selectByAddr(jCas, Sentence.class, bratAnnotatorModel.getSentenceAddress()); bratAnnotatorModel.setSentenceBeginOffset(sentence.getBegin()); bratAnnotatorModel.setSentenceEndOffset(sentence.getEnd()); }