use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class SequenceOutcomeReaderTest method testSkipLineReader.
@Test
public void testSkipLineReader() throws Exception {
CollectionReader reader = CollectionReaderFactory.createReader(SequenceOutcomeReader.class, SequenceOutcomeReader.PARAM_SOURCE_LOCATION, "src/test/resources/sequence/posDummy.txt", SequenceOutcomeReader.PARAM_SKIP_LINES_START_WITH_STRING, "#");
List<List<String>> readSequences = new ArrayList<>();
List<List<String>> readOutcomes = new ArrayList<>();
while (reader.hasNext()) {
JCas theJCas = JCasFactory.createJCas();
reader.getNext(theJCas.getCas());
Collection<TextClassificationSequence> sequence = JCasUtil.select(theJCas, TextClassificationSequence.class);
for (TextClassificationSequence s : sequence) {
List<TextClassificationTarget> targets = JCasUtil.selectCovered(theJCas, TextClassificationTarget.class, s);
List<String> tokens = new ArrayList<>();
for (TextClassificationTarget target : targets) {
tokens.add(target.getCoveredText());
}
readSequences.add(tokens);
}
Collection<TextClassificationOutcome> outcomeAnnotations = JCasUtil.select(theJCas, TextClassificationOutcome.class);
List<String> outcomes = new ArrayList<>();
for (TextClassificationOutcome o : outcomeAnnotations) {
outcomes.add(o.getOutcome());
}
readOutcomes.add(outcomes);
}
assertEquals(4, readSequences.get(1).size());
// 2 - tokens
assertEquals("This2", readSequences.get(1).get(0));
assertEquals("is2", readSequences.get(1).get(1));
assertEquals("a2", readSequences.get(1).get(2));
assertEquals("!", readSequences.get(1).get(3));
}
use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class LibsvmDataFormatLoadModelConnector method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
try {
File tempFile = createInputFile(jcas);
File prediction = runPrediction(tempFile);
List<TextClassificationOutcome> outcomes = getOutcomeAnnotations(jcas);
List<String> writtenPredictions = FileUtils.readLines(prediction, "utf-8");
checkErrorConditionNumberOfOutcomesEqualsNumberOfPredictions(outcomes, writtenPredictions);
for (int i = 0; i < outcomes.size(); i++) {
if (isRegression()) {
String val = writtenPredictions.get(i);
outcomes.get(i).setOutcome(val);
} else {
String val = writtenPredictions.get(i).replaceAll("\\.0", "");
String pred = integer2OutcomeMapping.get(val);
outcomes.get(i).setOutcome(pred);
}
}
} catch (Exception e) {
throw new AnalysisEngineProcessException(e);
}
}
use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class FolderwiseDataReader method setTextClassificationOutcome.
protected void setTextClassificationOutcome(JCas aJCas, Resource currentFile, int begin, int end) throws IOException {
TextClassificationOutcome tco = new TextClassificationOutcome(aJCas, begin, end);
tco.setOutcome(currentFile.getResource().getFile().getParentFile().getName());
tco.addToIndexes();
}
use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class CrfSuiteLoadModelConnector method setPredictedOutcome.
private void setPredictedOutcome(JCas jcas, String aLabels) {
List<TextClassificationOutcome> outcomes = new ArrayList<TextClassificationOutcome>(JCasUtil.select(jcas, TextClassificationOutcome.class));
String[] labels = aLabels.split("\n");
for (int i = 0, labelIdx = 0; i < outcomes.size(); i++) {
if (labels[labelIdx].isEmpty()) {
// empty lines mark end of sequence
// shift label index +1 to begin of next sequence
labelIdx++;
}
TextClassificationOutcome o = outcomes.get(i);
o.setOutcome(labels[labelIdx++]);
}
}
use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class MappingAnnotator method mapOutcomes.
private void mapOutcomes(JCas aJCas) {
Collection<TextClassificationOutcome> tcos = JCasUtil.select(aJCas, TextClassificationOutcome.class);
for (TextClassificationOutcome o : tcos) {
String outcome = o.getOutcome();
if (outcomeMap.containsKey(outcome)) {
continue;
}
outcomeMap.put(outcome, outcomeIdx++);
}
}
Aggregations