Search in sources :

Example 1 with PairFeatureExtractor

use of org.dkpro.tc.api.features.PairFeatureExtractor 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;
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) PairFeatureExtractor(org.dkpro.tc.api.features.PairFeatureExtractor) TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) JCas(org.apache.uima.jcas.JCas) CASException(org.apache.uima.cas.CASException) FeatureExtractorResource_ImplBase(org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase)

Example 2 with PairFeatureExtractor

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

the class BaselinePairFeatureTest method extractTest.

@Test
public void extractTest() throws Exception {
    AnalysisEngineDescription desc = createEngineDescription(BreakIteratorSegmenter.class);
    AnalysisEngine engine = createEngine(desc);
    PairFeatureExtractor extractor = new AlwaysZeroPairFeatureExtractor();
    Set<Feature> features = runExtractor(engine, extractor);
    assertEquals(1, features.size());
    for (Feature feature : features) {
        assertFeature("BaselineFeature", 0, feature);
    }
}
Also used : AlwaysZeroPairFeatureExtractor(org.dkpro.tc.features.pair.core.AlwaysZeroPairFeatureExtractor) PairFeatureExtractor(org.dkpro.tc.api.features.PairFeatureExtractor) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) FeatureTestUtil.assertFeature(org.dkpro.tc.testing.FeatureTestUtil.assertFeature) Feature(org.dkpro.tc.api.features.Feature) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine) AlwaysZeroPairFeatureExtractor(org.dkpro.tc.features.pair.core.AlwaysZeroPairFeatureExtractor) Test(org.junit.Test)

Aggregations

PairFeatureExtractor (org.dkpro.tc.api.features.PairFeatureExtractor)2 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)1 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)1 CASException (org.apache.uima.cas.CASException)1 JCas (org.apache.uima.jcas.JCas)1 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)1 Feature (org.dkpro.tc.api.features.Feature)1 FeatureExtractorResource_ImplBase (org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase)1 JCasId (org.dkpro.tc.api.type.JCasId)1 AlwaysZeroPairFeatureExtractor (org.dkpro.tc.features.pair.core.AlwaysZeroPairFeatureExtractor)1 FeatureTestUtil.assertFeature (org.dkpro.tc.testing.FeatureTestUtil.assertFeature)1 Test (org.junit.Test)1