diff --git a/PR_DESCRIPTION.md b/PR_DESCRIPTION.md new file mode 100644 index 00000000..156b7fa0 --- /dev/null +++ b/PR_DESCRIPTION.md @@ -0,0 +1,36 @@ +# PR Description: Advanced Ontology Extraction & Notebook Fixes + +## 🚀 Summary +This PR revamps the `12_Unstructured_to_Ontology.ipynb` cookbook to resolve critical `TypeError` issues and significantly enhances the educational value of the ontology extraction guide. It also includes documentation updates and minor fixes across the context engineering module. + +## 🐛 Fixes & Improvements + +### 1. Fix: `TypeError: 'Entity' object is not subscriptable` +- **Issue**: The original notebook attempted to access `Entity` and `Relation` objects using dictionary syntax (e.g., `e['text']`), causing runtime errors because these are implemented as Python `dataclasses`. +- **Resolution**: Updated all access patterns to use dot notation (e.g., `e.text`) and added explicit `to_dict()` conversion logic before passing data to `OntologyGenerator`. + +### 2. Feature: Enhanced Ontology Pipeline Guide +- **Classical NLP Pipeline**: detailed breakdown of using `NERExtractor` and `RelationExtractor` with proper object handling. +- **Generative AI Pipeline**: Added a robust example using `LLMOntologyGenerator` for direct schema generation from text. +- **Visualization**: Integrated `OntologyVisualizer` to compare outputs from both pipelines side-by-side. +- **Export**: Added steps to export the generated ontology to OWL/Turtle format (`.ttl`). + +### 3. Documentation & Cleanup +- **`10_Temporal_Knowledge_Graphs.ipynb`**: Cleaned up dependencies (removed Docker setup in favor of `pip install semantica`). +- **`docs/reference/context.md`**: Fixed duplicate entries and added documentation for the production Graph Store. +- **`semantica/graph_store/graph_store.py`**: Fixed a `NameError` (missing `Tuple` import). + +## 🛠️ Key Changes +- `cookbook/advanced/12_Unstructured_to_Ontology.ipynb`: **Complete Rewrite** +- `cookbook/advanced/10_Temporal_Knowledge_Graphs.ipynb`: **Updated** +- `docs/reference/context.md`: **Updated** +- `semantica/graph_store/graph_store.py`: **Fixed** + +## ✅ Verification +- Validated that `NERExtractor` returns `Entity` objects and they are correctly processed. +- Verified that `OntologyGenerator` receives correctly formatted dictionaries. +- Ensured the notebook runs end-to-end without syntax errors. + +## 📦 Dependencies +- No new external dependencies. +- Relies on existing `semantica` package structure. diff --git a/cookbook/advanced/Advanced_Triplet_Store.ipynb b/cookbook/advanced/Advanced_Triplet_Store.ipynb deleted file mode 100644 index e00a4f1c..00000000 --- a/cookbook/advanced/Advanced_Triplet_Store.ipynb +++ /dev/null @@ -1,173 +0,0 @@ -{ - "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 -} diff --git a/cookbook/introduction/20_Triplet_Store.ipynb b/cookbook/introduction/20_Triplet_Store.ipynb index 4390d648..350fcaa3 100644 --- a/cookbook/introduction/20_Triplet_Store.ipynb +++ b/cookbook/introduction/20_Triplet_Store.ipynb @@ -223,7 +223,7 @@ "source": [ "## Next Steps\n", "\n", - "Check out the **Advanced Triplet Store** guide in the `cookbook/advanced` folder for more complex operations like bulk loading optimization, transactions, and advanced SPARQL features." + "Check out the **Advanced Triplet Store** guide in the `cookbook/advanced` folder ([13_Advanced_Triplet_Store.ipynb](../advanced/13_Advanced_Triplet_Store.ipynb)) for more complex operations like bulk loading optimization, transactions, and advanced SPARQL features." ] } ],