Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello I am really struggling with coding of this problem. I will really appreciate if you can help me. question is written below: The file

Hello I am really struggling with coding of this problem. I will really appreciate if you can help me. question is written below:

The file contains names of reviewers and their reviews of different restaurants in

the comma separated format. The first string is the name of the reviewer followed

by a name of a restaurant and its rating. Python program

that computes a similarity score between any two reviewers using Euclidean

distances. An example data from the restaurant_reviews.txt file is given below:

Pete Wellsworth's reviews are:

'Rooster and Owl': 3.0,

'El Sapo Cuban Social Club': 4.0,

'Punjab Grill': 3.0,

'Shibumi': 5.0,

'Mama Chang': 3.5

Jay Samuel's reviews are:

'El Sapo Cuban Social Club':4.5,

'Mama Chang':1.0,

'Shibumi':4.0

The Euclidean distance between Jay Samuel and Pete Wellsworth is computed as

follows:

1) Only consider the restaurants that both have reviewed.

2) Take the difference between corresponding reviews.

3) Sum the square of the differences

4) The square root of the sum of differences is the Euclidean score. The shorter the

distance the closer the two reviewers.

For our example, this would be: (4.0 - 4.5)2 + (3.5 - 1.0)2 + (5.0 - 4.0)2 = 0.25 +

6.25 + 1 = 7.5

Euclidean distance is Square Root of 7.5 = 2.7386

Your program should provide the following:

1) Ability to read in a user provided filename which contains restaurant reviews in

the comma separated format similar to the given file restaurant_reviews.txt

2) Functionality to compute the similarity between two reviewers provided by the

user

3) Functionality to compute the similarity between one user provided reviewer and

all other reviewers in the database

A sample run for the two required functionalities is given below (user inputs are in

red):

Give the name of the restaurant reviews file: restaurant_reviews.txt

What do you want to do? Input 1 for similarity between two reviewers, or

Input 2 for similarity between one reviewer and all others in the database or 3

to quit: 1

Provide Reviewer1 name: Jay Samuel

Provide Reviewer2 name: Pete Wellsworth

The similarity score between Jay Samuel and Pete Wellsworth is: 2.7386

What do you want to do? Input 1 for similarity between two reviewers, or

Input 2 for similarity between one reviewer and all others in the database or 3

to quit: 2

Provide Reviewer name: Jay Samuel

The Similarity Scores are:

Jay Samuel Tomm Sietsema 1.87 Jay

Samuel Corby Kumar 1.50

Jay Samuel Jonathan Golder 2.87

Jay Samuel Pete Wellsworth 2.74

Jay Samuel Brette Anderson 1.58

Jay Samuel Michael Baumer 1.80

What do you want to do? Input 1 for similarity between two reviewers, or

Input 2 for similarity between one reviewer and all others in the database or 3

to quit: 3

Goodbye!

Hint:

a) A good way to convert the file contents to a Python data structure is to create

dictionary. For example the first two lines of the restaurant_reviews.txt file

can be stored as a dictionary entry such as the following:

{'Tomm Sietsema': {'Rooster and Owl': 2.5, 'El Sapo Cuban Social Club': 3.5,

'The Godfather': 3.0, 'Shibumi': 3.5, 'Mama Chang': 2.5,

'Punjab Grill': 3.0},'Jonathan Golder': {'Rooster and Owl': 3.0, 'El Sapo Cuban

Social Club': 3.5, 'The Godfather': 1.5, 'Shibumi': 5.0, 'Punjab Grill': 3.0,

'Mama Chang': 3.5}}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions