Search in sources :

Example 21 with JCasId

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

the class TestReaderSingleLabelDocumentReader 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();
    if (!suppress) {
        new TextClassificationTarget(jcas, 0, jcas.getDocumentText().length()).addToIndexes();
    }
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) CollectionException(org.apache.uima.collection.CollectionException) TextClassificationOutcome(org.dkpro.tc.api.type.TextClassificationOutcome) TextClassificationTarget(org.dkpro.tc.api.type.TextClassificationTarget) JCas(org.apache.uima.jcas.JCas) CASException(org.apache.uima.cas.CASException)

Example 22 with JCasId

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

the class CrfSuiteLoadModelConnector method getInstancesInSequence.

private List<Instance> getInstancesInSequence(FeatureExtractorResource_ImplBase[] featureExtractors, JCas jcas, TextClassificationSequence sequence, boolean addInstanceId, int sequenceId) throws Exception {
    List<Instance> instances = new ArrayList<Instance>();
    int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
    List<TextClassificationTarget> seqTargets = JCasUtil.selectCovered(jcas, TextClassificationTarget.class, sequence);
    for (TextClassificationTarget aTarget : seqTargets) {
        Instance instance = new Instance();
        if (addInstanceId) {
            instance.addFeature(InstanceIdFeature.retrieve(jcas, aTarget, sequenceId));
        }
        // execute feature extractors and add features to instance
        try {
            for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
                instance.addFeatures(((FeatureExtractor) featExt).extract(jcas, aTarget));
            }
        } catch (TextClassificationException e) {
            throw new AnalysisEngineProcessException(e);
        }
        // set and write outcome label(s)
        instance.setOutcomes(getOutcomes(jcas, aTarget));
        instance.setJcasId(jcasId);
        instance.setSequenceId(sequenceId);
        instance.setSequencePosition(aTarget.getId());
        instances.add(instance);
    }
    return instances;
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) Instance(org.dkpro.tc.api.features.Instance) TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) ArrayList(java.util.ArrayList) TextClassificationTarget(org.dkpro.tc.api.type.TextClassificationTarget) FeatureExtractorResource_ImplBase(org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Example 23 with JCasId

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

the class TestFoldUtil method createJCasIdAnnotation.

private void createJCasIdAnnotation(JCas jcas) {
    JCasId id = new JCasId(jcas);
    id.setId(0);
    id.addToIndexes();
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId)

Example 24 with JCasId

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

the class FoldClassificationUnitCasMultiplier method assignNewId.

private void assignNewId(JCas copyJCas) {
    JCasId jcasId = JCasUtil.selectSingle(copyJCas, JCasId.class);
    jcasId.setId(subCASCounter);
}
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