コード例 #1
0
 def get_client_configuration(self):
     """
     By overriding this class in you Configuration file, you can add new configurations
     and stil use the dynamic loader capabilities
     :return: Client configuration object
     """
     return ClientConfiguration()
コード例 #2
0
    def setUp(self):
        self.parser = TemplateGraph(AIMLParser())
        self.assertIsNotNone(self.parser)

        self.test_brain = None
        self.test_sentence = Sentence("test sentence")

        test_node = PatternOneOrMoreWildCardNode("*")

        self.test_sentence._matched_context = MatchContext()
        self.test_sentence._matched_context._matched_nodes = [
            Match(Match.WORD, test_node, 'one'),
            Match(Match.WORD, test_node, 'two'),
            Match(Match.WORD, test_node, 'three'),
            Match(Match.WORD, test_node, 'four'),
            Match(Match.WORD, test_node, 'five'),
            Match(Match.WORD, test_node, 'six'),
            Match(Match.TOPIC, test_node, '*'),
            Match(Match.THAT, test_node, '*')
        ]

        test_config = ClientConfiguration()

        self.test_bot = Bot(Brain(BrainConfiguration()),
                            config=test_config.bot_configuration)
        self.test_clientid = "testid"

        conversation = self.test_bot.get_conversation(self.test_clientid)
        question = Question.create_from_sentence(self.test_sentence)
        conversation._questions.append(question)
コード例 #3
0
 def test_get_config_by_name(self):
     client_config = ClientConfiguration()
     config_type = ConfigurationFactory.get_config_by_name(client_config, "yaml")
     self.assertIsNotNone(config_type)
     config_type = ConfigurationFactory.get_config_by_name(client_config, "json")
     self.assertIsNotNone(config_type)
     config_type = ConfigurationFactory.get_config_by_name(client_config, "xml")
     self.assertIsNotNone(config_type)
コード例 #4
0
    def setUp(self):
        self.parser = TemplateGraph()
        self.assertIsNotNone(self.parser)

        self.test_brain = None
        test_config = ClientConfiguration()
        self.test_bot = Bot(Brain(BrainConfiguration()),
                            config=test_config.bot_configuration)
        self.test_clientid = "testid"
コード例 #5
0
    def test_init(self):
        client_config = ClientConfiguration()
        yaml = YamlConfigurationFile(client_config)
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
          supress_warnings: true
          allow_system_aiml: true
          allow_learn_aiml: true
          allow_learnf_aiml: true

          files:
              aiml:
                  files: /aiml
                  extension: .aiml
                  directories: true
              sets:
                  files: /sets
                  extension: .txt
                  directories: false
              maps:
                  files: /maps
                  extension: .txt
                  directories: true
              denormal: denormal.txt
              normal: normal.txt
              gender: gender.txt
              person: person.txt
              person2: person2.txt
              predicates: predicates.txt
              pronouns: pronouns.txt
              properties: properties.txt
              triples: triples.txt
              preprocessors: preprocessors.txt
              postprocessors: postprocessors.txt

          services:
              REST:
                  path: programy.utils.services.rest.GenericRESTService
              Pannous:
                  path: programy.utils.services.pannous.PannousService
              Pandora:
                  path: programy.utils.services.pandora.PandoraService
              Wikipedia:
                  path: programy.utils.services.wikipedia.WikipediaService

        bot:
          prompt: ">>>"
          default_response: Sorry, I don't have an answer for that!
          exit_response: So long, and thanks for the fish!
          initial_question: Hi, how can I help you?
        """, ".")

        self.assertIsNotNone(client_config.bot_configuration)
        self.assertIsNotNone(client_config.brain_configuration)
コード例 #6
0
ファイル: test_think.py プロジェクト: FunRobots/simple_bot
    def setUp(self):
        self.parser = TemplateGraph()
        self.assertIsNotNone(self.parser)

        self.test_brain = None
        self.test_sentence = Sentence("test sentence")
        self.test_sentence._stars = ['one', 'two', 'three', 'four', 'five', 'six']
        self.test_sentence._thatstars = ["*"]
        self.test_sentence._topicstars = ["*"]

        test_config = ClientConfiguration()

        self.test_bot = Bot(Brain(BrainConfiguration()), config=test_config.bot_configuration)
        self.test_clientid = "testid"

        conversation = self.test_bot.get_conversation(self.test_clientid)
        question = Question.create_from_sentence(self.test_sentence)
        conversation._questions.append(question)
コード例 #7
0
    def test_bot_with_config(self):
        configuration = ClientConfiguration()
        self.assertIsNotNone(configuration)
        self.assertIsNotNone(configuration.bot_configuration)
        self.assertIsNotNone(configuration.brain_configuration)

        configuration.bot_configuration.prompt = ":"
        configuration.bot_configuration.default_response = "No answer for that"
        configuration.bot_configuration.exit_response = "See ya!"

        test_brain = Brain(BrainConfiguration())
        test_brain.load(configuration.brain_configuration)

        bot = Bot(test_brain, config=configuration.bot_configuration)
        self.assertIsNotNone(bot)

        self.assertEqual(bot.prompt, ":")
        self.assertEqual(bot.default_response, "No answer for that")
        self.assertEqual(bot.exit_response, "See ya!")
コード例 #8
0
    def test_init(self):
        client_config = ClientConfiguration()
        yaml = YamlConfigurationFile(client_config)
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        rest:
          host: 127.0.0.1
          port: 5000
          debug: false
          use_api_keys: false
        """, ".")

        rest_config = RestConfiguration()
        rest_config.load_config_section(yaml, ".")

        self.assertEqual("127.0.0.1", rest_config.host)
        self.assertEqual(5000, rest_config.port)
        self.assertEqual(False, rest_config.debug)
        self.assertEqual(False, rest_config.use_api_keys)
