forked from openlp/openlp
99% of OSIS import now working.
This commit is contained in:
parent
1181152c5a
commit
b7f224e280
@ -55,10 +55,18 @@ class BibleOSISImpl():
|
|||||||
"""
|
"""
|
||||||
log.info(u'BibleOSISImpl Initialising')
|
log.info(u'BibleOSISImpl Initialising')
|
||||||
self.verse_regex = re.compile(r'<verse osisID="([a-zA-Z0-9 ]*).([0-9]*).([0-9]*)">(.*?)</verse>')
|
self.verse_regex = re.compile(r'<verse osisID="([a-zA-Z0-9 ]*).([0-9]*).([0-9]*)">(.*?)</verse>')
|
||||||
self.note_regex = re.compile(r'<note([a-zA-Z0-9 "=]*)>(.*?)</note>')
|
self.note_regex = re.compile(r'<note(.*?)>(.*?)</note>')
|
||||||
|
self.title_regex = re.compile(r'<title(.*?)>(.*?)</title>')
|
||||||
|
self.milestone_regex = re.compile(r'<milestone(.*?)/>')
|
||||||
|
self.lb_regex = re.compile(r'<lb(.*?)>')
|
||||||
|
self.l_regex = re.compile(r'<l (.*?)>')
|
||||||
|
self.w_regex = re.compile(r'<w (.*?)>')
|
||||||
|
self.q_regex = re.compile(r'<q (.*?)>')
|
||||||
|
self.spaces_regex = re.compile(r'([ ]{2,})')
|
||||||
self.bibledb = bibledb
|
self.bibledb = bibledb
|
||||||
# books of the bible linked to bibleid {osis , name}
|
# books of the bible linked to bibleid {osis , name}
|
||||||
self.booksOfBible = {}
|
self.booksOfBible = {}
|
||||||
|
self.books = {}
|
||||||
# books of the bible linked to bibleid {osis ,Abbrev }
|
# books of the bible linked to bibleid {osis ,Abbrev }
|
||||||
self.abbrevOfBible = {}
|
self.abbrevOfBible = {}
|
||||||
filepath = os.path.split(os.path.abspath(__file__))[0]
|
filepath = os.path.split(os.path.abspath(__file__))[0]
|
||||||
@ -70,8 +78,9 @@ class BibleOSISImpl():
|
|||||||
fbibles = open(filepath, u'r')
|
fbibles = open(filepath, u'r')
|
||||||
for line in fbibles:
|
for line in fbibles:
|
||||||
p = line.split(u',')
|
p = line.split(u',')
|
||||||
self.booksOfBible[p[0]] = p[1].replace(u'\n', u'')
|
#self.booksOfBible[p[0]] = p[1].replace(u'\n', u'')
|
||||||
self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'')
|
self.books[p[0]] = (p[1].lstrip().rstrip(), p[2].lstrip().rstrip())
|
||||||
|
#self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'')
|
||||||
except:
|
except:
|
||||||
log.exception(u'OSIS bible import failed')
|
log.exception(u'OSIS bible import failed')
|
||||||
finally:
|
finally:
|
||||||
@ -111,53 +120,46 @@ class BibleOSISImpl():
|
|||||||
osis = None
|
osis = None
|
||||||
try:
|
try:
|
||||||
osis = codecs.open(osisfile_record, u'r', details['encoding'])
|
osis = codecs.open(osisfile_record, u'r', details['encoding'])
|
||||||
last_chapter = u'0'
|
last_chapter = 0
|
||||||
|
testament = 1
|
||||||
for file_record in osis:
|
for file_record in osis:
|
||||||
match = self.verse_regex.search(file_record)
|
match = self.verse_regex.search(file_record)
|
||||||
if match:
|
if match:
|
||||||
print 'Found:', match.group(4)
|
book = match.group(1)
|
||||||
#if last_chapter != match.group(2):
|
chapter = int(match.group(2))
|
||||||
print match.group(2)
|
verse = int(match.group(3))
|
||||||
# dialogobject.incrementProgressBar(
|
|
||||||
# u'Importing %s %s...' % \
|
|
||||||
# (self.books[match.group(1)], match.group(2)))
|
|
||||||
# last_chapter = match.group(2)
|
|
||||||
verse_text = match.group(4)
|
verse_text = match.group(4)
|
||||||
#verse_text = self.remove_block(
|
if last_chapter == 0:
|
||||||
#verse_text = self.note_regex.sub(lambda match: u'', verse_text)
|
if book == u'Gen':
|
||||||
print verse_text
|
dialogobject.ImportProgressBar.setMaximum(1188)
|
||||||
else:
|
else:
|
||||||
print 'Not found...', file_record[:10]
|
dialogobject.ImportProgressBar.setMaximum(260)
|
||||||
# (self.booksOfBible[p[0]], p[1]))
|
if last_chapter != chapter:
|
||||||
# book_ptr = None
|
if last_chapter != 0:
|
||||||
# count = 0
|
self.bibledb.save_verses()
|
||||||
# verseText = u'<verse osisID='
|
dialogobject.incrementProgressBar(
|
||||||
# testament = 1
|
u'Importing %s %s...' % \
|
||||||
# for file_record in osis:
|
(self.books[match.group(1)][0], chapter))
|
||||||
# # cancel pressed on UI
|
if book == u'Matt':
|
||||||
# if not self.loadbible:
|
testament += 1
|
||||||
# break
|
db_book = self.bibledb.create_book(
|
||||||
# pos = file_record.find(verseText)
|
unicode(self.books[book][0]),
|
||||||
# # we have a verse
|
unicode(self.books[book][1]),
|
||||||
# if pos > -1:
|
testament)
|
||||||
# epos = file_record.find(u'>', pos)
|
last_chapter = chapter
|
||||||
# # Book Reference
|
verse_text = self.note_regex.sub(u'', verse_text)
|
||||||
# ref = file_record[pos+15:epos-1]
|
verse_text = self.title_regex.sub(u'', verse_text)
|
||||||
# #lets find the bible text only
|
verse_text = self.milestone_regex.sub(u'', verse_text)
|
||||||
# # find start of text
|
verse_text = self.lb_regex.sub(u'', verse_text)
|
||||||
# pos = epos + 1
|
verse_text = self.l_regex.sub(u'', verse_text)
|
||||||
# # end of text
|
verse_text = self.w_regex.sub(u'', verse_text)
|
||||||
# epos = file_record.find(u'</verse>', pos)
|
verse_text = self.q_regex.sub(u'', verse_text)
|
||||||
# text = file_record[pos : epos]
|
verse_text = verse_text.replace(u'</lb>', u'')\
|
||||||
# #remove tags of extra information
|
.replace(u'</l>', u'').replace(u'<lg>', u'')\
|
||||||
# text = self.remove_block(u'<title', u'</title>', text)
|
.replace(u'</lg>', u'').replace(u'</q>', u'')\
|
||||||
# text = self.remove_block(u'<note', u'</note>', text)
|
.replace(u'</div>', u'')
|
||||||
# text = self.remove_block(
|
verse_text = self.spaces_regex.sub(u' ', verse_text)
|
||||||
# u'<divineName', u'</divineName>', text)
|
self.bibledb.add_verse(db_book.id, chapter, verse, verse_text)
|
||||||
# text = self.remove_tag(u'<lb', text)
|
|
||||||
# text = self.remove_tag(u'<q', text)
|
|
||||||
# text = self.remove_tag(u'<l', text)
|
|
||||||
# text = self.remove_tag(u'<lg', text)
|
|
||||||
# # Strange tags where the end is not the same as the start
|
# # Strange tags where the end is not the same as the start
|
||||||
# # The must be in this order as at least one bible has them
|
# # The must be in this order as at least one bible has them
|
||||||
# # crossing and the removal does not work.
|
# # crossing and the removal does not work.
|
||||||
@ -174,39 +176,8 @@ class BibleOSISImpl():
|
|||||||
# epos = text.find(u'<Rf>', pos)
|
# epos = text.find(u'<Rf>', pos)
|
||||||
# text = text[:pos] + text[epos + 4: ]
|
# text = text[:pos] + text[epos + 4: ]
|
||||||
# pos = text.find(u'<RF>')
|
# pos = text.find(u'<RF>')
|
||||||
# print ref
|
self.bibledb.save_verses()
|
||||||
# continue
|
dialogobject.incrementProgressBar(u'Finishing import...')
|
||||||
# # split up the reference
|
|
||||||
# p = ref.split(u'.', 3)
|
|
||||||
# if book_ptr != p[0]:
|
|
||||||
# # first time through
|
|
||||||
# if book_ptr is None:
|
|
||||||
# # set the max book size depending
|
|
||||||
# # on the first book read
|
|
||||||
# if p[0] == u'Gen':
|
|
||||||
# dialogobject.ImportProgressBar.setMaximum(1188)
|
|
||||||
# else:
|
|
||||||
# dialogobject.ImportProgressBar.setMaximum(260)
|
|
||||||
# # First book of NT
|
|
||||||
# if p[0] == u'Matt':
|
|
||||||
# testament += 1
|
|
||||||
# dialogobject.incrementProgressBar(u'Importing %s %s...' % \
|
|
||||||
# (self.booksOfBible[p[0]], p[1]))
|
|
||||||
# Receiver.send_message(u'process_events')
|
|
||||||
# self.bibledb.save_verses()
|
|
||||||
# book_ptr = p[0]
|
|
||||||
# book = self.bibledb.create_book(
|
|
||||||
# unicode(self.booksOfBible[p[0]]),
|
|
||||||
# unicode(self.abbrevOfBible[p[0]]),
|
|
||||||
# testament)
|
|
||||||
# count = 0
|
|
||||||
# self.bibledb.add_verse(book.id, p[1], p[2], text)
|
|
||||||
# #count += 1
|
|
||||||
# #Every 3 verses repaint the screen
|
|
||||||
# #if count % 3 == 0:
|
|
||||||
# # Receiver.send_message(u'process_events')
|
|
||||||
# # count = 0
|
|
||||||
# #self.bibledb.save_verses()
|
|
||||||
except:
|
except:
|
||||||
log.exception(u'Loading bible from OSIS file failed')
|
log.exception(u'Loading bible from OSIS file failed')
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
Reference in New Issue
Block a user