RDF::Closure::DatatypeHandling3pm
Validate and canonicalise typed literals
Analogous python
RDFClosure/DatatypeHandling.py
Overview
Provides datatype handling functions for OWL 2 RL and RDFS datatypes.
Functional Interface
This module can export four functions:
- •
-
"literal_canonical($lit)"Given an RDF::Trine::Node::Literal, returns a literal with the canonical lexical value for its given datatype. If the literal is not a valid lexical form for its datatype throws an Error.
If the literal is a plain literal, returns an rdf:PlainLiteral typed literal; if the literal is of an unrecognised datatype, simply returns the original literal.
Note that as per OWL 2 RL rules, xsd:dateTime literals are not shifted to UTC, even though XSD says that UTC is the canonical form. By setting the
"force_utc"to true, you can force XSD-style canonicalisation. (See the object-oriented interface.)
- •
-
"literal_canonical_safe($lit)"As per
"literal_canonical", but in the case where a literal is not a valid lexical form, simply returns the original literal.
- •
-
"literal_valid($lit)"Returns true iff the literal is a valid lexical form for its datatype. An example of an invalid literal might be:
"2011-02-29"^^xsd:date
- •
-
"literals_identical($lit1, $lit2)"Returns true iff the two literals are identical according to OWL 2 RL. Here are some example pairs that are identical:
# integers and decimals are drawn from the same pool of values"1.000"^^xsd:decimal"1"^^xsd:integer# different ways of writing the same datetime"2010-01-01T12:00:00.000Z"^^xsd:dateTime"2010-01-01T12:00:00+00:00"^^xsd:dateTimeHere are some example literals that are not identical:
# floats and decimals are drawn from different pools of values"1.000"^^xsd:float"1"^^xsd:integer# according to OWL 2 these are "equal but not identical"."2010-01-01T12:00:00+00:00"^^xsd:dateTime"2010-01-01T11:00:00-01:00"^^xsd:dateTimeThis latter example is affected by
"force_utc".
- •
-
"literal_to_perl($lit)"Returns a scalar value for the literal, or an appropriate object with overloaded operators (e.g. DateTime, Math::BigInt).
Variables $RDF, $RDFS, $OWL and $XSD may also be exported as a convenience. These are RDF::Trine::Namespace objects. Don't modify them.
Object-Oriented Interface
use RDF::Trine;use RDF::Closure::DatatypeHandling qw[$XSD];my $lit = RDF::Trine::Node::Literal->new("2010-01-01T11:00:00-01:00", undef, $XSD->dateTime);my $handler = RDF::Closure::DatatypeHandling->new(force_utc => 1);print $handler->literal_canonical($lit)->as_ntriples;
Disclaimer of warranties
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Releases
6 releases since Debian 7 (Wheezy); the text changed 3 times.