def test_item_build(): data = dict() data['name'] = 'u2' data['popularity'] = 5.0 item = Item(MOVIEID) item.add_data(data) assert_true(isinstance(item, Item)) assert_equal(str(item.get_data()), "{'popularity': 5.0, 'name': 'u2'}")
def _read_items(filename): items = dict() for line in open(filename): #1::Toy Story (1995)::Animation|Children's|Comedy data = line.strip('\r\n').split('::') item_id = data[0] item_name = data[1] genres = data[2:] items[item_id] = Item(item_id) items[item_id].add_data({'name': item_name, 'genres': genres}) return items
def setUp(self): data = Data() for stars, item_id, user_id in ratings: data.add_tuple((stars, item_id, user_id)) movies = dict() for mid, name, genres in movie_genres: movie = Item(mid) movie.add_data({'name': name, 'genres': genres}) movies[mid] = movie self.ratings = data self.movies = movies
def _read_items(filename): items = dict() for line in codecs.open(filename, 'r', 'latin1'): #1::Toy Story (1995)::Animation|Children's|Comedy data = line.strip('\r\n').split('::') item_id = int(data[0]) item_name = data[1] str_genres = data[2] genres = [] for genre in str_genres.split('|'): genres.append(genre) items[item_id] = Item(item_id) items[item_id].add_data({'name': item_name, 'genres': genres}) return items
def read_item_data(filename): itemdict = {} f = open(item_file, 'r') for r in f: p = r.split('::') if p[0] in itemdict: print "Duplicate!", p[0] else: item = Item(p[0]) idat = {} if len(p) > 1: idat['Title'] = p[1] if len(p) > 2: idat['Genres'] = p[2] item.add_data(idat) itemdict[p[0]] = item return itemdict
def load_movies(filename): """ Load movies. """ pattern = re.compile(r'''((?:[^,"']|"[^"]*"|'[^']*')+)''') items = dict() for line in open(filename): try: data = pattern.split(line)[1::2] item_id = int(data[0]) item_name = data[1] genres = data[2].split('|') item = Item(item_id) item.add_data({'name': item_name, 'genres': genres}) items[item_id] = item except ValueError: continue return items
def test_user_add_item(): u = User(USERID) item = Item(ARTISTID) item.add_data({'name': ARTISTID}) u.add_item(item, PLAYS) assert_equal(str(u.get_items()), '[(u2, 25)]')