mirror of
https://github.com/lukefleed/imdb-graph.git
synced 2026-10-16 01:29:02 +00:00
new chapters
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
void DataRead()
|
||||
{
|
||||
ifstream actors("data/Attori.txt");
|
||||
ifstream movies("data/FilmFiltrati.txt");
|
||||
|
||||
string s,t;
|
||||
const string space /* the final frontier */ = "\t";
|
||||
for (int i = 1; getline(actors,s); i++)
|
||||
{
|
||||
if (s.empty())
|
||||
continue;
|
||||
try {
|
||||
Actor TmpObj;
|
||||
int id = stoi(s.substr(0, s.find(space)));
|
||||
TmpObj.name = s.substr(s.find(space)+1);
|
||||
A[id] = TmpObj; // Python notation, works with C++17
|
||||
if (id > MAX_ACTOR_ID)
|
||||
MAX_ACTOR_ID = id;
|
||||
} catch (...) {
|
||||
cout << "Could not read the line " << i << " of Actors file" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 1; getline(movies,t); i++)
|
||||
{
|
||||
if (t.empty())
|
||||
continue;
|
||||
|
||||
try{
|
||||
Film TmpObj;
|
||||
int id = stoi(t.substr(0, t.find(space)));
|
||||
TmpObj.name = t.substr(t.find(space)+1);
|
||||
F[id] = TmpObj;
|
||||
} catch (...) {
|
||||
cout << "Could not read the line " << i << " of Film file" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
void BuildGraph()
|
||||
{
|
||||
ifstream relations("data/Relazioni.txt");
|
||||
string s;
|
||||
const string space = "\t";
|
||||
|
||||
for (int i=1; getline(relations,s); i++){
|
||||
if (s.empty())
|
||||
continue;
|
||||
try {
|
||||
int id_film = stoi(s.substr(0, s.find(space)));
|
||||
int id_attore = stoi(s.substr(s.find(space)+1));
|
||||
if (A.count(id_attore) && F.count(id_film)) { // Exclude movies and actors filtered
|
||||
A[id_attore].film_indices.push_back(id_film);
|
||||
F[id_film].actor_indicies.push_back(id_attore);
|
||||
}
|
||||
} catch (...) {
|
||||
cout << "Could not read the line " << i << " of Releations file" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
map<int, Actor> A; // Dictionary {actor_id (key): Actor (value)}
|
||||
map<int, Film> F; // Dictionary {film_id (key): Film (value)}
|
||||
@@ -0,0 +1,9 @@
|
||||
struct Film {
|
||||
string name;
|
||||
vector<int> actor_indicies;
|
||||
};
|
||||
|
||||
struct Actor {
|
||||
string name;
|
||||
vector<int> film_indices;
|
||||
};
|
||||
Reference in New Issue
Block a user