コード例 #1
0
    def get_degree_of_separation_visualisation(self, author1, author2):
        
        if author1 == '' or author2 == '':
            return Graph()
        
        if author1 == author2:
            return Graph()
        
        # Compute all the shortest paths from author1 to author2
        try:
            list_of_paths = all_shortest_paths(self.authors_graph, self.author_idx[author1], self.author_idx[author2])
        except NetworkXError as e:
            return "Not found"

        g = Graph()
        # Add the shortest paths to the graph
        try:
            for path in list_of_paths:
                g.add_path(path)
        except NetworkXNoPath as e:
            return Graph()

        # Add attributes to nodes
        for i in g.nodes():
            g.node[i]['name']=self.authors[i].name
        print g.nodes(data=True)
        return g
コード例 #2
0
def _sequence_graph(parameterValues):
    '''Convert a list of values to a graph that connects adgacent values'''
    graph = Graph()
    graph.add_nodes_from(parameterValues)
    graph.add_path(parameterValues)
    assert len(graph.nodes())>0, "Generated an empty graph. Is parameterValues empty?"
    return graph
コード例 #3
0
 def get_control_flow(self):
     """Create a control flow graph from saved nodes.
     """
     from networkx import Graph
     graph = Graph()
     for offset, node in self.nodes.iteritems():
         for following in node["successors"]:
             graph.add_path([offset, following])
     return graph