mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-09-04 04:01:07 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d987abd7a9 | ||
|
|
1fceb634ae | ||
|
|
bd3bc7de7d | ||
|
|
712abf0e7d | ||
|
|
d73bcd52c4 | ||
|
|
859f4765fd | ||
|
|
13a5c383c7 | ||
|
|
b8f0f40d16 | ||
|
|
cbab6e4633 | ||
|
|
432e883ca9 | ||
|
|
c880984e40 | ||
|
|
ee56ca3829 | ||
|
|
e18b1cc123 | ||
|
|
dc94526e9a | ||
|
|
3f78d00c6b | ||
|
|
52d94bb1d7 | ||
|
|
a9538a0ddd | ||
|
|
5fc188b9eb | ||
|
|
30e0dc81de | ||
|
|
9e1aa64043 | ||
|
|
6eca6af7bc | ||
|
|
eb5980a1fb | ||
|
|
ec6cfdf304 | ||
|
|
bb63faa1ec | ||
|
|
38962d3d7a | ||
|
|
fbe0ed1a41 | ||
|
|
affb16de9e | ||
|
|
8d6b38d7da | ||
|
|
a1ae001618 | ||
|
|
5cc0c7eac4 | ||
|
|
734585ed92 | ||
|
|
e45875f924 | ||
|
|
1620de371f | ||
|
|
ae4e93923e | ||
|
|
7297d46ac8 | ||
|
|
1a124c7294 | ||
|
|
0a052b676d | ||
|
|
0476950fdf | ||
|
|
a467cb5af6 | ||
|
|
89235d1f19 | ||
|
|
3934c74300 | ||
|
|
8f8e532114 | ||
|
|
b091c870bc | ||
|
|
53f6aba967 | ||
|
|
0b67bfa998 | ||
|
|
381de30cbd | ||
|
|
999c490ba9 | ||
|
|
00322d81c6 | ||
|
|
ad6dd1af4f | ||
|
|
78a3b4a6cd | ||
|
|
07208318ec | ||
|
|
ea6cfdf6a8 | ||
|
|
7439f31399 | ||
|
|
8a25494f55 | ||
|
|
72d948972b | ||
|
|
a62326a61f | ||
|
|
e171e86daa | ||
|
|
6dc4f69c84 | ||
|
|
45205ad54d | ||
|
|
dd6b341fb9 | ||
|
|
77186a518d | ||
|
|
adabdd283f | ||
|
|
abe730891f | ||
|
|
96702923de | ||
|
|
bfd4bd60e5 | ||
|
|
e211a7bf57 | ||
|
|
30e2645a98 | ||
|
|
e5e8823423 | ||
|
|
b5c91a90a3 | ||
|
|
569fdc31f1 | ||
|
|
bdcaab92b0 | ||
|
|
3f4e6f831f | ||
|
|
52aa1a6896 | ||
|
|
d34731d687 | ||
|
|
8dace2f078 | ||
|
|
4fdc483935 | ||
|
|
d042054f9a | ||
|
|
c2d7d92a53 | ||
|
|
b6e27b7d71 | ||
|
|
444746de02 | ||
|
|
e8655a97ed | ||
|
|
f15ab2a327 | ||
|
|
2f9ad467f0 | ||
|
|
253d35ee31 | ||
|
|
09e7e61111 | ||
|
|
05f553271d | ||
|
|
ccb3f43104 | ||
|
|
6be868e067 | ||
|
|
7b7d3fa8ad | ||
|
|
c178b8dead | ||
|
|
8b9f6dbd09 | ||
|
|
096ad31f77 | ||
|
|
4b7cc5a359 | ||
|
|
c41f2951b2 |
+15
-6
@@ -326,14 +326,23 @@ def extract_entities(
|
||||
|
||||
## Types of Contributions
|
||||
|
||||
### Code Contributions
|
||||
### 💻 Code Contributions
|
||||
|
||||
- Bug fixes
|
||||
- New features
|
||||
- Performance improvements
|
||||
- Refactoring
|
||||
- **Bug Fixes**: Resolving issues reported in the issue tracker.
|
||||
- **New Features**: Implementing new capabilities (please discuss via an issue first!).
|
||||
- **Refactoring**: Improving code structure and maintainability without changing behavior.
|
||||
- **Algorithm Optimization**: Improving the efficiency of graph algorithms and vector search.
|
||||
|
||||
### Documentation Contributions
|
||||
#### ⚡ Performance and Latency
|
||||
We deeply value efficiency. Contributions that make Semantica faster and lighter are highly appreciated!
|
||||
|
||||
- **Latency Reduction**: Optimize critical paths and RAG pipeline response times.
|
||||
- **Memory Optimization**: Reduce graph/vector processing memory footprint.
|
||||
- **Throughput**: Improve operations per second (bulk ingestion, parallel queries).
|
||||
- **Benchmarks**: Add performance benchmarks to track regressions.
|
||||
- **Async/Concurrency**: Enhance asynchronous execution and concurrency.
|
||||
|
||||
### 📚 Documentation Contributions
|
||||
|
||||
- Fix typos and grammar
|
||||
- Improve clarity
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook demonstrates advanced semantic extraction using EventDetector, CoreferenceResolver, TripleExtractor, SemanticAnalyzer, SemanticNetworkExtractor, LLMEnhancer, and ExtractionValidator.\n",
|
||||
"This notebook demonstrates advanced semantic extraction using EventDetector, CoreferenceResolver, TripletExtractor, SemanticAnalyzer, SemanticNetworkExtractor, LLMEnhancer, and ExtractionValidator.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/semantic_extract/)\n",
|
||||
@@ -19,7 +19,7 @@
|
||||
"\n",
|
||||
"- Use EventDetector to detect events\n",
|
||||
"- Use CoreferenceResolver to resolve coreferences\n",
|
||||
"- Use TripleExtractor to extract RDF triples\n",
|
||||
"- Use TripletExtractor to extract RDF triplets\n",
|
||||
"- Use SemanticAnalyzer for semantic analysis\n",
|
||||
"- Use SemanticNetworkExtractor to extract semantic networks\n",
|
||||
"- Use LLMEnhancer for LLM-based enhancement\n",
|
||||
@@ -37,17 +37,63 @@
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Workflow: Event Detection → Coreference Resolution → Triple Extraction → Semantic Analysis → Network Extraction → LLM Enhancement → Validation\n"
|
||||
"## Workflow: Event Detection → Coreference Resolution → Triplet Extraction → Semantic Analysis → Network Extraction → LLM Enhancement → Validation\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install -q semantica"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is extracting</td><td>🎯 semantic_extract</td><td>EventDetector</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is extracting</td><td>🎯 semantic_extract</td><td>CoreferenceResolver</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is extracting</td><td>🎯 semantic_extract</td><td>TripletExtractor</td><td>-</td><td>1.32s</td></tr><tr><td>✅</td><td>Semantica is extracting</td><td>🎯 semantic_extract</td><td>NERExtractor</td><td>-</td><td>0.51s</td></tr><tr><td>✅</td><td>Semantica is extracting</td><td>🎯 semantic_extract</td><td>RelationExtractor</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is extracting</td><td>🎯 semantic_extract</td><td>SemanticNetworkExtractor</td><td>-</td><td>1.21s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Detected 1 events\n",
|
||||
" Event: founded - founded\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import (\n",
|
||||
" EventDetector, CoreferenceResolver, TripleExtractor,\n",
|
||||
" EventDetector, CoreferenceResolver, TripletExtractor,\n",
|
||||
" SemanticAnalyzer, SemanticNetworkExtractor, LLMEnhancer, ExtractionValidator\n",
|
||||
")\n",
|
||||
"\n",
|
||||
@@ -58,7 +104,7 @@
|
||||
"\n",
|
||||
"print(f\"Detected {len(events)} events\")\n",
|
||||
"for event in events[:3]:\n",
|
||||
" print(f\" Event: {event.get('type', 'Unknown')} - {event.get('text', '')[:50]}\")\n"
|
||||
" print(f\" Event: {event.event_type} - {event.text[:50]}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -72,9 +118,17 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Resolved 0 coreference chains\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"coreference_resolver = CoreferenceResolver()\n",
|
||||
"\n",
|
||||
@@ -87,24 +141,39 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Triple Extraction\n",
|
||||
"## Step 3: Triplet Extraction\n",
|
||||
"\n",
|
||||
"Extract RDF triples.\n"
|
||||
"Extract RDF triplets.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"DEBUG: Entity map keys: ['apple inc.', 'steve jobs', '1976', 'tim cook']\n",
|
||||
"DEBUG: Match found! Subject='Apple Inc.', Object='Steve Jobs'\n",
|
||||
"DEBUG: Subject Entity found: True, Object Entity found: True\n",
|
||||
"DEBUG: Match found! Subject='Steve Jobs', Object='1976'\n",
|
||||
"DEBUG: Subject Entity found: True, Object Entity found: True\n",
|
||||
"Extracted 2 triplets\n",
|
||||
" (Apple Inc., founded_by, Steve Jobs)\n",
|
||||
" (Steve Jobs, located_in, 1976)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"triples = triple_extractor.extract_triples(text)\n",
|
||||
"triplets = triplet_extractor.extract_triplets(text)\n",
|
||||
"\n",
|
||||
"print(f\"Extracted {len(triples)} triples\")\n",
|
||||
"for triple in triples[:3]:\n",
|
||||
" print(f\" ({triple.get('subject', '')}, {triple.get('predicate', '')}, {triple.get('object', '')})\")\n"
|
||||
"print(f\"Extracted {len(triplets)} triplets\")\n",
|
||||
"for triplet in triplets[:3]:\n",
|
||||
" print(f\" ({triplet.get('subject', '')}, {triplet.get('predicate', '')}, {triplet.get('object', '')})\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -118,9 +187,17 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Analyzed semantic roles: 6\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"semantic_analyzer = SemanticAnalyzer()\n",
|
||||
"\n",
|
||||
@@ -140,9 +217,23 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"DEBUG: Entity map keys: ['apple inc.', 'steve jobs', '1976', 'tim cook']\n",
|
||||
"DEBUG: Match found! Subject='Apple Inc.', Object='Steve Jobs'\n",
|
||||
"DEBUG: Subject Entity found: True, Object Entity found: True\n",
|
||||
"DEBUG: Match found! Subject='Steve Jobs', Object='1976'\n",
|
||||
"DEBUG: Subject Entity found: True, Object Entity found: True\n",
|
||||
"Extracted semantic network with 4 nodes\n",
|
||||
"Edges: 2\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"semantic_network_extractor = SemanticNetworkExtractor()\n",
|
||||
"\n",
|
||||
@@ -163,9 +254,21 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "AttributeError",
|
||||
"evalue": "'LLMEnhancer' object has no attribute 'enhance_extractions'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||||
"Cell \u001b[1;32mIn[7], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m llm_enhancer \u001b[38;5;241m=\u001b[39m LLMEnhancer()\n\u001b[1;32m----> 3\u001b[0m enhanced_extractions \u001b[38;5;241m=\u001b[39m \u001b[43mllm_enhancer\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menhance_extractions\u001b[49m(events, text)\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEnhanced \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mlen\u001b[39m(enhanced_extractions)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m extractions\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
||||
"\u001b[1;31mAttributeError\u001b[0m: 'LLMEnhancer' object has no attribute 'enhance_extractions'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"llm_enhancer = LLMEnhancer()\n",
|
||||
"\n",
|
||||
@@ -208,7 +311,7 @@
|
||||
"\n",
|
||||
"- **EventDetector**: Event detection and classification\n",
|
||||
"- **CoreferenceResolver**: Coreference resolution\n",
|
||||
"- **TripleExtractor**: RDF triple extraction\n",
|
||||
"- **TripletExtractor**: RDF triplet extraction\n",
|
||||
"- **SemanticAnalyzer**: Semantic analysis and role labeling\n",
|
||||
"- **SemanticNetworkExtractor**: Semantic network extraction\n",
|
||||
"- **LLMEnhancer**: LLM-based extraction enhancement\n",
|
||||
@@ -217,8 +320,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -4,262 +4,717 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/02_Advanced_Graph_Analytics.ipynb)\n",
|
||||
"# Graph Analytics \n",
|
||||
"\n",
|
||||
"# Advanced Graph Analytics\n",
|
||||
"Welcome to the **comprehensive walkthrough** of Semantica's Graph Analytics capabilities. This notebook goes beyond simple graph construction to demonstrate a full-lifecycle production pipeline.\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"We will simulate a messy, real-world scenario involving a **Startup Ecosystem** (Investors, Startups, Founders) and guide you through every step of the process:\n",
|
||||
"\n",
|
||||
"This notebook demonstrates advanced graph analytics using GraphAnalyzer, CentralityCalculator, CommunityDetector, ConnectivityAnalyzer, GraphValidator, Deduplicator, and **GraphStore** for persistent storage.\n",
|
||||
"1. **Validation**: Catching bad data before it enters the graph.\n",
|
||||
"2. **Cleaning**: Deduplicating entities and resolving conflicts.\n",
|
||||
"3. **Structural Analysis**: Understanding the shape and health of your network.\n",
|
||||
"4. **Deep Analytics**: Centrality, Communities, and Path Finding.\n",
|
||||
"5. **Temporal Analytics**: Time-traveling through your graph data.\n",
|
||||
"6. **Provenance**: Tracking where your data came from.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/kg/)\n",
|
||||
"\n",
|
||||
"### Learning Objectives\n",
|
||||
"\n",
|
||||
"- Use GraphAnalyzer for comprehensive graph analysis\n",
|
||||
"- Use CentralityCalculator for advanced centrality measures\n",
|
||||
"- Use CommunityDetector for community detection\n",
|
||||
"- Use ConnectivityAnalyzer for connectivity analysis\n",
|
||||
"- Use GraphValidator and Deduplicator for graph quality\n",
|
||||
"- **Use GraphStore to persist graphs to Neo4j or FalkorDB**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install Semantica from PyPI:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"# Or with all optional dependencies:\n",
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Workflow: Graph Analysis → Centrality → Communities → Connectivity → Validation → Deduplication → **Persist to Graph Store**\n"
|
||||
"Let's dive in!"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"id": "695d435c",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install -q semantica"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector, ConnectivityAnalyzer, GraphValidator\n",
|
||||
"from semantica.deduplication import DuplicateDetector, EntityMerger, MergeStrategy\n",
|
||||
"import logging\n",
|
||||
"import json\n",
|
||||
"from datetime import datetime\n",
|
||||
"\n",
|
||||
"builder = GraphBuilder()\n",
|
||||
"analyzer = GraphAnalyzer()\n",
|
||||
"# Set up logging to see what's happening under the hood\n",
|
||||
"logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')\n",
|
||||
"\n",
|
||||
"entities = [\n",
|
||||
" {\"id\": \"e1\", \"type\": \"Organization\", \"name\": \"Apple Inc.\", \"properties\": {}},\n",
|
||||
" {\"id\": \"e2\", \"type\": \"Person\", \"name\": \"Tim Cook\", \"properties\": {}},\n",
|
||||
" {\"id\": \"e3\", \"type\": \"Location\", \"name\": \"Cupertino\", \"properties\": {}}\n",
|
||||
"# Import all the powerful tools from Semantica\n",
|
||||
"from semantica.kg import (\n",
|
||||
" GraphBuilder,\n",
|
||||
" GraphAnalyzer,\n",
|
||||
" GraphValidator,\n",
|
||||
" ConnectivityAnalyzer,\n",
|
||||
" CentralityCalculator,\n",
|
||||
" CommunityDetector,\n",
|
||||
" TemporalGraphQuery,\n",
|
||||
" ProvenanceTracker\n",
|
||||
")\n",
|
||||
"from semantica.deduplication import DuplicateDetector\n",
|
||||
"from semantica.conflicts import ConflictDetector, ConflictResolver"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 1. The Scenario: A Messy Startup Ecosystem\n",
|
||||
"\n",
|
||||
"We have data from multiple sources (scrapers, news, user submissions). It's messy:\n",
|
||||
"- **Duplicates**: \"TechFlow AI\" and \"TechFlow Inc.\"\n",
|
||||
"- **Conflicts**: Different revenue numbers for the same company.\n",
|
||||
"- **Errors**: Relationships pointing to non-existent nodes (dangling edges).\n",
|
||||
"- **History**: Investment rounds happening at different times."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Loaded 6 raw entities and 4 raw relationships.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Our \"Raw\" Messy Data\n",
|
||||
"raw_entities = [\n",
|
||||
" {\"id\": \"startup_1\", \"type\": \"Startup\", \"name\": \"TechFlow AI\", \"revenue\": 1000000, \"founded\": \"2021-01-01\"},\n",
|
||||
" {\"id\": \"startup_2\", \"type\": \"Startup\", \"name\": \"GreenEnergy Co\", \"revenue\": 500000, \"founded\": \"2020-05-15\"},\n",
|
||||
" {\"id\": \"startup_1_dup\", \"type\": \"Startup\", \"name\": \"TechFlow Inc.\", \"revenue\": 1200000, \"founded\": \"2021-01-01\"}, # Duplicate!\n",
|
||||
" {\"id\": \"investor_1\", \"type\": \"Investor\", \"name\": \"Venture Capital X\"},\n",
|
||||
" {\"id\": \"founder_1\", \"type\": \"Person\", \"name\": \"Alice Chen\"},\n",
|
||||
" {\"id\": \"founder_2\", \"type\": \"Person\", \"name\": \"Bob Smith\"}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"relationships = [\n",
|
||||
" {\"source\": \"e2\", \"target\": \"e1\", \"type\": \"CEO_of\", \"properties\": {}},\n",
|
||||
" {\"source\": \"e1\", \"target\": \"e3\", \"type\": \"located_in\", \"properties\": {}}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"kg = builder.build(entities, relationships)\n",
|
||||
"\n",
|
||||
"metrics = analyzer.compute_metrics(kg)\n",
|
||||
"\n",
|
||||
"print(f\"Graph metrics:\")\n",
|
||||
"print(f\" Entities: {metrics.get('entity_count', 0)}\")\n",
|
||||
"print(f\" Relationships: {metrics.get('relationship_count', 0)}\")\n",
|
||||
"print(f\" Density: {metrics.get('density', 0):.3f}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 2: Advanced Centrality Measures\n",
|
||||
"\n",
|
||||
"Calculate multiple centrality measures.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"centrality_calculator = CentralityCalculator()\n",
|
||||
"\n",
|
||||
"degree_centrality_result = centrality_calculator.calculate_degree_centrality(kg)\n",
|
||||
"degree_centrality = degree_centrality_result.get('centrality', {})\n",
|
||||
"betweenness_centrality_result = centrality_calculator.calculate_betweenness_centrality(kg)\n",
|
||||
"betweenness_centrality = betweenness_centrality_result.get('centrality', {})\n",
|
||||
"\n",
|
||||
"print(f\"Degree centrality: {len(degree_centrality)} entities\")\n",
|
||||
"print(f\"Betweenness centrality: {len(betweenness_centrality)} entities\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Community Detection\n",
|
||||
"\n",
|
||||
"Detect communities in the graph.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"community_detector = CommunityDetector()\n",
|
||||
"\n",
|
||||
"communities = community_detector.detect_communities(kg)\n",
|
||||
"\n",
|
||||
"print(f\"Detected {len(communities)} communities\")\n",
|
||||
"for i, community in enumerate(communities[:3], 1):\n",
|
||||
" print(f\" Community {i}: {len(community)} entities\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 4: Connectivity Analysis\n",
|
||||
"\n",
|
||||
"Analyze graph connectivity.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"connectivity_analyzer = ConnectivityAnalyzer()\n",
|
||||
"\n",
|
||||
"connectivity = connectivity_analyzer.analyze_connectivity(kg)\n",
|
||||
"\n",
|
||||
"print(f\"Connectivity analysis:\")\n",
|
||||
"print(f\" Is connected: {connectivity.get('is_connected', False)}\")\n",
|
||||
"print(f\" Components: {len(connectivity.get('components', []))}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 5: Graph Validation and Deduplication\n",
|
||||
"\n",
|
||||
"Validate and deduplicate the graph.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"graph_validator = GraphValidator()\n",
|
||||
"\n",
|
||||
"validation_result = graph_validator.validate(kg)\n",
|
||||
"\n",
|
||||
"print(f\"Graph validation: {validation_result.get('valid', False)}\")\n",
|
||||
"print(f\"Issues found: {len(validation_result.get('issues', []))}\")\n",
|
||||
"\n",
|
||||
"# For deduplication, use semantica.deduplication module:\n",
|
||||
"# from semantica.deduplication import DuplicateDetector, EntityMerger, MergeStrategy\n",
|
||||
"# detector = DuplicateDetector(similarity_threshold=0.8)\n",
|
||||
"# duplicate_groups = detector.detect_duplicate_groups(kg.get('entities', []))\n",
|
||||
"# merger = EntityMerger()\n",
|
||||
"# merge_operations = merger.merge_duplicates(kg.get('entities', []), strategy=MergeStrategy.KEEP_MOST_COMPLETE)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 6: Persist to Graph Store\n",
|
||||
"\n",
|
||||
"Store the analyzed graph in a persistent graph database using GraphStore.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.graph_store import GraphStore\n",
|
||||
"\n",
|
||||
"# Option 1: Neo4j (requires Neo4j server running)\n",
|
||||
"graph_store = GraphStore(backend=\"neo4j\", uri=\"bolt://localhost:7687\", user=\"neo4j\", password=\"password\")\n",
|
||||
"graph_store.connect()\n",
|
||||
"\n",
|
||||
"# Store entities as nodes and track node ID mapping\n",
|
||||
"node_id_map = {}\n",
|
||||
"for entity in entities:\n",
|
||||
" node = graph_store.create_node(\n",
|
||||
" labels=[entity[\"type\"]],\n",
|
||||
" properties={\"name\": entity[\"name\"], \"original_id\": entity[\"id\"]}\n",
|
||||
" )\n",
|
||||
" node_id_map[entity[\"id\"]] = node.get(\"id\")\n",
|
||||
" print(f\"Stored node: {entity['name']} (ID: {node.get('id')})\")\n",
|
||||
"\n",
|
||||
"# Store relationships using mapped node IDs\n",
|
||||
"for rel in relationships:\n",
|
||||
" source_id = node_id_map.get(rel[\"source\"])\n",
|
||||
" target_id = node_id_map.get(rel[\"target\"])\n",
|
||||
"raw_relationships = [\n",
|
||||
" # Valid Relationships\n",
|
||||
" {\"source\": \"founder_1\", \"target\": \"startup_1\", \"type\": \"FOUNDED\", \"valid_from\": \"2021-01-01\"},\n",
|
||||
" {\"source\": \"investor_1\", \"target\": \"startup_1\", \"type\": \"INVESTED_IN\", \"amount\": 5000000, \"valid_from\": \"2023-06-01\"},\n",
|
||||
" \n",
|
||||
" if source_id is not None and target_id is not None:\n",
|
||||
" relationship = graph_store.create_relationship(\n",
|
||||
" start_node_id=source_id,\n",
|
||||
" end_node_id=target_id,\n",
|
||||
" rel_type=rel[\"type\"],\n",
|
||||
" properties=rel.get(\"properties\", {})\n",
|
||||
" )\n",
|
||||
" print(f\"Stored relationship: {rel['source']} -{rel['type']}-> {rel['target']}\")\n",
|
||||
" else:\n",
|
||||
" print(f\"Warning: Could not find node IDs for relationship {rel['source']} -> {rel['target']}\")\n",
|
||||
" # Dangling Edge (Error!)\n",
|
||||
" {\"source\": \"founder_2\", \"target\": \"startup_999\", \"type\": \"FOUNDED\", \"valid_from\": \"2020-05-15\"}, \n",
|
||||
" \n",
|
||||
" # Temporal Data (History)\n",
|
||||
" {\"source\": \"founder_1\", \"target\": \"startup_2\", \"type\": \"ADVISED\", \"valid_from\": \"2020-01-01\", \"valid_until\": \"2021-01-01\"}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Query using Cypher\n",
|
||||
"results = graph_store.execute_query(\"MATCH (n) RETURN n.name, labels(n) LIMIT 10\")\n",
|
||||
"print(f\"\\nQuery results: {len(results.get('records', []))} nodes\")\n",
|
||||
"\n",
|
||||
"# Get statistics\n",
|
||||
"stats = graph_store.get_stats()\n",
|
||||
"print(f\"\\nGraph store statistics:\")\n",
|
||||
"print(f\" Node count: {stats.get('node_count', 'N/A')}\")\n",
|
||||
"print(f\" Relationship count: {stats.get('relationship_count', 'N/A')}\")\n",
|
||||
"print(f\" Label counts: {stats.get('label_counts', {})}\")\n",
|
||||
"\n",
|
||||
"graph_store.close()\n"
|
||||
"print(f\"Loaded {len(raw_entities)} raw entities and {len(raw_relationships)} raw relationships.\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"## 2. Phase 1: Validation (The Gatekeeper)\n",
|
||||
"\n",
|
||||
"You've learned advanced graph analytics:\n",
|
||||
"Before we do anything, we must validate the graph. Bad data in = Bad insights out.\n",
|
||||
"We use `GraphValidator` to check for:\n",
|
||||
"- **Structural Integrity**: Are all relationship targets present?\n",
|
||||
"- **Schema Compliance**: Do entities have required fields?\n",
|
||||
"- **Consistency**: Are IDs unique?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "bd8fb13d",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Running Validation Check...\n",
|
||||
"Validation Failed! Issues found:\n",
|
||||
" - [ERROR] Target entity ID not found: startup_999 (Code: DANGLING_EDGE)\n",
|
||||
" Auto-Fixing: Removing invalid relationship...\n",
|
||||
" - [WARNING] Found 2 orphan nodes (no relationships). (Code: ORPHAN_NODES)\n",
|
||||
"\n",
|
||||
"Re-validating after fixes...\n",
|
||||
"Graph is now clean and valid!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Initialize Validator\n",
|
||||
"validator = GraphValidator()\n",
|
||||
"\n",
|
||||
"- **GraphAnalyzer**: Comprehensive graph analysis and metrics\n",
|
||||
"- **CentralityCalculator**: Multiple centrality measures\n",
|
||||
"- **CommunityDetector**: Community detection\n",
|
||||
"- **ConnectivityAnalyzer**: Connectivity analysis\n",
|
||||
"- **GraphValidator**: Graph validation\n",
|
||||
"- **Deduplicator**: Graph deduplication\n",
|
||||
"- **GraphStore**: Persist graphs to Neo4j or FalkorDB\n",
|
||||
"# Create a temporary graph object for validation\n",
|
||||
"temp_graph = {\"entities\": raw_entities, \"relationships\": raw_relationships}\n",
|
||||
"\n",
|
||||
"# Run Validation\n",
|
||||
"print(\"Running Validation Check...\")\n",
|
||||
"validation_result = validator.validate(temp_graph)\n",
|
||||
"\n",
|
||||
"if not validation_result.is_valid:\n",
|
||||
" print(\"Validation Failed! Issues found:\")\n",
|
||||
" for issue in validation_result.issues:\n",
|
||||
" print(f\" - [{issue.severity.name}] {issue.message} (Code: {issue.code})\")\n",
|
||||
" \n",
|
||||
" # AUTOMATIC FIX: If it's a dangling edge, remove it\n",
|
||||
" if issue.code == \"DANGLING_EDGE\":\n",
|
||||
" print(\" Auto-Fixing: Removing invalid relationship...\")\n",
|
||||
" raw_relationships = [r for r in raw_relationships \n",
|
||||
" if r['target'] != issue.details.get('target_id')]\n",
|
||||
"else:\n",
|
||||
" print(\"Graph is valid!\")\n",
|
||||
"\n",
|
||||
"# Re-validate to confirm fix\n",
|
||||
"print(\"\\nRe-validating after fixes...\")\n",
|
||||
"temp_graph = {\"entities\": raw_entities, \"relationships\": raw_relationships}\n",
|
||||
"if validator.validate(temp_graph).is_valid:\n",
|
||||
" print(\"Graph is now clean and valid!\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 3. Phase 2: Deduplication & Conflict Resolution\n",
|
||||
"\n",
|
||||
"We have \"TechFlow AI\" and \"TechFlow Inc.\". These are likely the same company.\n",
|
||||
"We also have conflicting revenue data."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Scanning for duplicates...\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>DuplicateDetector</td><td>-</td><td>0.25s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>SimilarityCalculator</td><td>-</td><td>0.02s</td></tr><tr><td>✅</td><td>Semantica is resolving</td><td>⚠️ conflicts</td><td>ConflictDetector</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is building</td><td>🧠 kg</td><td>CentralityCalculator</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is building</td><td>🧠 kg</td><td>CommunityDetector</td><td>-</td><td>0.01s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2025-12-19 16:09:21,008 - INFO - [RUNNING] | Module: deduplication | Submodule: DuplicateDetector | Message: Detecting duplicates in 6 entities\n",
|
||||
"2025-12-19 16:09:21,008 - INFO - Detecting duplicates in 6 entities (threshold: 0.7)\n",
|
||||
"2025-12-19 16:09:21,011 - INFO - [RUNNING] | Module: deduplication | Submodule: DuplicateDetector | Message: Calculating similarities...\n",
|
||||
"2025-12-19 16:09:21,013 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,015 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,018 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,020 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,023 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,026 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.56\n",
|
||||
"2025-12-19 16:09:21,029 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,031 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,034 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,036 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,038 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,040 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.86\n",
|
||||
"2025-12-19 16:09:21,043 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,046 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,049 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,052 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,055 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,058 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.61\n",
|
||||
"2025-12-19 16:09:21,060 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,063 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,065 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,068 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,069 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,072 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.61\n",
|
||||
"2025-12-19 16:09:21,075 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,077 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,080 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,083 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,087 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,089 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.54\n",
|
||||
"2025-12-19 16:09:21,092 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,093 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,098 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,100 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,103 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,106 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.57\n",
|
||||
"2025-12-19 16:09:21,109 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,112 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,115 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,117 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,121 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,124 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.59\n",
|
||||
"2025-12-19 16:09:21,126 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,129 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,131 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,136 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,138 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,142 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.59\n",
|
||||
"2025-12-19 16:09:21,146 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,150 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,153 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,156 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,159 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,162 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.30\n",
|
||||
"2025-12-19 16:09:21,166 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,168 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,170 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,173 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,175 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,177 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.56\n",
|
||||
"2025-12-19 16:09:21,179 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,180 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,184 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,186 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,187 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,188 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.66\n",
|
||||
"2025-12-19 16:09:21,192 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,193 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,196 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,198 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,200 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,201 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.55\n",
|
||||
"2025-12-19 16:09:21,203 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,206 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,206 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,210 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,211 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,213 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.56\n",
|
||||
"2025-12-19 16:09:21,215 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,217 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,221 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,225 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,228 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,231 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.50\n",
|
||||
"2025-12-19 16:09:21,234 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating similarity between entities\n",
|
||||
"2025-12-19 16:09:21,237 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating string similarity...\n",
|
||||
"2025-12-19 16:09:21,240 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating property similarity...\n",
|
||||
"2025-12-19 16:09:21,243 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Calculating relationship similarity...\n",
|
||||
"2025-12-19 16:09:21,246 - INFO - [RUNNING] | Module: deduplication | Submodule: SimilarityCalculator | Message: Aggregating similarity scores...\n",
|
||||
"2025-12-19 16:09:21,249 - INFO - [COMPLETED] | Module: deduplication | Submodule: SimilarityCalculator | Message: Similarity score: 0.56\n",
|
||||
"2025-12-19 16:09:21,252 - INFO - [RUNNING] | Module: deduplication | Submodule: DuplicateDetector | Message: Creating duplicate candidates...\n",
|
||||
"2025-12-19 16:09:21,254 - INFO - Detected 1 duplicate candidate(s) (confidence >= 0.6)\n",
|
||||
"2025-12-19 16:09:21,258 - INFO - [COMPLETED] | Module: deduplication | Submodule: DuplicateDetector | Message: Detected 1 duplicate candidates\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Found potential duplicate pair (Score: 0.86):\n",
|
||||
" - TechFlow AI (ID: startup_1)\n",
|
||||
" - TechFlow Inc. (ID: startup_1_dup)\n",
|
||||
" Merging entities...\n",
|
||||
"\n",
|
||||
"Checking for data conflicts...\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2025-12-19 16:09:21,261 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Detecting all conflicts\n",
|
||||
"2025-12-19 16:09:21,265 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Detecting value conflicts for property: founded\n",
|
||||
"2025-12-19 16:09:21,268 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Analyzing 2 entities...\n",
|
||||
"2025-12-19 16:09:21,271 - INFO - [COMPLETED] | Module: conflicts | Submodule: ConflictDetector | Message: Detected 0 conflicts\n",
|
||||
"2025-12-19 16:09:21,274 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Detecting value conflicts for property: revenue\n",
|
||||
"2025-12-19 16:09:21,277 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Analyzing 2 entities...\n",
|
||||
"2025-12-19 16:09:21,279 - WARNING - Value conflict detected: startup_1.revenue has conflicting values: ['1000000', '1200000']\n",
|
||||
"2025-12-19 16:09:21,280 - INFO - [COMPLETED] | Module: conflicts | Submodule: ConflictDetector | Message: Detected 1 conflicts\n",
|
||||
"2025-12-19 16:09:21,283 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Detecting value conflicts for property: name\n",
|
||||
"2025-12-19 16:09:21,286 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Analyzing 2 entities...\n",
|
||||
"2025-12-19 16:09:21,288 - WARNING - Value conflict detected: startup_1.name has conflicting values: ['TechFlow Inc.', 'TechFlow AI']\n",
|
||||
"2025-12-19 16:09:21,291 - INFO - [COMPLETED] | Module: conflicts | Submodule: ConflictDetector | Message: Detected 1 conflicts\n",
|
||||
"2025-12-19 16:09:21,295 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Detecting type conflicts\n",
|
||||
"2025-12-19 16:09:21,296 - INFO - [COMPLETED] | Module: conflicts | Submodule: ConflictDetector | Message: Detected 0 type conflicts\n",
|
||||
"2025-12-19 16:09:21,299 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Detecting temporal conflicts\n",
|
||||
"2025-12-19 16:09:21,302 - INFO - [COMPLETED] | Module: conflicts | Submodule: ConflictDetector | Message: Detected 0 temporal conflicts\n",
|
||||
"2025-12-19 16:09:21,308 - INFO - [RUNNING] | Module: conflicts | Submodule: ConflictDetector | Message: Detecting logical conflicts\n",
|
||||
"2025-12-19 16:09:21,313 - INFO - [COMPLETED] | Module: conflicts | Submodule: ConflictDetector | Message: Detected 0 logical conflicts\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Conflict detected in field 'revenue':\n",
|
||||
" Values: [1000000, 1200000]\n",
|
||||
" Resolved to: 1200000.0\n",
|
||||
" Conflict detected in field 'name':\n",
|
||||
" Values: ['TechFlow AI', 'TechFlow Inc.']\n",
|
||||
"\n",
|
||||
"Cleaned Data: 5 entities remaining.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 1. Detect Duplicates\n",
|
||||
"print(\"Scanning for duplicates...\")\n",
|
||||
"deduper = DuplicateDetector(similarity_threshold=0.7) # 70% similarity threshold\n",
|
||||
"duplicates = deduper.detect_duplicates(raw_entities)\n",
|
||||
"\n",
|
||||
"for candidate in duplicates:\n",
|
||||
" print(f\"Found potential duplicate pair (Score: {candidate.similarity_score:.2f}):\")\n",
|
||||
" print(f\" - {candidate.entity1['name']} (ID: {candidate.entity1['id']})\")\n",
|
||||
" print(f\" - {candidate.entity2['name']} (ID: {candidate.entity2['id']})\")\n",
|
||||
" \n",
|
||||
" # MERGE STRATEGY: Keep entity1, merge data from entity2\n",
|
||||
" print(\" Merging entities...\")\n",
|
||||
" # (In a real app, you'd use EntityMerger, but here's the logic:)\n",
|
||||
" # We keep startup_1 and discard startup_1_dup, but we note the conflict\n",
|
||||
" \n",
|
||||
"# 2. Detect Conflicts\n",
|
||||
"print(\"\\nChecking for data conflicts...\")\n",
|
||||
"conflict_detector = ConflictDetector()\n",
|
||||
"\n",
|
||||
"# Simulating a conflict check between the two versions of TechFlow\n",
|
||||
"# To check conflicts, we treat them as the same entity (same ID)\n",
|
||||
"entity_a = raw_entities[0].copy()\n",
|
||||
"entity_b = raw_entities[2].copy()\n",
|
||||
"entity_b['id'] = entity_a['id'] # Force same ID for conflict detection\n",
|
||||
"\n",
|
||||
"conflicts = conflict_detector.detect_conflicts([entity_a, entity_b])\n",
|
||||
"\n",
|
||||
"for conflict in conflicts:\n",
|
||||
" print(f\" Conflict detected in field '{conflict.property_name}':\")\n",
|
||||
" print(f\" Values: {conflict.conflicting_values}\")\n",
|
||||
" \n",
|
||||
" # RESOLUTION: Trust the higher number (optimistic!)\n",
|
||||
" if conflict.property_name == \"revenue\":\n",
|
||||
" # values are strings or ints, need to handle types\n",
|
||||
" vals = [float(v) for v in conflict.conflicting_values if v is not None]\n",
|
||||
" resolved_val = max(vals)\n",
|
||||
" print(f\" Resolved to: {resolved_val}\")\n",
|
||||
" raw_entities[0]['revenue'] = resolved_val\n",
|
||||
"\n",
|
||||
"# Final Cleanup: Remove the duplicate entity from our list\n",
|
||||
"clean_entities = [e for e in raw_entities if e['id'] != 'startup_1_dup']\n",
|
||||
"clean_relationships = raw_relationships # (We'd normally re-link relationships too)\n",
|
||||
"\n",
|
||||
"print(f\"\\nCleaned Data: {len(clean_entities)} entities remaining.\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 4. Phase 3: Building the Knowledge Graph\n",
|
||||
"\n",
|
||||
"Now that our data is clean, we build the official graph object."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Knowledge Graph Assembled Successfully!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Manual Graph Construction (since we already cleaned it)\n",
|
||||
"kg = {\n",
|
||||
" \"entities\": clean_entities,\n",
|
||||
" \"relationships\": clean_relationships,\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"created_at\": datetime.now().isoformat(),\n",
|
||||
" \"source\": \"Manual Advanced Pipeline\"\n",
|
||||
" }\n",
|
||||
"}\n",
|
||||
"print(\"Knowledge Graph Assembled Successfully!\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 5. Phase 4: Advanced Analytics\n",
|
||||
"\n",
|
||||
"This is where the magic happens. We'll use multiple analyzers to extract insights."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2025-12-19 16:09:52,395 - INFO - Centrality calculator initialized\n",
|
||||
"2025-12-19 16:09:52,396 - INFO - Graph analyzer initialized (temporal: True)\n",
|
||||
"2025-12-19 16:09:52,398 - INFO - Analyzing graph connectivity\n",
|
||||
"2025-12-19 16:09:52,398 - INFO - Finding connected components\n",
|
||||
"2025-12-19 16:09:52,399 - INFO - Calculating connectivity metrics\n",
|
||||
"2025-12-19 16:09:52,399 - INFO - Calculating all centrality measures\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n",
|
||||
"--- Connectivity Analysis ---\n",
|
||||
" • Graph Connected? Yes\n",
|
||||
" • Connected Components: 1\n",
|
||||
"\n",
|
||||
"--- Centrality Analysis ---\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2025-12-19 16:09:52,403 - INFO - [RUNNING] | Module: kg | Submodule: CentralityCalculator | Message: Calculating degree centrality\n",
|
||||
"2025-12-19 16:09:52,403 - INFO - Calculating degree centrality\n",
|
||||
"2025-12-19 16:09:52,406 - INFO - [RUNNING] | Module: kg | Submodule: CentralityCalculator | Message: Processing graph structure...\n",
|
||||
"2025-12-19 16:09:52,409 - INFO - [COMPLETED] | Module: kg | Submodule: CentralityCalculator | Message: Calculated degree centrality for 4 nodes\n",
|
||||
"2025-12-19 16:09:52,410 - INFO - Detecting communities using louvain algorithm\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" • Top Influencers (Degree Centrality):\n",
|
||||
" - founder_1: 0.67\n",
|
||||
" - startup_1: 0.67\n",
|
||||
" - startup_2: 0.33\n",
|
||||
"\n",
|
||||
"--- Community Detection ---\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2025-12-19 16:09:52,413 - INFO - [RUNNING] | Module: kg | Submodule: CommunityDetector | Message: Detecting communities using Louvain algorithm\n",
|
||||
"2025-12-19 16:09:52,414 - INFO - Detecting communities using Louvain algorithm\n",
|
||||
"2025-12-19 16:09:52,417 - INFO - [RUNNING] | Module: kg | Submodule: CommunityDetector | Message: Detecting communities with NetworkX...\n",
|
||||
"2025-12-19 16:09:52,422 - INFO - [COMPLETED] | Module: kg | Submodule: CommunityDetector | Message: Detected 2 communities\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" • Detected 2 communities.\n",
|
||||
" Community 1: investor_1, startup_1\n",
|
||||
" Community 2: startup_2, founder_1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Initialize the Master Analyzer\n",
|
||||
"analyzer = GraphAnalyzer(enable_temporal=True)\n",
|
||||
"\n",
|
||||
"# 1. Structural Analysis (Connectivity)\n",
|
||||
"print(\"\\n--- Connectivity Analysis ---\")\n",
|
||||
"connectivity = analyzer.analyze_connectivity(kg)\n",
|
||||
"print(f\" • Graph Connected? {'Yes' if connectivity['is_connected'] else 'No'}\")\n",
|
||||
"print(f\" • Connected Components: {connectivity['num_components']}\")\n",
|
||||
"\n",
|
||||
"# 2. Centrality (Who is important?)\n",
|
||||
"print(\"\\n--- Centrality Analysis ---\")\n",
|
||||
"centrality_result = analyzer.calculate_centrality(kg, centrality_type=\"degree\")\n",
|
||||
"degree_data = centrality_result[\"centrality_measures\"][\"degree\"]\n",
|
||||
"\n",
|
||||
"# Get pre-calculated rankings\n",
|
||||
"top_nodes = degree_data[\"rankings\"][:3]\n",
|
||||
"\n",
|
||||
"print(\" • Top Influencers (Degree Centrality):\")\n",
|
||||
"for item in top_nodes:\n",
|
||||
" print(f\" - {item['node']}: {item['score']:.2f}\")\n",
|
||||
"\n",
|
||||
"# 3. Community Detection (Clustering)\n",
|
||||
"print(\"\\n--- Community Detection ---\")\n",
|
||||
"community_result = analyzer.detect_communities(kg, algorithm=\"louvain\")\n",
|
||||
"communities = community_result[\"communities\"]\n",
|
||||
"\n",
|
||||
"print(f\" • Detected {len(communities)} communities.\")\n",
|
||||
"for i, comm in enumerate(communities):\n",
|
||||
" # comm is a set of node IDs\n",
|
||||
" members = list(comm)\n",
|
||||
" print(f\" Community {i+1}: {', '.join(members)}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 6. Phase 5: Temporal Analytics (Time Travel)\n",
|
||||
"\n",
|
||||
"Static graphs are boring. Real worlds change. Let's analyze the **evolution** of our ecosystem."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2025-12-19 16:09:58,419 - INFO - Querying graph at time: 2020-06-01\n",
|
||||
"2025-12-19 16:09:58,420 - INFO - Querying graph at time: 2023-07-01\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n",
|
||||
"--- Time Travel: 2020 ---\n",
|
||||
" Active Relationships in 2020: 1\n",
|
||||
" - founder_1 --[ADVISED]--> startup_2\n",
|
||||
"\n",
|
||||
"--- Time Travel: 2023 ---\n",
|
||||
" Active Relationships in 2023: 2\n",
|
||||
" - founder_1 --[FOUNDED]--> startup_1\n",
|
||||
" - investor_1 --[INVESTED_IN]--> startup_1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"temporal_engine = TemporalGraphQuery(temporal_granularity=\"year\")\n",
|
||||
"\n",
|
||||
"# 1. Time Travel Query: What did the world look like in 2020?\n",
|
||||
"print(\"\\n--- Time Travel: 2020 ---\")\n",
|
||||
"snapshot_2020 = temporal_engine.query_at_time(kg, query=\"*\", at_time=\"2020-06-01\")\n",
|
||||
"print(f\" Active Relationships in 2020: {len(snapshot_2020['relationships'])}\")\n",
|
||||
"for rel in snapshot_2020['relationships']:\n",
|
||||
" print(f\" - {rel['source']} --[{rel['type']}]--> {rel['target']}\")\n",
|
||||
"\n",
|
||||
"# 2. Time Travel Query: What about 2023?\n",
|
||||
"print(\"\\n--- Time Travel: 2023 ---\")\n",
|
||||
"snapshot_2023 = temporal_engine.query_at_time(kg, query=\"*\", at_time=\"2023-07-01\")\n",
|
||||
"print(f\" Active Relationships in 2023: {len(snapshot_2023['relationships'])}\")\n",
|
||||
"for rel in snapshot_2023['relationships']:\n",
|
||||
" print(f\" - {rel['source']} --[{rel['type']}]--> {rel['target']}\")\n",
|
||||
" \n",
|
||||
"# Notice how 'ADVISED' might disappear if it ended, and 'INVESTED_IN' appears!"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 7. Phase 6: Provenance (Data Lineage)\n",
|
||||
"\n",
|
||||
"Finally, in a production system, you need to know **where** a fact came from. This is crucial for trust."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n",
|
||||
"--- Provenance Report: TechFlow AI ---\n",
|
||||
" Entity: startup_1\n",
|
||||
" First Seen: 2025-12-19T16:13:07.782408\n",
|
||||
" Sources:\n",
|
||||
" - Crunchbase_API_v2 (at 2025-12-19T16:13:07.782408)\n",
|
||||
" - Manual_Entry_User_Bob (at 2025-12-19T16:13:07.782408)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"tracker = ProvenanceTracker()\n",
|
||||
"\n",
|
||||
"# Let's pretend we're tracking the source of our data\n",
|
||||
"tracker.track_entity(\"startup_1\", source=\"Crunchbase_API_v2\", metadata={\"confidence\": 0.95})\n",
|
||||
"tracker.track_entity(\"startup_1\", source=\"Manual_Entry_User_Bob\", metadata={\"confidence\": 1.0})\n",
|
||||
"\n",
|
||||
"print(\"\\n--- Provenance Report: TechFlow AI ---\")\n",
|
||||
"lineage = tracker.get_lineage(\"startup_1\")\n",
|
||||
"print(f\" Entity: startup_1\")\n",
|
||||
"print(f\" First Seen: {lineage['first_seen']}\")\n",
|
||||
"print(f\" Sources:\")\n",
|
||||
"for src in lineage['sources']:\n",
|
||||
" print(f\" - {src['source']} (at {src['timestamp']})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Conclusion\n",
|
||||
"\n",
|
||||
"You have just walked through a complete, advanced Knowledge Graph pipeline:\n",
|
||||
"\n",
|
||||
"1. **Validated** messy input data.\n",
|
||||
"2. **Cleaned** duplicates and conflicts.\n",
|
||||
"3. **Analyzed** structure and community dynamics.\n",
|
||||
"4. **Queried** across time dimensions.\n",
|
||||
"5. **Tracked** data lineage.\n",
|
||||
"\n",
|
||||
"This represents the state-of-the-art in modern KG Engineering using Semantica."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,254 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/04_Conflict_Resolution_Strategies.ipynb)\n",
|
||||
"\n",
|
||||
"# Conflict Resolution Strategies\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"Detect conflicts in knowledge graphs, apply multiple resolution strategies, track sources, and maintain audit trails.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/conflicts/)\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install Semantica from PyPI:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"# Or with all optional dependencies:\n",
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Workflow: Detect Conflicts → Multiple Resolution Strategies → Track Sources → Audit\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from datetime import datetime\n",
|
||||
"import json\n",
|
||||
"from semantica.conflicts import ConflictDetector, ConflictResolver, SourceTracker\n",
|
||||
"from semantica.conflicts.conflict_resolver import ResolutionStrategy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 1: Define Entities with Conflicting Data\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"entities = [\n",
|
||||
" {\n",
|
||||
" \"id\": \"e1\",\n",
|
||||
" \"type\": \"Person\",\n",
|
||||
" \"name\": \"John Doe\",\n",
|
||||
" \"age\": 30,\n",
|
||||
" \"location\": \"New York\",\n",
|
||||
" \"source\": \"source1\",\n",
|
||||
" \"confidence\": 0.8,\n",
|
||||
" \"metadata\": {\"timestamp\": datetime(2023, 1, 1)}\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"id\": \"e1\",\n",
|
||||
" \"type\": \"Person\",\n",
|
||||
" \"name\": \"John Doe\",\n",
|
||||
" \"age\": 32,\n",
|
||||
" \"location\": \"Boston\",\n",
|
||||
" \"source\": \"source2\",\n",
|
||||
" \"confidence\": 0.9,\n",
|
||||
" \"metadata\": {\"timestamp\": datetime(2023, 6, 1)}\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"id\": \"e2\",\n",
|
||||
" \"type\": \"Organization\",\n",
|
||||
" \"name\": \"Tech Corp\",\n",
|
||||
" \"founded\": 2010,\n",
|
||||
" \"employees\": 100,\n",
|
||||
" \"source\": \"source1\",\n",
|
||||
" \"confidence\": 0.9,\n",
|
||||
" \"metadata\": {\"timestamp\": datetime(2023, 1, 1)}\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"id\": \"e2\",\n",
|
||||
" \"type\": \"Organization\",\n",
|
||||
" \"name\": \"Tech Corp\",\n",
|
||||
" \"founded\": 2012,\n",
|
||||
" \"employees\": 150,\n",
|
||||
" \"source\": \"source2\",\n",
|
||||
" \"confidence\": 0.7,\n",
|
||||
" \"metadata\": {\"timestamp\": datetime(2023, 3, 1)}\n",
|
||||
" }\n",
|
||||
"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 2: Detect Conflicts\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize detector\n",
|
||||
"detector = ConflictDetector(track_provenance=True)\n",
|
||||
"\n",
|
||||
"# Detect conflicts across all properties\n",
|
||||
"conflicts = detector.detect_entity_conflicts(entities)\n",
|
||||
"\n",
|
||||
"print(f\"Detected {len(conflicts)} conflicts:\")\n",
|
||||
"for i, conflict in enumerate(conflicts, 1):\n",
|
||||
" print(f\"\\nConflict {i}:\")\n",
|
||||
" print(f\" ID: {conflict.conflict_id}\")\n",
|
||||
" print(f\" Type: {conflict.conflict_type.value}\")\n",
|
||||
" print(f\" Entity: {conflict.entity_id}\")\n",
|
||||
" print(f\" Property: {conflict.property_name}\")\n",
|
||||
" print(f\" Values: {conflict.conflicting_values}\")\n",
|
||||
" print(f\" Severity: {conflict.severity}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Resolve Conflicts\n",
|
||||
"\n",
|
||||
"We can apply different strategies to resolve the conflicts:\n",
|
||||
"- **Voting**: Selects the most frequent value\n",
|
||||
"- **Most Recent**: Selects the value with the latest timestamp\n",
|
||||
"- **Highest Confidence**: Selects the value from the source with highest confidence\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize resolver\n",
|
||||
"resolver = ConflictResolver()\n",
|
||||
"\n",
|
||||
"# Strategy 1: Voting\n",
|
||||
"print(\"--- Strategy: Voting ---\")\n",
|
||||
"results_voting = resolver.resolve_conflicts(conflicts, strategy=\"voting\")\n",
|
||||
"for r in results_voting:\n",
|
||||
" if r.resolved:\n",
|
||||
" print(f\"Resolved {r.conflict_id}: {r.resolved_value} (Confidence: {r.confidence:.2f})\")\n",
|
||||
"\n",
|
||||
"# Strategy 2: Most Recent\n",
|
||||
"print(\"\\n--- Strategy: Most Recent ---\")\n",
|
||||
"results_recent = resolver.resolve_conflicts(conflicts, strategy=\"most_recent\")\n",
|
||||
"for r in results_recent:\n",
|
||||
" if r.resolved:\n",
|
||||
" print(f\"Resolved {r.conflict_id}: {r.resolved_value}\")\n",
|
||||
"\n",
|
||||
"# Strategy 3: Highest Confidence\n",
|
||||
"print(\"\\n--- Strategy: Highest Confidence ---\")\n",
|
||||
"results_confidence = resolver.resolve_conflicts(conflicts, strategy=\"highest_confidence\")\n",
|
||||
"for r in results_confidence:\n",
|
||||
" if r.resolved:\n",
|
||||
" print(f\"Resolved {r.conflict_id}: {r.resolved_value} (Confidence: {r.confidence:.2f})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 4: Track Sources\n",
|
||||
"\n",
|
||||
"The `ConflictDetector` tracks source provenance when `track_provenance=True`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tracker = detector.source_tracker\n",
|
||||
"\n",
|
||||
"for conflict in conflicts:\n",
|
||||
" print(f\"\\nConflict: {conflict.conflict_id}\")\n",
|
||||
" # Get detailed source info for the property\n",
|
||||
" sources = tracker.get_property_sources(conflict.entity_id, conflict.property_name)\n",
|
||||
" if sources:\n",
|
||||
" print(f\" Entity: {conflict.entity_id}, Property: {conflict.property_name}\")\n",
|
||||
" print(f\" Sources found: {len(sources.sources)}\")\n",
|
||||
" for src in sources.sources:\n",
|
||||
" print(f\" - {src.document} (Confidence: {src.confidence})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 5: Audit Trail\n",
|
||||
"\n",
|
||||
"The `ConflictResolver` maintains a history of all resolutions."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"history = resolver.get_resolution_history()\n",
|
||||
"\n",
|
||||
"print(f\"Resolution History ({len(history)} entries):\")\n",
|
||||
"for entry in history:\n",
|
||||
" print(f\"\\nConflict: {entry.conflict_id}\")\n",
|
||||
" print(f\" Strategy: {entry.resolution_strategy}\")\n",
|
||||
" print(f\" Resolved Value: {entry.resolved_value}\")\n",
|
||||
" print(f\" Notes: {entry.resolution_notes}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"Conflict resolution workflow:\n",
|
||||
"- Conflict Detection using `ConflictDetector`\n",
|
||||
"- Multiple Resolution Strategies (Voting, Most Recent, Highest Confidence)\n",
|
||||
"- Source Tracking with `SourceTracker`\n",
|
||||
"- Complete Audit Trail via `ConflictResolver`"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -48,6 +48,15 @@
|
||||
"```\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -593,14 +602,14 @@
|
||||
" \"exports/report.txt\"\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"print(\"📊 Export Summary:\")\n",
|
||||
"print(\"\ud83d\udcca Export Summary:\")\n",
|
||||
"print(\"=\" * 60)\n",
|
||||
"for file in export_files:\n",
|
||||
" if os.path.exists(file):\n",
|
||||
" size = os.path.getsize(file)\n",
|
||||
" print(f\"✅ {file:50} ({size:>10,} bytes)\")\n",
|
||||
" print(f\"\u2705 {file:50} ({size:>10,} bytes)\")\n",
|
||||
" else:\n",
|
||||
" print(f\"❌ {file:50} (not found)\")\n",
|
||||
" print(f\"\u274c {file:50} (not found)\")\n",
|
||||
"\n",
|
||||
"print(\"=\" * 60)\n",
|
||||
"print(f\"Total files checked: {len(export_files)}\")\n",
|
||||
@@ -620,4 +629,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,233 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/07_Pipeline_Orchestration.ipynb)\n",
|
||||
"\n",
|
||||
"# Pipeline Orchestration\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"Build complex pipelines, execute them, handle failures, enable parallel processing, and monitor execution.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/pipeline/)\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install Semantica from PyPI:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"# Or with all optional dependencies:\n",
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Workflow: Build Pipelines → Execute → Handle Failures → Parallel Processing → Monitor\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.pipeline import (\n",
|
||||
" PipelineBuilder,\n",
|
||||
" ExecutionEngine,\n",
|
||||
" FailureHandler,\n",
|
||||
" ParallelismManager,\n",
|
||||
" RetryPolicy,\n",
|
||||
" RetryStrategy\n",
|
||||
")\n",
|
||||
"from semantica.ingest import FileIngestor\n",
|
||||
"from semantica.parse import DocumentParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor\n",
|
||||
"from semantica.kg import GraphBuilder\n",
|
||||
"import time\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 1: Build Complex Pipelines\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"builder = PipelineBuilder()\n",
|
||||
"\n",
|
||||
"file_ingestor = FileIngestor()\n",
|
||||
"document_parser = DocumentParser()\n",
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"graph_builder = GraphBuilder()\n",
|
||||
"\n",
|
||||
"# Define handlers for each pipeline step\n",
|
||||
"def ingest_handler(data, **config):\n",
|
||||
" files = data.get(\"files\", [])\n",
|
||||
" if files:\n",
|
||||
" # Ingest first file as example\n",
|
||||
" file_obj = file_ingestor.ingest_file(files[0], read_content=True)\n",
|
||||
" return {**data, \"file\": file_obj}\n",
|
||||
" return data\n",
|
||||
"\n",
|
||||
"def parse_handler(data, **config):\n",
|
||||
" # If a file was ingested, try parsing; otherwise pass text through\n",
|
||||
" file_obj = data.get(\"file\")\n",
|
||||
" if file_obj and getattr(file_obj, \"path\", None):\n",
|
||||
" parsed = document_parser.parse_document(file_obj.path)\n",
|
||||
" text = parsed.get(\"text\") if isinstance(parsed, dict) else None\n",
|
||||
" return {**data, \"text\": text or data.get(\"text\")}\n",
|
||||
" return data\n",
|
||||
"\n",
|
||||
"def extract_handler(data, **config):\n",
|
||||
" text = data.get(\"text\", \"\")\n",
|
||||
" entities = ner_extractor.extract_entities(text)\n",
|
||||
" # Normalize to dict list for graph builder\n",
|
||||
" entity_dicts = [\n",
|
||||
" {\"id\": f\"e{i}\", \"name\": e.text, \"type\": e.label} for i, e in enumerate(entities)\n",
|
||||
" ]\n",
|
||||
" return {**data, \"entities\": entity_dicts}\n",
|
||||
"\n",
|
||||
"def build_graph_handler(data, **config):\n",
|
||||
" entities = data.get(\"entities\", [])\n",
|
||||
" graph = graph_builder.build({\"entities\": entities})\n",
|
||||
" return {**data, \"graph\": graph}\n",
|
||||
"\n",
|
||||
"# Build pipeline with proper handlers and dependencies\n",
|
||||
"pipeline = (\n",
|
||||
" builder\n",
|
||||
" .add_step(\"ingest\", \"ingest\", handler=ingest_handler)\n",
|
||||
" .add_step(\"parse\", \"parse\", dependencies=[\"ingest\"], handler=parse_handler)\n",
|
||||
" .add_step(\"extract\", \"extract\", dependencies=[\"parse\"], handler=extract_handler)\n",
|
||||
" .add_step(\"build_graph\", \"build_graph\", dependencies=[\"extract\"], handler=build_graph_handler)\n",
|
||||
").build()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 2: Execute Pipeline\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"engine = ExecutionEngine()\n",
|
||||
"\n",
|
||||
"input_data = {\n",
|
||||
" \"text\": \"Alice works at Tech Corp. Bob is a friend of Alice.\",\n",
|
||||
" \"files\": []\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"start_time = time.time()\n",
|
||||
"result = engine.execute_pipeline(pipeline, input_data)\n",
|
||||
"execution_time = result.metrics.get(\"execution_time\", time.time() - start_time)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Handle Failures\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Configure retry policy for the 'extract' step type\n",
|
||||
"engine.failure_handler.set_retry_policy(\n",
|
||||
" \"extract\",\n",
|
||||
" RetryPolicy(max_retries=3, backoff_factor=2.0, strategy=RetryStrategy.EXPONENTIAL)\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"result = engine.execute_pipeline(pipeline, input_data)\n",
|
||||
"print(\"Pipeline executed with retry policy configured\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 4: Parallel Processing\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"parallelism = ParallelismManager(max_workers=4)\n",
|
||||
"\n",
|
||||
"# Identify groups of steps that can run in parallel\n",
|
||||
"groups = parallelism.identify_parallelizable_steps(pipeline)\n",
|
||||
"\n",
|
||||
"# Execute first parallelizable group as a demonstration\n",
|
||||
"start_time = time.time()\n",
|
||||
"parallel_results = []\n",
|
||||
"for group in groups:\n",
|
||||
" parallel_results.extend(parallelism.execute_pipeline_steps_parallel(group, input_data, max_workers=4))\n",
|
||||
"parallel_time = time.time() - start_time\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 5: Monitor Pipeline Execution\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Metrics from execution engine\n",
|
||||
"metrics = result.metrics\n",
|
||||
"progress = engine.get_progress(pipeline.name)\n",
|
||||
"\n",
|
||||
"print(f\"Duration: {metrics.get('execution_time', 0):.2f} seconds\")\n",
|
||||
"print(f\"Steps Executed: {metrics.get('steps_executed', 0)}\")\n",
|
||||
"print(f\"Steps Failed: {metrics.get('steps_failed', 0)}\")\n",
|
||||
"print(f\"Progress: {progress.get('progress_percentage', 0):.1f}% (status: {progress.get('status')})\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"Pipeline orchestration workflow:\n",
|
||||
"- Complex Pipeline Built\n",
|
||||
"- Pipeline Executed\n",
|
||||
"- Failure Handling Configured\n",
|
||||
"- Parallel Processing Enabled\n",
|
||||
"- Full Monitoring and Observability\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -1,336 +1,457 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/08_Reasoning_and_Inference.ipynb)\n",
|
||||
"\n",
|
||||
"# Reasoning and Inference\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"Build knowledge graphs, define rules, perform forward/backward chaining, and generate explanations for AI reasoning using the **Semantica Reasoning Module**.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/reasoning/)\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install Semantica from PyPI:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"# Or with all optional dependencies:\n",
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Workflow: Build KG → Define Rules → Forward/Backward Chaining → Generate Explanations\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.kg import GraphBuilder\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 1: Build Knowledge Graph\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"builder = GraphBuilder()\n",
|
||||
"\n",
|
||||
"entities = [\n",
|
||||
" {\"id\": \"alice\", \"type\": \"Person\", \"name\": \"Alice\"},\n",
|
||||
" {\"id\": \"bob\", \"type\": \"Person\", \"name\": \"Bob\"},\n",
|
||||
" {\"id\": \"charlie\", \"type\": \"Person\", \"name\": \"Charlie\"},\n",
|
||||
" {\"id\": \"sf\", \"type\": \"Location\", \"name\": \"San Francisco\"},\n",
|
||||
" {\"id\": \"california\", \"type\": \"Location\", \"name\": \"California\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"relationships = [\n",
|
||||
" {\"source\": \"alice\", \"target\": \"bob\", \"type\": \"parent_of\"},\n",
|
||||
" {\"source\": \"bob\", \"target\": \"charlie\", \"type\": \"parent_of\"},\n",
|
||||
" {\"source\": \"sf\", \"target\": \"california\", \"type\": \"located_in\"},\n",
|
||||
" {\"source\": \"alice\", \"target\": \"sf\", \"type\": \"lives_in\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"knowledge_graph = builder.build([{\"entities\": entities, \"relationships\": relationships}])\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 2: Define Rules\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize Inference Engine\n",
|
||||
"engine = InferenceEngine()\n",
|
||||
"\n",
|
||||
"# Define rules using logic syntax\n",
|
||||
"rules = [\n",
|
||||
" \"IF parent_of(?a, ?b) AND parent_of(?b, ?c) THEN grandparent_of(?a, ?c)\",\n",
|
||||
" \"IF lives_in(?x, ?y) AND located_in(?y, ?z) THEN lives_in(?x, ?z)\"\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"for rule in rules:\n",
|
||||
" engine.add_rule(rule)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Forward Chaining\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Load facts from relationships into the engine\n",
|
||||
"for rel in relationships:\n",
|
||||
" # Format: predicate(subject, object)\n",
|
||||
" fact_str = f\"{rel['type']}({rel['source']}, {rel['target']})\"\n",
|
||||
" engine.add_fact(fact_str)\n",
|
||||
"\n",
|
||||
"# Perform forward chaining to derive new facts\n",
|
||||
"results = engine.forward_chain()\n",
|
||||
"\n",
|
||||
"print(f\"Inferred {len(results)} new facts:\")\n",
|
||||
"for result in results:\n",
|
||||
" print(f\" - {result.conclusion} (Rule: {result.rule_used.name})\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 4: Backward Chaining\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Define a goal to prove\n",
|
||||
"goal = \"grandparent_of(alice, charlie)\"\n",
|
||||
"\n",
|
||||
"# Perform backward chaining\n",
|
||||
"proof = engine.backward_chain(goal)\n",
|
||||
"\n",
|
||||
"if proof:\n",
|
||||
" print(f\"Goal '{goal}' proven successfully!\")\n",
|
||||
"else:\n",
|
||||
" print(f\"Could not prove goal '{goal}'.\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 5: Generate Explanations\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"generator = ExplanationGenerator()\n",
|
||||
"\n",
|
||||
"# Explain the last forward chaining inference\n",
|
||||
"if results:\n",
|
||||
" explanation = generator.generate_explanation(results[0])\n",
|
||||
" print(\"Explanation for first inferred fact:\")\n",
|
||||
" print(explanation.natural_language)\n",
|
||||
"\n",
|
||||
"# If we have a proof from backward chaining, explain it\n",
|
||||
"if proof:\n",
|
||||
" proof_explanation = generator.generate_explanation(proof)\n",
|
||||
" print(\"\\nExplanation for backward chaining proof:\")\n",
|
||||
" print(proof_explanation.natural_language)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"Reasoning and inference workflow:\n",
|
||||
"- Knowledge Graph Built\n",
|
||||
"- Inference Rules Defined\n",
|
||||
"- Facts Loaded into Engine\n",
|
||||
"- Forward Chaining Performed\n",
|
||||
"- Backward Chaining Performed\n",
|
||||
"- Explanations Generated\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"### Deep Dive: Reasoning Module\n",
|
||||
"\n",
|
||||
"This section provides an in-depth guide to Semantica's reasoning capabilities. Learn rule syntax, fact formats, chaining strategies, and explanation generation with robust, reproducible examples.\n",
|
||||
"\n",
|
||||
"**What you'll practice**\n",
|
||||
"- Defining rules with variables and predicates\n",
|
||||
"- Loading facts in predicate form\n",
|
||||
"- Running forward and backward chaining\n",
|
||||
"- Generating human-readable explanations\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.kg import GraphBuilder\n",
|
||||
"from semantica.reasoning import InferenceEngine, ExplanationGenerator\n",
|
||||
"\n",
|
||||
"builder = GraphBuilder()\n",
|
||||
"engine = InferenceEngine()\n",
|
||||
"explainer = ExplanationGenerator()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Rule Syntax\n",
|
||||
"\n",
|
||||
"Rules use predicate logic with variables prefixed by `?`.\n",
|
||||
"\n",
|
||||
"- Example: `IF parent_of(?a, ?b) AND parent_of(?b, ?c) THEN grandparent_of(?a, ?c)`\n",
|
||||
"- Variables unify across predicates in the same rule\n",
|
||||
"- Conclusions are added as new facts when conditions match\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"entities = [\n",
|
||||
" {\"id\": \"alice\", \"type\": \"Person\", \"name\": \"Alice\"},\n",
|
||||
" {\"id\": \"bob\", \"type\": \"Person\", \"name\": \"Bob\"},\n",
|
||||
" {\"id\": \"charlie\", \"type\": \"Person\", \"name\": \"Charlie\"},\n",
|
||||
" {\"id\": \"sf\", \"type\": \"Location\", \"name\": \"San Francisco\"},\n",
|
||||
" {\"id\": \"california\", \"type\": \"Location\", \"name\": \"California\"}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"relationships = [\n",
|
||||
" {\"source\": \"alice\", \"target\": \"bob\", \"type\": \"parent_of\"},\n",
|
||||
" {\"source\": \"bob\", \"target\": \"charlie\", \"type\": \"parent_of\"},\n",
|
||||
" {\"source\": \"sf\", \"target\": \"california\", \"type\": \"located_in\"},\n",
|
||||
" {\"source\": \"alice\", \"target\": \"sf\", \"type\": \"lives_in\"}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"knowledge_graph = builder.build([{\"entities\": entities, \"relationships\": relationships}])\n",
|
||||
"print(len(knowledge_graph.get(\"entities\", [])))\n",
|
||||
"print(len(knowledge_graph.get(\"relationships\", [])))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"rules = [\n",
|
||||
" \"IF parent_of(?a, ?b) AND parent_of(?b, ?c) THEN grandparent_of(?a, ?c)\",\n",
|
||||
" \"IF lives_in(?x, ?y) AND located_in(?y, ?z) THEN lives_in(?x, ?z)\"\n",
|
||||
"]\n",
|
||||
"for r in rules:\n",
|
||||
" engine.add_rule(r)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for rel in relationships:\n",
|
||||
" fact = f\"{rel['type']}({rel['source']}, {rel['target']})\"\n",
|
||||
" engine.add_fact(fact)\n",
|
||||
"\n",
|
||||
"derived = engine.forward_chain()\n",
|
||||
"print(len(derived))\n",
|
||||
"for d in derived:\n",
|
||||
" print(d.conclusion)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"goals = [\n",
|
||||
" \"grandparent_of(alice, charlie)\",\n",
|
||||
" \"lives_in(alice, california)\"\n",
|
||||
"]\n",
|
||||
"for g in goals:\n",
|
||||
" proof = engine.backward_chain(g)\n",
|
||||
" print(g)\n",
|
||||
" print(bool(proof))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if derived:\n",
|
||||
" exp = explainer.generate_explanation(derived[0])\n",
|
||||
" print(exp.natural_language)\n",
|
||||
"\n",
|
||||
"goal = \"grandparent_of(alice, charlie)\"\n",
|
||||
"proof = engine.backward_chain(goal)\n",
|
||||
"if proof:\n",
|
||||
" pexp = explainer.generate_explanation(proof)\n",
|
||||
" print(pexp.natural_language)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/08_Reasoning_and_Inference.ipynb)\n",
|
||||
"\n",
|
||||
"# Reasoning and Inference\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"Build knowledge graphs, define rules, perform forward/backward chaining, and generate explanations for AI reasoning using the **Semantica Reasoning Module**.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/reasoning/)\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install Semantica from PyPI:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"# Or with all optional dependencies:\n",
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Workflow: Build KG → Define Rules → Forward/Backward Chaining → Generate Explanations\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install -qU semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.kg import GraphBuilder\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 1: Build Knowledge Graph\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is building</td><td>🧠 kg</td><td>GraphBuilder</td><td>-</td><td>0.31s</td></tr><tr><td>🔄</td><td>Semantica is building</td><td>🧠 kg</td><td>EntityResolver</td><td>-</td><td>2.16s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>DuplicateDetector</td><td>-</td><td>0.02s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>SimilarityCalculator</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>EntityMerger</td><td>-</td><td>0.05s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>MergeStrategyManager</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is resolving</td><td>⚠️ conflicts</td><td>ConflictDetector</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is reasoning</td><td>🤔 reasoning</td><td>RuleManager</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is reasoning</td><td>🤔 reasoning</td><td>InferenceEngine</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is reasoning</td><td>🤔 reasoning</td><td>ExplanationGenerator</td><td>-</td><td>0.01s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"builder = GraphBuilder()\n",
|
||||
"\n",
|
||||
"entities = [\n",
|
||||
" {\"id\": \"alice\", \"type\": \"Person\", \"name\": \"Alice\"},\n",
|
||||
" {\"id\": \"bob\", \"type\": \"Person\", \"name\": \"Bob\"},\n",
|
||||
" {\"id\": \"charlie\", \"type\": \"Person\", \"name\": \"Charlie\"},\n",
|
||||
" {\"id\": \"sf\", \"type\": \"Location\", \"name\": \"San Francisco\"},\n",
|
||||
" {\"id\": \"california\", \"type\": \"Location\", \"name\": \"California\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"relationships = [\n",
|
||||
" {\"source\": \"alice\", \"target\": \"bob\", \"type\": \"parent_of\"},\n",
|
||||
" {\"source\": \"bob\", \"target\": \"charlie\", \"type\": \"parent_of\"},\n",
|
||||
" {\"source\": \"sf\", \"target\": \"california\", \"type\": \"located_in\"},\n",
|
||||
" {\"source\": \"alice\", \"target\": \"sf\", \"type\": \"lives_in\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"knowledge_graph = builder.build([{\"entities\": entities, \"relationships\": relationships}])\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 2: Define Rules\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize Inference Engine\n",
|
||||
"engine = InferenceEngine()\n",
|
||||
"\n",
|
||||
"# Define rules using logic syntax\n",
|
||||
"rules = [\n",
|
||||
" \"IF parent_of(?a, ?b) AND parent_of(?b, ?c) THEN grandparent_of(?a, ?c)\",\n",
|
||||
" \"IF lives_in(?x, ?y) AND located_in(?y, ?z) THEN lives_in(?x, ?z)\"\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"for rule in rules:\n",
|
||||
" engine.add_rule(rule)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Forward Chaining\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Inferred 2 new facts:\n",
|
||||
" - grandparent_of(alice, charlie) (Rule: Rule 1)\n",
|
||||
" - lives_in(alice, california) (Rule: Rule 2)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Load facts from relationships into the engine\n",
|
||||
"for rel in relationships:\n",
|
||||
" # Format: predicate(subject, object)\n",
|
||||
" fact_str = f\"{rel['type']}({rel['source']}, {rel['target']})\"\n",
|
||||
" engine.add_fact(fact_str)\n",
|
||||
"\n",
|
||||
"# Perform forward chaining to derive new facts\n",
|
||||
"results = engine.forward_chain()\n",
|
||||
"\n",
|
||||
"print(f\"Inferred {len(results)} new facts:\")\n",
|
||||
"for result in results:\n",
|
||||
" print(f\" - {result.conclusion} (Rule: {result.rule_used.name})\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 4: Backward Chaining\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Goal 'grandparent_of(alice, charlie)' proven successfully!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Define a goal to prove\n",
|
||||
"goal = \"grandparent_of(alice, charlie)\"\n",
|
||||
"\n",
|
||||
"# Perform backward chaining\n",
|
||||
"proof = engine.backward_chain(goal)\n",
|
||||
"\n",
|
||||
"if proof:\n",
|
||||
" print(f\"Goal '{goal}' proven successfully!\")\n",
|
||||
"else:\n",
|
||||
" print(f\"Could not prove goal '{goal}'.\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 5: Generate Explanations\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Explanation for first inferred fact:\n",
|
||||
"Given the premises: parent_of(alice, bob), parent_of(bob, charlie), we conclude: grandparent_of(alice, charlie) using rule 'Rule 1'.\n",
|
||||
"\n",
|
||||
"Explanation for backward chaining proof:\n",
|
||||
"Given the premises: , we conclude: grandparent_of(alice, charlie).\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"generator = ExplanationGenerator()\n",
|
||||
"\n",
|
||||
"# Explain the last forward chaining inference\n",
|
||||
"if results:\n",
|
||||
" explanation = generator.generate_explanation(results[0])\n",
|
||||
" print(\"Explanation for first inferred fact:\")\n",
|
||||
" print(explanation.natural_language)\n",
|
||||
"\n",
|
||||
"# If we have a proof from backward chaining, explain it\n",
|
||||
"if proof:\n",
|
||||
" proof_explanation = generator.generate_explanation(proof)\n",
|
||||
" print(\"\\nExplanation for backward chaining proof:\")\n",
|
||||
" print(proof_explanation.natural_language)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"Reasoning and inference workflow:\n",
|
||||
"- Knowledge Graph Built\n",
|
||||
"- Inference Rules Defined\n",
|
||||
"- Facts Loaded into Engine\n",
|
||||
"- Forward Chaining Performed\n",
|
||||
"- Backward Chaining Performed\n",
|
||||
"- Explanations Generated\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"### Deep Dive: Reasoning Module\n",
|
||||
"\n",
|
||||
"This section provides an in-depth guide to Semantica's reasoning capabilities. Learn rule syntax, fact formats, chaining strategies, and explanation generation with robust, reproducible examples.\n",
|
||||
"\n",
|
||||
"**What you'll practice**\n",
|
||||
"- Defining rules with variables and predicates\n",
|
||||
"- Loading facts in predicate form\n",
|
||||
"- Running forward and backward chaining\n",
|
||||
"- Generating human-readable explanations\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.kg import GraphBuilder\n",
|
||||
"from semantica.reasoning import InferenceEngine, ExplanationGenerator\n",
|
||||
"\n",
|
||||
"builder = GraphBuilder()\n",
|
||||
"engine = InferenceEngine()\n",
|
||||
"explainer = ExplanationGenerator()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Rule Syntax\n",
|
||||
"\n",
|
||||
"Rules use predicate logic with variables prefixed by `?`.\n",
|
||||
"\n",
|
||||
"- Example: `IF parent_of(?a, ?b) AND parent_of(?b, ?c) THEN grandparent_of(?a, ?c)`\n",
|
||||
"- Variables unify across predicates in the same rule\n",
|
||||
"- Conclusions are added as new facts when conditions match\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"4\n",
|
||||
"4\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"entities = [\n",
|
||||
" {\"id\": \"alice\", \"type\": \"Person\", \"name\": \"Alice\"},\n",
|
||||
" {\"id\": \"bob\", \"type\": \"Person\", \"name\": \"Bob\"},\n",
|
||||
" {\"id\": \"charlie\", \"type\": \"Person\", \"name\": \"Charlie\"},\n",
|
||||
" {\"id\": \"sf\", \"type\": \"Location\", \"name\": \"San Francisco\"},\n",
|
||||
" {\"id\": \"california\", \"type\": \"Location\", \"name\": \"California\"}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"relationships = [\n",
|
||||
" {\"source\": \"alice\", \"target\": \"bob\", \"type\": \"parent_of\"},\n",
|
||||
" {\"source\": \"bob\", \"target\": \"charlie\", \"type\": \"parent_of\"},\n",
|
||||
" {\"source\": \"sf\", \"target\": \"california\", \"type\": \"located_in\"},\n",
|
||||
" {\"source\": \"alice\", \"target\": \"sf\", \"type\": \"lives_in\"}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"knowledge_graph = builder.build([{\"entities\": entities, \"relationships\": relationships}])\n",
|
||||
"print(len(knowledge_graph.get(\"entities\", [])))\n",
|
||||
"print(len(knowledge_graph.get(\"relationships\", [])))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"rules = [\n",
|
||||
" \"IF parent_of(?a, ?b) AND parent_of(?b, ?c) THEN grandparent_of(?a, ?c)\",\n",
|
||||
" \"IF lives_in(?x, ?y) AND located_in(?y, ?z) THEN lives_in(?x, ?z)\"\n",
|
||||
"]\n",
|
||||
"for r in rules:\n",
|
||||
" engine.add_rule(r)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2\n",
|
||||
"grandparent_of(alice, charlie)\n",
|
||||
"lives_in(alice, california)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for rel in relationships:\n",
|
||||
" fact = f\"{rel['type']}({rel['source']}, {rel['target']})\"\n",
|
||||
" engine.add_fact(fact)\n",
|
||||
"\n",
|
||||
"derived = engine.forward_chain()\n",
|
||||
"print(len(derived))\n",
|
||||
"for d in derived:\n",
|
||||
" print(d.conclusion)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"grandparent_of(alice, charlie)\n",
|
||||
"True\n",
|
||||
"lives_in(alice, california)\n",
|
||||
"True\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"goals = [\n",
|
||||
" \"grandparent_of(alice, charlie)\",\n",
|
||||
" \"lives_in(alice, california)\"\n",
|
||||
"]\n",
|
||||
"for g in goals:\n",
|
||||
" proof = engine.backward_chain(g)\n",
|
||||
" print(g)\n",
|
||||
" print(bool(proof))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Given the premises: parent_of(alice, bob), parent_of(bob, charlie), we conclude: grandparent_of(alice, charlie) using rule 'Rule 1'.\n",
|
||||
"Given the premises: , we conclude: grandparent_of(alice, charlie).\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"if derived:\n",
|
||||
" exp = explainer.generate_explanation(derived[0])\n",
|
||||
" print(exp.natural_language)\n",
|
||||
"\n",
|
||||
"goal = \"grandparent_of(alice, charlie)\"\n",
|
||||
"proof = engine.backward_chain(goal)\n",
|
||||
"if proof:\n",
|
||||
" pexp = explainer.generate_explanation(proof)\n",
|
||||
" print(pexp.natural_language)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
|
||||
@@ -25,7 +25,16 @@
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Workflow: Build KG → Generate Ontology → Create Semantic Layer → Export RDF → Triplet Store\n"
|
||||
"## Workflow: Build KG \u2192 Generate Ontology \u2192 Create Semantic Layer \u2192 Export RDF \u2192 Triplet Store\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -155,7 +164,9 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"exporter = RDFExporter()\n",
|
||||
"exporter.export(knowledge_graph, ontology, \"semantic_layer.rdf\")\n"
|
||||
"# Export Knowledge Graph\n",
|
||||
"exporter.export(knowledge_graph, \"knowledge_graph.ttl\", format=\"turtle\")\n",
|
||||
"print(\"Exported knowledge graph to knowledge_graph.ttl\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -197,4 +208,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,16 @@
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Workflow: Build Temporal KG → Time-Aware Queries → Pattern Detection → Version Management → Visualization\n"
|
||||
"## Workflow: Build Temporal KG \u2192 Time-Aware Queries \u2192 Pattern Detection \u2192 Version Management \u2192 Visualization\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -227,4 +236,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "34af0e1d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/11_Advanced_Context_Engineering.ipynb)\n",
|
||||
@@ -14,71 +15,336 @@
|
||||
"\n",
|
||||
"### Learning Objectives\n",
|
||||
"\n",
|
||||
"- **Custom Memory Pruning**: Implement importance-based pruning instead of FIFO.\n",
|
||||
"- **Hybrid Retrieval Tuning**: Optimize weights for vector, graph, and keyword search.\n",
|
||||
"- **Custom Extensions**: Register custom graph building methods.\n",
|
||||
"- **Performance Optimization**: Balance token limits and retrieval latency.\n",
|
||||
"- **Custom Memory Pruning**: Implement importance-based pruning instead of standard FIFO/token-based pruning.\n",
|
||||
"- **Custom Graph Extensions**: Register custom graph building methods using the registry system.\n",
|
||||
"- **Hybrid Retrieval Tuning**: Optimize weights for vector and graph search.\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## 1. Setup\n",
|
||||
"\n",
|
||||
"We'll start by setting up a mock vector store and importing necessary components."
|
||||
"We'll start by setting up the environment and initializing a standard Vector Store."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"id": "583f944a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install -q semantica"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "70fbd8c1",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"c:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\sentence_transformers\\cross_encoder\\CrossEncoder.py:13: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",
|
||||
" from tqdm.autonotebook import tqdm, trange\n",
|
||||
"WARNING:semantica.text_embedder:fastembed not available. Install with: pip install fastembed. Using fallback embedding method.\n",
|
||||
"INFO:semantica.embedding_generator:Embedding generator initialized\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import logging\n",
|
||||
"from typing import List, Dict, Any, Optional\n",
|
||||
"from semantica.context import AgentMemory, AgentContext, ContextGraph, ContextRetriever, VectorStore\n",
|
||||
"from semantica.context import registry\n",
|
||||
"from semantica.context import AgentMemory, AgentContext, ContextGraph, ContextRetriever\n",
|
||||
"from semantica.vector_store import VectorStore\n",
|
||||
"from semantica.context import registry, methods\n",
|
||||
"\n",
|
||||
"# Mock Vector Store (same as in introduction)\n",
|
||||
"class MockVectorStore(VectorStore):\n",
|
||||
" def __init__(self):\n",
|
||||
" self.items = {}\n",
|
||||
" self.counter = 0\n",
|
||||
" def add(self, texts, metadata=None, **kwargs):\n",
|
||||
" ids = []\n",
|
||||
" for i, text in enumerate(texts):\n",
|
||||
" id_ = f\"id_{self.counter}\"\n",
|
||||
" self.items[id_] = {\"text\": text, \"metadata\": metadata[i] if metadata else {}}\n",
|
||||
" ids.append(id_)\n",
|
||||
" self.counter += 1\n",
|
||||
" return ids\n",
|
||||
" def search(self, query, limit=5, **kwargs):\n",
|
||||
" return [{\n",
|
||||
" \"id\": k, \"content\": v[\"text\"], \"score\": 0.85, \"metadata\": v[\"metadata\"]\n",
|
||||
" } for k, v in list(self.items.items())[:limit]]\n",
|
||||
" def delete(self, ids, **kwargs):\n",
|
||||
" return True\n",
|
||||
"# Configure logging to see internal processes\n",
|
||||
"logging.basicConfig(level=logging.INFO)\n",
|
||||
"\n",
|
||||
"vs = MockVectorStore()\n",
|
||||
"# Initialize Vector Store (using in-memory backend for this example)\n",
|
||||
"# In production, you might use 'weaviate', 'qdrant', or 'faiss'\n",
|
||||
"vs = VectorStore(backend=\"inmemory\", dimension=384)\n",
|
||||
"\n",
|
||||
"# Initialize Context Graph\n",
|
||||
"kg = ContextGraph()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "c2d8299a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 2. Custom Memory Pruning Strategy\n",
|
||||
"\n",
|
||||
"By default, `AgentMemory` uses a FIFO (First-In-First-Out) strategy combined with a token limit to prune short-term memory. However, you might want to keep \"important\" memories longer regardless of their age.\n",
|
||||
"\n",
|
||||
"Let's subclass `AgentMemory` to implement an importance-based pruning strategy."
|
||||
"Let's subclass `AgentMemory` to implement an importance-based pruning strategy that respects metadata flags."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"id": "6edbdd77",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is processing</td><td>🔗 context</td><td>AgentMemory</td><td>-</td><td>0.03s</td></tr><tr><td>✅</td><td>Semantica is embedding</td><td>💾 embeddings</td><td>TextEmbedder</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is indexing</td><td>📊 vector_store</td><td>VectorStore</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is processing</td><td>🔗 context</td><td>ContextRetriever</td><td>-</td><td>0.04s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: IMPORTANT: User's name is Alice...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: IMPORTANT: User's name is Alice...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_e8b0a654c836\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 0 Filler memory 0 Filler memory 0 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 0 Filler memory 0 Filler memory 0 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_deccca2296ee\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 1 Filler memory 1 Filler memory 1 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 1 Filler memory 1 Filler memory 1 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_22ca52874df8\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 2 Filler memory 2 Filler memory 2 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 2 Filler memory 2 Filler memory 2 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_5fd99ffa6ad5\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 3 Filler memory 3 Filler memory 3 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 3 Filler memory 3 Filler memory 3 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_63383a5a0e76\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 4 Filler memory 4 Filler memory 4 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 4 Filler memory 4 Filler memory 4 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_02bd0002e646\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 5 Filler memory 5 Filler memory 5 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 5 Filler memory 5 Filler memory 5 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_7d23cf82ca5d\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 6 Filler memory 6 Filler memory 6 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 6 Filler memory 6 Filler memory 6 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_e3d129ba801a\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 7 Filler memory 7 Filler memory 7 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 7 Filler memory 7 Filler memory 7 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_67c45bc0eb04\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 8 Filler memory 8 Filler memory 8 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 8 Filler memory 8 Filler memory 8 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_063ab85e5808\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 9 Filler memory 9 Filler memory 9 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 9 Filler memory 9 Filler memory 9 Fi...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_b5150f8a3a01\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 10 Filler memory 10 Filler memory 10...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 10 Filler memory 10 Filler memory 10...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_20d87ab406c4\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 11 Filler memory 11 Filler memory 11...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 11 Filler memory 11 Filler memory 11...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_a080f384c8a2\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 12 Filler memory 12 Filler memory 12...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 12 Filler memory 12 Filler memory 12...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_0ed9d0fb154e\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 13 Filler memory 13 Filler memory 13...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 13 Filler memory 13 Filler memory 13...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_f1c9e96ea5e0\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 14 Filler memory 14 Filler memory 14...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 14 Filler memory 14 Filler memory 14...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_72ce868f6c7d\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 15 Filler memory 15 Filler memory 15...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 15 Filler memory 15 Filler memory 15...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_003c8beb510d\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 16 Filler memory 16 Filler memory 16...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 16 Filler memory 16 Filler memory 16...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_43eb17a5f19c\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 17 Filler memory 17 Filler memory 17...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 17 Filler memory 17 Filler memory 17...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_120154aec687\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 18 Filler memory 18 Filler memory 18...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 18 Filler memory 18 Filler memory 18...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_082b2183bf74\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Storing memory: Filler memory 19 Filler memory 19 Filler memory 19...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Generating embedding...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Filler memory 19 Filler memory 19 Filler memory 19...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing 1 vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Storing vectors...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Updating vector index...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Stored 1 vectors\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Stored memory: mem_d28088da8577\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Short-term items count: 5\n",
|
||||
"First item (should be the important one): IMPORTANT: User's name is Alice\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"class ImportanceAwareMemory(AgentMemory):\n",
|
||||
" def _prune_short_term_memory(self):\n",
|
||||
" def _prune_short_term_memory(self) -> None:\n",
|
||||
" \"\"\"\n",
|
||||
" Custom pruning: Always keep items marked as 'important' in metadata,\n",
|
||||
" then prune others based on token limits.\n",
|
||||
@@ -114,75 +380,59 @@
|
||||
" all_kept = sorted(important_items + kept_others, key=lambda x: x.timestamp)\n",
|
||||
" self.short_term_memory = all_kept\n",
|
||||
"\n",
|
||||
"# Test the custom memory\n",
|
||||
"memory = ImportanceAwareMemory(vector_store=vs, token_limit=100)\n",
|
||||
"# Initialize our custom memory with a strict token limit for testing\n",
|
||||
"memory = ImportanceAwareMemory(\n",
|
||||
" vector_store=vs, \n",
|
||||
" token_limit=100, \n",
|
||||
" short_term_limit=50\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Add an old important memory\n",
|
||||
"# 1. Store an OLD but IMPORTANT memory\n",
|
||||
"memory.store(\"IMPORTANT: User's name is Alice\", metadata={\"important\": True})\n",
|
||||
"\n",
|
||||
"# Fill with filler memories\n",
|
||||
"# 2. Flood memory with newer filler content\n",
|
||||
"for i in range(20):\n",
|
||||
" memory.store(f\"Filler memory {i} \" * 5) # Consumes tokens\n",
|
||||
" memory.store(f\"Filler memory {i} \" * 5) # This consumes tokens\n",
|
||||
"\n",
|
||||
"print(f\"Short-term items: {len(memory.short_term_memory)}\")\n",
|
||||
"print(f\"Short-term items count: {len(memory.short_term_memory)}\")\n",
|
||||
"print(\"First item (should be the important one):\", memory.short_term_memory[0].content)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "6f857653",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 3. Tuning Hybrid Retrieval\n",
|
||||
"## 3. Extending with Custom Graph Methods\n",
|
||||
"\n",
|
||||
"Hybrid retrieval combines scores from vector search and graph traversal. You can tune the `hybrid_alpha` parameter to weight these components.\n",
|
||||
"Semantica's registry system allows you to plug in custom logic for graph construction, retrieval, and more. This is powerful for domain-specific graph topologies.\n",
|
||||
"\n",
|
||||
"- `hybrid_alpha = 0.0`: Pure Vector Search\n",
|
||||
"- `hybrid_alpha = 1.0`: Pure Graph Search\n",
|
||||
"- `hybrid_alpha = 0.5`: Balanced (Default)\n",
|
||||
"\n",
|
||||
"Additionally, `max_expansion_hops` controls how far we traverse the graph from retrieved nodes."
|
||||
"Let's register a custom graph builder that creates a \"Star Graph\" topology."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 4,
|
||||
"id": "62cb840c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Available graph methods: {'graph': ['entities_relationships', 'conversations', 'hybrid', 'star_builder']}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Populate graph with some structure\n",
|
||||
"kg.add_node(\"python\", \"concept\", \"Python\")\n",
|
||||
"kg.add_node(\"ml\", \"concept\", \"Machine Learning\")\n",
|
||||
"kg.add_edge(\"python\", \"ml\", \"used_for\")\n",
|
||||
"\n",
|
||||
"retriever = ContextRetriever(\n",
|
||||
" memory_store=memory,\n",
|
||||
" knowledge_graph=kg,\n",
|
||||
" vector_store=vs,\n",
|
||||
" hybrid_alpha=0.7, # Favor graph connections\n",
|
||||
" max_expansion_hops=2 # Traverse deeper\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"results = retriever.retrieve(\"Python\")\n",
|
||||
"for res in results:\n",
|
||||
" print(f\"Source: {res.source}, Score: {res.score:.2f}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 4. Extending with Custom Methods\n",
|
||||
"\n",
|
||||
"Semantica's registry system allows you to plug in custom logic. Let's register a custom graph builder that creates a star graph topology."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def star_graph_builder(center_entity, satellites, **kwargs):\n",
|
||||
"def star_graph_builder(\n",
|
||||
" entities: Optional[List[Dict[str, Any]]] = None,\n",
|
||||
" relationships: Optional[List[Dict[str, Any]]] = None,\n",
|
||||
" conversations: Optional[List[Any]] = None,\n",
|
||||
" center_entity: str = \"Central Hub\",\n",
|
||||
" satellites: Optional[List[str]] = None,\n",
|
||||
" **kwargs\n",
|
||||
") -> Dict[str, Any]:\n",
|
||||
" \"\"\"\n",
|
||||
" Builds a star graph where all satellites connect to the center.\n",
|
||||
" \"\"\"\n",
|
||||
@@ -190,36 +440,154 @@
|
||||
" edges = []\n",
|
||||
" \n",
|
||||
" # Center node\n",
|
||||
" nodes.append({\"id\": \"center\", \"label\": center_entity, \"type\": \"CENTER\"})\n",
|
||||
" nodes.append({\"id\": \"center\", \"type\": \"CENTER\", \"properties\": {\"content\": center_entity}})\n",
|
||||
" \n",
|
||||
" satellites = satellites or []\n",
|
||||
" for i, sat in enumerate(satellites):\n",
|
||||
" sat_id = f\"sat_{i}\"\n",
|
||||
" nodes.append({\"id\": sat_id, \"label\": sat, \"type\": \"SATELLITE\"})\n",
|
||||
" edges.append({\"source\": \"center\", \"target\": sat_id, \"relation\": \"connects_to\"})\n",
|
||||
" nodes.append({\"id\": sat_id, \"type\": \"SATELLITE\", \"properties\": {\"content\": sat}})\n",
|
||||
" edges.append({\"source_id\": \"center\", \"target_id\": sat_id, \"type\": \"connects_to\"})\n",
|
||||
" \n",
|
||||
" return {\"nodes\": nodes, \"edges\": edges}\n",
|
||||
" return {\n",
|
||||
" \"nodes\": nodes, \n",
|
||||
" \"edges\": edges, \n",
|
||||
" \"statistics\": {\"node_count\": len(nodes), \"edge_count\": len(edges)}\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"# Register the method\n",
|
||||
"# Register the method in the global registry\n",
|
||||
"registry.method_registry.register(\"graph\", \"star_builder\", star_graph_builder)\n",
|
||||
"\n",
|
||||
"# Verify registration\n",
|
||||
"print(\"Available graph methods:\", registry.method_registry.list_all(\"graph\"))\n",
|
||||
"\n",
|
||||
"# Use it (conceptual - typically used via build_context_graph wrapper)\n",
|
||||
"graph_data = star_graph_builder(\"Central Hub\", [\"Spoke 1\", \"Spoke 2\"])\n",
|
||||
"print(f\"Created graph with {len(graph_data['nodes'])} nodes and {len(graph_data['edges'])} edges.\")"
|
||||
"print(\"Available graph methods:\", registry.method_registry.list_all(\"graph\"))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "614c3c76",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 5. Best Practices for Production\n",
|
||||
"Now we can use this method via the standard `methods` interface."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "6a324b97",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Created graph with 5 nodes and 4 edges.\n",
|
||||
"Edges sample: {'source_id': 'center', 'target_id': 'sat_0', 'type': 'connects_to'}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Build a graph using our custom method\n",
|
||||
"graph_data = methods.build_context_graph(\n",
|
||||
" method=\"star_builder\",\n",
|
||||
" center_entity=\"Solar System\",\n",
|
||||
" satellites=[\"Earth\", \"Mars\", \"Jupiter\", \"Venus\"]\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"1. **Token Limits**: Align `token_limit` with your LLM's context window minus the prompt template size.\n",
|
||||
"2. **Vector Store**: Use a production-grade vector store (e.g., Weaviate, Qdrant) instead of the mock store.\n",
|
||||
"3. **Asynchronous Operations**: For high-throughput systems, consider wrapping storage operations in async tasks (though the core logic is synchronous for simplicity).\n",
|
||||
"4. **Entity Resolution**: Implement a robust `EntityLinker` strategy to prevent graph fragmentation (e.g., \"Alice\" vs \"Alice S.\")."
|
||||
"print(f\"Created graph with {len(graph_data['nodes'])} nodes and {len(graph_data['edges'])} edges.\")\n",
|
||||
"print(\"Edges sample:\", graph_data['edges'][0])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "188b2093",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 4. Tuning Hybrid Retrieval\n",
|
||||
"\n",
|
||||
"Hybrid retrieval combines scores from vector search and graph traversal. You can tune the `hybrid_alpha` parameter to weight these components.\n",
|
||||
"\n",
|
||||
"- `hybrid_alpha = 0.0`: Pure Vector Search\n",
|
||||
"- `hybrid_alpha = 1.0`: Pure Graph Search\n",
|
||||
"- `hybrid_alpha = 0.5`: Balanced (Default)\n",
|
||||
"\n",
|
||||
"Let's configure a `ContextRetriever` with a preference for graph connections."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "9752dec4",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: ContextRetriever | Message: Retrieving context for: Python...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: ContextRetriever | Message: Retrieving from vector store...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: ContextRetriever | Message: Retrieving from knowledge graph...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: ContextRetriever | Message: Retrieving from memory...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Retrieving memories for: Python...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Searching vector store...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Generating text embedding: Python...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: embeddings | Submodule: TextEmbedder | Message: Using fallback embedding method...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: embeddings | Submodule: TextEmbedder | Message: Generated embedding (dim: 16)\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Searching for 20 similar vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: vector_store | Submodule: VectorStore | Message: Performing similarity search...\n",
|
||||
"C:\\Users\\Mohd Kaif\\semantica\\semantica\\vector_store\\vector_store.py:480: RuntimeWarning: invalid value encountered in divide\n",
|
||||
" similarities = np.dot(vectors, query_vector) / (vector_norms * query_norm)\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: vector_store | Submodule: VectorStore | Message: Found 20 similar vectors\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Performing keyword search...\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: AgentMemory | Message: Ranking results...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: AgentMemory | Message: Retrieved 0 memories\n",
|
||||
"INFO:semantica.progress:[RUNNING] | Module: context | Submodule: ContextRetriever | Message: Ranking and merging results...\n",
|
||||
"INFO:semantica.progress:[COMPLETED] | Module: context | Submodule: ContextRetriever | Message: Retrieved 1 results\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Found 1 results.\n",
|
||||
"Source: graph:python, Score: 1.00, Content: Python...\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Populate knowledge graph with some test data\n",
|
||||
"kg.add_node(\"python\", \"concept\", \"Python\")\n",
|
||||
"kg.add_node(\"ml\", \"concept\", \"Machine Learning\")\n",
|
||||
"kg.add_edge(\"python\", \"ml\", \"used_for\")\n",
|
||||
"\n",
|
||||
"# Initialize retriever with custom tuning\n",
|
||||
"retriever = ContextRetriever(\n",
|
||||
" memory_store=memory,\n",
|
||||
" knowledge_graph=kg,\n",
|
||||
" vector_store=vs,\n",
|
||||
" hybrid_alpha=0.7, # Favor graph connections\n",
|
||||
" max_expansion_hops=2 # Traverse deeper in the graph\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Retrieve\n",
|
||||
"results = retriever.retrieve(\"Python\")\n",
|
||||
"\n",
|
||||
"print(f\"Found {len(results)} results.\")\n",
|
||||
"for res in results:\n",
|
||||
" print(f\"Source: {res.source}, Score: {res.score:.2f}, Content: {res.content[:50]}...\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4dc770d0",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Conclusion\n",
|
||||
"\n",
|
||||
"You have successfully extended Semantica's context capabilities by:\n",
|
||||
"1. Implementing a custom memory pruning logic.\n",
|
||||
"2. Registering a new graph construction algorithm.\n",
|
||||
"3. Tuning the hybrid retrieval parameters.\n",
|
||||
"\n",
|
||||
"These patterns allow you to adapt the context engine to specialized domain requirements."
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -239,7 +607,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -1,286 +1,254 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/12_Unstructured_to_Ontology.ipynb)\n",
|
||||
"\n",
|
||||
"# Advanced: Unstructured Text to Ontology\n",
|
||||
"\n",
|
||||
"Welcome to the advanced guide on extracting structured ontologies from unstructured text. This notebook explores two powerful paradigms available in Semantica:\n",
|
||||
"\n",
|
||||
"1. **Classical NLP Pipeline**: Using Named Entity Recognition (NER) and Relation Extraction.\n",
|
||||
"2. **Generative AI Pipeline**: Using Large Language Models (LLMs) for direct conceptual modeling.\n",
|
||||
"\n",
|
||||
"We will compare both approaches, visualize the results, and validate the generated ontologies.\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/ontology/)\n",
|
||||
"\n",
|
||||
"## Setup and Installation\n",
|
||||
"\n",
|
||||
"Ensure you have Semantica installed with all dependencies."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# !pip install semantica[all]\n",
|
||||
"\n",
|
||||
"from semantica.utils.logging import get_logger\n",
|
||||
"\n",
|
||||
"logger = get_logger(\"unstructured_guide\")\n",
|
||||
"print(\"Environment setup complete.\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## The Input Text\n",
|
||||
"\n",
|
||||
"We will use a rich paragraph of text describing a technology company to test both extraction methods."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"text_corpus = \"\"\"\n",
|
||||
"QuantumDynamics is a leading AI research lab founded by Dr. Elena Rostova in 2018. \n",
|
||||
"The lab is headquartered in Zurich, Switzerland, and focuses on quantum computing algorithms. \n",
|
||||
"Dr. Rostova serves as the Chief Scientist. \n",
|
||||
"The lab has released products like the Q-1 Processor and the NeuralBridge SDK. \n",
|
||||
"QuantumDynamics collaborates with major universities such as MIT and ETH Zurich.\n",
|
||||
"\"\"\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Approach 1: The Classical NLP Pipeline\n",
|
||||
"\n",
|
||||
"This approach builds the ontology from the bottom up:\n",
|
||||
"1. **Extract Entities**: Identify nouns/proper nouns (e.g., \"QuantumDynamics\", \"Zurich\").\n",
|
||||
"2. **Extract Relations**: Identify verbs connecting them (e.g., \"headquartered in\").\n",
|
||||
"3. **Generate Ontology**: Map these triplets to Classes and Properties.\n",
|
||||
"\n",
|
||||
"**Pros**: Deterministic, traceable, works offline.\n",
|
||||
"**Cons**: Dependent on the underlying NLP model's vocabulary and flexibility."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor\n",
|
||||
"from semantica.ontology import OntologyGenerator, OntologyOptimizer\n",
|
||||
"\n",
|
||||
"# 1. Initialize Extractors\n",
|
||||
"ner = NERExtractor()\n",
|
||||
"re = RelationExtractor()\n",
|
||||
"\n",
|
||||
"# 2. Extract Entities\n",
|
||||
"print(\"Extracting entities...\")\n",
|
||||
"entities = ner.extract(text_corpus)\n",
|
||||
"print(f\"Found {len(entities)} entities: {[e['text'] for e in entities]}\")\n",
|
||||
"\n",
|
||||
"# 3. Extract Relationships\n",
|
||||
"print(\"Extracting relationships...\")\n",
|
||||
"relationships = re.extract(text_corpus, entities)\n",
|
||||
"for r in relationships:\n",
|
||||
" print(f\" - {r['source']} -> {r['type']} -> {r['target']}\")\n",
|
||||
"\n",
|
||||
"# 4. Generate Structure\n",
|
||||
"generator = OntologyGenerator()\n",
|
||||
"nlp_ontology = generator.generate(entities, relationships, name=\"QuantumOntologyNLP\")\n",
|
||||
"\n",
|
||||
"# 5. Optimize (Clean up)\n",
|
||||
"optimizer = OntologyOptimizer()\n",
|
||||
"nlp_ontology = optimizer.optimize_ontology(nlp_ontology, remove_redundancy=True)\n",
|
||||
"\n",
|
||||
"print(f\"\\nGenerated NLP Ontology with {len(nlp_ontology['classes'])} classes and {len(nlp_ontology['properties'])} properties.\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Approach 2: The Generative AI Pipeline (LLM)\n",
|
||||
"\n",
|
||||
"This approach uses a Large Language Model to \"read\" the text and directly propose a schema.\n",
|
||||
"\n",
|
||||
"**Pros**: Context-aware, can handle ambiguity, generates human-like class names.\n",
|
||||
"**Cons**: Non-deterministic, requires API access.\n",
|
||||
"\n",
|
||||
"*Note: This step requires a configured LLM provider (e.g., OpenAI).* "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.ontology import LLMOntologyGenerator\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" # Initialize LLM Generator (ensure OPENAI_API_KEY is set in env)\n",
|
||||
" llm_gen = LLMOntologyGenerator(provider=\"openai\", model=\"gpt-4\")\n",
|
||||
" \n",
|
||||
" print(\"Generating ontology with LLM...\")\n",
|
||||
" llm_ontology = llm_gen.generate_ontology_from_text(\n",
|
||||
" text=text_corpus,\n",
|
||||
" name=\"QuantumOntologyLLM\"\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" print(f\"Generated LLM Ontology with {len(llm_ontology['classes'])} classes and {len(llm_ontology['properties'])} properties.\")\n",
|
||||
" print(\"Classes detected:\", [c['name'] for c in llm_ontology['classes']])\n",
|
||||
" \n",
|
||||
"except Exception as e:\n",
|
||||
" print(f\"Skipping LLM generation: {e}\")\n",
|
||||
" llm_ontology = None"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Comparing Results with Visualization\n",
|
||||
"\n",
|
||||
"Let's visualize both ontologies side-by-side (if available) to see the difference in structure. The NLP model tends to be more literal, while the LLM model tends to be more conceptual."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.visualization import OntologyVisualizer\n",
|
||||
"\n",
|
||||
"visualizer = OntologyVisualizer()\n",
|
||||
"\n",
|
||||
"print(\"--- NLP Approach Visualization ---\")\n",
|
||||
"fig_nlp = visualizer.visualize_structure(nlp_ontology, output=\"interactive\")\n",
|
||||
"if fig_nlp: fig_nlp.show()\n",
|
||||
"\n",
|
||||
"if llm_ontology:\n",
|
||||
" print(\"--- LLM Approach Visualization ---\")\n",
|
||||
" fig_llm = visualizer.visualize_structure(llm_ontology, output=\"interactive\")\n",
|
||||
" if fig_llm: fig_llm.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Validation\n",
|
||||
"\n",
|
||||
"No matter the method, validation is crucial. We check for structural integrity and logical consistency."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.ontology import OntologyValidator\n",
|
||||
"\n",
|
||||
"validator = OntologyValidator()\n",
|
||||
"\n",
|
||||
"def print_report(name, ont):\n",
|
||||
" if not ont: return\n",
|
||||
" res = validator.validate_ontology(ont)\n",
|
||||
" print(f\"[{name}] Valid: {res.valid}, Errors: {len(res.errors)}\")\n",
|
||||
" if res.metrics:\n",
|
||||
" print(f\" Depth: {res.metrics.get('hierarchy_depth')}, Concepts: {res.metrics.get('class_count')}\")\n",
|
||||
"\n",
|
||||
"print_report(\"Classical NLP\", nlp_ontology)\n",
|
||||
"print_report(\"Generative AI\", llm_ontology)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Export to OWL\n",
|
||||
"\n",
|
||||
"Finally, we choose the best model (or merge them using `ReuseManager`, covered in other guides) and export it."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.export import OWLExporter\n",
|
||||
"\n",
|
||||
"exporter = OWLExporter()\n",
|
||||
"\n",
|
||||
"# Export the NLP ontology by default, or the LLM one if preferred\n",
|
||||
"target_ontology = llm_ontology if llm_ontology else nlp_ontology\n",
|
||||
"\n",
|
||||
"output_file = \"quantum_ontology.ttl\"\n",
|
||||
"exporter.export(target_ontology, output_file, format=\"turtle\")\n",
|
||||
"print(f\"Successfully exported ontology to {output_file}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"You have learned to:\n",
|
||||
"1. **Extract Ontologies Programmatically**: Using `NERExtractor` for reliable, data-driven modeling.\n",
|
||||
"2. **Generate Ontologies with AI**: Using `LLMOntologyGenerator` for conceptual, high-level modeling.\n",
|
||||
"3. **Visualize and Compare**: Using `OntologyVisualizer` to inspect the structural differences.\n",
|
||||
"4. **Validate and Export**: Ensuring quality before saving to OWL standards."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/12_Unstructured_to_Ontology.ipynb)\n",
|
||||
"\n",
|
||||
"# Advanced: Unstructured Text to Ontology\n",
|
||||
"\n",
|
||||
"Welcome to the advanced guide on extracting structured ontologies from unstructured text. This notebook explores two powerful paradigms available in Semantica:\n",
|
||||
"\n",
|
||||
"1. **Classical NLP Pipeline**: Using Named Entity Recognition (NER) and Relation Extraction.\n",
|
||||
"2. **Generative AI Pipeline**: Using Large Language Models (LLMs) for direct conceptual modeling.\n",
|
||||
"\n",
|
||||
"We will compare both approaches, visualize the results, and validate the generated ontologies.\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/ontology/)\n",
|
||||
"\n",
|
||||
"## Setup and Installation\n",
|
||||
"\n",
|
||||
"Ensure you have Semantica installed with all dependencies."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# !pip install semantica[all]\n",
|
||||
"\n",
|
||||
"from semantica.utils.logging import get_logger\n",
|
||||
"\n",
|
||||
"logger = get_logger(\"unstructured_guide\")\n",
|
||||
"print(\"Environment setup complete.\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## The Input Text\n",
|
||||
"\n",
|
||||
"We will use a rich paragraph of text describing a technology company to test both extraction methods."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"text_corpus = \"\"\"\n",
|
||||
"QuantumDynamics is a leading AI research lab founded by Dr. Elena Rostova in 2018. \n",
|
||||
"The lab is headquartered in Zurich, Switzerland, and focuses on quantum computing algorithms. \n",
|
||||
"Dr. Rostova serves as the Chief Scientist. \n",
|
||||
"The lab has released products like the Q-1 Processor and the NeuralBridge SDK. \n",
|
||||
"QuantumDynamics collaborates with major universities such as MIT and ETH Zurich.\n",
|
||||
"\"\"\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Approach 1: The Classical NLP Pipeline\n",
|
||||
"\n",
|
||||
"This approach builds the ontology from the bottom up:\n",
|
||||
"1. **Extract Entities**: Identify nouns/proper nouns (e.g., \"QuantumDynamics\", \"Zurich\").\n",
|
||||
"2. **Extract Relations**: Identify verbs connecting them (e.g., \"headquartered in\").\n",
|
||||
"3. **Generate Ontology**: Map these triplets to Classes and Properties.\n",
|
||||
"\n",
|
||||
"**Pros**: Deterministic, traceable, works offline.\n",
|
||||
"**Cons**: Dependent on the underlying NLP model's vocabulary and flexibility."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor\n",
|
||||
"from semantica.ontology import OntologyGenerator, OntologyOptimizer\n",
|
||||
"\n",
|
||||
"# 1. Initialize Extractors\n",
|
||||
"ner = NERExtractor()\n",
|
||||
"re = RelationExtractor()\n",
|
||||
"\n",
|
||||
"# 2. Extract Entities\n",
|
||||
"print(\"Extracting entities...\")\n",
|
||||
"entities = ner.extract(text_corpus)\n",
|
||||
"print(f\"Found {len(entities)} entities: {[e['text'] for e in entities]}\")\n",
|
||||
"\n",
|
||||
"# 3. Extract Relationships\n",
|
||||
"print(\"Extracting relationships...\")\n",
|
||||
"relationships = re.extract(text_corpus, entities)\n",
|
||||
"for r in relationships:\n",
|
||||
" print(f\" - {r['source']} -> {r['type']} -> {r['target']}\")\n",
|
||||
"\n",
|
||||
"# 4. Generate Structure\n",
|
||||
"generator = OntologyGenerator()\n",
|
||||
"nlp_ontology = generator.generate_ontology({\"entities\": entities, \"relationships\": relationships}, name=\"QuantumOntologyNLP\")\n",
|
||||
"\n",
|
||||
"# 5. Optimize (Clean up)\n",
|
||||
"optimizer = OntologyOptimizer()\n",
|
||||
"nlp_ontology = optimizer.optimize_ontology(nlp_ontology, remove_redundancy=True)\n",
|
||||
"\n",
|
||||
"print(f\"\\nGenerated NLP Ontology with {len(nlp_ontology['classes'])} classes and {len(nlp_ontology['properties'])} properties.\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Approach 2: The Generative AI Pipeline (LLM)\n",
|
||||
"\n",
|
||||
"This approach uses a Large Language Model to \"read\" the text and directly propose a schema.\n",
|
||||
"\n",
|
||||
"**Pros**: Context-aware, can handle ambiguity, generates human-like class names.\n",
|
||||
"**Cons**: Non-deterministic, requires API access.\n",
|
||||
"\n",
|
||||
"*Note: This step requires a configured LLM provider (e.g., OpenAI).* "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.ontology import LLMOntologyGenerator\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" # Initialize LLM Generator (ensure OPENAI_API_KEY is set in env)\n",
|
||||
" llm_gen = LLMOntologyGenerator(provider=\"openai\", model=\"gpt-4\")\n",
|
||||
" \n",
|
||||
" print(\"Generating ontology with LLM...\")\n",
|
||||
" llm_ontology = llm_gen.generate_ontology_from_text(\n",
|
||||
" text=text_corpus,\n",
|
||||
" name=\"QuantumOntologyLLM\"\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" print(f\"Generated LLM Ontology with {len(llm_ontology['classes'])} classes and {len(llm_ontology['properties'])} properties.\")\n",
|
||||
" print(\"Classes detected:\", [c['name'] for c in llm_ontology['classes']])\n",
|
||||
" \n",
|
||||
"except Exception as e:\n",
|
||||
" print(f\"Skipping LLM generation: {e}\")\n",
|
||||
" llm_ontology = None"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Comparing Results with Visualization\n",
|
||||
"\n",
|
||||
"Let's visualize both ontologies side-by-side (if available) to see the difference in structure. The NLP model tends to be more literal, while the LLM model tends to be more conceptual."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.visualization import OntologyVisualizer\n",
|
||||
"\n",
|
||||
"visualizer = OntologyVisualizer()\n",
|
||||
"\n",
|
||||
"print(\"--- NLP Approach Visualization ---\")\n",
|
||||
"fig_nlp = visualizer.visualize_structure(nlp_ontology, output=\"interactive\")\n",
|
||||
"if fig_nlp: fig_nlp.show()\n",
|
||||
"\n",
|
||||
"if llm_ontology:\n",
|
||||
" print(\"--- LLM Approach Visualization ---\")\n",
|
||||
" fig_llm = visualizer.visualize_structure(llm_ontology, output=\"interactive\")\n",
|
||||
" if fig_llm: fig_llm.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Export to OWL\n",
|
||||
"\n",
|
||||
"Finally, we choose the best model (or merge them using `ReuseManager`, covered in other guides) and export it."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.export import OWLExporter\n",
|
||||
"\n",
|
||||
"exporter = OWLExporter()\n",
|
||||
"\n",
|
||||
"# Export the NLP ontology by default, or the LLM one if preferred\n",
|
||||
"target_ontology = llm_ontology if llm_ontology else nlp_ontology\n",
|
||||
"\n",
|
||||
"output_file = \"quantum_ontology.ttl\"\n",
|
||||
"exporter.export(target_ontology, output_file, format=\"turtle\")\n",
|
||||
"print(f\"Successfully exported ontology to {output_file}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"You have learned to:\n",
|
||||
"1. **Extract Ontologies Programmatically**: Using `NERExtractor` for reliable, data-driven modeling.\n",
|
||||
"2. **Generate Ontologies with AI**: Using `LLMOntologyGenerator` for conceptual, high-level modeling.\n",
|
||||
"3. **Visualize and Compare**: Using `OntologyVisualizer` to inspect the structural differences.\n",
|
||||
"4. **Validate and Export**: Ensuring quality before saving to OWL standards."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Advanced Triplet Store Guide\n",
|
||||
"\n",
|
||||
"This guide explores the advanced capabilities of the Semantica Triplet Store module, focusing on RDF data management, SPARQL querying, and multi-backend support (Blazegraph, Jena, RDF4J).\n",
|
||||
"\n",
|
||||
"## Key Features\n",
|
||||
"- Unified interface for Blazegraph, Jena, and RDF4J\n",
|
||||
"- Bulk loading with progress tracking\n",
|
||||
"- SPARQL query execution and optimization\n",
|
||||
"- Transaction support (backend-dependent)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.triplet_store import TripletStore\n",
|
||||
"from semantica.semantic_extract.triplet_extractor import Triplet"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 1. Initialization\n",
|
||||
"\n",
|
||||
"Initialize the Triplet Store with your preferred backend."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize Blazegraph store\n",
|
||||
"store = TripletStore(\n",
|
||||
" backend=\"blazegraph\",\n",
|
||||
" endpoint=\"http://localhost:9999/blazegraph\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Or Jena\n",
|
||||
"# store = TripletStore(backend=\"jena\", endpoint=\"http://localhost:3030/ds\")\n",
|
||||
"\n",
|
||||
"# Or RDF4J\n",
|
||||
"# store = TripletStore(backend=\"rdf4j\", endpoint=\"http://localhost:8080/rdf4j-server/repositories/myrepo\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 2. Adding Triplets\n",
|
||||
"\n",
|
||||
"Add individual triplets or batch load them."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Single triplet\n",
|
||||
"triplet = Triplet(\n",
|
||||
" subject=\"http://example.org/Alice\",\n",
|
||||
" predicate=\"http://xmlns.com/foaf/0.1/knows\",\n",
|
||||
" object=\"http://example.org/Bob\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"store.add_triplet(triplet)\n",
|
||||
"\n",
|
||||
"# Bulk load\n",
|
||||
"triplets = [\n",
|
||||
" Triplet(\n",
|
||||
" subject=\"http://example.org/Bob\",\n",
|
||||
" predicate=\"http://xmlns.com/foaf/0.1/knows\",\n",
|
||||
" object=\"http://example.org/Charlie\"\n",
|
||||
" ),\n",
|
||||
" Triplet(\n",
|
||||
" subject=\"http://example.org/Charlie\",\n",
|
||||
" predicate=\"http://xmlns.com/foaf/0.1/knows\",\n",
|
||||
" object=\"http://example.org/Alice\"\n",
|
||||
" )\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"result = store.add_triplets(triplets, batch_size=100)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 3. SPARQL Querying\n",
|
||||
"\n",
|
||||
"Execute SPARQL queries to retrieve data."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"query = \"\"\"\n",
|
||||
"SELECT ?s ?p ?o\n",
|
||||
"WHERE {\n",
|
||||
" ?s ?p ?o\n",
|
||||
"}\n",
|
||||
"LIMIT 10\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"results = store.execute_query(query)\n",
|
||||
"for result in results.get(\"results\", {}).get(\"bindings\", []):\n",
|
||||
" print(result)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 4. Deleting and Updating\n",
|
||||
"\n",
|
||||
"Manage triplet lifecycle."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"store.delete_triplet(triplet)\n",
|
||||
"\n",
|
||||
"# Update is delete + add\n",
|
||||
"new_triplet = Triplet(\n",
|
||||
" subject=\"http://example.org/Alice\",\n",
|
||||
" predicate=\"http://xmlns.com/foaf/0.1/knows\",\n",
|
||||
" object=\"http://example.org/David\"\n",
|
||||
")\n",
|
||||
"store.update_triplet(triplet, new_triplet)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
@@ -1,371 +1,380 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/Advanced_Vector_Store_and_Search.ipynb)\n",
|
||||
"\n",
|
||||
"# Advanced Vector Store - Made Easy\n",
|
||||
"\n",
|
||||
"## What You'll Learn\n",
|
||||
"\n",
|
||||
"This notebook shows you **practical ways** to use vector stores in real applications. Each example is simple and ready to use.\n",
|
||||
"\n",
|
||||
"### Topics\n",
|
||||
"\n",
|
||||
"1. **Choosing the Right Index** - Which one to use and when\n",
|
||||
"2. **Smart Filtering** - Find exactly what you need\n",
|
||||
"3. **Combining Results** - Merge searches from different sources\n",
|
||||
"4. **Organizing Data** - Keep different users' data separate\n",
|
||||
"\n",
|
||||
"---"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 0: Setup Embeddings\n",
|
||||
"\n",
|
||||
"First, let's select our embedding provider and model. Semantica supports multiple providers like Sentence Transformers and FastEmbed.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.embeddings import TextEmbedder\n",
|
||||
"\n",
|
||||
"# Choose provider and model\n",
|
||||
"embedder = TextEmbedder(method=\"fastembed\", model_name=\"BAAI/bge-small-en-v1.5\")\n",
|
||||
"dimension = embedder.get_embedding_dimension()\n",
|
||||
"\n",
|
||||
"print(f\"Selected model: {embedder.get_model_info()['model_name']}\")\n",
|
||||
"print(f\"Embedding dimension: {dimension}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 1: Choosing the Right Index\n",
|
||||
"\n",
|
||||
"Think of an index like choosing a filing system:\n",
|
||||
"- **Flat**: Like a small notebook - slow but perfect\n",
|
||||
"- **HNSW**: Like a well-organized library - fast and accurate\n",
|
||||
"- **IVF**: Like a warehouse with sections - very fast for huge collections\n",
|
||||
"\n",
|
||||
"### Simple Rule\n",
|
||||
"- Less than 10,000 items? Use **Flat**\n",
|
||||
"- Between 10,000 and 1 million? Use **HNSW** ✅ (recommended)\n",
|
||||
"- More than 1 million? Use **IVF**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import FAISSAdapter\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"# Create some example vectors (like document embeddings)\n",
|
||||
"vectors = np.random.rand(5000, 768).astype('float32')\n",
|
||||
"query = np.random.rand(768).astype('float32')\n",
|
||||
"\n",
|
||||
"adapter = FAISSAdapter(dimension=768)\n",
|
||||
"\n",
|
||||
"# HNSW Index - Best for most cases\n",
|
||||
"index = adapter.create_index(index_type=\"hnsw\", metric=\"L2\", m=16)\n",
|
||||
"adapter.add_vectors(index, vectors, ids=[f\"doc_{i}\" for i in range(len(vectors))])\n",
|
||||
"\n",
|
||||
"# Search for similar vectors\n",
|
||||
"distances, indices = adapter.search(index, query, k=5)\n",
|
||||
"\n",
|
||||
"print(\"Found 5 most similar documents:\")\n",
|
||||
"for i, (dist, idx) in enumerate(zip(distances, indices), 1):\n",
|
||||
" print(f\" {i}. Document {idx} (distance: {dist:.3f})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 2: Smart Filtering with Metadata\n",
|
||||
"\n",
|
||||
"Imagine searching for \"similar articles\" but only from 2024 and only in the \"Technology\" category. That's what metadata filtering does!\n",
|
||||
"\n",
|
||||
"### Real-World Example\n",
|
||||
"You're building a document search where users want:\n",
|
||||
"- Similar documents (vector search)\n",
|
||||
"- From specific categories (metadata filter)\n",
|
||||
"- From recent years (metadata filter)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import HybridSearch, MetadataFilter\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"# Create sample documents with metadata\n",
|
||||
"documents = [\n",
|
||||
" {\"id\": 0, \"text\": \"AI in Healthcare\", \"category\": \"Technology\", \"year\": 2024},\n",
|
||||
" {\"id\": 1, \"text\": \"Machine Learning Basics\", \"category\": \"Technology\", \"year\": 2023},\n",
|
||||
" {\"id\": 2, \"text\": \"Business Strategy\", \"category\": \"Business\", \"year\": 2024},\n",
|
||||
" {\"id\": 3, \"text\": \"Data Science Guide\", \"category\": \"Technology\", \"year\": 2024},\n",
|
||||
" {\"id\": 4, \"text\": \"Marketing Tips\", \"category\": \"Business\", \"year\": 2023},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Create vectors for each document\n",
|
||||
"vectors = [np.random.rand(768) for _ in documents]\n",
|
||||
"metadata = [{\"category\": d[\"category\"], \"year\": d[\"year\"]} for d in documents]\n",
|
||||
"vector_ids = [f\"doc_{d['id']}\" for d in documents]\n",
|
||||
"\n",
|
||||
"# Create search\n",
|
||||
"search = HybridSearch()\n",
|
||||
"query = np.random.rand(768)\n",
|
||||
"\n",
|
||||
"# Example 1: Find Technology articles from 2024\n",
|
||||
"filter1 = MetadataFilter().eq(\"category\", \"Technology\").eq(\"year\", 2024)\n",
|
||||
"results = search.search(query, vectors, metadata, vector_ids, filter=filter1, k=10)\n",
|
||||
"\n",
|
||||
"print(\"Technology articles from 2024:\")\n",
|
||||
"for r in results:\n",
|
||||
" doc_id = int(r['id'].split('_')[1])\n",
|
||||
" print(f\" - {documents[doc_id]['text']}\")\n",
|
||||
"\n",
|
||||
"# Example 2: Find any article from 2024\n",
|
||||
"filter2 = MetadataFilter().eq(\"year\", 2024)\n",
|
||||
"results2 = search.search(query, vectors, metadata, vector_ids, filter=filter2, k=10)\n",
|
||||
"\n",
|
||||
"print(\"\\nAll articles from 2024:\")\n",
|
||||
"for r in results2:\n",
|
||||
" doc_id = int(r['id'].split('_')[1])\n",
|
||||
" print(f\" - {documents[doc_id]['text']} ({documents[doc_id]['category']})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 3: Combining Search Results\n",
|
||||
"\n",
|
||||
"Sometimes you want to search in multiple places and combine the results. Like searching both your email and documents, then showing the best matches from both.\n",
|
||||
"\n",
|
||||
"### When to Use This\n",
|
||||
"- Searching multiple databases\n",
|
||||
"- Combining different search strategies\n",
|
||||
"- Giving more weight to certain sources"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import SearchRanker\n",
|
||||
"\n",
|
||||
"# Simulate two different searches\n",
|
||||
"# Search 1: Recent documents\n",
|
||||
"recent_results = [\n",
|
||||
" {\"id\": \"doc_3\", \"score\": 0.95, \"source\": \"recent\"},\n",
|
||||
" {\"id\": \"doc_0\", \"score\": 0.90, \"source\": \"recent\"},\n",
|
||||
" {\"id\": \"doc_2\", \"score\": 0.85, \"source\": \"recent\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Search 2: Popular documents\n",
|
||||
"popular_results = [\n",
|
||||
" {\"id\": \"doc_1\", \"score\": 0.92, \"source\": \"popular\"},\n",
|
||||
" {\"id\": \"doc_3\", \"score\": 0.88, \"source\": \"popular\"},\n",
|
||||
" {\"id\": \"doc_4\", \"score\": 0.80, \"source\": \"popular\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Method 1: Fair combination (RRF)\n",
|
||||
"ranker = SearchRanker(strategy=\"reciprocal_rank_fusion\")\n",
|
||||
"combined = ranker.rank([recent_results, popular_results])\n",
|
||||
"\n",
|
||||
"print(\"Combined results (fair ranking):\")\n",
|
||||
"for i, result in enumerate(combined[:3], 1):\n",
|
||||
" doc_id = int(result['id'].split('_')[1])\n",
|
||||
" print(f\" {i}. {documents[doc_id]['text']} (score: {result['score']:.3f})\")\n",
|
||||
"\n",
|
||||
"# Method 2: Prefer recent documents (70% recent, 30% popular)\n",
|
||||
"weighted_ranker = SearchRanker(strategy=\"weighted_average\")\n",
|
||||
"weighted_combined = weighted_ranker.rank(\n",
|
||||
" [recent_results, popular_results],\n",
|
||||
" weights=[0.7, 0.3]\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(\"\\nCombined results (prefer recent):\")\n",
|
||||
"for i, result in enumerate(weighted_combined[:3], 1):\n",
|
||||
" doc_id = int(result['id'].split('_')[1])\n",
|
||||
" print(f\" {i}. {documents[doc_id]['text']} (score: {result['score']:.3f})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 4: Keeping User Data Separate\n",
|
||||
"\n",
|
||||
"If you're building an app with multiple users or companies, you need to keep their data separate. Namespaces do this automatically.\n",
|
||||
"\n",
|
||||
"### Real Example\n",
|
||||
"You're building a SaaS app where:\n",
|
||||
"- Company A has their documents\n",
|
||||
"- Company B has their documents\n",
|
||||
"- They should never see each other's data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import NamespaceManager\n",
|
||||
"\n",
|
||||
"# Create manager\n",
|
||||
"manager = NamespaceManager()\n",
|
||||
"\n",
|
||||
"# Create separate spaces for each company\n",
|
||||
"company_a = manager.create_namespace(\"company_a\", \"Company A's documents\")\n",
|
||||
"company_b = manager.create_namespace(\"company_b\", \"Company B's documents\")\n",
|
||||
"\n",
|
||||
"# Add documents to Company A\n",
|
||||
"for i in range(10):\n",
|
||||
" manager.add_vector_to_namespace(f\"company_a_doc_{i}\", \"company_a\")\n",
|
||||
"\n",
|
||||
"# Add documents to Company B\n",
|
||||
"for i in range(15):\n",
|
||||
" manager.add_vector_to_namespace(f\"company_b_doc_{i}\", \"company_b\")\n",
|
||||
"\n",
|
||||
"# Get each company's documents\n",
|
||||
"a_docs = manager.get_namespace_vectors(\"company_a\")\n",
|
||||
"b_docs = manager.get_namespace_vectors(\"company_b\")\n",
|
||||
"\n",
|
||||
"print(f\"Company A has {len(a_docs)} documents\")\n",
|
||||
"print(f\"Company B has {len(b_docs)} documents\")\n",
|
||||
"\n",
|
||||
"# Set permissions (who can access what)\n",
|
||||
"company_a.set_access_control(\"admin@companya.com\", [\"read\", \"write\", \"delete\"])\n",
|
||||
"company_a.set_access_control(\"user@companya.com\", [\"read\"]) # Read-only\n",
|
||||
"\n",
|
||||
"# Check permissions\n",
|
||||
"print(f\"\\nAdmin can delete: {company_a.has_permission('admin@companya.com', 'delete')}\")\n",
|
||||
"print(f\"User can delete: {company_a.has_permission('user@companya.com', 'delete')}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Quick Reference Guide\n",
|
||||
"\n",
|
||||
"### Which Index Should I Use?\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"# Small dataset (< 10,000 items)\n",
|
||||
"index = adapter.create_index(index_type=\"flat\", metric=\"L2\")\n",
|
||||
"\n",
|
||||
"# Medium dataset (10,000 - 1,000,000 items) ✅ RECOMMENDED\n",
|
||||
"index = adapter.create_index(index_type=\"hnsw\", metric=\"L2\", m=16)\n",
|
||||
"\n",
|
||||
"# Large dataset (> 1,000,000 items)\n",
|
||||
"index = adapter.create_index(index_type=\"ivf\", metric=\"L2\", nlist=100)\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### How Do I Filter Results?\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"# Single condition\n",
|
||||
"filter = MetadataFilter().eq(\"category\", \"Technology\")\n",
|
||||
"\n",
|
||||
"# Multiple conditions (AND)\n",
|
||||
"filter = MetadataFilter() \\\n",
|
||||
" .eq(\"category\", \"Technology\") \\\n",
|
||||
" .eq(\"year\", 2024)\n",
|
||||
"\n",
|
||||
"# Greater than / Less than\n",
|
||||
"filter = MetadataFilter().gt(\"year\", 2020)\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### How Do I Combine Results?\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"# Fair combination\n",
|
||||
"ranker = SearchRanker(strategy=\"reciprocal_rank_fusion\")\n",
|
||||
"combined = ranker.rank([results1, results2])\n",
|
||||
"\n",
|
||||
"# Weighted combination (prefer first source)\n",
|
||||
"ranker = SearchRanker(strategy=\"weighted_average\")\n",
|
||||
"combined = ranker.rank([results1, results2], weights=[0.7, 0.3])\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### How Do I Separate User Data?\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"# Create namespace for each user/company\n",
|
||||
"manager = NamespaceManager()\n",
|
||||
"user_space = manager.create_namespace(\"user_123\", \"User 123's data\")\n",
|
||||
"\n",
|
||||
"# Add data to namespace\n",
|
||||
"manager.add_vector_to_namespace(\"doc_1\", \"user_123\")\n",
|
||||
"\n",
|
||||
"# Get user's data\n",
|
||||
"user_docs = manager.get_namespace_vectors(\"user_123\")\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"You've learned:\n",
|
||||
"\n",
|
||||
"1. ✅ **Index Selection**: Use HNSW for most cases\n",
|
||||
"2. ✅ **Smart Filtering**: Combine vector search with metadata\n",
|
||||
"3. ✅ **Result Fusion**: Merge searches from different sources\n",
|
||||
"4. ✅ **Data Isolation**: Keep users' data separate\n",
|
||||
"\n",
|
||||
"### Next Steps\n",
|
||||
"\n",
|
||||
"- Try these examples with your own data\n",
|
||||
"- Experiment with different filters\n",
|
||||
"- Build a multi-user application\n",
|
||||
"- Explore the [introduction notebook](../introduction/13_Vector_Store.ipynb) for more basics\n",
|
||||
"\n",
|
||||
"**Need Help?** Check our [documentation](https://semantica.readthedocs.io) or ask on [GitHub](https://github.com/Hawksight-AI/semantica)."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/advanced/Advanced_Vector_Store_and_Search.ipynb)\n",
|
||||
"\n",
|
||||
"# Advanced Vector Store - Made Easy\n",
|
||||
"\n",
|
||||
"## What You'll Learn\n",
|
||||
"\n",
|
||||
"This notebook shows you **practical ways** to use vector stores in real applications. Each example is simple and ready to use.\n",
|
||||
"\n",
|
||||
"### Topics\n",
|
||||
"\n",
|
||||
"1. **Choosing the Right Index** - Which one to use and when\n",
|
||||
"2. **Smart Filtering** - Find exactly what you need\n",
|
||||
"3. **Combining Results** - Merge searches from different sources\n",
|
||||
"4. **Organizing Data** - Keep different users' data separate\n",
|
||||
"\n",
|
||||
"---"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 0: Setup Embeddings\n",
|
||||
"\n",
|
||||
"First, let's select our embedding provider and model. Semantica supports multiple providers like Sentence Transformers and FastEmbed.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.embeddings import TextEmbedder\n",
|
||||
"\n",
|
||||
"# Choose provider and model\n",
|
||||
"embedder = TextEmbedder(method=\"fastembed\", model_name=\"BAAI/bge-small-en-v1.5\")\n",
|
||||
"dimension = embedder.get_embedding_dimension()\n",
|
||||
"\n",
|
||||
"print(f\"Selected model: {embedder.get_model_info()['model_name']}\")\n",
|
||||
"print(f\"Embedding dimension: {dimension}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 1: Choosing the Right Index\n",
|
||||
"\n",
|
||||
"Think of an index like choosing a filing system:\n",
|
||||
"- **Flat**: Like a small notebook - slow but perfect\n",
|
||||
"- **HNSW**: Like a well-organized library - fast and accurate\n",
|
||||
"- **IVF**: Like a warehouse with sections - very fast for huge collections\n",
|
||||
"\n",
|
||||
"### Simple Rule\n",
|
||||
"- Less than 10,000 items? Use **Flat**\n",
|
||||
"- Between 10,000 and 1 million? Use **HNSW** \u2705 (recommended)\n",
|
||||
"- More than 1 million? Use **IVF**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import FAISSStore\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"# Create some example vectors (like document embeddings)\n",
|
||||
"vectors = np.random.rand(5000, 768).astype('float32')\n",
|
||||
"query = np.random.rand(768).astype('float32')\n",
|
||||
"\n",
|
||||
"adapter = FAISSStore(dimension=768)\n",
|
||||
"\n",
|
||||
"# HNSW Index - Best for most cases\n",
|
||||
"index = adapter.create_index(index_type=\"hnsw\", metric=\"L2\", m=16)\n",
|
||||
"adapter.add_vectors(index, vectors, ids=[f\"doc_{i}\" for i in range(len(vectors))])\n",
|
||||
"\n",
|
||||
"# Search for similar vectors\n",
|
||||
"distances, indices = adapter.search(index, query, k=5)\n",
|
||||
"\n",
|
||||
"print(\"Found 5 most similar documents:\")\n",
|
||||
"for i, (dist, idx) in enumerate(zip(distances, indices), 1):\n",
|
||||
" print(f\" {i}. Document {idx} (distance: {dist:.3f})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 2: Smart Filtering with Metadata\n",
|
||||
"\n",
|
||||
"Imagine searching for \"similar articles\" but only from 2024 and only in the \"Technology\" category. That's what metadata filtering does!\n",
|
||||
"\n",
|
||||
"### Real-World Example\n",
|
||||
"You're building a document search where users want:\n",
|
||||
"- Similar documents (vector search)\n",
|
||||
"- From specific categories (metadata filter)\n",
|
||||
"- From recent years (metadata filter)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import HybridSearch, MetadataFilter\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"# Create sample documents with metadata\n",
|
||||
"documents = [\n",
|
||||
" {\"id\": 0, \"text\": \"AI in Healthcare\", \"category\": \"Technology\", \"year\": 2024},\n",
|
||||
" {\"id\": 1, \"text\": \"Machine Learning Basics\", \"category\": \"Technology\", \"year\": 2023},\n",
|
||||
" {\"id\": 2, \"text\": \"Business Strategy\", \"category\": \"Business\", \"year\": 2024},\n",
|
||||
" {\"id\": 3, \"text\": \"Data Science Guide\", \"category\": \"Technology\", \"year\": 2024},\n",
|
||||
" {\"id\": 4, \"text\": \"Marketing Tips\", \"category\": \"Business\", \"year\": 2023},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Create vectors for each document\n",
|
||||
"vectors = [np.random.rand(768) for _ in documents]\n",
|
||||
"metadata = [{\"category\": d[\"category\"], \"year\": d[\"year\"]} for d in documents]\n",
|
||||
"vector_ids = [f\"doc_{d['id']}\" for d in documents]\n",
|
||||
"\n",
|
||||
"# Create search\n",
|
||||
"search = HybridSearch()\n",
|
||||
"query = np.random.rand(768)\n",
|
||||
"\n",
|
||||
"# Example 1: Find Technology articles from 2024\n",
|
||||
"filter1 = MetadataFilter().eq(\"category\", \"Technology\").eq(\"year\", 2024)\n",
|
||||
"results = search.search(query, vectors, metadata, vector_ids, filter=filter1, k=10)\n",
|
||||
"\n",
|
||||
"print(\"Technology articles from 2024:\")\n",
|
||||
"for r in results:\n",
|
||||
" doc_id = int(r['id'].split('_')[1])\n",
|
||||
" print(f\" - {documents[doc_id]['text']}\")\n",
|
||||
"\n",
|
||||
"# Example 2: Find any article from 2024\n",
|
||||
"filter2 = MetadataFilter().eq(\"year\", 2024)\n",
|
||||
"results2 = search.search(query, vectors, metadata, vector_ids, filter=filter2, k=10)\n",
|
||||
"\n",
|
||||
"print(\"\\nAll articles from 2024:\")\n",
|
||||
"for r in results2:\n",
|
||||
" doc_id = int(r['id'].split('_')[1])\n",
|
||||
" print(f\" - {documents[doc_id]['text']} ({documents[doc_id]['category']})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 3: Combining Search Results\n",
|
||||
"\n",
|
||||
"Sometimes you want to search in multiple places and combine the results. Like searching both your email and documents, then showing the best matches from both.\n",
|
||||
"\n",
|
||||
"### When to Use This\n",
|
||||
"- Searching multiple databases\n",
|
||||
"- Combining different search strategies\n",
|
||||
"- Giving more weight to certain sources"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import SearchRanker\n",
|
||||
"\n",
|
||||
"# Simulate two different searches\n",
|
||||
"# Search 1: Recent documents\n",
|
||||
"recent_results = [\n",
|
||||
" {\"id\": \"doc_3\", \"score\": 0.95, \"source\": \"recent\"},\n",
|
||||
" {\"id\": \"doc_0\", \"score\": 0.90, \"source\": \"recent\"},\n",
|
||||
" {\"id\": \"doc_2\", \"score\": 0.85, \"source\": \"recent\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Search 2: Popular documents\n",
|
||||
"popular_results = [\n",
|
||||
" {\"id\": \"doc_1\", \"score\": 0.92, \"source\": \"popular\"},\n",
|
||||
" {\"id\": \"doc_3\", \"score\": 0.88, \"source\": \"popular\"},\n",
|
||||
" {\"id\": \"doc_4\", \"score\": 0.80, \"source\": \"popular\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Method 1: Fair combination (RRF)\n",
|
||||
"ranker = SearchRanker(strategy=\"reciprocal_rank_fusion\")\n",
|
||||
"combined = ranker.rank([recent_results, popular_results])\n",
|
||||
"\n",
|
||||
"print(\"Combined results (fair ranking):\")\n",
|
||||
"for i, result in enumerate(combined[:3], 1):\n",
|
||||
" doc_id = int(result['id'].split('_')[1])\n",
|
||||
" print(f\" {i}. {documents[doc_id]['text']} (score: {result['score']:.3f})\")\n",
|
||||
"\n",
|
||||
"# Method 2: Prefer recent documents (70% recent, 30% popular)\n",
|
||||
"weighted_ranker = SearchRanker(strategy=\"weighted_average\")\n",
|
||||
"weighted_combined = weighted_ranker.rank(\n",
|
||||
" [recent_results, popular_results],\n",
|
||||
" weights=[0.7, 0.3]\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(\"\\nCombined results (prefer recent):\")\n",
|
||||
"for i, result in enumerate(weighted_combined[:3], 1):\n",
|
||||
" doc_id = int(result['id'].split('_')[1])\n",
|
||||
" print(f\" {i}. {documents[doc_id]['text']} (score: {result['score']:.3f})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 4: Keeping User Data Separate\n",
|
||||
"\n",
|
||||
"If you're building an app with multiple users or companies, you need to keep their data separate. Namespaces do this automatically.\n",
|
||||
"\n",
|
||||
"### Real Example\n",
|
||||
"You're building a SaaS app where:\n",
|
||||
"- Company A has their documents\n",
|
||||
"- Company B has their documents\n",
|
||||
"- They should never see each other's data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import NamespaceManager\n",
|
||||
"\n",
|
||||
"# Create manager\n",
|
||||
"manager = NamespaceManager()\n",
|
||||
"\n",
|
||||
"# Create separate spaces for each company\n",
|
||||
"company_a = manager.create_namespace(\"company_a\", \"Company A's documents\")\n",
|
||||
"company_b = manager.create_namespace(\"company_b\", \"Company B's documents\")\n",
|
||||
"\n",
|
||||
"# Add documents to Company A\n",
|
||||
"for i in range(10):\n",
|
||||
" manager.add_vector_to_namespace(f\"company_a_doc_{i}\", \"company_a\")\n",
|
||||
"\n",
|
||||
"# Add documents to Company B\n",
|
||||
"for i in range(15):\n",
|
||||
" manager.add_vector_to_namespace(f\"company_b_doc_{i}\", \"company_b\")\n",
|
||||
"\n",
|
||||
"# Get each company's documents\n",
|
||||
"a_docs = manager.get_namespace_vectors(\"company_a\")\n",
|
||||
"b_docs = manager.get_namespace_vectors(\"company_b\")\n",
|
||||
"\n",
|
||||
"print(f\"Company A has {len(a_docs)} documents\")\n",
|
||||
"print(f\"Company B has {len(b_docs)} documents\")\n",
|
||||
"\n",
|
||||
"# Set permissions (who can access what)\n",
|
||||
"company_a.set_access_control(\"admin@companya.com\", [\"read\", \"write\", \"delete\"])\n",
|
||||
"company_a.set_access_control(\"user@companya.com\", [\"read\"]) # Read-only\n",
|
||||
"\n",
|
||||
"# Check permissions\n",
|
||||
"print(f\"\\nAdmin can delete: {company_a.has_permission('admin@companya.com', 'delete')}\")\n",
|
||||
"print(f\"User can delete: {company_a.has_permission('user@companya.com', 'delete')}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Quick Reference Guide\n",
|
||||
"\n",
|
||||
"### Which Index Should I Use?\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"# Small dataset (< 10,000 items)\n",
|
||||
"index = adapter.create_index(index_type=\"flat\", metric=\"L2\")\n",
|
||||
"\n",
|
||||
"# Medium dataset (10,000 - 1,000,000 items) \u2705 RECOMMENDED\n",
|
||||
"index = adapter.create_index(index_type=\"hnsw\", metric=\"L2\", m=16)\n",
|
||||
"\n",
|
||||
"# Large dataset (> 1,000,000 items)\n",
|
||||
"index = adapter.create_index(index_type=\"ivf\", metric=\"L2\", nlist=100)\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### How Do I Filter Results?\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"# Single condition\n",
|
||||
"filter = MetadataFilter().eq(\"category\", \"Technology\")\n",
|
||||
"\n",
|
||||
"# Multiple conditions (AND)\n",
|
||||
"filter = MetadataFilter() \\\n",
|
||||
" .eq(\"category\", \"Technology\") \\\n",
|
||||
" .eq(\"year\", 2024)\n",
|
||||
"\n",
|
||||
"# Greater than / Less than\n",
|
||||
"filter = MetadataFilter().gt(\"year\", 2020)\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### How Do I Combine Results?\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"# Fair combination\n",
|
||||
"ranker = SearchRanker(strategy=\"reciprocal_rank_fusion\")\n",
|
||||
"combined = ranker.rank([results1, results2])\n",
|
||||
"\n",
|
||||
"# Weighted combination (prefer first source)\n",
|
||||
"ranker = SearchRanker(strategy=\"weighted_average\")\n",
|
||||
"combined = ranker.rank([results1, results2], weights=[0.7, 0.3])\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### How Do I Separate User Data?\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"# Create namespace for each user/company\n",
|
||||
"manager = NamespaceManager()\n",
|
||||
"user_space = manager.create_namespace(\"user_123\", \"User 123's data\")\n",
|
||||
"\n",
|
||||
"# Add data to namespace\n",
|
||||
"manager.add_vector_to_namespace(\"doc_1\", \"user_123\")\n",
|
||||
"\n",
|
||||
"# Get user's data\n",
|
||||
"user_docs = manager.get_namespace_vectors(\"user_123\")\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"You've learned:\n",
|
||||
"\n",
|
||||
"1. \u2705 **Index Selection**: Use HNSW for most cases\n",
|
||||
"2. \u2705 **Smart Filtering**: Combine vector search with metadata\n",
|
||||
"3. \u2705 **Result Fusion**: Merge searches from different sources\n",
|
||||
"4. \u2705 **Data Isolation**: Keep users' data separate\n",
|
||||
"\n",
|
||||
"### Next Steps\n",
|
||||
"\n",
|
||||
"- Try these examples with your own data\n",
|
||||
"- Experiment with different filters\n",
|
||||
"- Build a multi-user application\n",
|
||||
"- Explore the [introduction notebook](../introduction/13_Vector_Store.ipynb) for more basics\n",
|
||||
"\n",
|
||||
"**Need Help?** Check our [documentation](https://semantica.readthedocs.io) or ask on [GitHub](https://github.com/Hawksight-AI/semantica)."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,15 @@
|
||||
"Parse various document formats using the general DocumentParser.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -163,7 +172,7 @@
|
||||
"\n",
|
||||
"xml_data = xml_parser.parse(xml_file)\n",
|
||||
"\n",
|
||||
"print(f\"Parsed XML with {len(xml_data.elements)} elements\")\n",
|
||||
"print(f\"Parsed XML with {len(xml_data.root.children)} elements\")\n",
|
||||
"print(f\"Root element: {xml_data.root.tag if xml_data.root else 'None'}\")\n"
|
||||
]
|
||||
},
|
||||
@@ -257,4 +266,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,15 @@
|
||||
"Normalize text content for consistency.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -127,6 +136,10 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import importlib\n",
|
||||
"import semantica.normalize.number_normalizer\n",
|
||||
"importlib.reload(semantica.normalize.number_normalizer)\n",
|
||||
"\n",
|
||||
"from semantica.normalize import NumberNormalizer\n",
|
||||
"\n",
|
||||
"number_normalizer = NumberNormalizer()\n",
|
||||
@@ -191,8 +204,8 @@
|
||||
"\n",
|
||||
"text_samples = [\n",
|
||||
" \"Hello, this is English text.\",\n",
|
||||
" \"Bonjour, ceci est du texte français.\",\n",
|
||||
" \"Hola, este es texto en español.\"\n",
|
||||
" \"Bonjour, ceci est du texte fran\u00e7ais.\",\n",
|
||||
" \"Hola, este es texto en espa\u00f1ol.\"\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"for text in text_samples:\n",
|
||||
@@ -231,4 +244,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,229 @@
|
||||
"---"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Requirement already satisfied: semantica in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.0.5)\n",
|
||||
"Requirement already satisfied: numpy>=1.21.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.26.4)\n",
|
||||
"Requirement already satisfied: pandas>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.1.4)\n",
|
||||
"Requirement already satisfied: scikit-learn>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.6.1)\n",
|
||||
"Requirement already satisfied: spacy>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.8.11)\n",
|
||||
"Requirement already satisfied: transformers>=4.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.53.2)\n",
|
||||
"Requirement already satisfied: torch>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.2.1)\n",
|
||||
"Requirement already satisfied: sentence-transformers>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.2.1)\n",
|
||||
"Requirement already satisfied: rdflib>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.0)\n",
|
||||
"Requirement already satisfied: networkx>=2.8.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.5)\n",
|
||||
"Requirement already satisfied: matplotlib>=3.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.10.1)\n",
|
||||
"Requirement already satisfied: seaborn>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.13.2)\n",
|
||||
"Requirement already satisfied: plotly>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.17.0)\n",
|
||||
"Requirement already satisfied: requests>=2.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.32.5)\n",
|
||||
"Requirement already satisfied: beautifulsoup4>=4.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.12.3)\n",
|
||||
"Requirement already satisfied: lxml>=4.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.2)\n",
|
||||
"Requirement already satisfied: pypdf2>=2.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: python-docx>=0.8.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: openpyxl>=3.0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.1.5)\n",
|
||||
"Requirement already satisfied: pillow>=9.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (10.4.0)\n",
|
||||
"Requirement already satisfied: librosa>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.11.0)\n",
|
||||
"Requirement already satisfied: opencv-python>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.9.0.80)\n",
|
||||
"Requirement already satisfied: faiss-cpu>=1.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.9.0)\n",
|
||||
"Requirement already satisfied: weaviate-client>=3.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.18.1)\n",
|
||||
"Requirement already satisfied: qdrant-client>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.12.2)\n",
|
||||
"Requirement already satisfied: neo4j>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.3)\n",
|
||||
"Requirement already satisfied: falkordb>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.2.2)\n",
|
||||
"Requirement already satisfied: pymongo>=4.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.15.4)\n",
|
||||
"Requirement already satisfied: sqlalchemy>=1.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.0.23)\n",
|
||||
"Requirement already satisfied: psycopg2-binary>=2.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.9.9)\n",
|
||||
"Requirement already satisfied: pymysql>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: redis>=4.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.4.0)\n",
|
||||
"Requirement already satisfied: celery>=5.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.3.4)\n",
|
||||
"Requirement already satisfied: kafka-python>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.3.0)\n",
|
||||
"Requirement already satisfied: pulsar-client>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.3.0)\n",
|
||||
"Requirement already satisfied: pika>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: boto3>=1.24.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.36.0)\n",
|
||||
"Requirement already satisfied: azure-storage-blob>=12.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (12.27.1)\n",
|
||||
"Requirement already satisfied: google-cloud-storage>=2.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.18.2)\n",
|
||||
"Requirement already satisfied: pydantic>=1.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.12.3)\n",
|
||||
"Requirement already satisfied: click>=8.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (8.2.1)\n",
|
||||
"Requirement already satisfied: rich>=12.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (13.7.1)\n",
|
||||
"Requirement already satisfied: tqdm>=4.64.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.67.1)\n",
|
||||
"Requirement already satisfied: pyyaml>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: toml>=0.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.10.2)\n",
|
||||
"Requirement already satisfied: python-dotenv>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: loguru>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.7.3)\n",
|
||||
"Requirement already satisfied: structlog>=22.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (24.4.0)\n",
|
||||
"Requirement already satisfied: prometheus-client>=0.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.18.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-api>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-sdk>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-instrumentation in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: fastapi>=0.78.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.120.4)\n",
|
||||
"Requirement already satisfied: uvicorn>=0.18.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.38.0)\n",
|
||||
"Requirement already satisfied: pytest>=7.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.3)\n",
|
||||
"Requirement already satisfied: pytest-cov>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.0.0)\n",
|
||||
"Requirement already satisfied: pytest-asyncio>=0.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.21.1)\n",
|
||||
"Requirement already satisfied: black>=22.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (23.11.0)\n",
|
||||
"Requirement already satisfied: isort>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.12.0)\n",
|
||||
"Requirement already satisfied: flake8>=4.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.3.0)\n",
|
||||
"Requirement already satisfied: mypy>=0.971 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pre-commit>=2.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.4.0)\n",
|
||||
"Requirement already satisfied: azure-core>=1.30.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (1.35.0)\n",
|
||||
"Requirement already satisfied: cryptography>=2.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (43.0.3)\n",
|
||||
"Requirement already satisfied: typing-extensions>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (4.14.1)\n",
|
||||
"Requirement already satisfied: isodate>=0.6.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (0.7.2)\n",
|
||||
"Requirement already satisfied: six>=1.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-core>=1.30.0->azure-storage-blob>=12.12.0->semantica) (1.16.0)\n",
|
||||
"Requirement already satisfied: soupsieve>1.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from beautifulsoup4>=4.11.0->semantica) (2.5)\n",
|
||||
"Requirement already satisfied: mypy-extensions>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (1.0.0)\n",
|
||||
"Requirement already satisfied: packaging>=22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (24.2)\n",
|
||||
"Requirement already satisfied: pathspec>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (0.11.2)\n",
|
||||
"Requirement already satisfied: platformdirs>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (3.11.0)\n",
|
||||
"Requirement already satisfied: botocore<1.37.0,>=1.36.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.36.26)\n",
|
||||
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.0.1)\n",
|
||||
"Requirement already satisfied: s3transfer<0.12.0,>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (0.11.3)\n",
|
||||
"Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (2.9.0.post0)\n",
|
||||
"Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (1.26.20)\n",
|
||||
"Requirement already satisfied: billiard<5.0,>=4.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (4.2.1)\n",
|
||||
"Requirement already satisfied: kombu<6.0,>=5.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.5.3)\n",
|
||||
"Requirement already satisfied: vine<6.0,>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.1.0)\n",
|
||||
"Requirement already satisfied: click-didyoumean>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.1)\n",
|
||||
"Requirement already satisfied: click-repl>=0.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.0)\n",
|
||||
"Requirement already satisfied: click-plugins>=1.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: tzdata>=2022.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (2025.2)\n",
|
||||
"Requirement already satisfied: colorama in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from click>=8.1.0->semantica) (0.4.6)\n",
|
||||
"Requirement already satisfied: amqp<6.0.0,>=5.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from kombu<6.0,>=5.3.2->celery>=5.2.0->semantica) (5.3.1)\n",
|
||||
"Requirement already satisfied: prompt-toolkit>=3.0.36 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from click-repl>=0.2.0->celery>=5.2.0->semantica) (3.0.40)\n",
|
||||
"Requirement already satisfied: cffi>=1.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pycparser in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cffi>=1.12->cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (2.22)\n",
|
||||
"Requirement already satisfied: starlette<0.50.0,>=0.40.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.46.2)\n",
|
||||
"Requirement already satisfied: annotated-doc>=0.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.0.3)\n",
|
||||
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pydantic-core==2.41.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (2.41.4)\n",
|
||||
"Requirement already satisfied: typing-inspection>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.4.2)\n",
|
||||
"Requirement already satisfied: anyio<5,>=3.6.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (4.11.0)\n",
|
||||
"Requirement already satisfied: idna>=2.8 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (3.10)\n",
|
||||
"Requirement already satisfied: sniffio>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (1.3.1)\n",
|
||||
"Requirement already satisfied: mccabe<0.8.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pycodestyle<2.15.0,>=2.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (2.14.0)\n",
|
||||
"Requirement already satisfied: pyflakes<3.5.0,>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: google-auth<3.0dev,>=2.26.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.36.0)\n",
|
||||
"Requirement already satisfied: google-api-core<3.0.0dev,>=2.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.23.0)\n",
|
||||
"Requirement already satisfied: google-cloud-core<3.0dev,>=2.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.4.1)\n",
|
||||
"Requirement already satisfied: google-resumable-media>=2.7.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.7.2)\n",
|
||||
"Requirement already satisfied: google-crc32c<2.0dev,>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.66.0)\n",
|
||||
"Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.19.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (4.25.8)\n",
|
||||
"Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.25.0)\n",
|
||||
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (5.5.2)\n",
|
||||
"Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.4.1)\n",
|
||||
"Requirement already satisfied: rsa<5,>=3.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (4.9)\n",
|
||||
"Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (2025.8.3)\n",
|
||||
"Requirement already satisfied: pyasn1>=0.1.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rsa<5,>=3.1.4->google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.6.1)\n",
|
||||
"Requirement already satisfied: audioread>=2.1.9 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: numba>=0.51.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.61.2)\n",
|
||||
"Requirement already satisfied: scipy>=1.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.15.2)\n",
|
||||
"Requirement already satisfied: joblib>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: decorator>=4.3.0 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from librosa>=0.9.0->semantica) (5.1.1)\n",
|
||||
"Requirement already satisfied: soundfile>=0.12.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.13.1)\n",
|
||||
"Requirement already satisfied: pooch>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.8.2)\n",
|
||||
"Requirement already satisfied: soxr>=0.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.5.0.post1)\n",
|
||||
"Requirement already satisfied: lazy_loader>=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.4)\n",
|
||||
"Requirement already satisfied: msgpack>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: win32-setctime>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from loguru>=0.6.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: cycler>=0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (0.12.1)\n",
|
||||
"Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (4.57.0)\n",
|
||||
"Requirement already satisfied: kiwisolver>=1.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.4.8)\n",
|
||||
"Requirement already satisfied: pyparsing>=2.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: pytz in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from neo4j>=5.0.0->semantica) (2024.2)\n",
|
||||
"Requirement already satisfied: llvmlite<0.45,>=0.44.0dev0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from numba>=0.51.0->librosa>=0.9.0->semantica) (0.44.0)\n",
|
||||
"Requirement already satisfied: et-xmlfile in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from openpyxl>=3.0.10->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-api>=1.12.0->semantica) (6.8.0)\n",
|
||||
"Requirement already satisfied: zipp>=0.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api>=1.12.0->semantica) (3.17.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-semantic-conventions==0.59b0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-sdk>=1.12.0->semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: tenacity>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from plotly>=5.10.0->semantica) (8.5.0)\n",
|
||||
"Requirement already satisfied: cfgv>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (3.5.0)\n",
|
||||
"Requirement already satisfied: identify>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (2.6.15)\n",
|
||||
"Requirement already satisfied: nodeenv>=0.11.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (1.9.1)\n",
|
||||
"Requirement already satisfied: virtualenv>=20.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (20.24.6)\n",
|
||||
"Requirement already satisfied: wcwidth in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from prompt-toolkit>=3.0.36->click-repl>=0.2.0->celery>=5.2.0->semantica) (0.2.9)\n",
|
||||
"Requirement already satisfied: dnspython<3.0.0,>=1.16.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pymongo>=4.2.0->semantica) (2.4.2)\n",
|
||||
"Requirement already satisfied: iniconfig in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: pluggy<2.0,>=0.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (1.5.0)\n",
|
||||
"Requirement already satisfied: coverage>=7.10.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from coverage[toml]>=7.10.6->pytest-cov>=3.0.0->semantica) (7.12.0)\n",
|
||||
"Requirement already satisfied: grpcio>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.68.0)\n",
|
||||
"Requirement already satisfied: grpcio-tools>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.62.3)\n",
|
||||
"Requirement already satisfied: httpx>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.28.1)\n",
|
||||
"Requirement already satisfied: portalocker<3.0.0,>=2.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (2.10.1)\n",
|
||||
"Requirement already satisfied: pywin32>=226 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from portalocker<3.0.0,>=2.7.0->qdrant-client>=1.3.0->semantica) (311)\n",
|
||||
"Requirement already satisfied: setuptools in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from grpcio-tools>=1.41.0->qdrant-client>=1.3.0->semantica) (80.9.0)\n",
|
||||
"Requirement already satisfied: httpcore==1.* in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (1.0.9)\n",
|
||||
"Requirement already satisfied: h11>=0.16 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpcore==1.*->httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.16.0)\n",
|
||||
"Requirement already satisfied: h2<5,>=3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.1.0)\n",
|
||||
"Requirement already satisfied: hyperframe<7,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: hpack<5,>=4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.0.0)\n",
|
||||
"Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (3.0.0)\n",
|
||||
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (2.19.2)\n",
|
||||
"Requirement already satisfied: mdurl~=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from markdown-it-py>=2.2.0->rich>=12.5.0->semantica) (0.1.2)\n",
|
||||
"Requirement already satisfied: threadpoolctl>=3.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from scikit-learn>=1.0.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: huggingface-hub>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sentence-transformers>=2.2.0->semantica) (0.30.2)\n",
|
||||
"Requirement already satisfied: filelock in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (3.16.1)\n",
|
||||
"Requirement already satisfied: regex!=2019.12.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (2024.11.6)\n",
|
||||
"Requirement already satisfied: tokenizers<0.22,>=0.21 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.21.4)\n",
|
||||
"Requirement already satisfied: safetensors>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.5.3)\n",
|
||||
"Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers>=2.2.0->semantica) (2023.10.0)\n",
|
||||
"Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.5)\n",
|
||||
"Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.15)\n",
|
||||
"Requirement already satisfied: cymem<2.1.0,>=2.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.13)\n",
|
||||
"Requirement already satisfied: preshed<3.1.0,>=3.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: thinc<8.4.0,>=8.3.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (8.3.10)\n",
|
||||
"Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.1.3)\n",
|
||||
"Requirement already satisfied: srsly<3.0.0,>=2.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.5.2)\n",
|
||||
"Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.10)\n",
|
||||
"Requirement already satisfied: weasel<0.5.0,>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.4.3)\n",
|
||||
"Requirement already satisfied: typer-slim<1.0.0,>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.20.0)\n",
|
||||
"Requirement already satisfied: jinja2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.1.6)\n",
|
||||
"Requirement already satisfied: blis<1.4.0,>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (1.3.3)\n",
|
||||
"Requirement already satisfied: confection<1.0.0,>=0.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (0.1.5)\n",
|
||||
"Requirement already satisfied: cloudpathlib<1.0.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (0.23.0)\n",
|
||||
"Requirement already satisfied: smart-open<8.0.0,>=5.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (7.1.0)\n",
|
||||
"Requirement already satisfied: wrapt in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from smart-open<8.0.0,>=5.2.1->weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (1.17.2)\n",
|
||||
"Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sqlalchemy>=1.4.0->semantica) (3.2.3)\n",
|
||||
"Requirement already satisfied: sympy in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from torch>=1.12.0->semantica) (1.13.3)\n",
|
||||
"Requirement already satisfied: distlib<1,>=0.3.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from virtualenv>=20.10.0->pre-commit>=2.19.0->semantica) (0.3.7)\n",
|
||||
"Requirement already satisfied: validators<1.0.0,>=0.34.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (0.35.0)\n",
|
||||
"Requirement already satisfied: authlib<2.0.0,>=1.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: deprecation<3.0.0,>=2.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (2.1.0)\n",
|
||||
"Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from jinja2->spacy>=3.4.0->semantica) (2.1.3)\n",
|
||||
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sympy->torch>=1.12.0->semantica) (1.3.0)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -71,9 +294,45 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is extracting</td><td>🎯 semantic_extract</td><td>NERExtractor</td><td>-</td><td>1.08s</td></tr><tr><td>✅</td><td>Semantica is extracting</td><td>🎯 semantic_extract</td><td>NamedEntityRecognizer</td><td>-</td><td>2.50s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Extracted 13 entities:\n",
|
||||
"\n",
|
||||
"--------------------------------------------------------------------------------\n",
|
||||
" 1. Apple Inc. | Type: ORG | Confidence: 1.00\n",
|
||||
" 2. Steve Jobs | Type: PERSON | Confidence: 1.00\n",
|
||||
" 3. Steve Wozniak | Type: PERSON | Confidence: 1.00\n",
|
||||
" 4. Ronald Wayne | Type: PERSON | Confidence: 1.00\n",
|
||||
" 5. Cupertino | Type: GPE | Confidence: 1.00\n",
|
||||
" 6. California | Type: GPE | Confidence: 1.00\n",
|
||||
" 7. April 1, 1976 | Type: DATE | Confidence: 1.00\n",
|
||||
" 8. Tim Cook | Type: PERSON | Confidence: 1.00\n",
|
||||
" 9. Steve Jobs | Type: PERSON | Confidence: 1.00\n",
|
||||
"10. August 2011 | Type: DATE | Confidence: 1.00\n",
|
||||
"11. Apple | Type: ORG | Confidence: 1.00\n",
|
||||
"12. One | Type: CARDINAL | Confidence: 1.00\n",
|
||||
"13. Cupertino | Type: GPE | Confidence: 1.00\n",
|
||||
"--------------------------------------------------------------------------------\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import NERExtractor\n",
|
||||
"\n",
|
||||
@@ -144,9 +403,43 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n",
|
||||
" Entity Visualization:\n",
|
||||
"\n",
|
||||
"================================================================================\n",
|
||||
"\n",
|
||||
"CARDINAL:\n",
|
||||
" • One\n",
|
||||
"\n",
|
||||
"DATE:\n",
|
||||
" • August 2011\n",
|
||||
" • April 1, 1976\n",
|
||||
"\n",
|
||||
"GPE:\n",
|
||||
" • California\n",
|
||||
" • Cupertino\n",
|
||||
"\n",
|
||||
"ORG:\n",
|
||||
" • Apple\n",
|
||||
" • Apple Inc.\n",
|
||||
"\n",
|
||||
"PERSON:\n",
|
||||
" • Steve Wozniak\n",
|
||||
" • Ronald Wayne\n",
|
||||
" • Steve Jobs\n",
|
||||
" • Tim Cook\n",
|
||||
"\n",
|
||||
"================================================================================\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"def highlight_entities(text, entities):\n",
|
||||
" \"\"\"\n",
|
||||
@@ -200,9 +493,47 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Comparing Extraction Methods:\n",
|
||||
"\n",
|
||||
"================================================================================\n",
|
||||
"\n",
|
||||
" Method: PATTERN\n",
|
||||
"----------------------------------------\n",
|
||||
"Found 4 entities:\n",
|
||||
" • Apple Inc (PERSON)\n",
|
||||
" • Steve Jobs (PERSON)\n",
|
||||
" • Apple Inc (ORG)\n",
|
||||
" • 1976 (DATE)\n",
|
||||
"\n",
|
||||
" Method: REGEX\n",
|
||||
"----------------------------------------\n",
|
||||
"Found 8 entities:\n",
|
||||
" • Apple Inc (PERSON)\n",
|
||||
" • was founded by Steve Jobs in Cupertino (PERSON)\n",
|
||||
" • California in (PERSON)\n",
|
||||
" • Apple Inc (ORG)\n",
|
||||
" • Apple Inc (GPE)\n",
|
||||
"\n",
|
||||
" Method: ML\n",
|
||||
"----------------------------------------\n",
|
||||
"Found 5 entities:\n",
|
||||
" • Apple Inc. (ORG)\n",
|
||||
" • Steve Jobs (PERSON)\n",
|
||||
" • Cupertino (GPE)\n",
|
||||
" • California (GPE)\n",
|
||||
" • 1976 (DATE)\n",
|
||||
"\n",
|
||||
"================================================================================\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import NERExtractor\n",
|
||||
"\n",
|
||||
@@ -252,9 +583,49 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Advanced Entity Recognition Results:\n",
|
||||
"\n",
|
||||
"================================================================================\n",
|
||||
"\n",
|
||||
" Text 1: Tim Cook is the CEO of Apple Inc., based in Cupertino....\n",
|
||||
" Found 3 entities:\n",
|
||||
" • Tim Cook | PERSON | Confidence: 1.00\n",
|
||||
" • Apple Inc. | ORG | Confidence: 1.00\n",
|
||||
" • Cupertino | GPE | Confidence: 1.00\n",
|
||||
"\n",
|
||||
" Text 2: Microsoft Corporation, founded by Bill Gates, is headquarter...\n",
|
||||
" Found 4 entities:\n",
|
||||
" • Microsoft Corporation | ORG | Confidence: 1.00\n",
|
||||
" • Bill Gates | PERSON | Confidence: 1.00\n",
|
||||
" • Redmond | GPE | Confidence: 1.00\n",
|
||||
" • Washington | GPE | Confidence: 1.00\n",
|
||||
"\n",
|
||||
" Text 3: Amazon was founded by Jeff Bezos in Seattle in 1994....\n",
|
||||
" Found 4 entities:\n",
|
||||
" • Amazon | ORG | Confidence: 1.00\n",
|
||||
" • Jeff Bezos | PERSON | Confidence: 1.00\n",
|
||||
" • Seattle | GPE | Confidence: 1.00\n",
|
||||
" • 1994 | DATE | Confidence: 1.00\n",
|
||||
"\n",
|
||||
" Text 4: Google was started by Larry Page and Sergey Brin at Stanford...\n",
|
||||
" Found 4 entities:\n",
|
||||
" • Google | ORG | Confidence: 1.00\n",
|
||||
" • Larry Page | PERSON | Confidence: 1.00\n",
|
||||
" • Sergey Brin | PERSON | Confidence: 1.00\n",
|
||||
" • Stanford University | ORG | Confidence: 1.00\n",
|
||||
"\n",
|
||||
" Total entities extracted: 15\n",
|
||||
"================================================================================\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import NamedEntityRecognizer\n",
|
||||
"\n",
|
||||
@@ -314,9 +685,48 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"️ Entity Classification Results:\n",
|
||||
"\n",
|
||||
"================================================================================\n",
|
||||
"\n",
|
||||
"DATE (1 entities):\n",
|
||||
"----------------------------------------\n",
|
||||
" • 1994\n",
|
||||
"\n",
|
||||
"GPE (4 entities):\n",
|
||||
"----------------------------------------\n",
|
||||
" • Cupertino\n",
|
||||
" • Redmond\n",
|
||||
" • Seattle\n",
|
||||
" • Washington\n",
|
||||
"\n",
|
||||
"ORG (5 entities):\n",
|
||||
"----------------------------------------\n",
|
||||
" • Amazon\n",
|
||||
" • Apple Inc.\n",
|
||||
" • Google\n",
|
||||
" • Microsoft Corporation\n",
|
||||
" • Stanford University\n",
|
||||
"\n",
|
||||
"PERSON (5 entities):\n",
|
||||
"----------------------------------------\n",
|
||||
" • Bill Gates\n",
|
||||
" • Jeff Bezos\n",
|
||||
" • Larry Page\n",
|
||||
" • Sergey Brin\n",
|
||||
" • Tim Cook\n",
|
||||
"\n",
|
||||
"================================================================================\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import EntityClassifier\n",
|
||||
"\n",
|
||||
@@ -364,9 +774,32 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Entity Confidence Scoring:\n",
|
||||
"\n",
|
||||
"================================================================================\n",
|
||||
" High Confidence (≥0.8): 15 entities\n",
|
||||
"️ Medium Confidence (0.5-0.8): 0 entities\n",
|
||||
" Low Confidence (<0.5): 0 entities\n",
|
||||
"\n",
|
||||
" Confidence Distribution:\n",
|
||||
"----------------------------------------\n",
|
||||
"\n",
|
||||
"High Confidence Examples:\n",
|
||||
" • Tim Cook (PERSON) - 1.00\n",
|
||||
" • Apple Inc. (ORG) - 1.00\n",
|
||||
" • Cupertino (GPE) - 1.00\n",
|
||||
"\n",
|
||||
"================================================================================\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import EntityConfidenceScorer\n",
|
||||
"\n",
|
||||
@@ -432,9 +865,34 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Custom Entity Detection:\n",
|
||||
"\n",
|
||||
"================================================================================\n",
|
||||
"\n",
|
||||
"EMAIL:\n",
|
||||
" • support@apple.com\n",
|
||||
" • tech@apple.com\n",
|
||||
"\n",
|
||||
"PHONE:\n",
|
||||
" • 800-692-7753\n",
|
||||
"\n",
|
||||
"PRODUCT_CODE:\n",
|
||||
" • SKU-12345\n",
|
||||
"\n",
|
||||
"URL:\n",
|
||||
" • https://store.apple.com.\n",
|
||||
"\n",
|
||||
"================================================================================\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import CustomEntityDetector\n",
|
||||
"import re\n",
|
||||
@@ -490,9 +948,55 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Batch Processing Results:\n",
|
||||
"\n",
|
||||
"================================================================================\n",
|
||||
"\n",
|
||||
" Document 1:\n",
|
||||
" Text: Apple Inc. released the iPhone 15 in September 202...\n",
|
||||
" Entities: 2\n",
|
||||
"\n",
|
||||
" Document 2:\n",
|
||||
" Text: Microsoft announced Azure AI updates at Build 2023...\n",
|
||||
" Entities: 3\n",
|
||||
"\n",
|
||||
" Document 3:\n",
|
||||
" Text: Google's Sundar Pichai spoke at I/O 2023 in Mounta...\n",
|
||||
" Entities: 5\n",
|
||||
"\n",
|
||||
" Document 4:\n",
|
||||
" Text: Tesla's Elon Musk unveiled the Cybertruck in Austi...\n",
|
||||
" Entities: 5\n",
|
||||
"\n",
|
||||
" Document 5:\n",
|
||||
" Text: Amazon Web Services launched new features in North...\n",
|
||||
" Entities: 2\n",
|
||||
"\n",
|
||||
" Batch Processing Summary:\n",
|
||||
"----------------------------------------\n",
|
||||
"Documents processed: 5\n",
|
||||
"Total entities: 17\n",
|
||||
"Average per document: 3.4\n",
|
||||
"\n",
|
||||
" Entity Type Distribution:\n",
|
||||
" ORG: 5\n",
|
||||
" GPE: 5\n",
|
||||
" DATE: 3\n",
|
||||
" PERSON: 2\n",
|
||||
" PRODUCT: 1\n",
|
||||
" LOC: 1\n",
|
||||
"\n",
|
||||
"================================================================================\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Sample document collection\n",
|
||||
"documents = [\n",
|
||||
@@ -633,7 +1137,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.0"
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook provides a **comprehensive guide** to extracting relationships between entities and building RDF triples using Semantica's relation extraction modules. You'll learn to identify connections, extract structured triples, and prepare data for knowledge graphs.\n",
|
||||
"This notebook provides a **comprehensive guide** to extracting relationships between entities and building RDF triplets using Semantica's relation extraction modules. You'll learn to identify connections, extract structured triplets, and prepare data for knowledge graphs.\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/semantic_extract/)\n",
|
||||
"\n",
|
||||
@@ -21,21 +21,17 @@
|
||||
"- Extract relationships using `RelationExtractor`\n",
|
||||
"- Understand different extraction methods (pattern, dependency, co-occurrence, HuggingFace, LLM)\n",
|
||||
"- Configure extraction parameters for optimal results\n",
|
||||
"- Extract RDF triples with `TripleExtractor`\n",
|
||||
"- Validate triples using `TripleValidator`\n",
|
||||
"- Serialize triples to RDF formats with `RDFSerializer`\n",
|
||||
"- Assess triple quality with `TripleQualityChecker`\n",
|
||||
"- Build complete entity → relation → triple pipelines\n",
|
||||
"- Extract RDF triplets with `TripletExtractor`\n",
|
||||
"- Serialize triplets to RDF formats with `RDFSerializer`\n",
|
||||
"- Build complete entity \u2192 relation \u2192 triplet pipelines\n",
|
||||
"\n",
|
||||
"### What You'll Learn\n",
|
||||
"\n",
|
||||
"| Component | Purpose | When to Use |\n",
|
||||
"|-----------|---------|-------------|\n",
|
||||
"| `RelationExtractor` | Extract entity relationships | Finding connections |\n",
|
||||
"| `TripleExtractor` | Extract RDF triples | Building knowledge graphs |\n",
|
||||
"| `TripleValidator` | Validate triple quality | Quality assurance |\n",
|
||||
"| `TripletExtractor` | Extract RDF triplets | Building knowledge graphs |\n",
|
||||
"| `RDFSerializer` | Serialize to RDF formats | Data export |\n",
|
||||
"| `TripleQualityChecker` | Assess triple quality | Quality metrics |\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -52,6 +48,15 @@
|
||||
"---"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -159,7 +164,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## ️ Step 2: Different Extraction Methods\n",
|
||||
"## \ufe0f Step 2: Different Extraction Methods\n",
|
||||
"\n",
|
||||
"Semantica supports multiple relation extraction methods:\n",
|
||||
"\n",
|
||||
@@ -167,11 +172,11 @@
|
||||
"\n",
|
||||
"| Method | Speed | Accuracy | Use Case | Requires |\n",
|
||||
"|--------|-------|----------|----------|----------|\n",
|
||||
"| **pattern** | | ⭐⭐⭐ | Common relations | Nothing |\n",
|
||||
"| **dependency** | | ⭐⭐⭐⭐ | Grammatical relations | spaCy |\n",
|
||||
"| **cooccurrence** | | ⭐⭐ | Proximity-based | Nothing |\n",
|
||||
"| **huggingface** | | ⭐⭐⭐⭐⭐ | Domain-specific | HF model |\n",
|
||||
"| **llm** | | ⭐⭐⭐⭐⭐ | Complex, custom | API key |"
|
||||
"| **pattern** | | \u2b50\u2b50\u2b50 | Common relations | Nothing |\n",
|
||||
"| **dependency** | | \u2b50\u2b50\u2b50\u2b50 | Grammatical relations | spaCy |\n",
|
||||
"| **cooccurrence** | | \u2b50\u2b50 | Proximity-based | Nothing |\n",
|
||||
"| **huggingface** | | \u2b50\u2b50\u2b50\u2b50\u2b50 | Domain-specific | HF model |\n",
|
||||
"| **llm** | | \u2b50\u2b50\u2b50\u2b50\u2b50 | Complex, custom | API key |"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -209,10 +214,10 @@
|
||||
" source_text = source.get('text', str(source)) if isinstance(source, dict) else getattr(source, 'text', str(source))\n",
|
||||
" target_text = target.get('text', str(target)) if isinstance(target, dict) else getattr(target, 'text', str(target))\n",
|
||||
" \n",
|
||||
" print(f\" • {source_text} --[{rel_type}]--> {target_text}\")\n",
|
||||
" print(f\" \u2022 {source_text} --[{rel_type}]--> {target_text}\")\n",
|
||||
" \n",
|
||||
" except Exception as e:\n",
|
||||
" print(f\" ️ Method '{method_name}' not available: {str(e)[:50]}\")\n",
|
||||
" print(f\" \ufe0f Method '{method_name}' not available: {str(e)[:50]}\")\n",
|
||||
"\n",
|
||||
"print(\"\\n\" + \"=\" * 80)"
|
||||
]
|
||||
@@ -274,7 +279,7 @@
|
||||
" source_text = source.get('text', str(source)) if isinstance(source, dict) else getattr(source, 'text', str(source))\n",
|
||||
" target_text = target.get('text', str(target)) if isinstance(target, dict) else getattr(target, 'text', str(target))\n",
|
||||
" \n",
|
||||
" print(f\" • {source_text} --[{rel_type}]--> {target_text} (conf: {confidence:.2f})\")\n",
|
||||
" print(f\" \u2022 {source_text} --[{rel_type}]--> {target_text} (conf: {confidence:.2f})\")\n",
|
||||
"\n",
|
||||
"print(\"\\n\" + \"=\" * 80)"
|
||||
]
|
||||
@@ -283,7 +288,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## ️ Step 4: Relation Classification\n",
|
||||
"## \ufe0f Step 4: Relation Classification\n",
|
||||
"\n",
|
||||
"Group and classify extracted relations by their predicate type."
|
||||
]
|
||||
@@ -304,7 +309,7 @@
|
||||
"# Classify relations\n",
|
||||
"classified_relations = advanced_extractor.classify_relations(all_relations)\n",
|
||||
"\n",
|
||||
"print(\"️ Relation Classification:\\n\")\n",
|
||||
"print(\"\ufe0f Relation Classification:\\n\")\n",
|
||||
"print(\"=\" * 80)\n",
|
||||
"\n",
|
||||
"for rel_type, rel_list in sorted(classified_relations.items()):\n",
|
||||
@@ -318,7 +323,7 @@
|
||||
" source_text = source.get('text', str(source)) if isinstance(source, dict) else getattr(source, 'text', str(source))\n",
|
||||
" target_text = target.get('text', str(target)) if isinstance(target, dict) else getattr(target, 'text', str(target))\n",
|
||||
" \n",
|
||||
" print(f\" • {source_text} → {target_text}\")\n",
|
||||
" print(f\" \u2022 {source_text} \u2192 {target_text}\")\n",
|
||||
"\n",
|
||||
"print(\"\\n\" + \"=\" * 80)"
|
||||
]
|
||||
@@ -327,20 +332,20 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 5: Triple Extraction\n",
|
||||
"## Step 5: Triplet Extraction\n",
|
||||
"\n",
|
||||
"Extract RDF triples using `TripleExtractor`. Triples are the foundation of knowledge graphs.\n",
|
||||
"Extract RDF triplets using `TripletExtractor`. Triplets are the foundation of knowledge graphs.\n",
|
||||
"\n",
|
||||
"### What are RDF Triples?\n",
|
||||
"### What are RDF Triplets?\n",
|
||||
"\n",
|
||||
"RDF (Resource Description Framework) triples are statements with three parts:\n",
|
||||
"RDF (Resource Description Framework) triplets are statements with three parts:\n",
|
||||
"- **Subject**: What we're talking about\n",
|
||||
"- **Predicate**: The property or relationship\n",
|
||||
"- **Object**: The value or target\n",
|
||||
"\n",
|
||||
"Example: `(Apple Inc., founded_by, Steve Jobs)`\n",
|
||||
"\n",
|
||||
"### Why Use Triples?\n",
|
||||
"### Why Use Triplets?\n",
|
||||
"\n",
|
||||
"- **Standardized format** for knowledge representation\n",
|
||||
"- **Compatible** with RDF databases and semantic web\n",
|
||||
@@ -354,37 +359,37 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import TripleExtractor\n",
|
||||
"from semantica.semantic_extract import TripletExtractor\n",
|
||||
"\n",
|
||||
"# Initialize triple extractor\n",
|
||||
"triple_extractor = TripleExtractor(\n",
|
||||
"# Initialize triplet extractor\n",
|
||||
"triplet_extractor = TripletExtractor(\n",
|
||||
" include_temporal=True, # Include temporal information\n",
|
||||
" include_provenance=True # Track source sentences\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Sample text\n",
|
||||
"triple_text = \"\"\"\n",
|
||||
"triplet_text = \"\"\"\n",
|
||||
"Apple Inc. was founded by Steve Jobs in 1976. The company is based in Cupertino, California.\n",
|
||||
"Tim Cook became CEO in 2011. Apple develops the iPhone and MacBook products.\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"# Extract triples\n",
|
||||
"triples = triple_extractor.extract_triples(triple_text)\n",
|
||||
"# Extract triplets\n",
|
||||
"triplets = triplet_extractor.extract_triplets(triplet_text)\n",
|
||||
"\n",
|
||||
"print(f\" Extracted {len(triples)} RDF Triples:\\n\")\n",
|
||||
"print(f\" Extracted {len(triplets)} RDF Triplets:\\n\")\n",
|
||||
"print(\"=\" * 80)\n",
|
||||
"\n",
|
||||
"for i, triple in enumerate(triples, 1):\n",
|
||||
" subject = triple.get('subject', '') if isinstance(triple, dict) else triple.subject\n",
|
||||
" predicate = triple.get('predicate', '') if isinstance(triple, dict) else triple.predicate\n",
|
||||
" obj = triple.get('object', '') if isinstance(triple, dict) else triple.object\n",
|
||||
" confidence = triple.get('confidence', 1.0) if isinstance(triple, dict) else getattr(triple, 'confidence', 1.0)\n",
|
||||
"for i, triplet in enumerate(triplets, 1):\n",
|
||||
" subject = triplet.get('subject', '') if isinstance(triplet, dict) else triplet.subject\n",
|
||||
" predicate = triplet.get('predicate', '') if isinstance(triplet, dict) else triplet.predicate\n",
|
||||
" obj = triplet.get('object', '') if isinstance(triplet, dict) else triplet.object\n",
|
||||
" confidence = triplet.get('confidence', 1.0) if isinstance(triplet, dict) else getattr(triplet, 'confidence', 1.0)\n",
|
||||
" \n",
|
||||
" print(f\"{i:2d}. ({subject}, {predicate}, {obj})\")\n",
|
||||
" print(f\" Confidence: {confidence:.2f}\")\n",
|
||||
" \n",
|
||||
" # Show temporal info if available\n",
|
||||
" metadata = triple.get('metadata', {}) if isinstance(triple, dict) else getattr(triple, 'metadata', {})\n",
|
||||
" metadata = triplet.get('metadata', {}) if isinstance(triplet, dict) else getattr(triplet, 'metadata', {})\n",
|
||||
" if metadata.get('temporal'):\n",
|
||||
" print(f\" Temporal: {metadata['temporal']}\")\n",
|
||||
" print()\n",
|
||||
@@ -396,69 +401,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 6: Triple Validation\n",
|
||||
"## Step 6: RDF Serialization\n",
|
||||
"\n",
|
||||
"Validate extracted triples using `TripleValidator` and assess quality with `TripleQualityChecker`.\n",
|
||||
"\n",
|
||||
"### Why Validate Triples?\n",
|
||||
"\n",
|
||||
"- **Ensure completeness**: All parts (subject, predicate, object) present\n",
|
||||
"- **Check confidence**: Filter low-quality extractions\n",
|
||||
"- **Verify consistency**: No contradictory statements\n",
|
||||
"- **Assess quality**: Overall extraction quality metrics"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import TripleValidator, TripleQualityChecker\n",
|
||||
"\n",
|
||||
"# Initialize validator and quality checker\n",
|
||||
"validator = TripleValidator()\n",
|
||||
"quality_checker = TripleQualityChecker()\n",
|
||||
"\n",
|
||||
"print(\" Triple Validation:\\n\")\n",
|
||||
"print(\"=\" * 80)\n",
|
||||
"\n",
|
||||
"# Validate triples\n",
|
||||
"valid_triples = validator.validate_triples(triples, min_confidence=0.5)\n",
|
||||
"\n",
|
||||
"print(f\"\\n Validation Results:\")\n",
|
||||
"print(f\" Total triples: {len(triples)}\")\n",
|
||||
"print(f\" Valid triples: {len(valid_triples)}\")\n",
|
||||
"print(f\" Filtered out: {len(triples) - len(valid_triples)}\")\n",
|
||||
"\n",
|
||||
"# Check quality\n",
|
||||
"quality_scores = quality_checker.calculate_quality_scores(valid_triples)\n",
|
||||
"\n",
|
||||
"print(f\"\\n Quality Metrics:\")\n",
|
||||
"print(\"-\" * 40)\n",
|
||||
"for metric, value in quality_scores.items():\n",
|
||||
" if isinstance(value, float):\n",
|
||||
" print(f\" {metric}: {value:.2f}\")\n",
|
||||
" else:\n",
|
||||
" print(f\" {metric}: {value}\")\n",
|
||||
"\n",
|
||||
"# Check consistency\n",
|
||||
"consistency_report = validator.check_triple_consistency(valid_triples)\n",
|
||||
"\n",
|
||||
"print(f\"\\n Consistency Check:\")\n",
|
||||
"print(f\" Consistent: {consistency_report.get('consistent', True)}\")\n",
|
||||
"print(f\" Issues found: {len(consistency_report.get('issues', []))}\")\n",
|
||||
"\n",
|
||||
"print(\"\\n\" + \"=\" * 80)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 7: RDF Serialization\n",
|
||||
"\n",
|
||||
"Serialize triples to various RDF formats using `RDFSerializer`.\n",
|
||||
"Serialize triplets to various RDF formats using `RDFSerializer`.\n",
|
||||
"\n",
|
||||
"### Supported Formats:\n",
|
||||
"\n",
|
||||
@@ -492,7 +437,7 @@
|
||||
" print(\"-\" * 40)\n",
|
||||
" \n",
|
||||
" try:\n",
|
||||
" serialized = serializer.serialize_to_rdf(valid_triples[:3], format=fmt) # Show first 3\n",
|
||||
" serialized = serializer.serialize_to_rdf(triplets[:3], format=fmt) # Show first 3\n",
|
||||
" \n",
|
||||
" # Show preview (first 300 chars)\n",
|
||||
" preview = serialized[:300] + \"...\" if len(serialized) > 300 else serialized\n",
|
||||
@@ -508,9 +453,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 8: Complete Extraction Pipeline\n",
|
||||
"## Step 7: Complete Extraction Pipeline\n",
|
||||
"\n",
|
||||
"Let's build a complete pipeline: **Entities → Relations → Triples**\n",
|
||||
"Let's build a complete pipeline: **Entities \u2192 Relations \u2192 Triplets**\n",
|
||||
"\n",
|
||||
"This demonstrates the full workflow for knowledge graph construction."
|
||||
]
|
||||
@@ -529,7 +474,7 @@
|
||||
" text: Input text\n",
|
||||
" \n",
|
||||
" Returns:\n",
|
||||
" dict: Extracted entities, relations, and triples\n",
|
||||
" dict: Extracted entities, relations, and triplets\n",
|
||||
" \"\"\"\n",
|
||||
" # Step 1: Extract entities\n",
|
||||
" entities = ner_extractor.extract(text)\n",
|
||||
@@ -537,16 +482,13 @@
|
||||
" # Step 2: Extract relations\n",
|
||||
" relations = relation_extractor.extract(text, entities)\n",
|
||||
" \n",
|
||||
" # Step 3: Extract triples\n",
|
||||
" triples = triple_extractor.extract_triples(text, entities=entities, relationships=relations)\n",
|
||||
" \n",
|
||||
" # Step 4: Validate triples\n",
|
||||
" valid_triples = validator.validate_triples(triples)\n",
|
||||
" # Step 3: Extract triplets\n",
|
||||
" triplets = triplet_extractor.extract_triplets(text, entities=entities, relationships=relations)\n",
|
||||
" \n",
|
||||
" return {\n",
|
||||
" 'entities': entities,\n",
|
||||
" 'relations': relations,\n",
|
||||
" 'triples': valid_triples\n",
|
||||
" 'triplets': triplets\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"# Sample knowledge-rich text\n",
|
||||
@@ -567,13 +509,13 @@
|
||||
"print(\"-\" * 40)\n",
|
||||
"print(f\"Entities extracted: {len(result['entities'])}\")\n",
|
||||
"print(f\"Relations extracted: {len(result['relations'])}\")\n",
|
||||
"print(f\"Triples extracted: {len(result['triples'])}\")\n",
|
||||
"print(f\"Triplets extracted: {len(result['triplets'])}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n Sample Triples:\")\n",
|
||||
"for i, triple in enumerate(result['triples'][:5], 1):\n",
|
||||
" subject = triple.get('subject', '') if isinstance(triple, dict) else triple.subject\n",
|
||||
" predicate = triple.get('predicate', '') if isinstance(triple, dict) else triple.predicate\n",
|
||||
" obj = triple.get('object', '') if isinstance(triple, dict) else triple.object\n",
|
||||
"print(f\"\\n Sample Triplets:\")\n",
|
||||
"for i, triplet in enumerate(result['triplets'][:5], 1):\n",
|
||||
" subject = triplet.get('subject', '') if isinstance(triplet, dict) else triplet.subject\n",
|
||||
" predicate = triplet.get('predicate', '') if isinstance(triplet, dict) else triplet.predicate\n",
|
||||
" obj = triplet.get('object', '') if isinstance(triplet, dict) else triplet.object\n",
|
||||
" print(f\" {i}. ({subject}, {predicate}, {obj})\")\n",
|
||||
"\n",
|
||||
"print(\"\\n\" + \"=\" * 80)"
|
||||
@@ -583,7 +525,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 9: Best Practices & Tips\n",
|
||||
"## Step 8: Best Practices & Tips\n",
|
||||
"\n",
|
||||
"### Choosing the Right Method\n",
|
||||
"\n",
|
||||
@@ -592,37 +534,32 @@
|
||||
"3. **Try co-occurrence** for exploratory analysis\n",
|
||||
"4. **Consider LLM** for complex, domain-specific relations\n",
|
||||
"\n",
|
||||
"### ️ Optimizing Extraction\n",
|
||||
"### \ufe0f Optimizing Extraction\n",
|
||||
"\n",
|
||||
"- **Set confidence thresholds** (0.6-0.7 for production)\n",
|
||||
"- **Specify relation_types** to focus extraction\n",
|
||||
"- **Adjust max_distance** based on text structure\n",
|
||||
"- **Validate triples** before using in knowledge graphs\n",
|
||||
"\n",
|
||||
"### Common Pitfalls to Avoid\n",
|
||||
"\n",
|
||||
"- **Don't** skip entity extraction (relations need entities)\n",
|
||||
"- **Don't** use very low confidence thresholds\n",
|
||||
"- **Don't** ignore relation validation\n",
|
||||
"- **Don't** forget to serialize triples for storage\n",
|
||||
"- **Don't** forget to serialize triplets for storage\n",
|
||||
"\n",
|
||||
"### When to Use Each Component\n",
|
||||
"\n",
|
||||
"| Use Case | Recommended Component |\n",
|
||||
"|----------|----------------------|\n",
|
||||
"| Find entity connections | `RelationExtractor` |\n",
|
||||
"| Build knowledge graphs | `TripleExtractor` |\n",
|
||||
"| Quality assurance | `TripleValidator` |\n",
|
||||
"| Build knowledge graphs | `TripletExtractor` |\n",
|
||||
"| Export to RDF | `RDFSerializer` |\n",
|
||||
"| Assess extraction quality | `TripleQualityChecker` |\n",
|
||||
"\n",
|
||||
"### Performance Tips\n",
|
||||
"\n",
|
||||
"1. **Extract entities once**, reuse for relations and triples\n",
|
||||
"1. **Extract entities once**, reuse for relations and triplets\n",
|
||||
"2. **Batch process** multiple documents together\n",
|
||||
"3. **Cache extractors** instead of recreating\n",
|
||||
"4. **Filter early** with confidence thresholds\n",
|
||||
"5. **Validate incrementally** rather than all at once"
|
||||
"4. **Filter early** with confidence thresholds"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -638,25 +575,22 @@
|
||||
" **Extract relationships** using `RelationExtractor` \n",
|
||||
" **Compare extraction methods** (pattern, dependency, co-occurrence, HuggingFace, LLM) \n",
|
||||
" **Configure extraction parameters** for optimal results \n",
|
||||
" **Extract RDF triples** with `TripleExtractor` \n",
|
||||
" **Validate triples** using `TripleValidator` \n",
|
||||
" **Extract RDF triplets** with `TripletExtractor` \n",
|
||||
" **Serialize to RDF formats** with `RDFSerializer` \n",
|
||||
" **Assess quality** with `TripleQualityChecker` \n",
|
||||
" **Build complete pipelines** from entities to triples \n",
|
||||
" **Build complete pipelines** from entities to triplets \n",
|
||||
"\n",
|
||||
"### Key Takeaways\n",
|
||||
"\n",
|
||||
"1. **Relations connect entities**: They form the backbone of knowledge graphs\n",
|
||||
"2. **Multiple methods available**: Choose based on accuracy vs speed needs\n",
|
||||
"3. **Configuration is powerful**: Tune parameters for your domain\n",
|
||||
"4. **Triples are standardized**: Use RDF for interoperability\n",
|
||||
"5. **Validation is essential**: Ensure quality before using triples\n",
|
||||
"6. **Pipelines are efficient**: Extract entities → relations → triples in sequence\n",
|
||||
"4. **Triplets are standardized**: Use RDF for interoperability\n",
|
||||
"5. **Pipelines are efficient**: Extract entities \u2192 relations \u2192 triplets in sequence\n",
|
||||
"\n",
|
||||
"### Next Steps\n",
|
||||
"\n",
|
||||
" **Next Notebook**: [07_Building_Knowledge_Graphs.ipynb](./07_Building_Knowledge_Graphs.ipynb) \n",
|
||||
"Learn how to build complete knowledge graphs from your extracted triples!\n",
|
||||
"Learn how to build complete knowledge graphs from your extracted triplets!\n",
|
||||
"\n",
|
||||
" **Further Reading**:\n",
|
||||
"- [Semantic Extract API Reference](https://semantica.readthedocs.io/reference/semantic_extract/)\n",
|
||||
@@ -690,4 +624,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook demonstrates how to build knowledge graphs from entities and relationships using Semantica's graph building modules. You'll learn to use `GraphBuilder`, `EntityResolver`, and `GraphValidator`.\n",
|
||||
"This notebook demonstrates how to build knowledge graphs from entities and relationships using Semantica's graph building modules. You'll learn to use `GraphBuilder` and `EntityResolver`.\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/kg/)\n",
|
||||
"\n",
|
||||
@@ -18,7 +18,6 @@
|
||||
"\n",
|
||||
"- Use `GraphBuilder` to construct knowledge graphs\n",
|
||||
"- Use `EntityResolver` to resolve entity conflicts\n",
|
||||
"- Use `GraphValidator` to validate graph structure\n",
|
||||
"**Note**: For deduplication, use the `semantica.deduplication` module.\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
@@ -40,7 +39,230 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Requirement already satisfied: semantica in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.0.5)\n",
|
||||
"Requirement already satisfied: numpy>=1.21.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.26.4)\n",
|
||||
"Requirement already satisfied: pandas>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.1.4)\n",
|
||||
"Requirement already satisfied: scikit-learn>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.6.1)\n",
|
||||
"Requirement already satisfied: spacy>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.8.11)\n",
|
||||
"Requirement already satisfied: transformers>=4.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.53.2)\n",
|
||||
"Requirement already satisfied: torch>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.2.1)\n",
|
||||
"Requirement already satisfied: sentence-transformers>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.2.1)\n",
|
||||
"Requirement already satisfied: rdflib>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.0)\n",
|
||||
"Requirement already satisfied: networkx>=2.8.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.5)\n",
|
||||
"Requirement already satisfied: matplotlib>=3.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.10.1)\n",
|
||||
"Requirement already satisfied: seaborn>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.13.2)\n",
|
||||
"Requirement already satisfied: plotly>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.17.0)\n",
|
||||
"Requirement already satisfied: requests>=2.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.32.5)\n",
|
||||
"Requirement already satisfied: beautifulsoup4>=4.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.12.3)\n",
|
||||
"Requirement already satisfied: lxml>=4.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.2)\n",
|
||||
"Requirement already satisfied: pypdf2>=2.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: python-docx>=0.8.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: openpyxl>=3.0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.1.5)\n",
|
||||
"Requirement already satisfied: pillow>=9.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (10.4.0)\n",
|
||||
"Requirement already satisfied: librosa>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.11.0)\n",
|
||||
"Requirement already satisfied: opencv-python>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.9.0.80)\n",
|
||||
"Requirement already satisfied: faiss-cpu>=1.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.9.0)\n",
|
||||
"Requirement already satisfied: weaviate-client>=3.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.18.1)\n",
|
||||
"Requirement already satisfied: qdrant-client>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.12.2)\n",
|
||||
"Requirement already satisfied: neo4j>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.3)\n",
|
||||
"Requirement already satisfied: falkordb>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.2.2)\n",
|
||||
"Requirement already satisfied: pymongo>=4.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.15.4)\n",
|
||||
"Requirement already satisfied: sqlalchemy>=1.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.0.23)\n",
|
||||
"Requirement already satisfied: psycopg2-binary>=2.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.9.9)\n",
|
||||
"Requirement already satisfied: pymysql>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: redis>=4.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.4.0)\n",
|
||||
"Requirement already satisfied: celery>=5.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.3.4)\n",
|
||||
"Requirement already satisfied: kafka-python>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.3.0)\n",
|
||||
"Requirement already satisfied: pulsar-client>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.3.0)\n",
|
||||
"Requirement already satisfied: pika>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: boto3>=1.24.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.36.0)\n",
|
||||
"Requirement already satisfied: azure-storage-blob>=12.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (12.27.1)\n",
|
||||
"Requirement already satisfied: google-cloud-storage>=2.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.18.2)\n",
|
||||
"Requirement already satisfied: pydantic>=1.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.12.3)\n",
|
||||
"Requirement already satisfied: click>=8.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (8.2.1)\n",
|
||||
"Requirement already satisfied: rich>=12.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (13.7.1)\n",
|
||||
"Requirement already satisfied: tqdm>=4.64.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.67.1)\n",
|
||||
"Requirement already satisfied: pyyaml>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: toml>=0.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.10.2)\n",
|
||||
"Requirement already satisfied: python-dotenv>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: loguru>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.7.3)\n",
|
||||
"Requirement already satisfied: structlog>=22.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (24.4.0)\n",
|
||||
"Requirement already satisfied: prometheus-client>=0.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.18.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-api>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-sdk>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-instrumentation in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: fastapi>=0.78.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.120.4)\n",
|
||||
"Requirement already satisfied: uvicorn>=0.18.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.38.0)\n",
|
||||
"Requirement already satisfied: pytest>=7.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.3)\n",
|
||||
"Requirement already satisfied: pytest-cov>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.0.0)\n",
|
||||
"Requirement already satisfied: pytest-asyncio>=0.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.21.1)\n",
|
||||
"Requirement already satisfied: black>=22.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (23.11.0)\n",
|
||||
"Requirement already satisfied: isort>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.12.0)\n",
|
||||
"Requirement already satisfied: flake8>=4.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.3.0)\n",
|
||||
"Requirement already satisfied: mypy>=0.971 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pre-commit>=2.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.4.0)\n",
|
||||
"Requirement already satisfied: azure-core>=1.30.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (1.35.0)\n",
|
||||
"Requirement already satisfied: cryptography>=2.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (43.0.3)\n",
|
||||
"Requirement already satisfied: typing-extensions>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (4.14.1)\n",
|
||||
"Requirement already satisfied: isodate>=0.6.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (0.7.2)\n",
|
||||
"Requirement already satisfied: six>=1.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-core>=1.30.0->azure-storage-blob>=12.12.0->semantica) (1.16.0)\n",
|
||||
"Requirement already satisfied: soupsieve>1.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from beautifulsoup4>=4.11.0->semantica) (2.5)\n",
|
||||
"Requirement already satisfied: mypy-extensions>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (1.0.0)\n",
|
||||
"Requirement already satisfied: packaging>=22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (24.2)\n",
|
||||
"Requirement already satisfied: pathspec>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (0.11.2)\n",
|
||||
"Requirement already satisfied: platformdirs>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (3.11.0)\n",
|
||||
"Requirement already satisfied: botocore<1.37.0,>=1.36.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.36.26)\n",
|
||||
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.0.1)\n",
|
||||
"Requirement already satisfied: s3transfer<0.12.0,>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (0.11.3)\n",
|
||||
"Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (2.9.0.post0)\n",
|
||||
"Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (1.26.20)\n",
|
||||
"Requirement already satisfied: billiard<5.0,>=4.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (4.2.1)\n",
|
||||
"Requirement already satisfied: kombu<6.0,>=5.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.5.3)\n",
|
||||
"Requirement already satisfied: vine<6.0,>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.1.0)\n",
|
||||
"Requirement already satisfied: click-didyoumean>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.1)\n",
|
||||
"Requirement already satisfied: click-repl>=0.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.0)\n",
|
||||
"Requirement already satisfied: click-plugins>=1.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: tzdata>=2022.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (2025.2)\n",
|
||||
"Requirement already satisfied: colorama in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from click>=8.1.0->semantica) (0.4.6)\n",
|
||||
"Requirement already satisfied: amqp<6.0.0,>=5.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from kombu<6.0,>=5.3.2->celery>=5.2.0->semantica) (5.3.1)\n",
|
||||
"Requirement already satisfied: prompt-toolkit>=3.0.36 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from click-repl>=0.2.0->celery>=5.2.0->semantica) (3.0.40)\n",
|
||||
"Requirement already satisfied: cffi>=1.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pycparser in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cffi>=1.12->cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (2.22)\n",
|
||||
"Requirement already satisfied: starlette<0.50.0,>=0.40.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.46.2)\n",
|
||||
"Requirement already satisfied: annotated-doc>=0.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.0.3)\n",
|
||||
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pydantic-core==2.41.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (2.41.4)\n",
|
||||
"Requirement already satisfied: typing-inspection>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.4.2)\n",
|
||||
"Requirement already satisfied: anyio<5,>=3.6.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (4.11.0)\n",
|
||||
"Requirement already satisfied: idna>=2.8 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (3.10)\n",
|
||||
"Requirement already satisfied: sniffio>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (1.3.1)\n",
|
||||
"Requirement already satisfied: mccabe<0.8.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pycodestyle<2.15.0,>=2.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (2.14.0)\n",
|
||||
"Requirement already satisfied: pyflakes<3.5.0,>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: google-auth<3.0dev,>=2.26.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.36.0)\n",
|
||||
"Requirement already satisfied: google-api-core<3.0.0dev,>=2.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.23.0)\n",
|
||||
"Requirement already satisfied: google-cloud-core<3.0dev,>=2.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.4.1)\n",
|
||||
"Requirement already satisfied: google-resumable-media>=2.7.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.7.2)\n",
|
||||
"Requirement already satisfied: google-crc32c<2.0dev,>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.66.0)\n",
|
||||
"Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.19.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (4.25.8)\n",
|
||||
"Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.25.0)\n",
|
||||
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (5.5.2)\n",
|
||||
"Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.4.1)\n",
|
||||
"Requirement already satisfied: rsa<5,>=3.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (4.9)\n",
|
||||
"Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (2025.8.3)\n",
|
||||
"Requirement already satisfied: pyasn1>=0.1.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rsa<5,>=3.1.4->google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.6.1)\n",
|
||||
"Requirement already satisfied: audioread>=2.1.9 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: numba>=0.51.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.61.2)\n",
|
||||
"Requirement already satisfied: scipy>=1.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.15.2)\n",
|
||||
"Requirement already satisfied: joblib>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: decorator>=4.3.0 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from librosa>=0.9.0->semantica) (5.1.1)\n",
|
||||
"Requirement already satisfied: soundfile>=0.12.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.13.1)\n",
|
||||
"Requirement already satisfied: pooch>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.8.2)\n",
|
||||
"Requirement already satisfied: soxr>=0.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.5.0.post1)\n",
|
||||
"Requirement already satisfied: lazy_loader>=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.4)\n",
|
||||
"Requirement already satisfied: msgpack>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: win32-setctime>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from loguru>=0.6.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: cycler>=0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (0.12.1)\n",
|
||||
"Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (4.57.0)\n",
|
||||
"Requirement already satisfied: kiwisolver>=1.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.4.8)\n",
|
||||
"Requirement already satisfied: pyparsing>=2.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: pytz in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from neo4j>=5.0.0->semantica) (2024.2)\n",
|
||||
"Requirement already satisfied: llvmlite<0.45,>=0.44.0dev0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from numba>=0.51.0->librosa>=0.9.0->semantica) (0.44.0)\n",
|
||||
"Requirement already satisfied: et-xmlfile in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from openpyxl>=3.0.10->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-api>=1.12.0->semantica) (6.8.0)\n",
|
||||
"Requirement already satisfied: zipp>=0.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api>=1.12.0->semantica) (3.17.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-semantic-conventions==0.59b0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-sdk>=1.12.0->semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: tenacity>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from plotly>=5.10.0->semantica) (8.5.0)\n",
|
||||
"Requirement already satisfied: cfgv>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (3.5.0)\n",
|
||||
"Requirement already satisfied: identify>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (2.6.15)\n",
|
||||
"Requirement already satisfied: nodeenv>=0.11.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (1.9.1)\n",
|
||||
"Requirement already satisfied: virtualenv>=20.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (20.24.6)\n",
|
||||
"Requirement already satisfied: wcwidth in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from prompt-toolkit>=3.0.36->click-repl>=0.2.0->celery>=5.2.0->semantica) (0.2.9)\n",
|
||||
"Requirement already satisfied: dnspython<3.0.0,>=1.16.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pymongo>=4.2.0->semantica) (2.4.2)\n",
|
||||
"Requirement already satisfied: iniconfig in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: pluggy<2.0,>=0.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (1.5.0)\n",
|
||||
"Requirement already satisfied: coverage>=7.10.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from coverage[toml]>=7.10.6->pytest-cov>=3.0.0->semantica) (7.12.0)\n",
|
||||
"Requirement already satisfied: grpcio>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.68.0)\n",
|
||||
"Requirement already satisfied: grpcio-tools>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.62.3)\n",
|
||||
"Requirement already satisfied: httpx>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.28.1)\n",
|
||||
"Requirement already satisfied: portalocker<3.0.0,>=2.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (2.10.1)\n",
|
||||
"Requirement already satisfied: pywin32>=226 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from portalocker<3.0.0,>=2.7.0->qdrant-client>=1.3.0->semantica) (311)\n",
|
||||
"Requirement already satisfied: setuptools in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from grpcio-tools>=1.41.0->qdrant-client>=1.3.0->semantica) (80.9.0)\n",
|
||||
"Requirement already satisfied: httpcore==1.* in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (1.0.9)\n",
|
||||
"Requirement already satisfied: h11>=0.16 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpcore==1.*->httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.16.0)\n",
|
||||
"Requirement already satisfied: h2<5,>=3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.1.0)\n",
|
||||
"Requirement already satisfied: hyperframe<7,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: hpack<5,>=4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.0.0)\n",
|
||||
"Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (3.0.0)\n",
|
||||
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (2.19.2)\n",
|
||||
"Requirement already satisfied: mdurl~=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from markdown-it-py>=2.2.0->rich>=12.5.0->semantica) (0.1.2)\n",
|
||||
"Requirement already satisfied: threadpoolctl>=3.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from scikit-learn>=1.0.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: huggingface-hub>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sentence-transformers>=2.2.0->semantica) (0.30.2)\n",
|
||||
"Requirement already satisfied: filelock in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (3.16.1)\n",
|
||||
"Requirement already satisfied: regex!=2019.12.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (2024.11.6)\n",
|
||||
"Requirement already satisfied: tokenizers<0.22,>=0.21 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.21.4)\n",
|
||||
"Requirement already satisfied: safetensors>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.5.3)\n",
|
||||
"Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers>=2.2.0->semantica) (2023.10.0)\n",
|
||||
"Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.5)\n",
|
||||
"Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.15)\n",
|
||||
"Requirement already satisfied: cymem<2.1.0,>=2.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.13)\n",
|
||||
"Requirement already satisfied: preshed<3.1.0,>=3.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: thinc<8.4.0,>=8.3.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (8.3.10)\n",
|
||||
"Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.1.3)\n",
|
||||
"Requirement already satisfied: srsly<3.0.0,>=2.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.5.2)\n",
|
||||
"Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.10)\n",
|
||||
"Requirement already satisfied: weasel<0.5.0,>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.4.3)\n",
|
||||
"Requirement already satisfied: typer-slim<1.0.0,>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.20.0)\n",
|
||||
"Requirement already satisfied: jinja2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.1.6)\n",
|
||||
"Requirement already satisfied: blis<1.4.0,>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (1.3.3)\n",
|
||||
"Requirement already satisfied: confection<1.0.0,>=0.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (0.1.5)\n",
|
||||
"Requirement already satisfied: cloudpathlib<1.0.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (0.23.0)\n",
|
||||
"Requirement already satisfied: smart-open<8.0.0,>=5.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (7.1.0)\n",
|
||||
"Requirement already satisfied: wrapt in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from smart-open<8.0.0,>=5.2.1->weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (1.17.2)\n",
|
||||
"Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sqlalchemy>=1.4.0->semantica) (3.2.3)\n",
|
||||
"Requirement already satisfied: sympy in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from torch>=1.12.0->semantica) (1.13.3)\n",
|
||||
"Requirement already satisfied: distlib<1,>=0.3.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from virtualenv>=20.10.0->pre-commit>=2.19.0->semantica) (0.3.7)\n",
|
||||
"Requirement already satisfied: validators<1.0.0,>=0.34.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (0.35.0)\n",
|
||||
"Requirement already satisfied: authlib<2.0.0,>=1.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: deprecation<3.0.0,>=2.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (2.1.0)\n",
|
||||
"Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from jinja2->spacy>=3.4.0->semantica) (2.1.3)\n",
|
||||
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sympy->torch>=1.12.0->semantica) (1.3.0)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -60,8 +282,8 @@
|
||||
"for i, entity in enumerate(entities_list[:5], 1):\n",
|
||||
" entities.append({\n",
|
||||
" \"id\": f\"e{i}\",\n",
|
||||
" \"type\": entity.get(\"type\", \"Entity\"),\n",
|
||||
" \"name\": entity.get(\"text\", entity.get(\"entity\", \"\")),\n",
|
||||
" \"type\": entity.label,\n",
|
||||
" \"name\": entity.text,\n",
|
||||
" \"properties\": {}\n",
|
||||
" })\n",
|
||||
"\n",
|
||||
@@ -70,14 +292,14 @@
|
||||
" relationships.append({\n",
|
||||
" \"source\": f\"e{1}\",\n",
|
||||
" \"target\": f\"e{i+1}\",\n",
|
||||
" \"type\": rel.get(\"type\", \"related_to\"),\n",
|
||||
" \"type\": rel.predicate,\n",
|
||||
" \"properties\": {}\n",
|
||||
" })\n",
|
||||
"\n",
|
||||
"knowledge_graph = builder.build(entities, relationships)\n",
|
||||
"\n",
|
||||
"print(f\"Built knowledge graph with {len(knowledge_graph.get('entities', []))} entities\")\n",
|
||||
"print(f\"Relationships: {len(knowledge_graph.get('relationships', []))}\")\n"
|
||||
"print(f\"Relationships: {len(knowledge_graph.get('relationships', []))}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -91,59 +313,52 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Original entities: 5\n",
|
||||
"Resolved entities: 4\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.kg import EntityResolver\n",
|
||||
"\n",
|
||||
"entity_resolver = EntityResolver()\n",
|
||||
"\n",
|
||||
"resolved_entities = entity_resolver.resolve(entities)\n",
|
||||
"resolved_entities = entity_resolver.resolve_entities(entities)\n",
|
||||
"\n",
|
||||
"print(f\"Original entities: {len(entities)}\")\n",
|
||||
"print(f\"Resolved entities: {len(resolved_entities)}\")\n"
|
||||
"print(f\"Resolved entities: {len(resolved_entities)}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Graph Validation\n",
|
||||
"\n",
|
||||
"Validate the knowledge graph structure.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.kg import GraphValidator\n",
|
||||
"\n",
|
||||
"graph_validator = GraphValidator()\n",
|
||||
"\n",
|
||||
"validation_result = graph_validator.validate(knowledge_graph)\n",
|
||||
"\n",
|
||||
"print(f\"Graph validation: {validation_result.get('valid', False)}\")\n",
|
||||
"print(f\"Issues: {len(validation_result.get('issues', []))}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 4: Deduplication\n",
|
||||
"## Step 3: Deduplication\n",
|
||||
"\n",
|
||||
"Remove duplicate entities from the graph.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Original entities: 4\n",
|
||||
"Deduplicated entities: 0\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.deduplication import DuplicateDetector, EntityMerger, MergeStrategy\n",
|
||||
"\n",
|
||||
@@ -174,7 +389,6 @@
|
||||
"\n",
|
||||
"- **GraphBuilder**: Construct knowledge graphs from entities and relationships\n",
|
||||
"- **EntityResolver**: Resolve entity conflicts and duplicates\n",
|
||||
"- **GraphValidator**: Validate graph structure and quality\n",
|
||||
"- **Deduplication**: Use `semantica.deduplication` module for removing duplicate entities\n",
|
||||
"\n",
|
||||
"Next: Learn how to analyze graphs in the Graph_Analytics notebook.\n"
|
||||
@@ -182,8 +396,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -1,289 +1,627 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/introduction/09_Your_First_Knowledge_Graph.ipynb)\n",
|
||||
"\n",
|
||||
"# 🚀 Your First Knowledge Graph\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook walks you through creating your first knowledge graph from a simple document. You'll learn the complete end-to-end workflow from ingesting a file to visualizing the resulting knowledge graph.\n",
|
||||
"\n",
|
||||
"> [!TIP]\n",
|
||||
"> This is the perfect starting point if you are new to Semantica. No prior knowledge of knowledge graphs is required!\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/kg/)\n",
|
||||
"\n",
|
||||
"### 🎯 Learning Objectives\n",
|
||||
"\n",
|
||||
"- **Understand the Workflow**: Learn the `File → Parse → Extract → Graph` pipeline\n",
|
||||
"- **Ingest Data**: Load documents using `FileIngestor`\n",
|
||||
"- **Parse Content**: Extract text using `DocumentParser`\n",
|
||||
"- **Extract Knowledge**: Identify entities using `NERExtractor`\n",
|
||||
"- **Build Graph**: Construct a graph using `GraphBuilder`\n",
|
||||
"- **Visualize**: See your graph come to life with `KGVisualizer`\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install Semantica from PyPI:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"# Or with all optional dependencies:\n",
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## 🔄 Simple End-to-End Workflow\n",
|
||||
"\n",
|
||||
"The complete workflow consists of four main steps:\n",
|
||||
"\n",
|
||||
"1. **📥 Ingest** - Load data from files or other sources\n",
|
||||
"2. **📄 Parse** - Extract and structure content from documents\n",
|
||||
"3. **⛏️ Extract** - Identify entities and relationships\n",
|
||||
"4. **🕸️ Build Graph** - Construct the knowledge graph\n",
|
||||
"\n",
|
||||
"Each step is demonstrated in the code cells below.\n",
|
||||
"\n",
|
||||
"> [!TIP]\n",
|
||||
"> **Alternative: Using Semantica Framework**\n",
|
||||
"> \n",
|
||||
"> For a simpler, high-level approach, you can use the `Semantica` framework class which orchestrates all these steps:\n",
|
||||
"> \n",
|
||||
"> ```python\n",
|
||||
"> from semantica.core import Semantica\n",
|
||||
"> \n",
|
||||
"> framework = Semantica()\n",
|
||||
"> framework.initialize()\n",
|
||||
"> \n",
|
||||
"> result = framework.build_knowledge_base(\n",
|
||||
"> sources=[\"sample_document.txt\"],\n",
|
||||
"> embeddings=True,\n",
|
||||
"> graph=True\n",
|
||||
"> )\n",
|
||||
"> \n",
|
||||
"> framework.shutdown()\n",
|
||||
"> ```\n",
|
||||
"> \n",
|
||||
"> This notebook shows the step-by-step approach for learning. See [Core Module Usage Guide](../../../semantica/core/core_usage.md) for more details.\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## 📂 Step 1: Ingest a File\n",
|
||||
"\n",
|
||||
"In this step, we'll use `FileIngestor` to load a document. The ingestor supports various file formats including PDF, DOCX, TXT, and more.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.ingest import FileIngestor\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"# Initialize the ingestor\n",
|
||||
"ingestor = FileIngestor()\n",
|
||||
"\n",
|
||||
"# Create a sample document for demonstration\n",
|
||||
"sample_text = \"\"\"\n",
|
||||
"Apple Inc. is a technology company founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976.\n",
|
||||
"The company is headquartered in Cupertino, California.\n",
|
||||
"Tim Cook is the current CEO of Apple Inc.\n",
|
||||
"Apple designs and manufactures consumer electronics, software, and online services.\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"sample_file = Path(\"sample_document.txt\")\n",
|
||||
"sample_file.write_text(sample_text)\n",
|
||||
"\n",
|
||||
"print(f\"File: {sample_file}\")\n",
|
||||
"print(f\"Content length: {len(sample_text)} characters\")\n",
|
||||
"\n",
|
||||
"# Ingest the file\n",
|
||||
"file_object = ingestor.ingest_file(sample_file, read_content=True)\n",
|
||||
"print(f\" File name: {file_object.name}\")\n",
|
||||
"print(f\" File type: {file_object.file_type}\")\n",
|
||||
"print(f\" Content available: {file_object.content is not None}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 📄 Step 2: Parse the Document\n",
|
||||
"\n",
|
||||
"After ingesting the file, we need to parse it to extract the text content. The `DocumentParser` handles various file formats and extracts structured content.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.parse import DocumentParser\n",
|
||||
"\n",
|
||||
"parser = DocumentParser()\n",
|
||||
"\n",
|
||||
"# Parse the document to extract text\n",
|
||||
"parsed_content = parser.parse_document(str(sample_file))\n",
|
||||
"print(f\" Parsed content length: {len(parsed_content) if parsed_content else 0} characters\")\n",
|
||||
"print(f\" Preview: {parsed_content[:200] if parsed_content else 'N/A'}...\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## ⛏️ Step 3: Extract Entities\n",
|
||||
"\n",
|
||||
"Now we'll extract entities from the parsed text using Named Entity Recognition (NER). This identifies people, organizations, locations, dates, and other entities in the text.\n",
|
||||
"\n",
|
||||
"> [!NOTE]\n",
|
||||
"> In a real scenario, you would use `NERExtractor` with an LLM or model backend. Here we simulate the output for demonstration purposes.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import NamedEntityRecognizer, NERExtractor\n",
|
||||
"\n",
|
||||
"ner = NamedEntityRecognizer()\n",
|
||||
"extractor = NERExtractor()\n",
|
||||
"\n",
|
||||
"print(f\"\\nText: {parsed_content[:100]}...\")\n",
|
||||
"\n",
|
||||
"# Simulated extraction results\n",
|
||||
"expected_entities = [\n",
|
||||
" {\"text\": \"Apple Inc.\", \"type\": \"Organization\", \"start\": 0, \"end\": 10},\n",
|
||||
" {\"text\": \"Steve Jobs\", \"type\": \"Person\", \"start\": 50, \"end\": 60},\n",
|
||||
" {\"text\": \"Steve Wozniak\", \"type\": \"Person\", \"start\": 62, \"end\": 75},\n",
|
||||
" {\"text\": \"Ronald Wayne\", \"type\": \"Person\", \"start\": 81, \"end\": 93},\n",
|
||||
" {\"text\": \"1976\", \"type\": \"Date\", \"start\": 97, \"end\": 101},\n",
|
||||
" {\"text\": \"Cupertino, California\", \"type\": \"Location\", \"start\": 130, \"end\": 151},\n",
|
||||
" {\"text\": \"Tim Cook\", \"type\": \"Person\", \"start\": 153, \"end\": 161},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"for entity in expected_entities:\n",
|
||||
" print(f\" - {entity['text']} ({entity['type']})\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 🕸️ Step 4: Build the Knowledge Graph\n",
|
||||
"\n",
|
||||
"Using the extracted entities and relationships, we'll construct a knowledge graph. The graph represents entities as nodes and relationships as edges.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.kg import GraphBuilder\n",
|
||||
"import networkx as nx\n",
|
||||
"\n",
|
||||
"builder = GraphBuilder()\n",
|
||||
"\n",
|
||||
"# Prepare data for graph construction\n",
|
||||
"entities_data = [\n",
|
||||
" {\"id\": f\"entity_{i}\", \"name\": entity[\"text\"], \"type\": entity[\"type\"]}\n",
|
||||
" for i, entity in enumerate(expected_entities)\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"relationships_data = [\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_1\", \"type\": \"founded_by\"},\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_2\", \"type\": \"founded_by\"},\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_3\", \"type\": \"founded_by\"},\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_4\", \"type\": \"founded_in\"},\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_5\", \"type\": \"located_in\"},\n",
|
||||
" {\"source\": \"entity_6\", \"target\": \"entity_0\", \"type\": \"ceo_of\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Build the graph using NetworkX\n",
|
||||
"kg = nx.DiGraph()\n",
|
||||
"\n",
|
||||
"for entity in entities_data:\n",
|
||||
" kg.add_node(entity[\"id\"], name=entity[\"name\"], type=entity[\"type\"])\n",
|
||||
"\n",
|
||||
"for rel in relationships_data:\n",
|
||||
" source_name = entities_data[int(rel[\"source\"].split(\"_\")[1])][\"name\"]\n",
|
||||
" target_name = entities_data[int(rel[\"target\"].split(\"_\")[1])][\"name\"]\n",
|
||||
" kg.add_edge(rel[\"source\"], rel[\"target\"], type=rel[\"type\"])\n",
|
||||
"\n",
|
||||
"print(f\" Nodes (entities): {len(kg.nodes)}\")\n",
|
||||
"print(f\" Edges (relationships): {len(kg.edges)}\")\n",
|
||||
"\n",
|
||||
"for node_id in kg.nodes():\n",
|
||||
" node_data = kg.nodes[node_id]\n",
|
||||
" print(f\" Node: {node_data['name']} ({node_data['type']})\")\n",
|
||||
"\n",
|
||||
"for source, target, data in kg.edges(data=True):\n",
|
||||
" source_name = kg.nodes[source]['name']\n",
|
||||
" target_name = kg.nodes[target]['name']\n",
|
||||
" print(f\" {source_name} --[{data['type']}]--> {target_name}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 📊 Step 5: Visualize and Analyze\n",
|
||||
"\n",
|
||||
"Finally, we'll visualize the knowledge graph and analyze its structure. This helps you understand the relationships and entities in your data.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.visualization import KGVisualizer\n",
|
||||
"\n",
|
||||
"visualizer = KGVisualizer()\n",
|
||||
"\n",
|
||||
"print(f\" Total entities: {len(kg.nodes)}\")\n",
|
||||
"print(f\" Total relationships: {len(kg.edges)}\")\n",
|
||||
"\n",
|
||||
"entity_types = {}\n",
|
||||
"for node_id in kg.nodes():\n",
|
||||
" entity_type = kg.nodes[node_id]['type']\n",
|
||||
" entity_types[entity_type] = entity_types.get(entity_type, 0) + 1\n",
|
||||
"\n",
|
||||
"for etype, count in entity_types.items():\n",
|
||||
" print(f\" - {etype}: {count}\")\n",
|
||||
"\n",
|
||||
"rel_types = {}\n",
|
||||
"for _, _, data in kg.edges(data=True):\n",
|
||||
" rel_type = data.get('type', 'unknown')\n",
|
||||
" rel_types[rel_type] = rel_types.get(rel_type, 0) + 1\n",
|
||||
"\n",
|
||||
"for rtype, count in rel_types.items():\n",
|
||||
" print(f\" - {rtype}: {count}\")\n",
|
||||
"\n",
|
||||
"# Cleanup\n",
|
||||
"if sample_file.exists():\n",
|
||||
" sample_file.unlink()\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/introduction/09_Your_First_Knowledge_Graph.ipynb)\n",
|
||||
"\n",
|
||||
"# 🚀 Your First Knowledge Graph\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook walks you through creating your first knowledge graph from a simple document. You'll learn the complete end-to-end workflow from ingesting a file to visualizing the resulting knowledge graph.\n",
|
||||
"\n",
|
||||
"> [!TIP]\n",
|
||||
"> This is the perfect starting point if you are new to Semantica. No prior knowledge of knowledge graphs is required!\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/kg/)\n",
|
||||
"\n",
|
||||
"### 🎯 Learning Objectives\n",
|
||||
"\n",
|
||||
"- **Understand the Workflow**: Learn the `File → Parse → Extract → Graph` pipeline\n",
|
||||
"- **Ingest Data**: Load documents using `FileIngestor`\n",
|
||||
"- **Parse Content**: Extract text using `DocumentParser`\n",
|
||||
"- **Extract Knowledge**: Identify entities using `NERExtractor`\n",
|
||||
"- **Build Graph**: Construct a graph using `GraphBuilder`\n",
|
||||
"- **Visualize**: See your graph come to life with `KGVisualizer`\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install Semantica from PyPI:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"# Or with all optional dependencies:\n",
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## 🔄 Simple End-to-End Workflow\n",
|
||||
"\n",
|
||||
"The complete workflow consists of four main steps:\n",
|
||||
"\n",
|
||||
"1. **📥 Ingest** - Load data from files or other sources\n",
|
||||
"2. **📄 Parse** - Extract and structure content from documents\n",
|
||||
"3. **⛏️ Extract** - Identify entities and relationships\n",
|
||||
"4. **🕸️ Build Graph** - Construct the knowledge graph\n",
|
||||
"\n",
|
||||
"Each step is demonstrated in the code cells below.\n",
|
||||
"\n",
|
||||
"> [!TIP]\n",
|
||||
"> **Alternative: Using Semantica Framework**\n",
|
||||
"> \n",
|
||||
"> For a simpler, high-level approach, you can use the `Semantica` framework class which orchestrates all these steps:\n",
|
||||
"> \n",
|
||||
"> ```python\n",
|
||||
"> from semantica.core import Semantica\n",
|
||||
"> \n",
|
||||
"> framework = Semantica()\n",
|
||||
"> framework.initialize()\n",
|
||||
"> \n",
|
||||
"> result = framework.build_knowledge_base(\n",
|
||||
"> sources=[\"sample_document.txt\"],\n",
|
||||
"> embeddings=True,\n",
|
||||
"> graph=True\n",
|
||||
"> )\n",
|
||||
"> \n",
|
||||
"> framework.shutdown()\n",
|
||||
"> ```\n",
|
||||
"> \n",
|
||||
"> This notebook shows the step-by-step approach for learning. See [Core Module Usage Guide](../../../semantica/core/core_usage.md) for more details.\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## 📂 Step 1: Ingest a File\n",
|
||||
"\n",
|
||||
"In this step, we'll use `FileIngestor` to load a document. The ingestor supports various file formats including PDF, DOCX, TXT, and more.\n"
|
||||
]
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Requirement already satisfied: semantica in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.0.5)\n",
|
||||
"Requirement already satisfied: numpy>=1.21.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.26.4)\n",
|
||||
"Requirement already satisfied: pandas>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.1.4)\n",
|
||||
"Requirement already satisfied: scikit-learn>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.6.1)\n",
|
||||
"Requirement already satisfied: spacy>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.8.11)\n",
|
||||
"Requirement already satisfied: transformers>=4.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.53.2)\n",
|
||||
"Requirement already satisfied: torch>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.2.1)\n",
|
||||
"Requirement already satisfied: sentence-transformers>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.2.1)\n",
|
||||
"Requirement already satisfied: rdflib>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.0)\n",
|
||||
"Requirement already satisfied: networkx>=2.8.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.5)\n",
|
||||
"Requirement already satisfied: matplotlib>=3.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.10.1)\n",
|
||||
"Requirement already satisfied: seaborn>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.13.2)\n",
|
||||
"Requirement already satisfied: plotly>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.17.0)\n",
|
||||
"Requirement already satisfied: requests>=2.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.32.5)\n",
|
||||
"Requirement already satisfied: beautifulsoup4>=4.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.12.3)\n",
|
||||
"Requirement already satisfied: lxml>=4.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.2)\n",
|
||||
"Requirement already satisfied: pypdf2>=2.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: python-docx>=0.8.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: openpyxl>=3.0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.1.5)\n",
|
||||
"Requirement already satisfied: pillow>=9.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (10.4.0)\n",
|
||||
"Requirement already satisfied: librosa>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.11.0)\n",
|
||||
"Requirement already satisfied: opencv-python>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.9.0.80)\n",
|
||||
"Requirement already satisfied: faiss-cpu>=1.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.9.0)\n",
|
||||
"Requirement already satisfied: weaviate-client>=3.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.18.1)\n",
|
||||
"Requirement already satisfied: qdrant-client>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.12.2)\n",
|
||||
"Requirement already satisfied: neo4j>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.3)\n",
|
||||
"Requirement already satisfied: falkordb>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.2.2)\n",
|
||||
"Requirement already satisfied: pymongo>=4.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.15.4)\n",
|
||||
"Requirement already satisfied: sqlalchemy>=1.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.0.23)\n",
|
||||
"Requirement already satisfied: psycopg2-binary>=2.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.9.9)\n",
|
||||
"Requirement already satisfied: pymysql>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: redis>=4.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.4.0)\n",
|
||||
"Requirement already satisfied: celery>=5.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.3.4)\n",
|
||||
"Requirement already satisfied: kafka-python>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.3.0)\n",
|
||||
"Requirement already satisfied: pulsar-client>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.3.0)\n",
|
||||
"Requirement already satisfied: pika>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: boto3>=1.24.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.36.0)\n",
|
||||
"Requirement already satisfied: azure-storage-blob>=12.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (12.27.1)\n",
|
||||
"Requirement already satisfied: google-cloud-storage>=2.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.18.2)\n",
|
||||
"Requirement already satisfied: pydantic>=1.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.12.3)\n",
|
||||
"Requirement already satisfied: click>=8.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (8.2.1)\n",
|
||||
"Requirement already satisfied: rich>=12.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (13.7.1)\n",
|
||||
"Requirement already satisfied: tqdm>=4.64.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.67.1)\n",
|
||||
"Requirement already satisfied: pyyaml>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: toml>=0.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.10.2)\n",
|
||||
"Requirement already satisfied: python-dotenv>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: loguru>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.7.3)\n",
|
||||
"Requirement already satisfied: structlog>=22.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (24.4.0)\n",
|
||||
"Requirement already satisfied: prometheus-client>=0.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.18.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-api>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-sdk>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-instrumentation in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: fastapi>=0.78.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.120.4)\n",
|
||||
"Requirement already satisfied: uvicorn>=0.18.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.38.0)\n",
|
||||
"Requirement already satisfied: pytest>=7.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.3)\n",
|
||||
"Requirement already satisfied: pytest-cov>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.0.0)\n",
|
||||
"Requirement already satisfied: pytest-asyncio>=0.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.21.1)\n",
|
||||
"Requirement already satisfied: black>=22.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (23.11.0)\n",
|
||||
"Requirement already satisfied: isort>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.12.0)\n",
|
||||
"Requirement already satisfied: flake8>=4.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.3.0)\n",
|
||||
"Requirement already satisfied: mypy>=0.971 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pre-commit>=2.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.4.0)\n",
|
||||
"Requirement already satisfied: azure-core>=1.30.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (1.35.0)\n",
|
||||
"Requirement already satisfied: cryptography>=2.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (43.0.3)\n",
|
||||
"Requirement already satisfied: typing-extensions>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (4.14.1)\n",
|
||||
"Requirement already satisfied: isodate>=0.6.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (0.7.2)\n",
|
||||
"Requirement already satisfied: six>=1.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-core>=1.30.0->azure-storage-blob>=12.12.0->semantica) (1.16.0)\n",
|
||||
"Requirement already satisfied: soupsieve>1.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from beautifulsoup4>=4.11.0->semantica) (2.5)\n",
|
||||
"Requirement already satisfied: mypy-extensions>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (1.0.0)\n",
|
||||
"Requirement already satisfied: packaging>=22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (24.2)\n",
|
||||
"Requirement already satisfied: pathspec>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (0.11.2)\n",
|
||||
"Requirement already satisfied: platformdirs>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (3.11.0)\n",
|
||||
"Requirement already satisfied: botocore<1.37.0,>=1.36.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.36.26)\n",
|
||||
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.0.1)\n",
|
||||
"Requirement already satisfied: s3transfer<0.12.0,>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (0.11.3)\n",
|
||||
"Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (2.9.0.post0)\n",
|
||||
"Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (1.26.20)\n",
|
||||
"Requirement already satisfied: billiard<5.0,>=4.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (4.2.1)\n",
|
||||
"Requirement already satisfied: kombu<6.0,>=5.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.5.3)\n",
|
||||
"Requirement already satisfied: vine<6.0,>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.1.0)\n",
|
||||
"Requirement already satisfied: click-didyoumean>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.1)\n",
|
||||
"Requirement already satisfied: click-repl>=0.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.0)\n",
|
||||
"Requirement already satisfied: click-plugins>=1.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: tzdata>=2022.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (2025.2)\n",
|
||||
"Requirement already satisfied: colorama in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from click>=8.1.0->semantica) (0.4.6)\n",
|
||||
"Requirement already satisfied: amqp<6.0.0,>=5.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from kombu<6.0,>=5.3.2->celery>=5.2.0->semantica) (5.3.1)\n",
|
||||
"Requirement already satisfied: prompt-toolkit>=3.0.36 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from click-repl>=0.2.0->celery>=5.2.0->semantica) (3.0.40)\n",
|
||||
"Requirement already satisfied: cffi>=1.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pycparser in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cffi>=1.12->cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (2.22)\n",
|
||||
"Requirement already satisfied: starlette<0.50.0,>=0.40.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.46.2)\n",
|
||||
"Requirement already satisfied: annotated-doc>=0.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.0.3)\n",
|
||||
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pydantic-core==2.41.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (2.41.4)\n",
|
||||
"Requirement already satisfied: typing-inspection>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.4.2)\n",
|
||||
"Requirement already satisfied: anyio<5,>=3.6.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (4.11.0)\n",
|
||||
"Requirement already satisfied: idna>=2.8 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (3.10)\n",
|
||||
"Requirement already satisfied: sniffio>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (1.3.1)\n",
|
||||
"Requirement already satisfied: mccabe<0.8.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pycodestyle<2.15.0,>=2.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (2.14.0)\n",
|
||||
"Requirement already satisfied: pyflakes<3.5.0,>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: google-auth<3.0dev,>=2.26.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.36.0)\n",
|
||||
"Requirement already satisfied: google-api-core<3.0.0dev,>=2.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.23.0)\n",
|
||||
"Requirement already satisfied: google-cloud-core<3.0dev,>=2.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.4.1)\n",
|
||||
"Requirement already satisfied: google-resumable-media>=2.7.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.7.2)\n",
|
||||
"Requirement already satisfied: google-crc32c<2.0dev,>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.66.0)\n",
|
||||
"Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.19.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (4.25.8)\n",
|
||||
"Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.25.0)\n",
|
||||
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (5.5.2)\n",
|
||||
"Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.4.1)\n",
|
||||
"Requirement already satisfied: rsa<5,>=3.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (4.9)\n",
|
||||
"Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (2025.8.3)\n",
|
||||
"Requirement already satisfied: pyasn1>=0.1.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rsa<5,>=3.1.4->google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.6.1)\n",
|
||||
"Requirement already satisfied: audioread>=2.1.9 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: numba>=0.51.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.61.2)\n",
|
||||
"Requirement already satisfied: scipy>=1.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.15.2)\n",
|
||||
"Requirement already satisfied: joblib>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: decorator>=4.3.0 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from librosa>=0.9.0->semantica) (5.1.1)\n",
|
||||
"Requirement already satisfied: soundfile>=0.12.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.13.1)\n",
|
||||
"Requirement already satisfied: pooch>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.8.2)\n",
|
||||
"Requirement already satisfied: soxr>=0.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.5.0.post1)\n",
|
||||
"Requirement already satisfied: lazy_loader>=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.4)\n",
|
||||
"Requirement already satisfied: msgpack>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: win32-setctime>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from loguru>=0.6.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: cycler>=0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (0.12.1)\n",
|
||||
"Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (4.57.0)\n",
|
||||
"Requirement already satisfied: kiwisolver>=1.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.4.8)\n",
|
||||
"Requirement already satisfied: pyparsing>=2.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: pytz in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from neo4j>=5.0.0->semantica) (2024.2)\n",
|
||||
"Requirement already satisfied: llvmlite<0.45,>=0.44.0dev0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from numba>=0.51.0->librosa>=0.9.0->semantica) (0.44.0)\n",
|
||||
"Requirement already satisfied: et-xmlfile in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from openpyxl>=3.0.10->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-api>=1.12.0->semantica) (6.8.0)\n",
|
||||
"Requirement already satisfied: zipp>=0.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api>=1.12.0->semantica) (3.17.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-semantic-conventions==0.59b0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-sdk>=1.12.0->semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: tenacity>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from plotly>=5.10.0->semantica) (8.5.0)\n",
|
||||
"Requirement already satisfied: cfgv>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (3.5.0)\n",
|
||||
"Requirement already satisfied: identify>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (2.6.15)\n",
|
||||
"Requirement already satisfied: nodeenv>=0.11.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (1.9.1)\n",
|
||||
"Requirement already satisfied: virtualenv>=20.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (20.24.6)\n",
|
||||
"Requirement already satisfied: wcwidth in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from prompt-toolkit>=3.0.36->click-repl>=0.2.0->celery>=5.2.0->semantica) (0.2.9)\n",
|
||||
"Requirement already satisfied: dnspython<3.0.0,>=1.16.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pymongo>=4.2.0->semantica) (2.4.2)\n",
|
||||
"Requirement already satisfied: iniconfig in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: pluggy<2.0,>=0.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (1.5.0)\n",
|
||||
"Requirement already satisfied: coverage>=7.10.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from coverage[toml]>=7.10.6->pytest-cov>=3.0.0->semantica) (7.12.0)\n",
|
||||
"Requirement already satisfied: grpcio>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.68.0)\n",
|
||||
"Requirement already satisfied: grpcio-tools>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.62.3)\n",
|
||||
"Requirement already satisfied: httpx>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.28.1)\n",
|
||||
"Requirement already satisfied: portalocker<3.0.0,>=2.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (2.10.1)\n",
|
||||
"Requirement already satisfied: pywin32>=226 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from portalocker<3.0.0,>=2.7.0->qdrant-client>=1.3.0->semantica) (311)\n",
|
||||
"Requirement already satisfied: setuptools in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from grpcio-tools>=1.41.0->qdrant-client>=1.3.0->semantica) (80.9.0)\n",
|
||||
"Requirement already satisfied: httpcore==1.* in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (1.0.9)\n",
|
||||
"Requirement already satisfied: h11>=0.16 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpcore==1.*->httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.16.0)\n",
|
||||
"Requirement already satisfied: h2<5,>=3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.1.0)\n",
|
||||
"Requirement already satisfied: hyperframe<7,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: hpack<5,>=4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.0.0)\n",
|
||||
"Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (3.0.0)\n",
|
||||
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (2.19.2)\n",
|
||||
"Requirement already satisfied: mdurl~=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from markdown-it-py>=2.2.0->rich>=12.5.0->semantica) (0.1.2)\n",
|
||||
"Requirement already satisfied: threadpoolctl>=3.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from scikit-learn>=1.0.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: huggingface-hub>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sentence-transformers>=2.2.0->semantica) (0.30.2)\n",
|
||||
"Requirement already satisfied: filelock in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (3.16.1)\n",
|
||||
"Requirement already satisfied: regex!=2019.12.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (2024.11.6)\n",
|
||||
"Requirement already satisfied: tokenizers<0.22,>=0.21 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.21.4)\n",
|
||||
"Requirement already satisfied: safetensors>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.5.3)\n",
|
||||
"Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers>=2.2.0->semantica) (2023.10.0)\n",
|
||||
"Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.5)\n",
|
||||
"Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.15)\n",
|
||||
"Requirement already satisfied: cymem<2.1.0,>=2.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.13)\n",
|
||||
"Requirement already satisfied: preshed<3.1.0,>=3.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: thinc<8.4.0,>=8.3.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (8.3.10)\n",
|
||||
"Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.1.3)\n",
|
||||
"Requirement already satisfied: srsly<3.0.0,>=2.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.5.2)\n",
|
||||
"Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.10)\n",
|
||||
"Requirement already satisfied: weasel<0.5.0,>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.4.3)\n",
|
||||
"Requirement already satisfied: typer-slim<1.0.0,>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.20.0)\n",
|
||||
"Requirement already satisfied: jinja2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.1.6)\n",
|
||||
"Requirement already satisfied: blis<1.4.0,>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (1.3.3)\n",
|
||||
"Requirement already satisfied: confection<1.0.0,>=0.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (0.1.5)\n",
|
||||
"Requirement already satisfied: cloudpathlib<1.0.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (0.23.0)\n",
|
||||
"Requirement already satisfied: smart-open<8.0.0,>=5.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (7.1.0)\n",
|
||||
"Requirement already satisfied: wrapt in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from smart-open<8.0.0,>=5.2.1->weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (1.17.2)\n",
|
||||
"Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sqlalchemy>=1.4.0->semantica) (3.2.3)\n",
|
||||
"Requirement already satisfied: sympy in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from torch>=1.12.0->semantica) (1.13.3)\n",
|
||||
"Requirement already satisfied: distlib<1,>=0.3.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from virtualenv>=20.10.0->pre-commit>=2.19.0->semantica) (0.3.7)\n",
|
||||
"Requirement already satisfied: validators<1.0.0,>=0.34.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (0.35.0)\n",
|
||||
"Requirement already satisfied: authlib<2.0.0,>=1.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: deprecation<3.0.0,>=2.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (2.1.0)\n",
|
||||
"Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from jinja2->spacy>=3.4.0->semantica) (2.1.3)\n",
|
||||
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sympy->torch>=1.12.0->semantica) (1.3.0)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install semantica"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"File: sample_document.txt\n",
|
||||
"Content length: 281 characters\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is ingesting</td><td>📥 ingest</td><td>FileIngestor</td><td>sample_document.txt</td><td>0.02s</td></tr><tr><td>✅</td><td>Semantica is parsing</td><td>🔍 parse</td><td>DocumentParser</td><td>sample_document.txt</td><td>0.02s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" File name: sample_document.txt\n",
|
||||
" File type: txt\n",
|
||||
" Content available: True\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.ingest import FileIngestor\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"# Initialize the ingestor\n",
|
||||
"ingestor = FileIngestor()\n",
|
||||
"\n",
|
||||
"# Create a sample document for demonstration\n",
|
||||
"sample_text = \"\"\"\n",
|
||||
"Apple Inc. is a technology company founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976.\n",
|
||||
"The company is headquartered in Cupertino, California.\n",
|
||||
"Tim Cook is the current CEO of Apple Inc.\n",
|
||||
"Apple designs and manufactures consumer electronics, software, and online services.\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"sample_file = Path(\"sample_document.txt\")\n",
|
||||
"sample_file.write_text(sample_text)\n",
|
||||
"\n",
|
||||
"print(f\"File: {sample_file}\")\n",
|
||||
"print(f\"Content length: {len(sample_text)} characters\")\n",
|
||||
"\n",
|
||||
"# Ingest the file\n",
|
||||
"file_object = ingestor.ingest_file(sample_file, read_content=True)\n",
|
||||
"print(f\" File name: {file_object.name}\")\n",
|
||||
"print(f\" File type: {file_object.file_type}\")\n",
|
||||
"print(f\" Content available: {file_object.content is not None}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 📄 Step 2: Parse the Document\n",
|
||||
"\n",
|
||||
"After ingesting the file, we need to parse it to extract the text content. The `DocumentParser` handles various file formats and extracts structured content.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Parsed content length: 0 characters\n",
|
||||
" Preview: N/A...\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.parse import DocumentParser\n",
|
||||
"\n",
|
||||
"parser = DocumentParser()\n",
|
||||
"# Parse the document to extract text\n",
|
||||
"parsed_document = parser.parse_document(str(sample_file))\n",
|
||||
"parsed_content = parsed_document.get(\"content\", \"\")\n",
|
||||
"print(f\" Parsed content length: {len(parsed_content) if parsed_content else 0} characters\")\n",
|
||||
"print(f\" Preview: {parsed_content[:200] if parsed_content else 'N/A'}...\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## ⛏️ Step 3: Extract Entities\n",
|
||||
"\n",
|
||||
"Now we'll extract entities from the parsed text using Named Entity Recognition (NER). This identifies people, organizations, locations, dates, and other entities in the text.\n",
|
||||
"\n",
|
||||
"> [!NOTE]\n",
|
||||
"> In a real scenario, you would use `NERExtractor` with an LLM or model backend. Here we simulate the output for demonstration purposes.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n",
|
||||
"Text: ...\n",
|
||||
" - Apple Inc. (Organization)\n",
|
||||
" - Steve Jobs (Person)\n",
|
||||
" - Steve Wozniak (Person)\n",
|
||||
" - Ronald Wayne (Person)\n",
|
||||
" - 1976 (Date)\n",
|
||||
" - Cupertino, California (Location)\n",
|
||||
" - Tim Cook (Person)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import NamedEntityRecognizer, NERExtractor\n",
|
||||
"\n",
|
||||
"ner = NamedEntityRecognizer()\n",
|
||||
"extractor = NERExtractor()\n",
|
||||
"\n",
|
||||
"print(f\"\\nText: {parsed_content[:100]}...\")\n",
|
||||
"\n",
|
||||
"# Simulated extraction results\n",
|
||||
"expected_entities = [\n",
|
||||
" {\"text\": \"Apple Inc.\", \"type\": \"Organization\", \"start\": 0, \"end\": 10},\n",
|
||||
" {\"text\": \"Steve Jobs\", \"type\": \"Person\", \"start\": 50, \"end\": 60},\n",
|
||||
" {\"text\": \"Steve Wozniak\", \"type\": \"Person\", \"start\": 62, \"end\": 75},\n",
|
||||
" {\"text\": \"Ronald Wayne\", \"type\": \"Person\", \"start\": 81, \"end\": 93},\n",
|
||||
" {\"text\": \"1976\", \"type\": \"Date\", \"start\": 97, \"end\": 101},\n",
|
||||
" {\"text\": \"Cupertino, California\", \"type\": \"Location\", \"start\": 130, \"end\": 151},\n",
|
||||
" {\"text\": \"Tim Cook\", \"type\": \"Person\", \"start\": 153, \"end\": 161},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"for entity in expected_entities:\n",
|
||||
" print(f\" - {entity['text']} ({entity['type']})\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 🕸️ Step 4: Build the Knowledge Graph\n",
|
||||
"\n",
|
||||
"Using the extracted entities and relationships, we'll construct a knowledge graph. The graph represents entities as nodes and relationships as edges.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Nodes (entities): 7\n",
|
||||
" Edges (relationships): 6\n",
|
||||
" Node: Apple Inc. (Organization)\n",
|
||||
" Node: Steve Jobs (Person)\n",
|
||||
" Node: Steve Wozniak (Person)\n",
|
||||
" Node: Ronald Wayne (Person)\n",
|
||||
" Node: 1976 (Date)\n",
|
||||
" Node: Cupertino, California (Location)\n",
|
||||
" Node: Tim Cook (Person)\n",
|
||||
" Apple Inc. --[founded_by]--> Steve Jobs\n",
|
||||
" Apple Inc. --[founded_by]--> Steve Wozniak\n",
|
||||
" Apple Inc. --[founded_by]--> Ronald Wayne\n",
|
||||
" Apple Inc. --[founded_in]--> 1976\n",
|
||||
" Apple Inc. --[located_in]--> Cupertino, California\n",
|
||||
" Tim Cook --[ceo_of]--> Apple Inc.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.kg import GraphBuilder\n",
|
||||
"import networkx as nx\n",
|
||||
"\n",
|
||||
"builder = GraphBuilder()\n",
|
||||
"\n",
|
||||
"# Prepare data for graph construction\n",
|
||||
"entities_data = [\n",
|
||||
" {\"id\": f\"entity_{i}\", \"name\": entity[\"text\"], \"type\": entity[\"type\"]}\n",
|
||||
" for i, entity in enumerate(expected_entities)\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"relationships_data = [\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_1\", \"type\": \"founded_by\"},\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_2\", \"type\": \"founded_by\"},\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_3\", \"type\": \"founded_by\"},\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_4\", \"type\": \"founded_in\"},\n",
|
||||
" {\"source\": \"entity_0\", \"target\": \"entity_5\", \"type\": \"located_in\"},\n",
|
||||
" {\"source\": \"entity_6\", \"target\": \"entity_0\", \"type\": \"ceo_of\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Build the graph using NetworkX\n",
|
||||
"kg = nx.DiGraph()\n",
|
||||
"\n",
|
||||
"for entity in entities_data:\n",
|
||||
" kg.add_node(entity[\"id\"], name=entity[\"name\"], type=entity[\"type\"])\n",
|
||||
"\n",
|
||||
"for rel in relationships_data:\n",
|
||||
" source_name = entities_data[int(rel[\"source\"].split(\"_\")[1])][\"name\"]\n",
|
||||
" target_name = entities_data[int(rel[\"target\"].split(\"_\")[1])][\"name\"]\n",
|
||||
" kg.add_edge(rel[\"source\"], rel[\"target\"], type=rel[\"type\"])\n",
|
||||
"\n",
|
||||
"print(f\" Nodes (entities): {len(kg.nodes)}\")\n",
|
||||
"print(f\" Edges (relationships): {len(kg.edges)}\")\n",
|
||||
"\n",
|
||||
"for node_id in kg.nodes():\n",
|
||||
" node_data = kg.nodes[node_id]\n",
|
||||
" print(f\" Node: {node_data['name']} ({node_data['type']})\")\n",
|
||||
"\n",
|
||||
"for source, target, data in kg.edges(data=True):\n",
|
||||
" source_name = kg.nodes[source]['name']\n",
|
||||
" target_name = kg.nodes[target]['name']\n",
|
||||
" print(f\" {source_name} --[{data['type']}]--> {target_name}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 📊 Step 5: Visualize and Analyze\n",
|
||||
"\n",
|
||||
"Finally, we'll visualize the knowledge graph and analyze its structure. This helps you understand the relationships and entities in your data.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Total entities: 7\n",
|
||||
" Total relationships: 6\n",
|
||||
" - Organization: 1\n",
|
||||
" - Person: 4\n",
|
||||
" - Date: 1\n",
|
||||
" - Location: 1\n",
|
||||
" - founded_by: 3\n",
|
||||
" - founded_in: 1\n",
|
||||
" - located_in: 1\n",
|
||||
" - ceo_of: 1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.visualization import KGVisualizer\n",
|
||||
"\n",
|
||||
"visualizer = KGVisualizer()\n",
|
||||
"\n",
|
||||
"print(f\" Total entities: {len(kg.nodes)}\")\n",
|
||||
"print(f\" Total relationships: {len(kg.edges)}\")\n",
|
||||
"\n",
|
||||
"entity_types = {}\n",
|
||||
"for node_id in kg.nodes():\n",
|
||||
" entity_type = kg.nodes[node_id]['type']\n",
|
||||
" entity_types[entity_type] = entity_types.get(entity_type, 0) + 1\n",
|
||||
"\n",
|
||||
"for etype, count in entity_types.items():\n",
|
||||
" print(f\" - {etype}: {count}\")\n",
|
||||
"\n",
|
||||
"rel_types = {}\n",
|
||||
"for _, _, data in kg.edges(data=True):\n",
|
||||
" rel_type = data.get('type', 'unknown')\n",
|
||||
" rel_types[rel_type] = rel_types.get(rel_type, 0) + 1\n",
|
||||
"\n",
|
||||
"for rtype, count in rel_types.items():\n",
|
||||
" print(f\" - {rtype}: {count}\")\n",
|
||||
"\n",
|
||||
"# Cleanup\n",
|
||||
"if sample_file.exists():\n",
|
||||
" sample_file.unlink()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
"# For Neo4j (requires Neo4j server)\n",
|
||||
"pip install neo4j\n",
|
||||
"\n",
|
||||
|
||||
"# For FalkorDB (requires Redis/FalkorDB server)\n",
|
||||
"pip install falkordb\n",
|
||||
"```\n",
|
||||
@@ -81,6 +80,229 @@
|
||||
"**Recommendation**: Use **Neo4j** for enterprise production systems or **FalkorDB** for high-performance real-time applications.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Requirement already satisfied: semantica in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.0.5)\n",
|
||||
"Requirement already satisfied: numpy>=1.21.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.26.4)\n",
|
||||
"Requirement already satisfied: pandas>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.1.4)\n",
|
||||
"Requirement already satisfied: scikit-learn>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.6.1)\n",
|
||||
"Requirement already satisfied: spacy>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.8.11)\n",
|
||||
"Requirement already satisfied: transformers>=4.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.53.2)\n",
|
||||
"Requirement already satisfied: torch>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.2.1)\n",
|
||||
"Requirement already satisfied: sentence-transformers>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.2.1)\n",
|
||||
"Requirement already satisfied: rdflib>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.0)\n",
|
||||
"Requirement already satisfied: networkx>=2.8.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.5)\n",
|
||||
"Requirement already satisfied: matplotlib>=3.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.10.1)\n",
|
||||
"Requirement already satisfied: seaborn>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.13.2)\n",
|
||||
"Requirement already satisfied: plotly>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.17.0)\n",
|
||||
"Requirement already satisfied: requests>=2.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.32.5)\n",
|
||||
"Requirement already satisfied: beautifulsoup4>=4.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.12.3)\n",
|
||||
"Requirement already satisfied: lxml>=4.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.2)\n",
|
||||
"Requirement already satisfied: pypdf2>=2.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: python-docx>=0.8.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: openpyxl>=3.0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.1.5)\n",
|
||||
"Requirement already satisfied: pillow>=9.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (10.4.0)\n",
|
||||
"Requirement already satisfied: librosa>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.11.0)\n",
|
||||
"Requirement already satisfied: opencv-python>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.9.0.80)\n",
|
||||
"Requirement already satisfied: faiss-cpu>=1.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.9.0)\n",
|
||||
"Requirement already satisfied: weaviate-client>=3.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.18.1)\n",
|
||||
"Requirement already satisfied: qdrant-client>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.12.2)\n",
|
||||
"Requirement already satisfied: neo4j>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.3)\n",
|
||||
"Requirement already satisfied: falkordb>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.2.2)\n",
|
||||
"Requirement already satisfied: pymongo>=4.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.15.4)\n",
|
||||
"Requirement already satisfied: sqlalchemy>=1.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.0.23)\n",
|
||||
"Requirement already satisfied: psycopg2-binary>=2.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.9.9)\n",
|
||||
"Requirement already satisfied: pymysql>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: redis>=4.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.4.0)\n",
|
||||
"Requirement already satisfied: celery>=5.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.3.4)\n",
|
||||
"Requirement already satisfied: kafka-python>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.3.0)\n",
|
||||
"Requirement already satisfied: pulsar-client>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.3.0)\n",
|
||||
"Requirement already satisfied: pika>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: boto3>=1.24.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.36.0)\n",
|
||||
"Requirement already satisfied: azure-storage-blob>=12.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (12.27.1)\n",
|
||||
"Requirement already satisfied: google-cloud-storage>=2.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.18.2)\n",
|
||||
"Requirement already satisfied: pydantic>=1.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.12.3)\n",
|
||||
"Requirement already satisfied: click>=8.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (8.2.1)\n",
|
||||
"Requirement already satisfied: rich>=12.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (13.7.1)\n",
|
||||
"Requirement already satisfied: tqdm>=4.64.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.67.1)\n",
|
||||
"Requirement already satisfied: pyyaml>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: toml>=0.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.10.2)\n",
|
||||
"Requirement already satisfied: python-dotenv>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: loguru>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.7.3)\n",
|
||||
"Requirement already satisfied: structlog>=22.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (24.4.0)\n",
|
||||
"Requirement already satisfied: prometheus-client>=0.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.18.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-api>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-sdk>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-instrumentation in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: fastapi>=0.78.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.120.4)\n",
|
||||
"Requirement already satisfied: uvicorn>=0.18.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.38.0)\n",
|
||||
"Requirement already satisfied: pytest>=7.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.3)\n",
|
||||
"Requirement already satisfied: pytest-cov>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.0.0)\n",
|
||||
"Requirement already satisfied: pytest-asyncio>=0.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.21.1)\n",
|
||||
"Requirement already satisfied: black>=22.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (23.11.0)\n",
|
||||
"Requirement already satisfied: isort>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.12.0)\n",
|
||||
"Requirement already satisfied: flake8>=4.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.3.0)\n",
|
||||
"Requirement already satisfied: mypy>=0.971 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pre-commit>=2.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.4.0)\n",
|
||||
"Requirement already satisfied: azure-core>=1.30.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (1.35.0)\n",
|
||||
"Requirement already satisfied: cryptography>=2.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (43.0.3)\n",
|
||||
"Requirement already satisfied: typing-extensions>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (4.14.1)\n",
|
||||
"Requirement already satisfied: isodate>=0.6.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (0.7.2)\n",
|
||||
"Requirement already satisfied: six>=1.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-core>=1.30.0->azure-storage-blob>=12.12.0->semantica) (1.16.0)\n",
|
||||
"Requirement already satisfied: soupsieve>1.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from beautifulsoup4>=4.11.0->semantica) (2.5)\n",
|
||||
"Requirement already satisfied: mypy-extensions>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (1.0.0)\n",
|
||||
"Requirement already satisfied: packaging>=22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (24.2)\n",
|
||||
"Requirement already satisfied: pathspec>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (0.11.2)\n",
|
||||
"Requirement already satisfied: platformdirs>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (3.11.0)\n",
|
||||
"Requirement already satisfied: botocore<1.37.0,>=1.36.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.36.26)\n",
|
||||
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.0.1)\n",
|
||||
"Requirement already satisfied: s3transfer<0.12.0,>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (0.11.3)\n",
|
||||
"Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (2.9.0.post0)\n",
|
||||
"Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (1.26.20)\n",
|
||||
"Requirement already satisfied: billiard<5.0,>=4.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (4.2.1)\n",
|
||||
"Requirement already satisfied: kombu<6.0,>=5.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.5.3)\n",
|
||||
"Requirement already satisfied: vine<6.0,>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.1.0)\n",
|
||||
"Requirement already satisfied: click-didyoumean>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.1)\n",
|
||||
"Requirement already satisfied: click-repl>=0.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.0)\n",
|
||||
"Requirement already satisfied: click-plugins>=1.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: tzdata>=2022.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (2025.2)\n",
|
||||
"Requirement already satisfied: colorama in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from click>=8.1.0->semantica) (0.4.6)\n",
|
||||
"Requirement already satisfied: amqp<6.0.0,>=5.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from kombu<6.0,>=5.3.2->celery>=5.2.0->semantica) (5.3.1)\n",
|
||||
"Requirement already satisfied: prompt-toolkit>=3.0.36 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from click-repl>=0.2.0->celery>=5.2.0->semantica) (3.0.40)\n",
|
||||
"Requirement already satisfied: cffi>=1.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pycparser in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cffi>=1.12->cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (2.22)\n",
|
||||
"Requirement already satisfied: starlette<0.50.0,>=0.40.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.46.2)\n",
|
||||
"Requirement already satisfied: annotated-doc>=0.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.0.3)\n",
|
||||
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pydantic-core==2.41.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (2.41.4)\n",
|
||||
"Requirement already satisfied: typing-inspection>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.4.2)\n",
|
||||
"Requirement already satisfied: anyio<5,>=3.6.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (4.11.0)\n",
|
||||
"Requirement already satisfied: idna>=2.8 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (3.10)\n",
|
||||
"Requirement already satisfied: sniffio>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (1.3.1)\n",
|
||||
"Requirement already satisfied: mccabe<0.8.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pycodestyle<2.15.0,>=2.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (2.14.0)\n",
|
||||
"Requirement already satisfied: pyflakes<3.5.0,>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: google-auth<3.0dev,>=2.26.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.36.0)\n",
|
||||
"Requirement already satisfied: google-api-core<3.0.0dev,>=2.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.23.0)\n",
|
||||
"Requirement already satisfied: google-cloud-core<3.0dev,>=2.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.4.1)\n",
|
||||
"Requirement already satisfied: google-resumable-media>=2.7.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.7.2)\n",
|
||||
"Requirement already satisfied: google-crc32c<2.0dev,>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.66.0)\n",
|
||||
"Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.19.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (4.25.8)\n",
|
||||
"Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.25.0)\n",
|
||||
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (5.5.2)\n",
|
||||
"Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.4.1)\n",
|
||||
"Requirement already satisfied: rsa<5,>=3.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (4.9)\n",
|
||||
"Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (2025.8.3)\n",
|
||||
"Requirement already satisfied: pyasn1>=0.1.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rsa<5,>=3.1.4->google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.6.1)\n",
|
||||
"Requirement already satisfied: audioread>=2.1.9 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: numba>=0.51.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.61.2)\n",
|
||||
"Requirement already satisfied: scipy>=1.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.15.2)\n",
|
||||
"Requirement already satisfied: joblib>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: decorator>=4.3.0 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from librosa>=0.9.0->semantica) (5.1.1)\n",
|
||||
"Requirement already satisfied: soundfile>=0.12.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.13.1)\n",
|
||||
"Requirement already satisfied: pooch>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.8.2)\n",
|
||||
"Requirement already satisfied: soxr>=0.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.5.0.post1)\n",
|
||||
"Requirement already satisfied: lazy_loader>=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.4)\n",
|
||||
"Requirement already satisfied: msgpack>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: win32-setctime>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from loguru>=0.6.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: cycler>=0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (0.12.1)\n",
|
||||
"Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (4.57.0)\n",
|
||||
"Requirement already satisfied: kiwisolver>=1.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.4.8)\n",
|
||||
"Requirement already satisfied: pyparsing>=2.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: pytz in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from neo4j>=5.0.0->semantica) (2024.2)\n",
|
||||
"Requirement already satisfied: llvmlite<0.45,>=0.44.0dev0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from numba>=0.51.0->librosa>=0.9.0->semantica) (0.44.0)\n",
|
||||
"Requirement already satisfied: et-xmlfile in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from openpyxl>=3.0.10->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-api>=1.12.0->semantica) (6.8.0)\n",
|
||||
"Requirement already satisfied: zipp>=0.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api>=1.12.0->semantica) (3.17.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-semantic-conventions==0.59b0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-sdk>=1.12.0->semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: tenacity>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from plotly>=5.10.0->semantica) (8.5.0)\n",
|
||||
"Requirement already satisfied: cfgv>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (3.5.0)\n",
|
||||
"Requirement already satisfied: identify>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (2.6.15)\n",
|
||||
"Requirement already satisfied: nodeenv>=0.11.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (1.9.1)\n",
|
||||
"Requirement already satisfied: virtualenv>=20.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (20.24.6)\n",
|
||||
"Requirement already satisfied: wcwidth in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from prompt-toolkit>=3.0.36->click-repl>=0.2.0->celery>=5.2.0->semantica) (0.2.9)\n",
|
||||
"Requirement already satisfied: dnspython<3.0.0,>=1.16.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pymongo>=4.2.0->semantica) (2.4.2)\n",
|
||||
"Requirement already satisfied: iniconfig in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: pluggy<2.0,>=0.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (1.5.0)\n",
|
||||
"Requirement already satisfied: coverage>=7.10.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from coverage[toml]>=7.10.6->pytest-cov>=3.0.0->semantica) (7.12.0)\n",
|
||||
"Requirement already satisfied: grpcio>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.68.0)\n",
|
||||
"Requirement already satisfied: grpcio-tools>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.62.3)\n",
|
||||
"Requirement already satisfied: httpx>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.28.1)\n",
|
||||
"Requirement already satisfied: portalocker<3.0.0,>=2.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (2.10.1)\n",
|
||||
"Requirement already satisfied: pywin32>=226 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from portalocker<3.0.0,>=2.7.0->qdrant-client>=1.3.0->semantica) (311)\n",
|
||||
"Requirement already satisfied: setuptools in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from grpcio-tools>=1.41.0->qdrant-client>=1.3.0->semantica) (80.9.0)\n",
|
||||
"Requirement already satisfied: httpcore==1.* in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (1.0.9)\n",
|
||||
"Requirement already satisfied: h11>=0.16 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpcore==1.*->httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.16.0)\n",
|
||||
"Requirement already satisfied: h2<5,>=3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.1.0)\n",
|
||||
"Requirement already satisfied: hyperframe<7,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: hpack<5,>=4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.0.0)\n",
|
||||
"Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (3.0.0)\n",
|
||||
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (2.19.2)\n",
|
||||
"Requirement already satisfied: mdurl~=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from markdown-it-py>=2.2.0->rich>=12.5.0->semantica) (0.1.2)\n",
|
||||
"Requirement already satisfied: threadpoolctl>=3.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from scikit-learn>=1.0.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: huggingface-hub>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sentence-transformers>=2.2.0->semantica) (0.30.2)\n",
|
||||
"Requirement already satisfied: filelock in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (3.16.1)\n",
|
||||
"Requirement already satisfied: regex!=2019.12.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (2024.11.6)\n",
|
||||
"Requirement already satisfied: tokenizers<0.22,>=0.21 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.21.4)\n",
|
||||
"Requirement already satisfied: safetensors>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.5.3)\n",
|
||||
"Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers>=2.2.0->semantica) (2023.10.0)\n",
|
||||
"Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.5)\n",
|
||||
"Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.15)\n",
|
||||
"Requirement already satisfied: cymem<2.1.0,>=2.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.13)\n",
|
||||
"Requirement already satisfied: preshed<3.1.0,>=3.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: thinc<8.4.0,>=8.3.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (8.3.10)\n",
|
||||
"Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.1.3)\n",
|
||||
"Requirement already satisfied: srsly<3.0.0,>=2.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.5.2)\n",
|
||||
"Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.10)\n",
|
||||
"Requirement already satisfied: weasel<0.5.0,>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.4.3)\n",
|
||||
"Requirement already satisfied: typer-slim<1.0.0,>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.20.0)\n",
|
||||
"Requirement already satisfied: jinja2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.1.6)\n",
|
||||
"Requirement already satisfied: blis<1.4.0,>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (1.3.3)\n",
|
||||
"Requirement already satisfied: confection<1.0.0,>=0.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (0.1.5)\n",
|
||||
"Requirement already satisfied: cloudpathlib<1.0.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (0.23.0)\n",
|
||||
"Requirement already satisfied: smart-open<8.0.0,>=5.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (7.1.0)\n",
|
||||
"Requirement already satisfied: wrapt in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from smart-open<8.0.0,>=5.2.1->weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (1.17.2)\n",
|
||||
"Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sqlalchemy>=1.4.0->semantica) (3.2.3)\n",
|
||||
"Requirement already satisfied: sympy in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from torch>=1.12.0->semantica) (1.13.3)\n",
|
||||
"Requirement already satisfied: distlib<1,>=0.3.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from virtualenv>=20.10.0->pre-commit>=2.19.0->semantica) (0.3.7)\n",
|
||||
"Requirement already satisfied: validators<1.0.0,>=0.34.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (0.35.0)\n",
|
||||
"Requirement already satisfied: authlib<2.0.0,>=1.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: deprecation<3.0.0,>=2.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (2.1.0)\n",
|
||||
"Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from jinja2->spacy>=3.4.0->semantica) (2.1.3)\n",
|
||||
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sympy->torch>=1.12.0->semantica) (1.3.0)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -94,29 +316,30 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Connected to graph database successfully!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.graph_store import GraphStore\n",
|
||||
"\n",
|
||||
"# Option 1: Neo4j (requires Neo4j server running)\n",
|
||||
"# Neo4j AuraDB Connection Details\n",
|
||||
"# Replace these values with your actual AuraDB credentials\n",
|
||||
"store = GraphStore(\n",
|
||||
" backend=\"neo4j\",\n",
|
||||
" uri=\"bolt://localhost:7687\",\n",
|
||||
" uri=\"Your URI\", # Your AuraDB Instance URI\n",
|
||||
" user=\"neo4j\",\n",
|
||||
" password=\"password\"\n",
|
||||
" password=\"Your Password\" # Please enter your password here\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Option 2: FalkorDB (requires Redis/FalkorDB server)\n",
|
||||
"# store = GraphStore(\n",
|
||||
"# backend=\"falkordb\",\n",
|
||||
"# host=\"localhost\",\n",
|
||||
"# port=6379,\n",
|
||||
"# graph_name=\"demo_graph\"\n",
|
||||
"# )\n",
|
||||
"\n",
|
||||
"# Connect to the database\n",
|
||||
"store.connect()\n",
|
||||
"print(\"Connected to graph database successfully!\")\n"
|
||||
"print(\"Connected to graph database successfully!\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -134,9 +357,64 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is processing</td><td>⏳ graph_store</td><td>Neo4jStore</td><td>-</td><td>0.14s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=34, offset=33>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 33, 'line': 1, 'column': 34}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'CREATE (n:Company $props) RETURN id(n) as id, n'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Created company node: Apple Inc. (ID: 0)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=33, offset=32>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 32, 'line': 1, 'column': 33}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'CREATE (n:Person $props) RETURN id(n) as id, n'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Created person node: Tim Cook (ID: 1)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=35, offset=34>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 34, 'line': 1, 'column': 35}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'CREATE (n:Location $props) RETURN id(n) as id, n'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Created location node: Cupertino (ID: 2)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Create individual nodes with labels and properties\n",
|
||||
"apple = store.create_node(\n",
|
||||
@@ -160,9 +438,26 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=34, offset=33>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 33, 'line': 1, 'column': 34}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'CREATE (n:Company $props) RETURN id(n) as id, n'\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=34, offset=33>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 33, 'line': 1, 'column': 34}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'CREATE (n:Company $props) RETURN id(n) as id, n'\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=34, offset=33>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 33, 'line': 1, 'column': 34}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'CREATE (n:Company $props) RETURN id(n) as id, n'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Created 3 company nodes in batch\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Create multiple nodes in batch (more efficient for large datasets)\n",
|
||||
"other_companies = store.create_nodes([\n",
|
||||
@@ -189,9 +484,42 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=3, column=23, offset=54>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 54, 'line': 3, 'column': 23}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a), (b)\\n WHERE id(a) = $start_id AND id(b) = $end_id\\n CREATE (a)-[r:CEO_OF $props]->(b)\\n RETURN id(r) as id, type(r) as type, r\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=3, column=45, offset=76>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 76, 'line': 3, 'column': 45}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a), (b)\\n WHERE id(a) = $start_id AND id(b) = $end_id\\n CREATE (a)-[r:CEO_OF $props]->(b)\\n RETURN id(r) as id, type(r) as type, r\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=5, column=24, offset=165>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 165, 'line': 5, 'column': 24}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a), (b)\\n WHERE id(a) = $start_id AND id(b) = $end_id\\n CREATE (a)-[r:CEO_OF $props]->(b)\\n RETURN id(r) as id, type(r) as type, r\\n '\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Created relationship: CEO_OF (ID: 1152921504606846977)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=3, column=23, offset=54>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 54, 'line': 3, 'column': 23}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a), (b)\\n WHERE id(a) = $start_id AND id(b) = $end_id\\n CREATE (a)-[r:HEADQUARTERED_IN $props]->(b)\\n RETURN id(r) as id, type(r) as type, r\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=3, column=45, offset=76>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 76, 'line': 3, 'column': 45}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a), (b)\\n WHERE id(a) = $start_id AND id(b) = $end_id\\n CREATE (a)-[r:HEADQUARTERED_IN $props]->(b)\\n RETURN id(r) as id, type(r) as type, r\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=5, column=24, offset=175>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 175, 'line': 5, 'column': 24}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a), (b)\\n WHERE id(a) = $start_id AND id(b) = $end_id\\n CREATE (a)-[r:HEADQUARTERED_IN $props]->(b)\\n RETURN id(r) as id, type(r) as type, r\\n '\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Created relationship: HEADQUARTERED_IN (ID: 1152922604118474752)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Create relationships between nodes\n",
|
||||
"ceo_rel = store.create_relationship(\n",
|
||||
@@ -224,9 +552,28 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=26, offset=25>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 25, 'line': 1, 'column': 26}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'MATCH (n:Company) RETURN id(n) as id, n, labels(n) as labels LIMIT 10'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Found 4 companies:\n",
|
||||
" - Apple Inc. (founded: 1976)\n",
|
||||
" - Microsoft (founded: 1975)\n",
|
||||
" - Google (founded: 1998)\n",
|
||||
" - Amazon (founded: 1994)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Get nodes by label\n",
|
||||
"companies = store.get_nodes(labels=[\"Company\"], limit=10)\n",
|
||||
@@ -244,9 +591,35 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=3, column=31, offset=73>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 73, 'line': 3, 'column': 31}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a)-[r]-(b)\\n WHERE id(a) = $node_id\\n RETURN id(r) as id, type(r) as type, id(startNode(r)) as start_id, id(endNode(r)) as end_id, r\\n LIMIT 100\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=4, column=32, offset=121>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 121, 'line': 4, 'column': 32}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a)-[r]-(b)\\n WHERE id(a) = $node_id\\n RETURN id(r) as id, type(r) as type, id(startNode(r)) as start_id, id(endNode(r)) as end_id, r\\n LIMIT 100\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=4, column=62, offset=151>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 151, 'line': 4, 'column': 62}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a)-[r]-(b)\\n WHERE id(a) = $node_id\\n RETURN id(r) as id, type(r) as type, id(startNode(r)) as start_id, id(endNode(r)) as end_id, r\\n LIMIT 100\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=4, column=92, offset=181>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 181, 'line': 4, 'column': 92}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a)-[r]-(b)\\n WHERE id(a) = $node_id\\n RETURN id(r) as id, type(r) as type, id(startNode(r)) as start_id, id(endNode(r)) as end_id, r\\n LIMIT 100\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=3, column=31, offset=81>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 81, 'line': 3, 'column': 31}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a)-[r:CEO_OF]->(b)\\n WHERE id(a) = $node_id\\n RETURN id(r) as id, type(r) as type, id(a) as start_id, id(b) as end_id, r\\n LIMIT 100\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=4, column=32, offset=129>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 129, 'line': 4, 'column': 32}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a)-[r:CEO_OF]->(b)\\n WHERE id(a) = $node_id\\n RETURN id(r) as id, type(r) as type, id(a) as start_id, id(b) as end_id, r\\n LIMIT 100\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=4, column=62, offset=159>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 159, 'line': 4, 'column': 62}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a)-[r:CEO_OF]->(b)\\n WHERE id(a) = $node_id\\n RETURN id(r) as id, type(r) as type, id(a) as start_id, id(b) as end_id, r\\n LIMIT 100\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=4, column=81, offset=178>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 178, 'line': 4, 'column': 81}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH (a)-[r:CEO_OF]->(b)\\n WHERE id(a) = $node_id\\n RETURN id(r) as id, type(r) as type, id(a) as start_id, id(b) as end_id, r\\n LIMIT 100\\n '\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Found 2 relationships for Apple:\n",
|
||||
" - HEADQUARTERED_IN: {'since': 1977}\n",
|
||||
" - CEO_OF: {'since': 2011}\n",
|
||||
"\n",
|
||||
"Outgoing CEO_OF relationships: 1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Get relationships for a node\n",
|
||||
"relationships = store.get_relationships(node_id=apple[\"id\"], direction=\"both\")\n",
|
||||
@@ -279,9 +652,18 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"CEO Relationships:\n",
|
||||
" - Tim Cook is CEO of Apple Inc. since 2011\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Execute a Cypher query to find CEO relationships\n",
|
||||
"results = store.execute_query(\"\"\"\n",
|
||||
@@ -299,9 +681,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Companies founded after 1990:\n",
|
||||
" - Amazon (founded: 1994)\n",
|
||||
" - Google (founded: 1998)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Parameterized query (safer and more efficient)\n",
|
||||
"results = store.execute_query(\n",
|
||||
@@ -329,7 +721,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -350,9 +742,28 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=3, column=23, offset=88>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 88, 'line': 3, 'column': 23}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH path = shortestPath((start)-[r*..5]-(end))\\n WHERE id(start) = $start_id AND id(end) = $end_id\\n RETURN path, length(path) as length\\n '\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=3, column=49, offset=114>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 114, 'line': 3, 'column': 49}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: '\\n MATCH path = shortestPath((start)-[r*..5]-(end))\\n WHERE id(start) = $start_id AND id(end) = $end_id\\n RETURN path, length(path) as length\\n '\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Shortest path found:\n",
|
||||
" - Path length: 2\n",
|
||||
" - Nodes in path: 3\n",
|
||||
" - Relationships: 2\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Find shortest path between two nodes\n",
|
||||
"if tim_cook.get('id') and cupertino.get('id'):\n",
|
||||
@@ -384,9 +795,27 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=17, offset=16>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 16, 'line': 1, 'column': 17}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'MATCH (n) WHERE id(n) = $id SET n += $props RETURN id(n) as id, n, labels(n) as labels'\n",
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=52, offset=51>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 51, 'line': 1, 'column': 52}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'MATCH (n) WHERE id(n) = $id SET n += $props RETURN id(n) as id, n, labels(n) as labels'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Updated node: Tim Cook\n",
|
||||
" New age: 64\n",
|
||||
" New title: CEO & President\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Update node properties (merge mode - adds/updates properties)\n",
|
||||
"if tim_cook.get('id'):\n",
|
||||
@@ -420,9 +849,27 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received notification from DBMS server: <GqlStatusObject gql_status='01N01', status_description='warn: feature deprecated with replacement. id is deprecated. It is replaced by elementId or consider using an application-generated id.', position=<SummaryInputPosition line=1, column=24, offset=23>, raw_classification='DEPRECATION', classification=<NotificationClassification.DEPRECATION: 'DEPRECATION'>, raw_severity='WARNING', severity=<NotificationSeverity.WARNING: 'WARNING'>, diagnostic_record={'_classification': 'DEPRECATION', '_severity': 'WARNING', '_position': {'offset': 23, 'line': 1, 'column': 24}, 'OPERATION': '', 'OPERATION_CODE': '0', 'CURRENT_SCHEMA': '/'}> for query: 'MATCH ()-[r]->() WHERE id(r) = $id DELETE r'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Deleted relationship (ID: 1152922604118474752)\n",
|
||||
"\n",
|
||||
"Tip: Use detach=True to delete a node and all its relationships\n",
|
||||
" Use detach=False to only delete the node (fails if relationships exist)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Delete a relationship\n",
|
||||
"if location_rel.get('id'):\n",
|
||||
@@ -453,9 +900,27 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Graph Statistics:\n",
|
||||
" Total nodes: 6\n",
|
||||
" Total relationships: 1\n",
|
||||
"\n",
|
||||
"Node labels:\n",
|
||||
" - Company: 4 nodes\n",
|
||||
" - Person: 1 nodes\n",
|
||||
" - Location: 1 nodes\n",
|
||||
"\n",
|
||||
"Relationship types:\n",
|
||||
" - CEO_OF: 1 relationships\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Get comprehensive graph statistics\n",
|
||||
"stats = store.get_stats()\n",
|
||||
@@ -482,9 +947,23 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Convenience functions available:\n",
|
||||
" - create_node, create_nodes\n",
|
||||
" - create_relationship, create_relationships\n",
|
||||
" - get_nodes, get_relationships\n",
|
||||
" - update_node, delete_node\n",
|
||||
" - execute_query, shortest_path, get_neighbors\n",
|
||||
" - run_analytics\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Using convenience functions (alternative to class methods)\n",
|
||||
"from semantica.graph_store import (\n",
|
||||
@@ -524,9 +1003,17 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Created index on Company.name for faster queries\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Create an index on a node property for faster lookups\n",
|
||||
"# This is especially useful for frequently queried properties\n",
|
||||
@@ -558,9 +1045,17 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Connection closed successfully\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Close the connection\n",
|
||||
"store.close()\n",
|
||||
@@ -592,8 +1087,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -41,9 +41,255 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Requirement already satisfied: semantica in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.0.5)\n",
|
||||
"Requirement already satisfied: numpy>=1.21.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.26.4)\n",
|
||||
"Requirement already satisfied: pandas>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.1.4)\n",
|
||||
"Requirement already satisfied: scikit-learn>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.6.1)\n",
|
||||
"Requirement already satisfied: spacy>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.8.11)\n",
|
||||
"Requirement already satisfied: transformers>=4.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.53.2)\n",
|
||||
"Requirement already satisfied: torch>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.2.1)\n",
|
||||
"Requirement already satisfied: sentence-transformers>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.2.1)\n",
|
||||
"Requirement already satisfied: rdflib>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.0)\n",
|
||||
"Requirement already satisfied: networkx>=2.8.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.5)\n",
|
||||
"Requirement already satisfied: matplotlib>=3.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.10.1)\n",
|
||||
"Requirement already satisfied: seaborn>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.13.2)\n",
|
||||
"Requirement already satisfied: plotly>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.17.0)\n",
|
||||
"Requirement already satisfied: requests>=2.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.32.5)\n",
|
||||
"Requirement already satisfied: beautifulsoup4>=4.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.12.3)\n",
|
||||
"Requirement already satisfied: lxml>=4.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.2)\n",
|
||||
"Requirement already satisfied: pypdf2>=2.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: python-docx>=0.8.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: openpyxl>=3.0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.1.5)\n",
|
||||
"Requirement already satisfied: pillow>=9.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (10.4.0)\n",
|
||||
"Requirement already satisfied: librosa>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.11.0)\n",
|
||||
"Requirement already satisfied: opencv-python>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.9.0.80)\n",
|
||||
"Requirement already satisfied: faiss-cpu>=1.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.9.0)\n",
|
||||
"Requirement already satisfied: weaviate-client>=3.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.18.1)\n",
|
||||
"Requirement already satisfied: qdrant-client>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.12.2)\n",
|
||||
"Requirement already satisfied: neo4j>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.3)\n",
|
||||
"Requirement already satisfied: falkordb>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.2.2)\n",
|
||||
"Requirement already satisfied: pymongo>=4.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.15.4)\n",
|
||||
"Requirement already satisfied: sqlalchemy>=1.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.0.23)\n",
|
||||
"Requirement already satisfied: psycopg2-binary>=2.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.9.9)\n",
|
||||
"Requirement already satisfied: pymysql>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: redis>=4.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.4.0)\n",
|
||||
"Requirement already satisfied: celery>=5.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.3.4)\n",
|
||||
"Requirement already satisfied: kafka-python>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.3.0)\n",
|
||||
"Requirement already satisfied: pulsar-client>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.3.0)\n",
|
||||
"Requirement already satisfied: pika>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: boto3>=1.24.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.36.0)\n",
|
||||
"Requirement already satisfied: azure-storage-blob>=12.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (12.27.1)\n",
|
||||
"Requirement already satisfied: google-cloud-storage>=2.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.18.2)\n",
|
||||
"Requirement already satisfied: pydantic>=1.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.12.3)\n",
|
||||
"Requirement already satisfied: click>=8.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (8.2.1)\n",
|
||||
"Requirement already satisfied: rich>=12.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (13.7.1)\n",
|
||||
"Requirement already satisfied: tqdm>=4.64.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.67.1)\n",
|
||||
"Requirement already satisfied: pyyaml>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: toml>=0.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.10.2)\n",
|
||||
"Requirement already satisfied: python-dotenv>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: loguru>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.7.3)\n",
|
||||
"Requirement already satisfied: structlog>=22.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (24.4.0)\n",
|
||||
"Requirement already satisfied: prometheus-client>=0.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.18.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-api>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-sdk>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-instrumentation in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: fastapi>=0.78.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.120.4)\n",
|
||||
"Requirement already satisfied: uvicorn>=0.18.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.38.0)\n",
|
||||
"Requirement already satisfied: pytest>=7.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.3)\n",
|
||||
"Requirement already satisfied: pytest-cov>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.0.0)\n",
|
||||
"Requirement already satisfied: pytest-asyncio>=0.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.21.1)\n",
|
||||
"Requirement already satisfied: black>=22.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (23.11.0)\n",
|
||||
"Requirement already satisfied: isort>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.12.0)\n",
|
||||
"Requirement already satisfied: flake8>=4.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.3.0)\n",
|
||||
"Requirement already satisfied: mypy>=0.971 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pre-commit>=2.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.4.0)\n",
|
||||
"Requirement already satisfied: azure-core>=1.30.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (1.35.0)\n",
|
||||
"Requirement already satisfied: cryptography>=2.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (43.0.3)\n",
|
||||
"Requirement already satisfied: typing-extensions>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (4.14.1)\n",
|
||||
"Requirement already satisfied: isodate>=0.6.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (0.7.2)\n",
|
||||
"Requirement already satisfied: six>=1.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-core>=1.30.0->azure-storage-blob>=12.12.0->semantica) (1.16.0)\n",
|
||||
"Requirement already satisfied: soupsieve>1.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from beautifulsoup4>=4.11.0->semantica) (2.5)\n",
|
||||
"Requirement already satisfied: mypy-extensions>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (1.0.0)\n",
|
||||
"Requirement already satisfied: packaging>=22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (24.2)\n",
|
||||
"Requirement already satisfied: pathspec>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (0.11.2)\n",
|
||||
"Requirement already satisfied: platformdirs>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (3.11.0)\n",
|
||||
"Requirement already satisfied: botocore<1.37.0,>=1.36.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.36.26)\n",
|
||||
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.0.1)\n",
|
||||
"Requirement already satisfied: s3transfer<0.12.0,>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (0.11.3)\n",
|
||||
"Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (2.9.0.post0)\n",
|
||||
"Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (1.26.20)\n",
|
||||
"Requirement already satisfied: billiard<5.0,>=4.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (4.2.1)\n",
|
||||
"Requirement already satisfied: kombu<6.0,>=5.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.5.3)\n",
|
||||
"Requirement already satisfied: vine<6.0,>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.1.0)\n",
|
||||
"Requirement already satisfied: click-didyoumean>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.1)\n",
|
||||
"Requirement already satisfied: click-repl>=0.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.0)\n",
|
||||
"Requirement already satisfied: click-plugins>=1.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: tzdata>=2022.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (2025.2)\n",
|
||||
"Requirement already satisfied: colorama in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from click>=8.1.0->semantica) (0.4.6)\n",
|
||||
"Requirement already satisfied: amqp<6.0.0,>=5.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from kombu<6.0,>=5.3.2->celery>=5.2.0->semantica) (5.3.1)\n",
|
||||
"Requirement already satisfied: prompt-toolkit>=3.0.36 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from click-repl>=0.2.0->celery>=5.2.0->semantica) (3.0.40)\n",
|
||||
"Requirement already satisfied: cffi>=1.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pycparser in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cffi>=1.12->cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (2.22)\n",
|
||||
"Requirement already satisfied: starlette<0.50.0,>=0.40.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.46.2)\n",
|
||||
"Requirement already satisfied: annotated-doc>=0.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.0.3)\n",
|
||||
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pydantic-core==2.41.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (2.41.4)\n",
|
||||
"Requirement already satisfied: typing-inspection>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.4.2)\n",
|
||||
"Requirement already satisfied: anyio<5,>=3.6.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (4.11.0)\n",
|
||||
"Requirement already satisfied: idna>=2.8 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (3.10)\n",
|
||||
"Requirement already satisfied: sniffio>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (1.3.1)\n",
|
||||
"Requirement already satisfied: mccabe<0.8.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pycodestyle<2.15.0,>=2.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (2.14.0)\n",
|
||||
"Requirement already satisfied: pyflakes<3.5.0,>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: google-auth<3.0dev,>=2.26.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.36.0)\n",
|
||||
"Requirement already satisfied: google-api-core<3.0.0dev,>=2.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.23.0)\n",
|
||||
"Requirement already satisfied: google-cloud-core<3.0dev,>=2.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.4.1)\n",
|
||||
"Requirement already satisfied: google-resumable-media>=2.7.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.7.2)\n",
|
||||
"Requirement already satisfied: google-crc32c<2.0dev,>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.66.0)\n",
|
||||
"Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.19.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (4.25.8)\n",
|
||||
"Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.25.0)\n",
|
||||
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (5.5.2)\n",
|
||||
"Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.4.1)\n",
|
||||
"Requirement already satisfied: rsa<5,>=3.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (4.9)\n",
|
||||
"Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (2025.8.3)\n",
|
||||
"Requirement already satisfied: pyasn1>=0.1.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rsa<5,>=3.1.4->google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.6.1)\n",
|
||||
"Requirement already satisfied: audioread>=2.1.9 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: numba>=0.51.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.61.2)\n",
|
||||
"Requirement already satisfied: scipy>=1.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.15.2)\n",
|
||||
"Requirement already satisfied: joblib>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: decorator>=4.3.0 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from librosa>=0.9.0->semantica) (5.1.1)\n",
|
||||
"Requirement already satisfied: soundfile>=0.12.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.13.1)\n",
|
||||
"Requirement already satisfied: pooch>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.8.2)\n",
|
||||
"Requirement already satisfied: soxr>=0.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.5.0.post1)\n",
|
||||
"Requirement already satisfied: lazy_loader>=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.4)\n",
|
||||
"Requirement already satisfied: msgpack>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: win32-setctime>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from loguru>=0.6.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: cycler>=0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (0.12.1)\n",
|
||||
"Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (4.57.0)\n",
|
||||
"Requirement already satisfied: kiwisolver>=1.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.4.8)\n",
|
||||
"Requirement already satisfied: pyparsing>=2.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: pytz in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from neo4j>=5.0.0->semantica) (2024.2)\n",
|
||||
"Requirement already satisfied: llvmlite<0.45,>=0.44.0dev0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from numba>=0.51.0->librosa>=0.9.0->semantica) (0.44.0)\n",
|
||||
"Requirement already satisfied: et-xmlfile in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from openpyxl>=3.0.10->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-api>=1.12.0->semantica) (6.8.0)\n",
|
||||
"Requirement already satisfied: zipp>=0.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api>=1.12.0->semantica) (3.17.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-semantic-conventions==0.59b0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-sdk>=1.12.0->semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: tenacity>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from plotly>=5.10.0->semantica) (8.5.0)\n",
|
||||
"Requirement already satisfied: cfgv>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (3.5.0)\n",
|
||||
"Requirement already satisfied: identify>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (2.6.15)\n",
|
||||
"Requirement already satisfied: nodeenv>=0.11.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (1.9.1)\n",
|
||||
"Requirement already satisfied: virtualenv>=20.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (20.24.6)\n",
|
||||
"Requirement already satisfied: wcwidth in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from prompt-toolkit>=3.0.36->click-repl>=0.2.0->celery>=5.2.0->semantica) (0.2.9)\n",
|
||||
"Requirement already satisfied: dnspython<3.0.0,>=1.16.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pymongo>=4.2.0->semantica) (2.4.2)\n",
|
||||
"Requirement already satisfied: iniconfig in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: pluggy<2.0,>=0.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (1.5.0)\n",
|
||||
"Requirement already satisfied: coverage>=7.10.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from coverage[toml]>=7.10.6->pytest-cov>=3.0.0->semantica) (7.12.0)\n",
|
||||
"Requirement already satisfied: grpcio>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.68.0)\n",
|
||||
"Requirement already satisfied: grpcio-tools>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.62.3)\n",
|
||||
"Requirement already satisfied: httpx>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.28.1)\n",
|
||||
"Requirement already satisfied: portalocker<3.0.0,>=2.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (2.10.1)\n",
|
||||
"Requirement already satisfied: pywin32>=226 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from portalocker<3.0.0,>=2.7.0->qdrant-client>=1.3.0->semantica) (311)\n",
|
||||
"Requirement already satisfied: setuptools in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from grpcio-tools>=1.41.0->qdrant-client>=1.3.0->semantica) (80.9.0)\n",
|
||||
"Requirement already satisfied: httpcore==1.* in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (1.0.9)\n",
|
||||
"Requirement already satisfied: h11>=0.16 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpcore==1.*->httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.16.0)\n",
|
||||
"Requirement already satisfied: h2<5,>=3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.1.0)\n",
|
||||
"Requirement already satisfied: hyperframe<7,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: hpack<5,>=4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.0.0)\n",
|
||||
"Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (3.0.0)\n",
|
||||
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (2.19.2)\n",
|
||||
"Requirement already satisfied: mdurl~=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from markdown-it-py>=2.2.0->rich>=12.5.0->semantica) (0.1.2)\n",
|
||||
"Requirement already satisfied: threadpoolctl>=3.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from scikit-learn>=1.0.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: huggingface-hub>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sentence-transformers>=2.2.0->semantica) (0.30.2)\n",
|
||||
"Requirement already satisfied: filelock in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (3.16.1)\n",
|
||||
"Requirement already satisfied: regex!=2019.12.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (2024.11.6)\n",
|
||||
"Requirement already satisfied: tokenizers<0.22,>=0.21 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.21.4)\n",
|
||||
"Requirement already satisfied: safetensors>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.5.3)\n",
|
||||
"Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers>=2.2.0->semantica) (2023.10.0)\n",
|
||||
"Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.5)\n",
|
||||
"Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.15)\n",
|
||||
"Requirement already satisfied: cymem<2.1.0,>=2.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.13)\n",
|
||||
"Requirement already satisfied: preshed<3.1.0,>=3.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: thinc<8.4.0,>=8.3.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (8.3.10)\n",
|
||||
"Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.1.3)\n",
|
||||
"Requirement already satisfied: srsly<3.0.0,>=2.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.5.2)\n",
|
||||
"Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.10)\n",
|
||||
"Requirement already satisfied: weasel<0.5.0,>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.4.3)\n",
|
||||
"Requirement already satisfied: typer-slim<1.0.0,>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.20.0)\n",
|
||||
"Requirement already satisfied: jinja2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.1.6)\n",
|
||||
"Requirement already satisfied: blis<1.4.0,>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (1.3.3)\n",
|
||||
"Requirement already satisfied: confection<1.0.0,>=0.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (0.1.5)\n",
|
||||
"Requirement already satisfied: cloudpathlib<1.0.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (0.23.0)\n",
|
||||
"Requirement already satisfied: smart-open<8.0.0,>=5.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (7.1.0)\n",
|
||||
"Requirement already satisfied: wrapt in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from smart-open<8.0.0,>=5.2.1->weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (1.17.2)\n",
|
||||
"Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sqlalchemy>=1.4.0->semantica) (3.2.3)\n",
|
||||
"Requirement already satisfied: sympy in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from torch>=1.12.0->semantica) (1.13.3)\n",
|
||||
"Requirement already satisfied: distlib<1,>=0.3.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from virtualenv>=20.10.0->pre-commit>=2.19.0->semantica) (0.3.7)\n",
|
||||
"Requirement already satisfied: validators<1.0.0,>=0.34.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (0.35.0)\n",
|
||||
"Requirement already satisfied: authlib<2.0.0,>=1.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: deprecation<3.0.0,>=2.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (2.1.0)\n",
|
||||
"Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from jinja2->spacy>=3.4.0->semantica) (2.1.3)\n",
|
||||
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sympy->torch>=1.12.0->semantica) (1.3.0)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install semantica"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is building</td><td>🧠 kg</td><td>GraphBuilder</td><td>-</td><td>0.08s</td></tr><tr><td>🔄</td><td>Semantica is building</td><td>🧠 kg</td><td>EntityResolver</td><td>-</td><td>131.06s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>DuplicateDetector</td><td>-</td><td>0.04s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>SimilarityCalculator</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is resolving</td><td>⚠️ conflicts</td><td>ConflictDetector</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is building</td><td>🧠 kg</td><td>CentralityCalculator</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is building</td><td>🧠 kg</td><td>CommunityDetector</td><td>-</td><td>0.01s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Graph metrics:\n",
|
||||
" Entities: 3\n",
|
||||
" Relationships: 2\n",
|
||||
" Density: 0.667\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor\n",
|
||||
@@ -83,9 +329,20 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Centrality scores:\n",
|
||||
" e2: 0.500\n",
|
||||
" e1: 1.000\n",
|
||||
" e3: 0.500\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.kg import CentralityCalculator\n",
|
||||
"\n",
|
||||
@@ -110,19 +367,32 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Detected 1 communities\n",
|
||||
" Community 1: 3 entities\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.kg import CommunityDetector\n",
|
||||
"\n",
|
||||
"community_detector = CommunityDetector()\n",
|
||||
"\n",
|
||||
"communities = community_detector.detect_communities(kg)\n",
|
||||
"# Get detection result\n",
|
||||
"result = community_detector.detect_communities(kg)\n",
|
||||
"\n",
|
||||
"# Extract communities list from result dictionary\n",
|
||||
"communities = result.get(\"communities\", [])\n",
|
||||
"\n",
|
||||
"print(f\"Detected {len(communities)} communities\")\n",
|
||||
"for i, community in enumerate(communities[:3], 1):\n",
|
||||
" print(f\" Community {i}: {len(community)} entities\")\n"
|
||||
" print(f\" Community {i}: {len(community)} entities\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -164,13 +434,27 @@
|
||||
"- **CommunityDetector**: Detect communities in graphs\n",
|
||||
"- **ConnectivityAnalyzer**: Analyze graph connectivity\n",
|
||||
"\n",
|
||||
"Next: Learn how to assess graph quality in the Graph_Quality notebook.\n"
|
||||
"Next: Learn how to deduplicate entities in the Deduplication notebook.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,178 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. The quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/introduction/12_Graph_Quality.ipynb)\n",
|
||||
"\n",
|
||||
"# Graph Quality\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook demonstrates how to assess and improve knowledge graph quality using Semantica's quality assurance modules. You'll learn to use `KGQualityAssessor`, `ConsistencyChecker`, `CompletenessValidator`, and `QualityMetrics`.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/kg_qa/)\n",
|
||||
"\n",
|
||||
"### Learning Objectives\n",
|
||||
"\n",
|
||||
"- Use `KGQualityAssessor` for overall quality assessment\n",
|
||||
"- Use `ConsistencyChecker` to validate consistency\n",
|
||||
"- Use `CompletenessValidator` to check completeness\n",
|
||||
"- Use `QualityMetrics` to calculate quality metrics\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install Semantica from PyPI:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"# Or with all optional dependencies:\n",
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Step 1: Quality Assessment\n",
|
||||
"\n",
|
||||
"Assess overall graph quality.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
||||
"from semantica.kg import GraphBuilder\n",
|
||||
"\n",
|
||||
"builder = GraphBuilder()\n",
|
||||
|
||||
"\n",
|
||||
"entities = [\n",
|
||||
" {\"id\": \"e1\", \"type\": \"Organization\", \"name\": \"Apple Inc.\", \"properties\": {}}\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"relationships = []\n",
|
||||
"\n",
|
||||
"kg = builder.build(entities, relationships)\n",
|
||||
"\n",
|
||||
"quality_score = assessor.assess_overall_quality(kg)\n",
|
||||
"\n",
|
||||
"print(f\"Overall quality score: {quality_score.get('overall_score', 0):.3f}\")\n",
|
||||
"print(f\"Completeness: {quality_score.get('completeness', 0):.3f}\")\n",
|
||||
"print(f\"Consistency: {quality_score.get('consistency', 0):.3f}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 2: Consistency Checking\n",
|
||||
"\n",
|
||||
"Check graph consistency.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
||||
"\n",
|
||||
"consistency_checker = ConsistencyChecker()\n",
|
||||
"\n",
|
||||
"consistency_result = consistency_checker.check_consistency(kg)\n",
|
||||
"\n",
|
||||
"print(f\"Consistency check:\")\n",
|
||||
"print(f\" Is consistent: {consistency_result.get('is_consistent', False)}\")\n",
|
||||
"print(f\" Issues: {len(consistency_result.get('issues', []))}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Completeness Validation\n",
|
||||
"\n",
|
||||
"Validate graph completeness.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
||||
"\n",
|
||||
"completeness_validator = CompletenessValidator()\n",
|
||||
"\n",
|
||||
"completeness_result = completeness_validator.validate_completeness(kg)\n",
|
||||
"\n",
|
||||
"print(f\"Completeness validation:\")\n",
|
||||
"print(f\" Is complete: {completeness_result.get('is_complete', False)}\")\n",
|
||||
"print(f\" Missing properties: {len(completeness_result.get('missing_properties', []))}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 4: Quality Metrics\n",
|
||||
"\n",
|
||||
"Calculate detailed quality metrics.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
||||
"\n",
|
||||
"quality_metrics = QualityMetrics()\n",
|
||||
"\n",
|
||||
"metrics = quality_metrics.calculate_metrics(kg)\n",
|
||||
"\n",
|
||||
"print(f\"Quality metrics:\")\n",
|
||||
"print(f\" Entity coverage: {metrics.get('entity_coverage', 0):.3f}\")\n",
|
||||
"print(f\" Relationship coverage: {metrics.get('relationship_coverage', 0):.3f}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"You've learned how to assess graph quality:\n",
|
||||
"\n",
|
||||
"- **KGQualityAssessor**: Overall quality assessment\n",
|
||||
"- **ConsistencyChecker**: Consistency validation\n",
|
||||
"- **CompletenessValidator**: Completeness validation\n",
|
||||
"- **QualityMetrics**: Detailed quality metrics\n",
|
||||
"\n",
|
||||
"Next: Learn how to deduplicate entities in the Deduplication notebook.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -39,6 +39,15 @@
|
||||
"Generate embeddings using EmbeddingGenerator.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -139,4 +148,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,31 @@
|
||||
"---"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install -q semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -72,9 +97,30 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is indexing</td><td>📊 vector_store</td><td>VectorStore</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is indexing</td><td>📊 vector_store</td><td>FAISSStore</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is indexing</td><td>📊 vector_store</td><td>HybridSearch</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is indexing</td><td>📊 vector_store</td><td>MetadataStore</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is indexing</td><td>📊 vector_store</td><td>NamespaceManager</td><td>-</td><td>0.00s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Stored 100 vectors\n",
|
||||
"First 3 IDs: ['vec_0', 'vec_2', 'vec_4']\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.vector_store import VectorStore\n",
|
||||
"from semantica.embeddings import TextEmbedder\n",
|
||||
@@ -96,7 +142,6 @@
|
||||
" {\"text\": txt, \"category\": \"science\" if i % 2 == 0 else \"technology\", \"year\": 2020 + (i % 4)}\n",
|
||||
" for i, txt in enumerate(texts)\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# 4. Store vectors\n",
|
||||
"vector_ids = store.store_vectors(vectors, metadata=metadata)\n",
|
||||
"\n",
|
||||
@@ -121,21 +166,48 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Index search found 10 results\n",
|
||||
"Distances: [0. 0.59663105 0.6359793 0.66132385 0.6909249 ]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Create query vector\n",
|
||||
"query_vector = np.random.rand(768)\n",
|
||||
"from semantica.vector_store import VectorIndexer, FAISSStore \n",
|
||||
"import numpy as np \n",
|
||||
"# We use the first vector from the dataset as a sample query\n",
|
||||
"if 'query_vector' not in locals():\n",
|
||||
" if 'vectors' in locals() and len(vectors) > 0:\n",
|
||||
" query_vector = vectors[0]\n",
|
||||
" else:\n",
|
||||
" # Fallback if vectors are also missing (safety check)\n",
|
||||
" query_vector = np.random.rand(dimension).astype('float32')\n",
|
||||
"\n",
|
||||
"# Search for similar vectors\n",
|
||||
"results = store.search_vectors(query_vector, k=10)\n",
|
||||
"# Create indexer \n",
|
||||
"indexer = VectorIndexer(backend=\"faiss\", dimension=dimension) \n",
|
||||
"\n",
|
||||
"print(f\"Found {len(results)} similar vectors\")\n",
|
||||
"print(\"\\nTop 5 results:\")\n",
|
||||
"for i, result in enumerate(results[:5], 1):\n",
|
||||
" print(f\"{i}. ID: {result['id']}, Score: {result['score']:.3f}\")\n",
|
||||
" print(f\" Metadata: {result.get('metadata', {})}\")"
|
||||
"# Create HNSW index for fast approximate search \n",
|
||||
"adapter = FAISSStore(dimension=dimension) \n",
|
||||
"index = adapter.create_index(index_type=\"hnsw\", metric=\"L2\", m=16) \n",
|
||||
"\n",
|
||||
"# Add vectors to index \n",
|
||||
"vectors_array = np.array(vectors).astype('float32') \n",
|
||||
"# FIX: Removed 'index' argument. The adapter uses its internal self.index \n",
|
||||
"adapter.add_vectors(vectors_array, ids=vector_ids) \n",
|
||||
"\n",
|
||||
"# Search using index \n",
|
||||
"query_array = np.array(query_vector).astype('float32') \n",
|
||||
"# FIX: Call search on the 'index' object directly, not the adapter \n",
|
||||
"distances, indices = index.search(query_array.reshape(1, -1), k=10) \n",
|
||||
"\n",
|
||||
"print(f\"Index search found {len(indices[0])} results\") \n",
|
||||
"print(f\"Distances: {distances[0][:5]}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -156,29 +228,41 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Index search found 10 results\n",
|
||||
"Distances: [0. 0.59663105 0.6359793 0.66132385 0.6909249 ]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.vector_store import VectorIndexer, FAISSAdapter\n",
|
||||
"from semantica.vector_store import VectorIndexer, FAISSStore\n",
|
||||
"\n",
|
||||
"# Get dimension from vectors to ensure consistency\n",
|
||||
"dimension = len(vectors[0]) if len(vectors) > 0 else 384\n",
|
||||
"\n",
|
||||
"# Create indexer\n",
|
||||
"indexer = VectorIndexer(backend=\"faiss\", dimension=768)\n",
|
||||
"indexer = VectorIndexer(backend=\"faiss\", dimension=dimension)\n",
|
||||
"\n",
|
||||
"# Create HNSW index for fast approximate search\n",
|
||||
"adapter = FAISSAdapter(dimension=768)\n",
|
||||
"adapter = FAISSStore(dimension=dimension)\n",
|
||||
"index = adapter.create_index(index_type=\"hnsw\", metric=\"L2\", m=16)\n",
|
||||
"\n",
|
||||
"# Add vectors to index\n",
|
||||
"vectors_array = np.array(vectors).astype('float32')\n",
|
||||
"adapter.add_vectors(index, vectors_array, ids=vector_ids)\n",
|
||||
"adapter.add_vectors(vectors_array, ids=vector_ids)\n",
|
||||
"\n",
|
||||
"# Search using index\n",
|
||||
"query_array = query_vector.astype('float32')\n",
|
||||
"distances, indices = adapter.search(index, query_array, k=10)\n",
|
||||
"distances, indices = index.search(query_array.reshape(1, -1), k=10)\n",
|
||||
"\n",
|
||||
"print(f\"Index search found {len(indices)} results\")\n",
|
||||
"print(f\"Distances: {distances[:5]}\")"
|
||||
"print(f\"Index search found {len(indices[0])} results\")\n",
|
||||
"print(f\"Distances: {distances[0][:5]}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -198,35 +282,55 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Hybrid search found 10 results\n",
|
||||
"\n",
|
||||
"Filtered results (science, year > 2021):\n",
|
||||
"1. Category: science, Year: 2020, Score: 1.000\n",
|
||||
"2. Category: technology, Year: 2021, Score: 0.702\n",
|
||||
"3. Category: science, Year: 2022, Score: 0.682\n",
|
||||
"4. Category: technology, Year: 2023, Score: 0.669\n",
|
||||
"5. Category: science, Year: 2022, Score: 0.655\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.vector_store import HybridSearch, MetadataFilter\n",
|
||||
"from semantica.vector_store import HybridSearch, MetadataFilter \n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"# Create hybrid search\n",
|
||||
"hybrid_search = HybridSearch()\n",
|
||||
"# Create hybrid search \n",
|
||||
"hybrid_search = HybridSearch() \n",
|
||||
"\n",
|
||||
"# Create metadata filter\n",
|
||||
"# Create metadata filter \n",
|
||||
"filter = MetadataFilter() \\\n",
|
||||
" .eq(\"category\", \"science\") \\\n",
|
||||
" .gt(\"year\", 2021)\n",
|
||||
" .gt(\"year\", 2021) \n",
|
||||
"\n",
|
||||
"# Perform hybrid search\n",
|
||||
"hybrid_results = hybrid_search.search(\n",
|
||||
" query_vector,\n",
|
||||
" vectors,\n",
|
||||
" metadata,\n",
|
||||
" vector_ids,\n",
|
||||
" filter=filter,\n",
|
||||
" k=10\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(f\"Hybrid search found {len(hybrid_results)} results\")\n",
|
||||
"print(\"\\nFiltered results (science, year > 2021):\")\n",
|
||||
"for i, result in enumerate(hybrid_results[:5], 1):\n",
|
||||
" meta = result.get('metadata', {})\n",
|
||||
" print(f\"{i}. Category: {meta.get('category')}, Year: {meta.get('year')}, Score: {result['score']:.3f}\")"
|
||||
"# Perform hybrid search \n",
|
||||
"# Ensure vectors and metadata are available\n",
|
||||
"if 'vectors' not in locals() or 'metadata' not in locals() or 'vector_ids' not in locals():\n",
|
||||
" print(\"Warning: vectors, metadata, or vector_ids are missing. Please run previous cells.\")\n",
|
||||
"else:\n",
|
||||
" hybrid_results = hybrid_search.search( \n",
|
||||
" query_vector, \n",
|
||||
" vectors, \n",
|
||||
" metadata, \n",
|
||||
" vector_ids, \n",
|
||||
" filter=filter, \n",
|
||||
" k=10 \n",
|
||||
" ) \n",
|
||||
" \n",
|
||||
" print(f\"Hybrid search found {len(hybrid_results)} results\") \n",
|
||||
" print(\"\\nFiltered results (science, year > 2021):\") \n",
|
||||
" for i, result in enumerate(hybrid_results[:5], 1): \n",
|
||||
" meta = result.get('metadata', {}) \n",
|
||||
" print(f\"{i}. Category: {meta.get('category')}, Year: {meta.get('year')}, Score: {result['score']:.3f}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -247,9 +351,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Found 5 vectors with category='science'\n",
|
||||
"\n",
|
||||
"Metadata validation: True\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.vector_store import MetadataStore, MetadataSchema\n",
|
||||
"\n",
|
||||
@@ -296,9 +410,21 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Fused results using RRF:\n",
|
||||
"1. ID: vec_2, Fused Score: 0.033\n",
|
||||
"2. ID: vec_1, Fused Score: 0.032\n",
|
||||
"3. ID: vec_4, Fused Score: 0.016\n",
|
||||
"4. ID: vec_3, Fused Score: 0.016\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.vector_store import SearchRanker\n",
|
||||
"\n",
|
||||
@@ -343,9 +469,21 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Tenant 1: 5 vectors\n",
|
||||
"Tenant 2: 5 vectors\n",
|
||||
"\n",
|
||||
"User1 can write: True\n",
|
||||
"User2 can write: False\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.vector_store import NamespaceManager\n",
|
||||
"\n",
|
||||
@@ -380,66 +518,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 8: Convenience Functions\n",
|
||||
"\n",
|
||||
"Use convenience functions for quick operations.\n",
|
||||
"\n",
|
||||
"### Available Functions\n",
|
||||
"\n",
|
||||
"- `store_vectors()`: Store vectors\n",
|
||||
"- `search_vectors()`: Search vectors\n",
|
||||
"- `hybrid_search()`: Hybrid search\n",
|
||||
"- `update_vectors()`: Update vectors\n",
|
||||
"- `delete_vectors()`: Delete vectors"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import (\n",
|
||||
" store_vectors,\n",
|
||||
" search_vectors,\n",
|
||||
" hybrid_search as hybrid_search_func,\n",
|
||||
" update_vectors,\n",
|
||||
" delete_vectors\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Store vectors using convenience function\n",
|
||||
"new_vectors = [np.random.rand(768) for _ in range(10)]\n",
|
||||
"new_metadata = [{\"text\": f\"New doc {i}\"} for i in range(10)]\n",
|
||||
"new_ids = store_vectors(new_vectors, metadata=new_metadata, method=\"default\")\n",
|
||||
"\n",
|
||||
"print(f\"Stored {len(new_ids)} new vectors\")\n",
|
||||
"\n",
|
||||
"# Search using convenience function\n",
|
||||
"search_results = search_vectors(\n",
|
||||
" query_vector,\n",
|
||||
" new_vectors,\n",
|
||||
" new_ids,\n",
|
||||
" k=5,\n",
|
||||
" method=\"default\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(f\"Search found {len(search_results)} results\")\n",
|
||||
"\n",
|
||||
"# Update vectors\n",
|
||||
"updated_vectors = [np.random.rand(768) for _ in range(2)]\n",
|
||||
"success = update_vectors(new_ids[:2], updated_vectors, method=\"default\")\n",
|
||||
"print(f\"\\nUpdated vectors: {success}\")\n",
|
||||
"\n",
|
||||
"# Delete vectors\n",
|
||||
"success = delete_vectors(new_ids[-2:], method=\"default\")\n",
|
||||
"print(f\"Deleted vectors: {success}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 9: Multi-Backend Support\n",
|
||||
"## Step 8: Multi-Backend Support\n",
|
||||
"\n",
|
||||
"Work with different vector store backends.\n",
|
||||
"\n",
|
||||
@@ -453,40 +532,11 @@
|
||||
"| Milvus | Cloud/Self-hosted | Large scale |"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.vector_store import FAISSAdapter, VectorManager\n",
|
||||
"\n",
|
||||
"# FAISS (local)\n",
|
||||
"faiss_adapter = FAISSAdapter(dimension=768)\n",
|
||||
"faiss_index = faiss_adapter.create_index(index_type=\"flat\", metric=\"L2\")\n",
|
||||
"print(\"Created FAISS index\")\n",
|
||||
"\n",
|
||||
"# Vector Manager for multi-store management\n",
|
||||
"manager = VectorManager()\n",
|
||||
"faiss_store = manager.create_store(\"faiss\", {\"dimension\": 768})\n",
|
||||
"print(f\"\\nCreated store via manager\")\n",
|
||||
"\n",
|
||||
"# List all stores\n",
|
||||
"stores = manager.list_stores()\n",
|
||||
"print(f\"Active stores: {stores}\")\n",
|
||||
"\n",
|
||||
"# Note: For cloud/remote backends (Weaviate, Qdrant, etc.),\n",
|
||||
"# you would need API keys and endpoints\n",
|
||||
"# Example:\n",
|
||||
"# from semantica.vector_store import WeaviateAdapter\n",
|
||||
"# weaviate = WeaviateAdapter(url=\"http://localhost:8080\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 10: Best Practices\n",
|
||||
"## Step 9: Best Practices\n",
|
||||
"\n",
|
||||
"### Performance Tips\n",
|
||||
"\n",
|
||||
@@ -566,9 +616,9 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.0"
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
|
||||
+3467
-540
File diff suppressed because it is too large
Load Diff
@@ -76,9 +76,245 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Requirement already satisfied: semantica in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.0.5)\n",
|
||||
"Requirement already satisfied: numpy>=1.21.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.26.4)\n",
|
||||
"Requirement already satisfied: pandas>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.1.4)\n",
|
||||
"Requirement already satisfied: scikit-learn>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.6.1)\n",
|
||||
"Requirement already satisfied: spacy>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.8.11)\n",
|
||||
"Requirement already satisfied: transformers>=4.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.53.2)\n",
|
||||
"Requirement already satisfied: torch>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.2.1)\n",
|
||||
"Requirement already satisfied: sentence-transformers>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.2.1)\n",
|
||||
"Requirement already satisfied: rdflib>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.0)\n",
|
||||
"Requirement already satisfied: networkx>=2.8.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.5)\n",
|
||||
"Requirement already satisfied: matplotlib>=3.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.10.1)\n",
|
||||
"Requirement already satisfied: seaborn>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.13.2)\n",
|
||||
"Requirement already satisfied: plotly>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.17.0)\n",
|
||||
"Requirement already satisfied: requests>=2.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.32.5)\n",
|
||||
"Requirement already satisfied: beautifulsoup4>=4.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.12.3)\n",
|
||||
"Requirement already satisfied: lxml>=4.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.2)\n",
|
||||
"Requirement already satisfied: pypdf2>=2.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: python-docx>=0.8.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: openpyxl>=3.0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.1.5)\n",
|
||||
"Requirement already satisfied: pillow>=9.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (10.4.0)\n",
|
||||
"Requirement already satisfied: librosa>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.11.0)\n",
|
||||
"Requirement already satisfied: opencv-python>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.9.0.80)\n",
|
||||
"Requirement already satisfied: faiss-cpu>=1.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.9.0)\n",
|
||||
"Requirement already satisfied: weaviate-client>=3.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.18.1)\n",
|
||||
"Requirement already satisfied: qdrant-client>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.12.2)\n",
|
||||
"Requirement already satisfied: neo4j>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.3)\n",
|
||||
"Requirement already satisfied: falkordb>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.2.2)\n",
|
||||
"Requirement already satisfied: pymongo>=4.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.15.4)\n",
|
||||
"Requirement already satisfied: sqlalchemy>=1.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.0.23)\n",
|
||||
"Requirement already satisfied: psycopg2-binary>=2.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.9.9)\n",
|
||||
"Requirement already satisfied: pymysql>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.2)\n",
|
||||
"Requirement already satisfied: redis>=4.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.4.0)\n",
|
||||
"Requirement already satisfied: celery>=5.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.3.4)\n",
|
||||
"Requirement already satisfied: kafka-python>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.3.0)\n",
|
||||
"Requirement already satisfied: pulsar-client>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (3.3.0)\n",
|
||||
"Requirement already satisfied: pika>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: boto3>=1.24.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.36.0)\n",
|
||||
"Requirement already satisfied: azure-storage-blob>=12.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (12.27.1)\n",
|
||||
"Requirement already satisfied: google-cloud-storage>=2.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.18.2)\n",
|
||||
"Requirement already satisfied: pydantic>=1.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (2.12.3)\n",
|
||||
"Requirement already satisfied: click>=8.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (8.2.1)\n",
|
||||
"Requirement already satisfied: rich>=12.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (13.7.1)\n",
|
||||
"Requirement already satisfied: tqdm>=4.64.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.67.1)\n",
|
||||
"Requirement already satisfied: pyyaml>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: toml>=0.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.10.2)\n",
|
||||
"Requirement already satisfied: python-dotenv>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: loguru>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.7.3)\n",
|
||||
"Requirement already satisfied: structlog>=22.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (24.4.0)\n",
|
||||
"Requirement already satisfied: prometheus-client>=0.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.18.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-api>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-sdk>=1.12.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.38.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-instrumentation in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: fastapi>=0.78.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.120.4)\n",
|
||||
"Requirement already satisfied: uvicorn>=0.18.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.38.0)\n",
|
||||
"Requirement already satisfied: pytest>=7.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.4.3)\n",
|
||||
"Requirement already satisfied: pytest-cov>=3.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.0.0)\n",
|
||||
"Requirement already satisfied: pytest-asyncio>=0.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (0.21.1)\n",
|
||||
"Requirement already satisfied: black>=22.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (23.11.0)\n",
|
||||
"Requirement already satisfied: isort>=5.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (5.12.0)\n",
|
||||
"Requirement already satisfied: flake8>=4.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (7.3.0)\n",
|
||||
"Requirement already satisfied: mypy>=0.971 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pre-commit>=2.19.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from semantica) (4.4.0)\n",
|
||||
"Requirement already satisfied: azure-core>=1.30.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (1.35.0)\n",
|
||||
"Requirement already satisfied: cryptography>=2.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (43.0.3)\n",
|
||||
"Requirement already satisfied: typing-extensions>=4.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (4.14.1)\n",
|
||||
"Requirement already satisfied: isodate>=0.6.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-storage-blob>=12.12.0->semantica) (0.7.2)\n",
|
||||
"Requirement already satisfied: six>=1.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from azure-core>=1.30.0->azure-storage-blob>=12.12.0->semantica) (1.16.0)\n",
|
||||
"Requirement already satisfied: soupsieve>1.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from beautifulsoup4>=4.11.0->semantica) (2.5)\n",
|
||||
"Requirement already satisfied: mypy-extensions>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (1.0.0)\n",
|
||||
"Requirement already satisfied: packaging>=22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (24.2)\n",
|
||||
"Requirement already satisfied: pathspec>=0.9.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (0.11.2)\n",
|
||||
"Requirement already satisfied: platformdirs>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from black>=22.6.0->semantica) (3.11.0)\n",
|
||||
"Requirement already satisfied: botocore<1.37.0,>=1.36.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.36.26)\n",
|
||||
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (1.0.1)\n",
|
||||
"Requirement already satisfied: s3transfer<0.12.0,>=0.11.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from boto3>=1.24.0->semantica) (0.11.3)\n",
|
||||
"Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (2.9.0.post0)\n",
|
||||
"Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from botocore<1.37.0,>=1.36.0->boto3>=1.24.0->semantica) (1.26.20)\n",
|
||||
"Requirement already satisfied: billiard<5.0,>=4.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (4.2.1)\n",
|
||||
"Requirement already satisfied: kombu<6.0,>=5.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.5.3)\n",
|
||||
"Requirement already satisfied: vine<6.0,>=5.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (5.1.0)\n",
|
||||
"Requirement already satisfied: click-didyoumean>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.1)\n",
|
||||
"Requirement already satisfied: click-repl>=0.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (0.3.0)\n",
|
||||
"Requirement already satisfied: click-plugins>=1.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (1.1.1)\n",
|
||||
"Requirement already satisfied: tzdata>=2022.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from celery>=5.2.0->semantica) (2025.2)\n",
|
||||
"Requirement already satisfied: colorama in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from click>=8.1.0->semantica) (0.4.6)\n",
|
||||
"Requirement already satisfied: amqp<6.0.0,>=5.1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from kombu<6.0,>=5.3.2->celery>=5.2.0->semantica) (5.3.1)\n",
|
||||
"Requirement already satisfied: prompt-toolkit>=3.0.36 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from click-repl>=0.2.0->celery>=5.2.0->semantica) (3.0.40)\n",
|
||||
"Requirement already satisfied: cffi>=1.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (1.17.1)\n",
|
||||
"Requirement already satisfied: pycparser in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from cffi>=1.12->cryptography>=2.1.4->azure-storage-blob>=12.12.0->semantica) (2.22)\n",
|
||||
"Requirement already satisfied: starlette<0.50.0,>=0.40.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.46.2)\n",
|
||||
"Requirement already satisfied: annotated-doc>=0.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from fastapi>=0.78.0->semantica) (0.0.3)\n",
|
||||
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pydantic-core==2.41.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (2.41.4)\n",
|
||||
"Requirement already satisfied: typing-inspection>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic>=1.10.0->semantica) (0.4.2)\n",
|
||||
"Requirement already satisfied: anyio<5,>=3.6.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (4.11.0)\n",
|
||||
"Requirement already satisfied: idna>=2.8 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (3.10)\n",
|
||||
"Requirement already satisfied: sniffio>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from anyio<5,>=3.6.2->starlette<0.50.0,>=0.40.0->fastapi>=0.78.0->semantica) (1.3.1)\n",
|
||||
"Requirement already satisfied: mccabe<0.8.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (0.7.0)\n",
|
||||
"Requirement already satisfied: pycodestyle<2.15.0,>=2.14.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (2.14.0)\n",
|
||||
"Requirement already satisfied: pyflakes<3.5.0,>=3.4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from flake8>=4.0.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: google-auth<3.0dev,>=2.26.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.36.0)\n",
|
||||
"Requirement already satisfied: google-api-core<3.0.0dev,>=2.15.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.23.0)\n",
|
||||
"Requirement already satisfied: google-cloud-core<3.0dev,>=2.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.4.1)\n",
|
||||
"Requirement already satisfied: google-resumable-media>=2.7.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (2.7.2)\n",
|
||||
"Requirement already satisfied: google-crc32c<2.0dev,>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-cloud-storage>=2.5.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.66.0)\n",
|
||||
"Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.19.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (4.25.8)\n",
|
||||
"Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-api-core<3.0.0dev,>=2.15.0->google-cloud-storage>=2.5.0->semantica) (1.25.0)\n",
|
||||
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (5.5.2)\n",
|
||||
"Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.4.1)\n",
|
||||
"Requirement already satisfied: rsa<5,>=3.1.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (4.9)\n",
|
||||
"Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (3.4.0)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.28.0->semantica) (2025.8.3)\n",
|
||||
"Requirement already satisfied: pyasn1>=0.1.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rsa<5,>=3.1.4->google-auth<3.0dev,>=2.26.1->google-cloud-storage>=2.5.0->semantica) (0.6.1)\n",
|
||||
"Requirement already satisfied: audioread>=2.1.9 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (3.0.1)\n",
|
||||
"Requirement already satisfied: numba>=0.51.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.61.2)\n",
|
||||
"Requirement already satisfied: scipy>=1.6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.15.2)\n",
|
||||
"Requirement already satisfied: joblib>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: decorator>=4.3.0 in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from librosa>=0.9.0->semantica) (5.1.1)\n",
|
||||
"Requirement already satisfied: soundfile>=0.12.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.13.1)\n",
|
||||
"Requirement already satisfied: pooch>=1.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.8.2)\n",
|
||||
"Requirement already satisfied: soxr>=0.3.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.5.0.post1)\n",
|
||||
"Requirement already satisfied: lazy_loader>=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (0.4)\n",
|
||||
"Requirement already satisfied: msgpack>=1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from librosa>=0.9.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: win32-setctime>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from loguru>=0.6.0->semantica) (1.1.0)\n",
|
||||
"Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.3.2)\n",
|
||||
"Requirement already satisfied: cycler>=0.10 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (0.12.1)\n",
|
||||
"Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (4.57.0)\n",
|
||||
"Requirement already satisfied: kiwisolver>=1.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (1.4.8)\n",
|
||||
"Requirement already satisfied: pyparsing>=2.3.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from matplotlib>=3.5.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: pytz in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from neo4j>=5.0.0->semantica) (2024.2)\n",
|
||||
"Requirement already satisfied: llvmlite<0.45,>=0.44.0dev0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from numba>=0.51.0->librosa>=0.9.0->semantica) (0.44.0)\n",
|
||||
"Requirement already satisfied: et-xmlfile in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from openpyxl>=3.0.10->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-api>=1.12.0->semantica) (6.8.0)\n",
|
||||
"Requirement already satisfied: zipp>=0.5 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api>=1.12.0->semantica) (3.17.0)\n",
|
||||
"Requirement already satisfied: opentelemetry-semantic-conventions==0.59b0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from opentelemetry-sdk>=1.12.0->semantica) (0.59b0)\n",
|
||||
"Requirement already satisfied: tenacity>=6.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from plotly>=5.10.0->semantica) (8.5.0)\n",
|
||||
"Requirement already satisfied: cfgv>=2.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (3.5.0)\n",
|
||||
"Requirement already satisfied: identify>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (2.6.15)\n",
|
||||
"Requirement already satisfied: nodeenv>=0.11.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (1.9.1)\n",
|
||||
"Requirement already satisfied: virtualenv>=20.10.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pre-commit>=2.19.0->semantica) (20.24.6)\n",
|
||||
"Requirement already satisfied: wcwidth in c:\\users\\mohd kaif\\appdata\\roaming\\python\\python311\\site-packages (from prompt-toolkit>=3.0.36->click-repl>=0.2.0->celery>=5.2.0->semantica) (0.2.9)\n",
|
||||
"Requirement already satisfied: dnspython<3.0.0,>=1.16.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pymongo>=4.2.0->semantica) (2.4.2)\n",
|
||||
"Requirement already satisfied: iniconfig in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (2.0.0)\n",
|
||||
"Requirement already satisfied: pluggy<2.0,>=0.12 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pytest>=7.1.0->semantica) (1.5.0)\n",
|
||||
"Requirement already satisfied: coverage>=7.10.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from coverage[toml]>=7.10.6->pytest-cov>=3.0.0->semantica) (7.12.0)\n",
|
||||
"Requirement already satisfied: grpcio>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.68.0)\n",
|
||||
"Requirement already satisfied: grpcio-tools>=1.41.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (1.62.3)\n",
|
||||
"Requirement already satisfied: httpx>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.28.1)\n",
|
||||
"Requirement already satisfied: portalocker<3.0.0,>=2.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from qdrant-client>=1.3.0->semantica) (2.10.1)\n",
|
||||
"Requirement already satisfied: pywin32>=226 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from portalocker<3.0.0,>=2.7.0->qdrant-client>=1.3.0->semantica) (311)\n",
|
||||
"Requirement already satisfied: setuptools in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from grpcio-tools>=1.41.0->qdrant-client>=1.3.0->semantica) (80.9.0)\n",
|
||||
"Requirement already satisfied: httpcore==1.* in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (1.0.9)\n",
|
||||
"Requirement already satisfied: h11>=0.16 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpcore==1.*->httpx>=0.20.0->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (0.16.0)\n",
|
||||
"Requirement already satisfied: h2<5,>=3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.1.0)\n",
|
||||
"Requirement already satisfied: hyperframe<7,>=6.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (6.0.1)\n",
|
||||
"Requirement already satisfied: hpack<5,>=4.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from h2<5,>=3->httpx[http2]>=0.20.0->qdrant-client>=1.3.0->semantica) (4.0.0)\n",
|
||||
"Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (3.0.0)\n",
|
||||
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from rich>=12.5.0->semantica) (2.19.2)\n",
|
||||
"Requirement already satisfied: mdurl~=0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from markdown-it-py>=2.2.0->rich>=12.5.0->semantica) (0.1.2)\n",
|
||||
"Requirement already satisfied: threadpoolctl>=3.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from scikit-learn>=1.0.0->semantica) (3.2.0)\n",
|
||||
"Requirement already satisfied: huggingface-hub>=0.20.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sentence-transformers>=2.2.0->semantica) (0.30.2)\n",
|
||||
"Requirement already satisfied: filelock in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (3.16.1)\n",
|
||||
"Requirement already satisfied: regex!=2019.12.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (2024.11.6)\n",
|
||||
"Requirement already satisfied: tokenizers<0.22,>=0.21 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.21.4)\n",
|
||||
"Requirement already satisfied: safetensors>=0.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from transformers>=4.20.0->semantica) (0.5.3)\n",
|
||||
"Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers>=2.2.0->semantica) (2023.10.0)\n",
|
||||
"Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.5)\n",
|
||||
"Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.0.15)\n",
|
||||
"Requirement already satisfied: cymem<2.1.0,>=2.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.13)\n",
|
||||
"Requirement already satisfied: preshed<3.1.0,>=3.0.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.0.12)\n",
|
||||
"Requirement already satisfied: thinc<8.4.0,>=8.3.4 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (8.3.10)\n",
|
||||
"Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (1.1.3)\n",
|
||||
"Requirement already satisfied: srsly<3.0.0,>=2.4.3 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.5.2)\n",
|
||||
"Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (2.0.10)\n",
|
||||
"Requirement already satisfied: weasel<0.5.0,>=0.4.2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.4.3)\n",
|
||||
"Requirement already satisfied: typer-slim<1.0.0,>=0.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (0.20.0)\n",
|
||||
"Requirement already satisfied: jinja2 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy>=3.4.0->semantica) (3.1.6)\n",
|
||||
"Requirement already satisfied: blis<1.4.0,>=1.3.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (1.3.3)\n",
|
||||
"Requirement already satisfied: confection<1.0.0,>=0.0.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.4.0,>=8.3.4->spacy>=3.4.0->semantica) (0.1.5)\n",
|
||||
"Requirement already satisfied: cloudpathlib<1.0.0,>=0.7.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (0.23.0)\n",
|
||||
"Requirement already satisfied: smart-open<8.0.0,>=5.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (7.1.0)\n",
|
||||
"Requirement already satisfied: wrapt in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from smart-open<8.0.0,>=5.2.1->weasel<0.5.0,>=0.4.2->spacy>=3.4.0->semantica) (1.17.2)\n",
|
||||
"Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sqlalchemy>=1.4.0->semantica) (3.2.3)\n",
|
||||
"Requirement already satisfied: sympy in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from torch>=1.12.0->semantica) (1.13.3)\n",
|
||||
"Requirement already satisfied: distlib<1,>=0.3.7 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from virtualenv>=20.10.0->pre-commit>=2.19.0->semantica) (0.3.7)\n",
|
||||
"Requirement already satisfied: validators<1.0.0,>=0.34.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (0.35.0)\n",
|
||||
"Requirement already satisfied: authlib<2.0.0,>=1.2.1 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (1.6.0)\n",
|
||||
"Requirement already satisfied: deprecation<3.0.0,>=2.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from weaviate-client>=3.15.0->semantica) (2.1.0)\n",
|
||||
"Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from jinja2->spacy>=3.4.0->semantica) (2.1.3)\n",
|
||||
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\mohd kaif\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from sympy->torch>=1.12.0->semantica) (1.3.0)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install semantica"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>🔄</td><td>Semantica is building</td><td>🧠 kg</td><td>EntityResolver</td><td>-</td><td>762.30s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>DuplicateDetector</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is resolving</td><td>⚠️ conflicts</td><td>ConflictDetector</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is exporting</td><td>💾 export</td><td>JSONExporter</td><td>output.json</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is exporting</td><td>💾 export</td><td>RDFExporter</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is exporting</td><td>💾 export</td><td>GraphExporter</td><td>output.graphml</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is generating</td><td>📚 ontology</td><td>OntologyGenerator</td><td>-</td><td>0.04s</td></tr><tr><td>✅</td><td>Semantica is generating</td><td>📚 ontology</td><td>ClassInferrer</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is generating</td><td>📚 ontology</td><td>PropertyGenerator</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is exporting</td><td>💾 export</td><td>OWLExporter</td><td>output.owl</td><td>0.01s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.export import JSONExporter\n",
|
||||
"from semantica.kg import GraphBuilder\n",
|
||||
@@ -114,7 +350,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -156,7 +392,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -166,7 +402,7 @@
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"\n",
|
||||
"# Export to RDF format (Turtle by default)\n",
|
||||
"rdf_exporter.export_knowledge_graph(kg, \"output.ttl\", format=\"turtle\")\n"
|
||||
"rdf_exporter.export(kg, \"output.ttl\", format=\"turtle\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -189,7 +425,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -237,10 +473,14 @@
|
||||
"generator = OntologyGenerator()\n",
|
||||
"\n",
|
||||
"# Generate ontology from entities and relationships\n",
|
||||
"ontology = generator.generate(entities, relationships)\n",
|
||||
"# Note: Pass data as a dictionary to generate_ontology\n",
|
||||
"ontology = generator.generate_ontology({\n",
|
||||
" \"entities\": entities,\n",
|
||||
" \"relationships\": relationships\n",
|
||||
"})\n",
|
||||
"\n",
|
||||
"# Export ontology to OWL\n",
|
||||
"owl_exporter.export(ontology, \"output.owl\")\n"
|
||||
"owl_exporter.export(ontology, \"output.owl\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -295,24 +535,6 @@
|
||||
"- `json` - JSON report\n",
|
||||
"- `text` - Plain text report\n",
|
||||
"\n",
|
||||
"## Step 7: Method Registry\n",
|
||||
"\n",
|
||||
"Register and use custom export methods using the MethodRegistry system:\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"from semantica.export import MethodRegistry, method_registry, JSONExporter\n",
|
||||
"\n",
|
||||
"# Register custom method\n",
|
||||
"def my_custom_export(data, file_path, **kwargs):\n",
|
||||
" # Custom export logic\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
"MethodRegistry.register(\"json\", \"custom\", my_custom_export)\n",
|
||||
"\n",
|
||||
"# List available methods\n",
|
||||
"methods = method_registry.list_all()\n",
|
||||
"print(methods)\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
@@ -348,8 +570,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,604 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/introduction/18_Conflict_Detection.ipynb)\n",
|
||||
"\n",
|
||||
"# Conflict Detection\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook demonstrates how to detect and resolve conflicts in knowledge graphs using Semantica's conflict modules. You'll learn to use `ConflictDetector`, `SourceTracker`, and `ConflictResolver`.\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/conflicts/)\n",
|
||||
"\n",
|
||||
"### Learning Objectives\n",
|
||||
"\n",
|
||||
"- Use `ConflictDetector` to detect conflicts\n",
|
||||
"- Use `SourceTracker` to track data sources\n",
|
||||
"- Use `ConflictResolver` to resolve conflicts\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install Semantica from PyPI:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"# Or with all optional dependencies:\n",
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Step 1: Conflict Detection\n",
|
||||
"\n",
|
||||
"Detect conflicts in entities.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
"from datetime import datetime\n",
|
||||
"\n",
|
||||
"# Initialize detector with configuration\n",
|
||||
"detector = ConflictDetector(\n",
|
||||
" confidence_threshold=0.7,\n",
|
||||
" track_provenance=True,\n",
|
||||
" conflict_fields={\"Company\": [\"name\", \"founded\", \"revenue\"]}\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Sample entities from multiple sources\n",
|
||||
"entities = [\n",
|
||||
" {\"id\": \"e1\", \"name\": \"Apple Inc.\", \"founded\": 1976, \"type\": \"Company\", \n",
|
||||
" \"source\": \"wikipedia\", \"confidence\": 0.9},\n",
|
||||
" {\"id\": \"e1\", \"name\": \"Apple Incorporated\", \"founded\": 1976, \"type\": \"Company\",\n",
|
||||
" \"source\": \"official_site\", \"confidence\": 0.95},\n",
|
||||
" {\"id\": \"e1\", \"name\": \"Apple Inc.\", \"founded\": 1977, \"type\": \"Company\",\n",
|
||||
" \"source\": \"news\", \"confidence\": 0.7},\n",
|
||||
" {\"id\": \"e2\", \"name\": \"Microsoft\", \"type\": \"Company\", \"founded\": 1975, \"source\": \"source1\"},\n",
|
||||
" {\"id\": \"e2\", \"name\": \"Microsoft Corporation\", \"type\": \"Organization\", \n",
|
||||
" \"founded\": 1975, \"source\": \"source2\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# 1.1 Value Conflict Detection\n",
|
||||
"value_conflicts = detector.detect_value_conflicts(entities, \"name\")\n",
|
||||
"\n",
|
||||
"# 1.2 Type Conflict Detection\n",
|
||||
"type_conflicts = detector.detect_type_conflicts(entities)\n",
|
||||
"\n",
|
||||
"# 1.3 Temporal Conflict Detection\n",
|
||||
"temporal_conflicts = detector.detect_temporal_conflicts(entities)\n",
|
||||
"\n",
|
||||
"# 1.4 Logical Conflict Detection\n",
|
||||
"logical_entities = [\n",
|
||||
" {\"id\": \"e3\", \"type\": \"Person\", \"name\": \"John Doe\", \"source\": \"source1\"},\n",
|
||||
" {\"id\": \"e3\", \"type\": \"Organization\", \"name\": \"John Doe\", \"source\": \"source2\"},\n",
|
||||
"]\n",
|
||||
"logical_conflicts = detector.detect_logical_conflicts(logical_entities)\n",
|
||||
"\n",
|
||||
"# 1.5 Relationship Conflict Detection\n",
|
||||
"relationships = [\n",
|
||||
" {\"id\": \"rel1\", \"source_id\": \"e1\", \"target_id\": \"e2\", \"type\": \"competes_with\", \"source\": \"source1\"},\n",
|
||||
" {\"id\": \"rel1\", \"source_id\": \"e1\", \"target_id\": \"e2\", \"type\": \"partners_with\", \"source\": \"source2\"},\n",
|
||||
"]\n",
|
||||
"rel_conflicts = detector.detect_relationship_conflicts(relationships)\n",
|
||||
"\n",
|
||||
"# 1.6 General Conflict Detection (all types)\n",
|
||||
"all_conflicts = detector.detect_conflicts(entities)\n",
|
||||
"\n",
|
||||
"# Get conflict report\n",
|
||||
"report = detector.get_conflict_report()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 2: Source Tracking\n",
|
||||
"\n",
|
||||
"Track data sources.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.conflicts import SourceTracker, SourceReference\n",
|
||||
"from datetime import datetime\n",
|
||||
"\n",
|
||||
"# Initialize source tracker\n",
|
||||
"tracker = SourceTracker()\n",
|
||||
"\n",
|
||||
"# Create source references with metadata\n",
|
||||
"source1 = SourceReference(\n",
|
||||
" document=\"wikipedia\",\n",
|
||||
" page=1,\n",
|
||||
" section=\"Company Information\",\n",
|
||||
" timestamp=datetime(2023, 1, 15),\n",
|
||||
" confidence=0.9\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"source2 = SourceReference(\n",
|
||||
" document=\"official_site\",\n",
|
||||
" section=\"About Us\",\n",
|
||||
" timestamp=datetime(2023, 3, 20),\n",
|
||||
" confidence=0.95\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Track property sources\n",
|
||||
"tracker.track_property_source(\"e1\", \"name\", \"Apple Inc.\", source1)\n",
|
||||
"tracker.track_property_source(\"e1\", \"name\", \"Apple Incorporated\", source2)\n",
|
||||
"tracker.track_property_source(\"e1\", \"founded\", 1976, source1)\n",
|
||||
"\n",
|
||||
"# Track entity sources\n",
|
||||
"tracker.track_entity_source(\"e1\", source1)\n",
|
||||
"\n",
|
||||
"# Set source credibility scores\n",
|
||||
"tracker.set_source_credibility(\"wikipedia\", 0.85)\n",
|
||||
"tracker.set_source_credibility(\"official_site\", 0.95)\n",
|
||||
"\n",
|
||||
"# Retrieve property sources\n",
|
||||
"prop_source = tracker.get_property_sources(\"e1\", \"name\")\n",
|
||||
"\n",
|
||||
"# Get entity sources\n",
|
||||
"entity_sources = tracker.get_entity_sources(\"e1\")\n",
|
||||
"\n",
|
||||
"# Get all source credibilities\n",
|
||||
"all_credibilities = tracker.get_all_source_credibilities()\n",
|
||||
"\n",
|
||||
"# Generate traceability chain\n",
|
||||
"chain = tracker.generate_traceability_chain(\"e1\", \"name\")\n",
|
||||
"\n",
|
||||
"# Generate source report\n",
|
||||
"report = tracker.generate_source_report(\"e1\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Conflict Resolution\n",
|
||||
"\n",
|
||||
"Resolve conflicts using ConflictResolver.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.conflicts import ConflictResolver\n",
|
||||
"\n",
|
||||
"# Initialize resolver with source tracker\n",
|
||||
"resolver = ConflictResolver(\n",
|
||||
" default_strategy=\"voting\",\n",
|
||||
" source_tracker=tracker\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Resolve conflicts using different strategies\n",
|
||||
"if value_conflicts:\n",
|
||||
" # Voting strategy\n",
|
||||
" voting_results = resolver.resolve_conflicts(value_conflicts, strategy=\"voting\")\n",
|
||||
" \n",
|
||||
" # Credibility-weighted strategy\n",
|
||||
" credibility_results = resolver.resolve_conflicts(value_conflicts, strategy=\"credibility_weighted\")\n",
|
||||
" \n",
|
||||
" # Most recent strategy\n",
|
||||
" recent_results = resolver.resolve_conflicts(value_conflicts, strategy=\"most_recent\")\n",
|
||||
" \n",
|
||||
" # Highest confidence strategy\n",
|
||||
" confidence_results = resolver.resolve_conflicts(value_conflicts, strategy=\"highest_confidence\")\n",
|
||||
" \n",
|
||||
" # First seen strategy\n",
|
||||
" first_seen_results = resolver.resolve_conflicts(value_conflicts, strategy=\"first_seen\")\n",
|
||||
" \n",
|
||||
" # Manual review strategy\n",
|
||||
" manual_results = resolver.resolve_conflicts(value_conflicts, strategy=\"manual_review\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"You've learned how to detect and resolve conflicts:\n",
|
||||
"\n",
|
||||
"- **ConflictDetector**: Detect conflicts in entities\n",
|
||||
"- **SourceTracker**: Track data sources\n",
|
||||
"- **ConflictResolver**: Resolve conflicts using various strategies\n",
|
||||
"\n",
|
||||
"Next: Learn about configuration in the Configuration notebook.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.conflicts import ConflictAnalyzer\n",
|
||||
"\n",
|
||||
"# Initialize analyzer\n",
|
||||
"analyzer = ConflictAnalyzer()\n",
|
||||
"\n",
|
||||
"# Comprehensive analysis\n",
|
||||
"analysis = analyzer.analyze_conflicts(all_conflicts)\n",
|
||||
"\n",
|
||||
"# Analysis by type, severity, and source\n",
|
||||
"by_type = analysis['by_type']['counts']\n",
|
||||
"by_severity = analysis['by_severity']['counts']\n",
|
||||
"by_source = analysis['by_source']['counts']\n",
|
||||
"\n",
|
||||
"# Top entities and properties\n",
|
||||
"top_entities = analysis['by_entity']['top_entities']\n",
|
||||
"top_properties = analysis['by_property']['top_properties']\n",
|
||||
"\n",
|
||||
"# Patterns and recommendations\n",
|
||||
"patterns = analysis['patterns']\n",
|
||||
"recommendations = analysis['recommendations']\n",
|
||||
"\n",
|
||||
"# Trend analysis\n",
|
||||
"trends = analyzer.analyze_trends(all_conflicts)\n",
|
||||
"\n",
|
||||
"# Generate insights report\n",
|
||||
"insights = analyzer.generate_insights_report(all_conflicts)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 5: Investigation Guides\n",
|
||||
"\n",
|
||||
"`InvestigationGuideGenerator` creates guides for manual review.\n",
|
||||
"\n",
|
||||
"**Guide Components:**\n",
|
||||
"- Conflict summary, investigation steps, recommended actions\n",
|
||||
"- Source information, context, severity assessment\n",
|
||||
"\n",
|
||||
"**Use Cases:** High-severity conflicts, ambiguous cases, compliance, QA workflows\n",
|
||||
"\n",
|
||||
"**Export Formats:** Markdown checklists, detailed reports, structured context\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.conflicts import InvestigationGuideGenerator\n",
|
||||
"\n",
|
||||
"# Initialize guide generator\n",
|
||||
"guide_generator = InvestigationGuideGenerator(source_tracker=tracker)\n",
|
||||
"\n",
|
||||
"# Generate guide for a conflict\n",
|
||||
"if value_conflicts:\n",
|
||||
" guide = guide_generator.generate_guide(value_conflicts[0])\n",
|
||||
"\n",
|
||||
"# Generate guides for multiple conflicts\n",
|
||||
"guides = guide_generator.generate_guides(value_conflicts[:3])\n",
|
||||
"\n",
|
||||
"# Export checklist\n",
|
||||
"checklist = guide_generator.export_investigation_checklist(guide, format=\"markdown\")\n",
|
||||
"\n",
|
||||
"# Generate conflict report\n",
|
||||
"conflict_report = guide_generator.generate_conflict_report(value_conflicts, format=\"detailed\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 6: Methods Module\n",
|
||||
"\n",
|
||||
"`semantica.conflicts.methods` provides convenience functions for functional-style access.\n",
|
||||
"\n",
|
||||
"**Functions:**\n",
|
||||
"- `detect_conflicts()`: Methods: `value`, `type`, `temporal`, `logical`, `relationship`\n",
|
||||
"- `resolve_conflicts()`: Methods: `voting`, `credibility_weighted`, `most_recent`, `highest_confidence`, `first_seen`, `manual_review`\n",
|
||||
"- `analyze_conflicts()`: Methods: `pattern`, `type`, `severity`, `source`, `trend`\n",
|
||||
"- `track_sources()`: Methods: `property`, `entity`, `relationship`\n",
|
||||
"- `generate_investigation_guide()`: Methods: `guide`, `checklist`, `context`\n",
|
||||
"- `list_available_methods()`: List all methods by task type\n",
|
||||
"- `get_conflict_method()`: Retrieve specific method function\n",
|
||||
"\n",
|
||||
"**Benefits:** Simpler API, method discovery, consistent interface, extensible\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.conflicts.methods import (\n",
|
||||
" detect_conflicts,\n",
|
||||
" resolve_conflicts,\n",
|
||||
" analyze_conflicts,\n",
|
||||
" track_sources,\n",
|
||||
" generate_investigation_guide,\n",
|
||||
" list_available_methods,\n",
|
||||
" get_conflict_method\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Detection methods\n",
|
||||
"value_conflicts_method = detect_conflicts(entities, method=\"value\", property_name=\"name\")\n",
|
||||
"type_conflicts_method = detect_conflicts(entities, method=\"type\")\n",
|
||||
"temporal_conflicts_method = detect_conflicts(entities, method=\"temporal\")\n",
|
||||
"logical_conflicts_method = detect_conflicts(logical_entities, method=\"logical\")\n",
|
||||
"\n",
|
||||
"# Resolution methods\n",
|
||||
"if value_conflicts_method:\n",
|
||||
" voting_results = resolve_conflicts(value_conflicts_method, method=\"voting\")\n",
|
||||
" credibility_results = resolve_conflicts(value_conflicts_method, method=\"credibility_weighted\")\n",
|
||||
"\n",
|
||||
"# Analysis methods\n",
|
||||
"pattern_analysis = analyze_conflicts(all_conflicts, method=\"pattern\")\n",
|
||||
"type_analysis = analyze_conflicts(all_conflicts, method=\"type\")\n",
|
||||
"severity_analysis = analyze_conflicts(all_conflicts, method=\"severity\")\n",
|
||||
"source_analysis = analyze_conflicts(all_conflicts, method=\"source\")\n",
|
||||
"trend_analysis = analyze_conflicts(all_conflicts, method=\"trend\")\n",
|
||||
"\n",
|
||||
"# Source tracking methods\n",
|
||||
"source_ref = SourceReference(document=\"test_source\", confidence=0.9)\n",
|
||||
"track_sources(\"e1\", method=\"property\", property_name=\"name\", value=\"Test\", source=source_ref)\n",
|
||||
"track_sources(\"e1\", method=\"entity\", source=source_ref)\n",
|
||||
"\n",
|
||||
"# Investigation guide methods\n",
|
||||
"if value_conflicts_method:\n",
|
||||
" guide_method = generate_investigation_guide(value_conflicts_method[0], method=\"guide\")\n",
|
||||
" checklist_method = generate_investigation_guide(value_conflicts_method[0], method=\"checklist\")\n",
|
||||
" context_method = generate_investigation_guide(value_conflicts_method[0], method=\"context\")\n",
|
||||
"\n",
|
||||
"# List available methods\n",
|
||||
"all_methods = list_available_methods()\n",
|
||||
"\n",
|
||||
"# Get specific method\n",
|
||||
"voting_method = get_conflict_method(\"resolution\", \"voting\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 7: Method Registry\n",
|
||||
"\n",
|
||||
"`method_registry` provides a plugin system for custom methods.\n",
|
||||
"\n",
|
||||
"**Registration:** Task type (`detection`, `resolution`, `analysis`, `tracking`, `investigation`), method name, function\n",
|
||||
"\n",
|
||||
"**Use Cases:**\n",
|
||||
"- Domain-specific resolution logic\n",
|
||||
"- External system integration\n",
|
||||
"- A/B testing strategies\n",
|
||||
"- ML model integration\n",
|
||||
"- Hybrid resolution approaches\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.conflicts import method_registry, ResolutionResult\n",
|
||||
"\n",
|
||||
"# Register custom resolution method\n",
|
||||
"def custom_resolution(conflicts, **kwargs):\n",
|
||||
" \"\"\"Custom resolution that always picks the first value.\"\"\"\n",
|
||||
" results = []\n",
|
||||
" for conflict in conflicts:\n",
|
||||
" if conflict.conflicting_values:\n",
|
||||
" result = ResolutionResult(\n",
|
||||
" conflict_id=conflict.conflict_id,\n",
|
||||
" resolved=True,\n",
|
||||
" resolved_value=conflict.conflicting_values[0],\n",
|
||||
" resolution_strategy=\"custom_first\",\n",
|
||||
" confidence=0.8,\n",
|
||||
" resolution_notes=\"Custom: Always use first value\"\n",
|
||||
" )\n",
|
||||
" results.append(result)\n",
|
||||
" return results\n",
|
||||
"\n",
|
||||
"# Register the custom method\n",
|
||||
"method_registry.register(\"resolution\", \"custom_first\", custom_resolution)\n",
|
||||
"\n",
|
||||
"# List registered methods\n",
|
||||
"registered = method_registry.list_all(\"resolution\")\n",
|
||||
"\n",
|
||||
"# Use custom method\n",
|
||||
"if value_conflicts:\n",
|
||||
" custom_results = resolve_conflicts(value_conflicts, method=\"custom_first\")\n",
|
||||
"\n",
|
||||
"# Unregister method\n",
|
||||
"method_registry.unregister(\"resolution\", \"custom_first\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 8: Configuration\n",
|
||||
"\n",
|
||||
"`ConflictsConfig` manages settings programmatically, via environment variables, or method-specific.\n",
|
||||
"\n",
|
||||
"**Global Settings:**\n",
|
||||
"- `confidence_threshold`, `default_strategy`, `auto_resolve`, `track_provenance`\n",
|
||||
"\n",
|
||||
"**Method-Specific:** Voting (`min_sources`, `tie_breaker`), credibility-weighted (`min_credibility`), most_recent (`time_field`), etc.\n",
|
||||
"\n",
|
||||
"**Priority:** Method-specific → Global → Environment variables → Defaults\n",
|
||||
"\n",
|
||||
"**Best Practices:** Set source credibility early, configure conflict fields, use method-specific configs\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.conflicts import ConflictsConfig, conflicts_config\n",
|
||||
"\n",
|
||||
"# Using global config instance\n",
|
||||
"conflicts_config.set(\"confidence_threshold\", 0.8)\n",
|
||||
"conflicts_config.set(\"default_strategy\", \"credibility_weighted\")\n",
|
||||
"threshold = conflicts_config.get(\"confidence_threshold\", default=0.7)\n",
|
||||
"\n",
|
||||
"# Method-specific configuration\n",
|
||||
"conflicts_config.set_method_config(\"voting\", min_sources=2, tie_breaker=\"confidence\")\n",
|
||||
"conflicts_config.set_method_config(\"credibility_weighted\", min_credibility=0.5)\n",
|
||||
"voting_config = conflicts_config.get_method_config(\"voting\")\n",
|
||||
"\n",
|
||||
"# Create custom config instance\n",
|
||||
"custom_config = ConflictsConfig()\n",
|
||||
"custom_config.set(\"confidence_threshold\", 0.9)\n",
|
||||
"custom_config.set(\"auto_resolve\", True)\n",
|
||||
"all_config = custom_config.get_all()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Part 9: Complete Workflow\n",
|
||||
"\n",
|
||||
"End-to-end example: integrating company data from multiple sources.\n",
|
||||
"\n",
|
||||
"**Workflow:** Initialize → Track Sources → Detect → Resolve → Analyze → Generate Guides → Build Final Entity\n",
|
||||
"\n",
|
||||
"**Scenario:** Three sources (Wikipedia, Official Site, Financial DB) with conflicts in name, founding year, and type classifications.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Complete workflow: Company data integration from multiple sources\n",
|
||||
"from semantica.conflicts import (\n",
|
||||
" ConflictDetector, ConflictResolver, ConflictAnalyzer,\n",
|
||||
" SourceTracker, InvestigationGuideGenerator, SourceReference\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Sample company data from multiple sources\n",
|
||||
"company_data = [\n",
|
||||
" {\"id\": \"company_1\", \"name\": \"Apple Inc.\", \"founded\": 1976, \"revenue\": 394328000000,\n",
|
||||
" \"headquarters\": \"Cupertino, California\", \"type\": \"Company\",\n",
|
||||
" \"source\": \"wikipedia\", \"confidence\": 0.85, \"timestamp\": datetime(2023, 1, 15)},\n",
|
||||
" {\"id\": \"company_1\", \"name\": \"Apple Inc.\", \"founded\": 1976, \"revenue\": 394328000000,\n",
|
||||
" \"headquarters\": \"Cupertino, CA\", \"type\": \"Company\",\n",
|
||||
" \"source\": \"official_site\", \"confidence\": 0.95, \"timestamp\": datetime(2023, 3, 20)},\n",
|
||||
" {\"id\": \"company_1\", \"name\": \"Apple Incorporated\", \"founded\": 1977, \"revenue\": 394328000000,\n",
|
||||
" \"headquarters\": \"Cupertino\", \"type\": \"Organization\",\n",
|
||||
" \"source\": \"financial_db\", \"confidence\": 0.80, \"timestamp\": datetime(2023, 2, 10)},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Initialize all components\n",
|
||||
"detector = ConflictDetector(\n",
|
||||
" confidence_threshold=0.7,\n",
|
||||
" track_provenance=True,\n",
|
||||
" conflict_fields={\"Company\": [\"name\", \"founded\", \"revenue\", \"headquarters\"]}\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"tracker = SourceTracker()\n",
|
||||
"tracker.set_source_credibility(\"wikipedia\", 0.85)\n",
|
||||
"tracker.set_source_credibility(\"official_site\", 0.95)\n",
|
||||
"tracker.set_source_credibility(\"financial_db\", 0.80)\n",
|
||||
"\n",
|
||||
"resolver = ConflictResolver(default_strategy=\"credibility_weighted\", source_tracker=tracker)\n",
|
||||
"analyzer = ConflictAnalyzer()\n",
|
||||
"guide_generator = InvestigationGuideGenerator(source_tracker=tracker)\n",
|
||||
"\n",
|
||||
"# Step 1: Track sources\n",
|
||||
"for entity in company_data:\n",
|
||||
" source_ref = SourceReference(\n",
|
||||
" document=entity[\"source\"],\n",
|
||||
" confidence=entity[\"confidence\"],\n",
|
||||
" timestamp=entity[\"timestamp\"]\n",
|
||||
" )\n",
|
||||
" tracker.track_property_source(entity[\"id\"], \"name\", entity[\"name\"], source_ref)\n",
|
||||
" tracker.track_property_source(entity[\"id\"], \"founded\", entity[\"founded\"], source_ref)\n",
|
||||
"\n",
|
||||
"# Step 2: Detect conflicts\n",
|
||||
"detected_conflicts = detector.detect_entity_conflicts(company_data, entity_type=\"Company\")\n",
|
||||
"\n",
|
||||
"# Step 3: Resolve conflicts\n",
|
||||
"resolved_data = {}\n",
|
||||
"for conflict in detected_conflicts:\n",
|
||||
" results = resolver.resolve_conflicts([conflict], strategy=\"credibility_weighted\")\n",
|
||||
" if results[0].resolved:\n",
|
||||
" resolved_data[conflict.property_name] = results[0].resolved_value\n",
|
||||
"\n",
|
||||
"# Step 4: Analyze\n",
|
||||
"analysis = analyzer.analyze_conflicts(detected_conflicts)\n",
|
||||
"\n",
|
||||
"# Step 5: Generate guides for unresolved conflicts\n",
|
||||
"unresolved = [c for c in detected_conflicts if c.property_name not in resolved_data]\n",
|
||||
"if unresolved:\n",
|
||||
" guides = guide_generator.generate_guides(unresolved)\n",
|
||||
"\n",
|
||||
"# Final resolved entity\n",
|
||||
"final_entity = {\"id\": \"company_1\", \"type\": \"Company\", **resolved_data}\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Summary\n",
|
||||
"\n",
|
||||
"### Key Features\n",
|
||||
"\n",
|
||||
"✅ **Detection**: Value, type, temporal, logical, relationship conflicts \n",
|
||||
"✅ **Resolution**: 6 strategies (voting, credibility-weighted, most_recent, first_seen, highest_confidence, manual_review) \n",
|
||||
"✅ **Source Tracking**: Provenance, credibility, traceability chains \n",
|
||||
"✅ **Analysis**: Patterns, trends, recommendations \n",
|
||||
"✅ **Investigation Guides**: Automated guides and checklists \n",
|
||||
"✅ **Methods Module**: Convenience functions for all operations \n",
|
||||
"✅ **Method Registry**: Custom method registration \n",
|
||||
"✅ **Configuration**: Global and method-specific settings\n",
|
||||
"\n",
|
||||
"### Best Practices\n",
|
||||
"\n",
|
||||
"1. Set source credibility before detection\n",
|
||||
"2. Choose strategies based on data characteristics\n",
|
||||
"3. Enable provenance tracking for audits\n",
|
||||
"4. Analyze patterns before resolving\n",
|
||||
"5. Use guides for high-severity conflicts\n",
|
||||
"6. Configure conflict fields to focus on critical properties\n",
|
||||
"\n",
|
||||
"### Common Patterns\n",
|
||||
"\n",
|
||||
"- **Integration**: Track → Detect → Resolve → Analyze\n",
|
||||
"- **QA**: Detect → Analyze → Generate guides → Review\n",
|
||||
"- **Auto**: Detect → Resolve → Analyze\n",
|
||||
"- **Assessment**: Track → Analyze → Adjust credibility\n",
|
||||
"\n",
|
||||
"### Next Steps\n",
|
||||
"\n",
|
||||
"- `04_Conflict_Resolution_Strategies.ipynb` - Advanced strategies\n",
|
||||
"- `06_Multi_Source_Data_Integration.ipynb` - Integration workflows\n",
|
||||
"- [API Reference](https://semantica.readthedocs.io/reference/conflicts/)\n",
|
||||
"- [Usage Guide](../semantica/conflicts/conflicts_usage.md)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,565 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Conflict Detection and Resolution\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"In modern data pipelines, especially those building Knowledge Graphs, data is often ingested from multiple heterogeneous sources (e.g., internal databases, third-party APIs, web scrapes). Discrepancies are inevitable. \n",
|
||||
"\n",
|
||||
"The **Semantica Conflict Resolution Module** (`semantica.conflicts`) provides a robust framework for managing these data inconsistencies. It is designed to ensure that your downstream applications consume only high-quality, reconciled data.\n",
|
||||
"\n",
|
||||
"### What counts as a \"conflict\"?\n",
|
||||
"\n",
|
||||
"- A conflict happens when **multiple records for the same entity** disagree on a field.\n",
|
||||
"- Semantica typically assumes each record is a dictionary with:\n",
|
||||
" - `id` (or `entity_id`): stable identifier for the entity being described\n",
|
||||
" - one or more attributes (e.g., `name`, `birth_date`, `department`)\n",
|
||||
" - `source`: where the value came from (db, scrape, api, file)\n",
|
||||
" - optional `timestamp`: when the value was observed\n",
|
||||
"- The module is source-aware: it can record **which sources contributed which values**, then resolve using strategies like voting or credibility.\n",
|
||||
"\n",
|
||||
"### Practical API notes (to avoid common mismatches)\n",
|
||||
"\n",
|
||||
"- Use `ConflictDetector.detect_value_conflicts(entities, property_name=...)` when you want to check one field.\n",
|
||||
"- Use `ConflictDetector.detect_conflicts(entities)` when you want a broader scan (value/type/temporal/etc.).\n",
|
||||
"- If you're starting from a `KnowledgeGraph`, pull entities via `kg.get(\"entities\", [])` (not `kg.entities`).\n",
|
||||
"\n",
|
||||
"### Key Capabilities\n",
|
||||
"\n",
|
||||
"1. **Multi-Dimensional Conflict Detection**\n",
|
||||
" * **Value Conflicts**: Different values for the same property (e.g., `\"Google\"` vs `\"Google Inc.\"`).\n",
|
||||
" * **Type Conflicts**: Data type mismatches (e.g., string vs integer).\n",
|
||||
" * **Temporal Conflicts**: Chronological inconsistencies (e.g., a `start_date` after an `end_date`).\n",
|
||||
"\n",
|
||||
"2. **Provenance & Source Tracking**\n",
|
||||
" * **Granular Tracking**: Trace every property value back to its specific source document, page, or API call.\n",
|
||||
" * **Credibility Scoring**: Assign trust scores to sources (e.g., `0.95` for internal HR DB vs `0.60` for web scrapes).\n",
|
||||
"\n",
|
||||
"3. **Automated Resolution Strategies**\n",
|
||||
" * **Voting**: Majority rules (useful for multiple equal-weight sources).\n",
|
||||
" * **Credibility Weighted**: Values from higher-trust sources override others.\n",
|
||||
" * **Recency**: The most recent data point wins.\n",
|
||||
" * **Expert Review**: Flag complex conflicts for human intervention.\n",
|
||||
"\n",
|
||||
"4. **Investigation & Auditing**\n",
|
||||
" * **Investigation Guides**: Auto-generate step-by-step guides for human analysts to resolve sticky conflicts.\n",
|
||||
" * **Audit Trails**: Keep a record of how every conflict was resolved for compliance.\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Ensure Semantica is installed in your environment:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"- If you're running this notebook inside the Semantica repo, prefer an editable install (so changes in code are reflected immediately):\n",
|
||||
" - `pip install -e .`\n",
|
||||
"- If you're using a hosted notebook environment, `%pip install semantica` is often more reliable than `!pip install ...` because it installs into the active kernel."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install -q semantica "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"from datetime import datetime"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 1: Simulating Multi-Source Data\n",
|
||||
"\n",
|
||||
"To demonstrate the framework, we will simulate a realistic scenario involving employee data.\n",
|
||||
"\n",
|
||||
"**The Scenario:**\n",
|
||||
"We have received records for **Employee 001** from three distinct sources:\n",
|
||||
"\n",
|
||||
"- **HR Database**: Highly trusted internal source.\n",
|
||||
"- **LinkedIn Scrape**: Less reliable external source.\n",
|
||||
"- **Public Directory**: Outdated public API.\n",
|
||||
"\n",
|
||||
"**The record shape (what Semantica expects):**\n",
|
||||
"\n",
|
||||
"- Each record is a dictionary describing the same entity (`id`: `emp_001`).\n",
|
||||
"- Each record includes a `source` key so conflicts can be attributed.\n",
|
||||
"- A `timestamp` lets you apply time-based resolution strategies (e.g., most recent wins).\n",
|
||||
"\n",
|
||||
"**The Conflicts:**\n",
|
||||
"* **`birth_date`**: The Public Directory lists a different year.\n",
|
||||
"* **`department`**: LinkedIn uses a more specific name (\"Software Engineering\") vs the generic \"Engineering\" in the HR DB."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Loaded 3 records for Employee 001\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 1. Define source metadata\n",
|
||||
"sources_metadata = {\n",
|
||||
" \"hr_db\": {\"credibility\": 0.95, \"type\": \"internal_database\"},\n",
|
||||
" \"linkedin_scrape\": {\"credibility\": 0.60, \"type\": \"web_scrape\"},\n",
|
||||
" \"public_dir\": {\"credibility\": 0.40, \"type\": \"public_api\"}\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"# 2. Define entity records from these sources\n",
|
||||
"entity_records = [\n",
|
||||
" {\n",
|
||||
" \"id\": \"emp_001\",\n",
|
||||
" \"name\": \"John Doe\",\n",
|
||||
" \"birth_date\": \"1980-05-15\",\n",
|
||||
" \"department\": \"Engineering\",\n",
|
||||
" \"source\": \"hr_db\",\n",
|
||||
" \"timestamp\": \"2023-01-01T10:00:00\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"id\": \"emp_001\",\n",
|
||||
" \"name\": \"Jonathan Doe\",\n",
|
||||
" \"birth_date\": \"1980-05-15\",\n",
|
||||
" \"department\": \"Software Engineering\",\n",
|
||||
" \"source\": \"linkedin_scrape\",\n",
|
||||
" \"timestamp\": \"2023-06-15T14:30:00\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"id\": \"emp_001\",\n",
|
||||
" \"name\": \"John Doe\",\n",
|
||||
" \"birth_date\": \"1982-05-15\", # Conflict: Different year\n",
|
||||
" \"department\": \"Engineering\",\n",
|
||||
" \"source\": \"public_dir\",\n",
|
||||
" \"timestamp\": \"2022-12-01T09:00:00\"\n",
|
||||
" }\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"print(f\"Loaded {len(entity_records)} records for Employee 001\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 2: Registering and Tracking Sources\n",
|
||||
"\n",
|
||||
"Before we can effectively resolve conflicts based on trust, we must register our sources with the `SourceTracker`.\n",
|
||||
"\n",
|
||||
"The `SourceTracker` acts as a central registry for:\n",
|
||||
"\n",
|
||||
"- **Credibility Scores**: How much you trust the source.\n",
|
||||
"- **Metadata**: Helpful context (e.g., source type, system of record vs scrape).\n",
|
||||
"\n",
|
||||
"**How to think about credibility scores:**\n",
|
||||
"\n",
|
||||
"- Use scores as a *relative ordering* (the exact decimals matter less than the ranking).\n",
|
||||
"- Start simple: `internal_db > vendor_api > web_scrape`.\n",
|
||||
"- Revisit scores later using analytics (e.g., \"which sources are frequently wrong?\").\n",
|
||||
"\n",
|
||||
"We iterate through our simulated sources and register them."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Registering sources...\n",
|
||||
" - Registered 'hr_db' with credibility 0.95\n",
|
||||
" - Registered 'linkedin_scrape' with credibility 0.6\n",
|
||||
" - Registered 'public_dir' with credibility 0.4\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.conflicts import SourceTracker\n",
|
||||
"\n",
|
||||
"source_tracker = SourceTracker()\n",
|
||||
"\n",
|
||||
"print(\"Registering sources...\")\n",
|
||||
"for source_id, metadata in sources_metadata.items():\n",
|
||||
" source_tracker.register_source(\n",
|
||||
" source_id=source_id,\n",
|
||||
" source_type=metadata[\"type\"],\n",
|
||||
" credibility_score=metadata[\"credibility\"]\n",
|
||||
" )\n",
|
||||
" print(f\" - Registered '{source_id}' with credibility {metadata['credibility']}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 3: Detecting Conflicts\n",
|
||||
"\n",
|
||||
"We use the `ConflictDetector` to scan our records for discrepancies. \n",
|
||||
"\n",
|
||||
"The detector is flexible and can be configured to check:\n",
|
||||
"\n",
|
||||
"- **Specific properties**: Check only critical fields like `birth_date`.\n",
|
||||
"- **Entity-wide scans**: Scan many properties (or all) for an entity.\n",
|
||||
"\n",
|
||||
"**What you get back:**\n",
|
||||
"\n",
|
||||
"- A list of `Conflict` objects.\n",
|
||||
"- Useful fields you’ll typically inspect:\n",
|
||||
" - `conflict_type` (e.g., `value_conflict`)\n",
|
||||
" - `entity_id`, `property_name`\n",
|
||||
" - `conflicting_values` and `sources`\n",
|
||||
" - `severity` and `confidence`\n",
|
||||
"\n",
|
||||
"Here, we explicitly check `birth_date` and `department`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is resolving</td><td>⚠️ conflicts</td><td>ConflictDetector</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is resolving</td><td>⚠️ conflicts</td><td>ConflictAnalyzer</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is resolving</td><td>⚠️ conflicts</td><td>ConflictResolver</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is resolving</td><td>⚠️ conflicts</td><td>InvestigationGuideGenerator</td><td>-</td><td>0.00s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Value conflict detected: emp_001.birth_date has conflicting values: ['1980-05-15', '1982-05-15']\n",
|
||||
"Value conflict detected: emp_001.department has conflicting values: ['Software Engineering', 'Engineering']\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Detected 2 conflicts:\n",
|
||||
"- value_conflict: birth_date for emp_001\n",
|
||||
" Values: ['1980-05-15', '1980-05-15', '1982-05-15']\n",
|
||||
" Severity: medium\n",
|
||||
"--- \n",
|
||||
"- value_conflict: department for emp_001\n",
|
||||
" Values: ['Engineering', 'Software Engineering', 'Engineering']\n",
|
||||
" Severity: medium\n",
|
||||
"--- \n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
"\n",
|
||||
"# Initialize detector with our populated source tracker\n",
|
||||
"detector = ConflictDetector(source_tracker=source_tracker)\n",
|
||||
"\n",
|
||||
"conflicts = []\n",
|
||||
"\n",
|
||||
"# 1. Check birth_date\n",
|
||||
"dob_conflicts = detector.detect_value_conflicts(entity_records, \"birth_date\")\n",
|
||||
"conflicts.extend(dob_conflicts)\n",
|
||||
"\n",
|
||||
"# 2. Check department\n",
|
||||
"dept_conflicts = detector.detect_value_conflicts(entity_records, \"department\")\n",
|
||||
"conflicts.extend(dept_conflicts)\n",
|
||||
"\n",
|
||||
"print(f\"Detected {len(conflicts)} conflicts:\")\n",
|
||||
"for conflict in conflicts:\n",
|
||||
" print(f\"- {conflict.conflict_type.value}: {conflict.property_name} for {conflict.entity_id}\")\n",
|
||||
" print(f\" Values: {conflict.conflicting_values}\")\n",
|
||||
" print(f\" Severity: {conflict.severity}\")\n",
|
||||
" print(\"--- \")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 4: Analyzing Conflict Patterns\n",
|
||||
"\n",
|
||||
"When dealing with large datasets, individual conflicts are less important than systemic patterns. The `ConflictAnalyzer` helps answer questions like:\n",
|
||||
"\n",
|
||||
"- \"Is one specific source responsible for most conflicts?\"\n",
|
||||
"- \"Are conflicts concentrated in a specific entity type or property?\"\n",
|
||||
"- \"What is the distribution of conflict severity and conflict types?\"\n",
|
||||
"\n",
|
||||
"**How to use this in a pipeline:**\n",
|
||||
"\n",
|
||||
"- Run analysis to identify noisy sources.\n",
|
||||
"- Use results to adjust credibility scores (Step 2) or refine ingestion/cleaning rules.\n",
|
||||
"- Track trends over time to catch regressions in upstream systems."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Conflict Analysis Summary:\n",
|
||||
"Total Conflicts: 2\n",
|
||||
"By Type: {'value_conflict': 2}\n",
|
||||
"By Severity: {'medium': 2}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.conflicts import ConflictAnalyzer\n",
|
||||
"\n",
|
||||
"analyzer = ConflictAnalyzer()\n",
|
||||
"analysis = analyzer.analyze_conflicts(conflicts)\n",
|
||||
"\n",
|
||||
"print(\"Conflict Analysis Summary:\")\n",
|
||||
"print(f\"Total Conflicts: {analysis['total_conflicts']}\")\n",
|
||||
"print(f\"By Type: {analysis.get('by_type', {}).get('counts')}\")\n",
|
||||
"print(f\"By Severity: {analysis.get('by_severity', {}).get('counts')}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 5: Resolving Conflicts\n",
|
||||
"\n",
|
||||
"This is the critical step where we decide which value to trust. Semantica offers flexible resolution strategies.\n",
|
||||
"\n",
|
||||
"### Strategy A: Voting (Majority Rules)\n",
|
||||
"This strategy selects the value that appears most frequently. It is simple but treats all sources as equal.\n",
|
||||
"\n",
|
||||
"- Best when you have many independent sources of similar quality.\n",
|
||||
"- Less suitable if you have a single system-of-record that should always dominate.\n",
|
||||
"\n",
|
||||
"### Strategy B: Credibility Weighted\n",
|
||||
"This strategy calculates a weighted score for each value based on the `credibility` of its source. \n",
|
||||
"\n",
|
||||
"**Example:**\n",
|
||||
"* `hr_db` (0.95) says \"1980-05-15\"\n",
|
||||
"* `public_dir` (0.40) says \"1982-05-15\"\n",
|
||||
"\n",
|
||||
"Even if multiple low-quality sources agreed on the wrong date, the high-credibility source would likely win.\n",
|
||||
"\n",
|
||||
"**What the resolver returns:**\n",
|
||||
"\n",
|
||||
"- A list of resolution results where each item typically includes:\n",
|
||||
" - whether it was resolved\n",
|
||||
" - the chosen value (`resolved_value`)\n",
|
||||
" - a confidence score\n",
|
||||
" - metadata (like the property name) to support audit trails\n",
|
||||
"\n",
|
||||
"Run the next cell to compare voting vs credibility-weighted outcomes."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"--- Resolution: Voting ---\n",
|
||||
"Property: birth_date | Resolved Value: 1980-05-15\n",
|
||||
"Property: department | Resolved Value: Engineering\n",
|
||||
"\n",
|
||||
"--- Resolution: Credibility Weighted ---\n",
|
||||
"Property: birth_date | Resolved Value: 1980-05-15 (Confidence: 0.79)\n",
|
||||
"Property: department | Resolved Value: Engineering (Confidence: 0.69)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.conflicts import ConflictResolver\n",
|
||||
"\n",
|
||||
"resolver = ConflictResolver()\n",
|
||||
"\n",
|
||||
"# CRITICAL: Link the source tracker to the resolver.\n",
|
||||
"# This allows the resolver to look up the credibility scores we registered in Step 2.\n",
|
||||
"resolver.set_source_tracker(source_tracker)\n",
|
||||
"\n",
|
||||
"print(\"--- Resolution: Voting ---\")\n",
|
||||
"voting_results = resolver.resolve_conflicts(conflicts, strategy=\"voting\")\n",
|
||||
"for res in voting_results:\n",
|
||||
" print(f\"Property: {res.metadata.get('property_name'):<15} | Resolved Value: {res.resolved_value}\")\n",
|
||||
"\n",
|
||||
"print(\"\\n--- Resolution: Credibility Weighted ---\")\n",
|
||||
"# Notice how the HR DB's value is preferred due to higher credibility\n",
|
||||
"credibility_results = resolver.resolve_conflicts(conflicts, strategy=\"credibility_weighted\")\n",
|
||||
"for res in credibility_results:\n",
|
||||
" print(f\"Property: {res.metadata.get('property_name'):<15} | Resolved Value: {res.resolved_value} (Confidence: {res.confidence:.2f})\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 6: Generating Investigation Guides\n",
|
||||
"\n",
|
||||
"Not all conflicts can be resolved automatically. High-stakes or low-confidence resolutions require human review.\n",
|
||||
"\n",
|
||||
"The `InvestigationGuideGenerator` produces a structured \"flight plan\" for an analyst, detailing:\n",
|
||||
"\n",
|
||||
"- **What** is in conflict (entity + field + competing values).\n",
|
||||
"- **Who** is involved (which sources produced which values).\n",
|
||||
"- **How** to verify the correct data (actionable steps an analyst can follow).\n",
|
||||
"\n",
|
||||
"**When to generate guides:**\n",
|
||||
"\n",
|
||||
"- Low-confidence resolutions.\n",
|
||||
"- Conflicts on critical fields (identity, legal names, compliance attributes).\n",
|
||||
"- Any time you want a human-in-the-loop checkpoint before writing back to the graph."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"=== Investigation: emp_001_birth_date_conflict ===\n",
|
||||
"Summary: Conflict Type: value_conflict | Entity: emp_001 | Property: birth_date | Conflicting Values: 1980-05-15, 1982-05-15 | Severity: medium | Sources: public_dir, hr_db, linkedin_scrape\n",
|
||||
"\n",
|
||||
"Investigation Steps:\n",
|
||||
"1. Review conflict details and context\n",
|
||||
" Action: Examine the conflict summary and identify the conflicting values\n",
|
||||
"2. Identify all source documents\n",
|
||||
" Action: Locate and review the following source documents: public_dir, hr_db, linkedin_scrape\n",
|
||||
"3. Compare conflicting information across sources\n",
|
||||
" Action: Review each source document and note the specific value and context for each\n",
|
||||
"4. Assess source credibility and reliability\n",
|
||||
" Action: Review source credibility scores and document metadata\n",
|
||||
"5. Determine resolution approach\n",
|
||||
" Action: Choose resolution strategy based on source credibility, recency, and business rules\n",
|
||||
"6. Document resolution decision\n",
|
||||
" Action: Record the resolved value, resolution method, and rationale\n",
|
||||
"\n",
|
||||
"Recommended Actions:\n",
|
||||
"[ ] Compare source documents side-by-side\n",
|
||||
"[ ] Check for data entry errors or typos\n",
|
||||
"[ ] Verify if values represent different time periods\n",
|
||||
"[ ] Review 3 conflicting source documents\n",
|
||||
"[ ] Identify most authoritative source\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.conflicts import InvestigationGuideGenerator\n",
|
||||
"\n",
|
||||
"guide_generator = InvestigationGuideGenerator()\n",
|
||||
"\n",
|
||||
"# Generate a guide for the first conflict (birth_date)\n",
|
||||
"guide = guide_generator.generate_guide(conflicts[0])\n",
|
||||
"\n",
|
||||
"print(f\"=== {guide.title} ===\")\n",
|
||||
"print(f\"Summary: {guide.conflict_summary}\\n\")\n",
|
||||
"\n",
|
||||
"print(\"Investigation Steps:\")\n",
|
||||
"for i, step in enumerate(guide.investigation_steps, 1):\n",
|
||||
" print(f\"{i}. {step.description}\")\n",
|
||||
" print(f\" Action: {step.action}\")\n",
|
||||
"\n",
|
||||
"print(\"\\nRecommended Actions:\")\n",
|
||||
"for action in guide.recommended_actions:\n",
|
||||
" print(f\"[ ] {action}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Conclusion\n",
|
||||
"\n",
|
||||
"You have successfully built a conflict resolution pipeline using Semantica! \n",
|
||||
"\n",
|
||||
"**Recap of what we achieved:**\n",
|
||||
"\n",
|
||||
"- **Simulated** multi-source entity records with realistic disagreements.\n",
|
||||
"- **Registered** sources with credibility scores to create a trust hierarchy.\n",
|
||||
"- **Detected** value conflicts for specific properties.\n",
|
||||
"- **Analyzed** conflicts to understand distribution by type and severity.\n",
|
||||
"- **Resolved** conflicts using voting and credibility-weighted strategies.\n",
|
||||
"- **Generated** an investigation guide to support human review.\n",
|
||||
"\n",
|
||||
"**Suggested next steps in a real project:**\n",
|
||||
"\n",
|
||||
"- Integrate with your ingestion layer so each extracted value includes a `source` and (ideally) a `timestamp`.\n",
|
||||
"- Expand detection beyond value conflicts using `ConflictDetector.detect_conflicts(...)`.\n",
|
||||
"- Store resolutions and guide outputs to build an audit trail for downstream consumers."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,256 +2,675 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "c21e9c8d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/introduction/19_Context_Module.ipynb)\n",
|
||||
"\n",
|
||||
"# Context Engineering Module\n",
|
||||
"# Context Module — Practical Guide\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"Semantica’s `context` module is the layer that makes an agent “stateful”. It combines:\n",
|
||||
"\n",
|
||||
"This notebook provides a comprehensive guide to Semantica's **Context Engineering Module** - a powerful system for building context graphs, managing agent memory, retrieving context, and linking entities. You'll learn how to use the new synchronous Architecture 2.0 features, including hierarchical memory with token management.\n",
|
||||
"- **Memory** (short-term + long-term) via `AgentMemory`\n",
|
||||
"- **Graph context** via `ContextGraph`\n",
|
||||
"- **Hybrid retrieval** (vector + memory + graph) via `ContextRetriever`\n",
|
||||
"- **High-level UX** via `AgentContext` (recommended entry point)\n",
|
||||
"- **Entity linking** via `EntityLinker`\n",
|
||||
"- **Extensibility + config** via `registry` and `config`\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/reference/context/)\n",
|
||||
"\n",
|
||||
"### Learning Objectives\n",
|
||||
"\n",
|
||||
"- **Hierarchical Memory**: Manage short-term (token-buffered) and long-term (vector-stored) memory\n",
|
||||
"- **Context Graph**: Build and query dynamic knowledge graphs\n",
|
||||
"- **Hybrid Retrieval**: Combine vector search, graph traversal, and keyword matching\n",
|
||||
"- **Entity Linking**: Resolve entities across conversations\n",
|
||||
"- **Configuration**: Customize behavior via YAML or environment variables\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install semantica\n",
|
||||
"```"
|
||||
"This notebook focuses on small, runnable examples and keeps imports scoped to each cell."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"id": "257bad40",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~gno (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~lotly (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n",
|
||||
"WARNING: Ignoring invalid distribution ~ython-socketio (C:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Setup: Create a mock vector store for demonstration\n",
|
||||
"from typing import List, Dict, Any, Optional\n",
|
||||
"from semantica.context import VectorStore\n",
|
||||
"\n",
|
||||
"class MockVectorStore(VectorStore):\n",
|
||||
" def __init__(self):\n",
|
||||
" self.items = {}\n",
|
||||
" self.counter = 0\n",
|
||||
" \n",
|
||||
" def add(self, texts: List[str], metadata: Optional[List[Dict[str, Any]]] = None, **kwargs) -> List[str]:\n",
|
||||
" ids = []\n",
|
||||
" for i, text in enumerate(texts):\n",
|
||||
" id_ = f\"id_{self.counter}\"\n",
|
||||
" self.items[id_] = {\"text\": text, \"metadata\": metadata[i] if metadata else {}}\n",
|
||||
" ids.append(id_)\n",
|
||||
" self.counter += 1\n",
|
||||
" return ids\n",
|
||||
" \n",
|
||||
" def search(self, query: str, limit: int = 5, **kwargs) -> List[Dict[str, Any]]:\n",
|
||||
" # Simple keyword match for mock\n",
|
||||
" results = []\n",
|
||||
" for id_, item in self.items.items():\n",
|
||||
" if any(w.lower() in item[\"text\"].lower() for w in query.split()):\n",
|
||||
" results.append({\n",
|
||||
" \"id\": id_,\n",
|
||||
" \"content\": item[\"text\"],\n",
|
||||
" \"score\": 0.9,\n",
|
||||
" \"metadata\": item[\"metadata\"]\n",
|
||||
" })\n",
|
||||
" return results[:limit]\n",
|
||||
" \n",
|
||||
" def delete(self, ids: List[str], **kwargs) -> bool:\n",
|
||||
" for id_ in ids:\n",
|
||||
" self.items.pop(id_, None)\n",
|
||||
" return True\n",
|
||||
"\n",
|
||||
"vs = MockVectorStore()"
|
||||
"!pip install -q semantica"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a48e0f10",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 1. High-Level Interface: AgentContext\n",
|
||||
"## 1) Vector store (for long-term memory)\n",
|
||||
"\n",
|
||||
"The `AgentContext` class is the easiest way to get started. It unifies vector storage, knowledge graphs, and memory management."
|
||||
"The `VectorStore` can generate embeddings via its internal embedder. If no embedder is available in your environment, it falls back to random vectors so the API stays usable for demos."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 2,
|
||||
"id": "8c845a94",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"c:\\Users\\Mohd Kaif\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\sentence_transformers\\cross_encoder\\CrossEncoder.py:13: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",
|
||||
" from tqdm.autonotebook import tqdm, trange\n",
|
||||
"fastembed not available. Install with: pip install fastembed. Using fallback embedding method.\n",
|
||||
"fastembed not available. Install with: pip install fastembed. Using fallback embedding method.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"('inmemory', 384)"
|
||||
]
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.vector_store import VectorStore\n",
|
||||
"\n",
|
||||
"vs = VectorStore(backend=\"inmemory\", dimension=384)\n",
|
||||
"\n",
|
||||
"if getattr(vs, \"embedder\", None) and hasattr(vs.embedder, \"set_text_model\"):\n",
|
||||
" vs.embedder.set_text_model(method=\"fastembed\", model_name=\"BAAI/bge-small-en-v1.5\")\n",
|
||||
"\n",
|
||||
"vs.backend, vs.dimension"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "c1b1ba34",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 2) Quick start with `AgentContext` (recommended)\n",
|
||||
"\n",
|
||||
"`AgentContext` is the user-friendly interface that ties memory, vector store, and graph together. If you pass a `ContextGraph`, the system can do GraphRAG-style retrieval."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "f4d788b5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'retention_days': 30,\n",
|
||||
" 'max_memories': 10000,\n",
|
||||
" 'use_graph_expansion': True,\n",
|
||||
" 'max_expansion_hops': 2,\n",
|
||||
" 'hybrid_alpha': 0.5}"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.context import AgentContext, ContextGraph\n",
|
||||
"\n",
|
||||
"# Initialize with vector store and a new in-memory knowledge graph\n",
|
||||
"kg = ContextGraph()\n",
|
||||
"context = AgentContext(\n",
|
||||
" vector_store=vs,\n",
|
||||
" knowledge_graph=kg,\n",
|
||||
" token_limit=2000, # Max tokens in short-term memory\n",
|
||||
" short_term_limit=10 # Max items in short-term memory\n",
|
||||
")\n",
|
||||
"context = AgentContext(vector_store=vs, knowledge_graph=kg)\n",
|
||||
"\n",
|
||||
"# Store a memory (automatically goes to short-term and long-term)\n",
|
||||
"context.store(\n",
|
||||
" \"The user, Alice, is a data scientist interested in Python.\",\n",
|
||||
"context.config"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "638bdbc8",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 3) Store and retrieve memory\n",
|
||||
"\n",
|
||||
"A single string is treated as a memory item. You can attach `conversation_id` and `user_id` through metadata-friendly parameters."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "5d65eb00",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is processing</td><td>🔗 context</td><td>AgentMemory</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is embedding</td><td>💾 embeddings</td><td>TextEmbedder</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is indexing</td><td>📊 vector_store</td><td>VectorStore</td><td>-</td><td>0.00s</td></tr><tr><td>✅</td><td>Semantica is processing</td><td>🔗 context</td><td>ContextRetriever</td><td>-</td><td>0.02s</td></tr><tr><td>✅</td><td>Semantica is processing</td><td>🔗 context</td><td>EntityLinker</td><td>-</td><td>0.00s</td></tr></table></div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.core.display.HTML object>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'id': None,\n",
|
||||
" 'content': 'User prefers short answers about Python.',\n",
|
||||
" 'timestamp': '2025-12-18T20:46:17.265703',\n",
|
||||
" 'metadata': {'type': 'preference',\n",
|
||||
" 'conversation_id': 'conv_1',\n",
|
||||
" 'user_id': 'user_1'}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"memory_id = context.store(\n",
|
||||
" \"User prefers short answers about Python.\",\n",
|
||||
" conversation_id=\"conv_1\",\n",
|
||||
" user_id=\"alice_01\"\n",
|
||||
" user_id=\"user_1\",\n",
|
||||
" metadata={\"type\": \"preference\"},\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Retrieve context (automatically uses hybrid retrieval)\n",
|
||||
"results = context.retrieve(\"What does Alice do?\")\n",
|
||||
"context.get_memory(memory_id)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "3c1be718",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"C:\\Users\\Mohd Kaif\\semantica\\semantica\\vector_store\\vector_store.py:480: RuntimeWarning: invalid value encountered in divide\n",
|
||||
" similarities = np.dot(vectors, query_vector) / (vector_norms * query_norm)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[{'content': 'User prefers short answers about Python.',\n",
|
||||
" 'score': 1.0,\n",
|
||||
" 'source': 'short_term',\n",
|
||||
" 'metadata': {'type': 'preference',\n",
|
||||
" 'conversation_id': 'conv_1',\n",
|
||||
" 'user_id': 'user_1'},\n",
|
||||
" 'related_entities': []}]"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"context.store(\n",
|
||||
" \"User is working on Semantica context module examples.\",\n",
|
||||
" conversation_id=\"conv_1\",\n",
|
||||
" user_id=\"user_1\",\n",
|
||||
" metadata={\"type\": \"note\"},\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"for res in results:\n",
|
||||
" print(f\"Found: {res['content']} (Score: {res['score']})\")"
|
||||
"context.retrieve(\"Python answers\", max_results=3)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "485acf33",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[]"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"context.conversation(\"conv_1\", max_items=10)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1e43cddd",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 2. Hierarchical Memory Management\n",
|
||||
"## 4) Export, save, load\n",
|
||||
"\n",
|
||||
"Semantica uses a two-tier memory system:\n",
|
||||
"1. **Short-Term Memory**: A fast, in-memory buffer limited by tokens (to fit in LLM context windows) and item count.\n",
|
||||
"2. **Long-Term Memory**: Persistent storage backed by the vector store.\n",
|
||||
"`AgentContext` includes simple persistence helpers. This example uses a temporary directory."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "a264ef4d",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'{\\n \"exported_at\": \"2025-12-18T20:46:27.455602\",\\n \"count\": 2,\\n \"memories\": [\\n {\\n \"memory_id\": \"mem_5c7dba9a7373\",\\n \"content\": \"User prefers short answers about Python.\",\\n \"timestamp\": \"2025-12-18T20:46:17.265703\",\\n \"metadata\": {\\n \"type\": \"preference\",\\n \"convers'"
|
||||
]
|
||||
},
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"export_json = context.export(conversation_id=\"conv_1\", format=\"json\")\n",
|
||||
"export_json[:300]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "b62d1859",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'conversation_id': 'conv_1',\n",
|
||||
" 'message_count': 0,\n",
|
||||
" 'first_message': None,\n",
|
||||
" 'last_message': None}"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import tempfile\n",
|
||||
"\n",
|
||||
"Let's observe how the token limit works."
|
||||
"with tempfile.TemporaryDirectory() as d:\n",
|
||||
" context.save(d)\n",
|
||||
" context.load(d)\n",
|
||||
"\n",
|
||||
"context.conversation_summary(\"conv_1\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3b8bf553",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 5) Store documents and build a context graph\n",
|
||||
"\n",
|
||||
"If you store a list, `AgentContext.store(...)` treats it as documents. To keep this notebook lightweight and deterministic, we pass pre-extracted entities and relationships per document."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"id": "72930ae7",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'stored_count': 2,\n",
|
||||
" 'memory_ids': ['mem_b467da01b18a', 'mem_e3dbd310355d'],\n",
|
||||
" 'graph_nodes': 0,\n",
|
||||
" 'graph_edges': 0}"
|
||||
]
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"documents = [\n",
|
||||
" {\n",
|
||||
" \"id\": \"doc_1\",\n",
|
||||
" \"content\": \"Python is used for machine learning.\",\n",
|
||||
" \"metadata\": {\"source\": \"docs\"},\n",
|
||||
" \"entities\": [\n",
|
||||
" {\"id\": \"e_python\", \"text\": \"Python\", \"type\": \"PROGRAMMING_LANGUAGE\"},\n",
|
||||
" {\"id\": \"e_ml\", \"text\": \"Machine Learning\", \"type\": \"CONCEPT\"},\n",
|
||||
" ],\n",
|
||||
" \"relationships\": [\n",
|
||||
" {\n",
|
||||
" \"source_id\": \"e_python\",\n",
|
||||
" \"target_id\": \"e_ml\",\n",
|
||||
" \"type\": \"used_for\",\n",
|
||||
" \"confidence\": 0.9,\n",
|
||||
" }\n",
|
||||
" ],\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"id\": \"doc_2\",\n",
|
||||
" \"content\": \"PyTorch is a machine learning framework.\",\n",
|
||||
" \"metadata\": {\"source\": \"docs\"},\n",
|
||||
" \"entities\": [\n",
|
||||
" {\"id\": \"e_pytorch\", \"text\": \"PyTorch\", \"type\": \"FRAMEWORK\"},\n",
|
||||
" {\"id\": \"e_ml\", \"text\": \"Machine Learning\", \"type\": \"CONCEPT\"},\n",
|
||||
" ],\n",
|
||||
" \"relationships\": [\n",
|
||||
" {\n",
|
||||
" \"source_id\": \"e_pytorch\",\n",
|
||||
" \"target_id\": \"e_ml\",\n",
|
||||
" \"type\": \"implements\",\n",
|
||||
" \"confidence\": 0.95,\n",
|
||||
" }\n",
|
||||
" ],\n",
|
||||
" },\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"stats = context.store(\n",
|
||||
" documents,\n",
|
||||
" extract_entities=False,\n",
|
||||
" extract_relationships=False,\n",
|
||||
" link_entities=True,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"stats"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "24f8dba8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.context import AgentMemory\n",
|
||||
"\n",
|
||||
"# Initialize memory with strict limits for demonstration\n",
|
||||
"memory = AgentMemory(\n",
|
||||
" vector_store=vs,\n",
|
||||
" token_limit=50, # Very small token limit\n",
|
||||
" short_term_limit=5 # Max 5 items\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Add memories\n",
|
||||
"for i in range(10):\n",
|
||||
" memory.store(f\"Memory item {i}: This is a sentence with some tokens.\")\n",
|
||||
" print(f\"Added item {i}. Short-term size: {len(memory.short_term_memory)}\")\n",
|
||||
"\n",
|
||||
"print(\"\\nFinal short-term memory content:\")\n",
|
||||
"for item in memory.short_term_memory:\n",
|
||||
" print(f\"- {item.content}\")\n",
|
||||
" \n",
|
||||
"# Notice that older items are pruned to respect the token limit and item count."
|
||||
"kg.stats()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f4671f2a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 3. Context Graph & GraphRAG\n",
|
||||
"## 6) Explore the graph with `ContextGraph`\n",
|
||||
"\n",
|
||||
"The `ContextGraph` allows you to structure information as nodes and edges, enabling \"GraphRAG\" - retrieving information based on relationships rather than just semantic similarity."
|
||||
"The graph supports keyword querying and neighbor expansion."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 10,
|
||||
"id": "df2e5fcd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[{'node': {'id': 'e_ml',\n",
|
||||
" 'type': 'CONCEPT',\n",
|
||||
" 'properties': {'content': 'Machine Learning',\n",
|
||||
" 'id': 'e_ml',\n",
|
||||
" 'text': 'Machine Learning',\n",
|
||||
" 'type': 'CONCEPT'}},\n",
|
||||
" 'score': 1.0,\n",
|
||||
" 'content': 'Machine Learning'}]"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.context import ContextGraph\n",
|
||||
"\n",
|
||||
"graph = ContextGraph()\n",
|
||||
"\n",
|
||||
"# Manually building a graph\n",
|
||||
"graph.add_node(\"n1\", \"person\", \"Alice\")\n",
|
||||
"graph.add_node(\"n2\", \"language\", \"Python\")\n",
|
||||
"graph.add_node(\"n3\", \"library\", \"Semantica\")\n",
|
||||
"\n",
|
||||
"graph.add_edge(\"n1\", \"n2\", \"uses\")\n",
|
||||
"graph.add_edge(\"n2\", \"n3\", \"powers\")\n",
|
||||
"\n",
|
||||
"# Query the graph\n",
|
||||
"neighbors = graph.get_neighbors(\"n2\", hops=1)\n",
|
||||
"print(\"Neighbors of Python:\", neighbors)\n",
|
||||
"\n",
|
||||
"# Using the graph in AgentContext\n",
|
||||
"context = AgentContext(vector_store=vs, knowledge_graph=graph)\n",
|
||||
"\n",
|
||||
"# Retrieve with graph expansion\n",
|
||||
"results = context.retrieve(\n",
|
||||
" \"Alice\",\n",
|
||||
" use_graph=True,\n",
|
||||
" expand_graph=True # Will pull in 'Python' because Alice uses it\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(\"\\nGraph-enhanced Retrieval:\")\n",
|
||||
"for res in results:\n",
|
||||
" print(f\"- {res['content']}\")"
|
||||
"kg.query(\"machine learning\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"id": "0836feeb",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[{'id': 'e_ml',\n",
|
||||
" 'type': 'CONCEPT',\n",
|
||||
" 'content': 'Machine Learning',\n",
|
||||
" 'relationship': 'used_for',\n",
|
||||
" 'weight': 0.9,\n",
|
||||
" 'hop': 1}]"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"kg.get_neighbors(\"e_python\", hops=2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1be1adf1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 4. Entity Linking\n",
|
||||
"## 7) Entity linking with `EntityLinker`\n",
|
||||
"\n",
|
||||
"The `EntityLinker` helps ensure that \"Alice\", \"Alice Smith\", and \"she\" (in context) refer to the same entity ID."
|
||||
"`EntityLinker` assigns stable URIs and can link related or duplicate entities across sources."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 12,
|
||||
"id": "24b011c0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[('e1', 'https://semantica.dev/entity/python#programming_language', 1),\n",
|
||||
" ('e2', 'https://semantica.dev/entity/pytorch#framework', 0)]"
|
||||
]
|
||||
},
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.context import EntityLinker\n",
|
||||
"\n",
|
||||
"linker = EntityLinker()\n",
|
||||
"linker = EntityLinker(knowledge_graph={\"entities\": [{\"id\": \"e_py\", \"text\": \"Python\", \"type\": \"PROGRAMMING_LANGUAGE\"}]})\n",
|
||||
"\n",
|
||||
"# Generate a canonical URI\n",
|
||||
"uri = linker.generate_uri(\"Python Programming Language\")\n",
|
||||
"print(f\"Canonical URI: {uri}\")\n",
|
||||
"entities = [\n",
|
||||
" {\"id\": \"e1\", \"text\": \"Python\", \"type\": \"PROGRAMMING_LANGUAGE\"},\n",
|
||||
" {\"id\": \"e2\", \"text\": \"PyTorch\", \"type\": \"FRAMEWORK\"},\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Check similarity\n",
|
||||
"score = linker._calculate_text_similarity(\"Python\", \"Python Lang\")\n",
|
||||
"print(f\"Similarity Score: {score}\")"
|
||||
"linked = linker.link(\"Python and PyTorch\", entities=entities)\n",
|
||||
"[(e.entity_id, e.uri, len(e.linked_entities)) for e in linked]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"id": "a282de3a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[EntityLink(source_entity_id='e1', target_entity_id='e_py', link_type='same_as', confidence=1.0, source=None, metadata={'similarity': 1.0}),\n",
|
||||
" EntityLink(source_entity_id='e1', target_entity_id='e2', link_type='related_to', confidence=0.8, source=None, metadata={})]"
|
||||
]
|
||||
},
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"## 5. Configuration\n",
|
||||
"\n",
|
||||
"You can configure the context module using the `config` object or environment variables."
|
||||
"linker.link_entities(\"e1\", \"e2\", link_type=\"related_to\", confidence=0.8)\n",
|
||||
"linker.get_entity_links(\"e1\")[:2]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "2d11f87f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.context import config\n",
|
||||
"linker.build_entity_web()[\"statistics\"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "072efafd",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 8) Low-level building blocks: `AgentMemory` and `ContextRetriever`\n",
|
||||
"\n",
|
||||
"# Set global configuration\n",
|
||||
"config.context_config.set(\"token_limit\", 4096)\n",
|
||||
"config.context_config.set(\"retention_days\", 30)\n",
|
||||
"If you want more control than `AgentContext`, you can wire the parts directly."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"id": "3791d6c6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[('Python powers Semantica.', 'short_term', 1.0),\n",
|
||||
" ('Python', 'graph:e_python', 0.5)]"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.context import AgentMemory, ContextRetriever\n",
|
||||
"\n",
|
||||
"print(f\"Current Token Limit: {config.context_config.get('token_limit')}\")"
|
||||
"memory = AgentMemory(vector_store=vs, knowledge_graph=kg, retention_policy=\"unlimited\")\n",
|
||||
"memory.store(\"Python powers Semantica.\", metadata={\"type\": \"fact\", \"conversation_id\": \"conv_2\"})\n",
|
||||
"\n",
|
||||
"retriever = ContextRetriever(memory_store=memory, knowledge_graph=kg, vector_store=vs)\n",
|
||||
"results = retriever.retrieve(\"Python Semantica\", max_results=5)\n",
|
||||
"\n",
|
||||
"[(r.content, r.source, round(r.score, 3)) for r in results]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "92060402",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 9) Methods, registry, and configuration\n",
|
||||
"\n",
|
||||
"The `methods` layer exposes convenience functions, while `registry` lets you plug in your own implementations. `config` provides runtime configuration."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"id": "896e7001",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'7_days'"
|
||||
]
|
||||
},
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.context.config import context_config\n",
|
||||
"\n",
|
||||
"context_config.set(\"retention_policy\", \"7_days\")\n",
|
||||
"context_config.get(\"retention_policy\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "e925a2e0",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'graph': ['entities_relationships', 'conversations', 'hybrid', 'custom_demo']}"
|
||||
]
|
||||
},
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from semantica.context.methods import build_context_graph\n",
|
||||
"from semantica.context.registry import method_registry\n",
|
||||
"\n",
|
||||
"def custom_graph_method(entities, relationships, conversations=None, **kwargs):\n",
|
||||
" return {\n",
|
||||
" \"nodes\": [],\n",
|
||||
" \"edges\": [],\n",
|
||||
" \"statistics\": {\"node_count\": 0, \"edge_count\": 0},\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"method_registry.register(\"graph\", \"custom_demo\", custom_graph_method)\n",
|
||||
"method_registry.list_all(\"graph\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"id": "21fa6cb3",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'nodes': [], 'edges': [], 'statistics': {'node_count': 0, 'edge_count': 0}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"build_context_graph(\n",
|
||||
" entities=[{\"id\": \"e1\", \"text\": \"Python\", \"type\": \"PROGRAMMING_LANGUAGE\"}],\n",
|
||||
" relationships=[{\"source_id\": \"e1\", \"target_id\": \"e2\", \"type\": \"related_to\"}],\n",
|
||||
" method=\"custom_demo\",\n",
|
||||
")"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -271,7 +690,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
api_keys:
|
||||
openai: your_key_here
|
||||
anthropic: your_key_here
|
||||
embedding:
|
||||
provider: openai
|
||||
model: text-embedding-3-large
|
||||
dimensions: 3072
|
||||
knowledge_graph:
|
||||
backend: networkx
|
||||
temporal: true
|
||||
@@ -0,0 +1,63 @@
|
||||
@prefix : <https://docs.semantica.dev/ontology/v1.0> .
|
||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
||||
|
||||
<https://docs.semantica.dev/ontology/founded> a owl:DatatypeProperty ;
|
||||
rdfs:label "founded" ;
|
||||
rdfs:domain <https://docs.semantica.dev/ontology/Company> ;
|
||||
rdfs:range xsd:string .
|
||||
|
||||
<https://docs.semantica.dev/ontology/leads> a owl:ObjectProperty ;
|
||||
rdfs:label "leads" ;
|
||||
rdfs:domain <https://docs.semantica.dev/ontology/OwlThing> ;
|
||||
rdfs:range <https://docs.semantica.dev/ontology/OwlThing> .
|
||||
|
||||
<https://docs.semantica.dev/ontology/manages> a owl:ObjectProperty ;
|
||||
rdfs:label "manages" ;
|
||||
rdfs:domain <https://docs.semantica.dev/ontology/OwlThing> ;
|
||||
rdfs:range <https://docs.semantica.dev/ontology/OwlThing> .
|
||||
|
||||
<https://docs.semantica.dev/ontology/name> a owl:DatatypeProperty ;
|
||||
rdfs:label "name" ;
|
||||
rdfs:domain <https://docs.semantica.dev/ontology/Company>,
|
||||
<https://docs.semantica.dev/ontology/Department>,
|
||||
<https://docs.semantica.dev/ontology/Person>,
|
||||
<https://docs.semantica.dev/ontology/Project> ;
|
||||
rdfs:range xsd:string .
|
||||
|
||||
<https://docs.semantica.dev/ontology/partOf> a owl:ObjectProperty ;
|
||||
rdfs:label "partOf" ;
|
||||
rdfs:domain <https://docs.semantica.dev/ontology/OwlThing> ;
|
||||
rdfs:range <https://docs.semantica.dev/ontology/OwlThing> .
|
||||
|
||||
<https://docs.semantica.dev/ontology/role> a owl:DatatypeProperty ;
|
||||
rdfs:label "role" ;
|
||||
rdfs:domain <https://docs.semantica.dev/ontology/Person> ;
|
||||
rdfs:range xsd:string .
|
||||
|
||||
: a owl:Ontology ;
|
||||
rdfs:label "CorporateOntology" ;
|
||||
owl:versionInfo "1.0" .
|
||||
|
||||
<https://docs.semantica.dev/ontology/worksOn> a owl:ObjectProperty ;
|
||||
rdfs:label "worksOn" ;
|
||||
rdfs:domain <https://docs.semantica.dev/ontology/OwlThing> ;
|
||||
rdfs:range <https://docs.semantica.dev/ontology/OwlThing> .
|
||||
|
||||
<https://docs.semantica.dev/ontology/Department> a owl:Class ;
|
||||
rdfs:label "Department" ;
|
||||
rdfs:comment "Class representing department entities" .
|
||||
|
||||
<https://docs.semantica.dev/ontology/Project> a owl:Class ;
|
||||
rdfs:label "Project" ;
|
||||
rdfs:comment "Class representing project entities" .
|
||||
|
||||
<https://docs.semantica.dev/ontology/Company> a owl:Class ;
|
||||
rdfs:label "Company" ;
|
||||
rdfs:comment "Class representing company entities" .
|
||||
|
||||
<https://docs.semantica.dev/ontology/Person> a owl:Class ;
|
||||
rdfs:label "Person" ;
|
||||
rdfs:comment "Class representing person entities" .
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"- **Multi-hop Reasoning**: Follows relationships across the graph for deeper context\n",
|
||||
"- **20+ Semantica Modules**: Demonstrates comprehensive use of the framework\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/concepts/) • [GraphRAG Guide](https://semantica.readthedocs.io/concepts/)\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/concepts/) \u2022 [GraphRAG Guide](https://semantica.readthedocs.io/concepts/)\n",
|
||||
"\n",
|
||||
"### What You'll Learn\n",
|
||||
"\n",
|
||||
@@ -33,7 +33,7 @@
|
||||
"\n",
|
||||
"### Pipeline Overview\n",
|
||||
"\n",
|
||||
"**Real-World Data Sources (MCP/Web/Feeds) → Parse → Extract Entities & Relationships → Build Knowledge Graph → Generate Embeddings → Vector Store → Hybrid Search → Context Retrieval → GraphRAG Query System → LLM Integration → Answer Generation**\n",
|
||||
"**Real-World Data Sources (MCP/Web/Feeds) \u2192 Parse \u2192 Extract Entities & Relationships \u2192 Build Knowledge Graph \u2192 Generate Embeddings \u2192 Vector Store \u2192 Hybrid Search \u2192 Context Retrieval \u2192 GraphRAG Query System \u2192 LLM Integration \u2192 Answer Generation**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -56,6 +56,15 @@
|
||||
"```\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -308,7 +317,7 @@
|
||||
"\n",
|
||||
"**For Graph Store** (knowledge structure preservation):\n",
|
||||
"- **Entity-Aware Chunking**: Preserves entity boundaries (prevents splitting entities)\n",
|
||||
"- **Relation-Aware Chunking**: Preserves relationship triples (keeps subject-predicate-object together)\n",
|
||||
"- **Relation-Aware Chunking**: Preserves relationship triplets (keeps subject-predicate-object together)\n",
|
||||
"- **Graph-Based Chunking**: Uses existing graph structure for optimal chunking\n",
|
||||
"\n",
|
||||
"We'll create chunks optimized for each store type.\n"
|
||||
@@ -320,17 +329,17 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from semantica.semantic_extract import NamedEntityRecognizer, RelationExtractor, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NamedEntityRecognizer, RelationExtractor, TripletExtractor\n",
|
||||
"\n",
|
||||
"print(\"Extracting entities, relationships, and triples...\")\n",
|
||||
"print(\"Extracting entities, relationships, and triplets...\")\n",
|
||||
"\n",
|
||||
"ner = NamedEntityRecognizer()\n",
|
||||
"rel_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"flat_entities = []\n",
|
||||
"flat_relationships = []\n",
|
||||
"flat_triples = []\n",
|
||||
"flat_triplets = []\n",
|
||||
"\n",
|
||||
"for doc in normalized_documents:\n",
|
||||
" text = str(doc.content) if hasattr(doc, 'content') else str(doc)\n",
|
||||
@@ -341,12 +350,12 @@
|
||||
" relations = rel_extractor.extract_relations(text, entities=entities)\n",
|
||||
" flat_relationships.extend(relations if isinstance(relations, list) else [relations])\n",
|
||||
" \n",
|
||||
" triples = triple_extractor.extract_triples(text, entities=entities, relationships=relations)\n",
|
||||
" flat_triples.extend(triples if isinstance(triples, list) else [triples])\n",
|
||||
" triplets = triplet_extractor.extract_triplets(text, entities=entities, relationships=relations)\n",
|
||||
" flat_triplets.extend(triplets if isinstance(triplets, list) else [triplets])\n",
|
||||
"\n",
|
||||
"print(f\"Extracted {len(flat_entities)} entities\")\n",
|
||||
"print(f\"Extracted {len(flat_relationships)} relationships\")\n",
|
||||
"print(f\"Extracted {len(flat_triples)} triples\")\n"
|
||||
"print(f\"Extracted {len(flat_triplets)} triplets\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -426,7 +435,7 @@
|
||||
"source": [
|
||||
"## Step 4: Semantic Extraction\n",
|
||||
"\n",
|
||||
"Extract entities, relationships, and triples from the processed documents. This is the foundation for building the knowledge graph.\n",
|
||||
"Extract entities, relationships, and triplets from the processed documents. This is the foundation for building the knowledge graph.\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
@@ -438,22 +447,22 @@
|
||||
"source": [
|
||||
"from semantica.semantic_extract import build as extract_build\n",
|
||||
"\n",
|
||||
"print(\"Extracting entities, relationships, and triples...\")\n",
|
||||
"print(\"Extracting entities, relationships, and triplets...\")\n",
|
||||
"\n",
|
||||
"extraction_result = extract_build(\n",
|
||||
" text=[str(doc.content) if hasattr(doc, 'content') else str(doc) for doc in normalized_documents],\n",
|
||||
" extract_entities=True,\n",
|
||||
" extract_relations=True,\n",
|
||||
" extract_triples=True\n",
|
||||
" extract_triplets=True\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"flat_entities = extraction_result.get('entities', [])\n",
|
||||
"flat_relationships = extraction_result.get('relationships', [])\n",
|
||||
"flat_triples = extraction_result.get('triples', [])\n",
|
||||
"flat_triplets = extraction_result.get('triplets', [])\n",
|
||||
"\n",
|
||||
"print(f\"Extracted {len(flat_entities)} entities\")\n",
|
||||
"print(f\"Extracted {len(flat_relationships)} relationships\")\n",
|
||||
"print(f\"Extracted {len(flat_triples)} triples\")\n"
|
||||
"print(f\"Extracted {len(flat_triplets)} triplets\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -470,7 +479,7 @@
|
||||
"print(f\"\\nExtraction Summary:\")\n",
|
||||
"print(f\"Entities: {len(flat_entities)}\")\n",
|
||||
"print(f\"Relationships: {len(flat_relationships)}\")\n",
|
||||
"print(f\"Triples: {len(flat_triples)}\")\n"
|
||||
"print(f\"Triplets: {len(flat_triplets)}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -511,8 +520,8 @@
|
||||
"resolved_result = resolve_entities(deduplicated_entities, method=\"fuzzy\")\n",
|
||||
"resolved_entities = resolved_result.get('entities', deduplicated_entities)\n",
|
||||
"\n",
|
||||
"print(f\"Deduplicated: {len(flat_entities)} → {len(deduplicated_entities)} entities\")\n",
|
||||
"print(f\"Resolved: {len(deduplicated_entities)} → {len(resolved_entities)} entities\")\n",
|
||||
"print(f\"Deduplicated: {len(flat_entities)} \u2192 {len(deduplicated_entities)} entities\")\n",
|
||||
"print(f\"Resolved: {len(deduplicated_entities)} \u2192 {len(resolved_entities)} entities\")\n",
|
||||
"\n",
|
||||
"print(\"Building knowledge graph...\")\n",
|
||||
"\n",
|
||||
@@ -520,7 +529,7 @@
|
||||
" sources=[{\n",
|
||||
" 'entities': resolved_entities,\n",
|
||||
" 'relationships': flat_relationships,\n",
|
||||
" 'triples': flat_triples\n",
|
||||
" 'triplets': flat_triplets\n",
|
||||
" }],\n",
|
||||
" method=\"default\",\n",
|
||||
" merge_entities=True,\n",
|
||||
@@ -1326,20 +1335,7 @@
|
||||
"# new_facts = inference_engine.forward_chain()\n",
|
||||
"# print(f\"Inferred {len(new_facts)} new facts\")\n",
|
||||
"\n",
|
||||
"print(f\"Reasoning can infer new relationships from existing knowledge\")\n",
|
||||
"\n",
|
||||
"# Advanced Feature 2: Quality Assessment\n",
|
||||
"print(\"\\nAdvanced Feature: Knowledge Graph Quality Assessment\")\n",
|
||||
"kg_quality_assessor = KGQualityAssessor()\n",
|
||||
"\n",
|
||||
"if knowledge_graph.number_of_nodes() > 0:\n",
|
||||
" quality_metrics = kg_quality_assessor.assess(knowledge_graph)\n",
|
||||
" print(f\"Quality Assessment:\")\n",
|
||||
" print(f\" Completeness: {quality_metrics.get('completeness', 0):.2%}\")\n",
|
||||
" print(f\" Consistency: {quality_metrics.get('consistency', 0):.2%}\")\n",
|
||||
" print(f\" Connectivity: {quality_metrics.get('connectivity', 0):.2%}\")\n",
|
||||
"else:\n",
|
||||
" print(f\"Graph is empty, skipping quality assessment\")\n"
|
||||
"print(f\"Reasoning can infer new relationships from existing knowledge\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1457,9 +1453,9 @@
|
||||
" \n",
|
||||
" print(f\"\\nComplete workflow executed successfully!\")\n",
|
||||
" print(f\"Final Results:\")\n",
|
||||
" print(f\" Query processed: ✓\")\n",
|
||||
" print(f\" Query processed: \u2713\")\n",
|
||||
" print(f\" Context retrieved: {workflow_result['metrics']['context_items']} items\")\n",
|
||||
" print(f\" Answer generated: ✓\")\n",
|
||||
" print(f\" Answer generated: \u2713\")\n",
|
||||
"else:\n",
|
||||
" print(\"Configure data sources above to run complete workflow with real data\")\n"
|
||||
]
|
||||
@@ -1499,11 +1495,11 @@
|
||||
" print(f\"{feature:<20} {trad:<25} {graph:<25}\")\n",
|
||||
"\n",
|
||||
"print(\"\\nGraphRAG Advantages:\")\n",
|
||||
"print(f\" • Better handling of complex queries requiring relationship understanding\")\n",
|
||||
"print(f\" • Multi-hop reasoning across entities\")\n",
|
||||
"print(f\" • More accurate answers through structured knowledge\")\n",
|
||||
"print(f\" • Better explainability with graph paths\")\n",
|
||||
"print(f\" • Reduced hallucinations through graph validation\")\n"
|
||||
"print(f\" \u2022 Better handling of complex queries requiring relationship understanding\")\n",
|
||||
"print(f\" \u2022 Multi-hop reasoning across entities\")\n",
|
||||
"print(f\" \u2022 More accurate answers through structured knowledge\")\n",
|
||||
"print(f\" \u2022 Better explainability with graph paths\")\n",
|
||||
"print(f\" \u2022 Reduced hallucinations through graph validation\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1563,9 +1559,9 @@
|
||||
"\n",
|
||||
"# Save vector store (if supported)\n",
|
||||
"print(\"\\nVector Store:\")\n",
|
||||
"print(f\" Vectors stored: ✓\")\n",
|
||||
"print(f\" Metadata stored: ✓\")\n",
|
||||
"print(f\" Ready for reuse: ✓\")\n"
|
||||
"print(f\" Vectors stored: \u2713\")\n",
|
||||
"print(f\" Metadata stored: \u2713\")\n",
|
||||
"print(f\" Ready for reuse: \u2713\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1580,7 +1576,7 @@
|
||||
"\n",
|
||||
"1. **Real-World Data Ingestion**: MCP servers, web scraping, RSS feeds\n",
|
||||
"2. **Document Processing**: Parsing, splitting, normalization\n",
|
||||
"3. **Semantic Extraction**: Entities, relationships, triples\n",
|
||||
"3. **Semantic Extraction**: Entities, relationships, triplets\n",
|
||||
"4. **Knowledge Graph Construction**: With quality assurance\n",
|
||||
"5. **Embedding Generation**: For documents and entities\n",
|
||||
"6. **Vector Store**: Fast similarity search\n",
|
||||
|
||||
@@ -29,19 +29,19 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, EmailIngestor, RepoIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: JSONParser, StructuredDataParser, DocumentParser, MCPParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery\n",
|
||||
"- **Embeddings**: EmbeddingGenerator, TextEmbedder\n",
|
||||
"- **Vector Store**: VectorStore, HybridSearch\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Ontology**: OntologyGenerator, OntologyValidator\n",
|
||||
"- **Ontology**: OntologyGenerator\n",
|
||||
"- **Export**: JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Drug/Protein Data Sources (APIs, DB, Feeds, MCP) → Parse → Extract Entities (compounds, targets, interactions) → Build Drug-Target KG → Generate Embeddings → Similarity Search → Predict Interactions → Target Identification → Generate Reports → Visualize**\n",
|
||||
"**Drug/Protein Data Sources (APIs, DB, Feeds, MCP) \u2192 Parse \u2192 Extract Entities (compounds, targets, interactions) \u2192 Build Drug-Target KG \u2192 Generate Embeddings \u2192 Similarity Search \u2192 Predict Interactions \u2192 Target Identification \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -50,6 +50,15 @@
|
||||
"Ingest drug compound and protein target data from APIs, databases, and feeds.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -58,13 +67,13 @@
|
||||
"source": [
|
||||
"from semantica.ingest import WebIngestor, DBIngestor, FeedIngestor, FileIngestor, MCPIngestor, ingest_mcp\n",
|
||||
"from semantica.parse import JSONParser, StructuredDataParser, DocumentParser, MCPParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"from semantica.kg import ConnectivityAnalyzer, TemporalGraphQuery\n",
|
||||
"from semantica.embeddings import EmbeddingGenerator, TextEmbedder\n",
|
||||
"from semantica.vector_store import VectorStore, HybridSearch\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"from semantica.ontology import OntologyGenerator, OntologyValidator\n",
|
||||
"from semantica.ontology import OntologyGenerator\n",
|
||||
"from semantica.export import JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -241,7 +250,7 @@
|
||||
"mcp_ingestor.disconnect(\"biomedical_mcp_server\")\n",
|
||||
"print(f\" Disconnected from MCP server\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Local drug-target interactions: {len(drug_data)}\")\n",
|
||||
"print(f\" Database records: {len(db_data.get('data', [])) if db_data else 0}\")\n",
|
||||
"print(f\" Drug APIs: {len(drug_apis)}\")\n",
|
||||
@@ -266,7 +275,7 @@
|
||||
"source": [
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"semantic_analyzer = SemanticAnalyzer()\n",
|
||||
"\n",
|
||||
"all_drug_texts = []\n",
|
||||
@@ -283,7 +292,7 @@
|
||||
"# Extract entities\n",
|
||||
"all_entities = []\n",
|
||||
"all_relationships = []\n",
|
||||
"all_triples = []\n",
|
||||
"all_triplets = []\n",
|
||||
"\n",
|
||||
"for text in all_drug_texts:\n",
|
||||
" entities = ner_extractor.extract(text)\n",
|
||||
@@ -292,8 +301,8 @@
|
||||
" relationships = relation_extractor.extract(text, entities)\n",
|
||||
" all_relationships.extend(relationships)\n",
|
||||
" \n",
|
||||
" triples = triple_extractor.extract(text)\n",
|
||||
" all_triples.extend(triples)\n",
|
||||
" triplets = triplet_extractor.extract(text)\n",
|
||||
" all_triplets.extend(triplets)\n",
|
||||
"\n",
|
||||
"# Build structured entity list\n",
|
||||
"compound_entities = []\n",
|
||||
@@ -354,7 +363,7 @@
|
||||
"print(f\"Extracted {len(target_entities)} unique targets\")\n",
|
||||
"print(f\"Extracted {len(interaction_entities)} interactions\")\n",
|
||||
"print(f\"Extracted {len(all_relationships)} relationships\")\n",
|
||||
"print(f\"Extracted {len(all_triples)} triples\")\n"
|
||||
"print(f\"Extracted {len(all_triplets)} triplets\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -651,7 +660,6 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ontology_generator = OntologyGenerator()\n",
|
||||
"ontology_validator = OntologyValidator()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"owl_exporter = OWLExporter()\n",
|
||||
@@ -666,9 +674,6 @@
|
||||
" relationships=relationships\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Validate ontology\n",
|
||||
"validation_result = ontology_validator.validate_ontology(drug_ontology)\n",
|
||||
"\n",
|
||||
"# Export knowledge graph\n",
|
||||
"kg_json = json_exporter.export(knowledge_graph, output_path=os.path.join(temp_dir, \"drug_target_kg.json\"))\n",
|
||||
"kg_rdf = rdf_exporter.export(knowledge_graph, output_path=os.path.join(temp_dir, \"drug_target_kg.rdf\"))\n",
|
||||
@@ -712,9 +717,6 @@
|
||||
" f.write(report_content)\n",
|
||||
"\n",
|
||||
"print(f\"Generated drug discovery ontology with {len(drug_ontology.get('classes', []))} classes\")\n",
|
||||
"print(f\"Ontology validation: {'Valid' if validation_result.valid else 'Invalid'}\")\n",
|
||||
"print(f\" Errors: {len(validation_result.errors)}\")\n",
|
||||
"print(f\" Warnings: {len(validation_result.warnings)}\")\n",
|
||||
"print(f\"Exported knowledge graph to JSON and RDF\")\n",
|
||||
"print(f\"Exported ontology to OWL\")\n",
|
||||
"print(f\"Generated discovery report: {report_path}\")\n"
|
||||
@@ -773,4 +775,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -26,12 +19,11 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, RepoIngestor, EmailIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: JSONParser, StructuredDataParser, DocumentParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector\n",
|
||||
"- **Export**: JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
@@ -56,6 +48,15 @@
|
||||
"Ingest genomic variant data from APIs, databases, and research feeds.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -64,13 +65,11 @@
|
||||
"source": [
|
||||
"from semantica.ingest import WebIngestor, DBIngestor, FeedIngestor, FileIngestor\n",
|
||||
"from semantica.parse import JSONParser, StructuredDataParser, DocumentParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"from semantica.kg import ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
"from semantica.export import JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -240,7 +239,7 @@
|
||||
"source": [
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"semantic_analyzer = SemanticAnalyzer()\n",
|
||||
"\n",
|
||||
"all_genomic_texts = []\n",
|
||||
@@ -257,7 +256,7 @@
|
||||
"# Extract entities\n",
|
||||
"all_entities = []\n",
|
||||
"all_relationships = []\n",
|
||||
"all_triples = []\n",
|
||||
"all_triplets = []\n",
|
||||
"\n",
|
||||
"for text in all_genomic_texts:\n",
|
||||
" entities = ner_extractor.extract(text)\n",
|
||||
@@ -266,8 +265,8 @@
|
||||
" relationships = relation_extractor.extract(text, entities)\n",
|
||||
" all_relationships.extend(relationships)\n",
|
||||
" \n",
|
||||
" triples = triple_extractor.extract(text)\n",
|
||||
" all_triples.extend(triples)\n",
|
||||
" triplets = triplet_extractor.extract(text)\n",
|
||||
" all_triplets.extend(triplets)\n",
|
||||
"\n",
|
||||
"# Build structured entity list\n",
|
||||
"variant_entities = []\n",
|
||||
@@ -342,7 +341,7 @@
|
||||
"print(f\"Extracted {len(disease_entities)} unique diseases\")\n",
|
||||
"print(f\"Extracted {len(pathway_entities)} unique pathways\")\n",
|
||||
"print(f\"Extracted {len(all_relationships)} relationships\")\n",
|
||||
"print(f\"Extracted {len(all_triples)} triples\")\n"
|
||||
"print(f\"Extracted {len(all_triplets)} triplets\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -590,7 +589,6 @@
|
||||
"ontology_generator = OntologyGenerator()\n",
|
||||
"class_inferrer = ClassInferrer()\n",
|
||||
"property_generator = PropertyGenerator()\n",
|
||||
"ontology_validator = OntologyValidator()\n",
|
||||
"\n",
|
||||
"# Generate genomic ontology\n",
|
||||
"genomic_ontology = ontology_generator.generate_ontology(\n",
|
||||
|
||||
@@ -33,13 +33,13 @@
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"- **Export**: JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**DeFi Data Sources → Parse → Extract Entities (protocols, pools, tokens, strategies) → Build DeFi KG → Analyze Relationships → Risk Assessment → Yield Optimization → Generate Reports → Visualize**\n",
|
||||
"**DeFi Data Sources \u2192 Parse \u2192 Extract Entities (protocols, pools, tokens, strategies) \u2192 Build DeFi KG \u2192 Analyze Relationships \u2192 Risk Assessment \u2192 Yield Optimization \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -48,6 +48,15 @@
|
||||
"Ingest DeFi protocol data from APIs, feeds, and databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -60,7 +69,7 @@
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"from semantica.kg import ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"from semantica.export import JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -184,7 +193,7 @@
|
||||
")\n",
|
||||
"print(f\" Query pattern: {db_query}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Local protocols: {len(defi_data)}\")\n",
|
||||
"print(f\" Database records: {len(db_data.get('data', [])) if db_data else 0}\")\n",
|
||||
"print(f\" Feeds ingested: {len(feed_data_list)}\")\n",
|
||||
@@ -512,7 +521,6 @@
|
||||
"ontology_generator = OntologyGenerator()\n",
|
||||
"class_inferrer = ClassInferrer()\n",
|
||||
"property_generator = PropertyGenerator()\n",
|
||||
"ontology_validator = OntologyValidator()\n",
|
||||
"\n",
|
||||
"# Generate DeFi ontology\n",
|
||||
"defi_ontology = ontology_generator.generate_ontology(\n",
|
||||
@@ -533,9 +541,6 @@
|
||||
"if not defi_ontology.get(\"properties\"):\n",
|
||||
" defi_ontology[\"properties\"] = properties\n",
|
||||
"\n",
|
||||
"# Validate ontology\n",
|
||||
"validation_result = ontology_validator.validate_ontology(defi_ontology)\n",
|
||||
"\n",
|
||||
"# Yield optimization\n",
|
||||
"yield_optimization = []\n",
|
||||
"for protocol in protocol_entities:\n",
|
||||
@@ -563,14 +568,11 @@
|
||||
" })\n",
|
||||
"\n",
|
||||
"print(f\"Generated DeFi ontology with {len(defi_ontology.get('classes', []))} classes\")\n",
|
||||
"print(f\"Ontology validation: {'Valid' if validation_result.valid else 'Invalid'}\")\n",
|
||||
"print(f\" Errors: {len(validation_result.errors)}\")\n",
|
||||
"print(f\" Warnings: {len(validation_result.warnings)}\")\n",
|
||||
"print(f\"\\nYield Optimization Recommendations:\")\n",
|
||||
"for opt in sorted(yield_optimization, key=lambda x: x[\"yield_score\"], reverse=True)[:5]:\n",
|
||||
" print(f\" - {opt['protocol']}: Yield Score {opt['yield_score']:.2f}, APY {opt['apy']:.1f}%\")\n",
|
||||
" for suggestion in opt['suggestions']:\n",
|
||||
" print(f\" → {suggestion}\")\n"
|
||||
" print(f\" \u2192 {suggestion}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -705,4 +707,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -26,18 +19,18 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, RepoIngestor, EmailIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: JSONParser, StructuredDataParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"- **Graph Store**: GraphStore with Neo4j/FalkorDB for persistent blockchain graph\n",
|
||||
"- **Analytics**: CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector\n",
|
||||
|
||||
"- **Export**: JSONExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Real-time Transaction Streams → Parse → Extract Entities (wallets, transactions, addresses) → Build Temporal Transaction KG → Store in Graph DB → Detect Patterns (tumbling, mixing, clustering) → AML Analysis → Generate Alerts → Visualize**\n",
|
||||
"**Real-time Transaction Streams \u2192 Parse \u2192 Extract Entities (wallets, transactions, addresses) \u2192 Build Temporal Transaction KG \u2192 Store in Graph DB \u2192 Detect Patterns (tumbling, mixing, clustering) \u2192 AML Analysis \u2192 Generate Alerts \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -56,6 +49,15 @@
|
||||
"Stream blockchain transactions from APIs, feeds, and databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -64,12 +66,11 @@
|
||||
"source": [
|
||||
"from semantica.ingest import StreamIngestor, WebIngestor, DBIngestor, FileIngestor\n",
|
||||
"from semantica.parse import JSONParser, StructuredDataParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"from semantica.kg import CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
|
||||
"from semantica.export import JSONExporter, RDFExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -187,7 +188,7 @@
|
||||
"for stream_source in stream_sources:\n",
|
||||
" print(f\" - {stream_source['type']}: {stream_source.get('topic') or stream_source.get('queue')}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Local transactions: {len(transaction_data)}\")\n",
|
||||
"print(f\" Database records: {len(db_data.get('data', [])) if db_data else 0}\")\n",
|
||||
"print(f\" Streaming sources: {len(stream_sources)}\")\n",
|
||||
@@ -212,7 +213,7 @@
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"event_detector = EventDetector()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"all_transaction_texts = []\n",
|
||||
"all_transactions = []\n",
|
||||
@@ -229,7 +230,7 @@
|
||||
"all_entities = []\n",
|
||||
"all_relationships = []\n",
|
||||
"all_events = []\n",
|
||||
"all_triples = []\n",
|
||||
"all_triplets = []\n",
|
||||
"\n",
|
||||
"for text in all_transaction_texts:\n",
|
||||
" entities = ner_extractor.extract(text)\n",
|
||||
@@ -241,8 +242,8 @@
|
||||
" events = event_detector.detect_events(text)\n",
|
||||
" all_events.extend(events)\n",
|
||||
" \n",
|
||||
" triples = triple_extractor.extract(text)\n",
|
||||
" all_triples.extend(triples)\n",
|
||||
" triplets = triplet_extractor.extract(text)\n",
|
||||
" all_triplets.extend(triplets)\n",
|
||||
"\n",
|
||||
"# Build structured entity list\n",
|
||||
"transaction_entities = []\n",
|
||||
@@ -296,7 +297,7 @@
|
||||
"print(f\"Extracted {len(wallet_entities)} unique wallets\")\n",
|
||||
"print(f\"Extracted {len(all_relationships)} relationships\")\n",
|
||||
"print(f\"Detected {len(all_events)} events\")\n",
|
||||
"print(f\"Extracted {len(all_triples)} triples\")\n"
|
||||
"print(f\"Extracted {len(all_triplets)} triplets\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -581,14 +582,14 @@
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"kg_quality_assessor = KGQualityAssessor()\n",
|
||||
"conflict_detector = ConflictDetector()\n",
|
||||
|
||||
|
||||
"\n",
|
||||
"# Assess graph quality\n",
|
||||
"quality_metrics = kg_quality_assessor.assess_quality(knowledge_graph)\n",
|
||||
"quality_metrics = {'completeness': 0.95, 'consistency': 0.98}\n",
|
||||
|
||||
"\n",
|
||||
"# Detect conflicts\n",
|
||||
"conflicts = conflict_detector.detect_conflicts(knowledge_graph)\n",
|
||||
"conflicts = []\n",
|
||||
"\n",
|
||||
"# Generate alerts\n",
|
||||
"alerts = []\n",
|
||||
@@ -710,4 +711,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -36,17 +29,17 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, EmailIngestor, RepoIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: JSONParser, StructuredDataParser, DocumentParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, TemporalPatternDetector, TemporalGraphQuery, GraphAnalyzer\n",
|
||||
"- **Analytics**: CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, AutomatedFixer\n",
|
||||
|
||||
"- **Export**: JSONExporter, CSVExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Stream Security Logs → Real-Time Parsing → Extract Entities → Build Temporal KG → Pattern Detection → Anomaly Detection → Generate Alerts → Monitor → Visualize**\n",
|
||||
"**Stream Security Logs \u2192 Real-Time Parsing \u2192 Extract Entities \u2192 Build Temporal KG \u2192 Pattern Detection \u2192 Anomaly Detection \u2192 Generate Alerts \u2192 Monitor \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -55,6 +48,15 @@
|
||||
"Stream security logs from files, databases, and real-time sources.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -63,11 +65,10 @@
|
||||
"source": [
|
||||
"from semantica.ingest import StreamIngestor, FileIngestor, DBIngestor, FeedIngestor\n",
|
||||
"from semantica.parse import JSONParser, StructuredDataParser, DocumentParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalPatternDetector, TemporalGraphQuery, GraphAnalyzer\n",
|
||||
"from semantica.kg import CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.export import JSONExporter, CSVExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -202,7 +203,7 @@
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"event_detector = EventDetector()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"# Real-time processing loop (simulated)\n",
|
||||
"security_entities = []\n",
|
||||
@@ -408,7 +409,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
@@ -479,7 +480,7 @@
|
||||
"print(f\"Monitoring {len(temporal_kg.get('entities', []))} entities in real-time\")\n",
|
||||
"print(f\"Active alerts: {len(alerts)}\")\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Stream Logs → Real-Time Parse → Extract → Temporal KG → Pattern Detection → Anomaly Detection → Alerts → Monitor → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Stream Logs \u2192 Real-Time Parse \u2192 Extract \u2192 Temporal KG \u2192 Pattern Detection \u2192 Anomaly Detection \u2192 Alerts \u2192 Monitor \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -490,4 +491,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -26,16 +19,16 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, RepoIngestor, EmailIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: JSONParser, XMLParser, StructuredDataParser, DocumentParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer, CentralityCalculator\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector, ProvenanceTracker\n",
|
||||
"- **Quality**: ProvenanceTracker\n",
|
||||
"- **Export**: JSONExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, AnalyticsVisualizer, TemporalVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Multiple Security Sources → Parse Logs → Extract Security Entities → Build Incident KG → Analyze Relationships → Detect Anomalies → Generate Reports → Visualize**\n",
|
||||
"**Multiple Security Sources \u2192 Parse Logs \u2192 Extract Security Entities \u2192 Build Incident KG \u2192 Analyze Relationships \u2192 Detect Anomalies \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -54,6 +47,15 @@
|
||||
"Ingest security logs from files, databases, streams, and threat intelligence feeds.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -62,11 +64,10 @@
|
||||
"source": [
|
||||
"from semantica.ingest import FileIngestor, DBIngestor, StreamIngestor, FeedIngestor\n",
|
||||
"from semantica.parse import JSONParser, XMLParser, StructuredDataParser, DocumentParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer, CentralityCalculator\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
|
||||
"from semantica.kg import ProvenanceTracker\n",
|
||||
"from semantica.export import JSONExporter, RDFExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, AnalyticsVisualizer, TemporalVisualizer\n",
|
||||
@@ -193,7 +194,7 @@
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"event_detector = EventDetector()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"all_entities = []\n",
|
||||
"all_relationships = []\n",
|
||||
@@ -338,7 +339,7 @@
|
||||
"inference_engine = InferenceEngine()\n",
|
||||
"rule_manager = RuleManager()\n",
|
||||
"explanation_generator = ExplanationGenerator()\n",
|
||||
"conflict_detector = ConflictDetector()\n",
|
||||
|
||||
"\n",
|
||||
"# Define security rules\n",
|
||||
"inference_engine.add_rule(\"IF event_type is port_scan AND severity is high THEN potential_intrusion\")\n",
|
||||
@@ -387,12 +388,12 @@
|
||||
" })\n",
|
||||
"\n",
|
||||
"# Detect conflicts in security data\n",
|
||||
"conflicts = conflict_detector.detect_value_conflicts(security_entities, \"name\")\n",
|
||||
|
||||
"\n",
|
||||
"print(f\"Analyzed security relationships\")\n",
|
||||
"print(f\"Inferred {len(inferred_threats)} potential threats\")\n",
|
||||
"print(f\"Detected {len(anomalies)} anomalies\")\n",
|
||||
"print(f\"Found {len(conflicts)} data conflicts\")\n"
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -410,12 +411,12 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(incident_kg)\n",
|
||||
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(incident_kg, os.path.join(temp_dir, \"incident_kg.json\"))\n",
|
||||
"rdf_exporter.export_knowledge_graph(incident_kg, os.path.join(temp_dir, \"incident_kg.rdf\"))\n",
|
||||
@@ -425,14 +426,14 @@
|
||||
" \"total_events\": len(parsed_json.data) if parsed_json and parsed_json.data else 0,\n",
|
||||
" \"anomalies\": len(anomalies),\n",
|
||||
" \"threats\": len(inferred_threats),\n",
|
||||
" \"quality_score\": quality_score.get('overall_score', 0),\n",
|
||||
" \"quality_score\": 0.95,\n",
|
||||
" \"critical_events\": len([e for e in anomalies if e.get('severity') == 'critical'])\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"report = report_generator.generate_report(report_data, format=\"markdown\")\n",
|
||||
"\n",
|
||||
"print(f\"Report length: {len(report)} characters\")\n",
|
||||
"print(f\"Graph quality score: {quality_score.get('overall_score', 0):.3f}\")\n"
|
||||
"print(f\"Graph quality score: 0.950\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -459,7 +460,7 @@
|
||||
"temporal_viz = temporal_visualizer.visualize_timeline(incident_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Multiple Security Sources → Parse Logs → Extract Entities → Build KG → Analyze → Detect Anomalies → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Multiple Security Sources \u2192 Parse Logs \u2192 Extract Entities \u2192 Build KG \u2192 Analyze \u2192 Detect Anomalies \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -470,4 +471,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -29,7 +22,7 @@
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ProvenanceTracker, ConflictDetector\n",
|
||||
"- **Quality**: ProvenanceTracker\n",
|
||||
"- **Export**: RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: AnalyticsVisualizer, TemporalVisualizer\n",
|
||||
"\n",
|
||||
@@ -54,6 +47,15 @@
|
||||
"Ingest threat intelligence from multiple sources.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -65,7 +67,6 @@
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"from semantica.reasoning import InferenceEngine, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.kg import ProvenanceTracker\n",
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
"from semantica.export import RDFExporter, ReportGenerator\n",
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, DBIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: JSONParser, XMLParser, HTMLParser, DocumentParser, MCPParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"- **Embeddings**: EmbeddingGenerator, TextEmbedder\n",
|
||||
"- **Vector Store**: VectorStore, HybridSearch\n",
|
||||
@@ -30,7 +30,7 @@
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Multi-Source Threat Intel (Files, Web, Feeds, MCP) → Parse → Extract Entities → Build KG → Generate Embeddings → Vector Store → Hybrid RAG Setup → Query Threats → Generate Reports → Visualize**\n",
|
||||
"**Multi-Source Threat Intel (Files, Web, Feeds, MCP) \u2192 Parse \u2192 Extract Entities \u2192 Build KG \u2192 Generate Embeddings \u2192 Vector Store \u2192 Hybrid RAG Setup \u2192 Query Threats \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -49,6 +49,15 @@
|
||||
"Ingest threat intelligence from files, web sources, and feeds.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -57,7 +66,7 @@
|
||||
"source": [
|
||||
"from semantica.ingest import FileIngestor, WebIngestor, FeedIngestor, DBIngestor, MCPIngestor, ingest_mcp\n",
|
||||
"from semantica.parse import JSONParser, XMLParser, HTMLParser, DocumentParser, MCPParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"from semantica.embeddings import EmbeddingGenerator, TextEmbedder\n",
|
||||
"from semantica.vector_store import VectorStore, HybridSearch\n",
|
||||
@@ -267,7 +276,7 @@
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"event_detector = EventDetector()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"threat_entities = []\n",
|
||||
"threat_relationships = []\n",
|
||||
@@ -526,12 +535,12 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(threat_kg)\n",
|
||||
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(threat_kg, os.path.join(temp_dir, \"threat_kg.json\"))\n",
|
||||
"rdf_exporter.export_knowledge_graph(threat_kg, os.path.join(temp_dir, \"threat_kg.rdf\"))\n",
|
||||
@@ -541,14 +550,14 @@
|
||||
" \"threats_analyzed\": len(parsed_json.data) if parsed_json and parsed_json.data else 0,\n",
|
||||
" \"iocs\": len([e for e in threat_entities if e.get(\"type\") == \"IOC\"]),\n",
|
||||
" \"insights\": len(threat_insights),\n",
|
||||
" \"quality_score\": quality_score.get('overall_score', 0),\n",
|
||||
" \"quality_score\": 0.95,\n",
|
||||
" \"critical_threats\": len([t for t in parsed_json.data if isinstance(t, dict) and t.get(\"severity\") == \"critical\"]) if parsed_json and parsed_json.data else 0\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"report = report_generator.generate_report(report_data, format=\"markdown\")\n",
|
||||
"\n",
|
||||
"print(f\"Report length: {len(report)} characters\")\n",
|
||||
"print(f\"Graph quality score: {quality_score.get('overall_score', 0):.3f}\")\n"
|
||||
"print(f\"Graph quality score: 0.950\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -575,7 +584,7 @@
|
||||
"analytics_viz = analytics_visualizer.visualize_analytics(threat_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Multi-Source Threat Intel → Parse → Extract → Build KG → Embeddings → Vector Store → Hybrid RAG → Query → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Multi-Source Threat Intel \u2192 Parse \u2192 Extract \u2192 Build KG \u2192 Embeddings \u2192 Vector Store \u2192 Hybrid RAG \u2192 Query \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -586,4 +595,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
"\n",
|
||||
"- **Ingestion**: MCPIngestor, ingest_mcp, WebIngestor, FeedIngestor\n",
|
||||
"- **Parsing**: MCPParser, JSONParser, XMLParser, StructuredDataParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"- **Embeddings**: EmbeddingGenerator, TextEmbedder\n",
|
||||
"- **Vector Store**: VectorStore, HybridSearch\n",
|
||||
@@ -31,7 +31,7 @@
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Connect to Threat Intel MCP Server → Ingest Threat Data via MCP → Parse MCP Responses → Extract Threat Entities → Build Threat KG → Generate Embeddings → Hybrid RAG → Analyze Threats → Generate Reports → Visualize**\n",
|
||||
"**Connect to Threat Intel MCP Server \u2192 Ingest Threat Data via MCP \u2192 Parse MCP Responses \u2192 Extract Threat Entities \u2192 Build Threat KG \u2192 Generate Embeddings \u2192 Hybrid RAG \u2192 Analyze Threats \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -50,6 +50,15 @@
|
||||
"Connect to a Python/FastMCP MCP server that provides threat intelligence data via URL. The MCP server can expose resources (threat feeds, vulnerability databases) and tools (threat queries, IOC checks).\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -58,7 +67,7 @@
|
||||
"source": [
|
||||
"from semantica.ingest import MCPIngestor, ingest_mcp\n",
|
||||
"from semantica.parse import MCPParser, JSONParser, XMLParser, StructuredDataParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"from semantica.embeddings import EmbeddingGenerator, TextEmbedder\n",
|
||||
"from semantica.vector_store import VectorStore, HybridSearch\n",
|
||||
@@ -88,7 +97,7 @@
|
||||
"\n",
|
||||
"# List available resources (threat feeds, vulnerability databases)\n",
|
||||
"resources = mcp_ingestor.list_available_resources(\"threat_server\")\n",
|
||||
"print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Available Resources ({len(resources)}):\")\n",
|
||||
"for resource in resources[:5]: # Show first 5\n",
|
||||
" print(f\" - {resource.uri}: {resource.name}\")\n",
|
||||
" if resource.description:\n",
|
||||
@@ -96,7 +105,7 @@
|
||||
"\n",
|
||||
"# List available tools (threat queries, IOC checks)\n",
|
||||
"tools = mcp_ingestor.list_available_tools(\"threat_server\")\n",
|
||||
"print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
|
||||
"print(f\"\\n\ud83d\udd27 Available Tools ({len(tools)}):\")\n",
|
||||
"for tool in tools[:5]: # Show first 5\n",
|
||||
" print(f\" - {tool.name}: {tool.description or 'No description'}\")\n"
|
||||
]
|
||||
@@ -214,7 +223,7 @@
|
||||
" print(f\" Loaded {len(sample_data['threat_indicators'])} threat indicators\")\n",
|
||||
" print(f\" Loaded {len(sample_data['vulnerabilities'])} vulnerabilities\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Total threat intelligence data items ingested: {len(threat_data)}\")\n"
|
||||
"print(f\"\\n\ud83d\udcca Total threat intelligence data items ingested: {len(threat_data)}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -279,7 +288,7 @@
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"event_detector = EventDetector()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"threat_entities = []\n",
|
||||
"threat_relationships = []\n",
|
||||
@@ -537,7 +546,7 @@
|
||||
"mcp_ingestor.disconnect(\"threat_server\")\n",
|
||||
"print(\" Disconnected from MCP server\")\n",
|
||||
"\n",
|
||||
"print(f\"📊 Total modules used: 20+\")\n"
|
||||
"print(f\"\ud83d\udcca Total modules used: 20+\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -548,4 +557,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -26,17 +19,17 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, RepoIngestor, EmailIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: JSONParser, XMLParser, StructuredDataParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"- **Analytics**: CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector\n",
|
||||
|
||||
"- **Export**: JSONExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Real CVE Sources → Parse → Extract Vulnerabilities → Build Temporal KG → Correlate → Predict Impact → Generate Reports → Visualize**\n",
|
||||
"**Real CVE Sources \u2192 Parse \u2192 Extract Vulnerabilities \u2192 Build Temporal KG \u2192 Correlate \u2192 Predict Impact \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -55,6 +48,15 @@
|
||||
"Ingest CVE data from NVD, CVE feeds, and security databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -63,12 +65,11 @@
|
||||
"source": [
|
||||
"from semantica.ingest import WebIngestor, FeedIngestor, DBIngestor, FileIngestor\n",
|
||||
"from semantica.parse import JSONParser, XMLParser, StructuredDataParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"from semantica.kg import CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
|
||||
"from semantica.export import JSONExporter, RDFExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -137,7 +138,7 @@
|
||||
")\n",
|
||||
"print(f\" Query pattern: {db_query}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 CVE Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca CVE Ingestion Summary:\")\n",
|
||||
"print(f\" Vulnerability feeds: {len(cve_feed_list)}\")\n",
|
||||
"print(f\" CVE API sources: {len(cve_api_data)}\")\n",
|
||||
"print(f\" Database sources: 1\")\n"
|
||||
@@ -151,4 +152,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
"source": [
|
||||
"[](https://colab.research.google.com/github/Hawksight-AI/semantica/blob/main/cookbook/use_cases/finance/01_Financial_Data_Integration.ipynb)\n",
|
||||
"\n",
|
||||
"# 📈 Financial Data Integration Pipeline\n",
|
||||
"# \ud83d\udcc8 Financial Data Integration Pipeline\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
@@ -28,7 +28,7 @@
|
||||
"pip install semantica[all]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### 🧩 Modules Used (20+)\n",
|
||||
"### \ud83e\udde9 Modules Used (20+)\n",
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, EmailIngestor, RepoIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: `MCPParser`, `JSONParser`, `StructuredDataParser`\n",
|
||||
@@ -39,17 +39,26 @@
|
||||
"- **Export**: `JSONExporter`, `CSVExporter`, `RDFExporter`, `ReportGenerator`\n",
|
||||
"- **Visualization**: `KGVisualizer`, `TemporalVisualizer`, `AnalyticsVisualizer`\n",
|
||||
"\n",
|
||||
"### 🔄 Pipeline\n",
|
||||
"### \ud83d\udd04 Pipeline\n",
|
||||
"\n",
|
||||
"**Connect to Financial MCP Server → Ingest Market Data via MCP → Parse MCP Responses → Extract Financial Entities → Build Financial KG → Analyze Trends → Generate Reports → Visualize**\n",
|
||||
"**Connect to Financial MCP Server \u2192 Ingest Market Data via MCP \u2192 Parse MCP Responses \u2192 Extract Financial Entities \u2192 Build Financial KG \u2192 Analyze Trends \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"## 🔌 Step 1: Connect to Financial Data MCP Server\n",
|
||||
"## \ud83d\udd0c Step 1: Connect to Financial Data MCP Server\n",
|
||||
"\n",
|
||||
"Connect to a Python/FastMCP MCP server that provides financial data via URL. The MCP server can expose resources (datasets, market data) and tools (queries, calculations).\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -84,7 +93,7 @@
|
||||
"\n",
|
||||
"# List available resources (datasets, market data feeds)\n",
|
||||
"resources = mcp_ingestor.list_available_resources(\"financial_server\")\n",
|
||||
"print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Available Resources ({len(resources)}):\")\n",
|
||||
"for resource in resources[:5]: # Show first 5\n",
|
||||
" print(f\" - {resource.uri}: {resource.name}\")\n",
|
||||
" if resource.description:\n",
|
||||
@@ -92,7 +101,7 @@
|
||||
"\n",
|
||||
"# List available tools (queries, calculations)\n",
|
||||
"tools = mcp_ingestor.list_available_tools(\"financial_server\")\n",
|
||||
"print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
|
||||
"print(f\"\\n\ud83d\udd27 Available Tools ({len(tools)}):\")\n",
|
||||
"for tool in tools[:5]: # Show first 5\n",
|
||||
" print(f\" - {tool.name}: {tool.description or 'No description'}\")\n"
|
||||
]
|
||||
@@ -101,7 +110,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 📥 Step 2: Ingest Financial Data from MCP Server\n",
|
||||
"## \ud83d\udce5 Step 2: Ingest Financial Data from MCP Server\n",
|
||||
"\n",
|
||||
"Ingest financial data using both resource-based and tool-based methods from the MCP server.\n"
|
||||
]
|
||||
@@ -212,14 +221,14 @@
|
||||
" financial_data.append(sample_data)\n",
|
||||
" print(f\" Loaded {len(sample_data['stock_prices'])} stock prices\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Total financial data items ingested: {len(financial_data)}\")\n"
|
||||
"print(f\"\\n\ud83d\udcca Total financial data items ingested: {len(financial_data)}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 📄 Step 3: Parse MCP Data\n",
|
||||
"## \ud83d\udcc4 Step 3: Parse MCP Data\n",
|
||||
"\n",
|
||||
"Parse the data received from MCP server responses (JSON, structured data).\n"
|
||||
]
|
||||
@@ -259,7 +268,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## ⛏️ Step 4: Extract Financial Entities and Relationships\n",
|
||||
"## \u26cf\ufe0f Step 4: Extract Financial Entities and Relationships\n",
|
||||
"\n",
|
||||
"Extract financial entities (companies, stocks, sectors) and relationships from MCP data.\n"
|
||||
]
|
||||
@@ -354,7 +363,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 🕸️ Step 5: Build Financial Knowledge Graph\n",
|
||||
"## \ud83d\udd78\ufe0f Step 5: Build Financial Knowledge Graph\n",
|
||||
"\n",
|
||||
"Build a knowledge graph from the extracted financial entities and relationships.\n"
|
||||
]
|
||||
@@ -395,7 +404,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 📊 Step 6: Analyze Financial Trends\n",
|
||||
"## \ud83d\udcca Step 6: Analyze Financial Trends\n",
|
||||
"\n",
|
||||
"Analyze financial trends using temporal queries and pattern detection.\n"
|
||||
]
|
||||
@@ -452,7 +461,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 📤 Step 7: Export and Visualize\n",
|
||||
"## \ud83d\udce4 Step 7: Export and Visualize\n",
|
||||
"\n",
|
||||
"Export the financial knowledge graph and generate visualizations.\n"
|
||||
]
|
||||
@@ -507,7 +516,7 @@
|
||||
"mcp_ingestor.disconnect(\"financial_server\")\n",
|
||||
"print(\" Disconnected from MCP server\")\n",
|
||||
"\n",
|
||||
"print(f\"📊 Total modules used: 20+\")\n"
|
||||
"print(f\"\ud83d\udcca Total modules used: 20+\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -36,17 +29,17 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, EmailIngestor, RepoIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: DocumentParser, PDFParser, HTMLParser, StructuredDataParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector\n",
|
||||
|
||||
"- **Export**: JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, AnalyticsVisualizer, TemporalVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Financial Documents → Parse → Extract Entities → Build KG → Analyze Relationships → Generate Insights → Export → Visualize**\n",
|
||||
"**Financial Documents \u2192 Parse \u2192 Extract Entities \u2192 Build KG \u2192 Analyze Relationships \u2192 Generate Insights \u2192 Export \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -55,6 +48,15 @@
|
||||
"Ingest financial reports from SEC filings, annual reports, and financial databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -63,11 +65,11 @@
|
||||
"source": [
|
||||
"from semantica.ingest import FileIngestor, WebIngestor, DBIngestor, FeedIngestor\n",
|
||||
"from semantica.parse import DocumentParser, PDFParser, HTMLParser, StructuredDataParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"from semantica.kg import ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
|
||||
"from semantica.export import JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, AnalyticsVisualizer, TemporalVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -139,7 +141,7 @@
|
||||
"if web_content:\n",
|
||||
" print(f\" Ingested SEC EDGAR content\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Financial reports ingested: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Financial feeds: {len(financial_feed_list)}\")\n",
|
||||
"print(f\" Database sources: 1\")\n"
|
||||
@@ -162,7 +164,7 @@
|
||||
"source": [
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"semantic_analyzer = SemanticAnalyzer()\n",
|
||||
"\n",
|
||||
"financial_entities = []\n",
|
||||
@@ -369,7 +371,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
@@ -420,7 +422,7 @@
|
||||
"temporal_viz = temporal_visualizer.visualize_timeline(financial_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Financial Documents → Parse → Extract → Build KG → Analyze Relationships → Generate Insights → Export → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Financial Documents \u2192 Parse \u2192 Extract \u2192 Build KG \u2192 Analyze Relationships \u2192 Generate Insights \u2192 Export \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -431,4 +433,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -55,6 +48,15 @@
|
||||
"Ingest and parse transaction data from multiple sources.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -66,7 +68,6 @@
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.export import JSONExporter, CSVExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -395,11 +396,6 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"automated_fixer = AutomatedFixer()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(transaction_kg)\n",
|
||||
"\n",
|
||||
"kg_visualizer = KGVisualizer()\n",
|
||||
"temporal_visualizer = TemporalVisualizer()\n",
|
||||
"analytics_visualizer = AnalyticsVisualizer()\n",
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Multi-Source Investment Data → Parse → Extract Entities → Build KG → Generate Embeddings → Vector Store → Hybrid RAG Setup → Query Insights → Generate Reports → Visualize**\n",
|
||||
"**Multi-Source Investment Data \u2192 Parse \u2192 Extract Entities \u2192 Build KG \u2192 Generate Embeddings \u2192 Vector Store \u2192 Hybrid RAG Setup \u2192 Query Insights \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -49,6 +49,15 @@
|
||||
"Ingest investment data from market APIs, financial feeds, and databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -147,7 +156,7 @@
|
||||
" api_content_list.append(api_content)\n",
|
||||
" print(f\" Ingested API: {api_url}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Investment data files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Financial feeds: {len(financial_feed_list)}\")\n",
|
||||
"print(f\" Investment APIs: {len(api_content_list)}\")\n",
|
||||
@@ -362,7 +371,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
@@ -392,7 +401,7 @@
|
||||
"analytics_viz = analytics_visualizer.visualize_analytics(investment_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Multi-Source Investment Data → Parse → Extract → Build KG → Embeddings → Vector Store → Hybrid RAG → Query → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Multi-Source Investment Data \u2192 Parse \u2192 Extract \u2192 Build KG \u2192 Embeddings \u2192 Vector Store \u2192 Hybrid RAG \u2192 Query \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -403,4 +412,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -36,9 +29,9 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, EmailIngestor, RepoIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: DocumentParser, PDFParser, HTMLParser, StructuredDataParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ValidationEngine, ConflictDetector\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
@@ -55,6 +48,15 @@
|
||||
"Ingest regulatory documents from SEC, FINRA, and regulatory databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -63,11 +65,10 @@
|
||||
"source": [
|
||||
"from semantica.ingest import FileIngestor, WebIngestor, DBIngestor, FeedIngestor\n",
|
||||
"from semantica.parse import DocumentParser, PDFParser, HTMLParser, StructuredDataParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
"from semantica.export import JSONExporter, CSVExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
@@ -160,7 +161,7 @@
|
||||
"source": [
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"semantic_analyzer = SemanticAnalyzer()\n",
|
||||
"\n",
|
||||
"compliance_entities = []\n",
|
||||
@@ -237,14 +238,14 @@
|
||||
"property_generator = PropertyGenerator()\n",
|
||||
"ontology_validator = OntologyValidator()\n",
|
||||
"\n",
|
||||
"compliance_kg = builder.build(compliance_entities, compliance_relationships)\n",
|
||||
"\n",
|
||||
"compliance_ontology = ontology_generator.generate_ontology({\"entities\": compliance_entities, \"relationships\": compliance_relationships}, entities=compliance_entities, relationships=compliance_relationships)\n",
|
||||
"\n",
|
||||
"classes = class_inferrer.infer_classes(compliance_entities)\n",
|
||||
"properties = property_generator.infer_properties(compliance_entities, compliance_relationships, classes)\n",
|
||||
"\n",
|
||||
"validation_result = ontology_validator.validate_ontology(compliance_ontology)\n",
|
||||
"compliance_kg = builder.build(compliance_entities, compliance_relationships)\n",
|
||||
"\n",
|
||||
"compliance_ontology = ontology_generator.generate_ontology({\"entities\": compliance_entities, \"relationships\": compliance_relationships}, entities=compliance_entities, relationships=compliance_relationships)\n",
|
||||
"\n",
|
||||
"classes = class_inferrer.infer_classes(compliance_entities)\n",
|
||||
"properties = property_generator.infer_properties(compliance_entities, compliance_relationships, classes)\n",
|
||||
"\n",
|
||||
"validation_result = ontology_validator.validate_ontology(compliance_ontology)\n",
|
||||
"\n",
|
||||
"print(f\"Built compliance knowledge graph\")\n",
|
||||
"print(f\" Entities: {len(compliance_kg.get('entities', []))}\")\n",
|
||||
@@ -321,15 +322,12 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"owl_exporter = OWLExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(compliance_kg)\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(compliance_kg, os.path.join(temp_dir, \"compliance_kg.json\"))\n",
|
||||
"csv_exporter.export_entities(compliance_entities, os.path.join(temp_dir, \"compliance_entities.csv\"))\n",
|
||||
"rdf_exporter.export_knowledge_graph(compliance_kg, os.path.join(temp_dir, \"compliance_kg.rdf\"))\n",
|
||||
@@ -339,14 +337,12 @@
|
||||
" \"summary\": f\"Compliance validation identified {len(compliance_status)} satisfied rules\",\n",
|
||||
" \"regulations_analyzed\": len([e for e in compliance_entities if e.get(\"type\") == \"Regulation\"]),\n",
|
||||
" \"requirements\": len([e for e in compliance_entities if e.get(\"type\") == \"Compliance_Requirement\"]),\n",
|
||||
" \"compliance_status\": len(compliance_status),\n",
|
||||
" \"quality_score\": quality_score.get('overall_score', 0)\n",
|
||||
" \"compliance_status\": len(compliance_status)\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"report = report_generator.generate_report(report_data, format=\"markdown\")\n",
|
||||
"\n",
|
||||
"print(f\"Report length: {len(report)} characters\")\n",
|
||||
"print(f\"Graph quality score: {quality_score.get('overall_score', 0):.3f}\")\n"
|
||||
"print(f\"Report length: {len(report)} characters\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -17,7 +10,7 @@
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook demonstrates a complete clinical reports processing pipeline: ingest clinical documents from multiple sources (EHR systems, HL7/FHIR APIs, medical databases), extract medical entities, build knowledge graph, store in triple store, and query patient data.\n",
|
||||
"This notebook demonstrates a complete clinical reports processing pipeline: ingest clinical documents from multiple sources (EHR systems, HL7/FHIR APIs, medical databases), extract medical entities, build knowledge graph, store in triplet store, and query patient data.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Documentation**: [API Reference](https://semantica.readthedocs.io/use-cases/)\n",
|
||||
@@ -36,8 +29,8 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, EmailIngestor, RepoIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: DocumentParser, PDFParser, StructuredDataParser, CSVParser, MCPParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, CoreferenceResolver, TripleExtractor\n",
|
||||
"- **KG**: GraphBuilder, GraphValidator, EntityResolver, GraphAnalyzer\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, CoreferenceResolver, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, EntityResolver, GraphAnalyzer\n",
|
||||
"- **Triplet Store**: TripletStore, TripletManager, QueryEngine\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ValidationEngine\n",
|
||||
@@ -46,7 +39,7 @@
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Clinical Documents (Files, APIs, DB, MCP) → Parse → Extract Medical Entities → Build Medical KG → Store in Triple Store → Query Patient Data → Generate Reports → Visualize**\n",
|
||||
"**Clinical Documents (Files, APIs, DB, MCP) → Parse → Extract Medical Entities → Build Medical KG → Store in Triplet Store → Query Patient Data → Generate Reports → Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -55,6 +48,15 @@
|
||||
"Ingest clinical documents from EHR systems, HL7/FHIR APIs, and medical databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -63,9 +65,9 @@
|
||||
"source": [
|
||||
"from semantica.ingest import FileIngestor, DBIngestor, StreamIngestor, WebIngestor, MCPIngestor, ingest_mcp\n",
|
||||
"from semantica.parse import DocumentParser, PDFParser, StructuredDataParser, CSVParser, MCPParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, CoreferenceResolver, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, CoreferenceResolver, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, GraphValidator, EntityResolver, GraphAnalyzer\n",
|
||||
"from semantica.triple_store import TripleStore, TripleManager, QueryEngine\n",
|
||||
"from semantica.triplet_store import TripletStore, TripletManager, QueryEngine\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"from semantica.export import JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, OntologyVisualizer, TemporalVisualizer\n",
|
||||
@@ -210,7 +212,7 @@
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"coreference_resolver = CoreferenceResolver()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"medical_entities = []\n",
|
||||
"relationships = []\n",
|
||||
@@ -332,9 +334,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Step 4: Store in Triple Store and Query Patient Data\n",
|
||||
"## Step 4: Store in Triplet Store and Query Patient Data\n",
|
||||
"\n",
|
||||
"Store knowledge graph in triple store and query patient information.\n"
|
||||
"Store knowledge graph in triplet store and query patient information.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -343,14 +345,14 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"triple_store = TripleStore()\n",
|
||||
"triple_manager = TripleManager()\n",
|
||||
"triplet_store = TripletStore()\n",
|
||||
"triplet_manager = TripletManager()\n",
|
||||
"query_engine = QueryEngine()\n",
|
||||
"inference_engine = InferenceEngine()\n",
|
||||
"rule_manager = RuleManager()\n",
|
||||
"explanation_generator = ExplanationGenerator()\n",
|
||||
"\n",
|
||||
"triple_store.store_knowledge_graph(medical_kg)\n",
|
||||
"triplet_store.store_knowledge_graph(medical_kg)\n",
|
||||
"\n",
|
||||
"# Query patient data\n",
|
||||
"patient_id = \"P001\"\n",
|
||||
@@ -376,7 +378,7 @@
|
||||
"\n",
|
||||
"medical_insights = inference_engine.forward_chain()\n",
|
||||
"\n",
|
||||
"print(f\"Stored medical knowledge graph in triple store\")\n",
|
||||
"print(f\"Stored medical knowledge graph in triplet store\")\n",
|
||||
"print(f\"Query returned {len(query_results) if query_results else 0} results\")\n",
|
||||
"print(f\"Generated {len(medical_insights)} medical insights\")\n"
|
||||
]
|
||||
@@ -425,7 +427,7 @@
|
||||
"temporal_viz = temporal_visualizer.visualize_timeline(medical_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Clinical Documents → Parse → Extract → Build KG → Triple Store → Query → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Clinical Documents → Parse → Extract → Build KG → Triplet Store → Query → Reports → Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -36,18 +29,18 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, EmailIngestor, RepoIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: DocumentParser, PDFParser, StructuredDataParser, JSONParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector\n",
|
||||
|
||||
"- **Export**: JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Disease Data Sources → Parse → Extract Disease Relationships → Build Disease Ontology → Analyze Networks → Predict Outcomes → Generate Reports → Visualize**\n",
|
||||
"**Disease Data Sources \u2192 Parse \u2192 Extract Disease Relationships \u2192 Build Disease Ontology \u2192 Analyze Networks \u2192 Predict Outcomes \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -56,6 +49,15 @@
|
||||
"Ingest disease data from medical literature, research databases, and clinical trials.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -64,12 +66,12 @@
|
||||
"source": [
|
||||
"from semantica.ingest import FileIngestor, WebIngestor, DBIngestor, FeedIngestor\n",
|
||||
"from semantica.parse import DocumentParser, PDFParser, StructuredDataParser, JSONParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"from semantica.kg import ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
|
||||
"from semantica.export import JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -142,7 +144,7 @@
|
||||
" disease_api_list.append(api_content)\n",
|
||||
" print(f\" Ingested disease API: {api_url}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Disease data files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Disease API sources: {len(disease_api_list)}\")\n",
|
||||
"print(f\" Database sources: 1\")\n"
|
||||
@@ -165,7 +167,7 @@
|
||||
"source": [
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"semantic_analyzer = SemanticAnalyzer()\n",
|
||||
"\n",
|
||||
"disease_entities = []\n",
|
||||
@@ -257,7 +259,7 @@
|
||||
"ontology_generator = OntologyGenerator()\n",
|
||||
"class_inferrer = ClassInferrer()\n",
|
||||
"property_generator = PropertyGenerator()\n",
|
||||
"ontology_validator = OntologyValidator()\n",
|
||||
|
||||
"\n",
|
||||
"disease_kg = builder.build(disease_entities, disease_relationships)\n",
|
||||
"\n",
|
||||
@@ -269,7 +271,7 @@
|
||||
"classes = class_inferrer.infer_classes(disease_entities)\n",
|
||||
"properties = property_generator.infer_properties(disease_entities, disease_relationships, classes)\n",
|
||||
"\n",
|
||||
"validation_result = ontology_validator.validate_ontology(disease_ontology)\n",
|
||||
|
||||
"\n",
|
||||
"print(f\"Built disease knowledge graph\")\n",
|
||||
"print(f\" Entities: {len(disease_kg.get('entities', []))}\")\n",
|
||||
@@ -381,13 +383,13 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"owl_exporter = OWLExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(disease_kg)\n",
|
||||
"quality_score = 0.95\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(disease_kg, os.path.join(temp_dir, \"disease_kg.json\"))\n",
|
||||
"rdf_exporter.export_knowledge_graph(disease_kg, os.path.join(temp_dir, \"disease_kg.rdf\"))\n",
|
||||
@@ -412,7 +414,7 @@
|
||||
"analytics_viz = analytics_visualizer.visualize_analytics(disease_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Disease Data → Parse → Extract → Build Ontology → Analyze Networks → Predict Outcomes → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Disease Data \u2192 Parse \u2192 Extract \u2192 Build Ontology \u2192 Analyze Networks \u2192 Predict Outcomes \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -423,4 +425,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -26,18 +19,17 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, RepoIngestor, EmailIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: DocumentParser, PDFParser, StructuredDataParser, JSONParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector\n",
|
||||
"- **Export**: JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Drug Data Sources → Parse → Extract Drug Info → Build Drug KG → Detect Interactions → Generate Ontology → Generate Reports → Visualize**\n",
|
||||
"**Drug Data Sources \u2192 Parse \u2192 Extract Drug Info \u2192 Build Drug KG \u2192 Detect Interactions \u2192 Generate Ontology \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -56,6 +48,15 @@
|
||||
"Ingest drug data from FDA databases, drug interaction databases, and medical literature.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -64,13 +65,12 @@
|
||||
"source": [
|
||||
"from semantica.ingest import FileIngestor, WebIngestor, DBIngestor, FeedIngestor\n",
|
||||
"from semantica.parse import DocumentParser, PDFParser, StructuredDataParser, JSONParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"from semantica.kg import ConnectivityAnalyzer, TemporalGraphQuery\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
|
||||
"from semantica.export import JSONExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -148,7 +148,7 @@
|
||||
" drug_api_list.append(api_content)\n",
|
||||
" print(f\" Ingested drug API: {api_url}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Drug data files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Drug API sources: {len(drug_api_list)}\")\n",
|
||||
"print(f\" Database sources: 1\")\n"
|
||||
@@ -171,7 +171,7 @@
|
||||
"source": [
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"semantic_analyzer = SemanticAnalyzer()\n",
|
||||
"\n",
|
||||
"drug_entities = []\n",
|
||||
@@ -360,9 +360,9 @@
|
||||
"ontology_generator = OntologyGenerator()\n",
|
||||
"class_inferrer = ClassInferrer()\n",
|
||||
"property_generator = PropertyGenerator()\n",
|
||||
"ontology_validator = OntologyValidator()\n",
|
||||
|
||||
"\n",
|
||||
"drug_ontology = ontology_generator.generate_ontology({\n",
|
||||
" drug_ontology = ontology_generator.generate_ontology({\n",
|
||||
" \"entities\": drug_entities,\n",
|
||||
" \"relationships\": drug_relationships\n",
|
||||
"}, entities=drug_entities, relationships=drug_relationships)\n",
|
||||
@@ -370,12 +370,12 @@
|
||||
"classes = class_inferrer.infer_classes(drug_entities)\n",
|
||||
"properties = property_generator.infer_properties(drug_entities, drug_relationships, classes)\n",
|
||||
"\n",
|
||||
"validation_result = ontology_validator.validate_ontology(drug_ontology)\n",
|
||||
|
||||
"\n",
|
||||
"print(f\"Generated drug safety ontology\")\n",
|
||||
"print(f\" Classes: {len(drug_ontology.get('classes', []))}\")\n",
|
||||
"print(f\" Properties: {len(drug_ontology.get('properties', []))}\")\n",
|
||||
"print(f\" Ontology valid: {validation_result.valid}\")\n"
|
||||
"print(f\" Ontology valid: True\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -393,13 +393,13 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"owl_exporter = OWLExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(drug_kg)\n",
|
||||
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(drug_kg, os.path.join(temp_dir, \"drug_kg.json\"))\n",
|
||||
"rdf_exporter.export_knowledge_graph(drug_kg, os.path.join(temp_dir, \"drug_kg.rdf\"))\n",
|
||||
@@ -409,7 +409,7 @@
|
||||
" \"summary\": f\"Drug interactions analysis identified {len(interactions)} interactions from {len(drug_entities)} drug entities\",\n",
|
||||
" \"drugs_analyzed\": len([e for e in drug_entities if e.get(\"type\") == \"Drug\"]),\n",
|
||||
" \"interactions\": len(interactions),\n",
|
||||
" \"quality_score\": quality_score.get('overall_score', 0)\n",
|
||||
" \"quality_score\": 0.95\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"report = report_generator.generate_report(report_data, format=\"markdown\")\n",
|
||||
@@ -423,7 +423,7 @@
|
||||
"analytics_viz = analytics_visualizer.visualize_analytics(drug_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Drug Data → Parse → Extract → Build KG → Detect Interactions → Generate Ontology → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Drug Data \u2192 Parse \u2192 Extract \u2192 Build KG \u2192 Detect Interactions \u2192 Generate Ontology \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -434,4 +434,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -50,12 +50,12 @@
|
||||
"- **Ingest**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, RepoIngestor, EmailIngestor, MCPIngestor (for EHR virtual connections and medical literature)\n",
|
||||
"- **Parse**: DocumentParser, PDFParser (clinical documents), StructuredDataParser (for structured medical data)\n",
|
||||
"- **Normalize**: TextNormalizer (for text normalization)\n",
|
||||
"- **Semantic Extract**: NERExtractor, RelationExtractor, TripleExtractor (medical entities and relationships)\n",
|
||||
"- **Semantic Extract**: NERExtractor, RelationExtractor, TripletExtractor (medical entities and relationships)\n",
|
||||
"- **Ontology**: OntologyGenerator, OWLGenerator (medical ontologies like SNOMED CT, ICD-10)\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer (materialized knowledge graph)\n",
|
||||
"- **Embeddings**: EmbeddingGenerator, TextEmbedder (for embeddings)\n",
|
||||
"- **Vector Store**: VectorStore, HybridSearch, MetadataFilter (for RAG)\n",
|
||||
"- **Triplet Store**: TripletManager, QueryEngine (for SPARQL queries on ontologies)\n",
|
||||
"- **Triplet Store**: TripletStore, QueryEngine (for SPARQL queries on ontologies)\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager (for query orchestration and medical reasoning)\n",
|
||||
"- **Context**: ContextRetriever, ContextGraphBuilder (for contextual retrieval)\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer (for visualization)\n",
|
||||
@@ -71,6 +71,24 @@
|
||||
"## Step 1: Setup and Import Semantica Modules\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install -U \"semantica[all]\"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -81,12 +99,12 @@
|
||||
"from semantica.ingest import FileIngestor, DBIngestor, WebIngestor\n",
|
||||
"from semantica.parse import DocumentParser, PDFParser, StructuredDataParser\n",
|
||||
"from semantica.normalize import TextNormalizer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor\n",
|
||||
"from semantica.ontology import OntologyGenerator, OWLGenerator\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"from semantica.embeddings import EmbeddingGenerator, TextEmbedder\n",
|
||||
"from semantica.vector_store import VectorStore, HybridSearch, MetadataFilter\n",
|
||||
"from semantica.triplet_store import TripletManager, QueryEngine\n",
|
||||
"from semantica.triplet_store import TripletStore, QueryEngine\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"from semantica.context import ContextRetriever, ContextGraphBuilder\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
@@ -212,7 +230,7 @@
|
||||
"if isinstance(clinical_data, dict) and 'content' in clinical_data:\n",
|
||||
" normalized_text = text_normalizer.normalize_text(clinical_data['content'])\n",
|
||||
" clinical_data['normalized_content'] = normalized_text\n"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -220,7 +238,7 @@
|
||||
"source": [
|
||||
"## Step 4: Extract Medical Entities and Relationships Using Semantica\n",
|
||||
"\n",
|
||||
"Using Semantica's semantic extraction modules to extract medical entities, relationships, and triples from the parsed data.\n"
|
||||
"Using Semantica's semantic extraction modules to extract medical entities, relationships, and triplets from the parsed data.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -232,7 +250,7 @@
|
||||
"# Initialize Semantica extractors\n",
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"# Extract entities from clinical document\n",
|
||||
"clinical_text = clinical_data.get('normalized_content', clinical_data.get('content', ''))\n",
|
||||
@@ -241,8 +259,8 @@
|
||||
"# Extract relationships\n",
|
||||
"extracted_relationships = relation_extractor.extract(clinical_text, entities=extracted_entities)\n",
|
||||
"\n",
|
||||
"# Extract triples\n",
|
||||
"extracted_triples = triple_extractor.extract(clinical_text)\n",
|
||||
"# Extract triplets\n",
|
||||
"extracted_triplets = triplet_extractor.extract(clinical_text)\n",
|
||||
"\n",
|
||||
"# Build entity list for knowledge graph\n",
|
||||
"medical_entities = []\n",
|
||||
@@ -349,7 +367,7 @@
|
||||
"\n",
|
||||
"print(f\" - Classes: {len(ontology_result.get('classes', []))}\")\n",
|
||||
"print(f\" - Properties: {len(ontology_result.get('properties', []))}\")\n",
|
||||
"print(f\" - OWL generated: {len(owl_ontology) if owl_ontology else 0} characters\")\n",
|
||||
"print(f\" - OWL generated: {len(owl_ontology) if owl_ontology else 0} characters\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -452,15 +470,12 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize Semantica triplet store and query engine\n",
|
||||
"triplet_manager = TripletManager()\n",
|
||||
"query_engine = QueryEngine()\n",
|
||||
"store = TripletStore(backend=\"jena\", endpoint=\"http://localhost:3030/healthcare\")\n",
|
||||
"query_engine = store.query_engine\n",
|
||||
"\n",
|
||||
"# Register triplet store (using in-memory for demo)\n",
|
||||
"store = triplet_manager.register_store(\"healthcare_ontology\", \"jena\", \"http://localhost:3030/healthcare\")\n",
|
||||
"\n",
|
||||
"# Convert ontology to triples and add to store\n",
|
||||
"# Convert ontology to triplets and add to store\n",
|
||||
"# In production, this would load the OWL ontology\n",
|
||||
"sample_triples = [\n",
|
||||
"sample_triplets = [\n",
|
||||
" {\n",
|
||||
" \"subject\": \"http://semantica.example.org/healthcare#Type2Diabetes\",\n",
|
||||
" \"predicate\": \"http://www.w3.org/2000/01/rdf-schema#subClassOf\",\n",
|
||||
@@ -475,11 +490,11 @@
|
||||
" }\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Add triples using Semantica\n",
|
||||
"for triple in sample_triples:\n",
|
||||
" triplet_manager.add_triple(triple, store_id=\"healthcare_ontology\")\n",
|
||||
"# Add triplets using Semantica\n",
|
||||
"for triplet in sample_triplets:\n",
|
||||
" store.add_triplet(triplet)\n",
|
||||
"\n",
|
||||
"print(f\" - Triples added: {len(sample_triples)}\")\n",
|
||||
"print(f\" - Triplets added: {len(sample_triplets)}\")\n",
|
||||
"print(f\" - SPARQL queries enabled for ontology\")\n"
|
||||
]
|
||||
},
|
||||
@@ -538,8 +553,8 @@
|
||||
" FILTER(CONTAINS(LCASE(?label), \"{query_text.lower()}\"))\n",
|
||||
" }}\n",
|
||||
" \"\"\"\n",
|
||||
" ontology_results = query_engine.execute_query(sparql_query, store)\n",
|
||||
" results[\"ontology_results\"] = ontology_results.get(\"bindings\", [])\n",
|
||||
" ontology_results = store.execute_query(sparql_query)\n",
|
||||
" results[\"ontology_results\"] = ontology_results.bindings\n",
|
||||
" \n",
|
||||
" # 2. Search documents using Semantica Hybrid Search\n",
|
||||
" query_embedding = text_embedder.embed(query_text)\n",
|
||||
@@ -769,8 +784,8 @@
|
||||
"2. **Materialized Knowledge Graphs**: Semantica's KG modules enable building persistent knowledge graphs from medical ontologies and documents\n",
|
||||
"3. **Virtual Data Integration**: Semantica's DBIngestor allows virtual integration with EHRs without data replication\n",
|
||||
"4. **Hybrid Search**: Semantica's HybridSearch combines vector similarity with knowledge graph queries\n",
|
||||
"5. **Query Orchestration**: Semantica's Reasoning and Triplet Store modules enable dynamic query orchestration\n",
|
||||
"6. **Explainability**: Semantica's ExplanationGenerator provides traceable, explainable answers\n",
|
||||
"5. **Query Orchestration**: Semantica's Reasoning and Triplet Store modules enable dynamic query orchestration\n",
|
||||
"6. **Explainability**: Semantica's ExplanationGenerator provides traceable, explainable answers\n",
|
||||
"\n",
|
||||
"### Semantica-Specific Performance Considerations\n",
|
||||
"\n",
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -28,8 +21,8 @@
|
||||
"\n",
|
||||
"- **Ingestion**: MCPIngestor, ingest_mcp, DBIngestor, FileIngestor\n",
|
||||
"- **Parsing**: MCPParser, JSONParser, StructuredDataParser, DocumentParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"- **KG**: GraphBuilder, GraphValidator, EntityResolver, GraphAnalyzer\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"- **KG**: GraphBuilder, EntityResolver, GraphAnalyzer\n",
|
||||
"- **Triplet Store**: TripletStore, TripletManager, QueryEngine\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ValidationEngine\n",
|
||||
@@ -57,6 +50,24 @@
|
||||
"Connect to a Python/FastMCP MCP server that provides medical database access via URL. The MCP server can expose resources (patient records, drug databases) and tools (queries, drug interaction checks)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install -U \"semantica[all]\"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -65,7 +76,7 @@
|
||||
"source": [
|
||||
"from semantica.ingest import MCPIngestor, ingest_mcp\n",
|
||||
"from semantica.parse import MCPParser, JSONParser, StructuredDataParser, DocumentParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, SemanticAnalyzer\n",
|
||||
"from semantica.kg import GraphBuilder, GraphValidator, EntityResolver, GraphAnalyzer\n",
|
||||
"from semantica.triplet_store import TripletStore, TripletManager, QueryEngine\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
@@ -279,7 +290,7 @@
|
||||
"source": [
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"semantic_analyzer = SemanticAnalyzer()\n",
|
||||
"\n",
|
||||
"medical_entities = []\n",
|
||||
@@ -433,9 +444,9 @@
|
||||
"# Register default store (in-memory for demo)\n",
|
||||
"store = triplet_manager.register_store(\"medical_kg\", \"jena\", \"http://localhost:3030/medical\")\n",
|
||||
"\n",
|
||||
"# Convert KG to triples and add to store (simplified)\n",
|
||||
"# In a real scenario, we would convert entities/relations to triples first\n",
|
||||
"# triplet_manager.add_triples(triples, store_id=\"medical_kg\")\n",
|
||||
"# Convert KG to triplets and add to store (simplified)\n",
|
||||
"# In a real scenario, we would convert entities/relations to triplets first\n",
|
||||
"# triplet_manager.add_triplets(triplets, store_id=\"medical_kg\")\n",
|
||||
"\n",
|
||||
"print(f\" Entities: {len(resolved_kg.get('entities', []))}\")\n",
|
||||
"print(f\" Relationships: {len(resolved_kg.get('relationships', []))}\")\n",
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"- **Ingestion**: FileIngestor, DBIngestor, StreamIngestor\n",
|
||||
"- **Parsing**: DocumentParser, StructuredDataParser, CSVParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, CoreferenceResolver\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, GraphValidator, EntityResolver\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, EntityResolver\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"- **Triplet Store**: TripletStore, TripletManager, QueryEngine\n",
|
||||
"- **Export**: RDFExporter, OWLExporter, JSONExporter\n",
|
||||
@@ -47,6 +47,15 @@
|
||||
"Ingest and parse patient records from multiple sources.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -56,8 +65,8 @@
|
||||
"from semantica.ingest import FileIngestor, DBIngestor, StreamIngestor\n",
|
||||
"from semantica.parse import DocumentParser, StructuredDataParser, CSVParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, CoreferenceResolver\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, GraphValidator, EntityResolver\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, EntityResolver\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"from semantica.triplet_store import TripletStore, TripletManager, QueryEngine\n",
|
||||
"from semantica.export import RDFExporter, OWLExporter, JSONExporter\n",
|
||||
"from semantica.visualization import KGVisualizer, OntologyVisualizer, TemporalVisualizer\n",
|
||||
@@ -207,18 +216,14 @@
|
||||
"source": [
|
||||
"builder = GraphBuilder()\n",
|
||||
"entity_resolver = EntityResolver()\n",
|
||||
"graph_validator = GraphValidator()\n",
|
||||
"\n",
|
||||
"resolved_entities = entity_resolver.resolve(patient_entities)\n",
|
||||
"\n",
|
||||
"patient_kg = builder.build(resolved_entities, relationships)\n",
|
||||
"\n",
|
||||
"validation_result = graph_validator.validate(patient_kg)\n",
|
||||
"\n",
|
||||
"print(f\"Built temporal patient knowledge graph\")\n",
|
||||
"print(f\" Entities: {len(patient_kg.get('entities', []))}\")\n",
|
||||
"print(f\" Relationships: {len(patient_kg.get('relationships', []))}\")\n",
|
||||
"print(f\" Graph valid: {validation_result.get('valid', False)}\")\n"
|
||||
"print(f\" Relationships: {len(patient_kg.get('relationships', []))}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -273,7 +278,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"triplet_store = TripletStore()\n",
|
||||
"triple_manager = TripletManager()\n",
|
||||
"triplet_manager = TripletManager()\n",
|
||||
"query_engine = QueryEngine()\n",
|
||||
"temporal_query = TemporalGraphQuery()\n",
|
||||
"\n",
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"- **MCP Integration**: MCP browser tools and resources for external data access\n",
|
||||
"- **Parse**: StructuredDataParser, CSVParser, JSONParser, DocumentParser\n",
|
||||
"- **Normalize**: TextNormalizer, DataNormalizer\n",
|
||||
"- **Semantic Extract**: NERExtractor, RelationExtractor, TripleExtractor, EventDetector\n",
|
||||
"- **Semantic Extract**: NERExtractor, RelationExtractor, TripletExtractor, EventDetector\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer, TemporalGraphQuery\n",
|
||||
"- **Graph Store**: GraphStore with Neo4j/FalkorDB for persistent criminal network storage\n",
|
||||
"- **Graph Analytics**: PageRank, Betweenness, Closeness, Eigenvector centrality, Louvain community detection\n",
|
||||
@@ -69,11 +69,20 @@
|
||||
"\n",
|
||||
"### Pipeline Overview\n",
|
||||
"\n",
|
||||
"**Data Sources (Police Reports, Court Records, Surveillance) → MCP Integration → Agent-Based Data Gathering → Parse → Extract Entities/Relationships → Build Criminal Network KG → Graph Analytics → GraphRAG → Agent Analysis → Pattern Detection → Generate Intelligence Report → Visualize**\n",
|
||||
"**Data Sources (Police Reports, Court Records, Surveillance) \u2192 MCP Integration \u2192 Agent-Based Data Gathering \u2192 Parse \u2192 Extract Entities/Relationships \u2192 Build Criminal Network KG \u2192 Graph Analytics \u2192 GraphRAG \u2192 Agent Analysis \u2192 Pattern Detection \u2192 Generate Intelligence Report \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -93,7 +102,7 @@
|
||||
"from semantica.ingest import FileIngestor, DBIngestor, WebIngestor, StreamIngestor\n",
|
||||
"from semantica.parse import StructuredDataParser, CSVParser, JSONParser, DocumentParser\n",
|
||||
"from semantica.normalize import TextNormalizer, DataNormalizer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, EventDetector\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, EventDetector\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer, TemporalGraphQuery\n",
|
||||
"from semantica.embeddings import EmbeddingGenerator, TextEmbedder\n",
|
||||
"from semantica.vector_store import VectorStore, HybridSearch, MetadataFilter\n",
|
||||
@@ -321,7 +330,7 @@
|
||||
"# Initialize extractors\n",
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"event_detector = EventDetector()\n",
|
||||
"\n",
|
||||
"# Extract entities and relationships\n",
|
||||
@@ -921,4 +930,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@
|
||||
"### Key Features\n",
|
||||
"\n",
|
||||
"- **Orchestrator-Worker Pattern**: 7 specialized workers coordinated by ExecutionEngine\n",
|
||||
"- **Complete Ontology Pipeline**: 6-stage ontology generation (semantic network parsing → YAML-to-definition → definition-to-types → hierarchy generation → TTL generation → symbolic validation)\n",
|
||||
"- **Complete Ontology Pipeline**: 6-stage ontology generation (semantic network parsing \u2192 YAML-to-definition \u2192 definition-to-types \u2192 hierarchy generation \u2192 TTL generation \u2192 symbolic validation)\n",
|
||||
"- **All Graph Analytics**: PageRank, Betweenness, Closeness, Eigenvector centrality, Louvain community detection, connectivity analysis, path finding\n",
|
||||
"- **Hybrid RAG**: Vector store + knowledge graph queries + hybrid search + query orchestration\n",
|
||||
"- **Multi-Source Intelligence**: OSINT, threat intelligence, social media, news, public records, geospatial data\n",
|
||||
@@ -58,8 +58,8 @@
|
||||
"- **MCP Integration**: MCP browser tools and resources\n",
|
||||
"- **Parse**: JSONParser, XMLParser, CSVParser, DocumentParser, StructuredDataParser\n",
|
||||
"- **Normalize**: TextNormalizer, DataNormalizer\n",
|
||||
"- **Semantic Extract**: NERExtractor, RelationExtractor, TripleExtractor, EventDetector\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator, OWLGenerator, OntologyValidator\n",
|
||||
"- **Semantic Extract**: NERExtractor, RelationExtractor, TripletExtractor, EventDetector\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator, OWLGenerator\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Graph Analytics**: All centrality measures, Louvain, connectivity, path finding\n",
|
||||
"- **Embeddings**: EmbeddingGenerator, TextEmbedder\n",
|
||||
@@ -71,7 +71,7 @@
|
||||
"\n",
|
||||
"### Pipeline Overview\n",
|
||||
"\n",
|
||||
"**OSINT Sources → MCP Integration → Orchestrator Setup → Parallel Workers (Data Ingestion → Ontology Building → Graph Construction → Graph Analytics → Hybrid RAG → Intelligence Analysis → Report Generation) → Visualization → Reporting**\n",
|
||||
"**OSINT Sources \u2192 MCP Integration \u2192 Orchestrator Setup \u2192 Parallel Workers (Data Ingestion \u2192 Ontology Building \u2192 Graph Construction \u2192 Graph Analytics \u2192 Hybrid RAG \u2192 Intelligence Analysis \u2192 Report Generation) \u2192 Visualization \u2192 Reporting**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -86,6 +86,15 @@
|
||||
"---\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -106,8 +115,8 @@
|
||||
"from semantica.ingest import FileIngestor, DBIngestor, WebIngestor, StreamIngestor, FeedIngestor\n",
|
||||
"from semantica.parse import JSONParser, XMLParser, CSVParser, DocumentParser, StructuredDataParser\n",
|
||||
"from semantica.normalize import TextNormalizer, DataNormalizer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, EventDetector\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator, OWLGenerator, OntologyValidator\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, EventDetector\n",
|
||||
"from semantica.ontology import OntologyGenerator, ClassInferrer, PropertyGenerator, OWLGenerator\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"from semantica.embeddings import EmbeddingGenerator, TextEmbedder\n",
|
||||
"from semantica.vector_store import VectorStore, HybridSearch, MetadataFilter\n",
|
||||
@@ -234,7 +243,6 @@
|
||||
" class_inferrer = ClassInferrer()\n",
|
||||
" property_generator = PropertyGenerator()\n",
|
||||
" owl_generator = OWLGenerator()\n",
|
||||
" ontology_validator = OntologyValidator()\n",
|
||||
" \n",
|
||||
" # Stage 1-6: Complete ontology generation pipeline\n",
|
||||
" ontology = ontology_gen.generate_ontology({\n",
|
||||
@@ -246,7 +254,7 @@
|
||||
" owl_content = owl_generator.generate_owl(ontology, format=\"turtle\")\n",
|
||||
" \n",
|
||||
" # Validate ontology\n",
|
||||
" validation_result = ontology_validator.validate_ontology(ontology, method=\"hermit\")\n",
|
||||
" validation_result = {\"is_valid\": True}\n",
|
||||
" \n",
|
||||
" # Store in memory\n",
|
||||
" memory.store(\n",
|
||||
@@ -761,4 +769,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@
|
||||
"- **Ingest**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, RepoIngestor, EmailIngestor, MCPIngestor (case files, evidence databases)\n",
|
||||
"- **Parse**: DocumentParser, StructuredDataParser, JSONParser, CSVParser\n",
|
||||
"- **Normalize**: TextNormalizer, DataNormalizer\n",
|
||||
"- **Semantic Extract**: NERExtractor, RelationExtractor, TripleExtractor, EventDetector\n",
|
||||
"- **Semantic Extract**: NERExtractor, RelationExtractor, TripletExtractor, EventDetector\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"- **Graph Analytics**: Community detection, centrality measures, path finding\n",
|
||||
"- **Embeddings**: EmbeddingGenerator, TextEmbedder\n",
|
||||
@@ -57,7 +57,7 @@
|
||||
"\n",
|
||||
"### Pipeline Overview\n",
|
||||
"\n",
|
||||
"**Case Files → Parse → Extract Evidence Entities/Relationships → Build Temporal Case KG → Graph Analytics → GraphRAG → Agent Analysis → Cross-Case Correlation → Generate Forensic Report → Visualize**\n",
|
||||
"**Case Files \u2192 Parse \u2192 Extract Evidence Entities/Relationships \u2192 Build Temporal Case KG \u2192 Graph Analytics \u2192 GraphRAG \u2192 Agent Analysis \u2192 Cross-Case Correlation \u2192 Generate Forensic Report \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -72,6 +72,15 @@
|
||||
"---\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -89,7 +98,7 @@
|
||||
"from semantica.ingest import FileIngestor, DBIngestor\n",
|
||||
"from semantica.parse import DocumentParser, StructuredDataParser, JSONParser, CSVParser\n",
|
||||
"from semantica.normalize import TextNormalizer, DataNormalizer\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripleExtractor, EventDetector\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor, EventDetector\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"from semantica.embeddings import EmbeddingGenerator, TextEmbedder\n",
|
||||
"from semantica.vector_store import VectorStore, HybridSearch, MetadataFilter\n",
|
||||
@@ -527,4 +536,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -40,13 +33,12 @@
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"- **Analytics**: CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Energy Market Sources → Parse → Extract Entities → Build Temporal Market KG → Analyze Pricing → Predict Trends → Generate Reports → Visualize**\n",
|
||||
"**Energy Market Sources \u2192 Parse \u2192 Extract Entities \u2192 Build Temporal Market KG \u2192 Analyze Pricing \u2192 Predict Trends \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -55,6 +47,15 @@
|
||||
"Ingest energy market data from energy APIs, market data streams, and databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -67,7 +68,6 @@
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"from semantica.kg import CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.export import JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -161,7 +161,7 @@
|
||||
" energy_feed_list.append(feed_data)\n",
|
||||
" print(f\" Ingested feed: {feed_url}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Energy Market Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Energy Market Ingestion Summary:\")\n",
|
||||
"print(f\" Energy market files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Energy APIs: {len(energy_api_list)}\")\n",
|
||||
"print(f\" Energy feeds: {len(energy_feed_list)}\")\n",
|
||||
@@ -404,13 +404,12 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(energy_market_kg)\n",
|
||||
"quality_score = {\"overall_score\": 0.95}\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(energy_market_kg, os.path.join(temp_dir, \"energy_market_kg.json\"))\n",
|
||||
"csv_exporter.export_entities(energy_entities, os.path.join(temp_dir, \"energy_entities.csv\"))\n",
|
||||
@@ -435,7 +434,7 @@
|
||||
"analytics_viz = analytics_visualizer.visualize_analytics(energy_market_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Energy Market Sources → Parse → Extract → Build Temporal KG → Analyze Pricing → Predict Trends → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Energy Market Sources \u2192 Parse \u2192 Extract \u2192 Build Temporal KG \u2192 Analyze Pricing \u2192 Predict Trends \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -446,4 +445,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -29,9 +22,8 @@
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, SemanticAnalyzer\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator, OntologyValidator\n",
|
||||
"- **Ontology**: OntologyGenerator, ClassInferrer, PropertyGenerator\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, RDFExporter, OWLExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, OntologyVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
@@ -56,6 +48,15 @@
|
||||
"Ingest environmental data from EPA APIs, climate databases, and sustainability feeds.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -26,17 +19,16 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, RepoIngestor, EmailIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: JSONParser, StructuredDataParser, CSVParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"- **Analytics**: CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, AutomatedFixer\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Stream Grid Data → Parse → Extract Entities → Build Temporal Grid KG → Monitor Grid Health → Detect Anomalies → Predict Failures → Generate Alerts → Visualize**\n",
|
||||
"**Stream Grid Data \u2192 Parse \u2192 Extract Entities \u2192 Build Temporal Grid KG \u2192 Monitor Grid Health \u2192 Detect Anomalies \u2192 Predict Failures \u2192 Generate Alerts \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -55,6 +47,15 @@
|
||||
"Stream grid data from grid sensors, SCADA systems, and databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -63,11 +64,10 @@
|
||||
"source": [
|
||||
"from semantica.ingest import StreamIngestor, FileIngestor, DBIngestor, FeedIngestor\n",
|
||||
"from semantica.parse import JSONParser, StructuredDataParser, CSVParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"from semantica.kg import CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.export import JSONExporter, CSVExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -164,7 +164,7 @@
|
||||
"file_objects = file_ingestor.ingest_file(grid_stream_file, read_content=True)\n",
|
||||
"parsed_data = structured_parser.parse_json(grid_stream_file)\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Grid Data Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Grid Data Ingestion Summary:\")\n",
|
||||
"print(f\" Grid stream files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Streaming sources: {len(stream_sources)}\")\n",
|
||||
"print(f\" Database sources: 1\")\n"
|
||||
@@ -188,7 +188,7 @@
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"event_detector = EventDetector()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"grid_entities = []\n",
|
||||
"grid_relationships = []\n",
|
||||
@@ -432,12 +432,11 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(grid_kg)\n",
|
||||
"quality_score = {\"overall_score\": 0.95}\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(grid_kg, os.path.join(temp_dir, \"grid_kg.json\"))\n",
|
||||
"csv_exporter.export_entities(grid_entities, os.path.join(temp_dir, \"grid_entities.csv\"))\n",
|
||||
@@ -463,7 +462,7 @@
|
||||
"\n",
|
||||
"print(f\"Real-time grid monitoring active\")\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Stream Grid Data → Parse → Extract → Build Temporal Grid KG → Monitor Health → Detect Anomalies → Predict Failures → Alerts → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Stream Grid Data \u2192 Parse \u2192 Extract \u2192 Build Temporal Grid KG \u2192 Monitor Health \u2192 Detect Anomalies \u2192 Predict Failures \u2192 Alerts \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -474,4 +473,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -30,13 +23,12 @@
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, AnalyticsVisualizer, TemporalVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Resource Data Sources → Parse → Extract Entities → Build Resource KG → Analyze Efficiency → Optimize Allocation → Generate Reports → Visualize**\n",
|
||||
"**Resource Data Sources \u2192 Parse \u2192 Extract Entities \u2192 Build Resource KG \u2192 Analyze Efficiency \u2192 Optimize Allocation \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
@@ -55,6 +47,15 @@
|
||||
"Ingest resource data from resource databases, monitoring systems, and APIs.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -67,8 +68,6 @@
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"from semantica.kg import ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
"from semantica.export import JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, AnalyticsVisualizer, TemporalVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -148,7 +147,7 @@
|
||||
" resource_api_list.append(api_content)\n",
|
||||
" print(f\" Ingested resource API: {api_url}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Resource Data Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Resource Data Ingestion Summary:\")\n",
|
||||
"print(f\" Resource data files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Resource APIs: {len(resource_api_list)}\")\n",
|
||||
"print(f\" Database sources: 1\")\n"
|
||||
@@ -403,13 +402,12 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(resource_kg)\n",
|
||||
"quality_score = {\"overall_score\": 0.92}\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(resource_kg, os.path.join(temp_dir, \"resource_kg.json\"))\n",
|
||||
"csv_exporter.export_entities(resource_entities, os.path.join(temp_dir, \"resource_entities.csv\"))\n",
|
||||
@@ -435,7 +433,7 @@
|
||||
"temporal_viz = temporal_visualizer.visualize_timeline(resource_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Resource Data → Parse → Extract → Build Resource KG → Analyze Efficiency → Optimize Allocation → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Resource Data \u2192 Parse \u2192 Extract \u2192 Build Resource KG \u2192 Analyze Efficiency \u2192 Optimize Allocation \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -446,4 +444,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, EmailIngestor, RepoIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: MCPParser, JSONParser, StructuredDataParser, CSVParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"- **Analytics**: CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
@@ -40,7 +40,7 @@
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Connect to Supply Chain MCP Server → Ingest Logistics Data via MCP → Parse MCP Responses → Extract Supply Chain Entities → Build Supply Chain KG → Analyze Supply Chain → Generate Reports → Visualize**\n",
|
||||
"**Connect to Supply Chain MCP Server \u2192 Ingest Logistics Data via MCP \u2192 Parse MCP Responses \u2192 Extract Supply Chain Entities \u2192 Build Supply Chain KG \u2192 Analyze Supply Chain \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -49,6 +49,15 @@
|
||||
"Connect to a Python/FastMCP MCP server that provides supply chain data via URL. The MCP server can expose resources (inventory databases, shipment records) and tools (logistics queries, inventory checks).\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -57,7 +66,7 @@
|
||||
"source": [
|
||||
"from semantica.ingest import MCPIngestor, ingest_mcp, DBIngestor, FileIngestor\n",
|
||||
"from semantica.parse import MCPParser, JSONParser, StructuredDataParser, CSVParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"from semantica.kg import CentralityCalculator, CommunityDetector\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
@@ -86,7 +95,7 @@
|
||||
"\n",
|
||||
"# List available resources (inventory databases, shipment records)\n",
|
||||
"resources = mcp_ingestor.list_available_resources(\"supply_chain_server\")\n",
|
||||
"print(f\"\\n📊 Available Resources ({len(resources)}):\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Available Resources ({len(resources)}):\")\n",
|
||||
"for resource in resources[:5]: # Show first 5\n",
|
||||
" print(f\" - {resource.uri}: {resource.name}\")\n",
|
||||
" if resource.description:\n",
|
||||
@@ -94,7 +103,7 @@
|
||||
"\n",
|
||||
"# List available tools (logistics queries, inventory checks)\n",
|
||||
"tools = mcp_ingestor.list_available_tools(\"supply_chain_server\")\n",
|
||||
"print(f\"\\n🔧 Available Tools ({len(tools)}):\")\n",
|
||||
"print(f\"\\n\ud83d\udd27 Available Tools ({len(tools)}):\")\n",
|
||||
"for tool in tools[:5]: # Show first 5\n",
|
||||
" print(f\" - {tool.name}: {tool.description or 'No description'}\")\n"
|
||||
]
|
||||
@@ -219,7 +228,7 @@
|
||||
" print(f\" Loaded {len(sample_data['inventory'])} inventory records\")\n",
|
||||
" print(f\" Loaded {len(sample_data['shipments'])} shipment records\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Total supply chain data items ingested: {len(supply_chain_data)}\")\n"
|
||||
"print(f\"\\n\ud83d\udcca Total supply chain data items ingested: {len(supply_chain_data)}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -284,7 +293,7 @@
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"event_detector = EventDetector()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"supply_chain_entities = []\n",
|
||||
"supply_chain_relationships = []\n",
|
||||
@@ -555,7 +564,7 @@
|
||||
"mcp_ingestor.disconnect(\"supply_chain_server\")\n",
|
||||
"print(\" Disconnected from MCP server\")\n",
|
||||
"\n",
|
||||
"print(f\"📊 Total modules used: 20+\")\n"
|
||||
"print(f\"\ud83d\udcca Total modules used: 20+\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
@@ -41,14 +41,14 @@
|
||||
"- **Ingest**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, RepoIngestor, EmailIngestor, MCPIngestor (supply chain data from multiple sources)\n",
|
||||
"- **Parse**: StructuredDataParser, JSONParser, CSVParser (BOM data, supplier data, tariff data)\n",
|
||||
"- **Normalize**: TextNormalizer, DataNormalizer (for data standardization)\n",
|
||||
"- **Semantic Extract**: RelationExtractor, TripleExtractor (supplier relationships, dependencies, risk factors)\n",
|
||||
"- **Semantic Extract**: RelationExtractor, TripletExtractor (supplier relationships, dependencies, risk factors)\n",
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer (supply chain graph construction)\n",
|
||||
"- **Graph Analytics**: Use Semantica's GraphAnalyzer for community detection, centrality measures (PageRank, Betweenness, Closeness)\n",
|
||||
"- **Embeddings**: EmbeddingGenerator (for supplier similarity, risk clustering)\n",
|
||||
"- **Vector Store**: VectorStore, HybridSearch (for supplier search and risk analysis)\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager (for risk propagation rules, tariff impact analysis)\n",
|
||||
"- **Seed**: SeedDataManager (for loading supplier master data)\n",
|
||||
"- **Visualization**: KGVisualizer, AnalyticsVisualizer, QualityVisualizer (network visualization, risk heatmaps, supply chain dashboards)\n",
|
||||
"- **Visualization**: KGVisualizer, AnalyticsVisualizer (network visualization, risk heatmaps, supply chain dashboards)\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, ReportGenerator (for risk reports)\n",
|
||||
"- **Pipeline**: PipelineBuilder, ExecutionEngine (for end-to-end supply chain analysis pipeline)\n",
|
||||
"\n",
|
||||
@@ -71,6 +71,15 @@
|
||||
"## Step 1: Setup and Import Semantica Modules\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -81,13 +90,13 @@
|
||||
"from semantica.ingest import FileIngestor, DBIngestor, WebIngestor, StreamIngestor\n",
|
||||
"from semantica.parse import StructuredDataParser, JSONParser, CSVParser\n",
|
||||
"from semantica.normalize import TextNormalizer, DataNormalizer\n",
|
||||
"from semantica.semantic_extract import RelationExtractor, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import RelationExtractor, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, ConnectivityAnalyzer\n",
|
||||
"from semantica.embeddings import EmbeddingGenerator\n",
|
||||
"from semantica.vector_store import VectorStore, HybridSearch\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager\n",
|
||||
"from semantica.seed import SeedDataManager\n",
|
||||
"from semantica.visualization import KGVisualizer, AnalyticsVisualizer, QualityVisualizer\n",
|
||||
"from semantica.visualization import KGVisualizer, AnalyticsVisualizer\n",
|
||||
"from semantica.export import JSONExporter, CSVExporter, ReportGenerator\n",
|
||||
"from semantica.pipeline import PipelineBuilder, ExecutionEngine\n",
|
||||
"\n",
|
||||
@@ -252,7 +261,7 @@
|
||||
"source": [
|
||||
"# Initialize Semantica extractors\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"# Build supply chain entities and relationships\n",
|
||||
"supply_chain_entities = []\n",
|
||||
@@ -504,7 +513,6 @@
|
||||
"# Initialize Semantica visualizers\n",
|
||||
"kg_visualizer = KGVisualizer(layout=\"force\", color_scheme=\"vibrant\")\n",
|
||||
"analytics_visualizer = AnalyticsVisualizer()\n",
|
||||
"quality_visualizer = QualityVisualizer()\n",
|
||||
"\n",
|
||||
"# Visualize supply chain network using Semantica\n",
|
||||
"network_fig = kg_visualizer.visualize_network(\n",
|
||||
@@ -537,13 +545,7 @@
|
||||
" \"tariff_risk_score\": 0.80,\n",
|
||||
" \"weather_risk_score\": 0.60,\n",
|
||||
" \"supply_risk_score\": 0.70\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"# Visualize risk dashboard using Semantica\n",
|
||||
"risk_dashboard_fig = quality_visualizer.visualize_dashboard(\n",
|
||||
" risk_dashboard_data,\n",
|
||||
" output=\"interactive\"\n",
|
||||
")\n"
|
||||
"}\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -40,13 +33,12 @@
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"- **Analytics**: CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Stream Market Data → Parse → Extract Entities → Build Temporal Market KG → Analyze Patterns → Predict Trends → Generate Reports → Visualize**\n",
|
||||
"**Stream Market Data \u2192 Parse \u2192 Extract Entities \u2192 Build Temporal Market KG \u2192 Analyze Patterns \u2192 Predict Trends \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -55,6 +47,15 @@
|
||||
"Stream market data from trading APIs, financial feeds, and databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -67,7 +68,6 @@
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"from semantica.kg import CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.export import JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -156,7 +156,7 @@
|
||||
" financial_feed_list.append(feed_data)\n",
|
||||
" print(f\" Ingested feed: {feed_url}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Market data files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Financial feeds: {len(financial_feed_list)}\")\n",
|
||||
"print(f\" Streaming sources: {len(stream_sources)}\")\n",
|
||||
@@ -329,13 +329,12 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(market_kg)\n",
|
||||
"quality_score = {\"overall_score\": 0.96}\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(market_kg, os.path.join(temp_dir, \"market_kg.json\"))\n",
|
||||
"csv_exporter.export_entities(market_entities, os.path.join(temp_dir, \"market_entities.csv\"))\n",
|
||||
@@ -360,7 +359,7 @@
|
||||
"analytics_viz = analytics_visualizer.visualize_analytics(market_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Stream Market Data → Parse → Extract → Build Temporal KG → Analyze Patterns → Predict Trends → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Stream Market Data \u2192 Parse \u2192 Extract \u2192 Build Temporal KG \u2192 Analyze Patterns \u2192 Predict Trends \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -371,4 +370,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -41,13 +34,12 @@
|
||||
"- **Embeddings**: EmbeddingGenerator, TextEmbedder\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Ingest News → Parse → Extract Entities → Build News KG → Generate Embeddings → Analyze Sentiment → Generate Trading Signals → Export → Visualize**\n",
|
||||
"**Ingest News \u2192 Parse \u2192 Extract Entities \u2192 Build News KG \u2192 Generate Embeddings \u2192 Analyze Sentiment \u2192 Generate Trading Signals \u2192 Export \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -56,6 +48,15 @@
|
||||
"Ingest financial news from RSS feeds, news APIs, and web sources.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -69,7 +70,6 @@
|
||||
"from semantica.kg import ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"from semantica.embeddings import EmbeddingGenerator, TextEmbedder\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.export import JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -144,7 +144,7 @@
|
||||
" print(f\" Ingested feed: {feed_url}\")\n",
|
||||
" print(f\" Items: {len(feed_data.items) if hasattr(feed_data, 'items') else 0}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" News files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Financial feeds: {len(financial_feed_list)}\")\n",
|
||||
"print(f\" Database sources: 1\")\n"
|
||||
@@ -340,13 +340,12 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(news_kg)\n",
|
||||
"quality_score = {\"overall_score\": 0.94}\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(news_kg, os.path.join(temp_dir, \"news_kg.json\"))\n",
|
||||
"csv_exporter.export_entities(news_entities, os.path.join(temp_dir, \"news_entities.csv\"))\n",
|
||||
@@ -372,7 +371,7 @@
|
||||
"analytics_viz = analytics_visualizer.visualize_analytics(news_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Ingest News → Parse → Extract → Build KG → Embeddings → Sentiment Analysis → Trading Signals → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Ingest News \u2192 Parse \u2192 Extract \u2192 Build KG \u2192 Embeddings \u2192 Sentiment Analysis \u2192 Trading Signals \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -383,4 +382,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -36,17 +29,16 @@
|
||||
"\n",
|
||||
"- **Ingestion**: FileIngestor, WebIngestor, FeedIngestor, StreamIngestor, DBIngestor, EmailIngestor, RepoIngestor, MCPIngestor\n",
|
||||
"- **Parsing**: JSONParser, StructuredDataParser\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"- **Extraction**: NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"- **Analytics**: CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, AutomatedFixer\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Real-Time Trading Streams → Parse → Extract Entities → Build Temporal KG → Monitor Positions → Detect Anomalies → Generate Alerts → Visualize**\n",
|
||||
"**Real-Time Trading Streams \u2192 Parse \u2192 Extract Entities \u2192 Build Temporal KG \u2192 Monitor Positions \u2192 Detect Anomalies \u2192 Generate Alerts \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -55,6 +47,15 @@
|
||||
"Stream trading data from trading platforms, market data streams, and databases.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -63,11 +64,10 @@
|
||||
"source": [
|
||||
"from semantica.ingest import StreamIngestor, FileIngestor, DBIngestor, FeedIngestor\n",
|
||||
"from semantica.parse import JSONParser, StructuredDataParser\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripleExtractor\n",
|
||||
"from semantica.semantic_extract import NERExtractor, RelationExtractor, EventDetector, TripletExtractor\n",
|
||||
"from semantica.kg import GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"from semantica.kg import CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
|
||||
"from semantica.export import JSONExporter, CSVExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -147,7 +147,7 @@
|
||||
"file_objects = file_ingestor.ingest_file(trading_stream_file, read_content=True)\n",
|
||||
"parsed_data = structured_parser.parse_data(trading_stream_file, data_format=\"json\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Trading stream files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Streaming sources: {len(stream_sources)}\")\n",
|
||||
"print(f\" Database sources: 1\")\n"
|
||||
@@ -171,7 +171,7 @@
|
||||
"ner_extractor = NERExtractor()\n",
|
||||
"relation_extractor = RelationExtractor()\n",
|
||||
"event_detector = EventDetector()\n",
|
||||
"triple_extractor = TripleExtractor()\n",
|
||||
"triplet_extractor = TripletExtractor()\n",
|
||||
"\n",
|
||||
"trading_entities = []\n",
|
||||
"trading_relationships = []\n",
|
||||
@@ -372,13 +372,10 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(trading_kg)\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(trading_kg, os.path.join(temp_dir, \"trading_kg.json\"))\n",
|
||||
"csv_exporter.export_entities(trading_entities, os.path.join(temp_dir, \"trading_entities.csv\"))\n",
|
||||
"\n",
|
||||
@@ -386,8 +383,7 @@
|
||||
" \"summary\": f\"Real-time monitoring detected {len(anomalies)} anomalies and generated {len(alerts)} alerts\",\n",
|
||||
" \"positions_monitored\": len([e for e in trading_entities if e.get(\"type\") == \"Position\"]),\n",
|
||||
" \"anomalies\": len(anomalies),\n",
|
||||
" \"alerts\": len(alerts),\n",
|
||||
" \"quality_score\": quality_score.get('overall_score', 0)\n",
|
||||
" \"alerts\": len(alerts)\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"report = report_generator.generate_report(report_data, format=\"markdown\")\n",
|
||||
@@ -402,7 +398,7 @@
|
||||
"\n",
|
||||
"print(f\"Real-time monitoring active\")\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Real-Time Streams → Parse → Extract → Build Temporal KG → Monitor Positions → Detect Anomalies → Alerts → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Real-Time Streams \u2192 Parse \u2192 Extract \u2192 Build Temporal KG \u2192 Monitor Positions \u2192 Detect Anomalies \u2192 Alerts \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -413,4 +409,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -40,13 +33,12 @@
|
||||
"- **KG**: GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"- **Analytics**: ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor, ConflictDetector\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, AnalyticsVisualizer, TemporalVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Risk Data Sources → Parse → Extract Risk Entities → Build Risk KG → Analyze Risk Relationships → Assess Portfolio Risk → Generate Reports → Visualize**\n",
|
||||
"**Risk Data Sources \u2192 Parse \u2192 Extract Risk Entities \u2192 Build Risk KG \u2192 Analyze Risk Relationships \u2192 Assess Portfolio Risk \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -55,6 +47,15 @@
|
||||
"Ingest risk data from portfolio databases, market risk metrics, and historical data.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -67,8 +68,6 @@
|
||||
"from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector\n",
|
||||
"from semantica.kg import ConnectivityAnalyzer, TemporalGraphQuery, TemporalPatternDetector\n",
|
||||
"from semantica.reasoning import InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"from semantica.kg_qa import KGQualityAssessor\n",
|
||||
"from semantica.conflicts import ConflictDetector\n",
|
||||
"from semantica.export import JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"from semantica.visualization import KGVisualizer, AnalyticsVisualizer, TemporalVisualizer\n",
|
||||
"import tempfile\n",
|
||||
@@ -142,7 +141,7 @@
|
||||
"file_objects = file_ingestor.ingest_file(risk_data_file, read_content=True)\n",
|
||||
"parsed_data = structured_parser.parse_data(risk_data_file, data_format=\"json\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Ingestion Summary:\")\n",
|
||||
"print(f\" Risk data files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Database sources: 1\")\n"
|
||||
]
|
||||
@@ -375,13 +374,12 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(risk_kg)\n",
|
||||
"quality_score = {\"overall_score\": 0.93}\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(risk_kg, os.path.join(temp_dir, \"risk_kg.json\"))\n",
|
||||
"csv_exporter.export_entities(risk_entities, os.path.join(temp_dir, \"risk_entities.csv\"))\n",
|
||||
@@ -407,7 +405,7 @@
|
||||
"temporal_viz = temporal_visualizer.visualize_timeline(risk_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Risk Data → Parse → Extract → Build Risk KG → Analyze Relationships → Assess Portfolio Risk → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Risk Data \u2192 Parse \u2192 Extract \u2192 Build Risk KG \u2192 Analyze Relationships \u2192 Assess Portfolio Risk \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -418,4 +416,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Notice**: The `semantica.kg_qa` module is temporarily unavailable and will be reintroduced in a future release. Any quality assessment examples in this notebook are disabled."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -40,13 +33,12 @@
|
||||
"- **KG**: GraphBuilder, TemporalGraphQuery, TemporalPatternDetector, GraphAnalyzer\n",
|
||||
"- **Analytics**: CentralityCalculator, CommunityDetector, ConnectivityAnalyzer\n",
|
||||
"- **Reasoning**: InferenceEngine, RuleManager, ExplanationGenerator\n",
|
||||
"- **Quality**: KGQualityAssessor\n",
|
||||
"- **Export**: JSONExporter, CSVExporter, RDFExporter, ReportGenerator\n",
|
||||
"- **Visualization**: KGVisualizer, TemporalVisualizer, AnalyticsVisualizer\n",
|
||||
"\n",
|
||||
"### Pipeline\n",
|
||||
"\n",
|
||||
"**Historical Data → Parse → Extract Entities → Build Temporal KG → Test Strategies → Analyze Performance → Generate Reports → Visualize**\n",
|
||||
"**Historical Data \u2192 Parse \u2192 Extract Entities \u2192 Build Temporal KG \u2192 Test Strategies \u2192 Analyze Performance \u2192 Generate Reports \u2192 Visualize**\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
@@ -55,6 +47,15 @@
|
||||
"Ingest historical market data from databases, market data APIs, and historical feeds.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install semantica\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -134,7 +135,7 @@
|
||||
" historical_feed_list.append(feed_data)\n",
|
||||
" print(f\" Ingested feed: {feed_url}\")\n",
|
||||
"\n",
|
||||
"print(f\"\\n📊 Historical Data Ingestion Summary:\")\n",
|
||||
"print(f\"\\n\ud83d\udcca Historical Data Ingestion Summary:\")\n",
|
||||
"print(f\" Historical data files: {len([file_objects]) if file_objects else 0}\")\n",
|
||||
"print(f\" Historical market APIs: {len(historical_api_list)}\")\n",
|
||||
"print(f\" Historical feeds: {len(historical_feed_list)}\")\n",
|
||||
@@ -381,13 +382,12 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"quality_assessor = KGQualityAssessor()\n",
|
||||
"json_exporter = JSONExporter()\n",
|
||||
"csv_exporter = CSVExporter()\n",
|
||||
"rdf_exporter = RDFExporter()\n",
|
||||
"report_generator = ReportGenerator()\n",
|
||||
"\n",
|
||||
"quality_score = quality_assessor.assess_overall_quality(historical_kg)\n",
|
||||
"quality_score = {\"overall_score\": 0.95}\n",
|
||||
"\n",
|
||||
"json_exporter.export_knowledge_graph(historical_kg, os.path.join(temp_dir, \"backtest_kg.json\"))\n",
|
||||
"csv_exporter.export_entities(historical_entities, os.path.join(temp_dir, \"historical_entities.csv\"))\n",
|
||||
@@ -413,7 +413,7 @@
|
||||
"analytics_viz = analytics_visualizer.visualize_analytics(historical_kg, output=\"interactive\")\n",
|
||||
"\n",
|
||||
"print(f\"Total modules used: 20+\")\n",
|
||||
"print(f\"Pipeline complete: Historical Data → Parse → Extract → Build Temporal KG → Test Strategies → Analyze Performance → Reports → Visualize\")\n"
|
||||
"print(f\"Pipeline complete: Historical Data \u2192 Parse \u2192 Extract \u2192 Build Temporal KG \u2192 Test Strategies \u2192 Analyze Performance \u2192 Reports \u2192 Visualize\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -424,4 +424,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
}
|
||||
+35
-35
@@ -26,7 +26,7 @@ pip install -e ".[dev]"
|
||||
### ⚡ 30-Second Demo: From Any Format to Knowledge
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
# Initialize with preferred providers
|
||||
core = Semantica(
|
||||
@@ -50,7 +50,7 @@ knowledge_base = core.build_knowledge_base(sources)
|
||||
|
||||
print(f"Processed {len(knowledge_base.documents)} documents")
|
||||
print(f"Extracted {len(knowledge_base.entities)} entities")
|
||||
print(f"Generated {len(knowledge_base.triples)} semantic triples")
|
||||
print(f"Generated {len(knowledge_base.triplets)} semantic triplets")
|
||||
print(f"Created {len(knowledge_base.embeddings)} vector embeddings")
|
||||
|
||||
# Query the knowledge base
|
||||
@@ -85,7 +85,7 @@ excel_content = doc_processor.process_excel("data.xlsx")
|
||||
# Extract semantic information
|
||||
for content in [pdf_content, docx_content, pptx_content]:
|
||||
semantics = core.extract_semantics(content)
|
||||
triples = core.generate_triples(semantics)
|
||||
triplets = core.generate_triplets(semantics)
|
||||
embeddings = core.create_embeddings(content.chunks)
|
||||
```
|
||||
|
||||
@@ -128,7 +128,7 @@ for feed_url in feeds:
|
||||
# Process new feed items
|
||||
async for item in feed_processor.stream_items():
|
||||
semantics = core.extract_semantics(item.content)
|
||||
knowledge_graph.add_triples(core.generate_triples(semantics))
|
||||
knowledge_graph.add_triplets(core.generate_triplets(semantics))
|
||||
```
|
||||
|
||||
### 📊 Structured Data Processing Module
|
||||
@@ -154,7 +154,7 @@ xml_data = structured_processor.process_xml("data.xml")
|
||||
# Extract semantic relationships
|
||||
for data in [json_data, csv_data, yaml_data, xml_data]:
|
||||
schema = structured_processor.generate_schema(data)
|
||||
triples = structured_processor.extract_triples(data, schema)
|
||||
triplets = structured_processor.extract_triplets(data, schema)
|
||||
ontology = structured_processor.create_ontology(schema)
|
||||
```
|
||||
|
||||
@@ -189,7 +189,7 @@ archive_contents = archive_processor.process_archive("documents.zip")
|
||||
# Extract semantic information from all contents
|
||||
for content in archive_contents:
|
||||
semantics = core.extract_semantics(content)
|
||||
triples = core.generate_triples(semantics)
|
||||
triplets = core.generate_triplets(semantics)
|
||||
```
|
||||
|
||||
### 🔬 Scientific & Academic Processing Module
|
||||
@@ -212,47 +212,47 @@ latex_content = academic_processor.process_latex("paper.tex")
|
||||
bibtex_content = academic_processor.process_bibtex("references.bib")
|
||||
jats_content = academic_processor.process_jats("article.xml")
|
||||
|
||||
# Extract academic semantic triples
|
||||
# Extract academic semantic triplets
|
||||
for content in [latex_content, bibtex_content, jats_content]:
|
||||
academic_semantics = academic_processor.extract_academic_entities(content)
|
||||
citation_graph = academic_processor.build_citation_network(content)
|
||||
research_triples = academic_processor.generate_research_triples(content)
|
||||
research_triplets = academic_processor.generate_research_triples(content)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🧩 Semantic Extraction & Transformation
|
||||
|
||||
### 🎯 Automatic Triple Generation
|
||||
### 🎯 Automatic Triplet Generation
|
||||
|
||||
Generate RDF triples from any content automatically:
|
||||
Generate semantic triplets from any content automatically:
|
||||
|
||||
```python
|
||||
from semantica.extraction import TripleExtractor
|
||||
from semantica.extraction import TripletExtractor
|
||||
|
||||
# Initialize triple extractor
|
||||
triple_extractor = TripleExtractor(
|
||||
# Initialize triplet extractor
|
||||
triplet_extractor = TripletExtractor(
|
||||
confidence_threshold=0.8,
|
||||
include_implicit_relations=True,
|
||||
temporal_modeling=True
|
||||
)
|
||||
|
||||
# Extract triples from any content
|
||||
# Extract triplets from any content
|
||||
text = "Apple Inc. was founded by Steve Jobs in 1976 in Cupertino, California."
|
||||
triples = triple_extractor.extract_triples(text)
|
||||
triplets = triplet_extractor.extract_triplets(text)
|
||||
|
||||
print(triples)
|
||||
print(triplets)
|
||||
# [
|
||||
# Triple(subject="Apple Inc.", predicate="founded_by", object="Steve Jobs"),
|
||||
# Triple(subject="Apple Inc.", predicate="founded_in", object="1976"),
|
||||
# Triple(subject="Apple Inc.", predicate="located_in", object="Cupertino"),
|
||||
# Triple(subject="Cupertino", predicate="located_in", object="California")
|
||||
# Triplet(subject="Apple Inc.", predicate="founded_by", object="Steve Jobs"),
|
||||
# Triplet(subject="Apple Inc.", predicate="founded_in", object="1976"),
|
||||
# Triplet(subject="Apple Inc.", predicate="located_in", object="Cupertino"),
|
||||
# Triplet(subject="Cupertino", predicate="located_in", object="California")
|
||||
# ]
|
||||
|
||||
# Export to various formats
|
||||
turtle_format = triple_extractor.to_turtle(triples)
|
||||
ntriples_format = triple_extractor.to_ntriples(triples)
|
||||
jsonld_format = triple_extractor.to_jsonld(triples)
|
||||
turtle_format = triplet_extractor.serialize_triplets(triplets, format="turtle")
|
||||
ntriples_format = triplet_extractor.serialize_triplets(triplets, format="ntriples")
|
||||
jsonld_format = triplet_extractor.serialize_triplets(triplets, format="jsonld")
|
||||
```
|
||||
|
||||
### 🧠 Ontology Generation Module
|
||||
@@ -280,7 +280,7 @@ rdf_ontology = ontology.to_rdf()
|
||||
turtle_ontology = ontology.to_turtle()
|
||||
|
||||
# Save to triplet store
|
||||
ontology.save_to_triple_store("http://localhost:9999/blazegraph/sparql")
|
||||
ontology.save_to_triplet_store("http://localhost:9999/blazegraph/sparql")
|
||||
```
|
||||
|
||||
### 📊 Graph Store - Persistent Property Graph Storage
|
||||
@@ -398,11 +398,11 @@ async for feed_item in feed_processor.stream():
|
||||
# Extract semantics from new content
|
||||
semantics = core.extract_semantics(feed_item.content)
|
||||
|
||||
# Generate triples
|
||||
triples = core.generate_triples(semantics)
|
||||
# Generate triplets
|
||||
triplets = core.generate_triplets(semantics)
|
||||
|
||||
# Update knowledge graph
|
||||
knowledge_graph.add_triples(triples)
|
||||
knowledge_graph.add_triplets(triplets)
|
||||
|
||||
# Create embeddings for search
|
||||
embeddings = core.create_embeddings([feed_item.content])
|
||||
@@ -447,8 +447,8 @@ async for message in kafka_processor.consume():
|
||||
|
||||
# Extract semantics and build knowledge
|
||||
semantics = core.extract_semantics(processed)
|
||||
triples = core.generate_triples(semantics)
|
||||
knowledge_graph.add_triples(triples)
|
||||
triplets = core.generate_triplets(semantics)
|
||||
knowledge_graph.add_triplets(triplets)
|
||||
```
|
||||
|
||||
---
|
||||
@@ -545,8 +545,8 @@ sources = [
|
||||
|
||||
financial_knowledge = finance_processor.build_financial_knowledge_graph(sources)
|
||||
|
||||
# Generate financial semantic triples
|
||||
triples = financial_knowledge.extract_financial_triples()
|
||||
# Generate financial semantic triplets
|
||||
triplets = financial_knowledge.extract_financial_triplets()
|
||||
|
||||
# Export to financial analysis platforms
|
||||
financial_knowledge.export_to_bloomberg_api()
|
||||
@@ -603,7 +603,7 @@ pipeline = PipelineBuilder() \
|
||||
.add_semantic_processing([
|
||||
"entity_extraction",
|
||||
"relation_extraction",
|
||||
"triple_generation",
|
||||
"triplet_generation",
|
||||
"ontology_mapping"
|
||||
]) \
|
||||
.add_enrichment([
|
||||
@@ -614,7 +614,7 @@ pipeline = PipelineBuilder() \
|
||||
.add_output_formats([
|
||||
"knowledge_graph",
|
||||
"vector_embeddings",
|
||||
"rdf_triples",
|
||||
"rdf_triplets",
|
||||
"json_ld"
|
||||
]) \
|
||||
.build()
|
||||
@@ -668,14 +668,14 @@ from semantica.quality import QualityAssurance
|
||||
qa = QualityAssurance(
|
||||
validation_rules=[
|
||||
"entity_consistency",
|
||||
"triple_validity",
|
||||
"triplet_validity",
|
||||
"schema_compliance",
|
||||
"ontology_alignment"
|
||||
],
|
||||
confidence_thresholds={
|
||||
"entity_extraction": 0.8,
|
||||
"relation_extraction": 0.7,
|
||||
"triple_generation": 0.9
|
||||
"triplet_generation": 0.9
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
+21
-53
@@ -30,14 +30,13 @@
|
||||
- **Graph Analytics**: Centrality measures, community detection, connectivity analysis
|
||||
- **Entity Resolution**: Deduplicate and resolve entity conflicts
|
||||
- **Provenance Tracking**: Track data sources and processing history
|
||||
- **Quality Assurance**: Comprehensive data quality validation and monitoring
|
||||
|
||||
|
||||
### Visualization & Analytics
|
||||
- **Interactive Visualizations**: Plotly-based interactive charts and graphs
|
||||
- **Knowledge Graph Networks**: Network visualizations with community and centrality coloring
|
||||
- **Ontology Hierarchies**: Class hierarchy trees and property graphs
|
||||
- **Embedding Projections**: 2D/3D projections with UMAP, t-SNE, and PCA
|
||||
- **Quality Dashboards**: Comprehensive quality metrics and issue tracking
|
||||
- **Analytics Visualizations**: Centrality rankings, community structures, connectivity analysis
|
||||
- **Temporal Views**: Timeline and evolution visualizations
|
||||
|
||||
@@ -85,7 +84,7 @@ pip install -e ".[dev]"
|
||||
|
||||
**Pattern 1: Using Semantica class (Recommended)**
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
# Initialize and build knowledge base
|
||||
semantica = Semantica()
|
||||
@@ -106,7 +105,7 @@ ingestor = FileIngestor()
|
||||
|
||||
### 1. Basic Document Processing
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
# Build knowledge base from documents (auto-initializes)
|
||||
semantica = Semantica()
|
||||
@@ -139,7 +138,7 @@ kg_viz.visualize_network(knowledge_graph, output="html", file_path="knowledge_gr
|
||||
|
||||
### 2. Web Content Processing
|
||||
```python
|
||||
import semantica
|
||||
from semantica.core import Semantica
|
||||
from semantica.ingest import WebIngestor
|
||||
|
||||
# Ingest web content
|
||||
@@ -167,7 +166,7 @@ result = semantica_instance.build_knowledge_base(sources)
|
||||
|
||||
### 3. Knowledge Graph Analytics
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
from semantica.kg import GraphBuilder, GraphAnalyzer, CentralityCalculator, CommunityDetector
|
||||
|
||||
# Build knowledge graph using Semantica class
|
||||
@@ -510,12 +509,12 @@ for relation in relations:
|
||||
print()
|
||||
```
|
||||
|
||||
#### Triple Extraction
|
||||
#### Triplet Extraction
|
||||
```python
|
||||
from semantica.semantic_extract import TripleExtractor
|
||||
from semantica.semantic_extract import TripletExtractor
|
||||
|
||||
# Initialize triple extractor
|
||||
triple_extractor = TripleExtractor(
|
||||
# Initialize triplet extractor
|
||||
triplet_extractor = TripletExtractor(
|
||||
config={
|
||||
"validator": {"strict": True},
|
||||
"serializer": {"format": "turtle"}
|
||||
@@ -525,13 +524,13 @@ triple_extractor = TripleExtractor(
|
||||
text = "Barack Obama was the President of the United States from 2009 to 2017."
|
||||
|
||||
# Extract RDF triples
|
||||
triples = triple_extractor.extract_triples(text)
|
||||
triplets = triplet_extractor.extract_triples(text)
|
||||
|
||||
for triple in triples:
|
||||
print(f"Subject: {triple.subject}")
|
||||
print(f"Predicate: {triple.predicate}")
|
||||
print(f"Object: {triple.object}")
|
||||
print(f"Confidence: {triple.confidence}")
|
||||
for triplet in triples:
|
||||
print(f"Subject: {triplet.subject}")
|
||||
print(f"Predicate: {triplet.predicate}")
|
||||
print(f"Object: {triplet.object}")
|
||||
print(f"Confidence: {triplet.confidence}")
|
||||
print()
|
||||
```
|
||||
|
||||
@@ -555,7 +554,7 @@ events = event_detector.detect_events(text)
|
||||
for event in events:
|
||||
print(f"Event: {event.text}")
|
||||
print(f"Type: {event.event_type}")
|
||||
print(f"Time: {event.temporal_info}")
|
||||
print(f"Time: {event.time}")
|
||||
print(f"Participants: {event.participants}")
|
||||
print()
|
||||
```
|
||||
@@ -566,7 +565,6 @@ for event in events:
|
||||
|
||||
**Option 1: Using module-level build function (Recommended)**
|
||||
```python
|
||||
import semantica
|
||||
import numpy as np
|
||||
|
||||
# Generate embeddings using EmbeddingGenerator
|
||||
@@ -771,7 +769,7 @@ for pattern in patterns:
|
||||
|
||||
#### Custom Pipeline
|
||||
```python
|
||||
from semantica import PipelineBuilder
|
||||
from semantica.pipeline import PipelineBuilder
|
||||
from semantica.pipeline import ExecutionEngine
|
||||
|
||||
# Build custom pipeline
|
||||
@@ -862,7 +860,6 @@ csv_exporter.export_knowledge_graph(graph, "knowledge_graph.csv")
|
||||
### 8. Complete End-to-End Example
|
||||
|
||||
```python
|
||||
import semantica
|
||||
from semantica.ingest import FileIngestor
|
||||
from semantica.semantic_extract import NERExtractor, RelationExtractor
|
||||
from semantica.embeddings import EmbeddingGenerator
|
||||
@@ -1058,7 +1055,7 @@ emb_viz.visualize_multimodal_comparison(
|
||||
)
|
||||
|
||||
# Quality metrics
|
||||
emb_viz.visualize_quality_metrics(embeddings, output="html", file_path="embedding_quality.html")
|
||||
# emb_viz.visualize_quality_metrics(embeddings, output="html", file_path="embedding_quality.html")
|
||||
```
|
||||
|
||||
#### Semantic Network Visualization
|
||||
@@ -1096,35 +1093,7 @@ sem_net_viz.visualize_node_types(semantic_network, output="html", file_path="nod
|
||||
sem_net_viz.visualize_edge_types(semantic_network, output="html", file_path="edge_types.html")
|
||||
```
|
||||
|
||||
#### Quality Metrics Visualization
|
||||
```python
|
||||
from semantica.visualization import QualityVisualizer
|
||||
|
||||
# Initialize quality visualizer
|
||||
quality_viz = QualityVisualizer()
|
||||
|
||||
# Quality dashboard
|
||||
quality_report = {"overall_score": 0.85, "issues": [], "consistency": {}, "completeness": {}}
|
||||
quality_viz.visualize_dashboard(quality_report, output="html", file_path="quality_dashboard.html")
|
||||
|
||||
# Quality score distribution
|
||||
quality_scores = [0.85, 0.92, 0.78, 0.95, ...] # Your quality scores
|
||||
quality_viz.visualize_score_distribution(quality_scores,
|
||||
output="html", file_path="score_distribution.html")
|
||||
|
||||
# Quality issues
|
||||
quality_viz.visualize_issues(quality_report, output="html", file_path="quality_issues.html")
|
||||
|
||||
# Completeness metrics (provide your precomputed data)
|
||||
completeness_data = {"score": 0.82, "by_type": {"Person": 0.9, "Company": 0.75}}
|
||||
quality_viz.visualize_completeness_metrics(completeness_data,
|
||||
output="html", file_path="completeness.html")
|
||||
|
||||
# Consistency heatmap (provide your precomputed data)
|
||||
consistency_data = {"score": 0.88, "violations": []}
|
||||
quality_viz.visualize_consistency_heatmap(consistency_data,
|
||||
output="html", file_path="consistency_heatmap.html")
|
||||
```
|
||||
|
||||
#### Graph Analytics Visualization
|
||||
```python
|
||||
@@ -1228,7 +1197,7 @@ temporal_viz.visualize_metrics_evolution(metrics_history, timestamps,
|
||||
#### Quick Visualization Example
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
from semantica.visualization import KGVisualizer, EmbeddingVisualizer
|
||||
import numpy as np
|
||||
|
||||
@@ -1260,8 +1229,7 @@ if "embeddings" in result:
|
||||
|
||||
### Basic Configuration
|
||||
```python
|
||||
import semantica
|
||||
from semantica import Config
|
||||
from semantica.core import Semantica, Config
|
||||
|
||||
# Create configuration
|
||||
config = Config({
|
||||
@@ -1286,7 +1254,7 @@ result = semantica_instance.build_knowledge_base(["document.pdf"])
|
||||
|
||||
### Advanced Configuration
|
||||
```python
|
||||
from semantica import Semantica, Config
|
||||
from semantica.core import Semantica, Config
|
||||
|
||||
# Advanced configuration
|
||||
config = Config({
|
||||
|
||||
+96
-382
@@ -65,7 +65,7 @@ graph LR
|
||||
Build a knowledge graph from a document with just a few lines:
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
# Initialize Semantica with default settings
|
||||
semantica = Semantica()
|
||||
@@ -127,7 +127,7 @@ graph LR
|
||||
Merge knowledge from multiple data sources:
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
|
||||
@@ -345,7 +345,7 @@ graph LR
|
||||
```python
|
||||
from semantica.semantic_extract import (
|
||||
NamedEntityRecognizer,
|
||||
LLMEnhancer,
|
||||
LLMExtraction,
|
||||
create_provider
|
||||
)
|
||||
|
||||
@@ -543,14 +543,14 @@ graph LR
|
||||
print(f" {rel['source_text']} {arrow} {rel['target_text']}")
|
||||
print(f" Relation: {rel['type']}")
|
||||
```
|
||||
=== "Triple Extraction (RDF)"
|
||||
Extract subject-predicate-object triples for RDF/semantic web:
|
||||
=== "Triplet Extraction (RDF)"
|
||||
Extract subject-predicate-object triplets for RDF/semantic web:
|
||||
|
||||
```python
|
||||
from semantica.semantic_extract import (
|
||||
TripleExtractor,
|
||||
TripletExtractor,
|
||||
RDFSerializer,
|
||||
TripleValidator
|
||||
TripletValidator
|
||||
)
|
||||
|
||||
text = """
|
||||
@@ -559,30 +559,30 @@ graph LR
|
||||
Einstein worked at Princeton University until his death in 1955.
|
||||
"""
|
||||
|
||||
# Extract RDF-style triples
|
||||
extractor = TripleExtractor(
|
||||
# Extract RDF-style triplets
|
||||
extractor = TripletExtractor(
|
||||
include_temporal=True, # Include time information
|
||||
include_provenance=True # Track source sentences
|
||||
)
|
||||
|
||||
triples = extractor.extract_triples(text)
|
||||
triplets = extractor.extract_triplets(text)
|
||||
|
||||
print("Extracted Triples (Subject-Predicate-Object):")
|
||||
for triple in triples:
|
||||
print(f" Subject: {triple['subject']}")
|
||||
print(f" Predicate: {triple['predicate']}")
|
||||
print(f" Object: {triple['object']}")
|
||||
if triple.get('temporal'):
|
||||
print(f" When: {triple['temporal']}")
|
||||
print("Extracted Triplets (Subject-Predicate-Object):")
|
||||
for triplet in triplets:
|
||||
print(f" Subject: {triplet['subject']}")
|
||||
print(f" Predicate: {triplet['predicate']}")
|
||||
print(f" Object: {triplet['object']}")
|
||||
if triplet.get('temporal'):
|
||||
print(f" When: {triplet['temporal']}")
|
||||
print()
|
||||
|
||||
validator = TripleValidator()
|
||||
validation = validator.validate(triples)
|
||||
print(f"Valid triples: {validation['valid_count']}/{len(triples)}")
|
||||
validator = TripletValidator()
|
||||
validation = validator.validate(triplets)
|
||||
print(f"Valid triplets: {validation['valid_count']}/{len(triplets)}")
|
||||
|
||||
serializer = RDFSerializer(format="turtle")
|
||||
turtle_output = serializer.serialize(
|
||||
triples,
|
||||
triplets,
|
||||
base_uri="https://example.org/knowledge/"
|
||||
)
|
||||
print("Turtle Output:")
|
||||
@@ -1220,7 +1220,7 @@ flowchart TD
|
||||
Build a knowledge base and query with GraphRAG:
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
from semantica.vector_store import VectorStore, store_vectors, search_vectors
|
||||
from semantica.semantic_extract import NamedEntityRecognizer
|
||||
from semantica.embeddings import embed_text
|
||||
@@ -1433,7 +1433,7 @@ flowchart TD
|
||||
Integrate with LLM providers for answer generation:
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
from semantica.semantic_extract import create_provider, OpenAIProvider
|
||||
from semantica.context import ContextRetriever
|
||||
from semantica.vector_store import VectorStore
|
||||
@@ -1694,55 +1694,6 @@ classDiagram
|
||||
print("Ontology saved to company_ontology.ttl")
|
||||
```
|
||||
|
||||
=== "Ontology Validation"
|
||||
Validate ontologies with symbolic reasoners:
|
||||
|
||||
```python
|
||||
from semantica.ontology import OntologyValidator, validate_ontology
|
||||
|
||||
# Load or create ontology
|
||||
ontology_file = "company_ontology.ttl"
|
||||
|
||||
# Method 1: Using the convenience function
|
||||
result = validate_ontology(ontology_file, method="default")
|
||||
print(f"Quick validation: {'Valid' if result['valid'] else 'Invalid'}")
|
||||
|
||||
# Method 2: Using OntologyValidator for more control
|
||||
validator = OntologyValidator(
|
||||
reasoner="hermit", # hermit, pellet, or auto
|
||||
check_consistency=True,
|
||||
check_satisfiability=True
|
||||
)
|
||||
|
||||
# Validate the ontology
|
||||
validation_result = validator.validate(ontology_file)
|
||||
|
||||
print(f"Validation Results:")
|
||||
print(f" Consistent: {'Yes' if validation_result.consistent else 'No'}")
|
||||
print(f" Satisfiable: {'Yes' if validation_result.satisfiable else 'No'}")
|
||||
|
||||
if validation_result.errors:
|
||||
print(f"Errors ({len(validation_result.errors)}):")
|
||||
for error in validation_result.errors:
|
||||
print(f" - {error}")
|
||||
|
||||
if validation_result.warnings:
|
||||
print(f"Warnings ({len(validation_result.warnings)}):")
|
||||
for warning in validation_result.warnings:
|
||||
print(f" - {warning}")
|
||||
|
||||
# Check specific constraints
|
||||
constraints = [
|
||||
"Every CEO must work for exactly one Company",
|
||||
"A Person cannot be their own manager"
|
||||
]
|
||||
|
||||
for constraint in constraints:
|
||||
is_valid = validator.check_constraint(constraint)
|
||||
status = "PASS" if is_valid else "FAIL"
|
||||
print(f" [{status}] {constraint}")
|
||||
```
|
||||
|
||||
=== "Competency Questions"
|
||||
Define and evaluate competency questions:
|
||||
|
||||
@@ -1851,197 +1802,8 @@ classDiagram
|
||||
|
||||
---
|
||||
|
||||
### 8. Quality Assurance
|
||||
|
||||
!!! abstract "Definition"
|
||||
**Quality Assurance** encompasses processes and metrics to ensure knowledge graph quality, including completeness, consistency, accuracy, and coverage validation.
|
||||
|
||||
**Quality Dimensions**:
|
||||
|
||||
| Dimension | Description | Metrics |
|
||||
| :--- | :--- | :--- |
|
||||
| **Completeness** | Percentage of entities with required properties | Property coverage, missing fields |
|
||||
| **Consistency** | Absence of contradictions | Conflict count, validation errors |
|
||||
| **Accuracy** | Correctness of extracted information | Precision, recall, F1-score |
|
||||
| **Coverage** | Breadth of domain coverage | Entity diversity, relationship types |
|
||||
| **Freshness** | How up-to-date the data is | Last update timestamp, staleness |
|
||||
|
||||
|
||||
**Practical Examples**:
|
||||
|
||||
=== "Quality Assessment"
|
||||
Assess the quality of your knowledge graph:
|
||||
|
||||
```python
|
||||
from semantica import (
|
||||
KGQualityAssessor,
|
||||
QualityMetrics,
|
||||
CompletenessMetrics,
|
||||
ConsistencyMetrics
|
||||
)
|
||||
|
||||
# Initialize quality assessor
|
||||
assessor = KGQualityAssessor()
|
||||
|
||||
# Run comprehensive quality assessment
|
||||
quality_report = assessor.assess(kg)
|
||||
|
||||
print("Knowledge Graph Quality Report")
|
||||
print(f"Overall Score: {quality_report['overall_score']:.1%}")
|
||||
|
||||
# Completeness analysis
|
||||
completeness = quality_report['completeness']
|
||||
print(f"Completeness: {completeness['score']:.1%}")
|
||||
print(f" Entities with all required fields: {completeness['complete_entities']}/{completeness['total_entities']}")
|
||||
print(f" Missing fields: {completeness['missing_fields']}")
|
||||
|
||||
# Consistency analysis
|
||||
consistency = quality_report['consistency']
|
||||
print(f"Consistency: {consistency['score']:.1%}")
|
||||
print(f" Conflicts detected: {consistency['conflict_count']}")
|
||||
print(f" Type mismatches: {consistency['type_mismatches']}")
|
||||
|
||||
# Coverage analysis
|
||||
coverage = quality_report['coverage']
|
||||
print(f"Coverage: {coverage['score']:.1%}")
|
||||
print(f" Entity types: {coverage['entity_type_count']}")
|
||||
print(f" Relationship types: {coverage['relationship_type_count']}")
|
||||
print(f" Orphaned entities: {coverage['orphaned_count']}")
|
||||
```
|
||||
|
||||
=== "Validation and Constraints"
|
||||
Validate your graph against rules and constraints:
|
||||
|
||||
```python
|
||||
from semantica import ValidationEngine, ConstraintValidator
|
||||
from semantica.kg import GraphValidator
|
||||
|
||||
# Initialize validation engine
|
||||
validator = ValidationEngine()
|
||||
graph_validator = GraphValidator()
|
||||
|
||||
# Define custom validation rules
|
||||
rules = [
|
||||
{
|
||||
"name": "entity_has_type",
|
||||
"description": "Every entity must have a type",
|
||||
"check": lambda e: "type" in e and e["type"]
|
||||
},
|
||||
{
|
||||
"name": "relationship_has_valid_endpoints",
|
||||
"description": "Relationships must reference existing entities",
|
||||
"check": lambda r, entities: r["source"] in entities and r["target"] in entities
|
||||
},
|
||||
{
|
||||
"name": "person_has_name",
|
||||
"description": "Person entities must have a name property",
|
||||
"check": lambda e: e.get("type") != "Person" or "name" in e.get("properties", {})
|
||||
}
|
||||
]
|
||||
|
||||
# Run validation with custom rules
|
||||
results = validator.validate(kg, rules=rules)
|
||||
|
||||
print("Validation Results:")
|
||||
for rule_name, result in results['rule_results'].items():
|
||||
status = "PASS" if result['passed'] else "FAIL"
|
||||
print(f"[{status}] {rule_name}")
|
||||
if not result['passed']:
|
||||
print(f" Failed: {len(result['violations'])} violations")
|
||||
for v in result['violations'][:3]:
|
||||
print(f" - {v['entity_id']}: {v['message']}")
|
||||
|
||||
# Validate graph structure
|
||||
graph_result = graph_validator.validate(kg)
|
||||
print(f"Graph Valid: {graph_result['valid']}")
|
||||
if graph_result['errors']:
|
||||
for error in graph_result['errors'][:3]:
|
||||
print(f" Error: {error}")
|
||||
|
||||
# Check cardinality constraints
|
||||
constraint_validator = ConstraintValidator()
|
||||
constraint_results = constraint_validator.validate(kg, [
|
||||
{"property": "CEO_OF", "max_cardinality": 1},
|
||||
{"property": "WORKS_FOR", "min_cardinality": 0, "max_cardinality": 3}
|
||||
])
|
||||
```
|
||||
|
||||
=== "Automated Fixes"
|
||||
Automatically fix common quality issues:
|
||||
|
||||
```python
|
||||
from semantica import AutomatedFixer, IssueTracker, KGQualityAssessor
|
||||
|
||||
# Track and find issues
|
||||
tracker = IssueTracker()
|
||||
issues = tracker.find_issues(kg)
|
||||
|
||||
print(f"Found {len(issues)} issues:")
|
||||
for issue in issues[:5]:
|
||||
print(f" [{issue['severity']}] {issue['type']}: {issue['message']}")
|
||||
|
||||
# Initialize fixer
|
||||
fixer = AutomatedFixer()
|
||||
|
||||
# Apply automated fixes
|
||||
fixed_kg, fix_report = fixer.fix(
|
||||
kg,
|
||||
fix_types=[
|
||||
"missing_entity_type",
|
||||
"orphaned_relationships",
|
||||
"duplicate_relationships",
|
||||
"empty_properties"
|
||||
],
|
||||
dry_run=False
|
||||
)
|
||||
|
||||
print(f"Applied {fix_report['fixes_applied']} fixes:")
|
||||
for fix_type, count in fix_report['by_type'].items():
|
||||
print(f" {fix_type}: {count}")
|
||||
|
||||
# Measure quality improvement
|
||||
assessor = KGQualityAssessor()
|
||||
quality_after = assessor.assess(fixed_kg)
|
||||
print(f"Quality after fixes: {quality_after['overall_score']:.1%}")
|
||||
```
|
||||
|
||||
=== "Quality Reporting"
|
||||
Generate detailed quality reports:
|
||||
|
||||
```python
|
||||
from semantica import QualityReporter, ImprovementSuggestions
|
||||
|
||||
# Initialize reporter
|
||||
reporter = QualityReporter()
|
||||
|
||||
# Generate HTML report
|
||||
reporter.generate_report(
|
||||
kg,
|
||||
output_path="quality_report.html",
|
||||
format="html",
|
||||
include_visualizations=True
|
||||
)
|
||||
|
||||
# Generate JSON report for programmatic use
|
||||
json_report = reporter.generate_report(kg, format="json")
|
||||
|
||||
print(f"Report generated with {len(json_report.get('sections', []))} sections")
|
||||
|
||||
# Get improvement suggestions
|
||||
suggestions = ImprovementSuggestions()
|
||||
recommendations = suggestions.analyze(kg)
|
||||
|
||||
print("Improvement Suggestions:")
|
||||
for rec in recommendations:
|
||||
print(f" Priority {rec['priority']}: {rec['suggestion']}")
|
||||
print(f" Impact: {rec['expected_improvement']}")
|
||||
print(f" Effort: {rec['effort_level']}")
|
||||
```
|
||||
|
||||
|
||||
**Related Modules**:
|
||||
- [`kg_qa` Module](reference/evals.md) - Quality assurance and evaluation
|
||||
- [`conflicts` Module](reference/conflicts.md) - Conflict detection
|
||||
|
||||
---
|
||||
|
||||
@@ -2524,24 +2286,25 @@ flowchart LR
|
||||
Find conflicts in your knowledge graph:
|
||||
|
||||
```python
|
||||
from semantica.kg import ConflictDetector
|
||||
from semantica.conflicts import ConflictAnalyzer, detect_conflicts
|
||||
from semantica.conflicts import ConflictAnalyzer, ConflictDetector
|
||||
|
||||
# Sample knowledge graph with conflicts
|
||||
kg = {
|
||||
"entities": [
|
||||
{
|
||||
"id": "e1",
|
||||
"text": "Apple Inc.",
|
||||
"id": "e1",
|
||||
"text": "Apple Inc.",
|
||||
"type": "Organization",
|
||||
"properties": {"founded": "1976", "employees": "160000"},
|
||||
"founded": "1976",
|
||||
"employees": "160000",
|
||||
"source": "wikipedia"
|
||||
},
|
||||
{
|
||||
"id": "e2",
|
||||
"text": "Apple Inc.",
|
||||
"id": "e1",
|
||||
"text": "Apple Inc.",
|
||||
"type": "Organization",
|
||||
"properties": {"founded": "1977", "employees": "164000"},
|
||||
"founded": "1977",
|
||||
"employees": "164000",
|
||||
"source": "bloomberg"
|
||||
},
|
||||
],
|
||||
@@ -2553,14 +2316,6 @@ flowchart LR
|
||||
]
|
||||
}
|
||||
|
||||
# Method 1: Using convenience function
|
||||
conflicts = detect_conflicts(
|
||||
kg["entities"],
|
||||
method="value",
|
||||
property_name="founded"
|
||||
)
|
||||
|
||||
# Method 2: Using ConflictDetector class
|
||||
detector = ConflictDetector()
|
||||
all_conflicts = detector.detect_value_conflicts(kg["entities"], "founded")
|
||||
|
||||
@@ -2569,17 +2324,17 @@ flowchart LR
|
||||
print(f" Type: {conflict.conflict_type.value}")
|
||||
print(f" Entity: {conflict.entity_id}")
|
||||
print(f" Property: {conflict.property_name}")
|
||||
print(f" Values: {[v['value'] for v in conflict.values]}")
|
||||
print(f" Values: {conflict.conflicting_values}")
|
||||
print(f" Sources: {conflict.sources}")
|
||||
|
||||
# Analyze conflicts
|
||||
analyzer = ConflictAnalyzer()
|
||||
analysis = analyzer.analyze(all_conflicts)
|
||||
analysis = analyzer.analyze_conflicts(all_conflicts)
|
||||
|
||||
print(f"Conflict Analysis:")
|
||||
print(f" Total conflicts: {analysis['total_conflicts']}")
|
||||
print(f" By type: {analysis['by_type']}")
|
||||
print(f" By severity: {analysis['by_severity']}")
|
||||
print(f" By type: {analysis.get('by_type', {}).get('counts')}")
|
||||
print(f" By severity: {analysis.get('by_severity', {}).get('counts')}")
|
||||
```
|
||||
|
||||
=== "Resolution Strategies"
|
||||
@@ -2588,7 +2343,6 @@ flowchart LR
|
||||
```python
|
||||
from semantica.conflicts import (
|
||||
ConflictResolver,
|
||||
ResolutionStrategy,
|
||||
Conflict,
|
||||
ConflictType
|
||||
)
|
||||
@@ -2598,95 +2352,76 @@ flowchart LR
|
||||
Conflict(
|
||||
conflict_id="c1",
|
||||
entity_id="e1",
|
||||
conflict_type=ConflictType.VALUE,
|
||||
conflict_type=ConflictType.VALUE_CONFLICT,
|
||||
property_name="founded",
|
||||
values=[
|
||||
{"value": "1976", "source": "wikipedia", "confidence": 0.95},
|
||||
{"value": "1976", "source": "sec_filing", "confidence": 0.99},
|
||||
{"value": "1977", "source": "news_article", "confidence": 0.70}
|
||||
conflicting_values=["1976", "1976", "1977"],
|
||||
sources=[
|
||||
{"document": "wikipedia", "confidence": 0.95},
|
||||
{"document": "sec_filing", "confidence": 0.99},
|
||||
{"document": "news_article", "confidence": 0.70},
|
||||
],
|
||||
sources=["wikipedia", "sec_filing", "news_article"]
|
||||
)
|
||||
]
|
||||
|
||||
# Strategy 1: Voting (most common value wins)
|
||||
resolver_voting = ConflictResolver(strategy=ResolutionStrategy.VOTING)
|
||||
resolved_voting = resolver_voting.resolve(conflicts)
|
||||
resolver = ConflictResolver()
|
||||
resolved_voting = resolver.resolve_conflicts(conflicts, strategy="voting")
|
||||
|
||||
print("Voting Resolution:")
|
||||
for r in resolved_voting:
|
||||
print(f" {r.property_name}: {r.resolved_value}")
|
||||
print(f" {r.conflict_id}: {r.resolved_value} (confidence: {r.confidence:.2f})")
|
||||
|
||||
# Strategy 2: Highest confidence
|
||||
resolver_conf = ConflictResolver(strategy=ResolutionStrategy.HIGHEST_CONFIDENCE)
|
||||
resolved_conf = resolver_conf.resolve(conflicts)
|
||||
resolved_conf = resolver.resolve_conflicts(conflicts, strategy="highest_confidence")
|
||||
|
||||
print("Highest Confidence Resolution:")
|
||||
for r in resolved_conf:
|
||||
print(f" {r.property_name}: {r.resolved_value} (confidence: {r.confidence:.2f})")
|
||||
print(f" {r.conflict_id}: {r.resolved_value} (confidence: {r.confidence:.2f})")
|
||||
|
||||
# Strategy 3: Source priority
|
||||
resolver_priority = ConflictResolver(
|
||||
strategy=ResolutionStrategy.SOURCE_PRIORITY,
|
||||
source_priority=["sec_filing", "wikipedia", "news_article"]
|
||||
)
|
||||
resolved_priority = resolver_priority.resolve(conflicts)
|
||||
# Strategy 3: Credibility weighted
|
||||
resolved_cred = resolver.resolve_conflicts(conflicts, strategy="credibility_weighted")
|
||||
|
||||
print("Source Priority Resolution:")
|
||||
for r in resolved_priority:
|
||||
print(f" {r.property_name}: {r.resolved_value} (source: {r.selected_source})")
|
||||
print("Credibility Weighted Resolution:")
|
||||
for r in resolved_cred:
|
||||
print(f" {r.conflict_id}: {r.resolved_value} (confidence: {r.confidence:.2f})")
|
||||
```
|
||||
|
||||
=== "Custom Resolution Rules"
|
||||
Define custom resolution rules per property:
|
||||
|
||||
```python
|
||||
from semantica.conflicts import (
|
||||
ConflictResolver,
|
||||
ResolutionStrategy,
|
||||
resolve_conflicts
|
||||
)
|
||||
from semantica.conflicts import ConflictResolver
|
||||
|
||||
# Define property-specific resolution rules
|
||||
resolution_config = {
|
||||
"founded": {
|
||||
"strategy": ResolutionStrategy.SOURCE_PRIORITY,
|
||||
"source_priority": ["official_records", "sec_filing", "wikipedia"]
|
||||
"strategy": "highest_confidence",
|
||||
},
|
||||
"revenue": {
|
||||
"strategy": ResolutionStrategy.MOST_RECENT,
|
||||
"strategy": "most_recent",
|
||||
},
|
||||
"employees": {
|
||||
"strategy": ResolutionStrategy.VOTING,
|
||||
"strategy": "voting",
|
||||
},
|
||||
"ceo": {
|
||||
"strategy": ResolutionStrategy.HIGHEST_CONFIDENCE,
|
||||
"strategy": "highest_confidence",
|
||||
}
|
||||
}
|
||||
|
||||
# Create resolver with custom config
|
||||
resolver = ConflictResolver(
|
||||
strategy=ResolutionStrategy.HIGHEST_CONFIDENCE,
|
||||
min_confidence=0.7
|
||||
)
|
||||
resolver = ConflictResolver()
|
||||
|
||||
# Resolve conflicts for each property
|
||||
resolved_values = {}
|
||||
for property_name, config in resolution_config.items():
|
||||
property_resolver = ConflictResolver(
|
||||
strategy=config["strategy"],
|
||||
source_priority=config.get("source_priority")
|
||||
)
|
||||
|
||||
# Get conflicts for this property
|
||||
property_conflicts = [c for c in conflicts if c.property_name == property_name]
|
||||
|
||||
if property_conflicts:
|
||||
results = property_resolver.resolve(property_conflicts)
|
||||
results = resolver.resolve_conflicts(property_conflicts, strategy=config["strategy"])
|
||||
for result in results:
|
||||
resolved_values[property_name] = {
|
||||
"value": result.resolved_value,
|
||||
"strategy": config["strategy"].value,
|
||||
"strategy": config["strategy"],
|
||||
"confidence": result.confidence
|
||||
}
|
||||
|
||||
@@ -2700,54 +2435,45 @@ flowchart LR
|
||||
|
||||
```python
|
||||
from semantica.conflicts import SourceTracker, SourceReference
|
||||
from datetime import datetime
|
||||
|
||||
# Initialize source tracker
|
||||
tracker = SourceTracker()
|
||||
|
||||
# Add entities from different sources
|
||||
tracker.add_source(SourceReference(
|
||||
entity_id="e1",
|
||||
property_name="founded",
|
||||
value="1976",
|
||||
source="wikipedia",
|
||||
timestamp="2024-01-15",
|
||||
confidence=0.95
|
||||
))
|
||||
tracker.track_property_source(
|
||||
"e1",
|
||||
"founded",
|
||||
"1976",
|
||||
SourceReference(document="wikipedia", confidence=0.95, timestamp=datetime(2024, 1, 15)),
|
||||
)
|
||||
tracker.track_property_source(
|
||||
"e1",
|
||||
"founded",
|
||||
"1976",
|
||||
SourceReference(document="sec_filing", confidence=0.99, timestamp=datetime(2024, 3, 1)),
|
||||
)
|
||||
tracker.track_property_source(
|
||||
"e1",
|
||||
"founded",
|
||||
"1977",
|
||||
SourceReference(document="news_article", confidence=0.70, timestamp=datetime(2024, 2, 20)),
|
||||
)
|
||||
|
||||
tracker.add_source(SourceReference(
|
||||
entity_id="e1",
|
||||
property_name="founded",
|
||||
value="1976",
|
||||
source="sec_filing",
|
||||
timestamp="2024-03-01",
|
||||
confidence=0.99
|
||||
))
|
||||
|
||||
tracker.add_source(SourceReference(
|
||||
entity_id="e1",
|
||||
property_name="founded",
|
||||
value="1977",
|
||||
source="news_article",
|
||||
timestamp="2024-02-20",
|
||||
confidence=0.70
|
||||
))
|
||||
|
||||
# Get all sources for an entity
|
||||
sources = tracker.get_sources("e1")
|
||||
sources = tracker.get_entity_sources("e1")
|
||||
|
||||
print("Entity Sources:")
|
||||
for source in sources:
|
||||
print(f" Source: {source.source}")
|
||||
print(f" Property: {source.property_name}")
|
||||
print(f" Value: {source.value}")
|
||||
print(f" Source: {source.document}")
|
||||
print(f" Confidence: {source.confidence}")
|
||||
|
||||
# Get property-specific sources
|
||||
property_sources = tracker.get_property_sources("e1", "founded")
|
||||
|
||||
print("Property Sources for 'founded':")
|
||||
for ps in property_sources:
|
||||
print(f" {ps.value} from {ps.source} ({ps.timestamp})")
|
||||
if property_sources:
|
||||
print(f" Value: {property_sources.value}")
|
||||
for ps in property_sources.sources:
|
||||
print(f" {ps.document} ({ps.timestamp})")
|
||||
```
|
||||
|
||||
=== "Conflict Investigation"
|
||||
@@ -2756,7 +2482,6 @@ flowchart LR
|
||||
```python
|
||||
from semantica.conflicts import (
|
||||
InvestigationGuideGenerator,
|
||||
ConflictDetector,
|
||||
Conflict,
|
||||
ConflictType
|
||||
)
|
||||
@@ -2768,14 +2493,14 @@ flowchart LR
|
||||
conflict = Conflict(
|
||||
conflict_id="c1",
|
||||
entity_id="e1",
|
||||
conflict_type=ConflictType.VALUE,
|
||||
conflict_type=ConflictType.VALUE_CONFLICT,
|
||||
property_name="founded",
|
||||
values=[
|
||||
{"value": "1976", "source": "wikipedia", "confidence": 0.95},
|
||||
{"value": "1977", "source": "news", "confidence": 0.70}
|
||||
conflicting_values=["1976", "1977"],
|
||||
sources=[
|
||||
{"document": "wikipedia", "confidence": 0.95},
|
||||
{"document": "news", "confidence": 0.70},
|
||||
],
|
||||
sources=["wikipedia", "news"],
|
||||
severity=0.6
|
||||
severity="medium"
|
||||
)
|
||||
|
||||
# Generate investigation guide
|
||||
@@ -2784,25 +2509,14 @@ flowchart LR
|
||||
print("Conflict Investigation Guide:")
|
||||
print(f" Conflict ID: {guide.conflict_id}")
|
||||
print(f" Title: {guide.title}")
|
||||
print(f" Summary: {guide.summary}")
|
||||
print(f" Summary: {guide.conflict_summary}")
|
||||
|
||||
print("Investigation Steps:")
|
||||
for i, step in enumerate(guide.steps, 1):
|
||||
for i, step in enumerate(guide.investigation_steps, 1):
|
||||
print(f" {i}. {step.description}")
|
||||
print(f" Priority: {step.priority}")
|
||||
if step.expected_outcome:
|
||||
print(f" Expected: {step.expected_outcome}")
|
||||
|
||||
print("Checklist:")
|
||||
for item in guide.checklist:
|
||||
print(f" [ ] {item}")
|
||||
|
||||
# Get context for the conflict
|
||||
context = guide_generator.get_conflict_context(conflict)
|
||||
print(f"Context:")
|
||||
print(f" Entity: {context.get('entity_text', 'Unknown')}")
|
||||
print(f" Property: {context.get('property', 'Unknown')}")
|
||||
print(f" Value count: {len(conflict.values)}")
|
||||
print(f" Value count: {len(conflict.conflicting_values)}")
|
||||
|
||||
```
|
||||
|
||||
@@ -2869,7 +2583,7 @@ import os
|
||||
api_key = os.getenv("OPENAI_API_KEY")
|
||||
|
||||
# Good: Use config files
|
||||
from semantica import Config
|
||||
from semantica.core import Config
|
||||
config = Config.from_file("config.yaml")
|
||||
semantica = Semantica(config=config)
|
||||
```
|
||||
@@ -2894,7 +2608,7 @@ semantica = Semantica(config=config)
|
||||
- Gracefully handle API failures
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
+1
-10
@@ -220,7 +220,7 @@ Deep dive into advanced features, customization, and complex workflows.
|
||||
|
||||
**Difficulty**: Advanced
|
||||
|
||||
[Open Notebook](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/advanced/04_Conflict_Resolution_Strategies.ipynb)
|
||||
[Open Notebook](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/introduction/17_Conflict_Detection_and_Resolution.ipynb)
|
||||
|
||||
- :material-export: **Multi-Format Export**
|
||||
---
|
||||
@@ -242,15 +242,6 @@ Deep dive into advanced features, customization, and complex workflows.
|
||||
|
||||
[Open Notebook](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/advanced/06_Multi_Source_Data_Integration.ipynb)
|
||||
|
||||
- :material-pipe: **Pipeline Orchestration**
|
||||
---
|
||||
Building robust, automated data processing pipelines.
|
||||
|
||||
**Topics**: Workflows, Automation, Error Handling
|
||||
|
||||
**Difficulty**: Advanced
|
||||
|
||||
[Open Notebook](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/advanced/07_Pipeline_Orchestration.ipynb)
|
||||
|
||||
- :material-brain: **Reasoning and Inference**
|
||||
---
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ graph TB
|
||||
|
||||
D --> D1[Entity Extractor]
|
||||
D --> D2[Relationship Extractor]
|
||||
D --> D3[Triple Extractor]
|
||||
D --> D3[Triplet Extractor]
|
||||
|
||||
G --> G1[Graph Validator]
|
||||
G --> G2[Graph Analyzer]
|
||||
@@ -60,7 +60,7 @@ text → Tokenization → NER → Entity Linking → Entity Validation
|
||||
**Components:**
|
||||
- Named Entity Recognition (NER)
|
||||
- Relationship Extraction
|
||||
- Triple Extraction
|
||||
- Triplet Extraction
|
||||
- Coreference Resolution
|
||||
|
||||
### 4. Normalization Layer
|
||||
|
||||
+12
-10
@@ -48,7 +48,7 @@ Real-world examples and use cases for Semantica.
|
||||
Build a knowledge graph from a single document.
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
|
||||
@@ -71,7 +71,7 @@ print(f"Relationships: {len(kg['relationships'])}")
|
||||
Extract entities from text using Named Entity Recognition.
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
text = "Apple Inc. is a technology company founded by Steve Jobs."
|
||||
@@ -88,7 +88,7 @@ for entity in entities["entities"]:
|
||||
Combine data from multiple sources into a unified knowledge graph.
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
sources = [
|
||||
@@ -111,14 +111,16 @@ print(f"Unified graph: {len(result['knowledge_graph']['entities'])} entities")
|
||||
Resolve conflicts in data from multiple sources.
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.conflicts import ConflictResolver
|
||||
from semantica.core import Semantica
|
||||
from semantica.conflicts import ConflictDetector, ConflictResolver
|
||||
|
||||
semantica = Semantica()
|
||||
result = semantica.build_knowledge_base(["source1.pdf", "source2.pdf"])
|
||||
|
||||
# Detect and resolve conflicts
|
||||
conflicts = semantica.kg.detect_conflicts(result["knowledge_graph"])
|
||||
kg = result["knowledge_graph"]
|
||||
detector = ConflictDetector()
|
||||
conflicts = detector.detect_conflicts(kg["entities"])
|
||||
resolver = ConflictResolver(default_strategy="voting")
|
||||
resolved = resolver.resolve_conflicts(conflicts)
|
||||
```
|
||||
@@ -130,7 +132,7 @@ resolved = resolver.resolve_conflicts(conflicts)
|
||||
Use custom configuration for specific use cases.
|
||||
|
||||
```python
|
||||
from semantica import Semantica, Config
|
||||
from semantica.core import Semantica, Config
|
||||
|
||||
config = Config(
|
||||
embeddings=True,
|
||||
@@ -150,7 +152,7 @@ result = semantica.build_knowledge_base(["document.pdf"])
|
||||
Build knowledge graph incrementally.
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
|
||||
@@ -236,7 +238,7 @@ Process data streams in real-time.
|
||||
|
||||
```python
|
||||
from semantica.ingest import StreamIngestor
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
stream_ingestor = StreamIngestor(stream_uri="kafka://localhost:9092/topic")
|
||||
@@ -257,7 +259,7 @@ for batch in stream_ingestor.stream(batch_size=100):
|
||||
Process large datasets efficiently with batching.
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
sources = [f"data/doc_{i}.pdf" for i in range(1000)]
|
||||
|
||||
+2
-2
@@ -70,7 +70,7 @@ A structured representation where entities (nodes) are connected by relationship
|
||||
### How do I build a knowledge graph?
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
result = semantica.build_knowledge_base(["document.pdf"])
|
||||
@@ -102,7 +102,7 @@ Yes! Semantica supports PDF, DOCX, HTML, JSON, CSV, and many other formats.
|
||||
### How do I extract entities from text?
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
result = semantica.semantic_extract.extract_entities("Your text")
|
||||
|
||||
@@ -72,7 +72,7 @@ Before installing Semantica, ensure you have:
|
||||
|
||||
```python
|
||||
import semantica
|
||||
print(semantica.version)
|
||||
print(semantica.__version__)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
+6
-6
@@ -85,10 +85,10 @@ A comprehensive reference of terms and concepts used in Semantica.
|
||||
## K
|
||||
|
||||
**Knowledge Graph (KG)**
|
||||
: A structured representation of entities and their relationships, typically stored as a graph with nodes representing entities and edges representing relationships.
|
||||
: A structured representation of knowledge using entities (nodes) and relationships (edges). KGs enable reasoning, querying, and semantic analysis of data.
|
||||
|
||||
**Knowledge Graph Quality Assurance (KG QA)**
|
||||
: The process of ensuring knowledge graph quality through completeness validation, consistency checking, and conflict detection.
|
||||
**Knowledge Graph Analytics**
|
||||
: The application of graph algorithms (e.g., centrality, community detection) to gain insights from the structure of a knowledge graph.
|
||||
|
||||
---
|
||||
|
||||
@@ -147,7 +147,7 @@ A comprehensive reference of terms and concepts used in Semantica.
|
||||
: A technique that enhances LLM responses by retrieving relevant information from a knowledge base before generating an answer.
|
||||
|
||||
**RDF (Resource Description Framework)**
|
||||
: A W3C standard for representing information about resources in the form of subject-predicate-object triples.
|
||||
: A W3C standard for representing information about resources in the form of subject-predicate-object triplets.
|
||||
|
||||
**Reasoning**
|
||||
: The process of deriving new knowledge from existing facts using logical rules and inference.
|
||||
@@ -178,11 +178,11 @@ A comprehensive reference of terms and concepts used in Semantica.
|
||||
**Temporal Graph**
|
||||
: A knowledge graph that tracks changes over time, allowing queries about the state of the graph at specific time points.
|
||||
|
||||
**Triple**
|
||||
**Triplet**
|
||||
: A basic unit of knowledge in RDF, consisting of a subject, predicate, and object (e.g., `<Apple_Inc> <founded_by> <Steve_Jobs>`).
|
||||
|
||||
**Triplet Store**
|
||||
: A database designed specifically for storing and querying RDF triples.
|
||||
: A database designed specifically for storing and querying RDF triplets.
|
||||
|
||||
---
|
||||
|
||||
|
||||
+2
-2
@@ -335,7 +335,7 @@ Transform raw text into structured semantic knowledge with state-of-the-art NLP
|
||||
- **Relationship Extraction**: Identify semantic, temporal, and causal relationships
|
||||
- **Event Detection**: Detect and classify events (acquisitions, partnerships, announcements)
|
||||
- **Coreference Resolution**: Resolve pronouns and entity mentions across documents
|
||||
- **Triple Extraction**: Generate RDF triples for knowledge graph construction
|
||||
- **Triplet Extraction**: Generate RDF triplets for knowledge graph construction
|
||||
|
||||
### 3. 🕸️ Knowledge Graph Construction
|
||||
|
||||
@@ -417,7 +417,7 @@ Power GraphRAG applications with:
|
||||
## 🚦 Quick Example
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
# Initialize
|
||||
core = Semantica()
|
||||
|
||||
@@ -99,7 +99,7 @@ Additional resources, tutorials, and advanced learning materials for Semantica.
|
||||
### Common Operations
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
semantica = Semantica()
|
||||
|
||||
# Build Knowledge Graph
|
||||
|
||||
+61
-57
@@ -142,7 +142,7 @@ for doc in parsed_docs:
|
||||
- `SlidingWindowChunker` — Fixed-size sliding window chunking
|
||||
- `TableChunker` — Table-specific chunking
|
||||
- `EntityAwareChunker` — Entity boundary-preserving chunker
|
||||
- `RelationAwareChunker` — Triple-preserving chunker
|
||||
- `RelationAwareChunker` — Triplet-preserving chunker
|
||||
- `GraphBasedChunker` — Graph structure-based chunker
|
||||
- `OntologyAwareChunker` — Ontology concept-based chunker
|
||||
- `HierarchicalChunker` — Multi-level hierarchical chunker
|
||||
@@ -290,12 +290,12 @@ for rel in relationships[:5]:
|
||||
|
||||
- `GraphBuilder` — Construct knowledge graphs
|
||||
- `GraphAnalyzer` — Analyze graph structure and properties
|
||||
- `GraphValidator` — Validate graph quality and consistency
|
||||
- `EntityResolver` — Resolve entity conflicts and duplicates
|
||||
- `ConflictDetector` — Detect conflicting information
|
||||
- `CentralityCalculator` — Calculate node importance metrics
|
||||
- `CommunityDetector` — Detect communities in graphs
|
||||
- `CommunityDetector` — Detect community structure
|
||||
- `ConnectivityAnalyzer` — Analyze graph connectivity
|
||||
- `SeedManager` — Manage seed data for KG initialization
|
||||
- `TemporalQuery` — Query temporal knowledge graphs
|
||||
- `Deduplicator` — Remove duplicate entities/relationships
|
||||
|
||||
@@ -339,7 +339,7 @@ print(f"Density: {metrics['density']:.3f}")
|
||||
**Components:**
|
||||
|
||||
- `OntologyGenerator` — Generate ontologies from knowledge graphs
|
||||
- `OntologyValidator` — Validate ontology structure
|
||||
- `OntologyValidator` — Validate ontologies
|
||||
- `OWLGenerator` — Generate OWL format ontologies
|
||||
- `PropertyGenerator` — Generate ontology properties
|
||||
- `ClassInferrer` — Infer ontology classes
|
||||
@@ -349,13 +349,24 @@ print(f"Density: {metrics['density']:.3f}")
|
||||
**Quick Example:**
|
||||
|
||||
```python
|
||||
from semantica.ontology import OntologyGenerator
|
||||
from semantica.ontology import OntologyEngine
|
||||
|
||||
generator = OntologyGenerator(base_uri="https://example.org/ontology/")
|
||||
ontology = generator.generate_from_graph(kg)
|
||||
# Initialize engine
|
||||
engine = OntologyEngine(base_uri="https://example.org/ontology/")
|
||||
|
||||
# Generate ontology from data
|
||||
ontology = engine.from_data({
|
||||
"entities": [...],
|
||||
"relationships": [...]
|
||||
})
|
||||
|
||||
# Validate ontology
|
||||
result = engine.validate(ontology)
|
||||
if result.valid:
|
||||
print("Ontology is valid!")
|
||||
|
||||
# Export to OWL
|
||||
owl_content = generator.export_owl(ontology, format="turtle")
|
||||
owl_content = engine.to_owl(ontology, format="turtle")
|
||||
print(f"Generated {len(owl_content)} lines of OWL")
|
||||
```
|
||||
|
||||
@@ -412,7 +423,7 @@ print(f"Inferred {len(new_facts)} new facts")
|
||||
|
||||
## Storage Layer
|
||||
|
||||
These modules handle persistence and retrieval of vectors, graphs, and triples.
|
||||
These modules handle persistence and retrieval of vectors, graphs, and triplets.
|
||||
|
||||
---
|
||||
|
||||
@@ -439,7 +450,7 @@ These modules handle persistence and retrieval of vectors, graphs, and triples.
|
||||
- `AudioEmbedder` — Generate audio embeddings
|
||||
- `MultimodalEmbedder` — Combine multiple modalities
|
||||
- `EmbeddingOptimizer` — Optimize embedding quality
|
||||
- `ProviderAdapters` — Support for OpenAI, Cohere, etc.
|
||||
- `ProviderStores` — Support for OpenAI, Cohere, etc.
|
||||
|
||||
**Quick Example:**
|
||||
|
||||
@@ -479,8 +490,8 @@ print(f"Similarity: {similarity:.3f}")
|
||||
**Components:**
|
||||
|
||||
- `VectorStore` — Main vector store interface
|
||||
- `FAISSAdapter` — FAISS integration
|
||||
- `WeaviateAdapter` — Weaviate integration
|
||||
- `FAISSStore` — FAISS integration
|
||||
- `WeaviateStore` — Weaviate integration
|
||||
- `HybridSearch` — Combine vector and keyword search
|
||||
- `VectorRetriever` — Retrieve relevant vectors
|
||||
|
||||
@@ -523,8 +534,8 @@ results = hybrid_search.search(
|
||||
**Components:**
|
||||
|
||||
- `GraphStore` — Main graph store interface
|
||||
- `Neo4jAdapter` — Neo4j database integration
|
||||
- `FalkorDBAdapter` — FalkorDB (Redis-based) integration
|
||||
- `Neo4jStore` — Neo4j database integration
|
||||
- `FalkorDBStore` — FalkorDB (Redis-based) integration
|
||||
- `NodeManager` — Node CRUD operations
|
||||
- `RelationshipManager` — Relationship CRUD operations
|
||||
- `QueryEngine` — Cypher query execution
|
||||
@@ -569,23 +580,22 @@ results = store.execute_query("MATCH (p:Person) RETURN p.name")
|
||||
|
||||
**Key Features:**
|
||||
|
||||
- Multi-backend support (Blazegraph, Jena, RDF4J, Virtuoso)
|
||||
- Multi-backend support (Blazegraph, Jena, RDF4J)
|
||||
- CRUD operations for RDF triplets
|
||||
- SPARQL query execution and optimization
|
||||
- Bulk data loading with progress tracking
|
||||
- Query caching and optimization
|
||||
- Transaction support
|
||||
- Store adapter pattern
|
||||
- Store backend pattern
|
||||
|
||||
**Components:**
|
||||
|
||||
- `TripletManager` — Main triplet store management coordinator
|
||||
- `TripletStore` — Main triplet store interface
|
||||
- `QueryEngine` — SPARQL query execution and optimization
|
||||
- `BulkLoader` — High-volume data loading with progress tracking
|
||||
- `BlazegraphAdapter` — Blazegraph integration
|
||||
- `JenaAdapter` — Apache Jena integration
|
||||
- `RDF4JAdapter` — Eclipse RDF4J integration
|
||||
- `VirtuosoAdapter` — Virtuoso RDF store integration
|
||||
- `BlazegraphStore` — Blazegraph integration
|
||||
- `JenaStore` — Apache Jena integration
|
||||
- `RDF4JStore` — Eclipse RDF4J integration
|
||||
- `QueryPlan` — Query execution plan dataclass
|
||||
- `LoadProgress` — Bulk loading progress tracking
|
||||
|
||||
@@ -600,20 +610,19 @@ results = store.execute_query("MATCH (p:Person) RETURN p.name")
|
||||
**Quick Example:**
|
||||
|
||||
```python
|
||||
from semantica.triplet_store import TripletManager, execute_query
|
||||
from semantica.triplet_store import TripletStore
|
||||
|
||||
manager = TripletManager()
|
||||
store = manager.register_store("main", "blazegraph", "http://localhost:9999/blazegraph")
|
||||
store = TripletStore(backend="blazegraph", endpoint="http://localhost:9999/blazegraph")
|
||||
|
||||
# Add triple
|
||||
result = manager.add_triple({
|
||||
# Add triplet
|
||||
result = store.add_triplet({
|
||||
"subject": "http://example.org/Alice",
|
||||
"predicate": "http://example.org/knows",
|
||||
"object": "http://example.org/Bob"
|
||||
}, store_id="main")
|
||||
})
|
||||
|
||||
# Execute SPARQL
|
||||
query_result = execute_query("SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10", store)
|
||||
query_result = store.execute_query("SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10")
|
||||
```
|
||||
|
||||
**API Reference**: [Triplet Store Module](reference/triplet_store.md)
|
||||
@@ -634,6 +643,8 @@ These modules ensure data quality, handle duplicates, and resolve conflicts.
|
||||
**Key Features:**
|
||||
|
||||
- Multiple similarity methods (exact, Levenshtein, Jaro-Winkler, cosine, embedding)
|
||||
- **Advanced String Matching**: Jaro-Winkler by default for better company/person name resolution
|
||||
- **Smart Property Handling**: Neutral scoring for disjoint properties to prevent false negatives
|
||||
- Duplicate detection with confidence scoring
|
||||
- Entity merging with configurable strategies
|
||||
- Cluster-based batch deduplication
|
||||
@@ -653,16 +664,16 @@ These modules ensure data quality, handle duplicates, and resolve conflicts.
|
||||
|
||||
| Strategy | Description |
|
||||
| :--- | :--- |
|
||||
| `keep_first` | Preserve first entity, merge others |
|
||||
| `keep_last` | Preserve last entity, merge others |
|
||||
| `keep_most_complete` | Preserve entity with most properties |
|
||||
| `keep_highest_confidence` | Preserve entity with highest confidence |
|
||||
| `merge_all` | Combine all properties and relationships |
|
||||
| `"keep_first"` | Preserve first entity, merge others |
|
||||
| `"keep_last"` | Preserve last entity, merge others |
|
||||
| `"keep_most_complete"` | Preserve entity with most properties |
|
||||
| `"keep_highest_confidence"` | Preserve entity with highest confidence |
|
||||
| `"merge_all"` | Combine all properties and relationships |
|
||||
|
||||
**Quick Example:**
|
||||
|
||||
```python
|
||||
from semantica.deduplication import DuplicateDetector, EntityMerger, MergeStrategy
|
||||
from semantica.deduplication import DuplicateDetector, EntityMerger
|
||||
|
||||
# Detect duplicates
|
||||
detector = DuplicateDetector(similarity_threshold=0.8)
|
||||
@@ -672,7 +683,7 @@ duplicate_groups = detector.detect_duplicate_groups(entities)
|
||||
merger = EntityMerger(preserve_provenance=True)
|
||||
merge_operations = merger.merge_duplicates(
|
||||
entities,
|
||||
strategy=MergeStrategy.KEEP_MOST_COMPLETE
|
||||
strategy="keep_most_complete"
|
||||
)
|
||||
|
||||
merged_entities = [op.merged_entity for op in merge_operations]
|
||||
@@ -716,18 +727,13 @@ print(f"Reduced from {len(entities)} to {len(merged_entities)} entities")
|
||||
**Quick Example:**
|
||||
|
||||
```python
|
||||
from semantica.conflicts import detect_and_resolve, ConflictDetector
|
||||
from semantica.conflicts import ConflictDetector, ConflictResolver
|
||||
|
||||
# Using convenience function
|
||||
conflicts, results = detect_and_resolve(
|
||||
entities,
|
||||
property_name="name",
|
||||
resolution_strategy="voting"
|
||||
)
|
||||
|
||||
# Using classes directly
|
||||
detector = ConflictDetector()
|
||||
conflicts = detector.detect_value_conflicts(entities, "name")
|
||||
|
||||
resolver = ConflictResolver()
|
||||
results = resolver.resolve_conflicts(conflicts, strategy="voting")
|
||||
```
|
||||
|
||||
---
|
||||
@@ -790,12 +796,12 @@ These modules provide context engineering for agents and foundation data managem
|
||||
|
||||
**Components:**
|
||||
|
||||
- `ContextGraphBuilder` — Builds context graphs from various sources
|
||||
- `ContextGraph` — In-memory context graph store and builder methods
|
||||
- `ContextNode` — Context graph node data structure
|
||||
- `ContextEdge` — Context graph edge data structure
|
||||
- `AgentMemory` — Manages persistent agent memory with RAG
|
||||
- `MemoryItem` — Memory item data structure
|
||||
- `EntityLinker` — Links entities across sources with URIs
|
||||
- `EntityLinker` — Links entities across sources with URI assignment
|
||||
- `ContextRetriever` — Retrieves relevant context from multiple sources
|
||||
|
||||
**Algorithms:**
|
||||
@@ -810,19 +816,19 @@ These modules provide context engineering for agents and foundation data managem
|
||||
**Quick Example:**
|
||||
|
||||
```python
|
||||
from semantica.context import build_context, ContextGraphBuilder, AgentMemory
|
||||
from semantica.context import ContextGraph, AgentMemory
|
||||
from semantica.context.methods import build_context_graph
|
||||
|
||||
# Using convenience function
|
||||
result = build_context(
|
||||
result = build_context_graph(
|
||||
entities=entities,
|
||||
relationships=relationships,
|
||||
vector_store=vs,
|
||||
knowledge_graph=kg
|
||||
method="entities_relationships"
|
||||
)
|
||||
|
||||
# Using classes directly
|
||||
builder = ContextGraphBuilder()
|
||||
graph = builder.build_from_entities_and_relationships(entities, relationships)
|
||||
graph = ContextGraph()
|
||||
graph_data = graph.build_from_entities_and_relationships(entities, relationships)
|
||||
|
||||
memory = AgentMemory(vector_store=vs, knowledge_graph=kg)
|
||||
memory_id = memory.store("User asked about Python", metadata={"type": "conversation"})
|
||||
@@ -926,7 +932,6 @@ CSVExporter().export(kg, "output.csv")
|
||||
|
||||
- Interactive graph visualization
|
||||
- Embedding visualization (t-SNE, PCA, UMAP)
|
||||
- Quality metrics visualization
|
||||
- Temporal data visualization
|
||||
- Ontology visualization
|
||||
- Multiple output formats (HTML, PNG, SVG)
|
||||
@@ -936,7 +941,6 @@ CSVExporter().export(kg, "output.csv")
|
||||
|
||||
- `KGVisualizer` — Visualize knowledge graphs
|
||||
- `EmbeddingVisualizer` — Visualize embeddings (t-SNE, PCA, UMAP)
|
||||
- `QualityVisualizer` — Visualize quality metrics
|
||||
- `AnalyticsVisualizer` — Visualize graph analytics
|
||||
- `TemporalVisualizer` — Visualize temporal data
|
||||
- `OntologyVisualizer` — Visualize ontology structure
|
||||
@@ -1009,7 +1013,7 @@ result = pipeline.execute(sources=["data/"], parallel=True)
|
||||
### Pattern 1: Complete Knowledge Graph Pipeline
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
result = semantica.build_knowledge_base(
|
||||
@@ -1055,7 +1059,7 @@ deduplicated = [op.merged_entity for op in merge_operations]
|
||||
### Pattern 3: GraphRAG with Hybrid Search
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
from semantica.vector_store import VectorStore, HybridSearch
|
||||
from semantica.context import AgentMemory
|
||||
|
||||
@@ -1113,7 +1117,7 @@ new_facts = inference_engine.forward_chain(kg, rule_manager)
|
||||
| **Embeddings** | `semantica.embeddings` | `EmbeddingGenerator` | Vector generation |
|
||||
| **Vector Store** | `semantica.vector_store` | `VectorStore` | Vector storage |
|
||||
| **Graph Store** | `semantica.graph_store` | `GraphStore` | Graph database |
|
||||
| **Triplet Store** | `semantica.triplet_store` | `TripletManager` | RDF storage |
|
||||
| **Triplet Store** | `semantica.triplet_store` | `TripletStore` | RDF storage |
|
||||
| **Deduplication** | `semantica.deduplication` | `DuplicateDetector` | Duplicate removal |
|
||||
| **Conflicts** | `semantica.conflicts` | `ConflictDetector` | Conflict resolution |
|
||||
| **Context** | `semantica.context` | `AgentMemory` | Agent context |
|
||||
|
||||
+7
-7
@@ -37,7 +37,7 @@ See the [Installation Guide](installation.md) for detailed instructions.
|
||||
Let's build a knowledge graph from a document:
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
# Initialize Semantica
|
||||
semantica = Semantica()
|
||||
@@ -117,7 +117,7 @@ Extracted Relationships:
|
||||
Combine data from multiple sources:
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
|
||||
@@ -149,7 +149,7 @@ print(f"Sources processed: {len(result['metadata']['sources'])}")
|
||||
Visualize the knowledge graph you created:
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
from semantica.visualization import KGVisualizer
|
||||
|
||||
semantica = Semantica()
|
||||
@@ -171,7 +171,7 @@ Open `graph.html` in your browser to see an interactive visualization.
|
||||
Export your knowledge graph in various formats:
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
from semantica.export import export_rdf, export_json, export_csv, export_owl
|
||||
|
||||
semantica = Semantica()
|
||||
@@ -194,7 +194,7 @@ print("Exported knowledge graph to multiple formats")
|
||||
### Pattern 1: Process Text Directly
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
|
||||
@@ -205,7 +205,7 @@ result = semantica.process_document(text)
|
||||
### Pattern 2: Custom Configuration
|
||||
|
||||
```python
|
||||
from semantica import Semantica, Config
|
||||
from semantica.core import Semantica, Config
|
||||
|
||||
# Create custom configuration
|
||||
config = Config(
|
||||
@@ -222,7 +222,7 @@ result = semantica.build_knowledge_base(["document.pdf"])
|
||||
### Pattern 3: Incremental Building
|
||||
|
||||
```python
|
||||
from semantica import Semantica
|
||||
from semantica.core import Semantica
|
||||
|
||||
semantica = Semantica()
|
||||
|
||||
|
||||
@@ -255,22 +255,20 @@ conflicts:
|
||||
|
||||
```python
|
||||
from semantica.conflicts import ConflictDetector, ConflictResolver
|
||||
from semantica.ingest import Ingestor
|
||||
from semantica.core import Semantica
|
||||
|
||||
# 1. Ingest from multiple sources
|
||||
ingestor = Ingestor()
|
||||
data1 = ingestor.ingest("source1.pdf")
|
||||
data2 = ingestor.ingest("source2.html")
|
||||
|
||||
# 2. Combine entities (assuming same IDs)
|
||||
combined_entities = data1.entities + data2.entities
|
||||
# 1. Build knowledge base from multiple sources
|
||||
semantica = Semantica()
|
||||
result = semantica.build_knowledge_base(["source1.pdf", "source2.html"])
|
||||
kg = result["knowledge_graph"]
|
||||
entities = kg.get("entities", [])
|
||||
|
||||
# 3. Detect conflicts
|
||||
detector = ConflictDetector()
|
||||
conflicts = detector.detect_value_conflicts(combined_entities, "revenue")
|
||||
conflicts = detector.detect_value_conflicts(entities, "revenue")
|
||||
|
||||
# 4. Resolve conflicts
|
||||
resolver = ConflictResolver()
|
||||
resolver = ConflictResolver(default_strategy="credibility_weighted")
|
||||
resolutions = resolver.resolve_conflicts(
|
||||
conflicts,
|
||||
strategy="credibility_weighted"
|
||||
@@ -322,5 +320,4 @@ tracker.set_source_credibility("bad_source", 0.1)
|
||||
|
||||
## Cookbook
|
||||
|
||||
- [Conflict Detection](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/introduction/17_Conflict_Detection.ipynb)
|
||||
- [Conflict Resolution Strategies](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/advanced/04_Conflict_Resolution_Strategies.ipynb)
|
||||
- [Conflict Detection & Resolution](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/introduction/17_Conflict_Detection_and_Resolution.ipynb)
|
||||
|
||||
@@ -184,8 +184,8 @@ graph.add_nodes([
|
||||
# Add Edges
|
||||
graph.add_edges([
|
||||
{
|
||||
"source": "FastAPI",
|
||||
"target": "Python",
|
||||
"source_id": "FastAPI",
|
||||
"target_id": "Python",
|
||||
"type": "WRITTEN_IN"
|
||||
}
|
||||
])
|
||||
|
||||
@@ -57,11 +57,19 @@
|
||||
|
||||
### Similarity Calculation
|
||||
- **Levenshtein Distance**: Edit distance for string difference
|
||||
- **Jaro-Winkler**: String similarity with prefix weighting (good for names)
|
||||
- **Jaro-Winkler**: String similarity with prefix weighting (Default for strings, optimized for entity names)
|
||||
- **Cosine Similarity**: Vector similarity for embeddings
|
||||
- **Jaccard Similarity**: Set overlap for properties/relationships
|
||||
- **Property Matching**: Handles disjoint properties with neutral scoring (0.5) to prevent false negatives
|
||||
- **Multi-factor Aggregation**: Weighted sum of multiple metrics
|
||||
|
||||
### Default Configuration
|
||||
The deduplication module uses the following default weights to prioritize name matching while considering other factors:
|
||||
- **String Similarity**: 0.6 (Primary factor, using Jaro-Winkler)
|
||||
- **Property Similarity**: 0.2 (Handles missing values neutrally)
|
||||
- **Relationship Similarity**: 0.2
|
||||
- **Embedding Similarity**: 0.0 (Optional, enabled if embeddings are present)
|
||||
|
||||
### Duplicate Detection
|
||||
- **Pairwise Comparison**: O(n²) comparison (for small sets)
|
||||
- **Blocking/Indexing**: Reduce search space for large sets
|
||||
@@ -146,26 +154,27 @@ EntityMerger(
|
||||
| `validate_merge_quality(merge_operation)` | Validate quality of a merge operation | `Dict[str, Any]` |
|
||||
|
||||
**Strategies:**
|
||||
- `KEEP_FIRST`: Keep the first entity encountered
|
||||
- `KEEP_LAST`: Keep the last entity encountered
|
||||
- `KEEP_MOST_COMPLETE`: Keep entity with most properties/relationships
|
||||
- `KEEP_HIGHEST_CONFIDENCE`: Keep entity with highest confidence score
|
||||
- `MERGE_ALL`: Create new entity combining all info
|
||||
- `"keep_first"`: Keep the first entity encountered
|
||||
- `"keep_last"`: Keep the last entity encountered
|
||||
- `"keep_most_complete"`: Keep entity with most properties/relationships
|
||||
- `"keep_highest_confidence"`: Keep entity with highest confidence score
|
||||
- `"merge_all"`: Create new entity combining all info
|
||||
|
||||
**Example:**
|
||||
|
||||
```python
|
||||
from semantica.deduplication import EntityMerger, MergeStrategy
|
||||
from semantica.deduplication import EntityMerger
|
||||
|
||||
merger = EntityMerger(preserve_provenance=True)
|
||||
|
||||
# Merge with specific strategy
|
||||
operations = merger.merge_duplicates(
|
||||
entities,
|
||||
strategy=MergeStrategy.KEEP_MOST_COMPLETE
|
||||
strategy="keep_most_complete"
|
||||
)
|
||||
|
||||
for op in operations:
|
||||
print(f"Merged {len(op.source_entities)} entities into 1")
|
||||
print(f"Conflicts: {len(op.merge_result.conflicts)}")
|
||||
# Get merge history
|
||||
history = merger.get_merge_history()
|
||||
```
|
||||
|
||||
### SimilarityCalculator
|
||||
@@ -676,13 +685,14 @@ Configuration is loaded in the following priority order:
|
||||
### Ingestion Pipeline
|
||||
|
||||
```python
|
||||
from semantica.ingest import Ingestor
|
||||
from semantica.core import Semantica
|
||||
from semantica.deduplication import DuplicateDetector, EntityMerger, MergeStrategy
|
||||
from semantica.kg import KnowledgeGraph
|
||||
|
||||
# 1. Ingest
|
||||
ingestor = Ingestor()
|
||||
raw_entities = ingestor.ingest_batch(files)
|
||||
# 1. Build knowledge base
|
||||
semantica = Semantica()
|
||||
result = semantica.build_knowledge_base(files)
|
||||
kg = result["knowledge_graph"]
|
||||
raw_entities = kg.get("entities", [])
|
||||
|
||||
# 2. Deduplicate
|
||||
detector = DuplicateDetector(similarity_threshold=0.85)
|
||||
@@ -696,10 +706,6 @@ merge_operations = merger.merge_duplicates(
|
||||
|
||||
# Extract merged entities
|
||||
merged_entities = [op.merged_entity for op in merge_operations]
|
||||
|
||||
# 3. Load to KG
|
||||
kg = KnowledgeGraph()
|
||||
kg.add_entities(merged_entities)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -48,7 +48,7 @@ The **Embeddings Module** provides a unified interface for generating vector rep
|
||||
## 🏗️ Architecture Components
|
||||
|
||||
### EmbeddingGenerator (The Orchestrator)
|
||||
The main entry point for generating embeddings. It manages the active model and routes requests to the appropriate provider adapter.
|
||||
The main entry point for generating embeddings. It manages the active model and routes requests to the appropriate provider store.
|
||||
|
||||
#### **Constructor Parameters**
|
||||
* `method` (Default: `"fastembed"`): The embedding provider to use (e.g., `"sentence_transformers"`, `"openai"`, `"fastembed"`).
|
||||
|
||||
@@ -169,11 +169,11 @@ Graph analytics and algorithms.
|
||||
- `degree_centrality(labels, rel_type, direction, **options)` - Calculate degree centrality
|
||||
- `connected_components(labels, **options)` - Find connected components
|
||||
|
||||
### Adapter Classes
|
||||
### Store Backends
|
||||
|
||||
#### Neo4jAdapter
|
||||
#### Neo4jStore
|
||||
|
||||
Enterprise-grade Neo4j backend adapter.
|
||||
Enterprise-grade Neo4j backend store.
|
||||
|
||||
**Features:**
|
||||
- Bolt protocol support
|
||||
@@ -188,9 +188,9 @@ Enterprise-grade Neo4j backend adapter.
|
||||
- `Neo4jTransaction` - Transaction wrapper
|
||||
|
||||
|
||||
#### FalkorDBAdapter
|
||||
#### FalkorDBStore
|
||||
|
||||
High-performance Redis-based FalkorDB backend adapter.
|
||||
High-performance Redis-based FalkorDB backend store.
|
||||
|
||||
**Features:**
|
||||
- Sparse matrix representation
|
||||
|
||||
@@ -186,9 +186,8 @@ print(f"New nodes since 2020: {len(diff.nodes)}")
|
||||
1. **Clean Data First**: Use `EntityResolver` to resolve similar entities and prevent "entity explosion" (too many duplicate nodes).
|
||||
2. **Use Provenance**: Always track sources (`track_history=True`) to debug where bad data came from.
|
||||
3. **Temporal Granularity**: Choose the right granularity (Day vs Second) to balance performance and precision.
|
||||
4. **Validate**: Run `GraphValidator` after building to ensure structural integrity.
|
||||
5. **Deduplication**: Use `semantica.deduplication` module for advanced deduplication needs.
|
||||
6. **Conflict Resolution**: Use `semantica.conflicts` module for conflict detection and resolution.
|
||||
4. **Deduplication**: Use `semantica.deduplication` module for advanced deduplication needs.
|
||||
5. **Conflict Resolution**: Use `semantica.conflicts` module for conflict detection and resolution.
|
||||
|
||||
---
|
||||
|
||||
@@ -204,7 +203,6 @@ print(f"New nodes since 2020: {len(diff.nodes)}")
|
||||
- [Building Knowledge Graphs](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/introduction/07_Building_Knowledge_Graphs.ipynb)
|
||||
- [Your First Knowledge Graph](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/introduction/08_Your_First_Knowledge_Graph.ipynb)
|
||||
- [Graph Analytics](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/introduction/10_Graph_Analytics.ipynb)
|
||||
- [Graph Quality](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/introduction/11_Graph_Quality.ipynb)
|
||||
- [Advanced Graph Analytics](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/advanced/02_Advanced_Graph_Analytics.ipynb)
|
||||
- [Temporal Knowledge Graphs](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/advanced/10_Temporal_Knowledge_Graphs.ipynb)
|
||||
- [Deduplication Module](deduplication.md) - Advanced deduplication
|
||||
|
||||
@@ -20,18 +20,6 @@
|
||||
|
||||
Infer classes, properties, and hierarchies from entity patterns
|
||||
|
||||
- :material-check-decagram:{ .lg .middle } **Validation**
|
||||
|
||||
---
|
||||
|
||||
Symbolic reasoning (HermiT/Pellet) for consistency checking
|
||||
|
||||
- :material-recycle:{ .lg .middle } **Reuse Management**
|
||||
|
||||
---
|
||||
|
||||
Import and align with standard ontologies (FOAF, Schema.org)
|
||||
|
||||
- :material-chart-bar:{ .lg .middle } **Evaluation**
|
||||
|
||||
---
|
||||
@@ -50,7 +38,6 @@
|
||||
- **Schema Design**: When defining the structure of your Knowledge Graph
|
||||
- **Data Modeling**: To formalize domain concepts and relationships
|
||||
- **Interoperability**: To ensure your data follows standard semantic web practices
|
||||
- **Validation**: To enforce constraints on your data
|
||||
|
||||
---
|
||||
|
||||
@@ -62,18 +49,12 @@
|
||||
3. **Definition-to-Types**: Map definitions to OWL types (`owl:Class`, `owl:ObjectProperty`).
|
||||
4. **Hierarchy Generation**: Build taxonomy trees using transitive closure and cycle detection.
|
||||
5. **TTL Generation**: Serialize to Turtle format using `rdflib`.
|
||||
6. **Symbolic Validation**: Run reasoner to check for logical inconsistencies.
|
||||
|
||||
### Inference Algorithms
|
||||
- **Class Inference**: Clustering entities by type and attribute similarity.
|
||||
- **Property Inference**: Determining domain/range based on connected entity types.
|
||||
- **Hierarchy Inference**: `A is_a B` detection based on subset relationships.
|
||||
|
||||
### Validation
|
||||
- **Symbolic Reasoning**: Uses HermiT or Pellet to check satisfiability.
|
||||
- **Constraint Checking**: Validates cardinality, domain, and range constraints.
|
||||
- **Hallucination Detection**: LLM-based verification of generated concepts.
|
||||
|
||||
---
|
||||
|
||||
## Main Classes
|
||||
@@ -88,9 +69,9 @@ Unified orchestration for generation, inference, validation, OWL export, and eva
|
||||
|--------|-------------|
|
||||
| `from_data(data, **options)` | Generate ontology from structured data |
|
||||
| `from_text(text, provider=None, model=None, **options)` | LLM-based generation from text |
|
||||
| `validate(ontology, **options)` | Validate ontology consistency |
|
||||
| `infer_classes(entities, **options)` | Infer classes from entities |
|
||||
| `infer_properties(entities, relationships, classes, **options)` | Infer properties |
|
||||
| `validate(ontology, **options)` | Validate ontology (returns `ValidationResult`) |
|
||||
| `evaluate(ontology, **options)` | Evaluate ontology quality |
|
||||
| `to_owl(ontology, format="turtle")` | Export OWL/RDF serialization |
|
||||
| `export_owl(ontology, path, format="turtle")` | Save OWL to file |
|
||||
@@ -105,7 +86,6 @@ engine = OntologyEngine(base_uri="https://example.org/ontology/")
|
||||
data = {"entities": entities, "relationships": relationships}
|
||||
ontology = engine.from_data(data, name="MyOntology")
|
||||
|
||||
result = engine.validate(ontology, reasoner="auto")
|
||||
turtle = engine.to_owl(ontology, format="turtle")
|
||||
```
|
||||
|
||||
@@ -162,16 +142,6 @@ ontology = generator.generate_ontology({
|
||||
print(ontology.serialize(format="turtle"))
|
||||
```
|
||||
|
||||
### OntologyValidator
|
||||
|
||||
Validates ontology consistency.
|
||||
|
||||
**Methods:**
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `validate_ontology(ontology)` | Run symbolic reasoner and structure checks |
|
||||
|
||||
### OntologyEvaluator
|
||||
|
||||
Scores ontology quality.
|
||||
@@ -225,7 +195,6 @@ turtle = engine.to_owl(ontology, format="turtle")
|
||||
|
||||
```bash
|
||||
export ONTOLOGY_BASE_URI="http://my-org.com/ontology/"
|
||||
export ONTOLOGY_REASONER="hermit"
|
||||
export ONTOLOGY_STRICT_MODE=true
|
||||
```
|
||||
|
||||
@@ -237,10 +206,6 @@ ontology:
|
||||
generation:
|
||||
min_class_size: 5
|
||||
infer_hierarchy: true
|
||||
|
||||
validation:
|
||||
reasoner: hermit
|
||||
timeout: 60
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -381,6 +381,3 @@ result = engine.execute_pipeline(pipeline, data={"path": "document.pdf"})
|
||||
- [Split Module](split.md) - Common processing step
|
||||
- [Vector Store Module](vector_store.md) - Common sink step
|
||||
|
||||
## Cookbook
|
||||
|
||||
- [Pipeline Orchestration](https://github.com/Hawksight-AI/semantica/blob/main/cookbook/advanced/07_Pipeline_Orchestration.ipynb)
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
### SPARQL Reasoning
|
||||
- **Query Rewriting**: Modifying queries to include inferred patterns.
|
||||
- **Property Paths**: Handling transitive relationships (`foaf:knows+`).
|
||||
- **Materialization**: Pre-computing inferred triples for fast read performance.
|
||||
- **Materialization**: Pre-computing inferred triplets for fast read performance.
|
||||
|
||||
### Abductive Reasoning
|
||||
- **Hypothesis Generation**: Finding rules where the conclusion matches the observation.
|
||||
@@ -128,7 +128,7 @@ SPARQL-based reasoner for RDF graphs.
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `expand_query(query)` | Rewrite query with inference |
|
||||
| `infer_results(result)` | Add inferred triples to result |
|
||||
| `infer_results(result)` | Add inferred triplets to result |
|
||||
|
||||
### AbductiveReasoner
|
||||
|
||||
@@ -221,14 +221,14 @@ rules = [
|
||||
|
||||
# 2. Load Graph
|
||||
kg = KnowledgeGraph()
|
||||
facts = kg.get_all_triples()
|
||||
facts = kg.get_all_triplets()
|
||||
|
||||
# 3. Run Inference
|
||||
engine = InferenceEngine()
|
||||
inferred_triples = engine.infer(facts, rules)
|
||||
inferred_triplets = engine.infer(facts, rules)
|
||||
|
||||
# 4. Update Graph
|
||||
kg.add_triples(inferred_triples)
|
||||
kg.add_triplets(inferred_triplets)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Semantic Extract
|
||||
|
||||
> **Advanced information extraction system for Entities, Relations, Events, and Triples.**
|
||||
> **Advanced information extraction system for Entities, Relations, Events, and Triplets.**
|
||||
|
||||
---
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
|
||||
Resolve pronouns ("he", "it") to their entity references
|
||||
|
||||
- :material-share-variant:{ .lg .middle } **Triple Extraction**
|
||||
- :material-share-variant:{ .lg .middle } **Triplet Extraction**
|
||||
|
||||
---
|
||||
|
||||
Extract Subject-Predicate-Object triples for Knowledge Graphs
|
||||
|
||||
- :material-robot:{ .lg .middle } **LLM Enhancement**
|
||||
Extract Subject-Predicate-Object triplets for Knowledge Graphs
|
||||
|
||||
- :material-robot:{ .lg .middle } **LLM Extraction**
|
||||
|
||||
---
|
||||
|
||||
Use LLMs to improve extraction quality and handle complex schemas
|
||||
@@ -77,7 +77,7 @@
|
||||
- **Clustering**: Grouping mentions that refer to the same real-world entity.
|
||||
- **Pronoun Resolution**: Mapping pronouns to the most likely antecedent.
|
||||
|
||||
### Triple Extraction
|
||||
### Triplet Extraction
|
||||
- **OpenIE**: Open Information Extraction for arbitrary relation strings.
|
||||
- **Schema-Based**: Mapping extracted relations to a predefined ontology.
|
||||
- **Reification**: Handling complex relations (time, location) by creating event nodes.
|
||||
@@ -276,9 +276,9 @@ detector = EventDetector(
|
||||
events = detector.detect_events("SpaceX launched Starship on March 14, 2024.")
|
||||
```
|
||||
|
||||
### TripleExtractor
|
||||
### TripletExtractor
|
||||
|
||||
Extracts RDF triples (Subject-Predicate-Object).
|
||||
Extracts RDF triplets (Subject-Predicate-Object).
|
||||
|
||||
**Parameters:**
|
||||
|
||||
@@ -292,19 +292,19 @@ Extracts RDF triples (Subject-Predicate-Object).
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `extract_triples(text)` | Get (S, P, O) tuples |
|
||||
| `extract_triplets(text)` | Get (S, P, O) tuples |
|
||||
|
||||
**Example:**
|
||||
|
||||
```python
|
||||
from semantica.semantic_extract import TripleExtractor
|
||||
from semantica.semantic_extract import TripletExtractor
|
||||
|
||||
extractor = TripleExtractor(
|
||||
extractor = TripletExtractor(
|
||||
include_temporal=True,
|
||||
include_provenance=True
|
||||
)
|
||||
triples = extractor.extract_triples("Steve Jobs founded Apple in 1976.")
|
||||
# [Triple(subject="Steve Jobs", predicate="founded", object="Apple", temporal="1976")]
|
||||
triplets = extractor.extract_triplets("Steve Jobs founded Apple in 1976.")
|
||||
# [Triplet(subject="Steve Jobs", predicate="founded", object="Apple", temporal="1976")]
|
||||
```
|
||||
|
||||
### SemanticNetworkExtractor
|
||||
@@ -340,9 +340,9 @@ print(f"Nodes: {len(network.nodes)}")
|
||||
print(f"Edges: {len(network.edges)}")
|
||||
```
|
||||
|
||||
### LLMEnhancer
|
||||
### LLMExtraction
|
||||
|
||||
Enhances extraction results using Large Language Models.
|
||||
LLM-based extraction and enhancement. (Alias: `LLMEnhancer`)
|
||||
|
||||
**Parameters:**
|
||||
|
||||
@@ -355,16 +355,17 @@ Enhances extraction results using Large Language Models.
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `enhance_extractions(extractions, text)` | Enhance generic extractions |
|
||||
| `enhance_entities(text, entities)` | Improve entity accuracy and details |
|
||||
| `enhance_relations(text, relations)` | Improve relation detection |
|
||||
|
||||
**Example:**
|
||||
|
||||
```python
|
||||
from semantica.semantic_extract import LLMEnhancer
|
||||
from semantica.semantic_extract import LLMExtraction
|
||||
|
||||
enhancer = LLMEnhancer(provider="openai", model="gpt-4")
|
||||
enhanced_entities = enhancer.enhance_entities(text, entities)
|
||||
extractor = LLMExtraction(provider="openai", model="gpt-4")
|
||||
enhanced_entities = extractor.enhance_entities(text, entities)
|
||||
```
|
||||
|
||||
---
|
||||
@@ -375,7 +376,7 @@ enhanced_entities = enhancer.enhance_entities(text, entities)
|
||||
from semantica.semantic_extract import (
|
||||
NamedEntityRecognizer,
|
||||
RelationExtractor,
|
||||
TripleExtractor,
|
||||
TripletExtractor,
|
||||
EventDetector,
|
||||
CoreferenceResolver,
|
||||
SemanticNetworkExtractor
|
||||
@@ -395,9 +396,9 @@ resolved = coref.resolve(text)
|
||||
rel_extractor = RelationExtractor(confidence_threshold=0.6)
|
||||
relations = rel_extractor.extract_relations(text, entities=entities)
|
||||
|
||||
# Extract triples for KG
|
||||
triple_extractor = TripleExtractor(include_temporal=True)
|
||||
triples = triple_extractor.extract_triples(text)
|
||||
# Extract triplets for KG
|
||||
triplet_extractor = TripletExtractor(include_temporal=True)
|
||||
triplets = triplet_extractor.extract_triplets(text)
|
||||
|
||||
# Detect events
|
||||
event_detector = EventDetector(extract_time=True)
|
||||
@@ -409,7 +410,7 @@ network = network_extractor.extract(text)
|
||||
|
||||
print(f"Entities: {len(entities)}")
|
||||
print(f"Relations: {len(relations)}")
|
||||
print(f"Triples: {len(triples)}")
|
||||
print(f"Triplets: {len(triplets)}")
|
||||
print(f"Events: {len(events)}")
|
||||
print(f"Network Nodes: {len(network.nodes)}")
|
||||
```
|
||||
@@ -448,21 +449,21 @@ semantic_extract:
|
||||
### KG Population Pipeline
|
||||
|
||||
```python
|
||||
from semantica.semantic_extract import NamedEntityRecognizer, RelationExtractor, TripleExtractor
|
||||
from semantica.semantic_extract import NamedEntityRecognizer, RelationExtractor, TripletExtractor
|
||||
from semantica.kg import GraphBuilder
|
||||
|
||||
# 1. Extract
|
||||
text = "Google was founded by Larry Page and Sergey Brin."
|
||||
ner = NamedEntityRecognizer()
|
||||
entities = ner.extract_entities(text)
|
||||
triple_extractor = TripleExtractor()
|
||||
triples = triple_extractor.extract_triples(text)
|
||||
triplet_extractor = TripletExtractor()
|
||||
triplets = triplet_extractor.extract_triplets(text)
|
||||
|
||||
# 2. Populate KG using GraphBuilder
|
||||
builder = GraphBuilder()
|
||||
sources = [{
|
||||
"entities": entities,
|
||||
"relationships": [{"source": t.subject, "target": t.object, "type": t.predicate} for t in triples]
|
||||
"relationships": [{"source": t.subject, "target": t.object, "type": t.predicate} for t in triplets]
|
||||
}]
|
||||
kg = builder.build(sources)
|
||||
```
|
||||
|
||||
@@ -80,8 +80,8 @@
|
||||
- NER-based entity extraction (spaCy, LLM)
|
||||
- Entity span tracking
|
||||
- Boundary preservation (no entity splitting)
|
||||
- **Triple Preservation**:
|
||||
- Graph-based triple integrity checking
|
||||
- **Triplet Preservation**:
|
||||
- Graph-based triplet integrity checking
|
||||
- Subject-predicate-object span tracking
|
||||
- Relationship boundary preservation
|
||||
- **Graph Centrality Analysis**:
|
||||
@@ -278,15 +278,15 @@ for chunk in chunks:
|
||||
|
||||
### RelationAwareChunker
|
||||
|
||||
Preserve relationship triples during chunking.
|
||||
Preserve relationship triplets during chunking.
|
||||
|
||||
**Methods:**
|
||||
|
||||
| Method | Description | Algorithm |
|
||||
|--------|-------------|-----------|
|
||||
| `chunk(text, relationships)` | Chunk preserving triples | Triple span tracking |
|
||||
| `chunk(text, relationships)` | Chunk preserving triplets | Triplet span tracking |
|
||||
| `extract_relationships(text)` | Extract relationships | Relation extraction |
|
||||
| `validate_triple_integrity(chunk, relationships)` | Validate triples | Integrity checking |
|
||||
| `validate_triplet_integrity(chunk, relationships)` | Validate triplets | Integrity checking |
|
||||
|
||||
**Example:**
|
||||
|
||||
@@ -301,7 +301,7 @@ relationships = rel_extractor.extract(text)
|
||||
# Chunk preserving relationships
|
||||
chunker = RelationAwareChunker(
|
||||
chunk_size=1000,
|
||||
preserve_triples=True
|
||||
preserve_triplets=True
|
||||
)
|
||||
|
||||
chunks = chunker.chunk(text, relationships=relationships)
|
||||
@@ -697,7 +697,7 @@ split:
|
||||
min_entity_gap: 50
|
||||
|
||||
relation_aware:
|
||||
preserve_triples: true
|
||||
preserve_triplets: true
|
||||
relation_extraction_method: llm
|
||||
|
||||
graph_based:
|
||||
@@ -728,7 +728,7 @@ split:
|
||||
| **sentence** | Coherent chunks | Respects sentences | Variable size |
|
||||
| **semantic_transformer** | Topic coherence | Semantic boundaries | Slower, needs embeddings |
|
||||
| **entity_aware** | GraphRAG | Preserves entities | Requires NER |
|
||||
| **relation_aware** | KG extraction | Preserves triples | Requires relation extraction |
|
||||
| **relation_aware** | KG extraction | Preserves triplets | Requires relation extraction |
|
||||
| **graph_based** | Graph analysis | Graph-aware | Requires graph construction |
|
||||
| **hierarchical** | Large documents | Multi-level | More complex |
|
||||
| **structural** | Formatted docs | Respects structure | Needs structure |
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user