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

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


    System.out.println();
    for(BinaryTextRelation binaryTextRelation : JCasUtil.select(systemView, BinaryTextRelation.class)) {
           
      String category = binaryTextRelation.getCategory();
     
      IdentifiedAnnotation entity1; // entity whose role is "Argument"
      IdentifiedAnnotation entity2; // entity whose role is "Related_to"
     
      if(binaryTextRelation.getArg1().getRole().equals("Argument")) {
        entity1 = (IdentifiedAnnotation) binaryTextRelation.getArg1().getArgument();
        entity2 = (IdentifiedAnnotation) binaryTextRelation.getArg2().getArgument();
      } else {
        entity1 = (IdentifiedAnnotation) binaryTextRelation.getArg2().getArgument();
        entity2 = (IdentifiedAnnotation) binaryTextRelation.getArg1().getArgument();
      }
     
      String arg1 = entity1.getCoveredText();
      String arg2 = entity2.getCoveredText();
     
      int type1 = entity1.getTypeID();
      int type2 = entity2.getTypeID();
     
      // print relation and its arguments: location_of(colon/6, colon cancer/2)
      System.out.format("%s(%s/%d, %s/%d)\n", category, arg1, type1, arg2, type2);

      if(displayContext) {
View Full Code Here


        throw new AnalysisEngineProcessException(e);
      }  
     
      for(BinaryTextRelation binaryTextRelation : JCasUtil.select(systemView, BinaryTextRelation.class)) {

        IdentifiedAnnotation entity1 = (IdentifiedAnnotation) binaryTextRelation.getArg1().getArgument();
        IdentifiedAnnotation entity2 = (IdentifiedAnnotation) binaryTextRelation.getArg2().getArgument();

        String category = binaryTextRelation.getCategory();
        if(! category.equals("location_of")) {
          continue;
        }
       
        String arg1 = entity1.getCoveredText().toLowerCase();
        String arg2 = entity2.getCoveredText().toLowerCase();
        int type1 = entity1.getTypeID();
        int type2 = entity2.getTypeID();
       
        // first argument has to be an anatomical site
        if(type1 != CONST.NE_TYPE_ID_ANATOMICAL_SITE) {
          continue;
        }
        // skip location_of(anatomical site, anatomical site)
        if(type1 == CONST.NE_TYPE_ID_ANATOMICAL_SITE && type2 == CONST.NE_TYPE_ID_ANATOMICAL_SITE) {
          continue;
        }
       
        List<Sentence> enclosingSentences = JCasUtil.selectCovering(
            systemView,
            Sentence.class,
            entity1.getBegin(),
            entity2.getEnd());
       
        System.out.format("%s|%s|%s\n", arg1, arg2, enclosingSentences.get(0).getCoveredText());
      }
    }
View Full Code Here

    // allowable arg2 types for location_of
  // Per CTAKES-190, only link anatomical sites in LocationOf to EventMentions, but these three are EventMentions now,
  // so this check of type ID now already handles if it is an EventMention.
    HashSet<Integer> okArg2Types = new HashSet<Integer>(Arrays.asList(CONST.NE_TYPE_ID_DISORDER, CONST.NE_TYPE_ID_FINDING, CONST.NE_TYPE_ID_PROCEDURE));
   
    IdentifiedAnnotation arg1 = pair.getArg1(); // Argument (should be anatomical site)
    IdentifiedAnnotation arg2 = pair.getArg2(); // Related_to (should be either disorder, sign/symptom, or procedure)
    int type1 = arg1.getTypeID();
    int type2 = arg2.getTypeID();
   
    if(type1 == CONST.NE_TYPE_ID_ANATOMICAL_SITE && okArg2Types.contains(type2)) {
      return true;
    }
   
View Full Code Here

    // allowable arg1 types
  // Per CTAKES-190, only link SeverityModifiers to EventMention, but the 2 type IDs below are EventMentions now,
    // so this check of type ID now already handles if it is an EventMention.
    HashSet<Integer> okArg1Types = new HashSet<Integer>(Arrays.asList(CONST.NE_TYPE_ID_DISORDER, CONST.NE_TYPE_ID_FINDING));

    IdentifiedAnnotation arg1 = pair.getArg1(); // Argument (should be either disease/disorder or sign/symptom
    int type1 = arg1.getTypeID();

    if(okArg1Types.contains(type1)) {
      return true; // assume arg2 is a modifier
    }
