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))
    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_create_mental_image_without_recall(self):
        casimir_simulation = CasimirSimulation(app)
        casimir_simulation.MAX_AMOUNT_OF_RETRIES = 0
        paris_city_object = CityObject("Paris")
        prague_city_object = CityObject("Prague")
        london_city_object = CityObject("London")
        south_cardinal_relation = SouthCardinalRelation()
        east_cardinal_relation = EastCardinalRelation()
        casimir_simulation.save_knowledge_fragment(
            south_cardinal_relation, [paris_city_object, london_city_object])
        casimir_simulation.save_knowledge_fragment(
            east_cardinal_relation, [prague_city_object, paris_city_object])
        casimir_simulation.update_settings(-0.5, 0.6, 1, 0.1, True, 0.1, False,
                                           False, False, 0)

        created_spatial_mental_image = casimir_simulation.create_mental_image([
            RelationType.CardinalRelation, prague_city_object,
            london_city_object
        ])

        self.assertEqual(len(created_spatial_mental_image['smm']), 2)
        self.assertEqual(created_spatial_mental_image['smm'][0]['east'],
                         'Prague')
        self.assertEqual(created_spatial_mental_image['smm'][0]['middle'],
                         'Paris')
        self.assertEqual(created_spatial_mental_image['smm'][1]['west'],
                         'Paris')
        self.assertEqual(created_spatial_mental_image['smm'][1]['middle'],
                         'Prague')
    def test_create_mental_image_call_the_correct_methods(
            self, mock_receive_knowledge_fragments,
            mock_received_all_necessary_nodes):
        casimir_simulation = CasimirSimulation(app)
        casimir_simulation.MAX_AMOUNT_OF_RETRIES = 3
        paris_city_object = CityObject("Paris")
        prague_city_object = CityObject("Prague")
        london_city_object = CityObject("London")
        south_cardinal_relation = SouthCardinalRelation()
        east_cardinal_relation = EastCardinalRelation()
        casimir_simulation.save_knowledge_fragment(
            south_cardinal_relation, [paris_city_object, london_city_object])
        casimir_simulation.save_knowledge_fragment(
            east_cardinal_relation, [prague_city_object, paris_city_object])
        mock_receive_knowledge_fragments.side_effect = [
            KnowledgeSubnet(casimir_simulation.long_term_memory_controller.
                            long_term_memory_service.stored_relations[
                                RelationType.CardinalRelation][0]),
            KnowledgeSubnet(casimir_simulation.long_term_memory_controller.
                            long_term_memory_service.stored_relations[
                                RelationType.CardinalRelation][1])
        ]
        mock_received_all_necessary_nodes.side_effect = [False, True]

        casimir_simulation.create_mental_image(
            [CardinalRelation, [paris_city_object, london_city_object]])

        self.assertEqual(mock_received_all_necessary_nodes.call_count, 2)
Exemple #5
0
 def test_add_inter_cardinal_to_smm(self):
     working_memory = WorkingMemoryService()
     spatial_mental_model = SpatialMentalModel()
     spatial_mental_model.middle = "A"
     spatial_mental_model.north_east = "B"
     relation = StoredRelation(
         NorthWestCardinalRelation,
         [CityObject("C"), CityObject("A")], 0)
     working_memory.add_to_smm(spatial_mental_model, relation)
     self.assertEquals(spatial_mental_model.north_west.name, "C")
    def test_get_all_objects_names_in_context_array(self):
        casimir_simulation = CasimirSimulation(app)
        paris_city_object = CityObject("Paris")
        london_city_object = CityObject("London")
        context_array = [
            CardinalRelation, paris_city_object, london_city_object
        ]

        object_name_list = casimir_simulation._get_all_objects_names_in_context_array(
            context_array)
        self.assertEquals(object_name_list[0], "Paris")
        self.assertEquals(object_name_list[1], "London")
 def create_long_term_memory_based_on_papers_example(self):
     long_term_memory = LongTermMemoryService()
     long_term_memory.paris_city_object = CityObject("Paris")
     long_term_memory.prague_city_object = CityObject("Prague")
     long_term_memory.london_city_object = CityObject("London")
     long_term_memory.france_country_object = CountryObject("France")
     long_term_memory.england_country_object = CountryObject("England")
     long_term_memory.south_cardinal_relation = SouthCardinalRelation()
     long_term_memory.east_cardinal_relation = EastCardinalRelation()
     long_term_memory.part_of_topological_relation = PartOfTopologicalRelation()
     
     long_term_memory.save_knowledge_fragment(long_term_memory.part_of_topological_relation, [long_term_memory.paris_city_object, long_term_memory.france_country_object])
     long_term_memory.save_knowledge_fragment(long_term_memory.part_of_topological_relation, [long_term_memory.london_city_object, long_term_memory.england_country_object])
     long_term_memory.save_knowledge_fragment(long_term_memory.south_cardinal_relation, [long_term_memory.paris_city_object, long_term_memory.london_city_object])
     long_term_memory.save_knowledge_fragment(long_term_memory.east_cardinal_relation, [long_term_memory.prague_city_object, long_term_memory.paris_city_object])
     
     return long_term_memory
    def test_create_mental_image_with_only_one_relation_receive_just_complete_fragments(
            self):
        casimir_simulation = CasimirSimulation(app)
        casimir_simulation.MAX_AMOUNT_OF_RETRIES = 0
        paris_city_object = CityObject("Paris")
        london_city_object = CityObject("London")
        south_cardinal_relation = SouthCardinalRelation()
        casimir_simulation.save_knowledge_fragment(
            south_cardinal_relation, [paris_city_object, london_city_object])
        casimir_simulation.update_settings(-0.5, 0.6, 1, 0.1, True, 0.1, False,
                                           False, True, 0)

        created_spatial_mental_image = casimir_simulation.create_mental_image([
            RelationType.CardinalRelation, paris_city_object,
            london_city_object
        ])

        self.assertEqual(len(created_spatial_mental_image['smm']), 0)
    def test_received_all_necessary_nodes_should_return_true(self):
        casimir_simulation = CasimirSimulation(app)
        paris_city_object = CityObject("Paris")
        prague_city_object = CityObject("Prague")
        london_city_object = CityObject("London")
        south_cardinal_relation = SouthCardinalRelation()
        east_cardinal_relation = EastCardinalRelation()
        casimir_simulation.save_knowledge_fragment(
            south_cardinal_relation, [paris_city_object, london_city_object])
        casimir_simulation.save_knowledge_fragment(
            east_cardinal_relation, [prague_city_object, paris_city_object])
        objects_to_receive = ["Paris", "London"]
        knowledge_subnet = KnowledgeSubnet(
            casimir_simulation.long_term_memory_controller.
            long_term_memory_service.stored_objects["Paris"])
        knowledge_subnet.objects["London"] = london_city_object

        self.assertTrue(
            casimir_simulation._received_all_necessary_nodes(
                objects_to_receive, knowledge_subnet))
Exemple #10
0
 def test_city_object_is_initialized_correctly(self):
     city_object = CityObject("Berlin")
     self.assertEqual(city_object.object_type, ObjectType.City)
     self.assertEqual(city_object.name, "Berlin")