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 an RDF::Trine::Node::Literal and 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 as literal_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 (think DateTime, 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.

<http://www.perlrdf.org/>.


πŸŽ€ AUTHOR πŸŽ€

Toby Inkster <tobyink@cpan.org>.


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:


πŸ’€ 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