private CAS getEmptyCas() throws ResourceInitializationException { CAS cas = null; while(cas == null) { // Use class level locking to serialize access to CasCreationUtils // Only one thread at the time can create a CAS. UIMA uses lazy // initialization approach which can cause NPE when two threads // attempt to initialize a CAS. synchronized( CasCreationUtils.class) { cas = CasCreationUtils.createCas(cr_tsd, cr_tp, cr_fid, cr_properties); } } return cas; }
public DynamicTypeGenerator(ArrayList<TypeSystemDescription> typeSystemDescriptions) { try { TypeSystemDescription mergedTypeSystem = CasCreationUtils.mergeTypeSystems(typeSystemDescriptions); this.typeSystemDescription = mergedTypeSystem; JCas jCas = CasCreationUtils.createCas(mergedTypeSystem, null, null).getJCas(); customTypes = new HashSet<>(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
/** * Creates the cas. * * @param aAeDescription the a ae description * @param aPerformanceTuningSettings the a performance tuning settings * @param aResourceManager the a resource manager * @return the cas * @throws ResourceInitializationException the resource initialization exception */ public CAS createCas(AnalysisEngineDescription aAeDescription, Properties aPerformanceTuningSettings, ResourceManager aResourceManager) throws ResourceInitializationException { getMergeInput(aAeDescription, aResourceManager); // merge TypeSystemDescription aggTypeDesc = CasCreationUtils.mergeTypeSystems(typeSystemsToMerge, aResourceManager); TypePriorities aggTypePriorities = CasCreationUtils.mergeTypePriorities(typePrioritiesToMerge, aResourceManager); FsIndexCollection aggIndexColl = CasCreationUtils.mergeFsIndexes(fsIndexesToMerge, aResourceManager); return CasCreationUtils.createCas(aggTypeDesc, aggTypePriorities, aggIndexColl.getFsIndexes(), aPerformanceTuningSettings, aResourceManager); }
List<ProcessingResourceMetaData> mdList = getMetaDataList(l, aResourceManager); fsIndexes.add(md.getFsIndexCollection()); return mergeFsIndexes(fsIndexes, aResourceManager);
/** * Merges several TypeSystemDescriptions into one. Also resolves imports in the * TypeSystemDescription objects. * * @param aTypeSystems * a collection of TypeSystems to be merged * @param aResourceManager * Resource Manager to use to locate type systems imported by name * * @return a new TypeSystemDescription that is the result of merging all of the type systems * together * * @throws ResourceInitializationException * if an incompatibility exists or if an import could not be resolved */ public static TypeSystemDescription mergeTypeSystems(Collection<? extends TypeSystemDescription> aTypeSystems, ResourceManager aResourceManager) throws ResourceInitializationException { return mergeTypeSystems(aTypeSystems, aResourceManager, null); }
throws ResourceInitializationException { List<ProcessingResourceMetaData> mdList = getMetaDataList(aComponentDescriptionsOrMetaData, aResourceManager); TypeSystemDescription aggTypeDesc = mergeTypeSystems(typeSystems, aResourceManager); TypePriorities aggTypePriorities = mergeTypePriorities(typePriorities, aResourceManager); FsIndexCollection aggIndexColl = mergeFsIndexes(fsIndexes, aResourceManager); return doCreateCas(null, aggTypeDesc, aggTypePriorities, aggIndexColl.getFsIndexes(), aPerformanceTuningSettings, aResourceManager);
public CasDefinition(Collection<? extends ProcessingResourceMetaData> aMetaDataToMerge, ResourceManager aResourceManager) throws ResourceInitializationException { // extract TypeSystems, TypePriorities, and FsIndexes from metadata List<TypeSystemDescription> typeSystems = new ArrayList<TypeSystemDescription>(); List<TypePriorities> typePrioritiesList = new ArrayList<TypePriorities>(); List<FsIndexCollection> fsIndexes = new ArrayList<FsIndexCollection>(); Iterator<? extends ProcessingResourceMetaData> it = aMetaDataToMerge.iterator(); while (it.hasNext()) { ProcessingResourceMetaData md = it.next(); if (md.getTypeSystem() != null) typeSystems.add(md.getTypeSystem()); if (md.getTypePriorities() != null) typePrioritiesList.add(md.getTypePriorities()); if (md.getFsIndexCollection() != null) fsIndexes.add(md.getFsIndexCollection()); } // merge TypePriorities and FsIndexes TypePriorities aggTypePriorities = CasCreationUtils.mergeTypePriorities(typePrioritiesList, aResourceManager); FsIndexCollection aggIndexColl = CasCreationUtils.mergeFsIndexes(fsIndexes, aResourceManager); TypeSystemDescription aggTypeDesc = CasCreationUtils.mergeTypeSystems(typeSystems, aResourceManager); this.typeSystemDescription = aggTypeDesc; this.typePriorities = aggTypePriorities; this.fsIndexDescriptions = aggIndexColl.getFsIndexes(); this.resourceManager = aResourceManager; }
aTypeSystemDesc = mergeTypeSystems(tsList, aResourceManager, null); setupTypeSystem(casMgr, aTypeSystemDesc); setupTypePriorities(casMgr, aTypePriorities); setupIndexes(casMgr, aFsIndexes);
List<ProcessingResourceMetaData> mdList = getMetaDataList(l, aResourceManager); typeSystems.add(md.getTypeSystem()); return mergeTypeSystems(typeSystems, aResourceManager, aOutputMergedTypes);
List<ProcessingResourceMetaData> mdList = getMetaDataList(l, aResourceManager); typePriorities.add(md.getTypePriorities()); return mergeTypePriorities(typePriorities, aResourceManager);
/** * Merge delegate analysis engine type priorities. * * @param aAeDescription the a ae description * @param aResourceManager the a resource manager * @return the type priorities * @throws ResourceInitializationException the resource initialization exception */ private TypePriorities mergeDelegateAnalysisEngineTypePriorities( AnalysisEngineDescription aAeDescription, ResourceManager aResourceManager) throws ResourceInitializationException { getMergeInput(aAeDescription, aResourceManager); return CasCreationUtils.mergeTypePriorities(typePrioritiesToMerge, aResourceManager); }
/** * Merge delegate analysis engine fs index collections. * * @param aAeDescription the a ae description * @param aResourceManager the a resource manager * @return the fs index collection * @throws ResourceInitializationException the resource initialization exception */ private FsIndexCollection mergeDelegateAnalysisEngineFsIndexCollections( AnalysisEngineDescription aAeDescription, ResourceManager aResourceManager) throws ResourceInitializationException { getMergeInput(aAeDescription, aResourceManager); return CasCreationUtils.mergeFsIndexes(fsIndexesToMerge, aResourceManager); }
/** * Merge delegate analysis engine type systems. * * @param aAeDescription the a ae description * @param aResourceManager the a resource manager * @param aOutputMergedTypes the a output merged types * @return the type system description * @throws ResourceInitializationException the resource initialization exception */ private TypeSystemDescription mergeDelegateAnalysisEngineTypeSystems( AnalysisEngineDescription aAeDescription, ResourceManager aResourceManager, Map aOutputMergedTypes) throws ResourceInitializationException { getMergeInput(aAeDescription, aResourceManager); return CasCreationUtils.mergeTypeSystems(typeSystemsToMerge, aResourceManager, aOutputMergedTypes); }
throws ResourceInitializationException { List<ProcessingResourceMetaData> mdList = getMetaDataList(aComponentDescriptionsOrMetaData, aResourceManager); TypePriorities aggTypePriorities = mergeTypePriorities(typePriorities, aResourceManager); FsIndexCollection aggIndexColl = mergeFsIndexes(fsIndexes, aResourceManager); return doCreateCas(aTypeSystem, null, aggTypePriorities, aggIndexColl.getFsIndexes(), aPerformanceTuningSettings, aResourceManager); } else { TypeSystemDescription aggTypeDesc = mergeTypeSystems(typeSystems); return doCreateCas(null, aggTypeDesc, aggTypePriorities, aggIndexColl.getFsIndexes(), aPerformanceTuningSettings, aResourceManager);
TypeSystemDescription aggTypeDesc = CasCreationUtils.mergeTypeSystems(typeSystems, getResourceManager()); TypePriorities aggTypePriorities = CasCreationUtils.mergeTypePriorities(typePriorities, getResourceManager()); FsIndexCollection aggIndexColl = CasCreationUtils.mergeFsIndexes(fsIndexCollections, getResourceManager());
TypePriorities aggTypePriorities = CasCreationUtils.mergeTypePriorities(typePrioritiesList, resMgr);
private FsIndexCollection mergeFsIndexes() throws ResourceInitializationException { FsIndexCollection aggIndexColl = getCasManagerWrapper().getMetadata() .getFsIndexCollection(); if ( aggregateMetadata.getFsIndexes() != null ) { for ( FsIndexDescription fid : aggregateMetadata.getFsIndexes() ) { getCasManagerWrapper().getMetadata() .getFsIndexCollection().addFsIndex(fid); } List<FsIndexCollection> cl = new ArrayList<FsIndexCollection>(); cl.add(getCasManagerWrapper().getMetadata().getFsIndexCollection()); aggIndexColl = CasCreationUtils. mergeFsIndexes(cl, getCasManagerWrapper().getResourceManager()); } return aggIndexColl; } private TypePriorities mergeTypePriorities() throws ResourceInitializationException {
private CAS createCas() throws ResourceInitializationException { return CasCreationUtils.createCas(ts, null, null, null); }
private TypeSystem createTypeSystem() throws IOException, UIMAException { TypeSystemDescription tsDesc = null; if (typeSystemDescPaths != null && typeSystemDescPaths.length > 0) { tsDesc = createTypeSystemDescriptionFromPath(typeSystemDescPaths); } if (typeSystemDescNames != null && typeSystemDescNames.length > 0) { TypeSystemDescription tsDescFromNames = createTypeSystemDescription( typeSystemDescNames); if (tsDesc != null) { tsDesc = mergeTypeSystems(asList(tsDesc, tsDescFromNames)); } else { tsDesc = tsDescFromNames; } } if (tsDesc == null) { throw new IllegalStateException( "Type system description paths or names were not specified!"); } CAS dumbCas = CasCreationUtils.createCas(tsDesc, null, null); TypeSystem typeSystem = dumbCas.getTypeSystem(); // printAllTypes(); return typeSystem; }
/** * Merges several TypeSystemDescriptions into one. Also resolves imports in the * TypeSystemDescription objects. * * @param aTypeSystems * a collection of TypeSystems to be merged * * @return a new TypeSystemDescription that is the result of merging all of the type systems * together * * @throws ResourceInitializationException * if an incompatibility exists or if an import could not be resolved */ public static TypeSystemDescription mergeTypeSystems(Collection<? extends TypeSystemDescription> aTypeSystems) throws ResourceInitializationException { return mergeTypeSystems(aTypeSystems, UIMAFramework.newDefaultResourceManager()); }