table of contents
RDF::Closure::DatatypeHandling(3pm) | User Contributed Perl Documentation | RDF::Closure::DatatypeHandling(3pm) |
NAME¶
RDF::Closure::DatatypeHandling - validate and canonicalise typed literals
ANALOGOUS PYTHON¶
RDFClosure/DatatypeHandling.py
DESCRIPTION¶
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:dateTime
Here 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:dateTime
This 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;
SEE ALSO¶
RDF::Closure.
AUTHOR¶
Toby Inkster <tobyink@cpan.org>.
COPYRIGHT¶
Copyright 2008-2011 Ivan Herman
Copyright 2011-2012 Toby Inkster
This library is free software; you can redistribute it and/or modify it under any of the following licences:
- The Artistic License 1.0 <http://www.perlfoundation.org/artistic_license_1_0>.
- The GNU General Public License Version 1 <http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt>, or (at your option) any later version.
- The W3C Software Notice and License <http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231>.
- The Clarified Artistic License <http://www.ncftp.com/ncftp/doc/LICENSE.txt>.
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.
2021-09-24 | perl v5.32.1 |