Refine search
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; }
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; } }
@SuppressWarnings("unchecked") public static <A extends AnnotationFS> A getSingleAnnotation(JCas cas, Class<A> typeJCasClass) { Type annoType = CasUtil.getAnnotationType(cas.getCas(), typeJCasClass); AnnotationIndex<Annotation> annoIdx = cas.getAnnotationIndex(annoType); if (annoIdx.size() == 0) { return null; } else if (annoIdx.size() == 1) { return (A) annoIdx.iterator().next(); } else { throw new IllegalStateException(String.format( "Too much (>1) annotations of type %s", annoType)); } }
/** * @param cas * @param type * @param feature * @return feature value of the first annotation of given type from given * CAS. E.g., it is useful to get document metadata values. If there * is no such annotation method will return null. */ public static String getStringValue(CAS cas, Type type, Feature feature) { AnnotationIndex<AnnotationFS> metaIdx = cas.getAnnotationIndex(type); if (metaIdx.size() > 0) { AnnotationFS meta = metaIdx.iterator().next(); return meta.getFeatureValueAsString(feature); } else { return null; } }
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); }
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 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; }
public static void addSourceDocumentInformation(CAS cas, File each) { Type sdiType = cas.getTypeSystem() .getType("org.apache.uima.examples.SourceDocumentInformation"); if (sdiType != null) { if (cas.getAnnotationIndex(sdiType).size() == 0) { AnnotationFS sdi = cas.createAnnotation(sdiType, cas.getDocumentAnnotation().getBegin(), cas.getDocumentAnnotation().getEnd()); Feature uriFeature = sdiType.getFeatureByBaseName("uri"); sdi.setStringValue(uriFeature, each.toURI().getPath()); cas.addFsToIndexes(sdi); } } }
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; }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { CAS cas = aJCas.getCas(); String id = getDocumentId(cas); String documentText = cas.getDocumentText(); Type eventType = cas.getTypeSystem().getType(EventMention.class.getCanonicalName()); try { if (!bioEventServiceMode) { DocumentWriter documentWriter = createDocumentWriter(id); EventWriter eventWriter = createEventWriter(documentText, id); documentWriter.write(cas.getJCas()); Iterator eventIterator = cas.getAnnotationIndex(eventType).iterator(); int i = 1; while (eventIterator.hasNext()) { Iterator eventIterator = cas.getAnnotationIndex(eventType).iterator(); int i = 1; while (eventIterator.hasNext()) {
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; }
int size = 0; try { jCas = cas.getJCas(); size = jCas.getAnnotationIndex(TokenSeed.type).size(); result = jCas.getTypeSystem().getType(seedType); } catch (CASException e1) { cas.addFsToIndexes(a); try { a = sourceLexer.yylex(); MARKUP markup = new MARKUP(jCas, begin, end); markup.addToIndexes(); FSIterator<AnnotationFS> subiterator = cas.getAnnotationIndex(result).subiterator(markup); while(subiterator.isValid()) { AnnotationFS fs = subiterator.get(); toRemove.add(fs); subiterator.moveToNext();
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; }
/** * 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; } }
private static JCas getViewWithGoldAnnotations(JCas correspondingCasThatHasGoldAnnotations) { JCas viewWithPreexistingGoldAnnotations = null; try { viewWithPreexistingGoldAnnotations = correspondingCasThatHasGoldAnnotations.getView(AssertionEvaluation.GOLD_VIEW_NAME); } catch (org.apache.uima.cas.CASRuntimeException cre) { // Let it just continue if there's an exception and check for null later } catch (org.apache.uima.cas.CASException viewException) { // Let it just continue if there's an exception and check for null later } catch (NullPointerException npe) { // Let it just continue if there's an exception and check for null later } if (viewWithPreexistingGoldAnnotations == null) { viewWithPreexistingGoldAnnotations = correspondingCasThatHasGoldAnnotations; LOGGER.debug("Using view " + viewWithPreexistingGoldAnnotations.getViewName()); int n = viewWithPreexistingGoldAnnotations.getAnnotationIndex().size(); LOGGER.debug("With " + n + " annotations"); if (n==0) { Iterator<CAS> iter = viewWithPreexistingGoldAnnotations.getCas().getViewIterator(); while (iter.hasNext()) { CAS cas = iter.next(); LOGGER.debug("view " + cas.getViewName() + " has " + cas.getAnnotationIndex().size() + " indexed annotations."); } throw new RuntimeException("n==0"); } } return viewWithPreexistingGoldAnnotations; }
@Override protected void initializeIterator() throws IOException { try { analyzeInput(); } catch (AnalysisEngineProcessException | ResourceInitializationException e) { throw new IOException(e); } finalOffset = correctOffset(cas.getDocumentText().length()); Type tokenType = cas.getTypeSystem().getType(tokenTypeString); iterator = cas.getAnnotationIndex(tokenType).iterator(); }
private String getDocumentId(CAS cas) { Header header = null; Type headerType = cas.getTypeSystem().getType(Header.class.getCanonicalName()); Iterator<org.apache.uima.jcas.tcas.Annotation> iterator; try { iterator = cas.getJCas().getAnnotationIndex(Header.type).iterator(); header = (Header) iterator.next(); } catch (CASRuntimeException e) { e.printStackTrace(); } catch (CASException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (header != null) { return header.getDocId(); } return new Integer(id++).toString(); } }
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); } }