I have the following two strings with their POS tags:
Sent1: \"something like how writer pro or phraseology works would be really cool.\"<
Check StackOverflow Link
from nltk.tokenize import word_tokenize def would_be(tagged): return any(['would', 'be', 'JJ'] == [tagged[i][0], tagged[i+1][0], tagged[i+2][1]] for i in xrange(len(tagged) - 2)) S = "more options like the syntax editor would be nice." pos = nltk.pos_tag(word_tokenize(S)) would_be(pos)
Also check code
from nltk.tokenize import word_tokenize
import nltk
def checkTag(S):
pos = nltk.pos_tag(word_tokenize(S))
flag = 0
for tag in pos:
if tag[1] == 'JJ':
flag = 1
if flag:
for ind,tag in enumerate(pos):
if tag[0] == 'would' and pos[ind+1][0] == 'be':
return True
return False
return False
S = "something like how writer pro or phraseology works would be really cool."
print checkTag(S)