Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CMSC 256 Accessing BRIDGES Datasets and Sorting with a Comparator Lab This project will use the BRIDGES API with an actor/movie dataset from IMDB. The

CMSC 256 Accessing BRIDGES Datasets and Sorting with a Comparator Lab

This project will use the BRIDGES API with an actor/movie dataset from IMDB. The actor/movie dataset, curated from IMDB, is a text file containing a set of actor/movie pairs, one pair per line. Note that both actors and movies can and will appear multiple times, in the data file. The purpose of this assignment is to:

Access a dataset using the BRIDGES API.

Display the contents of the dataset in various sorted orders.

You will need to obtain BRIDGES credentials to complete this lab. Create an account on the BRIDGES server by following these steps:

Go to http://bridgesuncc.github.io/ Links to an external site.and on the top menu bar, select Downloads and then click on the Java client to download the BRIDGES source code as a .jar file that contains all the needed classes to run a BRIDGES program.

Click on "Login" (at the upper right corner).

Click on "Sign Up!" (at the bottom of the "Login" box).

Fill out the form with a username that does not contain any spaces.

Go to the "Profile" page (link at the top right).

Note the "API Sha1 Key"; you will need it in the next part.

Follow the instructions in the Getting Started guide for your IDE that are found on this page - https://bridgesuncc.github.io/bridges_setup.htmlLinks to an external site.

Task Access movie data from BRIDGES dataset and display it in sorted order.

Create a new Eclipse or IntelliJ project and name it SortingLab. In Eclipse, click Next and then the Libraries tab, then use the Add External JARs button on the right to include the BRIDGES files to the project. In IntelliJ,

Create a package called cmsc256 then right-click on the package to create a new Java class called SortingLab and import the following files:

import bridges.connect.Bridges;

import bridges.connect.DataSource;

import bridges.data_src_dependent.ActorMovieIMDB;

import java.util.List;

Use the BRIDGES API to get movie data using the DataSource class and following the steps shown below. Documentation can be found here Links to an external site..

// In the main method, create the Bridges object replacing

// the 2nd & 3rd parameters with

// your individual Bridges user id and API key

Bridges bridges = new Bridges(3, "YOUR_USER_ID", "YOUR_API_KEY");

DataSource ds = bridges.getDataSource();

List movieData = null;

try {

movieData = ds.getActorMovieIMDBData(Integer.MAX_VALUE);

}

catch (Exception e) {

System.out.println("Unable to connect to Bridges.");

}

The List will be populated with ActorMovieIMDB objects. The documentation for this class can be found at http://bridgesuncc.github.io/doc/java-api/current/html/classbridges_1_1data__src__dependent_1_1_actor_movie_i_m_d_b.html Links to an external site..

Review the methods in the API to see how to access information about each ActorMovieIMDB object.

Write a loop that displays the actor and movie title for the first 5 objects in the list:

for(int i = 0; i < 5; i++) {

ActorMovieIMDB entry = movieData.get(i);

System.out.println("" + i + ". " + entry.getActor() + " was in " + entry.getMovie());

}

You should see the following:

Kevin_Bacon_(I) was in He_Said,_She_Said_(1991)

Kevin_Bacon_(I) was in Only_When_I_Laugh_(1981)

Kevin_Bacon_(I) was in Picture_Perfect_(1997)

Kevin_Bacon_(I) was in Stir_of_Echoes_(1999)

Christian_Bale was in All_the_Little_Animals_(1998)

Filtering the Data

Using an enhanced for loop, write the code to display all names of the actors (only the actor name) who appeared in the movie, Being John Malkovich. (Note: there are not spaces in the data set for the movie title, so youll need to use Being_John_Malkovich_(1999) as the search string.

There are 75 actors in the list who were in the movie.

Sorting the Data by Actor

Create another Java class called ActorComparator that implements the Comparator interface.

Add the import statement: import bridges.data_src_dependent.ActorMovieIMDB;

Replace the type parameter with ActorMovieIMDB

Implement the compare method so that movies are sorted by the first name of the actor. (Note that the actor name is given in the form first_last, so a lexicographic sort of the actor provides the correct sorting by first name.)

Add code to the main method of your Lab class that will sort, then display the list actors who appeared in the movie, Being John Malkovich. To sort the List of movies, you can create a separate ArrayList that contains only the actors that appeared in Being John Malkovich. The type of the ArrayList will be the Bridges class ActorMovieIMDB

ArrayList filteredMovieList = new ArrayList<>();

Sort this filtered list using ArrayList methods - look through the documentation here: https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html Links to an external site.to find an appropriate method.

Display the sorted list.

Here is what the beginning of the list should display when sorted:

The following actors appeared in the movie, Being John Malkovich:

Andy_Dick

Audrey_Gelfund

Bill_M._Ryusaki

Bill_Wittman

Brad_Pitt

Byrne_Piven

Cameron_Diaz

// plus others

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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 Databases questions