1919import neo4j
2020from neo4j .exceptions import ClientError
2121
22+ BASE_KG_BUILDER_LABEL = "__KGBuilder__"
2223BASE_ENTITY_LABEL = "__Entity__"
2324EXCLUDED_LABELS = ["_Bloom_Perspective_" , "_Bloom_Scene_" ]
2425EXCLUDED_RELS = ["_Bloom_HAS_SCENE_" ]
@@ -82,13 +83,23 @@ def get_schema(
8283 driver : neo4j .Driver ,
8384) -> str :
8485 """
85- Returns the schema of the graph.
86+ Returns the schema of the graph as a string with following format:
87+
88+ .. code-block:: text
89+
90+ Node properties:
91+ Person {id: INTEGER, name: STRING}
92+ Relationship properties:
93+ KNOWS {fromDate: DATE}
94+ The relationships:
95+ (:Person)-[:KNOWS]->(:Person)
8696
8797 Args:
8898 driver (neo4j.Driver): Neo4j Python driver instance.
8999
90100 Returns:
91101 str: the graph schema information in a serialized format.
102+
92103 """
93104 structured_schema = get_structured_schema (driver )
94105
@@ -129,6 +140,40 @@ def get_structured_schema(driver: neo4j.Driver) -> dict[str, Any]:
129140 """
130141 Returns the structured schema of the graph.
131142
143+ Returns a dict with following format:
144+
145+ .. code:: python
146+
147+ {
148+ 'node_props': {
149+ 'Person': [{'property': 'id', 'type': 'INTEGER'}, {'property': 'name', 'type': 'STRING'}]
150+ },
151+ 'rel_props': {
152+ 'KNOWS': [{'property': 'fromDate', 'type': 'DATE'}]
153+ },
154+ 'relationships': [
155+ {'start': 'Person', 'type': 'KNOWS', 'end': 'Person'}
156+ ],
157+ 'metadata': {
158+ 'constraint': [
159+ {'id': 7, 'name': 'person_id', 'type': 'UNIQUENESS', 'entityType': 'NODE', 'labelsOrTypes': ['Persno'], 'properties': ['id'], 'ownedIndex': 'person_id', 'propertyType': None},
160+ ],
161+ 'index': [
162+ {'label': 'Person', 'properties': ['name'], 'size': 2, 'type': 'RANGE', 'valuesSelectivity': 1.0, 'distinctValues': 2.0},
163+ ]
164+ }
165+ }
166+
167+ Note:
168+ The internal structure of the returned dict depends on the apoc.meta.data
169+ and apoc.schema.nodes procedures.
170+
171+ Warning:
172+ Some labels are excluded from the output schema:
173+
174+ - The `__Entity__` and `__KGBuilder__` node labels which are created by the KG Builder pipeline within this package
175+ - Some labels related to Bloom internals.
176+
132177 Args:
133178 driver (neo4j.Driver): Neo4j Python driver instance.
134179
@@ -140,7 +185,10 @@ def get_structured_schema(driver: neo4j.Driver) -> dict[str, Any]:
140185 for data in query_database (
141186 driver ,
142187 NODE_PROPERTIES_QUERY ,
143- params = {"EXCLUDED_LABELS" : EXCLUDED_LABELS + [BASE_ENTITY_LABEL ]},
188+ params = {
189+ "EXCLUDED_LABELS" : EXCLUDED_LABELS
190+ + [BASE_ENTITY_LABEL , BASE_KG_BUILDER_LABEL ]
191+ },
144192 )
145193 ]
146194
@@ -156,7 +204,10 @@ def get_structured_schema(driver: neo4j.Driver) -> dict[str, Any]:
156204 for data in query_database (
157205 driver ,
158206 REL_QUERY ,
159- params = {"EXCLUDED_LABELS" : EXCLUDED_LABELS + [BASE_ENTITY_LABEL ]},
207+ params = {
208+ "EXCLUDED_LABELS" : EXCLUDED_LABELS
209+ + [BASE_ENTITY_LABEL , BASE_KG_BUILDER_LABEL ]
210+ },
160211 )
161212 ]
162213
0 commit comments