Skip to main content

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.

Metadata

Release files for SchemaExtractor 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SchemaExtractor 1.0.2
File Size Uploaded Provenance Actions
schemaextractor-1.0.2.tar.gz 8.8 kB Without provenance Details for schemaextractor-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for SchemaExtractor 1.0.2
File Interpreter ABI Platform Actions
schemaextractor-1.0.2-py3-none-any.whl Python 3 none any Details for schemaextractor-1.0.2-py3-none-any.whl

Total release size: 18.3 kB

Release files / schemaextractor-1.0.2.tar.gz

Download URL schemaextractor-1.0.2.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1a695676b533be5eea3276b9bcea6767d3fda307a1e9d1a6904f199c010f046b
BLAKE2b-256 checksum
How to use checksums
d284f4e71795e438ae1a91c5d9e30c89c080bb3f524debcfd233c582eca7cb7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.7 Darwin/23.6.0

Release files / schemaextractor-1.0.2-py3-none-any.whl

Download URL schemaextractor-1.0.2-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f23b29109548bb89d985301673f4b3ed2465718dca134e363197eea1e78c9c6
BLAKE2b-256 checksum
How to use checksums
4bc4bcdb4ea55933f7d9d8497ed9988d56f8115ece7520b8a55832e97ab3a3e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.7 Darwin/23.6.0

Security for SchemaExtractor 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page