Skip to main content

Generates OWL, SHACL shapes and SKOS concepts from XML Schema (XSD) files

Project description

XSD2RDF

License

A tool to convert XML Schema (XSD) files into various RDF formats (SHACL, OWL, SKOS) with integrated validation capabilities.

Overview

XSD2RDF allows you to convert XML Schema definitions into:

  • SHACL (Shapes Constraint Language) for RDF data validation
  • OWL (Web Ontology Language) for ontology representation
  • SKOS (Simple Knowledge Organization System) for concept schemes and taxonomies

Features

  • Convert XSD to SHACL, OWL, and SKOS based on integrated principles
  • SHACL shape constraints are linked to SKOS concept schemes when applicable
  • Handle complex XSD structures (choices, unions, complex types, enumerations, etc.)
  • SHACL shapes are validated according to SHACL-SHACL

This repository also includes a validation script to check RDF data against the generated SHACL shapes and SKOS concepts.

Installation

From PyPI

pip install xsd2rdf

From Source

git clone https://github.com/YourUsername/xsd2rdf.git
cd xsd2rdf
python -m pip install poetry
poetry install

Basic Usage

Convert an XSD file to all RDF formats (SHACL, OWL, SKOS):

python -m xsd2rdf -x path/to/schema.xsd

This generates the following files:

  • schema.xsd.shape.ttl (SHACL shapes)
  • schema.xsd.owl.ttl (OWL ontology)
  • schema.xsd.*.skos.ttl (SKOS concept schemes, one file per enumeration)

Command Line Parameters

  • -x, --XSD_FILE: XSD file to be converted
  • -f, --FOLDER: Folder containing non-related XSD files to be converted
  • -o, --OUTPUT_DIR: Output directory for generated files (default: same as XSD file)
  • -a, --ABBREVIATIONS_FILE: File containing custom abbreviations, one per line
  • -d, --debug: Enable debug output
  • -nc, --namespaced-concepts: Use namespaced IRIs for SKOS concepts

Either -x or -f must be specified, but not both. If both are specified, -x takes precedence.

SKOS IRI Options

By default, SKOS concept IRIs are created using a flat structure:

targetnamespace/concepts/conceptschemename_conceptname

With the --namespaced-concepts flag, concepts use a hierarchical structure:

targetnamespace/concepts/conceptschemename/conceptname

Examples

With custom output directory:

python -m xsd2rdf  -x path/to/schema.xsd -o output/directory

With folder containing multiple unrelated XSD files:

python -m xsd2rdf -f path/to/folder

Using a custom abbreviations file:

python -m xsd2rdf -x path/to/schema.xsd -a path/to/abbreviations.txt

A practical way to generate a list of abbreviations on a Windows machine using Powershell is with this command:

 Select-String -Path "c:\Users\mathi\Git\era\xsd2rdf\debug\SFERA_v3.00.xsd" -Pattern "\b[A-Z]{2,}\b" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | Where-Object { $_ -cmatch "^[A-Z]{2,}$" } | Sort-Object -Unique | Where-Object { $_.Length -ge 2 -and $_.Length -le 10 }

Using namespaced concept IRIs:

python -m xsd2rdf -x path/to/schema.xsd --namespaced-concepts

The abbreviations file should contain one abbreviation per line. These abbreviations will be preserved as uppercase when creating human-readable labels from camelCase or PascalCase strings.

Validation

This feature is only available from source as it is meant for development purposes.

Prerequisites:

  • Create sample data for validation schema.xsd.shape.ttl in the same directory as the xsd file

To validate RDF data against SHACL shapes with SKOS concepts:

python shacl-validation.py path/to/schema.xsd

This result will:

  1. Load the data from schema.xsd.sample.ttl
  2. Include all related SKOS files (schema.xsd.*.skos.ttl)
  3. Perform validation using the generated SHACL shapes (schema.xsd.shape.ttl)
  4. Report results in the command line

Example

Converting an XSD file with enumerations:

python -m xsd2rdf xsd2rdf -x comparison/enumerations.xsd

Validating data using generated shapes and concepts:

python shacl-validation.py comparison/enumerations.xsd

Wiki Pages

Some wiki pages explain the inner workings of the convertor and the list of mapping rules implemented within the tool.

License

EUPL 1.2

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

xsd2rdf-1.1.1.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

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

xsd2rdf-1.1.1-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file xsd2rdf-1.1.1.tar.gz.

File metadata

  • Download URL: xsd2rdf-1.1.1.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for xsd2rdf-1.1.1.tar.gz
Algorithm Hash digest
SHA256 5a6ec8f0c31241f2dc058e6e5415dd9f280f5f71691f283c024e1a6d90d37ae8
MD5 1c483c37fcf1dfd4f58e1a0ae0aa43d7
BLAKE2b-256 d502c2e29086cda7b444a0c5e6b1a66d2772a184d9e6209c7911fa31b51e6f4e

See more details on using hashes here.

File details

Details for the file xsd2rdf-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: xsd2rdf-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for xsd2rdf-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2285be9756815e0706618726d5e143389aeed815c2ac573fcf3e79f140d146dc
MD5 023febb85df9716e012e02439bdd0a20
BLAKE2b-256 68eeffb12cd5db8ee9cc097e378d183c4bd9358774eee2fdc2faa0b6930bd9ae

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