use of org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase in project dkpro-tc by dkpro.
the class InstanceExtractor method getSingleInstanceUnit.
private Instance getSingleInstanceUnit(Instance instance, JCas jcas, boolean supportsSparseFeature) throws Exception {
int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
TextClassificationTarget unit = JCasUtil.selectSingle(jcas, TextClassificationTarget.class);
if (addInstanceId) {
instance.addFeature(InstanceIdFeature.retrieve(jcas, unit));
}
for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
if (supportsSparseFeature) {
instance.addFeatures(getSparse(jcas, unit, featExt));
} else {
instance.addFeatures(getDense(jcas, unit, featExt));
}
instance.setOutcomes(getOutcomes(jcas, unit));
instance.setWeight(getWeight(jcas, unit));
instance.setJcasId(jcasId);
}
return instance;
}
use of org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase in project dkpro-tc by dkpro.
the class InstanceExtractor method getUnitInstances.
public List<Instance> getUnitInstances(JCas jcas, boolean supportSparseFeatures) throws TextClassificationException {
List<Instance> instances = new ArrayList<Instance>();
int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
Collection<TextClassificationTarget> targets = JCasUtil.select(jcas, TextClassificationTarget.class);
for (TextClassificationTarget aTarget : targets) {
Instance instance = new Instance();
if (addInstanceId) {
Feature feat = InstanceIdFeature.retrieve(jcas, aTarget);
instance.addFeature(feat);
}
for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
if (!(featExt instanceof FeatureExtractor)) {
throw new TextClassificationException("Feature extractor does not implement interface [" + FeatureExtractor.class.getName() + "]: " + featExt.getResourceName());
}
if (supportSparseFeatures) {
instance.addFeatures(getSparse(jcas, aTarget, featExt));
} else {
instance.addFeatures(getDense(jcas, aTarget, featExt));
}
}
// set and write outcome label(s)
instance.setOutcomes(getOutcomes(jcas, aTarget));
instance.setWeight(getWeight(jcas, aTarget));
instance.setJcasId(jcasId);
// instance.setSequenceId(sequenceId);
instance.setSequencePosition(aTarget.getId());
instances.add(instance);
}
return instances;
}
use of org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase in project dkpro-tc by dkpro.
the class InstanceExtractor method getSingleInstancePair.
private Instance getSingleInstancePair(Instance instance, JCas jcas) throws TextClassificationException {
try {
int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
if (addInstanceId) {
instance.addFeature(InstanceIdFeature.retrieve(jcas));
}
for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
if (!(featExt instanceof PairFeatureExtractor)) {
throw new TextClassificationException("Using non-pair FE in pair mode: " + featExt.getResourceName());
}
JCas view1 = jcas.getView(Constants.PART_ONE);
JCas view2 = jcas.getView(Constants.PART_TWO);
instance.setOutcomes(getOutcomes(jcas, null));
instance.setWeight(getWeight(jcas, null));
instance.setJcasId(jcasId);
instance.addFeatures(((PairFeatureExtractor) featExt).extract(view1, view2));
}
} catch (CASException e) {
throw new TextClassificationException(e);
}
return instance;
}
use of org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase in project dkpro-tc by dkpro.
the class ValidityCheckConnector method verifyNonPairFeatureExtractors.
private void verifyNonPairFeatureExtractors(String[] featureExtractors) throws Exception {
for (String featExt : featureExtractors) {
FeatureExtractorResource_ImplBase featExtC = (FeatureExtractorResource_ImplBase) Class.forName(featExt).newInstance();
implementsFeatureExtractorInterface(featExt, featExtC);
checkErrorConditionImplementsConflictingFeatureExtractorInterfaces(featExt, featExtC);
}
}
use of org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase in project dkpro-tc by dkpro.
the class TestTaskUtils method testInstanceMultiplicationWithoutUnitId.
@Test
public void testInstanceMultiplicationWithoutUnitId() throws Exception {
JCas jCas = initJCas(false);
FeatureExtractorResource_ImplBase[] featureExtractors = {};
InstanceExtractor ie = new InstanceExtractor(Constants.FM_SEQUENCE, featureExtractors, true);
List<Instance> multipleInstances = ie.getInstances(jCas, false);
assertEquals(6, multipleInstances.size());
// Sequence 1
int idx = 0;
assertEquals("4711_0_0", multipleInstances.get(idx).getFeatures().iterator().next().getValue());
assertEquals(0, multipleInstances.get(idx).getSequenceId());
assertEquals(0, multipleInstances.get(idx).getSequencePosition());
assertEquals("DT", multipleInstances.get(idx).getOutcome());
idx = 1;
assertEquals("4711_0_1", multipleInstances.get(idx).getFeatures().iterator().next().getValue());
assertEquals(0, multipleInstances.get(idx).getSequenceId());
assertEquals(1, multipleInstances.get(idx).getSequencePosition());
assertEquals("NN", multipleInstances.get(idx).getOutcome());
idx = 2;
assertEquals("4711_0_2", multipleInstances.get(idx).getFeatures().iterator().next().getValue());
assertEquals(0, multipleInstances.get(idx).getSequenceId());
assertEquals(2, multipleInstances.get(idx).getSequencePosition());
assertEquals("VBZ", multipleInstances.get(idx).getOutcome());
// Sequence 2
idx = 3;
assertEquals("4711_1_0", multipleInstances.get(idx).getFeatures().iterator().next().getValue());
assertEquals(1, multipleInstances.get(idx).getSequenceId());
assertEquals(0, multipleInstances.get(idx).getSequencePosition());
assertEquals("DT", multipleInstances.get(idx).getOutcome());
idx = 4;
assertEquals("4711_1_1", multipleInstances.get(idx).getFeatures().iterator().next().getValue());
assertEquals(1, multipleInstances.get(idx).getSequenceId());
assertEquals(1, multipleInstances.get(idx).getSequencePosition());
assertEquals("NN", multipleInstances.get(idx).getOutcome());
idx = 5;
assertEquals("4711_1_2", multipleInstances.get(idx).getFeatures().iterator().next().getValue());
assertEquals(1, multipleInstances.get(idx).getSequenceId());
assertEquals(2, multipleInstances.get(idx).getSequencePosition());
assertEquals("VBZ", multipleInstances.get(idx).getOutcome());
}
Aggregations