allRemoveAnnotations.iterator(), containingConstraint);
@Override protected void setBestCategory(CAS tcas, String bestCategory) { FSIndex<AnnotationFS> categoryIndex = tcas.getAnnotationIndex(mCategoryType); AnnotationFS categoryAnnotation; if (categoryIndex.size() > 0) { categoryAnnotation = categoryIndex.iterator().next(); } else { categoryAnnotation = tcas.createAnnotation(mCategoryType, 0, tcas.getDocumentText().length()); tcas.getIndexRepository().addFS(categoryAnnotation); } categoryAnnotation.setStringValue(mCategoryFeature, bestCategory); } }
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); } }
@Override public FSIterator<T> iterator() { return (FSIterator<T>) this.index.iterator(); }
@Override public FSIterator<T> iterator(FeatureStructure fs) { return (FSIterator<T>) this.index.iterator(fs); }
@Override public Iterator<T> iterator() { return index.withSnapshotIterators().iterator(); }
@Override @SuppressWarnings("unchecked") public FSIterator<SofaFS> getSofaIterator() { FSIndex<SofaFS> sofaIndex = (FSIndex<SofaFS>) ( FSIndex<?>) this.svd.baseCAS.indexRepository.getIndex(CAS.SOFA_INDEX_NAME); return sofaIndex.iterator(); }
@Override public FSIterator<T> iterator(boolean ambiguous) { if (ambiguous) { return (FSIterator<T>) this.index.iterator(); } // return non-constrained, non-strict, unambiguous iterator boolean strict = false; boolean isBounded = false; return new Subiterator<T>(this.index.iterator(), null, 0, 0, ambiguous, strict, isBounded, ((FSIndexRepositoryImpl.IndexImpl<T>)(this.index)).getFsRepositoryImpl()); }
private static FeatureStructure[] getIndexContents(FSIndex<? extends FeatureStructure> fsIndex) { return getIndexContents(fsIndex.iterator()); }
private void removeOverlap(JCas jCas) { HashMap<String, IntervalST> typeSpanMap = new HashMap<>(); FSIndex annoIndex = jCas.getAnnotationIndex(); Iterator annoIter = annoIndex.iterator(); while (annoIter.hasNext()) { Object obj = annoIter.next(); String typeName = obj.getClass().getCanonicalName(); IntervalST thisSpanTree = typeSpanMap.getOrDefault(typeName, new IntervalST()); checkOverlap(thisSpanTree, (Annotation) obj); } }
@Override public FSIterator<T> subiterator(AnnotationFS annot, boolean ambiguous, boolean strict) { boolean isBounded = true; return new Subiterator<T>(this.index.iterator(), annot, 0, 0, ambiguous, strict, isBounded, ((FSIndexRepositoryImpl.IndexImpl<T>)(this.index)).getFsRepositoryImpl()); }
private void processSentence(CAS tcas, AnnotationFS sentence) { FSIndex<AnnotationFS> chunkIndex = tcas.getAnnotationIndex(mChunkType); ContainingConstraint containingConstraint = new ContainingConstraint(sentence); Iterator<AnnotationFS> chunkIterator = tcas.createFilteredIterator( chunkIndex.iterator(), containingConstraint); while (chunkIterator.hasNext()) { AnnotationFS chunkAnnotation = (AnnotationFS) chunkIterator.next(); processChunk(tcas, (chunkAnnotation)); } }
private void indexAnnotations(JCas jCas) { for (Class conceptType : evidenceAnnotationTree.keySet()) { FSIndex annoIndex = jCas.getAnnotationIndex(conceptType); Iterator annoIter = annoIndex.iterator(); IntervalST<Annotation> intervalST = new IntervalST<>(); while (annoIter.hasNext()) { Annotation anno = (Annotation) annoIter.next(); intervalST.put(new Interval1D(anno.getBegin(), anno.getEnd()), anno); } evidenceAnnotationTree.put(conceptType, intervalST); } }
private void indexScopes(JCas jCas) { scopes.clear(); for (Class scopeClass : scopeIndex.values()) { FSIndex annoIndex = jCas.getAnnotationIndex(scopeClass); FSIterator annoIter = annoIndex.iterator(); IntervalST<Annotation> scopeTree = new IntervalST<>(); while (annoIter.hasNext()) { Annotation scopeAnnotation = (Annotation) annoIter.next(); scopeTree.put(new Interval1D(scopeAnnotation.getBegin(), scopeAnnotation.getEnd()), scopeAnnotation); } scopes.put(scopeClass, scopeTree); } }
/** * Retrieves annotations of the given type from the {@link CAS}. * * @param type the type * @return the annotations */ @Override public Collection<AnnotationFS> getAnnotations(Type type) { FSIndex<AnnotationFS> annotationIndex = mCAS.getAnnotationIndex(type); StrictTypeConstraint typeConstrain = new StrictTypeConstraint(type); FSIterator<AnnotationFS> strictTypeIterator = mCAS .createFilteredIterator(annotationIndex.iterator(), typeConstrain); return fsIteratorToCollection(strictTypeIterator); }
public void processCas(CAS cas) throws ResourceProcessException { FSIndex categoryIndex = cas.getAnnotationIndex(mCategoryType); if (categoryIndex.size() > 0) { AnnotationFS categoryAnnotation = (AnnotationFS) categoryIndex.iterator().next(); // add to event collection DocumentSample sample = new DocumentSample( categoryAnnotation.getStringValue(mCategoryFeature), cas.getDocumentText()); documentSamples.add(sample); } }
@Override public void actionPerformed(ActionEvent event) { String title = this.main.getIndexLabel() + " - " + this.main.getIndex().getType().getName(); MultiAnnotViewerFrame f = new MultiAnnotViewerFrame(title); f.addWindowListener(new CloseAnnotationViewHandler(this.main)); FSIterator it = this.main.getIndex().iterator(); final String text = this.main.getCas().getDocumentText(); System.out.println("Creating extents."); AnnotationExtent[] extents = MultiMarkup.createAnnotationMarkups(it, text.length(), this.main .getStyleMap()); System.out.println("Initializing text frame."); f.init(text, extents, this.main.getDimension(MainFrame.annotViewSizePref)); System.out.println("Done."); }
@Override protected void setBestCategory(CAS tcas, String bestCategory) { FSIndex<AnnotationFS> categoryIndex = tcas.getAnnotationIndex(mCategoryType); AnnotationFS categoryAnnotation; if (categoryIndex.size() > 0) { categoryAnnotation = categoryIndex.iterator().next(); } else { categoryAnnotation = tcas.createAnnotation(mCategoryType, 0, tcas.getDocumentText().length()); tcas.getIndexRepository().addFS(categoryAnnotation); } categoryAnnotation.setStringValue(mCategoryFeature, bestCategory); } }
public static IntervalST<Integer> indexAnnotation(JCas jcas, int typeId, ArrayList<Annotation> annotations) { FSIndex annoIndex = jcas.getAnnotationIndex(typeId); FSIterator annoIter = annoIndex.iterator(); IntervalST<Integer> index = new IntervalST<>(); int i = 0; while (annoIter.hasNext()) { Annotation annotation = (Annotation) annoIter.next(); annotations.add(annotation); // assume there is no overlapping annotations index.put(new Interval1D(annotation.getBegin(), annotation.getEnd()), i); i++; } return index; }
public static IntervalST<Annotation> indexAnnotation(JCas jcas, int typeId) { FSIndex annoIndex = jcas.getAnnotationIndex(typeId); FSIterator annoIter = annoIndex.iterator(); IntervalST<Annotation> index = new IntervalST<>(); while (annoIter.hasNext()) { Annotation annotation = (Annotation) annoIter.next(); // assume there is no overlapping annotations index.put(new Interval1D(annotation.getBegin(), annotation.getEnd()), annotation); } return index; }