Document utilities
This commit is contained in:
parent
2b378114aa
commit
00568ca6d3
21 changed files with 371 additions and 29 deletions
|
|
@ -5,6 +5,23 @@ from langdetect import LangDetectException, detect
|
|||
|
||||
|
||||
def predict_language(text: Optional[str]) -> str:
|
||||
"""Predict the language code from text.
|
||||
|
||||
A thin wrapper over [langcodes](https://github.com/rspeer/langcodes) for convenient
|
||||
language tagging.
|
||||
|
||||
Examples:
|
||||
>>> predict_language('This is a sentence.')
|
||||
'en'
|
||||
|
||||
Args:
|
||||
text: Text used for prediction.
|
||||
|
||||
Returns:
|
||||
The predicted language code (en, en-US) or `und` if a prediction could not be
|
||||
made.
|
||||
"""
|
||||
|
||||
if not text:
|
||||
return Language.make().to_tag()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue