forked from adyeths/u2o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
u2o.py
2515 lines (2216 loc) · 99.7 KB
/
u2o.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
# -*- coding: utf8 -*-
r'''
Convert usfm bibles to osis
Notes:
* better handling of osisID's is probably needed.
* no attempt has been made to process any \z tags in this script.
* I can think of scenarios where this script may not work properly. However,
it works fine for all of the usfm bibles that I have access to at this
time.
* xop and sd# need better handling. There may be better ways to handle
lh and lf... need to investigate this.
* Some new USFM 3.0 tags are not implemented yet... as well as new forms
for some other tags...
jmp...jmp*, qt*-s\* ... qt#-e\*
w...w*, fig...fig*, periph
* table cell column spanning are not implemented
Alternative Book Ordering:
To have the books output in an order different from the built in canonical
book order you will have to create a simple text file.
FIRST, put the OSIS ID's for the books in the order you want, one per line,
in a plain text file. Example:
Gen
Exod
Lev
...
Rev
SECOND, name the file as follows: order-SomeOrderYouWant.txt
THIRD, place that file in the directory where you will be running
the script. This new book order will be automatically detected and
available.
Examples can be provided. Simple send me an email and ask me for them.
NOTE: I should probably change this so that there's a more central
location for these alternative book orderings.
This script has been tested and is known to work with CPython 3.4.0,
CPython 2.7.6, jython 2.7.0, pypy 2.5.0, and pypy3 2.4.0.
Neither jython nor pypy are recomended as they are quite a bit slower at
running this script than CPython.
This script is public domain. You may do whatever you want with it.
'''
#
# uFDD0 - used to mark line breaks during processing
# uFDD1 - used to preserve line breaks during wj processing
#
# uFDE0 - used to mark the start of introductions
# uFDE1 - used to mark the end of introductions
#
from __future__ import print_function, unicode_literals
import sys
import argparse
import os.path
import glob
import re
import codecs
import unicodedata
from contextlib import closing
# try to import multiprocessing
# (jython 2.7.0 doesn't have this module.)
HAVEMULTIPROCESSING = False
try:
import multiprocessing
HAVEMULTIPROCESSING = True
except ImportError:
pass
# try to import lxml so that we can validate
# our output against the OSIS schema.
HAVELXML = False
try:
import lxml.etree as et
HAVELXML = True
except ImportError:
pass
# try to import the Sword lib so that we can
# create proper osis references
HAVESWORD = False
try:
import Sword
HAVESWORD = True
except ImportError:
pass
# -------------------------------------------------------------------------- #
META = {
'USFM': '3.0', # Targeted USFM version
'OSIS': '2.1.1', # Targeted OSIS version
'VERSION': '0.6b', # THIS SCRIPT version
'DATE': '2017-01-10' # THIS SCRIPT revision date
}
# -------------------------------------------------------------------------- #
OSISHEADER = '''<?xml version="1.0" encoding="utf-8"?>
<osis xmlns="http://www.bibletechnologies.net/2003/OSIS/namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bibletechnologies.net/2003/OSIS/namespace
http://www.bibletechnologies.net/osisCore.2.1.1.xsd">
<osisText osisIDWork="{}" osisRefWork="Bible" xml:lang="{}">
<header>
<work osisWork="{}">
<title>{}</title>
{}
<type type="OSIS">Bible</type>
<identifier type="OSIS">Bible.{}.{}</identifier>
<refSystem>Bible</refSystem>
</work>
</header>\n'''
OSISFOOTER = '''
</osisText>
</osis>\n'''
# -------------------------------------------------------------------------- #
CANONICALORDER = [
# Canonical order used by the usfm2osis.py script...
# minus the extra books that aren't part of usfm at this time.
'FRONT', 'INTRODUCTION',
'Gen', 'Exod', 'Lev', 'Num', 'Deut', 'Josh', 'Judg', 'Ruth', '1Sam',
'2Sam', '1Kgs', '2Kgs', '1Chr', '2Chr', 'PrMan', 'Jub', '1En', 'Ezra',
'Neh', 'Tob', 'Jdt', 'Esth', 'EsthGr', '1Meq', '2Meq', '3Meq', 'Job',
'Ps', 'AddPs', '5ApocSyrPss', 'Odes', 'Prov', 'Reproof', 'Eccl', 'Song',
'Wis', 'Sir', 'PssSol', 'Isa', 'Jer', 'Lam', 'Bar', 'EpJer', '2Bar',
'EpBar', '4Bar', 'Ezek', 'Dan', 'DanGr', 'PrAzar', 'Sus', 'Bel', 'Hos',
'Joel', 'Amos', 'Obad', 'Jonah', 'Mic', 'Nah', 'Hab', 'Zeph', 'Hag',
'Zech', 'Mal',
'1Esd', '2Esd', '4Ezra', '5Ezra', '6Ezra', '1Macc', '2Macc', '3Macc',
'4Macc',
'Matt', 'Mark', 'Luke', 'John', 'Acts', 'Rom', '1Cor', '2Cor', 'Gal',
'Eph', 'Phil', 'Col', '1Thess', '2Thess', '1Tim', '2Tim', 'Titus', 'Phlm',
'Heb', 'Jas', '1Pet', '2Pet', '1John', '2John', '3John', 'Jude', 'Rev',
'EpLao',
'XXA', 'XXB', 'XXC', 'XXD', 'XXE', 'XXF', 'XXG',
'BACK', 'CONCORDANCE', 'GLOSSARY', 'INDEX', 'GAZETTEER',
'X-OTHER'
]
# get list of book orders available from external files in the current
# working directory. Each order file has the following naming pattern:
# order-SOMEORDER.txt
BOOKORDERS = sorted([_.replace('order-', '').replace('.txt', '') for _ in
glob.glob('order-*.txt')])
BOOKORDERS.append('none')
BOOKORDERS.insert(0, 'canonical')
# -------------------------------------------------------------------------- #
# convert usfm book names
BOOKNAMES = {
# old testament books
'GEN': 'Gen', 'EXO': 'Exod', 'LEV': 'Lev', 'NUM': 'Num',
'DEU': 'Deut', 'JOS': 'Josh', 'JDG': 'Judg', 'RUT': 'Ruth',
'1SA': '1Sam', '2SA': '2Sam', '1KI': '1Kgs', '2KI': '2Kgs',
'1CH': '1Chr', '2CH': '2Chr', 'EZR': 'Ezra', 'NEH': 'Neh',
'EST': 'Esth', 'JOB': 'Job', 'PSA': 'Ps', 'PRO': 'Prov',
'ECC': 'Eccl', 'SNG': 'Song', 'ISA': 'Isa', 'JER': 'Jer',
'LAM': 'Lam', 'EZK': 'Ezek', 'DAN': 'Dan', 'HOS': 'Hos',
'JOL': 'Joel', 'AMO': 'Amos', 'OBA': 'Obad', 'JON': 'Jonah',
'MIC': 'Mic', 'NAM': 'Nah', 'HAB': 'Hab', 'ZEP': 'Zeph',
'HAG': 'Hag', 'ZEC': 'Zech', 'MAL': 'Mal',
# new testament books
'MAT': 'Matt', 'MRK': 'Mark', 'LUK': 'Luke', 'JHN': 'John',
'ACT': 'Acts', 'ROM': 'Rom', '1CO': '1Cor', '2CO': '2Cor',
'GAL': 'Gal', 'EPH': 'Eph', 'PHP': 'Phil', 'COL': 'Col',
'1TH': '1Thess', '2TH': '2Thess', '1TI': '1Tim', '2TI': '2Tim',
'TIT': 'Titus', 'PHM': 'Phlm', 'HEB': 'Heb', 'JAS': 'Jas',
'1PE': '1Pet', '2PE': '2Pet', '1JN': '1John', '2JN': '2John',
'3JN': '3John', 'JUD': 'Jude', 'REV': 'Rev',
# other books
'TOB': 'Tob', 'JDT': 'Jdt', 'ESG': 'EsthGr', 'WIS': 'Wis',
'SIR': 'Sir', 'BAR': 'Bar', 'LJE': 'EpJer', 'S3Y': 'PrAzar',
'SUS': 'Sus', 'BEL': 'Bel', '1MA': '1Macc', '2MA': '2Macc',
'3MA': '3Macc', '4MA': '4Macc', '1ES': '1Esd', '2ES': '2Esd',
'MAN': 'PrMan', 'PS2': 'AddPs', 'ODA': 'Odes', 'PSS': 'PssSol',
'EZA': '4Ezra', '5EZ': '5Ezra', '6EZ': '6Ezra', 'DAG': 'DanGr',
'PS3': '5ApocSyrPss',
'2BA': '2Bar', 'LBA': 'EpBar', 'JUB': 'Jub', 'ENO': '1En',
'1MQ': '1Meq', '2MQ': '2Meq', '3MQ': '3Meq',
'REP': 'Reproof', '4BA': '4Bar', 'LAO': 'EpLao',
# private use
'XXA': 'XXA', 'XXB': 'XXB', 'XXC': 'XXC', 'XXD': 'XXD',
'XXE': 'XXE', 'XXF': 'XXF', 'XXG': 'XXG',
# Peripheral books
'FRT': 'FRONT', 'INT': 'INTRODUCTION',
'BAK': 'BACK', 'CNC': 'CONCORDANCE',
'GLO': 'GLOSSARY', 'TDX': 'INDEX',
'NDX': 'GAZETTEER', 'OTH': 'X-OTHER'
}
# -------------------------------------------------------------------------- #
# TAG MAPPINGS
# identification tags
IDTAGS = {
r'\sts': ('<milestone type="x-usfm-sts" n="', '" />'),
r'\toc1': ('<milestone type="x-usfm-toc1" n="', '" />'),
r'\toc2': ('<milestone type="x-usfm-toc2" n="', '" />'),
r'\toc3': ('<milestone type="x-usfm-toc3" n="', '" />'),
# ebible.org bibles sometimes use a ztoc4 tag. If it's desired to process
# this tag then simply uncomment the ztoc4 line here.
# (No other ztags are even attempted in this converter.)
# r'\ztoc4': ('<milestone type=x-usfm-ztoc4 n="', '" />'),
r'\restore': ('<!-- restore - ', ' -->'),
# the osis 2.1.1 user manual says the value of h h1 h2 and h3 tags should
# be in the short attribute of a title.
# ************************************************************************
# NOTE: These types of titles seem to be problematic when trying to import
# bibles for The SWORD Project. So alternative conversions have been
# implemented to work around the issue.
# ************************************************************************
# r'\h': ('<title type="runningHead" short="', '" />'),
# r'\h1': ('<title type="runningHead" n="1" short="', '" />'),
# r'\h2': ('<title type="runningHead" n="2" short="', '" />'),
# r'\h3': ('<title type="runningHead" n="3" short="', '" />')
# ************************************************************************
r'\h': ('<milestone type="x-usfm-h" n="', '" />'),
r'\h1': ('<milestone type="x-usfm-h1" n="', '" />'),
r'\h2': ('<milestone type="x-usfm-h2" n="', '" />'),
r'\h3': ('<milestone type="x-usfm-h3" n="', '" />')
}
# the osis 2.1.1 user manual says the value of id, ide, and rem should be
# placed in description tags in the header. That's why they are in a separate
# list instead of the dict above.
IDTAGS2 = [r'\id', r'\ide', r'\rem']
# title tags
TITLETAGS = {
# ---------------------------------------------------------
# ##### SECTION TAGS get special handling elsewhere ##### #
r'\is': ('<title type="x-introduction">', '</title>'),
r'\is1': ('<title type="x-introduction">', '</title>'),
r'\is2': ('<title type="x-introduction">', '</title>'),
# \is3 and \is4 are not currently handled in this script.
# r'\is3': ('<title type="x-introduction">', '</title>'),
# r'\is4': ('<title type="x-introduction">', '</title>'),
#
r'\ms': ('<title>', '</title>'),
r'\ms1': ('<title>', '</title>'),
r'\ms2': ('<title>', '</title>'),
r'\ms3': ('<title>', '</title>'),
# \ms4 is not currently handled by this script.
# r'\ms4': ('<title>', '</title>'),
#
r'\s': ('<title>', '</title>'),
r'\s1': ('<title>', '</title>'),
r'\s2': ('<title>', '</title>'),
r'\s3': ('<title>', '</title>'),
r'\s4': ('<title>', '</title>'),
# ##### Semantic Whitespace ##### #
r'\sd': ('<milestone type="x-usfm-sd" />', ''),
r'\sd1': ('<milestone type="x-usfm-sd1" />', ''),
r'\sd2': ('<milestone type="x-usfm-sd2" />', ''),
r'\sd3': ('<milestone type="x-usfm-sd3" />', ''),
r'\sd4': ('<milestone type="x-usfm-sd4" />', ''),
# ---------------------------------------------------------
# ##### INTRODUCTIONS ##### #
r'\imt': ('<title type="main">', '</title>'),
r'\imt1': ('<title level="1" type="main">', '</title>'),
r'\imt2': ('<title level="2" type="main">', '</title>'),
r'\imt3': ('<title level="3" type="main">', '</title>'),
r'\imt4': ('<title level="4" type="main">', '</title>'),
r'\imte': ('<title type="main">', '</title>'),
r'\imte1': ('<title level="1" type="main">', '</title>'),
r'\imte2': ('<title level="2" type="main">', '</title>'),
r'\imte3': ('<title level="3" type="main">', '</title>'),
r'\imte4': ('<title level="4" type="main">', '</title>'),
# r'\ib': ('', ''),
# ##### Normal Title Section ##### #
r'\mt': ('<title type="main">', '</title>'),
r'\mt1': ('<title level="1" type="main">', '</title>'),
r'\mt2': ('<title level="2" type="main">', '</title>'),
r'\mt3': ('<title level="3" type="main">', '</title>'),
r'\mt4': ('<title level="4" type="main">', '</title>'),
r'\mte': ('<title type="main">', '</title>'),
r'\mte1': ('<title level="1" type="main">', '</title>'),
r'\mte2': ('<title level="2" type="main">', '</title>'),
r'\mte3': ('<title level="3" type="main">', '</title>'),
r'\mte4': ('<title level="4" type="main">', '</title>'),
#
r'\mr': ('<title type="scope"><reference>', '</reference></title>'),
r'\sr': ('<title type="scope"><reference>', '</reference></title>'),
r'\r': ('<title type="parallel"><reference type="parallel">',
'</reference></title>'),
r'\d': ('<title type="psalm" canonical="true">', '</title>'),
r'\sp': ('<speaker>', '</speaker>'),
# ##### chapter cl tags ##### #
#
# For whatever it's worth, I understand how this usfm tag is used.
# I just don't know what I need to do with it regarding osis.
#
# This is the best way I know how to convert these tags.
#
# The osis user manual says to convert these to titles and use chapterLabel
# for type in the title tag. That type is not allowed according to the osis
# 2.1.1 schema though. So I use x-chapterLabel for the type instead.
# NOTE: titles created in this manner don't work with The SWORD Project
# sofware and create problems with displaying other titles as well.
# So the conversion to titles is disabled for now and milestone
# markers are inserted instead.
# r'\cl': ('<title type="x-chapterLabel" short="', '" />'),
r'\cl': ('<milestone type="x-chapterLabel" n="', '" />'),
# ##### chapter cd tags ##### #
# the osis user manual says cd titles should be in an introduction div.
r'\cd': (u'<div type="introduction">\ufdd0<title type="x-description">',
u'</title>\ufdd0</div>'),
# ##### special features ##### #
# the osis user manual says this should be in an lg tag of type doxology
# with an l tag of type refrain.
r'\lit': (u'<lg type="doxology">\ufdd0<l type="refrain">',
u'</l>\ufdd0</lg>')
}
# paragraph and poetry/prose tags
PARTAGS = {
# INTRODUCTIONS
r'\iot': (r'<item type="x-head">', r'</item>'),
r'\io': (r'<item type="x-indent-1">', r'</item>'),
r'\io1': (r'<item type="x-indent-1">', r'</item>'),
r'\io2': (r'<item type="x-indent-2">', r'</item>'),
r'\io3': (r'<item type="x-indent-3">', r'</item>'),
r'\io4': (r'<item type="x-indent-4">', r'</item>'),
r'\ip': (r'<p>', r' </p>'),
r'\im': (r'<p type="x-noindent">', r' </p>'),
r'\ipq': (r'<p type="x-quote">', r' </p>'),
r'\imq': (r'<p type="x-noindent-quote">', r' </p>'),
r'\ipi': (r'<p type="x-indented">', r' </p>'),
r'\imi': (r'<p type="x-noindent-indented">', r' </p>'),
r'\ili': (r'<item type="x-indent-1">', r' </item>'),
r'\ili1': (r'<item type="x-indent-1">', r' </item>'),
r'\ili2': (r'<item type="x-indent-2">', r' </item>'),
r'\ipr': (r'<p type="x-right">', r' </p>'),
r'\iq': (r'<l level="1">', r' </l>'),
r'\iq1': (r'<l level="1">', r' </l>'),
r'\iq2': (r'<l level="2">', r' </l>'),
r'\iq3': (r'<l level="3">', r' </l>'),
r'\iex': (r'<div type="bridge">', r'</div>'),
r'\ie': (r'<!-- ie -->', r''),
# ##### PARAGRAPH/POETRY
r'\p': (r'<p>', r' </p>'),
r'\m': (r'<p type="x-noindent">', r' </p>'),
r'\po': (r'<p type="x-usfm-po">', r' </p>'),
r'\pmo': (r'<p type="x-embedded-opening">', r' </p>'),
r'\pm': (r'<p type="x-embedded">', r' </p>'),
r'\pmc': (r'<p type="x-embedded-closing">', r' </p>'),
r'\pmr': (r'<p type="x-right">', r' </p>'),
r'\pi': (r'<p type="x-indented">', r' </p>'),
r'\pi1': (r'<p type="x-indented-1">', r' </p>'),
r'\pi2': (r'<p type="x-indented-2">', r' </p>'),
r'\pi3': (r'<p type="x-indented-3">', r' </p>'),
r'\pi4': (r'<p type="x-indented-4">', r' </p>'),
r'\mi': (r'<p type="x-noindent-indented">', r' </p>'),
r'\cls': (r'<closer>', r'</closer>'),
r'\lh': (r'<p type="x-usfm-lh">', r'</p>'),
r'\lf': (r'<p type="x-usfm-lf">', r'</p>'),
r'\li': (r'<item type="x-indent-1">', r' </item>'),
r'\li1': (r'<item type="x-indent-1">', r' </item>'),
r'\li2': (r'<item type="x-indent-2">', r' </item>'),
r'\li3': (r'<item type="x-indent-3">', r' </item>'),
r'\li4': (r'<item type="x-indent-4">', r' </item>'),
r'\lim': (r'<item type="x-usfm-lim">', r' </item>'),
r'\lim1': (r'<item type="x-usfm-lim1">', r' </item>'),
r'\lim2': (r'<item type="x-usfm-lim2">', r' </item>'),
r'\lim3': (r'<item type="x-usfm-lim3">', r' </item>'),
r'\lim4': (r'<item type="x-usfm-lim4">', r' </item>'),
r'\pc': (r'<p type="x-center">', r' </p>'),
r'\pr': (r'<p type="x-right">', r' </p>'),
r'\ph': (r'<item type="x-indent-1">', r' </item>'),
r'\ph1': (r'<item type="x-indent-1">', r' </item>'),
r'\ph2': (r'<item type="x-indent-2">', r' </item>'),
r'\ph3': (r'<item type="x-indent-3">', r' </item>'),
# POETRY Markers
r'\q': (r'<l level="1">', r' </l>'),
r'\q1': (r'<l level="1">', r' </l>'),
r'\q2': (r'<l level="2">', r' </l>'),
r'\q3': (r'<l level="3">', r' </l>'),
r'\q4': (r'<l level="4">', r' </l>'),
r'\qr': (r'<l type="x-right">', r' </l>'),
r'\qc': (r'<l type="x-center">', r' </l>'),
r'\qa': (r'<title type="acrostic">', r'</title>'),
r'\qd': (r'<l type="x-usfm-qd">', r'</l>'),
r'\qm': (r'<l type="x-embedded" level="1">', r' </l>'),
r'\qm1': (r'<l type="x-embedded" level="1">', r' </l>'),
r'\qm2': (r'<l type="x-embedded" level="2">', r' </l>'),
r'\qm3': (r'<l type="x-embedded" level="3">', r' </l>'),
r'\qm4': (r'<l type="x-embedded" level="4">', r' </l>')
}
# other introduction and poetry tags
OTHERTAGS = {
# selah is handled in a special manner.
r'\qs ': '<selah>',
r'\qs*': '</selah>',
# these get special handling.
r'\ie': '<!-- ie -->', # handled with partags... probably not needed here.
r'\ib ': '<!-- b -->', # this tag is handled exactly like b.
r'\b ': '<!-- b -->',
r'\nb ': '<!-- nb -->'
}
# table cell tags
CELLTAGS = {
# header cells
r'\th': ('<cell role="label">', '</cell>'),
r'\th1': ('<cell role="label">', '</cell>'),
r'\th2': ('<cell role="label">', '</cell>'),
r'\th3': ('<cell role="label">', '</cell>'),
r'\th4': ('<cell role="label">', '</cell>'),
r'\th5': ('<cell role="label">', '</cell>'),
r'\thr': ('<cell role="label" type="x-right">', '</cell>'),
r'\thr1': ('<cell role="label" type="x-right">', '</cell>'),
r'\thr2': ('<cell role="label" type="x-right">', '</cell>'),
r'\thr3': ('<cell role="label" type="x-right">', '</cell>'),
r'\thr4': ('<cell role="label" type="x-right">', '</cell>'),
r'\thr5': ('<cell role="label" type="x-right">', '</cell>'),
# normal cells
r'\tc': ('<cell>', '</cell>'),
r'\tc1': ('<cell>', '</cell>'),
r'\tc2': ('<cell>', '</cell>'),
r'\tc3': ('<cell>', '</cell>'),
r'\tc4': ('<cell>', '</cell>'),
r'\tc5': ('<cell>', '</cell>'),
r'\tcr': ('<cell type="x-right">', '</cell>'),
r'\tcr1': ('<cell type="x-right">', '</cell>'),
r'\tcr2': ('<cell type="x-right">', '</cell>'),
r'\tcr3': ('<cell type="x-right">', '</cell>'),
r'\tcr4': ('<cell type="x-right">', '</cell>'),
r'\tcr5': ('<cell type="x-right">', '</cell>')
}
# special text and character style tags.
# \wj tags are handled with a special function. Don't add it here.
SPECIALTEXT = {
# tags for special text
r'\add': ('<transChange type="added">', '</transChange>'),
r'\addpn': ('<transChange type="added" subType="x-usfm-addpn">',
'</transChange>'),
r'\nd': ('<divineName>', '</divineName>'),
r'\pn': ('<name>', '</name>'),
r'\qt': ('<seg type="otPassage">', '</seg>'),
r'\sig': ('<signed>', '</signed>'),
r'\ord': ('<hi type="super">', '</hi>'),
r'\tl': ('<foreign>', '</foreign>'),
r'\bk': ('<name type="x-usfm-bk">', '</name>'),
r'\k': ('<seg type="keyword">', '</seg>'),
r'\dc': ('<transChange type="added" editions="dc">', '</transChange>'),
r'\sls': ('<foreign type="x-secondaryLanguage">', '</foreign>'),
r'\+add': ('<seg type="x-nested"><transChange type="added">',
'</transChange></seg>'),
r'\+addpn': ('<seg type="x-nested"><transChange type="added" subType="x-usfm-addpn">',
'</transChange></seg>'),
r'\+nd': ('<seg type="x-nested"><divineName>', '</divineName></seg>'),
r'\+pn': ('<seg type="x-nested"><name>', '</name></seg>'),
r'\+qt': ('<seg type="x-nested"><seg type="otPassage">', '</seg></seg>'),
r'\+sig': ('<seg type="x-nested"><signed>', '</signed></seg>'),
r'\+ord': ('<seg type="x-nested"><hi type="super">', '</hi></seg>'),
r'\+tl': ('<seg type="x-nested"><foreign>', '</foreign></seg>'),
r'\+bk': ('<seg type="x-nested"><name type="x-usfm-bk">', '</name></seg>'),
r'\+k': ('<seg type="x-nested"><seg type="keyword">', '</seg></seg>'),
r'\+dc': ('<seg type="x-nested"><transChange type="added" editions="dc">',
'</transChange></seg>'),
r'\+sls': ('<seg type="x-nested"><foreign type="x-secondaryLanguage">',
'</foreign></seg>'),
# tags for character styles
r'\em': ('<hi type="emphasis">', '</hi>'),
r'\bd': ('<hi type="bold">', '</hi>'),
r'\it': ('<hi type="italic">', '</hi>'),
r'\bdit': ('<hi type="bold"><hi type="italic">', '</hi></hi>'),
r'\no': ('<hi type="normal">', '</hi>'),
r'\sc': ('<hi type="small-caps">', '</hi>'),
r'\+em': ('<seg type="x-nested"><hi type="emphasis">', '</hi></seg>'),
r'\+bd': ('<seg type="x-nested"><hi type="bold">', '</hi></seg>'),
r'\+it': ('<seg type="x-nested"><hi type="italic">', '</hi></seg>'),
r'\+bdit': ('<seg type="x-nested"><hi type="bold"><hi type="italic">',
'</hi></hi></seg>'),
r'\+no': ('<seg type="x-nested"><hi type="normal">', '</hi></seg>'),
r'\+sc': ('<seg type="x-nested"><hi type="small-caps">', '</hi></seg>'),
# a few stray list tags that work well being handled in this section.
r'\lik': ('<seg type="x-usfm-lik">', '</seg>'),
r'\liv': ('<seg type="x-usfm-liv">', '</seg>'),
r'\liv1': ('<seg type="x-usfm-liv1">', '</seg>'),
r'\liv2': ('<seg type="x-usfm-liv2">', '</seg>'),
r'\liv3': ('<seg type="x-usfm-liv3">', '</seg>'),
r'\liv4': ('<seg type="x-usfm-liv4">', '</seg>'),
r'\litl': ('<seg type="x-usfm-litl">', '</seg>'),
# a few stray introduction and poetry tags that
# work well being handled in this section.
r'\ior': ('<reference>', '</reference>'),
r'\iqt': ('<q subType="x-introduction">', '</q>'),
r'\rq': ('<reference type="source">', '</reference>'),
r'\qac': ('<hi type="acrostic">', '</hi>'),
r'\+ior': ('<seg type="x-nested"><reference>', '</reference></seg>'),
r'\+iqt': ('<seg type="x-nested"><q subType="x-introduction">',
'</q></seg>'),
r'\+rq': ('<seg type="x-nested"><reference type="source">',
'</reference></seg>'),
r'\+qac': ('<seg type="x-nested"><hi type="acrostic">', '</hi></seg>')
}
# special features
# do not add \lit here... that is handled with TITLETAGS.
FEATURETAGS = {
r'\ndx': ('', '<index="Index" level1="{}" /> '),
r'\pro': ('<milestone type="x-usfm-pro" n="', '" /> '),
r'\png': ('', '<index index="Geography" level1="{}" />'),
r'\rb': ('<milestone type="x-usfm-rb" n="', '" /> '),
r'\rt': ('<milestone type="x-usfm-rt" n="', '" /> '),
r'\w': ('', '<index index="Glossary" level1="{}" />'),
r'\wa': ('', '<index index="Aramaic" level1="{}" />'),
r'\wg': ('', '<index index="Greek" level1="{}" />'),
r'\wh': ('', '<index index="Hebrew" level1="{}" />')
}
# footnote and cross reference tags
NOTETAGS = {
r'\f': ('<note placement="foot">', '</note>'),
r'\fe': ('<note placement="end">', '</note>'),
r'\x': ('<note type="crossReference">', '</note>'),
r'\ef': ('<note placement="foot" subtype="x-extended">', '</note>'),
r'\ex': ('<note type="crossReference" subtype="x-extended">', '</note>')
}
# tags internal to footnotes and cross references
# * If any of these ever start with anything other than \f or \x *
# * then the NOTEFIXRE regex will need to be modified. *
NOTETAGS2 = {
r'\fm': ('<hi type="super">', '</hi>'),
r'\fdc': ('<seg editions="dc">', '</seg>'),
r'\fr': ('<reference type="annotateRef">', '</reference>'),
r'\fk': ('<catchWord>', '</catchWord>'),
r'\fq': ('<catchWord>', '</catchWord>'),
r'\fqa': ('<rdg type="alternate">', '</rdg>'),
# I think this should be label... but that doesn't validate.
# r'\fl': ('<label>', '</label>'),
r'\fl': ('<seg type="x-usfm-fl">', '</seg>'),
r'\fv': ('<hi type="super">', '</hi>'),
r'\ft': ('', ''),
r'\xot': ('<seg editions="ot">', '</seg>'),
r'\xnt': ('<seg editions="nt">', '</seg>'),
r'\xdc': ('<seg editions="dc">', '</seg>'),
r'\xk': ('<catchWord>', '</catchWord>'),
r'\xq': ('<catchWord>', '</catchWord>'),
# there is no mapping in the osis manual for the xo usfm tag
# old handling of this tag is commented out.
# r'\xo': ('<reference type="annotateRef">', '</reference>'),
# potential alternate handling of xo and xt...
# r'\xo': ('<reference type="x-anchorRef">', '</reference>'),
# r'\xt': ('<reference type="annotateRef">', '</reference>'),
# currently preferred handling of xo and xt...
r'\xo': ('<seg type="x-usfm-xo">', '</seg>'),
r'\xop': ('<seg type="x-usfm-xop">', '</seg>'),
r'\xta': ('<seg type="x-usfm-xta">', '</seg>'),
r'\xt': ('<reference>', '</reference>')
}
# -------------------------------------------------------------------------- #
# REGULAR EXPRESSIONS
# squeeze whitespace into single space character
SQUEEZE = re.compile(r'\s+', re.U + re.M + re.DOTALL)
# matches special text and character styles
# Automatically build SPECIALTEXTRE regex string from SPECIALTEXT dict.
SPECIALTEXTRE_S = r'''
# put special text tags into a named group called 'tag'
(?P<tag>
# tags always start with a backslash and may have a + symbol which
# indicates that it's a nested character style.
\\\+?
# match the tags we want to match.
(?:{})
)
# there is always at least one space separating the tag and the content
\s+
# put the tag content into a named group called 'osis'
(?P<osis>.*?)
# tag end marker
(?P=tag)\*
'''.format('|'.join([_.replace('\\', '') for _ in SPECIALTEXT.keys()
if not _.startswith(r'\+')]))
SPECIALTEXTRE = re.compile(SPECIALTEXTRE_S, re.U + re.VERBOSE)
del SPECIALTEXTRE_S
# matches special feature tags
# Automatically build SPECIALFEATURESRE regex string from FEATURETAGS dict.
SPECIALFEATURESRE_S = r'''
# put the special features tags into a named group called 'tag'
(?P<tag>
# tags always start with a backslash
\\
# this matches all of the known usfm special features except
# for fig which is handled in a different manner.
(?:{})
)
# there is always at least one space separating the tag and the content
\s+
# put the tag content into a named group called 'osis'
(?P<osis>.*?)
# tag end marker
(?P=tag)\*
'''.format('|'.join([_.replace('\\', '') for _ in FEATURETAGS.keys()
if not _.startswith(r'\+')]))
SPECIALFEATURESRE = re.compile(SPECIALFEATURESRE_S, re.U + re.VERBOSE)
del SPECIALFEATURESRE_S
# regex used in footnote/crossref functions
# Automatically build NOTERE regex string from NOTETAGS dict.
NOTERE_S = r'''
# put the footnote and cross reference markers into a named group
# called 'tag'
(?P<tag>
# tags always start with a backslash
\\
# this matches the usfm footnote and cross reference markers.
(?:{})
)
# there is always at least one space following the tag.
\s+
# footnote caller (currently ignored by this script)
\S
# there is always at least one space following the caller
\s+
# put the tag content into a named group called 'osis'
(?P<osis>.*?)
# footnote / cross reference end tag
(?P=tag)\*
'''.format('|'.join([_.replace('\\', '') for _ in NOTETAGS.keys()
if not _.startswith(r'\+')]))
NOTERE = re.compile(NOTERE_S, re.U + re.VERBOSE)
del NOTERE_S
# ---
# Automatically build NOTEFIXRE regex string from NOTETAGS2 dict.
NOTEFIXRE_S = r'''
(
# tags always start with a backslash
\\
# this matches all of the footnote/crossref specific usfm tags that
# appear inside footnotes and cross references.
(?:{})
)
# there is always at least one space following the tag.
\s+
# This matches the content of the tag
(.*?)
# This marks the end of the tag. It matches against either the
# start of an additional tag or the end of the note.
(?=\\[fx]|</note)
'''.format('|'.join([_.replace('\\', '') for _ in NOTETAGS2.keys()
if not _.startswith(r'\+')]))
NOTEFIXRE = re.compile(NOTEFIXRE_S, re.U + re.VERBOSE)
del NOTEFIXRE_S
# match \cp and \vp tags
CPRE = re.compile(
r'''
\\(?:cp)
\s+
(?P<num>\S+)\b
\s*
''', re.U + re.VERBOSE)
VPRE = re.compile(
r'''
\\(?:vp)
\s+
(?P<num>\S+)
\s*
\\vp\*
\s*
''', re.U + re.VERBOSE)
# regex for matching against \ca or \va usfm tags.
CVARE = re.compile(
r'''
# put the tag we match into a named group called tag
(?P<tag>
# tags always start with a backslash
\\
# match against either ca or va
(?:ca|va)
)
# there is always at least one space following the tag
\s+
# put the number into a named group called num
(?P<num>\S+)
# make sure the end tag matched the start tag...
(?P=tag)\*
# there may or may not be space following this tag.
\s*
''', re.U + re.VERBOSE)
# regex for finding usfm tags
USFMRE = re.compile(r'''
# the first character of a usfm tag is always a backslash
\\
# a plus symbol marks the start of a nested character style.
# this may or may not be present.
\+?
# tag names are ascii letters
[A-Za-z]+
# tags may or may not be numbered
[0-9]?
# a word boundary to mark the end of our tags.
\b
# character style closing tags ends with an asterisk.
\*?
''', re.U + re.VERBOSE)
# -------------------------------------------------------------------------- #
# VARIABLES USED BY REFLOW ROUTINE
# set of paragraph style tags built MOSTLY from other lists above...
# this is used by reflow to reformat the input for processing
# * chapter paragraph tags are omitted because we handle them differently
PARFLOW = set(IDTAGS.keys())
PARFLOW.update(TITLETAGS.keys())
PARFLOW.update(PARTAGS.keys())
PARFLOW.update([r'\ide', r'\rem', r'\tr', r'\pb', r'\periph'])
# poetry/prose tags... used by reflow subroutine below.
# this is used by reflow to test if we have paragraph markup.
PARCHECK = set(PARTAGS.keys())
try:
PARCHECK.remove(r'\iex')
except KeyError:
pass
try:
PARCHECK.remove(r'\ie')
except KeyError:
pass
# title tags... used by reflow subroutine below.
# use TITLETAGS keys to eliminate unnecessary duplication
TITLEFLOW = set(TITLETAGS.keys())
# -------------------------------------------------------------------------- #
# VARIABLES USED BY POSTPROCESS ROUTINE
OSISITEM = set()
OSISL = set()
for _ in PARTAGS:
if PARTAGS[_][0].startswith('<item '):
OSISITEM.add(PARTAGS[_][0])
elif PARTAGS[_][0].startswith('<l '):
OSISL.add(PARTAGS[_][0])
OSISL.add('<l>')
OSISITEM.add('<item>')
# -------------------------------------------------------------------------- #
# osis 2.1.1 schema...
# compressed with bzip2 and base64 encoded.
SCHEMA = b'''
QlpoOTFBWSZTWSchBD8AHwNfgEAAcX//f////9+////+YCe7AM94DhqfVb5vu3w97x70e8C33tA0
Eje9ffD4699161lPPWbsz3OxMj2YvZvffHeOzgHQG0epbWtL23MGjVaPbAr69AXoBni1S3tyeZvW
fEMfb3rOgG9ttGhb7vCSEIATIJkyTSntqYhPKnlPaoe0UyZNGjQAAGmgmghDRMo9SbU2RqGmRkAa
AABoZAAkJFNMqehNGp7UZND1Aj9Uek9T1D9SYaEGTanpGmjIwSeqUoqfqTRpG0TRtGpkaYjCDJgE
yAxAwjTTCJImiYiTaqf6FPST9U9MoeSeQmh6TJpp5QGgA0YQRJCaE0EamKeQVP1PUxRtRtRtRoB6
gGgAAFz4Gk/r2dGrXY72FT8TkPc+Mjfv5PFn5KnLll78c/7/38b+vMdPMpderyKSpHWbjPr8/a5T
UdOXcHp/Ns/Lll+mdEOfnakZrf0CgmmMSSSFsPT0WNtgp1yDa1dCrHZeqcn5AftLE2fF24rCChJU
BzaiquS7ZlZZg+8UqIqk6qpQcSLUql2DnZrdt4oz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5c1yQW43aphfJQJ5R+ZqygTLxdDbhrHBhKc2Fu4l6mkBOYWd8pAT4
RTh7chfEWJWgRmzMhmBq9U+K1wEkEclUIgoUKDAviOIw1LhZP0ZREUIUKBSiUCkRiMRQiKEAFVgL
KikYoFKBJCCwGKxVCAAUqGTBBsg+XphIDaJJgA6BtGLXI2+hneE0Pz82nzN1n5ONYbMaWvDTere8
4PwgQFAkCEipABCK1VGMY1tVlbVNmrfF83z5BGGh8B7jl9P4hR9qva4frAHInE9QfMgxU93zF3JF
OFCQJyEEPw==
'''
# -------------------------------------------------------------------------- #
def convertcl(text):
'''
convert cl tags that appear only before chapter one to
the form that appears after each chapter marker.
'''
lines = text.split('\n')
# count number of cl tags in text
clcount = 0
for i in lines:
if i.startswith(r'\cl '):
clcount += 1
# test for presence of only 1 cl marker.
if clcount == 1:
chaplines = [_ for _ in range(len(lines)) if
lines[_].startswith(r'\c ')]
# get cl marker line if it precedes chapter 1 and add this after
# each chapter marker in the book.
if lines[chaplines[0] - 1].startswith(r'\cl '):
clmarker = lines[chaplines[0] - 1]
lines[chaplines[0] - 1] = ''
for i in reversed(chaplines):
lines.insert(i + 1, clmarker)
# return our lines with converted cl tags.
return '\n'.join(lines)
def reflow(text):
'''
Reflow the text for processing, placing all paragraph style tags on their
own line. This makes it significantly easier to handle paragraph markup.
'''
# ####################################################################### #
# The titlepar function depends on how this routine was written in order #
# to function properly. Don't make changes here unless you know what #
# you're doing and understand the ramifications in relation to how the #
# titlepar function operates! #
# ####################################################################### #
mangletext = False
# test for paragraph markup before mangling the text
for i in PARCHECK:
if i in text:
mangletext = True