Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

Fix export_yaml schema export bug and update docs

KaifAhmad13207eb3b4116
diff --git a/docs/reference/export.md b/docs/reference/export.md
index 2e2d0ab7..38648080 100644
--- a/docs/reference/export.md
+++ b/docs/reference/export.md
@@ -394,7 +394,7 @@ Export ontology schemas to YAML format.
| Method | Description | Algorithm |
|--------|-------------|-----------|
-| `export(schema, filename)` | Export schema | YAML schema serialization |
+| `export_ontology_schema(ontology, filename)` | Export ontology schema | YAML schema serialization |
**Example:**
@@ -402,7 +402,7 @@ Export ontology schemas to YAML format.
from semantica.export import YAMLSchemaExporter
exporter = YAMLSchemaExporter()
-exporter.export(schema, "schema.yaml")
+exporter.export_ontology_schema(schema, "schema.yaml")
```
---
diff --git a/semantica/export/export_usage.md b/semantica/export/export_usage.md
index 736ceb7c..c6001823 100644
--- a/semantica/export/export_usage.md
+++ b/semantica/export/export_usage.md
@@ -280,7 +280,7 @@ from semantica.export import YAMLSchemaExporter
exporter = YAMLSchemaExporter()
# Export schema
-exporter.export(schema, "schema.yaml")
+exporter.export_ontology_schema(schema, "schema.yaml")
```
### Using YAML Export Methods
diff --git a/semantica/export/methods.py b/semantica/export/methods.py
index 5dd52674..62126b14 100644
--- a/semantica/export/methods.py
+++ b/semantica/export/methods.py
@@ -201,7 +201,7 @@ def export_rdf(
"""
# Check for custom method in registry
custom_method = method_registry.get("rdf", method)
- if custom_method:
+ if custom_method and custom_method is not export_rdf:
try:
return custom_method(data, file_path, format=format, **kwargs)
except Exception as e:
@@ -250,7 +250,7 @@ def export_json(
"""
# Check for custom method in registry
custom_method = method_registry.get("json", method)
- if custom_method:
+ if custom_method and custom_method is not export_json:
try:
return custom_method(data, file_path, format=format, **kwargs)
except Exception as e:
@@ -296,7 +296,7 @@ def export_csv(
"""
# Check for custom method in registry
custom_method = method_registry.get("csv", method)
- if custom_method:
+ if custom_method and custom_method is not export_csv:
try:
return custom_method(data, file_path, **kwargs)
except Exception as e:
@@ -347,7 +347,7 @@ def export_graph(
"""
# Check for custom method in registry
custom_method = method_registry.get("graph", method)
- if custom_method:
+ if custom_method and custom_method is not export_graph:
try:
return custom_method(graph_data, file_path, format=format, **kwargs)
except Exception as e:
@@ -395,7 +395,7 @@ def export_yaml(
"""
# Check for custom method in registry
custom_method = method_registry.get("yaml", method)
- if custom_method:
+ if custom_method and custom_method is not export_yaml:
try:
return custom_method(data, file_path, **kwargs)
except Exception as e:
@@ -413,7 +413,9 @@ def export_yaml(
exporter.export(data, file_path, **kwargs)
elif method == "schema":
exporter = YAMLSchemaExporter(**config)
- exporter.export(data, file_path, **kwargs)
+ yaml_content = exporter.export_ontology_schema(data, **kwargs)
+ with open(file_path, "w", encoding="utf-8") as f:
+ f.write(yaml_content)
else:
raise ProcessingError(f"Unknown YAML export method: {method}")
@@ -450,7 +452,7 @@ def export_owl(
"""
# Check for custom method in registry
custom_method = method_registry.get("owl", method)
- if custom_method:
+ if custom_method and custom_method is not export_owl:
try:
return custom_method(ontology, file_path, format=format, **kwargs)
except Exception as e:
@@ -502,7 +504,7 @@ def export_vector(
"""
# Check for custom method in registry
custom_method = method_registry.get("vector", method)
- if custom_method:
+ if custom_method and custom_method is not export_vector:
try:
return custom_method(vectors, file_path, format=format, **kwargs)
except Exception as e:
@@ -550,7 +552,7 @@ def export_lpg(
"""
# Check for custom method in registry
custom_method = method_registry.get("lpg", method)
- if custom_method:
+ if custom_method and custom_method is not export_lpg:
try:
return custom_method(knowledge_graph, file_path, **kwargs)
except Exception as e:
@@ -601,7 +603,7 @@ def generate_report(
"""
# Check for custom method in registry
custom_method = method_registry.get("report", method)
- if custom_method:
+ if custom_method and custom_method is not generate_report:
try:
return custom_method(data, file_path, format=format, **kwargs)
except Exception as e:
diff --git a/tests/test_export_methods_wrapper.py b/tests/test_export_methods_wrapper.py
new file mode 100644
index 00000000..240d2329
--- /dev/null
+++ b/tests/test_export_methods_wrapper.py
@@ -0,0 +1,37 @@
+import sys
+import os
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
+
+import unittest
+import tempfile
+import shutil
+import yaml
+from pathlib import Path
+from semantica.export.methods import export_yaml
+
+class TestExportMethodsWrapper(unittest.TestCase):
+ def setUp(self):
+ self.test_dir = tempfile.mkdtemp()
+ self.schema = {
+ "uri": "http://example.org/schema",
+ "classes": [{"id": "Person", "label": "Person"}],
+ "properties": [{"id": "knows", "label": "Knows"}]
+ }
+
+ def tearDown(self):
+ shutil.rmtree(self.test_dir)
+
+ def test_export_yaml_schema(self):
+ output_path = Path(self.test_dir) / "schema.yaml"
+
+ # This should call export_ontology_schema internally
+ export_yaml(self.schema, str(output_path), method="schema")
+
+ self.assertTrue(output_path.exists())
+ with open(output_path, 'r') as f:
+ data = yaml.safe_load(f)
+ self.assertEqual(data['ontology']['uri'], "http://example.org/schema")
+ self.assertEqual(len(data['classes']), 1)
+
+if __name__ == '__main__':
+ unittest.main()