|
50 | 50 | "metadata": {}, |
51 | 51 | "outputs": [], |
52 | 52 | "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", |
67 | 64 | " 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", |
69 | 67 | " 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", |
81 | 72 | " \"\"\"\n", |
82 | 73 | " Executes the Cypher queries of the given files and returns the first result that is not empty.\n", |
83 | 74 | " If all given file names result in empty results, the last (empty) result will be returned.\n", |
|
639 | 630 | "name": "python", |
640 | 631 | "nbconvert_exporter": "python", |
641 | 632 | "pygments_lexer": "ipython3", |
642 | | - "version": "3.11.9" |
| 633 | + "version": "3.12.9" |
643 | 634 | }, |
644 | 635 | "title": "Object Oriented Design Quality Metrics for Java with Neo4j" |
645 | 636 | }, |
|
0 commit comments