Examples of BinaryTextRelation


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

   */
  protected String getRelationCategory(
      Map<List<Annotation>, BinaryTextRelation> relationLookup,
      IdentifiedAnnotation arg1,
      IdentifiedAnnotation arg2) {
    BinaryTextRelation relation = relationLookup.get(Arrays.asList(arg1, arg2));
    String category;
    if (relation != null) {
      category = relation.getCategory();
    } else if (coin.nextDouble() <= this.probabilityOfKeepingANegativeExample) {
      category = NO_RELATION_CATEGORY;
    } else {
      category = null;
    }
View Full Code Here

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

    relArg1.addToIndexes();
    RelationArgument relArg2 = new RelationArgument(jCas);
    relArg2.setArgument(arg2);
    relArg2.setRole("Related_to");
    relArg2.addToIndexes();
    BinaryTextRelation relation = new BinaryTextRelation(jCas);
    relation.setArg1(relArg1);
    relation.setArg2(relArg2);
    relation.setCategory(predictedCategory);
    relation.addToIndexes();
  }
View Full Code Here

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

          }
          // load the relation label from the CAS (if there is one)
          List<Annotation> key = new ArrayList<Annotation>(Arrays.asList(arg1, arg2));
          String category;
          if (relationLookup.containsKey(key)) {
            BinaryTextRelation relation = relationLookup.get(key);
            category = relation.getCategory();
          } else {
            // first check for opposite direction
            key = new ArrayList<Annotation>(Arrays.asList(arg2,arg1));
            if(relationLookup.containsKey(key)){
              // reverse direction
              BinaryTextRelation relation = relationLookup.get(key);
              category = relation.getCategory() + "-1";
            }else{
              category = NO_RELATION_CATEGORY;
            }
          }
         
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

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

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

    // test the relation annotators
    Collection<BinaryTextRelation> relations = JCasUtil.select(jCas, BinaryTextRelation.class);
    assertEquals(2, relations.size());
    Iterator<BinaryTextRelation> iterator = relations.iterator();
    BinaryTextRelation slightFracture = iterator.next();
    assertTrue(slightFracture instanceof DegreeOfTextRelation);
    assertEquals("degree_of", slightFracture.getCategory());
    assertEquals(fracture, slightFracture.getArg1().getArgument());
    assertEquals(slight, slightFracture.getArg2().getArgument());
    BinaryTextRelation fractureFibula = iterator.next();
    assertEquals("location_of", fractureFibula.getCategory());
    assertTrue(fractureFibula instanceof LocationOfTextRelation);
    assertEquals(fracture, fractureFibula.getArg1().getArgument());
    assertEquals(fibula, fractureFibula.getArg2().getArgument());
  }
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.