| 1 |
NAME |
| 2 |
Test::RDF - Test RDF data for content, validity and equality, etc. |
| 3 |
|
| 4 |
VERSION |
| 5 |
Version 1.22 |
| 6 |
|
| 7 |
SYNOPSIS |
| 8 |
use Test::RDF; |
| 9 |
|
| 10 |
is_valid_rdf($rdf_string, $syntax, 'RDF string is valid according to selected syntax'); |
| 11 |
is_rdf($rdf_string, $syntax1, $expected_rdf_string, $syntax2, 'The two strings have the same triples'); |
| 12 |
isomorph_graphs($model, $expected_model, 'The two models have the same triples'); |
| 13 |
are_subgraphs($model1, $model2, 'Model 1 is a subgraph of model 2' ); |
| 14 |
has_uri($uri_string, $model, 'Has correct URI'); |
| 15 |
hasnt_uri($uri_string, $model, "Hasn't correct URI"); |
| 16 |
has_subject($uri_string, $model, 'Subject URI is found'); |
| 17 |
has_predicate($uri_string, $model, 'Predicate URI is found'); |
| 18 |
has_object_uri($uri_string, $model, 'Object URI is found'); |
| 19 |
has_type($uri_string, $model, 'Class URI is found'); |
| 20 |
has_literal($string, $language, $datatype, $model, 'Literal is found'); |
| 21 |
hasnt_literal($string, $language, $datatype, $model, 'Literal is not found'); |
| 22 |
pattern_target($model); |
| 23 |
pattern_ok($pattern, '$pattern found in $model'); |
| 24 |
pattern_fail($pattern, '$pattern not found in $model'); |
| 25 |
|
| 26 |
DESCRIPTION |
| 27 |
This Perl module, Test::RDF, provides tools for testing code which deals |
| 28 |
with RDF. It can test RDF for validity, check if two RDF graphs are the |
| 29 |
same, or subgraphs of each other, if a URI is or is not in a dataset, if |
| 30 |
it has certain subjects, predicates, objects or literals. It can also test |
| 31 |
to see if a full pattern is present or absent. |
| 32 |
|
| 33 |
EXPORT |
| 34 |
is_valid_rdf |
| 35 |
Use to check if the input RDF string is valid in the chosen syntax |
| 36 |
|
| 37 |
is_rdf |
| 38 |
Use to check if the input RDF strings are isomorphic (i.e. the same). |
| 39 |
|
| 40 |
isomorph_graphs |
| 41 |
Use to check if the input RDF::Trine::Models have isomorphic graphs. |
| 42 |
|
| 43 |
are_subgraphs |
| 44 |
Use to check if the first RDF::Trine::Models is a subgraph of the second. |
| 45 |
|
| 46 |
has_subject |
| 47 |
Check if the string URI passed as first argument is a subject in any of |
| 48 |
the statements given in the model given as second argument. |
| 49 |
|
| 50 |
has_predicate |
| 51 |
Check if the string URI passed as first argument is a predicate in any of |
| 52 |
the statements given in the model given as second argument. |
| 53 |
|
| 54 |
has_object_uri |
| 55 |
Check if the string URI passed as first argument is a object in any of the |
| 56 |
statements given in the model given as second argument. |
| 57 |
|
| 58 |
has_type |
| 59 |
Check if the string URI passed as first argument is an RDF class instance |
| 60 |
in any of the statements given in the model given as second argument. |
| 61 |
|
| 62 |
has_literal |
| 63 |
Check if the string passed as first argument, with corresponding optional |
| 64 |
language and datatype as second and third respectively, is a literal in |
| 65 |
any of the statements given in the model given as fourth argument. |
| 66 |
|
| 67 |
language and datatype may not occur in the same statement, so the test |
| 68 |
fails if they are both set. If none are used, use `undef`, like e.g. |
| 69 |
|
| 70 |
has_literal('A test', undef, undef, $model, 'Simple literal'); |
| 71 |
|
| 72 |
A test for a typed literal may be done like |
| 73 |
|
| 74 |
has_literal('42', undef, 'http://www.w3.org/2001/XMLSchema#integer', $model, 'Just an integer'); |
| 75 |
|
| 76 |
and a language literal like |
| 77 |
|
| 78 |
has_literal('This is a Another test', 'en', undef, $model, 'Language literal'); |
| 79 |
|
| 80 |
hasnt_literal |
| 81 |
This is like the above, only the opposite: It checks if a literal doesn't |
| 82 |
exist. Like the above, the test will fail if the literal is invalid, |
| 83 |
however. |
| 84 |
|
| 85 |
has_uri |
| 86 |
Check if the string URI passed as first argument is present in any of the |
| 87 |
statements given in the model given as second argument. |
| 88 |
|
| 89 |
hasnt_uri |
| 90 |
Check if the string URI passed as first argument is not present in any of |
| 91 |
the statements given in the model given as second argument. |
| 92 |
|
| 93 |
pattern_target |
| 94 |
Tests that the object passed as its parameter is an RDF::Trine::Model or |
| 95 |
RDF::Trine::Store. That is, tests that it is a valid thing to match basic |
| 96 |
graph patterns against. |
| 97 |
|
| 98 |
Additionally, this test establishes the target for future `pattern_ok` |
| 99 |
tests. |
| 100 |
|
| 101 |
pattern_ok |
| 102 |
Tests that the pattern passed matches against the target established by |
| 103 |
`pattern_target`. The pattern may be passed as an RDF::Trine::Pattern, or |
| 104 |
a list of RDF::Trine::Statement objects. |
| 105 |
|
| 106 |
use Test::RDF; |
| 107 |
use RDF::Trine qw[iri literal blank variable statement]; |
| 108 |
use My::Module; |
| 109 |
|
| 110 |
my $foaf = RDF::Trine::Namespace->new('http://xmlns.com/foaf/0.1/'); |
| 111 |
pattern_target(My::Module->get_model); # check isa RDF::Trine::Model |
| 112 |
pattern_ok( |
| 113 |
statement( |
| 114 |
variable('who'), |
| 115 |
$foaf->name, |
| 116 |
literal('Kjetil Kjernsmo') |
| 117 |
), |
| 118 |
statement( |
| 119 |
variable('who'), |
| 120 |
$foaf->page, |
| 121 |
iri('http://search.cpan.org/~kjetilk/') |
| 122 |
), |
| 123 |
"Data contains Kjetil's details." |
| 124 |
); |
| 125 |
|
| 126 |
Note: `pattern_target` must have been tested before any `pattern_ok` |
| 127 |
tests. |
| 128 |
|
| 129 |
pattern_fail |
| 130 |
The same as above, but tests if the pattern returns no results instead. |
| 131 |
|
| 132 |
NOTE |
| 133 |
Graph isomorphism is a complex problem, so do not attempt to run the |
| 134 |
isomorphism tests on large datasets. For more information see |
| 135 |
<http://en.wikipedia.org/wiki/Graph_isomorphism_problem>. |
| 136 |
|
| 137 |
AUTHOR |
| 138 |
Kjetil Kjernsmo, `<kjetilk at cpan.org>` |
| 139 |
|
| 140 |
BUGS |
| 141 |
Please report any bugs using github |
| 142 |
<https://github.com/kjetilk/Test-RDF/issues> |
| 143 |
|
| 144 |
SUPPORT |
| 145 |
You can find documentation for this module with the perldoc command. |
| 146 |
|
| 147 |
perldoc Test::RDF |
| 148 |
|
| 149 |
You may find the Perl and RDF community website <http://www.perlrdf.org/> |
| 150 |
useful. |
| 151 |
|
| 152 |
You can also look for information at: |
| 153 |
|
| 154 |
* AnnoCPAN: Annotated CPAN documentation |
| 155 |
|
| 156 |
<http://annocpan.org/dist/Test-RDF> |
| 157 |
|
| 158 |
* CPAN Ratings |
| 159 |
|
| 160 |
<http://cpanratings.perl.org/d/Test-RDF> |
| 161 |
|
| 162 |
* Search CPAN |
| 163 |
|
| 164 |
<http://search.cpan.org/dist/Test-RDF/> |
| 165 |
|
| 166 |
* MetaCPAN |
| 167 |
|
| 168 |
<https://metacpan.org/module/Test::RDF> |
| 169 |
|
| 170 |
ACKNOWLEDGEMENTS |
| 171 |
Michael Hendricks wrote the first Test::RDF. The present module is a |
| 172 |
complete rewrite from scratch using Gregory Todd William's |
| 173 |
RDF::Trine::Graph to do the heavy lifting. |
| 174 |
|
| 175 |
Toby Inkster has submitted the pattern_* functions. |
| 176 |
|
| 177 |
LICENSE AND COPYRIGHT |
| 178 |
Copyright 2010 ABC Startsiden AS. Copyright 2010, 2011, 2012, 2013, 2014, |
| 179 |
2015, 2017 Kjetil Kjernsmo. |
| 180 |
|
| 181 |
This program is free software; you can redistribute it and/or modify it |
| 182 |
under the terms of either: the GNU General Public License as published by |
| 183 |
the Free Software Foundation; or the Artistic License. |
| 184 |
|
| 185 |
See http://dev.perl.org/licenses/ for more information. |
| 186 |
|