Skip to content

Commit bb4c931

Browse files
committed
Improve neo4j database query functions
1 parent ac6a79f commit bb4c931

17 files changed

+187
-315
lines changed

jupyter/ExternalDependenciesJava.ipynb

+6-13
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,16 @@
4444
},
4545
{
4646
"cell_type": "code",
47-
"execution_count": 235,
47+
"execution_count": null,
4848
"id": "c1db254b",
4949
"metadata": {},
5050
"outputs": [],
5151
"source": [
5252
"def get_cypher_query_from_file(filename):\n",
5353
" with open(filename) as file:\n",
54-
" return ' '.join(file.readlines())"
55-
]
56-
},
57-
{
58-
"cell_type": "code",
59-
"execution_count": 236,
60-
"id": "59310f6f",
61-
"metadata": {},
62-
"outputs": [],
63-
"source": [
54+
" return ' '.join(file.readlines())\n",
55+
"\n",
56+
"\n",
6457
"def query_cypher_to_data_frame(filename):\n",
6558
" records, summary, keys = driver.execute_query(get_cypher_query_from_file(filename))\n",
6659
" return pd.DataFrame([r.values() for r in records], columns=keys)"
@@ -1735,7 +1728,7 @@
17351728
"celltoolbar": "Tags",
17361729
"code_graph_analysis_pipeline_data_validation": "ValidateJavaExternalDependencies",
17371730
"kernelspec": {
1738-
"display_name": "Python 3 (ipykernel)",
1731+
"display_name": "codegraph",
17391732
"language": "python",
17401733
"name": "python3"
17411734
},
@@ -1749,7 +1742,7 @@
17491742
"name": "python",
17501743
"nbconvert_exporter": "python",
17511744
"pygments_lexer": "ipython3",
1752-
"version": "3.11.9"
1745+
"version": "3.12.9"
17531746
},
17541747
"title": "External Dependencies for Java"
17551748
},

jupyter/ExternalDependenciesTypescript.ipynb

+5-12
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,9 @@
5151
"source": [
5252
"def get_cypher_query_from_file(filename):\n",
5353
" with open(filename) as file:\n",
54-
" return ' '.join(file.readlines())"
55-
]
56-
},
57-
{
58-
"cell_type": "code",
59-
"execution_count": null,
60-
"id": "59310f6f",
61-
"metadata": {},
62-
"outputs": [],
63-
"source": [
54+
" return ' '.join(file.readlines())\n",
55+
"\n",
56+
"\n",
6457
"def query_cypher_to_data_frame(filename):\n",
6558
" records, summary, keys = driver.execute_query(get_cypher_query_from_file(filename))\n",
6659
" return pd.DataFrame([r.values() for r in records], columns=keys)"
@@ -1638,7 +1631,7 @@
16381631
"celltoolbar": "Tags",
16391632
"code_graph_analysis_pipeline_data_validation": "ValidateTypescriptModuleDependencies",
16401633
"kernelspec": {
1641-
"display_name": "Python 3 (ipykernel)",
1634+
"display_name": "codegraph",
16421635
"language": "python",
16431636
"name": "python3"
16441637
},
@@ -1652,7 +1645,7 @@
16521645
"name": "python",
16531646
"nbconvert_exporter": "python",
16541647
"pygments_lexer": "ipython3",
1655-
"version": "3.11.9"
1648+
"version": "3.12.9"
16561649
},
16571650
"title": "External Dependencies for Typescript"
16581651
},

jupyter/InternalDependenciesJava.ipynb

+18-27
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,25 @@
5050
"metadata": {},
5151
"outputs": [],
5252
"source": [
53-
"def get_cypher_query_from_file(cypherFileName):\n",
54-
" with open(cypherFileName) as file:\n",
55-
" return ' '.join(file.readlines())"
56-
]
57-
},
58-
{
59-
"cell_type": "code",
60-
"execution_count": null,
61-
"id": "59310f6f",
62-
"metadata": {},
63-
"outputs": [],
64-
"source": [
65-
"def query_cypher_to_data_frame(filename : str, limit: int = 10_000):\n",
66-
" cypher_query_template = \"{query}\\nLIMIT {row_limit}\"\n",
53+
"def get_cypher_query_from_file(cypher_file_name : str):\n",
54+
" with open(cypher_file_name) as file:\n",
55+
" return ' '.join(file.readlines())\n",
56+
"\n",
57+
"\n",
58+
"def query_cypher_to_data_frame(filename : str, limit: int = -1):\n",
59+
" \"\"\"\n",
60+
" Execute the Cypher query of the given file and returns the result.\n",
61+
" filename : str : The name of the file containing the Cypher query\n",
62+
" limit : int : The optional limit of rows to optimize the query. Default = -1 = no limit\n",
63+
" \"\"\"\n",
6764
" cypher_query = get_cypher_query_from_file(filename)\n",
68-
" cypher_query = cypher_query_template.format(query = cypher_query, row_limit = limit)\n",
65+
" if limit > 0:\n",
66+
" cypher_query = \"{query}\\nLIMIT {row_limit}\".format(query = cypher_query, row_limit = limit)\n",
6967
" records, summary, keys = driver.execute_query(cypher_query)\n",
70-
" return pd.DataFrame([r.values() for r in records], columns=keys)"
71-
]
72-
},
73-
{
74-
"cell_type": "code",
75-
"execution_count": null,
76-
"id": "c09da482",
77-
"metadata": {},
78-
"outputs": [],
79-
"source": [
80-
"def query_first_non_empty_cypher_to_data_frame(*filenames : str, limit: int = 10_000):\n",
68+
" return pd.DataFrame([r.values() for r in records], columns=keys)\n",
69+
"\n",
70+
"\n",
71+
"def query_first_non_empty_cypher_to_data_frame(*filenames : str, limit: int = -1):\n",
8172
" \"\"\"\n",
8273
" Executes the Cypher queries of the given files and returns the first result that is not empty.\n",
8374
" If all given file names result in empty results, the last (empty) result will be returned.\n",
@@ -639,7 +630,7 @@
639630
"name": "python",
640631
"nbconvert_exporter": "python",
641632
"pygments_lexer": "ipython3",
642-
"version": "3.11.9"
633+
"version": "3.12.9"
643634
},
644635
"title": "Object Oriented Design Quality Metrics for Java with Neo4j"
645636
},

