def search(self, selected_affils, conf_name, year, exclude_papers=[], rtype="affil", force=False):
"""
Checks if the graph model already exists, otherwise creates one and
runs the ranking on the nodes.
"""
graph = build_graph(conf_name,
year,
self.params['H'],
self.params['min_topic_lift'],
self.params['min_ngram_lift'],
exclude_papers, force, load=True, save=self.save)
# Store number of nodes for checking later
self.nnodes = graph.number_of_nodes()
# Rank nodes using subgraph
scores = rank_nodes(graph, return_type=rtype, **self.params)
# Adds the score to the nodes and writes to disk. A stupid cast
# is required because write_gexf can't handle np.float64
scores = {nid: float(score) for nid, score in scores.items()}
nx.set_node_attributes(graph, "score", scores)
# nx.write_gexf(graph, utils.get_graph_file_name(model_folder, query))
# Returns the top values of the type of node of interest
results = get_top_nodes(graph, scores.items(), limit=selected_affils, return_type=rtype)
# Add to class object for future access
self.graph = graph
return results
评论列表
文章目录