Git Product home page Git Product logo

pyfranc's Introduction

Pyfranc

Text language detection basic on trigrams. Support 403 language from franc-all

Install

This package is tested in Python 3.8, but should work on the whole 3rd revision of Python.

pip:

pip install pyfranc

Use

How library

from pyfranc import franc

franc.land_detect('Alle menslike wesens word vry')[0][0] # 'afr'
franc.lang_detect('এটি একটি ভাষা একক IBM স্ক্রিপ্ট')[0][0]  # 'ben'
franc.lang_detect('Alle menneske er fødde til fridom')[0][0] # 'nno'
franc.lang_detect('')[0][0] # 'und'

# You can change what’s too short (default: 10):
franc.lang_detect('the')[0][0] # 'und'
franc.lang_detec('the', minlength=3)[0][0] # 'sco'

[0][0] has taken first value (iso code lang) in first element in output array.

whitelist

franc.lang_detect('Considerando ser essencial que os direitos humanos', whitelist = ['por', 'spa'])
# [['por', 1], ['spa', 0.6034146900423971]]

blacklist

franc.lang_detect('Considerando ser essencial que os direitos humanos', blacklist = ['src', 'glg'])

#[['por', 1],
# ['ina', 0.6211756617394293], 
# ['spa', 0.6034146900423971], 
# ['ast', 0.5628509224246592], 
# ['oci', 0.5583820327718574]
# ... 310 more items]

How CLI

CLI to detect the language of text.

usage: pyfranc_cli [-h] --string STRING [--top TOP] [--minlength MINLENGTH]
                   [--whitelist [WHITELIST [WHITELIST ...]]]
                   [--blacklist [BLACKLIST [BLACKLIST ...]]] [--percentage]

optional arguments:
  -h, --help            	show this help message and exit
  -s, --string 		string	Input string.
  -t, --top   		int  	Print top results (Default: 5)).
  -m, --minlength 	int		Minimum string length to accept (Default: 10).
  -w, --whitelist   [WHITELIST [WHITELIST ...]]
							Allow languages.
  -b, --blacklist   [BLACKLIST [BLACKLIST ...]]
							Disallow languages.
  -p, --percentage  bool     	Print relative match value (in percent).

usage:

# output language
$ pyfranc_cli -t1 -s "Alle menslike wesens word vry"
# 'afr' : 1.0

# output language from stdin (expects utf8)
$ echo "এটি একটি ভাষা একক IBM স্ক্রিপ্ট" | pyfranc_cli -t 1 -s $0
# 'ben' : 1.0

# ignore certain languages
$ pyfranc_cli --blacklist por glg "O Brasil caiu 26 posições"
# 'vec' : 1.0

# output language from stdin with only
$ echo "Alle mennesker er født frie og" | pyfranc_cli -t 1 --whitelist nob dan -s $0
# 'nob' : 1.0'

Derivation

Pyfranc is a outright port from Franc (JavaScript, MIT), trigram-utils (JavaScript, MIT), collapse-white-space (JavaScript, MIT), and n-gram (JavaScript, MIT). All this by Titus Wormer.

License

MIT © cyb3rk0tik

pyfranc's People

Contributors

cyb3rk0tik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.