64
64
YAML_FILE_PATH = os .path .join (OUTPUT_DIR , "extracted_schema.yaml" )
65
65
66
66
67
- async def extract_and_save_schema () -> SchemaConfig :
67
+ async def extract_and_save_schema () -> None :
68
68
"""Extract schema from text and save it to JSON and YAML files."""
69
69
70
70
# Define LLM parameters
@@ -110,8 +110,6 @@ async def extract_and_save_schema() -> SchemaConfig:
110
110
for entity1 , relation , entity2 in inferred_schema .potential_schema :
111
111
print (f" { entity1 } --[{ relation } ]--> { entity2 } " )
112
112
113
- return inferred_schema
114
-
115
113
finally :
116
114
# Close the LLM client
117
115
await llm .async_client .close ()
@@ -120,17 +118,20 @@ async def extract_and_save_schema() -> SchemaConfig:
120
118
async def main () -> None :
121
119
"""Run the example."""
122
120
123
- # Extract schema and save to files
124
- schema_config = await extract_and_save_schema ()
121
+ # extract schema and save to files
122
+ await extract_and_save_schema ()
125
123
126
- print (f "\n Schema files have been saved to:" )
124
+ print ("\n Schema files have been saved to:" )
127
125
print (f" - JSON: { JSON_FILE_PATH } " )
128
126
print (f" - YAML: { YAML_FILE_PATH } " )
129
127
130
- print ("\n Example of how to load the schema from files:" )
131
- print (" from neo4j_graphrag.experimental.components.schema import SchemaConfig" )
132
- print (f" schema_from_json = SchemaConfig.from_file('{ JSON_FILE_PATH } ')" )
133
- print (f" schema_from_yaml = SchemaConfig.from_file('{ YAML_FILE_PATH } ')" )
128
+ # load schema from files
129
+ print ("\n Loading schemas from saved files:" )
130
+ schema_from_json = SchemaConfig .from_file (JSON_FILE_PATH )
131
+ schema_from_yaml = SchemaConfig .from_file (YAML_FILE_PATH )
132
+
133
+ print (f"Entities in JSON schema: { list (schema_from_json .entities .keys ())} " )
134
+ print (f"Entities in YAML schema: { list (schema_from_yaml .entities .keys ())} " )
134
135
135
136
136
137
if __name__ == "__main__" :
0 commit comments