Class LanguageCodeValidator
java.lang.Object
opennlp.tools.util.LanguageCodeValidator
Validates language codes against ISO 639 standards.
Accepts:
- ISO 639-1 two-letter language codes
(e.g.,
"en","de") - ISO 639-2/3 three-letter language codes
(e.g.,
"eng","deu") - The special code
"x-unspecified"used internally by OpenNLP
Valid codes are derived from Locale.availableLocales()
plus additional ISO 639-2 bibliographic codes and
"und" (undetermined).
Also converts between ISO 639-1 two-letter codes and ISO 639-2/3
three-letter codes, see toIso6391(String) and
toIso6393(String).
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks whether the given language code is a valid ISO 639 code.static StringConverts a three-letter ISO 639-2/3 code, terminologic ("nld") or bibliographic ("dut"), to its ISO 639-1 two-letter equivalent ("nl").static StringConverts an ISO 639-1 two-letter code ("de") or an ISO 639-2 bibliographic code ("ger") to its ISO 639-2/3 three-letter equivalent ("deu").static voidvalidateLanguageCode(String languageCode) Validates the given language code and throws anIllegalArgumentExceptionif it is not a recognized ISO 639 language code.
-
Method Details
-
isValid
Checks whether the given language code is a valid ISO 639 code.- Parameters:
languageCode- The language code to check. Must not benull.- Returns:
trueif the code is valid,falseotherwise.- Throws:
IllegalArgumentException- Thrown iflanguageCodeisnull.
-
validateLanguageCode
Validates the given language code and throws anIllegalArgumentExceptionif it is not a recognized ISO 639 language code.- Parameters:
languageCode- The language code to validate. Must not benull.- Throws:
IllegalArgumentException- Thrown if the code is not a valid ISO 639 language code or isnull.
-
toIso6391
Converts a three-letter ISO 639-2/3 code, terminologic ("nld") or bibliographic ("dut"), to its ISO 639-1 two-letter equivalent ("nl"). The code is lower-cased withStringUtil.toLowerCase(CharSequence)first. Two-letter codes and codes without a two-letter equivalent are returned lower-cased and otherwise unchanged. The code is not validated; usevalidateLanguageCode(String)for that.- Parameters:
languageCode- The language code to convert. Must not benull.- Returns:
- The ISO 639-1 code, or the lower-cased input if there is none.
- Throws:
IllegalArgumentException- Thrown iflanguageCodeisnull.
-
toIso6393
Converts an ISO 639-1 two-letter code ("de") or an ISO 639-2 bibliographic code ("ger") to its ISO 639-2/3 three-letter equivalent ("deu"). The code is lower-cased withStringUtil.toLowerCase(CharSequence)first. Other codes, and two-letter codes without a three-letter equivalent, are returned lower-cased and otherwise unchanged. The code is not validated; usevalidateLanguageCode(String)for that.- Parameters:
languageCode- The language code to convert. Must not benull.- Returns:
- The ISO 639-2/3 code, or the lower-cased input if there is none.
- Throws:
IllegalArgumentException- Thrown iflanguageCodeisnull.
-