Package 

Class LanguageDetector

  • All Implemented Interfaces:

    
    public final class LanguageDetector
    
                        

    Detects the language of given input text.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • detectLanguageOf

         final Language detectLanguageOf(String text)

        Detects the language of given input text.

        Parameters:
        text - The input text to detect the language for.
      • computeLanguageConfidenceValues

         final SortedMap<Language, Double> computeLanguageConfidenceValues(String text)

        Computes confidence values for every language considered possible for the given input text.

        The values that this method computes are part of a relative confidence metric, not of an absolute one. Each value is a number between 0.0 and 1.0. The most likely language is always returned with value 1.0. All other languages get values assigned which are lower than 1.0, denoting how less likely those languages are in comparison to the most likely language.

        The map returned by this method does not necessarily contain all languages which the calling instance of LanguageDetector was built from. If the rule-based engine decides that a specific language is truly impossible, then it will not be part of the returned map. Likewise, if no ngram probabilities can be found within the detector's languages for the given input text, the returned map will be empty. The confidence value for each language not being part of the returned map is assumed to be 0.0.

        Parameters:
        text - The input text to detect the language for.
      • destroy

        @Deprecated(message = "since 1.2.0, will be removed in 1.3.0", replaceWith = @ReplaceWith(imports = {}, expression = "unloadLanguageModels()")) final Unit destroy()

        Unloads all language models loaded by this LanguageDetector instance and frees associated resources.

        This will be useful if the library is used within a web application inside an application server. By calling this method prior to undeploying the web application, the language models are removed and memory is freed. This prevents exceptions such as OutOfMemoryError when the web application is redeployed multiple times, even though they should not be thrown due to the internal use of ForkJoinPool.commonPool for loading language models in parallel.

      • unloadLanguageModels

         final Unit unloadLanguageModels()

        Unloads all language models loaded by this LanguageDetector instance and frees associated resources.

        This will be useful if the library is used within a web application inside an application server. By calling this method prior to undeploying the web application, the language models are removed and memory is freed. This prevents exceptions such as OutOfMemoryError when the web application is redeployed multiple times, even though they should not be thrown due to the internal use of ForkJoinPool.commonPool for loading language models in parallel.