import spacy, en_core_web_sm
nlp = en_core_web_sm.load()
doc = nlp(u"I will go to the mall")
chk_set = set(['VERB'])
print chk_set.issubset(t.pos_ for t in doc)
The code above returns True if POS = verb is present.
Now I want to extend this code to read through a list of sentences stored in an excel sheet. To check the presence of punctuation in the sentence I am able to achieve it using the code below.
The question is how to extend this the code below to incorporate verb check above.
from pandas import read_excel
import pandas as pd
import xlsxwriter
my_sheet_name = 'Metrics'
df = read_excel('sentence.xlsx', sheet_name = my_sheet_name)
df['.']=df['Sentence'].str.contains('.')
# df['VERB']=df['Sentence'].str.contains('.')
writer = pd.ExcelWriter('sentence.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Metrics')
writer.save()
Expected result:
Sentence Verb
I will go to the mall True
the mall False
I may be here tomorrow. True