Java Code Examples for org.apache.uima.util.CasCreationUtils#setupTypeSystem()

The following examples show how to use org.apache.uima.util.CasCreationUtils#setupTypeSystem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SofaTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
   * @see junit.framework.TestCase#setUp()
   */
  protected void setUp() throws Exception {
    try {
      super.setUp();
      this.casMgr = CASFactory.createCAS();
      CasCreationUtils.setupTypeSystem(this.casMgr, (TypeSystemDescription) null);
      // Create a writable type system.
      TypeSystemMgr tsa = this.casMgr.getTypeSystemMgr();
      // Add new types and features.
      // Type topType = tsa.getTopType();
      this.annotationType = tsa.getType(CAS.TYPE_NAME_ANNOTATION);
//      annotSofaFeat = annotationType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_SOFA);
      this.docAnnotationType = tsa.getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION);
      assertTrue(this.annotationType != null);
      this.crossType = tsa.addType("sofa.test.CrossAnnotation", this.annotationType);
      this.otherFeat = tsa.addFeature("otherAnnotation", this.crossType, this.annotationType);
      // Commit the type system.
      ((CASImpl) this.casMgr).commitTypeSystem();

      // reinit type system values because the commit might reuse an existing one
      tsa = this.casMgr.getTypeSystemMgr(); 
      this.annotationType = tsa.getType(CAS.TYPE_NAME_ANNOTATION);
      this.docAnnotationType = tsa.getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION);
      this.crossType = tsa.getType("sofa.test.CrossAnnotation");
      this.otherFeat = crossType.getFeatureByBaseName("otherAnnotation");
      
      // Create the Base indexes.
      this.casMgr.initCASIndexes();
      FSIndexRepositoryMgr irm = this.casMgr.getIndexRepositoryMgr();
      // init.initIndexes(irm, casMgr.getTypeSystemMgr());
      irm.commit();

      this.cas = this.casMgr.getCAS().getView(CAS.NAME_DEFAULT_SOFA);
      assertTrue(this.cas.getSofa() == null);
      assertTrue(this.cas.getViewName().equals(CAS.NAME_DEFAULT_SOFA));
    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
  }
 
Example 2
Source File: JcasSofaTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see junit.framework.TestCase#setUp()
 */
