NLP processing: splitting a review and keeping the rating associated with the review before split

Viewed 51

I need help with this question. I have a data frame that has a list of reviews. The reviews are essays and i want to split the essays into sentences and assign them a sentiment score. My goal is to create a weighted average of scores against the overall rating for the review. I want to identify the reason why someone would give a low score against a high score and give a thorough analysis on what the underlying reason for the review.

Eg. I love Disneyland. This one i went to was a horrible experience. There weren't enough rides and the bottled water was stupidly expensive.

In the above context (lets assume rank was 2 out of 5), i have split the essay into 3 sentences and assigned them a sentiment score: [1, -0.45, -0.2]

I need to assign them the rank of 2 as well because they are all in the same essay. Here is the code I'm using so far:

nlp = spacy.load("en_core_web_sm") # load spacey
sentences = [] # list my sentences in a review

for i in range(len(low_reviews['Review_Text'])):
  doc = nlp(low_reviews['Review_Text'].iloc[i]
  for sent in doc.sents:
    sentences.append(sent.text)

With the sentences, I apply the sentiment score using textblob:

# sentence sentiment analysis
sentiment = []
for i in sentences:
  blob = TextBlob(i)
  sentiment.append(blob.sentiment.polarity)

Then I create a Date Frame with the sentences and sentiment. What I need is the Rank as well that was assigned for the review before i split it into its sentences. I'm not sure how I can do this.

I would greatly appreciate if anyone can point me in the right direction.

0 Answers
Related