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:
Raoul Snyman 2010-02-04 21:34:12 +02:00
parent e465264630
commit ce6738a976
3 changed files with 20 additions and 13 deletions

View File

@ -28,13 +28,15 @@ import chardet
import logging import logging
import re 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))?)?', r'(?:[ ]*-[ ]*([0-9]+|end))?(?:[ ]*,[ ]*([0-9]+)(?:[ ]*-[ ]*([0-9]+|end))?)?',
re.UNICODE) 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]+)', r'([0-9]+)[ ]*-[ ]*([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)',
re.UNICODE) re.UNICODE)
log = logging.getLogger(__name__)
def parse_reference(reference): def parse_reference(reference):
""" """
This is the über-awesome function that takes a person's typed in string 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) (book, chapter, start_verse, end_verse)
""" """
reference = reference.strip() reference = reference.strip()
log.debug('parse_reference("%s")', reference)
reference_list = [] reference_list = []
# We start with the most "complicated" match first, so that they are found # We start with the most "complicated" match first, so that they are found
# first, and we don't have any "false positives". # first, and we don't have any "false positives".
match = chapter_range.match(reference) match = chapter_range.match(reference)
if match: if match:
log.debug('Found a chapter range.')
reference_list.extend([ reference_list.extend([
(match.group(1), match.group(2), match.group(3), -1), (match.group(1), match.group(2), match.group(3), -1),
(match.group(1), match.group(4), 1, match.group(5)) (match.group(1), match.group(4), 1, match.group(5))
@ -59,6 +63,7 @@ def parse_reference(reference):
else: else:
match = only_verses.match(reference) match = only_verses.match(reference)
if match: if match:
log.debug('Found a verse range.')
book = match.group(1) book = match.group(1)
chapter = match.group(2) chapter = match.group(2)
verse = match.group(3) verse = match.group(3)
@ -82,6 +87,8 @@ def parse_reference(reference):
(book, chapter, verse, match.group(4)), (book, chapter, verse, match.group(4)),
(book, chapter, match.group(5), end_verse) (book, chapter, match.group(5), end_verse)
]) ])
else:
log.debug('Didn\'t find anything.')
return reference_list return reference_list
class SearchResults: class SearchResults:

View File

@ -157,7 +157,7 @@ class BibleDB(QtCore.QObject):
return self.session.query(Book).order_by(Book.id).all() return self.session.query(Book).order_by(Book.id).all()
def get_book(self, book): 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)\ db_book = self.session.query(Book)\
.filter(Book.name.like(book + u'%'))\ .filter(Book.name.like(book + u'%'))\
.first() .first()
@ -200,7 +200,7 @@ class BibleDB(QtCore.QObject):
end_verse = self.get_chapter_count(book) end_verse = self.get_chapter_count(book)
if db_book: if db_book:
book = db_book.name 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)\ verses = self.session.query(Verse)\
.filter_by(book_id=db_book.id)\ .filter_by(book_id=db_book.id)\
.filter_by(chapter=chapter)\ .filter_by(chapter=chapter)\
@ -276,11 +276,11 @@ class BibleDB(QtCore.QObject):
return False return False
def dump_bible(self): def dump_bible(self):
log.debug( u'.........Dumping Bible Database') log.debug(u'.........Dumping Bible Database')
log.debug( '...............................Books ') log.debug('...............................Books ')
books = self.session.query(Book).all() books = self.session.query(Book).all()
log.debug(books) log.debug(books)
log.debug( u'...............................Verses ') log.debug(u'...............................Verses ')
verses = self.session.query(Verse).all() verses = self.session.query(Verse).all()
log.debug(verses) log.debug(verses)

View File

@ -250,12 +250,12 @@ class BibleManager(object):
Returns all the number of verses for a given Returns all the number of verses for a given
book and chapterMaxBibleBookVerses 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) reflist = parse_reference(versetext)
web_index = bible.find('(%s)' % self.web) #web_index = bible.find('(%s)' % self.web)
if web_index >= 0: #if web_index >= 0:
bible = bible[:web_index - 1] # bible = bible[:web_index - 1]
log.debug('Updated bible name: %s', bible) # log.debug('Updated bible name: %s', bible)
#web, bible = self.is_bible_web(bible) #web, bible = self.is_bible_web(bible)
#if web: #if web:
# return self.http_cache[bible].get_verses(reflist) # return self.http_cache[bible].get_verses(reflist)