Skip to content

Commit be27a89

Browse files
author
Mark Needham
committed
add write queries for the algos
1 parent add7d30 commit be27a89

File tree

4 files changed

+100
-30
lines changed

4 files changed

+100
-30
lines changed

generate_notebook.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def find_tag(file, tag):
4949
if len(sys.argv) >= 6:
5050
explanation_tag = sys.argv[5]
5151

52+
write_graph_tag = "write-sample-graph"
53+
if len(sys.argv) >= 7:
54+
write_graph_tag = sys.argv[6]
55+
5256
heading_text = """\
5357
# {0}
5458
{1}
@@ -106,6 +110,21 @@ def find_tag(file, tag):
106110

107111
streaming_graph_explanation_text = find_tag(algorithm_file, explanation_tag)
108112

113+
write_graph_text = '''We can also call a version of the algorithm that will store the result as a property on a
114+
node. This is useful if we want to run future queries that use the result.'''
115+
116+
write_query_content = find_tag(cypher_file, write_graph_tag)
117+
118+
write_graph = '''\
119+
write_query = """\
120+
121+
%s
122+
"""
123+
124+
with driver.session() as session:
125+
session.write_transaction(lambda tx: tx.run(write_query))''' % write_query_content
126+
127+
109128
viz_intro_text = '''## Graph Visualisation
110129
111130
Sometimes a picture can tell more than a table of results and this is often the case with graph algorithms.
@@ -222,6 +241,8 @@ def find_tag(file, tag):
222241
nbf.v4.new_markdown_cell(streaming_graph_text),
223242
nbf.v4.new_code_cell(run_algorithm),
224243
nbf.v4.new_markdown_cell(streaming_graph_explanation_text),
244+
nbf.v4.new_markdown_cell(write_graph_text),
245+
nbf.v4.new_code_cell(write_graph),
225246
nbf.v4.new_markdown_cell(viz_intro_text),
226247
nbf.v4.new_code_cell(neo_vis_div_cell),
227248
nbf.v4.new_markdown_cell(python_to_js_text),

generate_notebooks.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ python generate_notebook.py \
66
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/pagerank.adoc" \
77
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/scripts/pagerank.cypher"
88

9-
python generate_notebook.py \
10-
"Louvain" \
11-
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/louvain.adoc" \
12-
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/scripts/louvain.cypher"
13-
149
python generate_notebook.py \
1510
"Betweenness Centrality" \
1611
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/betweenness-centrality.adoc" \
1712
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/scripts/betweenness-centrality.cypher"
1813

14+
python generate_notebook.py \
15+
"Louvain" \
16+
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/louvain.adoc" \
17+
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/scripts/louvain.cypher"
18+
1919
python generate_notebook.py \
2020
"Closeness Centrality" \
2121
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/closeness-centrality.adoc" \

notebooks/BetweennessCentrality.ipynb

Lines changed: 38 additions & 13 deletions
Large diffs are not rendered by default.

notebooks/PageRank.ipynb

Lines changed: 36 additions & 12 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)