Exemplo n.º 1
0
class TestMovingToLondonScenario(unittest.TestCase):
    """
    Scenario
    --------
    ACHILLE and JULIE are moving from Toulouse to London, and they must
    pack everything before leaving. ACHILLE is sorting its video tapes, and he 
    throws away the oldest ones. Jido is watching him.

    Setup:
      One trashbin, one cardboard box, 2 tapes on the table [TAPE1 = Lord of 
      the Robots (lotr) and TAPE2 = JIDO-E].
    
    Complete scenario here:
    http://homepages.laas.fr/slemaign/wiki/doku.php?id=scenario_demo_roman
    """
    def setUp(self):
        self.dialog = Dialog()
        self.dialog.start()

        self.oro = ResourcePool().ontology_server

        try:

            self.oro.add([
                'ACHILLE rdf:type Human',
                'ACHILLE rdfs:label Achille',
                'JULIE rdf:type Human',
                'JULIE rdfs:label Julie',
                'TABLE rdf:type Table',
                'Trashbin rdfs:subClassOf Box',
                'CardBoardBox rdfs:subClassOf Box',
                'CardBoardBox rdfs:label "cardboard box"',
                'TRASHBIN rdf:type Trashbin',
                'CARDBOARD_BOX rdf:type CardBoardBox',
                'CARDBOARD_BOX isOn TABLE',
                'TAPE1 rdf:type VideoTape',
                'TAPE1 rdfs:label "The Lords of the robots"',
                'TAPE1 isOn TABLE',
                'TAPE2 rdf:type VideoTape',
                'TAPE2 rdfs:label "Jido-E"',
                'TAPE2 isOn TABLE',
                'VideoTape owl:equivalentClass Tape',
                'TAPE1 owl:differentFrom TAPE2',
            ])
            """           
            self.oro.addForAgent('ACHILLE',
                        ['BLUE_TRASHBIN rdf:type Trashbin',
                        'PINK_TRASHBIN rdf:type Trashbin',
                        'BLACK_TAPE rdf:type VideoTape', 'BLACK_TAPE isIn PINK_TRASHBIN',
                        'GREY_TAPE rdf:type VideoTape', 'GREY_TAPE isOn HRP2TABLE'])
            """
        except AttributeError:  #the ontology server is not started of doesn't know the method
            print(
                "Couldn't connect to the ontology server. Aborting the test.")
            raise

        try:
            self.oro.addForAgent('ACHILLE', [
                'ACHILLE rdf:type Human',
                'ACHILLE rdfs:label Achille',
                'JULIE rdf:type Human',
                'JULIE rdfs:label Julie',
                'TABLE rdf:type Table',
                'Trashbin rdfs:subClassOf Box',
                'CardBoardBox rdfs:subClassOf Box',
                'CardBoardBox rdfs:label "cardboard box"',
                'TRASHBIN rdf:type Trashbin',
                'CARDBOARD_BOX rdf:type CardBoardBox',
                'CARDBOARD_BOX isOn TABLE',
                'TAPE1 rdf:type VideoTape',
                'TAPE1 rdfs:label "The Lords of the robots"',
                'TAPE1 isOn TABLE',
                'TAPE2 rdf:type VideoTape',
                'TAPE2 rdfs:label "Jido-E"',
                'TAPE2 isOn TABLE',
                'VideoTape owl:equivalentClass Tape',
                'TAPE1 owl:differentFrom TAPE2',
            ])
        except AttributeError:  #the ontology server is not started of doesn't know the method
            print(
                "Couldn't connect to the ontology server. Aborting the test.")
            raise

        try:
            self.oro.addForAgent('JULIE', [
                'ACHILLE rdf:type Human',
                'ACHILLE rdfs:label Achille',
                'JULIE rdf:type Human',
                'JULIE rdfs:label Julie',
                'TABLE rdf:type Table',
                'Trashbin rdfs:subClassOf Box',
                'CardBoardBox rdfs:subClassOf Box',
                'CardBoardBox rdfs:label "cardboard box"',
                'TRASHBIN rdf:type Trashbin',
                'CARDBOARD_BOX rdf:type CardBoardBox',
                'CARDBOARD_BOX isOn TABLE',
                'TAPE1 rdf:type VideoTape',
                'TAPE1 rdfs:label "The Lords of the robots"',
                'TAPE1 isOn TABLE',
                'TAPE2 rdf:type VideoTape',
                'TAPE2 rdfs:label "Jido-E"',
                'TAPE2 isOn TABLE',
                'VideoTape owl:equivalentClass Tape',
                'TAPE1 owl:differentFrom TAPE2',
            ])
        except AttributeError:  #the ontology server is not started of doesn't know the method
            print(
                "Couldn't connect to the ontology server. Aborting the test.")
            raise

    def runTest(self):
        """ MOVING TO LONDON SCENARIO
        
        ACHILLE puts TAPE1 in CARDBOARDBOX"""

        print()
        self.oro.add(['TAPE1 isIn CARDBOARD_BOX'])
        self.oro.addForAgent('ACHILLE', ['ACHILLE pointsAt CARDBOARD_BOX'])

        stmt = "Jido, what is in the box?"
        answer = "This box"
        ####
        res = self.dialog.test('ACHILLE', stmt, answer)
        self.assertEquals(res[1][1], "The Lords of the robots.")

        self.oro.removeForAgent('ACHILLE', ['ACHILLE pointsAt CARDBOARD_BOX'])

        stmt = "Ok. And where is the other tape?"
        ####
        self.assertEquals(
            self.dialog.test('ACHILLE', stmt)[1][1],
            "The other tape is on the table.")

        stmt = "Ok. Thanks."
        self.assertEquals(
            self.dialog.test('ACHILLE', stmt)[1][1], "You're welcome.")
        """Julie arrives, and gives two big boxes to ACHILLE. He can not take anything!"""

        self.oro.update(['TAPE2 isReachable false'])

        stmt = "Jido, can you take Jido-E?"
        ####
        res = self.dialog.test('ACHILLE', stmt)

        expected_result = [
            'ACHILLE desires *', '* rdf:type Get', '* performedBy myself',
            '* actsOnObject TAPE2'
        ]

        self.assertTrue(check_results(res[0], expected_result))
        """Julie pushes a bit the TAPE2, which is now close enough, but still 
        unreachable because of an obstacle.
        """
        self.oro.addForAgent('ACHILLE', ['ACHILLE pointsAt TAPE2'])
        stmt = "And now, can you reach this tape?"
        ####
        ### Check ['myself reaches TAPE2']
        self.assertEquals(
            self.dialog.test('ACHILLE', stmt)[1][1],
            "I don't know, if I can reach this tape now.")
        self.oro.removeForAgent('ACHILLE', ['ACHILLE pointsAt TAPE2'])
        """Julie pushes again the tape. It is now reachable.
        """
        self.oro.update(['TAPE2 isReachable true'])

        stmt = "Jido, can you take it?"
        ####
        ### Do you mean Jido-E
        answer = "I mean Jido-E"
        ###
        res = self.dialog.test('JULIE', stmt, answer)
        expected_result = [
            'JULIE desires *', '* rdf:type Get', '* performedBy myself',
            '* actsOnObject TAPE2'
        ]

        self.assertTrue(check_results(res[0], expected_result))
        """Achille puts JIDO-E in the trashbin. Jido still observes. Achille 
        leaves. Julie finds JIDO-E in the trashbin, and takes it away. ACHILLE 
        comes back to the table.
        """

        print()
        self.oro.remove(['TAPE2 isOn TABLE'])
        self.oro.add(['TAPE2 isAt JULIE'])
        self.oro.addForAgent('ACHILLE', ['TAPE2 isIn TRASHBIN'])

        stmt = "Can you give me the tape in the trashbin?"
        #Expected intermediate question: "You mean, the JIDO-E tape?"
        #NOT FOR ROMAN demo!
        #answer = "Yes"
        ####
        res = self.dialog.test('ACHILLE', stmt)

        expected_result = [
            'ACHILLE desires *', '* rdf:type Give', '* performedBy myself',
            '* actsOnObject TAPE2', '* receivedBy ACHILLE'
        ]

        self.assertTrue(check_results(res[0], expected_result))

    def tearDown(self):
        self.dialog.stop()
        self.dialog.join()
