def make_sim_graphs(school_graphs, school_akws): """ Takes school graphs dict and school author-kw dict and makes a keyword similarity graph for each school. Returns dict keyed by school name with sim graphs as values. """ school_simgraphs = {} for school in school_graphs: collab_graph = school_graphs[school] akw = school_akws[school] sim_graph = gu.make_sim_graph(akw, collab_graph) school_simgraphs[school] = sim_graph return school_simgraphs
def test_sim_graph_making(self): akw = { 1: {"keywords": ["java", "python", "django"]}, 2: {"keywords": ["java", "python", "graphs"]}, 3: {"keywords": ["software", "graphs", "programming"]} } col_graph = nx.Graph() col_graph.add_node(1, {"name": 'bob', 'in_school': True, 'paper_count': 12}) col_graph.add_node(2, {"name": 'alice', 'in_school': True, 'paper_count': 10}) col_graph.add_node(3, {"name": 'eve', 'in_school': True, 'paper_count': 20}) col_graph.add_edge(1, 3) sim_graph = gu.make_sim_graph(akw, col_graph) self.assertEqual(sim_graph.number_of_nodes(), 3) self.assertEqual(sim_graph.number_of_edges(), 2) self.assertTrue(sim_graph.has_edge(1, 2) and sim_graph.has_edge(2, 3)) self.assertTrue("java" in sim_graph[1][2]['sim_kw'] and "python" in sim_graph[1][2]['sim_kw']) self.assertTrue("graphs" in sim_graph[2][3]['sim_kw'])