Search in sources :

Example 6 with ExternalResourceDescription

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

the class KeywordNGramTest method initialize.

private List<Instance> initialize(boolean includeComma, boolean markSentenceLocation) throws Exception {
    File luceneFolder = folder.newFolder();
    File outputPath = folder.newFolder();
    Object[] parameters = new Object[] { KeywordNGram.PARAM_UNIQUE_EXTRACTOR_NAME, "123", KeywordNGram.PARAM_NGRAM_KEYWORDS_FILE, "src/test/resources/data/keywordlist.txt", KeywordNGram.PARAM_SOURCE_LOCATION, luceneFolder, KeywordNGramMC.PARAM_TARGET_LOCATION, luceneFolder, KeywordNGram.PARAM_KEYWORD_NGRAM_MARK_SENTENCE_LOCATION, markSentenceLocation, KeywordNGram.PARAM_KEYWORD_NGRAM_INCLUDE_COMMAS, includeComma };
    CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription(TestReaderSingleLabelDocumentReader.class, TestReaderSingleLabelDocumentReader.PARAM_SOURCE_LOCATION, "src/test/resources/ngrams/trees.txt");
    AnalysisEngineDescription segmenter = AnalysisEngineFactory.createEngineDescription(BreakIteratorSegmenter.class);
    AnalysisEngineDescription metaCollector = AnalysisEngineFactory.createEngineDescription(KeywordNGramMC.class, parameters);
    ExternalResourceDescription featureExtractor = ExternalResourceFactory.createExternalResourceDescription(KeywordNGram.class, toString(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);
    Gson gson = new Gson();
    List<String> lines = FileUtils.readLines(new File(outputPath, JsonDataWriter.JSON_FILE_NAME), "utf-8");
    List<Instance> instances = new ArrayList<>();
    for (String l : lines) {
        instances.add(gson.fromJson(l, Instance.class));
    }
    assertEquals(1, instances.size());
    return instances;
}
Also used : JsonDataWriter(org.dkpro.tc.core.io.JsonDataWriter) Instance(org.dkpro.tc.api.features.Instance) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) CollectionReaderDescription(org.apache.uima.collection.CollectionReaderDescription) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) File(java.io.File) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 7 with ExternalResourceDescription

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

the class KeywordPPipelineTest method getFeatureExtractorCollector.

@Override
protected void getFeatureExtractorCollector(List<Object> parameterList) throws ResourceInitializationException {
    ExternalResourceDescription featureExtractor = ExternalResourceFactory.createExternalResourceDescription(LuceneKeywordPFE.class, toString(parameterList.toArray()));
    List<ExternalResourceDescription> fes = new ArrayList<>();
    fes.add(featureExtractor);
    featExtractorConnector = TaskUtils.getFeatureExtractorConnector(outputPath.getAbsolutePath(), JsonDataWriter.class.getName(), Constants.LM_SINGLE_LABEL, Constants.FM_PAIR, false, false, false, false, Collections.emptyList(), fes, new String[] {});
}
Also used : ArrayList(java.util.ArrayList) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 8 with ExternalResourceDescription

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

the class NGramPPipelineTest method getFeatureExtractorCollector.

@Override
protected void getFeatureExtractorCollector(List<Object> parameterList) throws ResourceInitializationException {
    ExternalResourceDescription featureExtractor = ExternalResourceFactory.createExternalResourceDescription(LuceneNGramPFE.class, toString(parameterList.toArray()));
    List<ExternalResourceDescription> fes = new ArrayList<>();
    fes.add(featureExtractor);
    featExtractorConnector = TaskUtils.getFeatureExtractorConnector(outputPath.getAbsolutePath(), JsonDataWriter.class.getName(), Constants.LM_SINGLE_LABEL, Constants.FM_PAIR, false, false, false, false, Collections.emptyList(), fes, new String[] {});
}
Also used : ArrayList(java.util.ArrayList) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 9 with ExternalResourceDescription

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

the class KeywordCPPipelineTest method getFeatureExtractorCollector.

@Override
protected void getFeatureExtractorCollector(List<Object> parameterList) throws ResourceInitializationException {
    ExternalResourceDescription featureExtractor = ExternalResourceFactory.createExternalResourceDescription(LuceneKeywordCPFE.class, toString(parameterList.toArray()));
    List<ExternalResourceDescription> fes = new ArrayList<>();
    fes.add(featureExtractor);
    featExtractorConnector = TaskUtils.getFeatureExtractorConnector(outputPath.getAbsolutePath(), JsonDataWriter.class.getName(), Constants.LM_SINGLE_LABEL, Constants.FM_PAIR, false, false, false, false, Collections.emptyList(), fes, new String[] {});
}
Also used : ArrayList(java.util.ArrayList) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 10 with ExternalResourceDescription

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

the class NGramCPPipelineTest method getFeatureExtractorCollector.

@Override
protected void getFeatureExtractorCollector(List<Object> parameterList) throws ResourceInitializationException {
    ExternalResourceDescription featureExtractor = ExternalResourceFactory.createExternalResourceDescription(LuceneNGramCPFE.class, toString(parameterList.toArray()));
    List<ExternalResourceDescription> fes = new ArrayList<>();
    fes.add(featureExtractor);
    featExtractorConnector = TaskUtils.getFeatureExtractorConnector(outputPath.getAbsolutePath(), JsonDataWriter.class.getName(), Constants.LM_SINGLE_LABEL, Constants.FM_PAIR, false, false, false, false, Collections.emptyList(), fes, new String[] {});
}
Also used : ArrayList(java.util.ArrayList) 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