Download presentation
Presentation is loading. Please wait.
1
Working with Dictionaries
def reply(sentence): """Returns a reply to the sentence.""” if 'mom' or 'work' or 'died' in sentence.split(): for word in sentence.split(): if word == 'mom': return random.choice(keywords.get('mom')) if word == 'work': return random.choice(keywords.get('work')) if word == 'died': return random.choice(keywords.get('died')) probability = random.randint(0, 3) if probability == 0: return random.choice(hedges)) etc.
2
Working with Dictionaries
def reply(sentence): """Returns a reply to the sentence.""” probability = random.randint(0, 3) if probability == 0: return random.choice(hedges)) elif probability == 1: return getKeywordResponse(sentence) etc.
3
Working with Dictionaries
def getKeywordResponse(sentence): """Returns a keyword response to the sentence.""” if 'mom' or 'work' or 'died' in sentence.split(): for word in sentence.split(): if word == 'mom': return random.choice(keywords.get('mom')) if word == 'work': return random.choice(keywords.get('work')) if word == 'died': return random.choice(keywords.get('died')) return reply(sentence)
4
Working with Dictionaries
def getKeywordResponse(sentence): """Returns a keyword response to the sentence.""” for word in sentence.split(): if word in keywords: return random.choice(keywords.get(word)) return reply(sentence)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.