Generates OWL, SHACL shapes and SKOS concepts from XML Schema (XSD) files
Project description
XSD2RDF
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 (required)-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
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
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.ttlin 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 will:
- Load the data from
schema.xsd.sample.ttl - Include all related SKOS files (
schema.xsd.*.skos.ttl) - Perform validation using the generated SHACL shapes (
schema.xsd.shape.ttl) - 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
License
EUPL 1.2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xsd2rdf-0.5.0.tar.gz.
File metadata
- Download URL: xsd2rdf-0.5.0.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f999f10236a529764b45a429b19a531d6206e15f082ed1f2f3e5a9e4b112a28
|
|
| MD5 |
61500fa536fd20456516d6117ef78e7e
|
|
| BLAKE2b-256 |
7513f8894ce528df8b3b127c9c653913b03696107a58366318a45e44686875a4
|
File details
Details for the file xsd2rdf-0.5.0-py3-none-any.whl.
File metadata
- Download URL: xsd2rdf-0.5.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aba5da7911bc47aa5c717a8dba714173a5db55d94faed13bcbecfd0567efc6f2
|
|
| MD5 |
f5c80cf71bff9758df5f9eb0eb00a0df
|
|
| BLAKE2b-256 |
75e62d4758287b1ba3708351f807772b78e838c7ab324cad80b427f079474702
|