def test_long_term_memory_can_save_multiple_relations_with_different_categories_correctly(self):
        long_term_memory = LongTermMemoryService()
        paris_city_object = CityObject("Paris")
        london_city_object = CityObject("London")
        north_cardinal_relation = NorthCardinalRelation()      
        france_country_object = CountryObject("France")
        part_of_topological_relation = PartOfTopologicalRelation()
        cairo_city_object = CityObject("Cairo")
        south_cardinal_relation = SouthCardinalRelation()

        long_term_memory.save_knowledge_fragment(north_cardinal_relation, [london_city_object, paris_city_object])
        long_term_memory.save_knowledge_fragment(part_of_topological_relation, [paris_city_object, france_country_object])
        long_term_memory.save_knowledge_fragment(south_cardinal_relation, [cairo_city_object, paris_city_object])

        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][0].objects[0], "London")
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][0].objects[1], "Paris")
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][0].time_of_creation, 1)
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][0].amount_of_usages, 1)
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][1].objects[0], "Cairo")
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][1].objects[1], "Paris")
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][1].time_of_creation, 3)
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][1].amount_of_usages, 1)
        self.assertEqual(long_term_memory.stored_relations[RelationType.TopologicalRelation][0].objects[0], "Paris")
        self.assertEqual(long_term_memory.stored_relations[RelationType.TopologicalRelation][0].objects[1], "France")
        self.assertEqual(long_term_memory.stored_relations[RelationType.TopologicalRelation][0].time_of_creation, 2)
        self.assertEqual(long_term_memory.stored_relations[RelationType.TopologicalRelation][0].amount_of_usages, 1)
        self.assertEqual(long_term_memory.stored_objects["Paris"].stored_object, paris_city_object)
        self.assertEqual(long_term_memory.stored_objects["Paris"].time_of_creation, 1)
        self.assertEqual(long_term_memory.stored_objects["Paris"].amount_of_usages, 3)
        self.assertEqual(long_term_memory.stored_objects["Paris"].relation_links[0][0], RelationType.CardinalRelation)
        self.assertEqual(long_term_memory.stored_objects["Paris"].relation_links[0][1], 0)
        self.assertEqual(long_term_memory.stored_objects["Paris"].relation_links[1][0], RelationType.TopologicalRelation)
        self.assertEqual(long_term_memory.stored_objects["Paris"].relation_links[1][1], 0)
        self.assertEqual(long_term_memory.stored_objects["Paris"].relation_links[2][0], RelationType.CardinalRelation)
        self.assertEqual(long_term_memory.stored_objects["Paris"].relation_links[2][1], 1)
    def test_long_term_memory_can_save_multiple_relations_with_equal_category_correctly(self):
        long_term_memory = LongTermMemoryService()
        paris_city_object = CityObject("Paris")
        london_city_object = CityObject("London")
        north_cardinal_relation = NorthCardinalRelation()
        cairo_city_object = CityObject("Cairo")
        south_cardinal_relation = SouthCardinalRelation()

        long_term_memory.save_knowledge_fragment(north_cardinal_relation, [london_city_object, paris_city_object])
        long_term_memory.save_knowledge_fragment(south_cardinal_relation, [cairo_city_object, paris_city_object])

        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][0].relation.name, CardinalRelationName.North)
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][0].objects[0], "London")
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][0].objects[1], "Paris")
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][0].time_of_creation, 1)
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][0].amount_of_usages, 1)
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][1].relation.name, CardinalRelationName.South)
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][1].objects[0], "Cairo")
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][1].objects[1], "Paris")
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][1].time_of_creation, 2)
        self.assertEqual(long_term_memory.stored_relations[RelationType.CardinalRelation][1].amount_of_usages, 1)
        self.assertEqual(long_term_memory.stored_objects["Paris"].time_of_creation, 1)
        self.assertEqual(long_term_memory.stored_objects["Paris"].amount_of_usages, 2)
        self.assertEqual(long_term_memory.stored_objects["Paris"].relation_links[0], (RelationType.CardinalRelation, 0))
        self.assertEqual(long_term_memory.stored_objects["Paris"].relation_links[1], (RelationType.CardinalRelation, 1))
