Search in sources :

Example 6 with ResourceManager

use of org.apache.uima.resource.ResourceManager in project dkpro-tc by dkpro.

the class FeatureUtil method createResource.

@SuppressWarnings("unchecked")
public static <T extends Resource> T createResource(TcFeature feature) throws ResourceInitializationException, ResourceAccessException {
    // Configure external resource
    ExternalResourceDescription desc = feature.getActualValue();
    // Configure resource manager
    ResourceManagerConfiguration cfg = UIMAFramework.getResourceSpecifierFactory().createResourceManagerConfiguration();
    ExternalResourceFactory.bindExternalResource(cfg, "rootResource", desc);
    // Instantiate resource manager (internally instantiates resources)
    final ResourceManager manager = new ResourceManager_impl();
    manager.initializeExternalResources(cfg, "/", null);
    T res = (T) manager.getResource("/rootResource");
    // Initialize nested resources
    UimaContextAdmin ctx = new RootUimaContext_impl() {

        @Override
        public ResourceManager getResourceManager() {
            return manager;
        }
    };
    ExternalResourceInitializer.initialize(res, ctx);
    // Get resource instance
    return res;
}
Also used : RootUimaContext_impl(org.apache.uima.impl.RootUimaContext_impl) ResourceManagerConfiguration(org.apache.uima.resource.metadata.ResourceManagerConfiguration) UimaContextAdmin(org.apache.uima.UimaContextAdmin) ResourceManager(org.apache.uima.resource.ResourceManager) ResourceManager_impl(org.apache.uima.resource.impl.ResourceManager_impl) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Aggregations

ResourceManager (org.apache.uima.resource.ResourceManager)6 UIMAFramework.newDefaultResourceManager (org.apache.uima.UIMAFramework.newDefaultResourceManager)3 UimaContextAdmin (org.apache.uima.UimaContextAdmin)3 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)3 ExecutionException (org.dkpro.lab.engine.ExecutionException)3 LifeCycleException (org.dkpro.lab.engine.LifeCycleException)3 UimaTask (org.dkpro.lab.uima.task.UimaTask)3 RootUimaContext_impl (org.apache.uima.impl.RootUimaContext_impl)2 ExternalResourceDescription (org.apache.uima.resource.ExternalResourceDescription)2 ResourceManager_impl (org.apache.uima.resource.impl.ResourceManager_impl)2 ResourceManagerConfiguration (org.apache.uima.resource.metadata.ResourceManagerConfiguration)2 TaskContext (org.dkpro.lab.engine.TaskContext)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UIMAFramework.produceCollectionReader (org.apache.uima.UIMAFramework.produceCollectionReader)1 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)1 AggregateAnalysisEngine_impl (org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl)1 PrimitiveAnalysisEngine_impl (org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl)1 CAS (org.apache.uima.cas.CAS)1