RDF.ex v0.5.4 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
Compares two RDF.Literal
s
Checks if two RDF.Literal
s are equal
Checks if the first of two RDF.Literal
s 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.Literal
s is smaller then the other
Returns the lexical representation of the given literal according to its datatype
Creates a new RDF.Literal
, but fails if it’s not valid
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
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.Literal
s.
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.
Checks if two RDF.Literal
s 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
Checks if the first of two RDF.Literal
s 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
.
Returns if a literal is a language-tagged literal.
Checks if the first of two RDF.Literal
s 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
, 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}
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 datatype | XSD datatype |
---|---|
string | xsd:string |
boolean | xsd:boolean |
integer | xsd:integer |
float | xsd:double |
Time | xsd:time |
Date | xsd:date |
DateTime | xsd:dateTime |
NaiveDateTime | xsd: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.
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.
Returns if a literal is a simple literal.
A simple literal has no datatype or language.
Returns if the value of the given literal is a valid according to its datatype.