View Source RDF.PropertyMap (RDF.ex v1.1.1)

A bidirectional mappings from atom names to RDF.IRIs of properties.

These mapping can be used in all functions of the RDF data structures to provide the meaning of the predicate terms in input statements or define how the IRIs of predicates should be mapped with the value mapping functions like RDF.Description.values/2 etc. The :context option of these functions either take a RDF.PropertyMap directly or anything from which a RDF.PropertyMap can be created with new/1.

Because the mapping is bidirectional each term and IRI can be used only in one mapping of a RDF.PropertyMap.

RDF.PropertyMap implements the Enumerable protocol and the Access behaviour.

Link to this section Summary

Functions

Adds a set of property mappings to property_map.

Adds a property mapping between term and iri to property_map.

Adds a set of property mappings to property_map and raises an error on conflicts.

Deletes the property mapping for term from property_map.

Drops the given terms from the property_map.

Returns the IRI for the given term in property_map.

Returns whether a mapping for the given term is defined in property_map.

Returns the list of all IRIs in the given property_map.

Creates an empty RDF.PropertyMap.

Creates a new RDF.PropertyMap with initial mappings.

Adds a set of property mappings to property_map overwriting all existing mappings.

Adds a property mapping between term and iri to property_map overwriting existing mappings.

Returns the term for the given namespace in prefix_map.

Returns whether a mapping for the given iri is defined in property_map.

Returns the list of all terms in the given property_map.

Converts property map to a list.

Link to this section Types

@type coercible_term() :: atom() | String.t()
@type input() ::
  t() | map() | keyword() | RDF.Namespace.t() | RDF.Vocabulary.Namespace.t()
@type t() :: %RDF.PropertyMap{
  iris: %{required(atom()) => RDF.IRI.t()},
  terms: %{required(RDF.IRI.t()) => atom()}
}

Link to this section Functions

Link to this function

add(property_map, namespace)

View Source
@spec add(t(), input()) :: {:ok, t()} | {:error, String.t()}

Adds a set of property mappings to property_map.

The mappings can be passed in various ways:

  • as keyword lists or maps where terms for the RDF properties can be given as atoms or strings, while the property IRIs can be given as RDF.IRIs or strings
  • a strict RDF.Vocabulary.Namespace from which all lowercase terms are added with their respective IRI; since IRIs can also be once in a RDF.PropertyMap a defined alias term is preferred over an original term
  • a RDF.Namespace from which all lowercase terms are added with their respective IRI
  • another RDF.PropertyMap from which all mappings are merged

Unless a mapping for any of the terms or IRIs in the input already exists, an :ok tuple is returned, otherwise an :error tuple.

Link to this function

add(property_map, term, iri)

View Source
@spec add(t(), coercible_term(), RDF.IRI.coercible()) ::
  {:ok, t()} | {:error, String.t()}

Adds a property mapping between term and iri to property_map.

Unless another mapping for term or iri already exists, an :ok tuple is returned, otherwise an :error tuple.

Link to this function

add!(property_map, mappings)

View Source
@spec add!(t(), input()) :: t()

Adds a set of property mappings to property_map and raises an error on conflicts.

See add/2 for the different forms in which mappings can be provided.

Link to this function

delete(property_map, term)

View Source
@spec delete(t(), coercible_term()) :: t()

Deletes the property mapping for term from property_map.

If no mapping for term exists, property_map is returned unchanged.

Link to this function

drop(property_map, terms)

View Source
@spec drop(t(), [coercible_term()]) :: t()

Drops the given terms from the property_map.

If terms contains terms that are not in property_map, they're simply ignored.

@spec iri(t(), coercible_term()) :: RDF.IRI.t() | nil

Returns the IRI for the given term in property_map.

Returns nil, when the given term is not present in property_map.

Link to this function

iri_defined?(property_map, term)

View Source
@spec iri_defined?(t(), coercible_term()) :: boolean()

Returns whether a mapping for the given term is defined in property_map.

@spec iris(t()) :: [RDF.IRI.t()]

Returns the list of all IRIs in the given property_map.

@spec new() :: t()

Creates an empty RDF.PropertyMap.

@spec new(input()) :: t()

Creates a new RDF.PropertyMap with initial mappings.

See add/2 for the different forms in which mappings can be provided.

Link to this function

put(property_map, mappings)

View Source
@spec put(t(), input()) :: t()

Adds a set of property mappings to property_map overwriting all existing mappings.

See add/2 for the different forms in which mappings can be provided.

Note, that not just all mappings with the used terms in the input mappings are overwritten, but also all mappings with IRIs in the input mappings

Link to this function

put(property_map, term, iri)

View Source
@spec put(t(), coercible_term(), RDF.IRI.coercible()) :: t()

Adds a property mapping between term and iri to property_map overwriting existing mappings.

@spec term(t(), RDF.IRI.coercible()) :: atom() | nil

Returns the term for the given namespace in prefix_map.

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

Link to this function

term_defined?(property_map, iri)

View Source
@spec term_defined?(t(), RDF.IRI.coercible()) :: boolean()

Returns whether a mapping for the given iri is defined in property_map.

@spec terms(t()) :: [atom()]

Returns the list of all terms in the given property_map.

@spec to_list(t()) :: [{atom(), RDF.IRI.t()}]

Converts property map to a list.

Each term-IRI pair in the property map is converted to a two-element tuple {term, iri} in the resulting list.

examples

Examples

iex> RDF.PropertyMap.new(foo: "http://example.com/foo") |> RDF.PropertyMap.to_list()
[foo: ~I<http://example.com/foo>]