# -*- coding: utf-8 -*- from graphgenpy import GraphGenerator from graphgenpy import utils import os import networkx as nx # Give me a graph of actors (role=1) that have played in the same movie, only for movie_ids 0-200 datalogQuery = """ Nodes(id,name):- name(id,name),cast_info(_,id,movie_id,_,_,_,role),movie_id <=200,role='1'. Edges(id1,id2):- cast_info(_,id1,movie_id,_,_,_,role),cast_info(_,id2,movie_id,_,_,_,role), role='1',movie_id<= 200. """ filename = 'coactorship' # Specify database connection details and instanciate GraphGen object gg = GraphGenerator("imdb","localhost","5432","kostasx","pass") # Evaluate graph extraction query and serialize the resulting graph to disk in a standard format fname = gg.generateGraph(datalogQuery,filename,GraphGenerator.GML) # Import graph into NetworkX by reading the serialized graph #for GML Format G = nx.read_gml(fname,'id'); print "Graph Loaded into NetworkX! Running PageRank..." nx.pagerank(G) print "Done!"
from graphgenpy import GraphGenerator import networkx as nx # a graph of authors if they've bought the same part. datalogQuery = """ Nodes(ID, Name) :- Customer(ID, Name). Edges(ID1, ID2) :- Orders(orderId1, ID1),Lineitem(orderId1,part),Orders(orderId2, ID2),Lineitem(orderId2,part),part < 1000. """ # Credentials for connecting to the database gg = GraphGenerator("tpch", "localhost", "5432", "kostasx", "password") #All these must be strings!! # Evaluate graph extraction query and serialize the resulting graph to disk in a standard format. Return the file's name in the FS. extracted_name = "extracted_graph_tpch" fname = gg.generateGraph(datalogQuery, extracted_name, GraphGenerator.GML) # Load graph into NetworkX G = nx.read_gml(fname, 'id') #by default, the graph format will me gml print "Graph Loaded into NetworkX! Running PageRank..." # Run any algorithm on the graph using NetowrkX # print nx.pagerank(G) print "Done!"
from graphgenpy import GraphGenerator import networkx as nx # a graph of authors if they've bought the same part. datalogQuery = """ Nodes(ID, Name) :- Customer(ID, Name). Edges(ID1, ID2) :- Orders(orderId1, ID1),Lineitem(orderId1,part),Orders(orderId2, ID2),Lineitem(orderId2,part),part < 1000. """ # Credentials for connecting to the database gg = GraphGenerator("tpch","localhost","5432","kostasx","password") #All these must be strings!! # Evaluate graph extraction query and serialize the resulting graph to disk in a standard format. Return the file's name in the FS. extracted_name = "extracted_graph_tpch" fname = gg.generateGraph(datalogQuery,extracted_name,GraphGenerator.GML) # Load graph into NetworkX G = nx.read_gml(fname,'id') #by default, the graph format will me gml print "Graph Loaded into NetworkX! Running PageRank..." # Run any algorithm on the graph using NetowrkX # print nx.pagerank(G) print "Done!"
from graphgenpy import GraphGenerator import networkx as nx # a graph of authors if they've bought the same part. datalogQuery = """ Nodes(ID, Name) :- Customer(ID, Name). Edges(ID1, ID2) :- Orders(orderId1, ID1),Lineitem(orderId1,part),Orders(orderId2, ID2),Lineitem(orderId2,part),part < 1000. """ # Credentials for connecting to the database gg = GraphGenerator("localhost","5432","tpch","kostasx","password") #All these must be strings!! # Evaluate graph extraction query and serialize the resulting graph to disk in a standard format. Return the file's name in the FS. fname = gg.generateGraph(datalogQuery,"extracted_graph_tpch",GraphGenerator.GML) # Load graph into NetworkX G = nx.read_gml(fname,'id') #by default, the graph format will me gml print "Graph Loaded into NetworkX! Running PageRank..." # Run any algorithm on the graph using NetowrkX # print nx.pagerank(G) print "Done!"