def onFileExport(self): # Check for uncompiled changes retval = None if self.editSpace.up_to_date is False: if DEBUG: print("Code is not compiled. Compile before export.") retval = handleCompileMsg() if retval == QMessageBox.Cancel: return if retval == QMessageBox.Yes: if DEBUG: print('Compiling code before exporting') try: self.onCompile() except Exception as ex: print('Couldn\'t compile before exporting') return try: fname, filter = QFileDialog.getSaveFileName(self, 'Export to file') if fname == "": if DEBUG: print("Cancel clicked") return Storage.exportAIML(fname, self.editSpace.aiml) # save as an aiml file # Display Dialog exportSuccessful() except Exception as ex: print("Exception caught trying to export") print(ex) handleError(ex)
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))
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))
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))
# 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
import os, sys sys.path.append(os.path.abspath('..')) import Utils.Storage as Storage from Model.Data import * aiml = AIML() category = Category() pattern = Pattern() template = Template() random = Random() comment = Comment() li1 = ConditionItem() li2 = ConditionItem() li3 = ConditionItem() li4 = ConditionItem() oob = Oob() robot = Robot() aiml.append( category.append(pattern).append( template.append( random.append(li1).append( comment.append(li2.append('hi')).append( li3.append('hi')).append(li4.append('hi')))).append( oob.append(robot)))) Storage.exportAIML('test_multiline_comments', aiml) print(aiml)
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))
def onFileExport(self): fname, filter = QFileDialog.getSaveFileName(self, 'Export to file') Storage.exportAIML(fname, self.editSpace.aiml) # save as an aiml file