Skip to main content

SchemaExtractor: A Python library with a multi-agent architecture for extracting and analyzing schemas from knowledge graphs.

Project description

Schema Extractor

A python library for extracting and analyzing schema from knowledge graphs represented in turtle representation using multi-autonomous agents.

Features

  • Extract schema components from TTL files
  • Provide technical and semantic analysis
  • Merge insights using different strategies
  • Multiple output formats (text/JSON)
  • Command-line interface
  • Example script for quick start

Installation

Install this package via :

pip install SchemaExtractor

Or get the newest development version via:

pip install git+https://github.com/sensein/SchemaExtractor.git

Important

Copy the default configuration file and update the OPEN ROUTER API key. The rest can be used default.

# Copy and customize config
cp src/configuration/config.yaml my_config.yaml 

Configuration

The library uses a YAML configuration file to manage settings for all agents. You have two options:

Use Configuration:

  • Create your own YAML file with the same structure
  • Pass it using the --config option
  • Allows customization of all agent settings

Example Configuration Structure:

openrouter:
  base_url: "https://openrouter.ai/api/v1"
  api_key: "your-api-key"
  headers:
    HTTP-Referer: "https://brainkb.org"
    X-Title: "Schema Extractor MultiAutonomous Agents"

base_config:
  temperature: 0.7
  top_p: 0.9
  presence_penalty: 0.0
  frequency_penalty: 0.0

agent_configs:
  executor:
    name: "SPARQLExecutorAgent"
    system_message: "..."
    model: "openai/gpt-4o-2024-11-20"
    temperature: 0.5
  prompt:
    name: "PromptAgent"
    system_message: "..."
    model: "openai/gpt-4o-2024-11-20"
    temperature: 0.7
  merger:
    name: "MergerAgent"
    system_message: "..."
    model: "openai/gpt-4o-2024-11-20"
    temperature: 0.6

Usage

1. Example Script (Quick Start)

python experiment/example.py --config my_config.yaml


python experiment/example.py \
    --ttl-file experiment/schema.ttl \
    --config my_config.yaml \
    --strategy comprehensive \
    --format json \
    --output analysis.json

script Options:

  • --ttl-file: Path to TTL file (default: tests/sample.ttl)
  • --config: Path to config YAML file (optional)
  • --strategy: Analysis strategy (comprehensive, selective, conflict_resolution)
  • --format: Output format (text, json)
  • --output: Output file path (optional)

2. Command Line Interface

# Basic usage with default config
schema-extract extract data/schema.ttl

# With custom config
schema-extract extract data/schema.ttl --config my_config.yaml

# Full example with all options
schema-extract extract data/schema.ttl \
    --config my_config.yaml \
    --strategy comprehensive \
    --format json \
    --output results.json

# Show version
schema-extract version

# Show help
schema-extract --help
schema-extract extract --help

3. Python Library

from SchemaExtractor.app import SchemaExtractorApp

app = SchemaExtractorApp()

app = SchemaExtractorApp(config_file="my_config.yaml")

# Process  
result = app.extract_schema(
    ttl_file_path="data/schema.ttl",
    merge_strategy="comprehensive",
    output_format="text"
)


if result["status"] == "success":
    if result.get("output"):  # text format
        print(result["output"])
    else:  # json format
        print(f"Technical Analysis: {result['technical_analysis']}")
        print(f"Semantic Analysis: {result['semantic_analysis']}")
        print(f"Merged Analysis: {result['merged_analysis']}")
        print(f"Insights: {result['insights']}")

Output Sample for experiment/sample.ttl data:

output_snapshot_1.png output_snapshot_2.png output_snapshot_3.png

Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the Apache License 2.0 - see the LICENSE.txt file for details.

Authors

Acknowledgments

  • This work is part of the BrainKB project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

schemaextractor-1.0.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

schemaextractor-1.0.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file schemaextractor-1.0.2.tar.gz.

File metadata

  • Download URL: schemaextractor-1.0.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Darwin/23.6.0

File hashes

Hashes for schemaextractor-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1a695676b533be5eea3276b9bcea6767d3fda307a1e9d1a6904f199c010f046b
MD5 253bd9f248b7c713048f015c33beda5e
BLAKE2b-256 d284f4e71795e438ae1a91c5d9e30c89c080bb3f524debcfd233c582eca7cb7b

See more details on using hashes here.

File details

Details for the file schemaextractor-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: schemaextractor-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Darwin/23.6.0

File hashes

Hashes for schemaextractor-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f23b29109548bb89d985301673f4b3ed2465718dca134e363197eea1e78c9c6
MD5 cbdb32dfaf9711b99932cab7120427c1
BLAKE2b-256 4bc4bcdb4ea55933f7d9d8497ed9988d56f8115ece7520b8a55832e97ab3a3e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page