Skip to main content

Guess the natural language of a text

Project description

Slightly modified guess-language that’s faster.

Attempts to determine the natural language of a selection of Unicode (utf-8) text.

Based on guesslanguage.cpp by Jacob R Rideout for KDE which itself is based on Language::Guess by Maciej Ceglowski.

Detects over 60 languages - all languages listed in the trigrams directory plus Japanese, Chinese, Korean and Greek.

guess_language uses heuristics based on the character set and trigrams in a sample text to detect the language. It works better with longer samples and will be confused if the sample text includes markup such as HTML tags.

Usage

The main entry points all take a single string as input and return a language identifier. The string must be Unicode or UTF-8 text. The language identifer can be the language name in English, the two- or three-letter IANA language code, a language ID or a tuple containing all three codes.

The primary entry points, and the return values, are as follows:

guessLanguage(txt) - IANA language code
guessLanguageTag(txt) - IANA language code (same as guessLanguage)
guessLanguageName(txt) - Language name in English
guessLanguageId(txt) - language ID
guessLanguageInfo(txt) - tuple of (IANA code, id, name)

Note: I (Kent Johnson) am no longer using or maintaining this code. Phi-Long DO maintains a Python 3 version (with support for lib3to2) at https://bitbucket.org/spirit/guess_language. guess_language has also been ported to JavaScript (https://github.com/wooorm/franc) and R (https://github.com/MangoTheCat/franc).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

guess-language-fast-0.2.1.tar.gz (297.9 kB view details)

Uploaded Source

File details

Details for the file guess-language-fast-0.2.1.tar.gz.

File metadata

  • Download URL: guess-language-fast-0.2.1.tar.gz
  • Upload date:
  • Size: 297.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.2

File hashes

Hashes for guess-language-fast-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5dfedb2c32c109ca7fa9f96c4569a20cf4d62fb4c11b8372a96176a966c25212
MD5 6722f80f2928f177cab0b4da99e9651d
BLAKE2b-256 8b9cade814b8bcaad2a0a52f561ae360d3650fa232451cdd9c13d813dcd46555

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page