| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
import argparse |
| 22 |
from utils import * |
| 23 |
|
| 24 |
def main(): |
| 25 |
parser = argparse.ArgumentParser(description="Export chunked words in patgen format.") |
| 26 |
parser.add_argument('-d', '--dictionary', required=True, dest="DICTIONARY", |
| 27 |
help="dictionary file") |
| 28 |
parser.add_argument('-t', '--table', required=True, dest="TABLE", |
| 29 |
help="translation table, possibly including hyphenation patterns to be used for showing the good and bad hyphens found") |
| 30 |
args = parser.parse_args() |
| 31 |
conn, c = open_dictionary(args.DICTIONARY) |
| 32 |
c.execute("SELECT text,braille FROM dictionary WHERE braille IS NOT NULL") |
| 33 |
load_table(args.TABLE) |
| 34 |
hyphenation_enabled = liblouis.hyphenationEnabled() |
| 35 |
for text, braille in c.fetchall(): |
| 36 |
|
| 37 |
if len(text) > 48: |
| 38 |
printerrln('WARNING: word is too long to be processed, may be translated incorrectly: %s' % text) |
| 39 |
continue |
| 40 |
if not is_letter(text): |
| 41 |
printerrln('WARNING: word has non-letters: %s' % text) |
| 42 |
continue |
| 43 |
suggested_hyphen_string = suggest_chunks(text, braille) |
| 44 |
if suggested_hyphen_string: |
| 45 |
if hyphenation_enabled: |
| 46 |
actual_hyphen_string = hyphenate(text) |
| 47 |
else: |
| 48 |
actual_hyphen_string = "".join(["0" * (len(text) - 1)]) |
| 49 |
println(my_zip(text, |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
map(lambda e, a: ".0" if e == "x" and a == "1" else |
| 56 |
"0" if e == "x" else |
| 57 |
"*" if e == "1" and a == "1" else |
| 58 |
"-" if e == "1" else |
| 59 |
"." if a == "1" else None, |
| 60 |
suggested_hyphen_string, actual_hyphen_string))) |
| 61 |
conn.close() |
| 62 |
|
| 63 |
if __name__ == "__main__": main() |