當前位置: 首頁>>代碼示例>>Python>>正文


Python schema.schema方法代碼示例

本文整理匯總了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 
開發者ID:RasaHQ,項目名稱:tutorial-knowledge-base,代碼行數:41,代碼來源:actions.py

示例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 
開發者ID:RasaHQ,項目名稱:tutorial-knowledge-base,代碼行數:11,代碼來源:actions.py

示例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 
開發者ID:RasaHQ,項目名稱:tutorial-knowledge-base,代碼行數:11,代碼來源:actions.py

示例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 
開發者ID:RasaHQ,項目名稱:tutorial-knowledge-base,代碼行數:41,代碼來源:actions.py

示例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') 
開發者ID:graphql-python,項目名稱:graphql-ws,代碼行數:6,代碼來源:app.py


注:本文中的schema.schema方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。