示例#3
0
    def test_use_relation_for_smm_if_suitable_smm_exists_in_wm_and_relation_is_incomplete_for_first_object(
            self):
        working_memory = WorkingMemoryService()
        relation = StoredRelation(NorthCardinalRelation(), ["London", "Paris"],
                                  1)
        relation.objects_received[0] = False

        smm1 = SpatialMentalModel()
        smm1.east = "Berlin"
        smm1.middle = "Paris"
        smm2 = SpatialMentalModel()
        smm2.south = "Freiburg"
        smm2.middle = "Paris"
        working_memory.stored_spatial_mental_models = [smm1, smm2]
        working_memory.use_relation_for_smm(relation)
        actual_smm_list = working_memory.stored_spatial_mental_models

        self.assertEquals(len(actual_smm_list), 3)
        self.assertEqual(actual_smm_list[0].east, "Berlin")
        self.assertEqual(actual_smm_list[0].middle, "Paris")
        self.assertEqual(actual_smm_list[0].north, None)
        self.assertEqual(actual_smm_list[1].north, None)
        self.assertEqual(actual_smm_list[1].middle, "Paris")
        self.assertEqual(actual_smm_list[1].south, "Freiburg")
        self.assertEqual(actual_smm_list[2].north, None)
        self.assertEqual(actual_smm_list[2].middle, "Paris")
        self.assertEqual(actual_smm_list[2].south, None)
    def test_save_knowledge_fragment_calling_the_correct_methods(
            self, mock_save_knowledge_fragment):
        casimir_simulation = CasimirSimulation(app)
        relation_to_save = NorthCardinalRelation()
        object1_to_save = MiscellaneousObject("A")
        object2_to_save = MiscellaneousObject("B")

        casimir_simulation.save_knowledge_fragment(
            relation_to_save, [object1_to_save, object2_to_save])

        mock_save_knowledge_fragment.assert_has_calls(
            [call(relation_to_save, [object1_to_save, object2_to_save])])
示例#5
0
    def test_create_smm_for_complete_cardinal_relation(self):
        working_memory = WorkingMemoryService()
        relation = StoredRelation(NorthCardinalRelation(),
                                  ["Hamburg", "Freiburg"], 1)

        working_memory.create_new_smm(relation)
        actual_smm_list = working_memory.stored_spatial_mental_models

        self.assertEquals(len(actual_smm_list), 1)
        self.assertEqual(actual_smm_list[0].north, "Hamburg")
        self.assertEqual(actual_smm_list[0].middle, "Freiburg")
        self.assertEqual(actual_smm_list[0].south, None)
示例#6
0
    def test_multiple_use_relation_for_smm_if_suitable_smm_exists_in_wm_and_relation_is_complete(
            self):
        working_memory = WorkingMemoryService()
        relation = StoredRelation(NorthCardinalRelation(), ["London", "Paris"],
                                  1)
        relation2 = StoredRelation(SouthWestCardinalRelation(),
                                   ["Madrid", "Paris"], 1)

        smm = SpatialMentalModel()
        smm.east = "Berlin"
        smm.middle = "Paris"
        working_memory.stored_spatial_mental_models = [smm]
        working_memory.use_relation_for_smm(relation)
        working_memory.use_relation_for_smm(relation2)
        actual_smm_list = working_memory.stored_spatial_mental_models

        self.assertEquals(len(actual_smm_list), 1)
        self.assertEqual(actual_smm_list[0].east, "Berlin")
        self.assertEqual(actual_smm_list[0].south_west, "Madrid")
        self.assertEqual(actual_smm_list[0].middle, "Paris")
        self.assertEqual(actual_smm_list[0].north, "London")
示例#7
0
 def test_north_cardinal_relation_is_initialized_correctly(self):
     north_relation = NorthCardinalRelation()
     self.assertEqual(north_relation.name, CardinalRelationName.North)
     self.assertEqual(north_relation.relation_type,
                      RelationType.CardinalRelation)
     self.assertEqual(north_relation.amount_of_objects, 2)