def branch(words):
"""
This initial filter of our input sentence.
It tokenizes the words and tags the words with parts of speech.
It then passes the tokenized and tagged words to 1 of 3 functions.
A sentence is either declarative() , interrogative() , or imperative()
Args:
words (String): The words inputted by the user
Returns:
String: response from one of the three functions that handle type of sentences.
"""
parts_of_speech = nltk.pos_tag(nltk.word_tokenize(words))
leading_word = parts_of_speech[0][1][0]
if leading_word == 'W':
return interrogative(parts_of_speech[1:])
elif leading_word == "V":
return imperative(parts_of_speech)
else:
declarative(parts_of_speech)
评论列表
文章目录