Пример #1
0
 def test_topic_import(self):
     imported = Storage.importAIML('./test_aimls/mexican_food')
     Storage.exportAIML('./test_aimls/mexican_food_exp', imported)
     exported = Storage.importAIML('./test_aimls/mexican_food_exp')
     # print(f'TEST:\n{imported}')
     # print(f'EXPECTED:\n{exported}')
     self.assertEqual(str(imported), str(exported))
Пример #2
0
 def test_parsing_commented_tree(self):
     parser = ET.XMLParser(target=CommentedTreeBuilder())
     tree = ET.parse('test_aimls/utils.aiml', parser)
     tree.write('test_aimls/out.aiml', xml_declaration=True, encoding='UTF-8')
     util = Storage.importAIML('./test_aimls/utils')
     out = Storage.importAIML('./test_aimls/out')
     self.assertEqual(str(util), str(out))
Пример #3
0
 def test_comments_util_import(self):
     imported = Storage.importAIML('./test_aimls/utils')
     Storage.exportAIML('./test_aimls/utils_exp', imported)
     exported = Storage.importAIML('./test_aimls/utils_exp')
     print(f'TEST:\n{imported}')
     print(f'EXPECTED:\n{exported}')
     self.maxDiff = None
     self.assertEqual(str(imported),str(exported))
Пример #4
0
    def onFileImport(self):
        try:
            fname, filter = QFileDialog.getOpenFileName(self, "Import File")

            if fname == "":
                if DEBUG: print("Cancel was clicked")
                return

            yoffset = -4000
            if DEBUG: print("fname: " + fname)
            self.filename = os.path.splitext(fname)[
                0]  # removing extension from path name
            aiml = Storage.importAIML(self.filename)  # import the aiml file
            numCats = 0
            if DEBUG: print(f"aiml tags:\n{aiml.tags}")
            topics = []
            for cat in aiml.tags:
                if cat.type == "topic":
                    topics.append(cat)
                    continue
                self.catCreated.emit(cat)
                numCats = numCats + 1
            for cat in topics:
                self.catCreated.emit(cat)
                numCats = numCats + 1
            if DEBUG:
                print("Finished creating " + str(numCats) + " categories")
            if DEBUG: print("file import successful")
            self.onCompile()
            if DEBUG: print("Compile after import sucessful!")
        except Exception as ex:
            handleError(ex)
            print(ex)
Пример #5
0
 def test_import(self):
     ac = AimlCreator()
     expected = ac.make_aiml2()
     #NOTE: Make sure to not have the '.aiml' after file name. 
     #      Causes an aborted core dump. Why?
     imported = Storage.importAIML('./test_aimls/atomic')
     self.assertEqual(str(expected), str(imported))
Пример #6
0
 def test_export(self):
     #NOTE: Works with make_aiml2 but NOT make_aiml() might have
     #      something to do with the topic tag
     ac = AimlCreator()
     export = ac.make_aiml2()
     Storage.exportAIML('./test_aimls/exporting', export)
     imported = Storage.importAIML('./test_aimls/exporting')
     self.assertEqual(str(export), str(imported))
Пример #7
0
    def test_import_jupiter(self):
        app = QApplication(sys.argv)
        wnd = EditorWindow()
        wnd.show()
        wnd.onFileImport()
        aiml = wnd.editSpace.aiml

        imported = Storage.importAIML('./test_aimls/jupiter')
        self.assertEqual(str(aiml), str(imported))
Пример #8
0
    def onFileImport(self):
        try:
            fname, filter = QFileDialog.getOpenFileName(self, "Import File")
            yoffset = -4000
            print("fname: " + fname)
            self.filename = os.path.splitext(fname)[
                0]  # removing extension from path name
            aiml = Storage.importAIML(self.filename)  # import the aiml file
            numCats = 0
            print("aiml tags: " + str(aiml.tags))
            for cat in aiml.tags:
                if cat.type == "topic":
                    print("found topic!")

                    for tag in cat.tags:
                        if tag.type == "category":
                            print("tag is a category")
                            self.catCreated.emit(
                                tag)  # emitting signal to EditorWidget
                            numCats = numCats + 1
                    self.editSpace.aiml.append(cat)
                if cat.type == "category":
                    print("tag is a category")
                    self.catCreated.emit(
                        cat)  # emitting signal to EditorWidget
                numCats = numCats + 1
            print("Finished creating " + str(numCats) + " categories")

            # for node in self.editSpace.scene.nodes:
            #     x = node.grNode.x()
            #     node.setPos(x, yoffset)
            #     yoffset = yoffset + 500
            print("file import successful")
        except Exception as ex:
            handleError(ex)
            print(ex)
Пример #9
0
# create AIML structure
aiml = AIML().append(Category().append(
    Pattern().append("START SESSION 1 *")).append(Template().append(
        Think().append(Set("username").append("star")).append(
            Set("topic").append("Session 1"))).append(
                "Ok. Let's begin our session. How are you doing today <star/>?"
            ).append(Oob().append(Robot())))).append(
                Topic("session").append(Category().append(
                    Pattern().append("*")).append(Template().append(
                        Think().append(Set("data").append("<star/>"))).append(
                            Condition("getsetimnet").append(
                                ConditionItem("verypositive").append(
                                    "I am happy").append(Oob().append(
                                        Robot().append(Options().append(
                                            Option("Yes")).append(
                                                Option("No")))))).
                            append(
                                ConditionItem("positive").append(
                                    "I am not as happy"))))))
# print it as a reference
print(aiml)

Storage.save('test2', aiml)  # save as a pickle file
aiml2 = Storage.restore('test2')  # restore the pickle
print("####################restored pickle file#######################")
print(aiml2)  # print for validation

Storage.exportAIML('test2', aiml2)  # save as an aiml file
aiml4 = Storage.importAIML('test2')  # import the aiml file
print(aiml4)  # print for validation
Пример #10
0
 def test_import_jupiter(self):
     imported = Storage.importAIML('./test_aimls/jupiter')
     Storage.exportAIML('./test_aimls/jupiter_exp', imported)
     exported = Storage.importAIML('./test_aimls/jupiter_exp')
     self.assertEqual(str(imported),str(exported))