Search in sources :

Example 1 with CrfSuiteFeatureFormatExtractionIterator

use of org.dkpro.tc.ml.crfsuite.writer.CrfSuiteFeatureFormatExtractionIterator in project dkpro-tc by dkpro.

the class CrfSuiteLoadModelConnector method process.

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    try {
        int sequenceId = 0;
        List<Instance> instance = new ArrayList<>();
        for (TextClassificationSequence seq : JCasUtil.select(jcas, TextClassificationSequence.class)) {
            instance.addAll(getInstancesInSequence(featureExtractors, jcas, seq, true, sequenceId++));
        }
        CrfSuiteFeatureFormatExtractionIterator iterator = new CrfSuiteFeatureFormatExtractionIterator(instance);
        // takes N sequences and classifies them - all results are hold in
        // memory
        StringBuilder output = new StringBuilder();
        while (iterator.hasNext()) {
            StringBuilder buffer = new StringBuilder();
            int limit = 5000;
            int idx = 0;
            while (iterator.hasNext()) {
                StringBuilder seqInfo = iterator.next();
                buffer.append(seqInfo);
                idx++;
                if (idx == limit) {
                    break;
                }
            }
            List<String> command = buildCommand();
            StringBuilder out = runCommand(command, buffer.toString());
            output.append(out);
        }
        setPredictedOutcome(jcas, output.toString());
    } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
    }
}
Also used : Instance(org.dkpro.tc.api.features.Instance) ArrayList(java.util.ArrayList) CrfSuiteFeatureFormatExtractionIterator(org.dkpro.tc.ml.crfsuite.writer.CrfSuiteFeatureFormatExtractionIterator) TextClassificationSequence(org.dkpro.tc.api.type.TextClassificationSequence) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) IOException(java.io.IOException) TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)1 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)1 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)1 Instance (org.dkpro.tc.api.features.Instance)1 TextClassificationSequence (org.dkpro.tc.api.type.TextClassificationSequence)1 CrfSuiteFeatureFormatExtractionIterator (org.dkpro.tc.ml.crfsuite.writer.CrfSuiteFeatureFormatExtractionIterator)1