本文整理汇总了Python中query.Query.isCanonical方法的典型用法代码示例。如果您正苦于以下问题:Python Query.isCanonical方法的具体用法?Python Query.isCanonical怎么用?Python Query.isCanonical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类query.Query
的用法示例。
在下文中一共展示了Query.isCanonical方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Session
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import isCanonical [as 别名]
class Session(object):
_dbSessionByUserId = {}
@classmethod
def getUserSession(cls, user):
sessionId = user.userId # quite the bad assumption!!
if sessionId in cls._dbSessionByUserId:
print('found a session for user')
return cls._dbSessionByUserId[sessionId]
print ('inserting a session for this user')
lSession = Session(sessionId, user)
cls._dbSessionByUserId[sessionId] = lSession
return lSession
def __init__(self, sessionId, user):
self.sessionId =sessionId
self.user = user
self.state = STATE_RESOLVING_QUERY_AND_LOCATION
self.location = None
self.query = Query(sessionId, '')
self.convoHistory = [] # tuples (time, in|out, text) ###appended
def respondToUserMessage(self, telMessage, matcher):
print("session gets an object like this " + str(type(telMessage)) + ", value=" + str(telMessage))
# state machine
# always change lastUpdateTime
# potentially creates query
# potentially adds to matcher
# returns None, or Message to send to user (based on Brain's thoughts)
# see
if telMessage.location:
if self.state > STATE_RESOLVING_QUERY_AND_LOCATION:
return "It is too late to change the location - cancel and resubmit if you want to change"
self.location = telMessage.location
if self.state == STATE_RESOLVING_LOCATION_ONLY:
matcher.addQuery(self.query)
self.state = STATE_WAITING_FOR_MATCH
return "OK! We are seeking a match for you now!"
if self.state ==STATE_RESOLVING_QUERY_ONLY:
return "Changed your location - still trying to resolve your query: \n" + self.query.errorText
if self.state == STATE_RESOLVING_QUERY_AND_LOCATION:
self.state = STATE_RESOLVING_QUERY_ONLY
return "Thanks for your location - still trying to resolve your query: \n" + self.query.errorText
raise("Something went horribly wrong - got new location and state was " + str(self.state))
elif telMessage.text:
print ("got me some text")
if self.state > STATE_RESOLVING_QUERY_AND_LOCATION:
return "It is too late to change the query - cancel and resubmit if you want to change"
self.query.setRawQuery(telMessage.text)
oldWasGood = self.state in [STATE_RESOLVING_LOCATION_ONLY]
newIsGood = self.query.isCanonical()
if self.state == STATE_RESOLVING_QUERY_ONLY:
if newIsGood:
matcher.addQuery(self.query)
self.state = STATE_WAITING_FOR_MATCH
return "OK! We are seeking a match for you now!"
else:
return "Have location, but still waiting for proper query\n" + self.query.errorText
if self.state ==STATE_RESOLVING_LOCATION_ONLY:
if newIsGood:
return "Query change accepted - still waiting for location"
else:
self.state = STATE_RESOLVING_QUERY_AND_LOCATION
return "Still waiting for both location and proper query\n" + self.query.errorText
if self.state == STATE_RESOLVING_QUERY_AND_LOCATION:
if newIsGood:
self.state = STATE_RESOLVING_LOCATION_ONLY
return "Query is valid! Still waiting for location"
else:
return "Still waiting for both location and proper query\n" + self.query.errorText
raise("Something went horribly wrong - got new text=" + str(self.query.rawText) + " and state was " + str(self.state))