Package org.apache.ctakes.typesystem.type.relation

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


              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<BinaryTextRelation>(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

  static HashSet<String> ctkRels = new HashSet<String>();
 
  @Override
  public void process(JCas jCas) throws AnalysisEngineProcessException {
    for(TemporalLink link : JCasUtil.select(jCas, TemporalLink.class)){
      BinaryTextRelation rel = new BinaryTextRelation(jCas);
      RelationArgument arg1 = new RelationArgument(jCas);
      Anchor source = link.getSource();
      arg1.setArgument(new Annotation(jCas, source.getBegin(), source.getEnd()));
      arg1.addToIndexes();
     
      RelationArgument arg2 = new RelationArgument(jCas);
      Anchor target = link.getTarget();
      arg2.setArgument(new Annotation(jCas, target.getBegin(), target.getEnd()));
      arg2.addToIndexes();
     
      String cat = getMappedCategory(link.getRelationType());
      if(cat.endsWith("-1")){
        rel.setArg1(arg2);
        rel.setArg2(arg1);
        rel.setCategory(cat.substring(0, cat.length()-2));
      }else{
        rel.setCategory(getMappedCategory(link.getRelationType()));
        rel.setArg1(arg1);
        rel.setArg2(arg2);
      }
      rel.addToIndexes();
    }
  }
View Full Code Here

  @Override
  protected String getRelationCategory(
      Map<List<Annotation>, BinaryTextRelation> relationLookup,
      IdentifiedAnnotation arg1,
      IdentifiedAnnotation arg2) {
    BinaryTextRelation relation = relationLookup.get(Arrays.asList(arg1, arg2));
    String category = null;
    if (relation != null) {
      category = relation.getCategory();
    } else {
      relation = relationLookup.get(Arrays.asList(arg2, arg1));
      if (relation != null) {
        if(relation.getCategory().equals("OVERLAP")){
          category = relation.getCategory();
        }else{
          category = relation.getCategory() + "-1";
        }
      }
    }
    if (category == null && coin.nextDouble() <= this.probabilityOfKeepingANegativeExample) {
      category = NO_RELATION_CATEGORY;
View Full Code Here

        }
        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(goldRelation));
          } else{
            System.out.println("Nailed it! " + formatRelation(systemRelation));
          }
        }
View Full Code Here

  @Override
  protected String getRelationCategory(
      Map<List<Annotation>, BinaryTextRelation> relationLookup,
      IdentifiedAnnotation arg1,
      IdentifiedAnnotation arg2) {
    BinaryTextRelation relation = relationLookup.get(Arrays.asList(arg1, arg2));
    String category = null;
    if (relation != null) {
      category = relation.getCategory();
    } else {
      relation = relationLookup.get(Arrays.asList(arg2, arg1));
      if (relation != null) {
        if(relation.getCategory().equals("OVERLAP")){
          category = relation.getCategory();
        }else{
          category = relation.getCategory() + "-1";
        }
      }
    }
    if (category == null && coin.nextDouble() <= this.probabilityOfKeepingANegativeExample) {
      category = NO_RELATION_CATEGORY;
View Full Code Here

            final TlinkTypeSet tlinkTypeSet = _tlinkTypesArray[row][column];
            if tlinkTypeSet == null || tlinkTypeSet.isEmpty() ) {
               continue;
            }
            for ( TlinkType tlinkType : tlinkTypeSet ) {
               final BinaryTextRelation tlink = createTlink(jCas, row, column, tlinkType );
               if ( tlink != null ) {
//                  System.out.println(row+","+column+" "+tlink.getFirstAnnotation().getSpannedText()+ " " + tlinkType + " " + tlink.getSecondAnnotation().getSpannedText());
                  closedTlinks.add( tlink );
               }
            }
View Full Code Here

     //      return new DefaultRelation( entityA, entityB, tlinkClass, "Closure", tlinkAttribute );
     RelationArgument arg1 = new RelationArgument(jCas);
     arg1.setArgument(entityA);
     RelationArgument arg2 = new RelationArgument(jCas);
     arg2.setArgument(entityB);
     BinaryTextRelation relation = new BinaryTextRelation(jCas);
     relation.setArg1(arg1);
     relation.setArg2(arg2);
     relation.setCategory(tlinkType.name().replace( "_", "-" ));//check if this is correct
     return relation;
   }
View Full Code Here

        }
        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(goldRelation));
          } else{
            System.out.println("Nailed it! " + formatRelation(systemRelation));
          }
        }
View Full Code Here

        for (Annotation container : isContainedIn.get(contained)) {
          RelationArgument arg1 = new RelationArgument(jCas);
          arg1.setArgument(container);
          RelationArgument arg2 = new RelationArgument(jCas);
          arg2.setArgument(contained);
          BinaryTextRelation relation = new BinaryTextRelation(jCas);
          relation.setArg1(arg1);
          relation.setArg2(arg2);
          relation.setCategory("CONTAINS");
          arg1.addToIndexes();
          arg2.addToIndexes();
          relation.addToIndexes();
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.ctakes.typesystem.type.relation.BinaryTextRelation

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.