RDF.ex v0.7.0 RDF.Term protocol View Source

Shared behaviour for all RDF terms.

A RDF.Term is anything which can be an element of RDF statements of a RDF graph:

see https://www.w3.org/TR/sparql11-query/#defn_RDFTerm

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

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

iex> RDF.Term.coerce("foo")
~L"foo"
iex> RDF.Term.coerce(42)
RDF.integer(42)

Tests for term equality.

see http://www.w3.org/TR/rdf-sparql-query/#func-sameTerm

Link to this function

equal_value?(term1, term2)

View Source

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 resolves those to IRIs.

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.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

iex> RDF.Term.value(~I<http://example.com/>)
"http://example.com/"
iex> RDF.Term.value(~L"foo")
"foo"
iex> RDF.integer(42) |> RDF.Term.value()
42