#C12372. Sentiment Analysis Using the AFINN Lexicon

    ID: 41792 Type: Default 1000ms 256MiB

Sentiment Analysis Using the AFINN Lexicon

Sentiment Analysis Using the AFINN Lexicon

You are given a number of sentences. For each sentence, compute its sentiment score by summing the scores of each word using the AFINN lexicon. The sentiment of each word is determined in a case-insensitive manner. If a word is not found in the lexicon, it contributes a score of 0.

The internal lexicon to be used is defined as follows:

[ \text{lexicon} = { \text{'love'}: 3,; \text{'wonderful'}: 4,; \text{'terrible'}: -3,; \text{'awful'}: -3 } ]

For example:

  • The sentence "I love this wonderful place" will have a sentiment score of 3 + 4 = 7.
  • The sentence "This is a terrible and awful experience" will have a score of -3 + (-3) = -6.
  • The sentence "I am going to the store now" will have a score of 0.
  • For the sentence "I love this place but the service is terrible", the score is 3 + (-3) = 0.

You should read the input from the standard input and print the result to the standard output.

inputFormat

The first line of the input contains an integer n indicating the number of sentences. The following n lines each contain one sentence.

For example:

2
I love this wonderful place
This is a terrible and awful experience

outputFormat

For each input sentence, output a single line containing the sentiment score computed using the provided lexicon.

For the above sample, the output should be:

7
-6
## sample
1
I love this wonderful place
7

</p>