RDF.PrefixMap (RDF.ex v0.9.1) View Source
A mapping a prefix atoms to IRI namespaces.
RDF.PrefixMap
implements the Enumerable
protocol.
Link to this section Summary
Functions
Adds a prefix mapping to prefix_map
.
Adds a prefix mapping to the given RDF.PrefixMap
and raises an exception in error cases.
Deletes the prefix mapping for prefix
from prefix_map
.
Drops the given prefixes
from prefix_map
.
Returns whether the given prefix exists in the given RDF.PrefixMap
.
Merges two RDF.PrefixMap
s.
Merges two RDF.PrefixMap
s, resolving conflicts through the given conflict_resolver
function.
Merges two RDF.PrefixMap
s and raises an exception in error cases.
Returns the namespace for the given prefix
in prefix_map
.
Returns all namespaces from the given RDF.PrefixMap
.
Creates an empty RDF.PrefixMap
.
Creates a new RDF.PrefixMap
with initial mappings.
Returns the prefix for the given namespace
in prefix_map
.
Converts an IRI into a prefixed name.
Converts a prefixed name into an IRI.
Returns all prefixes from the given RDF.PrefixMap
.
Adds a prefix mapping to prefix_map
overwriting an existing mapping.
Link to this section Types
Specs
coercible_namespace() :: RDF.Vocabulary.Namespace.t() | String.t() | RDF.IRI.t()
Specs
Specs
conflict_resolver() :: (coercible_prefix(), coercible_namespace(), coercible_namespace() -> coercible_namespace()) | :ignore | :overwrite
Specs
namespace() :: RDF.IRI.t()
Specs
prefix() :: atom()
Specs
Specs
t() :: %RDF.PrefixMap{map: prefix_map()}
Link to this section Functions
Specs
add(t(), coercible_prefix(), coercible_namespace()) :: {:ok, t()} | {:error, String.t()}
Adds a prefix mapping to prefix_map
.
Unless a mapping of prefix
to a different namespace already exists,
an :ok
tuple is returned, otherwise an :error
tuple.
Specs
add!(t(), coercible_prefix(), coercible_namespace()) :: t()
Adds a prefix mapping to the given RDF.PrefixMap
and raises an exception in error cases.
Specs
delete(t(), coercible_prefix()) :: t()
Deletes the prefix mapping for prefix
from prefix_map
.
If no mapping for prefix
exists, prefix_map
is returned unchanged.
Specs
drop(t(), [coercible_prefix()]) :: t()
Drops the given prefixes
from prefix_map
.
If prefixes
contains prefixes that are not in prefix_map
, they're simply ignored.
Specs
has_prefix?(t(), coercible_prefix()) :: boolean()
Returns whether the given prefix exists in the given RDF.PrefixMap
.
Specs
Merges two RDF.PrefixMap
s.
The second prefix map can also be given as any structure which can converted
to a RDF.PrefixMap
via new/1
.
If the prefix maps can be merged without conflicts, that is there are no
prefixes mapped to different namespaces an :ok
tuple is returned.
Otherwise an :error
tuple with the list of prefixes with conflicting
namespaces is returned.
See also merge/3
which allows you to resolve conflicts with a function.
Specs
merge(t(), t() | map() | keyword(), conflict_resolver() | nil) :: {:ok, t()} | {:error, [atom() | String.t()]}
Merges two RDF.PrefixMap
s, resolving conflicts through the given conflict_resolver
function.
The second prefix map can also be given as any structure which can converted
to a RDF.PrefixMap
via new/1
.
The given function will be invoked when there are conflicting mappings of
prefixes to different namespaces; its arguments are prefix
, namespace1
(the namespace for the prefix in the first prefix map),
and namespace2
(the namespace for the prefix in the second prefix map).
The value returned by the conflict_resolver
function is used as the namespace
for the prefix in the resulting prefix map.
Non-RDF.IRI
values will be tried to be converted to RDF.IRI
s via
RDF.IRI.new
implicitly.
The most common conflict resolution strategies on can be chosen directly with the following atoms:
:ignore
: keep the original namespace fromprefix_map1
:overwrite
: use the other namespace fromprefix_map2
If a conflict can't be resolved, the provided function can return nil
.
This will result in an overall return of an :error
tuple with the list of
prefixes for which the conflict couldn't be resolved.
If everything could be merged, an :ok
tuple is returned.
Specs
Merges two RDF.PrefixMap
s and raises an exception in error cases.
See merge/2
and merge/3
for more information on merging prefix maps.
Specs
namespace(t(), coercible_prefix()) :: namespace() | nil
Returns the namespace for the given prefix
in prefix_map
.
Returns nil
, when the given prefix
is not present in prefix_map
.
Specs
namespaces(t()) :: [coercible_namespace()]
Returns all namespaces from the given RDF.PrefixMap
.
Specs
new() :: t()
Creates an empty RDF.PrefixMap
.
Specs
Creates a new RDF.PrefixMap
with initial mappings.
The initial prefix mappings can be passed as keyword lists or maps.
The keys for the prefixes can be given as atoms or strings and will be normalized to atoms.
The namespaces can be given as RDF.IRI
s or strings and will be normalized to RDF.IRI
s.
Specs
prefix(t(), coercible_namespace()) :: coercible_prefix() | nil
Returns the prefix for the given namespace
in prefix_map
.
Returns nil
, when the given namespace
is not present in prefix_map
.
Specs
Converts an IRI into a prefixed name.
Returns nil
when no prefix for the namespace of iri
is defined in prefix_map
.
Examples
iex> RDF.PrefixMap.new(ex: "http://example.com/")
...> |> RDF.PrefixMap.prefixed_name(~I<http://example.com/Foo>)
"ex:Foo"
iex> RDF.PrefixMap.new(ex: "http://example.com/")
...> |> RDF.PrefixMap.prefixed_name("http://example.com/Foo")
"ex:Foo"
Specs
Converts a prefixed name into an IRI.
Returns nil
when the prefix in prefixed_name
is not defined in prefix_map
.
Examples
iex> RDF.PrefixMap.new(ex: "http://example.com/")
...> |> RDF.PrefixMap.prefixed_name_to_iri("ex:Foo")
~I<http://example.com/Foo>
Specs
prefixes(t()) :: [coercible_prefix()]
Returns all prefixes from the given RDF.PrefixMap
.
Specs
put(t(), coercible_prefix(), coercible_namespace()) :: t()
Adds a prefix mapping to prefix_map
overwriting an existing mapping.