Refine search
public void process(CAS cas) { FSIterator<AnnotationFS> tokenAnnotations = cas.getAnnotationIndex(mTokenType).iterator(); List<String> tokensList = new ArrayList<>(); while (tokenAnnotations.hasNext()) { tokensList.add(tokenAnnotations.next().getCoveredText()); } double[] result = mCategorizer.categorize(tokensList.toArray(new String[tokensList.size()])); String bestCategory = mCategorizer.getBestCategory(result); setBestCategory(cas, bestCategory); } }
/** * 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 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; }
public AnnotationFS next() { if (AnnotationComboIterator.this.nextLowerChecked) { if (!AnnotationComboIterator.this.nextLowerAvailable) { throw new NoSuchElementException(); } } else if (!hasNext()) { throw new NoSuchElementException(); } AnnotationComboIterator.this.nextLowerChecked = false; final AnnotationFS rv = AnnotationComboIterator.this.lowerIt.get(); AnnotationComboIterator.this.lowerIt.moveToNext(); return rv; }
private File getOutputFile(CAS cas) { if (StringUtils.isBlank(outputLocation)) { return null; } Type sdiType = cas.getTypeSystem().getType(RutaEngine.SOURCE_DOCUMENT_INFORMATION); String filename = "output.modified.html"; File file = new File(outputLocation, filename); if (sdiType != null) { FSIterator<AnnotationFS> sdiit = cas.getAnnotationIndex(sdiType).iterator(); if (sdiit.isValid()) { AnnotationFS annotationFS = sdiit.get(); Feature uriFeature = sdiType.getFeatureByBaseName("uri"); String stringValue = annotationFS.getStringValue(uriFeature); File f = new File(stringValue); String name = f.getName(); if (!name.endsWith(".modified.html")) { name = name + ".modified.html"; } file = new File(outputLocation, name); } } return file; }
public static Annotation getFirst(JCas jcas, Type type) { AnnotationIndex<Annotation> index = jcas.getAnnotationIndex(type); FSIterator<Annotation> iterator = index.iterator(); if (iterator.hasNext()) return (Annotation) iterator.next(); return null; }
public static FeatureStructure getTcasFS(CAS aCasView, String aTypeS) { org.apache.uima.cas.FeatureStructure idFS = null; Type type = aCasView.getTypeSystem().getType(aTypeS); if (type != null) { FSIterator<AnnotationFS> idIter = aCasView.getAnnotationIndex(type).iterator(); while (idIter.isValid()) { idFS = idIter.get(); idIter.moveToNext(); } } return idFS; }
private List<AnnotationFS> getAnnotationsInWindow2(AnnotationFS windowAnnotation, Type type) { List<AnnotationFS> result = new ArrayList<AnnotationFS>(); windowAnnotation = cas.createAnnotation(type, windowAnnotation.getBegin(), windowAnnotation.getEnd() + 1); FSIterator<AnnotationFS> completeIt = getCas().getAnnotationIndex(type).iterator(); if (getDocumentAnnotation().getEnd() < windowAnnotation.getEnd()) { completeIt.moveToLast(); } else { completeIt.moveTo(windowAnnotation); while (completeIt.isValid() && ((Annotation) completeIt.get()).getBegin() >= windowAnnotation.getBegin()) { completeIt.moveToPrevious(); if (completeIt.isValid()) { completeIt.moveToNext(); } else { completeIt.moveToFirst(); while (completeIt.isValid() && ((Annotation) completeIt.get()).getBegin() < windowAnnotation.getBegin()) { completeIt.moveToNext(); while (completeIt.isValid() && ((Annotation) completeIt.get()).getBegin() >= windowAnnotation.getBegin()) { Annotation annotation = (Annotation) completeIt.get(); if (getCas().getTypeSystem().subsumes(type, annotation.getType()) && annotation.getEnd() <= windowAnnotation.getEnd()) { result.add(annotation);
public static ArrayList<BaseToken> selectBaseToken (JCas jcas) { ArrayList<BaseToken> ret = new ArrayList<BaseToken>(); FSIterator<?> iter = jcas.getJFSIndexRepository().getAnnotationIndex(BaseToken.type).iterator(); while (iter.hasNext()) ret.add((BaseToken)iter.next()); java.util.Collections.sort(ret, new AnnotOffsetComparator()); return ret; }
public Collection<AnnotationFS> getAnnotations(Type type) { Collection<AnnotationFS> result = new LinkedList<AnnotationFS>(); AnnotationFS windowAnnotation = filter.getWindowAnnotation(); if (windowAnnotation != null && (windowAnnotation.getBegin() != cas.getDocumentAnnotation().getBegin() || windowAnnotation.getEnd() != cas.getDocumentAnnotation().getEnd())) { AnnotationFS frame = cas.createAnnotation(cas.getTypeSystem().getType(RutaEngine.FRAME_TYPE), windowAnnotation.getBegin(), windowAnnotation.getEnd()); FSIterator<AnnotationFS> subiterator = cas.getAnnotationIndex(type).subiterator(frame); while (subiterator.hasNext()) { AnnotationFS each = subiterator.next(); if (isVisible(each)) { result.add(each); } } } else { AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex(type); for (AnnotationFS each : annotationIndex) { if (isVisible(each)) { result.add(each); } } } return result; }
public static Annotation getFirst(JCas jcas, String typeName) { TypeSystem ts = jcas.getTypeSystem(); Type type = ts.getType(typeName); AnnotationIndex<Annotation> index = jcas.getAnnotationIndex(type); FSIterator<Annotation> iterator = index.iterator(); if (iterator.hasNext()) { return (Annotation) iterator.next(); } return null; }
public List<AnnotationFS> getOverappingAnnotations(AnnotationFS window, Type type) { List<AnnotationFS> result = new ArrayList<AnnotationFS>(); AnnotationFS newWindow = cas.createAnnotation(type, window.getBegin(), window.getEnd() - 1); FSIterator<AnnotationFS> iterator = cas.getAnnotationIndex(type).iterator(newWindow); if (!iterator.isValid()) { iterator.moveToLast(); } while (iterator.isValid()) { FeatureStructure fs = iterator.get(); if (fs instanceof AnnotationFS) { AnnotationFS a = (AnnotationFS) fs; if (a.getEnd() >= window.getEnd() && a.getBegin() <= window.getBegin()) { result.add(a); } } iterator.moveToPrevious(); } return result; }
public static boolean areAdjoining(Token t1, Token t2) { JCas jCas = getJCas(t1); FSIterator<Annotation> tokenIter = jCas.getAnnotationIndex(Token.typeIndexID).iterator(); tokenIter.moveTo(t1); assert (t1.equals(tokenIter.get())); tokenIter.moveToNext(); return tokenIter.isValid() && tokenIter.get().equals(t2); }
private boolean check(AnnotationFS annotation, RutaStream stream, Type t) { boolean result = false; FSIterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(t).iterator(annotation); while (it.isValid()) { AnnotationFS a = it.get(); if (a.getEnd() >= annotation.getBegin()) { result = true; break; } it.moveToNext(); } return result; }
nameAnnotationTypeNodeMap.clear(); TypeSystem typeSystem = mInputDocument.getCAS().getTypeSystem(); List<Type> types = typeSystem.getProperlySubsumedTypes( typeSystem.getType(CAS.TYPE_NAME_ANNOTATION)); types.add(typeSystem.getType(CAS.TYPE_NAME_ANNOTATION)); AnnotationIndex<AnnotationFS> index = cas.getAnnotationIndex(type); for (FSIterator<AnnotationFS> it = index.iterator(); it.hasNext(); ) { AnnotationFS annotation = it.next(); if (annotation.getType().equals(type)) { typeNode.add(new AnnotationTreeNode(mInputDocument, annotation));
/** * search for a {@link DocumentMetadata} annotation in given CAS and return * its 'sourceUri' feature value * * @param cas * @return sourceUri value or null if there is no a DocumentMetadata * annotation */ public static String getDocumentUri(CAS cas) { TypeSystem ts = cas.getTypeSystem(); Type docMetaType = ts.getType(getMetadataTypeName()); if (docMetaType == null) { return null; } Feature sourceUriFeat; try { sourceUriFeat = featureExist(docMetaType, "sourceUri"); } catch (AnalysisEngineProcessException e) { throw new IllegalStateException(e); } FSIterator<AnnotationFS> dmIter = cas.getAnnotationIndex(docMetaType).iterator(); if (dmIter.hasNext()) { AnnotationFS docMeta = dmIter.next(); return docMeta.getStringValue(sourceUriFeat); } else { return null; } }
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 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()); }
private boolean check(AnnotationFS annotation, TextMarkerStream stream, Type t) { boolean result = false; FSIterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(t).iterator(annotation); if (!it.isValid()) { it.moveToLast(); } while (it.isValid()) { AnnotationFS a = (AnnotationFS) it.get(); if (a.getBegin() <= annotation.getBegin()) { result = true; break; } it.moveToPrevious(); } return result; }
@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); } }