Skip to content

Commit b734255

Browse files
authored
Merge pull request #42 from JohT/feature/query-parameters
Support query parameters
2 parents 7716db4 + 6fdb4f7 commit b734255

File tree

139 files changed

+1621
-908
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1621
-908
lines changed

COMMANDS.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,49 @@ Be sure to replace `path/to/local/neo4j` and `password` with your settings.
208208
cat ./cypher/Get_Graph_Data_Science_Library_Version.cypher | path/to/local/neo4j/bin/cypher-shell -u neo4j -p password --format plain
209209
```
210210
211+
Query parameter can be added with the option `--param`. Here is an example:
212+
213+
```shell
214+
cat ./cypher/Get_Graph_Data_Science_Library_Version.cypher | path/to/local/neo4j/bin/cypher-shell -u neo4j -p password --format plain --param {a: 1}
215+
```
216+
217+
For a full list of options use the help function:
218+
219+
```shell
220+
path/to/local/neo4j/bin/cypher-shell --help
221+
```
222+
211223
### HTTP API
212224
213225
Use [executeQuery.sh](./scripts/executeQuery.sh) to execute a Cypher query from the file given as an argument.
214-
It uses `curl` and `jq` to access the HTTP API of Neo4j.
226+
It uses `curl` and `jq` to access the [HTTP API of Neo4j](https://neo4j.com/docs/http-api/current/query).
215227
Here is an example:
216228
217229
```shell
218230
./scripts/executeQuery.sh ./cypher/Get_Graph_Data_Science_Library_Version.cypher
219231
```
220232
233+
Query parameters can be added as arguments after the file name. Here is an example:
234+
235+
```shell
236+
./scripts/executeQuery.sh ./cypher/Get_Graph_Data_Science_Library_Version.cypher a=1
237+
```
238+
239+
### executeQueryFunctions
240+
241+
The script [executeQueryFunctions.sh](./scripts/executeQueryFunctions.sh) contains functions to simplify the
242+
call of [executeQuery.sh](./scripts/executeQuery.sh) for different purposes. For example, `execute_cypher_summarized`
243+
prints out the results on the console in a summarized manner and `execute_cypher_expect_results` fails when there are no results.
244+
245+
The script also provides an API abstraction that defaults to [HTTP](#http-api), but can easily be switched to [cypher-shell](#cypher-shell).
246+
247+
Query parameters can be added as arguments after the file name. Here is an example:
248+
249+
```shell
250+
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
251+
execute_cypher ./cypher/Get_Graph_Data_Science_Library_Version.cypher a=1
252+
```
253+
221254
## Stop Neo4j
222255
223256
Use [stopNeo4j.sh](./scripts/stopNeo4j.sh) to stop the locally running Neo4j Graph Database. It does nothing if the database is already stopped. It runs the script with a temporary `NEO4J_HOME` environment variable to not interfere with a possibly globally installed Neo4j installation.

cypher/Centrality/Centrality_0b_Delete_Subraph_Projection.cypher

Lines changed: 0 additions & 5 deletions
This file was deleted.

cypher/Centrality/Centrality_1_Create_Projection.cypher

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// List the top centrality nodes with a 99.5 percentile or higher
2+
3+
MATCH (member)
4+
WHERE $dependencies_projection_node IN LABELS(member)
5+
AND member[$dependencies_projection_write_property] IS NOT NULL
6+
WITH count(DISTINCT member) AS memberCount
7+
,percentileDisc(member[$dependencies_projection_write_property], 0.995) AS centralityPercentile995
8+
,collect(DISTINCT member) AS members
9+
UNWIND members AS member
10+
WITH memberCount
11+
,centralityPercentile995
12+
,member
13+
ORDER BY member[$dependencies_projection_write_property] DESCENDING
14+
WHERE member[$dependencies_projection_write_property] >= centralityPercentile995
15+
WITH memberCount
16+
,centralityPercentile995
17+
,max(member[$dependencies_projection_write_property]) AS maxCentrality
18+
,collect(DISTINCT member) AS topMembers
19+
RETURN memberCount
20+
,maxCentrality
21+
,centralityPercentile995
22+
,topMembers

cypher/Centrality/Centrality_1b_Create_Subgraph_Without_Empty_Packages.cypher

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// List the top 2% nodes with the highest centrality score.
2+
3+
MATCH (member)
4+
WHERE $dependencies_projection_node IN labels(member)
5+
AND member[$dependencies_projection_write_property] IS NOT NULL
6+
WITH toInteger(toFloat(count(DISTINCT member)) * 0.02) AS memberCount2Percent
7+
,collect(DISTINCT member) AS members
8+
UNWIND members AS member
9+
WITH memberCount2Percent, member
10+
ORDER BY member[$dependencies_projection_write_property] DESCENDING
11+
WITH memberCount2Percent, collect(DISTINCT member)[0..memberCount2Percent] AS topMembers
12+
RETURN memberCount2Percent, topMembers
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Centrality Label Delete
2+
3+
CALL db.labels() YIELD label
4+
WHERE label = 'Top' + apoc.text.capitalize($dependencies_projection_write_property)
5+
WITH collect(label) AS selectedLabels
6+
MATCH (member)
7+
WHERE $dependencies_projection_node IN LABELS(member)
8+
AND member[$dependencies_projection_write_property] IS NOT NULL
9+
WITH collect(member) AS members, selectedLabels
10+
CALL apoc.create.removeLabels(members, selectedLabels) YIELD node
11+
RETURN COUNT(node) AS nodesCount;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Centrality Add label to the top 2% nodes with the highest centrality score
2+
3+
MATCH (member)
4+
WHERE $dependencies_projection_node IN labels(member)
5+
AND member[$dependencies_projection_write_property] IS NOT NULL
6+
WITH toInteger(toFloat(count(DISTINCT member)) * 0.02) AS memberCount2Percent
7+
,collect(DISTINCT member) AS members
8+
UNWIND members AS member
9+
WITH memberCount2Percent, member
10+
ORDER BY member[$dependencies_projection_write_property] DESCENDING
11+
WITH memberCount2Percent
12+
,collect(DISTINCT member)[0..memberCount2Percent] AS topMembers
13+
,'Top' + apoc.text.capitalize($dependencies_projection_write_property) AS labelName
14+
UNWIND topMembers AS topMember
15+
CALL apoc.create.addLabels(topMember, [labelName]) YIELD node
16+
RETURN count(node) AS nodesCount

cypher/Centrality/Centrality_2a_Page_Rank_Estimate_Memory.cypher renamed to cypher/Centrality/Centrality_2a_Page_Rank_Estimate.cypher

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//Centrality 2a Page Rank Estimate Memory
22

3-
CALL gds.pageRank.write.estimate('package-centrality-without-empty', {
4-
writeProperty: 'pageRank'
3+
CALL gds.pageRank.write.estimate(
4+
$dependencies_projection + '-without-empty', {
5+
writeProperty: $dependencies_projection_write_property
56
,maxIterations: 50
67
,dampingFactor: 0.85
78
,tolerance: 0.00000001
8-
,relationshipWeightProperty: 'weight25PercentInterfaces'
9+
,relationshipWeightProperty: $dependencies_projection_weight_property
910
,scaler: "L1Norm"
1011
})
1112
YIELD nodeCount, relationshipCount, bytesMin, bytesMax, heapPercentageMin, heapPercentageMax, treeView

cypher/Centrality/Centrality_2b_Page_Rank_Statistics.cypher

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//Centrality 2b Page Rank Statistics
22

3-
CALL gds.pageRank.stats('package-centrality-without-empty', {
3+
CALL gds.pageRank.stats(
4+
$dependencies_projection + '-without-empty', {
45
maxIterations: 50
56
,dampingFactor: 0.85
67
,tolerance: 0.00000001
7-
,relationshipWeightProperty: 'weight25PercentInterfaces'
8+
,relationshipWeightProperty: $dependencies_projection_weight_property
89
,scaler: "L1Norm"
910
})
1011
YIELD ranIterations

0 commit comments

Comments
 (0)