use of org.apache.uima.resource.ExternalResourceDescription 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;
}
use of org.apache.uima.resource.ExternalResourceDescription in project dkpro-tc by dkpro.
the class TcFeature method getDiscriminatorValue.
@Override
public Object getDiscriminatorValue() {
StringBuilder desc = new StringBuilder();
desc.append("[");
desc.append(fullFeatureName);
if (params != null && params.length > 0) {
desc.append("| ");
for (int i = 0; i < params.length; i++) {
Object object = params[i];
if (object instanceof ExternalResourceDescription) {
ExternalResourceDescription erd = (ExternalResourceDescription) object;
desc.append("ExtResDesc[" + erd.getName() + "]");
} else {
desc.append(object.toString());
}
if (i + 1 < params.length) {
desc.append(", ");
}
}
}
desc.append("]");
return desc.toString();
}
use of org.apache.uima.resource.ExternalResourceDescription in project dkpro-tc by dkpro.
the class SimilarityPairFeatureTest method similarityPairFeatureTest.
@Test
public void similarityPairFeatureTest() throws Exception {
ExternalResourceDescription gstResource = ExternalResourceFactory.createExternalResourceDescription(GreedyStringTilingMeasureResource.class, GreedyStringTilingMeasureResource.PARAM_MIN_MATCH_LENGTH, "3");
AnalysisEngineDescription desc = createEngineDescription(NoOpAnnotator.class);
AnalysisEngine engine = createEngine(desc);
JCas jcas = engine.newJCas();
TokenBuilder<Token, Sentence> tb = new TokenBuilder<Token, Sentence>(Token.class, Sentence.class);
JCas view1 = jcas.createView(VIEW1);
view1.setDocumentLanguage("en");
tb.buildTokens(view1, "This is a test .");
JCas view2 = jcas.createView(VIEW2);
view2.setDocumentLanguage("en");
tb.buildTokens(view2, "Test is this .");
engine.process(jcas);
SimilarityPairFeatureExtractor extractor = FeatureUtil.createResource(SimilarityPairFeatureExtractor.class, SimilarityPairFeatureExtractor.PARAM_UNIQUE_EXTRACTOR_NAME, "123", SimilarityPairFeatureExtractor.PARAM_SEGMENT_FEATURE_PATH, Token.class.getName(), SimilarityPairFeatureExtractor.PARAM_TEXT_SIMILARITY_RESOURCE, gstResource);
Set<Feature> features = extractor.extract(jcas.getView(VIEW1), jcas.getView(VIEW2));
Assert.assertEquals(1, features.size());
Iterator<Feature> iter = features.iterator();
assertFeature("SimilarityGreedyStringTiling_3", 0.8125, iter.next(), 0.0001);
}
use of org.apache.uima.resource.ExternalResourceDescription in project dkpro-tc by dkpro.
the class WordNGramTest method luceneNGramFeatureExtractorNonDefaultFrequencyThresholdTest.
@Test
public void luceneNGramFeatureExtractorNonDefaultFrequencyThresholdTest() throws Exception {
File luceneFolder = folder.newFolder();
File outputPath = folder.newFolder();
Object[] parameters = new Object[] { WordNGram.PARAM_NGRAM_USE_TOP_K, "3", WordNGram.PARAM_UNIQUE_EXTRACTOR_NAME, "123", WordNGram.PARAM_SOURCE_LOCATION, luceneFolder.toString(), WordNGram.PARAM_NGRAM_FREQ_THRESHOLD, "0.1f", WordNGramMC.PARAM_TARGET_LOCATION, luceneFolder.toString() };
List<Object> parameterList = new ArrayList<Object>(Arrays.asList(parameters));
CollectionReaderDescription reader = getMetaReader();
AnalysisEngineDescription segmenter = AnalysisEngineFactory.createEngineDescription(BreakIteratorSegmenter.class);
AnalysisEngineDescription metaCollector = AnalysisEngineFactory.createEngineDescription(WordNGramMC.class, parameterList.toArray());
ExternalResourceDescription featureExtractor = ExternalResourceFactory.createExternalResourceDescription(WordNGram.class, parameters);
List<ExternalResourceDescription> fes = new ArrayList<>();
fes.add(featureExtractor);
AnalysisEngineDescription featExtractorConnector = TaskUtils.getFeatureExtractorConnector(outputPath.getAbsolutePath(), JsonDataWriter.class.getName(), Constants.LM_SINGLE_LABEL, Constants.FM_DOCUMENT, false, false, false, false, Collections.emptyList(), fes, new String[] {});
// run meta collector
SimplePipeline.runPipeline(reader, segmenter, metaCollector);
// run FE(s)
SimplePipeline.runPipeline(reader, segmenter, featExtractorConnector);
List<Instance> instances = readInstances(outputPath);
assertEquals(4, instances.size());
assertEquals(1, getUniqueOutcomes(instances));
for (Instance i : instances) {
assertTrue(i.getFeatures().isEmpty());
}
}
use of org.apache.uima.resource.ExternalResourceDescription in project dkpro-tc by dkpro.
the class LuceneMetaCollectionBasedFeatureTestBase method prepareFeatureExtractor.
protected AnalysisEngineDescription prepareFeatureExtractor(File outputPath, Class<? extends Resource_ImplBase> class1, Object[] parameters) throws ResourceInitializationException {
List<ExternalResourceDescription> fes = makeResource(class1, parameters);
AnalysisEngineDescription featExtractorConnector = TaskUtils.getFeatureExtractorConnector(outputPath.getAbsolutePath(), JsonDataWriter.class.getName(), Constants.LM_SINGLE_LABEL, Constants.FM_DOCUMENT, false, false, false, false, Collections.emptyList(), fes, new String[] {});
return featExtractorConnector;
}
Aggregations