private Entity( final IdentifiedAnnotation annotation ) { _begin = annotation.getBegin(); _end = annotation.getEnd(); _coveredText = annotation.getCoveredText(); _polarity = annotation.getPolarity(); _uncertainty = annotation.getUncertainty(); _conditional = annotation.getConditional(); _generic = annotation.getGeneric(); _subject = annotation.getSubject(); _historyOf = annotation.getHistoryOf(); }
IdentifiedAnnotation m = (IdentifiedAnnotation) ctor.newInstance(jCas); m.setBegin(mention.getBegin()); m.setEnd(mention.getEnd()); for (Selector s : msg.keySet()) { if (!hypothAttr.contains(s)) { switch (s) { case CONDITIONAL: m.setConditional(mention.getConditional()); break; case GENERIC: m.setGeneric(mention.getGeneric()); break; case HISTORYOF: m.setHistoryOf(mention.getHistoryOf()); break; case POLARITY: m.setPolarity(mention.getPolarity()); break; case SUBJECT: m.setSubject(mention.getSubject()); break; case UNCERTAINTY: m.setUncertainty(mention.getUncertainty()); break; m.addToIndexes(jCas);
String value = null; if (property == CTAKESAnnotationProperty.BEGIN) { value = Integer.toString(annotation.getBegin()); } else if (property == CTAKESAnnotationProperty.END) { value = Integer.toString(annotation.getEnd()); } else if (property == CTAKESAnnotationProperty.CONDITIONAL) { value = Boolean.toString(annotation.getConditional()); } else if (property == CTAKESAnnotationProperty.CONFIDENCE) { value = Float.toString(annotation.getConfidence()); } else if (property == CTAKESAnnotationProperty.DISCOVERY_TECNIQUE) { value = Integer.toString(annotation.getDiscoveryTechnique()); } else if (property == CTAKESAnnotationProperty.GENERIC) { value = Boolean.toString(annotation.getGeneric()); } else if (property == CTAKESAnnotationProperty.HISTORY_OF) { value = Integer.toString(annotation.getHistoryOf()); } else if (property == CTAKESAnnotationProperty.ID) { value = Integer.toString(annotation.getId()); } else if (property == CTAKESAnnotationProperty.ONTOLOGY_CONCEPT_ARR) { FSArray mentions = annotation.getOntologyConceptArr(); StringBuilder sb = new StringBuilder(); if (mentions != null) { String polarity_pref = "POLARITY"; value = new StringBuilder(polarity_pref).append("="). append(Integer.toString(annotation.getPolarity())).toString();
IdentifiedAnnotation annotation = iterator.next(); StringBuilder annotationBuilder = new StringBuilder(); annotationBuilder.append(annotation.getCoveredText()); if (annotationPros != null) { for (CTAKESAnnotationProperty property : annotationPros) { metadata.add(CTAKES_META_PREFIX + annotation.getType().getShortName(), annotationBuilder.toString());
mention.setBegin(original.getBegin()); mention.setEnd(original.getEnd()); mention.setConditional(original.getConditional()); mention.setConfidence(original.getConfidence()); mention.setDiscoveryTechnique(original.getDiscoveryTechnique()); mention.setGeneric(original.getGeneric()); mention.setOntologyConceptArr(original.getOntologyConceptArr()); mention.setPolarity(original.getPolarity()); mention.setSegmentID(original.getSegmentID()); mention.setSentenceID(original.getSentenceID()); mention.setSubject(original.getSubject()); mention.setTypeID(original.getTypeID()); mention.setUncertainty(original.getUncertainty()); mention.setHistoryOf(original.getHistoryOf()); mention.addToIndexes();
/** * * @param goldAnnotation * @param jcas */ private static void copyAnnotation(Annotation goldAnnotation, JCas jcas) { Annotation newAnno; if (goldAnnotation instanceof IdentifiedAnnotation) { IdentifiedAnnotation ia = new IdentifiedAnnotation(jcas); ia.setConditional(((IdentifiedAnnotation) goldAnnotation).getConditional()); ia.setConfidence(((IdentifiedAnnotation) goldAnnotation).getConfidence()); ia.setDiscoveryTechnique(((IdentifiedAnnotation)goldAnnotation).getDiscoveryTechnique()); ia.setGeneric(((IdentifiedAnnotation) goldAnnotation).getGeneric()); ia.setHistoryOf(((IdentifiedAnnotation) goldAnnotation).getHistoryOf()); ia.setPolarity(((IdentifiedAnnotation) goldAnnotation).getPolarity()); ia.setSegmentID(((IdentifiedAnnotation) goldAnnotation).getSegmentID()); ia.setSentenceID(((IdentifiedAnnotation) goldAnnotation).getSentenceID()); ia.setSubject(((IdentifiedAnnotation) goldAnnotation).getSubject()); ia.setTypeID(((IdentifiedAnnotation) goldAnnotation).getTypeID()); ia.setUncertainty(((IdentifiedAnnotation) goldAnnotation).getUncertainty()); newAnno = ia; } else { throw new RuntimeException("Unexpected class of object " + goldAnnotation.getClass()); } newAnno.setBegin(goldAnnotation.getBegin()); newAnno.setEnd(goldAnnotation.getEnd()); newAnno.addToIndexes(); }
annotation.setTypeID( cTakesSemantic ); annotation.setBegin( spanCuis.getKey().getStart() ); annotation.setEnd( spanCuis.getKey().getEnd() ); annotation.setDiscoveryTechnique( CONST.NE_DISCOVERY_TECH_DICT_LOOKUP ); annotation.setOntologyConceptArr( conceptArr ); annotation.addToIndexes();
Map<String, TOP> idAnnotationMap, List<DelayedFeature> delayedFeatures) { mention.setTypeID(typeID); mention.setConfidence(1.0f); mention.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION); mention.setPolarity(negation == null ? CONST.NE_POLARITY_NEGATION_ABSENT : negation == true ? CONST.NE_POLARITY_NEGATION_PRESENT : CONST.NE_POLARITY_NEGATION_ABSENT); if (status != null) { if ("HistoryOf".equals(status)) { mention.setHistoryOf(CONST.NE_HISTORY_OF_PRESENT); } else if ("FamilyHistoryOf".equals(status)) { mention.setHistoryOf(CONST.NE_HISTORY_OF_PRESENT); mention.setSubject(CONST.ATTR_SUBJECT_FAMILY_MEMBER); } else if ("Possible".equals(status)) { mention.setUncertainty(CONST.NE_CERTAINTY_NEGATED); } else { throw new UnsupportedOperationException("Unknown status: " + status); if (mention.getTypeID() == CONST.NE_TYPE_ID_DRUG) { ontologyConcept = new OntologyConcept(jCas); ontologyConcept.setCode(code); mention.setOntologyConceptArr(new FSArray(jCas, 1)); mention.setOntologyConceptArr(0, ontologyConcept); mention.addToIndexes();
private String getAttrValueString(IdentifiedAnnotation mention, Selector s) { switch (s) { case CONDITIONAL: return String.valueOf(mention.getConditional()); case GENERIC: return String.valueOf(mention.getGeneric()); case HISTORYOF: return String.valueOf(mention.getHistoryOf()); case POLARITY: return String.valueOf(mention.getPolarity()); case SUBJECT: return String.valueOf(mention.getSubject()); case UNCERTAINTY: return String.valueOf(mention.getUncertainty()); default: return "?"; } }
private void addNamedEntity(JCas jcas, int begin, int end, Map<String, OntologyConcept> concepts, boolean bMedication, Set<NegSpan> negSet) { if (concepts.isEmpty()) return; IdentifiedAnnotation neLast = bMedication ? new MedicationEventMention( jcas) : new EntityMention(jcas); neLast.setPolarity(negSet.contains(new NegSpan(begin, end)) ? CONST.NE_POLARITY_NEGATION_PRESENT : CONST.NE_POLARITY_NEGATION_ABSENT); neLast.setBegin(begin); neLast.setEnd(end); FSArray ocArr = new FSArray(jcas, concepts.size()); int ocArrIdx = 0; for (OntologyConcept oc : concepts.values()) { // set the cui field if this is in fact a cui ocArr.set(ocArrIdx, oc); ocArrIdx++; } neLast.setOntologyConceptArr(ocArr); concepts.clear(); neLast.addToIndexes(); }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) throws AnalysisEngineProcessException { List<Feature> features = new ArrayList<Feature>(); // entity1 ... entity2 scenario if(arg1.getEnd() < arg2.getBegin()) { features.add(new Feature("arg1_arg2", true)); } // entity2 ... entity1 scenario if(arg2.getEnd() < arg1.getBegin()) { features.add(new Feature("arg2_arg1", true)); } return features; }
public static List<Integer> expandToNP(JCas jCas, IdentifiedAnnotation identifiedAnnotation) { List<Integer> originalSpan = Lists.newArrayList(identifiedAnnotation.getBegin(), identifiedAnnotation.getEnd()); jCas, TreebankNode.class, identifiedAnnotation.getBegin(), identifiedAnnotation.getEnd())) { identifiedAnnotation.setBegin(sortedTreebankNodes.get(0).getBegin()); identifiedAnnotation.setEnd(sortedTreebankNodes.get(0).getEnd());
/** @generated * @param jcas JCas to which this Feature Structure belongs * @param begin offset to the begin spot in the SofA * @param end offset to the end spot in the SofA */ public IdentifiedAnnotation(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
annotation.setTypeID( group.getCode() ); arrIdx++; annotation.setOntologyConceptArr( conceptArr ); extensions.addAll( resource.getModifierExtension() ); if ( FhirElementParser.hasExtension( GENERIC_EXT, extensions ) ) { annotation.setGeneric( true ); annotation.setUncertainty( CONST.NE_UNCERTAINTY_PRESENT ); annotation.setPolarity( CONST.NE_POLARITY_NEGATION_PRESENT ); annotation.setHistoryOf( CONST.NE_HISTORY_OF_PRESENT ); annotation.setSubject( FhirElementParser.getSubjectId( resource ) ); if ( annotation instanceof EventMention ) { final Event event = createEvent( jCas, extensions ); annotation.addToIndexes(); return annotation;
/** * I2b2 wants annotation begin and end offsets plus the covered text * @param jcas in case the blob needs to obtain annotation information from the jcas * @param annotation - * @return a blob with encoded text span and covered text of the annotation */ protected String createBlob( final JCas jcas, final IdentifiedAnnotation annotation ) { final StringBuilder sb = new StringBuilder(); sb.append( '<' ).append( SPAN_START_LABEL ).append( '>' ); sb.append( annotation.getBegin() ); sb.append( "</" ).append( SPAN_START_LABEL ).append( '>' ); sb.append( '<' ).append( SPAN_END_LABEL ).append( '>' ); sb.append( annotation.getEnd() ); sb.append( "</" ).append( SPAN_END_LABEL ).append( '>' ); sb.append( annotation.getCoveredText() ); return sb.toString(); }
private static String formatRelation(BinaryTextRelation relation) { IdentifiedAnnotation arg1 = (IdentifiedAnnotation) relation.getArg1().getArgument(); IdentifiedAnnotation arg2 = (IdentifiedAnnotation) relation.getArg2().getArgument(); String text = arg1.getCAS().getDocumentText(); int begin = Math.min(arg1.getBegin(), arg2.getBegin()); int end = Math.max(arg1.getBegin(), arg2.getBegin()); begin = Math.max(0, begin - 50); end = Math.min(text.length(), end + 50); return String.format( "%s(%s(type=%d), %s(type=%d)) in ...%s...", relation.getCategory(), arg1.getCoveredText(), arg1.getTypeID(), arg2.getCoveredText(), arg2.getTypeID(), text.substring(begin, end).replaceAll("[\r\n]", " ")); }
@Override public boolean filter(Annotation anno) { if (!(anno instanceof IdentifiedAnnotation)) return false; IdentifiedAnnotation ia = (IdentifiedAnnotation) anno; return ia.getOntologyConceptArr() != null && ia.getOntologyConceptArr().size() > 0; }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { // Create a dummy IdentifiedAnnotation in the type system // If the BaseToken Part Of Speech is a Noun Collection<BaseToken> tokens = JCasUtil.select(jcas, BaseToken.class); for (BaseToken token : tokens) { if (saveAnnotation && token.getPartOfSpeech() != null && token.getPartOfSpeech().startsWith("N")) { IdentifiedAnnotation ann = new IdentifiedAnnotation(jcas); ann.setBegin(token.getBegin()); ann.setEnd(token.getEnd()); ann.addToIndexes(); if (printAnnotation) { LOG.info("Token:" + token.getCoveredText() + " POS:" + token.getPartOfSpeech()); } } } }
static private String getAssertion( final IdentifiedAnnotation annotation ) { final StringBuilder sb = new StringBuilder(); if ( annotation.getPolarity() == CONST.NE_POLARITY_NEGATION_PRESENT ) { sb.append( "AFFIRMED" ); } else { sb.append( "NEGATED" ); } if ( annotation.getUncertainty() == CONST.NE_UNCERTAINTY_PRESENT ) { sb.append( "UNCERTAIN" ); } if ( annotation.getGeneric() ) { sb.append( "GENERIC" ); } if ( annotation.getConditional() ) { sb.append( "CONDITIONAL" ); } return sb.toString(); }
eMention = new EventMention(initView, first.start, last.end); } else { eMention = new IdentifiedAnnotation(initView, first.start, last.end); eMention.setTypeID(Mapper.getEntityTypeId(entityTypes.get(mentionId))); eMention.setId(identifiedAnnotationId++); eMention.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION); eMention.setConfidence(1); eMention.addToIndexes();