I'm working on an aspect-based sentiment analysis model using spaCy. I managed to extract aspects and adjectives as pairs in a list. I also included "not" before any adjective to handle any negations. I want to swap the adjective with its antonym if there is "not" before the adjective. I know spaCy has some similarity detection tools but I couldn't find anything about antonyms. Is it possible to do this with spaCy? If not how can I do it or is there a better way to handle the negations?
import spacy
from spacy.matcher import Matcher
nlp = spacy.load('en_core_web_sm')
txt = "The performance of the product is not great but The price is fair."
txt = txt.lower()
output = []
doc = nlp(txt)
matcher = Matcher(nlp.vocab, validate=True)
matcher.add("mood",None,[{"LOWER":{"IN":["is","are"]}},{"LOWER":{"IN":["no","not"]},"OP":"?"},{"DEP":"advmod","OP":"?"},{"DEP":"acomp"}])
for nc in doc.noun_chunks:
d = doc[nc.root.right_edge.i+1:nc.root.right_edge.i+1+3]
matches = matcher(d)
if matches:
_, start, end = matches[0]
output.append((nc.text, d[start+1:end].text))
print(output)
Expected output:
[('the performance', 'not great'), ('the product', 'not great'), ('the price', 'fair')]