Lang (Encode/Decode Utilities (Version 1.10))
Date: 2019-08-31

org.apache.commons.codec.language.bm

## Class Lang

- java.lang.Object
- - org.apache.commons.codec.language.bm.Lang

-     public class Lang
      extends java.lang.Object

  Language guessing utility.

  This class encapsulates rules used to guess the possible languages that a word originates from. This is done by reference to a whole series of rules distributed in resource files.

  Instances of this class are typically managed through the static factory method instance(). Unless you are developing your own language guessing rules, you will not need to interact with this class directly.

  This class is intended to be immutable and thread-safe.

  Lang resources

  Language guessing rules are typically loaded from resource files. These are UTF-8 encoded text files. They are systematically named following the pattern:

  > org/apache/commons/codec/language/bm/lang.txt

  The format of these resources is the following:
  - Rules: whitespace separated strings. There should be 3 columns to each row, and these will be interpreted as:
    1. pattern: a regular expression.
    2. languages: a '+'-separated list of languages.
    3. acceptOnMatch: 'true' or 'false' indicating if a match rules in or rules out the language.
  - End-of-line comments: Any occurrence of '//' will cause all text following on that line to be discarded as a comment.
  - Multi-line comments: Any line starting with '/*' will start multi-line commenting mode. This will skip all content until a line ending in '*' and '/' is found.
  - Blank lines: All blank lines will be skipped.

  Port of lang.php

  Since:
    1.6
  Version:
    $Id: Lang.java 1608115 2014-07-05 19:58:38Z tn $

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `private static class` | `Lang.LangRule`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static java.util.Map<NameType,Lang>` | `Langs`
    `private static java.lang.String` | `LANGUAGE_RULES_RN`
    `private Languages` | `languages`
    `private java.util.List<Lang.LangRule>` | `rules`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `private` | `Lang(java.util.List<Lang.LangRule> rules, Languages languages)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `guessLanguage(java.lang.String text)` Guesses the language of a word.
    `Languages.LanguageSet` | `guessLanguages(java.lang.String input)` Guesses the languages of a word.
    `static Lang` | `instance(NameType nameType)` Gets a Lang instance for one of the supported NameTypes.
    `static Lang` | `loadFromResource(java.lang.String languageRulesResourceName, Languages languages)` Loads language rules from a resource.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### Langs

          private static final java.util.Map<NameType,Lang> Langs

    - #### LANGUAGE_RULES_RN

          private static final java.lang.String LANGUAGE_RULES_RN

      See Also:
        Constant Field Values

    - #### languages

          private final Languages languages

    - #### rules

          private final java.util.List<Lang.LangRule> rules

  - ### Constructor Detail

    - #### Lang

          private Lang(java.util.List<Lang.LangRule> rules,
                       Languages languages)

  - ### Method Detail

    - #### instance

          public static Lang instance(NameType nameType)

      Gets a Lang instance for one of the supported NameTypes.
      Parameters:
        `nameType` - the NameType to look up
      Returns:
        a Lang encapsulating the language guessing rules for that name type

    - #### loadFromResource

          public static Lang loadFromResource(java.lang.String languageRulesResourceName,
                                              Languages languages)

      Loads language rules from a resource.

      In normal use, you will obtain instances of Lang through the `instance(NameType)` method. You will only need to call this yourself if you are developing custom language mapping rules.

      Parameters:
        `languageRulesResourceName` - the fully-qualified resource name to load
        `languages` - the languages that these rules will support
      Returns:
        a Lang encapsulating the loaded language-guessing rules.

    - #### guessLanguage

          public java.lang.String guessLanguage(java.lang.String text)

      Guesses the language of a word.
      Parameters:
        `text` - the word
      Returns:
        the language that the word originates from or `Languages.ANY` if there was no unique match

    - #### guessLanguages

          public Languages.LanguageSet guessLanguages(java.lang.String input)

      Guesses the languages of a word.
      Parameters:
        `input` - the word
      Returns:
        a Set of Strings of language names that are potential matches for the input word

commons-codec version 1.10 - Copyright © 2002-2019 - Apache Software Foundation