org.apache.uima.cas.impl.TypeSystemImpl Java Examples

The following examples show how to use org.apache.uima.cas.impl.TypeSystemImpl. 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: NewPrimitiveTypesTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private void reinitTypeSystem(TypeSystemImpl tsa) {
  annotationType = tsa.getType(CAS.TYPE_NAME_ANNOTATION);

  // new primitive types
  exampleType = tsa.refreshType(exampleType);

  floatFeature = tsa.refreshFeature(floatFeature);
  stringFeature = tsa.refreshFeature(stringFeature);
  booleanFeature = tsa.refreshFeature(booleanFeature);
  byteFeature = tsa.refreshFeature(byteFeature);
  shortFeature = tsa.refreshFeature(shortFeature);
  longFeature = tsa.refreshFeature(longFeature);
  doubleFeature = tsa.refreshFeature(doubleFeature);

  intArrayFeature = tsa.refreshFeature(intArrayFeature);
  floatArrayFeature = tsa.refreshFeature(floatArrayFeature);
  stringArrayFeature = tsa.refreshFeature(stringArrayFeature);
  booleanArrayFeature = tsa.refreshFeature(booleanArrayFeature);
  byteArrayFeature = tsa.refreshFeature(byteArrayFeature);
  shortArrayFeature = tsa.refreshFeature(shortArrayFeature);
  longArrayFeature = tsa.refreshFeature(longArrayFeature);
  doubleArrayFeature = tsa.refreshFeature(doubleArrayFeature);
}
 
Example #2
Source File: IteratorTestSorted.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void setUp() {
  CASImpl casMgr = (CASImpl) CASFactory.createCAS();
  TypeSystemImpl tsi = (TypeSystemImpl) casMgr.getTypeSystemMgr();
  TypeImpl level_1_type = tsi.addType("org.apache.uima.cas.test.Level_1", tsi.annotType);
  tsi.addFeature("id", level_1_type, tsi.floatType);
  TypeImpl level_2_type = tsi.addType("org.apache.uima.cas.test.Level_2",  level_1_type);
  TypeImpl level_3_type = tsi.addType("org.apache.uima.cas.test.Level_3",  level_2_type);
  TypeImpl level_4_type = tsi.addType("org.apache.uima.cas.test.Level_4",  level_3_type);
  TypeImpl level_5_type = tsi.addType("org.apache.uima.cas.test.Level_5",  level_4_type);
  TypeImpl level_6_type = tsi.addType("org.apache.uima.cas.test.Level_6",  level_5_type);
  
  casMgr.commitTypeSystem();
  try {
    FSIndexRepositoryMgr irm = casMgr.getIndexRepositoryMgr();
    casMgr.initCASIndexes();
    irm.commit();
    
    jcas = casMgr.getCurrentView().getJCas();
  } catch (CASException e) {
    e.printStackTrace();
    fail();
  }
}
 
Example #3
Source File: ResultSpecification_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private Iterable<String> subtypeNames(final String typeName) {
  final TypeSystemImpl ts = (TypeSystemImpl) mTypeSystem;
  return new Iterable<String>() {

    public Iterator<String> iterator() {
      return new Iterator<String>() {
        Type t = (null == ts) ? null : ts.getType(typeName);         
        List<Type> subtypes = (null == ts) ? EMPTY_TYPE_LIST 
                            : (null == t ) ? EMPTY_TYPE_LIST
                            : ts.getProperlySubsumedTypes(t);
        int  i = 0;

        public boolean hasNext() {
          return i < subtypes.size();
        }

        public String next() {
          return subtypes.get(i++).getName();
        }

        public void remove() {throw new UnsupportedOperationException();}
        
      };
    }
  };
}
 
Example #4
Source File: CasCreationUtils.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Create a CAS from a CAS Definition.
 * 
 * In V3, creating the type system is expensive (due to loading and setting up of JCas classes), so
 * we do the type system creation once per CasDefinition and store it with the CAS definition
 * 
 * @param casDef
 *                completely describes the CAS to be created
 * @param performanceTuningSettings
 *                Properties object containing framework performance tuning settings using key
 *                names defined on {@link UIMAFramework} interface
 * 
 * @return a new CAS matching the given CasDefinition
 * @throws ResourceInitializationException
 *                 if CAS creation fails

 */
