@@ -960,6 +960,86 @@ async def test_schema_from_text_filters_relationships_without_labels(
960960 assert ("Person" , "MANAGES" , "Organization" ) in schema .patterns
961961
962962
963+ @pytest .fixture
964+ def valid_schema_json_with_markdown () -> str :
965+ return """```json
966+ {
967+ "node_types": [
968+ {
969+ "label": "Person",
970+ "properties": [
971+ {"name": "name", "type": "STRING"}
972+ ]
973+ },
974+ {
975+ "label": "Organization",
976+ "properties": [
977+ {"name": "name", "type": "STRING"}
978+ ]
979+ }
980+ ],
981+ "relationship_types": [
982+ {
983+ "label": "WORKS_FOR",
984+ "properties": [
985+ {"name": "since", "type": "DATE"}
986+ ]
987+ }
988+ ],
989+ "patterns": [
990+ ["Person", "WORKS_FOR", "Organization"]
991+ ]
992+ }
993+ ```"""
994+
995+
996+ @pytest .fixture
997+ def valid_schema_json_with_markdown_no_language () -> str :
998+ return """```
999+ {
1000+ "node_types": [
1001+ {
1002+ "label": "Person",
1003+ "properties": [
1004+ {"name": "name", "type": "STRING"}
1005+ ]
1006+ }
1007+ ]
1008+ }
1009+ ```"""
1010+
1011+
1012+ def test_clean_json_content_markdown_with_json_language (
1013+ schema_from_text : SchemaFromTextExtractor ,
1014+ ) -> None :
1015+ content = """```json
1016+ {"node_types": [{"label": "Person"}]}
1017+ ```"""
1018+
1019+ cleaned = schema_from_text ._clean_json_content (content )
1020+ assert cleaned == '{"node_types": [{"label": "Person"}]}'
1021+
1022+
1023+ def test_clean_json_content_markdown_without_language (
1024+ schema_from_text : SchemaFromTextExtractor ,
1025+ ) -> None :
1026+ content = """```
1027+ {"node_types": [{"label": "Person"}]}
1028+ ```"""
1029+
1030+ cleaned = schema_from_text ._clean_json_content (content )
1031+ assert cleaned == '{"node_types": [{"label": "Person"}]}'
1032+
1033+
1034+ def test_clean_json_content_plain_json (
1035+ schema_from_text : SchemaFromTextExtractor ,
1036+ ) -> None :
1037+ content = '{"node_types": [{"label": "Person"}]}'
1038+
1039+ cleaned = schema_from_text ._clean_json_content (content )
1040+ assert cleaned == '{"node_types": [{"label": "Person"}]}'
1041+
1042+
9631043@pytest .mark .asyncio
9641044@patch ("neo4j_graphrag.experimental.components.schema.get_structured_schema" )
9651045async def test_schema_from_existing_graph (mock_get_structured_schema : Mock ) -> None :
0 commit comments