Search in sources :

Example 11 with JCasId

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

the class TestReaderSingleLabel method getNext.

@Override
public void getNext(CAS aCAS) throws IOException, CollectionException {
    super.getNext(aCAS);
    JCas jcas;
    try {
        jcas = aCAS.getJCas();
        JCasId id = new JCasId(jcas);
        id.setId(jcasId);
        id.addToIndexes();
    } catch (CASException e) {
        throw new CollectionException();
    }
    TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
    outcome.setOutcome(getTextClassificationOutcome(jcas));
    outcome.addToIndexes();
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) CollectionException(org.apache.uima.collection.CollectionException) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) JCas(org.apache.uima.jcas.JCas) CASException(org.apache.uima.cas.CASException)

Example 12 with JCasId

use of org.dkpro.tc.api.type.JCasId 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;
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) TextClassificationTarget(org.dkpro.tc.api.type.TextClassificationTarget) JCas(org.apache.uima.jcas.JCas) DocumentMetaData(de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData) TextClassificationSequence(org.dkpro.tc.api.type.TextClassificationSequence) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine)

Example 13 with JCasId

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

the class TcAnnotator method process.

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    if (!JCasUtil.exists(aJCas, JCasId.class)) {
        JCasId id = new JCasId(aJCas);
        id.setId(jcasId++);
        id.addToIndexes();
    }
    switch(featureMode) {
        case Constants.FM_DOCUMENT:
            processDocument(aJCas);
            break;
        case Constants.FM_PAIR:
            // same as document
            processDocument(aJCas);
            break;
        case Constants.FM_SEQUENCE:
            processSequence(aJCas);
            break;
        case Constants.FM_UNIT:
            processUnit(aJCas);
            break;
        default:
            throw new IllegalStateException("Feature mode [" + featureMode + "] is unknown");
    }
    if (conversionAnnotator != null && conversionAnnotator.length > 0) {
        callConversionEngine(aJCas);
    }
    if (!retainTargets) {
        removeTargets(aJCas);
    }
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId)

Example 14 with JCasId

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

the class TestPairReader method getNext.

@Override
public void getNext(JCas jcas) throws IOException, CollectionException {
    super.getNext(jcas);
    JCasId id = new JCasId(jcas);
    id.setId(jcasid++);
    id.addToIndexes();
    for (String outcomeValue : getTextClassificationOutcomes(jcas)) {
        TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
        outcome.setOutcome(outcomeValue);
        outcome.addToIndexes();
    }
    // as we are creating more than one CAS out of a single file, we need to have different
    // document titles and URIs for each CAS
    // otherwise, serialized CASes will be overwritten
    DocumentMetaData dmd = DocumentMetaData.get(jcas);
    dmd.setDocumentTitle(dmd.getDocumentTitle() + "-" + fileOffset);
    dmd.setDocumentUri(dmd.getDocumentUri() + "-" + fileOffset);
    fileOffset++;
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) DocumentMetaData(de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData)

Example 15 with JCasId

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

the class AssignIdConnector method process.

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    LogFactory.getLog(getClass()).info("--- validating CAS with id [" + jcasId + "] ---");
    boolean exists = JCasUtil.exists(aJCas, JCasId.class);
    if (!exists) {
        JCasId id = new JCasId(aJCas);
        id.setId(jcasId++);
        id.addToIndexes();
    }
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId)

Aggregations

JCasId (org.dkpro.tc.api.type.JCasId)24 TextClassificationTarget (org.dkpro.tc.api.type.TextClassificationTarget)11 JCas (org.apache.uima.jcas.JCas)9 TextClassificationOutcome (org.dkpro.tc.api.type.TextClassificationOutcome)8 CASException (org.apache.uima.cas.CASException)6 FeatureExtractorResource_ImplBase (org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase)6 CollectionException (org.apache.uima.collection.CollectionException)5 ArrayList (java.util.ArrayList)4 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)4 DocumentMetaData (de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData)3 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)3 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)3 Instance (org.dkpro.tc.api.features.Instance)3 PairFeatureExtractor (org.dkpro.tc.api.features.PairFeatureExtractor)3 IOException (java.io.IOException)2 Feature (org.dkpro.tc.api.features.Feature)2 FeatureExtractor (org.dkpro.tc.api.features.FeatureExtractor)2 TextClassificationSequence (org.dkpro.tc.api.type.TextClassificationSequence)2 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)1 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)1