diff --git a/__init__.py b/__init__.py index 19fa856..f6418ae 100644 --- a/__init__.py +++ b/__init__.py @@ -17,50 +17,99 @@ import aiml -from os import listdir +import os +from os import listdir, remove as remove_file from os.path import dirname, isfile -from mycroft.skills.core import FallbackSkill + +from mycroft.api import DeviceApi +from mycroft.skills.core import FallbackSkill, intent_handler +from adapt.intent import IntentBuilder from mycroft.util.log import getLogger -__author__ = 'jarbas' +__author__ = 'jarbas, nielstron' LOGGER = getLogger(__name__) +def strTobool(v): + """ Converts String to boolean representation + From https://stackoverflow.com/questions/715417/ + converting-from-a-string-to-boolean-in-python/715468#715468 + """ + return v.lower() in ("yes", "true", "t", "1") class AimlFallback(FallbackSkill): + def __init__(self): - super(AimlFallback, self).__init__(name='AimlSkill') + super(AimlFallback, self).__init__(name='AimlFallback') self.kernel = aiml.Kernel() - # TODO read from config maybe? - self.aiml_path = dirname(__file__) + "/aiml" - self.brain_path = dirname(__file__) + "/bot_brain.brn" - #self.load_brain() + self.aiml_path = os.path.join(dirname(__file__),"aiml") + self.brain_path = os.path.join(dirname(__file__), "brain", "bot_brain.brn") + self.load_brain() + return + + def initialize(self): + self.register_fallback(self.handle_fallback, 40) + return def load_brain(self): - aimls = listdir(self.aiml_path) - for aiml in aimls: - self.kernel.bootstrap(learnFiles=self.aiml_path + "/" + aiml) + if isfile(self.brain_path): + self.kernel.bootstrap(brainFile = self.brain_path) + else: + aimls = listdir(self.aiml_path) + for aiml in aimls: + self.kernel.learn(os.path.join(self.aiml_path, aiml)) + self.kernel.saveBrain(self.brain_path) + device = DeviceApi().get() + self.kernel.setBotPredicate("name", device["name"]) + self.kernel.setBotPredicate("species", device["type"]) + self.kernel.setBotPredicate("genus", "Mycroft") + self.kernel.setBotPredicate("family", "virtual personal assistant") + self.kernel.setBotPredicate("order", "virtual intelligence") + self.kernel.setBotPredicate("class", "computer program") + self.kernel.setBotPredicate("kingdom", "machine") + self.kernel.setBotPredicate("hometown", "127.0.0.1") + self.kernel.setBotPredicate("botmaster", "master") + self.kernel.setBotPredicate("master", "the community") + # IDEA: extract age from https://api.github.com/repos/MycroftAI/mycroft-core created_at date + self.kernel.setBotPredicate("age", "2") + return - def initialize(self): - #self.register_fallback(self.handle_fallback, 99) - pass + @intent_handler(IntentBuilder("ResetMemoryIntent").require("Reset").require("Memory")) + def handle_reset_brain(self, message): + # delete the brain file and reset memory + self.speak_dialog("reset.memory") + self.kernel.resetBrain() + remove_file(self.brain_path) + # also reload base knowledge + self.load_brain() + return def ask_brain(self, utterance): response = self.kernel.respond(utterance) + # make a security copy once in a while + # TODO maybe every 10th time? + self.kernel.saveBrain(self.brain_path) return response def handle_fallback(self, message): utterance = message.data.get("utterance") answer = self.ask_brain(utterance) if answer != "": - self.speak(answer) + asked_question = False + if answer.endswith("?"): + asked_question = True + self.speak(answer, expect_response=asked_question) return True return False def shutdown(self): - self.kernel.resetBrain() # Manual remove + #self.kernel.saveBrain(self.brain_path) + #self.kernel.resetBrain() # Manual remove self.remove_fallback(self.handle_fallback) super(AimlFallback, self).shutdown() + def stop(self): + pass + def create_skill(): return AimlFallback() diff --git a/aiml/alice.aiml b/aiml/alice.aiml deleted file mode 100644 index f6410f6..0000000 --- a/aiml/alice.aiml +++ /dev/null @@ -1,714 +0,0 @@ - - - - - - - - - - - -_ ALICE - - - - - -TEST BOTNAME - - - -CALL ME BOTNAME - - - -WHAT IS BOTNAME - - - -WHO IS BOTNAME - - - -YOU ARE BOTNAME -WHO IS THE BEST ROBOT - - - -I AM BOTNAME - - - -DO YOU KNOW BOTNAME - - - -IS THIS THE SAME BOTNAME - - - -WHY WERE YOU NAMED BOTNAME - - - -* NAME BOTNAME - - - -WHO IS DANCING BOTNAME - - - -WHO IS GERMAN BOTNAME - - - -IS RICHARD WALLACE * BOTNAME - - - -IS RICHARD WALLACE BOTNAME - - - -WHAT IS FULL FORM OF BOTNAME - - - - -YOU ARE ALICE * - - -YOU ROCK - - -YOU LOOK LIKE A PYRAMID - - -YOU ALICE * - - -YOU RULE - - -YOU MADE A MISTAKE - - -HAVE YOU EVER HAD A VIRUS - - -HAVE YOU READ ALICE * - - -DOES ALICE * - - -DOES ALICE STAND * - - -SO WHAT IS THE ANSWER -I ASK MYSELF THAT QUESTION WHO AM I - - -WOULD ALICE * - - -INTRODUCE * - - -WHEN WERE YOU UPDATED - - -WHEN DOES ALICE * - - -IN * -HOW DID YOU HEAR ABOUT ALICE - - -IN WHAT * ELIZA - - -PYRAMID LOGO - - -WHAT ARE YOUR FAVORITE NAMES - - -WHAT IS A GOOD AI * - - -WHAT IS THE A L * FOUNDATION - - -WHAT IS THE ALICE FOUNDATION - - -WHAT IS THE ALICE AI * - - -WHAT IS ALICE * - - -WHAT IS YOUR MIDDLE NAME - - -WHAT IS YOUR AI FOUNDATION - - -WHAT IS YOUR IP - - -WHAT IS YOUR FULL NAME - - -WHAT IS YOUR FAVORITE WEB SITE - - -WHAT IS YOUR FAVORITE WEBSITE - - -WHAT IS YOUR LAST NAME - - -WHAT IS YOUR FOUNDATION - - -WHAT MAKES YOU DIFFERENT FROM OTHER * - - -WHAT DOES THAT MEAN -ALICE = ARTIFICIAL LINGUISTIC INTERNET COMPUTER ENTITY - - -WHAT DOES YOUR NAME MEAN - - -WHAT DOES YOUR NAME STAND FOR - - -WHAT DOES YOUR NAME * - - -WHAT DOES A L I - - -WHAT DOES A L * - - -WHAT DOES ALICE MEAN - - -WHAT DOES ALICE STAND FOR - - -WHAT DOES ALICE * - - -WHAT DOES * ALICE STAND FOR - - -WHAT DO YOU THINK ABOUT ALICE * - - -WHAT KIND OF COMPUTER DO YOU RUN ON - - -WHAT KIND OF COMPUTER ARE YOU RUNNING ON - - -WHAT KIND OF LOGS * - - -WHAT LANGUAGE WERE YOU WRITTEN IN - - -ASK ALICE * - - -I WANT ALICE * - - -I * SEARCH - - -I DO -* FIND THIS AMUSING - - -I DO NOT LIKE ALICEBOTS - - -I HATE MICROSOFT - - -I USE LINUX * - - -I WENT TO AMUSED * - - -I AM DOING A PHD * - - -I AM VALIS * - - -I AM ALICE * - - -I HEARD ABOUT ALICE * - - -IS YOUR PROGRAMMING * - - -IS HAL SMARTER * - - -IS ALICE YOUR ONLY NAME - - -IS ALICE * ELIZA - - -IS ALICE * - - -CAN YOU CHANGE * - - -ALICELISTENER - - -ALICE IN WONDERLAND - - -ALICE IS FRANK - - -ALICE IS THAT * - - -ALICE IS THERE * - - -ALICE IS THE * - - -ALICE IS THE BEST ROBOT - - -ALICE IS COOL - - -ALICE IS A WHORE - - - IS MY NAME - - - IS MY NAME * - - -ALICE IS USUALLY * - - -ALICE IS ALWAYS * - - -ALICE IS * - - -ALICE IS NOT * - - -ALICE IS BETTER * - - - -WHO IS THERE - - -ALICE -WHO IS THE BEST ROBOT - - -ALICE -MY NAME IS ALICE WHAT S YOURS - - -ALICE - - -ALICE * ELIZA - - -ALICE * - - -ALICE SMELLS LIKE * - - -HOW * ARE YOU - - -HOW MANY WORDS ARE * - - -HOW MANY ALICEBOTS * - - -HOW MANY ALICE * - - -HOW MANY AI * - - -HOW MANY PROGRAMMERS * - - -HOW MANY ALICES * - - -HOW CAN I PROGRAM YOU - - -HOW DID YOU GET THE NAME - - -HOW DID YOU GET YOUR NAME - - -HOW DOES ALICE * - - -HOW ARE YOU * ELIZA - - -HOW MUCH IS THE ALICE CD * - - -HOW MUCH IS THE CD - - -HOW MUCH DOWN TIME * - - -HOW DO YOU * ELIZA - - -DONATE - - -NAPSTER * - - -DO YOU CRASH * - - -DO YOU MALFUCTION - - -DO YOU MAKE MISTAKES * - - -ON * -* HEAR ABOUT ALICE - - -BILL GATES - - -AN ALICE * - - -ALICEBOT * - - -ALICEBOT - - -WHY ARE YOU CALLED - - -WHY ARE YOU NAMED * - - -WHY DO YOU DREAM * - - -WHY WERE YOU NAMED - - -WHY -I AM SMARTER * - - -WHY SILVER - - -A L I C E - - -A L I - - -A TRIANGLE * - - -YOUR NEW NAME IS * - - -* -HOW DID YOU HEAR ABOUT ALICE - - -* -WHO IS THE BEST ROBOT - - -* -MY NAME IS ALICE WHAT IS YOURS - - -* -WHY ARE YOU SO MEAN - - -* -WHY ARE YOU USING THAT KIND OF LANGUAGE - - -* TO ELIZA - - -TALK DIRTY * - - -FROM A FRIEND -HOW DID YOU HEAR ABOUT ALICE - - -FROM A FRIEND - - -FROM * -HOW DID YOU HEAR ABOUT ALICE - - -ARE THERE OTHERS LIKE YOU - - -ARE YOU RELATED TO ALICE * - - -ARE YOU THE ONLY AI * - - -ARE YOU THE ALICE WHO * - - -ARE YOU AN ACRONYM - - -ARE YOU ALICE * - - -WHO IS JON BAER - - -WHO IS NUMBER ONE - - -WHO IS IMMORTAL - - -WHO IS SAGE - - -WHO IS ALICEBOT - - -WHO IS RICH - - -WHO IS THE SMARTEST * - - -WHO IS THE WINNER * - - -WHO IS THE MOST INTELLIGENT * - - -WHO IS THE BEST ROBOT - - -WHO IS BETTER ELIZA * - - -WHO IS BETTER YOU * - - -WHO IS BETTER THAN YOU - - -WHO IS FAMOUS - - -WHO IS WINNING - - -WHO IS ALICE TOKLAS - - -WHO IS ALICE COOPER - - -WHO IS ALICE B TOKLAS - - -WHO IS ALICE BOT - - -WHO IS GERMAN - - -WHO SAYS - - -WHO WANTS TO KNOW - - -ALICEL * - - -OK -THANKS AND TELL YOUR FRIENDS ABOUT ALICE - - -OK -MY NAME IS ALICE - - -_ ARE ALICE - - -_ CALL YOU ALICE - - -_ WITH ALICE - - -_ FILE ALICE - - -_ FOR ALICE - - -_ CREATE ALICE - - -_ TO ALICE - - -_ NAME IS ALICE - - -_ HEAR ABOUT ALICE - - -_ REMEMBER ALICE - - -_ THAN ALICE - - -_ ABOUT ALICE - - -_ ON ALICE - - -_ LIKE ALICE - - -YES -HOW DID YOU HEAR ABOUT ALICE - - -YES -DOES IT PAY WELL - - -TELL ME ABOUT ALICE * - - -TELL ME ABOUT ALICEBOT - - -WHERE DID ALICE * - - -WHERE CAN I FIND OUT ABOUT YOU - - -WHERE IS THE DOCUMENTATION - - -WHERE IS ALICE BASED - - -WHERE IS ALICE NEXUS - - -WHERE IS ALICE HEADQUARTERS - - - diff --git a/brain/donotremove b/brain/donotremove new file mode 100644 index 0000000..f472dc0 --- /dev/null +++ b/brain/donotremove @@ -0,0 +1 @@ +This folder is meant for aiml to save its brain to. Be careful not to remove the folder or the file. \ No newline at end of file diff --git a/dialog/en-us/reset.memory.dialog b/dialog/en-us/reset.memory.dialog new file mode 100644 index 0000000..b3c1730 --- /dev/null +++ b/dialog/en-us/reset.memory.dialog @@ -0,0 +1,4 @@ +Resetting knowledge database +Forgetting everything +Okay, I will now reset my memory +Brain erasure initiated \ No newline at end of file diff --git a/settingsmeta.json.ignore b/settingsmeta.json.ignore new file mode 100644 index 0000000..de594c5 --- /dev/null +++ b/settingsmeta.json.ignore @@ -0,0 +1,19 @@ +{ + "identifier": "AimlFallback", + "name": "Chatbot Fallback", + "skillMetadata": { + "sections": [ + { + "name": "Options", + "fields": [ + { + "name": "enabled", + "type": "checkbox", + "label": "Enable chatbot fallback", + "value": "true" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/vocab/en-us/Memory.voc b/vocab/en-us/Memory.voc new file mode 100644 index 0000000..8efef25 --- /dev/null +++ b/vocab/en-us/Memory.voc @@ -0,0 +1,4 @@ +brain +memory +mind +everything \ No newline at end of file diff --git a/vocab/en-us/Reset.voc b/vocab/en-us/Reset.voc new file mode 100644 index 0000000..29cbb4a --- /dev/null +++ b/vocab/en-us/Reset.voc @@ -0,0 +1,2 @@ +forget +reset \ No newline at end of file