Test::RDF(3pm)
π Test::RDF π
okay so bestie, this is the manual page for Test::RDF, living in the User Contributed Perl Documentation corner of your perldoc, and it is literally the glow-up you need if you're out here testing RDF data. Content, validity, equality β it does it all. β¨
β¨ NAME β¨
Test::RDF β test RDF data for content, validity and equality, etc. π¦
πΈ VERSION πΈ
Version 1.22 π
π SYNOPSIS π
here's the whole vibe in one code block, no cap:
use Test::RDF;
is_valid_rdf($rdf_string, $syntax, 'RDF string is valid according to selected syntax');
is_rdf($rdf_string, $syntax1, $expected_rdf_string, $syntax2, 'The two strings have the same triples');
isomorph_graphs($model, $expected_model, 'The two models have the same triples');
are_subgraphs($model1, $model2, 'Model 1 is a subgraph of model 2' );
has_uri($uri_string, $model, 'Has correct URI');
hasnt_uri($uri_string, $model, "Hasn't correct URI");
has_subject($uri_string, $model, 'Subject URI is found');
has_predicate($uri_string, $model, 'Predicate URI is found');
has_object_uri($uri_string, $model, 'Object URI is found');
has_type($uri_string, $model, 'Class URI is found');
has_literal($string, $language, $datatype, $model, 'Literal is found');
hasnt_literal($string, $language, $datatype, $model, 'Literal is not found');
pattern_target($model);
pattern_ok($pattern, '$pattern found in $model');
pattern_fail($pattern, '$pattern not found in $model');
like, all your faves in one place. iconic. π
π DESCRIPTION π
so this Perl module, Test::RDF, hands you the tools for testing code that deals with RDF. it can check whether RDF is valid, whether two RDF graphs are the same, or whether one is a subgraph of the other, whether a URI is or is not chilling in a dataset, whether that dataset has certain subjects, predicates, objects or literals. and yeah β it can also test whether a full pattern is present or absent. vibe check: passed. β¨
π EXPORT π
is_valid_rdf
use this one to check if the input RDF string is valid in the chosen syntax. π―
is_rdf
use this one to check if the input RDF strings are isomorphic β i.e. the same. πͺ
isomorph_graphs
use this one to check if the input RDF::Trine::Models have isomorphic graphs.
are_subgraphs
use this one to check if the first RDF::Trine::Models is a subgraph of the second. πͺ
has_subject
checks if the string URI you passed as the first argument is a subject in any of the statements given in the model you passed as the second argument.
has_predicate
checks if the string URI you passed as the first argument is a predicate in any of the statements given in the model you passed as the second argument.
has_object_uri
checks if the string URI you passed as the first argument is a object in any of the statements given in the model you passed as the second argument. (yes, "a object", the original said it, we're keeping it, it's cute π₯°)
has_type
checks if the string URI you passed as the first argument is an RDF class instance in any of the statements given in the model you passed as the second argument.
has_literal
checks if the string passed as the first argument β with the corresponding optional language and datatype as second and third respectively β is a literal in any of the statements given in the model passed as the fourth argument.
β οΈ heads up bestie: language and datatype may not occur in the same statement, so the test fails if they're both set. if you're not using either one, pass undef, like this:
has_literal('A test', undef, undef, $model, 'Simple literal');
a test for a typed literal looks like this:
has_literal('42', undef, 'http://www.w3.org/2001/XMLSchema#integer', $model, 'Just an integer');
and a language literal like this:
has_literal('This is a Another test', 'en', undef, $model, 'Language literal');
hasnt_literal
this is like the one above, only the opposite: it checks if a literal doesn't exist. but like the one above, the test will still fail if the literal is invalid, so don't get cute with it. π
has_uri
checks if the string URI passed as the first argument is present in any of the statements given in the model given as the second argument.
hasnt_uri
checks if the string URI passed as the first argument is not present in any of the statements given in the model given as the second argument.
pattern_target
tests that the object passed as its parameter is an RDF::Trine::Model or RDF::Trine::Store. that is, it tests that it's a valid thing to match basic graph patterns against. β¨
on top of that, this test establishes the target for future pattern_ok tests. main character energy, honestly.
pattern_ok
tests that the pattern passed matches against the target established by pattern_target. the pattern may be passed as an RDF::Trine::Pattern, or a list of RDF::Trine::Statement objects.
use Test::RDF;
use RDF::Trine qw[iri literal blank variable statement];
use My::Module;
my $foaf = RDF::Trine::Namespace->new('http://xmlns.com/foaf/0.1/');
pattern_target(My::Module->get_model); # check isa RDF::Trine::Model
pattern_ok(
statement(
variable('who'),
$foaf->name,
literal('Kjetil Kjernsmo')
),
statement(
variable('who'),
$foaf->page,
iri('http://search.cpan.org/~kjetilk/')
),
"Data contains Kjetil's details."
);
Note:pattern_targetmust have been tested before anypattern_oktests. do not skip this step, bestie, it will not go well. π
pattern_fail
the same as above, but tests if the pattern returns no results instead. π
π NOTE π
graph isomorphism is a complex problem, so do not attempt to run the isomorphism tests on large datasets. for more information see <http://en.wikipedia.org/wiki/Graph_isomorphism_problem>. like, fr fr, don't do it. π
βοΈ AUTHOR βοΈ
Kjetil Kjernsmo, "<kjetilk at cpan.org>" πΈ
π BUGS π
please report any bugs using github <https://github.com/kjetilk/Test-RDF/issues> π«Ά
π« SUPPORT π«
you can find documentation for this module with the perldoc command.
perldoc Test::RDF
you may find the Perl and RDF community website <http://www.perlrdf.org/> useful.
you can also look for information at:
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/Test-RDF>
- CPAN Ratings
<http://cpanratings.perl.org/d/Test-RDF>
- Search CPAN
<http://search.cpan.org/dist/Test-RDF/>
- MetaCPAN
<https://metacpan.org/module/Test::RDF>
π ACKNOWLEDGEMENTS π
Michael Hendricks wrote the first Test::RDF. the present module is a complete rewrite from scratch using Gregory Todd William's RDF::Trine::Graph to do the heavy lifting. πͺ
Toby Inkster has submitted the pattern_* functions. absolute legend. π
βοΈ LICENSE AND COPYRIGHT βοΈ
Copyright 2010 ABC Startsiden AS. Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2017 Kjetil Kjernsmo.
this program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
see <http://dev.perl.org/licenses/> for more information.
and that's the whole page, bestie!! πβ¨ this beauty ships as perl v5.34.0, dated 2022-06-28 β so if you ever need to cite it, that's the vibe check timestamp. go forth and test your RDF, you're gonna slay. ππ¦π
π¦ where this page comes from
- debian bookworm: libtest-rdf-perl 1.22-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-rdf-perl 1.22-2 Β· 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