Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

Update README.md

Mohd Kaif544f36797bee
diff --git a/README.md b/README.md
index d7db1855..2458fd6a 100644
--- a/README.md
+++ b/README.md
@@ -111,12 +111,8 @@ Semantica fills this gap with a **complete semantic intelligence framework**:
---
----
-
## ✨ Core Capabilities
-Semantica provides a comprehensive suite of capabilities that transform raw data into AI-ready semantic knowledge. Each capability is built with production-grade quality, extensibility, and performance in mind.
-
### 1. πŸ“Š Universal Data Ingestion
Process **50+ file formats** with intelligent semantic extraction:
@@ -184,544 +180,142 @@ Process **50+ file formats** with intelligent semantic extraction:
</tr>
</table>
-**Key Features:**
-
-| Feature | Description | Benefit |
-|---------|-------------|---------|
-| πŸ”„ **Batch Processing** | Process thousands of documents efficiently with parallel execution | High-throughput processing for large-scale data ingestion |
-| πŸ“Š **Streaming Support** | Handle real-time data feeds with low-latency processing | Real-time semantic knowledge updates from live sources |
-| πŸ” **Smart Extraction** | Preserve semantic context, structure, and metadata | Maintains relationships and meaning during extraction |
-| 🌍 **Multilingual** | Support for 100+ languages with automatic detection | Global data processing without language barriers |
-| πŸ”— **Cross-Format Linking** | Link entities across different file formats and sources | Unified knowledge representation from diverse data sources |
-| πŸ“ **Metadata Preservation** | Maintain document metadata, timestamps, and provenance | Full audit trail and source tracking |
-
-**Usage Example:**
+**Example: Multi-Source Ingestion**
```python
from semantica.ingest import FileIngestor, WebIngestor, FeedIngestor
-# Multi-source ingestion
+# Initialize ingestors
file_ingestor = FileIngestor()
web_ingestor = WebIngestor()
feed_ingestor = FeedIngestor()
# Ingest from multiple sources
sources = [
- file_ingestor.ingest("documents/"),
- web_ingestor.ingest("https://example.com/articles"),
- feed_ingestor.ingest("https://example.com/rss")
+ *file_ingestor.ingest("documents/", formats=["pdf", "docx", "xlsx"]),
+ *web_ingestor.ingest("https://example.com/articles"),
+ *feed_ingestor.ingest("https://example.com/rss")
]
-# All sources processed with unified semantic extraction
+print(f"βœ… Ingested {len(sources)} sources")
+# Output: βœ… Ingested 1,247 sources
```
---
### 2. 🧠 Semantic Intelligence Engine
-Transform raw text into structured semantic knowledge with state-of-the-art NLP and AI models. The semantic intelligence engine extracts entities, relationships, events, and generates RDF-ready triples from unstructured content.
-
-**Key Capabilities:**
-
-- **Multi-Layer Understanding**: From lexical analysis to pragmatic interpretation
-- **General-Purpose Processing**: Works across all domains without domain-specific modules
-- **High Accuracy**: Achieves 95%+ F1 scores on standard benchmarks
-- **Real-Time Processing**: Sub-second response times for most documents
-- **Scalable**: Handles documents from 1KB to 100MB+
-
-#### Entity & Relationship Extraction
-
-Semantica's semantic intelligence engine extracts structured knowledge from unstructured text using state-of-the-art NLP models. This comprehensive example demonstrates the complete extraction pipeline with detailed, structured output.
-
----
-
-##### πŸ“‹ **Example Overview**
-
-**Goal**: Extract structured knowledge from unstructured text about a company acquisition.
-
-**What We'll Extract:**
-- βœ… **Named Entities**: Organizations, people, dates, locations, money amounts
-- βœ… **Relationships**: Actions between entities (acquired, founded, joined, etc.)
-- βœ… **Semantic Triples**: RDF-ready subject-predicate-object structures
-- βœ… **Temporal Information**: When events occurred
-- βœ… **Confidence Scores**: Extraction certainty metrics
-
----
-
-##### πŸ“ **Step 1: Prepare Input Text**
-
-```python
-# Sample unstructured text about a company acquisition
-text = """
-Apple Inc., the technology giant founded by Steve Jobs in 1976, announced its acquisition
-of Beats Electronics for $3 billion on May 28, 2014. The deal, which was Apple's largest
-acquisition at the time, included Beats Music streaming service and Beats Electronics hardware.
-Dr. Dre and Jimmy Iovine, co-founders of Beats, joined Apple's executive team. The acquisition
-signaled Apple's entry into the premium audio market and streaming music services, competing
-directly with Spotify and other streaming platforms. The Cupertino-based company integrated
-Beats Music into what became Apple Music in 2015, which now has over 100 million subscribers
-worldwide.
-"""
-
-print(f"Input text length: {len(text)} characters")
-print(f"Input text words: {len(text.split())} words")
-```
-
-**Output:**
-```
-Input text length: 567 characters
-Input text words: 98 words
-```
-
----
+Transform raw text into structured semantic knowledge with state-of-the-art NLP and AI models.
-##### πŸ”§ **Step 2: Initialize and Run Extraction**
+**Example: Complete Extraction Pipeline**
```python
from semantica import Semantica
-# Initialize Semantica with default configuration
-core = Semantica()
-
-# Run complete semantic extraction pipeline
-results = core.extract_semantics(text)
-
-print(f"βœ… Extraction complete!")
-print(f" Processing time: {results.processing_time:.2f} seconds")
-print(f" Entities found: {len(results.entities)}")
-print(f" Relationships found: {len(results.relationships)}")
-print(f" Triples generated: {len(results.triples)}")
-```
-
----
-
-##### πŸ“Š **Step 3: Analyze Extracted Entities**
-
-```python
-# Entity Extraction Results
-from semantica import Semantica
+# Sample text
+text = """
+Apple Inc., founded by Steve Jobs in 1976, announced its acquisition of Beats
+Electronics for $3 billion on May 28, 2014. Dr. Dre and Jimmy Iovine, co-founders
+of Beats, joined Apple's executive team. The acquisition included Beats Music
+streaming service and Beats Electronics hardware.
+"""
+# Initialize and extract
core = Semantica()
results = core.extract_semantics(text)
-# Step 1: Entity Extraction
-# Semantica identifies all named entities in the text with their types and confidence scores
-print("=== STEP 1: EXTRACTED ENTITIES ===\n")
-print(f"Total entities found: {len(results.entities)}\n")
-
-for i, entity in enumerate(results.entities, 1):
- print(f"Entity {i}:")
- print(f" Text: '{entity.text}'")
- print(f" Type: {entity.type}")
- print(f" Confidence: {entity.confidence:.2f} ({'High' if entity.confidence > 0.9 else 'Medium' if entity.confidence > 0.7 else 'Low'})")
- print(f" Position in text: character {entity.start_char}-{entity.end_char}")
- print(f" Context: \"...{entity.context}...\"")
-
- # Additional entity metadata
- if hasattr(entity, 'aliases'):
- print(f" Alternative names: {entity.aliases}")
- if hasattr(entity, 'wikipedia_url'):
- print(f" Wikipedia: {entity.wikipedia_url}")
- print()
+# === EXTRACTED ENTITIES ===
+print(f"Entities found: {len(results.entities)}\n")
+for entity in results.entities:
+ print(f"- {entity.text} ({entity.type}, {entity.confidence:.2f})")
# Output:
-# Text: Apple Inc.
-# Type: Organization
-# Confidence: 0.98
-# Position: 0-10
-# Context: the technology giant founded by Steve Jobs
-#
-# Text: Steve Jobs
-# Type: Person
-# Confidence: 0.97
-# Position: 54-64
-# Context: founded by Steve Jobs in 1976
-#
-# Text: 1976
-# Type: Date
-# Confidence: 1.0
-# Position: 68-72
-# Context: founded by Steve Jobs in 1976
-#
-# Text: Beats Electronics
-# Type: Organization
-# Confidence: 0.95
-# Position: 115-131
-# Context: acquisition of Beats Electronics for $3 billion
-#
-# ... and more
-
-# Step 2: Relationship Extraction
-# Semantica identifies how entities relate to each other, capturing actions and connections
-print("=== STEP 2: EXTRACTED RELATIONSHIPS ===\n")
-print(f"Total relationships found: {len(results.relationships)}\n")
-
-for i, rel in enumerate(results.relationships, 1):
- print(f"Relationship {i}:")
- print(f" Subject: '{rel.subject}' ({rel.subject_type})")
- print(f" Predicate: '{rel.predicate}'")
- print(f" Object: '{rel.object}' ({rel.object_type})")
- print(f" Confidence: {rel.confidence:.2f}")
- print(f" Temporal Context: {rel.temporal if rel.temporal else 'Not specified'}")
- print(f" Source Text: \"{rel.source_text}\"")
-
- # Relationship metadata
- if hasattr(rel, 'negation'):
- print(f" Negated: {rel.negation}")
- if hasattr(rel, 'certainty'):
- print(f" Certainty: {rel.certainty}")
- print()
+# - Apple Inc. (Organization, 0.98)
+# - Steve Jobs (Person, 0.97)
+# - 1976 (Date, 1.00)
+# - Beats Electronics (Organization, 0.95)
+# - $3 billion (Money, 0.99)
+# - May 28, 2014 (Date, 0.98)
+# - Dr. Dre (Person, 0.97)
+# - Jimmy Iovine (Person, 0.94)
+
+# === EXTRACTED RELATIONSHIPS ===
+print(f"\nRelationships found: {len(results.relationships)}\n")
+for rel in results.relationships[:3]:
+ print(f"{rel.subject} --[{rel.predicate}]--> {rel.object}")
# Output:
-# Subject: Apple Inc.
-# Predicate: acquired
-# Object: Beats Electronics
-# Confidence: 0.96
-# Temporal: 2014-05-28
-# Source: announced its acquisition of Beats Electronics for $3 billion on May 28, 2014
-#
-# Subject: Steve Jobs
-# Predicate: founded
-# Object: Apple Inc.
-# Confidence: 0.98
-# Temporal: 1976
-# Source: founded by Steve Jobs in 1976
-#
-# Subject: Dr. Dre
-# Predicate: co-founded
-# Object: Beats Electronics
-# Confidence: 0.93
-# Temporal: null
-# Source: Dr. Dre and Jimmy Iovine, co-founders of Beats
-
-# Step 3: Triple Generation
-# Semantica generates RDF-ready triples for knowledge graph construction
-print("=== STEP 3: SEMANTIC TRIPLES (RDF-READY) ===\n")
-print(f"Total triples generated: {len(results.triples)}\n")
-print("Format: (Subject, Predicate, Object)\n")
-
-for i, triple in enumerate(results.triples, 1):
- print(f"Triple {i}:")
- print(f" Subject: {triple[0]}")
- print(f" Predicate: {triple[1]}")
- print(f" Object: {triple[2]}")
-
- # Triple metadata if available
- if len(triple) > 3:
- metadata = triple[3]
- if metadata.get('confidence'):
- print(f" Confidence: {metadata['confidence']:.2f}")
- if metadata.get('source'):
- print(f" Source: {metadata['source']}")
- print()
-
-print("\n=== EXTRACTION SUMMARY ===")
-print(f"βœ… Extracted {len(results.entities)} entities across {len(set(e.type for e in results.entities))} entity types")
-print(f"βœ… Identified {len(results.relationships)} relationships with temporal context")
-print(f"βœ… Generated {len(results.triples)} RDF-ready triples for knowledge graph")
-print(f"βœ… Average confidence: {sum(e.confidence for e in results.entities) / len(results.entities):.2f}")
-print(f"βœ… Processing time: {results.processing_time:.2f} seconds")
+# Apple Inc. --[founded_by]--> Steve Jobs
+# Apple Inc. --[acquired]--> Beats Electronics
+# Dr. Dre --[co-founded]--> Beats Electronics
+
+# === GENERATED TRIPLES ===
+print(f"\nTriples generated: {len(results.triples)}\n")
+for triple in results.triples[:5]:
+ print(f" {triple}")
# Output:
-# (<Apple_Inc>, <acquired>, <Beats_Electronics>)
-# (<Apple_Inc>, <paidAmount>, "$3B")
-# (<acquisition>, <occurredOn>, "2014-05-28")
-# (<Steve_Jobs>, <founded>, <Apple_Inc>)
-# (<founding>, <occurredIn>, "1976")
-# (<Dr_Dre>, <coFounded>, <Beats_Electronics>)
-# (<Jimmy_Iovine>, <coFounded>, <Beats_Electronics>)
-# (<Apple_Music>, <hasSubscribers>, "100000000")
-# (<Apple_Inc>, <headquarteredIn>, <Cupertino>)
+# (<Apple_Inc>, <founded_by>, <Steve_Jobs>)
+# (<Apple_Inc>, <acquired>, <Beats_Electronics>)
+# (<acquisition>, <amount>, "$3B")
+# (<acquisition>, <date>, "2014-05-28")
+# (<Dr_Dre>, <co-founded>, <Beats_Electronics>)
```
-#### Advanced NLP Features
-
-| Feature | Description | Technology Stack | Use Cases |
-|---------|-------------|-----------------|-----------|
-| **Multi-Layer Analysis** | Lexical β†’ Syntactic β†’ Semantic β†’ Pragmatic understanding | spaCy, NLTK, Transformers, Custom pipelines | Deep semantic understanding for complex documents |
-| **Named Entity Recognition** | 18+ entity types (Person, Organization, Location, etc.) | Transformers (BERT, RoBERTa), spaCy, Custom models | Extract structured entities from unstructured text |
-| **Relationship Extraction** | Open Information Extraction + pattern-based + ML-based extraction | Stanford OpenIE, Dependency parsing, Transformers | Build knowledge graph relationships automatically |
-| **Event Detection** | Complex event recognition with participants, time, location | Event extraction pipelines, Temporal reasoning | Extract events and their participants for temporal knowledge graphs |
-| **Coreference Resolution** | Entity linking across sentences, paragraphs, and documents | NeuralCoref, Transformer-based, Custom algorithms | Resolve pronouns and references for accurate entity tracking |
-| **Temporal Analysis** | Time-aware understanding, event ordering, temporal reasoning | SUTime, Temporal expression parsing | Build time-aware knowledge graphs with event sequencing |
-| **Semantic Role Labeling** | Identify semantic roles (agent, patient, instrument) | Transformers, Dependency parsing | Understand who did what to whom with what |
-| **Triple Extraction** | Generate RDF-ready subject-predicate-object triples | Custom extraction pipelines, LLM-based | Create semantic triples for knowledge graph construction |
-
-**Advanced Usage:**
+**Advanced Extraction with Custom Models**
```python
from semantica.semantic_extract import (
NamedEntityRecognizer,
RelationExtractor,
EventDetector,
- TripleExtractor,
- SemanticAnalyzer
+ TripleExtractor
)
-# Initialize extractors
-ner = NamedEntityRecognizer(model="transformer") # General-purpose NER works for all domains
-rel_extractor = RelationExtractor(strategy="hybrid") # OpenIE + Pattern
+# Initialize specialized extractors
+ner = NamedEntityRecognizer(model="transformer")
+rel_extractor = RelationExtractor(strategy="hybrid")
event_detector = EventDetector()
triple_extractor = TripleExtractor()
-# Extract from document
-document = """
-Apple Inc. announced its Q4 2024 earnings results on November 1, 2024.
-The company reported revenue of $89.5 billion, representing a 1% increase
-compared to the same quarter last year. CEO Tim Cook stated that the results
-were driven by strong iPhone sales, particularly the iPhone 15 Pro models.
-The Services division reached an all-time high with $22.3 billion in revenue.
-Apple's board of directors declared a cash dividend of $0.25 per share,
-payable to shareholders on November 16, 2024. The company also announced
-plans to expand its manufacturing facilities in India and Vietnam.
-Supply chain challenges in China were successfully mitigated through
-diversification efforts. Wall Street analysts had expected revenue of
-$89.28 billion, so Apple slightly exceeded expectations.
-"""
+# Extract with full pipeline
+entities = ner.extract(text)
+relationships = rel_extractor.extract(text, entities)
+events = event_detector.detect(text)
+triples = triple_extractor.extract(text, entities, relationships, events)
-# Step 1: Named Entity Recognition
-# Extract all entities with their types and confidence scores
-print("=== STEP 1: NAMED ENTITY RECOGNITION ===\n")
-entities = ner.extract(document)
-
-print(f"Found {len(entities)} entities across {len(set(e.type for e in entities))} entity types\n")
-print("Entity Breakdown by Type:\n")
-
-# Group entities by type
-entities_by_type = {}
-for entity in entities:
- if entity.type not in entities_by_type:
- entities_by_type[entity.type] = []
- entities_by_type[entity.type].append(entity)
-
-for entity_type, entity_list in entities_by_type.items():
- print(f"{entity_type} ({len(entity_list)} entities):")
- for entity in entity_list:
- confidence_indicator = "βœ“" if entity.confidence > 0.9 else "~" if entity.confidence > 0.7 else "?"
- print(f" {confidence_indicator} {entity.text} (confidence: {entity.confidence:.2f})")
- print()
-
-print("Detailed Entity Information:")
-for i, entity in enumerate(entities[:10], 1): # Show first 10
- print(f"\nEntity {i}: {entity.text}")
- print(f" Type: {entity.type}")
- print(f" Confidence: {entity.confidence:.2f} ({'High' if entity.confidence > 0.9 else 'Medium' if entity.confidence > 0.7 else 'Low'})")
- print(f" Position: characters {entity.start_char}-{entity.end_char}")
- if hasattr(entity, 'normalized_value'):
- print(f" Normalized: {entity.normalized_value}")
-
-# Step 2: Relationship Extraction
-# Identify how entities relate to each other using hybrid extraction
-print("\n=== STEP 2: RELATIONSHIP EXTRACTION ===\n")
-relationships = rel_extractor.extract(document, entities)
-
-print(f"Found {len(relationships)} relationships using hybrid extraction strategy\n")
-print("Extraction Strategy Breakdown:")
-print(" β€’ OpenIE: General relationship patterns (e.g., 'announced', 'reported')")
-print(" β€’ Pattern-based: Common relationship patterns across domains")
-print(" β€’ ML-based: Learned patterns from training data\n")
-
-print("Extracted Relationships (sorted by confidence):\n")
-# Sort by confidence
-sorted_relationships = sorted(relationships, key=lambda x: x.confidence, reverse=True)
-
-for i, rel in enumerate(sorted_relationships[:10], 1): # Show top 10
- print(f"Relationship {i}:")
- print(f" {rel.subject} --[{rel.predicate}]--> {rel.object}")
- print(f" Confidence: {rel.confidence:.2f}")
- print(f" Extraction Method: {rel.extraction_method if hasattr(rel, 'extraction_method') else 'Hybrid'}")
- if hasattr(rel, 'source_sentence'):
- print(f" Source Sentence: \"{rel.source_sentence[:80]}...\"")
- print()
-
-# Relationship statistics
-print(f"\nRelationship Statistics:")
-print(f" High confidence (>0.9): {sum(1 for r in relationships if r.confidence > 0.9)}")
-print(f" Medium confidence (0.7-0.9): {sum(1 for r in relationships if 0.7 <= r.confidence <= 0.9)}")
-print(f" Low confidence (<0.7): {sum(1 for r in relationships if r.confidence < 0.7)}")
-
-# Step 3: Event Detection
-# Identify structured events with participants, time, and location
-print("\n=== STEP 3: EVENT DETECTION ===\n")
-events = event_detector.detect(document)
-
-print(f"Detected {len(events)} structured events\n")
-
-for i, event in enumerate(events, 1):
- print(f"Event {i}: {event.type}")
- print(f" Event Type: {event.type} ({event.category if hasattr(event, 'category') else 'N/A'})")
- print(f" Participants: {', '.join(event.participants) if event.participants else 'None specified'}")
- print(f" Time: {event.temporal if event.temporal else 'Not specified'}")
- print(f" Location: {', '.join(event.location) if event.location else 'Not specified'}")
- print(f" Confidence: {event.confidence:.2f}")
-
- # Event details
- if hasattr(event, 'trigger_word'):
- print(f" Trigger: \"{event.trigger_word}\"")
- if hasattr(event, 'description'):
- print(f" Description: {event.description}")
-
- # Event properties
- if hasattr(event, 'properties'):
- print(f" Properties: {event.properties}")
- print()
-
-# Event timeline
-if any(e.temporal for e in events):
- print("Event Timeline:")
- timeline_events = sorted([e for e in events if e.temporal],
- key=lambda x: x.temporal if x.temporal else "")
- for event in timeline_events:
- print(f" {event.temporal}: {event.type}")
- print(f" Participants: {', '.join(event.participants)}")
-
-# Step 4: Triple Generation
-# Generate RDF-ready triples for knowledge graph construction
-print("\n=== STEP 4: TRIPLE GENERATION (RDF-READY) ===\n")
-triples = triple_extractor.extract(document, entities, relationships, events)
-
-print(f"Generated {len(triples)} semantic triples in RDF format\n")
-print("Triple Format: (Subject, Predicate, Object)\n")
-
-# Group triples by type for better organization
-triple_groups = {
- "Company Actions": [],
- "Financial Metrics": [],
- "Temporal Events": [],
- "Product Information": [],
- "Organizational Structure": []
-}
-
-for triple in triples:
- predicate = triple[1] if isinstance(triple[1], str) else str(triple[1])
- if any(word in predicate.lower() for word in ["revenue", "dividend", "reported", "earnings"]):
- triple_groups["Financial Metrics"].append(triple)
- elif any(word in predicate.lower() for word in ["announced", "declared", "stated"]):
- triple_groups["Company Actions"].append(triple)
- elif any(word in predicate.lower() for word in ["occurred", "time", "date"]):
- triple_groups["Temporal Events"].append(triple)
- elif any(word in predicate.lower() for word in ["product", "sales", "models"]):
- triple_groups["Product Information"].append(triple)
- else:
- triple_groups["Organizational Structure"].append(triple)
-
-for group_name, group_triples in triple_groups.items():
- if group_triples:
- print(f"{group_name} ({len(group_triples)} triples):")
- for i, triple in enumerate(group_triples[:5], 1): # Show first 5 per group
- print(f" {i}. {triple[0]} β†’ {triple[1]} β†’ {triple[2]}")
- if len(triple) > 3 and isinstance(triple[3], dict):
- metadata = triple[3]
- if metadata.get('confidence'):
- print(f" Confidence: {metadata['confidence']:.2f}")
- if len(group_triples) > 5:
- print(f" ... and {len(group_triples) - 5} more")
- print()
-
-# Step 5: Semantic Analysis
-# Deep semantic analysis of the document structure, topics, and relationships
-print("\n=== STEP 5: SEMANTIC ANALYSIS ===\n")
-analyzer = SemanticAnalyzer()
-semantic_graph = analyzer.analyze(document, entities, relationships)
-
-print("Semantic Analysis Results:\n")
-print(f"πŸ“Š Document Statistics:")
-print(f" Total concepts identified: {semantic_graph.concept_count}")
-print(f" Key relationships: {len(semantic_graph.key_relationships)}")
-print(f" Semantic clusters: {len(semantic_graph.clusters) if hasattr(semantic_graph, 'clusters') else 'N/A'}")
-print(f" Co-reference chains: {len(semantic_graph.coreference_chains) if hasattr(semantic_graph, 'coreference_chains') else 'N/A'}\n")
-
-print(f"🎯 Main Topics (with confidence):")
-for i, topic in enumerate(semantic_graph.main_topics[:5], 1):
- print(f" {i}. {topic['name']} (confidence: {topic['confidence']:.2f})")
- if 'keywords' in topic:
- print(f" Keywords: {', '.join(topic['keywords'][:5])}")
-print()
-
-print(f"πŸ’­ Document Sentiment:")
-sentiment = semantic_graph.sentiment
-print(f" Overall: {sentiment['label']} (score: {sentiment['score']:.2f})")
-if 'aspects' in sentiment:
- print(f" Aspect-level sentiment:")
- for aspect in sentiment['aspects'][:3]:
- print(f" - {aspect['aspect']}: {aspect['sentiment']} ({aspect['score']:.2f})")
-print()
-
-print(f"πŸ”— Key Semantic Relationships:")
-for i, rel in enumerate(semantic_graph.key_relationships[:5], 1):
- print(f" {i}. {rel['subject']} β†’ {rel['predicate']} β†’ {rel['object']}")
- print(f" Importance: {rel['importance']:.2f}, Evidence: {rel['evidence_count']} mentions")
-print()
-
-print(f"πŸ“ˆ Document Quality Metrics:")
-if hasattr(semantic_graph, 'quality_metrics'):
- metrics = semantic_graph.quality_metrics
- print(f" Coherence: {metrics.get('coherence', 'N/A')}")
- print(f" Completeness: {metrics.get('completeness', 'N/A')}")
- print(f" Informativeness: {metrics.get('informativeness', 'N/A')}")
-
-print("\nβœ… Complete extraction pipeline finished successfully!")
-print(f"βœ… Ready for knowledge graph construction with {len(triples)} triples")
+print(f"Entities: {len(entities)}")
+print(f"Relationships: {len(relationships)}")
+print(f"Events: {len(events)}")
+print(f"Triples: {len(triples)}")
```
---
### 3. πŸ•ΈοΈ Knowledge Graph Construction
-Build production-ready knowledge graphs from any data source with automatic entity resolution, relationship inference, and graph optimization. Semantica constructs semantically-rich knowledge graphs that serve as the foundation for GraphRAG, AI agents, and reasoning systems.
-
-**Key Features:**
+Build production-ready knowledge graphs from any data source with automatic entity resolution, relationship inference, and graph optimization.
-| Feature | Description | Benefit |
-|---------|-------------|---------|
-| **Automatic Entity Resolution** | Merge duplicate entities across sources using semantic similarity | Clean, unified knowledge graph without duplicates |
-| **Relationship Inference** | Discover implicit relationships through graph patterns and reasoning | Richer knowledge representation with inferred connections |
-| **Graph Optimization** | Optimize graph structure for query performance and storage | Fast queries and efficient storage |
-| **Multi-Graph Support** | Build and merge graphs from multiple sources | Unified knowledge from diverse inputs |
-| **Graph Analytics** | Centrality analysis, community detection, path finding | Understand graph structure and relationships |
-| **Provenance Tracking** | Track source and confidence for every assertion | Trustworthy, auditable knowledge |
-| **Graph Validation** | Validate graph consistency and quality | Production-ready, reliable graphs |
-
-#### Automatic Graph Generation
+**Example: Building Knowledge Graph**
```python
from semantica import Semantica
-from semantica.graph import GraphBuilder
-
-core = Semantica()
-
-# Process multiple documents
-documents = [
- "financial_reports/q4_2024.pdf",
- "https://company.com/news/rss",
- "meeting_notes/*.docx",
- "emails/archive.mbox"
-]
-# Sample documents for demonstration
+# Sample documents
documents = [
- """
- Apple Inc. was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976.
- The company is headquartered in Cupertino, California. Tim Cook became CEO in 2011
- after Jobs stepped down due to health reasons. Apple designs and manufactures
- consumer electronics including the iPhone, iPad, Mac computers, and Apple Watch.
- """,
- """
- In 2014, Apple acquired Beats Electronics for $3 billion, marking its largest
- acquisition. Dr. Dre and Jimmy Iovine, co-founders of Beats, joined Apple.
- The acquisition included Beats Music which was later integrated into Apple Music.
- Apple Music now competes with Spotify and has over 100 million subscribers.
- """,
- """
- Tim Cook, Apple's current CEO, has led the company to become the world's most
- valuable company with a market capitalization exceeding $3 trillion. Under Cook's
- leadership, Apple expanded into services including Apple Music, iCloud, and the
- App Store, generating over $80 billion annually in services revenue.
- """
+ """Apple Inc. was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976.
+ The company is headquartered in Cupertino, California.""",
+
+ """In 2014, Apple acquired Beats Electronics for $3 billion. Dr. Dre and
+ Jimmy Iovine joined Apple's executive team.""",
+
+ """Tim Cook became CEO in 2011 after Jobs stepped down. Under Cook's leadership,
+ Apple expanded into services generating over $80 billion annually."""
]
-# Build unified knowledge graph
-knowledge_graph = core.build_knowledge_graph(
+# Initialize and build graph
+core = Semantica()
+kg = core.build_knowledge_graph(
sources=documents,
merge_entities=True,
resolve_conflicts=True,
@@ -729,206 +323,94 @@ knowledge_graph = core.build_knowledge_graph(
)
# Graph Statistics
-print("=== KNOWLEDGE GRAPH STATISTICS ===")
-print(f"Total Nodes: {knowledge_graph.node_count}")
-print(f"Total Edges: {knowledge_graph.edge_count}")
-print(f"Entity Types: {knowledge_graph.entity_types}")
-print(f"Relationship Types: {knowledge_graph.relationship_types}")
-print()
-
-# Output:
-# Total Nodes: 25
-# Total Edges: 38
-# Entity Types: ['Person', 'Organization', 'Product', 'Date', 'Location', 'Money', 'Service']
-# Relationship Types: ['founded', 'acquired', 'headquartered_in', 'works_for', 'co-founded', 'competes_with', 'has_subscribers']
-
-# Query the knowledge graph using natural language and graph queries
-print("=== KNOWLEDGE GRAPH QUERIES ===\n")
-
-print("Query Method 1: Natural Language Queries\n")
-# Natural language queries are automatically converted to graph queries
-
-query1 = "Who founded Apple Inc.?"
-print(f"Q1: {query1}")
-result1 = knowledge_graph.query(query1, return_format="natural")
-print(f"A1: {result1.answer}")
-print(f" Confidence: {result1.confidence:.2f}")
-print(f" Supporting Entities: {[e.name for e in result1.supporting_entities]}")
-print(f" Graph Path: {' β†’ '.join(result1.graph_path)}")
-print(f" Source Documents: {result1.source_documents}")
-print()
+print("=== GRAPH STATISTICS ===")
+print(f"Nodes: {kg.node_count}")
+print(f"Edges: {kg.edge_count}")
+print(f"Entity Types: {kg.entity_types}")
+print(f"Relationship Types: {kg.relationship_types}\n")
# Output:
-# Q1: Who founded Apple Inc.?
-# A1: Apple Inc. was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976.
-# Confidence: 0.98
-# Supporting Entities: ['Steve Jobs', 'Steve Wozniak', 'Ronald Wayne', 'Apple Inc.']
-# Graph Path: Apple Inc. β†’ founded_by β†’ Steve Jobs | Steve Wozniak | Ronald Wayne
-# Source Documents: ['doc1.txt']
-
-query2 = "What companies did Apple acquire?"
-print(f"Q2: {query2}")
-result2 = knowledge_graph.query(query2, return_format="natural")
-print(f"A2: {result2.answer}")
-print(f" Details:")
-for detail in result2.details:
- print(f" β€’ {detail}")
-print(f" Related Relationships:")
-for rel in result2.related_relationships:
- print(f" - {rel.subject} β†’ {rel.predicate} β†’ {rel.object}")
-print()
+# Nodes: 25
+# Edges: 38
+# Entity Types: ['Person', 'Organization', 'Product', 'Date', 'Location', 'Money']
+# Relationship Types: ['founded', 'acquired', 'works_for', 'headquartered_in']
+
+# Query the graph
+result = kg.query("Who founded Apple Inc.?")
+print(f"Q: Who founded Apple Inc.?")
+print(f"A: {result.answer}")
+print(f"Confidence: {result.confidence:.2f}")
+print(f"Supporting Entities: {[e.name for e in result.supporting_entities]}\n")
# Output:
-# Q2: What companies did Apple acquire?
-# A2: Apple Inc. acquired Beats Electronics for $3 billion in May 2014.
-# Details:
-# β€’ Acquisition amount: $3 billion
-# β€’ Acquisition date: May 2014
-# β€’ Largest acquisition in Apple's history
-# Related Relationships:
-# - Apple Inc. β†’ acquired β†’ Beats Electronics
-# - Beats Electronics β†’ included β†’ Beats Music
-# - Beats Electronics β†’ included β†’ Beats Electronics hardware
-
-query3 = "What products does Apple manufacture?"
-print(f"Q3: {query3}")
-result3 = knowledge_graph.query(query3, return_format="natural")
-print(f"A3: {result3.answer}")
-print(f" Product List: {result3.entity_list}")
-print()
-
-query4 = "Who is the current CEO of Apple?"
-print(f"Q4: {query4}")
-result4 = knowledge_graph.query(query4, return_format="natural")
-print(f"A4: {result4.answer}")
-print(f" CEO Information:")
-if hasattr(result4, 'entity_details'):
- for detail in result4.entity_details:
- print(f" β€’ {detail}")
-print()
-
-print("Query Method 2: Graph Query Language (Cypher/SPARQL)\n")
-
-# Direct graph queries for more complex queries
-cypher_query = """
-MATCH (p:Person)-[r:founded]->(a:Organization {name: 'Apple Inc.'})
-RETURN p.name as founder, r.confidence as confidence, r.date as date
-ORDER BY r.confidence DESC
-"""
-print(f"Query: Find all founders of Apple Inc. with details\n")
-founders_result = knowledge_graph.query_cypher(cypher_query)
-print("Results:")
-for row in founders_result:
- print(f" Founder: {row['founder']}")
- print(f" Confidence: {row['confidence']:.2f}")
- print(f" Date: {row['date']}")
- print()
+# Q: Who founded Apple Inc.?
+# A: Apple Inc. was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976.
+# Confidence: 0.98
+# Supporting Entities: ['Steve Jobs', 'Steve Wozniak', 'Ronald Wayne', 'Apple Inc.']
# Export to multiple formats
-knowledge_graph.export("output.ttl", format="turtle") # RDF/Turtle
-knowledge_graph.export("output.jsonld", format="json-ld") # JSON-LD
-knowledge_graph.to_neo4j(uri, username, password) # Neo4j
-knowledge_graph.to_neptune(endpoint) # AWS Neptune
+kg.export("output.ttl", format="turtle")
+kg.export("output.jsonld", format="json-ld")
+kg.to_neo4j("bolt://localhost:7687", "neo4j", "password")
-print("\nβœ… Knowledge graph exported to multiple formats!")
+print("βœ… Graph exported to multiple formats!")
```
-<|tool▁calls▁begin|><|tool▁call▁begin|>
-read_file
-
-#### Supported Graph Databases
-
-| Database | Type | Key Features | Use Case |
-|----------|------|--------------|----------|
-| **Neo4j** | Property Graph | Cypher queries, scalability | General purpose KG |
-| **KuzuDB** | Embedded Graph | Fast, embeddable | Local development |
-| **ArangoDB** | Multi-model | Graph + Document + K/V | Flexible schemas |
-| **Amazon Neptune** | Managed Graph | AWS integration, serverless | Cloud-native apps |
-| **TigerGraph** | Distributed | GSQL, real-time analytics | Large-scale graphs |
-| **Blazegraph** | Triple Store | SPARQL 1.1, reasoning | Semantic web apps |
-| **Apache Jena** | Triple Store | Java-based, inference | Enterprise Java |
-| **GraphDB** | Triple Store | OWL reasoning, SPARQL FedX | Research & compliance |
----
+**Advanced Graph Analytics**
-### 4. πŸ“š Ontology Generation & Management
-
-Generate formal ontologies automatically using a sophisticated 6-stage LLM-based pipeline that transforms unstructured content into W3C-compliant OWL ontologies. Semantica's ontology generation combines the speed of LLMs with the precision of symbolic reasoners for production-quality semantic models.
+```python
+from semantica.kg import GraphAnalyzer
-**Key Features:**
+analyzer = GraphAnalyzer(kg)
-- **Automatic Generation**: Transform documents into formal ontologies without manual modeling
-- **6-Stage Pipeline**: From document parsing to TTL export with validation at each stage
-- **Symbolic Validation**: HermiT/Pellet reasoner integration for consistency checking
-- **Universal Generation**: Generate ontologies from any content type using general-purpose modules
-- **Quality Assurance**: F1 scores up to 0.99 with hybrid LLM + reasoner approach
-- **Best Practices**: Follows semantic modeling guidelines for knowledge engineers
+# Centrality analysis
+influential = analyzer.compute_centrality(methods=["pagerank", "betweenness"])
+print("\nMost Influential Entities:")
+for entity, score in influential[:5]:
+ print(f" {entity}: {score:.3f}")
-#### The 6-Stage Ontology Pipeline
+# Community detection
+communities = analyzer.detect_communities(algorithm="louvain")
+print(f"\nCommunities detected: {len(communities)}")
-```
-Stage 1: Semantic Network Parsing
-β”œβ”€ Extract domain concepts from documents
-β”œβ”€ Identify relationships and hierarchies
-└─ Generate structured YAML network
-
-Stage 2: YAML-to-Definition
-β”œβ”€ Transform network into class definitions
-β”œβ”€ Define properties and attributes
-└─ Establish naming conventions
-
-Stage 3: Definition-to-Types
-β”œβ”€ Map definitions to OWL types
-β”œβ”€ Define property domains and ranges
-└─ Set cardinality constraints
-
-Stage 4: Hierarchy Generation
-β”œβ”€ Build taxonomic structures
-β”œβ”€ Establish subsumption relationships
-└─ Create multi-level hierarchies
-
-Stage 5: TTL Generation
-β”œβ”€ Generate OWL/Turtle syntax
-β”œβ”€ Add annotations and metadata
-└─ Ensure W3C compliance
-
-Stage 6: Symbolic Validation
-β”œβ”€ HermiT/Pellet reasoner validation
-β”œβ”€ Consistency checking
-└─ Refinement (F1 up to 0.99)
+# Path finding
+paths = analyzer.find_shortest_paths("Apple Inc.", "Dr. Dre", max_length=3)
+print(f"\nPaths found: {len(paths)}")
+for path in paths:
+ print(f" {' β†’ '.join(path)}")
```
-#### Ontology Generation Example
+---
-**Input Documents:**
+### 4. πŸ“š Ontology Generation & Management
+
+Generate formal ontologies automatically using a 6-stage LLM-based pipeline that transforms unstructured content into W3C-compliant OWL ontologies.
+
+**The 6-Stage Pipeline:**
-```python
-# Sample domain documents about companies and acquisitions
-documents = [
- """
- Apple Inc., founded in 1976, is a technology company headquartered in Cupertino, California.
- The company designs and manufactures consumer electronics, software, and online services.
- Apple's main products include the iPhone smartphone, iPad tablet, Mac computers, and Apple Watch.
- The company is led by CEO Tim Cook, who succeeded founder Steve Jobs in 2011.
- """,
- """
- In May 2014, Apple announced its acquisition of Beats Electronics for $3 billion.
- Beats Electronics was co-founded by Dr. Dre and Jimmy Iovine. The acquisition included
- both Beats Music streaming service and Beats Electronics hardware division.
- Dr. Dre and Iovine joined Apple's executive team after the acquisition.
- """,
- """
- Beats Music was a music streaming service launched in 2014. It was integrated into
- Apple Music in 2015. Apple Music now has over 100 million subscribers worldwide
- and competes with Spotify, Amazon Music, and other streaming platforms.
- """
-]
+```
+Stage 1: Semantic Network Parsing β†’ Extract domain concepts
+Stage 2: YAML-to-Definition β†’ Transform into class definitions
+Stage 3: Definition-to-Types β†’ Map to OWL types
+Stage 4: Hierarchy Generation β†’ Build taxonomic structures
+Stage 5: TTL Generation β†’ Generate OWL/Turtle syntax
+Stage 6: Symbolic Validation β†’ HermiT/Pellet reasoning (F1 up to 0.99)
```
-**Ontology Generation Process:**
+**Example: Automatic Ontology Generation**
```python
from semantica.ontology import OntologyGenerator, OntologyValidator
+# Sample domain documents
+documents = [
+ """Apple Inc. is a technology company that designs and manufactures consumer
+ electronics, software, and online services. Products include iPhone, iPad, Mac.""",
+
+ """Companies can acquire other companies. Apple acquired Beats Electronics for
+ $3 billion. Acquisitions involve financial transactions and integration."""
+]
+
# Initialize generator
generator = OntologyGenerator(
llm_provider="openai",
@@ -936,187 +418,63 @@ generator = OntologyGenerator(
validation_mode="hybrid" # LLM + symbolic reasoner
)
-# Generate ontology from documents
+# Generate ontology
ontology = generator.generate_from_documents(
- sources=documents, # Using the documents defined above
+ sources=documents,
quality_threshold=0.95
)
print("=== ONTOLOGY GENERATION RESULTS ===")
-print(f"Classes Generated: {len(ontology.classes)}")
-print(f"Properties Generated: {len(ontology.properties)}")
-print(f"Axioms Created: {len(ontology.axioms)}")
-print(f"Validation Score: {ontology.validation_score:.2f}")
-print()
-
-# Display generated classes with detailed information
-print("=== GENERATED CLASSES (Sample) ===\n")
-print(f"Showing {min(10, len(ontology.classes))} of {len(ontology.classes)} classes:\n")
-
-for i, cls in enumerate(ontology.classes[:10], 1):
- print(f"Class {i}: {cls.name}")
- print(f" IRI: {cls.iri}")
- print(f" Description: {cls.description}")
- print(f" Superclasses: {cls.superclasses if cls.superclasses else 'None (root class)'}")
- print(f" Subclasses: {len(cls.subclasses)} direct subclasses")
- if cls.subclasses:
- print(f" - {', '.join([sc.name for sc in cls.subclasses[:3]])}{'...' if len(cls.subclasses) > 3 else ''}")
-
- print(f" Properties ({len(cls.properties)} total):")
- for prop in cls.properties[:5]: # Show first 5 properties
- print(f" β€’ {prop.name} ({prop.type})")
- if len(cls.properties) > 5:
- print(f" ... and {len(cls.properties) - 5} more properties")
-
- # Class constraints
- if hasattr(cls, 'cardinality_constraints'):
- print(f" Constraints:")
- for constraint in cls.cardinality_constraints:
- print(f" - {constraint}")
-
- # Class instances count (if available)
- if hasattr(cls, 'instance_count'):
- print(f" Instances: {cls.instance_count} entities")
-
- print(f" Confidence: {cls.generation_confidence:.2f}")
- print()
-
-# Class hierarchy visualization
-print("\n=== CLASS HIERARCHY (Taxonomy) ===\n")
-root_classes = [cls for cls in ontology.classes if not cls.superclasses]
-for root in root_classes[:3]: # Show first 3 root classes
- print(f"{root.name}")
- for subclass in root.subclasses[:3]:
- print(f" β”œβ”€ {subclass.name}")
- for subsubclass in subclass.subclasses[:2]:
- print(f" β”‚ β”œβ”€ {subsubclass.name}")
- print()
-
-# Display generated properties with detailed metadata
-print("=== GENERATED PROPERTIES (Sample) ===\n")
-print(f"Showing {min(10, len(ontology.properties))} of {len(ontology.properties)} properties:\n")
-
+print(f"Classes: {len(ontology.classes)}")
+print(f"Properties: {len(ontology.properties)}")
+print(f"Axioms: {len(ontology.axioms)}")
+print(f"Validation Score: {ontology.validation_score:.2f}\n")
+
+# Display classes
+print("=== GENERATED CLASSES ===")
+for cls in ontology.classes[:5]:
+ print(f"\nClass: {cls.name}")
+ print(f" Superclasses: {cls.superclasses or 'None'}")
+ print(f" Properties: {len(cls.properties)}")
+ for prop in cls.properties[:3]:
+ print(f" - {prop.name} ({prop.type})")
+
+# Display properties
+print("\n=== GENERATED PROPERTIES ===")
object_props = [p for p in ontology.properties if p.type == 'ObjectProperty']
datatype_props = [p for p in ontology.properties if p.type == 'DatatypeProperty']
-print(f"Property Type Distribution:")
-print(f" Object Properties (relationships): {len(object_props)}")
-print(f" Datatype Properties (attributes): {len(datatype_props)}\n")
-
-print("Object Properties (Relationships):\n")
-for i, prop in enumerate(object_props[:5], 1):
- print(f"Property {i}: {prop.name}")
- print(f" IRI: {prop.iri}")
- print(f" Type: {prop.type} (links entities)")
- print(f" Domain (subject): {', '.join(prop.domain)}")
- print(f" Range (object): {', '.join(prop.range)}")
-
- # Property characteristics
- if hasattr(prop, 'functional'):
- print(f" Functional: {prop.functional}")
- if hasattr(prop, 'inverse_functional'):
- print(f" Inverse Functional: {prop.inverse_functional}")
- if hasattr(prop, 'transitive'):
- print(f" Transitive: {prop.transitive}")
- if hasattr(prop, 'symmetric'):
- print(f" Symmetric: {prop.symmetric}")
-
- # Cardinality constraints
- if hasattr(prop, 'min_cardinality'):
- print(f" Cardinality: min={prop.min_cardinality}, max={prop.max_cardinality}")
-
- print(f" Description: {prop.description}")
- print(f" Confidence: {prop.generation_confidence:.2f}")
- print()
-
-print("Datatype Properties (Attributes):\n")
-for i, prop in enumerate(datatype_props[:5], 1):
- print(f"Property {i}: {prop.name}")
- print(f" IRI: {prop.iri}")
- print(f" Type: {prop.type} (data values)")
- print(f" Domain: {', '.join(prop.domain)}")
- print(f" Range (datatype): {prop.range}")
- print(f" Description: {prop.description}")
- if hasattr(prop, 'default_value'):
- print(f" Default Value: {prop.default_value}")
- print()
+print(f"Object Properties: {len(object_props)}")
+for prop in object_props[:3]:
+ print(f" {prop.name}: {prop.domain} β†’ {prop.range}")
+
+print(f"\nDatatype Properties: {len(datatype_props)}")
+for prop in datatype_props[:3]:
+ print(f" {prop.name}: {prop.domain} β†’ {prop.range}")
# Validate with symbolic reasoner
validator = OntologyValidator(reasoner="hermit")
validation_report = validator.validate(ontology)
-print("=== VALIDATION REPORT ===")
+print("\n=== VALIDATION REPORT ===")
if validation_report.is_consistent:
print("βœ… Ontology is logically consistent")
- print(f"βœ… All {len(validation_report.checks)} validation checks passed")
- print(f"βœ… No contradictions found")
- print(f"βœ… Ontology is satisfiable")
- ontology.save("company_acquisition_ontology.ttl")
- print("\nβœ… Ontology saved to company_acquisition_ontology.ttl")
+ print(f"βœ… All {len(validation_report.checks)} checks passed")
+ ontology.save("domain_ontology.ttl")
+ print("\nβœ… Saved to domain_ontology.ttl")
else:
print("❌ Inconsistencies found:")
for issue in validation_report.issues:
print(f" - {issue.severity}: {issue.message}")
- print(f" Element: {issue.element}")
- print(f" Suggestion: {issue.suggestion}")
- print()
-
-# View generated TTL (Turtle) syntax
-print("=== GENERATED OWL/TTL SYNTAX (Turtle Format) ===\n")
-ttl_content = ontology.to_ttl()
-print("Full TTL file preview (first 800 characters):\n")
-print(ttl_content[:800])
-print("\n... (truncated, full file contains more classes and properties) ...\n")
-
-# Statistics about generated TTL
-print("TTL File Statistics:")
-print(f" Total lines: {len(ttl_content.splitlines())}")
-print(f" File size: {len(ttl_content)} characters")
-print(f" OWL 2.0 compliance: βœ… Valid")
-print(f" RDF syntax: βœ… Valid")
-print(f" Namespace: {ontology.namespace}")
-print()
-
-# Validation summary
-print("=== VALIDATION SUMMARY ===\n")
-print(f"βœ… Logical Consistency: {'Passed' if ontology.is_consistent else 'Failed'}")
-print(f"βœ… Satisfiability: {'All classes satisfiable' if ontology.is_satisfiable else 'Some classes unsatisfiable'}")
-print(f"βœ… No Contradictions: {'None found' if not ontology.has_contradictions else 'Contradictions detected'}")
-print(f"βœ… Quality Score: {ontology.validation_score:.2f}/1.00")
-print()
-
-if ontology.validation_score >= 0.95:
- print("πŸŽ‰ Ontology quality exceeds threshold! Ready for production use.")
-elif ontology.validation_score >= 0.85:
- print("βœ… Ontology quality is good, minor refinements recommended.")
-else:
- print("⚠️ Ontology quality below threshold, review and refinement recommended.")
-
-print(f"\nβœ… Ontology generation complete!")
-print(f"βœ… Saved to: company_acquisition_ontology.ttl")
-print(f"βœ… Ready for use in knowledge graphs, AI agents, and reasoning systems!")
```
-#### Ontology Features
-
-| Feature | Description | Standards |
-|---------|-------------|-----------|
-| **OWL 2.0 Support** | Full OWL 2 DL profiles | W3C OWL 2 |
-| **RDF 1.1** | RDF triples, graphs, datasets | W3C RDF 1.1 |
-| **RDFS** | Schema definition and inference | W3C RDFS |
-| **SKOS** | Controlled vocabularies, thesauri | W3C SKOS |
-| **Dublin Core** | Metadata standardization | DCMI Metadata Terms |
-| **Schema.org** | Web markup vocabulary | Schema.org |
-| **FOAF** | Social network ontology | FOAF Project |
-| **Symbolic Validation** | HermiT, Pellet reasoners | Formal verification |
-
---
### 5. πŸ”— Context Engineering for AI Agents
Formalize context as graphs to enable AI agents with memory, tools, and purpose:
-#### The Three Layers of Context
+**The Three Layers of Context:**
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
@@ -1141,14 +499,14 @@ Formalize context as graphs to enable AI agents with memory, tools, and purpose:
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
-#### Building Context-Aware Agents
+**Example: Building Context-Aware Agent**
```python
-from semantica.context import ContextGraphBuilder, EntityLinker, AgentMemory
+from semantica.context import ContextGraphBuilder, AgentMemory
from semantica.prompting import PromptBuilder
-from semantica.tools import ToolRegistry
+from semantica.agents import ToolRegistry
-# Build context graph from interactions
+# Build context graph from conversations
context_builder = ContextGraphBuilder()
context_graph = context_builder.build_from_conversations(
conversations=["conv_1.json", "conv_2.json"],
@@ -1156,14 +514,14 @@ context_graph = context_builder.build_from_conversations(
extract_intents=True
)
-# Agent memory management
+# Initialize agent memory
memory = AgentMemory(
vector_store="pinecone",
knowledge_graph=context_graph,
retention_policy="30_days"
)
-# Store new context
+# Store context
memory.store(
content="User prefers technical documentation over tutorials",
metadata={"user_id": "user_123", "session": "session_456"}
@@ -1176,6 +534,10 @@ relevant_context = memory.retrieve(
use_graph_expansion=True
)
+print("=== RETRIEVED CONTEXT ===")
+for ctx in relevant_context:
+ print(f"- {ctx.content} (score: {ctx.score:.2f})")
+
# Build context-aware prompt
prompt_builder = PromptBuilder()
prompt = prompt_builder.build(
@@ -1183,77 +545,23 @@ prompt = prompt_builder.build(
context=relevant_context,
user_query="Create a learning plan"
)
+
+print("\n=== GENERATED PROMPT ===")
+print(prompt)
```
---
### 6. 🎯 Knowledge Graph-Powered RAG (GraphRAG)
-Combine vector search speed with knowledge graph precision for 30% accuracy improvements:
-
-#### Hybrid Retrieval Architecture
+Combine vector search speed with knowledge graph precision for 30% accuracy improvements.
-**Example: Question Answering with GraphRAG**
-
-This comprehensive example demonstrates how GraphRAG combines vector similarity search with knowledge graph traversal to provide more accurate, context-rich answers than either method alone.
-
-**Knowledge Base Content:**
-
-Before querying, we have built a knowledge base containing:
-
-1. **Vector Embeddings**: All text chunks from documents are embedded for fast semantic similarity search
-2. **Knowledge Graph**: Entities and relationships extracted and stored in a graph structure
-
-The knowledge graph structure contains:
-
-```python
-# Sample knowledge graph structure with entities and relationships:
-#
-# ENTITIES:
-# - Apple Inc. (Organization)
-# β”œβ”€ Properties: name="Apple Inc.", founded_year=1976, headquarters="Cupertino, CA"
-# └─ Relationships:
-# β”œβ”€ founded_by β†’ [Steve Jobs, Steve Wozniak, Ronald Wayne] (date: 1976)
-# β”œβ”€ headquartered_in β†’ Cupertino, California
-# β”œβ”€ CEO β†’ Tim Cook (since 2011)
-# β”œβ”€ manufactures β†’ [iPhone, iPad, Mac computers, Apple Watch]
-# └─ acquired β†’ Beats Electronics (amount: $3B, date: 2014-05-28)
-#
-# - Beats Electronics (Organization)
-# β”œβ”€ Properties: name="Beats Electronics", founded_year=2006
-# └─ Relationships:
-# β”œβ”€ co-founded_by β†’ [Dr. Dre, Jimmy Iovine]
-# β”œβ”€ products β†’ [Beats Music (streaming service), Beats headphones]
-# └─ acquired_by β†’ Apple Inc. (2014-05-28)
-#
-# - Apple Music (Service)
-# β”œβ”€ Properties: name="Apple Music", launched_year=2015, subscribers=100M+
-# └─ Relationships:
-# β”œβ”€ launched β†’ 2015
-# β”œβ”€ integrated_from β†’ Beats Music
-# └─ competes_with β†’ [Spotify, Amazon Music, YouTube Music]
-#
-# - Steve Jobs, Steve Wozniak, Ronald Wayne, Tim Cook, Dr. Dre, Jimmy Iovine (Person entities)
-# - iPhone, iPad, Mac computers, Apple Watch (Product entities)
-# - Cupertino, California (Location entities)
-#
-# VECTOR EMBEDDINGS:
-# All text chunks from source documents are embedded using text-embedding-3-large model.
-# These embeddings enable fast semantic similarity search for initial retrieval.
-#
-# HYBRID RETRIEVAL PROCESS:
-# 1. Vector search finds semantically similar text chunks (fast)
-# 2. Extract entities from vector results
-# 3. Expand from entities using graph relationships (comprehensive)
-# 4. Rerank combined results (optimal)
-```
-
-**GraphRAG Query Example:**
+**Example: GraphRAG Query**
```python
from semantica.qa_rag import HybridRetriever, GraphRAGEngine
-# Initialize GraphRAG with both vector and graph stores
+# Initialize GraphRAG
graphrag = GraphRAGEngine(
vector_store="pinecone",
knowledge_graph="neo4j",
@@ -1263,260 +571,70 @@ graphrag = GraphRAGEngine(
# User query
query = "Who founded Apple and what major acquisitions did they make?"
-print("=== GRAPHRAG RETRIEVAL PROCESS ===\n")
-
-# Step 1: Vector search finds semantically similar content
-# This is the fast initial retrieval phase using semantic similarity
-print("Step 1: Vector Search (Fast Semantic Similarity)")
-print("=" * 60)
-print("Searching vector embeddings for semantically similar text chunks...")
-print(f"Query: '{query}'")
-print(f"Searching {graphrag.vector_store.size} embedded text chunks\n")
-
+# === STEP 1: VECTOR SEARCH ===
+print("Step 1: Vector Search")
vector_results = graphrag.vector_search(query, top_k=20)
-print(f"βœ… Found {len(vector_results)} similar text chunks\n")
-
-print("Top 5 Vector Search Results:")
-for i, result in enumerate(vector_results[:5], 1):
- print(f"\nResult {i}:")
- print(f" Text: {result.text[:150]}...")
- print(f" Similarity Score: {result.score:.3f} ({'High' if result.score > 0.85 else 'Medium' if result.score > 0.7 else 'Low'})")
- print(f" Source Document: {result.source_document}")
- print(f" Chunk Position: {result.chunk_index} of {result.total_chunks} chunks")
- if hasattr(result, 'entities'):
- print(f" Entities in chunk: {len(result.entities)}")
-print()
-
-# Output:
-# ============================================================
-# Searching vector embeddings for semantically similar text chunks...
-# Query: 'Who founded Apple and what major acquisitions did they make?'
-# Searching 1,247 embedded text chunks
-#
-# βœ… Found 20 similar text chunks
-#
-# Top 5 Vector Search Results:
-#
-# Result 1:
-# Text: Apple Inc. was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976. The company is headquartered in Cupertino...
-# Similarity Score: 0.892 (High)
-# Source Document: company_history.pdf
-# Chunk Position: 3 of 45 chunks
-# Entities in chunk: 5
-#
-# Result 2:
-# Text: In May 2014, Apple announced its acquisition of Beats Electronics for $3 billion, marking the largest acquisition...
-# Similarity Score: 0.876 (High)
-# Source Document: acquisitions_news.pdf
-# Chunk Position: 1 of 12 chunks
-# Entities in chunk: 4
-
-# Step 2: Extract entities from vector results
-# These entities will be used as "seed nodes" for graph expansion
-print("\nStep 2: Entity Extraction from Vector Results")
-print("=" * 60)
-print("Extracting entities from top vector search results...")
-print("These entities will serve as seed nodes for graph expansion.\n")
+print(f"βœ… Found {len(vector_results)} similar chunks\n")
+# === STEP 2: ENTITY EXTRACTION ===
+print("Step 2: Entity Extraction")
entities = graphrag.extract_entities(vector_results)
+print(f"βœ… Extracted {len(entities)} unique entities\n")
-print(f"βœ… Extracted {len(entities)} unique entities from vector results\n")
-print("Entity Breakdown:")
-entities_by_type = {}
-for entity in entities:
- if entity.type not in entities_by_type:
- entities_by_type[entity.type] = []
- entities_by_type[entity.type].append(entity)
-
-for entity_type, entity_list in entities_by_type.items():
- print(f" {entity_type}: {len(entity_list)} entities")
- for entity in entity_list[:3]:
- print(f" - {entity.name} (confidence: {entity.confidence:.2f})")
- if len(entity_list) > 3:
- print(f" ... and {len(entity_list) - 3} more")
- print()
-
-# Seed entities for graph expansion
-seed_entities = [e for e in entities if e.confidence > 0.85]
-print(f"Selected {len(seed_entities)} high-confidence entities as seed nodes:")
-for entity in seed_entities:
- print(f" β€’ {entity.name} ({entity.type})")
-print()
-
-# Output:
-# ============================================================
-# Extracting entities from top vector search results...
-# These entities will serve as seed nodes for graph expansion.
-#
-# βœ… Extracted 8 unique entities from vector results
-#
-# Entity Breakdown:
-# Organization: 2 entities
-# - Apple Inc. (confidence: 0.98)
-# - Beats Electronics (confidence: 0.95)
-# Person: 3 entities
-# - Steve Jobs (confidence: 0.97)
-# - Steve Wozniak (confidence: 0.94)
-# - Tim Cook (confidence: 0.92)
-# Event: 1 entities
-# - acquisition (confidence: 0.89)
-# ... and 2 more
-#
-# Selected 7 high-confidence entities as seed nodes:
-# β€’ Apple Inc. (Organization)
-# β€’ Beats Electronics (Organization)
-# β€’ Steve Jobs (Person)
-# β€’ Steve Wozniak (Person)
-# β€’ Tim Cook (Person)
-
-# Step 3: Graph expansion from seed entities
-# This is where knowledge graphs excel - following relationships to find related information
-print("\nStep 3: Knowledge Graph Expansion (Relationship Traversal)")
-print("=" * 60)
-print("Expanding from seed entities using knowledge graph relationships...")
-print("This step discovers related information that vector search might miss.\n")
-
+# === STEP 3: GRAPH EXPANSION ===
+print("Step 3: Graph Expansion")
expanded_context = graphrag.expand_graph(
- seed_entities=seed_entities,
- max_hops=2, # Explore 2 relationship hops away from seed entities
- relationship_types=["founded", "acquired", "co-founded", "works_for", "headquartered_in", "manufactures"],
- include_properties=True # Include entity properties in expansion
+ seed_entities=entities,
+ max_hops=2,
+ relationship_types=["founded", "acquired", "co-founded"]
)
+print(f"βœ… Expanded from {len(entities)} to {len(expanded_context.nodes)} nodes\n")
-print(f"βœ… Expanded context generated\n")
-print(f"Graph Expansion Statistics:")
-print(f" Seed Nodes: {len(seed_entities)}")
-print(f" Expanded Nodes: {len(expanded_context.nodes)}")
-print(f" Total Relationships: {len(expanded_context.edges)}")
-print(f" New Nodes Discovered: {len(expanded_context.nodes) - len(seed_entities)}\n")
-
-print("Expansion Paths Discovered:")
-print("\n Direct connections (1 hop):")
-direct_connections = expanded_context.get_paths_by_hops(seed_entities, max_hops=1)
-for entity, paths in list(direct_connections.items())[:3]:
- print(f" {entity.name}:")
- for path in paths[:2]:
- print(f" β†’ {path[1].predicate} β†’ {path[1].target.name}")
-print("\n Two-hop connections (2 hops):")
-two_hop_connections = expanded_context.get_paths_by_hops(seed_entities, max_hops=2)
-for entity, paths in list(two_hop_connections.items())[:2]:
- print(f" {entity.name}:")
- for path in paths[:1]:
- print(f" β†’ {path[1].predicate} β†’ {path[1].target.name}")
- if len(path) > 2:
- print(f" β†’ {path[2].predicate} β†’ {path[2].target.name}")
-print()
-
-# Output:
-# ============================================================
-# Expanding from seed entities using knowledge graph relationships...
-# This step discovers related information that vector search might miss.
-#
-# βœ… Expanded context generated
-#
-# Graph Expansion Statistics:
-# Seed Nodes: 7
-# Expanded Nodes: 15
-# Total Relationships: 23
-# New Nodes Discovered: 8
-#
-# Expansion Paths Discovered:
-#
-# Direct connections (1 hop):
-# Apple Inc.:
-# β†’ founded_by β†’ Steve Jobs
-# β†’ founded_by β†’ Steve Wozniak
-# β†’ acquired β†’ Beats Electronics
-#
-# Two-hop connections (2 hops):
-# Apple Inc.:
-# β†’ acquired β†’ Beats Electronics
-# β†’ co-founded_by β†’ Dr. Dre
-# β†’ co-founded_by β†’ Jimmy Iovine
-
-# Step 4: Hybrid retrieval combining vector + graph
-print("Step 4: Hybrid Retrieval (Vector + Graph)")
+# === STEP 4: HYBRID RETRIEVAL ===
+print("Step 4: Hybrid Retrieval")
results = graphrag.retrieve(
query=query,
- vector_top_k=20, # Start with 20 vector matches
- expand_graph=True, # Expand using knowledge graph
- max_hops=2, # Traverse 2 relationship levels
- relationship_types=["founded", "acquired", "co-founded"],
- rerank=True, # Rerank combined results
- final_top_k=5 # Return top 5 final answers
+ vector_top_k=20,
+ expand_graph=True,
+ max_hops=2,
+ rerank=True,
+ final_top_k=5
)
-# Step 5: Display comprehensive results
-print("=== FINAL GRAPHRAG RESULTS ===\n")
+# === DISPLAY RESULTS ===
+print("\n=== GRAPHRAG RESULTS ===\n")
for i, result in enumerate(results, 1):
print(f"Result {i} (Score: {result.score:.3f})")
- print(f"Text: {result.text}")
- print(f"\nGraph Context (Relationship Paths):")
- for path in result.graph_paths[:3]: # Show top 3 paths
- print(f" Path: {' β†’ '.join([n for n in path])}")
- print(f"\nRelated Entities:")
- for entity in result.related_entities[:5]:
- print(f" - {entity.name} ({entity.type})")
- print(f"\nSource Documents: {result.source_documents}")
- print("-" * 80)
- print()
-
-# Output Example:
-# Result 1 (Score: 0.945)
-# Text: Apple Inc. was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976.
-# The company's largest acquisition was Beats Electronics for $3 billion in 2014.
-# Dr. Dre and Jimmy Iovine, co-founders of Beats, joined Apple after the acquisition.
-#
-# Graph Context (Relationship Paths):
-# Path: Apple Inc. β†’ founded_by β†’ Steve Jobs
-# Path: Apple Inc. β†’ acquired β†’ Beats Electronics β†’ co-founded_by β†’ Dr. Dre
-# Path: Apple Inc. β†’ acquired β†’ Beats Electronics β†’ co-founded_by β†’ Jimmy Iovine
-#
-# Related Entities:
-# - Apple Inc. (Organization)
-# - Steve Jobs (Person)
-# - Beats Electronics (Organization)
-# - Dr. Dre (Person)
-# - Jimmy Iovine (Person)
-#
-# Source Documents: ['doc1.pdf', 'news_article.html', 'company_wiki.md']
+ print(f"Text: {result.text[:150]}...")
+ print(f"\nGraph Paths:")
+ for path in result.graph_paths[:2]:
+ print(f" {' β†’ '.join(path)}")
+ print(f"\nRelated Entities: {[e.name for e in result.related_entities[:3]]}")
+ print(f"Sources: {result.source_documents}\n")
+ print("-" * 80 + "\n")
```
-**Why GraphRAG Provides Better Answers:**
-
-Unlike vector-only RAG which might return: *"Apple was founded by Steve Jobs"* (correct but incomplete)
-
-GraphRAG returns: *"Apple Inc. was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976. The company's largest acquisition was Beats Electronics for $3 billion in May 2014, through which Dr. Dre and Jimmy Iovine joined Apple's executive team."*
-
-The graph expansion adds crucial context that vector search alone would miss!
-
-#### GraphRAG Performance Comparison
+**Performance Comparison:**
| Approach | Accuracy | Speed | Context Quality |
|----------|----------|-------|-----------------|
-| **Vector-Only RAG** | 70% | ⚑ Fast | Limited to similarity |
-| **Graph-Only** | 75% | 🐌 Slow | Rich but incomplete |
-| **GraphRAG (Hybrid)** | 91% ⭐ | ⚑ Fast | Best of both worlds |
-
-**Why GraphRAG Wins:**
-- βœ… Vector search finds semantically similar content (fast)
-- βœ… Graph expansion adds relationship context (comprehensive)
-- βœ… Hybrid reranking balances relevance and completeness
-- βœ… 30% accuracy improvement over vector-only approaches
+| Vector-Only RAG | 70% | ⚑ 50ms | ⭐⭐⭐ |
+| Graph-Only | 75% | 🐌 300ms | ⭐⭐⭐⭐ |
+| **GraphRAG (Hybrid)** | **91%** ⭐ | ⚑ 80ms | ⭐⭐⭐⭐⭐ |
---
### 7. πŸ€– Multi-Agent System Infrastructure
-Enable AI agents to coordinate through shared semantic models:
+Enable AI agents to coordinate through shared semantic models.
-#### Multi-Agent Coordination
+**Example: Multi-Agent Coordination**
```python
from semantica.agents import MultiAgentSystem, AgentCoordinator
from semantica.ontology import SharedOntologyManager
-# Create shared ontology for agent coordination
+# Load shared ontology
ontology_manager = SharedOntologyManager()
ontology = ontology_manager.load("domain_ontology.ttl")
@@ -1526,7 +644,7 @@ mas = MultiAgentSystem(
coordination_mode="semantic"
)
-# Define agents with specialized roles
+# Create specialized agents
research_agent = mas.create_agent(
role="researcher",
capabilities=["web_search", "document_analysis"],
@@ -1545,7 +663,7 @@ writing_agent = mas.create_agent(
constraints=ontology_manager.get_constraints("writing_operations")
)
-# Coordinate multi-agent workflow
+# Coordinate workflow
coordinator = AgentCoordinator(
agents=[research_agent, analysis_agent, writing_agent],
workflow_graph=workflow_definition
@@ -1554,36 +672,28 @@ coordinator = AgentCoordinator(
# Execute coordinated task
result = coordinator.execute_workflow(
task="Create a comprehensive market analysis report",
- validation_mode="ontology_based" # Validate against shared ontology
+ validation_mode="ontology_based"
)
-```
-
-#### Multi-Agent Features
-| Feature | Description | Benefit |
-|---------|-------------|---------|
-| **Shared Ontologies** | Common semantic models for all agents | Consistent understanding |
-| **Semantic Routing** | Intent-based task assignment | Efficient coordination |
-| **Constraint Validation** | Real-time action validation | Prevent invalid operations |
-| **Context Sharing** | Shared knowledge graphs | Coordinated decision-making |
-| **Conflict Resolution** | Automatic conflict detection & resolution | Reliable operations |
+print(f"βœ… Workflow completed")
+print(f"Tasks executed: {len(result.completed_tasks)}")
+print(f"Validation status: {result.validation_status}")
+```
---
### 8. πŸ”§ Production-Ready Quality Assurance
-Enterprise-grade validation, conflict detection, and quality scoring:
+Enterprise-grade validation, conflict detection, and quality scoring.
#### The Four Critical QA Features
-##### 1. Schema Template Enforcement
-
-**Problem**: Libraries invent entities instead of following business schemas
+**1. Schema Template Enforcement**
```python
from semantica.templates import SchemaTemplate
-# Define fixed business schema
+# Define business schema
company_schema = SchemaTemplate(
name="company_knowledge_graph",
entities={
@@ -1594,30 +704,25 @@ company_schema = SchemaTemplate(
"Person": {
"required_properties": ["name", "role"],
"optional_properties": ["email", "department"]
- },
- "Product": {
- "required_properties": ["name", "category"],
- "optional_properties": ["price", "launch_date"]
}
},
relationships={
"works_for": {"domain": "Person", "range": "Company"},
- "produces": {"domain": "Company", "range": "Product"},
- "founded_by": {"domain": "Company", "range": "Person"}
+ "produces": {"domain": "Company", "range": "Product"}
}
)
# Enforce schema during extraction
-knowledge_base = core.build_knowledge_base(
+kb = core.build_knowledge_base(
sources=documents,
schema_template=company_schema,
- strict_mode=True # Reject entities not in schema
+ strict_mode=True
)
-```
-##### 2. Seed Data System
+print(f"βœ… Schema enforcement: {kb.compliance_rate:.1f}% compliant")
+```
-**Problem**: AI guesses information instead of building on known facts
+**2. Seed Data System**
```python
from semantica.seed import SeedManager
@@ -1627,77 +732,61 @@ seed_manager = SeedManager()
# Load verified data
seed_manager.load_from_csv("verified_companies.csv")
seed_manager.load_from_json("hr_database.json")
-seed_manager.load_from_xlsx("product_catalog.xlsx")
-# Create foundation graph from seed data
-foundation_graph = seed_manager.build_foundation_graph(
- schema=company_schema
-)
+# Build foundation graph
+foundation_graph = seed_manager.build_foundation_graph(schema=company_schema)
-# Build on top of verified foundation
-knowledge_base = core.build_knowledge_base(
+# Build on verified foundation
+kb = core.build_knowledge_base(
sources=["new_documents/"],
foundation_graph=foundation_graph
)
-# Result: Reduced hallucinations by building on verified facts
+print(f"βœ… Foundation entities: {foundation_graph.node_count}")
+print(f"βœ… New entities: {kb.node_count - foundation_graph.node_count}")
```
-##### 3. Advanced Deduplication
-
-**Problem**: Messy graphs with duplicates like "Q1 2024" vs "First Quarter 2024"
+**3. Advanced Deduplication**
```python
-from semantica.deduplication import DuplicateDetector, EntityMerger, SimilarityCalculator
+from semantica.deduplication import DuplicateDetector, EntityMerger
# Detect duplicates
-duplicate_detector = DuplicateDetector()
-similarity_calc = SimilarityCalculator(threshold=0.85)
-
-duplicates = duplicate_detector.find_duplicates(
- entities=knowledge_base.entities,
- similarity_calculator=similarity_calc
+detector = DuplicateDetector()
+duplicates = detector.find_duplicates(
+ entities=kb.entities,
+ similarity_threshold=0.85
)
# Merge duplicates
-entity_merger = EntityMerger()
-merged = entity_merger.merge_duplicates(
+merger = EntityMerger()
+merged = merger.merge_duplicates(
duplicates=duplicates,
strategy="highest_confidence"
)
-print(f"Found {len(duplicates)} duplicate groups")
-print(f"Merged into {len(merged)} canonical entities")
+print(f"βœ… Found {len(duplicates)} duplicate groups")
+print(f"βœ… Merged into {len(merged)} canonical entities")
```
-##### 4. Conflict Detection & Resolution
-
-**Problem**: Sources disagree but no flagging or provenance tracking
+**4. Conflict Detection & Resolution**
```python
-from semantica.conflicts import ConflictDetector, SourceTracker, ConflictResolver
+from semantica.conflicts import ConflictDetector, ConflictResolver
-# Detect value conflicts
-conflict_detector = ConflictDetector()
-conflicts = conflict_detector.detect_conflicts(
- entities=knowledge_base.entities,
- properties=["revenue", "employee_count", "founded_year"]
+# Detect conflicts
+detector = ConflictDetector()
+conflicts = detector.detect_conflicts(
+ entities=kb.entities,
+ properties=["revenue", "employee_count"]
)
-# Track source provenance
-source_tracker = SourceTracker()
+print(f"⚠️ Found {len(conflicts)} conflicts\n")
for conflict in conflicts:
- sources = source_tracker.get_sources(
- entity=conflict.entity,
- property=conflict.property
- )
-
- print(f"Conflict detected for {conflict.entity.name}.{conflict.property}:")
- for source in sources:
- print(f" Source: {source.name}")
- print(f" Value: {source.value}")
- print(f" Confidence: {source.confidence}")
+ print(f"Conflict: {conflict.entity.name}.{conflict.property}")
+ print(f" Values: {conflict.values}")
+ print(f" Sources: {conflict.sources}\n")
# Resolve conflict
resolver = ConflictResolver()
@@ -1705,38 +794,28 @@ for conflict in conflicts:
conflict=conflict,
strategy="most_recent"
)
+ print(f" βœ… Resolved: {resolution.chosen_value}\n")
```
-#### Comprehensive Quality Scoring
+**Comprehensive Quality Scoring**
```python
from semantica.kg_qa import QualityAssessor
-from semantica.quality import QualityEngine
-# Quality assessment
+# Assess quality
assessor = QualityAssessor()
-quality_report = assessor.assess(knowledge_base)
-
-# Quality engine validation
-quality_engine = QualityEngine()
-validation_results = quality_engine.validate(knowledge_base)
-
-print(f"Overall Score: {quality_report.overall_score}/100")
-print(f"\nDetailed Scores:")
-print(f" Completeness: {quality_report.completeness_score}/100")
-print(f" Consistency: {quality_report.consistency_score}/100")
-print(f" Accuracy: {quality_report.accuracy_score}/100")
-
-print(f"\nIssues Found:")
-print(f" Duplicates: {quality_report.duplicate_count}")
-print(f" Conflicts: {quality_report.conflict_count}")
-
-# Validation results
-for result in validation_results:
- print(f" {result.check_name}: {result.status}")
- if result.issues:
- for issue in result.issues:
- print(f" - {issue}")
+report = assessor.assess(kb)
+
+print("=== QUALITY REPORT ===")
+print(f"Overall Score: {report.overall_score}/100\n")
+print("Detailed Scores:")
+print(f" Completeness: {report.completeness_score}/100")
+print(f" Consistency: {report.consistency_score}/100")
+print(f" Accuracy: {report.accuracy_score}/100\n")
+print("Issues:")
+print(f" Duplicates: {report.duplicate_count}")
+print(f" Conflicts: {report.conflict_count}")
+print(f" Missing properties: {report.missing_property_count}")
```
---
@@ -1749,7 +828,6 @@ for result in validation_results:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ SEMANTICA FRAMEWORK β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ DATA INGESTION LAYER β”‚ β”‚
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
@@ -1759,6 +837,15 @@ for result in validation_results:
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ ↓ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
+β”‚ β”‚ SEMANTIC PROCESSING LAYER β”‚ β”‚
+β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
+β”‚ β”‚ β”‚ Parse β”‚ Normalize β”‚ Extract β”‚ Build Graph β”‚ β”‚ β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ Semantics β”‚ β”‚ β”‚ β”‚
+β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
+β”‚ β”‚ NLP β€’ Embeddings β€’ Ontologies β€’ Quality Assurance β”‚ β”‚
+β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
+β”‚ ↓ β”‚
+β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ APPLICATION LAYER β”‚ β”‚
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
β”‚ β”‚ β”‚ GraphRAG β”‚ AI Agents β”‚Multi-Agent β”‚ Analytics β”‚ β”‚ β”‚
@@ -1766,127 +853,73 @@ for result in validation_results:
β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
β”‚ β”‚ Hybrid Retrieval β€’ Context Engineering β€’ Reasoning β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
-β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
### Module Architecture
-Semantica consists of **29 production-ready modules** organized into logical layers:
-
-#### Core & Infrastructure Modules (5 modules)
-
-| Module | Purpose | Key Components |
-|--------|---------|----------------|
-| `semantica.core` | Framework orchestration | Orchestrator, Config Manager, Lifecycle, Plugin Registry |
-| `semantica.pipeline` | Pipeline management | Pipeline Builder, Execution Engine, Resource Scheduler |
-| `semantica.utils` | Shared utilities | Helper functions, common utilities |
-| `semantica.monitoring` | System monitoring | Metrics Collector, Analytics Dashboard, Performance Monitor, Health Checker |
-| `semantica.security` | Security & access | Access Control |
-
-#### Data Processing Modules (5 modules)
-
-| Module | Purpose | Supported Formats |
-|--------|---------|------------------|
-| `semantica.ingest` | Data ingestion | File, Web, Email, Feed, DB, Stream, Repo |
-| `semantica.parse` | Document parsing | PDF, DOCX, XLSX, PPTX, HTML, JSON, XML, CSV, Excel, Email, Image, Media, Code |
-| `semantica.normalize` | Data normalization | Text, Entity, Date, Number normalization, Cleaning, Encoding |
-| `semantica.split` | Document chunking | Context-aware segmentation, chunking strategies |
-| `semantica.streaming` | Real-time processing | Stream Processor, Monitor, Aggregator, Transformer |
-
-#### Semantic Intelligence Modules (4 modules)
-
-| Module | Purpose | Key Features |
-|--------|---------|--------------|
-| `semantica.semantic_extract` | Semantic extraction | Named Entity Recognition, Relation Extraction, Event Detection, Coreference Resolution, Triple Extraction, Semantic Analysis |
-| `semantica.embeddings` | Vector embeddings | Text, Image, Audio, Multimodal embeddings, Embedding optimization |
-| `semantica.ontology` | Ontology generation | Ontology Generator, Class Inferrer, Property Generator, Validator, OWL Generator, Requirements Spec, Competency Questions |
-| `semantica.vocabulary` | Vocabulary management | Vocabulary Manager, Controlled Vocabularies, SKOS support |
-
-#### Knowledge Graph Modules (3 modules)
-
-| Module | Purpose | Technologies |
-|--------|---------|--------------|
-| `semantica.kg` | Graph construction & analysis | Graph Builder, Analyzer, Validator, Entity Resolver, Deduplicator, Centrality, Community Detection |
-| `semantica.triple_store` | RDF storage | Blazegraph, Virtuoso, Apache Jena, GraphDB, SPARQL |
-| `semantica.vector_store` | Vector storage | Pinecone, FAISS, Qdrant, Weaviate, Chroma |
-
-#### AI Application Modules (6 modules)
-
-| Module | Purpose | Use Cases |
-|--------|---------|-----------|
-| `semantica.qa_rag` | Knowledge Graph-Powered RAG | RAG Manager, Hybrid Retriever, Context Builder, Memory Store |
-| `semantica.context` | Context engineering | Context Graph, Entity Linker, Agent Memory, Context Retriever |
-| `semantica.prompting` | Prompt engineering | Prompt Builder |
-| `semantica.agents` | Agent infrastructure | Tool Registry |
-| `semantica.reasoning` | Reasoning & inference | Knowledge graph reasoning engines |
-| `semantica.quality` | Quality assurance | Quality Engine |
-
-#### Quality Assurance Modules (5 modules)
-
-| Module | Purpose | Key Features |
-|--------|---------|--------------|
-| `semantica.templates` | Schema templates | Schema Template enforcement |
-| `semantica.seed` | Seed data management | Pre-verified data foundation |
-| `semantica.deduplication` | Entity deduplication | Duplicate Detector, Entity Merger, Similarity Calculator, Merge Strategy, Cluster Builder |
-| `semantica.conflicts` | Conflict detection | Conflict Detector, Source Tracker, Conflict Resolver, Investigation Guide, Conflict Analyzer |
-| `semantica.kg_qa` | Knowledge graph QA | Quality Assessor |
-
-#### Export & Utilities Modules (2 modules)
-
-| Module | Purpose | Export Formats |
-|--------|---------|----------------|
-| `semantica.export` | Data export | JSON, RDF, YAML, CSV, Graph, Reports |
-| `semantica.utils` | Shared utilities | Common helper functions |
+**29 Production-Ready Modules Organized into Logical Layers:**
+
+#### Core & Infrastructure (5 modules)
+- `semantica.core` - Framework orchestration
+- `semantica.pipeline` - Pipeline management
+- `semantica.utils` - Shared utilities
+- `semantica.monitoring` - System monitoring
+- `semantica.security` - Access control
+
+#### Data Processing (5 modules)
+- `semantica.ingest` - Universal data ingestion
+- `semantica.parse` - Document parsing
+- `semantica.normalize` - Data normalization
+- `semantica.split` - Document chunking
+- `semantica.streaming` - Real-time processing
+
+#### Semantic Intelligence (4 modules)
+- `semantica.semantic_extract` - Entity & relation extraction
+- `semantica.embeddings` - Vector embeddings
+- `semantica.ontology` - Ontology generation
+- `semantica.vocabulary` - Vocabulary management
+
+#### Knowledge Graph (3 modules)
+- `semantica.kg` - Graph construction & analysis
+- `semantica.triple_store` - RDF storage
+- `semantica.vector_store` - Vector storage
+
+#### AI Applications (6 modules)
+- `semantica.qa_rag` - GraphRAG engine
+- `semantica.context` - Context engineering
+- `semantica.prompting` - Prompt engineering
+- `semantica.agents` - Agent infrastructure
+- `semantica.reasoning` - Reasoning & inference
+- `semantica.quality` - Quality assurance
+
+#### Quality Assurance (5 modules)
+- `semantica.templates` - Schema templates
+- `semantica.seed` - Seed data management
+- `semantica.deduplication` - Entity deduplication
+- `semantica.conflicts` - Conflict detection
+- `semantica.kg_qa` - Knowledge graph QA
+
+#### Export & Utilities (1 module)
+- `semantica.export` - Multi-format export
---
## πŸš€ Quick Start
-### Installation Options
-
-#### Option 1: Complete Installation (Recommended)
-
-Install with all features and format support:
+### Installation
```bash
+# Complete installation (recommended)
pip install "semantica[all]"
-```
-
-#### Option 2: Lightweight Installation
-
-Minimal installation for basic features:
-```bash
+# Lightweight installation
pip install semantica
-```
-
-#### Option 3: Custom Installation
-
-Install specific feature sets:
-
-```bash
-# PDF and Office documents
-pip install "semantica[pdf,office]"
-
-# Web scraping and feeds
-pip install "semantica[web,feeds]"
-# Graph databases
-pip install "semantica[neo4j,kuzu]"
+# Custom installation
+pip install "semantica[pdf,office,web,neo4j,ai]"
-# AI and ML features
-pip install "semantica[ai,ml]"
-
-# Quality assurance
-pip install "semantica[qa]"
-```
-
-#### Option 4: Development Installation
-
-For contributors and developers:
-
-```bash
+# Development installation
git clone https://github.com/semantica/semantica.git
cd semantica
pip install -e ".[dev,test,docs]"
@@ -1894,18 +927,7 @@ pip install -e ".[dev,test,docs]"
### Quick Start Examples
-#### Example 1: Basic Document Processing with Detailed Text Output
-
-**Input Document:** `company_news.txt`
-
-```
-Apple Inc. announced today that it has acquired Beats Electronics for $3 billion.
-This marks Apple's largest acquisition in its history. Dr. Dre and Jimmy Iovine,
-co-founders of Beats, will join Apple's executive team. The acquisition includes
-both Beats Music streaming service and Beats Electronics hardware division.
-```
-
-**Processing Example:**
+#### Example 1: Process Single Document
```python
from semantica import Semantica
@@ -1913,225 +935,58 @@ from semantica import Semantica
# Initialize
core = Semantica()
-# Process a single document
+# Process document
result = core.process("company_news.txt")
-# Access extracted information
-print("=== EXTRACTION RESULTS ===\n")
-print(f"Entities Extracted: {len(result.entities)}")
-print(f"Relationships Found: {len(result.relationships)}")
-print(f"Semantic Triples: {len(result.triples)}")
-print()
+# Display results
+print(f"Entities: {len(result.entities)}")
+print(f"Relationships: {len(result.relationships)}")
+print(f"Triples: {len(result.triples)}")
-# Display detailed entities
-print("=== EXTRACTED ENTITIES ===")
for entity in result.entities:
- print(f"- {entity.text} ({entity.type}, confidence: {entity.confidence:.2f})")
-# Output:
-# - Apple Inc. (Organization, confidence: 0.98)
-# - Beats Electronics (Organization, confidence: 0.95)
-# - $3 billion (Money, confidence: 0.99)
-# - Dr. Dre (Person, confidence: 0.97)
-# - Jimmy Iovine (Person, confidence: 0.94)
-# - Beats Music (Service, confidence: 0.91)
-# - Beats Electronics hardware division (Product, confidence: 0.89)
-
-print("\n=== EXTRACTED RELATIONSHIPS ===\n")
-print(f"Total relationships extracted: {len(result.relationships)}\n")
-print("Relationship Details:\n")
-
-for i, rel in enumerate(result.relationships, 1):
- print(f"Relationship {i}:")
- print(f" Subject: '{rel.subject}' ({rel.subject_type})")
- print(f" Predicate: '{rel.predicate}'")
- print(f" Object: '{rel.object}' ({rel.object_type})")
- print(f" Confidence: {rel.confidence:.2f}")
- print(f" Source Text: \"{rel.source_text}\"")
-
- # Temporal information
- if rel.temporal:
- print(f" Temporal: {rel.temporal}")
-
- # Relationship properties
- if hasattr(rel, 'negation') and rel.negation:
- print(f" ⚠️ Negated relationship")
- if hasattr(rel, 'certainty'):
- print(f" Certainty: {rel.certainty}")
- if hasattr(rel, 'extraction_method'):
- print(f" Extraction Method: {rel.extraction_method}")
-
- print()
-
-print("\n=== GENERATED TRIPLES ===")
-for triple in result.triples[:5]:
- print(f" {triple}")
-# Output:
-# (<Apple_Inc>, <acquired>, <Beats_Electronics>)
-# (<acquisition>, <hasAmount>, "$3B")
-# (<Dr_Dre>, <coFounded>, <Beats_Electronics>)
-# (<Jimmy_Iovine>, <coFounded>, <Beats_Electronics>)
-# (<Beats_Electronics>, <includes>, <Beats_Music>)
+ print(f"- {entity.text} ({entity.type}, {entity.confidence:.2f})")
-# Export results
+# Export
result.export("output.json")
-print("\nβœ… Results exported to output.json")
```
-#### Example 2: Build Knowledge Graph from Multiple Text Sources
-
-**Input Documents:**
+#### Example 2: Build Knowledge Graph
```python
-documents = {
- "doc1.txt": """
- TechCorp Inc. was founded in 2010 by Sarah Johnson and Michael Chen.
- The company is headquartered in San Francisco, California. Sarah Johnson
- serves as CEO while Michael Chen is the Chief Technology Officer.
- """,
- "doc2.txt": """
- In 2019, TechCorp acquired DataViz Analytics for $500 million. DataViz
- Analytics was founded by David Kim in 2015 and specialized in data
- visualization software. Following the acquisition, David Kim joined
- TechCorp as VP of Analytics.
- """,
- "doc3.txt": """
- TechCorp's flagship product is CloudSuite, launched in 2012. CloudSuite
- provides integrated enterprise software solutions. The company also
- offers TechSuite Analytics, which was enhanced with DataViz technology
- after the 2019 acquisition.
- """
-}
-```
+from semantica import Semantica
-**Knowledge Graph Construction:**
+# Multiple documents
+documents = ["doc1.txt", "doc2.txt", "doc3.txt"]
-```python
-from semantica import Semantica
+# Build graph
+core = Semantica(graph_db="neo4j")
+kg = core.build_knowledge_graph(documents)
-# Initialize with graph database
-core = Semantica(
- graph_db="neo4j",
- neo4j_uri="bolt://localhost:7687",
- neo4j_user="neo4j",
- neo4j_password="password"
-)
+# Statistics
+print(f"Nodes: {kg.node_count}")
+print(f"Edges: {kg.edge_count}")
-# Save documents
-for filename, content in documents.items():
- with open(filename, "w") as f:
- f.write(content)
-
-# Process multiple sources
-sources = ["doc1.txt", "doc2.txt", "doc3.txt"]
-
-# Build knowledge graph
-print("=== BUILDING KNOWLEDGE GRAPH ===\n")
-kg = core.build_knowledge_graph(sources)
-
-print(f"βœ… Graph created successfully!\n")
-print(f"Graph Structure:")
-print(f" Total Nodes: {kg.node_count}")
-print(f" Total Edges: {kg.edge_count}")
-print(f" Average Degree: {kg.edge_count / kg.node_count:.2f} connections per node")
-print(f" Connected Components: {kg.connected_components}")
-print(f" Density: {kg.density:.4f}")
-print()
-
-print(f"Entity Type Distribution:")
-entity_type_counts = kg.get_entity_type_counts()
-for entity_type, count in sorted(entity_type_counts.items(), key=lambda x: x[1], reverse=True):
- percentage = (count / kg.node_count) * 100
- print(f" {entity_type}: {count} entities ({percentage:.1f}%)")
-print()
-
-print(f"Relationship Type Distribution:")
-rel_type_counts = kg.get_relationship_type_counts()
-for rel_type, count in sorted(rel_type_counts.items(), key=lambda x: x[1], reverse=True):
- print(f" {rel_type}: {count} relationships")
-print()
-
-# Graph quality metrics
-print(f"Graph Quality Metrics:")
-print(f" Entity Resolution: {kg.entity_resolution_rate:.1f}% duplicates merged")
-print(f" Conflict Resolution: {kg.conflict_resolution_rate:.1f}% conflicts resolved")
-print(f" Average Entity Confidence: {kg.average_entity_confidence:.2f}")
-print(f" Average Relationship Confidence: {kg.average_relationship_confidence:.2f}")
-print(f" Graph Completeness: {kg.completeness_score:.1f}%")
-print()
-
-# Query the graph with natural language
-print("=== KNOWLEDGE GRAPH QUERIES ===\n")
-
-query1 = "Who founded TechCorp?"
-result1 = kg.query(query1)
-print(f"Q: {query1}")
-print(f"A: {result1.answer}")
-print(f" Entities: {[e.name for e in result1.entities]}")
-print()
-# Output:
-# Q: Who founded TechCorp?
-# A: TechCorp Inc. was founded by Sarah Johnson and Michael Chen in 2010.
-# Entities: ['TechCorp Inc.', 'Sarah Johnson', 'Michael Chen']
-
-query2 = "What companies did TechCorp acquire?"
-result2 = kg.query(query2)
-print(f"Q: {query2}")
-print(f"A: {result2.answer}")
-print(f" Graph Path: {result2.graph_path}")
-print()
-# Output:
-# Q: What companies did TechCorp acquire?
-# A: TechCorp acquired DataViz Analytics for $500 million in 2019.
-# Graph Path: TechCorp β†’ acquired β†’ DataViz Analytics
-
-query3 = "What products does TechCorp offer?"
-result3 = kg.query(query3)
-print(f"Q: {query3}")
-print(f"A: {result3.answer}")
-print()
-# Output:
-# Q: What products does TechCorp offer?
-# A: TechCorp offers CloudSuite (launched 2012) and TechSuite Analytics.
-
-# Advanced graph query with Cypher
-print("=== ADVANCED CYPHER QUERIES ===\n")
-cypher_query = "MATCH (c:Organization {name: 'TechCorp Inc.'})-[r:ACQUIRED]->(target) RETURN target.name, r.amount, r.date"
-results = kg.query_cypher(cypher_query)
-print("Acquisition Details:")
-for row in results:
- print(f" Company: {row['target.name']}")
- print(f" Amount: {row['r.amount']}")
- print(f" Date: {row['r.date']}")
- print()
-# Output:
-# Acquisition Details:
-# Company: DataViz Analytics
-# Amount: $500 million
-# Date: 2019
-
-# Visualize
-kg.visualize(output="knowledge_graph.html")
-print("\nβœ… Knowledge graph visualized in knowledge_graph.html")
+# Query
+result = kg.query("Who founded the company?")
+print(result.answer)
```
#### Example 3: GraphRAG Setup
```python
from semantica import Semantica
-from semantica.rag import GraphRAGEngine
+from semantica.qa_rag import GraphRAGEngine
-# Initialize with vector and graph stores
+# Initialize with stores
core = Semantica(
vector_store="pinecone",
- graph_db="neo4j",
- embedding_model="text-embedding-3-large"
+ graph_db="neo4j"
)
# Build knowledge base
kb = core.build_knowledge_base(
sources=["documents/"],
- generate_embeddings=True,
- build_graph=True
+ generate_embeddings=True
)
# Initialize GraphRAG
@@ -2140,65 +995,39 @@ graphrag = GraphRAGEngine(
knowledge_graph=kb.graph
)
-# Query with hybrid retrieval
-response = graphrag.query(
- query="What are the main research findings?",
- use_vectors=True,
- use_graph=True,
- max_results=5
-)
-
+# Query
+response = graphrag.query("What are the main findings?")
print(response.answer)
-print(f"Sources: {len(response.sources)}")
```
-#### Example 4: Production Setup with Quality Assurance
+#### Example 4: Production Setup with QA
```python
from semantica import Semantica
from semantica.templates import SchemaTemplate
from semantica.seed import SeedDataManager
-from semantica.qa import QualityAssessor
-# Define business schema
-schema = SchemaTemplate.from_file("company_schema.yaml")
-
-# Load seed data
+# Load schema and seed data
+schema = SchemaTemplate.from_file("schema.yaml")
seed_manager = SeedDataManager()
seed_manager.load_from_database("postgresql://...")
foundation = seed_manager.create_foundation(schema)
-# Initialize with all QA features
-core = Semantica(
- graph_db="neo4j",
- quality_assurance=True,
- conflict_detection=True,
- deduplication=True,
- validation_mode="strict"
-)
-
-# Build knowledge base with QA
+# Build with QA
+core = Semantica(quality_assurance=True)
kb = core.build_knowledge_base(
- sources=["new_data/"],
+ sources=["data/"],
schema_template=schema,
foundation_graph=foundation,
enable_all_qa=True
)
# Assess quality
+from semantica.kg_qa import QualityAssessor
assessor = QualityAssessor()
report = assessor.assess(kb)
print(f"Quality Score: {report.overall_score}/100")
-print(f"Issues: {report.total_issues}")
-
-# Auto-fix issues
-if report.has_fixable_issues:
- kb = assessor.auto_fix(kb, report)
- print("βœ… Issues fixed automatically")
-
-# Deploy to production
-kb.deploy(environment="production")
```
---
@@ -2207,551 +1036,258 @@ kb.deploy(environment="production")
### 1. 🏒 Enterprise Knowledge Engineering
-**Challenge**: Process diverse enterprise data sources and build unified knowledge graphs.
-
-**Solution**: Use Semantica's universal processing modules to ingest and process any enterprise data source.
-
-**Example: Enterprise Document Processing**
+**Challenge:** Process diverse enterprise data sources and build unified knowledge graphs.
```python
from semantica import Semantica
from semantica.ingest import FileIngestor, WebIngestor, DBIngestor
-from semantica.parse import PDFParser, DOCXParser, HTMLParser
-# Initialize (works for any enterprise data)
+# Initialize
core = Semantica(graph_db="neo4j")
-# Step 1: Ingest from enterprise sources using universal ingestors
-file_ingestor = FileIngestor()
-web_ingestor = WebIngestor()
-db_ingestor = DBIngestor()
-
-sources = []
-sources.extend(file_ingestor.ingest("/shared/documents/"))
-sources.extend(file_ingestor.ingest("/shared/projects/"))
-sources.extend(web_ingestor.ingest("https://confluence.company.com/api"))
-sources.extend(db_ingestor.ingest("postgresql://db", query="SELECT * FROM articles"))
-
-print(f"βœ… Ingested {len(sources)} enterprise sources")
+# Multi-source ingestion
+sources = [
+ *FileIngestor().ingest("/shared/documents/"),
+ *WebIngestor().ingest("https://confluence.company.com/api"),
+ *DBIngestor().ingest("postgresql://db", query="SELECT * FROM articles")
+]
-# Step 2: Process all through universal pipeline
-knowledge_graph = core.build_knowledge_graph(
+# Build unified graph
+kg = core.build_knowledge_graph(
sources=sources,
merge_entities=True,
- resolve_conflicts=True,
- generate_embeddings=True
+ resolve_conflicts=True
)
-# Enterprise features using universal modules:
-# - Single source of truth (unified graph)
-# - Cross-departmental search (universal query)
-# - Automatic relationship discovery (general-purpose extraction)
-# - Version tracking (core module features)
-# - Access control (security module)
+print(f"βœ… Enterprise knowledge graph: {kg.node_count} nodes")
```
-**Processing Modules Used**:
-- βœ… `semantica.ingest`: Universal data ingestion from files, web, databases
-- βœ… `semantica.parse`: Document parsing (PDF, DOCX, HTML, etc.)
-- βœ… `semantica.kg`: Knowledge graph construction (domain-agnostic)
-
-**Business Impact**:
-- πŸ” **80% faster information discovery**
-- πŸ”— **Automatic cross-reference detection**
-- πŸ“Š **Real-time enterprise dashboards**
-- πŸ”’ **Compliance and governance**
-
----
+**Impact:** 80% faster information discovery, automatic cross-reference detection
### 2. πŸ€– AI Agents & Autonomous Systems
-**Challenge**: Build AI agents that can process diverse data sources and make informed decisions.
-
-**Solution**: Use universal processing modules to build agent-ready knowledge infrastructure.
-
-**Example: Building Agent Knowledge Base**
+**Challenge:** Build AI agents with access to structured knowledge.
```python
from semantica import Semantica
from semantica.agents import AgentManager
-from semantica.ingest import FileIngestor, DBIngestor
-from semantica.ontology import OntologyGenerator
-# Step 1: Build knowledge base from diverse sources
+# Build knowledge base
core = Semantica()
-ingestor = FileIngestor()
-db_ingestor = DBIngestor()
-
-# Ingest from various sources (any domain)
-sources = []
-sources.extend(ingestor.ingest("documents/"))
-sources.extend(db_ingestor.ingest("postgresql://db", query="SELECT * FROM data"))
-
-# Build knowledge graph (universal process)
kb = core.build_knowledge_base(
- sources=sources,
+ sources=["documents/"],
extract_entities=True,
- extract_relationships=True,
- build_graph=True,
- generate_embeddings=True
-)
-
-# Step 2: Generate ontology (general-purpose)
-ontology_generator = OntologyGenerator()
-ontology = ontology_generator.generate_from_documents(sources, quality_threshold=0.95)
-
-# Step 3: Initialize agent with knowledge
-agent_manager = AgentManager(
- knowledge_graph=kb.graph,
- shared_ontology=ontology
+ build_graph=True
)
-# Create agent (works for any domain)
+# Create agent with knowledge
+agent_manager = AgentManager(knowledge_graph=kb.graph)
agent = agent_manager.create_agent(
role="data_analyst",
- capabilities=["query_graph", "generate_reports", "detect_patterns"]
+ capabilities=["query_graph", "generate_reports"]
)
-# Agent uses universal modules to:
-# 1. Query knowledge graph
-# 2. Extract insights using semantic extraction
-# 3. Generate reports using universal formatting
-# 4. Detect patterns using graph analytics
-
-result = agent.analyze("Show me trends and patterns in the data")
+# Agent analyzes data
+result = agent.analyze("Show me trends in the data")
print(result.report)
```
-**Gartner Prediction**: By 2028, 15% of business decisions will be made autonomously through agentic AI.
-
----
-
### 3. πŸ“„ Multi-Format Document Processing
-**Challenge**: Process documents from various sources and formats to extract structured knowledge.
-
-**Solution**: Universal processing modules that work with any document type or domain.
-
-**Example: Processing Various Document Types**
+**Challenge:** Process various document formats uniformly.
```python
from semantica import Semantica
-from semantica.ingest import FileIngestor, WebIngestor, FeedIngestor
-from semantica.parse import PDFParser, DOCXParser, HTMLParser
-
-# Initialize Semantica (general-purpose, works for all domains)
-core = Semantica()
+from semantica.ingest import FileIngestor
-# Step 1: Ingest documents from multiple sources
+# Ingest multiple formats
ingestor = FileIngestor()
-web_ingestor = WebIngestor()
-feed_ingestor = FeedIngestor()
-
-# Ingest from various sources
sources = [
- ingestor.ingest("documents/*.pdf"),
- ingestor.ingest("reports/*.docx"),
- web_ingestor.ingest("https://example.com/article"),
- feed_ingestor.ingest("https://example.com/rss"),
- ingestor.ingest("data/*.json"),
- ingestor.ingest("spreadsheets/*.xlsx")
+ *ingestor.ingest("*.pdf"),
+ *ingestor.ingest("*.docx"),
+ *ingestor.ingest("*.xlsx"),
+ *ingestor.ingest("*.json")
]
-print(f"βœ… Ingested {len(sources)} document sources")
-
-# Step 2: Parse documents using universal parsers
-pdf_parser = PDFParser()
-docx_parser = DOCXParser()
-html_parser = HTMLParser()
-
-# All documents processed through same pipeline
-parsed_docs = []
-for source in sources:
- if source.format == "pdf":
- doc = pdf_parser.parse(source)
- elif source.format == "docx":
- doc = docx_parser.parse(source)
- elif source.format == "html":
- doc = html_parser.parse(source)
- parsed_docs.append(doc)
-
-print(f"βœ… Parsed {len(parsed_docs)} documents")
-
-# Step 3: Extract semantic knowledge (same process for all domains)
-knowledge_base = core.build_knowledge_base(
- sources=parsed_docs,
- extract_entities=True,
- extract_relationships=True,
- generate_triples=True
-)
-
-# Step 4: Build knowledge graph (domain-agnostic)
-kg = core.build_knowledge_graph(
- sources=parsed_docs,
- merge_entities=True,
- resolve_conflicts=True
-)
-
-# Query the unified knowledge graph
-results = kg.query("What are the key entities and relationships?")
+# Process all through unified pipeline
+core = Semantica()
+kb = core.build_knowledge_base(sources)
-print(f"βœ… Knowledge graph created with {kg.node_count} nodes and {kg.edge_count} edges")
+print(f"βœ… Processed {len(sources)} documents")
+print(f"βœ… Knowledge graph: {kb.graph.node_count} nodes")
```
-**Key Point**: Same processing modules work for any document typeβ€”PDFs, web pages, emails, reports, etc. No domain-specific processors needed.
-
----
-
### 4. πŸ”„ Data Pipeline Processing
-**Challenge**: Process diverse data sources through a unified pipeline.
-
-**Solution**: Modular pipeline that adapts to any data format or domain.
-
-**Example: Building Custom Processing Pipeline**
+**Challenge:** Build custom processing pipelines.
```python
-from semantica import Semantica
from semantica.pipeline import PipelineBuilder
from semantica.ingest import FileIngestor
-from semantica.parse import PDFParser, DOCXParser
-from semantica.normalize import TextCleaner, LanguageDetector
-from semantica.split import SemanticChunker
-from semantica.semantic_extract import NamedEntityRecognizer, RelationExtractor
-
-# Initialize core
-core = Semantica()
+from semantica.semantic_extract import NamedEntityRecognizer
-# Build custom pipeline using processing modules
+# Build pipeline
pipeline = PipelineBuilder() \
- .add_step("ingest", {
- "ingestor": FileIngestor(),
- "sources": ["documents/*.pdf", "reports/*.docx", "data/*.json"]
- }) \
- .add_step("parse", {
- "parsers": {
- "pdf": PDFParser(),
- "docx": DOCXParser()
- }
- }) \
- .add_step("normalize", {
- "cleaner": TextCleaner(),
- "language_detector": LanguageDetector()
- }) \
- .add_step("chunk", {
- "chunker": SemanticChunker(),
- "chunk_size": 512,
- "chunk_overlap": 50
- }) \
- .add_step("extract", {
- "ner": NamedEntityRecognizer(),
- "relation_extractor": RelationExtractor()
- }) \
- .add_step("build_graph", {
- "merge_entities": True,
- "resolve_conflicts": True
- }) \
+ .add_step("ingest", {"ingestor": FileIngestor()}) \
+ .add_step("extract", {"ner": NamedEntityRecognizer()}) \
+ .add_step("build_graph", {"merge_entities": True}) \
.set_parallelism(4) \
.build()
-# Execute pipeline
+# Execute
results = pipeline.run()
-
-print(f"βœ… Pipeline completed")
-print(f" Documents processed: {results.document_count}")
-print(f" Entities extracted: {results.entity_count}")
-print(f" Knowledge graph nodes: {results.graph.node_count}")
+print(f"βœ… Pipeline completed: {results.document_count} documents")
```
-**Key Point**: Pipeline modules are domain-agnostic. They process any content using the same universal methods.
-
----
-
-### 5. πŸ“Š Knowledge Graph from Diverse Sources
-
-**Challenge**: Combine data from multiple sources into a unified knowledge graph.
-
-**Solution**: Universal ingestion and processing modules handle any source type.
+### 5. πŸ“Š Multi-Source Knowledge Graph
-**Example: Multi-Source Knowledge Graph Construction**
+**Challenge:** Combine data from files, web, and databases.
```python
from semantica import Semantica
-from semantica.ingest import FileIngestor, WebIngestor, FeedIngestor, DBIngestor
-
-# Initialize (works for any domain)
-core = Semantica()
-
-# Ingest from multiple source types
-file_ingestor = FileIngestor()
-web_ingestor = WebIngestor()
-feed_ingestor = FeedIngestor()
-db_ingestor = DBIngestor()
+from semantica.ingest import FileIngestor, WebIngestor, DBIngestor
# Collect diverse sources
-sources = []
-
-# File-based sources
-sources.extend(file_ingestor.ingest("documents/*.pdf"))
-sources.extend(file_ingestor.ingest("spreadsheets/*.xlsx"))
-
-# Web sources
-sources.extend(web_ingestor.ingest("https://example.com/api/articles"))
-sources.extend(feed_ingestor.ingest("https://example.com/rss"))
-
-# Database sources
-sources.extend(db_ingestor.ingest("postgresql://localhost/db", query="SELECT * FROM articles"))
-
-print(f"βœ… Collected {len(sources)} sources from multiple types")
-
-# Process all through same pipeline
-knowledge_graph = core.build_knowledge_graph(
- sources=sources,
- merge_entities=True,
- resolve_conflicts=True,
- generate_embeddings=True
-)
+sources = [
+ *FileIngestor().ingest("documents/*.pdf"),
+ *WebIngestor().ingest("https://example.com/api/articles"),
+ *DBIngestor().ingest("postgresql://localhost/db")
+]
-# Query unified graph
-results = knowledge_graph.query("What entities are connected across all sources?")
+# Build unified graph
+core = Semantica()
+kg = core.build_knowledge_graph(sources, merge_entities=True)
-print(f"βœ… Unified knowledge graph: {knowledge_graph.node_count} nodes, {knowledge_graph.edge_count} edges")
+print(f"βœ… Unified graph: {kg.node_count} nodes, {kg.edge_count} edges")
```
-**Key Point**: Same ingestion and processing modules work across file, web, database, and feed sources.
-
---
## πŸ”¬ Advanced Features
-### 1. Incremental Knowledge Graph Updates
-
-Keep knowledge graphs up-to-date with streaming updates:
+### 1. Incremental Updates
```python
-from semantica import Semantica
from semantica.streaming import StreamProcessor
-core = Semantica(graph_db="neo4j")
-
-# Initialize stream processor
+# Stream processor
stream = StreamProcessor(
knowledge_graph=core.graph,
- update_mode="incremental",
- conflict_resolution="latest_wins"
+ update_mode="incremental"
)
-# Process streaming data
stream.connect("kafka://localhost:9092/topic")
stream.start()
-
-# Automatic updates:
-# - New entities added
-# - Relationships updated
-# - Conflicts resolved
-# - Deduplication applied
-# - Graph remains consistent
+# Automatic real-time updates
```
### 2. Multi-Language Support
-Process documents in 100+ languages:
-
```python
-from semantica import Semantica
-
core = Semantica(
- languages=["en", "es", "fr", "de", "zh", "ja"],
+ languages=["en", "es", "fr", "de", "zh"],
auto_detect_language=True,
- translate_to="en" # Optional: translate all to English
+ translate_to="en"
)
-# Process multilingual documents
kb = core.build_knowledge_base([
"documents_english/",
"documentos_espaΓ±ol/",
- "documents_franΓ§ais/",
- "dokumente_deutsch/"
+ "documents_franΓ§ais/"
])
-
# Unified multilingual knowledge graph
-# - Entities linked across languages
-# - Relationships normalized
-# - Ontology in target language
```
### 3. Custom Ontology Import
-Import and extend existing ontologies:
-
```python
from semantica.ontology import OntologyManager
-ontology_manager = OntologyManager()
-
-# Import existing ontologies
-ontology_manager.import_ontology(
- "schema.org",
- namespace="https://schema.org/"
-)
-ontology_manager.import_ontology(
- "custom_domain.ttl",
- format="turtle"
-)
+manager = OntologyManager()
+manager.import_ontology("schema.org")
+manager.import_ontology("custom_domain.ttl", format="turtle")
# Extend with custom classes
-ontology_manager.add_class(
+manager.add_class(
name="CustomEntity",
parent="schema:Thing",
- properties=["customProperty1", "customProperty2"]
+ properties=["customProperty1"]
)
-# Use in extraction
-core = Semantica(ontology=ontology_manager.ontology)
+core = Semantica(ontology=manager.ontology)
```
### 4. Advanced Reasoning
-Enable semantic reasoning and inference:
-
```python
from semantica.reasoning import ReasoningEngine
reasoning = ReasoningEngine(
- reasoning_types=[
- "deductive", # Logical inference
- "inductive", # Pattern-based inference
- "abductive" # Best explanation inference
- ],
- reasoner="hermit" # or "pellet", "fact++"
+ reasoning_types=["deductive", "inductive", "abductive"],
+ reasoner="hermit"
)
-# Apply reasoning to knowledge graph
-inferred_triples = reasoning.infer(knowledge_graph)
-
-print(f"Original triples: {len(knowledge_graph.triples)}")
-print(f"Inferred triples: {len(inferred_triples)}")
-print(f"Total: {len(knowledge_graph.triples) + len(inferred_triples)}")
+# Apply reasoning
+inferred_triples = reasoning.infer(kg)
-# Examples of inferred knowledge:
-# - Transitive relationships (if A→B and B→C, then A→C)
-# - Symmetric relationships (if A→B, then B→A)
-# - Property inheritance (subclass inherits parent properties)
-# - Inverse relationships (if A employed_by B, then B employs A)
+print(f"Original: {len(kg.triples)}")
+print(f"Inferred: {len(inferred_triples)}")
```
-### 5. Graph Analytics & Network Analysis
-
-Perform advanced graph analytics on knowledge graphs:
+### 5. Graph Analytics
```python
from semantica.analytics import GraphAnalytics
-analytics = GraphAnalytics(knowledge_graph)
+analytics = GraphAnalytics(kg)
# Centrality analysis
-influential_entities = analytics.compute_centrality(
- methods=["pagerank", "betweenness", "eigenvector"]
+influential = analytics.compute_centrality(
+ methods=["pagerank", "betweenness"]
)
# Community detection
-communities = analytics.detect_communities(
- algorithm="louvain", # or "label_propagation", "girvan_newman"
- min_size=5
-)
+communities = analytics.detect_communities(algorithm="louvain")
# Path finding
-paths = analytics.find_shortest_paths(
- source_entity="Apple Inc.",
- target_entity="Microsoft",
- max_length=4
-)
+paths = analytics.find_shortest_paths("Entity A", "Entity B")
-# Subgraph extraction
-subgraph = analytics.extract_subgraph(
- center_entity="Machine Learning",
- radius=2, # 2-hop neighborhood
- relationship_types=["related_to", "part_of"]
-)
-
-# Similarity analysis
-similar_entities = analytics.find_similar_entities(
- entity="Python",
- method="structural_similarity",
- top_k=10
-)
-
-# Generate analytics report
-report = analytics.generate_report(
- include_visualizations=True,
- output_format="html"
-)
+print(f"Influential entities: {len(influential)}")
+print(f"Communities: {len(communities)}")
```
### 6. Custom Pipelines
-Build custom processing pipelines:
-
```python
from semantica.pipeline import PipelineBuilder
-# Define custom pipeline
pipeline = PipelineBuilder()
-
pipeline.add_stage("parse", parser="custom_parser")
-pipeline.add_stage("extract_entities", model="custom_ner_model")
-pipeline.add_stage("extract_relationships", extractor="custom_re")
+pipeline.add_stage("extract_entities", model="custom_ner")
pipeline.add_stage("validate", validator="custom_validator")
-pipeline.add_stage("enrich", enricher="external_api")
-pipeline.add_stage("deduplicate", strategy="custom_dedup")
pipeline.add_stage("store", destination="custom_db")
-# Execute pipeline
results = pipeline.execute(input_data)
-
-# Pipeline features:
-# - Custom stages and components
-# - Parallel processing
-# - Error handling and retry
-# - Stage-level caching
-# - Progress monitoring
```
-### 7. API Integration & Webhooks
-
-Integrate with external services:
+### 7. API Integration
```python
-from semantica.integrations import APIIntegration, WebhookManager
+from semantica.integrations import APIIntegration
-# REST API integration
api = APIIntegration()
api.register_endpoint(
name="crunchbase",
url="https://api.crunchbase.com/v4/",
- auth_token=crunchbase_token
+ auth_token=token
)
-# Enrich entities with external data
-enriched_entities = api.enrich_entities(
- entities=knowledge_graph.entities,
+# Enrich entities
+enriched = api.enrich_entities(
+ entities=kg.entities,
endpoint="crunchbase",
- fields=["funding", "employees", "headquarters"]
-)
-
-# Webhook notifications
-webhook_manager = WebhookManager()
-webhook_manager.register_webhook(
- event="knowledge_graph_updated",
- url="https://your-service.com/webhook",
- method="POST"
+ fields=["funding", "employees"]
)
-
-# Trigger on events:
-# - New entities extracted
-# - Conflicts detected
-# - Quality score drops
-# - Graph updates complete
```
---
@@ -2760,64 +1296,45 @@ webhook_manager.register_webhook(
### Docker Deployment
-Deploy Semantica with Docker:
-
```dockerfile
# Dockerfile
FROM python:3.11-slim
-
WORKDIR /app
-# Install system dependencies
RUN apt-get update && apt-get install -y \
- build-essential \
- libpq-dev \
+ build-essential libpq-dev \
&& rm -rf /var/lib/apt/lists/*
-# Install Semantica
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
-# Copy application code
COPY . .
-
-# Run application
CMD ["python", "app.py"]
```
```yaml
# docker-compose.yml
version: '3.8'
-
services:
semantica:
build: .
- ports:
- - "8000:8000"
+ ports: ["8000:8000"]
environment:
- NEO4J_URI=bolt://neo4j:7687
- PINECONE_API_KEY=${PINECONE_API_KEY}
- - OPENAI_API_KEY=${OPENAI_API_KEY}
- depends_on:
- - neo4j
- - redis
+ depends_on: [neo4j, redis]
neo4j:
image: neo4j:5.13
- ports:
- - "7474:7474"
- - "7687:7687"
+ ports: ["7474:7474", "7687:7687"]
environment:
- NEO4J_AUTH=neo4j/password
- volumes:
- - neo4j_data:/data
+ volumes: [neo4j_data:/data]
redis:
image: redis:7-alpine
- ports:
- - "6379:6379"
- volumes:
- - redis_data:/data
+ ports: ["6379:6379"]
+ volumes: [redis_data:/data]
volumes:
neo4j_data:
@@ -2826,16 +1343,11 @@ volumes:
### Kubernetes Deployment
-Deploy at scale with Kubernetes:
-
```yaml
-# semantica-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: semantica
- labels:
- app: semantica
spec:
replicas: 3
selector:
@@ -2851,17 +1363,6 @@ spec:
image: semantica:latest
ports:
- containerPort: 8000
- env:
- - name: NEO4J_URI
- valueFrom:
- secretKeyRef:
- name: semantica-secrets
- key: neo4j-uri
- - name: OPENAI_API_KEY
- valueFrom:
- secretKeyRef:
- name: semantica-secrets
- key: openai-api-key
resources:
requests:
memory: "4Gi"
@@ -2869,33 +1370,6 @@ spec:
limits:
memory: "8Gi"
cpu: "4"
- livenessProbe:
- httpGet:
- path: /health
- port: 8000
- initialDelaySeconds: 30
- periodSeconds: 10
- readinessProbe:
- httpGet:
- path: /ready
- port: 8000
- initialDelaySeconds: 5
- periodSeconds: 5
-
----
-apiVersion: v1
-kind: Service
-metadata:
- name: semantica-service
-spec:
- selector:
- app: semantica
- ports:
- - protocol: TCP
- port: 80
- targetPort: 8000
- type: LoadBalancer
-
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
@@ -2915,86 +1389,45 @@ spec:
target:
type: Utilization
averageUtilization: 70
- - type: Resource
- resource:
- name: memory
- target:
- type: Utilization
- averageUtilization: 80
```
### Cloud Deployment
-#### AWS Deployment
-
+**AWS:**
```python
-# AWS integration
from semantica.cloud import AWSDeployment
aws = AWSDeployment(
region="us-east-1",
- graph_db="neptune", # AWS Neptune
- vector_db="opensearch", # AWS OpenSearch
- storage="s3", # S3 for documents
- compute="lambda" # or "ecs", "eks"
-)
-
-# Deploy infrastructure
-aws.deploy(
- stack_name="semantica-production",
- auto_scaling=True,
- monitoring=True,
- backup=True
-)
-
-# Process with AWS services
-core = Semantica(
- graph_db=aws.neptune_endpoint,
- vector_store=aws.opensearch_endpoint,
- storage=aws.s3_bucket
+ graph_db="neptune",
+ vector_db="opensearch"
)
+aws.deploy(stack_name="semantica-prod", auto_scaling=True)
```
-#### Azure Deployment
-
+**Azure:**
```python
-# Azure integration
from semantica.cloud import AzureDeployment
azure = AzureDeployment(
subscription_id="...",
- resource_group="semantica-rg",
- graph_db="cosmos_gremlin",
- vector_db="cognitive_search",
- storage="blob_storage"
-)
-
-azure.deploy(
- location="eastus",
- sku="standard"
+ graph_db="cosmos_gremlin"
)
+azure.deploy(location="eastus")
```
-#### GCP Deployment
-
+**GCP:**
```python
-# GCP integration
from semantica.cloud import GCPDeployment
gcp = GCPDeployment(
project_id="semantica-project",
- graph_db="neo4j_aura",
- vector_db="vertex_ai_matching_engine",
- storage="cloud_storage"
-)
-
-gcp.deploy(
- region="us-central1",
- zones=["us-central1-a", "us-central1-b"]
+ graph_db="neo4j_aura"
)
+gcp.deploy(region="us-central1")
```
-### Monitoring & Observability
+### Monitoring
```python
from semantica.monitoring import Monitor, MetricsCollector
@@ -3002,8 +1435,7 @@ from semantica.monitoring import Monitor, MetricsCollector
# Initialize monitoring
monitor = Monitor(
prometheus_endpoint="http://prometheus:9090",
- grafana_endpoint="http://grafana:3000",
- alertmanager_endpoint="http://alertmanager:9093"
+ grafana_endpoint="http://grafana:3000"
)
# Collect metrics
@@ -3012,35 +1444,14 @@ metrics.enable_metrics([
"processing_rate",
"extraction_accuracy",
"graph_size",
- "query_latency",
- "memory_usage",
- "error_rate"
+ "query_latency"
])
-# Set up alerts
+# Set alerts
monitor.add_alert(
name="high_error_rate",
condition="error_rate > 0.05",
- severity="critical",
- notification_channels=["slack", "email"]
-)
-
-monitor.add_alert(
- name="low_quality_score",
- condition="quality_score < 0.80",
- severity="warning",
- notification_channels=["slack"]
-)
-
-# Dashboard
-monitor.create_dashboard(
- name="Semantica Production",
- panels=[
- "processing_rate_panel",
- "quality_metrics_panel",
- "graph_growth_panel",
- "error_tracking_panel"
- ]
+ severity="critical"
)
```
@@ -3050,329 +1461,139 @@ monitor.create_dashboard(
### Processing Speed
-| Document Type | Documents/Hour | Entities/Second | Triples/Second |
-|---------------|----------------|-----------------|----------------|
-| **PDF** (10 pages) | 1,200 | 450 | 800 |
-| **DOCX** (5 pages) | 2,500 | 600 | 1,100 |
-| **HTML** (articles) | 5,000 | 1,200 | 2,000 |
-| **JSON** (structured) | 10,000 | 2,500 | 4,000 |
-| **CSV** (1000 rows) | 15,000 | 3,000 | 5,000 |
+| Document Type | Docs/Hour | Entities/Sec | Triples/Sec |
+|---------------|-----------|--------------|-------------|
+| PDF (10 pages) | 1,200 | 450 | 800 |
+| DOCX (5 pages) | 2,500 | 600 | 1,100 |
+| HTML (articles) | 5,000 | 1,200 | 2,000 |
+| JSON (structured) | 10,000 | 2,500 | 4,000 |
-*Benchmarks on AWS c5.4xlarge (16 vCPU, 32GB RAM)*
+*AWS c5.4xlarge (16 vCPU, 32GB RAM)*
### Accuracy Metrics
| Task | Precision | Recall | F1 Score |
|------|-----------|--------|----------|
-| **Entity Extraction** | 0.94 | 0.91 | 0.92 |
-| **Relationship Extraction** | 0.89 | 0.85 | 0.87 |
-| **Ontology Generation** | 0.96 | 0.93 | 0.94 |
-| **Duplicate Detection** | 0.97 | 0.95 | 0.96 |
-| **Conflict Detection** | 0.98 | 0.97 | 0.97 |
+| Entity Extraction | 0.94 | 0.91 | 0.92 |
+| Relationship Extraction | 0.89 | 0.85 | 0.87 |
+| Ontology Generation | 0.96 | 0.93 | 0.94 |
+| Duplicate Detection | 0.97 | 0.95 | 0.96 |
### GraphRAG Performance
-| System | Accuracy | Latency | Context Quality |
-|--------|----------|---------|-----------------|
-| Vector-Only RAG | 70% | 50ms | ⭐⭐⭐ |
+| System | Accuracy | Latency | Context |
+|--------|----------|---------|---------|
+| Vector-Only | 70% | 50ms | ⭐⭐⭐ |
| Graph-Only | 75% | 300ms | ⭐⭐⭐⭐ |
| **Semantica GraphRAG** | **91%** ⭐ | **80ms** | ⭐⭐⭐⭐⭐ |
-**30% accuracy improvement** over vector-only RAG systems
+**30% accuracy improvement** over vector-only RAG
---
## πŸ—ΊοΈ Roadmap
### Q1 2025
-
-- [x] Core framework release (v1.0)
+- [x] Core framework (v1.0)
- [x] GraphRAG engine
- [x] 6-stage ontology pipeline
- [x] Quality assurance modules
- [ ] Enhanced multi-language support
- [ ] Real-time streaming improvements
-- [ ] Performance optimizations
### Q2 2025
-
-- [ ] Multi-modal processing (images, audio, video)
-- [ ] Advanced reasoning engine v2
-- [ ] AutoML for custom NER models
+- [ ] Multi-modal processing
+- [ ] Advanced reasoning v2
+- [ ] AutoML for NER models
- [ ] Federated knowledge graphs
-- [ ] Enterprise SSO integration
-- [ ] Enhanced cloud-native features
+- [ ] Enterprise SSO
### Q3 2025
-
- [ ] Temporal knowledge graphs
- [ ] Probabilistic reasoning
- [ ] Automated ontology alignment
-- [ ] Graph neural network integration
-- [ ] Advanced visualization tools
-- [ ] Mobile SDK release
+- [ ] Graph neural networks
+- [ ] Mobile SDK
### Q4 2025
-
-- [ ] Quantum-ready graph algorithms
-- [ ] Neuromorphic computing support
-- [ ] Blockchain integration for provenance
-- [ ] Advanced privacy-preserving techniques
-- [ ] Industry-specific pre-trained models
+- [ ] Quantum-ready algorithms
+- [ ] Neuromorphic computing
+- [ ] Blockchain provenance
+- [ ] Privacy-preserving techniques
- [ ] Version 2.0 release
-### Community Requests
-
-Vote on features in our [GitHub Discussions](https://github.com/semantica/semantica/discussions)!
-
---
## 🀝 Community & Support
### πŸ’¬ Join Our Community
-<table>
-<tr>
-<td width="50%">
-
-#### Discussion Channels
-- πŸ’¬ [**Discord Server**](https://discord.gg/semantica)
- - Real-time help and discussions
- - Community showcases
- - Feature announcements
-
-- πŸ™ [**GitHub Discussions**](https://github.com/semantica/semantica/discussions)
- - Q&A forum
- - Feature requests
- - Best practices sharing
-
-- πŸ“§ [**Mailing List**](https://groups.google.com/g/semantica)
- - Monthly newsletters
- - Release announcements
- - Community highlights
-
-</td>
-<td width="50%">
-
-#### Social Media
-- 🐦 [**Twitter**](https://twitter.com/semantica_ai)
- - Daily tips and tricks
- - Community highlights
- - Latest updates
-
-- πŸ“Ί [**YouTube**](https://youtube.com/semantica)
- - Video tutorials
- - Webinars and talks
- - Use case demonstrations
-
-- πŸ’Ό [**LinkedIn**](https://linkedin.com/company/semantica)
- - Professional updates
- - Job opportunities
- - Enterprise showcases
-
-</td>
-</tr>
-</table>
+| Channel | Purpose |
+|---------|---------|
+| [Discord](https://discord.gg/semantica) | Real-time help, showcases |
+| [GitHub Discussions](https://github.com/semantica/semantica/discussions) | Q&A, feature requests |
+| [Twitter](https://twitter.com/semantica_ai) | Updates, tips |
+| [YouTube](https://youtube.com/semantica) | Tutorials, webinars |
### πŸ“š Learning Resources
-#### Documentation
-
-- πŸ“– [**Official Documentation**](https://semantica.readthedocs.io/)
- - Complete API reference
- - Architecture guides
- - Best practices
-
-- 🎯 [**Tutorials**](https://semantica.readthedocs.io/tutorials/)
- - Step-by-step guides
- - Interactive notebooks
- - Video walkthroughs
-
-- πŸ’‘ [**Examples Repository**](https://github.com/semantica/examples)
- - Real-world implementations
- - Industry-specific examples
- - Integration patterns
-
-#### Educational Content
-
-- πŸŽ“ [**Semantica Academy**](https://academy.semantica.io/)
- - Free online courses
- - Certification programs
- - Hands-on workshops
-
-- πŸ“ [**Blog**](https://blog.semantica.io/)
- - Technical deep-dives
- - Case studies
- - Research updates
-
-- πŸ“š [**Knowledge Base**](https://kb.semantica.io/)
- - FAQs and troubleshooting
- - Common patterns
- - Performance tuning
+- πŸ“– [Documentation](https://semantica.readthedocs.io/)
+- 🎯 [Tutorials](https://semantica.readthedocs.io/tutorials/)
+- πŸ’‘ [Examples](https://github.com/semantica/examples)
+- πŸŽ“ [Academy](https://academy.semantica.io/)
+- πŸ“ [Blog](https://blog.semantica.io/)
### 🏒 Enterprise Support
-For organizations requiring professional support:
-
| Tier | Features | SLA | Price |
|------|----------|-----|-------|
-| **Community** | Community support, public issues | Best effort | Free |
-| **Professional** | Email support, priority issues | 48h response | Contact sales |
-| **Enterprise** | 24/7 support, dedicated engineer | 4h response | Contact sales |
-| **Premium** | Phone support, custom development | 1h response | Contact sales |
-
-**Enterprise Services:**
-- 🎯 Custom implementation consulting
-- 🏫 On-site training programs
-- πŸ”’ Security audits and compliance
-- πŸš€ Migration and integration support
-- πŸ“Š Performance optimization
-- πŸ› οΈ Custom feature development
+| Community | Public support | Best effort | Free |
+| Professional | Email support | 48h | Contact |
+| Enterprise | 24/7 support | 4h | Contact |
+| Premium | Phone, custom dev | 1h | Contact |
-**Contact**: [email protected]
+**Contact:** [email protected]
---
## 🀝 Contributing
-We welcome contributions from the community! Semantica is built by developers, for developers.
-
### How to Contribute
-#### 1. Code Contributions
-
```bash
-# Fork the repository
+# Fork and clone
git clone https://github.com/your-username/semantica.git
cd semantica
-# Create a new branch
-git checkout -b feature/your-feature-name
+# Create branch
+git checkout -b feature/your-feature
-# Install development dependencies
+# Install dev dependencies
pip install -e ".[dev,test]"
-# Make your changes and add tests
-# ... code ...
-
-# Run tests
+# Make changes and test
pytest tests/
-
-# Run linting
black semantica/
flake8 semantica/
-mypy semantica/
# Commit and push
-git commit -m "Add your feature"
-git push origin feature/your-feature-name
-
-# Create pull request on GitHub
+git commit -m "Add feature"
+git push origin feature/your-feature
```
-#### 2. Documentation Contributions
-
-- Improve existing documentation
-- Add tutorials and examples
-- Translate documentation
-- Create video tutorials
-
-#### 3. Bug Reports
-
-Found a bug? [Create an issue](https://github.com/semantica/semantica/issues/new?template=bug_report.md)
-
-- Describe the bug clearly
-- Provide reproducible steps
-- Include system information
-- Add relevant error messages
-
-#### 4. Feature Requests
-
-Have an idea? [Request a feature](https://github.com/semantica/semantica/issues/new?template=feature_request.md)
-
-- Explain the use case
-- Describe desired behavior
-- Discuss alternative solutions
-- Link to relevant resources
-
-### Development Guidelines
+### Contribution Types
-#### Code Standards
+1. **Code** - New features, bug fixes
+2. **Documentation** - Improvements, tutorials
+3. **Bug Reports** - [Create issue](https://github.com/semantica/semantica/issues/new?template=bug_report.md)
+4. **Feature Requests** - [Request feature](https://github.com/semantica/semantica/issues/new?template=feature_request.md)
-- Follow PEP 8 style guide
-- Write comprehensive docstrings
-- Add type hints (Python 3.8+)
-- Maintain 90%+ test coverage
-- Use meaningful variable names
-- Keep functions focused and small
+### Recognition
-#### Testing Requirements
-
-```python
-# Example test structure
-def test_entity_extraction():
- """Test entity extraction from sample text."""
- core = Semantica()
- text = "Apple Inc. was founded by Steve Jobs."
-
- result = core.extract_entities(text)
-
- assert len(result.entities) == 2
- assert result.entities[0].text == "Apple Inc."
- assert result.entities[0].type == "Organization"
- assert result.entities[1].text == "Steve Jobs"
- assert result.entities[1].type == "Person"
-```
-
-#### Documentation Standards
-
-- Use Google-style docstrings
-- Include code examples
-- Add type information
-- Document exceptions
-- Link to related functions
-
-```python
-def extract_entities(text: str, model: str = "default") -> EntityResult:
- """Extract named entities from text.
-
- Args:
- text: Input text to process.
- model: NER model to use. Options: "default", "biomedical", "financial".
-
- Returns:
- EntityResult containing extracted entities with metadata.
-
- Raises:
- ValueError: If text is empty or model is invalid.
- ModelNotFoundError: If specified model is not available.
-
- Example:
- >>> from semantica import Semantica
- >>> core = Semantica()
- >>> result = core.extract_entities("Apple Inc. is a tech company.")
- >>> print(result.entities)
- [Entity(text='Apple Inc.', type='Organization', confidence=0.98)]
-
- See Also:
- extract_relationships: Extract relationships between entities.
- build_knowledge_graph: Build complete knowledge graph.
- """
- pass
-```
-
-### Contributor Recognition
-
-All contributors are recognized in:
-- πŸ“œ [CONTRIBUTORS.md](CONTRIBUTORS.md)
-- πŸ† GitHub repository contributors page
-- πŸ“° Release notes
-- πŸŽ–οΈ Special badges on Discord
-
-**Top contributors receive:**
+Contributors receive:
+- πŸ“œ Recognition in [CONTRIBUTORS.md](CONTRIBUTORS.md)
+- πŸ† GitHub badges
- 🎁 Semantica swag
-- 🎟️ Conference tickets
-- πŸ’Ό Job referrals
- 🌟 Featured showcases
---
@@ -3380,3 +1601,13 @@ All contributors are recognized in:
## πŸ“œ License
Semantica is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
+
+---
+
+<div align="center">
+
+**Built with ❀️ by the Semantica Community**
+
+[Website](https://semantica.io) β€’ [Documentation](https://semantica.readthedocs.io/) β€’ [GitHub](https://github.com/semantica/semantica) β€’ [Discord](https://discord.gg/semantica)
+
+</div>