Search in sources :

Example 26 with CollectionReader

use of org.apache.uima.collection.CollectionReader in project dkpro-tc by dkpro.

the class LibsvmSaveAndLoadModelDocumentRegression 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);
}
Also used : CollectionReader(org.apache.uima.collection.CollectionReader) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine)

Example 27 with CollectionReader

use of org.apache.uima.collection.CollectionReader in project dkpro-tc by dkpro.

the class LiblinearSaveAndLoadModelDocumentSingleLabelTest method unitLoadAndUseModel.

private static void unitLoadAndUseModel(File modelFolder) throws Exception {
    AnalysisEngine tcAnno = AnalysisEngineFactory.createEngine(TcAnnotator.class, TcAnnotator.PARAM_TC_MODEL_LOCATION, modelFolder.getAbsolutePath(), TcAnnotator.PARAM_NAME_UNIT_ANNOTATION, Token.class.getName());
    CollectionReader reader = CollectionReaderFactory.createReader(TeiReader.class, TeiReader.PARAM_SOURCE_LOCATION, unitTrainFolder, TeiReader.PARAM_LANGUAGE, "en", TeiReader.PARAM_PATTERNS, Arrays.asList(TeiReader.INCLUDE_PREFIX + "a02.xml"));
    List<TextClassificationOutcome> outcomes = new ArrayList<>();
    JCas jcas = JCasFactory.createJCas();
    jcas.setDocumentLanguage("en");
    reader.getNext(jcas.getCas());
    tcAnno.process(jcas);
    outcomes.addAll(JCasUtil.select(jcas, TextClassificationOutcome.class));
    Set<String> possibleOutcomes = new HashSet<>();
    possibleOutcomes.add("AT");
    possibleOutcomes.add("NP");
    possibleOutcomes.add("pct");
    possibleOutcomes.add("WDT");
    possibleOutcomes.add("JJ");
    possibleOutcomes.add("VBD");
    possibleOutcomes.add("NNS");
    possibleOutcomes.add("TO");
    possibleOutcomes.add("VBN");
    possibleOutcomes.add("IN");
    possibleOutcomes.add("CC");
    possibleOutcomes.add("NN");
    possibleOutcomes.add("VBD");
    possibleOutcomes.add("AP");
    possibleOutcomes.add("HVD");
    assertEquals(31, outcomes.size());
    for (TextClassificationOutcome o : outcomes) {
        assertTrue(possibleOutcomes.contains(o.getOutcome()));
    }
}
Also used : CollectionReader(org.apache.uima.collection.CollectionReader) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine) HashSet(java.util.HashSet)

Example 28 with CollectionReader

use of org.apache.uima.collection.CollectionReader 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());
}
Also used : CollectionReader(org.apache.uima.collection.CollectionReader) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine)

Example 29 with CollectionReader

use of org.apache.uima.collection.CollectionReader 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());
    }
}
Also used : CollectionReader(org.apache.uima.collection.CollectionReader) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine)

Example 30 with CollectionReader

use of org.apache.uima.collection.CollectionReader 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());
}
Also used : CollectionReader(org.apache.uima.collection.CollectionReader) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine)

Aggregations

CollectionReader (org.apache.uima.collection.CollectionReader)35 JCas (org.apache.uima.jcas.JCas)28 ArrayList (java.util.ArrayList)25 TextClassificationOutcome (org.dkpro.tc.api.type.TextClassificationOutcome)15 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)14 Test (org.junit.Test)13 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)8 CAS (org.apache.uima.cas.CAS)7 File (java.io.File)5 TextClassificationTarget (org.dkpro.tc.api.type.TextClassificationTarget)5 List (java.util.List)4 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)4 TextClassificationSequence (org.dkpro.tc.api.type.TextClassificationSequence)4 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)3 Lemma (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma)3 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)3 Evaluator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator)2 PossibleValue (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)2 ValuesGenerator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator)2 ConstraintsGrammar (de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar)2