public List<Feature> extract(JCas view, T focusAnnotation) throws CleartkExtractorException { List<Feature> flist = new LinkedList<Feature>(); for (Annotation anno : JCasUtil.select(view, goalClass)) { Feature f = new Feature(); f.setName("subtype"); f.setValue(anno.getType().getShortName()); flist.add(f); } return flist; }
private static String createStrRepr(final Annotation source) { return String.format("[%d, %d, %s]", source.getBegin(), source.getEnd(), source.getType().getShortName()); }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { DocumentMetaData meta = iterate(aJCas, DocumentMetaData.class).iterator().next(); System.out.println("=== METADATA ========================================"); System.out.println("URI : "+meta.getDocumentUri()); System.out.println("Language: "+aJCas.getDocumentLanguage()); System.out.println("=== TEXT ============================================"); System.out.println(aJCas.getDocumentText()); System.out.println("=== ANNOTATIONS ====================================="); for (Annotation a : iterate(aJCas, Annotation.class)) { System.out.println(a.getType().getName() + "(" + a.getBegin() + "," + a.getEnd() + ") [" + a.getCoveredText() + "]"); } } }
public RutaAnnotation getCorrectTMA(List<AnnotationFS> annotationsInWindow, RutaAnnotation heuristicAnnotation) { for (AnnotationFS annotation : annotationsInWindow) { if (annotation instanceof RutaAnnotation) { RutaAnnotation tma = (RutaAnnotation) annotation; if (tma.getBegin() == heuristicAnnotation.getBegin() && tma.getEnd() == heuristicAnnotation.getEnd() && tma.getAnnotation().getType() .equals(heuristicAnnotation.getAnnotation().getType())) { return tma; } } } return null; }
private List<Annotation> getAnnotationList(Type... annotationTypes) { List<Annotation> list = Lists.newArrayList(); FSIterator<Annotation> it = actual.getAnnotationIndex().iterator(); while(it.hasNext()) { Annotation a = it.next(); if(annotationTypes.length == 0) list.add(a); else for(Type type:annotationTypes) if(type.equals(a.getType())) list.add(a); } return list; }
@Override public Type getType() { return new Annotation(jCas).getType(); } }
@Override public String getTypeName() { if (getItem() == null) { return "Root"; } else { return getItem().getType().getShortName(); } }
public TextMarkerAnnotation getCorrectTMA(List<AnnotationFS> annotationsInWindow, TextMarkerAnnotation heuristicAnnotation) { for (AnnotationFS annotation : annotationsInWindow) { if (annotation instanceof TextMarkerAnnotation) { TextMarkerAnnotation tma = (TextMarkerAnnotation) annotation; if (tma.getBegin() == heuristicAnnotation.getBegin() && tma.getEnd() == heuristicAnnotation.getEnd() && tma.getAnnotation().getType() .equals(heuristicAnnotation.getAnnotation().getType())) { return tma; } } } return null; }
/** * @param annotation - * @return annotation type and covered text in a fhir codeable concept. */ static public CodeableConcept createSimpleCode( final org.apache.uima.jcas.tcas.Annotation annotation ) { final String type = annotation.getType() // .getShortName(); .getName(); return createSimpleCode( CODING_TYPE_SYSTEM, type, null, annotation.getCoveredText() ); }
@Override public String getTypeName() { if (getItem() == null) { return "Root"; } else { return getItem().getType().getShortName(); } }
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; }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { Set<Annotation> toDelete = null; if (deleteSource) { toDelete = new HashSet<Annotation>(); } for (Annotation anno : JCasUtil.select(jcas, sourceClass)) { Annotation newAnnotation = AnnotationFactory.createAnnotation(jcas, anno.getBegin(), anno.getEnd(), targetClass); if (deleteSource) toDelete.add(anno); if (!(targetFeatureName.isEmpty() || targetFeatureValue.isEmpty())) { Feature feature = newAnnotation.getType().getFeatureByBaseName(targetFeatureName); if (feature != null) newAnnotation.setFeatureValueFromString(feature, targetFeatureValue); } } if (deleteSource) { for (Annotation a : toDelete) { a.removeFromIndexes(); } } }
static private String getDebugText( final Annotation a ) { return a.getType().getShortName() + "(" + a.getBegin() + "-" + a.getEnd() + "): " + a.getCoveredText(); }
private static int getAnnotationId(final Annotation source, final Sparse3DObjectMatrix<String, ImmutableSpanTextLabel> spanAnnotationMatrix, final Object2IntMap<ImmutableSpanTextLabel> spanAnnotationIds) { final int begin = source.getBegin(); final int end = source.getEnd(); final String label = source.getType().getShortName(); final SpanTextLabel spanAnnotation = spanAnnotationMatrix.get3DValue(begin, end, label); return spanAnnotation == null ? -1 : spanAnnotationIds.getInt(spanAnnotation); }
private void processAnnotaion(Annotation a, Map<String, BasicDBList> dbLists, String typeName) { MongoFieldMapping fieldMapping = ALL_MAPPINGS.get(typeName); BasicDBList dbList; // getOrElseCreate if (dbLists.containsKey(fieldMapping.shortName)) { dbList = dbLists.get(fieldMapping.shortName); } else { dbList = new BasicDBList(); dbLists.put(fieldMapping.shortName, dbList); } BasicDBObject o = new BasicDBObject(); dbList.add(o); o.put(BEGIN, a.getBegin()); o.put(END, a.getEnd()); Type t = a.getType(); for (Feature f : t.getFeatures()) { if (fieldMapping.fieldMappings.containsKey(f.getShortName())) { String dbKey = fieldMapping.fieldMappings.get(f.getShortName()); MongoFieldMapping.writeFieldToDb(f.getRange().getShortName(), o, a, dbKey, f); } } } }
@Override public ImmutableSpanTextLabel apply(final Annotation annotation) { final ImmutableSpan span = new ImmutableSpan(annotation.getBegin(), annotation.getEnd()); final ImmutableSpanText spanText = new ImmutableSpanText(span, annotation.getCoveredText()); final Map<Attribute, Object> attrs = createAttrMap(annotation); return new ImmutableSpanTextLabel(spanText, annotation.getType().getShortName(), attrs); }
/** * Add an annotation to the JCas index, notifying UimaMonitor of the fact we have done so * * @param annot Annotation(s) to add */ public void add(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { annot.addToIndexes(); monitor.entityAdded(annot.getType().getName()); if (annot instanceof Entity) { Entity entity = (Entity) annot; // Add in a value if it doesn't have one if (Strings.isNullOrEmpty(entity.getValue())) { entity.setValue(annot.getCoveredText()); } addToHistory(annot.getCAS(), HistoryEvents.createAdded((Recordable) annot, referrer)); } } }
/** * Add an annotation to the JCas index, notifying UimaMonitor of the fact we have done so * * @param annot Annotation(s) to add */ public void add(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { annot.addToIndexes(); monitor.entityAdded(annot.getType().getName()); if (annot instanceof Entity) { Entity entity = (Entity) annot; // Add in a value if it doesn't have one if (Strings.isNullOrEmpty(entity.getValue())) { entity.setValue(annot.getCoveredText()); } addToHistory(annot.getCAS(), HistoryEvents.createAdded((Recordable) annot, referrer)); } } }
@Test public void testRecordable() throws UIMAException { JCas jCas = JCasFactory.createJCas(); FakeRecordable fakeRecordable = new FakeRecordable(jCas); assertEquals(new Annotation(jCas).getType().getName(), fakeRecordable.getTypeName()); }