Esempio n. 1
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        other:
        """, ConsoleConfiguration(), ".")

        client_config = ClientConfigurationData("console")
        client_config.load_configuration(yaml, ".")

        self.assertIsNotNone(client_config.bot_selector)

        self.assertIsNotNone(client_config.scheduler)
        self.assertEqual(None, client_config.scheduler.name)
        self.assertEqual(0, client_config.scheduler.debug_level)
        self.assertFalse(client_config.scheduler.add_listeners)
        self.assertFalse(client_config.scheduler.remove_all_jobs)

        self.assertIsNotNone(client_config.renderer)
Esempio n. 2
0
    def test_with_data_multiple_bots(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        console:
          prompt: ">>>"
          
          renderer: programy.clients.render.text.TextRenderer
          
          scheduler:
            name: Scheduler1
            debug_level: 0
            add_listeners: True
            remove_all_jobs: True

          bot_selector: programy.clients.botfactory.DefaultBotSelector
          bots:
            bot1:
                prompt: ">>>"
                initial_question: Hi, how can I help you today?
                initial_question_srai: YINITIALQUESTION
                default_response: Sorry, I don't have an answer for that!
                default_response_srai: YDEFAULTRESPONSE
                empty_string: YEMPTY
                exit_response: So long, and thanks for the fish!
                exit_response_srai: YEXITRESPONSE
                override_properties: true
                max_question_recursion: 1000
                max_question_timeout: 60
                max_search_depth: 100
                max_search_timeout: 60
                
                spelling:
                  load: true
                  classname: programy.spelling.norvig.NorvigSpellingChecker
                  alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                  check_before: true
                  check_and_retry: true
                  
                splitter:
                    classname: programy.dialog.splitter.regex.RegexSentenceSplitter
    
                joiner:
                    classname: programy.dialog.joiner.SentenceJoiner
    
                conversations:
                  save: true
                  load: false
                  max_histories: 100
                  restore_last_topic: false
                  initial_topic: TOPIC1
                  empty_on_start: false
            
                from_translator:
                    classname: programy.nlp.translate.textblob_translator.TextBlobTranslator
                    from: fr
                    to: en 
    
                to_translator:
                    classname: programy.nlp.translate.textblob_translator.TextBlobTranslator
                    from: en
                    to: fr
    
                sentiment:
                    classname: programy.nlp.sentiment.textblob_sentiment.TextBlobSentimentAnalyser
                    scores: programy.nlp.sentiment.scores.SentimentScores
    
                brain_selector: programy.bot.DefaultBrainSelector
                brains:
                    brain1:
                    
                        # Overrides
                        overrides:
                          allow_system_aiml: true
                          allow_learn_aiml: true
                          allow_learnf_aiml: true
                    
                        # Defaults
                        defaults:
                          default_get: unknown
                          default_property: unknown
                          default_map: unknown
                          learnf-path: file
                    
                        # Binary
                        binaries:
                          save_binary: true
                          load_binary: true
                          load_aiml_on_binary_fail: true
                    
                        # Braintree
                        braintree:
                          create: true
                    
                        services:
                            OPENCHAT:
                                classname: programy.services.openchat.openchat.service.OpenChatRESTService
                            REST:
                                classname: programy.services.rest.GenericRESTService
                                method: GET
                                host: 0.0.0.0
                                port: 8080
                            Pannous:
                                classname: programy.services.pannous.PannousService
                                url: http://weannie.pannous.com/api
                    
                        openchatbots:
                          chatbot1:
                            url: http://localhost:5959/api/rest/v2.0/ask
                            method: GET
                    
                        security:
                            authentication:
                                classname: programy.security.authenticate.passthrough.BasicPassThroughAuthenticationService
                                denied_srai: AUTHENTICATION_FAILED
                            authorisation:
                                classname: programy.security.authorise.usergroupsauthorisor.BasicUserGroupAuthorisationService
                                denied_srai: AUTHORISATION_FAILED
                                usergroups:
                                  storage: file
                    
                        dynamic:
                            variables:
                                gettime: programy.dynamic.variables.datetime.GetTime
                            sets:
                                numeric: programy.dynamic.sets.numeric.IsNumeric
                                roman:   programy.dynamic.sets.roman.IsRomanNumeral
                            maps:
                                romantodec: programy.dynamic.maps.roman.MapRomanToDecimal
                                dectoroman: programy.dynamic.maps.roman.MapDecimalToRoman

            bot2:
                prompt: ">>>"
                initial_question: Hi, how can I help you today?
                initial_question_srai: YINITIALQUESTION
                default_response: Sorry, I don't have an answer for that!
                default_response_srai: YDEFAULTRESPONSE
                empty_string: YEMPTY
                exit_response: So long, and thanks for the fish!
                exit_response_srai: YEXITRESPONSE
                override_properties: true
                max_question_recursion: 1000
                max_question_timeout: 60
                max_search_depth: 100
                max_search_timeout: 60
                
                spelling:
                  load: true
                  classname: programy.spelling.norvig.NorvigSpellingChecker
                  alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                  check_before: true
                  check_and_retry: true
                  
                splitter:
                    classname: programy.dialog.splitter.regex.RegexSentenceSplitter
    
                joiner:
                    classname: programy.dialog.joiner.SentenceJoiner
    
                conversations:
                  save: true
                  load: false
                  max_histories: 100
                  restore_last_topic: false
                  initial_topic: TOPIC1
                  empty_on_start: false
            
                from_translator:
                    classname: programy.nlp.translate.textblob_translator.TextBlobTranslator
                    from: fr
                    to: en 
    
                to_translator:
                    classname: programy.nlp.translate.textblob_translator.TextBlobTranslator
                    from: en
                    to: fr
    
                sentiment:
                    classname: programy.nlp.sentiment.textblob_sentiment.TextBlobSentimentAnalyser
                    scores: programy.nlp.sentiment.scores.SentimentScores
    
                brain_selector: programy.bot.DefaultBrainSelector
                brains:
                    brain1:
                    
                        # Overrides
                        overrides:
                          allow_system_aiml: true
                          allow_learn_aiml: true
                          allow_learnf_aiml: true
                    
                        # Defaults
                        defaults:
                          default_get: unknown
                          default_property: unknown
                          default_map: unknown
                          learnf-path: file
                    
                        # Binary
                        binaries:
                          save_binary: true
                          load_binary: true
                          load_aiml_on_binary_fail: true
                    
                        # Braintree
                        braintree:
                          create: true
                    
                        services:
                            OPENCHAT:
                                classname: programy.services.openchat.openchat.service.OpenChatRESTService
                            REST:
                                classname: programy.services.rest.GenericRESTService
                                method: GET
                                host: 0.0.0.0
                                port: 8080
                            Pannous:
                                classname: programy.services.pannous.PannousService
                                url: http://weannie.pannous.com/api
                    
                        openchatbots:
                          chatbot1:
                            url: http://localhost:5959/api/rest/v2.0/ask
                            method: GET
                    
                        security:
                            authentication:
                                classname: programy.security.authenticate.passthrough.BasicPassThroughAuthenticationService
                                denied_srai: AUTHENTICATION_FAILED
                            authorisation:
                                classname: programy.security.authorise.usergroupsauthorisor.BasicUserGroupAuthorisationService
                                denied_srai: AUTHORISATION_FAILED
                                usergroups:
                                  storage: file
                    
                        dynamic:
                            variables:
                                gettime: programy.dynamic.variables.datetime.GetTime
                            sets:
                                numeric: programy.dynamic.sets.numeric.IsNumeric
                                roman:   programy.dynamic.sets.roman.IsRomanNumeral
                            maps:
                                romantodec: programy.dynamic.maps.roman.MapRomanToDecimal
                                dectoroman: programy.dynamic.maps.roman.MapDecimalToRoman
                            
        """, ConsoleConfiguration(), ".")

        client_config = ClientConfigurationData("console")
        client_config.load_configuration(yaml, ".")

        self.assertEqual(2, len(client_config.configurations))
        self.assertEqual("programy.clients.botfactory.DefaultBotSelector",
                         client_config.bot_selector)

        self.assertIsNotNone(client_config.scheduler)
        self.assertEqual("Scheduler1", client_config.scheduler.name)
        self.assertEqual(0, client_config.scheduler.debug_level)
        self.assertTrue(client_config.scheduler.add_listeners)
        self.assertTrue(client_config.scheduler.remove_all_jobs)

        self.assertEqual("programy.clients.render.text.TextRenderer",
                         client_config.renderer)