Package org.apache.uima.cas

Examples of org.apache.uima.cas.FSIndex


      logger.logError(PARAM_DATA_BLOCK_FS + " '"
          + spanFeatureStructureName
          + "' specified, but does not exist: ");
      throw new AnnotatorInitializationException();
    }
    FSIndex dbIndex = tcas.getAnnotationIndex(spanFeatureStructureType);
    FSIterator spanIterator = dbIndex.iterator();
    while (spanIterator.hasNext()) {
      AnnotationFS enclosingSpanAnnotation = (AnnotationFS) spanIterator
          .next();
      String enclosingRegionSpan = enclosingSpanAnnotation
          .getCoveredText();
View Full Code Here


      setJCas(tcas.getJCas()); // this is needed to get around an issue
      // where UIMA crashes if no JCas is
      // referenced
      // logger.setupDocument (getJCas ());

      FSIndex dbIndex = tcas.getAnnotationIndex(spanFeatureStructureType);
      FSIterator spanIterator = dbIndex.iterator();

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

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

      // create an annotation and add to index of both views
      AnnotationFS anAnnot = cas.createAnnotation(cas.getAnnotationType(), 0, 5);
      cas.getIndexRepository().addFS(anAnnot);
      cas2.getIndexRepository().addFS(anAnnot);
      FSIndex tIndex = cas.getAnnotationIndex();
      FSIndex t2Index = cas2.getAnnotationIndex();
      assertTrue(tIndex.size() == 2); // document annot and this one
      assertTrue(t2Index.size() == 2); // ditto

      // serialize
      StringWriter sw = new StringWriter();
      XMLSerializer xmlSer = new XMLSerializer(sw, false);
      XmiCasSerializer xmiSer = new XmiCasSerializer(cas.getTypeSystem());
      xmiSer.serialize(cas, xmlSer.getContentHandler());
      String xml = sw.getBuffer().toString();

      // deserialize into another CAS (repeat twice to check it still works after reset)
      CAS newCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
              new FsIndexDescription[0]);
      for (int i = 0; i < 2; i++) {
        XmiCasDeserializer newDeser = new XmiCasDeserializer(newCas.getTypeSystem());
        ContentHandler newDeserHandler = newDeser.getXmiCasHandler(newCas);
        SAXParserFactory fact = SAXParserFactory.newInstance();
        SAXParser parser = fact.newSAXParser();
        XMLReader xmlReader = parser.getXMLReader();
        xmlReader.setContentHandler(newDeserHandler);
        xmlReader.parse(new InputSource(new StringReader(xml)));

        // check sofas
        assertEquals("This is a test", newCas.getDocumentText());
        CAS newCas2 = newCas.getView("OtherSofa");
        assertEquals("This is only a test", newCas2.getDocumentText());

        // check that annotation is still indexed in both views
        assertTrue(tIndex.size() == 2); // document annot and this one
        assertTrue(t2Index.size() == 2); // ditto

        newCas.reset();
      }
    } catch (Exception e) {
      JUnitExtension.handleException(e);
View Full Code Here

      assertTrue(cas2.getAnnotationIndex(orgType).size() == 0);
      assertTrue(cas.getAnnotationIndex(orgType).size() > 0);

      // but that some types are still there
      Type personType = cas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Person");
      FSIndex personIndex = cas2.getAnnotationIndex(personType);
      assertTrue(personIndex.size() > 0);

      // check that mentionType has been filtered out (set to null)
      FeatureStructure somePlace = personIndex.iterator().get();
      Feature mentionTypeFeat = personType.getFeatureByBaseName("mentionType");
      assertNotNull(mentionTypeFeat);
      assertNull(somePlace.getStringValue(mentionTypeFeat));
    } catch (Exception e) {
      JUnitExtension.handleException(e);
View Full Code Here

      int numSofas = 0;
      while (sofaIter.isValid()) {
        numSofas++;
        sofaIter.moveToNext();
      }
      FSIndex engIndex = engTcas.getAnnotationIndex();
      FSIndex gerIndex = gerTcas.getAnnotationIndex();
      FSIndex frIndex = frTcas.getAnnotationIndex();
      // 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();
      AnnotationFS engAnnot = (AnnotationFS) engIt.get();
      AnnotationFS gerAnnot = (AnnotationFS) gerIt.get();
      AnnotationFS frAnnot = (AnnotationFS) frIt.get();
      assertTrue(docAnnotationType.getName().equals(engAnnot.getType().getName()));
      assertTrue(docAnnotationType.getName().equals(gerAnnot.getType().getName()));
View Full Code Here

      setJCas(tcas.getJCas()); // this is needed to get around an issue
      // where UIMA crashes if no JCas is
      // referenced
      // logger.setupDocument (getJCas ());

      FSIndex dbIndex = tcas.getAnnotationIndex(spanFeatureStructureType);
      FSIterator spanIterator = dbIndex.iterator();

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

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

          new Object[] { FsVariables.VALUE_FEATURE_NAME });
    }
  }

  public boolean checkCas(CAS cas) {
    FSIndex variableIndex = cas.getIndexRepository().getIndex(FsVariables.INDEX_NAME);
    if (variableIndex == null) {
      return false;
    }
    TypeSystem ts = cas.getTypeSystem();
    Type type = ts.getType(FsVariables.TYPE_NAME);
View Full Code Here

  /**
   * @see JCasAnnotator_ImplBase#process(JCas)
   */
  public void process(JCas aJCas) {
    // get annotation indexes
    FSIndex roomNumberIndex = aJCas.getAnnotationIndex(RoomNumber.type);
    FSIndex dateIndex = aJCas.getAnnotationIndex(DateAnnot.type);
    FSIndex timeIndex = aJCas.getAnnotationIndex(TimeAnnot.type);

    // store end position of last meeting we identified, to prevent multiple
    // annotations over same span
    int lastMeetingEnd = -1;

    // iterate over all combinations
    Iterator roomNumberIter = roomNumberIndex.iterator();
    while (roomNumberIter.hasNext()) {
      RoomNumber room = (RoomNumber) roomNumberIter.next();

      Iterator dateIter = dateIndex.iterator();
      while (dateIter.hasNext()) {
        DateAnnot date = (DateAnnot) dateIter.next();

        Iterator time1Iter = timeIndex.iterator();
        while (time1Iter.hasNext()) {
          TimeAnnot time1 = (TimeAnnot) time1Iter.next();

          Iterator time2Iter = timeIndex.iterator();
          while (time2Iter.hasNext()) {
            TimeAnnot time2 = (TimeAnnot) time2Iter.next();

            // times must be different annotations
            if (time1 != time2) {
View Full Code Here

    // later go back and add these to the CAS indexes. We need to do this
    // because it's not allowed to add to an index that you're currently
    // iterating over.
    List uimaMeetings = new ArrayList();

    FSIndex meetingIndex = aJCas.getAnnotationIndex(Meeting.type);
    FSIterator iter = meetingIndex.iterator();
    while (iter.isValid()) {
      Meeting meeting = (Meeting) iter.get();
      // get span of text within 50 chars on either side of meeting
      // (window size should probably be a config. param)
      int begin = meeting.getBegin() - 50;
View Full Code Here

    // call a CAS Analysis Engine that "translates" the English document
    // and puts the translation into a German Sofa
    seAnnotator.process(cas);

    // get annotation iterator for the English CAS view
    FSIndex anIndex = englishView.getAnnotationIndex();
    FSIterator anIter = anIndex.iterator();

    // and print out all annotations found
    System.out.println("---Printing all annotations for English Sofa---");
    while (anIter.isValid()) {
      AnnotationFS annot = (AnnotationFS) anIter.get();
      System.out.println(" " + annot.getType().getName() + ": " + annot.getCoveredText());
      anIter.moveToNext();
    }

    // now try to get the CAS view for the German Sofa
    System.out.println();
    CAS germanView = cas.getView("GermanDocument");

    // and annotator iterator for the German CAS View
    anIndex = germanView.getAnnotationIndex();
    anIter = anIndex.iterator();
    Type cross = germanView.getTypeSystem().getType("sofa.test.CrossAnnotation");
    Feature other = cross.getFeatureByBaseName("otherAnnotation");

    // print out all annotations for the German Sofa
    System.out.println("---Printing all annotations for German Sofa---");
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.FSIndex

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.