use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class LiblinearSaveAndLoadModelDocumentSingleLabelTest method documentLoadAndUseModel.
private static void documentLoadAndUseModel(File modelFolder, boolean evaluateWithClassificationArgs) throws Exception {
AnalysisEngine tokenizer = AnalysisEngineFactory.createEngine(BreakIteratorSegmenter.class);
AnalysisEngine tcAnno = AnalysisEngineFactory.createEngine(TcAnnotator.class, TcAnnotator.PARAM_TC_MODEL_LOCATION, modelFolder.getAbsolutePath());
CollectionReader reader = CollectionReaderFactory.createReader(TextReader.class, TextReader.PARAM_SOURCE_LOCATION, documentTestFolder, TextReader.PARAM_LANGUAGE, "en", TextReader.PARAM_PATTERNS, Arrays.asList(TextReader.INCLUDE_PREFIX + "*/*.txt"));
List<TextClassificationOutcome> outcomes = new ArrayList<>();
while (reader.hasNext()) {
JCas jcas = JCasFactory.createJCas();
reader.getNext(jcas.getCas());
jcas.setDocumentLanguage("en");
tokenizer.process(jcas);
tcAnno.process(jcas);
outcomes.add(JCasUtil.selectSingle(jcas, TextClassificationOutcome.class));
}
assertEquals(4, outcomes.size());
assertEquals("neutral", outcomes.get(0).getOutcome());
assertEquals("neutral", outcomes.get(1).getOutcome());
assertEquals("neutral", outcomes.get(2).getOutcome());
assertEquals("neutral", outcomes.get(3).getOutcome());
}
use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class LibsvmSaveAndLoadModelDocumentSingleLabelTest method documentLoadAndUseModel.
private static void documentLoadAndUseModel(File modelFolder, boolean evaluateWithClassificationArgs) throws Exception {
AnalysisEngine tokenizer = AnalysisEngineFactory.createEngine(BreakIteratorSegmenter.class);
AnalysisEngine tcAnno = AnalysisEngineFactory.createEngine(TcAnnotator.class, TcAnnotator.PARAM_TC_MODEL_LOCATION, modelFolder.getAbsolutePath());
CollectionReader reader = CollectionReaderFactory.createReader(TextReader.class, TextReader.PARAM_SOURCE_LOCATION, documentTestFolder, TextReader.PARAM_LANGUAGE, "en", TextReader.PARAM_PATTERNS, Arrays.asList(TextReader.INCLUDE_PREFIX + "*/*.txt"));
List<TextClassificationOutcome> outcomes = new ArrayList<>();
while (reader.hasNext()) {
JCas jcas = JCasFactory.createJCas();
reader.getNext(jcas.getCas());
jcas.setDocumentLanguage("en");
tokenizer.process(jcas);
tcAnno.process(jcas);
outcomes.add(JCasUtil.selectSingle(jcas, TextClassificationOutcome.class));
}
assertEquals(4, outcomes.size());
if (evaluateWithClassificationArgs) {
assertEquals(4, outcomes.size());
assertEquals("neutral", outcomes.get(0).getOutcome());
assertEquals("neutral", outcomes.get(1).getOutcome());
assertEquals("neutral", outcomes.get(2).getOutcome());
assertEquals("neutral", outcomes.get(3).getOutcome());
} else {
assertEquals(4, outcomes.size());
assertEquals("emotional", outcomes.get(0).getOutcome());
assertEquals("emotional", outcomes.get(1).getOutcome());
assertEquals("emotional", outcomes.get(2).getOutcome());
assertEquals("emotional", outcomes.get(3).getOutcome());
}
}
use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class WekaSaveAndLoadModelDocumentPairRegression method pairLoadModelRegression.
private static void pairLoadModelRegression(File modelFolder) throws Exception {
CollectionReader reader = CollectionReaderFactory.createReader(STSReader.class, STSReader.PARAM_INPUT_FILE, pairTrainFiles, STSReader.PARAM_GOLD_FILE, pairGoldFiles);
AnalysisEngine tcAnno = AnalysisEngineFactory.createEngine(TcAnnotator.class, TcAnnotator.PARAM_TC_MODEL_LOCATION, modelFolder.getAbsolutePath());
JCas jcas = JCasFactory.createJCas();
reader.getNext(jcas.getCas());
tcAnno.process(jcas);
List<TextClassificationOutcome> outcomes = new ArrayList<>(JCasUtil.select(jcas, TextClassificationOutcome.class));
assertEquals(1, outcomes.size());
assertEquals("4.0958", outcomes.get(0).getOutcome());
}
use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class WekaUnitAnnotator method process.
@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
Collection<Token> tokens = JCasUtil.select(aJCas, Token.class);
for (Token token : tokens) {
TextClassificationTarget unit = new TextClassificationTarget(aJCas, token.getBegin(), token.getEnd());
unit.setId(tcId++);
unit.setSuffix(token.getCoveredText());
unit.addToIndexes();
TextClassificationOutcome outcome = new TextClassificationOutcome(aJCas, token.getBegin(), token.getEnd());
outcome.setOutcome(getTextClassificationOutcome(aJCas, unit));
outcome.addToIndexes();
}
}
use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.
the class XgboostSaveAndLoadModelDocumentRegression method regressionLoadModel.
private void regressionLoadModel(File modelFolder) throws UIMAException, IOException {
CollectionReader reader = CollectionReaderFactory.createReader(LinewiseTextOutcomeReader.class, LinewiseTextOutcomeReader.PARAM_OUTCOME_INDEX, 0, LinewiseTextOutcomeReader.PARAM_TEXT_INDEX, 1, LinewiseTextOutcomeReader.PARAM_SOURCE_LOCATION, regressionTest, LinewiseTextOutcomeReader.PARAM_LANGUAGE, "en");
AnalysisEngine segmenter = AnalysisEngineFactory.createEngine(BreakIteratorSegmenter.class);
AnalysisEngine tcAnno = AnalysisEngineFactory.createEngine(TcAnnotator.class, TcAnnotator.PARAM_TC_MODEL_LOCATION, modelFolder.getAbsolutePath(), TcAnnotator.PARAM_NAME_UNIT_ANNOTATION, Token.class.getName());
JCas jcas = JCasFactory.createJCas();
reader.hasNext();
reader.getNext(jcas.getCas());
segmenter.process(jcas);
tcAnno.process(jcas);
List<TextClassificationOutcome> outcomes = new ArrayList<>(JCasUtil.select(jcas, TextClassificationOutcome.class));
assertEquals(1, outcomes.size());
Double d = Double.valueOf(outcomes.get(0).getOutcome());
assertTrue(d > 0.1 && d < 5);
}
Aggregations