RDF.ex v0.6.0 RDF.Literal View Source

RDF literals are leaf nodes of a RDF graph containing raw data, like strings and numbers.

Link to this section Summary

Functions

Returns the given literal in its canonical lexical representation.

Returns if the given literal is in its canonical lexical representation.

Checks if two RDF.Literals are equal.

Checks if the first of two RDF.Literals is greater then the other.

Returns if a literal is a datatyped literal.

Returns if a literal is a language-tagged literal.

Checks if the first of two RDF.Literals is smaller then the other.

Returns the lexical representation of the given literal according to its datatype.

Creates a new RDF.Literal of the given value and tries to infer an appropriate XSD datatype.

Creates a new RDF.Literal with the given datatype or language tag.

Creates a new RDF.Literal, but fails if it's not valid.

Returns if a literal is a plain literal.

Returns if a literal is a simple literal.

Returns if the value of the given literal is a valid according to its datatype.

Link to this section Types

Link to this section Functions

Returns the given literal in its canonical lexical representation.

Returns if the given literal is in its canonical lexical representation.

Compares two RDF.Literals.

Returns :gt if first literal is greater than the second in terms of their datatype and :lt for vice versa. If the two literals are equal :eq is returned. For datatypes with only partial ordering :indeterminate is returned when the order of the given literals is not defined.

Returns nil when the given arguments are not comparable datatypes.

Link to this function

equal_value?(left, right) View Source

Checks if two RDF.Literals are equal.

Non-RDF terms are tried to be coerced via RDF.Term.coerce/1 before comparison.

Returns nil when the given arguments are not comparable as Literals.

see https://www.w3.org/TR/rdf-concepts/#section-Literal-Equality

Link to this function

greater_than?(literal1, literal2) View Source

Checks if the first of two RDF.Literals is greater then the other.

Returns nil when the given arguments are not comparable datatypes.

Returns if a literal is a datatyped literal.

For historical reasons, this excludes xsd:string and rdf:langString.

see http://www.w3.org/TR/rdf-concepts/#dfn-typed-literal

Returns if a literal is a language-tagged literal.

see http://www.w3.org/TR/rdf-concepts/#dfn-plain-literal

Link to this function

less_than?(literal1, literal2) View Source

Checks if the first of two RDF.Literals is smaller then the other.

Returns nil when the given arguments are not comparable datatypes.

Returns the lexical representation of the given literal according to its datatype.

Creates a new RDF.Literal of the given value and tries to infer an appropriate XSD datatype.

Note: The RDF.literal function is a shortcut to this function.

The following mapping of Elixir types to XSD datatypes is applied:

Elixir datatypeXSD datatype
stringxsd:string
booleanxsd:boolean
integerxsd:integer
floatxsd:double
Timexsd:time
Datexsd:date
DateTimexsd:dateTime
NaiveDateTimexsd:dateTime

Examples

iex> RDF.Literal.new(42)
%RDF.Literal{value: 42, datatype: XSD.integer}

Creates a new RDF.Literal with the given datatype or language tag.

Link to this function

new!(value, opts \\ %{}) View Source

Creates a new RDF.Literal, but fails if it's not valid.

Note: Validation is only possible if an RDF.Datatype with an implementation of RDF.Datatype.valid?/1 exists.

Examples

iex> RDF.Literal.new!("3.14", datatype: XSD.double) == RDF.Literal.new("3.14", datatype: XSD.double)
true

iex> RDF.Literal.new!("invalid", datatype: "http://example/unkown_datatype") == RDF.Literal.new("invalid", datatype: "http://example/unkown_datatype")
true

iex> RDF.Literal.new!("foo", datatype: XSD.integer)
** (RDF.Literal.InvalidError) invalid RDF.Literal: %RDF.Literal{value: nil, lexical: "foo", datatype: ~I<http://www.w3.org/2001/XMLSchema#integer>}

iex> RDF.Literal.new!("foo", datatype: RDF.langString)
** (RDF.Literal.InvalidError) invalid RDF.Literal: %RDF.Literal{value: "foo", datatype: ~I<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>, language: nil}

Returns if a literal is a plain literal.

A plain literal may have a language, but may not have a datatype. For all practical purposes, this includes xsd:string literals too.

see http://www.w3.org/TR/rdf-concepts/#dfn-plain-literal

Returns if a literal is a simple literal.

A simple literal has no datatype or language.

see http://www.w3.org/TR/sparql11-query/#simple_literal

Returns if the value of the given literal is a valid according to its datatype.