Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
leila-messallem committed May 20, 2024
1 parent be47247 commit 8fe6c5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions src/neo4j_genai/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
"""


def _query(driver: neo4j.Driver, query: str, params: dict = {}) -> list[dict[str, Any]]:
def _query_database(
driver: neo4j.Driver, query: str, params: dict = {}
) -> list[dict[str, Any]]:
"""
Queries the database.
Expand Down Expand Up @@ -79,23 +81,23 @@ def get_schema(
str: the graph schema information in a serialized format.
"""
node_properties = [
el["output"]
for el in _query(
data["output"]
for data in _query_database(
driver,
NODE_PROPERTIES_QUERY,
params={"EXCLUDED_LABELS": EXCLUDED_LABELS + [BASE_ENTITY_LABEL]},
)
]

rel_properties = [
el["output"]
for el in _query(
data["output"]
for data in _query_database(
driver, REL_PROPERTIES_QUERY, params={"EXCLUDED_LABELS": EXCLUDED_RELS}
)
]
relationships = [
el["output"]
for el in _query(
data["output"]
for data in _query_database(
driver,
REL_QUERY,
params={"EXCLUDED_LABELS": EXCLUDED_LABELS + [BASE_ENTITY_LABEL]},
Expand All @@ -104,23 +106,24 @@ def get_schema(

# Format node properties
formatted_node_props = []
for el in node_properties:
for element in node_properties:
props_str = ", ".join(
[f"{prop['property']}: {prop['type']}" for prop in el["properties"]]
[f"{prop['property']}: {prop['type']}" for prop in element["properties"]]
)
formatted_node_props.append(f"{el['labels']} {{{props_str}}}")
formatted_node_props.append(f"{element['labels']} {{{props_str}}}")

# Format relationship properties
formatted_rel_props = []
for el in rel_properties:
for element in rel_properties:
props_str = ", ".join(
[f"{prop['property']}: {prop['type']}" for prop in el["properties"]]
[f"{prop['property']}: {prop['type']}" for prop in element["properties"]]
)
formatted_rel_props.append(f"{el['type']} {{{props_str}}}")
formatted_rel_props.append(f"{element['type']} {{{props_str}}}")

# Format relationships
formatted_rels = [
f"(:{el['start']})-[:{el['type']}]->(:{el['end']})" for el in relationships
f"(:{element['start']})-[:{element['type']}]->(:{element['end']})"
for element in relationships
]

return "\n".join(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_get_schema_happy_path(driver):
)


@patch("neo4j_genai.schema._query", side_effect=_query_return_value)
@patch("neo4j_genai.schema._query_database", side_effect=_query_return_value)
def test_get_schema_ensure_formatted_response(driver):
result = get_schema(driver)
assert (
Expand Down

0 comments on commit 8fe6c5e

Please sign in to comment.