Package org.apache.uima.cas

Examples of org.apache.uima.cas.SofaFS


    try {

      // Create a Sofa (using old APIs for now)
      SofaID_impl id = new SofaID_impl();
      id.setSofaID("EnglishDocument");
      SofaFS es = this.cas.createSofa(id, "text");
      // Initial View is #1!!!
      assertTrue(2 == es.getSofaRef());

      // Set the document text
      es.setLocalSofaData("this beer is good");

      // Test Multiple Sofas across XCAS serialization
      String xcasFilename = "Sofa.xcas";
      XCASSerializer ser = new XCASSerializer(this.cas.getTypeSystem());
      OutputStream outputXCAS = new FileOutputStream(xcasFilename);
      XMLSerializer xmlSer = new XMLSerializer(outputXCAS);
      try {
        ser.serialize(cas, xmlSer.getContentHandler());
        outputXCAS.close();
      } catch (IOException e) {
        e.printStackTrace();
      } catch (SAXException e) {
        e.printStackTrace();
      }

      // Deserialize XCAS
     this.cas.reset();
      InputStream inputXCAS = new FileInputStream(xcasFilename);
      try {
        XCASDeserializer.deserialize(inputXCAS, cas, false);
        inputXCAS.close();
      } catch (SAXException e2) {
        e2.printStackTrace();
      } catch (IOException e2) {
        e2.printStackTrace();
      }
      // Delete the generated file.
      File xcasFile = new File(xcasFilename);
      if (xcasFile.exists()) {
        assertTrue(xcasFile.delete());
      }
     
      // Add a new Sofa
      // SofaID_impl gid = new SofaID_impl();
      // gid.setSofaID("GermanDocument");
      // SofaFS gs = ((CASImpl)cas).createSofa(gid,"text");
      CAS gerTcas =this.cas.createView("GermanDocument");
      assertTrue(gerTcas.getViewName().equals("GermanDocument"));
      SofaFS gs = gerTcas.getSofa();

      assertTrue(gs != null);
      assertTrue(3 == gs.getSofaRef());

      // Set the document text
      // gs.setLocalSofaData("das bier ist gut");
      gerTcas.setDocumentText("das bier ist gut");

      // Test multiple Sofas across binary serialization
      CASSerializer cs = Serialization.serializeNoMetaData(cas);
      cas = Serialization.createCAS(casMgr, cs);

      // Add a new Sofa
      // SofaID_impl fid = new SofaID_impl();
      // fid.setSofaID("FrenchDocument");
      // SofaFS fs = ((CASImpl)cas).createSofa(fid, "text");
      CAS frT =this.cas.createView("FrenchDocument");
      assertTrue(frT.getViewName().equals("FrenchDocument"));
      SofaFS fs = frT.getSofa();
      assertTrue(fs != null);
      assertTrue(4 == fs.getSofaRef());

      // Test multiple Sofas across blob serialization
      ByteArrayOutputStream fos = new ByteArrayOutputStream();
      Serialization.serializeCAS(cas, fos);
     this.cas.reset();
View Full Code Here


    assertTrue( testView.getViewName().equals("TestView"));
   
    this.cas.reset();
    SofaID_impl id = new SofaID_impl();
    id.setSofaID("TestView");
    SofaFS testSofa = this.cas.createSofa(id, "text");
    CAS newView = this.cas.getView(testSofa);
    assertTrue( newView.getViewName().equals("TestView"));
  }
View Full Code Here

  private final String getSofaId() {
    String sofaID = "<none>";
    CAS cas = getView();
    if (cas != null) {
      SofaFS sofaFs = cas.getSofa();
      if (sofaFs != null) {
        sofaID = sofaFs.getSofaID();
      }
    }
    return sofaID;
  }
View Full Code Here

      Iterator<?> sofas = ((CASImpl) MainFrame.this.cas).getBaseCAS().getSofaIterator();
      Feature sofaIdFeat = MainFrame.this.cas.getTypeSystem().getFeatureByFullName(
          CAS.FEATURE_FULL_NAME_SOFAID);
      boolean nonDefaultSofaFound = false;
      while (sofas.hasNext()) {
        SofaFS sofa = (SofaFS) sofas.next();
        String sofaId = sofa.getStringValue(sofaIdFeat);
        if (!CAS.NAME_DEFAULT_SOFA.equals(sofaId)) {
          this.sofaSelectionComboBox.addItem(sofaId);
          nonDefaultSofaFound = true;
        }
      }
View Full Code Here

    Iterator<?> sofas = ((CASImpl) getCas()).getBaseCAS().getSofaIterator();
    Feature sofaIdFeat = getCas().getTypeSystem()
        .getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFAID);
    boolean nonDefaultSofaFound = false;
    while (sofas.hasNext()) {
      SofaFS sofa = (SofaFS) sofas.next();
      String sofaId = sofa.getStringValue(sofaIdFeat);
      if (!CAS.NAME_DEFAULT_SOFA.equals(sofaId)) {
        this.sofaSelectionComboBox.addItem(sofaId);
        nonDefaultSofaFound = true;
      }
    }
View Full Code Here

   * @deprecated
   */
  @Deprecated
  public SofaFS createSofa(SofaID sofaID, String mimeType) {
    // extract absolute SofaName string from the ID
    SofaFS aSofa = createSofa(sofaID.getSofaID(), mimeType);
    getView(aSofa); // will create the view, needed to make the
    // resetNoQuestions and other things that
    // iterate over views work.
    return aSofa;
  }
View Full Code Here

  }

  private SofaFS getSofa(String sofaName) {
    FSIterator<SofaFS> iterator = this.svd.baseCAS.getSofaIterator();
    while (iterator.isValid()) {
      SofaFS sofa = (SofaFS) iterator.get();
      if (sofaName.equals(getStringValue(((FeatureStructureImpl) sofa).getAddress(),
          this.svd.casMetadata.ts.sofaIdFeatCode))) {
        return sofa;
      }
      iterator.moveToNext();
View Full Code Here

        new String[] { sofaName });
    throw e;
  }

  SofaFS getSofa(int sofaRef) {
    SofaFS aSofa = (SofaFS) this.ll_getFSForRef(sofaRef);
    if (aSofa == null) {
      CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFAREF_NOT_FOUND);
      throw e;
    }
    return aSofa;
View Full Code Here

    FSIterator<SofaFS> iterator = this.svd.baseCAS.getSofaIterator();
    final Feature idFeat = getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFAID);
    // Add FSs to index repository for each View
    while (iterator.isValid()) {
      SofaFS sofa = (SofaFS) iterator.get();
      String id = getLowLevelCAS().ll_getStringValue(((FeatureStructureImpl) sofa).getAddress(),
          ((FeatureImpl) idFeat).getCode());
      if (CAS.NAME_DEFAULT_SOFA.equals(id)) {
        this.registerInitialSofa();
        this.svd.sofaNameSet.add(id);
View Full Code Here

  FSIterator<SofaFS> iterator = this.svd.baseCAS.getSofaIterator();
  final Feature idFeat = getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFAID);
  // Add FSs to index repository for each View
  while (iterator.isValid()) {
        SofaFS sofa = (SofaFS) iterator.get();
        String id = getLowLevelCAS().ll_getStringValue(((FeatureStructureImpl) sofa).getAddress(),
            ((FeatureImpl) idFeat).getCode());
        if (CAS.NAME_DEFAULT_SOFA.equals(id)) {
          this.registerInitialSofa();
          this.svd.sofaNameSet.add(id);
View Full Code Here

TOP

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

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.