View Source RDF.Term protocol (RDF.ex v1.0.0)
Shared behaviour for all RDF terms.
A RDF.Term
is anything which can be an element of RDF statements of a RDF graph:
Link to this section Summary
Functions
Converts a given value into a RDF term.
Tests for term equality.
Tests for equality of values.
Checks if the given value is a RDF term.
Returns the native Elixir value of a RDF term.
Link to this section Types
@type t() :: RDF.Resource.t() | RDF.Literal.t()
Link to this section Functions
Converts a given value into a RDF term.
Returns nil
if the given value is not convertible into any valid RDF.Term.
examples
Examples
iex> RDF.Term.coerce("foo")
~L"foo"
iex> RDF.Term.coerce(42)
RDF.XSD.integer(42)
Tests for term equality.
Tests for equality of values.
Non-RDF terms are tried to be coerced via RDF.Term.coerce/1
before comparison.
Returns nil
if the given terms are not comparable.
see http://www.w3.org/TR/rdf-sparql-query/#func-RDFterm-equal and the value equality semantics of the different literal datatypes here: https://www.w3.org/TR/sparql11-query/#OperatorMapping
Checks if the given value is a RDF term.
Note: As opposed to RDF.term?
this function returns false
on atoms and does
not try to resolve them to IRIs.
examples
Examples
iex> RDF.Term.term?(RDF.iri("http://example.com/resource"))
true
iex> RDF.Term.term?(EX.Resource)
false
iex> RDF.Term.term?(RDF.bnode)
true
iex> RDF.Term.term?(RDF.XSD.integer(42))
true
iex> RDF.Term.term?(42)
false
Returns the native Elixir value of a RDF term.
Returns nil
if the given value is not a a valid RDF term or a value convertible to a RDF term.
examples
Examples
iex> RDF.Term.value(~I<http://example.com/>)
"http://example.com/"
iex> RDF.Term.value(~L"foo")
"foo"
iex> RDF.XSD.integer(42) |> RDF.Term.value()
42