import scipy.sparse as sp import numpy as np from time import time import args class Dataset(object): def __init__(self, path): self.testRatings = self.load_rating_file_as_list(path + ".test.rating") self.testNegatives = self.load_negative_file(path + ".test.negative") assert len(self.testRatings) == len(self.testNegatives) def load_rating_file_as_list(self, filename): ratingList = [] with open(filename, "r") as f: line = f.readline() while line != None and line != "": arr = line.split("\t") user, item = int(arr[0]), int(arr[1]) ratingList.append([user, item]) line = f.readline() return ratingList def load_negative_file(self, filename): negativeList = [] with open(filename, "r") as f: line = f.readline() while line != None and line != "": arr = line.split("\t") negatives = [] for x in arr[1: ]: negatives.append(int(x)) negativeList.append(negatives) line = f.readline() return negativeList