本文整理汇总了Python中search.Search.list_similar_to_terms方法的典型用法代码示例。如果您正苦于以下问题:Python Search.list_similar_to_terms方法的具体用法?Python Search.list_similar_to_terms怎么用?Python Search.list_similar_to_terms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类search.Search
的用法示例。
在下文中一共展示了Search.list_similar_to_terms方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: launch_search
# 需要导入模块: from search import Search [as 别名]
# 或者: from search.Search import list_similar_to_terms [as 别名]
def launch_search(query, session, qkey):
""" Launch a search with the given search terms """
pgs, stats = TreeUtility.raw_tag_toklist(
session, query.token_list(), root=_QUERY_ROOT
)
# Collect the list of search terms
terms = []
tweights = []
fixups = []
for pg in pgs:
for sent in pg:
for t in sent:
# Obtain search stems for the tokens.
d = dict(x=t["x"], w=0.0)
tweights.append(d)
# The terms are represented as (stem, category) tuples.
stems = stems_of_token(t)
if stems:
terms.extend(stems)
fixups.append((d, len(stems)))
assert sum(n for _, n in fixups) == len(terms)
if Settings.DEBUG:
print("Terms are:\n {0}".format(terms))
# Launch the search and return the answers, as well as the
# search terms augmented with information about
# whether and how they were used
result = Search.list_similar_to_terms(session, terms, _MAXLEN_SEARCH)
weights = result["weights"]
assert len(weights) == len(terms)
# Insert the weights at the proper places in the
# token weight list
index = 0
for d, n in fixups:
d["w"] = sum(weights[index : index + n]) / n
index += n
return dict(answers=result["articles"], weights=tweights)