Skip to content

fix(generators): add --normalize-prefixes flag for well-known prefix names#4

Open
jdsika wants to merge 1 commit intomainfrom
fix/normalize-well-known-prefixes
Open

fix(generators): add --normalize-prefixes flag for well-known prefix names#4
jdsika wants to merge 1 commit intomainfrom
fix/normalize-well-known-prefixes

Conversation

@jdsika
Copy link
Copy Markdown

@jdsika jdsika commented Mar 26, 2026

Summary

Add an opt-in --normalize-prefixes flag to all generators that normalises non-standard prefix aliases to rdflib's curated default names (e.g. sdoschema for https://schema.org/).

Motivation

Schemas often declare custom prefix aliases for well-known namespaces (e.g. sdo for https://schema.org/, dce for http://purl.org/dc/elements/1.1/). When generated artifacts are consumed by tools that expect conventional prefix names, this causes friction. This flag allows opt-in normalization without changing default behavior.

Changes

  • generator.py: Add well_known_prefix_map() utility that returns rdflib's curated namespace-to-prefix mapping. Add normalize_prefixes field to Generator base class and --normalize-prefixes/--no-normalize-prefixes CLI flag.
  • owlgen.py: Gate graph.bind(..., override=False) behind the flag so rdflib's default prefix names take precedence only when enabled.
  • shaclgen.py: Same gating for SHACL graph prefix binding.
  • jsonldcontextgen.py: When flag is set, remap non-standard prefix aliases to standard names in the namespace dict and apply the remap consistently to CURIE generation in _build_element_id().

Backward Compatibility

The flag defaults to off — existing behavior is fully preserved. No snapshot updates required.

@jdsika jdsika force-pushed the fix/normalize-well-known-prefixes branch 3 times, most recently from 42e007b to 71db97f Compare March 26, 2026 17:16
@jdsika jdsika changed the title fix(generators): normalize well-known prefixes in output fix(generators): add --normalize-prefixes flag for well-known prefix names Mar 26, 2026
…names

Add an opt-in --normalize-prefixes flag to OWL, SHACL, and JSON-LD
Context generators that normalises non-standard prefix aliases to
rdflib's curated default names (e.g. sdo -> schema for schema.org).

When enabled:
- OWL/SHACL generators use override=False on graph.bind() so that
  rdflib's default prefix bindings take precedence over schema aliases
- ContextGenerator remaps non-standard prefix names to their standard
  equivalents and applies the remap consistently to CURIE generation

The flag defaults to off, preserving existing behaviour.

Tests verify flag-on remapping (dce -> dc, sdo -> schema), CURIE
consistency, and flag-off backward compatibility.

Signed-off-by: jdsika <carlo.van-driesten@bmw.de>
@jdsika jdsika force-pushed the fix/normalize-well-known-prefixes branch from 71db97f to e987cd8 Compare March 26, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant