Sentiment analysis

From Computer Science Wiki
This a problem set for you to work through [1]

This is a problem set. Some of these are easy, others are far more difficult. The purpose of these problems sets are:

  1. to build your skill applying computational thinking to a problem
  2. to assess your knowledge and skills of different programming practices

What is this problem set trying to do[edit]

You are going to look at a real-world problem, and design and construct a solution.

The Problem[edit]

Sentiment analysis (also known as opinion mining or emotion AI) is the use of natural language processing, text analysis, computational linguistics, and biometrics to systematically identify, extract, quantify, and study affective states and subjective information.[2]

Sentiment analysis, also referred to as opinion mining, is an approach that identifies the emotional tone behind a body of text.[3]

Sentiment analysis is using a computer program to attempt to determine what a body of text means. See the section on tests to help you understand.

Design and construct a program that takes as input a body of text and outputs the sentiment of that body of text. The output must be one of the following: positive negative neutral

Example Tests[edit]

  • User Input: Coronet has the best lines of all day cruisers
  • Expected output: probably positive

  • User Input: Bertram has a deep V hull and runs easily through seas.
  • Expected output:probably positive

  • User Input: Pastel-colored 1980s day cruisers from Florida are ugly.
  • Expected output: probably negative

  • User Input: Dinner last night was good, but not great
  • Expected output: probably neutral

  • User Input: I'm going to take the dog for a walk
  • Expected output: probably neutral

Hacker edition[edit]

In the hacker version, design and construct sentiment analysis so that the algorithm can determine additional sentiments:

enjoyment anger disgust sadness fear surprise

How you will be assessed[edit]

Your solution will be graded using the following axis:


  • To what extent does your code implement the features required by our specification?
  • To what extent is there evidence of effort?


  • To what extent did your code meet specifications?
  • To what extent did your code meet unit tests?
  • To what extent is your code free of bugs?


  • To what extent is your code written well (i.e. clearly, efficiently, elegantly, and/or logically)?
  • To what extent is your code eliminating repetition?
  • To what extent is your code using functions appropriately?


  • To what extent is your code readable?
  • To what extent is your code commented?
  • To what extent are your variables well named?
  • To what extent do you adhere to style guide?


A possible solution[edit]

Click the expand link to see one possible solution, but NOT before you have tried and failed!

not yet!