mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
Add a Cite Us section to the README with BibTeX citation info, and align it with docs/citation.md (author/organization: Semantica, 2026). Update LICENSE and docs/project-license.md copyright holder to Semantica, and replace the stale Hawksight-AI GitHub org slug with semantica-agi across READMEs, plugin manifests, cookbook notebooks, and GitHub templates.
6.2 KiB
6.2 KiB
In [ ]:
!pip install -qU semantica
In [ ]:
from semantica.kg import GraphBuilder
from semantica.ontology import OntologyGenerator
from semantica.export import RDFExporter
from semantica.triplet_store import TripletStore
In [ ]:
builder = GraphBuilder()
entities = [
{"id": "e1", "type": "Person", "name": "Alice", "properties": {"age": 30, "role": "Engineer"}},
{"id": "e2", "type": "Person", "name": "Bob", "properties": {"age": 35, "role": "Manager"}},
{"id": "e3", "type": "Organization", "name": "Tech Corp", "properties": {"founded": 2010}},
{"id": "e4", "type": "Project", "name": "Project Alpha", "properties": {"status": "active"}},
]
relationships = [
{"source": "e1", "target": "e2", "type": "reports_to"},
{"source": "e1", "target": "e3", "type": "works_for"},
{"source": "e2", "target": "e3", "type": "works_for"},
{"source": "e1", "target": "e4", "type": "works_on"},
]
knowledge_graph = builder.build(entities, relationships)
In [ ]:
generator = OntologyGenerator()
ontology = generator.generate_from_graph(knowledge_graph)
In [ ]:
def create_mappings(kg, ontology):
mappings = {
"entity_type_mappings": {},
"relationship_type_mappings": {},
"property_mappings": {}
}
entity_types = set(e.get("type") for e in entities)
ontology_classes = ontology.get("classes", [])
for entity_type in entity_types:
matching_class = next((cls for cls in ontology_classes if cls.get("name") == entity_type), None)
if matching_class:
mappings["entity_type_mappings"][entity_type] = matching_class.get("uri", entity_type)
relationship_types = set(r.get("type") for r in relationships)
ontology_properties = ontology.get("properties", [])
for rel_type in relationship_types:
matching_prop = next((prop for prop in ontology_properties if prop.get("name") == rel_type), None)
if matching_prop:
mappings["relationship_type_mappings"][rel_type] = matching_prop.get("uri", rel_type)
return mappings
mappings = create_mappings(knowledge_graph, ontology)
semantic_layer = {
"graph": knowledge_graph,
"ontology": ontology,
"mappings": mappings,
"metadata": {
"version": "1.0",
"created_at": "2024-01-01",
"description": "Enterprise semantic layer"
}
}
In [ ]:
exporter = RDFExporter()
# Export Knowledge Graph
exporter.export(knowledge_graph, "knowledge_graph.ttl", format="turtle")
print("Exported knowledge graph to knowledge_graph.ttl")