Sentence outSentence = new Sentence(aJCas); outSentence.setBegin(tokensStored.get("t_" + firstTokenInSentence.get(i)).getEnd()); outSentence.setEnd(tokensStored.get("t_" + (tokensStored.size())).getEnd()); outSentence.addToIndexes(); break; outSentence.setBegin(tokensStored.get("t_" + firstTokenInSentence.get(i)) .getBegin()); outSentence.setEnd(tokensStored.get("t_" + (tokensStored.size())).getEnd()); outSentence.addToIndexes(); outSentence.setBegin(tokensStored.get("t_" + firstTokenInSentence.get(i)) .getBegin()); outSentence.setEnd(tokensStored.get("t_" + firstTokenInSentence.get(i + 1)) .getEnd()); outSentence.addToIndexes(); .setBegin(tokensStored.get("t_" + firstTokenInSentence.get(i)).getEnd() + 1); outSentence.setEnd(tokensStored.get("t_" + firstTokenInSentence.get(i + 1)) .getEnd()); outSentence.addToIndexes();
/** * 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; }
Sentence.class, BratAjaxCasUtil.getLastSentenceAddressInDisplayWindow(jCas, firstSentence.getAddress(), windowSize)); begin = firstSentence.getBegin(); end = lastSentence.getEnd(); sentenceNumber = BratAjaxCasUtil.getFirstSentenceNumber(jCas, firstSentence.getAddress()); segmentAdress.put(username, new HashMap<Integer, Integer>()); segmentBeginEnd.put(sentence.getBegin(), sentence.getEnd()); segmentText.put(sentence.getBegin(), sentence.getCoveredText().toString()); segmentNumber.put(sentence.getBegin(), sentenceNumber); segmentAdress.get(username).put(sentence.getBegin(), sentence.getAddress());
/** @generated * @param jcas JCas to which this Feature Structure belongs * @param begin offset to the begin spot in the SofA * @param end offset to the end spot in the SofA */ public Sentence(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
protected void setSentence(JCas aJCas, int begin, int end) { Sentence sentence = new Sentence(aJCas, begin, end); sentence.addToIndexes(); }
public static void tokenize(JCas aJCas) { BreakIterator bi = BreakIterator.getWordInstance(Locale.US); for (Sentence s : select(aJCas, Sentence.class)) { bi.setText(s.getCoveredText()); int last = bi.first(); int cur = bi.next(); while (cur != BreakIterator.DONE) { int[] span = new int[] { last, cur }; trim(s.getCoveredText(), span); if (!isEmpty(span[0], span[1])) { Token seg = new Token(aJCas, span[0] + s.getBegin(), span[1] + s.getBegin()); seg.addToIndexes(aJCas); } last = cur; cur = bi.next(); } } }
private static JCas makeJCasOneSentence(String aText) throws UIMAException { JCas jcas = makeJCas(); TokenBuilder<Token, Sentence> tb = new TokenBuilder<>(Token.class, Sentence.class); tb.buildTokens(jcas, aText); // Remove the sentences generated by the token builder which treats the line break as a // sentence break for (Sentence s : select(jcas, Sentence.class)) { s.removeFromIndexes(); } // Add a new sentence covering the whole text new Sentence(jcas, 0, jcas.getDocumentText().length()).addToIndexes(); return jcas; }
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(); }
public int getBegin() { return uimaSentence.getBegin(); }
@Override public void setFirstVisibleUnit(Sentence aFirstVisibleUnit) { JCas jcas; try { jcas = aFirstVisibleUnit.getCAS().getJCas(); } catch (CASException e) { throw new IllegalStateException("Unable to fetch JCas from CAS", e); } firstVisibleUnitAddress = WebAnnoCasUtil.getAddr(aFirstVisibleUnit); firstVisibleUnitBegin = aFirstVisibleUnit.getBegin(); firstVisibleUnitEnd = aFirstVisibleUnit.getEnd(); Sentence lastVisibleUnit = getLastSentenceInDisplayWindow(jcas, getAddr(aFirstVisibleUnit), getPreferences().getWindowSize()); firstVisibleUnitIndex = WebAnnoCasUtil.getSentenceNumber(jcas, aFirstVisibleUnit.getBegin()); lastVisibleUnitIndex = WebAnnoCasUtil.getSentenceNumber(jcas, lastVisibleUnit.getBegin()); unitCount = select(jcas, Sentence.class).size(); windowBeginOffset = aFirstVisibleUnit.getBegin(); windowEndOffset = lastVisibleUnit.getEnd(); }
List<CoreMap> sentences = new ArrayList<>(); for (Sentence s : select(aJCas, Sentence.class)) { Annotation sentence = new Annotation(s.getCoveredText()); sentence.set(CharacterOffsetBeginAnnotation.class, s.getBegin()); sentence.set(CharacterOffsetEndAnnotation.class, s.getEnd()); sentence.set(SentenceIndexAnnotation.class, sentences.size());
@Override public boolean keepArgument(JCas jCas) { List<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class)); // remove one-sentence arguments if (sentences.size() == 1) { return false; } for (Sentence s : sentences) { if (s.getCoveredText().length() > MAX_SENTENCE_LENGTH) { return false; } } return true; } }
private void copyAnnotations(JCas jCasSrc, JCas jCasDst) { CasCopier copier = new CasCopier(jCasSrc.getCas(), jCasDst.getCas()); for (Sentence anSrc : JCasUtil.select(jCasSrc, Sentence.class)) { Sentence anDst = (Sentence) copier.copyFs(anSrc); anDst.addToIndexes(); } for (Token anSrc : JCasUtil.select(jCasSrc, Token.class)) { Token anDst = (Token) copier.copyFs(anSrc); anDst.addToIndexes(); } for (POS anSrc : JCasUtil.select(jCasSrc, POS.class)) { POS anDst = (POS) copier.copyFs(anSrc); anDst.addToIndexes(); } } }
private Annotation getAnnotationObject(JCas aJCas, String viewName, String type, Integer[] index) throws Exception{ if (type.matches(txpAnn.token)) return new Token(aJCas.getView(viewName)); if (type.matches(txpAnn.lemma)) return new Lemma(aJCas.getView(viewName)); if (type.matches(txpAnn.pos)) return getAnnotationObject(aJCas, viewName, txpAnn.getAnnotation(type).get(index), POS.class); if (type.matches(txpAnn.sentence)) return new Sentence(aJCas.getView(viewName)); if (type.matches(txpAnn.ne)) return getAnnotationObject(aJCas, viewName, txpAnn.getNEtype(index), NamedEntity.class); return new Annotation(aJCas.getView(viewName)); }
public int getEnd() { return uimaSentence.getEnd(); }
private void annotateSentence(JCas aJCas, int aBegin, int aEnd) { new Sentence(aJCas, aBegin, aEnd).addToIndexes(); }
public static void tokenize(JCas aJCas) { BreakIterator bi = BreakIterator.getWordInstance(Locale.US); for (Sentence s : select(aJCas, Sentence.class)) { bi.setText(s.getCoveredText()); int last = bi.first(); int cur = bi.next(); while (cur != BreakIterator.DONE) { int[] span = new int[] { last, cur }; trim(s.getCoveredText(), span); if (!isEmpty(span[0], span[1])) { Token seg = new Token(aJCas, span[0] + s.getBegin(), span[1] + s.getBegin()); seg.addToIndexes(aJCas); } last = cur; cur = bi.next(); } } }
/** * 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(); }
public int getBegin() { return uimaSentence.getBegin(); }
/** * <B>NOTE:</B> Must be called only after one of the conversion methods was called. * @return a mapping between a root, and the text of the tree's sentence. This is an ordered map, * ordered by the order of sentences in the text. * @throws CasTreeConverterException */ public LinkedHashMap<BasicNode, String> getTreesToSentences() throws CasTreeConverterException { if (lastRootList == null || lastSentenceList == null) { throw new CasTreeConverterException("getTreesToSentences() called before a conversion method was called."); } if (lastRootList.size() != lastSentenceList.size()) { throw new CasTreeConverterException("Internal error - lastRootList(size=" + lastRootList.size() + ") and lastSentenceList(size=" + lastSentenceList.size() + ") are in different sizes."); } LinkedHashMap<BasicNode, String> result = new LinkedHashMap<BasicNode, String>(lastRootList.size()); Iterator<Sentence> iterSentences = lastSentenceList.iterator(); for (BasicNode node : lastRootList) { Sentence sentence = iterSentences.next(); result.put(node, sentence.getCoveredText()); } return result; }