View Full Code Here

      ApiConcept originalConcept = apiConceptList.get(currentIndex);

      Concept associatedConcept = (Concept) indexer
          .lookupByAddress(originalConcept.getExternalId());
      int entityAddress = associatedConcept.getOriginalEntityExternalId();
      IdentifiedAnnotation annotation = (IdentifiedAnnotation) indexer
          .lookupByAddress(entityAddress);

      // possible values for currentAssertionType:
      // present
      // absent
View Full Code Here

  /**
   * Is this pair of entities enclosed inside a noun phrase?
   */
  public static boolean isEnclosed(IdentifiedAnnotationPair pair, TreebankNode np) {
   
    IdentifiedAnnotation arg1 = pair.getArg1();
    IdentifiedAnnotation arg2 = pair.getArg2();

    if((np.getBegin() <= arg1.getBegin()) &&
        (np.getEnd() >= arg1.getEnd()) &&
        (np.getBegin() <= arg2.getBegin()) &&
        (np.getEnd() >= arg2.getEnd())) {
      return true;
    }
   
    return false;
  }
View Full Code Here

    List<IdentifiedAnnotationPair> result = new ArrayList<IdentifiedAnnotationPair>();
    for(IdentifiedAnnotationPair pair : pairs) {
      if(Utils.validateDegreeOfArgumentTypes(pair)) {
        for(TreebankNode nounPhrase : Utils.getNounPhrases(identifiedAnnotationView, (Sentence) sentence)) {
          if(Utils.isEnclosed(pair, nounPhrase)) {
            IdentifiedAnnotation arg1 = pair.getArg1();
            IdentifiedAnnotation arg2 = pair.getArg2();
            result.add(new IdentifiedAnnotationPair(arg1, arg2));
            System.out.println("NP: " + nounPhrase.getCoveredText() + ", " + nounPhrase.getBegin() + ", " + nounPhrase.getEnd());
            System.out.println("arg1: " + arg1.getCoveredText() + ", " + arg1.getBegin() + ", " + arg1.getEnd());
            System.out.println("arg2: " + arg2.getCoveredText() + ", " + arg2.getBegin() + ", " + arg2.getEnd());
            System.out.println();
            break; // don't check other NPs
          }
        }
      }
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

    List<IdentifiedAnnotationPair> result = new ArrayList<IdentifiedAnnotationPair>();
    for(IdentifiedAnnotationPair pair : pairs) {
      if(Utils.validateLocationOfArgumentTypes(pair)) {
        for(TreebankNode nounPhrase : Utils.getNounPhrases(identifiedAnnotationView, (Sentence) sentence)) {
          if(Utils.isEnclosed(pair, nounPhrase)) {
            IdentifiedAnnotation arg1 = pair.getArg1();
            IdentifiedAnnotation arg2 = pair.getArg2();
            result.add(new IdentifiedAnnotationPair(arg1, arg2));
            System.out.println("NP: " + nounPhrase.getCoveredText() + ", " + nounPhrase.getBegin() + ", " + nounPhrase.getEnd());
            System.out.println("arg1: " + arg1.getCoveredText() + ", " + arg1.getBegin() + ", " + arg1.getEnd());
            System.out.println("arg2: " + arg2.getCoveredText() + ", " + arg2.getBegin() + ", " + arg2.getEnd());
            System.out.println();
            break; // don't check other NPs
          }
        }
      }
View Full Code Here

        // arguments
        List<BinaryTextRelation> relations = Lists.newArrayList();
        for (BinaryTextRelation relation : goldBinaryTextRelations) {
          boolean hasSystemArgs = true;
          for (RelationArgument relArg : Lists.newArrayList(relation.getArg1(), relation.getArg2())) {
            IdentifiedAnnotation goldArg = (IdentifiedAnnotation) relArg.getArgument();
            Class<? extends IdentifiedAnnotation> goldClass = goldArg.getClass();
            boolean noSystemArg = JCasUtil.selectCovered(jCas, goldClass, goldArg).isEmpty();
            hasSystemArgs = hasSystemArgs && !noSystemArg;
          }
          if (hasSystemArgs) {
            relations.add(relation);
          } else {
            IdentifiedAnnotation arg1 = (IdentifiedAnnotation) relation.getArg1().getArgument();
            IdentifiedAnnotation arg2 = (IdentifiedAnnotation) relation.getArg2().getArgument();
            String messageFormat =
                "removing relation between %s and %s which is impossible to "
                    + "find with system mentions";
            String message = String.format(messageFormat, format(arg1), format(arg2));
            UIMAFramework.getLogger(this.getClass()).log(Level.WARNING, message);
          }
        }
        goldBinaryTextRelations = relations;
      }

      if (this.allowSmallerSystemArguments) {

        // collect all the arguments of the manually annotated relations
        Set<IdentifiedAnnotation> goldArgs = Sets.newHashSet();
        for (BinaryTextRelation relation : goldBinaryTextRelations) {
          for (RelationArgument relArg : Lists.newArrayList(relation.getArg1(), relation.getArg2())) {
            goldArgs.add((IdentifiedAnnotation) relArg.getArgument());
          }
        }

        // collect all the arguments of system-predicted relations that don't
        // match some gold argument
        Set<IdentifiedAnnotation> unmatchedSystemArgs = Sets.newHashSet();
        for (BinaryTextRelation relation : systemBinaryTextRelations) {
          for (RelationArgument relArg : Lists.newArrayList(relation.getArg1(), relation.getArg2())) {
            IdentifiedAnnotation systemArg = (IdentifiedAnnotation) relArg.getArgument();
            Class<? extends IdentifiedAnnotation> systemClass = systemArg.getClass();
            boolean matchesSomeGold = false;
            for (IdentifiedAnnotation goldArg : JCasUtil.selectCovered(
                goldView,
                systemClass,
                systemArg)) {
              if (goldArg.getBegin() == systemArg.getBegin()
                  && goldArg.getEnd() == systemArg.getEnd()) {
                matchesSomeGold = true;
                break;
              }
            }
            if (!matchesSomeGold) {
              unmatchedSystemArgs.add(systemArg);
            }
          }
        }

        // map each unmatched system argument to the gold argument that encloses
        // it
        Map<IdentifiedAnnotation, IdentifiedAnnotation> systemToGold = Maps.newHashMap();
        for (IdentifiedAnnotation goldArg : goldArgs) {
          Class<? extends IdentifiedAnnotation> goldClass = goldArg.getClass();
          for (IdentifiedAnnotation systemArg : JCasUtil.selectCovered(jCas, goldClass, goldArg)) {
            if (unmatchedSystemArgs.contains(systemArg)) {

              // if there's no mapping yet for this system arg, map it to the
              // enclosing gold arg
              IdentifiedAnnotation oldGoldArg = systemToGold.get(systemArg);
              if (oldGoldArg == null) {
                systemToGold.put(systemArg, goldArg);
              }

              // if there's already a mapping for this system arg, only re-map
              // it to match the type
              else {
                IdentifiedAnnotation current, other;
                if (systemArg.getTypeID() == goldArg.getTypeID()) {
                  systemToGold.put(systemArg, goldArg);
                  current = goldArg;
                  other = oldGoldArg;
                } else {
                  current = oldGoldArg;
                  other = goldArg;
                }

                // issue a warning since this re-mapping procedure is imperfect
                String message =
                    "system argument %s mapped to gold argument %s, but could also be mapped to %s";
                message = String.format(message, format(systemArg), format(current), format(other));
                UIMAFramework.getLogger(this.getClass()).log(Level.WARNING, message);
              }
            }
          }
        }

        // replace system arguments with gold arguments where necessary/possible
        for (BinaryTextRelation relation : systemBinaryTextRelations) {
          for (RelationArgument relArg : Lists.newArrayList(relation.getArg1(), relation.getArg2())) {
            IdentifiedAnnotation systemArg = (IdentifiedAnnotation) relArg.getArgument();
            IdentifiedAnnotation matchingGoldArg = systemToGold.get(systemArg);
            if (matchingGoldArg != null) {
              String messageFormat = "replacing system argument %s with gold argument %s";
              String message =
                  String.format(messageFormat, format(systemArg), format(matchingGoldArg));
              UIMAFramework.getLogger(this.getClass()).log(Level.WARNING, message);
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.