Search in sources :

Example 21 with TextClassificationOutcome

use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.

the class VectorizationSeq2SeqOfLabel method processOutcome.

private void processOutcome(JCas aJCas) throws Exception {
    List<AnnotationFS> sequenceAnnos = new ArrayList<AnnotationFS>(CasUtil.select(aJCas.getCas(), sequenceSpanType));
    for (AnnotationFS s : sequenceAnnos) {
        List<TextClassificationOutcome> instances = JCasUtil.selectCovered(aJCas, TextClassificationOutcome.class, s);
        if (instances.isEmpty()) {
            continue;
        }
        int i = 0;
        for (; i < instances.size(); i++) {
            TextClassificationOutcome tco = instances.get(i);
            if (toInteger) {
                writerSeqOutcome.write(outcomeMap.get(tco.getOutcome()).toString());
            } else {
                writerSeqOutcome.write(tco.getOutcome());
            }
            if (i + 1 >= maximumLength) {
                break;
            }
            if (i + 1 < instances.size()) {
                writerSeqOutcome.write(" ");
            }
        }
        writerSeqOutcome.write(System.lineSeparator());
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) ArrayList(java.util.ArrayList)

Example 22 with TextClassificationOutcome

use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.

the class VocabularyOutcomeCollector method collectOutcomes.

private void collectOutcomes(JCas aJCas) {
    Collection<TextClassificationOutcome> tcos = JCasUtil.select(aJCas, TextClassificationOutcome.class);
    for (TextClassificationOutcome o : tcos) {
        String outcome = o.getOutcome();
        outcomes.add(outcome);
    }
}
Also used : TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome)

Example 23 with TextClassificationOutcome

use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.

the class InstanceExtractor method getWeight.

private double getWeight(JCas jcas, AnnotationFS unit) throws TextClassificationException {
    Collection<TextClassificationOutcome> outcomes;
    if (unit == null) {
        outcomes = JCasUtil.select(jcas, TextClassificationOutcome.class);
    } else {
        outcomes = JCasUtil.selectCovered(jcas, TextClassificationOutcome.class, unit);
    }
    if (outcomes.size() == 0) {
        throw new TextClassificationException("No instance weight annotation present in current CAS.");
    }
    double weight = -1.0;
    for (TextClassificationOutcome outcome : outcomes) {
        weight = outcome.getWeight();
    }
    return weight;
}
Also used : TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome)

Example 24 with TextClassificationOutcome

use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.

the class InstanceExtractor method getOutcomes.

public List<String> getOutcomes(JCas jcas, AnnotationFS unit) throws TextClassificationException {
    Collection<TextClassificationOutcome> outcomes;
    if (unit == null) {
        outcomes = JCasUtil.select(jcas, TextClassificationOutcome.class);
    } else {
        outcomes = JCasUtil.selectCovered(jcas, TextClassificationOutcome.class, unit);
    }
    if (outcomes.size() == 0) {
        throw new TextClassificationException("No outcome annotations present in current CAS.");
    }
    List<String> stringOutcomes = new ArrayList<String>();
    for (TextClassificationOutcome outcome : outcomes) {
        stringOutcomes.add(outcome.getOutcome());
    }
    return stringOutcomes;
}
Also used : TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) ArrayList(java.util.ArrayList)

Example 25 with TextClassificationOutcome

use of org.dkpro.tc.api.type.TextClassificationOutcome in project dkpro-tc by dkpro.

the class SequenceOutcomeAnnotator_ImplBase method process.

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    for (TextClassificationTarget unit : JCasUtil.selectCovered(jcas, TextClassificationTarget.class, JCasUtil.selectSingle(jcas, TextClassificationSequence.class))) {
        TextClassificationOutcome outcome = new TextClassificationOutcome(jcas, unit.getBegin(), unit.getEnd());
        outcome.setOutcome(getTextClassificationOutcome(jcas, unit));
        outcome.setWeight(getTextClassificationOutcomeWeight(jcas, unit));
        outcome.addToIndexes();
    }
}
Also used : TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) TextClassificationTarget(org.dkpro.tc.api.type.TextClassificationTarget) TextClassificationSequence(org.dkpro.tc.api.type.TextClassificationSequence)

Aggregations

TextClassificationOutcome (org.dkpro.tc.api.type.TextClassificationOutcome)59 JCas (org.apache.uima.jcas.JCas)29 ArrayList (java.util.ArrayList)27 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)19 TextClassificationTarget (org.dkpro.tc.api.type.TextClassificationTarget)18 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)16 CollectionReader (org.apache.uima.collection.CollectionReader)15 CollectionException (org.apache.uima.collection.CollectionException)9 CASException (org.apache.uima.cas.CASException)8 JCasId (org.dkpro.tc.api.type.JCasId)8 TextClassificationSequence (org.dkpro.tc.api.type.TextClassificationSequence)7 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)6 Test (org.junit.Test)6 DocumentMetaData (de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData)5 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)5 File (java.io.File)5 IOException (java.io.IOException)4 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)4 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)4 HashSet (java.util.HashSet)3