jupyter/InternalDependenciesTypescript.ipynb

+18-27
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,25 @@
5050
"metadata": {},
5151
"outputs": [],
5252
"source": [
53-
"def get_cypher_query_from_file(cypherFileName):\n",
54-
" with open(cypherFileName) as file:\n",
55-
" return ' '.join(file.readlines())"
56-
]
57-
},
58-
{
59-
"cell_type": "code",
60-
"execution_count": null,
61-
"id": "59310f6f",
62-
"metadata": {},
63-
"outputs": [],
64-
"source": [
65-
"def query_cypher_to_data_frame(filename : str, limit: int = 10_000):\n",
66-
" cypher_query_template = \"{query}\\nLIMIT {row_limit}\"\n",
53+
"def get_cypher_query_from_file(cypher_file_name : str):\n",
54+
" with open(cypher_file_name) as file:\n",
55+
" return ' '.join(file.readlines())\n",
56+
"\n",
57+
"\n",
58+
"def query_cypher_to_data_frame(filename : str, limit: int = -1):\n",
59+
" \"\"\"\n",
60+
" Execute the Cypher query of the given file and returns the result.\n",
61+
" filename : str : The name of the file containing the Cypher query\n",
62+
" limit : int : The optional limit of rows to optimize the query. Default = -1 = no limit\n",
63+
" \"\"\"\n",
6764
" cypher_query = get_cypher_query_from_file(filename)\n",
68-
" cypher_query = cypher_query_template.format(query = cypher_query, row_limit = limit)\n",
65+
" if limit > 0:\n",
66+
" cypher_query = \"{query}\\nLIMIT {row_limit}\".format(query = cypher_query, row_limit = limit)\n",
6967
" records, summary, keys = driver.execute_query(cypher_query)\n",
70-
" return pd.DataFrame([r.values() for r in records], columns=keys)"
71-
]
72-
},
73-
{
74-
"cell_type": "code",
75-
"execution_count": null,
76-
"id": "bb3646d7",
77-
"metadata": {},
78-
"outputs": [],
79-
"source": [
80-
"def query_first_non_empty_cypher_to_data_frame(*filenames : str, limit: int = 10_000):\n",
68+
" return pd.DataFrame([r.values() for r in records], columns=keys)\n",
69+
"\n",
70+
"\n",
71+
"def query_first_non_empty_cypher_to_data_frame(*filenames : str, limit: int = -1):\n",
8172
" \"\"\"\n",
8273
" Executes the Cypher queries of the given files and returns the first result that is not empty.\n",
8374
" If all given file names result in empty results, the last (empty) result will be returned.\n",
@@ -481,7 +472,7 @@
481472
"name": "python",
482473
"nbconvert_exporter": "python",
483474
"pygments_lexer": "ipython3",
484-
"version": "3.11.9"
475+
"version": "3.12.9"
485476
},
486477
"title": "Object Oriented Design Quality Metrics for Java with Neo4j"
487478
},

jupyter/MethodMetricsJava.ipynb

+5-12
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,9 @@
5151
"source": [
5252
"def get_cypher_query_from_file(filename):\n",
5353
" with open(filename) as file:\n",
54-
" return ' '.join(file.readlines())"
55-
]
56-
},
57-
{
58-
"cell_type": "code",
59-
"execution_count": null,
60-
"id": "59310f6f",
61-
"metadata": {},
62-
"outputs": [],
63-
"source": [
54+
" return ' '.join(file.readlines())\n",
55+
" \n",
56+
"\n",
6457
"def query_cypher_to_data_frame(filename):\n",
6558
" records, summary, keys = driver.execute_query(get_cypher_query_from_file(filename))\n",
6659
" return pd.DataFrame([r.values() for r in records], columns=keys)"
@@ -467,7 +460,7 @@
467460
],
468461
"code_graph_analysis_pipeline_data_validation": "ValidateJavaMethods",
469462
"kernelspec": {
470-
"display_name": "Python 3 (ipykernel)",
463+
"display_name": "codegraph",
471464
"language": "python",
472465
"name": "python3"
473466
},
@@ -481,7 +474,7 @@
481474
"name": "python",
482475
"nbconvert_exporter": "python",
483476
"pygments_lexer": "ipython3",
484-
"version": "3.11.4"
477+
"version": "3.12.9"
485478
},
486479
"title": "Object Oriented Design Quality Metrics for Java with Neo4j"
487480
},

