Search in sources :

Example 1 with ExternalResourceDescription

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;
}
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 ExternalResourceDescription

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();
}
Also used : ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 3 with ExternalResourceDescription

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);
}
Also used : TokenBuilder(org.apache.uima.fit.testing.factory.TokenBuilder) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) FeatureTestUtil.assertFeature(org.dkpro.tc.testing.FeatureTestUtil.assertFeature) Feature(org.dkpro.tc.api.features.Feature) SimilarityPairFeatureExtractor(org.dkpro.tc.features.pair.similarity.SimilarityPairFeatureExtractor) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine) Test(org.junit.Test)

Example 4 with ExternalResourceDescription

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());
    }
}
Also used : CollectionReaderDescription(org.apache.uima.collection.CollectionReaderDescription) JsonDataWriter(org.dkpro.tc.core.io.JsonDataWriter) Instance(org.dkpro.tc.api.features.Instance) ArrayList(java.util.ArrayList) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) File(java.io.File) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription) Test(org.junit.Test)

Example 5 with ExternalResourceDescription

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;
}
Also used : JsonDataWriter(org.dkpro.tc.core.io.JsonDataWriter) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Aggregations

ExternalResourceDescription (org.apache.uima.resource.ExternalResourceDescription)27 ArrayList (java.util.ArrayList)17 File (java.io.File)10 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)10 JsonDataWriter (org.dkpro.tc.core.io.JsonDataWriter)8 CollectionReaderDescription (org.apache.uima.collection.CollectionReaderDescription)7 Instance (org.dkpro.tc.api.features.Instance)5 Test (org.junit.Test)5 Gson (com.google.gson.Gson)4 MetaDependent (org.dkpro.tc.api.features.meta.MetaDependent)4 CustomResourceSpecifier (org.apache.uima.resource.CustomResourceSpecifier)3 TcFeature (org.dkpro.tc.api.features.TcFeature)3 MetaCollectorConfiguration (org.dkpro.tc.api.features.meta.MetaCollectorConfiguration)3 HashMap (java.util.HashMap)2 UimaContextAdmin (org.apache.uima.UimaContextAdmin)2 RootUimaContext_impl (org.apache.uima.impl.RootUimaContext_impl)2 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)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