-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
175 lines (136 loc) · 4.39 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "UserDatabase.h"
#include "User.h"
#include <iostream>
#include <string>
#include "Recommender.h"
using namespace std;
#include "MovieDatabase.h"
#include "Movie.h"
void findMatches(const Recommender& r, const MovieDatabase& md, const string& user_email, int num_recommendations) {
// get up to ten movie recommendations for the user
vector<MovieAndRank> recommendations =
r.recommend_movies(user_email, num_recommendations);
if (recommendations.empty())
cout << "We found no movies to recommend :(.\n";
else {
for (int i = 0; i < recommendations.size(); i++) {
const MovieAndRank& mr = recommendations[i];
Movie* m = md.get_movie_from_id(mr.movie_id);
cout << i + 1 << ". " << m->get_title() << " (" << m->get_release_year() << ")\n Rating: " << m->get_rating() << "\n Compatibility Score: "
<< mr.compatibility_score << "\n";
}
}
}
int main()
{
UserDatabase udb;
MovieDatabase mdb;
// /u/cs/ugrad/kung
if(udb.load("/Users/genekung/Desktop/Cs32/P_4/P_4/Users.txt"))
{
cout << "sucess" << endl;
}
if(mdb.load("/Users/genekung/Desktop/CS32/P_4/P_4/Movies.txt"))
{
cout << "sucess" << endl;
}
/*
if(udb.load("/u/cs/ugrad/kung/Users.txt"))
{
cout << "sucess" << endl;
}
if(mdb.load("/u/cs/ugrad/kung/Movies.txt"))
{
cout << "sucess" << endl;
}
*/
Recommender rec(udb, mdb);
findMatches(rec, mdb, "[email protected]", 10);
}
const string USER_DATAFILE = "users.txt";
const string MOVIE_DATAFILE = "movies.txt";
void printUserInfo(User* u) {
if (u == nullptr) {
cout << "No user in the database has that email address." << endl;
return;
}
else {
cout << "Name: " << u->get_full_name() << endl;
}
cout << "Email: " << u->get_email() << endl;
cout << "Movie Ids: " << endl;
vector<string> movieIDs = u->get_watch_history();
for (string s : movieIDs) {
cout << s << endl;
}
cout << endl;
}
void printMovieInfo(Movie* m) {
if (m == nullptr) {
cout << "No user in the database with that key." << endl;
return;
}
cout << "ID: " << m->get_id() << endl;
cout << "Title: " << m->get_title() << endl;
cout << "Year: " << m->get_release_year() << endl;
for (string s : m->get_directors()) {
cout << s << ", ";
}
cout << endl;
for (string s : m->get_actors()) {
cout << s << ", ";
}
cout << endl;
for (string s : m->get_genres()) {
cout << s << ", ";
}
cout << endl;
cout << "Rating: " << m->get_rating();
cout << endl << endl;
}
/*
int main()
{
MovieDatabase db;
if(db.load("/Users/genekung/Desktop/CS32/Movies.txt"))
{
vector<Movie*> moviesWithDirectors = db.get_movies_with_actor("arNOLD schwarzenegger");
//vector<Movie*> moviesWithDirectors = db.get_movies_with_genre("DRAMA");
for(int i = 0; i < moviesWithDirectors.size(); i++)
{
cout << moviesWithDirectors[i]->get_title() << endl;
}
//Movie* testMovie1 = db.get_movie_from_id("ID10782");
//printMovieInfo(testMovie1);
//Movie* testMovie2 = db.get_movie_from_id("ID25779");
//printMovieInfo(testMovie2);
// cout << testMovie2->get_title() << endl;
}
UserDatabase udb;
if(udb.load("/Users/genekung/Desktop/CS32/P_4/P_4/Users.txt"))
{
User* testUser1 = udb.get_user_from_email("[email protected]");
printUserInfo(testUser1);
User* testUser2 = udb.get_user_from_email("[email protected]");
printUserInfo(testUser2);
}
if (0&&!udb.load(USER_DATAFILE)) // In skeleton, load always return false
{
cout << "Failed to load user data file " << USER_DATAFILE << "!" << endl;
return 1;
}
for (;;)
{
cout << "Enter user email address (or quit): ";
string email;
getline(cin, email);
if (email == "quit")
return 0;
User* u = udb.get_user_from_email(email);
if (u == nullptr)
cout << "No user in the database has that email address." << endl;
else
cout << "Found " << u->get_full_name() << endl;
}
}
*/