OntologyEngine is your main entry point for the complete ontology workflow:
from semantica.ontology import OntologyEngine# Initialize with base URI for your domainengine = OntologyEngine(base_uri="https://example.org/ontology/")# Generate ontology from your knowledge graph dataontology = engine.from_data({"entities": entities, "relationships": relationships})# Validate a graph against the generated SHACL shapesreport = engine.validate_graph(kg, ontology=ontology)if not report.conforms: for v in report.violations: print(f"{v.severity}: {v.message} on {v.focus_node}")# Export to OWL Turtleengine.export_owl(ontology, "ontology.ttl", format="turtle")
OntologyEngine orchestrates the full ontology lifecycle: generation, validation, export, and evaluation:
from semantica.ontology import OntologyEngineengine = OntologyEngine(base_uri="https://example.org/ontology/")# Generate ontology from KG dataontology = engine.from_data({"entities": entities, "relationships": relationships})# Validate a graph against the generated SHACL shapesreport = engine.validate_graph(kg, ontology=ontology)if not report.conforms: for v in report.violations: print(f"{v.severity}: {v.message} on {v.focus_node}")# Export to OWL Turtleengine.export_owl(ontology, "ontology.ttl", format="turtle")
from semantica.ontology import OntologyEngine# 1. Initialize engineengine = OntologyEngine(base_uri="https://yourcompany.com/ontology/")# 2. Generate from your dataontology = engine.from_data({"entities": entities, "relationships": relationships})# 3. Validate against a knowledge graphreport = engine.validate_graph(kg, ontology=ontology)if report.conforms: print("✓ Graph conforms to ontology")else: print(f"✗ Found {len(report.violations)} violations")
Generate ontologies from text descriptions:
from semantica.ontology import LLMOntologyGeneratorgenerator = LLMOntologyGenerator(provider="openai")ontology = generator.generate_ontology_from_text(""" Create an e-commerce ontology with products, customers, orders, categories, reviews, and payment methods.""")# Refine with additional constraintsengine = OntologyEngine()validated = engine.validate(ontology)
Export ontologies in multiple formats:
from semantica.ontology import OntologyEngineengine = OntologyEngine()# Export as OWL/Turtle for Protégéengine.export_owl(ontology, "schema.ttl", format="turtle")# Export as JSON-LD for web applicationsengine.export_owl(ontology, "schema.jsonld", format="json-ld")# Generate SHACL shapes for validationengine.export_shacl(ontology, "shapes.ttl")
Ontology versioning (VersionManager, OntologyVersion) has moved to semantica.change_management. Import from there: from semantica.change_management import VersionManager.