mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
Seven introduction notebooks linked to a different notebook's filename in their Colab badge (off-by-one numbering), sending readers to the wrong notebook or a 404. Point each badge back at its own file.
6.1 KiB
6.1 KiB
In [ ]:
!pip install -q semanticaIn [ ]:
from semantica.visualization import KGVisualizer
from semantica.kg import GraphBuilder
kg_visualizer = KGVisualizer()
builder = GraphBuilder()
entities = [
{"id": "e1", "type": "Organization", "name": "Apple Inc.", "properties": {}},
{"id": "e2", "type": "Person", "name": "Tim Cook", "properties": {}}
]
relationships = [
{"source": "e2", "target": "e1", "type": "CEO_of", "properties": {}}
]
kg = builder.build(entities, relationships)
visualization = kg_visualizer.visualize_network(kg, output="interactive")
In [ ]:
from semantica.visualization import OntologyVisualizer
from semantica.ontology import OntologyGenerator
ontology_visualizer = OntologyVisualizer()
# Initialize generator with min_occurrences=1 to allow single-instance classes
generator = OntologyGenerator(min_occurrences=1)
# Generate ontology using the correct method signature (dictionary input)
ontology = generator.generate_ontology({"entities": entities, "relationships": relationships})
# Visualize the hierarchy
visualization = ontology_visualizer.visualize_hierarchy(ontology, output="interactive")In [ ]:
from semantica.visualization import EmbeddingVisualizer
from semantica.embeddings import EmbeddingGenerator
import numpy as np
embedding_visualizer = EmbeddingVisualizer()
generator = EmbeddingGenerator()
texts = ["Apple Inc.", "Microsoft Corporation", "Amazon"]
embeddings = generator.generate_embeddings(texts, data_type="text")
labels = ["Apple", "Microsoft", "Amazon"]
visualization = embedding_visualizer.visualize_2d_projection(embeddings, labels, method="umap")
In [ ]:
from semantica.visualization import SemanticNetworkVisualizer
# Initialize (uses new defaults: Vibrant colors, Kamada-Kawai layout)
viz = SemanticNetworkVisualizer()
# Your semantic network data
semantic_network = {
"nodes": [
{"id": "n1", "label": "Python", "type": "Language"},
{"id": "n2", "label": "Code", "type": "Concept"}
],
"edges": [
{"source": "n1", "target": "n2", "label": "writes"}
]
}
# This will now display the interactive graph in the notebook cell
viz.visualize_network(
semantic_network,
output="html",
file_path="network_graph.html"
)