-
- All Implemented Interfaces:
public final class LanguageDetectorBuilderConfigures and creates an instance of LanguageDetector.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classLanguageDetectorBuilder.Companion
-
Method Summary
Modifier and Type Method Description final LanguageDetectorbuild()Creates and returns the configured instance of LanguageDetector. final LanguageDetectorBuilderwithMinimumRelativeDistance(Double distance)Sets the desired value for the minimum relative distance measure. final LanguageDetectorBuilderwithPreloadedLanguageModels()Preloads all language models when creating the instance of LanguageDetector. final LanguageDetectorBuilderwithLowAccuracyMode()Disables the high accuracy mode in order to save memory and increase performance. -
-
Method Detail
-
build
final LanguageDetector build()
Creates and returns the configured instance of LanguageDetector.
-
withMinimumRelativeDistance
final LanguageDetectorBuilder withMinimumRelativeDistance(Double distance)
Sets the desired value for the minimum relative distance measure.
By default, Lingua returns the most likely language for a given input text. However, there are certain words that are spelled the same in more than one language. The word prologue, for instance, is both a valid English and French word. Lingua would output either English or French which might be wrong in the given context. For cases like that, it is possible to specify a minimum relative distance that the logarithmized and summed up probabilities for each possible language have to satisfy.
Be aware that the distance between the language probabilities is dependent on the length of the input text. The longer the input text, the larger the distance between the languages. So if you want to classify very short text phrases, do not set the minimum relative distance too high. Otherwise you will get most results returned as Language.UNKNOWN which is the return value for cases where language detection is not reliably possible.
- Parameters:
distance- A value between 0.0 and 0.99.
-
withPreloadedLanguageModels
final LanguageDetectorBuilder withPreloadedLanguageModels()
Preloads all language models when creating the instance of LanguageDetector.
By default, Lingua uses lazy-loading to load only those language models on demand which are considered relevant by the rule-based filter engine. For web services, for instance, it is rather beneficial to preload all language models into memory to avoid unexpected latency while waiting for the service response. This method allows to switch between these two loading modes.
-
withLowAccuracyMode
final LanguageDetectorBuilder withLowAccuracyMode()
Disables the high accuracy mode in order to save memory and increase performance.
By default, Lingua's high detection accuracy comes at the cost of loading large language models into memory which might not be feasible for systems running low on resources.
This method disables the high accuracy mode so that only a small subset of language models is loaded into memory. The downside of this approach is that detection accuracy for short texts consisting of less than 120 characters will drop significantly. However, detection accuracy for texts which are longer than 120 characters will remain mostly unaffected.
-
-
-
-