forked from jtauber/greek-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.py
executable file
·103 lines (82 loc) · 3.16 KB
/
reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
import argparse
from utils import load_yaml, load_wordset, load_path_attr
from utils import get_morphgnt, parse_verse_ranges
argparser = argparse.ArgumentParser()
argparser.add_argument("verses", help="verses to cover (e.g. 'John 18:1-11')")
argparser.add_argument("--headwords", help="headwords file")
argparser.add_argument("--glosses", help="glosses file")
argparser.add_argument(
"--language", default="eng",
help="language of glosses and other non-Greek text (defaults to eng)")
argparser.add_argument("--exclude", help="exclusion list file")
argparser.add_argument(
"--typeface", default="Times New Roman",
help="typeface to use (defaults to Times New Roman)")
argparser.add_argument(
"--backend", default="backends.LaTeX",
help="python class to use for backend (defaults to backends.LaTeX)")
args = argparser.parse_args()
verses = parse_verse_ranges(args.verses)
if args.exclude:
exclusions = load_wordset(args.exclude)
else:
exclusions = set()
if args.glosses:
glosses = load_yaml(args.glosses)
else:
glosses = None
if args.headwords:
headwords = load_yaml(args.headwords)
else:
headwords = {}
def verb_parse(ccat_parse):
text = ccat_parse[1:4]
if ccat_parse[3] in "DISO":
text += " " + ccat_parse[0] + ccat_parse[5]
elif ccat_parse[3] == "P":
text += " " + ccat_parse[4:7]
return text
def strip_textcrit(word):
return word.replace("⸀", "").replace("⸂", "").replace("⸃", "")
def output_reader(verses, backend, language):
print(backend.preamble(args.typeface, language))
postponed_book = postponed_chapter = None
for entry in get_morphgnt(verses):
if entry[0] == "WORD":
row = entry[1]
lexeme = row["lemma"]
text = strip_textcrit(row["text"])
if lexeme not in exclusions:
pos = row["ccat-pos"]
headword = headwords.get(lexeme, lexeme)
if glosses:
gloss = glosses[lexeme].get(
row["bcv"], glosses[lexeme]["default"])
else:
gloss = None
if pos in ["V-"]:
parse = verb_parse(row["ccat-parse"])
else:
parse = None
print(backend.word(text, headword, parse, gloss, language))
else:
print(backend.word(text))
elif entry[0] == "VERSE_START":
if postponed_book:
print(backend.book_chapter_verse(
postponed_book, postponed_chapter, entry[1]))
postponed_book = postponed_chapter = None
elif postponed_chapter:
print(backend.chapter_verse(postponed_chapter, entry[1]))
postponed_chapter = None
else:
print(backend.verse(entry[1]))
elif entry[0] == "CHAPTER_START":
postponed_chapter = entry[1]
elif entry[0] == "BOOK_START":
postponed_book = entry[1]
else:
print(backend.comment(entry))
print(backend.postamble())
output_reader(verses, load_path_attr(args.backend)(), args.language)