示例#1
0
async def test_query_entities(data_file, object_type, attributes,
                              expected_length):
    knowledge_base = InMemoryKnowledgeBase(data_file)

    entities = await knowledge_base.get_objects(object_type=object_type,
                                                attributes=attributes)
    assert expected_length == len(entities)
示例#2
0
    def __init__(self):
        knowledge_base = InMemoryKnowledgeBase(
            basedir + '/data/knowledge_base_data.json')
        knowledge_base.set_representation_function_of_object(
            "hotel", lambda obj: obj["name"] + " (" + obj["city"] + ")")

        super().__init__(knowledge_base)
示例#3
0
文件: actions.py 项目: Ibabot/Iba
    def __init__(self):
        knowledge_base = InMemoryKnowledgeBase("./actions/bank_data.json")
        knowledge_base.set_representation_function_of_object(
            "bank", lambda obj: obj["name"] + ", " + obj["google_location"] +
            " (" + obj["location"] + ")")

        super().__init__(knowledge_base)
示例#4
0
async def test_get_attributes_for(data_file, object_type, expected_attributes):
    knowledge_base = InMemoryKnowledgeBase(data_file)

    actual_attributes = await knowledge_base.get_attributes_of_object(
        object_type=object_type)

    assert set(expected_attributes) == set(actual_attributes)
示例#5
0
async def test_query_object(data_file, object_type, object_identifier,
                            expected_value):
    knowledge_base = InMemoryKnowledgeBase(data_file)

    actual_value = await knowledge_base.get_object(
        object_type=object_type, object_identifier=object_identifier)

    assert expected_value == actual_value
示例#6
0
    def __init__(self):
        knowledge_base = InMemoryKnowledgeBase("knowledge_base_data.json")

        knowledge_base.set_representation_function_of_object(
            "rationing", lambda obj: obj["Location"] + " " + "(" + obj["Zone"]
            + " - " + obj["day"] + ")")

        super().__init__(knowledge_base)
示例#7
0
    def __init__(self):
        # load knowledge base with data from the given file
        knowledge_base = InMemoryKnowledgeBase("knowledge_base_data.json")

        # overwrite the representation function of the hotel object
        # by default the representation function is just the name of the object
        knowledge_base.set_representation_function_of_object(
            "hotel", lambda obj: obj["name"] + " (" + obj["city"] + ")")

        super().__init__(knowledge_base)
示例#8
0
    def __init__(self):
        # load knowledge base with data from the given file
        knowledge_base = InMemoryKnowledgeBase("dataset/knowledge_data.json")

        # overwrite the representation function of the hotel object
        # by default the representation function is just the name of the object
        knowledge_base.set_representation_function_of_object(
            "movie", lambda obj:
            '%s (Visit https://www.imdb.com/title/tt{%07d}) for more details.'
            % (obj["name"], obj['imdb']))
        super(ActionMyKB, self).__init__(knowledge_base)
示例#9
0
async def test_key_attribute_of_object(data_file, object_type,
                                       set_key_attribute,
                                       expected_key_attribute):
    knowledge_base = InMemoryKnowledgeBase(data_file)
    if set_key_attribute:
        knowledge_base.set_key_attribute_of_object(object_type,
                                                   set_key_attribute)

    actual_key_attribute = await knowledge_base.get_key_attribute_of_object(
        object_type=object_type)

    assert expected_key_attribute == actual_key_attribute
示例#10
0
def test_action_run(data_file, slots, expected_slots):
    knowledge_base = InMemoryKnowledgeBase(data_file)
    action = ActionQueryKnowledgeBase(knowledge_base)

    dispatcher = CollectingDispatcher()
    tracker = Tracker("default", slots, {}, [], False, None, {},
                      "action_listen")

    actual_slots = action.run(dispatcher, tracker, {})

    compare_slots(expected_slots, actual_slots)
    compare_slots(actual_slots, expected_slots)
示例#11
0
def test_action_run(data_file, slots, expected_slots):
    knowledge_base = InMemoryKnowledgeBase(data_file)
    action = ActionQueryKnowledgeBase(knowledge_base)

    dispatcher = CollectingDispatcher()
    tracker = Tracker("default", slots, {}, [], False, None, {},
                      "action_listen")

    loop = asyncio.new_event_loop()
    actual_slots = loop.run_until_complete(action.run(dispatcher, tracker, {}))
    loop.close()

    compare_slots(expected_slots, actual_slots)
    compare_slots(actual_slots, expected_slots)
示例#12
0
async def test_get_representation_function_of_object(data_file, object_type,
                                                     set_repr_function,
                                                     expected_repr_function):
    knowledge_base = InMemoryKnowledgeBase(data_file)
    if set_repr_function:
        knowledge_base.set_representation_function_of_object(
            object_type, set_repr_function)

    actual_repr_function = await knowledge_base.get_representation_function_of_object(
        object_type=object_type)

    dummy_object = await knowledge_base.get_object(object_type, 1)

    assert expected_repr_function(dummy_object) == actual_repr_function(
        dummy_object)
示例#13
0
 def __init__(self):
     # load knowledge base with data from the given file
     knowledge_base = InMemoryKnowledgeBase("./data/data_chat.json")
     super().__init__(knowledge_base)
示例#14
0
 def __init__(self):
     knowledge_base = InMemoryKnowledgeBase("maori_knowledge_base.json")
     super().__init__(knowledge_base)
示例#15
0
    def __init__(self):
        knowledge_base = InMemoryKnowledgeBase("data.json")
        super().__init__(knowledge_base)

        self.en_to_zh = EnToZh("en_to_zh.json")
示例#16
0
 def __init__(self):
     knowledge_base = InMemoryKnowledgeBase("data/pokemondb.json")
     super().__init__(knowledge_base)
示例#17
0
	def __init__(self):
		knowledge_base = InMemoryKnowledgeBase("knowledge_base_data.json")
	
		super().__init__(knowledge_base)