interlinear 0.0.2__tar.gz → 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: interlinear
3
- Version: 0.0.2
3
+ Version: 0.1.0
4
4
  Summary: Interlinear text handling.
5
5
  Author: John C. G. Sturdy
6
6
  Author-email: "John C. G. Sturdy" <jcg.sturdy@gmail.com>
@@ -7,6 +7,6 @@ name = "interlinear"
7
7
  authors = [{name = "John C. G. Sturdy", email = "jcg.sturdy@gmail.com"}]
8
8
  readme = "README.md"
9
9
  license = "GPL-3.0-or-later"
10
- version = "0.0.2"
10
+ version = "0.1.0"
11
11
  description = "Interlinear text handling."
12
12
  dynamic = ["dependencies"]
@@ -2,10 +2,9 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="interlinear",
5
- version="0.0.2",
5
+ version="0.1.0",
6
6
  description="Interlinear text system",
7
7
  author="John C. G. Sturdy",
8
8
  author_email="jcg.sturdy@gmail.com",
9
- packages=find_packages(),
10
9
  install_requires=['expressionive', 'orgbookchapterverse']
11
10
  )
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import argparse
4
+ import os
5
+ import sys
6
+
7
+ from expressionive.expressionive import htmltags as T
8
+ import expressionive.exprpages as exprpages
9
+ from orgbookchapterverse.orgbookchapterverse import TextCollection, interlinear_chapters
10
+
11
+ def get_args():
12
+ parser = argparse.ArgumentParser()
13
+ parser.add_argument("--book", "-b")
14
+ parser.add_argument("--chapter", "-c")
15
+ parser.add_argument("--verse", "-v")
16
+ parser.add_argument("--language", "-l", action='append')
17
+ parser.add_argument("--output", "-o")
18
+ parser.add_argument("--format", "-f", default="html")
19
+ # parser.add_argument("reference", action='append')
20
+ return vars(parser.parse_args())
21
+
22
+ def emphasize_word(text):
23
+ """Convert markdown-style bolding to expressionive."""
24
+ result = []
25
+ while "**" in text:
26
+ try:
27
+ before, between, after = text.split("**", 2)
28
+ result.append(before)
29
+ result.append(T.span(class_='word')[between])
30
+ text = after
31
+ except:
32
+ # there was an unmatched "**" in the text
33
+ result.append(text)
34
+ return result
35
+ result.append(text)
36
+ return result
37
+
38
+ def spanify_verse(verse):
39
+ """Put span markers into a numbered verse."""
40
+ number, text = verse.strip(' ').split(' ', 1)
41
+ return [T.span(class_='verse_number')[number], T.span(class_='verse_text')[emphasize_word(text)]]
42
+
43
+ def chapter_html(bible, chapter):
44
+ """Return the expressionive structure for a Bible chapter."""
45
+ return T.div(class_="bible_chapter")[[T.p(class_="bible_verse")[spanify_verse(line)]
46
+ for line in bible.chapter(chapter_name_hack(chapter)).lines()
47
+ if line]]
48
+
49
+ def chapters_html(bible, chapters):
50
+ """Return the expressionive structure for a list of Bible chapters."""
51
+ return [[T.h3[chapter], chapter_html(bible, chapter)]
52
+ for chapter in chapters]
53
+
54
+ def interlinear_verse(number, verse):
55
+ return [T.tr[[T.th[str(number)],
56
+ [[T.td[text]
57
+ for text in verse]]
58
+ ]]]
59
+
60
+ def chapter_interlinear_html(versions, chapter):
61
+ """Return the expressionive structure for an interlinear text."""
62
+ try:
63
+ book_name, chapter_number = chapter.rsplit(" ", 1)
64
+ except ValueError:
65
+ print("problem splitting", chapter, "into book name and chapter number")
66
+ return []
67
+ return T.table(class_="interlinear_chapter")[
68
+ [[T.tr[[T.th(class_="verse_number")[str(vnumber)],
69
+ [[T.td(class_=(("verse_text_%d_%d" % (len(versions), colno))
70
+ if len(versions) <= 4
71
+ else "verse_text"))[emphasize_word(text)]
72
+ for colno, text in enumerate(verse)]]
73
+ ]]]
74
+ for vnumber, verse in enumerate(
75
+ interlinear_chapter(versions, book_name, chapter_number),
76
+ start=1)]]
77
+
78
+ def chapters_interlinear_html(versions, chapters, heading=T.h2):
79
+ """Return the expressionive structure for a list of Bible chapters."""
80
+ return [[heading[chapter], chapter_interlinear_html(versions, chapter)]
81
+ for chapter in chapters]
82
+
83
+ # Map language names (in their own languages and in English) to filenames:
84
+ VERSION_FILES = {
85
+ "albanian": "al",
86
+ "deutsch": "de",
87
+ "dutch": "nl",
88
+ "finnish": "fi",
89
+ "français": "fr",
90
+ "french": "fr",
91
+ "german": "de",
92
+ "greek": "gr",
93
+ "hebrew": "he",
94
+ "icelandic": "is",
95
+ "italian": "it",
96
+ "kiswahili": "sw",
97
+ "kjv": "kj",
98
+ "latin": "vg",
99
+ "mongolian": "mn",
100
+ "nederlands": "nl",
101
+ "norsk": "no",
102
+ "norwegian": "no",
103
+ "polish": "pl",
104
+ "polska": "pl",
105
+ "portuguese": "po",
106
+ "português": "po",
107
+ "romanian": "ro",
108
+ "românește": "ro",
109
+ "russian": "ru",
110
+ "shqip": "al",
111
+ "suomi": "fi",
112
+ "svenska": "se",
113
+ "swahili": "sw",
114
+ "swedish": "se",
115
+ "ukrainian": "uk",
116
+ "vulgate": "vg",
117
+ "íslenska": "is",
118
+ "ελληνικά": "gr",
119
+ "русский": "ru",
120
+ "українська": "uk",
121
+ "עִבְרִית": "he",
122
+ "ἑλληνική": "gr",
123
+ }
124
+
125
+ NORMALISED_NAMES = {
126
+ "Psalm": "Psalms",
127
+ }
128
+
129
+ def chapter_range(chapters):
130
+ start, end = chapters.split('-')
131
+ return list(range(int(start), int(end)+1))
132
+
133
+ def chapter_interlinear_html(chapter_contents):
134
+ """Return the expressionive structure for an interlinear text."""
135
+ return T.table(class_="interlinear_chapter")[
136
+ [[T.tr[[T.th(class_="verse_number")[str(vnumber)],
137
+ [[T.td(class_=("verse_text_%d" % colno))[emphasize_word(text)]
138
+ for colno, text in enumerate(verse)]]
139
+ ]]]
140
+ for vnumber, verse in enumerate(
141
+ chapter_contents,
142
+ start=1)]]
143
+
144
+ def chapters_interlinear_html(chapters):
145
+ """Return the expressionive structure for a list of Bible chapters."""
146
+ return [[T.h3[chapter_number], chapter_interlinear_html(chapter_contents)]
147
+ for chapter_number, chapter_contents in chapters]
148
+
149
+ def interlinear_html(data, filename):
150
+ """Output the text as HTML."""
151
+ with open(filename, 'w') if filename else sys.stdout as hstream:
152
+ hstream.write(
153
+ exprpages.page_text(
154
+ T.div(class_='bible')[
155
+ chapters_interlinear_html(data)
156
+ ],
157
+ title="Bible",
158
+ style_text="",
159
+ script_text=""))
160
+
161
+ def interlinear_json(data, filename):
162
+ """Output the text as JSON."""
163
+ with open(filename, 'w') as jstream:
164
+ json.dump(data, jstream)
165
+
166
+ CONVERTERS = {
167
+ 'html': interlinear_html,
168
+ 'json': interlinear_json,
169
+ }
170
+
171
+ def bible_main(book, chapter, verse,
172
+ language,
173
+ output,
174
+ format,
175
+ # reference
176
+ ):
177
+ if format not in CONVERTERS:
178
+ raise ValueError("Format %s not supported" % format)
179
+ if not book:
180
+ raise ValueError("Book must be specified")
181
+ book = NORMALISED_NAMES.get(book, book)
182
+ versions = [
183
+ TextCollection(os.path.expandvars("$BIBLE/%s.org" % VERSION_FILES[version.lower()]), version)
184
+ for version in language
185
+ ]
186
+ chapters = ((chapter_range(chapter)
187
+ if "-" in chapter
188
+ else [int(chapter)])
189
+ if chapter
190
+ else list(range(1, len(versions[0][book])+1)))
191
+ print("chapters are", chapters)
192
+
193
+ texts = interlinear_chapters(versions, book, chapters)
194
+
195
+ CONVERTERS[format](texts, output)
196
+
197
+ if __name__ == "__main__":
198
+ bible_main(**get_args())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: interlinear
3
- Version: 0.0.2
3
+ Version: 0.1.0
4
4
  Summary: Interlinear text handling.
5
5
  Author: John C. G. Sturdy
6
6
  Author-email: "John C. G. Sturdy" <jcg.sturdy@gmail.com>
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ src/interlinear/__init__.py
6
+ src/interlinear/interlinear.py
7
+ src/interlinear.egg-info/PKG-INFO
8
+ src/interlinear.egg-info/SOURCES.txt
9
+ src/interlinear.egg-info/dependency_links.txt
10
+ src/interlinear.egg-info/requires.txt
11
+ src/interlinear.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ interlinear
@@ -1,9 +0,0 @@
1
- LICENSE
2
- README.md
3
- pyproject.toml
4
- setup.py
5
- interlinear.egg-info/PKG-INFO
6
- interlinear.egg-info/SOURCES.txt
7
- interlinear.egg-info/dependency_links.txt
8
- interlinear.egg-info/requires.txt
9
- interlinear.egg-info/top_level.txt
File without changes
File without changes
File without changes