Search in sources :

Example 21 with ExternalResourceDescription

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

the class WekaExternalResourceDemo method getParameterSpace.

public static ParameterSpace getParameterSpace() throws ResourceInitializationException {
    // configure training and test data reader dimension
    // train/test will use both, while cross-validation will only use the
    // train part
    Map<String, Object> dimReaders = new HashMap<String, Object>();
    CollectionReaderDescription readerTrain = CollectionReaderFactory.createReaderDescription(PairTwentyNewsgroupsReader.class, PairTwentyNewsgroupsReader.PARAM_LISTFILE, listFilePathTrain, PairTwentyNewsgroupsReader.PARAM_LANGUAGE_CODE, languageCode);
    dimReaders.put(DIM_READER_TRAIN, readerTrain);
    CollectionReaderDescription readerTest = CollectionReaderFactory.createReaderDescription(PairTwentyNewsgroupsReader.class, PairTwentyNewsgroupsReader.PARAM_LISTFILE, listFilePathTest, PairTwentyNewsgroupsReader.PARAM_LANGUAGE_CODE, languageCode);
    dimReaders.put(DIM_READER_TEST, readerTest);
    // Create the External Resource here:
    ExternalResourceDescription gstResource = ExternalResourceFactory.createExternalResourceDescription(CosineSimilarityResource.class, CosineSimilarityResource.PARAM_NORMALIZATION, NormalizationMode.L2.toString());
    Dimension<TcFeatureSet> dimFeatureSets = Dimension.create(DIM_FEATURE_SET, new TcFeatureSet(TcFeatureFactory.create(SimilarityPairFeatureExtractor.class, SimilarityPairFeatureExtractor.PARAM_TEXT_SIMILARITY_RESOURCE, gstResource)));
    Map<String, Object> config = new HashMap<>();
    config.put(DIM_CLASSIFICATION_ARGS, new Object[] { new WekaAdapter(), SMO.class.getName() });
    config.put(DIM_DATA_WRITER, new WekaAdapter().getDataWriterClass().getName());
    config.put(DIM_FEATURE_USE_SPARSE, new WekaAdapter().useSparseFeatures());
    Dimension<Map<String, Object>> mlas = Dimension.createBundle("config", config);
    ParameterSpace pSpace = new ParameterSpace(Dimension.createBundle(DIM_READERS, dimReaders), Dimension.create(DIM_LEARNING_MODE, LM_SINGLE_LABEL), Dimension.create(DIM_FEATURE_MODE, FM_PAIR), dimFeatureSets, mlas);
    return pSpace;
}
Also used : HashMap(java.util.HashMap) TcFeatureSet(org.dkpro.tc.api.features.TcFeatureSet) WekaAdapter(org.dkpro.tc.ml.weka.WekaAdapter) CollectionReaderDescription(org.apache.uima.collection.CollectionReaderDescription) SMO(weka.classifiers.functions.SMO) ParameterSpace(org.dkpro.lab.task.ParameterSpace) HashMap(java.util.HashMap) Map(java.util.Map) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 22 with ExternalResourceDescription

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

the class ExtractFeaturesConnectorTest method extractFeaturesConnectorRegressionTest.