public static CAS createCas(CasDefinition casDef, Properties performanceTuningSettings)
    throws ResourceInitializationException {
  TypeSystemImpl tsi = casDef.getTypeSystemImpl();
  CAS cas;
  if (null == tsi) {
    synchronized (casDef) {
      if (null == tsi) { // retest under sync lock
        cas = createCas(casDef.getTypeSystemDescription(), casDef.getTypePriorities(), 
            casDef.getFsIndexDescriptions(), performanceTuningSettings, casDef.getResourceManager());
        casDef.setTypeSystemImpl((TypeSystemImpl) cas.getTypeSystem());
        return cas;
      }  
    }
  } 
  
  return doCreateCas(tsi, casDef.getTypeSystemDescription(), casDef.getTypePriorities(), 
          casDef.getFsIndexDescriptions(), performanceTuningSettings, casDef.getResourceManager());
}
 
Example #5
Source File: TestCasMultiplier.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public boolean hasNext() throws AnalysisEngineProcessException {
  CAS outputCas = getEmptyCAS();
  try {
    Assert.assertTrue(((TypeSystemImpl)mInputCAS.getTypeSystem()).getLargestTypeCode() ==
      ((TypeSystemImpl)outputCas.getTypeSystem()).getLargestTypeCode());
    Assert.assertTrue(mInputCAS.getTypeSystem() == outputCas.getTypeSystem());
  }
  finally {
    outputCas.release();
  }
  return false;
}
 
Example #6
Source File: JsonCasSerializer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Add subtype information for used types limited to used subtypes
 * @throws IOException 
 */
private void addJsonSubtypes(TypeImpl ti) throws IOException {
  IntVector iv = mapType2Subtypes.get(ti.getCode());
  if (null != iv && iv.size() > 0) {
    jch.writeNlJustBeforeNext();
    jg.writeFieldName(SUB_TYPES_NAME);
    jg.writeStartArray();
    
    TypeSystemImpl tsi = ti.getTypeSystem();
    for (int typeCode : iv.toArray()) {
      jg.writeString(getSerializedTypeName(tsi.getTypeForCode(typeCode)));
    }
    jg.writeEndArray();
  }
}
 
Example #7
Source File: IndexRepositoryMergingTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    cas = (CASImpl) CASFactory.createCAS();
    
    TypeSystemImpl ts = this.typeSystem = cas.getTypeSystemImpl();
    annotSubtype = ts.addType("annotSubtype", ts.annotType);
    ts.addFeature("x", annotSubtype, ts.intType);
    cas.commitTypeSystem();  // also creates the initial indexrepository
    // handle type system reuse
    ts = this.typeSystem = cas.getTypeSystemImpl();
    annotSubtype = ts.getType("annotSubtype");
    
    cas.initCASIndexes();  // requires committed type system
    
    
    ir = (FSIndexRepositoryImpl) this.cas.getIndexRepositoryMgr(); 
    FSIndexComparator comp = ir.createComparator();
    Type annotation = ts.getType(CAS.TYPE_NAME_ANNOTATION);
    comp.setType(annotation);
    comp.addKey(annotation.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_BEGIN),
            FSIndexComparator.STANDARD_COMPARE);
    comp.addKey(annotation.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_END),
            FSIndexComparator.REVERSE_STANDARD_COMPARE);
    LinearTypeOrderBuilder tob = ir.createTypeSortOrder();
    try {
//      tob.add(new String[] { CAS.TYPE_NAME_ANNOTATION, "annotSubtype",   });  // is equal to annotationIndex
      tob.add(new String[] { "annotSubtype", CAS.TYPE_NAME_ANNOTATION  });  // is !equal AnnotationIndex
      comp.addKey(tob.getOrder(), FSIndexComparator.STANDARD_COMPARE);
    } catch (CASException e) {
      TestCase.assertTrue(false);
    }
    ir.createIndex(comp, "Annot Index");  // should not be the same as the built-in one due to different type order
    ir.createIndex(comp, "Annot Index2");  // should not be the same as the built-in one due to different type order
    FSIndexComparatorImpl comp2 = ((FSIndexComparatorImpl)comp).copy();
    comp2.setType(annotSubtype);
    ir.createIndex(comp2, "Annot Index Subtype");  // should not be the same as the built-in one due to different type order
    ir.commit();
  }
 
