Find the adjective corresponding to the subject -Python NLP

Viewed 200

There is a efficient way to find the adjective corresponding to a subject?

def find_ADJ(NOUN, sentence):
    return (NOUN, ADJ)

sentence = "I have a blue car that was a gift from my wife who is beautiful"

INPUT: find_ADJ(car,sentence)
OUTPUT: (car, blue)
    
INPUT: find_ADJ(wife,sentence)
OUTPUT: (wife, beautiful)

*Or return more than one adjetive

I have tried to do things with Spacy (pos_ and dep_) but without results. Do someone know a library or a way to do what I am looking for? Thanks you

2 Answers

you can try corefrence resolution libraries such as stanford corenlp or huggingface .i know that huggingface show related words.

demo:https://huggingface.co/coref/

I tried what you want to do using spaCy library which tells you which element of the string is an adjective. However, it tells you all the adjectives and not to the related to the desired noun. What I did (I think a little inefficient) is look for all adjectives in a radius of 3 elements of the desired noun. It will most likely will bring you the adjective associated to the noun according to English grammar. That is my approach, if you have something else to improve my answer I'm open to discussion.

Related