コード例 #9
0
    def load_configuration(self, arguments):
        self.configuration = ClientConfiguration()

        self.configuration.brain_configuration._supress_warnings = False

        self.configuration.brain_configuration._aiml_files = None
        self.configuration.brain_configuration._set_files = None
        self.configuration.brain_configuration._map_files = None

        self.configuration.brain_configuration._denormal = None
        self.configuration.brain_configuration._normal = None
        self.configuration.brain_configuration._gender = None
        self.configuration.brain_configuration._person = None
        self.configuration.brain_configuration._person2 = None
        self.configuration.brain_configuration._predicates = None
        self.configuration.brain_configuration._pronouns = None
        self.configuration.brain_configuration._properties = None
        self.configuration.brain_configuration._triples = None
        self.configuration.brain_configuration._preprocessors = None

        self.configuration.bot_configuration.default_response = ""
コード例 #10
0
    def test_load_from_file(self):
        client_config = ClientConfiguration()
        yaml = YamlConfigurationFile(client_config)
        self.assertIsNotNone(yaml)
        yaml.load_from_file(os.path.dirname(__file__) + "/test_yaml.yaml", ",")
        self.assertIsNotNone(yaml.yaml_data)
        brain = yaml.get_section("brain")
        self.assertIsNotNone(brain)
        files = yaml.get_section("files", brain)
        self.assertIsNotNone(files)
        aiml = yaml.get_section("aiml", files)
        self.assertIsNotNone(aiml)

        files = yaml.get_section("files", aiml)
        self.assertIsNotNone(files)
        self.assertEqual(files, "/aiml")
        extension = yaml.get_section("extension", aiml)
        self.assertIsNotNone(extension)
        self.assertEqual(extension, ".aiml")
        directories = yaml.get_section("directories", aiml)
        self.assertIsNotNone(directories)
        self.assertEqual(directories, True)
コード例 #11
0
    def test_load_from_file(self):
        client_config = ClientConfiguration()
        xml = XMLConfigurationFile(client_config)
        self.assertIsNotNone(xml)
        xml.load_from_file(os.path.dirname(__file__) + "/test_xml.xml", ",")
        self.assertIsNotNone(xml.xml_data)
        brain = xml.get_section("brain")
        self.assertIsNotNone(brain)
        files = xml.get_section("files", brain)
        self.assertIsNotNone(files)
        aiml = xml.get_section("aiml", files)
        self.assertIsNotNone(aiml)

        files = xml.get_section("files", aiml)
        self.assertIsNotNone(files)
        self.assertEqual(files.text, "/aiml")
        extension = xml.get_section("extension", aiml)
        self.assertIsNotNone(extension)
        self.assertEqual(extension.text, ".aiml")
        directories = xml.get_section("directories", aiml)
        self.assertIsNotNone(directories)
        self.assertEqual(directories.text, "True")