Example #8
Source File: TypeSystemReinitTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testReinitCASCompleteSerializerWithArrays() throws Exception {
  try {
    AnalysisEngineDescription aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
            new XMLInputSource(JUnitExtension
                    .getFile("ExampleTae/arrayTypeSerialization.xml")));
   
    CAS cas1 = CasCreationUtils.createCas(aed);
    cas1.setDocumentText("foo");
    CASCompleteSerializer ser = Serialization.serializeCASComplete((CASMgr) cas1);

    CAS tcas2 = CasCreationUtils.createCas(new TypeSystemDescription_impl(), null, null);
    CASImpl cas2 = ((CASImpl) tcas2).getBaseCAS();
    tcas2.setDocumentText("bar");

    // reinit
    //  This uses cas2 which only has a base type system to start, 
    //    and loads it from a complete serialization which has other new types
    cas2.getBinaryCasSerDes().reinit(ser);
    CAS tcas3 = cas2.getCurrentView();

    assertTrue(tcas2 == tcas3);
    assertNotNull(cas1.getTypeSystem().getType("Test.ArrayType"));
    assertNotNull(tcas3.getTypeSystem().getType("Test.ArrayType"));
    
    TypeSystemImpl ts = (TypeSystemImpl)cas2.getTypeSystem();
    Type arrayType = ts.getType("Test.ArrayType");
    Feature arrayFeat = arrayType.getFeatureByBaseName("arrayFeature");
    TypeImpl featRange = (TypeImpl)(arrayFeat.getRange());
   
    assertTrue(ts.ll_isArrayType(featRange.getCode()));
    assertFalse(arrayFeat.isMultipleReferencesAllowed());
    
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #9
Source File: AnalysisEngineImplBase.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.analysis_engine.AnalysisEngine#getFeatureNamesForType(java.lang.String)
 */
public synchronized String[] getFeatureNamesForType(String aTypeName) {
  // build CAS and populate mFirstTypeSystem
  CASImpl cas = (CASImpl) getCasManager().getCas(this.getUimaContextAdmin().getQualifiedContextName());
  TypeSystemImpl ts = cas.getTypeSystemImpl();
  getCasManager().releaseCas(cas);

  TypeImpl t = ts.getType(aTypeName);
  return (t == null) ? null : t.getFeaturesAsStream().map(f -> f.getShortName()).toArray(size -> new String[size]);
}
 
Example #10
Source File: FSIterator.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @return the type this iterator is over
 */
default Type getType() {
  LowLevelIndex<T> idx = ((LowLevelIterator<T>)this).ll_getIndex();
  return (null == idx) // happens with a low level empty index, maybe wrapped by others
           ? TypeSystemImpl.staticTsi.getTopType()
           : idx.getType();
}
 
Example #11
Source File: BinaryCasReader.java    From bluima with Apache License 2.0 5 votes vote down vote up
public static void deserialize(File file, JCas jCas) throws IOException,
        ClassNotFoundException, ResourceInitializationException {
    InputStream dis = new GZIPInputStream(new FileInputStream(file));
    TypeSystemImpl ts = null;

    ObjectInputStream ois = new ObjectInputStream(dis);
    CASMgrSerializer casMgrSerializer = (CASMgrSerializer) ois.readObject();
    ts = casMgrSerializer.getTypeSystem();
    ts.commit();

    deserializeCAS(jCas.getCas(), dis, ts, null);
    dis.close();
}
 
Example #12
Source File: FeatureStructureClassGen.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private int getReturnInst(FeatureImpl feature) {
  switch (((TypeImpl) feature.getRange()).getCode()) {
  case TypeSystemImpl.booleanTypeCode : return IRETURN;
  case TypeSystemImpl.byteTypeCode    : return IRETURN;
  case TypeSystemImpl.shortTypeCode   : return IRETURN;
  case TypeSystemImpl.intTypeCode     : return IRETURN;
  case TypeSystemImpl.longTypeCode    : return LRETURN;
  case TypeSystemImpl.floatTypeCode   : return FRETURN;
  case TypeSystemImpl.doubleTypeCode  : return DRETURN;
  default                             : return ARETURN;
  }
}
 
Example #13
Source File: FeatureStructureClassGen.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private int getLoadInst(int typeCode) {
  switch (typeCode) {
  case TypeSystemImpl.booleanTypeCode : return ILOAD;
  case TypeSystemImpl.byteTypeCode    : return ILOAD;
  case TypeSystemImpl.shortTypeCode   : return ILOAD;
  case TypeSystemImpl.intTypeCode     : return ILOAD;
  case TypeSystemImpl.longTypeCode    : return LLOAD;
  case TypeSystemImpl.floatTypeCode   : return FLOAD;
  case TypeSystemImpl.doubleTypeCode  : return DLOAD;
  default                             : return ALOAD;
  }
}
 
Example #14
Source File: Jg.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if is string subtype.
 *
 * @param fd the fd
 * @return true, if is string subtype
 */
boolean isStringSubtype(FeatureDescription fd) {
  if (null != typeSystem) {
    String rangeTypeName = fd.getRangeTypeName();
    TypeImpl rangeType = (TypeImpl) typeSystem.getType(rangeTypeName);
    return rangeType.getSuperType() == ((TypeSystemImpl)typeSystem).stringType;
  }
  return false;
}
 
Example #15
Source File: FeatureStructureClassGen.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private int getArrayLoadInst(FeatureImpl feature) {      // load from array
  switch (((TypeImpl) feature.getRange()).getCode()) {
  case TypeSystemImpl.booleanTypeCode : return BALOAD;
  case TypeSystemImpl.byteTypeCode    : return BALOAD;
  case TypeSystemImpl.shortTypeCode   : return SALOAD;
  case TypeSystemImpl.intTypeCode     : return IALOAD;
  case TypeSystemImpl.longTypeCode    : return LALOAD;
  case TypeSystemImpl.floatTypeCode   : return FALOAD;
  case TypeSystemImpl.doubleTypeCode  : return DALOAD;
  default                             : return AALOAD;
  }
}
 
Example #16
Source File: FeatureStructureClassGen.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private int getArrayStoreInst(FeatureImpl feature) {     // store into array
  switch (((TypeImpl) feature.getRange()).getCode()) {
  case TypeSystemImpl.booleanTypeCode : return BASTORE;
  case TypeSystemImpl.byteTypeCode    : return BASTORE;
  case TypeSystemImpl.shortTypeCode   : return SASTORE;
  case TypeSystemImpl.intTypeCode     : return IASTORE;
  case TypeSystemImpl.longTypeCode    : return LASTORE;
  case TypeSystemImpl.floatTypeCode   : return FASTORE;
  case TypeSystemImpl.doubleTypeCode  : return DASTORE;
  default                             : return AASTORE;
  }
}
 
Example #17
Source File: UIMATypeSystemClassLoaderInjector.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new UIMAClassLoader based on a classpath URL's
 * 
 * @param classpath
 *          an array of wellformed classpath URL's
 */
public UIMATypeSystemClassLoaderInjector(ClassLoader cl, TypeSystemImpl tsi) {
  this.cl = cl;
  this.tsi = tsi;
  
  Lookup methodHandleAccessContext = MethodHandles.lookup();
  
  mhFindLoadedClass = Misc.getProtectedMethodHandle(clc, methodHandleAccessContext, "findLoadedClass", sc);
  mhGetPackage      = Misc.getProtectedMethodHandle(clc, methodHandleAccessContext, "getPackage", sc);
  mhDefinePackage   = Misc.getProtectedMethodHandle(clc, methodHandleAccessContext, "definePackage", sc, sc, sc, sc, sc, sc, sc, URL.class);
  mhDefineClass     = Misc.getProtectedMethodHandle(clc, methodHandleAccessContext, "defineClass", sc, byte[].class, int.class, int.class);
  mhResolveClass    = Misc.getProtectedMethodHandle(clc, methodHandleAccessContext, "resolveClass", Class.class);      
}
 
Example #18
Source File: UimacppEngine.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private static void serializeResultSpecification(ResultSpecification rs, CASImpl cas,
        IntVector resultSpecTypes, IntVector resultSpecFeatures) {
  TypeOrFeature[] tofs = rs.getResultTypesAndFeatures();
  TypeSystemImpl tsImpl = cas.getTypeSystemImpl();
  for (int i = 0; i < tofs.length; ++i) {
    if (tofs[i].isType()) {
      TypeImpl t = (TypeImpl) tsImpl.getType(tofs[i].getName());
      resultSpecTypes.add(t.getCode());
    } else {
      FeatureImpl f = (FeatureImpl) tsImpl.getFeatureByFullName(tofs[i].getName());
      resultSpecFeatures.add(f.getCode());
    }
  }
}
 
Example #19
Source File: JCasImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
TypeSystemImpl getTypeSystemImpl() {
  return casImpl.getTypeSystemImpl();
}
 
Example #20
Source File: IndexComparitorTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private void reinitTypes(TypeSystemImpl tsm) {
  
  // Add new types and features.
  topType = tsm.getTopType();
  integerType = tsm.refreshType(integerType);
  stringType = tsm.refreshType(stringType);
  booleanType = tsm.refreshType(booleanType);
  doubleType = tsm.refreshType(doubleType);
  longType = tsm.refreshType(longType);
  byteType = tsm.refreshType(byteType);
  shortType = tsm.refreshType(shortType);
  
  type1 = tsm.refreshType(type1);
  type1Sub1 = tsm.refreshType(type1Sub1);
  type1Sub2 = tsm.refreshType(type1Sub2);

  type1Used = tsm.refreshFeature(type1Used);
  type1UsedShort = tsm.refreshFeature(type1UsedShort);
  type1UsedByte = tsm.refreshFeature(type1UsedByte);
  type1UsedBoolean = tsm.refreshFeature(type1UsedBoolean);
  type1UsedString = tsm.refreshFeature(type1UsedString);
  type1UsedLong = tsm.refreshFeature(type1UsedLong);
  type1UsedDouble = tsm.refreshFeature(type1UsedDouble);
  
  type1Ignored = tsm.refreshFeature(type1Ignored);

  type1Sub1Used = tsm.refreshFeature(type1Sub1Used);
  type1Sub1UsedShort = tsm.refreshFeature(type1Sub1UsedShort);
  type1Sub1UsedByte = tsm.refreshFeature(type1Sub1UsedByte);
  type1Sub1UsedBoolean = tsm.refreshFeature(type1Sub1UsedBoolean);
  type1Sub1UsedString = tsm.refreshFeature(type1Sub1UsedString);
  type1Sub1UsedLong = tsm.refreshFeature(type1Sub1UsedLong);
  type1Sub1UsedDouble = tsm.refreshFeature(type1Sub1UsedDouble);
  type1Sub1Ignored = tsm.refreshFeature(type1Sub1Ignored);

  type1Sub2Used = tsm.refreshFeature(type1Sub2Used);
  type1Sub2UsedShort = tsm.refreshFeature(type1Sub2UsedShort);
  type1Sub2UsedByte = tsm.refreshFeature(type1Sub2UsedByte);
  type1Sub2UsedBoolean = tsm.refreshFeature(type1Sub2UsedBoolean);
  type1Sub2UsedString = tsm.refreshFeature(type1Sub2UsedString);
  type1Sub2UsedLong = tsm.refreshFeature(type1Sub2UsedLong);
  type1Sub2UsedDouble = tsm.refreshFeature(type1Sub2UsedDouble);
  type1Sub2Ignored = tsm.refreshFeature(type1Sub2Ignored);
}
 
Example #21
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);
    }

  }
 
