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;
}
Aggregations