use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class InstanceExtractor method getSingleInstanceDocument.
private Instance getSingleInstanceDocument(Instance instance, JCas jcas, boolean supportSparseFeatures) throws TextClassificationException {
int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
TextClassificationTarget documentTcu = JCasUtil.selectSingle(jcas, TextClassificationTarget.class);
if (addInstanceId) {
instance.addFeature(InstanceIdFeature.retrieve(jcas));
}
for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
if (!(featExt instanceof FeatureExtractor)) {
throw new TextClassificationException("Using incompatible feature in document mode: " + featExt.getResourceName());
}
if (supportSparseFeatures) {
instance.addFeatures(getSparse(jcas, documentTcu, featExt));
} else {
instance.addFeatures(getDense(jcas, documentTcu, featExt));
}
instance.setOutcomes(getOutcomes(jcas, null));
instance.setWeight(getWeight(jcas, null));
instance.setJcasId(jcasId);
}
return instance;
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class InstanceExtractor method getSequenceInstances.
public List<Instance> getSequenceInstances(JCas jcas, boolean useSparse) throws TextClassificationException {
List<Instance> instances = new ArrayList<Instance>();
int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
int sequenceId = 0;
int unitId = 0;
Collection<TextClassificationSequence> sequences = JCasUtil.select(jcas, TextClassificationSequence.class);
for (TextClassificationSequence seq : sequences) {
unitId = 0;
List<TextClassificationTarget> seqTargets = JCasUtil.selectCovered(jcas, TextClassificationTarget.class, seq);
for (TextClassificationTarget aTarget : seqTargets) {
aTarget.setId(unitId++);
Instance instance = new Instance();
if (addInstanceId) {
instance.addFeature(InstanceIdFeature.retrieve(jcas, aTarget, sequenceId));
}
for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
if (useSparse) {
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);
}
sequenceId++;
}
return instances;
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class ValidityCheckConnectorPost method checkErrorConditionMissingOutcomeForTargetIfUnitOrSequenceMode.
private void checkErrorConditionMissingOutcomeForTargetIfUnitOrSequenceMode(List<TextClassificationTarget> targets, List<TextClassificationOutcome> outcomes) throws AnalysisEngineProcessException {
// labeled with an outcome annotation
if (featureModeI == 2 || featureModeI == 4) {
if (targets.size() == 0) {
throw new AnalysisEngineProcessException(new TextClassificationException("Your experiment is supposed to have [+" + TextClassificationTarget.class.getName() + "] annotations, which are missing"));
} else {
if (targets.size() != outcomes.size()) {
throwException("Number of targets [" + targets.size() + "] != number of outcomes [" + outcomes.size() + "]");
}
for (int i = 0; i < targets.size(); i++) {
TextClassificationTarget t = targets.get(i);
TextClassificationOutcome o = outcomes.get(i);
if (t.getBegin() != o.getBegin() || t.getEnd() != o.getEnd()) {
throwException("Index of target and outcome do not match taget span: [" + t.getBegin() + " - " + t.getEnd() + "] != outcome span " + o.getBegin() + " - " + o.getEnd());
}
}
}
}
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class SequenceContextMetaCollector method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Collection<TextClassificationSequence> sequences = JCasUtil.select(jcas, TextClassificationSequence.class);
for (TextClassificationSequence seq : sequences) {
int id = seq.getId();
for (TextClassificationTarget unit : JCasUtil.selectCovered(jcas, TextClassificationTarget.class, seq)) {
String idString;
try {
idString = (String) InstanceIdFeature.retrieve(jcas, unit, id).getValue();
ContextMetaCollectorUtil.addContext(jcas, unit, idString, bw);
} catch (Exception e) {
throw new AnalysisEngineProcessException(e);
}
}
}
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class SingleLabelReaderBase method getNext.
@Override
public void getNext(CAS aCAS) throws IOException, CollectionException {
super.getNext(aCAS);
JCas jcas;
try {
jcas = aCAS.getJCas();
} catch (CASException e) {
throw new CollectionException();
}
TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
outcome.setOutcome(getTextClassificationOutcome(jcas));
outcome.setWeight(getTextClassificationOutcomeWeight(jcas));
outcome.addToIndexes();
new TextClassificationTarget(jcas, 0, jcas.getDocumentText().length()).addToIndexes();
}
Aggregations