View Source RDF.Namespace behaviour (RDF.ex v2.0.1)
A behaviour and generator for modules of terms resolving to RDF.IRI
s.
Note: A RDF.Namespace
is NOT a IRI namespace! The terms of a RDF.Namespace
don't
have to necessarily refer to IRIs from the same IRI namespace. "Namespace" here is
just meant in the sense that an Elixir module is a namespace. Most of the
Most of the time you'll want to use a RDF.Vocabulary.Namespace
, a special type of
RDF.Namespace
where all terms indeed resolve to IRIs of a shared base URI namespace.
For an introduction into RDF.Namespace
s and RDF.Vocabulary.Namespace
s see
this guide.
Summary
Callbacks
All RDF.IRI
s of a RDF.Namespace
.
Resolves a term to a RDF.IRI
.
All terms of a RDF.Namespace
.
Functions
A macro to let a module act as a specified RDF.Namespace
or RDF.Vocabulary.Namespace
.
Creates a RDF.Namespace
module with the given name and term mapping dynamically.
Creates a RDF.Namespace
module with the given name and term mapping dynamically.
A macro to define a RDF.Namespace
.
Resolves a qualified term to a RDF.IRI
.
Resolves a qualified term to a RDF.IRI
or raises an error when that's not possible.
Types
@type t() :: module()
Callbacks
@callback __iris__() :: [RDF.IRI.t()]
All RDF.IRI
s of a RDF.Namespace
.
@callback __resolve_term__(atom()) :: {:ok, RDF.IRI.t()} | {:error, Exception.t()}
Resolves a term to a RDF.IRI
.
@callback __terms__() :: [atom()]
All terms of a RDF.Namespace
.
Functions
A macro to let a module act as a specified RDF.Namespace
or RDF.Vocabulary.Namespace
.
Example
defmodule Example.NS do
use RDF.Vocabulary.Namespace
defvocab Example,
base_iri: "http://www.example.com/ns/",
terms: [:Foo, :bar]
end
defmodule Example do
import RDF.Namespace
act_as_namespace Example.NS.Example
# your application functions
end
Example.Foo |> Example.bar(42)
Creates a RDF.Namespace
module with the given name and term mapping dynamically.
The line where the module is defined and its file must be passed as options.
Creates a RDF.Namespace
module with the given name and term mapping dynamically.
The line where the module is defined and its file must be passed as options.
A macro to define a RDF.Namespace
.
Example
defmodule YourApp.NS do
import RDF.Namespace
defnamespace EX, [
foo: ~I<http://example1.com/foo>,
Bar: "http://example2.com/Bar",
]
end
Warning
This macro is intended to be used at compile-time, i.e. in the body of a
defmodule
definition. If you want to createRDF.Namespace
s dynamically at runtime, please usecreate/4
.
@spec resolve_term(RDF.IRI.t() | module()) :: {:ok, RDF.IRI.t()} | {:error, Exception.t()}
Resolves a qualified term to a RDF.IRI
.
It determines a RDF.Namespace
from the qualifier of the given term and
delegates to remaining part of the term to __resolve_term__/1
of this
determined namespace.
Resolves a qualified term to a RDF.IRI
or raises an error when that's not possible.
See resolve_term/1
for more.