def check_imperative(self, paragraph):
"""
Check the given sentence/s for Imperatives.
:param paragraph:
The input paragraph to be tested.
:return:
A list of tuples having 2 elements (invalid word, parts of speech)
or an empty list if no invalid words are found.
"""
words = nltk.word_tokenize(nltk.sent_tokenize(paragraph)[0])
# VBZ : Verb, 3rd person singular present, like 'adds', 'writes'
# etc
# VBD : Verb, Past tense , like 'added', 'wrote' etc
# VBG : Verb, Present participle, like 'adding', 'writing'
word, tag = nltk.pos_tag(['I'] + words)[1:2][0]
if(tag.startswith('VBZ') or
tag.startswith('VBD') or
tag.startswith('VBG') or
word.endswith('ing')): # Handle special case for VBG
return (word, tag)
else:
return None
评论列表
文章目录