本文整理汇总了Python中schema.schema方法的典型用法代码示例。如果您正苦于以下问题:Python schema.schema方法的具体用法?Python schema.schema怎么用?Python schema.schema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schema
的用法示例。
在下文中一共展示了schema.schema方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_entity_name
# 需要导入模块: import schema [as 别名]
# 或者: from schema import schema [as 别名]
def get_entity_name(tracker: Tracker, entity_type: Text):
"""
Get the name of the entity the user referred to. Either the NER detected the
entity and stored its name in the corresponding slot or the user referred to
the entity by an ordinal number, such as first or last, or the user refers to
an entity by its attributes.
:param tracker: Tracker
:param entity_type: the entity type
:return: the name of the actual entity (value of key attribute in the knowledge base)
"""
# user referred to an entity by an ordinal number
mention = tracker.get_slot("mention")
if mention is not None:
return resolve_mention(tracker)
# user named the entity
entity_name = tracker.get_slot(entity_type)
if entity_name:
return entity_name
# user referred to an entity by its attributes
listed_items = tracker.get_slot("listed_items")
attributes = get_attributes_of_entity(entity_type, tracker)
if listed_items and attributes:
# filter the listed_items by the set attributes
graph_database = GraphDatabase()
for entity in listed_items:
key_attr = schema[entity_type]["key"]
result = graph_database.validate_entity(
entity_type, entity, key_attr, attributes
)
if result is not None:
return to_str(result, key_attr)
return None
示例2: get_attributes_of_entity
# 需要导入模块: import schema [as 别名]
# 或者: from schema import schema [as 别名]
def get_attributes_of_entity(entity_type, tracker):
# check what attributes the NER found for entity type
attributes = []
if entity_type in schema:
for attr in schema[entity_type]["attributes"]:
attr_val = tracker.get_slot(attr.replace("-", "_"))
if attr_val is not None:
attributes.append({"key": attr, "value": attr_val})
return attributes
示例3: reset_attribute_slots
# 需要导入模块: import schema [as 别名]
# 或者: from schema import schema [as 别名]
def reset_attribute_slots(slots, entity_type, tracker):
# check what attributes the NER found for entity type
if entity_type in schema:
for attr in schema[entity_type]["attributes"]:
attr = attr.replace("-", "_")
attr_val = tracker.get_slot(attr)
if attr_val is not None:
slots.append(SlotSet(attr, None))
return slots
示例4: run
# 需要导入模块: import schema [as 别名]
# 或者: from schema import schema [as 别名]
def run(self, dispatcher, tracker, domain):
graph_database = GraphDatabase()
# get entity type of entity
entity_type = get_entity_type(tracker)
if entity_type is None:
dispatcher.utter_template("utter_rephrase", tracker)
return []
# get name of entity and attribute of interest
name = get_entity_name(tracker, entity_type)
attribute = get_attribute(tracker)
if name is None or attribute is None:
dispatcher.utter_template("utter_rephrase", tracker)
slots = [SlotSet("mention", None)]
reset_attribute_slots(slots, entity_type, tracker)
return slots
# query knowledge base
key_attribute = schema[entity_type]["key"]
value = graph_database.get_attribute_of(
entity_type, key_attribute, name, attribute
)
# utter response
if value is not None and len(value) == 1:
dispatcher.utter_message(
f"{name} has the value '{value[0]}' for attribute '{attribute}'."
)
else:
dispatcher.utter_message(
f"Did not found a valid value for attribute {attribute} for entity '{name}'."
)
slots = [SlotSet("mention", None), SlotSet(entity_type, name)]
reset_attribute_slots(slots, entity_type, tracker)
return slots
示例5: init_graphql
# 需要导入模块: import schema [as 别名]
# 或者: from schema import schema [as 别名]
def init_graphql(app, loop):
app.add_route(GraphQLView.as_view(schema=schema,
executor=AsyncioExecutor(loop=loop)),
'/graphql')