Exemplo n.º 2
0
class TestQuestionHandlerScenarioMovingToLondon(unittest.TestCase):
    """Tests the processing of question by the Dialog module.
    This must be tested with oro-server using the testsuite.oro.owl ontology.
    """

    def setUp(self):
        self.dialog = Dialog()
        self.dialog.start()

        self.oro = ResourcePool().ontology_server

        try:

            self.oro.add(['ACHILLE rdf:type Human',
                          'ACHILLE rdfs:label Achille',
                          'JULIE rdf:type Human',
                          'JULIE rdfs:label Julie',
                          'table1 rdf:type Table',
                          'Trashbin rdfs:subClassOf Box',
                          'CardBoardBox rdfs:subClassOf Box',
                          'CardBoardBox rdfs:label "cardboard box"',
                          'TRASHBIN rdf:type Trashbin',
                          'CARDBOARD_BOX rdf:type CardBoardBox',
                          'CARDBOARD_BOX isOn table1',
                          'TAPE1 rdf:type VideoTape',
                          'TAPE1 rdfs:label "The Lords of the robots"',
                          'TAPE1 isOn table1',
                          'TAPE2 rdf:type VideoTape',
                          'TAPE2 rdfs:label "Jido-E"',
                          'TAPE2 isOn table1',

                          'VideoTape owl:equivalentClass Tape',
                          'TAPE1 owl:differentFrom TAPE2',
            ])
        except AttributeError:
            pass

        try:

            self.oro.addForAgent(ResourcePool().get_model_mapping('ACHILLE'),
                                 ['ACHILLE rdf:type Human',
                                  'ACHILLE rdfs:label Achille',
                                  'JULIE rdf:type Human',
                                  'JULIE rdfs:label Julie',
                                  'table1 rdf:type Table',
                                  'Trashbin rdfs:subClassOf Box',
                                  'CardBoardBox rdfs:subClassOf Box',
                                  'CardBoardBox rdfs:label "cardboard box"',
                                  'TRASHBIN rdf:type Trashbin',
                                  'CARDBOARD_BOX rdf:type CardBoardBox',
                                  'CARDBOARD_BOX isOn table1',
                                  'TAPE1 rdf:type VideoTape',
                                  'TAPE1 rdfs:label "The Lords of the robots"',
                                  'TAPE1 isOn table1',
                                  'TAPE2 rdf:type VideoTape',
                                  'TAPE2 rdfs:label "Jido-E"',
                                  'TAPE2 isOn table1',

                                  'VideoTape owl:equivalentClass Tape',

                                  'TAPE1 owl:differentFrom TAPE2',
                                 ])
        except AttributeError:
            pass

    def test1(self):

        self.oro.add(['TAPE1 isIn CARDBOARD_BOX'])
        self.oro.removeForAgent(ResourcePool().get_model_mapping('ACHILLE'), ['ACHILLE focusesOn TAPE2'])
        self.oro.addForAgent(ResourcePool().get_model_mapping('ACHILLE'), ['ACHILLE focusesOn CARDBOARD_BOX'])

        stmt = "Jido, what is in the box?"
        answer = "this box"
        ####
        self.assertEquals(self.dialog.test('ACHILLE', stmt, answer)[1][1], "The Lords of the robots.")


    def test2(self):
        #Fill in the history
        stmt = " the TAPE1 is in the CARDBOARD_BOX"
        self.dialog.test('ACHILLE', stmt)

        stmt = "Ok. And where is the other tape?"
        ####
        self.assertEquals(self.dialog.test('ACHILLE', stmt)[1][1], "Alright. The other tape is on the table.")

    def test3(self):
        stmt = "Ok thank you."
        self.assertIn(self.dialog.test('ACHILLE', stmt)[1][1], AGREEMENTS)

    def test3_2(self):
        stmt = "thank you."
        self.assertEquals(self.dialog.test('ACHILLE', stmt)[1][1], "You're welcome.")


    def test4(self):
        self.oro.update(['TAPE2 isReachable false'])

        stmt = "can you take Jido-E?"
        ####
        res = self.dialog.test('ACHILLE', stmt)

        expected_result = ['ACHILLE desires *',
                           '* rdf:type Get',
                           '* performedBy myself',
                           '* actsOnObject TAPE2']

        self.assertTrue(check_results(res[0], expected_result))
        self.assertIn(res[1][1], AGREEMENTS)

    def test_5(self):
        self.oro.update(['TAPE2 isReachable false'])

        stmt = "can you take Jido-E?"
        ####
        res = self.dialog.test('ACHILLE', stmt)

        expected_result = ['ACHILLE desires *',
                           '* rdf:type Get',
                           '* performedBy myself',
                           '* actsOnObject TAPE2']

        self.assertTrue(check_results(res[0], expected_result))
        self.assertIn(res[1][1], AGREEMENTS)

    def test_6(self):

        ###
        self.oro.removeForAgent(ResourcePool().get_model_mapping('ACHILLE'), ['ACHILLE focusesOn CARDBOARD_BOX'])
        self.oro.addForAgent(ResourcePool().get_model_mapping('ACHILLE'), ['ACHILLE focusesOn TAPE2'])
        stmt = "Jido, can you reach this tape?"
        ####
        ## expected to check['myself reaches TAPE2']
        self.assertEquals(self.dialog.test('ACHILLE', stmt)[1][1], "I don't know, if I can reach it.")


    def test_7(self):
        self.oro.update(['TAPE2 isReachable true'])
        #Feel history
        self.dialog.dialog_history = []
        stmt = "can you reach Jido-E?"
        res = self.dialog.test('ACHILLE', stmt)
        ###
        stmt = "can you take it?"
        ####
        answer = "yes"
        ###
        res = self.dialog.test('ACHILLE', stmt, answer)

        expected_result = ['ACHILLE desires *',
                           '* rdf:type Get',
                           '* performedBy myself',
                           '* actsOnObject TAPE2']

        self.assertTrue(check_results(res[0], expected_result))

    def test_8(self):
        ###
        stmt = "can you take the tape?"
        ####
        answer = "forget it"
        ###
        res = self.dialog.test('ACHILLE', stmt, answer)

        expected_result = []

        self.assertTrue(check_results(res[0], expected_result))
