use of org.dkpro.tc.api.type.JCasId 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.JCasId 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.JCasId in project dkpro-tc by dkpro.
the class TestReaderMultiLabel method getNext.
@Override
public void getNext(CAS aCAS) throws IOException, CollectionException {
super.getNext(aCAS);
JCas jcas;
try {
jcas = aCAS.getJCas();
JCasId id = new JCasId(jcas);
id.setId(jcasId);
id.addToIndexes();
} catch (CASException e) {
throw new CollectionException();
}
for (String outcomeValue : getTextClassificationOutcomes(jcas)) {
TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
outcome.setOutcome(outcomeValue);
outcome.addToIndexes();
}
}
use of org.dkpro.tc.api.type.JCasId in project dkpro-tc by dkpro.
the class IdentificationCollector method processDocumentMode.
private void processDocumentMode(JCas aJCas) throws AnalysisEngineProcessException {
int jcasId = JCasUtil.selectSingle(aJCas, JCasId.class).getId();
try {
String documentFile = DocumentMetaData.get(aJCas).getDocumentUri();
if (documentFile == null) {
documentFile = DocumentMetaData.get(aJCas).getDocumentId();
}
writer.write(jcasId + "\t" + documentFile + System.lineSeparator());
} catch (IOException e) {
throw new AnalysisEngineProcessException(e);
}
}
use of org.dkpro.tc.api.type.JCasId in project dkpro-tc by dkpro.
the class TestReaderRegression method getNext.
@Override
public void getNext(CAS aCAS) throws IOException, CollectionException {
super.getNext(aCAS);
JCas jcas;
try {
jcas = aCAS.getJCas();
JCasId id = new JCasId(jcas);
id.setId(jcasId++);
id.addToIndexes();
} catch (CASException e) {
throw new CollectionException();
}
TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
outcome.setOutcome(getTextClassificationOutcome(jcas));
outcome.addToIndexes();
}
Aggregations