RdfIri.withFragment constructor
const
RdfIri.withFragment(})
Creates an IRI mapping by appending a fragment to a base IRI.
This constructor is specifically designed for classes that represent IRI terms which 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 identifier classes
that represent fragment-based references within a document.
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 from
@RdfIriPartannotated properties - Context variables from global providers,
@RdfProvides, or parent'sprovidedAs - Reserved expansion with
{+variable}to preserve URI structure
Example usage:
@RdfIri.withFragment('{+documentIri}', 'section-{sectionId}')
class SectionReference {
@RdfIriPart()
final String sectionId;
SectionReference(this.sectionId);
}
@RdfGlobalResource(
DocumentClass.classIri,
IriStrategy('tag:example.org,2025:document-{id}', 'documentIri')
)
class Document {
@RdfIriPart()
final String id;
@RdfProperty(Vocab.currentSection)
final SectionReference section;
// Section IRI will be: tag:example.org,2025:document-123#section-intro
}
Implementation
const RdfIri.withFragment(String baseIriTemplate, String fragmentTemplate,
{bool registerGlobally = true})
: template = baseIriTemplate,
fragmentTemplate = fragmentTemplate,
super(registerGlobally: registerGlobally);