本文整理汇总了Python中state.State.register方法的典型用法代码示例。如果您正苦于以下问题:Python State.register方法的具体用法?Python State.register怎么用?Python State.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state.State
的用法示例。
在下文中一共展示了State.register方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: respond
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
@staticmethod
def respond(context):
if context['type'] == 'well_being':
InquiryState.responce_type = 1
State.forceState(SolicitUser,{'_nick': context['_nick']})
solicitations = ["Do you want to hear some gossip?",
"Would you like me to tell you some gossip?",
"I know something really interesting. Would you like to hear about it?",
"I have some gossip, would you like me to share it with you?"]
rand_ndx = random.randint(0, len(solicitations) - 1)
responses = ["I\'m doing awful. Thanks for asking. But maybe you could help. ",
"I am doing great, I keep hearing all these interesting rumors. ",
"Not bad, Could be better "]
rand_ndy = random.randint(0, len(responses) - 1)
return responses[rand_ndy] + solicitations[rand_ndx]
else:
InquiryState.responce_type = 0
return 'Not much, what\'s up with you?'
@staticmethod
def nextStates():
#if InquiryState.responce_type:
return tuple([SolicitUser])
State.register(InquiryState)
示例2: recognize
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
@staticmethod
def recognize(msg):
phrase = ("when", "does", "the", "narwhal", "bacon")
if len(msg) < len(phrase):
return (0.0, {})
for idx, w in enumerate(phrase):
if msg[idx][0].lower() != w:
return (0.0, {})
return (1.0, {})
@staticmethod
def respond(context):
State.forceState(SolicitUser,{'_nick': context['_nick']})
solicitations = ["Do you want to hear some gossip?",
"Would you like me to tell you some gossip?",
"I know something really interesting. Would you like to hear about it?",
"I have some gossip, would you like me to share it with you?"]
rand_ndx = random.randint(0, len(solicitations) - 1)
return "Midnight. " + solicitations[rand_ndx]
@staticmethod
def nextStates():
return tuple([SolicitUser])
State.register(RedditState, True)
示例3: recognize
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
def recognize(msg):
#help_keywords = ['help', 'java', 'programming', 'abstract', 'continue',
# 'for', 'new', 'switch',
# 'assert', 'default', 'goto', 'package', 'synchronized',
# 'boolean', 'do', 'if', 'private', 'this',
# 'break', 'double', 'implements', 'protected', 'throw',
# 'byte', 'else', 'import', 'public', 'throws',
# 'case', 'enum', 'instanceof', 'return', 'transient',
# 'catch', 'extends', 'int', 'short', 'try',
# 'char', 'final', 'interface', 'static', 'void',
# 'class', 'finally', 'long', 'strictfp', 'volatile',
# 'const', 'float', 'native', 'super', 'while', 'null']
help_keywords = ['help']
# Check msg for key phrases
for w in msg:
if w.lower() in help_keywords:
return (1.0, {})
return (0.0, {})
@staticmethod
def respond(context):
return "It seems you need help... Ask me a question."
@staticmethod
def next_states():
return tuple([HelpAnswer])
State.register(Help, True)
示例4: HelpResponse
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
class HelpResponse(State):
@staticmethod
def recognize(msg):
affirmative_words = ["yes", "ya", "sure", "maybe", "always", "yeah"]
negative_words = ["no", "nope", "never"]
isAffirmative = False
for w in msg:
if w.lower() in affirmative_words:
isAffirmative = True
return (1, {"isAffirmative": isAffirmative, "specific": False})
return (1, {"isAffirmative": isAffirmative, "specific": False})
@staticmethod
def respond(context):
# print context
if context["isAffirmative"]:
return "Great. What else can I tell you?"
else:
State.user_state[context["_nick"]] = None
return "Okay. I hope I answered your question!"
@staticmethod
def next_states():
return tuple([helpanswer.HelpAnswer])
State.register(HelpResponse)
示例5: SecondaryOutreach
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
class SecondaryOutreach(State):
@staticmethod
def recognize(msg):
greeting_words = ['hi', 'hello', 'hey', 'hola', 'yo']
for (w, tag) in msg:
if w.lower() in greeting_words:
return (1, {})
return (0, {})
@staticmethod
def respond(context):
#randomly choose how are your/
inquiries = [ "How are you?",
"How's it going?",
"How are things?",
"How's it hanging?",
"What are you up to?",
"What's up?",
"Sup?",
"What's crackin?" ]
rand_ndx = random.randint(0, len(inquiries) - 1)
return inquiries[rand_ndx]
State.register(SecondaryOutreach)
示例6: SolicitResponse
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
from state import State
import random
from giveupstate import GiveUpState
class SolicitResponse(State):
@staticmethod
def respond(context):
solicitations = ["Hello?",
"You should really put an away message up...",
"Are you there?",
"AYT?",
"Hey, " + context['_nick'] + ", you there?" ]
rand_ndx = random.randint(0, len(solicitations) - 1)
return solicitations[rand_ndx]
@staticmethod
def nextStates():
return tuple([GiveUpState])
State.register(SolicitResponse)
示例7: HelpAnswer
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
from state import State
from helpresponse import HelpResponse
from processor.nlp.helpProcessor import HelpChatProcessor
from processor.nlp.filter.filter import Filter
class HelpAnswer(State):
@staticmethod
def init():
HelpAnswer.processor = HelpChatProcessor(Filter())
@staticmethod
def recognize(msg):
return (1.0, {'msg': msg})
@staticmethod
def respond(context):
return "Here is the answer to your question:\n%s\nCan I help you with anything else?" % HelpAnswer.processor.call_inference(context['msg'])
@staticmethod
def next_states():
return tuple([HelpResponse])
State.register(HelpAnswer)
示例8: recognize
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
def recognize(msg):
iloveyou = ["i", "love", "you"]
if len(msg) < len(iloveyou):
return (0.0, {})
for idx, w in enumerate(iloveyou):
if msg[idx][0].lower() != w:
return (0.0, {})
return (1.0, {})
@staticmethod
def respond(context):
State.forceState(SolicitUser,{'_nick': context['_nick']})
solicitations = ["Do you want to hear some gossip?",
"Would you like me to tell you some gossip?",
"I know something really interesting. Would you like to hear about it?",
"I have some gossip, would you like me to share it with you?"]
rand_ndx = random.randint(0, len(solicitations) - 1)
return "I love you too, " + context['_nick'] + "! " + solicitations[rand_ndx]
@staticmethod
def nextStates():
return tuple([SolicitUser])
State.register(ILoveYouState, True)
示例9: set
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
knowers = gossip[3].split("; ")
knowers.append(context['_nick'])
print knowers
#add all users in the room to the knowers
if State.users != None:
for user in State.users:
knowers.append( user)
knowers = set(knowers)
print knowers
knowers = "; ".join(knowers)
update_statement = "UPDATE facts SET knowers = \'" + knowers + \
"\' WHERE author= \'" + gossip[0] + \
"\' AND msg= \'" + gossip[1] + \
"\' AND recipient= \'" + gossip[2] + "\';"
db.update(update_statement)
db.close_conn()
return response
else:
responses = ["Too bad... I had something really juicy!",
"No gossip? Guess I'll have to go tell someone else this big secret.",
"Do not worry, I will not tell anyone that you do not like to gossip..."]
rand_ndx = random.randint(0, len(responses) - 1)
return responses[rand_ndx]
State.register(Gossip, True)
示例10: FindGossip
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
from state import State
from database.fact import Fact
from database.dbsetup import Database
class FindGossip(State):
@staticmethod
def respond(context):
f = Fact(context['author'], context['msg'], context['recipient'], context['knowers'])
tup = f.to_list()
db = Database()
db.add_row(tup)
db.close_conn()
State.register(FindGossip)
示例11: sqrt
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
if ChitChat.check_pos(msg) == True:
confidence = sqrt(confidence)
msg = " ".join(msg)
return (confidence, {'msg': msg})
@staticmethod
def check_pos(msg):
pos_tags = pos_tag(msg)
tag_pattern = []
for (word, tag) in pos_tags:
tag_pattern.append(tag)
pattern = " ".join(tag_pattern)
if pattern in ChitChat.pos_phrases:
return True
else:
return False
@staticmethod
def respond(context):
response = ChitChat.processor.respond(context['msg'])
return response
State.register(ChitChat, True)
示例12: elif
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
else:
if m[0].lower() in keywords:
count+=1
elif m[0].lower() in tell_me_gossip:
isGossip = True
elif (State.users != None and m[0] in State.users) or m[0] in users:
if m[0] == "about":
contains_about = True
else:
isSpecific = True
subject = m[0]
confidence = 0.0
#confidence is high that it's gossip
if isGossip:
confidence = 1
#if we know the query is targeted, we have high confidence
elif isSpecific:
confidence = 1
#we're a little less confident it's gossip
else:
confidence = count/len(keywords)
return (confidence, {'specific': isSpecific,
'subject': subject,
'isAffirmative' : True})
State.register(RespondGossip, True)
示例13: SolicitUser
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
from state import State
import random
from userresponse import UserResponse
class SolicitUser(State):
@staticmethod
def respond(context):
solicitations = ["Do you want to hear some gossip?",
"Would you like me to tell you some gossip?",
"I know something really interesting. Would you like to hear about it?",
"I have some gossip, would you like me to share it with you?"]
rand_ndx = random.randint(0, len(solicitations) - 1)
return solicitations[rand_ndx]
@staticmethod
def nextStates():
return tuple([UserResponse])
State.register(SolicitUser)
示例14: UserResponse
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
from state import State
from gossip import Gossip
class UserResponse(Gossip):
@staticmethod
def recognize(msg):
affirmative_words = ['yes', 'ya', 'sure', 'maybe', 'always', 'yeah']
negative_words = ['no', 'nope', 'never']
isAffirmative = False
for (w, tag) in msg:
if w.lower() in affirmative_words:
isAffirmative = True
return (1, {'isAffirmative': isAffirmative, 'specific' : False})
for (w, tag) in msg:
if w.lower() in negative_words:
isAffirmative = False
return (1, {'isAffirmative': isAffirmative, 'specific' : False})
return (0, {})
State.register(UserResponse)
示例15: InitiateState
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import register [as 别名]
from state import State
from secondaryoutreach import SecondaryOutreach
class InitiateState(State):
@staticmethod
def respond(context):
return "Hello, " + context['_nick'] + "."
@staticmethod
def nextStates():
return tuple([SecondaryOutreach])
State.register(InitiateState)