RDF.Literal (RDF.ex v0.9.1) View Source
RDF literals are leaf nodes of a RDF graph containing raw data, like strings, numbers etc.
A literal is a struct consisting of a literal
field holding either a RDF.Literal.Datatype
struct
for the respective known datatype of the literal or a RDF.Literal.Generic
struct if the datatype
is unknown, i.e. has no RDF.Literal.Datatype
implementation.
Link to this section Summary
Functions
Transforms the given literal
into its canonical form.
Returns if the lexical of the given literal
has the canonical form.
Returns the canonical lexical of the given literal
.
Coerces a new RDF.Literal
from another value.
Returns if the given value is a RDF.Literal
or RDF.Literal.Datatype
struct.
Returns the IRI of datatype of the given literal
.
Checks if two literals are equal.
Checks if two literals have equal values.
Returns if the literal uses the RDF.Literal.Generic
datatype or on of the dedicated builtin or custom RDF.Literal.Datatype
s.
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 'literal' is literal with the given datatype
.
Returns the language of the given literal
if present.
Checks if the first of two RDF.Literal
s is smaller then the other.
Returns the lexical form of the given literal
.
Matches the lexical form of the given RDF.Literal
against a XPath and XQuery regular expression pattern with flags.
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.
Updates the value of a RDF.Literal
without changing everything else.
Returns if the given literal
is valid with respect to its datatype.
Returns the value of the given literal
.
Link to this section Types
Specs
t() :: %RDF.Literal{literal: RDF.Literal.Datatype.literal()}
Link to this section Functions
Specs
Transforms the given literal
into its canonical form.
Specs
Returns if the lexical of the given literal
has the canonical form.
Specs
Returns the canonical lexical of the given literal
.
Coerces a new RDF.Literal
from another value.
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 |
Decimal | xsd:decimal |
Time | xsd:time |
Date | xsd:date |
DateTime | xsd:dateTime |
NaiveDateTime | xsd:dateTime |
URI | xsd:AnyURI |
When an RDF.Literal
can not be coerced, nil
is returned
(as opposed to new/1
which fails in this case).
Examples
iex> RDF.Literal.coerce(42)
%RDF.Literal{literal: %RDF.XSD.Integer{value: 42}}
Specs
compare(t(), t()) :: RDF.Literal.Datatype.comparison_result() | :indeterminate | nil
Returns if the given value is a RDF.Literal
or RDF.Literal.Datatype
struct.
If you simply want to check for a RDF.Literal
use pattern matching or RDF.literal?/1
.
This function is a bit slower than those and most of the time only needed when
implementing RDF.Literal.Datatype
s where you have to deal with the raw,
i.e. unwrapped RDF.Literal.Datatype
structs.
Specs
Returns the IRI of datatype of the given literal
.
Specs
Checks if two literals are equal.
Two literals are equal if they have the same datatype, value and lexical form.
Specs
Checks if two literals have equal values.
Specs
Returns if the literal uses the RDF.Literal.Generic
datatype or on of the dedicated builtin or custom RDF.Literal.Datatype
s.
Specs
Checks if the first of two RDF.Literal
s is greater then the other.
Specs
Returns if a literal is a datatyped literal.
For historical reasons, this excludes xsd:string
and rdf:langString
.
Specs
Returns if a literal is a language-tagged literal.
Checks if 'literal' is literal with the given datatype
.
datatype
can be one of the following:
- a
RDF.Literal.Datatype
module which checks if the literal is of this datatype or derived from it RDF.XSD.Numeric
which checks if the literal is one of the numeric XSD datatypes or derived of one of themRDF.XSD.Datatype
which checks if the literal is a XSD datatype or derived of one of them
Specs
Returns the language of the given literal
if present.
Specs
Checks if the first of two RDF.Literal
s is smaller then the other.
Specs
Returns the lexical form of the given literal
.
Specs
Matches the lexical form of the given RDF.Literal
against a XPath and XQuery regular expression pattern with flags.
The regular expression language is defined in XQuery 1.0 and XPath 2.0 Functions and Operators.
Specs
Creates a new RDF.Literal
of the given value and tries to infer an appropriate XSD datatype.
See coerce/1
for applied mapping of Elixir types to XSD datatypes.
Note: The RDF.literal
function is a shortcut to this function.
Examples
iex> RDF.Literal.new(42)
%RDF.Literal{literal: %RDF.XSD.Integer{value: 42}}
Specs
Creates a new RDF.Literal
with the given datatype or language tag.
Specs
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("foo")
%RDF.Literal{literal: %RDF.XSD.String{value: "foo"}}
iex> RDF.Literal.new!("foo", datatype: RDF.NS.XSD.integer)
** (RDF.Literal.InvalidError) invalid RDF.Literal: %RDF.Literal{literal: %RDF.XSD.Integer{value: nil, lexical: "foo"}, valid: false}
iex> RDF.Literal.new!("foo", datatype: RDF.langString)
** (RDF.Literal.InvalidError) invalid RDF.Literal: %RDF.Literal{literal: %RDF.LangString{language: nil, value: "foo"}, valid: false}
Specs
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.
Specs
Returns if a literal is a simple literal.
A simple literal has no datatype or language.
Updates the value of a RDF.Literal
without changing everything else.
The optional second argument allows to specify what will be passed to fun
with the :as
option,
eg. with as: :lexical
the lexical is passed to the function.
Example
iex> RDF.XSD.integer(42) |> RDF.Literal.update(fn value -> value + 1 end)
RDF.XSD.integer(43)
iex> ~L"foo"de |> RDF.Literal.update(fn _ -> "bar" end)
~L"bar"de
iex> RDF.literal("foo", datatype: "http://example.com/dt") |> RDF.Literal.update(fn _ -> "bar" end)
RDF.literal("bar", datatype: "http://example.com/dt")
iex> RDF.XSD.integer(42) |> RDF.XSD.Integer.update(
...> fn value -> value <> "1" end, as: :lexical)
RDF.XSD.integer(421)
Specs
Returns if the given literal
is valid with respect to its datatype.
Specs
Returns the value of the given literal
.