Skip to content

Commit 47ab43e

Browse files
author
Mark Needham
committed
more notebooks
1 parent dfa58a1 commit 47ab43e

10 files changed

+607
-342
lines changed

empty.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
3+
from neo4j.v1 import GraphDatabase, basic_auth
4+
5+
host = os.environ.get("NEO4J_HOST", "bolt://localhost")
6+
user = os.environ.get("NEO4J_USER", "neo4j")
7+
password = os.environ.get("NEO4J_PASSWORD", "neo")
8+
driver = GraphDatabase.driver(host, auth=basic_auth(user, password))
9+
10+
11+
def clear_db():
12+
with driver.session() as session:
13+
session.run("MATCH (n) DETACH DELETE n")
14+
15+
16+
clear_db()

generate_notebook.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ def find_tag(file, tag):
3131
print("Usage: python generate_notebook.py <Algorithm Name> <Description> <Cypher File>")
3232
sys.exit(1)
3333

34-
3534
algorithm_name = sys.argv[1]
3635
algorithm_description = find_tag(sys.argv[2], "introduction")
3736
cypher_file = sys.argv[3]
3837

38+
stream_graph_tag = "stream-sample-graph"
39+
if len(sys.argv) >= 5:
40+
stream_graph_tag = sys.argv[4]
41+
42+
3943
text = """\
4044
# {0}
4145
{1}
@@ -53,7 +57,7 @@ def find_tag(file, tag):
5357
driver = GraphDatabase.driver(host, auth=basic_auth(user, password))"""
5458

5559
create_graph_content = find_tag(cypher_file, "create-sample-graph")
56-
streaming_query_content = find_tag(cypher_file, "stream-sample-graph")
60+
streaming_query_content = find_tag(cypher_file, stream_graph_tag)
5761

