2017-02-18 20:35:27 +00:00
|
|
|
defmodule RDF.Quad do
|
|
|
|
@moduledoc """
|
2017-06-16 20:50:56 +00:00
|
|
|
Helper functions for RDF quads.
|
2017-02-18 20:35:27 +00:00
|
|
|
|
2017-06-16 20:50:56 +00:00
|
|
|
A RDF Quad is represented as a plain Elixir tuple consisting of four valid
|
|
|
|
RDF values for subject, predicate, object and a graph context.
|
2017-02-18 20:35:27 +00:00
|
|
|
"""
|
|
|
|
|
2017-06-16 22:44:11 +00:00
|
|
|
alias RDF.Statement
|
2017-02-18 20:35:27 +00:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Creates a `RDF.Quad` with proper RDF values.
|
|
|
|
|
2017-08-11 20:22:27 +00:00
|
|
|
An error is raised when the given elements are not coercible to RDF values.
|
2017-02-18 20:35:27 +00:00
|
|
|
|
|
|
|
Note: The `RDF.quad` function is a shortcut to this function.
|
|
|
|
|
2017-06-16 22:27:05 +00:00
|
|
|
## Examples
|
2017-02-18 20:35:27 +00:00
|
|
|
|
|
|
|
iex> RDF.Quad.new("http://example.com/S", "http://example.com/p", 42, "http://example.com/Graph")
|
2017-04-10 01:06:20 +00:00
|
|
|
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42), ~I<http://example.com/Graph>}
|
2017-06-16 22:44:11 +00:00
|
|
|
iex> RDF.Quad.new(EX.S, EX.p, 42, EX.Graph)
|
2017-08-20 20:35:14 +00:00
|
|
|
{RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42), RDF.iri("http://example.com/Graph")}
|
2017-02-18 20:35:27 +00:00
|
|
|
"""
|
|
|
|
def new(subject, predicate, object, graph_context) do
|
|
|
|
{
|
2017-08-11 20:22:27 +00:00
|
|
|
Statement.coerce_subject(subject),
|
|
|
|
Statement.coerce_predicate(predicate),
|
|
|
|
Statement.coerce_object(object),
|
|
|
|
Statement.coerce_graph_name(graph_context)
|
2017-02-18 20:35:27 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Creates a `RDF.Quad` with proper RDF values.
|
|
|
|
|
2017-08-11 20:22:27 +00:00
|
|
|
An error is raised when the given elements are not coercible to RDF values.
|
2017-02-18 20:35:27 +00:00
|
|
|
|
|
|
|
Note: The `RDF.quad` function is a shortcut to this function.
|
|
|
|
|
2017-06-16 22:27:05 +00:00
|
|
|
## Examples
|
2017-02-18 20:35:27 +00:00
|
|
|
|
|
|
|
iex> RDF.Quad.new {"http://example.com/S", "http://example.com/p", 42, "http://example.com/Graph"}
|
2017-04-10 01:06:20 +00:00
|
|
|
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42), ~I<http://example.com/Graph>}
|
2017-06-16 22:44:11 +00:00
|
|
|
iex> RDF.Quad.new {EX.S, EX.p, 42, EX.Graph}
|
2017-08-20 20:35:14 +00:00
|
|
|
{RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42), RDF.iri("http://example.com/Graph")}
|
2017-02-18 20:35:27 +00:00
|
|
|
"""
|
|
|
|
def new({subject, predicate, object, graph_context}),
|
|
|
|
do: new(subject, predicate, object, graph_context)
|
|
|
|
|
|
|
|
end
|