Example #22
Source File: FeatureStructureTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void setUp() {
	try {
		this.cas = (CASImpl) CASInitializer.initCas(new CASTestSetup(), null);
		assertTrue(this.cas != null);
		this.ts = (TypeSystemImpl) this.cas.getTypeSystem();
		assertTrue(this.ts != null);
	} catch (Exception e) {
		e.printStackTrace();
		assertTrue(false);
	}
	this.topType = this.ts.getType(CAS.TYPE_NAME_TOP);
	assertTrue(this.topType != null);
	this.stringType = this.ts.getType(CAS.TYPE_NAME_STRING);
	assertTrue(this.stringType != null);
	this.tokenType = this.ts.getType(CASTestSetup.TOKEN_TYPE);
	assertTrue(this.stringType != null);
	this.intType = this.ts.getType(CAS.TYPE_NAME_INTEGER);
	assertTrue(this.intType != null);
	this.tokenTypeType = this.ts.getType(CASTestSetup.TOKEN_TYPE_TYPE);
	assertTrue(this.tokenTypeType != null);
	this.wordType = this.ts.getType(CASTestSetup.WORD_TYPE);
	assertTrue(this.wordType != null);
	this.arrayFsWithSubtypeType = this.ts.getType(CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE);
	assertTrue(this.arrayFsWithSubtypeType != null);
	this.arrayFsWithSubtypeTypeFeat = this.ts
			.getFeatureByFullName(CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE_FEAT_Q);
	this.group1Type = this.ts.getType(CASTestSetup.GROUP_1);
	assertTrue(this.group1Type != null);
	this.group2Type = this.ts.getType(CASTestSetup.GROUP_2);
	assertTrue(this.group2Type != null);
	this.tokenTypeFeat = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_TYPE_FEAT_Q);
	assertTrue(this.tokenTypeFeat != null);
	this.lemmaFeat = this.ts.getFeatureByFullName(CASTestSetup.LEMMA_FEAT_Q);
	assertTrue(this.lemmaFeat != null);
	this.sentLenFeat = this.ts.getFeatureByFullName(CASTestSetup.SENT_LEN_FEAT_Q);
	assertTrue(this.sentLenFeat != null);
	this.tokenFloatFeat = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_FLOAT_FEAT_Q);
	assertTrue(this.tokenFloatFeat != null);
   this.tokenDoubleFeat = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_DOUBLE_FEAT_Q);
   assertTrue(this.tokenDoubleFeat != null);
   this.tokenLongFeat = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_LONG_FEAT_Q);
   assertTrue(this.tokenLongFeat != null);
	this.startFeature = this.ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_BEGIN);
	assertTrue(this.startFeature != null);
	this.langPairType = this.ts.getType(CASTestSetup.LANG_PAIR);
	assertTrue(this.langPairType != null);
	this.lang1 = this.langPairType.getFeatureByBaseName(CASTestSetup.LANG1);
	assertTrue(this.lang1 != null);
	this.lang2 = this.langPairType.getFeatureByBaseName(CASTestSetup.LANG2);
	assertTrue(this.lang2 != null);
	this.descr = this.langPairType.getFeatureByBaseName(CASTestSetup.DESCR_FEAT);
	assertTrue(this.descr != null);
	this.neListType = this.ts.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
	assertTrue(this.neListType != null);
	this.tlFeature = this.neListType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);
	assertTrue(this.tlFeature != null);
	this.hdFeature = this.neListType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
	assertTrue(this.hdFeature != null);
}
 
