Python bindings around Google Chromium's embedded compact language detection library (CLD2)
pip install pycld2PYCLD2 - Python Bindings to CLD2
Python bindings for the Compact Langauge Detect 2 (CLD2).
This package contains forks of:
- The
cld2C++ library, developed by Dick Sites - The
chromium-compact-language-detectorC++ extension module, originally created by Mike McCandless, which has been modified post-fork. These bindings, among other changes, make the support of over 165 languages the default.
The goal of this project is to consolidate the upstream library with its bindings, so the user can pip install one package instead of two.
The LICENSE is the same as Chromium's LICENSE and is included in the LICENSE file for reference.
Installing
$ python -m pip install -U pycld2
Example
import pycld2 as cld2
isReliable, textBytesFound, details = cld2.detect(
"а неправильный формат идентификатора дн назад"
)
print(isReliable)
# True
details[0]
# ('RUSSIAN', 'ru', 98, 404.0)
fr_en_Latn = """\
France is the largest country in Western Europe and the third-largest in Europe as a whole.
A accès aux chiens et aux frontaux qui lui ont été il peut consulter et modifier ses collections
et exporter Cet article concerne le pays européen aujourd’hui appelé République française.
Pour d’autres usages du nom France, Pour une aide rapide et effective, veuiller trouver votre aide
dans le menu ci-dessus.
Motoring events began soon after the construction of the first successful gasoline-fueled automobiles.
The quick brown fox jumped over the lazy dog."""
isReliable, textBytesFound, details, vectors = cld2.detect(
fr_en_Latn, returnVectors=True
)
print(vectors)
# ((0, 94, 'ENGLISH', 'en'), (94, 329, 'FRENCH', 'fr'), (423, 139, 'ENGLISH', 'en'))
