Java Code Examples for org.apache.uima.cas.impl.CASImpl#getTypeSystemImpl()

The following examples show how to use org.apache.uima.cas.impl.CASImpl#getTypeSystemImpl() . 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: JsonCasSerializerTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private void setupTypeSystem(String tsdName) throws InvalidXMLException, IOException, ResourceInitializationException, CASException {
    File tsdFile = JUnitExtension.getFile("CasSerialization/desc/" + tsdName);
    tsd = parser.parseTypeSystemDescription(new XMLInputSource(tsdFile));
    cas = (CASImpl) CasCreationUtils.createCas(tsd, null, null);
//    cas.getSofaRef();  // creates the default sofa
    jcas = cas.getJCas();
    tsi = cas.getTypeSystemImpl();
    topType = (TypeImpl) tsi.getTopType();
    annotationType = (TypeImpl) tsi.getType("uima.tcas.Annotation"); 
    allTypesType = (TypeImpl) tsi.getType("org.apache.uima.test.AllTypes");
    tokenType = (TypeImpl) tsi.getType("org.apache.uima.test.Token");
    emptyIntListType = (TypeImpl) tsi.getType("uima.cas.EmptyIntegerList");
//    nonEmptyIntListType = (TypeImpl) tsi.getType("uima.cas.NonEmptyIntegerList");
//    emptyFSListType = (TypeImpl) tsi.getType("uima.cas.EmptyFSList");
//    nonEmptyFSListType = (TypeImpl) tsi.getType("uima.cas.NonEmptyFSList");
    
  }
 
Example 2
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 3
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 4
Source File: AnnotationIndexTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
  long startTime = System.nanoTime();
  TypeSystemDescription typeSystemDescription = UIMAFramework.getXMLParser().parseTypeSystemDescription(
      new XMLInputSource(typeSystemFile1));
  System.out.format("time to parse ts: %,d%n", (System.nanoTime() - startTime)/ 1000000);
  startTime = System.nanoTime();
  cas = (CASImpl) CasCreationUtils.createCas(typeSystemDescription, new TypePriorities_impl(), null);
  jcas = cas.getJCas();
  ir = (FSIndexRepositoryImpl) cas.getIndexRepository();
  ai = cas.getAnnotationIndex(); 
  tsi = cas.getTypeSystemImpl();
  topType = tsi.getTopType();   
  System.out.format("time to create CAS: %,d%n", (System.nanoTime() - startTime)/ 1000000);
  startTime = System.nanoTime();
  
  //prefill
  int[] ttt = new int[SZp2];
  for (int i = 0; i < SZp2; i++) { ttt[i] = i;}
  ttt = shuffle(ttt);  
    
  
  for (int i = 0; i < SZp2; i++) {
    as[ttt[i]] = new Annotation(jcas, i, i + 200);
    ir.addFS(as[ttt[i]]);
  }

  System.out.format("time to create Annotations, add to indexes: %,d%n", (System.nanoTime() - startTime)/ 1000000);
  startTime = System.nanoTime();

}
 
Example 5
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 6
Source File: CasCopier.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
   * Creates a new CasCopier that can be used to copy FeatureStructures from one CAS to another.
   * Note that if you are merging data from multiple CASes, you must create a new CasCopier
   * for each source CAS. This version of the constructor supports a "lenient copy" option. When set,
   * the CAS copy function will ignore (not attempt to copy) FSs and features not defined in the type system
   * of the destination CAS, rather than throwing an exception.
   * 
   * @param aSrcCas
   *          the CAS to copy from.
   * @param aDestCas
   *          the CAS to copy into.
   * @param lenient
   *          ignore FSs and features not defined in the type system of the destination CAS
   */
  public CasCopier(CAS aSrcCas, CAS aDestCas, boolean lenient) {

    mFsMap = new IdentityHashMap<>(((CASImpl)(aSrcCas.getLowLevelCAS())).getLastUsedFsId());
    originalSrcCas = (CASImpl)aSrcCas.getLowLevelCAS();
    originalTgtCas = (CASImpl)aDestCas.getLowLevelCAS();
    
    srcTsi = originalSrcCas.getTypeSystemImpl();
    tgtTsi = originalTgtCas.getTypeSystemImpl();

    src2TgtType = (srcTsi == tgtTsi) ? null : new Int2ObjListMap<>(srcTsi.getTypeArraySize());
    src2TgtFeat = (srcTsi == tgtTsi) ? null : new Int2ObjListMap<>(srcTsi.getNumberOfFeatures() + 1);
    

//    tInfoArray = new TypeInfo[srcTsi.getLargestTypeCode() + 1];
    
//    srcStringType = srcTsi.stringType;
//    srcStringTypeCode = srcStringType.getCode();
    
//    mDestSofaFeature = aDestCas.getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFA);
    this.lenient = lenient;
    
    // the next is to support the style of use where
    //   an instance of this copier is made, corresponding to two views in the same CAS
    //   or corresponding to two views in different CASs
    //   and then individual FeatureStructures are copied using copyFS(...)
    
    srcCasViewImpl = (CASImpl) originalSrcCas.getLowLevelCAS();
    tgtCasViewImpl = (CASImpl) originalTgtCas.getLowLevelCAS();
    
    srcViewName = srcCasViewImpl.getViewName();
    tgtViewName = tgtCasViewImpl.getViewName();
    
    if (srcViewName == null) {  // base cas
      isChangeViewName = (tgtViewName == null) ? false : true;
    } else {
      isChangeViewName = !srcViewName.equals(tgtViewName);
    }
    
    isEqualTypeSystems = srcTsi.equals(tgtTsi);
  }