RDF::C...ndling(3pm)
β¨ NAME β¨
RDF::Closure::DatatypeHandling β bestie, this one validates and canonicalises typed literals. That's the whole job. She's a specialist. π
π ANALOGOUS PYTHON π
RDFClosure/DatatypeHandling.py
(yes she has a python cousin, they're giving sibling energy)
π DESCRIPTION π
So this module hands you datatype handling functions for OWL 2 RL and RDFS datatypes. That's it, that's the vibe. π
πΈ Functional Interface πΈ
You can export four functions from this module:
literal_canonical($lit)β give it anRDF::Trine::Node::Literaland it hands back a literal whose lexical value is the canonical one for whatever datatype that literal claims. But heads up: if the literal isn't a valid lexical form for its datatype, it throws an Error. Not a vibe, but okay.
If you pass a plain literal, you get back an rdf:PlainLiteral typed literal. If the datatype is one she doesn't recognise, she just returns the original literal, no notes.
Also, real talk: as per OWL 2 RL rules, xsd:dateTime literals are not shifted to UTC, even though XSD says UTC is the canonical form. If you want that XSD-style canonicalisation anyway, set force_utc to true. (Peep the object-oriented interface below for how.)
literal_canonical_safe($lit)β literally the same asliteral_canonical, except when the literal is not a valid lexical form she just returns the original literal instead of throwing. She's chill like that. π«Άliteral_valid($lit)β returns true iff the literal is a valid lexical form for its datatype. Example of one that is not valid:
"2011-02-29"^^xsd:date
literals_identical($lit1, $lit2)β returns true iff the two literals are identical according to OWL 2 RL. Here's some identical pairs, look at them:
# 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
And here's some 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
That last one is affected by force_utc. ikyk. π
literal_to_perl($lit)β returns a scalar value for the literal, or an appropriate object with overloaded operators (thinkDateTime,Math::BigInt).
Bonus: the variables $RDF, $RDFS, $OWL and $XSD can also be exported as a convenience. They're RDF::Trine::Namespace objects.
π¨ Do not modify them. Don't do it. Not even a little. Leave the namespaces alone bestie. π
π¦ 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.
ngl that's the whole warranty, there is no more warranty, this is it, periodt. π
okay that's the page!! brought to you by perl v5.32.1, dated 2021-09-24, from the User Contributed Perl Documentation corner of the internet. slay, go canonicalise some literals, mwah πβ¨π
π¦ where this page comes from
- debian bookworm: librdf-closure-perl 0.001-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: librdf-closure-perl 0.001-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: librdf-closure-perl 0.001-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: librdf-closure-perl 0.001-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: librdf-closure-perl 0.001-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: librdf-closure-perl 0.001-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms