Package org.apache.uima.jcas.tcas

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


  protected Annotation createAnnotation(AnnotationFS matchedAnnotation, RuleElement element,
          RutaStream stream, RuleMatch match) {
    Type t = type.getType(element.getParent());
    AnnotationFS newAnnotationFS = stream.getCas().createAnnotation(t,
            matchedAnnotation.getBegin(), matchedAnnotation.getEnd());
    Annotation newAnnotation = null;
    if (newAnnotationFS instanceof Annotation) {
      newAnnotation = (Annotation) newAnnotationFS;
      newAnnotation.addToIndexes();
    } else {
      return null;
    }
    stream.addAnnotation(newAnnotation, match);
    return newAnnotation;
View Full Code Here


            ignoreCharValue.toCharArray(), maxIgnoreCharValue, true);
    for (AnnotationFS annotationFS : found) {
      List<String> rowWhere = table.getRowWhere(index - 1, annotationFS.getCoveredText());
      FeatureStructure newFS = stream.getCas().createFS(type);
      if (newFS instanceof Annotation) {
        Annotation a = (Annotation) newFS;
        a.setBegin(annotationFS.getBegin());
        a.setEnd(annotationFS.getEnd());
        stream.addAnnotation(a, match);
      }
      TOP newStructure = null;
      if (newFS instanceof TOP) {
        newStructure = (TOP) newFS;
View Full Code Here

    }

    if (oldBegin != newBegin || newEnd != oldEnd) {
      stream.removeAnnotation(annotation);
      if (annotation instanceof Annotation) {
        Annotation a = (Annotation) annotation;
        a.setBegin(newBegin);
        a.setEnd(newEnd);
      }
      if (newBegin < newEnd) {
        stream.addAnnotation(annotation, true, match);
      }
    }
View Full Code Here

  protected void updateHeuristicAnnotation(RuleMatch match, RuleElement element, RutaStream stream,
          AnnotationFS matchedAnnotation, double deltaScore) {
    Type heuristicType = stream.getJCas().getCasType(RutaAnnotation.type);
    RutaAnnotation heuristicAnnotation = (RutaAnnotation) stream.getCas().createAnnotation(
            heuristicType, matchedAnnotation.getBegin(), matchedAnnotation.getEnd());
    Annotation newAnnotation = (Annotation) stream.getCas().createAnnotation(
            type.getType(element.getParent()), heuristicAnnotation.getBegin(),
            heuristicAnnotation.getEnd());
    heuristicAnnotation.setScore(deltaScore);
    heuristicAnnotation.setAnnotation(newAnnotation);
    List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(heuristicAnnotation,
            heuristicType);

    if (annotationsInWindow.isEmpty()) {
      heuristicAnnotation.addToIndexes();
      newAnnotation.addToIndexes();
      stream.addAnnotation(newAnnotation, match);
    } else {
      RutaAnnotation tma = stream.getCorrectTMA(annotationsInWindow, heuristicAnnotation);
      if (tma != null) {
        tma.removeFromIndexes();
        double newScore = tma.getScore() + deltaScore;
        tma.setScore(newScore);
        tma.addToIndexes();
      } else {
        heuristicAnnotation.addToIndexes();
        newAnnotation.addToIndexes();
        stream.addAnnotation(newAnnotation, match);
      }
    }

  }
View Full Code Here

      // TODO Auto-generated catch block
      e1.printStackTrace();
      assertTrue(false);
    }
    FSIndex jcasSetIndex = jcas.getJFSIndexRepository().getIndex(CASTestSetup.ANNOT_SET_INDEX);
    Annotation jcasAnnotation = (Annotation) jcasSetIndex.find(annot);
    assertNotNull(jcasAnnotation);
    assertNull(jcasSetIndex.find(this.cas.createAnnotation(this.annotationType, -1, -1)));

    // /////////////////////////////////////////////////////////////////////////
    // Test fast fail.
View Full Code Here

    } catch (CASException e) {
      throw new RuntimeException(e);
    }
    FSIterator iter = jcas.getAnnotationIndex().iterator();
    while (iter.isValid()) {
      Annotation annot = (Annotation) iter.get();
      iter.moveToNext();

      // find out what entity this annotation represents
      EntityResolver.Entity entity = mEntityResolver.getEntity(annot);

      //if not an entity, skip it
      if (entity == null)
        continue;
     
      // have we seen this entity before?
      JCheckBox checkbox = (JCheckBox) mEntityToCheckboxMap.get(entity);
      if (checkbox == null) {
        // assign next available color
        Color c = COLORS[mEntityToCheckboxMap.size() % COLORS.length];
        // add checkbox
        checkbox = new JCheckBox(entity.getCanonicalForm(), true);
        checkbox.setToolTipText(entity.getCanonicalForm());
        checkbox.addActionListener(this);
        checkbox.setBackground(c);
        entityCheckboxPanel.add(checkbox);
        // add to (Entity, Checkbox) map
        mEntityToCheckboxMap.put(entity, checkbox);
      }

      // if checkbox is checked, assign color to text
      if (checkbox.isSelected()) {
        int begin = annot.getBegin();
        int end = annot.getEnd();
        // be careful of 0-length annotation. If we try to set background color when there
        // is no selection, it will set the input text style, which is not what we want.
        if (begin != end) {
          MutableAttributeSet attrs = new SimpleAttributeSet();
          StyleConstants.setBackground(attrs, checkbox.getBackground());
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

    }
    jcas.setDocumentText(text);
    try {
      this.ae.process(jcas);
      AnnotationIndex<Annotation> tokenIndex = jcas.getAnnotationIndex(jcas.getCasType(Token.type));
      Annotation sentence = jcas.getAnnotationIndex(jcas.getCasType(Sentence.type)).iterator().next();
      FSIterator<Annotation> tokenIterator = tokenIndex.subiterator(sentence);
      Annotation token = tokenIndex.iterator().next();
      tokenIterator.moveTo(token); //throws ClassCastException   
      UnambiguousIteratorImpl<Annotation> it = new UnambiguousIteratorImpl<Annotation>(tokenIndex.iterator());
      it.moveTo(token);
    } catch (AnalysisEngineProcessException e) {
      e.printStackTrace();
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.