Skip to content
Discussion options

You must be logged in to vote

Well after many attempts, I found the solution as follows;

for a in doc:
    if a.dep_ == "prep" and a.pos_ == "ADP" and a.head.pos_ == "VERB":
        for b in a.head.children:
            if b.dep_ == "nsubj":
                sents = [t.sent for t in a.sent]
                for n in sents:
                    for c in n:
                        if c.dep_ == 'dobj':
                            pattern2_sents = [c.sent]
                        if c.dep_ != 'pobj':
                            pattern4_sents = [c.sent]

It may be of the use for someone else. However I am not sure why simple iterating if token.dep_ != 'dobj' would not work in the original question.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fatihbozdag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usage General spaCy usage feat / doc Feature: Doc, Span and Token objects
1 participant