Search in sources :

Example 1 with Feature

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

the class InstanceTest method instanceEmptyInitializationTest.

@Test
public void instanceEmptyInitializationTest() throws Exception {
    Instance instance = new Instance();
    assertEquals(0, instance.getFeatures().size());
    Feature f3 = new Feature("feature3", "value1", FeatureType.STRING);
    instance.addFeature(f3);
    assertEquals(1, instance.getFeatures().size());
}
Also used : Instance(org.dkpro.tc.api.features.Instance) Feature(org.dkpro.tc.api.features.Feature) Test(org.junit.Test)

Example 2 with Feature

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

the class InstanceTest method testSetterAndGetter.

@Test
public void testSetterAndGetter() {
    Instance i = new Instance(Arrays.asList(new Feature("dummy", 0, FeatureType.STRING)), "RESULT");
    i.setJcasId(4711);
    i.setSequenceId(234);
    i.setWeight(2.0);
    i.setSequencePosition(3);
    assertEquals(4711, i.getJcasId());
    assertEquals(234, i.getSequenceId());
    assertEquals(2.0, i.getWeight(), 0.001);
    assertEquals(3, i.getSequencePosition());
    assertTrue(i.toString().startsWith("4711-234"));
}
Also used : Instance(org.dkpro.tc.api.features.Instance) Feature(org.dkpro.tc.api.features.Feature) Test(org.junit.Test)

Example 3 with Feature

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

the class InstanceTest method instanceAddFeatureSetTest.

@Test
public void instanceAddFeatureSetTest() 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");
    Set<Feature> s = new HashSet<Feature>();
    Feature f3 = new Feature("feature3", "value3", FeatureType.STRING);
    Feature f4 = new Feature("feature4", "value4", FeatureType.STRING);
    s.add(f3);
    s.add(f4);
    instance.addFeatures(s);
    assertEquals(4, instance.getFeatures().size());
}
Also used : Instance(org.dkpro.tc.api.features.Instance) ArrayList(java.util.ArrayList) Feature(org.dkpro.tc.api.features.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Feature

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

the class InstanceTest method instanceSetSingleOutcomeTest.

@Test
public void instanceSetSingleOutcomeTest() throws Exception {
    Feature f1 = new Feature("feature1", "value1", FeatureType.STRING);
    Instance instance = new Instance();
    instance.addFeature(f1);
    instance.setOutcomes("outcome");
    assertEquals(1, instance.getOutcomes().size());
    assertEquals("outcome", instance.getOutcome());
}
Also used : Instance(org.dkpro.tc.api.features.Instance) Feature(org.dkpro.tc.api.features.Feature) Test(org.junit.Test)

Example 5 with Feature

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

the class InstanceTest method instanceSetNewFeatureCollectionBySetterTest.

@Test
public void instanceSetNewFeatureCollectionBySetterTest() throws TextClassificationException {
    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");
    Feature f3 = new Feature("feature3", "value1", FeatureType.STRING);
    Feature f4 = new Feature("feature4", "value1", FeatureType.STRING);
    Set<Feature> newFeatures = new HashSet<>();
    newFeatures.add(f3);
    newFeatures.add(f4);
    instance.setFeatures(newFeatures);
    assertEquals(2, instance.getFeatures().size());
    Iterator<Feature> iterator = instance.getFeatures().iterator();
    Feature next = iterator.next();
    iterator.hasNext();
    Feature next2 = iterator.next();
    if (!next.getName().equals("feature3") && !next2.getName().equals("feature3")) {
        fail("Expected to find a feature named [feature3]");
    }
    if (!next.getName().equals("feature4") && !next2.getName().equals("feature4")) {
        fail("Expected to find a feature named [feature4]");
    }
}
Also used : Instance(org.dkpro.tc.api.features.Instance) ArrayList(java.util.ArrayList) Feature(org.dkpro.tc.api.features.Feature) HashSet(java.util.HashSet) 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