LanguageDetector class final
Detects the language of a piece of text.
Use LanguageDetector.pureDart for the zero-dependency default (a
Unicode script pre-filter plus a character n-gram model, covering 58
languages — see CompositeBackend), or supply a custom backend for
testing or an alternative scoring strategy.
Example:
final detector = LanguageDetector.pureDart();
switch (detector.detect('Bonjour le monde')) {
case Detected(best: final guess):
print('${guess.code} (${guess.confidence})'); // fr (...)
case Undetermined():
print('could not determine a language');
}
Constructors
-
LanguageDetector({required LanguageDetectorBackend backend, double minConfidence = 0.5, Set<
String> ? restrictTo}) -
Creates a detector scoring with
backend. -
LanguageDetector.pureDart({double minConfidence = 0.5, Set<
String> ? restrictTo}) -
The zero-dependency default: a Unicode script pre-filter plus a
character n-gram model, covering 58 languages (see
CompositeBackend).factory
Properties
- backend → LanguageDetectorBackend
-
The scoring strategy this detector delegates to.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- minConfidence → double
-
The minimum confidence (in
[0.0, 1.0]) a guess must reach for detect to return Detected rather than Undetermined.final -
restrictTo
→ Set<
String> ? -
If non-null, guesses whose code is not in this set are dropped before
ranking. See the constructor doc for how this interacts with
pureDart's backend-level narrowing.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
detect(
String text) → DetectionResult -
Full detection: scores
textwith backend, applies restrictTo (if set) and minConfidence, and ranks the result by descending confidence. -
dominantScript(
String text) → String? -
Cheap, script-only classification of
text— does not run the n-gram stage. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited