Package org.apache.ctakes.typesystem.type.textsem

Examples of org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation


        Map<String, Double> scores = new HashMap<String, Double>();
        String concept = this.wsd.disambiguate(listConcept, i, null,
            windowSize, metric, scores, true);
        if(log.isTraceEnabled())
          log.trace("i: " + i + ", concept: " + concept);
        IdentifiedAnnotation ne = listNonTrivialNE.get(i);
        FSArray concepts = ne.getOntologyConceptArr();
        for (int j = 0; j < concepts.size(); j++) {
          OntologyConcept yoc = (OntologyConcept) concepts.get(j);
          String conceptId = this.getConceptId(yoc);
          // update the score and set the predicted concept field
          if (concept == null || concept.equals(conceptId))
            yoc.setDisambiguated(true);
          if (scores.containsKey(conceptId))
            yoc.setScore(scores.get(conceptId));

        }
      } else if (conceptSenses.size() == 1) {
        // only one concept - for ytex concept set the predicted concept
        IdentifiedAnnotation ne = listNonTrivialNE.get(i);
        FSArray concepts = ne.getOntologyConceptArr();
        OntologyConcept oc = (OntologyConcept) concepts.get(0);
        oc.setDisambiguated(true);
      }
    }
  }
View Full Code Here


  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();
  }
