Search in sources :

Example 1 with ResourceManager_impl

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

the class FeatureUtil method createResource.

// TODO this will eventually also be included in uimaFit and can be removed then
@SuppressWarnings("unchecked")
public static <T extends Resource> T createResource(Class<T> aClass, Object... aParam) throws ResourceInitializationException, ResourceAccessException {
    // Configure external resource
    ExternalResourceDescription desc = ExternalResourceFactory.createExternalResourceDescription(aClass, aParam);
    // 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)

Example 2 with ResourceManager_impl

use of org.apache.uima.resource.impl.ResourceManager_impl 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

UimaContextAdmin (org.apache.uima.UimaContextAdmin)2 RootUimaContext_impl (org.apache.uima.impl.RootUimaContext_impl)2 ExternalResourceDescription (org.apache.uima.resource.ExternalResourceDescription)2 ResourceManager (org.apache.uima.resource.ResourceManager)2 ResourceManager_impl (org.apache.uima.resource.impl.ResourceManager_impl)2 ResourceManagerConfiguration (org.apache.uima.resource.metadata.ResourceManagerConfiguration)2