protected void setUp() throws Exception {
  try {
    super.setUp();
    casMgr = CASFactory.createCAS();
    CasCreationUtils.setupTypeSystem(casMgr, (TypeSystemDescription) null);
    // Create a writable type system.
    TypeSystemMgr tsa = casMgr.getTypeSystemMgr();
    // Add new types and features.
    Type annotType = tsa.getType(CAS.TYPE_NAME_ANNOTATION);
    Type crossType = tsa.addType("org.apache.uima.cas.test.CrossAnnotation", annotType);
    tsa.addFeature("otherAnnotation", crossType, annotType);
    // Commit the type system.
    ((CASImpl) casMgr).commitTypeSystem();

    // Create the Base indexes.
    casMgr.initCASIndexes();
    FSIndexRepositoryMgr irm = casMgr.getIndexRepositoryMgr();
    // init.initIndexes(irm, casMgr.getTypeSystemMgr());
    irm.commit();

    cas = casMgr.getCAS().getView(CAS.NAME_DEFAULT_SOFA);
    jcas = cas.getJCas();
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example 3
Source File: CasAnnotationViewerTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
protected void setUp() throws Exception {
  viewer = new CasAnnotationViewer();

  CASMgr casMgr = CASFactory.createCAS();
  CasCreationUtils.setupTypeSystem(casMgr, (TypeSystemDescription) null);
  // Create a writable type system.
  TypeSystemMgr tsa = casMgr.getTypeSystemMgr();
  // Add new types and features.
  annotationType = tsa.getType(CAS.TYPE_NAME_ANNOTATION);
  assertTrue(annotationType != null);

  // new primitive types
  exampleType = tsa.addType("test.primitives.Example", annotationType);

  floatFeature = tsa.addFeature("floatFeature", exampleType, tsa.getType(CAS.TYPE_NAME_FLOAT));
  stringFeature = tsa.addFeature("stringFeature", exampleType, tsa.getType(CAS.TYPE_NAME_STRING));
  booleanFeature = tsa.addFeature("boolFeature", exampleType, tsa.getType(CAS.TYPE_NAME_BOOLEAN));
  byteFeature = tsa.addFeature("byteFeature", exampleType, tsa.getType(CAS.TYPE_NAME_BYTE));
  shortFeature = tsa.addFeature("shortFeature", exampleType, tsa.getType(CAS.TYPE_NAME_SHORT));
  longFeature = tsa.addFeature("longFeature", exampleType, tsa.getType(CAS.TYPE_NAME_LONG));
  doubleFeature = tsa.addFeature("doubleFeature", exampleType, tsa.getType(CAS.TYPE_NAME_DOUBLE));

  intArrayFeature = tsa.addFeature("intArrayFeature", exampleType, tsa
          .getType(CAS.TYPE_NAME_INTEGER_ARRAY));
  floatArrayFeature = tsa.addFeature("floatArrayFeature", exampleType, tsa
          .getType(CAS.TYPE_NAME_FLOAT_ARRAY), false);
  stringArrayFeature = tsa.addFeature("stringArrayFeature", exampleType, tsa
          .getType(CAS.TYPE_NAME_STRING_ARRAY), false);
  booleanArrayFeature = tsa.addFeature("boolArrayFeature", exampleType, tsa
          .getType(CAS.TYPE_NAME_BOOLEAN_ARRAY));
  byteArrayFeature = tsa.addFeature("byteArrayFeature", exampleType, tsa
          .getType(CAS.TYPE_NAME_BYTE_ARRAY), false);
  shortArrayFeature = tsa.addFeature("shortArrayFeature", exampleType, tsa
          .getType(CAS.TYPE_NAME_SHORT_ARRAY));
  longArrayFeature = tsa.addFeature("longArrayFeature", exampleType, tsa
          .getType(CAS.TYPE_NAME_LONG_ARRAY));
  doubleArrayFeature = tsa.addFeature("doubleArrayFeature", exampleType, tsa
          .getType(CAS.TYPE_NAME_DOUBLE_ARRAY), false);

  // Commit the type system.
  TypeSystemImpl tsi = ((CASImpl) casMgr).commitTypeSystem();
  if (tsi != tsa) {
    annotationType = tsi.refreshType(annotationType);
    exampleType = tsi.refreshType(exampleType);
    floatFeature = tsi.refreshFeature(floatFeature);
    stringFeature = tsi.refreshFeature(stringFeature);
    booleanFeature = tsi.refreshFeature(booleanFeature);
    byteFeature = tsi.refreshFeature(byteFeature);
    shortFeature = tsi.refreshFeature(shortFeature);
    longFeature = tsi.refreshFeature(longFeature);
    doubleFeature = tsi.refreshFeature(doubleFeature);
    intArrayFeature = tsi.refreshFeature(intArrayFeature);
    floatArrayFeature = tsi.refreshFeature(floatArrayFeature);
    stringArrayFeature = tsi.refreshFeature(stringArrayFeature);
    booleanArrayFeature = tsi.refreshFeature(booleanArrayFeature);
    byteArrayFeature = tsi.refreshFeature(byteArrayFeature);
    shortArrayFeature = tsi.refreshFeature(shortArrayFeature);
    longArrayFeature = tsi.refreshFeature(longArrayFeature);
    doubleArrayFeature = tsi.refreshFeature(doubleArrayFeature);     
  }

  // Create the Base indexes.
  casMgr.initCASIndexes();
  FSIndexRepositoryMgr irm = casMgr.getIndexRepositoryMgr();
  // init.initIndexes(irm, casMgr.getTypeSystemMgr());
  irm.commit();

  cas = casMgr.getCAS().getView(CAS.NAME_DEFAULT_SOFA);

}
 
Example 4
Source File: NewPrimitiveTypesTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
   * @see junit.framework.TestCase#setUp()
   */
  protected void setUp() throws Exception {
    try {
//      long startTime = System.nanoTime();
      super.setUp();
      casMgr = CASFactory.createCAS();
      CasCreationUtils.setupTypeSystem(casMgr, (TypeSystemDescription) null);
      // Create a writable type system.
      TypeSystemMgr tsa = casMgr.getTypeSystemMgr();
      // Add new types and features.
      annotationType = tsa.getType(CAS.TYPE_NAME_ANNOTATION);
      assertTrue(annotationType != null);

      // new primitive types
      exampleType = tsa.addType("test.primitives.Example", annotationType);

      floatFeature = tsa.addFeature("floatFeature", exampleType, tsa.getType(CAS.TYPE_NAME_FLOAT));
      stringFeature = tsa.addFeature("stringFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_STRING));
      booleanFeature = tsa.addFeature("boolFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_BOOLEAN));
      byteFeature = tsa.addFeature("byteFeature", exampleType, tsa.getType(CAS.TYPE_NAME_BYTE));
      shortFeature = tsa.addFeature("shortFeature", exampleType, tsa.getType(CAS.TYPE_NAME_SHORT));
      longFeature = tsa.addFeature("longFeature", exampleType, tsa.getType(CAS.TYPE_NAME_LONG));
      doubleFeature = tsa.addFeature("doubleFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_DOUBLE));

      intArrayFeature = tsa.addFeature("intArrayFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_INTEGER_ARRAY));
      floatArrayFeature = tsa.addFeature("floatArrayFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_FLOAT_ARRAY), false);
      stringArrayFeature = tsa.addFeature("stringArrayFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_STRING_ARRAY), false);
      booleanArrayFeature = tsa.addFeature("boolArrayFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_BOOLEAN_ARRAY));
      byteArrayFeature = tsa.addFeature("byteArrayFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_BYTE_ARRAY), false);
      shortArrayFeature = tsa.addFeature("shortArrayFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_SHORT_ARRAY));
      longArrayFeature = tsa.addFeature("longArrayFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_LONG_ARRAY));
      doubleArrayFeature = tsa.addFeature("doubleArrayFeature", exampleType, tsa
              .getType(CAS.TYPE_NAME_DOUBLE_ARRAY), false);

      // Commit the type system.
      ((CASImpl) casMgr).commitTypeSystem();
      tsa = ((CASImpl) casMgr).getTypeSystemMgr();
      reinitTypeSystem((TypeSystemImpl) tsa);

      // Create the Base indexes.
      casMgr.initCASIndexes();

      // create custom indexes to test new primitive keys
      FSIndexRepositoryMgr irm = casMgr.getIndexRepositoryMgr();
      FSIndexComparator comp = irm.createComparator();
      comp.setType(tsa.getType("test.primitives.Example"));
      comp.addKey(tsa.getFeatureByFullName("test.primitives.Example:doubleFeature"),
          FSIndexComparator.STANDARD_COMPARE);
      irm.createIndex(comp, "doubleIndex");

      comp = irm.createComparator();
      comp.setType(tsa.getType("test.primitives.Example"));
      comp.addKey(tsa.getFeatureByFullName("test.primitives.Example:longFeature"),
          FSIndexComparator.REVERSE_STANDARD_COMPARE);
      irm.createIndex(comp, "longIndex");

      comp = irm.createComparator();
      comp.setType(tsa.getType("test.primitives.Example"));
      comp.addKey(tsa.getFeatureByFullName("test.primitives.Example:shortFeature"),
          FSIndexComparator.STANDARD_COMPARE);
      irm.createIndex(comp, "shortIndex");

      irm.commit();

      cas = casMgr.getCAS().getView(CAS.NAME_DEFAULT_SOFA);
//      System.out.format("Debug NewPrimitiveTypesTest time to setup CAS: %,d microsec%n",
//          (System.nanoTime() - startTime)/1000L);

    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }

  }