Lingua example
Latest stable Based on Text release 0.2.1
The runnable Lingua example compares detector reuse, an explicit language subset, and low-accuracy mode. Its mixed sample contains English, Korean, and Japanese sentences.
Run it
Section titled “Run it”./gradlew :examples:lingua-examples:runThe report contains three lines:
reuse=<detected English, Korean, and Japanese set>subset=<detected English, Korean, and Japanese set>lowAccuracy=ENGLISHThe two mixed-language values are sets; do not assert their printed order.
Reused detector
Section titled “Reused detector”The first detector is constructed for exactly English, Korean, and Japanese, sets minimum relative distance to 0.0, preloads models, and keeps full-accuracy mode. The example calls it after construction instead of rebuilding it around each text.
This is the default shape for a service with a known support policy: define the set at application setup and share the configured detector.
DSL subset
Section titled “DSL subset”The second detector uses the DSL form:
val detector = languageDetectorOf(languages) { withMinimumRelativeDistance(0.0) withPreloadedLanguageModels()}It should represent the same product language set as the parameter-based detector. The comparison makes configuration drift visible.
Low-accuracy detector
Section titled “Low-accuracy detector”The third detector supports only English and German, loads models lazily, and enables low-accuracy mode. The sample Hello service users resolves to English in the release fixture.
Low-accuracy mode is a deliberate resource/quality trade-off. Validate it against your corpus rather than switching it on as an invisible performance flag.
Modify it safely
Section titled “Modify it safely”- Replace the support set with the exact languages of your product.
- Add short and ambiguous inputs.
- Add blank input and verify
detectAllLanguagesOfreturns an empty set. - Add an application route assertion separate from detector output.
Continue with mixed-language processing, runtime boundaries, and the Lingua module.