IriMapping.withFragment constructor
Creates a mapping for generating IRIs by appending a fragment to a base IRI.
This constructor is specifically designed for creating property IRIs that differ from a base IRI
only by their fragment identifier. It works with any URI scheme (hierarchical like https://
or non-hierarchical like tag:), making it ideal for properties that reference resources
within the same document distinguished by fragments.
The generator will:
- Process
baseIriTemplateto get the base IRI - Strip any existing fragment from the base IRI (everything after and including
#) - Process
fragmentTemplateto get the fragment value - Append
#${fragmentValue}to create the final IRI
Both templates support the standard placeholder system:
- Property placeholders corresponding to the annotated property's value
- Context variables from global providers,
@RdfProvides, or parent'sprovidedAs - Reserved expansion with
{+variable}to preserve URI structure
Example usage:
@RdfGlobalResource(
DocumentClass.classIri,
IriStrategy('tag:example.org,2025:document-{docId}', 'documentIri')
)
class Document {
@RdfIriPart()
final String docId;
@RdfProperty(
Vocab.relatedItem,
iri: IriMapping.withFragment('{+documentIri}', 'item-{itemId}')
)
final String itemId;
// Property IRI will be: tag:example.org,2025:document-123#item-456
}
Implementation
const IriMapping.withFragment(String baseIriTemplate, String fragmentTemplate)
: template = baseIriTemplate,
fragmentTemplate = fragmentTemplate,
super();