[data-shapes] use BASE or CURIEs in sh:pattern; tie it up to sh:declare (#857)

VladimirAlexiev has just created a new issue for https://github.com/w3c/data-shapes:

== use BASE or CURIEs in sh:pattern; tie it up to sh:declare ==
https://github.com/w3c/data-shapes/issues/855#issuecomment-4252949852 gives an example like this:
```ttl
@base <https://example.org/data/>.
@prefix person: <https://example.org/data/person/>.
:Person a sh:ClassShape;
  sh:pattern "^https://example.org/data/person/\\d+$";
.
```
I hate it that I have to repeat the BASE in the pattern. I'd rater write it as `person/\\d+` or `person:/\\d+`.

When I do modeling with my little tool "RDF by Example", I always make a file `prefixes.ttl` that's shared between, and prepended to, all models.
> [RDF by Example: rdfpuml for True RDF Diagrams, rdf2rml for R2RML Generation. ](https://bibbase.org/network/publication/alexiev-rdfbyexamplerdfpumlfortruerdfdiagramsrdf2rmlforr2rmlgeneration-2016)[Alexiev, V.](https://bibbase.org/show?bib=https://vladimiralexiev.github.io/my/Alexiev-bibliography.bib&theme=side&showSearch=true&urlLabel=URL) In Semantic Web in Libraries 2016 (SWIB 2016), Bonn, Germany, November 2016. [URL](https://vladimiralexiev.github.io/my/pres/20161128-rdfpuml-rdf2rml/index-full.html)   [slides](https://vladimiralexiev.github.io/my/pres/20161128-rdfpuml-rdf2rml/index.html)   [video](https://youtu.be/4WoYlaGF6DE)

This way I only need to change prefixes in one place, which guarantees consistency.
- Such a discipline is useful with any modeling tool or methodology.
- Services like prefix.cc are useful, but they are limited to established and public ontologies (i.e. not during development)
- This may seem a trivial issue, but the fact is that people often mis-quote even standard namespaces
- I don't know how many times I've had to point to people that http is not the same as https; `/` is different from `#` and `/#` is a bad idea

---
Prior art:
Graphwise's GraphQL thing ("SOML") has 3 [object characteristics](https://platform.ontotext.com/semantic-objects/5.0/soml/objects.html) (I'm not proud of that, it is not quite well designed):
- `prefix`: uses base, implicitly anchored at start
- `regex`: unanchored
- `pattern`: can be used for [id-generation](https://platform.ontotext.com/semantic-objects/5.0/soml/objects.html#soml-objects-id-generation) and validation

Example:
- See [overall-structure](https://platform.ontotext.com/semantic-objects/5.0/soml/index.html#overall-structure) for `specialPrefixes`
```yaml
specialPrefixes:
  base_iri:     https://example.org/data/
  vocab_iri:    https://example.org/ontology#
  vocab_prefix: ex
objects:
  Person:  # mapped to ex:Person by default
    prefix: person/  # Instance URLs must start with https://example.org/data/person/
    regex: ^https://example.org/data/person/\d+$  # and must end in digits
    pattern: person/${ident}  # and those digits must match the field "ident"
    props:
      ident: {pattern: \d+} # mapped to ex:ident and xsd:string by default
```

---

Request:
- Add new prop `sh:uriPattern`
- Can be used on NodeShape (to check the node's URL) or PropertyShape (to check the target URL)
- IMHO `sh:flags` should not be applicable because case is important in most URLs
- It's implicitly anchored on both ends (i.e. requries full match, not substring match)
- Can use any of the `sh:prefixes` (so that prop should be allowed on PropertyShape too)
  - Allows CURIEs, i.e. a prefixed URL can include URL delimiters like slash, hash, etc
- Can use a relative URL, as per:
  - https://github.com/w3c/data-shapes/issues/856

```ttl
@base <https://example.org/data/>.
@prefix pers: <https://example.org/data/person/>.
@prefix ex: <https://example.org/ontology#>.

ex: a owl:Ontology;
  sh:base "https://example.org/data/""^^xsd:anyURI;
  sh:declare 
    [sh:prefix "ex"; sh:namespace "https://example.org/ontology#"^^xsd:anyURI],
    [sh:prefix "pers"; sh:namespace "https://example.org/data/person/"^^xsd:anyURI];
.
ex:Person a sh:ClassShape;
  sh:prefixes ex: ;
  sh:pattern "^https://example.org/data/person/\\d+$";
  sh:uriPattern "pers:\\d+"; # prefixed CURIE, means the same
  sh:uriPattern "person/\\d+"; # relative URL, means the same
  sh:property ex:PersonAddress_PropShape;
.
ex:PersonAddress_PropShape a sh:PropertyShape
  sh:path ex:address;
  sh:class ex:Address;
  sh:pattern "^https://example.org/data/person/\\d+/address$";
  sh:uriPattern "pers:\\d+/address"; # prefixed CURIE, means the same
  sh:uriPattern "person/\\d+/address"; # relative URL, means the same
.
```

Please view or discuss this issue at https://github.com/w3c/data-shapes/issues/857 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 15 April 2026 15:27:44 UTC