Extract entities from Simple passive voice sentence by Python Spacy

1.9k views Asked by At

Using Python Spacy, how to extract entity from simple passive voice sentence? In the follow sentence, my intention is to extract both "John” from the sentence as nsubjpass and .ent_.

sentence = "John was accused of crimes by David"

2

There are 2 answers

0
Sohel Khan On BEST ANSWER

I am answering to my question because I will ask question on complex sentences later on so that someone can review the answer to the simple sentence and then help me to answer on the complex sentences.

code

each_sentence =  "John was accused of crimes by David"
doc=nlp(each_sentence)

passive_toks=[tok for tok in doc if (tok.dep_ == "nsubjpass") ]
if passive_toks != []:
    print(passive_toks)

Result:

[John]

0
AudioBubble On

Go through the spacy 2.0 nightly build. It should have the solution you're looking for.