Search in sources :

Example 16 with JCasId

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

the class InstanceExtractor method getSingleInstanceDocument.

private Instance getSingleInstanceDocument(Instance instance, JCas jcas, boolean supportSparseFeatures) throws TextClassificationException {
    int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
    TextClassificationTarget documentTcu = JCasUtil.selectSingle(jcas, TextClassificationTarget.class);
    if (addInstanceId) {
        instance.addFeature(InstanceIdFeature.retrieve(jcas));
    }
    for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
        if (!(featExt instanceof FeatureExtractor)) {
            throw new TextClassificationException("Using incompatible feature in document mode: " + featExt.getResourceName());
        }
        if (supportSparseFeatures) {
            instance.addFeatures(getSparse(jcas, documentTcu, featExt));
        } else {
            instance.addFeatures(getDense(jcas, documentTcu, featExt));
        }
        instance.setOutcomes(getOutcomes(jcas, null));
        instance.setWeight(getWeight(jcas, null));
        instance.setJcasId(jcasId);
    }
    return instance;
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) FeatureExtractor(org.dkpro.tc.api.features.FeatureExtractor) PairFeatureExtractor(org.dkpro.tc.api.features.PairFeatureExtractor) TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) TextClassificationTarget(org.dkpro.tc.api.type.TextClassificationTarget) FeatureExtractorResource_ImplBase(org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase)

Example 17 with JCasId

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

the class InstanceExtractor method getSequenceInstances.

public List<Instance> getSequenceInstances(JCas jcas, boolean useSparse) throws TextClassificationException {
    List<Instance> instances = new ArrayList<Instance>();
    int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
    int sequenceId = 0;
    int unitId = 0;
    Collection<TextClassificationSequence> sequences = JCasUtil.select(jcas, TextClassificationSequence.class);
    for (TextClassificationSequence seq : sequences) {
        unitId = 0;
        List<TextClassificationTarget> seqTargets = JCasUtil.selectCovered(jcas, TextClassificationTarget.class, seq);
        for (TextClassificationTarget aTarget : seqTargets) {
            aTarget.setId(unitId++);
            Instance instance = new Instance();
            if (addInstanceId) {
                instance.addFeature(InstanceIdFeature.retrieve(jcas, aTarget, sequenceId));
            }
            for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
                if (useSparse) {
                    instance.addFeatures(getSparse(jcas, aTarget, featExt));
                } else {
                    instance.addFeatures(getDense(jcas, aTarget, featExt));
                }
            }
            // set and write outcome label(s)
            instance.setOutcomes(getOutcomes(jcas, aTarget));
            instance.setWeight(getWeight(jcas, aTarget));
            instance.setJcasId(jcasId);
            instance.setSequenceId(sequenceId);
            instance.setSequencePosition(aTarget.getId());
            instances.add(instance);
        }
        sequenceId++;
    }
    return instances;
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) Instance(org.dkpro.tc.api.features.Instance) ArrayList(java.util.ArrayList) TextClassificationTarget(org.dkpro.tc.api.type.TextClassificationTarget) TextClassificationSequence(org.dkpro.tc.api.type.TextClassificationSequence) FeatureExtractorResource_ImplBase(org.dkpro.tc.api.features.FeatureExtractorResource_ImplBase)

Example 18 with JCasId

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

the class TestReaderMultiLabel 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();
    }
    for (String outcomeValue : getTextClassificationOutcomes(jcas)) {
        TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
        outcome.setOutcome(outcomeValue);
        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 19 with JCasId

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

the class IdentificationCollector method processDocumentMode.

private void processDocumentMode(JCas aJCas) throws AnalysisEngineProcessException {
    int jcasId = JCasUtil.selectSingle(aJCas, JCasId.class).getId();
    try {
        String documentFile = DocumentMetaData.get(aJCas).getDocumentUri();
        if (documentFile == null) {
            documentFile = DocumentMetaData.get(aJCas).getDocumentId();
        }
        writer.write(jcasId + "\t" + documentFile + System.lineSeparator());
    } catch (IOException e) {
        throw new AnalysisEngineProcessException(e);
    }
}
Also used : JCasId(org.dkpro.tc.api.type.JCasId) IOException(java.io.IOException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Example 20 with JCasId

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

the class TestReaderRegression 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)

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