Skip to content

Commit 78633c6

Browse files
Improve schema from text example
1 parent 8885e2c commit 78633c6

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

examples/automatic_schema_extraction/schema_from_text.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
YAML_FILE_PATH = os.path.join(OUTPUT_DIR, "extracted_schema.yaml")
6565

6666

67-
async def extract_and_save_schema() -> SchemaConfig:
67+
async def extract_and_save_schema() -> None:
6868
"""Extract schema from text and save it to JSON and YAML files."""
6969

7070
# Define LLM parameters
@@ -110,8 +110,6 @@ async def extract_and_save_schema() -> SchemaConfig:
110110
for entity1, relation, entity2 in inferred_schema.potential_schema:
111111
print(f" {entity1} --[{relation}]--> {entity2}")
112112

113-
return inferred_schema
114-
115113
finally:
116114
# Close the LLM client
117115
await llm.async_client.close()
@@ -120,17 +118,20 @@ async def extract_and_save_schema() -> SchemaConfig:
120118
async def main() -> None:
121119
"""Run the example."""
122120

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()
125123

126-
print(f"\nSchema files have been saved to:")
124+
print("\nSchema files have been saved to:")
127125
print(f" - JSON: {JSON_FILE_PATH}")
128126
print(f" - YAML: {YAML_FILE_PATH}")
129127

130-
print("\nExample 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("\nLoading 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())}")
134135

135136

136137
if __name__ == "__main__":

0 commit comments

Comments
 (0)