def search(self, query, exclude=[], limit=20, rtype="paper", force=False):
"""
Checks if the graph model already exists, otherwise creates one and
runs the ranking on the nodes.
"""
graph = build_graph(query,
self.params['K'],
self.params['H'],
self.params['min_topic_lift'],
self.params['min_ngram_lift'],
exclude, force, load=True, save=self.save)
# Store number of nodes for checking later
self.nnodes = graph.number_of_nodes()
# Rank nodes using subgraph
scores = ranker.rank_nodes(graph, limit=limit, 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=limit, return_type=rtype)
# Add to class object for future access
self.graph = graph
return [str(pub_id) for _nid, pub_id, _score in results]
评论列表
文章目录