In this section

Definition

Let U be the set of all normalized Tagged URNs.

A Tagged URN has the structure:

prefix:key1=value1;key2=value2;...

Each element u ∈ U has:

  • A prefix (e.g., media, cap)
  • Zero or more tags as key-value pairs
  • A well-defined canonical representation

Syntax

Grammar

tagged-urn  ::= prefix ":" tags?
prefix      ::= identifier
tags        ::= tag (";" tag)*
tag         ::= key ("=" value)?
key         ::= identifier
value       ::= unquoted-value | quoted-value
identifier  ::= [a-z][a-z0-9-]*

Examples

media:                           # Identity (no tags)
media:bytes;pdf                  # Two tags with implicit * values
cap:in=media:pdf;extract;out=media:record
cap:in="media:bytes;pdf";extract;out="media:record"

Normalization

All Tagged URNs are normalized on parse using these rules:

Case normalization

Component Rule
Prefix Lowercase
Keys Lowercase
Unquoted values Lowercase
Quoted values Preserve case

Value-less tags

A tag without = is treated as having value *:

Input:  media:bytes;pdf
Parsed: media:pdf=*;bytes=*

When serializing, * values serialize back to value-less form:

Internal: {pdf: "*", bytes: "*"}
Output:   media:bytes;pdf

Tag ordering

Tags are stored in a sorted map (BTreeMap) and serialized in alphabetical key order:

Input:  media:bytes;pdf
Output: media:bytes;pdf      # 'bytes' before 'pdf' alphabetically

Quoting rules

A value requires quoting if it contains: ;, =, ", \, space, or uppercase characters.

Inside quotes:

  • " is escaped as \"
  • \ is escaped as \\
  • All other characters are literal

The six canonical forms

Tagged URNs encode constraints on each key using one of six canonical forms. Several authored aliases collapse to the same canonical form during parsing; serialization always emits the canonical representative deterministically.

Authored aliases Canonical Stored value Reading
?x ≡ x? ≡ x=? ?x "?" no constraint
?x=v ≡ x?=v ≡ x=?v x?=v "?=v" absent OR (present and not v)
x ≡ x=* x "*" present with any value (must-have)
!x=v ≡ x!=v ≡ x=!v x!=v "!=v" present and not v
x=v x=v "v" present and exactly v
!x ≡ x! ≡ x=! !x "!" absent (must-not-have)

Qualifier position

The qualifier ? or ! may appear EITHER as a key prefix (?x, !x, ?x=v, !x=v) OR as an infix immediately before = (x?, x!, x?=v, x!=v). The two notations are exact aliases.

Disallowed combinations

Hard parse errors:

  • Mixed prefix and infix: ?x?, ?x?=v, !x!=v, !x?. The qualifier appears twice on the same key.
  • Mixed ? and !: ?!x, !?x. These are contradictory.
  • Qualifier with sigil value: ?x=*, !x=*, ?x=?, ?x=!. A qualifier and a sigil-only value would conflate the two semantics.
  • Empty value: x= — exact value cannot be empty.
  • Bare ? or ! with nothing after: prefix:?, prefix:!. A qualifier requires a key.

Why six forms

The six forms partition into two semantic chains plus their endpoints:

  • Positive chain (presence claims): ?x (no constraint) → x (must-have-any) → x=v (must-have-exactly-v).
  • Negative chain (absence/exclusion claims): ?x (no constraint) → x?=v (absent or not v) → x!=v (present and not v) → !x (absent).

Both chains start at the same shared origin (?x, no constraint). The chains diverge by the kind of claim being made: positive chains require presence and progressively pin the value; negative chains forbid values and progressively narrow the kind of forbidding.

Canonical of x=*

Bare x and x=* are the same form. The parser stores both with value "*"; the serializer emits the bare form x (no =* suffix) as canonical. This keeps marker-style writing (extract, bytes, numeric) consistent with explicit-value writing.


What a form means, and the tables

Each form means the set of states its key may be in (unset, or set to a value), and means it on either side of a comparison:

