org.apache.commons.codec.language.bm
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.
org/apache/commons/codec/language/bm/lang.txtThe format of these resources is the following:
Modifier and Type | Class and Description |
---|---|
private static class |
Lang.LangRule |
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 |
Modifier | Constructor and Description |
---|---|
private |
Lang(java.util.List<Lang.LangRule> rules,
Languages languages) |
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.
|
private static final java.lang.String LANGUAGE_RULES_RN
private final Languages languages
private final java.util.List<Lang.LangRule> rules
private Lang(java.util.List<Lang.LangRule> rules, Languages languages)
public static Lang instance(NameType nameType)
nameType
- the NameType to look uppublic 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.
languageRulesResourceName
- the fully-qualified resource name to loadlanguages
- the languages that these rules will supportpublic java.lang.String guessLanguage(java.lang.String text)
text
- the wordLanguages.ANY
if there was no unique matchpublic Languages.LanguageSet guessLanguages(java.lang.String input)
input
- the wordcommons-codec version 1.6-SNAPSHOT - Copyright © 2002-2016 - Apache Software Foundation