Model Storerating Ratings Movielist Mov - Path Genre - Path
Model Storerating Ratings Movielist Mov - Path Genre - Path
Recommender:
package org.movie;
import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator;
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
import
org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;
import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
import java.io.*;
import java.util.*;
}
} catch (IOException e) {
System.out.println("There was an error.");
e.printStackTrace();
} catch (TasteException e) {
System.out.println("There was a Taste Exception.");
e.printStackTrace();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return ratedM;
}
int id = Integer.parseInt(genres.get(genres.size()-1));
genres.remove(genres.get(genres.size()-1)); // removed last as
it was id
for(String p: pref)
{
if (genres.contains(p))
{
movieIDS.add(id);
}}}
}catch (IOException e)
{
e.printStackTrace();
}
return movieIDS;
}
public static ArrayList<Movie> getter(ArrayList<Integer> ids)
{
int x = 0;
ArrayList<Movie> finalMovies = new ArrayList<>();
for (Integer id: ids) {
if(x>50)
{ break;}
Movie m = Movie.getMovie(id);
finalMovies.add(m);
x++;
}
return finalMovies;
}
public static ArrayList<Movie> MoodBuild(String genre)
{
ArrayList<Movie> mra = new ArrayList<>();
String moodAssigned = Mood.assignMood(genre);
int x = 0;
FXMain.moodHead.setText(moodAssigned);
ArrayList<Integer> foundId = Search.genresearch(genre);
for(int i: foundId)
{
if(x>19)
{break;}
Movie m = Movie.getMovie(i);
mra.add(m);
x++;
}
return mra;}}
Movie:
package org.movie;
import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator;
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
import
org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;
import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
import java.io.*;
import java.util.*;
}
} catch (IOException e) {
System.out.println("There was an error.");
e.printStackTrace();
} catch (TasteException e) {
System.out.println("There was a Taste Exception.");
e.printStackTrace();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return ratedM;
}
Collections.shuffle(finalMovies);
FXMain.genreHead.setText("Movies for " + User.currentUser.getName());
return finalMovies;
}
int id = Integer.parseInt(genres.get(genres.size()-1));
genres.remove(genres.get(genres.size()-1)); // removed last as
it was id
for(String p: pref)
{
if (genres.contains(p))
{
movieIDS.add(id);
}}}
}catch (IOException e)
{
e.printStackTrace();
}
return movieIDS;
}
public static ArrayList<Movie> getter(ArrayList<Integer> ids)
{
int x = 0;
ArrayList<Movie> finalMovies = new ArrayList<>();
for (Integer id: ids) {
if(x>50)
{ break;}
Movie m = Movie.getMovie(id);
finalMovies.add(m);
x++;
}
return finalMovies;
}
public static ArrayList<Movie> MoodBuild(String genre)
{
ArrayList<Movie> mra = new ArrayList<>();
String moodAssigned = Mood.assignMood(genre);
int x = 0;
FXMain.moodHead.setText(moodAssigned);
ArrayList<Integer> foundId = Search.genresearch(genre);
for(int i: foundId)
{
if(x>19)
{break;}
Movie m = Movie.getMovie(i);
mra.add(m);
x++;
}
return mra;}}
User:
package org.movie;
import java.io.*;
import java.util.ArrayList;
class User implements Comparable<User> {
static ArrayList<String> usernames = new ArrayList<>();
static User currentUser;
static String user_path = "data/userdata.csv";
private final String username;
private final String password;
static String gender;
try {
BufferedReader r = new BufferedReader(new
FileReader((user_path)));
do{
String line;
while ((line = r.readLine()) != null)
{
String [] data = line.split(",");
usernames.add(data[0]);
}
if(usernames.contains(username))
{isUser = true;
return true;}
else {isUser = false;}
}while(isUser);
age = Integer.parseInt(FXMain.age.getText());
if(!isUser)
{ usernames.add(username);
currentUser = new User(username,password,gender,age);}
}catch (IOException e)
{
e.printStackTrace();}
return false;
}
static boolean login(){
String username, password, line;
boolean isUser = true, logged =false;
try{
while (true){
BufferedReader f = new BufferedReader(new FileReader(user_path));
username = FXMain.username.getText();
password = FXMain.password.getText();
@Override
public String toString() {
return username + ',' + password + ',' + gender + ',' + age + ',' +
preferences;
}
}
enum UserRating {
ONE("1 star"),
TWO("2 stars"),
THREE("3 stars"),
FOUR("4 stars"),
FIVE("5 stars"),
SIX("6 stars"),
SEVEN("7 stars"),
EIGHT("8 stars"),
NINE("9 stars"),
TEN("10 stars");
UserRating(String description) {
this.description = description;
}
Genre:
package org.movie;
public interface Genre {
static String assignGenre(String genre) {
String [] data = genre.split(" ");
String x = "";
for (String a:data ) {
switch (a) {
case "10749" -> a = "Romantic";
case "28" -> a = "Action";
case "35" -> a = "Comedy";
case "27" -> a = "Horror";
case "12" -> a = "Adventure";
case "14" -> a = "Fantasy";
case "16" -> a = "Animation";
case "36" -> a = "History";
case "37" -> a = "Western";
case "80" -> a = "Crime";
case "878" -> a = "Science Fiction";
case "9648" -> a = "Mystery";
case "10402" -> a = "Music";
case "10751" -> a = "Family";
case "10752" -> a = "War";
case "10769" -> a = "Foreign";
case "10770" -> a = "TV Movie";
default -> a = "";
}
x += " "+ a;
}
return x;
}
static String assignID(String genre) {
String [] data = genre.split("\\.");
String x = "";
for (String a:data ) {
switch (a) {
case "Romantic"-> a = "10749";
case "Action"-> a = "28";
case "Comedy"-> a = "35" ;
case "Horror"-> a = "27" ;
case "Adventure"-> a = "12" ;
case "Fantasy"-> a = "14" ;
case "Animation"-> a = "16" ;
case "History"-> a = "36" ;
case "Western"-> a = "37" ;
case "Crime"-> a = "80" ;
case "Science Fiction" -> a = "878" ;
case "Mystery"-> a = "9648" ;
case "Music"-> a = "10402" ;
case "Family"-> a = "10751" ;
case "War"-> a = "10752" ;
case "Foreign"-> a = "10769" ;
case "TV Movie"-> a = "10770" ;
default -> a = "";
}
x += a+ ".";
}
return x;
}
}
Mood:
package org.movie;
public class Mood {
public static String assignMood(String genre) {
return switch (genre.toLowerCase()) {
case "10749", "35", "10402", "10751", "16" -> "Happy, Lively";
case "28", "12", "14", "80", "9648" -> "Exciting, Thrilling";
case "36", "99", "878" -> "Curious, Informative";
case "10752", "18" -> "Sad";
default -> "";
};
}
}
Search:
package org.movie;
import java.io.*;
import java.util.ArrayList;
class Search {
static String genre_path = "data/genres_raw.csv";
if (movie.getTitle().contains((key).getTitle())) {
foundMovies.add(movie);
}
}
} catch (IOException | ArrayIndexOutOfBoundsException e) {
System.out.println("End of results.");
return foundMovies;
}
return null;
}
FXMain:
package org.movie;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Override
public void start(Stage primestage) throws Exception {
Recommender.RatingBuild();
stage = primestage;
currentPane = welcomeScreen();
Scene s = new Scene(currentPane);
stage.setScene(s);
back.setText("Back");
back.setAlignment(Pos.TOP_LEFT);
back.getStyleClass().add("back");
back.setOnAction(e-> {
currentPane = home();
stage.getScene().setRoot(currentPane);
});
stage.setTitle("MRS-45K");
stage.getIcons().add(new Image("img.png"));
stage.show();
}
Pane welcomeScreen()
{
//WELCOME SCREEN
//Login Button
login = new Button("Login");
login.getStyleClass().add("logsign-button");
login.setOnAction(e-> {
currentPane = login();
stage.getScene().setRoot(currentPane);
});
//Signup Button
signup= new Button("Sign up");
signup.getStyleClass().add("logsign-button");
signup.setOnAction(e-> {
currentPane = reg();
stage.getScene().setRoot(currentPane);
});
//Greeting
Label greet = new Label("It's nice to have you here.");
greet.getStyleClass().add("greet");
//Title
Label title = new Label("MRS-45K");
title.getStyleClass().add("title");
//Headers
VBox top = new VBox(title,welcome,greet);
top.setAlignment(Pos.TOP_CENTER);
top.getStylesheets().add("style.css");
//border check
//top.setBorder(new Border(new
BorderStroke(Color.BLACK,BorderStrokeStyle.DOTTED,CornerRadii.EMPTY,new
BorderWidths(2))));
return welcSc; }
Pane login()
{
username = new TextField();
username.getStyleClass().add("login-fields");
gp.getStyleClass().add("gpfields");
loginstat.getStyleClass().add("login-stat");
submit.getStyleClass().add("submit-button");
submit.setOnAction(e->{
boolean b = User.login();
if(b){
currentPane = home();
stage.getScene().setRoot(currentPane);}
if (!b)
{
loginstat.setText("Invalid credentials.");
}
});
m.getStyleClass().add("gender-button");
f.getStyleClass().add("gender-button");
m.setOnAction(e->{
if(m.isSelected())
{
f.setSelected(false);
}
});
f.setOnAction(e->{
if(f.isSelected())
{
m.setSelected(false);
}
});
gp.getStyleClass().add("gpfields");
register.getStyleClass().add("submit-button");
register.setOnAction(e->{
boolean b = User.reg();
userexists.getStyleClass().add("login-stat");
if(b) {
userexists.getStyleClass().add("userexist-stat");
Pane home(){
//Search Bar
HBox search = new HBox(key,searcher);
search.setTranslateX(190);
key.getStyleClass().add("search-bar");
searcher.getStyleClass().add("search");
searcher.setOnAction(e -> {
String toSearch = key.getText();
Movie m = new Movie(0,toSearch,0, 0.0F);
searchResults = Search.results(m);
currentPane = searched();
stage.getScene().setRoot(currentPane);
});
//Menu
MenuButton menu = new MenuButton("Menu");
menu.getItems().add(m1);
m1.getStyleClass().add("menu-item");
menu.getStyleClass().add("menu");
m1.setOnAction( e-> {
currentPane = browse();
stage.getScene().setRoot(currentPane);
});
//Rating Build
Label rated = new Label("Well rated movies you might like");
rated.getStyleClass().add("mood-head");
HBox hb = new HBox();
ArrayList<Movie> mra = Recommender.displayRatingRec();
tile(hb, mra);
hb.setSpacing(5);
hb.getStyleClass().add("movie-scroll");
//Mood Build
ArrayList<Movie> moodB = Recommender.MoodBuild("16");
HBox mood = new HBox();
tile(mood, moodB);
moodHead.getStyleClass().add("mood-head");
mood.setSpacing(5);
mood.getStyleClass().add("movie-scroll");
//GenreBuild
ArrayList<Movie> genreB = Recommender.GenreBuild();
HBox genre = new HBox();
for (int i = 0; i < 30; i++) {
tile = new Button();
Movie cM = genreB.get(i);
tile.setWrapText(true);
tile.setText(cM.getTitle()+"\n"+cM.getVoteAvg());
tile.getStyleClass().add("movie");// Set button size
genre.getChildren().add(tile);
}
for(Node b : genre.getChildren())
{
((Button) b).setOnAction( e -> {
currentPane = movie((Button) b);
stage.getScene().setRoot(currentPane);
});
}
genreHead.getStyleClass().add("mood-head");
genre.setSpacing(5);
genre.getStyleClass().add("movie-scroll");
VBox vb = new
VBox(rated,recMovie,genreHead,genreMovie,moodHead,moodMovie);
return full;}
Pane searched()
{
searchedKey.getStyleClass().add("mood-head");
searchedKey.setText("Search results for \""+key.getText()+"\"");
full.getStylesheets().add("style.css");
return full;
}
Pane browse() {
ComboBox<String> genreComboBox = new ComboBox<>();
genreComboBox.setPromptText("Select Genre");
genreComboBox.getStyleClass().add("combo-box");
genreComboBox.getItems().addAll(
"Action", "Adventure", "Animation", "Comedy", "Crime",
"Family", "Fantasy",
"Foreign", "History", "Horror", "Music", "Mystery",
"Romantic", "Science Fiction",
"TV Movie", "War", "Western");
browse.getStylesheets().add("style.css");
return browse;
}
Pane getPreferences(){
Label thanks = new Label("Thank you for registering with us. \n Please
select your preferences:");
thanks.getStyleClass().add("pref-head");
}
prefs.getStyleClass().add("genrebox");
saveButton.getStyleClass().add("save-button");
saveButton.setOnAction(e -> {
String preferences ="";
for (Node node : prefs.getChildren()) {
if (node instanceof CheckBox && (((CheckBox)
node).isSelected())) {
preferences += ((CheckBox) node).getText()+".";
}
}
User.currentUser.setPreferences(Genre.assignID(preferences));
if(FXMain.m.isSelected())
{
User.currentUser.setGender("Male");
}
if(FXMain.f.isSelected())
{ User.currentUser.setGender("Female");
}
savePreferenceToFile(User.currentUser, preferences); // Save
preference to file
currentPane = home();
stage.getScene().setRoot(currentPane);
});
full.getStyleClass().add("pref-screen");
full.getStylesheets().add("style.css");
return full;
}
Pane movie(Button b)
{
String title = b.getText().substring(0,b.getText().lastIndexOf("\n"));
//label working
try {
String line;
BufferedReader br = new BufferedReader(new
FileReader(Recommender.movielist));
while ((line = br.readLine()) != null)
{
String data [] = line.split(",");
if(title.contains(data[1]))
{
syn.setText(data[2].replaceAll("~",","));
released.setText("Release date: " +data[3]);
runtime.setText("Runtime in minutes: "+data[4]);
genres.setText("Genres: " +Genre.assignGenre(data[5]));
rating.setText("IMDb rating: " + data[6]);
}
}
}catch (IOException e)
{e.printStackTrace();}
catch (ArrayIndexOutOfBoundsException e)
{
}
VBox vb = new VBox(name, released,runtime,rating,genres,plot,syn);
vb.setTranslateY(20);
vb.setTranslateX(10);
vb.setSpacing(10);
vb.setPadding(new Insets(10));
BorderPane bp = new BorderPane();
bp.setTop(back);
bp.setCenter(vb);
bp.getStyleClass().add("profile");
bp.getStylesheets().add("style.css");
return bp;
}
Collections.sort(movies);
return movies.subList(0, Max);
}
try {
BufferedReader reader = new BufferedReader(new
FileReader("data/profiled.csv"));
String line;
while ((line = reader.readLine()) != null) {
String[] atad = line.split(",");
if (atad.length >= 6) {
String mTitle = atad[1];
if (mTitle.startsWith(alphabet)) {
movies.add(mTitle);
}
}
}
}catch (IOException e) {
e.printStackTrace();
}
Collections.sort(movies);
return movies.subList(0, Math.min(movies.size(), Max));
}
FlowCheck:
package org.movie;
import java.util.Scanner;
Style Sheet:
.logsign-button {
-fx-background-color: #891000;
-fx-text-fill: #ebe1df;
-fx-font-size: 35px;
-fx-padding: 10px 20px;
-fx-font-family: Bahnschrift;
-fx-pref-height: 65;
-fx-pref-width: 190;
}
.back {
-fx-background-color: #891000;
-fx-text-fill: #ebe1df;
-fx-pref-height: 40;
-fx-font-size: 20;
-fx-padding: 10px 20px;
-fx-font-family: Bahnschrift;
}
.title {
-fx-text-fill: #fffefd;
-fx-font-family: Bahnschrift;
-fx-font-size: 58;
-fx-padding: 15;
}
.welc {
-fx-text-fill: #fffefd;
-fx-padding: 10;
-fx-font-family: Bahnschrift;
-fx-font-size: 38;
-fx-translate-y: 30;
}
.greet {
-fx-text-fill: #fffefd;
-fx-font-family: Bahnschrift;
-fx-font-size: 35;
-fx-translate-y: 40;
}
.logsign {
-fx-spacing: 150;
-fx-alignment: center;
-fx-translate-y: 240;
-fx-padding: 20;
}
.welcome-screen {
-fx-alignment: top-center;
-fx-pref-width: 900;
-fx-pref-height: 680;
-fx-background-color: #af2311;
}
.home-screen {
-fx-alignment: bottom-left;
-fx-pref-width: 900;
-fx-pref-height: 680;
-fx-background-color: #af2311;
}
.result-screen {
-fx-alignment: center-left;
-fx-pref-width: 900;
-fx-pref-height: 680;
-fx-background-color: #af2311;
}
.profile {
-fx-pref-width: 900;
-fx-pref-height: 680;
-fx-background-color: #af2311;
}
.pref-screen {
-fx-alignment: center;
-fx-pref-width: 900;
-fx-pref-height: 680;
-fx-background-color: #af2311;
}
.login-head {
-fx-text-fill: #fffefd;
-fx-font-family: Bahnschrift;
-fx-font-size: 47;
-fx-translate-y: 40;
}
.pref-head {
-fx-text-fill: #fffefd;
-fx-font-family: Bahnschrift;
-fx-font-size: 37;
-fx-translate-x: 30;
-fx-translate-y: 30;
-fx-alignment: top-left;
}
.search {
-fx-border-color: #630b00;
-fx-background-color: #891000;
-fx-text-fill: #ebe1df;
-fx-font-size: 15px;
-fx-font-family: Bahnschrift;
-fx-pref-height: 45;
-fx-pref-width: 80;
}
.search-bar {
-fx-border-color: #630b00;
-fx-background-color: #891000;
-fx-text-fill: #ebe1df;
-fx-font-size: 15px;
-fx-font-family: Bahnschrift;
-fx-pref-height: 45;
-fx-pref-width: 180;
}
.login-txt {
-fx-text-fill: #fffefd;
-fx-font-family: Bahnschrift;
-fx-font-size: 32;
-fx-translate-y: 80;
}
.login-fields {
-fx-background-color: #630b00;
-fx-text-fill:#fffefd;
-fx-font-size: 17;
-fx-font-family: Bahnschrift;
-fx-pref-height: 50;
-fx-pref-width: 350;
}
.login-labels {
-fx-text-fill: #fffefd;
-fx-font-size: 28;
}
.login-stat {
-fx-text-fill: #fffefd;
-fx-font-size: 28;
-fx-alignment: center;
-fx-translate-y: 40;
}
.userexist-stat {
-fx-text-fill: #fffefd;
-fx-font-size: 24;
-fx-alignment: bottom-center;
-fx-translate-y: 90;
}
.gpfields {
-fx-hgap: 40;
-fx-vgap: 20;
-fx-translate-y: 90;
-fx-alignment: center;
-fx-pref-width: 300;
-fx-pref-height: 300;
}
.genrebox {
-fx-hgap: 2;
-fx-vgap: 10;
-fx-translate-x: -30;
-fx-alignment: center;
-fx-pref-width: 300;
-fx-pref-height: 300;
}
.submit-button {
-fx-background-color: #630b00;
-fx-text-fill: #ebe1df;
-fx-font-size: 33px;
-fx-translate-y: 110;
-fx-font-family: Bahnschrift;
-fx-pref-height: 65;
-fx-pref-width: 220;
-fx-alignment: center;
}
.save-button {
-fx-background-color: #630b00;
-fx-text-fill: #ebe1df;
-fx-font-size: 33px;
-fx-translate-y: 60;
-fx-font-family: Bahnschrift;
-fx-pref-height: 65;
-fx-pref-width: 180;
-fx-alignment: center;
}
.gender-button {
-fx-text-fill: #fffefd;
-fx-font-size: 20;
-fx-font-family: Bahnschrift;
-fx-translate-x: 30;
-fx-pref-height: 60;
-fx-pref-width: 100;
}
.gender-box {
-fx-spacing:100;
-fx-alignment: center-left;
}
.age-box {
-fx-background-color: #630b00;
-fx-text-fill:#fffefd;
-fx-font-size: 17;
-fx-font-family: Bahnschrift;
-fx-pref-height: 50;
-fx-pref-width: 350;
}
.movie {
-fx-background-color: #891000;
-fx-text-fill: #ebe1df;
-fx-text-alignment: center;
-fx-font-size: 15px;
-fx-padding: 10px;
-fx-font-family: Bahnschrift;
-fx-pref-height: 110;
-fx-pref-width: 100;
}
.searched-movies {
-fx-background-color: #891000;
-fx-text-fill: #ebe1df;
-fx-text-alignment: center;
-fx-font-size: 15px;
-fx-padding: 10px;
-fx-font-family: Bahnschrift;
-fx-pref-height: 80;
-fx-pref-width: 300;
}
.genre {
-fx-background-color: #891000;
-fx-text-fill: #ebe1df;
-fx-text-alignment: center;
-fx-padding: 10px;
-fx-font-family: Bahnschrift;
}
.mood-head {
-fx-padding: 10;
-fx-text-fill: #fffefd;
-fx-font-size: 28;
-fx-alignment: center-left;
}
.movie-scroll {
-fx-alignment: bottom-left;
-fx-background-color: #5b0b00;
-fx-padding: 3;
}
.result-scroll {
-fx-alignment: bottom-left;
-fx-background-color: #5b0b00;
-fx-padding: 3;
-fx-pref-width: 300;
}
.menu .label {
-fx-text-fill:#fffefd;
-fx-background-color: #630b00;
-fx-font-size: 15;
-fx-font-family: Bahnschrift;}
.menu {
-fx-background-color: #630b00;
}
.menu-item .label{
-fx-text-fill:#fffefd;
-fx-background-color: #630b00;
-fx-alignment: center;
-fx-font-size: 13;
-fx-font-family: Bahnschrift;
}
.menu-item {
-fx-background-color: #630b00;
-fx-pref-width: 90;
-fx-alignment: center;
}
.movie-result {
-fx-background-color: #891000;
-fx-text-fill: #ebe1df;
-fx-text-alignment: center;
-fx-font-size: 15px;
-fx-padding: 10px;
-fx-font-family: Bahnschrift;
-fx-pref-height: 110;
-fx-pref-width: 400;
}.browse {
-fx-pref-height: 700;
-fx-pref-width: 1000;
-fx-background-color: #AF2311;
}
.combo-box {
-fx-background-color: #891000;
-fx-text-fill: #FFFEFD;
-fx-prompt-text-fill: #FFFEFD;
}
.defaultzaid {
-fx-background-color: #FF0700;
-fx-text-fill: #FFFEFD;
-fx-font-size: 19;
}
.list-cell {
-fx-pref-width: 1000;
-fx-background-color: #891000;
-fx-text-fill: #FFFEFD;
}
.list-cell:selected {
-fx-background-color: #891000;
-fx-text-fill: #FFFEFD;
}
.m-name {
-fx-padding: 10;
-fx-text-fill: #fffefd;
-fx-font-size: 25;
-fx-alignment: center-left;
-fx-background-color: #861405;
}
.m-plot {
-fx-padding: 10;
-fx-text-fill: #fffefd;
-fx-font-size: 19;
-fx-alignment: center-left;
-fx-background-color: #861405;
}