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;
}
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);
}
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);
}
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;
}
Aggregations