RDF.ex v0.6.1 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.
Matches the string representation of the given value against a XPath and XQuery regular expression pattern.
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
t()
View Source
t() :: module()
t() :: module()
Link to this section Functions
canonical(literal) View Source
Returns the given literal in its canonical lexical representation.
canonical?(arg1) View Source
Returns if the given literal is in its canonical lexical representation.
compare(left, right) View Source
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.
equal_value?(left, right) View Source
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
greater_than?(literal1, literal2) View Source
Checks if the first of two RDF.Literal
s is greater then the other.
Returns nil
when the given arguments are not comparable datatypes.
has_datatype?(literal) View Source
Returns if a literal is a datatyped literal.
For historical reasons, this excludes xsd:string
and rdf:langString
.
has_language?(arg1) View Source
Returns if a literal is a language-tagged literal.
less_than?(literal1, literal2) View Source
Checks if the first of two RDF.Literal
s is smaller then the other.
Returns nil
when the given arguments are not comparable datatypes.
lexical(literal) View Source
Returns the lexical representation of the given literal according to its datatype.
matches?(value, pattern, flags \\ "") View Source
Matches the string representation of the given value against a XPath and XQuery regular expression pattern.
The regular expression language is defined in XQuery 1.0 and XPath 2.0 Functions and Operators.
The pattern
and the optional flags
can be given as an Elixir string or as
xsd:string
RDF.Literal
s.
new(value) View Source
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}
new(value, opts) View Source
Creates a new RDF.Literal
with the given datatype or language tag.
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}
plain?(arg1) View Source
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.
simple?(arg1) View Source
Returns if a literal is a simple literal.
A simple literal has no datatype or language.
typed?(literal) View Source
valid?(literal) View Source
Returns if the value of the given literal is a valid according to its datatype.