Search in sources :

Example 21 with FeatureResult

use of com.joliciel.talismane.machineLearning.features.FeatureResult 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)

Example 22 with FeatureResult

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

the class RecursiveShapeSplitter method shouldSplit.

public double shouldSplit(Split splitCandidate) {
    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());
            }
        }
    }
    List<Decision> decisions = decisionMaker.decide(featureResults);
    double yesProb = 0.0;
    for (Decision decision : decisions) {
        if (decision.getOutcome().equals(SplitOutcome.DO_SPLIT.name())) {
            yesProb = decision.getProbability();
            break;
        }
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("splitCandidate: left=" + splitCandidate.getShape().getLeft() + ", pos=" + splitCandidate.getPosition());
        LOG.trace("yesProb: " + yesProb);
    }
    return yesProb;
}
Also used : RuntimeEnvironment(com.joliciel.talismane.machineLearning.features.RuntimeEnvironment) ArrayList(java.util.ArrayList) FeatureResult(com.joliciel.talismane.machineLearning.features.FeatureResult) Decision(com.joliciel.talismane.machineLearning.Decision)

Aggregations

FeatureResult (com.joliciel.talismane.machineLearning.features.FeatureResult)22 ArrayList (java.util.ArrayList)22 RuntimeEnvironment (com.joliciel.talismane.machineLearning.features.RuntimeEnvironment)18 List (java.util.List)14 Decision (com.joliciel.talismane.machineLearning.Decision)11 TreeSet (java.util.TreeSet)10 TalismaneException (com.joliciel.talismane.TalismaneException)9 ClassificationEvent (com.joliciel.talismane.machineLearning.ClassificationEvent)9 IOException (java.io.IOException)9 Map (java.util.Map)8 Set (java.util.Set)8 SortedSet (java.util.SortedSet)8 Collectors (java.util.stream.Collectors)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 TokenSequence (com.joliciel.talismane.tokeniser.TokenSequence)5 WeightedOutcome (com.joliciel.talismane.utils.WeightedOutcome)5 TreeMap (java.util.TreeMap)5 TalismaneSession (com.joliciel.talismane.TalismaneSession)4 ClassificationEventStream (com.joliciel.talismane.machineLearning.ClassificationEventStream)4