Example #23
Source File: UIMATypeSystemClassLoader.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void setTsi(TypeSystemImpl tsi) {
  this.tsi = tsi;
}
 
Example #24
Source File: CasDefinition.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * @param typeSystemImpl the typeSystemImpl to set
 */
public void setTypeSystemImpl(TypeSystemImpl typeSystemImpl) {
  this.typeSystemImpl = typeSystemImpl;
}
 
Example #25
Source File: CasDefinition.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * @return the typeSystemImpl
 */
public TypeSystemImpl getTypeSystemImpl() {
  return typeSystemImpl;
}
 
Example #26
Source File: CASFactory.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public static CASMgr createCAS(TypeSystem ts, boolean useJcasCache) {
  if (ts == null) {
    throw new NullPointerException("TypeSystem");
  }
  return new CASImpl((TypeSystemImpl) ts, CASImpl.DEFAULT_INITIAL_HEAP_SIZE);
}
 
Example #27
Source File: CASFactory.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public static CASMgr createCAS(int initialHeapSize, TypeSystem ts, boolean useJcasCache) {
  if (ts == null) {
    throw new NullPointerException("TypeSystem");
  }
  return new CASImpl((TypeSystemImpl) ts, initialHeapSize);
}
 
Example #28
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 #29
Source File: JsonCasSerializer.java    From uima-uimaj with Apache License 2.0 3 votes vote down vote up
/**
 * Serializes a Delta CAS to an output (File, Writer, or OutputStream).  
 * This version of this method allows many options to be configured.
 *    
 *    
 * @param aCAS
 *          CAS to serialize.
 * @param aTargetTypeSystem
 *          type system to which the produced XMI will conform. Any types or features not in the
 *          target type system will not be serialized.  A null value indicates that all types and features
 *          will be serialized.
 * @param output
 *          File, Writer, or OutputStream to which to write the JSON document
 * @param aPrettyPrint
 *          if true the JSON output will be formatted with newlines and indenting.  If false it will be unformatted.
 * @param aMarker
 *        an optional object used to determine which FeatureStructures and modifications were created after
 *          the mark was set. Used to serialize a Delta CAS consisting of only new FSs and views and
 *          preexisting FSs and Views that have been modified.  If null, full serialization is done.        
 *          See the JavaDocs for {@link Marker} for details.
 * @param sharedData optional, used for delta serialization (not yet supported)
 * @throws IOException if there was an IOException
 */
