[liblouis-liblouisxml] Re: Provide example?

  • From: Michael Whapples <mwhapples@xxxxxxx>
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Thu, 02 Jul 2009 15:26:13 +0100

Hello,
I have to say for examples of using liblouis from C then the programs included with liblouis are probably good examples. Also if you want to look through it then liblouisxml is another good one (this is how I worked out how to use the lou_hyphenate function for creating my java bindings).

As for using it from python, the doc strings give good details, there doesn't seem to be any big surprises when I tried it. However may be a document listing some examples might be good, as the examples could be reused as doctests. Anyway here are some examples from my quick look at it. These examples should work in doctest.

>>> import louis

Show a US grade2 translation of a unicode string with no typeform information

>>> louis.translateString(['en-us-g2.ctb'], u'Hello world', None, 0)
u',hello _w'

Now do a translation using bold for the string

>>> louis.translateString(['en-us-g2.ctb'], u'Hello world', [louis.bold]*11, 0)
u',hello __w'

There seems to be a bug there that bold indicator is not added to Hello.

Now do a translation using cursor position.

>>> louis.translate(['en-us-g2.ctb'], u'Hello world', None, 5, 0)
(u',hello _w', [0, 0, 1, 2, 3, 4, 5, 6, 6], [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7], 6)

See the doc string for louis.translate (IE. louis.translate.__doc__) for details on each element of the returned tuple.

As lou_free is called automatically on exit for us we don't need to do that ourselves.

The python bindings don't support back translation so I can't give examples for that.

Hope these have been useful.

Michael Whapples
On 02/07/09 14:31, John J. Boyer wrote:
Samuel,

I'm not sure I understand what is wanted. However, for liblouis one can
find examples in lou_allround.c by searching for the string lou_

John

On Thu, Jul 02, 2009 at 01:29:53PM +0200, Samuel Thibault wrote:
Hello,

A debian user requested some examples on how to use python-louis or
liblouis.

Samuel
For a description of the software and to download it go to
http://www.jjb-software.com

For a description of the software and to download it go to
http://www.jjb-software.com

Other related posts: