예제 #1
0
	def test_single_author_graph(self):
		g = nx.Graph()
		g.add_nodes_from([1, 2, 3, 4, 5])
		g.add_edge(1, 2)
		g.add_edge(1, 3)
		g.add_edge(3, 5)
		g.add_edge(5, 4)
		cutoff = 2
		single = gu.single_author_graph(g, 1, cutoff)
		self.assertEqual(single.number_of_nodes(), 4)
		self.assertEqual(single.number_of_edges(), 3)
		self.assertTrue(1 in single.nodes() and 2 in single.nodes() and 3 in single.nodes() and 5 in single.nodes())
		self.assertFalse(4 in single.nodes())
예제 #2
0
파일: views.py 프로젝트: tvzeller/SumProj
def single_from_id(author_num, unigraph, cutoff):
	"""
	Takes node id, full graph and cutoff and returns graph with all nodes reachable by source node up to a distance of cutoff
	"""
	# make full node id
	author_id = "http://eprints.gla.ac.uk/view/author/" + author_num + ".html"
	# Node not found, return error message
	if author_id not in graph_utils.get_node_set(unigraph):
		errorMessage = json.dumps({"error": "Sorry, the author was not found"})
		return HttpResponse(errorMessage, content_type='application/json')

	# Make and return single author graph
	author_graph = graph_utils.single_author_graph(unigraph, author_id, cutoff)

	graphdata = graph_utils.json_from_graph(author_graph)
	newdata = json.dumps(graphdata)

	return HttpResponse(newdata, content_type='application/json')