Refine search
private void addChunkAnnotation(CAS tcas, AnnotationFS[] tokenAnnotations, String tag, int start, int end) { AnnotationFS chunk = tcas.createAnnotation(mChunkType, tokenAnnotations[start].getBegin(), tokenAnnotations[end - 1].getEnd()); chunk.setStringValue(mChunkFeature, tag); tcas.getIndexRepository().addFS(chunk); }
public AnnotationIteratorPair next() { if (!this.upperIt.hasNext()) { throw new NoSuchElementException(); } final AnnotationFS upperFS = this.upperIt.next(); this.upperBegin = upperFS.getBegin(); this.upperEnd = upperFS.getEnd(); this.nextLowerChecked = false; return new AnnotationIteratorPair(upperFS, new AnnotationIterator()); }
public boolean hasNext() { if (AnnotationComboIterator.this.nextLowerChecked) { return AnnotationComboIterator.this.nextLowerAvailable; } AnnotationComboIterator.this.nextLowerChecked = true; AnnotationComboIterator.this.nextLowerAvailable = false; if (AnnotationComboIterator.this.lowerIt.isValid()) { AnnotationFS lowerFS = AnnotationComboIterator.this.lowerIt.get(); int lowerBegin = lowerFS.getBegin(); while (lowerBegin < AnnotationComboIterator.this.upperBegin) { AnnotationComboIterator.this.lowerIt.moveToNext(); if (AnnotationComboIterator.this.lowerIt.isValid()) { lowerFS = AnnotationComboIterator.this.lowerIt.get(); lowerBegin = lowerFS.getBegin(); } else { return false; } } if (AnnotationComboIterator.this.upperEnd >= lowerFS.getEnd()) { AnnotationComboIterator.this.nextLowerAvailable = true; } } return AnnotationComboIterator.this.nextLowerAvailable; }
protected void process(CAS cas, AnnotationFS sentenceAnnotation) { FSIndex<AnnotationFS> allTokens = cas.getAnnotationIndex(mTokenType); ContainingConstraint containingConstraint = new ContainingConstraint(sentenceAnnotation); String sentence = sentenceAnnotation.getCoveredText(); Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator( allTokens.iterator(), containingConstraint); List<Span> tokenSpans = new LinkedList<>(); while (containingTokens.hasNext()) { AnnotationFS token = containingTokens.next(); tokenSpans.add(new Span(token.getBegin() - sentenceAnnotation.getBegin(), token.getEnd() - sentenceAnnotation.getBegin())); } ParseConverter converter = new ParseConverter(sentence, tokenSpans.toArray(new Span[tokenSpans.size()])); Parse unparsedTree = converter.getParseForTagger(); if (unparsedTree.getChildCount() > 0) { Parse parse = mParser.parse(unparsedTree); // TODO: We need a strategy to handle the case that a full // parse could not be found. What to do in this case? parse = converter.transformParseFromTagger(parse); if (mLogger.isLoggable(Level.INFO)) { StringBuffer parseString = new StringBuffer(); parse.show(parseString); mLogger.log(Level.INFO, parseString.toString()); } createAnnotation(cas, sentenceAnnotation.getBegin(), parse); } }
/** * Create a new combo iterator. * * @param cas * The CAS we're operating on. * @param upper * The type of the upper iterator, e.g., sentence. * @param lower * The type of the lower iterator, e.g., token. */ public AnnotationComboIterator(CAS cas, Type upper, Type lower) { this.upperIt = cas.getAnnotationIndex(upper).iterator(); this.lowerIt = cas.getAnnotationIndex(lower).iterator(); this.upperIt.moveToFirst(); this.lowerIt.moveToFirst(); if (this.upperIt.isValid()) { final AnnotationFS upperFS = this.upperIt.get(); this.upperBegin = upperFS.getBegin(); this.upperEnd = upperFS.getEnd(); } else { this.nextLowerChecked = true; } }
public static List<AnnotationFS> selectAt(CAS aJcas, final Type type, int aBegin, int aEnd) { List<AnnotationFS> covered = CasUtil.selectCovered(aJcas, type, aBegin, aEnd); // Remove all that do not have the exact same offset covered.removeIf(cur -> !(cur.getBegin() == aBegin && cur.getEnd() == aEnd)); return covered; }
public static List<AnnotationFS> selectAt(CAS aJcas, final Type type, int aBegin, int aEnd) { List<AnnotationFS> covered = CasUtil.selectCovered(aJcas, type, aBegin, aEnd); // Remove all that do not have the exact same offset covered.removeIf(cur -> !(cur.getBegin() == aBegin && cur.getEnd() == aEnd)); return covered; }
public static List<AnnotationFS> selectAt(CAS aJcas, final Type type, int aBegin, int aEnd) { List<AnnotationFS> covered = CasUtil.selectCovered(aJcas, type, aBegin, aEnd); // Remove all that do not have the exact same offset covered.removeIf(cur -> !(cur.getBegin() == aBegin && cur.getEnd() == aEnd)); return covered; }