Skip to main content

semantic_jsonsubschema

semantic_jsonsubschema checks whether one JSON Schema is a subschema of another, while extending structural checks with semantic reasoning on x-concept annotations.

This library is a fork and semantic extension of the jsonsubschema work by Habib et al. It supports the demo work submitted to the ISWC Demo Track.

Links

Main features

  • JSON subschema checking (s1 <: s2)
  • Semantic policy control when x-concept is missing on one side
  • Semantic reasoners for concept hierarchies:
    • equality
    • rdfs
    • skos
    • owl_rl
    • hermit
  • Schema algebra operations:
    • meet
    • join
    • semantic equivalence (s1 <: s2 and s2 <: s1)

Installation

From PyPI:

pip install semantic_jsonsubschema

From source:

git clone https://gitlab.emse.fr/territoire-public/semantic_jsonsubschema.git
cd semantic_jsonsubschema
pip install .

For contributors:

uv sync --extra dev --extra docs

Python API quick start

from semantic_jsonsubschema import isSubschema

s1 = {"type": "integer"}
s2 = {"type": ["integer", "number"]}

print("LHS <: RHS", isSubschema(s1, s2))

Semantic context with reasoner and policy:

from rdflib import Graph

from semantic_jsonsubschema import (
    EvaluationContext,
    SemanticInclusionPolicy,
    PolicyDecision,
    SKOSReasoner,
    isSubschema,
)

graph = Graph()
graph.parse(data='''
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix ex: <https://example.org/> .

ex:MeasuredAirTemperature skos:broader ex:FluidTemperature .
''', format="turtle")

policy = SemanticInclusionPolicy(
    x_defined_y_not_defined=PolicyDecision.TRUE,
    x_not_defined_y_defined=PolicyDecision.TRUE,
    x_not_defined_y_not_defined=PolicyDecision.TRUE,
)

ctx = EvaluationContext(
    reasoner=SKOSReasoner(graph),
    semantic_inclusion_policy=policy,
)

s1 = {"type": "number", "x-concept": "https://example.org/MeasuredAirTemperature"}
s2 = {"type": "number", "x-concept": "https://example.org/FluidTemperature"}

print(isSubschema(s1, s2, ctx=ctx))

CLI quick start

Basic comparison:

semantic_jsonsubschema compare schema1.json schema2.json

Show command-level help:

semantic_jsonsubschema --help
semantic_jsonsubschema compare --help

With semantic options:

semantic_jsonsubschema compare schema1.json schema2.json \
  --reasoner skos \
  --ontology https://ci.mines-stetienne.fr/semantic-jsonsubschema/example \
  --policy-json '{"x_not_defined_y_defined": true, "x_defined_y_not_defined": true, "x_not_defined_y_not_defined": true}'

Use a policy file instead of inline JSON:

semantic_jsonsubschema compare schema1.json schema2.json \
  --reasoner owl_rl \
  --policy-file policy.json \
  --rdf-graph graph.ttl

Other operations:

semantic_jsonsubschema canonicalize schema.json
semantic_jsonsubschema simplify schema.json
semantic_jsonsubschema meet lhs.json rhs.json
semantic_jsonsubschema join lhs.json rhs.json
semantic_jsonsubschema neg schema.json

Note: simplify first canonicalizes, then simplifies. You do not need to run canonicalize manually before simplify.

Run semantic_jsonsubschema --help for all options.

Development

Run tests:

python -m unittest discover -s test -p 'test_*.py'

Run a focused test suite:

python -m unittest test.test_api test.semantic.test_api

Publication checklist

Publish on PyPI

uv build
uv publish --check-url https://upload.pypi.org/legacy/ dist/*

Publish documentation on Read the Docs

  • Read the Docs config is in .readthedocs.yaml
  • Sphinx docs root is docs/
  • Activate the repository on Read the Docs and choose the default branch

Local docs build:

uv sync --extra docs
sphinx-build -b html docs docs/_build/html

Authorship

Main authors of this fork:

  • Maxime Lefrancois
  • Nicolas Berne
  • Irfan Ullah
  • William Charles

Upstream attribution is preserved in NOTICE.txt.

License

This project is distributed under Apache License 2.0. See LICENSE.txt.

Download files

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

Source Distribution

semantic_jsonsubschema-0.9.0.tar.gz (64.4 kB view details)

Uploaded Source

Built Distribution

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

semantic_jsonsubschema-0.9.0-py3-none-any.whl (48.7 kB view details)

Uploaded Python 3

File details

Details for the file semantic_jsonsubschema-0.9.0.tar.gz.

File metadata

  • Download URL: semantic_jsonsubschema-0.9.0.tar.gz
  • Upload date:
  • Size: 64.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for semantic_jsonsubschema-0.9.0.tar.gz
Algorithm Hash digest
SHA256 545506502f514825ea0a511f38fd65af8dc31c828b9d46d0f77b7d8d4caf87b6
MD5 401b7769b440fa57a5a7f06dc15e0af1
BLAKE2b-256 c57e532b69951167f88b068bfb67eba5d55acb6b246384cbdfeceb40fbe68a73

See more details on using hashes here.

File details

Details for the file semantic_jsonsubschema-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: semantic_jsonsubschema-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 48.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for semantic_jsonsubschema-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bc2b1af2a9fd1b3ec3f71bf19e65ba1318014e180d61cacc6943cfbbc359650
MD5 eca1ca3b9dda0e3429abb357d9f9b6d4
BLAKE2b-256 d7b1bd1b23483a4ea63595ba9e1bcaf939a48c351b6fc77bb0ccffb6fbda3c32

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 files

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