RDF.ex v0.6.1 RDF.Statement View Source
Helper functions for RDF statements.
A RDF statement is either a RDF.Triple
or a RDF.Quad
.
Link to this section Summary
Functions
Creates a RDF.Statement
tuple with proper RDF values.
Checks if the given tuple is a valid RDF statement, i.e. RDF triple or quad.
Returns a tuple of native Elixir values from a RDF.Statement
of RDF terms.
Link to this section Types
coercible_graph_name()
View Source
coercible_graph_name() :: graph_name() | atom() | String.t()
coercible_graph_name() :: graph_name() | atom() | String.t()
coercible_object() View Source
coercible_predicate() View Source
coercible_subject() View Source
graph_name()
View Source
graph_name() :: RDF.IRI.t() | RDF.BlankNode.t()
graph_name() :: RDF.IRI.t() | RDF.BlankNode.t()
object()
View Source
object() :: RDF.IRI.t() | RDF.BlankNode.t() | RDF.Literal.t()
object() :: RDF.IRI.t() | RDF.BlankNode.t() | RDF.Literal.t()
predicate()
View Source
predicate() :: RDF.IRI.t()
predicate() :: RDF.IRI.t()
subject()
View Source
subject() :: RDF.IRI.t() | RDF.BlankNode.t()
subject() :: RDF.IRI.t() | RDF.BlankNode.t()
Link to this section Functions
coerce(statement) View Source
Creates a RDF.Statement
tuple with proper RDF values.
An error is raised when the given elements are not coercible to RDF values.
Examples
iex> RDF.Statement.coerce {"http://example.com/S", "http://example.com/p", 42}
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}
iex> RDF.Statement.coerce {"http://example.com/S", "http://example.com/p", 42, "http://example.com/Graph"}
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42), ~I<http://example.com/Graph>}
valid?(tuple) View Source
Checks if the given tuple is a valid RDF statement, i.e. RDF triple or quad.
The elements of a valid RDF statement must be RDF terms. On the subject position only IRIs and blank nodes allowed, while on the predicate and graph context position only IRIs allowed. The object position can be any RDF term.
valid_graph_name?(arg1) View Source
valid_object?(arg1) View Source
valid_predicate?(arg1) View Source
valid_subject?(arg1) View Source
values(statement, mapping \\ &default_term_mapping/1) View Source
Returns a tuple of native Elixir values from a RDF.Statement
of RDF terms.
Returns nil
if one of the components of the given tuple is not convertible via RDF.Term.value/1
.
The optional second argument allows to specify a custom mapping with a function
which will receive a tuple {statement_position, rdf_term}
where
statement_position
is one of the atoms :subject
, :predicate
, :object
or
:graph_name
, while rdf_term
is the RDF term to be mapped. When the given
function returns nil
this will be interpreted as an error and will become
the overhaul result of the values/2
call.
Examples
iex> RDF.Statement.values {~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}
{"http://example.com/S", "http://example.com/p", 42}
iex> RDF.Statement.values {~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42), ~I<http://example.com/Graph>}
{"http://example.com/S", "http://example.com/p", 42, "http://example.com/Graph"}
iex> {~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42), ~I<http://example.com/Graph>}
...> |> RDF.Statement.values(fn
...> {:subject, subject} ->
...> subject |> to_string() |> String.last()
...> {:predicate, predicate} ->
...> predicate |> to_string() |> String.last() |> String.to_atom()
...> {:object, object} ->
...> RDF.Term.value(object)
...> {:graph_name, graph_name} ->
...> graph_name
...> end)
{"S", :p, 42, ~I<http://example.com/Graph>}