[liblouis-liblouisxml] Re: [EXTERNAL] Re: Here's the Python formatter

  • From: James Bowden <James.Bowden@xxxxxxxxxxx>
  • To: "liblouis-liblouisxml@xxxxxxxxxxxxx" <liblouis-liblouisxml@xxxxxxxxxxxxx>
  • Date: Thu, 17 Dec 2020 12:18:19 +0000

Hi John,

Many thanks for your python file.

A couple of points of interest:

1. Our email system stripped the "potentially unsafe" attachment type of .PY 
files.
I don't know if anyone else also had similar problems? Perhaps you could rename 
as .txt to avoid this?

2. I wonder if two spaces should be prepended to the translated line to show 
ordinary braille paragraphs?
Of course, this assumes everything is ordinary text ... a more complex system 
is needed to manage headings etc.

3. Now showing my ignorance of Python: do you know if
next(inputFile, None)
copes with different input encodings, or will it return the raw byte stream 
direct from the file?

I trust this helps.

With best regards,

James.

From: liblouis-liblouisxml-bounce@xxxxxxxxxxxxx 
<liblouis-liblouisxml-bounce@xxxxxxxxxxxxx> On Behalf Of John J. Boyer
Sent: 17 December 2020 08:37
To: liblouis-liblouisxml@xxxxxxxxxxxxx
Subject: [EXTERNAL] [liblouis-liblouisxml] Re: Here's the Python formatter

CAUTION: External. Do not click links or open attachments unless you know the 
content is safe.
________________________________
Hello Michael,

Thanks for the clarification on freing the liblouis table. I'm pasting the 
program directly into this mesage. so it is easier to read.
Maybe some server didn't like the filename of the attachment. Let's see what 
happens this time.

""" This program, lou_transtext.py, takes an input file, translates it with 
liblouis according to the tablelist variable
and formats it with a line length given in the lineLength variable. It asks for 
the names of the input file and the output file.
As provided, tableList is ["en-ueb-g2.ctb] Note that it is a Python list.
lineLength is currently set to 38. You can set tableList and lineLength 
according to your preferences.
"""

tableList = ["en-ueb-g2.ctb"]
lineLength = 38
import louis
import textwrap
fileIn = input ("Please enter the input file name: ")
fileOut = input ("Please enter the output file name: ")
inputFile = open (fileIn, "rt")
outputFile = open (fileOut, "wt", newline='\r\n')
while True:
line = next(inputFile, None)
if line is None:
break
line2 = line.strip()
if line2 == "":
continue
translation = louis.translateString (tableList, line2, 0, 0)
outputFile.write (textwrap.fill (translation, lineLength))
outputFile.write("\n")
inputFile.close()
outputFile.close()
print ("Done.")

On Thu, Dec 17, 2020 at 07:22:01AM +0000, Michael Whapples wrote:

Hello,

Regarding how the table memory gets freed, this is automatically done by the
bindings when Python exits. The bindings use the atexit module of Python to
register the lou_free function to be called on exit.


Thanks to the Python approach of treating developers as adults, it is
possible to call the lou_free function yourself:

import louis

louis.liblouis.lou_free()


I would recommend against doing that though. As said lou_free is called
automatically on exit. If you need to free the table memory at some other
point I guess you could use the above, although using the liblouis object is
probably seen as dealing with implementation details rather than the API. It
might be preferrable to request the addition of a function in the bindings
API to avoid this direct accessing of implementation details.


Michael Whapples

On 17/12/2020 00:52, John J. Boyer wrote:
Hello Everyone

The Python formatter that I mentioned a few weeks ago is attached. It has a 
doc string that explains its usage.
One thing I'm wondering about is what happens to the memory used by the 
liblouis table when the program ends. I don't see how to clear it.

John

For a description of the software, to download it and links to
project pages go to http://liblouis.org<http://liblouis.org>
Donate: http://liblouis.org/sponsoring<http://liblouis.org/sponsoring>

--
John J. Boyer
Email: john.boyer@xxxxxxxxxxxxxxxxx
website: http://www.abilitiessoft.org<http://www.abilitiessoft.org>
Status: Company dissolved but website and email addresses live.
Location: Madison, Wisconsin, USA
Mission: developing assistive technology software and providing STEM services
that are available at no cost


For a description of the software, to download it and links to
project pages go to http://liblouis.org<http://liblouis.org>
Donate: http://liblouis.org/sponsoring<http://liblouis.org/sponsoring>


--

Give a life-changing gift this Christmas. RNIB Virtual Charity Gifts make more 
meaningful presents, while making good things happen for blind and partially 
sighted people in the UK. Browse RNIB Virtual Charity Gifts at 
https://www.rnib.org.uk/virtual-gifts and receive an e-greeting card to keep ;
yourself or send directly to your chosen recipient.

--


DISCLAIMER:

NOTICE: The information contained in this email and any attachments is 
confidential and may be privileged.  If you are not the intended recipient you 
should not use, disclose, distribute or copy any of the content of it or of any 
attachment; you are requested to notify the sender immediately of your receipt 
of the email and then to delete it and any attachments from your system.

RNIB endeavours to ensure that emails and any attachments generated by its 
staff are free from viruses or other contaminants.  However, it cannot accept 
any responsibility for any  such which are transmitted.

We therefore recommend you scan all attachments.

Please note that the statements and views expressed in this email and any 
attachments are those of the author and do not necessarily represent those of 
RNIB.

RNIB Registered Charity Number: 226227

Website: https://www.rnib.org.uk

Other related posts:

  • » [liblouis-liblouisxml] Re: [EXTERNAL] Re: Here's the Python formatter - James Bowden