From 66307d2f6fa7c011c750588f708cfc1deff74e1c Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Tue, 14 Apr 2009 23:34:23 +0000 Subject: Merge HabarConSara branch --- diff --git a/Speak.activity/NEWS b/Speak.activity/NEWS index 306df4b..d65c35e 100644 --- a/Speak.activity/NEWS +++ b/Speak.activity/NEWS @@ -1,3 +1,7 @@ +10 + +* #743: FIx crash for as sintaxis (dirakx) + 7 * #7852: Fix crash on launch by using numpy (morgs) diff --git a/Speak.activity/activity.py b/Speak.activity/activity.py index 8c4eaf5..240ffa1 100755..100644 --- a/Speak.activity/activity.py +++ b/Speak.activity/activity.py @@ -42,6 +42,7 @@ import fft_mouth import waveform_mouth import voice import face +import brain import chat import audio from collab import CollabActivity @@ -166,6 +167,8 @@ class SpeakActivity(CollabActivity): self.face.look_ahead() + self.brain = brain.defaultBrain(self.face.status.voice) + # say hello to the user presenceService = presenceservice.get_instance() xoOwner = presenceService.get_owner() @@ -272,6 +275,7 @@ class SpeakActivity(CollabActivity): def voice_changed_cb(self, combo): self.face.status.voice = combo.props.value self.face.say(self.face.status.voice.friendlyname) + self.brain = brain.defaultBrain(self.face.status.voice) def pitch_adjusted_cb(self, get, data=None): self.face.status.pitch = get.value @@ -369,7 +373,7 @@ class SpeakActivity(CollabActivity): self.face.look_ahead() # speak the text - self.face.say(text) + self.face.say(self.brain.respond(text)) # add this text to our history unless it is the same as the last item history = self.entrycombo.get_model() diff --git a/Speak.activity/activity/activity-hablarconsara.svg b/Speak.activity/activity/activity-hablarconsara.svg new file mode 100644 index 0000000..dcd31cc --- /dev/null +++ b/Speak.activity/activity/activity-hablarconsara.svg @@ -0,0 +1,134 @@ + + + +]> + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/Speak.activity/bot/PyAIML-0.8.5/CHANGES.txt b/Speak.activity/bot/PyAIML-0.8.5/CHANGES.txt new file mode 100644 index 0000000..9d4b0d5 --- /dev/null +++ b/Speak.activity/bot/PyAIML-0.8.5/CHANGES.txt @@ -0,0 +1,154 @@ +version 0.8.5 + - Fixed a couple lingering Unicode bugs, one of which was breaking things + pretty thoroughly under Python 2.2.3. + - Improved whitespace handling, to the point where it should be compliant + with the AIML 1.0.1 standard. Basically, whitespace will be stripped + down to readable levels, unless the xml:space attribute is used to + indicate otherwise. + - Fixed bug in PatternMgr where the character '1' was mistaken identified + as punctuation to be stripped, instead of the intended '!'. + +version 0.8.4: + - Fixed bug in AimlParser creation, if the aiml module was not in the same + directory as the script that imported it. + - Improved Unicode support (again) (thanks to Daniel Kottow for his help). + - 2nd pass at documentation. All functions now have useful, properly-formatted + docstrings. + +version 0.8.3: + - Reworked the way AimlParser objects are created, to allow support for + XML namespaces in a future version. + - First pass at Unicode-proofing the whole system, so that multi-lingual + AIML files can be processed. + - Added support for "index" attribute in "star", "thatstar" and "topicstar" + elements (thanks to Robert D. Cotey for the patch!). Also added type-check + to ensure that the value of the "index" attribute is an integer. + +version 0.8.2: + - Added protection against infinite AIML recursion. + - Removed the deprecated Kernel.getBotName and Kernel.setBotName functions. + - Added workaround for Unicode input crash. Feeding the Kernel Unicode + input no longer crashes the interpreter, but some internal input-formatting + operations must be skipped, which could cause some nonsensical replies + (like you're not already used to nonsensical replies, though...) + +version 0.8.1: + - "system" elements now attempt to intelligently convert between UNIX-style + and Windows-style pathnames as appropriate. For cross-platform compatibility, + all AIML files should use UNIX-style paths inside their "system" elements. + - Fixed crashes under Windows9X when a "system" element is executed when + w9xpopen.exe is unavailable. + - Re-piped most errors and warnings to go to stderr instead of stdout. + - Fixed bug that would cause the the bot to stop responding to any input in a session + if the "that" or "topic" strings were 100% whitespace (but still not empty). + - Fixed bug that would cause multi-line "that" strings to become corrupted. For + example, "Hello there.\nNice to meet you" would become "HELLO THERENICE TO MEET + YOU" when queried for that-matching. + +version 0.8: + - Removed support for non-standard "mode" attribute in "system" elements. + It just wasn't worth breaking the AIML standard for. + - Reworked persistent session support (I warned you!). The old method involving + Kernel.persistentSessions() has been removed. Instead, there is a new + Kernel.getSessionData() method which gives the bot author access to the session + data. You can store this data however you wish. Session data can be restored + later by repeated calls to Kernel.setPredicate(). + - Improved AIML parser error handling; instead of aborting the entire file, a + parse error now only ignores the current category and forges ahead. To check for + parse errors, check the return value of AimlParser.getNumErrors() after parsing. + +version 0.7: + - Further improved AIML parsing; missing or invalid XML attributes are now + detected at parse-time. There's also a first stab at support for Forward + Compatibility Mode: if the "version" attribute of an AIML tag is not 1.0.1, + the parser is much more forgiving of unknown or missing XML tags and attributes. + - Added "support" for the 'gossip' tag. The specific behavior of this tag is + totally undefined; currently, the PyAIML implementation treats it as a big + no-op. Its contents are ignored, and it returns the empty string (but at least + it isn't flagged as a syntax error!) + - Oops; I've implemented 'person' as 'person2' and vice versa this whole time! + Swapped them back; they should each behave correctly now. + - A bit of code cleanup, with an emphasis on using proper XML/AIML terminology + whenever possible. + - Fixed some exception-masking in the 'condition' element processor, which could + prevent AIML parse errors from being reported. + - Added full support for the "bot" tag (previously only the 'bot name="name"' + form was supported). Bot predicates are set using the Kernel.setBotPredicate() + function. Note that Kernel.getBotName() and Kernel.setBotName() have been + deprecated, and will disappear in a future release. + +version 0.6.1: + - Fixed undefined variable exception that was thrown whenever there was no + match for the user's input. + - Fixed an infinite recursion bug caused by processing two or more nested + 'srai' or 'sr' elements. + +version 0.6 + - Completely rewrote the LearnHandler class (which handles all AIML parsing) + to be much less forgiving of incorrect AIML. Currently, any AIML errors + outside of "template" elements should be caught and reported at load-time. + AIML errors inside templates are still not detected until run-time. + - Added support for atomic 'person' and 'person2' tags (they implicitly use + 'star' as their contents if none are provided). + - Oops; Kernel.respond() was DEFINITELY not thread-safe. Now it is, provided + you're using Python's standard 'threading' module. If not, you'll have to + provide your own mutual-exclusion system to ensure that only one thread + is calling Kernel.respond() at a time. + - Recursive tags ('srai' and 'sr') no longer add their intermediate results + to the input and output history. + - EXPERIMENTAL FEATURE: persistent sessions. If enabled using + Kernel.persistentSessions(True), session data will be written to disk + after every response. This lets session data be preserved when the + Kernel is destroyed, at the expense of a small performance hit (all + that extra disk I/O). The semantics of this feature may change in future + releases! + - Added support for the "id" tag (it returns the session ID). + - Added support for the "topic", "topicstar" and "thatstar" tags. + - Commented up the test.py file. + - Added a summary to the end of the Kernel.py self-test (since there are now + too many tests to fit on screen). + - Added support for multi-sentence input. The user's input is split into + individual sentences, each of which is treated as a completely separate + piece of input. I'm *pretty* sure this is the Right Way(tm). + +version 0.5 + - The filename inside Learn tags can now contain wildcards. Besides + simplifying the loading of multiple files, this allows the possibility + of loading AIML files that may not exist without crashing the + interpreter. + - Attempting to set the value of a predicate in a nonexistent session + now automatically creates the session, instead of silently doing nothing. + - "set" tags now output the new value of the variable, as well as assigning + it. + +version 0.4.1 + - Unknown AIML tags are handled in a more forgiving fashion. If an + unknown tag is encountered, instead of ignoring its contents entirely, + the contents are processed and returned unaltered. + - Added support for "bot name='name'" tags, both in patterns and in + templates. This also fixes a nasty infinite loop crash when a user + says Hello to a bot. + +version 0.4 + - Added support for "star" and "sr" tags. + - Considered adding support for the "secure" tag, but decided against it. + see SUPPORTED_TAGS.txt for more information. + +version 0.3 + - Cleaned up AIML processing code to remove some unnecessary + special-cases in the interpretation algorithm. + - Added support for "input" and "that" tags. + +version 0.2 + - 50% speedup in Kernel.loadBrain() and Kernel.saveBrain(). + - The optional 'learnFiles' and 'commands' arguments to + Kernel.bootstrap() can now be either strings or lists. This + allows multiple files/commands to be loaded during + initialization. + - Added support for "person" and "person2" tags. + - Added general word-substitution functionality. This opens up + the potential for localizing PyAIML into non-English languages. + See DefaultSubs.py for more info. + +version 0.1: + - Initial release. \ No newline at end of file diff --git a/Speak.activity/bot/PyAIML-0.8.5/README.txt b/Speak.activity/bot/PyAIML-0.8.5/README.txt new file mode 100644 index 0000000..82a7f8b --- /dev/null +++ b/Speak.activity/bot/PyAIML-0.8.5/README.txt @@ -0,0 +1,41 @@ +PyAIML -- The Python AIML Interpreter +author: Cort Stratton (cort@users.sourceforge.net) +web: http://pyaiml.sourceforge.net/ + +PyAIML is an interpreter for AIML (the Artificial Intelligence Markup +Language), implemented entirely in standard Python. It strives for +simple, austere, 100% compliance with the AIML 1.0.1 standard, no less +and no more. + +This is currently pre-alpha software. Use at your +own risk! + +For information on what's new in this version, see the +CHANGES.txt file. + +For information on the state of development, including +the current level of AIML 1.0.1 compliance, see the +SUPPORTED_TAGS.txt file. + +Quick & dirty example (assuming you've downloaded the +"standard" AIML set): + + import aiml + + # The Kernel object is the public interface to + # the AIML interpreter. + k = aiml.Kernel() + + # Use the 'learn' method to load the contents + # of an AIML file into the Kernel. + k.learn("std-startup.xml") + + # Use the 'respond' method to compute the response + # to a user's input string. respond() returns + # the interpreter's response, which in this case + # we ignore. + k.respond("load aiml b") + + # Loop forever, reading user input from the command + # line and printing responses. + while True: print k.respond(raw_input("> ")) \ No newline at end of file diff --git a/Speak.activity/bot/PyAIML-0.8.5/SUPPORTED_TAGS.txt b/Speak.activity/bot/PyAIML-0.8.5/SUPPORTED_TAGS.txt new file mode 100644 index 0000000..bbbf708 --- /dev/null +++ b/Speak.activity/bot/PyAIML-0.8.5/SUPPORTED_TAGS.txt @@ -0,0 +1,94 @@ +This document describes the current state of PyAIML's compliance +to the AIML 1.0.1 standard. The full AIML reference manual can be +found online at http://alicebot.org/TR/2001/WD-aiml. + +The following tags are currently supported: + + (see notes) + + + + + + + + +
  • + + + + + + + + + + + + + + + + + + + +Support for the following tags should be implemented in the next version: + + None + +The following tags are not supported: + + (see notes) + / (see notes) + (see notes) + (see notes) + +------------------------------------------------------------------ + +NOTES ON SPECIFIC TAGS: + + +To set the bot's name, use Kernel.setBotName("NewName"). Note that the +name *MUST* be a single word! Use Kernel.getBotName() to query the bot's +name in your code. + + +The AIML 1.0.1 specification lets engine authors implement the the behavior +of the tag however they wish. I haven't yet decided what I'd like +to do with it, so right now it doesn't do anything at all. + + / +These elements appear to have been dropped between AIML 1.0 and AIML 1.0.1. +They may someday be added as a part of an AIML 1.0 backwards-compatibility +mode, but in the meantime, use instead. + + +Support for the JavaScript tag is not anticipated; one of the design +goals of PyAIML is to remain 100% pure standard Python. So until +somebody writes a JavaScript interpreter in Python, PyAIML won't +support the tag. On the bright side, it is possible +to simulate the effects of the tag (i.e. dynamically- +generated tag contents) using the tag. This +solution has the added advantage of allowing *any* programming +language to be used, not just JavaScript. +UPDATE: The python-spidermonkey project provides a bridge between Python +and the open-source SpiderMonkey JavaScript library. I am currently +investigating the possibility of adding support for the +tag ON A PURELY OPTIONAL BASIS. + + +Some AIML implementations support a non-standard tag, intended to +wrap parts of a template which should only be processed if the user is +"secure", or trusted. After implementing support for this tag, I realized +that it wasn't doing anything that you can't do with the tag. +Therefore, I've decided to drop support for the tag. You can +easily duplicate its effects; simply replace this: + you are allowed +with this: + +
  • you are allowed
  • +
  • you are not allowed
  • +
    +Then, use the Kernel.setPredicate() call to set the "secure" predicate to +"yes" for any session that you wish to be secure. \ No newline at end of file diff --git a/Speak.activity/bot/PyAIML-0.8.5/TODO.txt b/Speak.activity/bot/PyAIML-0.8.5/TODO.txt new file mode 100644 index 0000000..cd75a71 --- /dev/null +++ b/Speak.activity/bot/PyAIML-0.8.5/TODO.txt @@ -0,0 +1,13 @@ +Laundry list of future tasks, in no particular order: + + - AIML 1.0.1 compliance (highest priority): + - Unknown yet well-defined elements (e.g. HTML) inside templates + (see sections 3.2, 3.6). + - AimlParser._validateElemStart() needs to test the well-formedness of + attribute values (for example, making sure that the "index" attribute + has an integer value, and not a string). UPDATE: this works for , + and . Still needs to be written for and , + which take either an integer or an integer pair. + - Support the Program D startup file syntax, or something similar? It + seems to be a good way to initialize bot settings and substitutions. + - Documentation/tutorials. diff --git a/Speak.activity/bot/PyAIML-0.8.5/pkg-info b/Speak.activity/bot/PyAIML-0.8.5/pkg-info new file mode 100644 index 0000000..908caaa --- /dev/null +++ b/Speak.activity/bot/PyAIML-0.8.5/pkg-info @@ -0,0 +1,12 @@ +Metadata-Version: 1.0 +Name: PyAIML +Version: 0.8.5 +Summary: An interpreter package for AIML, the Artificial Intelligence Markup Language +Home-page: http://pyaiml.sourceforge.net/ +Author: Cort Stratton +Author-email: cort@users.sourceforge.net +License: UNKNOWN +Description: PyAIML implements an interpreter for AIML, the Artificial Intelligence + Markup Language developed by Dr. Richard Wallace of the A.L.I.C.E. Foundation. + It can be used to implement a conversational AI program. +Platform: any diff --git a/Speak.activity/bot/PyAIML-0.8.5/setup.cfg b/Speak.activity/bot/PyAIML-0.8.5/setup.cfg new file mode 100644 index 0000000..89ca66e --- /dev/null +++ b/Speak.activity/bot/PyAIML-0.8.5/setup.cfg @@ -0,0 +1,6 @@ +[bdist_wininst] +title=PyAIML + +[sdist] +formats=zip,gztar,bztar + diff --git a/Speak.activity/bot/PyAIML-0.8.5/setup.py b/Speak.activity/bot/PyAIML-0.8.5/setup.py new file mode 100755 index 0000000..3cc058a --- /dev/null +++ b/Speak.activity/bot/PyAIML-0.8.5/setup.py @@ -0,0 +1,34 @@ +# Command to build: +from distutils.core import setup +import glob + +package_prefix = "Lib/site-packages/aiml" + +setup(name="PyAIML", + version="0.8.5", + author="Cort Stratton", + author_email="cort@users.sourceforge.net", + maintainer="Cort Stratton", + maintainer_email="cort@users.sourceforge.net", + + description="An interpreter package for AIML, the Artificial Intelligence Markup Language", + long_description="""PyAIML implements an interpreter for AIML, the Artificial Intelligence +Markup Language developed by Dr. Richard Wallace of the A.L.I.C.E. Foundation. +It can be used to implement a conversational AI program.""", + url="http://pyaiml.sourceforge.net/", + platforms=["any"], + classifiers=["Development Status :: 3 - Alpha", + "Environment :: Console", + "Intended Audience :: Developers", + "Programming Language :: Python", + "Operating System :: OS Independent", + "Topic :: Communications :: Chat", + "Topic :: Scientific/Engineering :: Artificial Intelligence" + ], + + packages=["aiml"], + data_files=[ + (package_prefix, glob.glob("aiml/self-test.aiml")), + (package_prefix, glob.glob("*.txt")), + ], +) diff --git a/Speak.activity/bot/README b/Speak.activity/bot/README new file mode 100644 index 0000000..449768c --- /dev/null +++ b/Speak.activity/bot/README @@ -0,0 +1,9 @@ +HabarConSara Activity + +Humorada de modificación a Actividad Hablar +Elaborada por Sebastian Silva + +http://www.fuentelibre.org/ + +Puede obtener las fuentes de los cerebros AIML descargando la versión de desarrollo: +git clone git://gitorious.org/hablar-con-sara/mainline.git HablarConSara.activity diff --git a/Speak.activity/bot/__init__.py b/Speak.activity/bot/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Speak.activity/bot/__init__.py diff --git a/Speak.activity/bot/aiml/AimlParser.py b/Speak.activity/bot/aiml/AimlParser.py new file mode 100755 index 0000000..75c2cf1 --- /dev/null +++ b/Speak.activity/bot/aiml/AimlParser.py @@ -0,0 +1,545 @@ +from xml.sax.handler import ContentHandler +from xml.sax.xmlreader import Locator +import sys +import xml.sax +import xml.sax.handler + +class AimlParserError(Exception): pass + +class AimlHandler(ContentHandler): + # The legal states of the AIML parser + _STATE_OutsideAiml = 0 + _STATE_InsideAiml = 1 + _STATE_InsideCategory = 2 + _STATE_InsidePattern = 3 + _STATE_AfterPattern = 4 + _STATE_InsideThat = 5 + _STATE_AfterThat = 6 + _STATE_InsideTemplate = 7 + _STATE_AfterTemplate = 8 + + def __init__(self, encoding = "UTF-8"): + self.categories = {} + self._encoding = encoding + self._state = self._STATE_OutsideAiml + self._version = "" + self._namespace = "" + self._forwardCompatibleMode = False + self._currentPattern = "" + self._currentThat = "" + self._currentTopic = "" + self._insideTopic = False + self._currentUnknown = "" # the name of the current unknown element + + # This is set to true when a parse error occurs in a category. + self._skipCurrentCategory = False + + # Counts the number of parse errors in a particular AIML document. + # query with getNumErrors(). If 0, the document is AIML-compliant. + self._numParseErrors = 0 + + # TODO: select the proper validInfo table based on the version number. + self._validInfo = self._validationInfo101 + + # This stack of bools is used when parsing
  • elements inside + # elements, to keep track of whether or not an + # attribute-less "default"
  • element has been found yet. Only + # one default
  • is allowed in each element. We need + # a stack in order to correctly handle nested tags. + self._foundDefaultLiStack = [] + + # This stack of strings indicates what the current whitespace-handling + # behavior should be. Each string in the stack is either "default" or + # "preserve". When a new AIML element is encountered, a new string is + # pushed onto the stack, based on the value of the element's "xml:space" + # attribute (if absent, the top of the stack is pushed again). When + # ending an element, pop an object off the stack. + self._whitespaceBehaviorStack = ["default"] + + self._elemStack = [] + self._locator = Locator() + self.setDocumentLocator(self._locator) + + def getNumErrors(self): + "Return the number of errors found while parsing the current document." + return self._numParseErrors + + def setEncoding(self, encoding): + """Set the text encoding to use when encoding strings read from XML. + + Defaults to 'UTF-8'. + + """ + self._encoding = encoding + + def _location(self): + "Return a string describing the current location in the source file." + line = self._locator.getLineNumber() + column = self._locator.getColumnNumber() + return "(line %d, column %d)" % (line, column) + + def _pushWhitespaceBehavior(self, attr): + """Push a new string onto the whitespaceBehaviorStack. + + The string's value is taken from the "xml:space" attribute, if it exists + and has a legal value ("default" or "preserve"). Otherwise, the previous + stack element is duplicated. + + """ + assert len(self._whitespaceBehaviorStack) > 0, "Whitespace behavior stack should never be empty!" + try: + if attr["xml:space"] == "default" or attr["xml:space"] == "preserve": + self._whitespaceBehaviorStack.append(attr["xml:space"]) + else: + raise AimlParserError, "Invalid value for xml:space attribute "+self._location() + except KeyError: + self._whitespaceBehaviorStack.append(self._whitespaceBehaviorStack[-1]) + + def startElementNS(self, name, qname, attr): + print "QNAME:", qname + print "NAME:", name + uri,elem = name + if (elem == "bot"): print "name:", attr.getValueByQName("name"), "a'ite?" + self.startElement(elem, attr) + pass + + def startElement(self, name, attr): + # Wrapper around _startElement, which catches errors in _startElement() + # and keeps going. + + # If we're inside an unknown element, ignore everything until we're + # out again. + if self._currentUnknown != "": + return + # If we're skipping the current category, ignore everything until + # it's finished. + if self._skipCurrentCategory: + return + + # process this start-element. + try: self._startElement(name, attr) + except AimlParserError, msg: + # Print the error message + sys.stderr.write("PARSE ERROR: %s\n" % msg) + + self._numParseErrors += 1 # increment error count + # In case of a parse error, if we're inside a category, skip it. + if self._state >= self._STATE_InsideCategory: + self._skipCurrentCategory = True + + def _startElement(self, name, attr): + if name == "aiml": + # tags are only legal in the OutsideAiml state + if self._state != self._STATE_OutsideAiml: + raise AimlParserError, "Unexpected tag "+self._location() + self._state = self._STATE_InsideAiml + self._insideTopic = False + self._currentTopic = u"" + try: self._version = attr["version"] + except KeyError: + # This SHOULD be a syntax error, but so many AIML sets out there are missing + # "version" attributes that it just seems nicer to let it slide. + #raise AimlParserError, "Missing 'version' attribute in tag "+self._location() + #print "WARNING: Missing 'version' attribute in tag "+self._location() + #print " Defaulting to version 1.0" + self._version = "1.0" + self._forwardCompatibleMode = (self._version != "1.0.1") + self._pushWhitespaceBehavior(attr) + # Not sure about this namespace business yet... + #try: + # self._namespace = attr["xmlns"] + # if self._version == "1.0.1" and self._namespace != "http://alicebot.org/2001/AIML-1.0.1": + # raise AimlParserError, "Incorrect namespace for AIML v1.0.1 "+self._location() + #except KeyError: + # if self._version != "1.0": + # raise AimlParserError, "Missing 'version' attribute(s) in tag "+self._location() + elif self._state == self._STATE_OutsideAiml: + # If we're outside of an AIML element, we ignore all tags. + return + elif name == "topic": + # tags are only legal in the InsideAiml state, and only + # if we're not already inside a topic. + if (self._state != self._STATE_InsideAiml) or self._insideTopic: + raise AimlParserError, "Unexpected tag", self._location() + try: self._currentTopic = unicode(attr['name']) + except KeyError: + raise AimlParserError, "Required \"name\" attribute missing in element "+self._location() + self._insideTopic = True + elif name == "category": + # tags are only legal in the InsideAiml state + if self._state != self._STATE_InsideAiml: + raise AimlParserError, "Unexpected tag "+self._location() + self._state = self._STATE_InsideCategory + self._currentPattern = u"" + self._currentThat = u"" + # If we're not inside a topic, the topic is implicitly set to * + if not self._insideTopic: self._currentTopic = u"*" + self._elemStack = [] + self._pushWhitespaceBehavior(attr) + elif name == "pattern": + # tags are only legal in the InsideCategory state + if self._state != self._STATE_InsideCategory: + raise AimlParserError, "Unexpected tag "+self._location() + self._state = self._STATE_InsidePattern + elif name == "that" and self._state == self._STATE_AfterPattern: + # are legal either inside a