RDF.Namespace behaviour (RDF.ex v2.1.0)
View SourceA behaviour and generator for modules of terms resolving to RDF.IRIs.
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.Namespaces and RDF.Vocabulary.Namespaces see
this guide.
Summary
Callbacks
All RDF.IRIs 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.IRIs 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",
]
endWarning
This macro is intended to be used at compile-time, i.e. in the body of a
defmodule definition. If you want to create RDF.Namespaces dynamically
at runtime, please use create/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.