本文整理匯總了Python中utils.Timer.check_expired方法的典型用法代碼示例。如果您正苦於以下問題:Python Timer.check_expired方法的具體用法?Python Timer.check_expired怎麽用?Python Timer.check_expired使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utils.Timer
的用法示例。
在下文中一共展示了Timer.check_expired方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: search
# 需要導入模塊: from utils import Timer [as 別名]
# 或者: from utils.Timer import check_expired [as 別名]
def search(dbfile, query, year=None, size=5, debug=False, timeout=None):
"""Search the database for query, optionally with an estimated year."""
this_year = date.today().year
if year:
year = int(year)
words = query.split()
timer = Timer(timeout=timeout)
results = _search_index(timer, dbfile, words, size, year=year, debug=debug)
# Similar to diffutils.get_close_matches, but ignores capitalization
# and IMDb suffixes.
scores = {}
akascores = {}
cutoff = 0.6
lcquery = query.lower()
matchers = [(1.0, SequenceMatcher(b=lcquery))]
if year:
yearstr = ' ('+str(year)
if yearstr not in lcquery:
matchers.append((1.0, SequenceMatcher(b=lcquery+yearstr+')')))
for title, ryear, akafor, nratings in results:
titles = [(1.0, title.lower()),
(1.0, parsers.TITLERE.match(title).group('name').lower())]
# Try matching without the subtitle. But only do this if the query
# included a year, since otherwise "ABC (1991)" and "ABC: Revenge
# of the DEF (1999)" rank the same. We exact a 95% penalty against
# matches that occur this way.
if year and ':' in titles[-1][1]:
titles.append((0.95, titles[-1][1][0:titles[-1][1].find(':')]))
# Take highest score from all matches checked
score = 0
mycutoff = cutoff
# Match against query with and without year
for matcherpenalty, matcher in matchers:
# Check titile both with and without the suffix
for titlepenalty, mystr in titles:
matcher.set_seq1(mystr)
if matcher.real_quick_ratio() > mycutoff and \
matcher.quick_ratio() > mycutoff:
myratio = matcher.ratio()*matcherpenalty*titlepenalty
if myratio > mycutoff:
score = max(score, myratio)
mycutoff = score
# If the movie scored at all, add it to the result list
if score > 0:
timer.check_expired()
nratings = int(nratings)
stored_title = akafor if akafor else title
# Weight score by the number of ratings
factor = (0.0205376)*nratings**(0.167496)+(0.9226)
# Slightly discourage TV shows in favor of movies. This
# makes it more difficult to match mini-series, but that's
# just too bad.
if stored_title[0] == '"':
factor *= 0.95
# Movies without a known year are extremely unlikely to be the
# correct result.
if not ryear:
factor *= 0.90
elif year: # and ryear
ryear = int(ryear)
if year == this_year and ryear == this_year:
# Extend the benefit of the doubt to prerelease movies
# (and others from this year) that have not had many
# votes on IMDb.
factor = max(factor, 1)
# Adjust weight to disambiguate results by year-similarity
factor *= exp(-(year-ryear)**2/160.0)
score *= factor
if stored_title not in scores or scores[stored_title] < score:
scores[stored_title] = score
if akafor:
akascores[stored_title] = title
elif stored_title in akascores:
del akascores[stored_title]
return scores, akascores