Lutaml::Model provides a comprehensive RDF infrastructure with Namespace, NamespaceSet, Iri, and Literal classes. These are shared by the JSON-LD and Turtle format adapters.
Namespace
Lutaml::Rdf::Namespace is the abstract base class for RDF namespace vocabularies. Subclasses define uri and prefix at the class level:
ns = Class.new(Lutaml::Rdf::Namespace)
ns.uri "http://example.org/ns/"
ns.prefix "ex"
ns["someName"] # => "http://example.org/ns/someName"
ns.prefixed("Name") # => "ex:Name"Immutability
Once set, uri and prefix are frozen and cannot be changed:
ns = Class.new(Lutaml::Rdf::Namespace)
ns.uri "http://example.org/ns/"
ns.uri "http://other.org/" # => raises FrozenErrorEach subclass has independent state — setting uri on one does not affect another.
NamespaceSet
Lutaml::Rdf::NamespaceSet is an ordered, enumerable collection of namespace classes with O(1) prefix lookup:
set = Lutaml::Rdf::NamespaceSet.new(
Lutaml::Rdf::Namespaces::SkosNamespace,
Lutaml::Rdf::Namespaces::DctermsNamespace
)
set["skos"] # => SkosNamespace (O(1) lookup)
set.size # => 2
set.resolve_compact_iri("skos:Concept")
# => "http://www.w3.org/2004/02/skos/core#Concept"
set.compact("http://www.w3.org/2004/02/skos/core#Concept")
# => "skos:Concept"
set.to_hash
# => { "skos" => "http://www.w3.org/2004/02/skos/core#",
# "dcterms" => "http://purl.org/dc/terms/" }Collision detection
Adding two different namespace classes with the same prefix raises an error:
set = Lutaml::Rdf::NamespaceSet.new(SkosNamespace)
ns = Class.new(Lutaml::Rdf::Namespace)
ns.uri "http://other.org/"
ns.prefix "skos"
set.add(ns) # => raises ArgumentError: Prefix 'skos' conflictsAdding the same class twice is allowed (idempotent).
Iri
Lutaml::Rdf::Iri is an immutable value object for IRIs:
iri = Lutaml::Rdf::Iri.new("http://example.org/concept/1")
iri.to_s # => "http://example.org/concept/1"
iri.value # => "http://example.org/concept/1" (frozen)
# Expand compact → full
set = Lutaml::Rdf::NamespaceSet.new(SkosNamespace)
compact_iri = Lutaml::Rdf::Iri.new("skos:Concept")
compact_iri.expand(set) # => Iri("http://www.w3.org/2004/02/skos/core#Concept")
# Compact full → compact
full_iri = Lutaml::Rdf::Iri.new("http://www.w3.org/2004/02/skos/core#Concept")
full_iri.compact(set) # => "skos:Concept"Implements Comparable for sorting.
Literal
Lutaml::Rdf::Literal is a value object for RDF literals with optional datatype and language tag:
# Plain literal
lit = Lutaml::Rdf::Literal.new("hello")
lit.to_turtle # => '"hello"'
lit.to_jsonld_term # => "hello"
# Language-tagged literal
lit = Lutaml::Rdf::Literal.new("hello", language: "en")
lit.to_turtle # => '"hello"@en'
lit.to_jsonld_term # => { "@value" => "hello", "@language" => "en" }
# Typed literal
lit = Lutaml::Rdf::Literal.new("42", datatype: "http://www.w3.org/2001/XMLSchema#integer")
lit.to_turtle # => '"42"^^<http://www.w3.org/2001/XMLSchema#integer>'
lit.to_jsonld_term # => { "@value" => "42", "@type" => "xsd:integer" }Standard W3C Namespaces
Pre-defined namespace classes are in Lutaml::Rdf::Namespaces:
| Class | Prefix | URI |
|---|---|---|
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
RdfNamespace is a backward-compatible alias for RdfSyntaxNamespace. |
Custom Namespaces
Define your own by subclassing:
class MyNamespace < Lutaml::Rdf::Namespace
uri "http://example.org/vocab/"
prefix "my"
end
MyNamespace["term"] # => "http://example.org/vocab/term"Error hierarchy
| Class | Description |
|---|---|
| Base error for all RDF errors |
| Raised when Turtle mapping has no |
Unified RDF Mapping
Lutaml::Rdf::Mapping is the unified mapping base class shared by both Turtle and JSON-LD format adapters. It provides the rdf DSL for defining predicate-based mappings once and using them for both output formats.
See Unified RDF Serialization for the complete guide.
MappingRule
Lutaml::Rdf::MappingRule is a value object for predicate-to-attribute mappings:
# Created by the `predicate` DSL method
predicate :prefLabel, namespace: SkosNamespace, to: :name, lang_tagged: trueEach rule stores: predicate_name, namespace, to (attribute symbol), and lang_tagged flag.
MemberRule
Lutaml::Rdf::MemberRule is a value object for the members declaration in graph-level RDF mapping:
# In a container model's rdf block
members :conceptsStores the attribute name referencing the collection of member models.
Transform
Lutaml::Rdf::Transform is the base transform class for RDF serialization, shared by both Turtle::Transform and JsonLd::Transform. It provides:
-
resolve_subject_uri(mapping, instance)— evaluates the subject block -
resolve_type_uri(mapping)— resolves compact IRI to full URI -
resolve_type_compact(mapping)— returns the compact IRI form -
extract_language(value)— extracts language code fromLanguageTaggedvalues