RDF.ex v0.7.1 RDF.PrefixMap 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 the given RDF.PrefixMap.

Adds a prefix mapping to the given RDF.PrefixMap and raises an exception in error cases.

Deletes a prefix mapping from the given RDF.PrefixMap.

Drops the given prefixes from the given prefix_map.

Returns whether the given prefix exists in the given RDF.PrefixMap.

Merges two RDF.PrefixMaps, resolving conflicts through the given conflict_resolver function.

Merges two RDF.PrefixMaps and raises an exception in error cases.

Returns the namespace for the given prefix in the given RDF.PrefixMap.

Returns all namespaces from the given RDF.PrefixMap.

Creates an empty RDF.PrefixMap.

Creates a new RDF.PrefixMap.

Returns the prefix for the given namespace in the given RDF.PrefixMap.

Returns all prefixes from the given RDF.PrefixMap.

Link to this section Types

Link to this type

coercible_namespace()

View Source
coercible_namespace() :: atom() | String.t() | RDF.IRI.t()
Link to this type

coercible_prefix()

View Source
coercible_prefix() :: atom() | String.t()
Link to this type

namespace()

View Source
namespace() :: RDF.IRI.t()
Link to this type

prefix_map()

View Source
prefix_map() :: %{required(prefix()) => namespace()}
Link to this type

t()

View Source
t() :: %RDF.PrefixMap{map: prefix_map()}

Link to this section Functions

Link to this function

add(prefix_map, prefix, namespace)

View Source
add(t(), coercible_prefix(), coercible_namespace()) ::
  {:ok, t()} | {:error, String.t()}

Adds a prefix mapping to the given RDF.PrefixMap.

Unless a mapping of the given prefix to a different namespace already exists, an ok tuple is returned, other an error tuple.

Link to this function

add!(prefix_map, prefix, namespace)

View Source

Adds a prefix mapping to the given RDF.PrefixMap and raises an exception in error cases.

Link to this function

delete(prefix_map, prefix)

View Source
delete(t(), coercible_prefix()) :: t()

Deletes a prefix mapping from the given RDF.PrefixMap.

Link to this function

drop(prefix_map, prefixes)

View Source
drop(t(), [coercible_prefix()]) :: t()

Drops the given prefixes from the given prefix_map.

If prefixes contains prefixes that are not in prefix_map, they're simply ignored.

Link to this function

has_prefix?(prefix_map, prefix)

View Source
has_prefix?(t(), coercible_prefix()) :: boolean()

Returns whether the given prefix exists in the given RDF.PrefixMap.

Link to this function

merge(prefix_map1, prefix_map2)

View Source
merge(t(), t() | map() | keyword()) ::
  {:ok, t()} | {:error, [atom() | String.t()]}

Merges two RDF.PrefixMaps.

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.

Link to this function

merge(prefix_map1, prefix_map2, conflict_resolver)

View Source
merge(t(), t() | map() | keyword(), conflict_resolver() | nil) ::
  {:ok, t()} | {:error, [atom() | String.t()]}

Merges two RDF.PrefixMaps, 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 converted to RDF.IRI via RDF.IRI.new implicitly.

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.

Link to this function

merge!(prefix_map1, prefix_map2, conflict_resolver \\ nil)

View Source
merge!(t(), t() | map() | keyword(), conflict_resolver() | nil) :: t()

Merges two RDF.PrefixMaps and raises an exception in error cases.

See merge/2 and merge/3 for more information on merging prefix maps.

Link to this function

namespace(prefix_map, prefix)

View Source
namespace(t(), coercible_prefix()) :: namespace() | nil

Returns the namespace for the given prefix in the given RDF.PrefixMap.

Returns nil, when the given prefix is not present in prefix_map.

Link to this function

namespaces(prefix_map)

View Source
namespaces(t()) :: [coercible_namespace()]

Returns all namespaces from the given RDF.PrefixMap.

Creates an empty RDF.PrefixMap.

Link to this function

new(map)

View Source
new(t() | map() | keyword()) :: t()

Creates a new RDF.PrefixMap.

The 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.IRIs or strings and will be normalized to RDF.IRIs.

Link to this function

prefix(prefix_map, namespace)

View Source
prefix(t(), coercible_namespace()) :: coercible_prefix() | nil

Returns the prefix for the given namespace in the given RDF.PrefixMap.

Returns nil, when the given namespace is not present in prefix_map.

Link to this function

prefixes(prefix_map)

View Source
prefixes(t()) :: [coercible_prefix()]

Returns all prefixes from the given RDF.PrefixMap.