RDF::Closure(3pm)

πŸ’– RDF::Closure β€” the manual, but make it make sense πŸ’–

okay bestie, so this is the page for RDF::Closure(3pm), which lives in the User Contributed Perl Documentation corner of your system. it's about inferencing, it's pure Perl, and honestly? it eats. let's go 🌸


✨ NAME ✨

RDF::Closure β€” pure Perl RDF inferencing. that's it, that's the whole vibe. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the whole thing in action, copy it exactly bestie, don't freestyle:

use RDF::Trine::Iterator qw[sgrep];
use RDF::Closure qw[iri mk_filter FLT_NONRDF FLT_BORING];

my $data = iri('http://bloggs.example.com/foaf.rdf');
my $foaf = iri('http://xmlns.com/foaf/0.1/index.rdf');

my $model = RDF::Trine::Model->temporary_model;
my $p     = 'RDF::Trine::Parser';
$p->parse_url_into_model($data->uri, $model, context => $data->uri);
$p->parse_url_into_model($foaf->uri, $model, context => $foaf->uri);

my $cl = RDF::Closure::Engine->new('rdfs', $model);
$cl->closure;

my $filter = mk_filter(FLT_NONRDF|FLT_BORING, [$foaf]);
my $output = &sgrep($filter, $model->as_stream);

print RDF::Trine::Serializer
  ->new('RDFXML')
  ->serialize_iterator_to_string($output);

🌈 DESCRIPTION 🌈

so this distribution is a pure Perl RDF inference engine, designed as an add-in for RDF::Trine. no cap, it's largely a port of Ivan Herman's Python RDFClosure library β€” though there's been some restructuing along the way, and there are a few extras thrown in for funsies. πŸŽ€

where one of the Perl modules has a direct equivalent in Ivan's library, that's noted in the POD. iykyk. πŸ“

🧚 Functions

this package inherits from RDF::Trine and exports the same functions, plus this one absolute icon:

  • mk_filter($basic_filters, $ignore_contexts) β€” creates a filter (coderef) that's suitable for use with sgrep from RDF::Trine::Iterator. yes, a coderef. we love a callback. πŸ’…

$basic_filters is an integer, and you build it up by bitwise-OR-ing the constants FLT_NONRDF and FLT_BORING together. bitwise-OR? iconic. 🫢

$ignore_contexts is an arrayref of RDF::Trine::Node objects β€” each one represents a context that should be filtered out. bye girl, not you. πŸ‘‹

like, for example:

use RDF::Trine::Iterator qw[sgrep];
use RDF::Closure qw[iri mk_filter FLT_NONRDF FLT_BORING];

my $foaf   = iri('http://xmlns.com/foaf/0.1/index.rdf');
my $filter = mk_filter(FLT_NONRDF|FLT_BORING, [$foaf]);

my $remaining = &sgrep($filter, $model->as_stream);

# $remaining is now an iterator which will return all triples
# from $model except: those in the FOAF named graph, those which
# are non-RDF (e.g. literal subject) and those which are boring.

so $remaining comes back as an iterator that hands you every triple from $model except:

  • the ones in the FOAF named graph 🌸
  • the ones that are non-RDF (like, a literal subject? girl.) πŸ’€
  • and the ones that are just plain boring πŸ™ˆ

which triples are boring, you ask? ok so listen. any triple shaped like { ?x owl:sameAs ?x .}, { ?x owl:equivalentProperty ?x .}, { ?x owl:equivalentClass ?x .}, { ?x rdfs:subPropertyOf ?x .} or { ?x rdfs:subClassOf ?x .} is boring β€” that means the same term is sitting in both subject and object position. also, any triple where the subject, predicate and object nodes are all hanging out in the RDF, RDFS, OWL or XSD namespaces? boring. everything else is not boring. those are the rules, periodt. ⭐

and for convenience, RDF::Closure also exports variables called $RDF, $RDFS, $OWL and $XSD β€” they're RDF::Trine::Namespace objects. little gifts. 🎁


πŸ‘‘ SEE ALSO πŸ‘‘

  • RDF::Closure::Engine
  • RDF::Closure::Model
  • RDF::Trine::Parser::OwlFn

also: RDF::Trine, RDF::Query.

and the links, bestie:


πŸ’œ AUTHOR πŸ’œ

Toby Inkster <tobyink@cpan.org>. king behavior, honestly. πŸ‘‘


Copyright 2011-2012 Toby Inkster

This library is free software; you can redistribute it and/or modify it under any of the following licences β€” yes, any of them, pick your fighter:

  1. The Artistic License 1.0 <http://www.perlfoundation.org/artistic_license_1_0>.
  2. 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.
  3. The W3C Software Notice and License <http://www.consortium/Legal/2002/copyright-software-20021231>. β€” wait no bestie, exact link: <http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231>.
  4. The Clarified Artistic License <http://www.ncftp.com/ncftp/doc/LICENSE.txt>.

πŸ’€ DISCLAIMER OF WARRANTIES πŸ’€

ok so this is the part where we yell. 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.

like. no promises. none. zero. nada. it's giving "you're on your own but with love". 😭


and that's the whole page, bestie! this was perl v5.32.1, dated 2021-09-24, and it's the RDF::Closure(3pm) manual. go forth and infer. slay. βœ¨πŸ’–πŸŒˆ
πŸ“¦ where this page comes from