I am working on a novel and I need to find all the adjectives associated to three different characters in order to compare their descriptions. Any idea on how I can do that? I am Python beginner :-)
I thought about creating three different dictionaries with the adjectives and their frequencies, but any suggestion will be appreciated.
Somebody suggested this:
# Tokenize the text into words
words = word_tokenize(verga_eros)
# Use NLTK's part-of-speech (POS) tagger to tag each word with its part of speech
tagged_words = pos_tag(words)
# Create a dictionary to store the adjectives associated with each character
adjectives = {
"Marie": [],
"Lucy": [],
"Ella": []
}
# Loop through each tagged word and extract the adjectives associated with each character
for i in range(len(tagged_words)):
word, pos = tagged_words[i]
if pos == "JJ": # If the word is an adjective
if i > 0 and tagged_words[i-1][0] == "Marie": # If the previous word is "Marie"
adjectives["Marie"].append(word)
elif i > 0 and tagged_words[i-1][0] == "Lucy": # If the previous word is "Lucy"
adjectives["Lucy"].append(word)
elif i > 0 and tagged_words[i-1][0] == "Ella": # If the previous word is "Ella"
adjectives["Ella"].append(word)
# Print the adjectives associated with each character
print("Adjectives for Marie:", adjectives["Marie"])
print("Adjectives for Lucy:", adjectives["Lucy"])
print("Adjectives for Ella:", adjectives["Ella"])
But I need to use stanza instead of nltk!