Debian Codegraph @

tools/lou_maketable.d/export_chunked_words.py

raw symbols SCIP
1 # liblouis Braille Translation and Back-Translation Library
2 #
3 # Copyright (C) 2017 Bert Frees
4 #
5 # This file is part of liblouis.
6 #
7 # liblouis is free software: you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published
9 # by the Free Software Foundation, either version 2.1 of the License, or
10 # (at your option) any later version.
11 #
12 # liblouis is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with liblouis. If not, see <http://www.gnu.org/licenses/>.
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 # ignore long words for now
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 # * = correct hyphen
51 # - = missed hyphen
52 # . = bad hyphen
53 # .0 = optional hyphen present
54 # 0 = optional hyphen not present
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()