Form The states it allows
missing, ?x every state
x?=v unset, or set to anything but v
x set, to any value
x!=v set, to anything but v
x=v set to exactly v
!x unset

Two forms are compared by their sets, and there are two comparisons (Predicates has both tables):

  1. Inclusion, the guarantee (⪯). The instance satisfies the pattern when every state the instance allows, the pattern allows. An instance that omits a key, or says ?x, promises nothing; x promises presence and no value.
  2. Overlap, the possibility (meets). The two allow a common state. x meets x=pdf: “some x” could be a pdf.

A complete thing (a value’s media, a cap’s own tags) is compared by inclusion after its omissions are read as absences (satisfies).

Examples

# Type: media:bytes;pdf        Pattern: media:pdf
# 'pdf': present ⊆ present ✓      'bytes': present ⊆ (anything) ✓
# conforms_to: YES

# Type: media:pdf;audio=mp3    Pattern: media:pdf;!audio
# 'audio': {mp3} ⊄ {unset}
# conforms_to: NO, meets: NO

# Type: media:pdf;v=final      Pattern: media:pdf;v!=draft
# 'v': {final} ⊆ {set, not draft} ✓
# conforms_to: YES

# Type: media:pdf              Pattern: media:pdf;v?=draft
# 'v': (anything) ⊄ {unset or not draft} — a pdf TYPE may be a draft
# conforms_to: NO, meets: YES
# A pdf VALUE with no v tag: satisfies: YES

# Type: media:ext              Pattern: media:document;ext=pdf
# 'ext': {any value} ⊄ {pdf}, but they overlap
# conforms_to: NO, meets: YES

The base relation ⪯

Define a binary relation on Tagged URNs:

a ⪯ b   iff   a is at least as specific as b

Equivalently:

  • a refines b
  • b accepts a
  • a is lower in the partial order than b

Operational definition

a ⪯ b holds iff for every key K:

Properties

The relation ⪯ is:

  • Reflexive: ∀u ∈ U, u ⪯ u
  • Transitive: (a ⪯ b ∧ b ⪯ c) ⟹ a ⪯ c
  • Antisymmetric (modulo normalization): (a ⪯ b ∧ b ⪯ a) ⟹ a ≡ b

This makes ⪯ a partial order on normalized URNs.


Identity elements

Media identity

The Media URN identity is:

media:

This URN:

  • Has no tags
  • Accepts any Media URN (top of the partial order)
  • Has specificity 0

Reflexivity: media: ⪯ media: holds (identity accepts itself).

Tagged URN identity

For any prefix P, the identity is:

P:

A URN with no tags accepts any URN with the same prefix.


Partial order structure

Tagged URNs with the same prefix form a partial order (specialization order):

                    media:                    (top - most generic)
                      |
              media:bytes
                /         \
       media:pdf          media:image
           |                   |
   media:pdf;v=2.0      media:png;image
           |
media:pdf;v=2.0;compressed              (more specific)
  • Top (⊤): The identity prefix: with no tags
  • Ordering: More tags = more specific = lower in the order

Note: While this structure has lattice-like properties (bounded above by identity), we do not formally define join (⊔) or meet (⊓) operations. The system uses only the partial order relation ⪯.


Parse errors

The following conditions produce parse errors:

Condition Error
Missing prefix MissingPrefix
Empty prefix EmptyPrefix
Duplicate key DuplicateKey
Numeric key NumericKey
Empty value after = EmptyValue
Unclosed quote UnclosedQuote
Invalid escape sequence InvalidEscape

Summary

The Tagged URN domain U provides:

  1. Normalized representation: Canonical string form via case/ordering rules
  2. Six-form constraint alphabet: ?x, x?=v, x (=x=*), x!=v, x=v, !x, plus the implicit “missing”
  3. Partial order ⪯: Reflexive, transitive, antisymmetric relation
  4. Lattice structure: Identity at top, specificity increasing downward
  5. Compositional matching: Per key, by what each form means: inclusion for the guarantee, overlap for the possibility

All higher-level constructs (predicates, Cap URNs, dispatch) build on this foundation.