Coder Social home page Coder Social logo

python-bidi's Introduction

Python BiDi

image

image

Bi-directional (BiDi) layout implementation in pure python

Package documentation

API

The algorithm starts with a single entry point bidi.algorithm.get_display.

Required arguments:

  • unicode_or_str: The original unicode or string (i.e.: storage). If it's a string use the optional argument encoding to specify it's encoding.

Optional arguments:

  • encoding: If unicode_or_str is a string, specifies the encoding. The algorithm uses unicodedata which requires unicode. This encoding will be used to decode and encode back to string before returning (default: "utf-8").
  • upper_is_rtl: True to treat upper case chars as strong 'R' for debugging (default: False).
  • base_dir: 'L' or 'R', override the calculated base_level.
  • debug: True to display (using sys.stderr) the steps taken with the algorithm (default: False).

Returns the display layout, either as unicode or encoding encoded string (depending on the type of unicode_or_str').

Example:

>>> from bidi.algorithm import get_display
>>> get_display(u'car is THE CAR in arabic', upper_is_rtl=True)
u'car is RAC EHT in arabic'

CLI

pybidi is a command line utility (calling bidi.main) for running the bidi algorithm. the script can get a string as a parameter or read text from stdin. Usage:

$ pybidi -h
Usage: pybidi [options]

Options:
  -h, --help            show this help message and exit
  -e ENCODING, --encoding=ENCODING
                        Text encoding (default: utf-8)
  -u, --upper-is-rtl    treat upper case chars as strong 'R' for debugging
                        (default: False).
  -d, --debug           Output to stderr steps taken with the algorithm
  -b BASE_DIR, --base-dir=BASE_DIR
                        Override base direction [L|R]

Examples:

$ pybidi -u 'car is THE CAR in arabic'
car is RAC EHT in arabic

$ cat ~/Documents/example.txt | pybidi
...

Installation

See docs/INSTALL.rst

Running tests

To run the tests:

python setup.py test

Some explicit tests are failing right now (see TODO)

python-bidi's People

Contributors

meirkriheli avatar justvanrossum avatar jwilk avatar

Watchers

James Cloos 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.