Package org.apache.uima.jcas.tcas

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


    while(casIter.hasNext()){
      JCas jcas = casIter.next();
      JCas goldView = jcas.getView(Evaluation_ImplBase.GOLD_VIEW_NAME);
      Collection<TemporalTextRelation> rels = JCasUtil.select(goldView, TemporalTextRelation.class);
      for(BinaryTextRelation rel : rels){
        Annotation arg1 = rel.getArg1().getArgument();
        Annotation arg2 = rel.getArg2().getArgument();
        String timeClass = null;
        if(arg1 instanceof TimeMention && arg2 instanceof EventMention){
          timeClass = ((TimeMention) arg1).getTimeClass();
        }else if(arg1 instanceof EventMention && arg2 instanceof TimeMention){
          timeClass = ((TimeMention) arg2).getTimeClass();
View Full Code Here


      Map<List<Annotation>, TemporalTextRelation> dischargeTimeRelationLookup;
        dischargeTimeRelationLookup = new HashMap<>();
        if (this.isTraining()) {
          dischargeTimeRelationLookup = new HashMap<>();
          for (TemporalTextRelation relation : JCasUtil.select(jCas, TemporalTextRelation.class)) {
            Annotation arg1 = relation.getArg1().getArgument();
            Annotation arg2 = relation.getArg2().getArgument();
            // The key is a list of args so we can do bi-directional lookup
            if(arg1 instanceof TimeMention && arg2 instanceof EventMention ){
              if( arg1==dischargeTime){
                dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
                continue;
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<>(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

      final Map<RareWordDictionary,Collection<SpannedRareWordTerm>> dictionaryTermsMap
            = new HashMap<RareWordDictionary, Collection<SpannedRareWordTerm>>();
      final Iterator windowIterator = annotationIndex.iterator();
      try {
         while ( windowIterator.hasNext() ) {
            final Annotation window = (Annotation) windowIterator.next();
            if ( isWindowOk( window ) ) {
               processWindow( jcas, window, dictionaryTermsMap );
            }
         }
      } catch ( ArrayIndexOutOfBoundsException iobE ) {
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();
          if(arg1==null || arg2==null){
            System.out.println("Null argument at Doc: "+ fileName);
          }else{
            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<>(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

      event.addToIndexes();
      props.addToIndexes();
    }
   
    for(Element linkEl : dataElem.getChild("TAGS").getChildren("TLINK")){
      Annotation fromEnt = id2entity.get(linkEl.getAttributeValue("fromID"));
      Annotation toEnt = id2entity.get(linkEl.getAttributeValue("toID"));
      String cat = linkEl.getAttributeValue("type");
      TemporalTextRelation link = new TemporalTextRelation(jcas);
      RelationArgument arg1 = new RelationArgument(jcas);
      arg1.setArgument(fromEnt);
      link.setArg1(arg1);
View Full Code Here

 
  AnnotationIndex<Annotation> index = view.getAnnotationIndex(uimaAnnotationType);
  Iterator<Annotation> iter = index.iterator();
  output("Printing annotations for view " + view.getViewName());
  while (iter.hasNext()) {
    Annotation a = iter.next();
    printAnnotation(a);
  }
 
  //// Temp debug code
  //if (view.getViewName().equals("GoldView")) {
View Full Code Here

        FSIterator<Annotation> itPOS =
          workingView.getAnnotationIndex(tokenType).iterator();
        Integer c = 0;
        Integer i = 0;
        while ( itPOS.hasNext() ) {
          Annotation token = itPOS.next();
          // Create a new token to be learned and add it to the list,
          // if the POS value is relevant (not null)
          Token tokenTmp = new Token();
          tokenTmp.word  = token.getCoveredText();
          tokenTmp.pos   = token.getStringValue(featPOS);
          if (tokenTmp.pos != null) {
            c++;
            theLearnedTokens.add(tokenTmp);
          } else {
            UIMAFramework.getLogger().log(Level.WARNING,
View Full Code Here

      AnnotationIndex tokenIndex = (AnnotationIndex) tcas.getAnnotationIndex(tokenType);

      while (spanIterator.hasNext()) {
        ArrayList<AnnotationFS> tokens = new ArrayList<AnnotationFS>(2048);

        Annotation spanAnnotation = (Annotation) spanIterator.next();

        FSIterator tokenIter = tokenIndex.subiterator(spanAnnotation);

        // System.err.println ("Tokens:");
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.