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

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


  {
      int count=0;
      Iterator<?> itr = getAnnotationsIteratorInSpan(jcas, type, beginSpan, endSpan);
      while(itr.hasNext())
      {
        IdentifiedAnnotation ne = (IdentifiedAnnotation)itr.next();
        if(isValidNE(ne.getTypeID(), validNeTypes))
          count++;
      }
      return count;
  }
View Full Code Here


  {
      List<IdentifiedAnnotation> list = new ArrayList<IdentifiedAnnotation>();
      Iterator<?> itr = getAnnotationsIteratorInSpan(jcas, type, beginSpan, endSpan);
      while(itr.hasNext())
      {
        IdentifiedAnnotation ne = (IdentifiedAnnotation)itr.next(); // might be an EventMention or an EntityMention
        if(isValidNE(ne.getTypeID(), validNeTypes))
          list.add(ne);
      }
      return list;
  }
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;
      if (true)  {
        // 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.
        }
      } else {
        // This switch should no longer be needed now that with 3.1 we are using correct specific types like
        // AnatomicalSiteMention rather than EntityMention and DiseaseDisorderMention etc
        switch (original.getTypeID()) {

        case CONST.NE_TYPE_ID_ANATOMICAL_SITE: ;
        //org.apache.ctakes.typesystem.type.textsem.AnatomicalSiteMention
        //org.apache.ctakes.typesystem.type.textsem.EntityMention
        mention = new AnatomicalSiteMention(jcas);
        mapToMentions.put(original, mention);
        setAttributesFromOriginal(mention, original);
        annotationsToRemoveFromCas.add(original);
        break;

        case CONST.NE_TYPE_ID_DISORDER: ;
        //org.apache.ctakes.typesystem.type.textsem.DiseaseDisorderMention
        //org.apache.ctakes.typesystem.type.textsem.EventMention
        mention = new DiseaseDisorderMention(jcas);
        mapToMentions.put(original, mention);
        setAttributesFromOriginal(mention, original);
        annotationsToRemoveFromCas.add(original);
        break;

        case CONST.NE_TYPE_ID_DRUG: ;

        if (original instanceof MedicationEventMention) {
          mention = new MedicationMention(jcas);
          mapToMentions.put(original, mention);
          setAttributesFromOriginal(mention, original);
          annotationsToRemoveFromCas.add(original);
        }
        break;

        case CONST.NE_TYPE_ID_FINDING: ; // aka sign/symptom
        //org.apache.ctakes.typesystem.type.textsem.SignSymptomMention
        //org.apache.ctakes.typesystem.type.textsem.EventMention
        mention = new SignSymptomMention(jcas);
        mapToMentions.put(original, mention);
        setAttributesFromOriginal(mention, original);
        annotationsToRemoveFromCas.add(original);
        break;

        case CONST.NE_TYPE_ID_PROCEDURE: ;
        //org.apache.ctakes.typesystem.type.textsem.ProcedureMention
        //org.apache.ctakes.typesystem.type.textsem.EventMention
        mention = new ProcedureMention(jcas);
        mapToMentions.put(original, mention);
        setAttributesFromOriginal(mention, original);
        annotationsToRemoveFromCas.add(original);
        break;

        default: ;
        // 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");
  int i = 0;
 
  if (binaryTextRelations != null) {
   
      for (FeatureStructure binaryTextRelationFS: binaryTextRelations) {
       
        i++;
        //logger.info("binaryTextRelationFS = " + binaryTextRelationFS);
        BinaryTextRelation binaryTextRelation = (BinaryTextRelation) binaryTextRelationFS;
        LocationOfTextRelation locationOfTextRelation = null;
        DegreeOfTextRelation degreeOfTextRelation = null;
        if (binaryTextRelation instanceof LocationOfTextRelation) {
          locationOfTextRelation = (LocationOfTextRelation) binaryTextRelationFS;
        } else 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());
          } else {
            EventMention eventMention = (EventMention) ia;
            if (eventMention instanceof DiseaseDisorderMention) {
              DiseaseDisorderMention ddm = (DiseaseDisorderMention) eventMention;
              logger.error("Need to implement attr for " + relation + " for DiseaseDisorderMention");
            } else if (eventMention instanceof SignSymptomMention) {
              SignSymptomMention ssm = (SignSymptomMention) eventMention;
              ssm.setSeverity(degreeOfTextRelation);
            } else {
              logger.error("Need to implement more cases for handling EventMention " + eventMention + " within relation: " + relation);
            }
          }
         
        } else if (relation.equals("location_of")) {

          EntityMention arg2Arg = (EntityMention) arg2.getArgument(); // wrongly created as EntityMention prior to 3.0
          IdentifiedAnnotation ia = mapToMentions.get(arg2Arg);

          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) arg1.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;
View Full Code Here

      Iterator neIter = FSUtil
          .getAnnotationsInSpanIterator(jcas,
              IdentifiedAnnotation.type, sen.getBegin(),
              sen.getEnd() + 1);
      while (neIter.hasNext()) {
        IdentifiedAnnotation n = (IdentifiedAnnotation) neIter.next();
        if (n.getTypeID() == 2 || n.getTypeID() == 3)
          foundPSE = true;

        if (n.getTypeID() == 1)
          foundDrug = true;
      }

      if (!foundPSE)
        continue;

      if (foundPSE && foundDrug) {
        PSESentence ps = new PSESentence(jcas);
        ps.setBegin(sen.getBegin());
        ps.setEnd(sen.getEnd());
        ps.addToIndexes();
      } else if (foundPSE && !foundDrug) {
        int num = sen.getSentenceNumber();
        num = (num > 0) ? num - 1 : num;
        int[] previousSenSpan = SEUtil
            .getSentenceSpanOfGivenSentenceNum(jcas, num);

        // only if they are in the same line
        if (SEUtil.isSpanInSameLine(jcas, previousSenSpan[0],
            sen.getEnd())) {
          neIter = FSUtil.getAnnotationsInSpanIterator(jcas,
              IdentifiedAnnotation.type, previousSenSpan[0],
              previousSenSpan[1] + 1);
          while (neIter.hasNext()) {
            IdentifiedAnnotation n = (IdentifiedAnnotation) neIter
                .next();
            if (n.getTypeID() == 1) {
              PSESentence ps = new PSESentence(jcas);
              ps.setBegin(previousSenSpan[0]);
              ps.setEnd(sen.getEnd());
              ps.addToIndexes();
              break;
View Full Code Here

        Iterator neItr= indexes.getAnnotationIndex(IdentifiedAnnotation.type).iterator();
        List l = new ArrayList();
       
        //add drug to List
        while (neItr.hasNext()) {
          IdentifiedAnnotation nea = (IdentifiedAnnotation) neItr.next();         
          if(nea.getTypeID()==1)
            if(nea.getBegin()>=begin && nea.getEnd()<=end)
              l.add(nea);
        }
       
        return l;
  }
View Full Code Here

    List<IdentifiedAnnotation> neLst = new ArrayList<IdentifiedAnnotation>();
    Iterator neIter = FSUtil.getAnnotationsInSpanIterator(
        jcas, IdentifiedAnnotation.type, begin, end+1);
    while(neIter.hasNext()) {
      IdentifiedAnnotation ne = (IdentifiedAnnotation) neIter.next();
      if(ne.getTypeID()==neType) neLst.add(ne);
    }
   
    Iterator wtIter = FSUtil.getAnnotationsInSpanIterator(
        jcas, WordToken.type, begin, end);
    int cnt=0;
View Full Code Here

   */
  public static boolean isDrugBetween(JCas jcas, int begin, int end) {
    Iterator neIter = FSUtil.getAnnotationsInSpanIterator(
        jcas, IdentifiedAnnotation.type, begin, end+1);
    while(neIter.hasNext()) {
      IdentifiedAnnotation ne = (IdentifiedAnnotation) neIter.next();
      if(ne.getTypeID()==1) return true;
    }
   
    return false;
  }
View Full Code Here

   */
  public static boolean isPSEBetween(JCas jcas, int begin, int end) {
    Iterator neIter = FSUtil.getAnnotationsInSpanIterator(
        jcas, IdentifiedAnnotation.type, begin, end+1);
    while(neIter.hasNext()) {
      IdentifiedAnnotation ne = (IdentifiedAnnotation) neIter.next();
      if(ne.getTypeID()==2 || ne.getTypeID()==3) return true;
    }
   
    return false;
  }
View Full Code Here

    List pse = new ArrayList();

    Iterator neIter = FSUtil.getAnnotationsInSpanIterator(jcas,
        IdentifiedAnnotation.type, ps.getBegin(), ps.getEnd() + 1);
    while (neIter.hasNext()) {
      IdentifiedAnnotation n = (IdentifiedAnnotation) neIter.next();
      // drug
      if (n.getTypeID() == 1) {
        drug.add(n);
      }
      // signs/symptoms or disease/disorders
      if (n.getTypeID() == 2 || n.getTypeID() == 3) {
        pse.add(n);
      }
    }

    // for each metaKey
    Iterator metaKeyIter = metaKey.iterator();
    while (metaKeyIter.hasNext()) {
      String mk = (String) metaKeyIter.next();
      Set kwSet = (Set) metaKeywords.get(mk);

      // for each keyword in a given metaKey
      Iterator kwIter = kwSet.iterator();
      String kw = "";
      int kwPos = -1;
      boolean foundKw = false;

      while (kwIter.hasNext()) {
        String pseSenText = ps.getCoveredText().toLowerCase();
        kw = (String) kwIter.next();
        kwPos = pseSenText.indexOf(kw);
        if (kwPos == -1)
          continue;
        // if 1st before & after char is non-alphabet
        int kwB = kwPos - 1;
        int kwA = kwPos + kw.length();
        // cf) end is the end index + 1;
        if ((pseSenText.length() <= kwA) || // == would be satisfied
            (kwPos == 0 && pseSenText.substring(kwA, kwA + 1)
                .matches("\\W"))
            || (pseSenText.substring(kwA, kwA + 1).matches("\\W") && pseSenText
                .substring(kwB, kwB + 1).matches("\\W"))) {
          foundKw = true;
          break;
        }

        // String lcCoveredText = ps.getCoveredText().toLowerCase();
        // if( (kwPos==0 && ( lcCoveredText.length() >= kwA+1 &&
        // lcCoveredText.substring(kwA,kwA+1).matches("\\W"))) ||
        // ((lcCoveredText.length() >= kwA+1
        // && lcCoveredText.length() >= kwB+1 &&
        // lcCoveredText.substring(kwA,kwA+1).matches("\\W")
        // && lcCoveredText.substring(kwB,kwB+1).matches("\\W")) )) {
        // foundKw = true;
        // break;
        // }

      }

      // if not found the keyword, go to next keyword
      if (!foundKw) {
        feature.add("nul");
        continue;
      }

      int kwBegin = kwPos + ps.getBegin();
      int kwEnd = kwBegin + kw.length(); // index of end ch + 1
      boolean beforePse = false;
      boolean afterPse = false;
      boolean betweenPseAndDrug = false;
      boolean betweenDrugAndPse = false;

      // check if keyword exists between PSE and Drug
      Iterator iter1, iter2;
      iter1 = pse.iterator();
      while (iter1.hasNext()) {
        IdentifiedAnnotation pseNE = (IdentifiedAnnotation) iter1.next();
        if (kwBegin > pseNE.getEnd()) {
          iter2 = drug.iterator();
          while (iter2.hasNext()) {
            IdentifiedAnnotation drugNE = (IdentifiedAnnotation) iter2.next();
            if (kwEnd < drugNE.getBegin()) {
              betweenPseAndDrug = true;
              break;
            }
          }
        }
        if (betweenPseAndDrug)
          break;
      }

      // check if keyword exists between Drug and PSE
      iter1 = drug.iterator();
      while (iter1.hasNext()) {
        IdentifiedAnnotation drugNE = (IdentifiedAnnotation) iter1.next();
        if (kwBegin > drugNE.getEnd()) {
          iter2 = pse.iterator();
          while (iter2.hasNext()) {
            IdentifiedAnnotation pseNE = (IdentifiedAnnotation) iter2.next();
            if (kwEnd < pseNE.getBegin()) {
              betweenDrugAndPse = true;
              break;
            }
          }
        }
        if (betweenDrugAndPse)
          break;
      }

      if ((!betweenPseAndDrug) && (!betweenDrugAndPse)) {
        Iterator pseIter = pse.iterator();
        while (pseIter.hasNext()) {
          IdentifiedAnnotation n = (IdentifiedAnnotation) pseIter.next();
          if (kwEnd < n.getBegin())
            beforePse = true;
          if (kwBegin > n.getEnd())
            afterPse = true;
        }
      }

      if (mk.equals("SideEffectWord")) {
View Full Code Here

        Iterator neItr= indexes.getAnnotationIndex(IdentifiedAnnotation.type).iterator();
        Set<String> spanSet = new HashSet<String>();
        List<IdentifiedAnnotation> duplicatedNE = new ArrayList<IdentifiedAnnotation>();
       
        while (neItr.hasNext()) {
          IdentifiedAnnotation nea = (IdentifiedAnnotation) neItr.next();         
          String span = Integer.toString(nea.getTypeID())+"|"+
            Integer.toString(nea.getBegin())+"|"+Integer.toString(nea.getEnd());
          if(spanSet.contains(span)) {
            duplicatedNE.add(nea);
          }
          spanSet.add(span);
        }
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.