2016-10-15 16:26:56 +00:00
|
|
|
defmodule RDF.Triple do
|
|
|
|
@moduledoc """
|
2017-06-16 20:50:56 +00:00
|
|
|
Helper functions for RDF triples.
|
2016-10-15 16:26:56 +00:00
|
|
|
|
2017-06-16 20:50:56 +00:00
|
|
|
A RDF Triple is represented as a plain Elixir tuple consisting of three valid
|
|
|
|
RDF values for subject, predicate and object.
|
2016-10-15 16:26:56 +00:00
|
|
|
"""
|
|
|
|
|
2017-06-16 22:44:11 +00:00
|
|
|
alias RDF.Statement
|
2016-10-15 16:26:56 +00:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Creates a `RDF.Triple` with proper RDF values.
|
|
|
|
|
|
|
|
An error is raised when the given elements are not convertible to RDF values.
|
|
|
|
|
|
|
|
Note: The `RDF.triple` function is a shortcut to this function.
|
|
|
|
|
2017-06-16 22:27:05 +00:00
|
|
|
## Examples
|
2016-10-15 16:26:56 +00:00
|
|
|
|
|
|
|
iex> RDF.Triple.new("http://example.com/S", "http://example.com/p", 42)
|
2017-04-10 01:06:20 +00:00
|
|
|
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}
|
2017-06-16 22:44:11 +00:00
|
|
|
iex> RDF.Triple.new(EX.S, EX.p, 42)
|
|
|
|
{RDF.uri("http://example.com/S"), RDF.uri("http://example.com/p"), RDF.literal(42)}
|
2016-10-15 16:26:56 +00:00
|
|
|
"""
|
|
|
|
def new(subject, predicate, object) do
|
|
|
|
{
|
2017-04-12 14:48:17 +00:00
|
|
|
Statement.convert_subject(subject),
|
|
|
|
Statement.convert_predicate(predicate),
|
|
|
|
Statement.convert_object(object)
|
2016-10-15 16:26:56 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Creates a `RDF.Triple` with proper RDF values.
|
|
|
|
|
|
|
|
An error is raised when the given elements are not convertible to RDF values.
|
|
|
|
|
|
|
|
Note: The `RDF.triple` function is a shortcut to this function.
|
|
|
|
|
2017-06-16 22:27:05 +00:00
|
|
|
## Examples
|
2016-10-15 16:26:56 +00:00
|
|
|
|
|
|
|
iex> RDF.Triple.new {"http://example.com/S", "http://example.com/p", 42}
|
2017-04-10 01:06:20 +00:00
|
|
|
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}
|
2017-06-16 22:44:11 +00:00
|
|
|
iex> RDF.Triple.new {EX.S, EX.p, 42}
|
|
|
|
{RDF.uri("http://example.com/S"), RDF.uri("http://example.com/p"), RDF.literal(42)}
|
2016-10-15 16:26:56 +00:00
|
|
|
"""
|
|
|
|
def new({subject, predicate, object}), do: new(subject, predicate, object)
|
|
|
|
|
|
|
|
end
|