use of com.joliciel.talismane.machineLearning.features.RuntimeEnvironment in project talismane by joliciel-informatique.
the class PatternEventStream method next.
@Override
public ClassificationEvent next() throws TalismaneException, IOException {
ClassificationEvent event = null;
if (this.hasNext()) {
TokenPatternMatch tokenPatternMatch = currentPatternMatches.get(currentIndex);
TokeniserOutcome outcome = currentOutcomes.get(currentIndex);
String classification = outcome.name();
LOG.debug("next event, pattern match: " + tokenPatternMatch.toString() + ", outcome:" + classification);
List<FeatureResult<?>> tokenFeatureResults = new ArrayList<FeatureResult<?>>();
for (TokenPatternMatchFeature<?> feature : tokenPatternMatchFeatures) {
RuntimeEnvironment env = new RuntimeEnvironment();
FeatureResult<?> featureResult = feature.check(tokenPatternMatch, env);
if (featureResult != null) {
tokenFeatureResults.add(featureResult);
}
}
if (LOG.isTraceEnabled()) {
SortedSet<String> featureResultSet = tokenFeatureResults.stream().map(f -> f.toString()).collect(Collectors.toCollection(() -> new TreeSet<String>()));
for (String featureResultString : featureResultSet) {
LOG.trace(featureResultString);
}
}
event = new ClassificationEvent(tokenFeatureResults, classification);
currentIndex++;
if (currentIndex == currentPatternMatches.size()) {
currentPatternMatches = null;
}
}
return event;
}
use of com.joliciel.talismane.machineLearning.features.RuntimeEnvironment in project jochre by urieli.
the class LetterFeatureTester method testFeatures.
void testFeatures(ShapeInSequence shapeInSequence, Set<LetterFeature<?>> features) {
LetterSequence history = null;
LetterGuesserContext context = new LetterGuesserContext(shapeInSequence, history);
for (LetterFeature<?> feature : features) {
RuntimeEnvironment env = new RuntimeEnvironment();
feature.check(context, env);
}
}
use of com.joliciel.talismane.machineLearning.features.RuntimeEnvironment in project jochre by urieli.
the class JochreLetterEventStream method next.
@Override
public ClassificationEvent next() {
ClassificationEvent event = null;
if (this.hasNext()) {
Shape shape = shapeInSequence.getShape();
LOG.debug("next event, shape: " + shape);
LetterGuesserContext context = new LetterGuesserContext(shapeInSequence, history);
List<FeatureResult<?>> featureResults = new ArrayList<>();
// analyse features
for (LetterFeature<?> feature : features) {
RuntimeEnvironment env = new RuntimeEnvironment();
FeatureResult<?> featureResult = feature.check(context, env);
if (featureResult != null) {
featureResults.add(featureResult);
if (LOG.isTraceEnabled()) {
LOG.trace(featureResult.toString());
}
}
}
String outcome = shape.getLetter();
event = new ClassificationEvent(featureResults, outcome);
history.getLetters().add(outcome);
// set shape to null so that hasNext can retrieve the next one.
this.shapeInSequence = null;
}
return event;
}
use of com.joliciel.talismane.machineLearning.features.RuntimeEnvironment in project jochre by urieli.
the class LetterGuesser method guessLetter.
/**
* Analyses this shape, using the context provided for features that are not
* intrinsic. Updates shape.getWeightedOutcomes to include all outcomes
* above a certain threshold of probability.
*
* @return the best outcome for this shape.
*/
public String guessLetter(ShapeInSequence shapeInSequence, LetterSequence history) {
Shape shape = shapeInSequence.getShape();
if (LOG.isTraceEnabled())
LOG.trace("guessLetter, shape: " + shape);
List<FeatureResult<?>> featureResults = new ArrayList<FeatureResult<?>>();
// analyse features
for (LetterFeature<?> feature : features) {
LetterGuesserContext context = new LetterGuesserContext(shapeInSequence, history);
RuntimeEnvironment env = new RuntimeEnvironment();
FeatureResult<?> featureResult = feature.check(context, env);
if (featureResult != null) {
featureResults.add(featureResult);
if (LOG.isTraceEnabled()) {
LOG.trace(featureResult.toString());
}
}
}
List<Decision> letterGuesses = decisionMaker.decide(featureResults);
// store outcomes
String bestOutcome = null;
shape.getLetterGuesses().clear();
for (Decision letterGuess : letterGuesses) {
if (letterGuess.getProbability() >= MIN_PROB_TO_STORE) {
shape.getLetterGuesses().add(letterGuess);
}
}
bestOutcome = shape.getLetterGuesses().iterator().next().getOutcome();
if (LOG.isTraceEnabled()) {
LOG.trace("Shape: " + shape);
LOG.trace("Letter: " + shape.getLetter());
LOG.trace("Best outcome: " + bestOutcome);
}
return bestOutcome;
}
use of com.joliciel.talismane.machineLearning.features.RuntimeEnvironment 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;
}
Aggregations