Skip to content

Commit

Permalink
Merge pull request #20 from arangoml/query-options
Browse files Browse the repository at this point in the history
Introduce AQL query options to create_networkx_graph
  • Loading branch information
cw00dw0rd authored Oct 7, 2021
2 parents 75e37d9 + b00e778 commit c62bd09
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ attributes = { 'vertexCollections':
# Export networkX graph
g = ma.create_networkx_graph(graph_name = 'FraudDetection', graph_attributes = attributes)

# You can also provide valid Python-Arango AQL query options to the command above, like such:
# g = ma.create_networkx_graph(graph_name = 'FraudDetection', graph_attributes = attributes, ttl=1000, stream=True)

# Use networkX
nx.draw(g, with_labels=True)
```
Expand Down
6 changes: 3 additions & 3 deletions adbnx_adapter/adbnx_adapter/arangoDB_networkx_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def is_valid_graph_attributes(self, graph_config):

return valid_config

def create_networkx_graph(self, graph_name, graph_attributes):
def create_networkx_graph(self, graph_name, graph_attributes, **query_options):

if self.is_valid_graph_attributes(graph_attributes):
g = nx.DiGraph()
Expand All @@ -77,7 +77,7 @@ def create_networkx_graph(self, graph_name, graph_attributes):
csps = ','.join(cspl)
query = query + "RETURN { " + csps + "}"

cursor = self.db.aql.execute(query)
cursor = self.db.aql.execute(query, **query_options)
for doc in cursor:
g.add_node(doc['_id'], attr_dict=doc)

Expand All @@ -88,7 +88,7 @@ def create_networkx_graph(self, graph_name, graph_attributes):
csps = ','.join(cspl)
query = query + "RETURN { " + csps + "}"

cursor = self.db.aql.execute(query)
cursor = self.db.aql.execute(query, **query_options)
# breakpoint()
for doc in cursor:
g.add_edge(doc['_from'], doc['_to'])
Expand Down
6 changes: 3 additions & 3 deletions adbnx_adapter/adbnx_adapter/dgl_arangoDB_networkx_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class DGLArangoDB_Networkx_Adapter(ArangoDB_Networkx_Adapter):

def create_networkx_graph(self, graph_name, graph_attributes):
def create_networkx_graph(self, graph_name, graph_attributes, **query_options):

if self.is_valid_graph_attributes(graph_attributes):
edge_names = []
Expand Down Expand Up @@ -45,7 +45,7 @@ def create_networkx_graph(self, graph_name, graph_attributes):
ens = k.split('_', 1)
redge = ens[1] + '_' + ens[0]
rsgraph = rsgdata[redge]
cursor = self.db.aql.execute(query)
cursor = self.db.aql.execute(query, **query_options)
for doc in cursor:
nfrom = doc['_from']
nto = doc['_to']
Expand All @@ -67,7 +67,7 @@ def create_networkx_graph(self, graph_name, graph_attributes):
csps = ','.join(cspl)
query = query + "RETURN { " + csps + "}"

cursor = self.db.aql.execute(query)
cursor = self.db.aql.execute(query, **query_options)
for doc in cursor:
exclude_attr = ['_id', '_key', 'node_id']
if k == 'incident':
Expand Down
6 changes: 3 additions & 3 deletions adbnx_adapter/adbnx_adapter/imdb_arangoDB_networkx_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class IMDBArangoDB_Networkx_Adapter(ArangoDB_Networkx_Adapter):

def create_networkx_graph(self, graph_name, graph_attributes):
def create_networkx_graph(self, graph_name, graph_attributes, **query_options):

if self.is_valid_graph_attributes(graph_attributes):
g = nx.DiGraph()
Expand All @@ -24,7 +24,7 @@ def create_networkx_graph(self, graph_name, graph_attributes):
csps = ','.join(cspl)
query = query + "RETURN { " + csps + "}"

cursor = self.db.aql.execute(query)
cursor = self.db.aql.execute(query, **query_options)
for doc in cursor:
if k == "Users":
bip_key = 0
Expand All @@ -39,7 +39,7 @@ def create_networkx_graph(self, graph_name, graph_attributes):
csps = ','.join(cspl)
query = query + "RETURN { " + csps + "}"

cursor = self.db.aql.execute(query)
cursor = self.db.aql.execute(query, **query_options)

for doc in cursor:
g.add_edge(doc['_from'], doc['_to'])
Expand Down

0 comments on commit c62bd09

Please sign in to comment.