66import sys
77import getopt
88import json
9+ import os
910from xml .etree import ElementTree as ET
1011
1112bookNameData = {}
5556stripHFromMorph = False
5657prefixLemmasWithH = False
5758remapVerses = False
59+ splitByBook = False
5860
5961
6062def getBookData (filename ):
@@ -134,6 +136,7 @@ def getCommandOptions(argv):
134136 global stripHFromMorph
135137 global prefixLemmasWithH
136138 global remapVerses
139+ global splitByBook
137140
138141 try :
139142 opts , args = getopt .getopt (argv , "h:" ,
@@ -142,14 +145,15 @@ def getCommandOptions(argv):
142145 "removeLemmaTypes" ,
143146 "stripHFromMorph" ,
144147 "prefixLemmasWithH" ,
145- "remapVerses"
148+ "remapVerses" ,
149+ "splitByBook"
146150 ])
147151 except getopt .GetoptError :
148- print ('python3 morphhb.py --stripPointing --removeLemmaTypes --stripHFromMorph --prefixLemmasWithH --remapVerses' )
152+ print ('python3 morphhb.py --stripPointing --removeLemmaTypes --stripHFromMorph --prefixLemmasWithH --remapVerses --splitByBook ' )
149153 sys .exit (2 )
150154 for opt , arg in opts :
151155 if opt == '-h' :
152- print ('python3 morphhb.py --stripPointing --removeLemmaTypes --stripHFromMorph --prefixLemmasWithH --remapVerses' )
156+ print ('python3 morphhb.py --stripPointing --removeLemmaTypes --stripHFromMorph --prefixLemmasWithH --remapVerses --splitByBook ' )
153157 sys .exit ()
154158 elif opt in ("--stripPointing" ):
155159 print ('stripPointing' )
@@ -166,6 +170,9 @@ def getCommandOptions(argv):
166170 elif opt in ("--remapVerses" ):
167171 print ('remapVerses' )
168172 remapVerses = True
173+ elif opt in ("--splitByBook" ):
174+ print ('splitByBook' )
175+ splitByBook = True
169176
170177
171178def main ():
@@ -259,17 +266,25 @@ def main():
259266 remapped ['Psalms' ][12 ][4 ][6 :16 ] = []
260267 remapped ['Psalms' ][12 ][5 ][0 : 6 ] = []
261268
262- jsonStr = str (hebrew )
263269 if remapVerses :
264- jsonStr = str (remapped )
265-
266- jsonStr = re .sub (r'(?<=\},)' , '\n ' , jsonStr )
267- if stripPointing :
268- jsonStr = stripPointingFunc (jsonStr )
269-
270- print ("var morphhb={};" .format (jsonStr ))
271- print ('' )
272- print ('module.exports=morphhb;' )
270+ final = remapped
271+ else :
272+ final = hebrew
273+
274+ name = 'remapped' if remapVerses else 'hebrew'
275+
276+ if splitByBook :
277+ output_dir = os .path .join ('./json' , name )
278+ if not os .path .exists (output_dir ):
279+ os .makedirs (output_dir )
280+
281+ for book in final :
282+ target_file = os .path .join (output_dir , book .replace (" " , "" ).lower ())
283+ with open (target_file + '.json' , 'w' , encoding = 'utf8' ) as f :
284+ json .dump (final [book ], f , ensure_ascii = False )
285+ else :
286+ with open (name + '.json' , 'w' , encoding = 'utf8' ) as f :
287+ json .dump (final , f , ensure_ascii = False )
273288
274289
275290if __name__ == "__main__" :
0 commit comments