コード例 #12
0
    def test_init(self):
        client_config = ClientConfiguration()
        yaml = YamlConfigurationFile(client_config)
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        bot:
            prompt: ">>>"
            initial_question: Hi, how can I help you today?
            default_response: Sorry, I don't have an answer for that!
            exit_response: So long, and thanks for the fish!
        """, ".")

        bot_config = BotConfiguration()
        bot_config.load_config_section(yaml, ".")

        self.assertEqual(">>>", bot_config.prompt)
        self.assertEqual("Hi, how can I help you today?",
                         bot_config.initial_question)
        self.assertEqual("Sorry, I don't have an answer for that!",
                         bot_config.default_response)
        self.assertEqual("So long, and thanks for the fish!",
                         bot_config.exit_response)
コード例 #13
0
    def test_load_from_text(self):
        client_config = ClientConfiguration()
        json = JSONConfigurationFile(client_config)
        self.assertIsNotNone(json)
        json.load_from_text(
            """
{
    "brain": {
        "supress_warnings": false,
        "allow_system_aiml": true,
        "allow_learn_aiml": true,
        "allow_learnf_aiml": true,

        "files": {
            "aiml": {
                "files": "/aiml",
                "extension": ".aiml",
                "directories": true
            },
            "sets": {
                "files": "/sets",
                "extension": ".txt",
                "directories": false
            },
            "maps": {
                "files": "/maps",
                "extension": ".txt",
                "directories": true
            },
            "denormal": "denormal.txt",
            "normal": "normal.txt",
            "gender": "gender.txt",
            "person": "person.txt",
            "person2": "person2.txt",
            "predicates": "predicates.txt",
            "pronouns": "pronouns.txt",
            "properties": "properties.txt",
            "triples": "triples.txt",
            "preprocessors": "preprocessors.txt",
            "postprocessors": "postprocessors.txt"
        },

        "services": {
            "REST": {
                "path": "programy.utils.services.rest.GenericRESTService"
            },
            "Pannous": {
                "path": "programy.utils.services.pannous.PannousService"
            },
            "Pandora": {
                "path": "programy.utils.services.pandora.PandoraService"
            },
            "Wikipedia": {
                "path": "programy.utils.services.wikipedia.WikipediaService"
            }
        }
    },
    "bot": {
        "prompt": ">>>",
        "default_response": "Sorry, I don't have an answer for that!",
        "exit_response": "So long, and thanks for the fish!",
        "initial_question": "Hi, how can I help you>"
    }
}""", ",")
コード例 #14
0
    def test_init(self):
        client_config = ClientConfiguration()
        yaml = YamlConfigurationFile(client_config)
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
          supress_warnings: true
          allow_system_aiml: true
          allow_learn_aiml: true
          allow_learnf_aiml: true

          files:
                aiml:

                    files: $BOT_ROOT/aiml
                    extension: .aiml
                    directories: false
                sets:
                    files: $BOT_ROOT/sets
                    extension: .txt
                    directories: false
                maps:
                    files: $BOT_ROOT/maps
                    extension: .txt
                    directories: false
                denormal: $BOT_ROOT/config/denormal.txt
                normal: $BOT_ROOT/config/normal.txt
                gender: $BOT_ROOT/config/gender.txt
                person: $BOT_ROOT/config/person.txt
                person2: $BOT_ROOT/config/person2.txt
                predicates: $BOT_ROOT/config/predicates.txt
                pronouns: $BOT_ROOT/config/pronouns.txt
                properties: $BOT_ROOT/config/properties.txt
                triples: $BOT_ROOT/config/triples.txt
                preprocessors: $BOT_ROOT/config/preprocessors.conf
                postprocessors: $BOT_ROOT/config/postprocessors.conf

        """, ".")

        brain_config = BrainConfiguration()
        brain_config.load_config_section(yaml, ".")

        self.assertEqual(True, brain_config.supress_warnings)
        self.assertEqual(True, brain_config.allow_system_aiml)
        self.assertEqual(True, brain_config.allow_learn_aiml)
        self.assertEqual(True, brain_config.allow_learnf_aiml)

        self.assertIsNotNone(brain_config.aiml_files)
        self.assertIsNotNone(brain_config.set_files)
        self.assertIsNotNone(brain_config.map_files)
        self.assertEqual("./config/denormal.txt", brain_config.denormal)
        self.assertEqual("./config/normal.txt", brain_config.normal)
        self.assertEqual("./config/gender.txt", brain_config.gender)
        self.assertEqual("./config/person.txt", brain_config.person)
        self.assertEqual("./config/person2.txt", brain_config.person2)
        self.assertEqual("./config/predicates.txt", brain_config.predicates)
        self.assertEqual("./config/pronouns.txt", brain_config.pronouns)
        self.assertEqual("./config/properties.txt", brain_config.properties)
        self.assertEqual("./config/triples.txt", brain_config.triples)
        self.assertEqual("./config/preprocessors.conf",
                         brain_config.preprocessors)
        self.assertEqual("./config/postprocessors.conf",
                         brain_config.postprocessors)
        self.assertIsNotNone(brain_config.services)
