GithubHelp home page GithubHelp logo

chahank / str2bool Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kmonsoor/str2bool

0.0 0.0 0.0 17 KB

A Python helper function to convert a string to boolean i.e. [True, False], by guessing the approximate meaning of the input string

Python 100.00%

str2bool's Introduction

Build Status License

str2bool : String to Boolean conversion

a simple multi-lingual utility function to convert a string to boolean i.e. True, False, by guessing the approximate meaning of the input string. By default, it will return False. Return True ONLY if input is certainly a 'true'-ish word e.g. 'Positive', 'yeah' etc.

Maybe, someday it will be able to detect "boolean"-lity of large sentences. But, now it can sense only single AND basic words in many languages.

Currently supported languages:

  • English
  • Bengali
  • Dutch
  • Polish
  • Arabic
  • Chinese
  • Korean
  • Spanish
  • Ukrainian And, some more ...

Please consider adding your language-specific "yes"|"True"-ish words. See Contribution section below.

Installation

pip install git+git://github.com/kmonsoor/str2bool.git

Example usage

>>> import str2bool as s2b
>>> print(s2b.supported_languages)
['EN', 'BN', 'AR', 'NL', 'ES', 'KO', 'JA', 'ZH', 'TL', 'VI']
>>> s2b.string_to_boolean('True')
True
>>> s2b.string_to_boolean('0')
False
>>> s2b.string_to_boolean('Tak')  # polish
True
>>> s2b.string_to_boolean('না')   # bengali "no"
False
>>> s2b.string_to_boolean('joe is a good boy')
Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pycharm\docrunner.py", line 135, in __run
   compileflags, 1), test.globs)
  File "<doctest str2bool[6]>", line 1, in <module>
   s2b.string_to_boolean('joe is a good boy')
  File "C:/Users/k/PycharmProjects/str2bool/str2bool.py", line 51, in string_to_boolean
   raise ValueError('Only single words are supported in this alpha-version utility function.')
ValueError: Only single words are supported in this alpha-version utility function.

Contribution

  • To word new list in the "True-ish" checklist, please:

    1. Append the "yes"|"True"-ish word(s) at the end of the truish_words list,
    2. update supported_languages list, and
    3. create a pull-request.
  • Please add your suggestion, feature-request, constructive criticism, bug as issue on this GitHub repo

  • Even your generic observation, word-of-wisdom, inspiration, or just "Thanks, buddy" is highly welcome. Please send them to my email: k (at) kmonsoor (dot) com

  • Also, I would love to know any use-case where this tiny library is helping. :)

License

str2bool is released as open-source software under the MIT License (MIT).

str2bool's People

Contributors

kmonsoor avatar klivan avatar mchlnix avatar iqiexie avatar roy-cohen273 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.