detect method
- String text
Full detection: scores text with backend, applies restrictTo (if
set) and minConfidence, and ranks the result by descending
confidence.
Implementation
DetectionResult detect(String text) {
var guesses = backend.score(text);
final allowed = restrictTo;
if (allowed != null) {
guesses = [
for (final g in guesses)
if (allowed.contains(g.code)) g,
];
}
guesses = [...guesses]
..sort((a, b) => b.confidence.compareTo(a.confidence));
if (guesses.isEmpty) return Undetermined(guesses);
final best = guesses.first;
if (best.confidence >= minConfidence) {
return Detected(best, guesses);
}
return Undetermined(guesses);
}