Package org.apache.uima.jcas.tcas

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


      TOP_Type type = jcas.getType(org.apache.uima.jcas.tcas.Annotation.type);
      assertTrue(type instanceof org.apache.uima.jcas.tcas.Annotation_Type);
      type = jcas.getType(Annotation.typeIndexID);
      assertTrue(type instanceof Annotation_Type);

      Annotation a1 = new Annotation(jcas, 4, 5);
    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
  }
View Full Code Here


  public void testNonJCasCoveredByJCas() throws Exception {
    try {
      CAS localCas = jcas.getCas();
      Type subTok = localCas.getTypeSystem().getType("SubToken");
      Annotation a1 = new Annotation(jcas);
      a1.addToIndexes();
      FeatureStructure f1 = localCas.createFS(subTok);
      localCas.getIndexRepository().addFS(f1);

      JFSIndexRepository ir = jcas.getJFSIndexRepository();
      FSIndex index = ir.getAnnotationIndex();
View Full Code Here

    }
    //check that this does not leave JCAS in an inconsistent state
    //(a check for bug UIMA-738)
    Iterator<Annotation> iter = jcas.getAnnotationIndex().iterator();
    assertTrue(iter.hasNext());
    Annotation annot = iter.next();
    assertEquals("This is a test.", annot.getCoveredText());
  }
