Package org.apache.uima.jcas.tcas

Examples of org.apache.uima.jcas.tcas.Annotation


      Collection<BinaryTextRelation> systemRelations,
      Collection<BinaryTextRelation> goldRelations) {
    Set<BinaryTextRelation> goodSys = Sets.newHashSet();

    for(BinaryTextRelation sysrel : systemRelations){
      Annotation sysArg1 = sysrel.getArg1().getArgument();
      Annotation sysArg2 = sysrel.getArg2().getArgument();
      for(BinaryTextRelation goldrel : goldRelations){
        Annotation goldArg1 = goldrel.getArg1().getArgument();
        Annotation goldArg2 = goldrel.getArg2().getArgument();
        if (matchSpan(sysArg2, goldArg1) && matchSpan(sysArg1, goldArg2)){//the order of system pair was flipped
          if(sysrel.getCategory().equals("OVERLAP")){ //if the relation is overlap, and the arg order was flipped, then change back the order
            RelationArgument tempArg = (RelationArgument) sysrel.getArg1().clone();
            sysrel.setArg1((RelationArgument) sysrel.getArg2().clone());
            sysrel.setArg2(tempArg);
View Full Code Here


      Multimap<Annotation, Annotation> contains = HashMultimap.create();
      Set<BinaryTextRelation> containsRelations = Sets.newHashSet();
      for (BinaryTextRelation relation : JCasUtil.select(jCas, BinaryTextRelation.class)) {
        if (relation.getCategory().equals("CONTAINS")) {
          containsRelations.add(relation);
          Annotation arg1 = relation.getArg1().getArgument();
          Annotation arg2 = relation.getArg2().getArgument();
          contains.put(arg1, arg2);
          isContainedIn.put(arg2, arg1);
        }
      }

      // look for X -> Y -> Z containment chains and add X -> Z relations
      Deque<Annotation> todo = new ArrayDeque<Annotation>(isContainedIn.keySet());
      while (!todo.isEmpty()) {
        Annotation next = todo.removeFirst();
        for (Annotation parent : Lists.newArrayList(isContainedIn.get(next))) {
          for (Annotation grandParent : Lists.newArrayList(isContainedIn.get(parent))) {
            if (!isContainedIn.containsEntry(next, grandParent)) {
              isContainedIn.put(next, grandParent);
              contains.put(grandParent, next);
View Full Code Here

      Set<BinaryTextRelation> overlapRelations = Sets.newHashSet();
      Multimap<Annotation, Annotation> overlaps = HashMultimap.create();
      for (BinaryTextRelation relation : JCasUtil.select(jCas, BinaryTextRelation.class)) {
        if (relation.getCategory().equals("OVERLAP")) {
          overlapRelations.add(relation);
          Annotation arg1 = relation.getArg1().getArgument();
          Annotation arg2 = relation.getArg2().getArgument();
          overlaps.put(arg1, arg2);
        }
      }

      for (BinaryTextRelation orelation : overlapRelations) {
        Annotation argA = orelation.getArg1().getArgument();
        Annotation argB = orelation.getArg2().getArgument();
        //add overlap
        if (!overlaps.containsEntry(argB, argA)) {
          //create a new flipped relation:
          RelationArgument arg1 = new RelationArgument(jCas);
          arg1.setArgument(argB);
View Full Code Here

     
      Multimap<List<Annotation>, BinaryTextRelation> annotationsToRelation = HashMultimap.create();
      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();
              annotationsToRelation.put(Arrays.asList(arg1, arg2), relation);
        }
      }
      for (List<Annotation> span: Lists.newArrayList(annotationsToRelation.keySet())){
        Collection<BinaryTextRelation> relations = annotationsToRelation.get(span);
        if(relations.size()>1){//if same span maps to multiple relations
          Set<String> types = Sets.newHashSet();
          for(BinaryTextRelation relation: relations){
            types.add(relation.getCategory());
          }
          if(types.size()>1){
            for(BinaryTextRelation relation: Lists.newArrayList(relations)){
              annotationsToRelation.remove(span, relation);
              relation.getArg1().removeFromIndexes();
              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++;
          }   
        }
       
View Full Code Here

       
        if(lcComma || rcComma || lcAnd){
          // somehow in a list
          // check to see if any element of the list is already part of a relation
          for(BinaryTextRelation otherRel : JCasUtil.select(jCas, BinaryTextRelation.class)){
            Annotation a1 = otherRel.getArg1().getArgument();
            Annotation a2 = otherRel.getArg2().getArgument();
            if(a1 instanceof TimeMention || a2 instanceof TimeMention) continue; // covered by another feature
            if(priorNPs.contains(getKey(a1))){
              // one of the left children is already in another relation!
              feats.add(new Feature(prefix + "_leftSiblingInRelation", true));
             
              // check if the other argument in that relation is the secondary arg
              if(secondArg.getBegin() == a2.getBegin() && secondArg.getEnd() == a2.getEnd()){
                // the other proposed arg of this relation is already in a relation with another element of this list!
                feats.add(new Feature(prefix + "_leftSiblingInRelationWithCurArg"));
              }
            }
           
View Full Code Here

          // get overlapping spans
          if(this.printOverlapping){
            // iterate over all remaining gold annotations
            for(Annotation gold : goldOnly){
              Annotation bestSystem = null;
              int bestOverlap = 0;
              for(Annotation system : systemOnly){
                if(system.getBegin() >= gold.getBegin() && system.getEnd() <= gold.getEnd()){
                  // system completely contained by gold
                  int overlap = system.getEnd() - system.getBegin();
                  if(overlap > bestOverlap){
                    bestOverlap = overlap;
                    bestSystem = system;
                  }
                }else if(gold.getBegin() >= system.getBegin() && gold.getEnd() <= system.getEnd()){
                  // gold completely contained by gold
                  int overlap = gold.getEnd() - gold.getBegin();
                  if(overlap > bestOverlap){
                    bestOverlap = overlap;
                    bestSystem = system;
                  }
                }
              }
              if(bestSystem != null){
                this.logger.info(String.format("Allowed overlapping annotation: Gold(%s) => System(%s)\n", gold.getCoveredText(), bestSystem.getCoveredText()));
                partialGold.add(gold);
                partialSystem.add(bestSystem);
              }
            }
            if(partialGold.size() > 0){
View Full Code Here

  public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
      IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
    List<Feature> feats = Lists.newArrayList();
   
    for(BinaryTextRelation etc : JCasUtil.select(jCas, BinaryTextRelation.class)){
      Annotation etcA1 = etc.getArg1().getArgument();
      Annotation etcA2 = etc.getArg2().getArgument();
      if(etcA1 instanceof TimeMention || etcA2 instanceof TimeMention){
        if(etc.getCategory().equalsIgnoreCase("CONTAINS")){
          if(etcA1.getBegin() == arg1.getBegin() && etcA1.getEnd() == arg1.getEnd() ||
              etcA2.getBegin() == arg1.getBegin() && etcA2.getEnd() == arg1.getEnd()){
            feats.add(new Feature("ARG1_IN_NC"));
          }
          if(etcA1.getBegin() == arg2.getBegin() && etcA1.getEnd() == arg2.getEnd() ||
              etcA2.getBegin() == arg2.getBegin() && etcA2.getEnd() == arg2.getEnd()){
            feats.add(new Feature("ARG2_IN_NC"));
          }
        }
      }
    }
View Full Code Here

    protected static void printRelationAnnotations(String fileName, Collection<BinaryTextRelation> relations) {

      for(BinaryTextRelation binaryTextRelation : relations) {

        Annotation arg1 = binaryTextRelation.getArg1().getArgument();
        Annotation arg2 = binaryTextRelation.getArg2().getArgument();

        String arg1Type = arg1.getClass().getSimpleName();
        String arg2Type = arg2.getClass().getSimpleName();

        int arg1Begin = arg1.getBegin();
        int arg1End = arg1.getEnd();
        int arg2Begin = arg2.getBegin();
        int arg2End = arg2.getEnd();

        String category = binaryTextRelation.getCategory();

        System.out.format("%s\t%s\t%s\t%d\t%d\t%s\t%d\t%d\n",
            fileName, category, arg1Type, arg1Begin, arg1End, arg2Type, arg2Begin, arg2End);
View Full Code Here

      FSIterator<Annotation> tokensInThisSentenceIterator = tokenAnnotationIndex.subiterator(sentence);
      ArrayList<String> arrayOfTokens = new ArrayList<String>();
      //for (Annotation baseTokenAnnotationUntyped : tokenAnnotationIndex)
      while (tokensInThisSentenceIterator.hasNext())
      {
        Annotation baseTokenAnnotationUntyped = tokensInThisSentenceIterator.next();
//        // ignore tokens that are outside of the sentence.
//        // there has to be a better way to do this with Constraints, but this
//        // should work for now...
//        if (baseTokenAnnotationUntyped.getBegin() < sentenceBegin ||
//            baseTokenAnnotationUntyped.getEnd() > sentenceEnd)
View Full Code Here

        id = 0;
        for(TemporalTextRelation rel : JCasUtil.select(jcas, TemporalTextRelation.class)){
          Element linkEl = doc.createElement("TLINK");
          String linkID = "TL"+id; id++;
          linkEl.setAttribute("id", linkID);
          Annotation arg1 = rel.getArg1().getArgument();
          linkEl.setAttribute("fromID", argToId.get(arg1));
          linkEl.setAttribute("fromText", arg1.getCoveredText());
          Annotation arg2 = rel.getArg2().getArgument();
          linkEl.setAttribute("toID", argToId.get(arg2));
          linkEl.setAttribute("toText", arg2.getCoveredText());
          linkEl.setAttribute("type", rel.getCategory());
          tagsElement.appendChild(linkEl);
        }
       
        // boilerplate xml-writing code:
View Full Code Here

TOP

Related Classes of org.apache.uima.jcas.tcas.Annotation

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.