Search in sources :

Example 1 with CustomResourceSpecifier

use of org.apache.uima.resource.CustomResourceSpecifier in project dkpro-lab by dkpro.

the class TaskContextProvider method initialize.

@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException {
    if (!super.initialize(aSpecifier, aAdditionalParams)) {
        return false;
    }
    // Create synthetic context to be able to use InitializeUtil.
    UimaContextAdmin context = UIMAFramework.newUimaContext(UIMAFramework.getLogger(), UIMAFramework.newDefaultResourceManager(), UIMAFramework.newConfigurationManager());
    ConfigurationManager cfgMgr = context.getConfigurationManager();
    cfgMgr.setSession(context.getSession());
    CustomResourceSpecifier spec = (CustomResourceSpecifier) aSpecifier;
    for (Parameter p : spec.getParameters()) {
        cfgMgr.setConfigParameterValue(context.getQualifiedContextName() + p.getName(), p.getValue());
    }
    ConfigurationParameterInitializer.initialize(this, context);
    return true;
}
Also used : CustomResourceSpecifier(org.apache.uima.resource.CustomResourceSpecifier) UimaContextAdmin(org.apache.uima.UimaContextAdmin) ConfigurationParameter(org.apache.uima.fit.descriptor.ConfigurationParameter) Parameter(org.apache.uima.resource.Parameter) ConfigurationManager(org.apache.uima.resource.ConfigurationManager)

Example 2 with CustomResourceSpecifier

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

the class ModelSerializationTask method persistsFeatureClassObject.

private void persistsFeatureClassObject(TcFeature f, File aOutputFolder) throws Exception {
    ExternalResourceDescription feDesc = f.getActualValue();
    String implName;
    if (feDesc.getResourceSpecifier() instanceof CustomResourceSpecifier) {
        implName = ((CustomResourceSpecifier) feDesc.getResourceSpecifier()).getResourceClassName();
    } else {
        implName = feDesc.getImplementationName();
    }
    storeFeature(aOutputFolder, implName);
}
Also used : CustomResourceSpecifier(org.apache.uima.resource.CustomResourceSpecifier) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 3 with CustomResourceSpecifier

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

the class ModelSerializationTask method copyLuceneMetaResourcesAndGetOverrides.

private void copyLuceneMetaResourcesAndGetOverrides(TaskContext aContext, TcFeature f, File aOutputFolder) throws Exception {
    ExternalResourceDescription feDesc = f.getActualValue();
    Map<String, Object> parameterSettings = ConfigurationParameterFactory.getParameterSettings(feDesc.getResourceSpecifier());
    String implName;
    if (feDesc.getResourceSpecifier() instanceof CustomResourceSpecifier) {
        implName = ((CustomResourceSpecifier) feDesc.getResourceSpecifier()).getResourceClassName();
    } else {
        implName = feDesc.getImplementationName();
    }
    Class<?> feClass = Class.forName(implName);
    // Skip feature extractors that are not dependent on meta collectors
    if (!MetaDependent.class.isAssignableFrom(feClass)) {
        return;
    }
    MetaDependent feInstance = (MetaDependent) feClass.newInstance();
    Map<String, Object> metaOverrides = new HashMap<>();
    Map<String, Object> extractorOverrides = new HashMap<>();
    // Tell the meta collectors where to store their data
    for (MetaCollectorConfiguration conf : feInstance.getMetaCollectorClasses(parameterSettings)) {
        Map<String, String> collectorOverrides = conf.collectorOverrides;
        metaOverrides.putAll(collectorOverrides);
        extractorOverrides.putAll(conf.extractorOverrides);
        for (Entry<String, String> entry : collectorOverrides.entrySet()) {
            File file = new File(aContext.getFolder(META_KEY, AccessMode.READWRITE), entry.getValue().toString());
            String name = file.getName();
            String subFolder = aOutputFolder.getAbsoluteFile() + "/" + name;
            File targetFolder = new File(subFolder);
            copyToTargetLocation(file, targetFolder);
        }
    }
    writeOverrides(aOutputFolder, metaOverrides, META_COLLECTOR_OVERRIDE);
    writeOverrides(aOutputFolder, extractorOverrides, META_EXTRACTOR_OVERRIDE);
}
Also used : MetaDependent(org.dkpro.tc.api.features.meta.MetaDependent) CustomResourceSpecifier(org.apache.uima.resource.CustomResourceSpecifier) HashMap(java.util.HashMap) MetaCollectorConfiguration(org.dkpro.tc.api.features.meta.MetaCollectorConfiguration) File(java.io.File) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 4 with CustomResourceSpecifier

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

the class ExtractFeaturesTask method getRequiredTypesFromFeatureExtractors.

private Set<String> getRequiredTypesFromFeatureExtractors(List<ExternalResourceDescription> featureSet) throws Exception {
    Set<String> requirements = new HashSet<>();
    for (ExternalResourceDescription element : featureSet) {
        String implName;
        if (element.getResourceSpecifier() instanceof CustomResourceSpecifier) {
            implName = ((CustomResourceSpecifier) element.getResourceSpecifier()).getResourceClassName();
        } else {
            implName = element.getImplementationName();
        }
        TypeCapability annotation = ReflectionUtil.getAnnotation(Class.forName(implName), TypeCapability.class);
        if (annotation == null) {
            continue;
        }
        String[] inputs = annotation.inputs();
        StringBuilder sb = new StringBuilder();
        sb.append(implName + "|");
        for (int i = 0; i < inputs.length; i++) {
            sb.append(inputs[i]);
            if (i + 1 < inputs.length) {
                sb.append("|");
            }
        }
        requirements.add(sb.toString());
    }
    return requirements;
}
Also used : TypeCapability(org.apache.uima.fit.descriptor.TypeCapability) CustomResourceSpecifier(org.apache.uima.resource.CustomResourceSpecifier) HashSet(java.util.HashSet) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Aggregations

CustomResourceSpecifier (org.apache.uima.resource.CustomResourceSpecifier)4 ExternalResourceDescription (org.apache.uima.resource.ExternalResourceDescription)3 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 UimaContextAdmin (org.apache.uima.UimaContextAdmin)1 ConfigurationParameter (org.apache.uima.fit.descriptor.ConfigurationParameter)1 TypeCapability (org.apache.uima.fit.descriptor.TypeCapability)1 ConfigurationManager (org.apache.uima.resource.ConfigurationManager)1 Parameter (org.apache.uima.resource.Parameter)1 MetaCollectorConfiguration (org.dkpro.tc.api.features.meta.MetaCollectorConfiguration)1 MetaDependent (org.dkpro.tc.api.features.meta.MetaDependent)1