3. Sentiment Analysis

  • Worth: 5%

  • DUE: March 19th, 2024 at 11:55pm; submitted on MOODLE.

Warning

For this assignment, you may not work with anyone else.

You need to work independently.

3.1. How to submit your work

You need to submit your Java files directly on moodle. The first two lines of the Java files should be as follows:

// Student name:
// Student number:

3.2. Instructions

  • In this assignment you will calculate the overall sentiment of a text.

  • There are multiple techniques, but we will focus on a very simple one.

  • The analysis will be done by words.

    • The scale is going from -5 (very negative) to 5 (very positive).

  • You will create a first hash table based on the file sentiments.txt

    • This file is adapted from AFINN.

    • This hash table will map each word the corresponding value.

  • After that you need to take the input from a user.

    • Concretly a text.

    • I am giving you a csv file containing book reviews from Amazon that you can you use. Reviews.csv

    • You need to calculate the total sentiment of the text and the average.

    • Then you print the total sentiment of the text and the average.

    • The average sentiment gives us an idea if the text is positive, negative or neutral.

3.2.1. Structure of your program

The program should contain the following files:

  • main

  • Analysis : It’s the main class of the program.

  • Sentiment : The sentiment database that will contain only the words and their sentiment value.

3.2.1.1. main

  • This file should take two arguments from the console:

SentimentAnalysis <sentiment_database>

SentimentAnalysis is the name of the executable.

  • Then it should create the class Analsyis.

  • Then it asks the user to enter a text.

  • The program ends when the user type “quit”.

3.2.1.2. Analysis

  • The principal class of your program.

  • The constructor should take the sentiment file as an argument of the constructor.

  • With the file it should create the class Sentiment.

  • It should have a method taking the text entered by the user and sent by main.

  • It will calculate the total sentiment of the text. To do that it sum the sentiment of each word in the text.

  • It will also calculate the average sentiment (total sentiment / number of words).

  • Finally, it will print these values.

3.2.1.3. Sentiment

  • This class must be a Hash Table.

  • The hash must be done on the word.

  • It must contain a find methods that will return the value of the word. And 0 if the word doesn’t exist.

  • You can use the hash function that you want.

  • The way you handle collision also is up to you, but it needs to be explained in the comments.

3.3. Some marking details

Warning

Having the correct outputs doesn’t mean that you will obtain a perfect mark.

The marking will depend on:

  • Correctness.

  • Comments

  • Variable names

  • Style

  • etc.