My goal is to extract SVO-triplets from simple sentences. For example for the sentence "A person is standing in a kitchen making a sandwich." I want the output <person, standing, kitchen> and <person, making, sandwich>. I tried to use spacy/textacy for this, but somehow it won't return me any triplets (I tried to use other example sentences which worket for others, but also won't work for me).
That's the code I ran in Colab:
!python -m spacy download en_core_web_sm
import spacy
import textacy
nlp = English()
nlp = spacy.load('en_core_web_sm')
nlp.add_pipe('sentencizer')
tuples_list = []
def extract_SVO(text):
doc = nlp(text)
tuples = textacy.extract.subject_verb_object_triples(doc)
tuples_to_list = list(tuples)
if tuples_to_list != []:
print("got at least one!")
tuples_list.append(tuples_to_list)
else:
print("none!")
text = "A person is standing in a kitchen making a sandwich."
extract_SVO(text)
print(tuples_list)
What am I doing wrong? I'm thankful for any help.
If you know any other libraries that you prefer and also solve this task, please let me know!