Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

Fix Temporal KG notebook: update query parameters, version keys, and enable Plotly

KaifAhmad102a6f3fac284
diff --git a/cookbook/advanced/10_Temporal_Knowledge_Graphs.ipynb b/cookbook/advanced/10_Temporal_Knowledge_Graphs.ipynb
index 7d5efd3d..21597361 100644
--- a/cookbook/advanced/10_Temporal_Knowledge_Graphs.ipynb
+++ b/cookbook/advanced/10_Temporal_Knowledge_Graphs.ipynb
@@ -37,7 +37,7 @@
"metadata": {},
"outputs": [],
"source": [
- "!pip install semantica[all]"
+ "# !pip install semantica[all]"
]
},
{
@@ -50,6 +50,8 @@
"from datetime import datetime\n",
"from semantica.kg import GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, TemporalVersionManager\n",
"from semantica.visualization import TemporalVisualizer\n",
+ "import plotly.offline as pyo\n",
+ "pyo.init_notebook_mode(connected=True)\n",
"\n",
"# Ensure consistent output for reproducibility\n",
"import random\n",
@@ -167,7 +169,7 @@
"ceo_1990 = query_engine.query_at_time(\n",
" temporal_kg,\n",
" query=\"Find the CEO of TechCorp\",\n",
- " timestamp=\"1990-06-01\"\n",
+ " at_time=\"1990-06-01\"\n",
")\n",
"print(\"CEO in 1990:\", [e['id'] for e in ceo_1990.get('entities', [])])\n",
"\n",
@@ -175,7 +177,7 @@
"ceo_2015 = query_engine.query_at_time(\n",
" temporal_kg,\n",
" query=\"Find the CEO of TechCorp\",\n",
- " timestamp=\"2015-06-01\"\n",
+ " at_time=\"2015-06-01\"\n",
")\n",
"print(\"CEO in 2015:\", [e['id'] for e in ceo_2015.get('entities', [])])\n",
"\n",
@@ -278,8 +280,8 @@
"diff = version_manager.compare_versions(v1_1990, v2_2010)\n",
"\n",
"print(f\"\\nComparing {v1_1990['label']} vs {v2_2010['label']}:\")\n",
- "print(f\"New Entities: {diff.get('added_entities_count', 0)}\")\n",
- "print(f\"New Relationships: {diff.get('added_relationships_count', 0)}\")"
+ "print(f\"New Entities: {diff.get('entities_added', 0)}\")\n",
+ "print(f\"New Relationships: {diff.get('relationships_added', 0)}\")"
]
},
{
@@ -325,7 +327,7 @@
"temporal_data = extract_events(temporal_kg)\n",
"timeline_fig = visualizer.visualize_timeline(temporal_data, output=\"interactive\")\n",
"# In a notebook, this would render a Plotly figure. \n",
- "# timeline_fig.show()\n",
+ "timeline_fig.show()\n",
"\n",
"# 2. Version History Visualization\n",
"history = [\n",
@@ -334,7 +336,7 @@
" {\"version\": \"v3.0\", \"timestamp\": \"2020-01-01\", \"changes\": \"AI Era\"}\n",
"]\n",
"history_fig = visualizer.visualize_version_history(history, output=\"interactive\")\n",
- "# history_fig.show()\n",
+ "history_fig.show()\n",
"\n",
"print(\"Visualizations generated (render requires Jupyter environment).\")"
]