View Full Code Here

        }

        // add the Token
        int start = offset;
        offset = offset + tokenString.length();
        Annotation token = AnnotationFactory.createAnnotation(aJCas, start, offset, tokenClass);
        tokenAnnotations.add(token);

        // set the stem and part of speech if present
        if (posTags != null) {
          token.setStringValue(posFeature, posTags[tokenIndex]);
        }
        if (stems != null) {
          token.setStringValue(stemFeature, stems[tokenIndex]);
        }
        tokenIndex++;
      }
      if (!tokenAnnotations.isEmpty()) {
        int begin = tokenAnnotations.get(0).getBegin();
View Full Code Here

  private Map<List<Annotation>, BinaryTextRelation> createRelationLookup(
      JCas relationView) {
    Map<List<Annotation>, BinaryTextRelation> relationLookup;
    relationLookup = new HashMap<List<Annotation>, BinaryTextRelation>();
    for (BinaryTextRelation relation : JCasUtil.select(relationView, BinaryTextRelation.class)) {
      Annotation arg1, arg2;
      if (relation.getArg1().getRole().equals("Argument")) {
        arg1 = relation.getArg1().getArgument();
        arg2 = relation.getArg2().getArgument();
      } else {
        arg2 = relation.getArg1().getArgument();
View Full Code Here

      List<IdentifiedAnnotation> goldMentions = new ArrayList<IdentifiedAnnotation>();
      goldMentions.addAll(JCasUtil.select(goldView, EntityMention.class));
      goldMentions.addAll(JCasUtil.select(goldView, Modifier.class));
      CasCopier copier = new CasCopier(goldView.getCas(), systemView.getCas());
      for (IdentifiedAnnotation goldMention : goldMentions) {
        Annotation copy = (Annotation) copier.copyFs(goldMention);
        Feature sofaFeature = copy.getType().getFeatureByBaseName("sofa");
        copy.setFeatureValue(sofaFeature, systemView.getSofa());
        copy.addToIndexes();
      }
    }
View Full Code Here

      arg2end = arg2.getEnd();
      this.init(arg1begin, arg1end, arg2begin, arg2end);
    }
   
  public HashableArguments(BinaryTextRelation relation) {
    Annotation arg1, arg2;
    String role = relation.getArg1().getRole();
    if (role == null || role.equals("Argument")) {
      arg1 = relation.getArg1().getArgument();
      arg2 = relation.getArg2().getArgument();
    } else {
      arg2 = relation.getArg1().getArgument();
      arg1 = relation.getArg2().getArgument();
   
    this.init(arg1.getBegin(), arg1.getEnd(), arg2.getBegin(), arg2.getEnd());
  }
View Full Code Here

      List<IdentifiedAnnotation> cTakesMentions = new ArrayList<IdentifiedAnnotation>();
      cTakesMentions.addAll(JCasUtil.select(systemView, EntityMention.class));
      cTakesMentions.addAll(JCasUtil.select(systemView, Modifier.class));
      CasCopier copier = new CasCopier(systemView.getCas(), goldView.getCas());
      for (IdentifiedAnnotation cTakesMention : cTakesMentions) {
        Annotation copy = (Annotation) copier.copyFs(cTakesMention);
        Feature sofaFeature = copy.getType().getFeatureByBaseName("sofa");
        copy.setFeatureValue(sofaFeature, goldView.getSofa());
        copy.addToIndexes();
      }

      // replace gold EntityMentions and Modifiers in relations with cTAKES ones
      List<BinaryTextRelation> relations = new ArrayList<BinaryTextRelation>();
      relations.addAll(JCasUtil.select(goldView, BinaryTextRelation.class));
      for (BinaryTextRelation relation : relations) {

        // attempt to replace the gold RelationArguments with system ones
        int replacedArgumentCount = 0;
        for (RelationArgument relArg : Arrays.asList(relation.getArg1(), relation.getArg2())) {
          Annotation goldArg = relArg.getArgument();
          Class<? extends Annotation> argClass = goldArg.getClass();

          // find all annotations covered by the gold argument and of the same class (these should
          // be the ones copied over from the cTAKES output earlier)
          List<? extends Annotation> systemArgs = JCasUtil.selectCovered(
              goldView,
              argClass,
              goldArg);

          // no ctakes annotation found
          if (systemArgs.size() == 0) {
            String word = "no";
            String className = argClass.getSimpleName();
            String argText = goldArg.getCoveredText();
            String message = String.format("%s %s for \"%s\"", word, className, argText);
            this.getContext().getLogger().log(Level.FINE, message);
            continue;
          }
         
          // if there's exactly one annotation, replace the gold one with that
          if (systemArgs.size() == 1) {
            relArg.setArgument(systemArgs.get(0));
            replacedArgumentCount += 1;
          }

          else {
            // multiple ctakes arguments found; look for one that matches exactly
            // e.g. gold: "right breast", ctakes: "right breast", "breast"                                            
            for (Annotation systemArg : systemArgs) {
              String goldArgText = goldArg.getCoveredText();
              String systemArgText = systemArg.getCoveredText();
              if (systemArgText.equals(goldArgText)) {
                relArg.setArgument(systemArg);
                replacedArgumentCount += 1;
              }
            }
           
            if(replacedArgumentCount < 1) {
              // issue a warning message
              String word = "multiple";
              String className = argClass.getSimpleName();
              String argText = goldArg.getCoveredText();
              String message = String.format("%s %s for \"%s\"", word, className, argText);
              this.getContext().getLogger().log(Level.FINE, message);

              System.out.println("gold argument: " + goldArg.getCoveredText());
              System.out.println("gold type: " + ((IdentifiedAnnotation)goldArg).getTypeID());
              for(Annotation systemArg : systemArgs) {
                System.out.println("ctakes argument: " + systemArg.getCoveredText());
                System.out.println("ctakes type: " + ((IdentifiedAnnotation)systemArg).getTypeID());
              }
View Full Code Here

      allMarks.add((Markable)a);
    }
   
    // find out what sentence we're at to make it easier to go backwards:
    for(int i = 0; i < sentList.size(); i++){
      Annotation a = sentList.get(i);
      if(m.getBegin() >= a.getBegin() && m.getEnd() <= a.getEnd()){
        sentInd = i;
        break;
      }
    }
   
View Full Code Here

            this.sourceFile));
        return;
      }
     
      // look up the relations in the map and issue an error if they're missing
      Annotation sourceMention = idAnnotationMap.get(this.source.id);
      Annotation targetMention = idAnnotationMap.get(this.target.id);
      String badId = null;
      if (sourceMention == null) {
        badId = this.source.id;
      } else if (targetMention == null) {
        badId = this.target.id;
      }
      if (badId != null) {
        throw new UnsupportedOperationException(String.format(
            "no annotation with id '%s' in %s",
            badId,
            this.sourceFile));
      }

      // get the uncertainty
      if (this.uncertainty != null) {
        Annotation uncertainty = idAnnotationMap.get(this.uncertainty.id);
        if (uncertainty == null) {
          throw new UnsupportedOperationException(String.format(
              "no annotation with id '%s' in %s",
              this.uncertainty.id,
              this.sourceFile));
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.