Skip to content

somul18/RDF_Project_v1

Repository files navigation

🌐 RDF 1.1 Package & Multi-Agent Semantic Pipeline

A fully W3C-compliant Python RDF 1.1 engine coupled with a FastAPI backend, a premium glassmorphic developer UI, and a collaborative Multi-Agent extraction pipeline powered by Gemini 2.5.


🚀 Key Features

  • W3C RDF 1.1 Compliant Engine: Full abstract syntax support for IRIs, Blank Nodes, and Literals. Handles N-Triples and N-Quads parsing and serialization with Unicode and escape sequence support.
  • Graph Isomorphism: Fast, optimized graph and dataset isomorphism checks using color-refinement hash partitioning and backtrack pruning.
  • Pydantic Domain Model: Rich domain objects (RDFGraph, RDFDataset, RDFTriple, RDFQuad) with automated validation and prefix-expansion capabilities.
  • Fluent Builder API: Highly intuitive, chainable graph construction for human-readable triples:
    graph.person("Marie_Curie") \
         .type("Scientist") \
         .born_in("Warsaw") \
         .birth_year(1867)
  • Multi-Agent Collaborative Pipeline: Collaborating AI agents process unstructured text to output verified semantic graphs:
    1. Extractor Agent: Extracts structured entities and relations from raw text using Gemini.
    2. RDF Builder Agent: Maps raw relationships to standardized ontologies (e.g., foaf, schema, xsd).
    3. Validator Agent: Programmatically checks for syntactic issues, duplicate triples, and namespace completeness.
  • FastAPI & Dev Demo UI: Beautiful, dark-themed, glassmorphic UI allowing developers to run unstructured text through the agent workflow and view Turtle outputs in real-time.

🛠️ Tech Stack

  • Core: Python 3.13+, RDFLib, Pydantic v2
  • Agent Orchestration: Gemini API, Google GenAI SDK
  • API & Server: FastAPI, Uvicorn
  • Testing: Pytest, HTTPX (async client testing)
  • Frontend: Vanilla HTML5, CSS3 (Glassmorphism), Vanilla JavaScript

📂 Project Structure

RDF_Project_v1/
├── entrypoint/
│   ├── __init__.py
│   └── server.py          # FastAPI endpoints & UI server
├── src/
│   ├── agents/            # Multi-Agent pipeline (Gemini extraction/mapping)
│   ├── app/               # Main domain models and mapping services
│   ├── rdf/               # Namespace configurations (FOAF, OWL, etc.)
│   └── rdf11/             # W3C abstract syntax and isomorphism engine
├── UIs/
│   └── index.html         # Premium Developer UI
├── tests/                 # Unit & integration test suite
└── .gitignore             # Safe environment and cache exclusions

⚙️ Getting Started

1. Prerequisites

Ensure you have Python 3.10+ installed.

2. Configure Environment

Create a .env file in the root directory (this is automatically ignored by Git):

GEMINI_API_KEY=your_gemini_api_key_here

3. Run the FastAPI Server & Demo UI

Start the local server with the following command:

PYTHONPATH=src:. uvicorn entrypoint.server:app --reload --port 8000

Then navigate to http://localhost:8000/ in your web browser.

4. Running Tests

Run the comprehensive test suite (34 passing tests) in verbose mode:

PYTHONPATH=src:. pytest -v tests/

🤖 Multi-Agent Tool-Use Workflow

graph TD
    A[Unstructured Input Text] --> B[Root Agent]
    B -->|1. Extract Entities| C[Entity Extractor Agent]
    B -->|2. Extract Relations| D[Relation Extractor Agent]
    B -->|3. Build Graph via Tool Calls| E[RDF Builder Agent]
    E -->|Calls Tools| F[(Graph Toolbox)]
    B -->|4. Run Syntactic Validation| G[Validator Agent]
    G -->|Returns Report| H[Final Verified RDF Graph / Turtle]
Loading

Exposing the Backend as Tools

Agents do not directly manipulate the graph. Instead, they interact with the Python backend via the Graph Toolbox, which exposes the following operations as local Python functions/tools:

  • create_graph(graph_id)
  • bind_namespace(graph_id, prefix, uri)
  • add_type(graph_id, subject, type_node)
  • add_literal(graph_id, subject, predicate, value, datatype, language)
  • add_triple(graph_id, subject, predicate, object_val)

Flow Example:

  • Input Text: "Marie Curie was born in Warsaw in 1867."
  • Output Graph (Turtle):
    @prefix ex: <http://example.org/> .
    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
    @prefix schema1: <http://schema.org/> .
    
    ex:Marie_Curie a foaf:Person ;
        schema1:birthDate 1867 ;
        schema1:birthPlace ex:Warsaw .
    
    ex:Warsaw a schema1:Place .

About

Python RDF 1.1 engine with Pydantic v2 domain models, a collaborative Multi-Agent semantic pipeline powered by Gemini 2.5, and a FastAPI server with a glassmorphic developer UI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors