protected void buildSentenceToTokenNumberMap() { sentenceToTokenNumberMap = new HashMap<Sentence, List<BaseToken>>(); for (Sentence s : beginTreeMap.values()) { FSIterator<Annotation> tokensInSentenceIterator = jcas .getAnnotationIndex(BaseToken.type).subiterator(s); List<BaseToken> btList = new ArrayList<BaseToken>(); BaseToken bt = null; while ((bt = this.getNextNonEOLToken(tokensInSentenceIterator)) != null) { btList.add(bt); } sentenceToTokenNumberMap.put(s, btList); } }
protected void buildSentenceToTokenNumberMap() { sentenceToTokenNumberMap = new HashMap<Sentence, List<BaseToken>>(); for (Sentence s : beginTreeMap.values()) { FSIterator<Annotation> tokensInSentenceIterator = jcas .getAnnotationIndex(BaseToken.type).subiterator(s); List<BaseToken> btList = new ArrayList<BaseToken>(); BaseToken bt = null; while ((bt = this.getNextNonEOLToken(tokensInSentenceIterator)) != null) { btList.add(bt); } sentenceToTokenNumberMap.put(s, btList); } }
/** * Gets a list of annotations within the specified window annotation. * // * @param annotItr * @param jCas * @param window * @return * @throws Exception */ private List<Annotation> constrainToWindow(JCas jCas, int type, Annotation window) { List<Annotation> list = new ArrayList<Annotation>(); FSIterator subiterator = jCas.getAnnotationIndex(type).subiterator(window); while (subiterator.hasNext()) { Annotation annot = (Annotation) subiterator.next(); list.add(annot); } return list; }
/** * Gets a list of annotations within the specified window annotation. * // * @param annotItr * @param jCas * @param window * @return * @throws Exception */ private List<Annotation> constrainToWindow(JCas jCas, int type, Annotation window) { List<Annotation> list = new ArrayList<Annotation>(); FSIterator subiterator = jCas.getAnnotationIndex(type).subiterator(window); while (subiterator.hasNext()) { Annotation annot = (Annotation) subiterator.next(); list.add(annot); } return list; }
public static FeatureStructure[] getDebugLogicalStructure_SubAnnotations(AnnotationFS fs) { // uses sub iterators - may cause apparant skipping of initial annotations due to type // priorities. return getIndexContents(fs.getCAS().getAnnotationIndex().subiterator(fs)); // built-in // annotation // index }
protected List<Annotation> getMiddleScopeContextAnnotations(JCas jCas, Annotation focus) throws AnalysisEngineProcessException { List<Annotation> scopeContextAnnotations = new ArrayList<Annotation>(); FSIterator subiterator = jCas.getAnnotationIndex(contextType).subiterator(focus); while (subiterator.hasNext()) { scopeContextAnnotations.add((Annotation) subiterator.next()); } if (scopeContextAnnotations.size() == 0 && JCasUtil.getType(focus.getClass()) == contextType) scopeContextAnnotations.add(focus); else if (scopeContextAnnotations.size() == 0) { TypeSystem typeSystem = jCas.getTypeSystem(); Type superType = jCas.getType(focusType).casType; Type subType = focus.getType(); if (typeSystem.subsumes(superType, subType)) scopeContextAnnotations.add(focus); } return scopeContextAnnotations; }
protected List<Annotation> getMiddleScopeContextAnnotations(JCas jCas, Annotation focus) throws AnalysisEngineProcessException { List<Annotation> scopeContextAnnotations = new ArrayList<Annotation>(); FSIterator subiterator = jCas.getAnnotationIndex(contextType).subiterator(focus); while (subiterator.hasNext()) { scopeContextAnnotations.add((Annotation) subiterator.next()); } if (scopeContextAnnotations.size() == 0 && JCasUtil.getType(focus.getClass()) == contextType) scopeContextAnnotations.add(focus); else if (scopeContextAnnotations.size() == 0) { TypeSystem typeSystem = jCas.getTypeSystem(); Type superType = jCas.getType(focusType).casType; Type subType = focus.getType(); if (typeSystem.subsumes(superType, subType)) scopeContextAnnotations.add(focus); } return scopeContextAnnotations; }
public List<RutaBasic> getBasicsInWindow(AnnotationFS windowAnnotation) { List<RutaBasic> result = new ArrayList<RutaBasic>(); if (windowAnnotation instanceof RutaBasic) { result.add((RutaBasic) windowAnnotation); return result; } FSMatchConstraint defaultConstraint = filter.getDefaultConstraint(); FSIterator<AnnotationFS> iterator = cas.createFilteredIterator( cas.getAnnotationIndex(basicType).subiterator(windowAnnotation), defaultConstraint); while (iterator.isValid()) { result.add((RutaBasic) iterator.get()); iterator.moveToNext(); } return result; }
public List<TextMarkerBasic> getBasicsInWindow(AnnotationFS windowAnnotation) { List<TextMarkerBasic> result = new ArrayList<TextMarkerBasic>(); if (windowAnnotation instanceof TextMarkerBasic) { result.add((TextMarkerBasic) windowAnnotation); return result; } FSMatchConstraint defaultConstraint = filter.getDefaultConstraint(); FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(cas .getAnnotationIndex(basicType).subiterator(windowAnnotation), defaultConstraint); while (iterator.isValid()) { result.add((TextMarkerBasic) iterator.get()); iterator.moveToNext(); } return result; }
private void divideAnnotation(AnnotationFS annotation) { Objects.requireNonNull(typeToCreate); Objects.requireNonNull(dividers); FSIterator<AnnotationFS> subiterator = dividers.subiterator(annotation); int begin = annotation.getBegin(); while (subiterator.hasNext()) { int end = subiterator.next().getBegin(); cas.addFsToIndexes(cas.createAnnotation(typeToCreate, begin, end)); begin = end; } }
private void updateIterators(CAS cas, Type basicType, FilterManager filter, AnnotationFS additionalWindow) { if (additionalWindow != null) { this.basicIt = cas.getAnnotationIndex(basicType).subiterator(additionalWindow); } else { this.basicIt = cas.getAnnotationIndex(basicType).iterator(); } currentIt = filter.createFilteredIterator(cas, basicType); }
/** * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected */ public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); FSIterator<?> itr = annIdx.subiterator(ann); ann.removeFromIndexes(); return itr; }
private void updateIterators(CAS cas, Type basicType, FilterManager filter, AnnotationFS additionalWindow) { if (additionalWindow != null) { this.basicIt = cas.getAnnotationIndex(basicType).subiterator(additionalWindow); } else { this.basicIt = cas.getAnnotationIndex(basicType).iterator(); } currentIt = filter.createFilteredIterator(cas, basicType); }
/** * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected */ public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); FSIterator<?> itr = annIdx.subiterator(ann); ann.removeFromIndexes(); return itr; }
/** * Convenience method to get a sub-iterator for the specified type. * * @param <T> * the iteration type. * @param container * the containing annotation. * @param type * the type. * @param ambiguous * If set to <code>false</code>, resulting iterator will be unambiguous. * @param strict * Controls if annotations that overlap to the right are considered in or out. * @return A sub-iterator. * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a> */ @SuppressWarnings("unchecked") public static <T extends AnnotationFS> Iterator<T> iterator(AnnotationFS container, Class<T> type, boolean ambiguous, boolean strict) { CAS cas = container.getCAS(); return ((AnnotationIndex<T>) cas.getAnnotationIndex(CasUtil.getType(cas, type))).subiterator( container, ambiguous, strict); }
public FSIterator<AnnotationFS> createFilteredIterator(CAS cas, Type basicType) { if (windowAnnotation != null) { FSIterator<AnnotationFS> windowIt = cas.getAnnotationIndex(basicType) .subiterator(windowAnnotation); FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(windowIt, createCurrentConstraint(false)); return iterator; } else { FSIterator<AnnotationFS> iterator = cas.createFilteredIterator( cas.getAnnotationIndex(basicType).iterator(), createCurrentConstraint(false)); return iterator; } }
public FSIterator<AnnotationFS> createFilteredIterator(CAS cas, Type basicType) { if (windowAnnotation != null) { FSIterator<AnnotationFS> windowIt = cas.getAnnotationIndex(basicType).subiterator( windowAnnotation); FSIterator<AnnotationFS> iterator = cas.createFilteredIterator(windowIt, createCurrentConstraint(false)); return iterator; } else { FSIterator<AnnotationFS> iterator = cas.createFilteredIterator( cas.getAnnotationIndex(basicType).iterator(), createCurrentConstraint(false)); return iterator; } }
private void negateAnnotations(JCas aJCas, AnnotationIndex sentenceIdx, AnnotationIndex targetIdx, TargetAnnoFilter filter) { FSIterator sentenceIter = sentenceIdx.iterator(); while (sentenceIter.hasNext()) { Sentence s = (Sentence) sentenceIter.next(); FSIterator neIter = targetIdx.subiterator(s); while (neIter.hasNext()) { Annotation ne = (Annotation) neIter.next(); if (filter == null || filter.filter(ne)) checkNegation(aJCas, s, ne); // checkNegation2(aJCas, s, ne); } } }
private void negateAnnotations(JCas aJCas, AnnotationIndex sentenceIdx, AnnotationIndex targetIdx, TargetAnnoFilter filter) { FSIterator sentenceIter = sentenceIdx.iterator(); while (sentenceIter.hasNext()) { Sentence s = (Sentence) sentenceIter.next(); FSIterator neIter = targetIdx.subiterator(s); while (neIter.hasNext()) { Annotation ne = (Annotation) neIter.next(); if (filter == null || filter.filter(ne)) checkNegation(aJCas, s, ne); // checkNegation2(aJCas, s, ne); } } }
private void addHeadAnnotation(Constituent cons, Span headSpan) throws CASRuntimeException, CASException { FSIterator tokens = cons.getCAS().getJCas().getAnnotationIndex(Token.type).subiterator(cons); int headStart = offsetMap.getMapping(headSpan.getStart()); int headEnd = offsetMap.getMapping(headSpan.getEnd()); while (tokens.hasNext()) { Token token = (Token) tokens.next(); if (token.getBegin() == headStart && token.getEnd() == headEnd) { cons.setHead(token); tokens.moveToLast(); tokens.next(); } } }