Search in sources :

Example 6 with TextClassificationSequence

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

the class TcAnnotator method addTCSequenceAnnotation.

private void addTCSequenceAnnotation(JCas jcas) {
    Type type = jcas.getCas().getTypeSystem().getType(nameSequence);
    Collection<AnnotationFS> sequenceAnnotation = CasUtil.select(jcas.getCas(), type);
    for (AnnotationFS seq : sequenceAnnotation) {
        TextClassificationSequence tcs = new TextClassificationSequence(jcas, seq.getBegin(), seq.getEnd());
        tcs.addToIndexes();
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) TextClassificationSequence(org.dkpro.tc.api.type.TextClassificationSequence)

Example 7 with TextClassificationSequence

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

the class TestFoldUtil method setSeq.

private void setSeq(JCas cas, int beg, int end) {
    TextClassificationSequence seq = new TextClassificationSequence(cas, beg, end);
    seq.addToIndexes();
    String[] split = seq.getCoveredText().split(" ");
    setUnit(cas, beg, beg + split[0].length());
    setUnit(cas, beg + split[0].length() + 1, end);
}
Also used : TextClassificationSequence(org.dkpro.tc.api.type.TextClassificationSequence)

Example 8 with TextClassificationSequence

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

the class TestFoldUtil method countNumberOfTextClassificationSequencesAndUnitsPerCas.

private List<List<Integer>> countNumberOfTextClassificationSequencesAndUnitsPerCas(List<File> writtenBins) throws Exception {
    List<List<Integer>> arrayList = new ArrayList<>();
    List<Integer> units = new ArrayList<>();
    List<Integer> seq = new ArrayList<>();
    for (File f : writtenBins) {
        JCas jcas = JCasFactory.createJCas();
        CollectionReader createReader = createReader(jcas, f);
        createReader.getNext(jcas.getCas());
        Collection<TextClassificationTarget> colUni = JCasUtil.select(jcas, TextClassificationTarget.class);
        units.add(colUni.size());
        Collection<TextClassificationSequence> colSeq = JCasUtil.select(jcas, TextClassificationSequence.class);
        seq.add(colSeq.size());
    }
    arrayList.add(seq);
    arrayList.add(units);
    return arrayList;
}
Also used : CollectionReader(org.apache.uima.collection.CollectionReader) ArrayList(java.util.ArrayList) TextClassificationTarget(org.dkpro.tc.api.type.TextClassificationTarget) JCas(org.apache.uima.jcas.JCas) ArrayList(java.util.ArrayList) List(java.util.List) TextClassificationSequence(org.dkpro.tc.api.type.TextClassificationSequence) File(java.io.File)

Example 9 with TextClassificationSequence

use of org.dkpro.tc.api.type.TextClassificationSequence 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 10 with TextClassificationSequence

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

the class SequenceContextMetaCollector method process.

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    Collection<TextClassificationSequence> sequences = JCasUtil.select(jcas, TextClassificationSequence.class);
    for (TextClassificationSequence seq : sequences) {
        int id = seq.getId();
        for (TextClassificationTarget unit : JCasUtil.selectCovered(jcas, TextClassificationTarget.class, seq)) {
            String idString;
            try {
                idString = (String) InstanceIdFeature.retrieve(jcas, unit, id).getValue();
                ContextMetaCollectorUtil.addContext(jcas, unit, idString, bw);
            } catch (Exception e) {
                throw new AnalysisEngineProcessException(e);
            }
        }
    }
}
Also used : TextClassificationTarget(org.dkpro.tc.api.type.TextClassificationTarget) TextClassificationSequence(org.dkpro.tc.api.type.TextClassificationSequence) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Aggregations

TextClassificationSequence (org.dkpro.tc.api.type.TextClassificationSequence)15 TextClassificationTarget (org.dkpro.tc.api.type.TextClassificationTarget)11 ArrayList (java.util.ArrayList)6 JCas (org.apache.uima.jcas.JCas)6 TextClassificationOutcome (org.dkpro.tc.api.type.TextClassificationOutcome)6 List (java.util.List)4 CollectionReader (org.apache.uima.collection.CollectionReader)4 Test (org.junit.Test)3 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)2 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)2 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)2 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)2 Instance (org.dkpro.tc.api.features.Instance)2 JCasId (org.dkpro.tc.api.type.JCasId)2 DocumentMetaData (de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData)1 File (java.io.File)1 IOException (java.io.IOException)1 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)1 CASException (org.apache.uima.cas.CASException)1 Type (org.apache.uima.cas.Type)1