Exemplo n.º 3
0
class TestMovingToLondonScenario(unittest.TestCase):
    """
    Scenario
    --------
    ACHILLE and JULIE are moving from Toulouse to London, and they must
    pack everything before leaving. ACHILLE is sorting its video tapes, and he 
    throws away the oldest ones. Jido is watching him.

    Setup:
      One trashbin, one cardboard box, 2 tapes on the table [TAPE1 = Lord of 
      the Robots (lotr) and TAPE2 = JIDO-E].
    
    Complete scenario here:
    http://homepages.laas.fr/slemaign/wiki/doku.php?id=scenario_demo_roman
    """
    
    def setUp(self):
        self.dialog = Dialog()
        self.dialog.start()
        
        self.oro = ResourcePool().ontology_server
        
        try:
            
            self.oro.add([  'ACHILLE rdf:type Human',
                            'ACHILLE rdfs:label Achille',
                            'JULIE rdf:type Human', 
                            'JULIE rdfs:label Julie',
                            'TABLE rdf:type Table',
                            'Trashbin rdfs:subClassOf Box',
                            'CardBoardBox rdfs:subClassOf Box',
                            'CardBoardBox rdfs:label "cardboard box"',
                            'TRASHBIN rdf:type Trashbin',
                            'CARDBOARD_BOX rdf:type CardBoardBox',
                            'CARDBOARD_BOX isOn TABLE',
                            'TAPE1 rdf:type VideoTape', 
                            'TAPE1 rdfs:label "The Lords of the robots"', 
                            'TAPE1 isOn TABLE',
                            'TAPE2 rdf:type VideoTape', 
                            'TAPE2 rdfs:label "Jido-E"', 
                            'TAPE2 isOn TABLE',
                            'VideoTape owl:equivalentClass Tape',
                            'TAPE1 owl:differentFrom TAPE2',
                            ])
            """           
            self.oro.addForAgent('ACHILLE',
                        ['BLUE_TRASHBIN rdf:type Trashbin',
                        'PINK_TRASHBIN rdf:type Trashbin',
                        'BLACK_TAPE rdf:type VideoTape', 'BLACK_TAPE isIn PINK_TRASHBIN',
                        'GREY_TAPE rdf:type VideoTape', 'GREY_TAPE isOn HRP2TABLE'])
            """        
        except AttributeError: #the ontology server is not started of doesn't know the method
            print("Couldn't connect to the ontology server. Aborting the test.")
            raise
        
        try:
            self.oro.addForAgent('ACHILLE',[
                            'ACHILLE rdf:type Human',
                            'ACHILLE rdfs:label Achille',
                            'JULIE rdf:type Human', 
                            'JULIE rdfs:label Julie',
                            'TABLE rdf:type Table',
                            'Trashbin rdfs:subClassOf Box',
                            'CardBoardBox rdfs:subClassOf Box',
                            'CardBoardBox rdfs:label "cardboard box"',
                            'TRASHBIN rdf:type Trashbin',
                            'CARDBOARD_BOX rdf:type CardBoardBox',
                            'CARDBOARD_BOX isOn TABLE',
                            'TAPE1 rdf:type VideoTape', 
                            'TAPE1 rdfs:label "The Lords of the robots"', 
                            'TAPE1 isOn TABLE',
                            'TAPE2 rdf:type VideoTape', 
                            'TAPE2 rdfs:label "Jido-E"', 
                            'TAPE2 isOn TABLE',
                            
                            'VideoTape owl:equivalentClass Tape',
                            
                            'TAPE1 owl:differentFrom TAPE2',
                            ])
        except AttributeError: #the ontology server is not started of doesn't know the method
            print("Couldn't connect to the ontology server. Aborting the test.")
            raise
        
        
        try:
            self.oro.addForAgent('JULIE',[
                            'ACHILLE rdf:type Human',
                            'ACHILLE rdfs:label Achille',
                            'JULIE rdf:type Human', 
                            'JULIE rdfs:label Julie',
                            'TABLE rdf:type Table',
                            'Trashbin rdfs:subClassOf Box',
                            'CardBoardBox rdfs:subClassOf Box',
                            'CardBoardBox rdfs:label "cardboard box"',
                            'TRASHBIN rdf:type Trashbin',
                            'CARDBOARD_BOX rdf:type CardBoardBox',
                            'CARDBOARD_BOX isOn TABLE',
                            'TAPE1 rdf:type VideoTape', 
                            'TAPE1 rdfs:label "The Lords of the robots"', 
                            'TAPE1 isOn TABLE',
                            'TAPE2 rdf:type VideoTape', 
                            'TAPE2 rdfs:label "Jido-E"', 
                            'TAPE2 isOn TABLE',
                            
                            'VideoTape owl:equivalentClass Tape',
                            
                            'TAPE1 owl:differentFrom TAPE2',
                            ])
        except AttributeError: #the ontology server is not started of doesn't know the method
            print("Couldn't connect to the ontology server. Aborting the test.")
            raise
       
            
    def runTest(self):
        """ MOVING TO LONDON SCENARIO
        
        ACHILLE puts TAPE1 in CARDBOARDBOX"""

        print()
        self.oro.add(['TAPE1 isIn CARDBOARD_BOX'])
        self.oro.addForAgent('ACHILLE',['ACHILLE pointsAt CARDBOARD_BOX'])
        
        stmt = "Jido, what is in the box?"
        answer = "This box"
        ####
        res = self.dialog.test('ACHILLE', stmt, answer)
        self.assertEquals(res[1][1],"The Lords of the robots.")
        
        self.oro.removeForAgent('ACHILLE',['ACHILLE pointsAt CARDBOARD_BOX'])
        
        stmt = "Ok. And where is the other tape?"
        ####
        self.assertEquals(self.dialog.test('ACHILLE', stmt)[1][1],"The other tape is on the table.")
        
        stmt = "Ok. Thanks."
        self.assertEquals(self.dialog.test('ACHILLE', stmt)[1][1],"You're welcome.")
        
        """Julie arrives, and gives two big boxes to ACHILLE. He can not take anything!"""
       
        self.oro.update(['TAPE2 isReachable false'])
                            
        stmt = "Jido, can you take Jido-E?"
        ####
        res = self.dialog.test('ACHILLE', stmt)
        
        expected_result = ['ACHILLE desires *',
                  '* rdf:type Get',
                  '* performedBy myself',
                  '* actsOnObject TAPE2']
        
        self.assertTrue(check_results(res[0], expected_result))
        
        """Julie pushes a bit the TAPE2, which is now close enough, but still 
        unreachable because of an obstacle.
        """
        self.oro.addForAgent('ACHILLE',['ACHILLE pointsAt TAPE2'])
        stmt = "And now, can you reach this tape?"
        ####
        ### Check ['myself reaches TAPE2']
        self.assertEquals(self.dialog.test('ACHILLE', stmt)[1][1],"I don't know, if I can reach this tape now.")
        self.oro.removeForAgent('ACHILLE',['ACHILLE pointsAt TAPE2'])
        
        """Julie pushes again the tape. It is now reachable.
        """
        self.oro.update(['TAPE2 isReachable true'])
        
        stmt = "Jido, can you take it?"
        ####
        ### Do you mean Jido-E
        answer = "I mean Jido-E"
        ###
        res = self.dialog.test('JULIE', stmt, answer)
        expected_result = ['JULIE desires *',
                  '* rdf:type Get',
                  '* performedBy myself',
                  '* actsOnObject TAPE2']
        
        self.assertTrue(check_results(res[0], expected_result))
        
        """Achille puts JIDO-E in the trashbin. Jido still observes. Achille 
        leaves. Julie finds JIDO-E in the trashbin, and takes it away. ACHILLE 
        comes back to the table.
        """

        print()
        self.oro.remove(['TAPE2 isOn TABLE'])
        self.oro.add(['TAPE2 isAt JULIE'])
        self.oro.addForAgent('ACHILLE', ['TAPE2 isIn TRASHBIN'])
                            
        stmt = "Can you give me the tape in the trashbin?"
        #Expected intermediate question: "You mean, the JIDO-E tape?"
        #NOT FOR ROMAN demo!
        #answer = "Yes"
        ####
        res = self.dialog.test('ACHILLE', stmt)
        
        expected_result = ['ACHILLE desires *',
                  '* rdf:type Give',
                  '* performedBy myself',
                  '* actsOnObject TAPE2',
                  '* receivedBy ACHILLE']
        
        self.assertTrue(check_results(res[0], expected_result))

    def tearDown(self):
        self.dialog.stop()
        self.dialog.join()