View Full Code Here

   *            should we set the certainty (true) or confidence (false)
   */
  private void annotateNegation(JCas aJCas, Sentence s, Annotation anno,
      NegexToken t, boolean negated, boolean possible) {
    if (anno instanceof IdentifiedAnnotation) {
      IdentifiedAnnotation ne = (IdentifiedAnnotation) anno;
      if (!storeAsInterval) {
        if (possible)
          ne.setConfidence(-1);
        if (negated || (this.negatePossibilities && possible))
          ne.setPolarity(-1);
      } else {
        ne.setPolarity(negated || possible ? -1 : 0);
        float confidence = negated ? -1 : 1;
        if (possible)
          confidence *= 0.5;
        ne.setConfidence(confidence);
      }
    } else {
      try {
        BeanUtils.setProperty(anno, "negated", negated);
        BeanUtils.setProperty(anno, "possible", possible);
View Full Code Here

                  for ( UmlsConcept umlsConcept : conceptSet ) {
                     conceptArr.set( arrIdx, umlsConcept );
                     arrIdx++;
                  }

                  IdentifiedAnnotation neAnnot;
                  final int conceptKey = conceptEntry.getKey();
                  if ( conceptKey == CONST.NE_TYPE_ID_DRUG ) {
                     neAnnot = new MedicationMention( jcas );
                  } else if ( conceptKey == CONST.NE_TYPE_ID_ANATOMICAL_SITE ) {
                      neAnnot = new AnatomicalSiteMention( jcas );
                  } else if ( conceptKey == CONST.NE_TYPE_ID_DISORDER ) {
                      neAnnot = new DiseaseDisorderMention( jcas );
                  } else if ( conceptKey == CONST.NE_TYPE_ID_FINDING ) {
                      neAnnot = new SignSymptomMention( jcas );
                  } else if ( conceptKey == CONST.NE_TYPE_ID_LAB ) {
                      neAnnot = new LabMention( jcas );
                  } else if ( conceptKey == CONST.NE_TYPE_ID_PROCEDURE ) {
                      neAnnot = new ProcedureMention( jcas );
                  } else {
                      neAnnot = new EntityMention( jcas );
                  }
                  neAnnot.setTypeID( conceptKey );
                  neAnnot.setBegin( neBegin );
                  neAnnot.setEnd( neEnd );
                  neAnnot.setDiscoveryTechnique( CONST.NE_DISCOVERY_TECH_DICT_LOOKUP );
                  neAnnot.setOntologyConceptArr( conceptArr );
                  neAnnot.addToIndexes();
               }
            }
         }
      } catch ( Exception e ) {
         throw new AnalysisEngineProcessException( e );
View Full Code Here

    @Override
    public boolean filter(Annotation anno) {
      if (!(anno instanceof IdentifiedAnnotation))
        return false;
      IdentifiedAnnotation ia = (IdentifiedAnnotation) anno;
      return ia.getOntologyConceptArr() != null
          && ia.getOntologyConceptArr().size() > 0;
    }
View Full Code Here

  // For each IdentifiedAnnotations, if it is of one of the right types, copy to the appropriate new subtype
  List<Annotation> annotationsToRemoveFromCas = new ArrayList<Annotation>();
  try {
    while (identifiedAnnotationsIter.hasNext()) {
      IdentifiedAnnotation original = (IdentifiedAnnotation)identifiedAnnotationsIter.next();
      IdentifiedAnnotation mention = null;

      // for 3.0 and earlier, needed to map mentions to the more specific types. in post-3.0, already creating proper type
        // for things other than medications. Drug NER was creating MedicationEventMentions still for a while (in trunk)
        int t = original.getTypeID();
        if (t==CONST.NE_TYPE_ID_ANATOMICAL_SITE || t==CONST.NE_TYPE_ID_DISORDER || t==CONST.NE_TYPE_ID_DISORDER
            || t==CONST.NE_TYPE_ID_FINDING || t==CONST.NE_TYPE_ID_PROCEDURE) {
          mapToMentions.put(original, original); // with 3.1 don't need to map to proper mention type, already creating as proper type
        } else if (t==CONST.NE_TYPE_ID_DRUG) {
          // Drug NER (ctakes-drug-ner) was creating MedicationEventMention,
          // if found, create MedicationMention with its attributes based on the MedicationEventMention attributes
          if (original instanceof MedicationEventMention) {
            mention = new MedicationMention(jcas);
            mapToMentions.put(original, mention);
            setAttributesFromOriginal(mention, original);
            annotationsToRemoveFromCas.add(original);
          }

        }  else {
          // Some other type of IdentifiedAnnotation such as TimeMention, Modifier, DateMention, RomanNumeralAnnotation, etc
          // For each those we do nothing in this annotator.
        }
    }

  } catch (CASException e) {
    throw new AnalysisEngineProcessException(e);
  }
 
  // Fill in template slots from relations.
 
  //FSIndex<FeatureStructure> relationArgs = jcas.getFSIndexRepository().getIndex("_org.apache.ctakes.typesystem.type.relation.RelationArgument_GeneratedIndex");
  //FSIndex<FeatureStructure> binaryTextRelations = jcas.getFSIndexRepository().getIndex("_org.apache.ctakes.typesystem.type.relation.BinaryTextRelation_GeneratedIndex");
  FSIndex<FeatureStructure> locationOfTextRelations = jcas.getFSIndexRepository().getIndex("_org.apache.ctakes.typesystem.type.relation.LocationOfTextRelation_GeneratedIndex");
  FSIndex<FeatureStructure> degreeOfTextRelations = jcas.getFSIndexRepository().getIndex("_org.apache.ctakes.typesystem.type.relation.DegreeOfTextRelation_GeneratedIndex");
  int i = 0;
 
  if (locationOfTextRelations != null) {
   
      for (FeatureStructure binaryTextRelationFS: locationOfTextRelations) {
       
        i++;
        //logger.info("binaryTextRelationFS = " + binaryTextRelationFS);
        BinaryTextRelation binaryTextRelation = (BinaryTextRelation) binaryTextRelationFS;
        LocationOfTextRelation locationOfTextRelation = null;
        if (binaryTextRelation instanceof LocationOfTextRelation) {
          locationOfTextRelation = (LocationOfTextRelation) binaryTextRelationFS;
        }
       
        RelationArgument arg1 = binaryTextRelation.getArg1(); // an EntityMention  OR  location
        RelationArgument arg2 = binaryTextRelation.getArg2(); // a Modifier  OR   what is located at location
        String relation = binaryTextRelation.getCategory(); // "degree_of", "location_of"

        if (relation.equals("degree_of")) {
         
          // do nothing here, this loop is for dealing with location_of
          // degree_of has its own loop.
         
        } else if (relation.equals("location_of")) {

          IdentifiedAnnotation arg1Arg = (IdentifiedAnnotation) arg1.getArgument();
          IdentifiedAnnotation ia = mapToMentions.get(arg1Arg);

          if (ia instanceof EntityMention) {
           
            // Note you apparently can have an AnatomicalSiteMention be the location_of an AnatomicalSiteMention
            // from running rec041, end up with things like "Left lower extremity"  location_of "common femoral vein"
            // and "left renal vein" in relation location_of to anatomical site mention "renal vein"
            // and "vein" in relation location_of to anatomical site mention "renal vein"
            EntityMention entityMention = (EntityMention) ia;
            IdentifiedAnnotation location = (IdentifiedAnnotation) arg2.getArgument();
            IdentifiedAnnotation loc = (IdentifiedAnnotation)mapToMentions.get(location);
            if (loc instanceof AnatomicalSiteMention) {
              AnatomicalSiteMention asm = (AnatomicalSiteMention) loc;
              //asm.setBodyLocation(binaryTextRelation); // uncomment iff AnatomicalSiteMention ends up with a bodyLocation attribute
            } else {
              logger.error("Need to implement cases for handling EntityMention " + entityMention + " within relation: " + relation);
              logger.error("   loc " + loc + " in relation " + relation + " with/to " + entityMention);
              logger.error("   Using covered text: loc " + loc.getCoveredText() + " in relation " + relation + " with/to " + entityMention.getCoveredText());
            }

          } else {
           
            EventMention eventMention = (EventMention) ia;

            if (eventMention instanceof DiseaseDisorderMention) { //(eventMention.getTypeID()==CONST.NE_TYPE_ID_DISORDER) {
              DiseaseDisorderMention ddm = (DiseaseDisorderMention) eventMention;
              ddm.setBodyLocation(locationOfTextRelation);
            } else if (eventMention instanceof ProcedureMention) { //(eventMention.getTypeID()==CONST.NE_TYPE_ID_PROCEDURE) {
              ProcedureMention pm = (ProcedureMention) eventMention;
              pm.setBodyLocation(locationOfTextRelation);
            } else if (eventMention instanceof SignSymptomMention) { //(eventMention.getTypeID()==CONST.NE_TYPE_ID_FINDING) {
              SignSymptomMention ssm = (SignSymptomMention) eventMention;
              ssm.setBodyLocation(locationOfTextRelation);
            } else {
              logger.error("Need to implement more cases for handling EventMention " + eventMention + " within relation: " + relation);
            }
           
          }
        } else {
          logger.error("Need to implement more cases for relation: " + relation);
        }
      }
  }
 
  if (degreeOfTextRelations != null) {
   
      for (FeatureStructure binaryTextRelationFS: degreeOfTextRelations) {
       
        i++;
        //logger.info("binaryTextRelationFS = " + binaryTextRelationFS);
        BinaryTextRelation binaryTextRelation = (BinaryTextRelation) binaryTextRelationFS;
        DegreeOfTextRelation degreeOfTextRelation = null;
        if (binaryTextRelation instanceof DegreeOfTextRelation) {
          degreeOfTextRelation = (DegreeOfTextRelation) binaryTextRelationFS;
        }
       
        RelationArgument arg1 = binaryTextRelation.getArg1(); // an EntityMention  OR  location
        RelationArgument arg2 = binaryTextRelation.getArg2(); // a Modifier  OR   what is located at location
        String relation = binaryTextRelation.getCategory(); // "degree_of", "location_of"

        if (relation.equals("degree_of")) {
         
          Modifier severity = (Modifier) arg2.getArgument();
          // degree_of is aka severity, which applies to SignSymptomMention/SignSymptom and DiseaseDisorder
          // find Mention associated with arg1
          IdentifiedAnnotation arg1Arg = (IdentifiedAnnotation) arg1.getArgument();
          // set severity within the Mention to be arg2 (the Modifier)
          // Note at this point mapToMentions.get(entityMention) might be an entityMention instead of an EventMention
          // for example rec041 in the seed set resulted in
          //  ClassCastException: org.apache.ctakes.typesystem.type.textsem.AnatomicalSiteMention
          //  cannot be cast to org.apache.ctakes.typesystem.type.textsem.EventMention
          IdentifiedAnnotation ia = mapToMentions.get(arg1Arg);
          if (ia instanceof EntityMention) {
            EntityMention entityMention = (EntityMention) ia;
            logger.error("Need to implement cases for handling EntityMention " + entityMention + " within relation: " + relation);
            logger.error("   severity " + severity + " in relation " + relation + " with/to " + entityMention);
            logger.error("   Using covered text: severity " + severity.getCoveredText() + " in relation " + relation + " with/to " + entityMention.getCoveredText());
View Full Code Here

               final MetaDataHit mdh = lookupHit.getDictMetaDataHit();
               final String code = mdh.getMetaFieldValue( CODE_MF );
               validCodes.add( code );
            }
            final FSArray ocArr = createOntologyConceptArr( jcas, validCodes );
            IdentifiedAnnotation neAnnot = new MedicationMention( jcas ); // medication NEs are EventMention
            neAnnot.setTypeID( CONST.NE_TYPE_ID_DRUG );
            neAnnot.setBegin( neBegin );
            neAnnot.setEnd( neEnd );
            neAnnot.setDiscoveryTechnique( CONST.NE_DISCOVERY_TECH_DICT_LOOKUP );
            neAnnot.setOntologyConceptArr( ocArr );
            neAnnot.addToIndexes();
         } else {
            iv_logger.warn( "Filtered out: " + text );
         }
      }
   }
View Full Code Here

               ocArrIdx++;
               codes.add( code );
            }
         }
        
         IdentifiedAnnotation neAnnot = new IdentifiedAnnotation(jcas);
         if ( typeId == CONST.NE_TYPE_ID_DRUG ) {
            neAnnot = new MedicationMention( jcas );
         } else if ( typeId == CONST.NE_TYPE_ID_ANATOMICAL_SITE ) {
             neAnnot = new AnatomicalSiteMention( jcas );
         } else if ( typeId == CONST.NE_TYPE_ID_DISORDER ) {
             neAnnot = new DiseaseDisorderMention( jcas );
         } else if ( typeId == CONST.NE_TYPE_ID_FINDING ) {
             neAnnot = new SignSymptomMention( jcas );
         } else if ( typeId == CONST.NE_TYPE_ID_LAB ) {
             neAnnot = new LabMention( jcas );
         } else if ( typeId == CONST.NE_TYPE_ID_PROCEDURE ) {
             neAnnot = new ProcedureMention( jcas );
         } else {
             neAnnot = new EntityMention( jcas );
         }
         final int neBegin = entry.getKey().__start;
         final int neEnd = entry.getKey().__end;
         neAnnot.setBegin( neBegin );
         neAnnot.setEnd( neEnd );
         neAnnot.setDiscoveryTechnique( CONST.NE_DISCOVERY_TECH_DICT_LOOKUP );
         neAnnot.setOntologyConceptArr( ocArr );
         neAnnot.setTypeID( typeId );
         neAnnot.addToIndexes();
      }
   }
