Package org.apache.uima.jcas.tcas

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


    for (Annotation annotation : annotationIndex) {
      // TODO be careful here, because some people inherit from DocumentAnnotation
      if (typeSystem.subsumes(docType, annotation.getType())) {
        continue;
      }
      Annotation clone = (Annotation) casCopier.copyFs(annotation);
      // change the view/sofa of the new annotation...
      // see: http://osdir.com/ml/apache.uima.general/2007-09/msg00107.html
      clone.setFeatureValue(modview.getTypeSystem()
              .getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFA), modview.getSofa());
      final int mappedBegin = map[clone.getBegin()];
      final int mappedEnd = map[clone.getEnd()];
      if (mappedBegin < mappedEnd) {
        if (mappedEnd > fromJcas.getCas().getDocumentAnnotation().getEnd()) {
          getContext().getLogger().log(Level.WARNING, "illegal annotation offset mapping");
        } else {
          int max = modview.getCas().getDocumentAnnotation().getEnd();
          if (mappedBegin < max && mappedEnd <= max && mappedBegin >= 0 && mappedEnd > 0) {
            clone.setBegin(mappedBegin);
            clone.setEnd(mappedEnd);
            // TODO handle nested annotation features
            modview.addFsToIndexes(clone);
            indexedFs.add(clone);
          } else {
            getContext().getLogger().log(Level.WARNING, "illegal annotation offset mapping");
View Full Code Here


      List<RutaBasic> basicsToAdd = new ArrayList<RutaBasic>();
      basicsToAdd.add(anchorBasic);
      String text = anchorBasic.getCoveredText();
      StringBuilder candidate = new StringBuilder(text);
      // String lastCandidate = candidate.toString();
      Annotation interResult = null;
      while (streamPointer.isValid()) {
        if (containsFragment(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars,
                ignoreWS)) {
          streamPointer.moveToNext();
          if (streamPointer.isValid()) {
            RutaBasic next = (RutaBasic) streamPointer.get();
            if (contains(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars,
                    ignoreWS)) {
              interResult = new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(),
                      basicsToAdd.get(basicsToAdd.size() - 1).getEnd());
            }
            // lastCandidate = candidate.toString();
            candidate.append(next.getCoveredText());
            basicsToAdd.add(next);
View Full Code Here

          ArrayList<AnnotationFS> results, List<RutaBasic> basicsToAdd, String lastCandidate,
          Annotation interResult, char[] ignoreChars, int maxIgnoredChars, boolean ignoreWS) {
    if (basicsToAdd.size() >= 1
            && contains(lastCandidate, ignoreCase, size, ignoreChars, maxIgnoredChars, ignoreWS)) {

      results.add(new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(), basicsToAdd.get(
              basicsToAdd.size() - 1).getEnd()));
    } else if (interResult != null) {
      results.add(interResult);
    }
  }
View Full Code Here

        inputViewJCas, contextAnnotation);

    Boolean atLeastOneAnnotationToSearchFoundAmoungTheSubContextAnnotation = false;
    // for each annotation to search under the context annotation
    while (subContextAnnotationIterator.hasNext()) {
      Annotation aSubAnnotation = (Annotation) subContextAnnotationIterator
          .next();

      System.out.println("Debug: annotationToSearch "+annotationToSearch);
      System.out.println("Debug: aSubAnnotation.getClass().getName() "+aSubAnnotation.getClass().getName());

      //System.out.println("Debug: annotationToSearch.getClass().getName() "+annotationToSearch.getClass().getName()+" wordTypeName"+ wordTypeName);
      if (aSubAnnotation.getClass().getName().equalsIgnoreCase(annotationToSearch)) {
        atLeastOneAnnotationToSearchFoundAmoungTheSubContextAnnotation = true;

        System.out.println("Debug: if (aSubAnnotation.getClass().getName().equalsIgnoreCase(annotationToSearch)) {");

        System.out.println("Debug: anAnnotationToSearch.getBegin()>"+aSubAnnotation.getBegin()+ "< anAnnotationToSearch.getEnd()>"+aSubAnnotation.getEnd()+ "<" );
        //
        String featurePathValue = (String) FeatureUtils.getFeatureValue(aSubAnnotation, featureToSearch); // contextAnnotation.getCoveredText();

        // dictionary word recognizer
        this.recognize(inputViewJCas,this.getRootNode(),aSubAnnotation.getBegin(), aSubAnnotation.getEnd(), featurePathValue);
      }
    }
    if (!atLeastOneAnnotationToSearchFoundAmoungTheSubContextAnnotation) {
      System.err.println("WARNING: the specified context annotation "+annotationToSearch+" has not be found in the annotation index. Check the "+FEATUREPATH_TO_SEARCH_PARAM+" parameter. By default the process has been performed on the whole document text of the current view");
      this.recognize(inputViewJCas,this.getRootNode(), 0, inputViewJCas.getDocumentText().length(), "coveredText");
View Full Code Here

    FSIterator<AnnotationFS> iter = index.iterator();

    while (iter.isValid()) {
      EvalAnnotation a = (EvalAnnotation) iter.next();
      Annotation original = a.getOriginal();
      Type originalType = original.getType();

      if (map.containsKey(originalType.getName())) {
        TypeEvalData element = (TypeEvalData) map.get(originalType.getName());
        int oldCount = element.getTruePositives();
        element.setTruePositives(oldCount + 1);
      } else {
        TypeEvalData newData = new TypeEvalData(originalType.getName(), 1, 0, 0);
        map.put(originalType.getName(), newData);
      }
    }

    index = resultCas.getAnnotationIndex(falsePositiveType);
    iter = index.iterator();

    while (iter.isValid()) {
      EvalAnnotation a = (EvalAnnotation) iter.next();
      Annotation original = a.getOriginal();
      Type originalType = original.getType();

      if (map.containsKey(originalType.getName())) {
        TypeEvalData element = (TypeEvalData) map.get(originalType.getName());
        int oldCount = element.getFalsePositives();
        element.setFalsePositives(oldCount + 1);
      } else {
        TypeEvalData newData = new TypeEvalData(originalType.getName(), 0, 1, 0);
        map.put(originalType.getName(), newData);
      }
    }

    index = resultCas.getAnnotationIndex(falseNegativeType);
    iter = index.iterator();

    while (iter.isValid()) {
      EvalAnnotation a = (EvalAnnotation) iter.next();
      Annotation original = a.getOriginal();
      Type originalType = original.getType();

      if (map.containsKey(originalType.getName())) {
        TypeEvalData element = (TypeEvalData) map.get(originalType.getName());
        int oldCount = element.getFalseNegatives();
        element.setFalseNegatives(oldCount + 1);
View Full Code Here

    List<Annotation> result = new ArrayList<Annotation>();
    moveTo(annotation);
    while (currentIt.isValid()) {
      currentIt.moveToNext();
      if (currentIt.isValid()) {
        Annotation nextAnnotation = (Annotation) currentIt.get();
        if (nextAnnotation.getBegin() == annotation.getEnd()) {
          result.add(nextAnnotation);
        } else if (nextAnnotation.getBegin() >= annotation.getEnd()) {
          break;
        }
      }
    }
    return result;
View Full Code Here

      completeIt.moveToNext();
    }

    while (completeIt.isValid()
            && ((Annotation) completeIt.get()).getBegin() >= windowAnnotation.getBegin()) {
      Annotation annotation = (Annotation) completeIt.get();
      if (getCas().getTypeSystem().subsumes(type, annotation.getType())
              && annotation.getEnd() <= windowAnnotation.getEnd()) {
        result.add(annotation);
      }
      completeIt.moveToNext();
    }
    return result;
View Full Code Here

        String fTok = fst.nextToken();
        int frBegin = frText.indexOf(fTok, frEnd);
        frEnd = frBegin + fTok.length();

        Annotation engAnnot = new Annotation(engJcas, engBegin, engEnd);
        engAnnot.addToIndexes();

        Annotation frAnnot = new Annotation(frJcas, frBegin, frEnd);
        frAnnot.addToIndexes();

        CrossAnnotation gerAnnot = new CrossAnnotation(gerJcas);
        gerAnnot.setBegin(gerBegin);
        gerAnnot.setEnd(gerEnd);
        gerAnnot.setOtherAnnotation(engAnnot);
        gerAnnot.addToIndexes();
      }

      // Test that the annotations are in separate index spaces, and that Sofas are indexed
      JFSIndexRepository indexes = jcas.getJFSIndexRepository();
      // FSIndex sofaIndex = indexes.getIndex(CAS.SOFA_INDEX_NAME);
      indexes = engJcas.getJFSIndexRepository();
      FSIndex engIndex = indexes.getAnnotationIndex(Annotation.type);
      indexes = gerJcas.getJFSIndexRepository();
      FSIndex gerIndex = indexes.getAnnotationIndex(Annotation.type);
      indexes = frJcas.getJFSIndexRepository();
      FSIndex frIndex = indexes.getAnnotationIndex(Annotation.type);
      FSIterator sofaIter = jcas.getSofaIterator();
      int numSofas = 0;
      while (sofaIter.isValid()) {
        numSofas++;
        sofaIter.moveToNext();
      }
      // assertTrue(sofaIndex.size() == 3); // 3 sofas
      assertTrue(numSofas == 3);
      assertTrue(engIndex.size() == 5); // 4 annots plus documentAnnotation
      assertTrue(gerIndex.size() == 5); // 4 annots plus documentAnnotation
      assertTrue(frIndex.size() == 5); // 4 annots plus documentAnnotation

      // Test that the annotations are of the correct types
      FSIterator engIt = engIndex.iterator();
      FSIterator gerIt = gerIndex.iterator();
      FSIterator frIt = frIndex.iterator();
      Annotation engAnnot = (Annotation) engIt.get();
      Annotation gerAnnot = (Annotation) gerIt.get();
      Annotation frAnnot = (Annotation) frIt.get();
      assertTrue((CAS.TYPE_NAME_DOCUMENT_ANNOTATION).equals(engAnnot.getType().getName()));
      assertTrue((CAS.TYPE_NAME_DOCUMENT_ANNOTATION).equals(gerAnnot.getType().getName()));
      assertTrue((CAS.TYPE_NAME_DOCUMENT_ANNOTATION).equals(frAnnot.getType().getName()));

      engIt.moveToNext();
      gerIt.moveToNext();
      frIt.moveToNext();
      engAnnot = (Annotation) engIt.get();
      CrossAnnotation gerCrossAnnot = (CrossAnnotation) gerIt.get();
      frAnnot = (Annotation) frIt.get();
      assertTrue((CAS.TYPE_NAME_ANNOTATION).equals(engAnnot.getType().getName()));
      assertTrue(("this").equals(engAnnot.getCoveredText()));
      assertTrue((CAS.TYPE_NAME_ANNOTATION).equals(frAnnot.getType().getName()));
      assertTrue(("cette").equals(frAnnot.getCoveredText()));
      assertTrue(("org.apache.uima.cas.test.CrossAnnotation").equals(gerCrossAnnot.getType()
              .getName()));
      assertTrue(("das").equals(gerCrossAnnot.getCoveredText()));

      // Test that the other annotation feature of cross annotations works
      Annotation crossAnnot = gerCrossAnnot.getOtherAnnotation();
      assertTrue((CAS.TYPE_NAME_ANNOTATION).equals(crossAnnot.getType().getName()));
      assertTrue(("this").equals(crossAnnot.getCoveredText()));

      // Test that annotations accessed from a reference in the base CAS work correctly
      FSArray anArray = new FSArray(jcas, 3);
      anArray.set(0, engAnnot);
      anArray.set(1, frAnnot);
      anArray.set(2, gerCrossAnnot);
      Annotation tstAnnot = (Annotation) anArray.get(0);
      assertTrue(("this").equals(tstAnnot.getCoveredText()));
      tstAnnot = (Annotation) anArray.get(1);
      assertTrue(("cette").equals(tstAnnot.getCoveredText()));
      tstAnnot = (Annotation) anArray.get(2);
      assertTrue(("das").equals(tstAnnot.getCoveredText()));
    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
  }
View Full Code Here

      CAS newCas = CasCreationUtils.createCas(new TypeSystemDescription_impl(), null, null);
      JCas newJCas = newCas.getJCas();
      CAS view = newCas.createView("DetaggedView");
      view.getJCas();

      Annotation annot = new Annotation(newJCas);
      annot.addToIndexes();
     
      Iterator<Annotation> annotIter = newJCas.getAnnotationIndex(Annotation.type).iterator();
      Annotation annot2 = annotIter.next();
      assertEquals(annot, annot2);
      assertEquals(annot2.getSofa(), annot2.getCASImpl().getSofa());
     
      annot2.addToIndexes();
    }
    catch (Exception e) {
      JUnitExtension.handleException(e);     
    }   
  }
View Full Code Here

      JUnitExtension.handleException(e);
    }
  }

  public void testIteratorCopy() {
    Annotation something = new Annotation(jcas);
    something.addToIndexes();

    JFSIndexRepository ir = jcas.getJFSIndexRepository();
    FSIterator i1 = ir.getAnnotationIndex().iterator();
    FSIterator i2 = i1.copy();
    FSIterator i3 = i2.copy();
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.