fix(kg): resolve 'unhashable type: Entity' in GraphAnalyzer #159

- Robust ID extraction in CentralityCalculator, CommunityDetector, and ConnectivityAnalyzer
- Support for direct Entity objects and dictionaries as node identifiers
- Improved Entity hashability in utils/types.py
- Added integration test to verify fix and prevent regression
This commit is contained in:
KaifAhmad1
2026-01-08 17:23:31 +05:30
parent 9b18bc3da3
commit 58707ff721
89 changed files with 11322 additions and 10 deletions
+37
View File
@@ -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()