コード例 #15
0
 def test_load_config_data_xml(self):
     client_config = ClientConfiguration()
     ConfigurationFactory.load_configuration_from_file(
         client_config,
         os.path.dirname(__file__) + "/test_xml.xml")
     self.assert_config_data(client_config)
コード例 #16
0
    def test_load_from_text(self):
        client_config = ClientConfiguration()
        xml = XMLConfigurationFile(client_config)
        self.assertIsNotNone(xml)
        xml.load_from_text(
            """<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <brain>
        <supress_warnings>True</supress_warnings>
        <allow_system_aiml>True</allow_system_aiml>
        <allow_learn_aiml>True</allow_learn_aiml>
        <allow_learnf_aiml>True</allow_learnf_aiml>

       <files>
           <aiml>
               <files>/aiml</files>
               <extension>.aiml</extension>
               <directories>True</directories>
           </aiml>
           <sets>
               <files>/sets</files>
               <extension>.txt</extension>
               <directories>False</directories>
           </sets>
           <maps>
               <files>/maps</files>
               <extension>.txt</extension>
               <directories>True</directories>
           </maps>
            <denormal>denormal.txt</denormal>
            <normal>normal.txt</normal>
            <gender>gender.txt</gender>
            <person>person.txt</person>
            <person2>person2.txt</person2>
            <predicates>predicates.txt</predicates>
            <pronouns>pronouns.txt</pronouns>
            <properties>properties.txt</properties>
            <triples>triples.txt</triples>
            <preprocessors>preprocessors.txt</preprocessors>
            <postprocessors>postprocessors.txt</postprocessors>
       </files>
        <services>
            <REST>
                <path>programy.utils.services.rest.GenericRESTService</path>
            </REST>
            <Pannous>
                <path>programy.utils.services.pannous.PannousService</path>
            </Pannous>
            <Pandora>
                <path>programy.utils.services.pandora.PandoraService</path>
            </Pandora>
            <Wikipedia>
                <path>programy.utils.services.wikipedia.WikipediaService</path>
            </Wikipedia>
        </services>
    </brain>
    <bot>
        <prompt>>>></prompt>
        <default_response>Sorry, I don't have an answer for that!</default_response>
        <exit_response>So long, and thanks for the fish!</exit_response>
        <initial_question>Hi, how can I help you?</initial_question>
    </bot>
</configuration>
""", ",")
コード例 #17
0
 def load_configuration(self, arguments):
     self.configuration = ClientConfiguration()
     ConfigurationFactory.load_configuration_from_file(
         self.configuration,
         os.path.dirname(__file__) + "/test_files/train/testconfig.yaml")