I have the following two strings with their POS tags:
Sent1: \"something like how writer pro or phraseology works would be really cool.\"<
it seem you would just search consecutive tags for "would" followed by "be" and then for the first instance of tag "JJ". Something like this:
import nltk
def has_would_be_adj(S):
# make pos tags
pos = nltk.pos_tag(S.split())
# Search consecutive tags for "would", "be"
j = None # index of found "would"
for i, (x, y) in enumerate(zip(pos[:-1], pos[1:])):
if x[0] == "would" and y[0] == "be":
j = i
break
if j is None or len(pos) < j + 2:
return False
a = None # index of found adjective
for i, (word, tag) in enumerate(pos[j + 2:]):
if tag == "JJ":
a = i+j+2 #
break
if a is None:
return False
print("Found adjective {} at {}", pos[a], a)
return True
S = "something like how writer pro or phraseology works would be really cool."
print(has_would_be_adj(S))
I'm sure this could be written compacter and cleaner but it does what it says on the box :)