Search in sources :

Example 11 with ClassificationEvent

use of com.joliciel.talismane.machineLearning.ClassificationEvent in project jochre by urieli.

the class JochreSplitEventStream method next.

@Override
public ClassificationEvent next() {
    ClassificationEvent event = null;
    if (this.hasNext()) {
        LOG.debug("next event, " + splitCandidate.getShape() + ", split: " + splitCandidate.getPosition());
        List<FeatureResult<?>> featureResults = new ArrayList<FeatureResult<?>>();
        // analyse features
        for (SplitFeature<?> feature : splitFeatures) {
            RuntimeEnvironment env = new RuntimeEnvironment();
            FeatureResult<?> featureResult = feature.check(splitCandidate, env);
            if (featureResult != null) {
                featureResults.add(featureResult);
                if (LOG.isTraceEnabled()) {
                    LOG.trace(featureResult.toString());
                }
            }
        }
        SplitOutcome outcome = SplitOutcome.DO_NOT_SPLIT;
        for (Split split : splitCandidate.getShape().getSplits()) {
            int distance = splitCandidate.getPosition() - split.getPosition();
            if (distance < 0)
                distance = 0 - distance;
            // recall
            if (distance < splitCandidateFinder.getMinDistanceBetweenSplits()) {
                outcome = SplitOutcome.DO_SPLIT;
                break;
            }
        }
        if (outcome.equals(SplitOutcome.DO_SPLIT))
            yesCount++;
        else
            noCount++;
        LOG.debug("Outcome: " + outcome);
        event = new ClassificationEvent(featureResults, outcome.name());
        // set splitCandidate to null so that hasNext can retrieve the next one.
        this.splitCandidate = null;
    }
    return event;
}
Also used : RuntimeEnvironment(com.joliciel.talismane.machineLearning.features.RuntimeEnvironment) ArrayList(java.util.ArrayList) ClassificationEvent(com.joliciel.talismane.machineLearning.ClassificationEvent) FeatureResult(com.joliciel.talismane.machineLearning.features.FeatureResult)

Aggregations

ClassificationEvent (com.joliciel.talismane.machineLearning.ClassificationEvent)11 ArrayList (java.util.ArrayList)10 FeatureResult (com.joliciel.talismane.machineLearning.features.FeatureResult)9 RuntimeEnvironment (com.joliciel.talismane.machineLearning.features.RuntimeEnvironment)8 TalismaneException (com.joliciel.talismane.TalismaneException)6 IOException (java.io.IOException)6 List (java.util.List)5 ClassificationEventStream (com.joliciel.talismane.machineLearning.ClassificationEventStream)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Set (java.util.Set)4 SortedSet (java.util.SortedSet)4 TreeSet (java.util.TreeSet)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Shape (com.joliciel.jochre.graphics.Shape)1 TalismaneSession (com.joliciel.talismane.TalismaneSession)1 Decision (com.joliciel.talismane.machineLearning.Decision)1 ParseConfigurationFeature (com.joliciel.talismane.parser.features.ParseConfigurationFeature)1