forked from openlp/openlp
Fixed up searching for non-latin characters in Bible book names.
Removed an annoying exception to do with debug logging.
This commit is contained in:
parent
e465264630
commit
ce6738a976
@ -28,13 +28,15 @@ import chardet
|
||||
import logging
|
||||
import re
|
||||
|
||||
only_verses = re.compile(r'([a-zA-Z0-9 ]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)'
|
||||
only_verses = re.compile(r'([\w .]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)'
|
||||
r'(?:[ ]*-[ ]*([0-9]+|end))?(?:[ ]*,[ ]*([0-9]+)(?:[ ]*-[ ]*([0-9]+|end))?)?',
|
||||
re.UNICODE)
|
||||
chapter_range = re.compile(r'([a-zA-Z0-9 ]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*'
|
||||
chapter_range = re.compile(r'([\w .]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*'
|
||||
r'([0-9]+)[ ]*-[ ]*([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)',
|
||||
re.UNICODE)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def parse_reference(reference):
|
||||
"""
|
||||
This is the über-awesome function that takes a person's typed in string
|
||||
@ -47,11 +49,13 @@ def parse_reference(reference):
|
||||
(book, chapter, start_verse, end_verse)
|
||||
"""
|
||||
reference = reference.strip()
|
||||
log.debug('parse_reference("%s")', reference)
|
||||
reference_list = []
|
||||
# We start with the most "complicated" match first, so that they are found
|
||||
# first, and we don't have any "false positives".
|
||||
match = chapter_range.match(reference)
|
||||
if match:
|
||||
log.debug('Found a chapter range.')
|
||||
reference_list.extend([
|
||||
(match.group(1), match.group(2), match.group(3), -1),
|
||||
(match.group(1), match.group(4), 1, match.group(5))
|
||||
@ -59,6 +63,7 @@ def parse_reference(reference):
|
||||
else:
|
||||
match = only_verses.match(reference)
|
||||
if match:
|
||||
log.debug('Found a verse range.')
|
||||
book = match.group(1)
|
||||
chapter = match.group(2)
|
||||
verse = match.group(3)
|
||||
@ -82,6 +87,8 @@ def parse_reference(reference):
|
||||
(book, chapter, verse, match.group(4)),
|
||||
(book, chapter, match.group(5), end_verse)
|
||||
])
|
||||
else:
|
||||
log.debug('Didn\'t find anything.')
|
||||
return reference_list
|
||||
|
||||
class SearchResults:
|
||||
|
@ -157,7 +157,7 @@ class BibleDB(QtCore.QObject):
|
||||
return self.session.query(Book).order_by(Book.id).all()
|
||||
|
||||
def get_book(self, book):
|
||||
log.debug(u'BibleDb.get_book("%s")', __name__, book)
|
||||
log.debug(u'BibleDb.get_book("%s")', book)
|
||||
db_book = self.session.query(Book)\
|
||||
.filter(Book.name.like(book + u'%'))\
|
||||
.first()
|
||||
@ -200,7 +200,7 @@ class BibleDB(QtCore.QObject):
|
||||
end_verse = self.get_chapter_count(book)
|
||||
if db_book:
|
||||
book = db_book.name
|
||||
log.debug(u'Book name corrected to "%s"' % book)
|
||||
log.debug(u'Book name corrected to "%s"', book)
|
||||
verses = self.session.query(Verse)\
|
||||
.filter_by(book_id=db_book.id)\
|
||||
.filter_by(chapter=chapter)\
|
||||
@ -276,11 +276,11 @@ class BibleDB(QtCore.QObject):
|
||||
return False
|
||||
|
||||
def dump_bible(self):
|
||||
log.debug( u'.........Dumping Bible Database')
|
||||
log.debug( '...............................Books ')
|
||||
log.debug(u'.........Dumping Bible Database')
|
||||
log.debug('...............................Books ')
|
||||
books = self.session.query(Book).all()
|
||||
log.debug(books)
|
||||
log.debug( u'...............................Verses ')
|
||||
log.debug(u'...............................Verses ')
|
||||
verses = self.session.query(Verse).all()
|
||||
log.debug(verses)
|
||||
|
||||
|
@ -250,12 +250,12 @@ class BibleManager(object):
|
||||
Returns all the number of verses for a given
|
||||
book and chapterMaxBibleBookVerses
|
||||
"""
|
||||
log.debug(u'get_verses_from_text %s,%s', bible, versetext)
|
||||
log.debug(u'get_verses_from_text %s, %s', bible, versetext)
|
||||
reflist = parse_reference(versetext)
|
||||
web_index = bible.find('(%s)' % self.web)
|
||||
if web_index >= 0:
|
||||
bible = bible[:web_index - 1]
|
||||
log.debug('Updated bible name: %s', bible)
|
||||
#web_index = bible.find('(%s)' % self.web)
|
||||
#if web_index >= 0:
|
||||
# bible = bible[:web_index - 1]
|
||||
# log.debug('Updated bible name: %s', bible)
|
||||
#web, bible = self.is_bible_web(bible)
|
||||
#if web:
|
||||
# return self.http_cache[bible].get_verses(reflist)
|
||||
|
Loading…
Reference in New Issue
Block a user