use of org.dkpro.tc.api.type.TextClassificationTarget 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.TextClassificationTarget in project dkpro-tc by dkpro.
the class FoldClassificationUnitCasMultiplier method setTargetAnnotation.
private void setTargetAnnotation(JCas copyJCas) {
if (useSequences) {
for (AnnotationFS s : buf) {
TextClassificationSequence seq = new TextClassificationSequence(copyJCas, s.getBegin(), s.getEnd());
seq.addToIndexes();
seq.setId(seqCounter++);
// re-add the units that are covered by those sequences
for (TextClassificationTarget u : seqModeUnitsCoveredBySequenceAnno) {
u.addToIndexes();
}
seqModeUnitsCoveredBySequenceAnno = new ArrayList<>();
}
} else {
for (AnnotationFS u : buf) {
TextClassificationTarget unit = new TextClassificationTarget(copyJCas, u.getBegin(), u.getEnd());
unit.addToIndexes();
unit.setId(unitCounter);
unitCounter++;
}
}
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class TcAnnotator method addTCUnitAndOutcomeAnnotation.
private void addTCUnitAndOutcomeAnnotation(JCas aJCas) {
Type type = aJCas.getCas().getTypeSystem().getType(nameUnit);
Collection<AnnotationFS> unitAnnotation = CasUtil.select(aJCas.getCas(), type);
for (AnnotationFS unit : unitAnnotation) {
TextClassificationTarget tcs = new TextClassificationTarget(aJCas, unit.getBegin(), unit.getEnd());
tcs.addToIndexes();
TextClassificationOutcome tco = new TextClassificationOutcome(aJCas, unit.getBegin(), unit.getEnd());
tco.setOutcome(Constants.TC_OUTCOME_DUMMY_VALUE);
tco.addToIndexes();
}
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class TestFoldUtil method countNumberOfTextClassificationSequencesAndUnitsPerCas.
private List<List<Integer>> countNumberOfTextClassificationSequencesAndUnitsPerCas(List<File> writtenBins) throws Exception {
List<List<Integer>> arrayList = new ArrayList<>();
List<Integer> units = new ArrayList<>();
List<Integer> seq = new ArrayList<>();
for (File f : writtenBins) {
JCas jcas = JCasFactory.createJCas();
CollectionReader createReader = createReader(jcas, f);
createReader.getNext(jcas.getCas());
Collection<TextClassificationTarget> colUni = JCasUtil.select(jcas, TextClassificationTarget.class);
units.add(colUni.size());
Collection<TextClassificationSequence> colSeq = JCasUtil.select(jcas, TextClassificationSequence.class);
seq.add(colSeq.size());
}
arrayList.add(seq);
arrayList.add(units);
return arrayList;
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class TestFoldUtil method setUnit.
private void setUnit(JCas jcas, int beg, int end) {
TextClassificationTarget tcu = new TextClassificationTarget(jcas, beg, end);
tcu.addToIndexes();
}
Aggregations