CFFI bindings around Google Chromium's embedded compact language detection library (CLD2)
CFFI bindings for CLD2
This package contains the CLD (Compact Language Detection) library as maintained by Dick Sites (https://code.google.com/p/cld2/). The first fork was done at revision r161. It also contains python bindings that were originally created by Mike McCandless. The bindings have gone through several hands, with the latest changes being made to rework the bindings for CFFI.
These bindings are identical in API to the original cld2 bindings, and as a result can be used as a drop in replacement.
Should be as simple as
$ pip install cld2-cffi
The latest development version can be installed directly from GitHub:
$ pip install --upgrade 'git+https://github.com/GregBowyer/cld2-cffi.git'
import cld2 isReliable, textBytesFound, details = cld2.detect("This is my sample text") print(' reliable: %s' % (isReliable != 0)) print(' textBytes: %s' % textBytesFound) print(' details: %s' % str(details)) # The output looks like so: # reliable: True # textBytes: 24 # details: (('ENGLISH', 'en', 95, 1736.0), ('Unknown', 'un', 0, 0.0), ('Unknown', 'un', 0, 0.0))
First, you must get your content (plain text or HTML) encoded into UTF8 bytes. Then, detect like this:
isReliable, textBytesFound, details = cld2.detect(bytes)
The module exports these global constants:
Please see BUG_REPORTS.
Please see CONTRIBUTING.
Please see LICENSE.