Examples of BinaryTextRelation


Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

      }

      for (BinaryTextRelation relation : containsRelations) {
        RelationArgument arg1 = (RelationArgument) relation.getArg1().clone();
        RelationArgument arg2 = (RelationArgument) relation.getArg2().clone();
        BinaryTextRelation newrelation = new BinaryTextRelation(jCas);
        newrelation.setArg1(arg1);
        newrelation.setArg2(arg2);
        newrelation.setCategory("OVERLAP");
        arg1.addToIndexes();
        arg2.addToIndexes();
        newrelation.addToIndexes();
      }
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

          //create a new flipped relation:
          RelationArgument arg1 = new RelationArgument(jCas);
          arg1.setArgument(argB);
          RelationArgument arg2 = new RelationArgument(jCas);
          arg2.setArgument(argA);
          BinaryTextRelation relation = new BinaryTextRelation(jCas);
          relation.setArg1(arg1);
          relation.setArg2(arg2);
          relation.setCategory("OVERLAP");
          arg1.addToIndexes();
          arg2.addToIndexes();
          relation.addToIndexes();
          overlaps.put(argB, argA);
        }

      }
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

              relation.getArg2().removeFromIndexes();
              relation.removeFromIndexes();
            }
          }else if(types.size()==1){
            for (int i =1; i< relations.size(); i++){
              BinaryTextRelation relation = (BinaryTextRelation) relations.toArray()[i];
              annotationsToRelation.remove(span, relation);
              relation.getArg1().removeFromIndexes();
              relation.getArg2().removeFromIndexes();
              relation.removeFromIndexes();
            }
          }
        }
      }

      ArrayList<BinaryTextRelation> temporalRelation = new ArrayList<>(annotationsToRelation.values());//new ArrayList<BinaryTextRelation>();
      //      Map<List<Annotation>, BinaryTextRelation> temporalRelationLookup = new HashMap<List<Annotation>, BinaryTextRelation>();
      //
      //      for (BinaryTextRelation relation : JCasUtil.select(jCas, BinaryTextRelation.class)){
      //        String relationType = relation.getCategory();
      //        if(validTemporalType(relationType)){
      //          Annotation arg1 = relation.getArg1().getArgument();
      //              Annotation arg2 = relation.getArg2().getArgument();
      //              BinaryTextRelation tempRelation = temporalRelationLookup.get(Arrays.asList(arg1, arg2));
      //          if( tempRelation == null){
      //            temporalRelation.add(relation);         
      //                temporalRelationLookup.put(Arrays.asList(arg1, arg2), relation);
      //          }else{//if there is duplicate
      //            relation.getArg1().removeFromIndexes();
      //            relation.getArg2().removeFromIndexes();
      //            relation.removeFromIndexes();
      //          }
      //         
      //        }
      //      }

      if (!temporalRelation.isEmpty()){
        TLinkTypeArray2 relationArray = new TLinkTypeArray2(temporalRelation, new AnnotationIdCollection(temporalRelation));

        int addedCount = 0;
        for (BinaryTextRelation relation : relationArray.getClosedTlinks(jCas)) {
          RelationArgument arg1 = relation.getArg1();
          RelationArgument arg2 = relation.getArg2();
          String relationType = relation.getCategory();
          if(relationType.equals("CONTAINED-BY")||relationType.equals("AFTER")){//ignore these two categories, because their reciprocal already exist.
            continue;
          }
          //check if the inferred relation new:
          Collection<BinaryTextRelation> relations = annotationsToRelation.get(Arrays.asList(arg1.getArgument(), arg2.getArgument()));
          if(relations.isEmpty()){ //if haven't seen this inferred relation before, then add this relation
            arg1.addToIndexes();
            arg2.addToIndexes();
            relation.addToIndexes();
            addedCount++;
          }   
        }

        System.out.println( "**************************************************************");
 
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

   
      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
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

       
        // retrieve event-time relations in this sentece
        for(EventMention eventMention : eventMentionsInSentence) {
          for(TimeMention timeMention : timeMentionsInSentence) {
            // there are relations where arg1=time and arg2=event
            BinaryTextRelation timeEventRel = relationLookup.get(Arrays.asList(timeMention, eventMention));
            if(timeEventRel != null) {
              String text = String.format("%s(%s, %s)", timeEventRel.getCategory(), timeMention.getCoveredText(), eventMention.getCoveredText());
              formattedRelationsInSentence.add(text);
            }
            // and relations where arg1=event and arg2=time
            BinaryTextRelation eventTimeRel = relationLookup.get(Arrays.asList(eventMention, timeMention));
            if(eventTimeRel != null) {
              String text = String.format("%s(%s, %s)", eventTimeRel.getCategory(), eventMention.getCoveredText(), timeMention.getCoveredText());
              formattedRelationsInSentence.add(text);
            }
          }
        }
       
        // retrieve event-event relations in this sentence
        for(EventMention mention1 : eventMentionsInSentence) {
          for(EventMention mention2 : eventMentionsInSentence) {
            if(mention1 == mention2) {
              continue;
            }
            BinaryTextRelation relation = relationLookup.get(Arrays.asList(mention1, mention2));
            if(relation != null) {
              String text = String.format("%s(%s, %s)", relation.getCategory(), mention1.getCoveredText(), mention2.getCoveredText());
              formattedRelationsInSentence.add(text);
            }
          }
        }
       
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

              this.sourceFile));
        }
      }
     
      // add the relation to the CAS
      BinaryTextRelation relation = null;
      if ("affects".equals(this.annotation.type)) {
        this.assertTypes(sourceMention, EventMention.class, targetMention, IdentifiedAnnotation.class);
        relation = new AffectsTextRelation(jCas);
      } else if ("complicates/disrupts".equals(this.annotation.type)) {
        this.assertTypes(sourceMention, EventMention.class, targetMention, EventMention.class);
        relation = new ComplicatesDisruptsTextRelation(jCas);
      } else if ("degree_of".equals(this.annotation.type)) {
        this.assertTypes(sourceMention, EventMention.class, targetMention, Modifier.class);
        relation = new DegreeOfTextRelation(jCas);
      } else if ("location_of".equals(this.annotation.type)) {
        if (!(targetMention instanceof AnatomicalSiteMention) && (sourceMention instanceof AnatomicalSiteMention)) {
          // fix reversed arguments in manual annotations
          Annotation temp = sourceMention;
          sourceMention = targetMention;
          targetMention = temp;
//          LOGGER.warn(String.format(
//              "relation arguments in reverse order for \"%s\" annotation with id \"%s\"",
//              annotation.type,
//              annotation.id));
        }
        this.assertTypes(sourceMention, IdentifiedAnnotation.class, targetMention, AnatomicalSiteMention.class);
        relation = new LocationOfTextRelation(jCas);
      } else if ("manages/treats".equals(this.annotation.type)) {
        this.assertTypes(sourceMention, EventMention.class, targetMention, EventMention.class);
        relation = new ManagesTreatsTextRelation(jCas);
      } else if ("manifestation_of".equals(this.annotation.type)) {
        this.assertTypes(sourceMention, EventMention.class, targetMention, EventMention.class);
        relation = new ManifestationOfTextRelation(jCas);
        relation.setCategory("manifestation_of"); // fix typo in Knowtator type system
      } else if ("result_of".equals(this.annotation.type)) {
        this.assertTypes(sourceMention, EventMention.class, targetMention, IdentifiedAnnotation.class);
        relation = new ResultOfTextRelation(jCas);
      } else if ("TLINK".equals(this.annotation.type)) {
        relation = new TemporalTextRelation(jCas);
        relation.setCategory(this.type);
      } else if ("ALINK".equals(this.annotation.type)) {
        relation = new AspectualTextRelation(jCas);
        relation.setCategory(this.type);
      } else {
        relation = new BinaryTextRelation(jCas);
      }
     
      // set the relation cateory (if not already set)
      if (relation.getCategory() == null) {
        relation.setCategory(this.annotation.type);
      }
     
      // link the relation to its arguments and add it to the CAS
      RelationArgument sourceRA = new RelationArgument(jCas);
      sourceRA.setArgument(sourceMention);
      sourceRA.addToIndexes();
      RelationArgument targetRA = new RelationArgument(jCas);
      targetRA.setArgument(targetMention);
      targetRA.addToIndexes();
      relation.setArg1(sourceRA);
      relation.setArg2(targetRA);
      relation.addToIndexes();
   
      // add the relation to the map so it can be used in features of other annotations
      idAnnotationMap.put(this.annotation.id, relation);
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

          arg2.getClass());
    }
   
    @Override
    protected void setValue(TOP value) {
      BinaryTextRelation relation = (BinaryTextRelation) value;
      String message = null;
      if (!this.relationClass.isInstance(relation)) {
        message = "wrong relation type";
      } else if (this.arg1 != null && relation.getArg1().getArgument() != this.arg1) {
        message = "wrong relation arg1";
      } else if (this.arg2 != null && relation.getArg2().getArgument() != this.arg2) {
        message = "wrong relation arg2";
      } else if (!this.arg1Class.isInstance(relation.getArg1().getArgument())) {
        message = "wrong relation arg1 type";
      } else if (!this.arg2Class.isInstance(relation.getArg2().getArgument())) {
        message = "wrong relation arg2 type";
      }
      if (message != null) {
        LOGGER.warn(String.format(
            "%s: expected %s feature of %s to be %s(%s, %s) but found %s[%s](%s, %s) with id \"%s\"",
            message,
            this.featureName,
            format(this.annotation),
            this.relationClass.getSimpleName(),
            this.arg1 == null ? String.format("%s(...)", this.arg1Class.getSimpleName()) : format(this.arg1),
            this.arg2 == null ? String.format("%s(...)", this.arg2Class.getSimpleName()) : format(this.arg2),
            relation.getClass().getSimpleName(),
            relation.getCategory(),
            format(relation.getArg1().getArgument()),
            format(relation.getArg2().getArgument()),
            this.featureValue.id));
      } else {
        super.setValue(value);
      }
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

          arg2.getClass());
    }
   
    @Override
    protected void setValue(TOP value) {
      BinaryTextRelation relation = (BinaryTextRelation) value;
      String message = null;
      if (!this.relationClass.isInstance(relation)) {
        message = "wrong relation type";
      } else if (this.arg1 != null && relation.getArg1().getArgument() != this.arg1) {
        message = "wrong relation arg1";
      } else if (this.arg2 != null && relation.getArg2().getArgument() != this.arg2) {
        message = "wrong relation arg2";
      } else if (!this.arg1Class.isInstance(relation.getArg1().getArgument())) {
        message = "wrong relation arg1 type";
      } else if (!this.arg2Class.isInstance(relation.getArg2().getArgument())) {
        message = "wrong relation arg2 type";
      }
      if (message != null) {
        LOGGER.warn(String.format(
            "%s: expected %s feature of %s to be %s(%s, %s) but found %s[%s](%s, %s) with id \"%s\"",
            message,
            this.featureName,
            format(this.annotation),
            this.relationClass.getSimpleName(),
            this.arg1 == null ? String.format("%s(...)", this.arg1Class.getSimpleName()) : format(this.arg1),
            this.arg2 == null ? String.format("%s(...)", this.arg2Class.getSimpleName()) : format(this.arg2),
            relation.getClass().getSimpleName(),
            relation.getCategory(),
            format(relation.getArg1().getArgument()),
            format(relation.getArg2().getArgument()),
            this.featureValue.id));
      } else {
        super.setValue(value);
      }
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

        }
        Set<HashableArguments> all = Sets.union(goldMap.keySet(), systemMap.keySet());
        List<HashableArguments> sorted = Lists.newArrayList(all);
        Collections.sort(sorted);
        for (HashableArguments key : sorted) {
          BinaryTextRelation goldRelation = goldMap.get(key);
          BinaryTextRelation systemRelation = systemMap.get(key);
          if (goldRelation == null) {
            System.out.println("System added: " + formatRelation(systemRelation));
          } else if (systemRelation == null) {
            System.out.println("System dropped: " + formatRelation(goldRelation));
          } else if (!systemRelation.getCategory().equals(goldRelation.getCategory())) {
            String label = systemRelation.getCategory();
            System.out.printf("System labeled %s for %s\n", label, formatRelation(systemRelation));
          }
        }
      }
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

        copy.addToIndexes();
      }

      // copy gold relations to the system view
      for (BinaryTextRelation goldRelation : JCasUtil.select(goldView, BinaryTextRelation.class)) {
        BinaryTextRelation relation = (BinaryTextRelation) copier.copyFs(goldRelation);
        relation.addToIndexes(systemView);
        for (RelationArgument relArg : Lists.newArrayList(relation.getArg1(), relation.getArg2())) {
          relArg.addToIndexes(systemView);
          // relArg.getArgument() should have been added to indexes with
          // mentions above
        }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.