Search in sources :

Example 11 with FeatureExtractorResource_ImplBase

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

the class CrfSuiteLoadModelConnector method getInstancesInSequence.

private List<Instance> getInstancesInSequence(FeatureExtractorResource_ImplBase[] featureExtractors, JCas jcas, TextClassificationSequence sequence, boolean addInstanceId, int sequenceId) throws Exception {
    List<Instance> instances = new ArrayList<Instance>();
    int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
    List<TextClassificationTarget> seqTargets = JCasUtil.selectCovered(jcas, TextClassificationTarget.class, sequence);
    for (TextClassificationTarget aTarget : seqTargets) {
        Instance instance = new Instance();
        if (addInstanceId) {
            instance.addFeature(InstanceIdFeature.retrieve(jcas, aTarget, sequenceId));
        }
        // execute feature extractors and add features to instance
        try {
            for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
                instance.addFeatures(((FeatureExtractor) featExt).extract(jcas, aTarget));
            }
        } catch (TextClassificationException e) {
            throw new AnalysisEngineProcessException(e);
        }
        // set and write outcome label(s)
        instance.setOutcomes(getOutcomes(jcas, aTarget));
        instance.setJcasId(jcasId);
        instance.setSequenceId(sequenceId);
        instance.setSequencePosition(aTarget.getId());
        instances.add(instance);
    }
    return instances;
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) Instance(org.dkpro.tc.api.features.Instance) TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) ArrayList(java.util.ArrayList) TextClassificationTarget(org.dkpro.tc.api.type.TextClassificationTarget) FeatureExtractorResource_ImplBase(org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Aggregations

FeatureExtractorResource_ImplBase (org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase)11 Instance (org.dkpro.tc.api.features.Instance)6 JCasId (org.dkpro.tc.api.type.JCasId)6 TextClassificationTarget (org.dkpro.tc.api.type.TextClassificationTarget)5 JCas (org.apache.uima.jcas.JCas)4 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)4 ArrayList (java.util.ArrayList)3 PairFeatureExtractor (org.dkpro.tc.api.features.PairFeatureExtractor)3 InstanceExtractor (org.dkpro.tc.core.task.uima.InstanceExtractor)3 Test (org.junit.Test)3 FeatureExtractor (org.dkpro.tc.api.features.FeatureExtractor)2 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)1 CASException (org.apache.uima.cas.CASException)1 Feature (org.dkpro.tc.api.features.Feature)1 TextClassificationSequence (org.dkpro.tc.api.type.TextClassificationSequence)1 InstanceIdFeature (org.dkpro.tc.core.feature.InstanceIdFeature)1