Files
semantica/cookbook/advanced/Temporal_Knowledge_Graphs.ipynb
T
KaifAhmad1 116bbbd700 Update cookbook notebooks with real data sources
- Replace mock data with real feed URLs, APIs, and database patterns
- Add real threat intelligence feeds (CISA, US-CERT, Security Week, Dark Reading)
- Add real financial feeds (Reuters, CNN Money, Bloomberg, Financial Times)
- Add real healthcare feeds (CDC, WHO)
- Add real API endpoints (MITRE ATT&CK, NVD CVE API, Polygon.io, Alpha Vantage, FHIR APIs)
- Add realistic database connection patterns with SQL queries
- Add Kafka/RabbitMQ streaming configurations
- Update all cybersecurity notebooks (5/5) with real sources
- Update finance notebooks (2/2) with real sources
- Update healthcare notebooks (1/1) with real sources
- Create REAL_DATA_SOURCES.md documentation
- Improve error handling with try-except blocks
- Add batch processing for multiple feed URLs
2025-11-13 16:52:51 +05:30

5.2 KiB

Temporal Knowledge Graphs

Overview

This notebook demonstrates advanced temporal knowledge graph capabilities using TemporalGraphQuery, TemporalPatternDetector, TemporalVersionManager, and TemporalVisualizer.

Learning Objectives

  • Use TemporalGraphQuery for time-aware queries
  • Use TemporalPatternDetector to detect temporal patterns
  • Use TemporalVersionManager for temporal versioning and snapshots
  • Use TemporalVisualizer to visualize temporal data

Workflow: Build Temporal KG → Time-Aware Queries → Pattern Detection → Version Management → Visualization

In [ ]:
from semantica.kg import GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, TemporalVersionManager
from semantica.visualization import TemporalVisualizer
from datetime import datetime

builder = GraphBuilder()

entities = [
    {"id": "e1", "type": "Organization", "name": "Apple Inc.", "properties": {"founded": "1976"}},
    {"id": "e2", "type": "Person", "name": "Steve Jobs", "properties": {"born": "1955"}}
]

relationships = [
    {"source": "e2", "target": "e1", "type": "founded", "properties": {"timestamp": "1976-04-01"}}
]

temporal_kg = builder.build(entities, relationships)

print(f"Built temporal knowledge graph with {len(entities)} entities")

Step 2: Time-Aware Queries

Query the graph at specific time points.

In [ ]:
temporal_query = TemporalGraphQuery()

query_result = temporal_query.query_time_range(
    graph=temporal_kg,
    query="Find entities founded in 1976",
    start_time="1976-01-01",
    end_time="1976-12-31"
)

print(f"Time-aware query returned {len(query_result.get('entities', []))} entities")

Step 3: Temporal Pattern Detection

Detect temporal patterns in the graph.

In [ ]:
pattern_detector = TemporalPatternDetector()

patterns = pattern_detector.detect_temporal_patterns(
    temporal_kg,
    pattern_type="sequence",
    min_frequency=1
)

print(f"Detected {len(patterns)} temporal patterns")

Step 4: Version Management

Manage temporal versions and snapshots.

In [ ]:
version_manager = TemporalVersionManager()

snapshot = version_manager.create_snapshot(temporal_kg, timestamp=datetime.now())

print(f"Created temporal snapshot at {snapshot.get('timestamp', 'N/A')}")
print(f"Snapshot contains {len(snapshot.get('entities', []))} entities")

Step 5: Temporal Visualization

Visualize temporal data.

In [ ]:
temporal_visualizer = TemporalVisualizer()

visualization = temporal_visualizer.visualize_timeline(temporal_kg, output="interactive")

print("Generated temporal visualization")

Summary

You've learned advanced temporal knowledge graph capabilities:

  • TemporalGraphQuery: Time-aware graph querying
  • TemporalPatternDetector: Temporal pattern detection
  • TemporalVersionManager: Temporal versioning and snapshots
  • TemporalVisualizer: Temporal data visualization