本文整理汇总了Python中PatternMgr.PatternMgr.add方法的典型用法代码示例。如果您正苦于以下问题:Python PatternMgr.add方法的具体用法?Python PatternMgr.add怎么用?Python PatternMgr.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PatternMgr.PatternMgr
的用法示例。
在下文中一共展示了PatternMgr.add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: session
# 需要导入模块: from PatternMgr import PatternMgr [as 别名]
# 或者: from PatternMgr.PatternMgr import add [as 别名]
class Kernel:
# module constants
_globalSessionID = "_global" # key of the global session (duh)
_maxHistorySize = 10 # maximum length of the _inputs and _responses lists
_maxRecursionDepth = 1000 # maximum number of recursive <srai>/<sr> tags before the response is aborted.
# special predicate keys
_inputHistory = "_inputHistory" # keys to a queue (list) of recent user input
_outputHistory = "_outputHistory" # keys to a queue (list) of recent responses.
_inputStack = "_inputStack" # Should always be empty in between calls to respond()
def __init__(self):
self._verboseMode = True
self._version = "PyAIML 0.8.6"
self._brain = PatternMgr()
self._respondLock = threading.RLock()
self._textEncoding = "utf-8"
# set up the sessions
self._sessions = {}
self._addSession(self._globalSessionID)
# Set up the bot predicates
self._botPredicates = {}
self.setBotPredicate("name", "Freezer")
self.setBotPredicate("botmaster", "Jose Quintero")
year_of_birth=2013
self.setBotPredicate("anyo_nacimiento", str(year_of_birth))
age=date.today().year-2013
self.setBotPredicate("edad", str(age))
# set up the word substitutors (subbers):
self._subbers = {}
self._subbers['gender'] = WordSub(DefaultSubs.defaultGender)
self._subbers['person'] = WordSub(DefaultSubs.defaultPerson)
self._subbers['person2'] = WordSub(DefaultSubs.defaultPerson2)
self._subbers['normal'] = WordSub(DefaultSubs.defaultNormal)
# set up the element processors
self._elementProcessors = {
"bot": self._processBot,
"condition": self._processCondition,
"date": self._processDate,
"formal": self._processFormal,
"gender": self._processGender,
"get": self._processGet,
"gossip": self._processGossip,
"id": self._processId,
"input": self._processInput,
"javascript": self._processJavascript,
"learn": self._processLearn,
"li": self._processLi,
"lowercase": self._processLowercase,
"person": self._processPerson,
"person2": self._processPerson2,
"random": self._processRandom,
"text": self._processText,
"sentence": self._processSentence,
"set": self._processSet,
"size": self._processSize,
"sr": self._processSr,
"srai": self._processSrai,
"star": self._processStar,
"system": self._processSystem,
"template": self._processTemplate,
"that": self._processThat,
"thatstar": self._processThatstar,
"think": self._processThink,
"topicstar": self._processTopicstar,
"uppercase": self._processUppercase,
"version": self._processVersion,
}
def bootstrap(self, brainFile = None, learnFiles = [], commands = []):
"""Prepare a Kernel object for use.
If a brainFile argument is provided, the Kernel attempts to
load the brain at the specified filename.
If learnFiles is provided, the Kernel attempts to load the
specified AIML files.
Finally, each of the input strings in the commands list is
passed to respond().
"""
start = time.clock()
if brainFile:
self.loadBrain(brainFile)
# learnFiles might be a string, in which case it should be
# turned into a single-element list.
learns = learnFiles
try: learns = [ learnFiles + "" ]
except: pass
for file in learns:
self.learn(file)
# ditto for commands
cmds = commands
try: cmds = [ commands + "" ]
#.........这里部分代码省略.........