@Test
public void extractFeaturesConnectorRegressionTest() throws Exception {
    File outputPath = folder.newFolder();
    // we do not need parameters here, but in case we do :)
    Object[] parameters = new Object[] { NoopFeatureExtractor.PARAM_UNIQUE_EXTRACTOR_NAME, "123", UnitContextMetaCollector.PARAM_CONTEXT_FOLDER, Constants.ID_CONTEXT_KEY };
    ExternalResourceDescription featureExtractor = ExternalResourceFactory.createExternalResourceDescription(NoopFeatureExtractor.class, parameters);
    List<ExternalResourceDescription> fes = new ArrayList<>();
    fes.add(featureExtractor);
    CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription(TestReaderRegression.class, TestReaderRegression.PARAM_SOURCE_LOCATION, "src/test/resources/data/*.txt");
    AnalysisEngineDescription segmenter = AnalysisEngineFactory.createEngineDescription(BreakIteratorSegmenter.class);
    AnalysisEngineDescription doc = AnalysisEngineFactory.createEngineDescription(DocumentModeAnnotator.class, DocumentModeAnnotator.PARAM_FEATURE_MODE, Constants.FM_DOCUMENT);
    AnalysisEngineDescription featExtractorConnector = TaskUtils.getFeatureExtractorConnector(outputPath.getAbsolutePath(), JsonDataWriter.class.getName(), Constants.LM_REGRESSION, Constants.FM_DOCUMENT, false, false, false, false, Collections.emptyList(), fes, new String[] {});
    SimplePipeline.runPipeline(reader, segmenter, doc, 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(2, instances.size());
    assertEquals(1, getUniqueOutcomes(instances));
    assertEquals("0.45", instances.get(0).getOutcome());
    System.out.println(FileUtils.readFileToString(new File(outputPath, JsonDataWriter.JSON_FILE_NAME), "utf-8"));
}
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) Test(org.junit.Test)

Example 23 with ExternalResourceDescription

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

the class LuceneMetaCollectionBasedFeatureTestBase method makeResource.

protected List<ExternalResourceDescription> makeResource(Class<? extends Resource_ImplBase> class1, Object[] parameters) {
    ExternalResourceDescription featureExtractor = ExternalResourceFactory.createExternalResourceDescription(class1, parameters);
    List<ExternalResourceDescription> fes = new ArrayList<>();
    fes.add(featureExtractor);
    return fes;
}
Also used : ArrayList(java.util.ArrayList) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 24 with ExternalResourceDescription

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

the class NgramUnitTest method runFeatureExtractor.

private File runFeatureExtractor(File luceneFolder) throws Exception {
    File outputPath = folder.newFolder();
    Object[] parameters = new Object[] { WordNGram.PARAM_UNIQUE_EXTRACTOR_NAME, EXTRACTOR_NAME, WordNGram.PARAM_NGRAM_USE_TOP_K, "1", WordNGram.PARAM_SOURCE_LOCATION, luceneFolder.toString(), WordNGramMC.PARAM_TARGET_LOCATION, luceneFolder.toString(), WordNGram.PARAM_NGRAM_MIN_N, "1", WordNGram.PARAM_NGRAM_MAX_N, "1" };
    ExternalResourceDescription featureExtractor = ExternalResourceFactory.createExternalResourceDescription(WordNGram.class, parameters);
    List<ExternalResourceDescription> fes = new ArrayList<>();
    fes.add(featureExtractor);
    CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription(TestReaderSingleLabelDocumentReader.class, TestReaderSingleLabelDocumentReader.PARAM_LANGUAGE, "en", TestReaderSingleLabelDocumentReader.PARAM_SOURCE_LOCATION, "src/test/resources/ngrams/text3.txt", TestReaderSingleLabelDocumentReader.PARAM_SUPPRESS_DOCUMENT_ANNOTATION, true);
    AnalysisEngineDescription segmenter = AnalysisEngineFactory.createEngineDescription(BreakIteratorSegmenter.class);
    AnalysisEngineDescription unitAnno = AnalysisEngineFactory.createEngineDescription(EachTokenAsUnitAnnotator.class);
    AnalysisEngineDescription featExtractorConnector = TaskUtils.getFeatureExtractorConnector(outputPath.getAbsolutePath(), JsonDataWriter.class.getName(), Constants.LM_SINGLE_LABEL, Constants.FM_UNIT, false, false, false, false, Collections.emptyList(), fes, new String[] {});
    SimplePipeline.runPipeline(reader, segmenter, unitAnno, featExtractorConnector);
    return outputPath;
}
Also used : CollectionReaderDescription(org.apache.uima.collection.CollectionReaderDescription) JsonDataWriter(org.dkpro.tc.core.io.JsonDataWriter) ArrayList(java.util.ArrayList) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) File(java.io.File) ExternalResourceDescription(org.apache.uima.resource.ExternalResourceDescription)

Example 25 with ExternalResourceDescription

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

the class TokenLenTest method prepareFeatureExtractor.

@Override
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_UNIT, 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