0

I use the following function to identify that token is connected to the number:

def get_number_relationships(sentence):
    doc = nlp(sentence)
    print(doc)
    for token in doc:
        #print(f"--- TOKEN {token} ---")      
        for t in token.subtree:
            if t.like_num:
                pass
                #print(f"Numeric subtree token {t}")
        for c in token.children:
            if c.like_num and c.dep_ == "nummod":
                print(f"RELATED as NUMBERS: {c.text.upper()} and {token.text.upper()} with dependency {c.dep_}")

But it doesn't capture the relationship between "40" and "birds" here:

'40 of those birds were blue.'

This is the dependency graph:

enter image description here

I tried looking at ancestors but that has the same issue. How can I capture this dependency?

Rada Lu
  • 33
  • 4

0 Answers0