public static void jsonSerialize(CAS aCAS, TypeSystem aTargetTypeSystem, Object output, boolean aPrettyPrint, 
    Marker aMarker, XmiSerializationSharedData sharedData) 
        throws IOException {
  JsonCasSerializer ser = new JsonCasSerializer();
  ser.setFilterTypes((TypeSystemImpl)aTargetTypeSystem);
  ser.setPrettyPrint(aPrettyPrint);
  ser.serialize(aCAS, output, sharedData, aMarker);
}
 
Example #30
Source File: CasIOUtils.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * This load variant can be used for loading Form 6 compressed CASes where the 
 * type system to use to deserialize is provided as an argument.  It can also load other formats,
 * where its behavior is identical to load(casInputStream, aCas).
 *
 * Loads a CAS from an Input Stream. The format is determined from the content.
 * For SerialFormats of ending in _TSI SERIALIZED_TSI or COMPRESSED_FILTERED_TSI, 
 * the type system and index definitions are read from the cas input source;
 * the value of typeSystem is ignored.
 * 
 * For COMPRESSED_FILTERED_xxx formats, if the typeSystem is not null, 
 * the typeSystem is used for decoding.
 * 
 * If embedded TSI information is available, the CAS's type system and indexes definition are replaced,
 * except for SerialFormats COMPRESSED_FILTERED, COMPRESSED_FILTERED_TS, and COMPRESSED_FILTERED_TSI.
 * 
 *   To replace the CAS's type system and indexes definition for these, use a load form which 
 *   has the CasLoadMode argument, and set this to REINIT.
 *     
 * @param casInputStream
 *          The input stream containing the CAS, appropriately buffered.
 * @param aCAS
 *          The CAS that should be filled
 * @param typeSystem the type system to use for decoding the serialized form, must be non-null         
 * @return the SerialFormat of the loaded CAS
 * @throws IOException Problem loading from given InputStream   
 */
public static SerialFormat load(InputStream casInputStream, CAS aCAS, TypeSystem typeSystem) throws IOException {
  return load(casInputStream, null, aCAS, CasLoadMode.DEFAULT, (TypeSystemImpl) typeSystem);
}