本文整理汇总了Python中query.Query.key方法的典型用法代码示例。如果您正苦于以下问题:Python Query.key方法的具体用法?Python Query.key怎么用?Python Query.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类query.Query
的用法示例。
在下文中一共展示了Query.key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_query
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import key [as 别名]
def process_query(session, toklist, result):
""" Check whether the parse tree is describes a query, and if so, execute the query,
store the query answer in the result dictionary and return True """
q = Query(session)
if not q.parse(toklist, result):
# if Settings.DEBUG:
# print("Unable to parse query, error {0}".format(q.error()))
result["error"] = q.error()
return False
if not q.execute():
# This is a query, but its execution failed for some reason: return the error
# if Settings.DEBUG:
# print("Unable to execute query, error {0}".format(q.error()))
result["error"] = q.error()
return True
# Successful query: return the answer in response
result["response"] = q.answer()
# ...and the query type, as a string ('Person', 'Entity', 'Title' etc.)
result["qtype"] = qt = q.qtype()
result["key"] = q.key()
if qt == "Person":
# For a person query, add an image (if available)
img = get_image_url(q.key(), enclosing_session=session)
if img is not None:
result["image"] = dict(
src=img.src,
width=img.width,
height=img.height,
link=img.link,
origin=img.origin,
name=img.name,
)
return True