jupyter/NodeEmbeddingsJava.ipynb

+8-22
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,14 @@
9898
"source": [
9999
"def get_cypher_query_from_file(filename):\n",
100100
" with open(filename) as file:\n",
101-
" return ' '.join(file.readlines())"
102-
]
103-
},
104-
{
105-
"cell_type": "code",
106-
"execution_count": null,
107-
"id": "59310f6f",
108-
"metadata": {},
109-
"outputs": [],
110-
"source": [
101+
" return ' '.join(file.readlines())\n",
102+
" \n",
103+
"\n",
111104
"def query_cypher_to_data_frame(filename, parameters_: typ.Optional[typ.Dict[str, typ.Any]] = None):\n",
112105
" records, summary, keys = driver.execute_query(get_cypher_query_from_file(filename),parameters_=parameters_)\n",
113-
" return pd.DataFrame([r.values() for r in records], columns=keys)"
114-
]
115-
},
116-
{
117-
"cell_type": "code",
118-
"execution_count": null,
119-
"id": "bd1d9775",
120-
"metadata": {},
121-
"outputs": [],
122-
"source": [
106+
" return pd.DataFrame([r.values() for r in records], columns=keys)\n",
107+
"\n",
108+
"\n",
123109
"def query_first_non_empty_cypher_to_data_frame(*filenames : str, parameters: typ.Optional[typ.Dict[str, typ.Any]] = None):\n",
124110
" \"\"\"\n",
125111
" Executes the Cypher queries of the given files and returns the first result that is not empty.\n",
@@ -492,7 +478,7 @@
492478
],
493479
"code_graph_analysis_pipeline_data_validation": "ValidateJavaPackageDependencies",
494480
"kernelspec": {
495-
"display_name": "Python 3 (ipykernel)",
481+
"display_name": "codegraph",
496482
"language": "python",
497483
"name": "python3"
498484
},
@@ -506,7 +492,7 @@
506492
"name": "python",
507493
"nbconvert_exporter": "python",
508494
"pygments_lexer": "ipython3",
509-
"version": "3.11.9"
495+
"version": "3.12.9"
510496
},
511497
"title": "Object Oriented Design Quality Metrics for Java with Neo4j"
512498
},

jupyter/NodeEmbeddingsTypescript.ipynb

+8-22
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,14 @@
9898
"source": [
9999
"def get_cypher_query_from_file(filename):\n",
100100
" with open(filename) as file:\n",
101-
" return ' '.join(file.readlines())"
102-
]
103-
},
104-
{
105-
"cell_type": "code",
106-
"execution_count": null,
107-
"id": "59310f6f",
108-
"metadata": {},
109-
"outputs": [],
110-
"source": [
101+
" return ' '.join(file.readlines())\n",
102+
" \n",
103+
"\n",
111104
"def query_cypher_to_data_frame(filename, parameters_: typ.Optional[typ.Dict[str, typ.Any]] = None):\n",
112105
" records, summary, keys = driver.execute_query(get_cypher_query_from_file(filename),parameters_=parameters_)\n",
113-
" return pd.DataFrame([r.values() for r in records], columns=keys)"
114-
]
115-
},
116-
{
117-
"cell_type": "code",
118-
"execution_count": null,
119-
"id": "bd1d9775",
120-
"metadata": {},
121-
"outputs": [],
122-
"source": [
106+
" return pd.DataFrame([r.values() for r in records], columns=keys)\n",
107+
"\n",
108+
"\n",
123109
"def query_first_non_empty_cypher_to_data_frame(*filenames : str, parameters: typ.Optional[typ.Dict[str, typ.Any]] = None):\n",
124110
" \"\"\"\n",
125111
" Executes the Cypher queries of the given files and returns the first result that is not empty.\n",
@@ -495,7 +481,7 @@
495481
],
496482
"code_graph_analysis_pipeline_data_validation": "ValidateTypescriptModuleDependencies",
497483
"kernelspec": {
498-
"display_name": "Python 3 (ipykernel)",
484+
"display_name": "codegraph",
499485
"language": "python",
500486
"name": "python3"
501487
},
@@ -509,7 +495,7 @@
509495
"name": "python",
510496
"nbconvert_exporter": "python",
511497
"pygments_lexer": "ipython3",
512-
"version": "3.11.9"
498+
"version": "3.12.9"
513499
},
514500
"title": "Object Oriented Design Quality Metrics for Java with Neo4j"
515501
},

0 commit comments

Comments
 (0)