Skip to content

Stiksels/rdf-schema-doc

Repository files navigation

RDF Schema Diagram Generator

A Python tool that processes RDF OWL ontology files and generates comprehensive documentation in multiple formats, including Mermaid ER diagrams showing classes, properties with datatypes, and their relationships.

Overview

This tool helps you visualize and document your RDF OWL ontology by:

  • Processing OWL ontology files (Turtle, RDF/XML, JSON-LD, N-Triples)
  • Extracting classes, object properties, and datatype properties
  • Generating human-readable Markdown documentation
  • Creating UML diagrams (PlantUML and Mermaid formats)
  • Exporting structured formats (JSON, YAML) for programmatic analysis
  • Visualizing class hierarchies and property relationships

Installation

  1. Clone or download this repository
  2. Install dependencies:
pip install -r requirements.txt

Usage

Quick Start

To test the tool with the included example OWL file:

# Using the virtual environment's Python
python main.py -i examples/owl-uwp-oslo-cp.ttl -o ./schema-docs

# Or activate the virtual environment first
source venv/bin/activate
python main.py -i examples/owl-uwp-oslo-cp.ttl -o ./schema-docs

Basic Usage

python main.py --input ./ontology.ttl --output-dir ./schema-docs

Advanced Usage

python main.py \
  --input ./ontology.ttl \
  --input-format turtle \
  --output-dir ./schema-docs \
  --formats text uml json yaml

Command Line Options

  • --input, -i: Path to input RDF/OWL file (required)
  • --input-format, -f: Input file format ('turtle', 'xml', 'json-ld', 'nt', or auto-detect if not specified)
  • --output-dir, -o: Output directory for generated documentation (default: ./schema-docs)
  • --formats: Output formats to generate (default: text, uml, json, yaml)
    • Options: text, uml, json, yaml
    • Can specify multiple: --formats text uml json

Examples

Process the included example OWL file:

python main.py -i examples/owl-uwp-oslo-cp.ttl -o ./schema-docs

Process a Turtle OWL file:

python main.py -i ontology.ttl -o ./docs

Process an RDF/XML file:

python main.py -i ontology.rdf -f xml --formats text uml

Generate all formats:

python main.py -i ./ontology.ttl --formats text uml json yaml

Output Files

The tool generates the following files in the output directory:

  • schema_documentation.md - Comprehensive Markdown documentation

    • Ontology overview
    • Class-by-class documentation
    • Property listings with types and ranges
    • Relationship mappings
    • Index of all classes and properties
  • schema_diagram.puml - PlantUML diagram file

    • Can be rendered using PlantUML tools or online viewer
    • Shows classes as entities with relationships
  • schema_diagram.mmd - Mermaid diagram file

    • Can be rendered in Markdown viewers, GitHub, or Mermaid Live Editor
    • Entity-relationship diagram format showing classes, properties, and relationships
  • schema.json - Structured JSON schema definition

    • Machine-readable format
    • Suitable for programmatic analysis
  • schema.yaml - Structured YAML schema definition

    • Human-friendly structured format
    • Easy to compare with other schemas

Example Files

The repository includes an example OWL file in the examples/ directory:

  • examples/owl-uwp-oslo-cp.ttl - A sample OWL ontology for testing

You can use this file to test the tool:

python main.py -i examples/owl-uwp-oslo-cp.ttl -o ./schema-docs

Supported RDF Formats

  • Turtle (.ttl) - Default format, human-readable
  • RDF/XML (.rdf, .owl) - XML-based RDF format
  • JSON-LD (.jsonld) - JSON-based linked data format
  • N-Triples (.nt) - Line-based RDF format

Features

  • OWL Class Extraction: Extracts all owl:Class declarations
  • Property Analysis: Separates object properties and datatype properties
  • Relationship Visualization: Shows subclass hierarchies and property domain/range relationships
  • Multiple Domains: Handles properties with multiple domain classes
  • Datatype Support: Shows XSD datatypes for datatype properties
  • Multiple Output Formats: Text, UML, JSON, YAML

Limitations

  • Currently focuses on OWL ontologies (SHACL support may be added later)
  • Anonymous classes (owl:Restriction, owl:IntersectionOf) are not fully visualized
  • Property chains are not visualized
  • Individuals (owl:NamedIndividual) are ignored in diagram generation

Use Cases

Ontology Documentation

Generate comprehensive documentation of your OWL ontology for:

  • Team onboarding
  • Ontology evolution tracking
  • Integration planning
  • Semantic mapping workshops

Visual Analysis

Use Mermaid diagrams to:

  • Understand class hierarchies at a glance
  • Identify property relationships between classes
  • Review data type usage across properties
  • Share visual representations with stakeholders

Troubleshooting

Issue: "No classes found in input file"

  • Solution: Verify your file is a valid OWL ontology with owl:Class declarations

Issue: "Invalid RDF format"

  • Solution: Check that your file format matches the specified format, or let auto-detection work

Issue: "Properties not showing relationships"

  • Solution: Ensure properties have rdfs:domain and rdfs:range defined

Contributing

This tool is designed to work with OWL ontologies. For improvements or bug reports, please contact the development team.

License

Internal use only.

About

generate data model schema from rdf source

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages