[U] Variable names

This commit is contained in:
Hykilpikonna
2022-03-21 00:48:53 -04:00
parent 95244b2cd4
commit 2bc48868e4
+13 -7
View File
@@ -273,17 +273,23 @@ def load_review_graph(reviews_file: str, book_names_file: str) -> Graph:
True
"""
g = Graph()
mp = {} # maps book ID to book name
# mp[book_id] = book_name
mp: dict[str, str]
# Read book names file and create id-name mapping
with open(book_names_file, 'r', newline='', encoding='UTF-8') as f:
reader = csv.reader(f)
for row in reader:
mp[row[0]] = row[1]
mp = {book_id: name for book_id, name in reader}
# Read user review file and link user and reviews in the graph
with open(reviews_file, 'r', newline='', encoding='UTF-8') as f:
reader = csv.reader(f)
for row in reader:
g.add_vertex(row[0], 'user')
g.add_vertex(mp[row[1]], 'book')
g.add_edge(row[0], mp[row[1]])
for user_id, book_id, rating in reader:
g.add_vertex(user_id, 'user')
g.add_vertex(mp[book_id], 'book')
g.add_edge(user_id, mp[book_id])
return g