5862
create_graph = """\
5963
create_graph_query = '''\

generate_notebooks.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,33 @@ python generate_notebook.py \
2121
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/closeness-centrality.adoc" \
2222
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/scripts/closeness-centrality.cypher"
2323

24+
python generate_notebook.py \
25+
"Unweighted Connected Components" \
26+
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/connected-components.adoc" \
27+
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/scripts/connected-components.cypher" \
28+
"unweighted-stream-sample-graph"
29+
30+
python generate_notebook.py \
31+
"Weighted Connected Components" \
32+
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/connected-components.adoc" \
33+
"https://github.com/neo4j-contrib/neo4j-graph-algorithms/raw/3.2/doc/asciidoc/scripts/connected-components.cypher" \
34+
"weighted-stream-sample-graph"
35+
36+
37+
python empty.py
2438
jupyter nbconvert --execute --inplace notebooks/PageRank.ipynb
39+
40+
python empty.py
2541
jupyter nbconvert --execute --inplace notebooks/Louvain.ipynb
42+
43+
python empty.py
2644
jupyter nbconvert --execute --inplace notebooks/BetweennessCentrality.ipynb
45+
46+
python empty.py
2747
jupyter nbconvert --execute --inplace notebooks/ClosenessCentrality.ipynb
48+
49+
python empty.py
50+
jupyter nbconvert --execute --inplace notebooks/UnweightedConnectedComponents.ipynb
51+
52+
python empty.py
53+
jupyter nbconvert --execute --inplace notebooks/WeightedConnectedComponents.ipynb

notebooks/BetweennessCentrality.ipynb

Lines changed: 14 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -102,130 +102,46 @@
102102
" <tbody>\n",
103103
" <tr>\n",
104104
" <th>0</th>\n",
105-
" <td>140</td>\n",
105+
" <td>19</td>\n",
106106
" <td>4.0</td>\n",
107107
" </tr>\n",
108108
" <tr>\n",
109109
" <th>1</th>\n",
110-
" <td>142</td>\n",
110+
" <td>109</td>\n",
111111
" <td>2.0</td>\n",
112112
" </tr>\n",
113113
" <tr>\n",
114114
" <th>2</th>\n",
115-
" <td>8</td>\n",
115+
" <td>108</td>\n",
116116
" <td>0.0</td>\n",
117117
" </tr>\n",
118118
" <tr>\n",
119119
" <th>3</th>\n",
120-
" <td>9</td>\n",
120+
" <td>128</td>\n",
121121
" <td>0.0</td>\n",
122122
" </tr>\n",
123123
" <tr>\n",
124124
" <th>4</th>\n",
125-
" <td>10</td>\n",
125+
" <td>129</td>\n",
126126
" <td>0.0</td>\n",
127127
" </tr>\n",
128128
" <tr>\n",
129129
" <th>5</th>\n",
130-
" <td>11</td>\n",
131-
" <td>0.0</td>\n",
132-
" </tr>\n",
133-
" <tr>\n",
134-
" <th>6</th>\n",
135-
" <td>12</td>\n",
136-
" <td>0.0</td>\n",
137-
" </tr>\n",
138-
" <tr>\n",
139-
" <th>7</th>\n",
140-
" <td>13</td>\n",
141-
" <td>0.0</td>\n",
142-
" </tr>\n",
143-
" <tr>\n",
144-
" <th>8</th>\n",
145-
" <td>20</td>\n",
146-
" <td>0.0</td>\n",
147-
" </tr>\n",
148-
" <tr>\n",
149-
" <th>9</th>\n",
150-
" <td>21</td>\n",
151-
" <td>0.0</td>\n",
152-
" </tr>\n",
153-
" <tr>\n",
154-
" <th>10</th>\n",
155-
" <td>22</td>\n",
156-
" <td>0.0</td>\n",
157-
" </tr>\n",
158-
" <tr>\n",
159-
" <th>11</th>\n",
160-
" <td>23</td>\n",
161-
" <td>0.0</td>\n",
162-
" </tr>\n",
163-
" <tr>\n",
164-
" <th>12</th>\n",
165-
" <td>24</td>\n",
166-
" <td>0.0</td>\n",
167-
" </tr>\n",
168-
" <tr>\n",
169-
" <th>13</th>\n",
170-
" <td>25</td>\n",
171-
" <td>0.0</td>\n",
172-
" </tr>\n",
173-
" <tr>\n",
174-
" <th>14</th>\n",
175-
" <td>40</td>\n",
176-
" <td>0.0</td>\n",
177-
" </tr>\n",
178-
" <tr>\n",
179-
" <th>15</th>\n",
180-
" <td>41</td>\n",
181-
" <td>0.0</td>\n",
182-
" </tr>\n",
183-
" <tr>\n",
184-
" <th>16</th>\n",
185-
" <td>42</td>\n",
186-
" <td>0.0</td>\n",
187-
" </tr>\n",
188-
" <tr>\n",
189-
" <th>17</th>\n",
190-
" <td>43</td>\n",
191-
" <td>0.0</td>\n",
192-
" </tr>\n",
193-
" <tr>\n",
194-
" <th>18</th>\n",
195-
" <td>44</td>\n",
196-
" <td>0.0</td>\n",
197-
" </tr>\n",
198-
" <tr>\n",
199-
" <th>19</th>\n",
200-
" <td>45</td>\n",
130+
" <td>130</td>\n",
201131
" <td>0.0</td>\n",
202132
" </tr>\n",
203133
" </tbody>\n",
204134
"</table>\n",
205135
"</div>"
206136
],
207137
"text/plain": [
208-
" nodeId centrality\n",
209-
"0 140 4.0\n",
210-
"1 142 2.0\n",
211-
"2 8 0.0\n",
212-
"3 9 0.0\n",
213-
"4 10 0.0\n",
214-
"5 11 0.0\n",
215-
"6 12 0.0\n",
216-
"7 13 0.0\n",
217-
"8 20 0.0\n",
218-
"9 21 0.0\n",
219-
"10 22 0.0\n",
220-
"11 23 0.0\n",
221-
"12 24 0.0\n",
222-
"13 25 0.0\n",
223-
"14 40 0.0\n",
224-
"15 41 0.0\n",
225-
"16 42 0.0\n",
226-
"17 43 0.0\n",
227-
"18 44 0.0\n",
228-
"19 45 0.0"
138+
" nodeId centrality\n",
139+
"0 19 4.0\n",
140+
"1 109 2.0\n",
141+
"2 108 0.0\n",
142+
"3 128 0.0\n",
143+
"4 129 0.0\n",
144+
"5 130 0.0"
229145
]
230146
},
231147
"execution_count": 4,
@@ -248,25 +164,7 @@
248164
]
249165
}
250166
],
251-
"metadata": {
252-
"kernelspec": {
253-
"display_name": "Python 3",
254-
"language": "python",
255-
"name": "python3"
256-
},
257-
"language_info": {
258-
"codemirror_mode": {
259-
"name": "ipython",
260-
"version": 3
261-
},
262-
"file_extension": ".py",
263-
"mimetype": "text/x-python",
264-
"name": "python",
265-
"nbconvert_exporter": "python",
266-
"pygments_lexer": "ipython3",
267-
"version": "3.6.0"
268-
}
269-
},
167+
"metadata": {},
270168
"nbformat": 4,
271169
"nbformat_minor": 2
272170
}

notebooks/ClosenessCentrality.ipynb

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# ClosenessCentrality\n",
7+
"# Closeness Centrality\n",
88
"The _Closeness Centrality_ of a node measures the distance from that node to all other nodes.\n",
99
"Nodes with a high closeness score have the shortest distances to all other nodes.\n",
1010
"The premise of this algorithm is that nodes with short distance to other nodes can spread information very efficiently through the network.\n",
@@ -102,40 +102,40 @@
102102
" <tbody>\n",
103103
" <tr>\n",
104104
" <th>0</th>\n",
105-
" <td>163</td>\n",
106-
" <td>0.0</td>\n",
105+
" <td>191</td>\n",
106+
" <td>0.666667</td>\n",
107107
" </tr>\n",
108108
" <tr>\n",
109109
" <th>1</th>\n",
110-
" <td>164</td>\n",
111-
" <td>0.0</td>\n",
110+
" <td>190</td>\n",
111+
" <td>0.571429</td>\n",
112112
" </tr>\n",
113113
" <tr>\n",
114114
" <th>2</th>\n",
115-
" <td>165</td>\n",
116-
" <td>0.0</td>\n",
115+
" <td>192</td>\n",
116+
" <td>0.571429</td>\n",
117117
" </tr>\n",
118118
" <tr>\n",
119119
" <th>3</th>\n",
120-
" <td>166</td>\n",
121-
" <td>0.0</td>\n",
120+
" <td>189</td>\n",
121+
" <td>0.400000</td>\n",
122122
" </tr>\n",
123123
" <tr>\n",
124124
" <th>4</th>\n",
125-
" <td>167</td>\n",
126-
" <td>0.0</td>\n",
125+
" <td>193</td>\n",
126+
" <td>0.400000</td>\n",
127127
" </tr>\n",
128128
" </tbody>\n",
129129
"</table>\n",
130130
"</div>"
131131
],
132132
"text/plain": [
133133
" nodeId centrality\n",
134-
"0 163 0.0\n",
135-
"1 164 0.0\n",
136-
"2 165 0.0\n",
137-
"3 166 0.0\n",
138-
"4 167 0.0"
134+
"0 191 0.666667\n",
135+
"1 190 0.571429\n",
136+
"2 192 0.571429\n",
137+
"3 189 0.400000\n",
138+
"4 193 0.400000"
139139
]
140140
},
141141
"execution_count": 4,
@@ -145,7 +145,7 @@
145145
],
146146
"source": [
147147
"streaming_query = \"\"\"\n",
148-
"CALL algo.closeness.stream('Node', 'LINKS') YIELD nodeId, centrality\n",
148+
"CALL algo.closeness.stream('Node', 'LINK') YIELD nodeId, centrality\n",
149149
"RETURN nodeId,centrality order by centrality desc limit 20;\n",
150150
"\"\"\"\n",
151151
"\n",
@@ -157,25 +157,7 @@
157157
]
158158
}
159159
],
160-
"metadata": {
161-
"kernelspec": {
162-
"display_name": "Python 3",
163-
"language": "python",
164-
"name": "python3"
165-
},
166-
"language_info": {
167-
"codemirror_mode": {
168-
"name": "ipython",
169-
"version": 3
170-
},
171-
"file_extension": ".py",
172-
"mimetype": "text/x-python",
173-
"name": "python",
174-
"nbconvert_exporter": "python",
175-
"pygments_lexer": "ipython3",
176-
"version": "3.6.0"
177-
}
178-
},
160+
"metadata": {},
179161
"nbformat": 4,
180162
"nbformat_minor": 2
181163
}

0 commit comments

Comments
 (0)