@Override public int size() { return index.size(); } }
public long getHistogram(Type type) { return cas.getAnnotationIndex(type).size(); }
public int getHistogram(Type type) { return cas.getAnnotationIndex(type).size(); }
@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)); } }
/** * Runs the IntervalTagger on the JCAS object. * @param jcas jcas object */ private void runIntervalTagger(JCas jcas) { logger.log(Level.FINEST, "Running Interval Tagger..."); Integer beforeAnnotations = jcas.getAnnotationIndex().size(); // Prepare the options for IntervalTagger's execution Properties settings = new Properties(); settings.put(IntervalTagger.PARAM_LANGUAGE, language.getResourceFolder()); settings.put(IntervalTagger.PARAM_INTERVALS, true); settings.put(IntervalTagger.PARAM_INTERVAL_CANDIDATES, false); // Instantiate and process with IntervalTagger IntervalTaggerWrapper iTagger = new IntervalTaggerWrapper(); iTagger.initialize(settings); iTagger.process(jcas); // debug output Integer afterAnnotations = jcas.getAnnotationIndex().size(); logger.log(Level.FINEST, "Annotation delta: " + (afterAnnotations - beforeAnnotations)); }
private void saveEntities( final JCas jcas, final int encounterNum, final long patientNum, final String providerId, final Timestamp startDate ) throws SQLException { final AnnotationIndex<Annotation> identifiedsIndex = jcas.getAnnotationIndex( IdentifiedAnnotation.type ); if ( identifiedsIndex == null || identifiedsIndex.size() == 0 ) { return;
private void saveEntities( final JCas jcas, final int encounterNum, final long patientNum, final String providerId, final Timestamp startDate ) throws SQLException { final AnnotationIndex<Annotation> identifiedsIndex = jcas.getAnnotationIndex( IdentifiedAnnotation.type ); if ( identifiedsIndex == null || identifiedsIndex.size() == 0 ) { return;
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; }
private void process(CAS cas, PrintWriter out) { AnnotationIndex<AnnotationFS> tokenIdx = cas.getAnnotationIndex(tokenType); Multimap<AnnotationFS, String> tokLabelsMap = HashMultimap.create(tokenIdx.size(), 1);
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; }
/** * returns the number of annotations of specified type in the */ public static int countAnnotationsInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); ann.removeFromIndexes(); return annIdx.size(); }
/** * returns the number of annotations of specified type in the */ public static int countAnnotationsInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); ann.removeFromIndexes(); return annIdx.size(); }
/** * @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; } }
return; final Collection<String> tokenizedSentences = new ArrayList<>( sentences.size() ); try { for ( Object sentence : sentences ) {
try { jCas = cas.getJCas(); size = jCas.getAnnotationIndex(TokenSeed.type).size(); result = jCas.getTypeSystem().getType(seedType); } catch (CASException e) {
return; final Collection<String> tokenizedSentences = new ArrayList<>( sentences.size() ); try { for ( Object sentence : sentences ) {
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 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); } } }
@Override public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) { RuleElement element = context.getElement(); int count = 0; Type t = type.getType(context, stream); AnnotationIndex<Annotation> annotationIndex = stream.getJCas().getAnnotationIndex(t); count = annotationIndex.size(); if (var != null) { element.getParent().getEnvironment().setVariableValue(var, count); } boolean value = count >= min.getIntegerValue(context, stream) && count <= max.getIntegerValue(context, stream); return new EvaluatedCondition(this, value); }