Search in sources :

Example 51 with Feature

use of org.dkpro.tc.api.features.Feature in project dkpro-tc by dkpro.

the class InstanceTest method instanceInitializationByListTest.

@Test
public void instanceInitializationByListTest() throws Exception {
    Feature f1 = new Feature("feature1", "value1", FeatureType.STRING);
    Feature f2 = new Feature("feature2", "value1", FeatureType.STRING);
    List<Feature> features = new ArrayList<>();
    features.add(f1);
    features.add(f2);
    Instance instance = new Instance(features, "outcome");
    assertEquals(2, instance.getFeatures().size());
}
Also used : Instance(org.dkpro.tc.api.features.Instance) ArrayList(java.util.ArrayList) Feature(org.dkpro.tc.api.features.Feature) Test(org.junit.Test)

Example 52 with Feature

use of org.dkpro.tc.api.features.Feature in project dkpro-tc by dkpro.

the class InstanceTest method instanceInitializationBySetTest.

@Test
public void instanceInitializationBySetTest() throws Exception {
    Feature f1 = new Feature("feature1", "value1", FeatureType.STRING);
    Feature f2 = new Feature("feature2", "value1", FeatureType.STRING);
    Set<Feature> features = new HashSet<Feature>();
    features.add(f1);
    features.add(f2);
    Instance instance = new Instance(features, "outcome");
    assertEquals(2, instance.getFeatures().size());
}
Also used : Instance(org.dkpro.tc.api.features.Instance) Feature(org.dkpro.tc.api.features.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with Feature

use of org.dkpro.tc.api.features.Feature in project dkpro-tc by dkpro.

the class InstanceTest method instanceSetSeveralOutcomesTest.

@Test
public void instanceSetSeveralOutcomesTest() throws Exception {
    Feature f1 = new Feature("feature1", "value1", FeatureType.STRING);
    Feature f2 = new Feature("feature2", "value1", FeatureType.STRING);
    List<Feature> features = new ArrayList<>();
    features.add(f1);
    features.add(f2);
    Instance instance = new Instance(features, "outcome");
    List<String> newOutcomes = new ArrayList<String>();
    newOutcomes.add("outcome1");
    newOutcomes.add("outcome2");
    instance.setOutcomes(newOutcomes);
    assertEquals(2, instance.getOutcomes().size());
}
Also used : Instance(org.dkpro.tc.api.features.Instance) ArrayList(java.util.ArrayList) Feature(org.dkpro.tc.api.features.Feature) Test(org.junit.Test)

Example 54 with Feature

use of org.dkpro.tc.api.features.Feature in project dkpro-tc by dkpro.

the class InstanceTest method instanceInitializationWithListOfOutcomes.

@Test
public void instanceInitializationWithListOfOutcomes() throws Exception {
    Feature f1 = new Feature("feature1", "value1", FeatureType.STRING);
    Feature f2 = new Feature("feature2", "value1", FeatureType.STRING);
    List<Feature> features = new ArrayList<>();
    features.add(f1);
    features.add(f2);
    List<String> outcomes = new ArrayList<>();
    outcomes.add("outcome1");
    outcomes.add("outcome2");
    Instance instance = new Instance(features, outcomes);
    assertEquals(2, instance.getFeatures().size());
    assertEquals(2, instance.getOutcomes().size());
}
Also used : Instance(org.dkpro.tc.api.features.Instance) ArrayList(java.util.ArrayList) Feature(org.dkpro.tc.api.features.Feature) Test(org.junit.Test)

Example 55 with Feature

use of org.dkpro.tc.api.features.Feature in project dkpro-tc by dkpro.

the class GreedyStringTilingFeatureExtractorTest method greedyStringTilingFeatureExtractorTest.

@Test
public void greedyStringTilingFeatureExtractorTest() throws Exception {
    AnalysisEngine engine = createEngine(NoOpAnnotator.class);
    JCas jcas = engine.newJCas();
    jcas.setDocumentLanguage("en");
    jcas.setDocumentText("1234567890");
    engine.process(jcas);
    JCas jcas2 = engine.newJCas();
    jcas2.setDocumentLanguage("en");
    jcas2.setDocumentText("12345");
    engine.process(jcas2);
    GreedyStringTilingFeatureExtractor extractor = new GreedyStringTilingFeatureExtractor();
    Set<Feature> features1 = extractor.extract(jcas, jcas2);
    assertEquals(1, features1.size());
    Feature f1 = features1.iterator().next();
    assertEquals(f1.getValue(), 0.5);
}
Also used : GreedyStringTilingFeatureExtractor(org.dkpro.tc.features.pair.similarity.GreedyStringTilingFeatureExtractor) JCas(org.apache.uima.jcas.JCas) Feature(org.dkpro.tc.api.features.Feature) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine) Test(org.junit.Test)

Aggregations

Feature (org.dkpro.tc.api.features.Feature)94 Test (org.junit.Test)48 Instance (org.dkpro.tc.api.features.Instance)30 ArrayList (java.util.ArrayList)29 HashSet (java.util.HashSet)21 FeatureTestUtil.assertFeature (org.dkpro.tc.testing.FeatureTestUtil.assertFeature)17 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)16 TextClassificationTarget (org.dkpro.tc.api.type.TextClassificationTarget)16 JCas (org.apache.uima.jcas.JCas)15 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)13 File (java.io.File)8 Attribute (weka.core.Attribute)8 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)7 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)6 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)5 Chunk (de.tudarmstadt.ukp.dkpro.core.api.syntax.type.chunk.Chunk)4 OpenNlpPosTagger (de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpPosTagger)4 BreakIteratorSegmenter (de.tudarmstadt.ukp.dkpro.core.tokit.BreakIteratorSegmenter)4 Instances (weka.core.Instances)4 IOException (java.io.IOException)3