mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
- 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
5.3 KiB
5.3 KiB
In [ ]:
from semantica.kg import GraphBuilder, GraphAnalyzer
from semantica.semantic_extract import NERExtractor, RelationExtractor
builder = GraphBuilder()
analyzer = GraphAnalyzer()
entities = [
{"id": "e1", "type": "Organization", "name": "Apple Inc.", "properties": {}},
{"id": "e2", "type": "Person", "name": "Tim Cook", "properties": {}},
{"id": "e3", "type": "Location", "name": "Cupertino", "properties": {}}
]
relationships = [
{"source": "e2", "target": "e1", "type": "CEO_of", "properties": {}},
{"source": "e1", "target": "e3", "type": "located_in", "properties": {}}
]
kg = builder.build(entities, relationships)
metrics = analyzer.compute_metrics(kg)
print(f"Graph metrics:")
print(f" Entities: {metrics.get('entity_count', 0)}")
print(f" Relationships: {metrics.get('relationship_count', 0)}")
print(f" Density: {metrics.get('density', 0):.3f}")
In [ ]:
from semantica.kg import CentralityCalculator
centrality_calculator = CentralityCalculator()
centrality_scores = centrality_calculator.calculate_centrality(kg, measure="degree")
print(f"Centrality scores:")
for entity_id, score in list(centrality_scores.items())[:5]:
print(f" {entity_id}: {score:.3f}")
In [ ]:
from semantica.kg import CommunityDetector
community_detector = CommunityDetector()
communities = community_detector.detect_communities(kg)
print(f"Detected {len(communities)} communities")
for i, community in enumerate(communities[:3], 1):
print(f" Community {i}: {len(community)} entities")
In [ ]:
from semantica.kg import ConnectivityAnalyzer
connectivity_analyzer = ConnectivityAnalyzer()
connectivity = connectivity_analyzer.analyze_connectivity(kg)
print(f"Connectivity analysis:")
print(f" Is connected: {connectivity.get('is_connected', False)}")
print(f" Components: {len(connectivity.get('components', []))}")