use of org.dkpro.tc.api.type.JCasId in project dkpro-tc by dkpro.
the class TestReaderSingleLabel 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();
}
use of org.dkpro.tc.api.type.JCasId in project dkpro-tc by dkpro.
the class TestTaskUtils method initJCas.
private JCas initJCas(boolean setUnitIdAsPartOfTheInstanceId) throws Exception {
AnalysisEngine engine = AnalysisEngineFactory.createEngine(NoOpAnnotator.class);
JCas jCas = engine.newJCas();
JCasId id = new JCasId(jCas);
id.setId(4711);
id.addToIndexes();
DocumentMetaData meta = new DocumentMetaData(jCas);
meta.setDocumentTitle("title");
meta.setDocumentId("4711");
meta.addToIndexes();
String[][] tokens = { // sequence 1
{ "a", "DT" }, // sequence 1
{ "car", "NN" }, // sequence 1
{ "drives", "VBZ" }, // sequence 2
{ "the", "DT" }, // sequence 2
{ "hedgehogs", "NN" }, // sequence 2
{ "dies", "VBZ" } };
StringBuilder sb = new StringBuilder();
for (int i = 0; i < tokens.length; i++) {
int start = sb.length();
int end = start + tokens[i][0].length();
TextClassificationTarget unit = new TextClassificationTarget(jCas, start, end);
if (setUnitIdAsPartOfTheInstanceId) {
unit.setSuffix(tokens[i][0]);
}
unit.setId(i);
unit.addToIndexes();
TextClassificationOutcome outcome = new TextClassificationOutcome(jCas, start, end);
outcome.setOutcome(tokens[i][1]);
outcome.addToIndexes();
sb.append(tokens[i][0]);
if (i + 1 < tokens.length) {
sb.append(" ");
}
}
String text = sb.toString();
jCas.setDocumentText(text);
int lenSeq1 = tokens[0][0].length() + 1 + tokens[1][0].length() + 1 + tokens[2][0].length();
TextClassificationSequence seq1 = new TextClassificationSequence(jCas, 0, lenSeq1);
seq1.addToIndexes();
TextClassificationSequence seq2 = new TextClassificationSequence(jCas, lenSeq1 + 1, text.length());
seq2.addToIndexes();
return jCas;
}
use of org.dkpro.tc.api.type.JCasId in project dkpro-tc by dkpro.
the class TcAnnotator method process.
@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
if (!JCasUtil.exists(aJCas, JCasId.class)) {
JCasId id = new JCasId(aJCas);
id.setId(jcasId++);
id.addToIndexes();
}
switch(featureMode) {
case Constants.FM_DOCUMENT:
processDocument(aJCas);
break;
case Constants.FM_PAIR:
// same as document
processDocument(aJCas);
break;
case Constants.FM_SEQUENCE:
processSequence(aJCas);
break;
case Constants.FM_UNIT:
processUnit(aJCas);
break;
default:
throw new IllegalStateException("Feature mode [" + featureMode + "] is unknown");
}
if (conversionAnnotator != null && conversionAnnotator.length > 0) {
callConversionEngine(aJCas);
}
if (!retainTargets) {
removeTargets(aJCas);
}
}
use of org.dkpro.tc.api.type.JCasId in project dkpro-tc by dkpro.
the class TestPairReader method getNext.
@Override
public void getNext(JCas jcas) throws IOException, CollectionException {
super.getNext(jcas);
JCasId id = new JCasId(jcas);
id.setId(jcasid++);
id.addToIndexes();
for (String outcomeValue : getTextClassificationOutcomes(jcas)) {
TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
outcome.setOutcome(outcomeValue);
outcome.addToIndexes();
}
// as we are creating more than one CAS out of a single file, we need to have different
// document titles and URIs for each CAS
// otherwise, serialized CASes will be overwritten
DocumentMetaData dmd = DocumentMetaData.get(jcas);
dmd.setDocumentTitle(dmd.getDocumentTitle() + "-" + fileOffset);
dmd.setDocumentUri(dmd.getDocumentUri() + "-" + fileOffset);
fileOffset++;
}
use of org.dkpro.tc.api.type.JCasId in project dkpro-tc by dkpro.
the class AssignIdConnector method process.
@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
LogFactory.getLog(getClass()).info("--- validating CAS with id [" + jcasId + "] ---");
boolean exists = JCasUtil.exists(aJCas, JCasId.class);
if (!exists) {
JCasId id = new JCasId(aJCas);
id.setId(jcasId++);
id.addToIndexes();
}
}
Aggregations