View Full Code Here

  @Override
  public List<Feature> extract(JCas view, Annotation focusAnnotation)
      throws CleartkExtractorException {
    List<Feature> featList = new ArrayList<Feature>();
   
    IdentifiedAnnotation mention = (IdentifiedAnnotation) focusAnnotation;
    featList.add(new Feature("IsNegated", mention.getPolarity() == CONST.NE_POLARITY_NEGATION_PRESENT));
    return featList;
  }
View Full Code Here

    //logger.info("    before iterating over named entities...");
    for (FeatureStructure featureStructure : annotationIndex)
    {
      //logger.info("    begin single named entity");
      IdentifiedAnnotation annotation = (IdentifiedAnnotation) featureStructure;

      int begin = annotation.getBegin();
      int end = annotation.getEnd();
      String conceptText = annotation.getCoveredText();

      //logger.info(String.format("NAMED ENTITY: \"%s\" [%d-%d]", conceptText,
      //    begin, end));

      Concept concept = new Concept(jcas, begin, end);
      concept.setConceptText(conceptText);
      concept.setConceptType(null);

      concept.setOriginalEntityExternalId(annotation.getAddress());

      FSArray ontologyConceptArray = annotation
          .getOntologyConceptArr();

      ConceptType conceptType = ConceptLookup
          .lookupConceptType(ontologyConceptArray);
View Full Code Here

TOP

Related Classes of org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.