def test_graph_creation(self): # Test multiple graph creation possibilities # Import ratings as DataFrame ratings_import = RatingsImporter(source=CSVFile(ratings_filename), from_id_column='user_id', to_id_column='item_id', score_column='points', timestamp_column='timestamp', score_processor=NumberNormalizer()) ratings_frame = ratings_import.import_ratings() # Create graph using the property 'starring' from representation '0' ('dbpedia') g = NXTripartiteGraph(ratings_frame, movies_dir, item_exo_representation=0, item_exo_properties=['starring']) # Simple assert just to make sure the graph is created self.assertGreater(len(g.user_nodes), 0) self.assertGreater(len(g.item_nodes), 0) self.assertGreater(len(g.property_nodes), 0) # Create graph specifying only the exo representation g = NXTripartiteGraph(ratings_frame, movies_dir, item_exo_representation="dbpedia") # Simple assert just to make sure the graph is created self.assertGreater(len(g.user_nodes), 0) self.assertGreater(len(g.item_nodes), 0) self.assertGreater(len(g.property_nodes), 0) # Create graph specifying only the exo representation g = NXTripartiteGraph(ratings_frame, movies_dir, item_exo_properties=['starring']) # Simple assert just to make sure the graph is created self.assertGreater(len(g.user_nodes), 0) self.assertGreater(len(g.item_nodes), 0) self.assertGreater(len(g.property_nodes), 0) # Create graph specifying without properties g = NXTripartiteGraph(ratings_frame) # Simple assert just to make sure the graph is created self.assertGreater(len(g.user_nodes), 0) self.assertGreater(len(g.item_nodes), 0) self.assertEqual(len(g.property_nodes), 0)
def test_populate_from_dataframe_w_labels(self): df_label = pd.DataFrame.from_dict({ 'from_id': ["1", "1", "2", "2", "2", "3", "4", "4"], 'to_id': [ "tt0112281", "tt0112302", "tt0112281", "tt0112346", "tt0112453", "tt0112453", "tt0112346", "tt0112453" ], 'score': [0.8, 0.7, -0.4, 1.0, 0.4, 0.1, -0.3, 0.7], 'label': [ 'score_df', 'score_df', 'score_df', 'score_df', 'score_df', 'score_df', 'score_df', 'score_df' ] }) g: NXTripartiteGraph = NXTripartiteGraph( df_label, movies_dir, item_exo_representation="dbpedia", item_exo_properties=['film director']) for user, item, score in zip(df_label['from_id'], df_label['to_id'], df_label['score']): expected = {'label': 'score_df', 'weight': score} result = g.get_link_data(user, item) self.assertEqual(expected, result)
def setUp(self) -> None: self.df = pd.DataFrame.from_dict({'from_id': ["1", "1", "2", "2", "2", "3", "4", "4"], 'to_id': ["tt0112281", "tt0112302", "tt0112281", "tt0112346", "tt0112453", "tt0112453", "tt0112346", "tt0112453"], 'score': [0.8, 0.7, -0.4, 1.0, 0.4, 0.1, -0.3, 0.7]}) self.g: NXTripartiteGraph = NXTripartiteGraph(self.df, movies_dir, item_exo_representation="dbpedia", item_exo_properties=['film director'])