RDF.Quad (RDF.ex v0.8.2) View Source
Helper functions for RDF quads.
A RDF Quad is represented as a plain Elixir tuple consisting of four valid RDF values for subject, predicate, object and a graph context.
Link to this section Summary
Link to this section Types
Specs
coercible_t() :: {RDF.Statement.coercible_subject(), RDF.Statement.coercible_predicate(), RDF.Statement.coercible_object(), RDF.Statement.coercible_graph_name()}
Specs
t() :: {RDF.Statement.subject(), RDF.Statement.predicate(), RDF.Statement.object(), RDF.Statement.graph_name()}
Specs
Link to this section Functions
Specs
new(coercible_t()) :: t()
Creates a RDF.Quad
with proper RDF values.
An error is raised when the given elements are not coercible to RDF values.
Note: The RDF.quad
function is a shortcut to this function.
Examples
iex> RDF.Quad.new {"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>}
iex> RDF.Quad.new {EX.S, EX.p, 42, EX.Graph}
{RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42), RDF.iri("http://example.com/Graph")}
Specs
new( RDF.Statement.coercible_subject(), RDF.Statement.coercible_predicate(), RDF.Statement.coercible_object(), RDF.Statement.coercible_graph_name() ) :: t()
Creates a RDF.Quad
with proper RDF values.
An error is raised when the given elements are not coercible to RDF values.
Note: The RDF.quad
function is a shortcut to this function.
Examples
iex> RDF.Quad.new("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>}
iex> RDF.Quad.new(EX.S, EX.p, 42, EX.Graph)
{RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42), RDF.iri("http://example.com/Graph")}
Specs
Checks if the given tuple is a valid RDF quad.
The elements of a valid RDF quad 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.
Specs
values(t() | any(), RDF.Statement.term_mapping()) :: t_values() | nil
Returns a tuple of native Elixir values from a RDF.Quad
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.Quad.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.Quad.values(fn
...> {:object, object} ->
...> RDF.Term.value(object)
...> {:graph_name, graph_name} ->
...> graph_name
...> {_, resource} ->
...> resource |> to_string() |> String.last() |> String.to_atom()
...> end)
{:S, :p, 42, ~I<http://example.com/Graph>}