RDF-LDF-0.25000755000765000024 013547041572 12565 5ustar00hochstenstaff000000000000README100644000765000024 450613547041572 13533 0ustar00hochstenstaff000000000000RDF-LDF-0.25NAME RDF::LDF - Linked Data Fragments client SYNOPSIS use RDF::Trine::Store::LDF; use RDF::Trine::Store; # To use a HTTP cache: use LWP::UserAgent::CHICaching; my $cache = CHI->new( driver => 'Memory', global => 1 ); my $ua = LWP::UserAgent::CHICaching->new(cache => $cache); RDF::Trine->default_useragent($ua); my $store = RDF::Trine::Store->new_with_config({ storetype => 'LDF', url => $url }); my $it = $store->get_statements(); while (my $st = $it->next) { # $st is a RDF::Trine::Statement print "$st\n"; } # Or the low level modules themselves use RDF::LDF; my $client = RDF::LDF->new(url => 'http://fragments.dbpedia.org/2014/en'); my $iterator = $client->get_statements($subject, $predicate, $object); while (my $statement = $iterator->()) { # $model is a RDF::Trine::Statement } DESCRIPTION RDF::LDF implements a basic Linked Data Fragment client. This a low level module to implement the Linked Data Fragment protocol. You probably want to use RDF::Trine::Store::LDF. CONFIGURATION url URL to retrieve RDF from. Experimental: more than one URL can be provided for federated search over many LDF endpoints. my $store = RDF::Trine::Store->new_with_config({ storetype => 'LDF', url => [ $url1, $url2, $url3 ] }); # or my $client = RDF::LDF->new(url => [ $url1, $url2, $url3 ]); METHODS get_statements( $subject, $predicate, $object ) Return an iterator for every RDF::Trine::Statement served by the LDF server. get_pattern( $bgp ); Returns a stream object of all bindings matching the specified graph pattern. CONTRIBUTORS Patrick Hochstenbach, patrick.hochstenbach at ugent.be Gregory Todd Williams, greg@evilfunhouse.com Jacob Voss, voss@gbv.de COPYRIGHT AND LICENSE This software is copyright (c) 2015 by Patrick Hochstenbach. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Changes100644000765000024 474713547041572 14155 0ustar00hochstenstaff000000000000RDF-LDF-0.25Revision history for RDF::LDF 0.25 2019-10-08 10:06:15 CEST - Adding missing dependencies [manwar] 0.24 2018-05-30 13:00:57 CEST - Release 0.24 0.23_01 2018-05-28 14:59:17 CEST - Update to use hydra:template rather than VoID 0.23 2017-05-09 14:35:20 CEST - Fixing changing state of global RDF::Trine useragent bug 0.22 2016-05-12 16:24:47 CEST - Fixing stale hydra statements which end up in result set 0.21 2016-04-04 10:52:38 CEST - Better handling of accept headers 0.20 2016-04-04 10:50:12 CEST - Better handling of accept headers 0.19 2016-03-31 20:47:34 CEST - Update page predicates to latest Hydra spec which breaks existing LDF clients 0.18 2016-03-16 11:46:48 CET - Removing the caching component into a separate module 0.17 2016-02-22 10:36:32 CET - Removing Data::Util dependency 0.16 2015-12-10 09:38:40 CET - Fix missing JSON-LD support bug 0.15 2015-06-24 16:04:14 CEST - Provide better UTF8 tests and updated the documentation - Add support for federated queries 0.14 2015-05-27 11:37:24 CEST - Make LDF parser more forgiving for UTF-8 errors in the http response 0.13 2015-05-27 09:27:30 CEST - Fixing utf8 problem 0.12 2015-05-22 09:54:00 CEST - Requiring minimal RDF::NS for the REVERSE method 0.11 2015-05-22 09:32:21 CEST - Downgrading Perl dependencies 0.10 2015-05-21 10:18:52 CEST - Deleting some dependencies 0.09 2015-05-06 13:03:50 CEST - Minor fixed in build scripts 0.08 2015-04-24 09:53:02 CEST - Fixing command line creating JSON as output 0.07 2015-03-18 11:09:23 CET - Fixing missing Throwable - Fixing UTF-8 security bug in File::Slurp 0.06 2015-03-16 13:10:10 CET - Update requirements for HTTP::Message - Fixing Error and Moo conflict 0.05 2015-02-26 21:35:38 CET - adding better error handling - Catmandu::Error->throw is called but not loaded - use RDF::Trine::Parser to load URL contents into a model - use URI::Template in constructing fragment URLs - Improved use of RDF::Trine user agent and added mocked network tests - Enabled more get_pattern tests - Network test are optional with RDFLDF_NETWORK_TESTS=1 0.04 2015-02-23 16:38:51 CET - fixing the non-zero results bug - adding example sparql for testing 0.03 2015-02-23 15:09:04 CET - adding RDF::Trine::Store support - adding a ldf-client.pl command line client - provide example sparql queries 0.02 2015-02-19 20:24:24 CET - adding required modules in cpanfile 0.01 2015-02-19 10:48:34 CET - initial release LICENSE100644000765000024 4370513547041572 13704 0ustar00hochstenstaff000000000000RDF-LDF-0.25This software is copyright (c) 2015 by Patrick Hochstenbach. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2015 by Patrick Hochstenbach. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2015 by Patrick Hochstenbach. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. 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. The End cpanfile100644000765000024 143413547041572 14354 0ustar00hochstenstaff000000000000RDF-LDF-0.25requires 'perl', 'v5.10.1'; on 'test', sub { requires 'Test::Deep', 0; requires 'Test::Exception', 0; requires 'Test::More', '0'; requires 'Test::Pod', 0; requires 'Test::LWP::UserAgent', 0; requires 'Encode', 0; }; requires 'Cache::LRU', 0; requires 'Clone', 0; requires 'Data::Compare', 0; requires 'Getopt::Long', 0; requires 'HTTP::Message', 0; requires 'JSON', 0; requires 'Log::Any', 0; requires 'Moo', 0; requires 'LWP::UserAgent', 0; requires 'RDF::NS', '20150725'; requires 'RDF::Query', 0; requires 'RDF::Trine', 0; requires 'Throwable', 0; requires 'URI::Escape', 0; requires 'URI::Template', 0; requires 'LWP::UserAgent::CHICaching', 0; recommends 'Log::Any', '1.00'; recommends 'Moo', '1.004006'; recommends 'RDF::Query', '2.913'; recommends 'RDF::Trine', '1.013'; Build.PL100644000765000024 25413547041572 14123 0ustar00hochstenstaff000000000000RDF-LDF-0.25# This Build.PL for RDF-LDF was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.015. use strict; use warnings; use v5.10.1; use Module::Build::Tiny 0.034; Build_PL(); META.yml100644000765000024 306213547041572 14120 0ustar00hochstenstaff000000000000RDF-LDF-0.25--- abstract: 'Linked Data Fragments client' author: - 'Patrick Hochstenbach' build_requires: Encode: '0' Test::Deep: '0' Test::Exception: '0' Test::LWP::UserAgent: '0' Test::More: '0' Test::Pod: '0' configure_requires: Module::Build::Tiny: '0.034' dynamic_config: 0 generated_by: 'Dist::Milla version v1.0.17, Dist::Zilla version 6.008, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: RDF-LDF no_index: directory: - eg - examples - inc - share - t - xt recommends: Log::Any: '1.00' Moo: '1.004006' RDF::Query: '2.913' RDF::Trine: '1.013' requires: Cache::LRU: '0' Clone: '0' Data::Compare: '0' Getopt::Long: '0' HTTP::Message: '0' JSON: '0' LWP::UserAgent: '0' LWP::UserAgent::CHICaching: '0' Log::Any: '0' Moo: '0' RDF::NS: '20150725' RDF::Query: '0' RDF::Trine: '0' Throwable: '0' URI::Escape: '0' URI::Template: '0' perl: v5.10.1 resources: bugtracker: https://github.com/phochste/RDF-LDF/issues homepage: https://github.com/phochste/RDF-LDF repository: https://github.com/phochste/RDF-LDF.git version: '0.25' x_contributors: - 'Edward Betts ' - 'Gregory Todd Williams ' - 'Jakob Voß ' - 'Jakob Voss ' - 'Kjetil Kjernsmo ' - 'Mohammad S Anwar ' - 'Patrick Hochstenbach ' x_serialization_backend: 'YAML::Tiny version 1.69' MANIFEST100644000765000024 100513547041572 13773 0ustar00hochstenstaff000000000000RDF-LDF-0.25# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.008. Build.PL Changes LICENSE MANIFEST MANIFEST.SKIP META.json META.yml README bin/ldf-client.pl cpanfile demo/sparql01.txt demo/sparql02.txt demo/sparql03.txt demo/sparql04.txt demo/sparql05.txt demo/sparql06.txt demo/sparql07.txt demo/sparql08.txt demo/sparql09.txt lib/RDF/LDF.pm lib/RDF/LDF/Error.pm lib/RDF/Trine/Store/LDF.pm t/LDF-pattern-federated.t t/LDF-pattern.t t/RDF-LDF.t t/RDF-Trine-Store-LDF.t t/author-pod-syntax.t t/basic.t t000755000765000024 013547041572 12751 5ustar00hochstenstaff000000000000RDF-LDF-0.25basic.t100644000765000024 25013547041572 14334 0ustar00hochstenstaff000000000000RDF-LDF-0.25/tuse strict; use warnings; use Test::More; use Test::Exception; use JSON (); my $pkg; BEGIN { $pkg = 'RDF::LDF'; use_ok $pkg; } require_ok $pkg; done_testing; META.json100644000765000024 525013547041572 14271 0ustar00hochstenstaff000000000000RDF-LDF-0.25{ "abstract" : "Linked Data Fragments client", "author" : [ "Patrick Hochstenbach" ], "dynamic_config" : 0, "generated_by" : "Dist::Milla version v1.0.17, Dist::Zilla version 6.008, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "RDF-LDF", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.034" } }, "develop" : { "requires" : { "Dist::Milla" : "v1.0.17", "Test::Pod" : "1.41" } }, "runtime" : { "recommends" : { "Log::Any" : "1.00", "Moo" : "1.004006", "RDF::Query" : "2.913", "RDF::Trine" : "1.013" }, "requires" : { "Cache::LRU" : "0", "Clone" : "0", "Data::Compare" : "0", "Getopt::Long" : "0", "HTTP::Message" : "0", "JSON" : "0", "LWP::UserAgent" : "0", "LWP::UserAgent::CHICaching" : "0", "Log::Any" : "0", "Moo" : "0", "RDF::NS" : "20150725", "RDF::Query" : "0", "RDF::Trine" : "0", "Throwable" : "0", "URI::Escape" : "0", "URI::Template" : "0", "perl" : "v5.10.1" } }, "test" : { "requires" : { "Encode" : "0", "Test::Deep" : "0", "Test::Exception" : "0", "Test::LWP::UserAgent" : "0", "Test::More" : "0", "Test::Pod" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/phochste/RDF-LDF/issues" }, "homepage" : "https://github.com/phochste/RDF-LDF", "repository" : { "type" : "git", "url" : "https://github.com/phochste/RDF-LDF.git", "web" : "https://github.com/phochste/RDF-LDF" } }, "version" : "0.25", "x_contributors" : [ "Edward Betts ", "Gregory Todd Williams ", "Jakob Vo\u00df ", "Jakob Voss ", "Kjetil Kjernsmo ", "Mohammad S Anwar ", "Patrick Hochstenbach " ], "x_serialization_backend" : "Cpanel::JSON::XS version 4.12" } RDF-LDF.t100644000765000024 605013547041572 14315 0ustar00hochstenstaff000000000000RDF-LDF-0.25/tuse open ':std', ':encoding(utf8)'; use strict; use warnings; use Test::More; use Test::Exception; use RDF::LDF; use Test::LWP::UserAgent; RDF::Trine->default_useragent(user_agent()); my $client = RDF::LDF->new(url => 'http://fragments.dbpedia.org/2014/en'); ok $client , 'got a client to http://fragments.dbpedia.org/2014/en'; ok $client->is_fragment_server , 'this server is a ldf server'; my $it = $client->get_statements(); ok $it , 'got an iterator on the compelete database'; my $triple = $it->(); ok $triple , 'got a triple'; isa_ok $triple , 'RDF::Trine::Statement' , 'triple is an RDF::Trine::Statement'; my ($triple2,$info) = $it->(); ok $info , 'got ldf metadata'; ok $info->{void_triples} , 'got lotsa triples'; throws_ok { $client->get_pattern() } 'RDF::LDF::Error' , 'throws on empty pattern'; done_testing; sub user_agent { my $DBPEDIA_FRAGMENT = <<'END'; @prefix rdf: . @prefix skos: . @prefix dc: . @prefix hydra: . @prefix void: . @prefix dc11: . @prefix foaf: . dc11:rights ; foaf:thumbnail . hydra:member . dc:description "Triple Pattern Fragment of the 'DBpedia 2014' dataset containing triples matching the pattern { ?s ?p ?o }."@en ; dc:source ; dc:title "Linked Data Fragment of DBpedia 2014"@en ; void:subset ; void:triples 367999560 ; a hydra:Collection, hydra:PagedCollection ; hydra:first ; hydra:itemsPerPage 100 ; hydra:next ; hydra:totalItems 367999560 . void:subset ; void:uriLookupEndpoint "http://fragments.dbpedia.org/2014/en{?subject,predicate,object}" ; a void:Dataset, hydra:Collection ; hydra:search [ hydra:mapping [ hydra:property rdf:object ; hydra:variable "object" ], [ hydra:property rdf:predicate ; hydra:variable "predicate" ], [ hydra:property rdf:subject ; hydra:variable "subject" ] ; hydra:template "http://fragments.dbpedia.org/2014/en{?subject,predicate,object}" ] . END my $ua = Test::LWP::UserAgent->new( agent => "RDF:::LDF/$RDF::LDF::VERSION" ); $ua->map_response( qr{http://fragments.dbpedia.org/2014/en}, HTTP::Response->new('200', 'OK', ['Content-Type' => 'text/plain'], $DBPEDIA_FRAGMENT)); return $ua; } MANIFEST.SKIP100644000765000024 1113547041572 14474 0ustar00hochstenstaff000000000000RDF-LDF-0.25dist.ini RDF000755000765000024 013547041572 13667 5ustar00hochstenstaff000000000000RDF-LDF-0.25/libLDF.pm100644000765000024 4527413547041572 15026 0ustar00hochstenstaff000000000000RDF-LDF-0.25/lib/RDFpackage RDF::LDF; use strict; use warnings; use feature qw(state); use utf8; use Moo; use Data::Compare; use RDF::NS; use RDF::Trine; use RDF::Query; use URI::Escape; use LWP::UserAgent; use HTTP::Request::Common; use Log::Any (); use Cache::LRU; use Clone qw(clone); use JSON; use URI::Template; use RDF::LDF::Error; our $VERSION = '0.25'; has url => ( is => 'ro' , required => 1 ); has sn => ( is => 'ro' , lazy => 1, builder => sub { RDF::NS->new->REVERSE; } ); has lru => ( is => 'ro' , lazy => 1, builder => sub { Cache::LRU->new( size => 100 ); } ); has log => ( is => 'ro', lazy => 1, builder => sub { Log::Any->get_logger(category => ref(shift)); } ); # Public method sub is_fragment_server { my $self = shift; my $federated = ref($self->url) ? $self->url : [ $self->url ]; for my $part (@$federated) { return 0 unless $self->get_query_pattern($part); } return 1; } # Public method # Optimized method to find all bindings matching a pattern # See: # Verborgh, Ruben, et al. Querying Datasets on the Web with High Availability. ISWC2014 # http://linkeddatafragments.org/publications/iswc2014.pdf sub get_pattern { my ($self,$bgp,$context,%args) = @_; unless (defined $bgp) { RDF::LDF::Error->throw(text => "can't execute get_pattern for an empty pattern"); } my (@triples) = ($bgp->isa('RDF::Trine::Statement') or $bgp->isa('RDF::Query::Algebra::Filter')) ? $bgp : $bgp->triples; unless (@triples) { RDF::LDF::Error->throw(text => "can't execute get_pattern for an empty pattern"); } my @vars = $bgp->referenced_variables; my @bgps = map { $self->_parse_triple_pattern($_)} @triples; my $sub = sub { state $it = $self->_find_variable_bindings(\@bgps); my $b = $it->(); return undef unless $b; my $binding = RDF::Trine::VariableBindings->new({}); for my $key (keys %$b) { my $val = $b->{$key}; $key =~ s{^\?}{}; $binding->set($key => $val); } $binding; }; RDF::Trine::Iterator::Bindings->new($sub,\@vars); } sub _find_variable_bindings { my $self = shift; my $bgps = shift; my $bindings = shift // {}; my $iterator = sub { state $it; state $results = sub {}; my $ret; # Loop over all variabe bindings with multiple matches while (!defined($ret = $results->())) { unless (defined $it) { # Find the an binding iterator for the best pattern from $bgpgs ($it,$bgps) = $self->_find_variable_bindings_($bgps); return undef unless $it; } # Update all the other bgps with the current binding.. my $this_binding = $it->(); return undef unless $this_binding; $bindings = { %$bindings , %$this_binding }; return $bindings unless @$bgps; # Apply all the bindings to the rest of the bgps; my $bgps_prime = $self->_apply_binding($this_binding,$bgps); $results = $self->_find_variable_bindings($bgps_prime,$bindings); } $ret; }; $iterator; } # Given an array ref of patterns return the variable bindings for the # pattern with the least number of triples. # # my ($iterator, $rest) = $self->_find_variable_bindings([ {pattern} , {pattern} , ... ]); # # where: # # $iterator - Iterator for variable bindings for the winnnig pattern, or undef when no # patterns are provided or we get zero results # # $rest - An array ref of patterns not containing the best pattern sub _find_variable_bindings_ { my ($self,$bgps) = @_; return (undef, undef) unless _is_array_ref($bgps) && @$bgps > 0; my ($pattern,$rest) = $self->_find_best_pattern($bgps); return (undef,undef) unless defined $pattern; my $it = $self->get_statements($pattern); # Build a mapping of variable bindings to Triple nodes. E.g. # { # '?s' => 'subject' , # '?p' => 'predicate' , # '?o' => 'object' , #} my %pattern_var_map = map { $pattern->{$_} =~ /^\?/ ? ($pattern->{$_} , $_) : () } keys %$pattern; my $num_of_bindings = keys %pattern_var_map; my $sub = sub { my $triple = $it->(); return undef unless defined $triple; my %var_map = %pattern_var_map; for (keys %var_map) { my $method = $var_map{$_}; $var_map{$_} = $triple->$method; } return {%var_map}; }; return ($sub,$rest); } sub _apply_binding { my ($self,$binding,$bgps) = @_; return unless _is_array_ref($bgps) && @$bgps > 0; my $copy = clone $bgps; my @new = (); for my $pattern (@$copy) { for (qw(subject predicate object)) { my $val = $pattern->{$_}; if (defined($val) && $binding->{$val}) { my $str_val = $self->_node_as_string($binding->{$val}); $pattern->{$_} = $str_val } } push @new, $pattern; } return \@new; } # Create a pattern which binds to the graph pattern # # Usage: # # my $triples = [ # { subject => ... , predicate => ... , object => ... } , #tp1 # { subject => ... , predicate => ... , object => ... } , #tp2 # ... # { subject => ... , predicate => ... , object => ... } , #tpN # ]; # # my ($pattern, $rest) = $self->_find_best_pattern($triples); # # $pattern => Pattern in $triples which least amount of results # $rest => All patterns in $triples except $pattern # sub _find_best_pattern { my ($self,$triples) = @_; return undef unless @$triples > 0; # If we only have one tripple pattern, the use it to create the bind if (@$triples == 1) { return $triples->[0] , []; } my $best_pattern = undef; my $best_count = undef; for my $pattern (@$triples) { my $count = $self->_total_triples($pattern) // 0; if ($count == 0) { $best_pattern = undef; $best_count = 0; last; } elsif (!defined $best_count || $count < $best_count) { $best_count = $count; $best_pattern = $pattern; } } return (undef,$triples) unless defined $best_pattern; my @rest_triples = map { Data::Compare::Compare($_,$best_pattern) ? () : ($_) } @$triples; return ($best_pattern, \@rest_triples); } # Find the total number of triples available for a pattern # # Usage: # # my $count = $self->_total_triples( # { subject => ... , predicate => ... , object => ...} # ); # Where # $count is a number sub _total_triples { my ($self,$pattern) = @_; # Retrieve one... my $iterator = $self->get_statements($pattern); return 0 unless $iterator; my ($model,$info) = $iterator->(); $info->{hydra_totalItems}; } sub _node_as_string { my $self = shift; my $node = shift; if (_is_blessed($node) && $node->isa('RDF::Trine::Node')) { if ($node->isa('RDF::Trine::Node::Variable')) { return $node->as_string; # ?foo } elsif ($node->isa('RDF::Trine::Node::Literal')) { return $node->as_string; # includes quotes and any language or datatype } else { return $node->value; # the raw IRI or blank node identifier value, without other syntax } } return ''; } # For an BGP triple create a fragment pattern sub _parse_triple_pattern { my ($self,$triple) = @_; my $subject = $self->_node_as_string($triple->subject); my $predicate = $self->_node_as_string($triple->predicate); my $object = $self->_node_as_string($triple->object); my $hash = { subject => $subject , predicate => $predicate, object => $object }; return $hash; } # Dynamic find out which triple patterns need to be used to query the fragment server # Returns a hash: # { # rdf_subject => , # rdf_predicate => , # rdf_object => # hydra_template => # } sub get_query_pattern { my ($self,$url) = @_; my $fragment = $self->get_model_and_info($url); return undef unless defined $fragment; my $info = $fragment->{info}; my $pattern; return undef unless _is_hash_ref($info); return undef unless $info->{hydra_template}; for (keys %$info) { next unless _is_hash_ref($info->{$_}) && $info->{$_}->{hydra_property}; my $property = join "_" , $self->sn->qname($info->{$_}->{hydra_property}); my $variable = $info->{$_}->{hydra_variable}; $pattern->{$property} = $variable; } return undef unless $pattern->{rdf_subject}; return undef unless $pattern->{rdf_predicate}; return undef unless $pattern->{rdf_object}; $pattern->{hydra_template} = $info->{hydra_template}; $pattern; } #---------------------------------------------------------------------------------- # Public method sub get_statements { my ($self,@triple) = @_; my ($subject,$predicate,$object); if (@triple == 3) { ($subject,$predicate,$object) = @triple; } elsif (_is_hash_ref($triple[0])) { $subject = $triple[0]->{subject}; $predicate = $triple[0]->{predicate}; $object = $triple[0]->{object}; } $subject = $subject->value if (_is_blessed($subject) && $subject->isa('RDF::Trine::Node') and not $subject->is_variable); $predicate = $predicate->value if (_is_blessed($predicate) && $predicate->isa('RDF::Trine::Node') and not $predicate->is_variable); if (_is_blessed($object) && $object->isa('RDF::Trine::Node') and not $object->is_variable) { $object = ($object->isa('RDF::Trine::Node::Literal')) ? $object->as_string : $object->value; } # Do a federated search over all the URLs provided my $parts = ref($self->url) ? $self->url : [ $self->url ]; my @federated; for my $part (@$parts) { my $pattern = $self->get_query_pattern($part); return undef unless defined $pattern; my %params; $params{ $pattern->{rdf_subject} } = $subject if _is_string($subject); $params{ $pattern->{rdf_predicate} } = $predicate if _is_string($predicate); $params{ $pattern->{rdf_object} } = $object if _is_string($object); my $template = URI::Template->new($pattern->{hydra_template}); push @federated , $template->process(%params)->as_string; } my $sub = sub { state $model; state $info; state $iterator; state $url = shift(@federated); my $triple; do { unless (defined $model) { # When no more result pages are available switch # to the next federated url... return unless defined($url) || defined($url = pop(@federated)); my $fragment = $self->get_model_and_info($url); return unless defined $fragment->{model}; $model = $fragment->{model}; $info = $fragment->{info}; $url = $info->{hydra_next}; $iterator = $model->get_statements; } $triple = $iterator->next; unless ($iterator->peek) { $model = undef; } } while (!defined $triple && defined($url = pop(@federated))); wantarray ? ($triple,$info) : $triple; }; $sub; } # Fetch a fragment page and extract the metadata sub get_model_and_info { my ($self,$url) = @_; if (my $cache = $self->lru->get($url)) { return $cache; } my $model = $self->get_fragment($url); my $info = {}; if (defined $model) { $info = $self->_model_metadata($model,$url, clean => 1); } my $fragment = { model => $model , info => $info }; $self->lru->set($url => $fragment); $fragment; } # Fetch a result page from fragment server sub get_fragment { my ($self,$url) = @_; return undef unless $url; $self->log->info("fetching: $url"); my $model = RDF::Trine::Model->temporary_model; # JSON support in RDF::Trine isn't JSON-LD # Set the accept header quality parameter at a minimum for this format my $ua = clone(RDF::Trine->default_useragent); $ua->agent("RDF:::LDF/$RDF::LDF::VERSION " . $ua->_agent); $ua->default_header('Accept','text/turtle;q=1.0,application/turtle;q=1.0,application/x-turtle;q=1.0,application/rdf+xml;q=0.9,text/x-nquads;q=0.9,application/json;q=0.1,application/x-rdf+json;q=0.1'); eval { # Need to explicitly set the useragent to keep the accept headers RDF::Trine::Parser->parse_url_into_model($url, $model, useragent => $ua); }; if ($@) { $self->log->error("failed to parse input"); } return $model; } # Create a hash with fragment metadata from a RDF::Trine::Model # parameters: # $model - RDF::Trine::Model # $this_uri - result page URL # %opts # clean => 1 - remove the metadata from the model sub _model_metadata { my ($self,$model,$this_uri,%opts) = @_; my $info = {}; $self->_build_metadata($model, { subject => RDF::Trine::Node::Resource->new($this_uri) } , $info); if ($opts{clean}) { $model->remove_statements( RDF::Trine::Node::Resource->new($this_uri), undef, undef ); $model->remove_statements( undef, undef, RDF::Trine::Node::Resource->new($this_uri) ); } for my $predicate ( 'http://www.w3.org/ns/hydra/core#variable' , 'http://www.w3.org/ns/hydra/core#property' , 'http://www.w3.org/ns/hydra/core#mapping' , 'http://www.w3.org/ns/hydra/core#template' , 'http://www.w3.org/ns/hydra/core#member' , 'http://www.w3.org/ns/hydra/core#variableRepresentation' , ) { $self->_build_metadata($model, { predicate => RDF::Trine::Node::Resource->new($predicate) }, $info); if ($opts{clean}) { $model->remove_statements( undef, RDF::Trine::Node::Resource->new($predicate) , undef); } } my $source = $info->{dct_source}->[0] if _is_array_ref($info->{dct_source}); if ($source) { $self->_build_metadata($model, { subject => RDF::Trine::Node::Resource->new($source) }, $info); if ($opts{clean}) { $model->remove_statements( RDF::Trine::Node::Resource->new($source), undef, undef ); $model->remove_statements( undef, undef, RDF::Trine::Node::Resource->new($source) ); } } $info; } # Helper method for _parse_model sub _build_metadata { my ($self, $model, $triple, $info) = @_; my $iterator = $model->get_statements( $triple->{subject}, $triple->{predicate}, $triple->{object} ); while (my $triple = $iterator->next) { my $subject = $triple->subject->as_string; my $predicate = $triple->predicate->uri_value; my $object = $triple->object->value; my $qname = join "_" , $self->sn->qname($predicate); if ($qname =~ /^(hydra_variable|hydra_property)$/) { my $id= $triple->subject->value; $info->{"_$id"}->{$qname} = $object; } elsif ($qname eq 'hydra_mapping') { my $id= $triple->subject->value; push @{$info->{"_$id"}->{$qname}} , $object; } elsif ($qname =~ /^(void|hydra)_/) { $info->{$qname} = $object; } else { push @{$info->{$qname}} , $object; } } $info; } sub _is_array_ref { return ref($_[0]) eq 'ARRAY'; } sub _is_hash_ref { return ref($_[0]) eq 'HASH'; } sub _is_blessed { return ref($_[0]) =~ /\S/; } sub _is_string { return defined($_[0]) && !ref($_[0]) && ref(\$_[0]) ne 'GLOB' && length($_[0]) > 0; } 1; __END__ =head1 NAME RDF::LDF - Linked Data Fragments client =begin markdown # STATUS [![Build Status](https://travis-ci.org/phochste/RDF-LDF.svg)](https://travis-ci.org/phochste/RDF-LDF) [![Coverage Status](https://coveralls.io/repos/phochste/RDF-LDF/badge.svg)](https://coveralls.io/r/phochste/RDF-LDF) [![Kwalitee Score](http://cpants.cpanauthors.org/dist/RDF-LDF.png)](http://cpants.cpanauthors.org/dist/RDF-LDF) =end markdown =head1 SYNOPSIS use RDF::Trine::Store::LDF; use RDF::Trine::Store; # To use a HTTP cache: use LWP::UserAgent::CHICaching; my $cache = CHI->new( driver => 'Memory', global => 1 ); my $ua = LWP::UserAgent::CHICaching->new(cache => $cache); RDF::Trine->default_useragent($ua); my $store = RDF::Trine::Store->new_with_config({ storetype => 'LDF', url => $url }); my $it = $store->get_statements(); while (my $st = $it->next) { # $st is a RDF::Trine::Statement print "$st\n"; } # Or the low level modules themselves use RDF::LDF; my $client = RDF::LDF->new(url => 'http://fragments.dbpedia.org/2014/en'); my $iterator = $client->get_statements($subject, $predicate, $object); while (my $statement = $iterator->()) { # $model is a RDF::Trine::Statement } =head1 DESCRIPTION RDF::LDF implements a basic L client. This a low level module to implement the Linked Data Fragment protocol. You probably want to use L. =head1 CONFIGURATION =over =item url URL to retrieve RDF from. Experimental: more than one URL can be provided for federated search over many LDF endpoints. my $store = RDF::Trine::Store->new_with_config({ storetype => 'LDF', url => [ $url1, $url2, $url3 ] }); # or my $client = RDF::LDF->new(url => [ $url1, $url2, $url3 ]); =back =head1 METHODS =over =item get_statements( $subject, $predicate, $object ) Return an iterator for every RDF::Trine::Statement served by the LDF server. =item get_pattern( $bgp ); Returns a stream object of all bindings matching the specified graph pattern. =back =head1 CONTRIBUTORS Patrick Hochstenbach, C<< patrick.hochstenbach at ugent.be >> Gregory Todd Williams, C<< greg@evilfunhouse.com >> Jacob Voss, C<< voss@gbv.de >> =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2015 by Patrick Hochstenbach. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =encoding utf8 =cut LDF-pattern.t100644000765000024 1761713547041572 15412 0ustar00hochstenstaff000000000000RDF-LDF-0.25/tuse open ':std', ':encoding(utf8)'; use strict; use warnings; use Test::More; use Test::Exception; use RDF::Trine qw(statement iri variable); use RDF::LDF; use Test::LWP::UserAgent; use Encode; use utf8; RDF::Trine->default_useragent(user_agent()); my $client = RDF::LDF->new(url => 'http://example.org/2014/en?test=1'); ok $client , 'got a client to http://example.org/2014/en?test=1'; ok $client->is_fragment_server , 'this server is a ldf server'; { note("single triple pattern"); my $triple = statement(variable('s'), iri('http://dbpedia.org/ontology/birthPlace'), variable('place')); my $iter = $client->get_pattern($triple); isa_ok $iter, 'RDF::Trine::Iterator::Bindings', 'iterator for get_pattern'; my $r = $iter->next; isa_ok $r, 'RDF::Trine::VariableBindings', 'result object'; my $s = $r->{'s'}; isa_ok $s, 'RDF::Trine::Node::Resource', 'expected subject IRI'; is $s->value, 'http://dbpedia.org/resource/Agusti_Pol', 'expected subject IRI value'; } { note("single triple pattern utf8"); my $triple = statement(variable('s'), iri('http://xmlns.com/foaf/0.1/name'), variable('name')); my $iter = $client->get_pattern($triple); isa_ok $iter, 'RDF::Trine::Iterator::Bindings', 'iterator for get_pattern'; my $r = $iter->next; isa_ok $r, 'RDF::Trine::VariableBindings', 'result object'; my $s = $r->{'s'}; isa_ok $s, 'RDF::Trine::Node::Resource', 'expected subject IRI'; is $s->value, 'http://dbpedia.org/resource/François_Schuiten', 'expected subject IRI value'; } { note("two triple pattern BGP"); my $bgp = RDF::Query::Algebra::BasicGraphPattern->new( statement(variable('s'), iri('http://dbpedia.org/ontology/birthPlace'), variable('place')), statement(variable('s'), iri('http://xmlns.com/foaf/0.1/name'), variable('name')), ); my $iter = $client->get_pattern($bgp); isa_ok $iter, 'RDF::Trine::Iterator::Bindings', 'iterator for get_pattern'; my $count = 0; my %seen; while (my $r = $iter->next) { isa_ok $r, 'RDF::Trine::VariableBindings', 'result object'; my $s = $r->{'s'}; $seen{ $s->value }{count}++; push(@{ $seen{ $s->value }{name} }, $r->{'name'}->value); push(@{ $seen{ $s->value }{place} }, $r->{'place'}->value); $count++; } is $count, 3, 'result count'; is_deeply(\%seen, { 'http://dbpedia.org/resource/Agustiar_Batubara' => { 'count' => 2, 'name' => ['Agustiar Batubara', 'Agustiar Batubara'], 'place' => [ 'http://dbpedia.org/resource/Indonesia', 'http://dbpedia.org/resource/Surabaya'], }, 'http://dbpedia.org/resource/Agusti_Pol' => { 'count' => 1, 'name' => [ 'Agusti Pol'], 'place' => [ 'http://dbpedia.org/resource/Andorra'], } }, 'expected counts'); } done_testing; sub add_fragment_response { my $ua = shift; my $url = shift; my $content = shift; my $total = shift // 1; my $next = shift; my $NS = <<'END'; @prefix rdf: . @prefix rdfs: . @prefix owl: . @prefix skos: . @prefix xsd: . @prefix dc: . @prefix dc11: . @prefix foaf: . @prefix geo: . @prefix dbpedia: . @prefix dbpedia-owl: . @prefix dbpprop: . @prefix hydra: . @prefix void: . END my $META = <<'END'; hydra:member . void:subset ; void:uriLookupEndpoint "http://example.org/2014/en?test=1{&subject,predicate,object}" ; a void:Dataset, hydra:Collection ; hydra:search [ hydra:mapping [ hydra:property rdf:object ; hydra:variable "object" ], [ hydra:property rdf:predicate ; hydra:variable "predicate" ], [ hydra:property rdf:subject ; hydra:variable "subject" ] ; hydra:template "http://example.org/2014/en?test=1{&subject,predicate,object}" ] . END my $FRAGMENT = <<"END"; <$url> dc:description "Triple Pattern Fragment of the 'DBpedia 2014' dataset containing triples matching the pattern { ?s ?p ?o }." ; dc:source ; dc:title "Linked Data Fragment of DBpedia 2014" ; void:subset ; a hydra:Collection, hydra:PagedCollection ; hydra:first <$url> ; hydra:itemsPerPage 5 ; void:triples $total ; hydra:totalItems $total . END if (defined($next)) { $FRAGMENT .= <<"END"; <$url> hydra:next<$next> . END } $ua->map_response( qr{^\Q$url\E$}, HTTP::Response->new( '200', 'OK', ['Content-Type' => 'text/turtle;charset=utf-8'], Encode::encode_utf8($NS) . Encode::encode_utf8($META) . Encode::encode_utf8($FRAGMENT) . Encode::encode_utf8($content) ) ); } sub user_agent { my $ua = Test::LWP::UserAgent->new( agent => "RDF:::LDF/$RDF::LDF::VERSION" ); # ?s dbpedia-owl:birthPlace ?name my $birthPlaces = <<'END'; dbpedia:Agusti_Pol dbpedia-owl:birthPlace dbpedia:Andorra . dbpedia:Agustiar_Batubara dbpedia-owl:birthPlace dbpedia:Indonesia, dbpedia:Surabaya . dbpedia:Agustin_Aguayo dbpedia-owl:birthPlace dbpedia:Guadalajara . END add_fragment_response($ua, 'http://example.org/2014/en?test=1', $birthPlaces, 4); add_fragment_response($ua, 'http://example.org/2014/en?test=1&subject=%3Fs&predicate=http%3A%2F%2Fdbpedia.org%2Fontology%2FbirthPlace&object=%3Fplace', $birthPlaces, 3); # ?s foaf:name ?name (page 1) my $names = <<'END'; dbpedia:François_Schuiten foaf:name "François Schuiten" . foaf:name "4th arrondissement of Marseille"@en . foaf:name "4th arrondissement of Paris"@en . foaf:name "4th arrondissement of Porto-Novo"@en . foaf:name "4th arrondissement"@en . foaf:name "Fourth Municipality of Naples"@en, "Municipalità 4"@en, "Quarta Municipalità"@en . END add_fragment_response($ua, 'http://example.org/2014/en?test=1&subject=%3Fs&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', $names, 7, 'http://example.org/2014/en?test=1&subject=%3Fs&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname&page=2'); # ?s foaf:name ?name (page 2) my $names2 = <<'END'; dbpedia:Agusti_Pol foaf:name "Agusti Pol" . dbpedia:Agustiar_Batubara foaf:name "Agustiar Batubara" . END add_fragment_response($ua, 'http://example.org/2014/en?test=1&subject=%3Fs&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname&page=2', $names, 7); # dbpedia:Agusti_Pol foaf:name ?name my $pol_name = <<'END'; dbpedia:Agusti_Pol foaf:name "Agusti Pol" . END add_fragment_response($ua, 'http://example.org/2014/en?test=1&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgusti_Pol&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', $pol_name, 1); # dbpedia:Agustiar_Batubara foaf:name ?name my $batubara_name = <<'END'; dbpedia:Agustiar_Batubara foaf:name "Agustiar Batubara" . END add_fragment_response($ua, 'http://example.org/2014/en?test=1&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgustiar_Batubara&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', $batubara_name, 1); # dbpedia:Agustin_Aguayo foaf:name ?name (No results) add_fragment_response($ua, 'http://example.org/2014/en?test=1&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgustin_Aguayo&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', '', 0); return $ua; } bin000755000765000024 013547041572 13256 5ustar00hochstenstaff000000000000RDF-LDF-0.25ldf-client.pl100755000765000024 571013547041572 16002 0ustar00hochstenstaff000000000000RDF-LDF-0.25/bin#!/usr/bin/env perl $|++; use strict; use RDF::LDF; use RDF::Trine::Store::LDF; use RDF::Trine::Store; use RDF::Query; use Getopt::Long; use utf8; use Encode; use JSON (); my $JSON = JSON->new->utf8->allow_nonref; sub encode_json { $JSON->encode(@_) } my ($subject,$predicate,$object); @ARGV = map { Encode::decode('UTF-8', $_) } @ARGV; GetOptions("subject=s" => \$subject , "predicate=s" => \$predicate , "object=s" => \$object); my $url = shift; my $sparql = shift; unless (defined $url) { print STDERR < --predicate=<.> --object=<.> EOF exit(1); } init_cache(); if (defined $sparql) { process_sparql($sparql); } else { process_fragments($subject,$predicate,$object); } sub init_cache { use LWP::UserAgent::CHICaching; my $cache = CHI->new( driver => 'Memory', global => 1 ); my $ua = LWP::UserAgent::CHICaching->new(cache => $cache); RDF::Trine->default_useragent($ua); } sub process_fragments { my ($subject,$predicate,$object) = @_; my $client = RDF::LDF->new(url => [split(/\s+/,$url)]); my $it = $client->get_statements($subject,$predicate,$object); print "[\n"; if ($it) { while (my $st = $it->()) { printf "{\"subject\":%s,\"predicate\":%s,\"object\":%s}\n", encode_json($st->subject->value), encode_json($st->predicate->value), encode_json($st->object->value); } } print "]\n"; } sub process_sparql { my $sparql = shift; $sparql = do { local (@ARGV,$/) = $sparql; <> } if -r $sparql; my $store = RDF::Trine::Store->new_with_config({ storetype => 'LDF', url => [split(/\s+/,$url)] }); my $model = RDF::Trine::Model->new($store); my $rdf_query = RDF::Query->new( $sparql ); unless ($rdf_query) { print STDERR "failed to parse:\n$sparql"; exit(2); } my $iter = $rdf_query->execute($model); print "[\n"; if ($iter) { my $count = 0; while (my $s = $iter->next) { my $h = {}; for my $v ($s->variables) { my $node = $s->{$v}; my $val; if ($node->isa('RDF::Trine::Node::Variable')) { $val = $node->as_string; # ?foo } elsif ($node->isa('RDF::Trine::Node::Literal')) { $val = $node->as_string; # includes quotes and any language or datatype $val =~ s{^"|"$}{}g; } else { $val = $node->value; # the raw IRI or blank node identifier value, without other syntax } $h->{$v} = $val; } print (",\n") if ($count++ > 0); print encode_json($h); } print "\n"; } print "]\n"; }demo000755000765000024 013547041572 13432 5ustar00hochstenstaff000000000000RDF-LDF-0.25sparql01.txt100644000765000024 111013547041572 15767 0ustar00hochstenstaff000000000000RDF-LDF-0.25/demo# perl -I lib bin/ldf-client.pl http://fragments.dbpedia.org/2014/en demo/sparql01.txt PREFIX owl: PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?s ?p ?o}sparql02.txt100644000765000024 34413547041572 15760 0ustar00hochstenstaff000000000000RDF-LDF-0.25/demo# perl -I lib bin/ldf-client.pl http://data.linkeddatafragments.org/viaf demo/sparql02.txt PREFIX schema: SELECT * WHERE { ?work schema:name ?name; schema:author [ schema:name "Picasso, Pablo" ]. }sparql03.txt100644000765000024 35013547041572 15756 0ustar00hochstenstaff000000000000RDF-LDF-0.25/demo# perl -I lib bin/ldf-client.pl http://data.linkeddatafragments.org/viaf demo/sparql03.txt PREFIX schema: SELECT * WHERE { ?work schema:name ?name; schema:author [ schema:name "Heisenberg, Werner" ]. }sparql04.txt100644000765000024 125113547041572 16000 0ustar00hochstenstaff000000000000RDF-LDF-0.25/demo# perl -I lib bin/ldf-client.pl http://fragments.dbpedia.org/2014/en demo/sparql04.txt PREFIX owl: PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?musician . }sparql05.txt100644000765000024 131413547041572 16001 0ustar00hochstenstaff000000000000RDF-LDF-0.25/demo# perl -I lib bin/ldf-client.pl http://fragments.dbpedia.org/2014/en demo/sparql05.txt PREFIX owl: PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?musician . ?musician foaf:name ?name . } sparql06.txt100644000765000024 37013547041572 15763 0ustar00hochstenstaff000000000000RDF-LDF-0.25/demo# perl -I lib bin/ldf-client.pl http://fragments.dbpedia.org/2014/en sparql06.txt PREFIX ontology: PREFIX property: SELECT ?craft WHERE { ?craft a ontology:Spacecraft . } LIMIT 150sparql07.txt100644000765000024 54413547041572 15767 0ustar00hochstenstaff000000000000RDF-LDF-0.25/demo# perl -I lib bin/ldf-client.pl http://fragments.dbpedia.org/2014/en sparql07.txt PREFIX ontology: PREFIX property: PREFIX xsd: SELECT * { ?craft a ontology:Spacecraft . ?craft property:launch ?date . FILTER ( ?date > "1999-01-01"^^xsd:date ) }sparql08.txt100644000765000024 67713547041572 15777 0ustar00hochstenstaff000000000000RDF-LDF-0.25/demo# perl -I lib bin/ldf-client.pl http://fragments.dbpedia.org/2014/en sparql07.txt PREFIX rdfs: PREFIX type: PREFIX prop: SELECT ?country_name ?population WHERE { ?country a type:LandlockedCountries ; rdfs:label ?country_name ; prop:populationEstimate ?population . FILTER (?population > 15000000) . }sparql09.txt100644000765000024 101013547041572 15776 0ustar00hochstenstaff000000000000RDF-LDF-0.25/demo# perl -I lib bin/ldf-client.pl http://fragments.dbpedia.org/2014/en sparql09.txt PREFIX type: PREFIX prop: PREFIX rdfs: SELECT ?country_name ?population WHERE { ?country a type:LandlockedCountries ; rdfs:label ?country_name ; prop:populationEstimate ?population . FILTER (?population > 15000000 && langMatches(lang(?country_name), "EN")) . } ORDER BY DESC(?population)LDF000755000765000024 013547041572 14274 5ustar00hochstenstaff000000000000RDF-LDF-0.25/lib/RDFError.pm100644000765000024 31113547041572 16036 0ustar00hochstenstaff000000000000RDF-LDF-0.25/lib/RDF/LDFpackage RDF::LDF::Error; # The error handling via Error in RDF::Trine is in conflict with # Moo packages. This Throwable package is a stop gap use Moo; with 'Throwable'; has text => (is => 'ro'); 1;author-pod-syntax.t100644000765000024 45413547041572 16667 0ustar00hochstenstaff000000000000RDF-LDF-0.25/t#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); RDF-Trine-Store-LDF.t100644000765000024 2437213547041572 16515 0ustar00hochstenstaff000000000000RDF-LDF-0.25/tuse open ':std', ':encoding(utf8)'; use strict; use warnings; use Test::More; use Test::Exception; use RDF::Trine::Store; use utf8; my $pkg; BEGIN { $pkg = 'RDF::Trine::Store::LDF'; use_ok $pkg; } require_ok $pkg; SKIP: { unless ($ENV{RDFLDF_NETWORK_TESTS}) { skip( "No network. Set RDFLDF_NETWORK_TESTS to run these tests.", 5 ); } my $store; $store = $pkg->new_with_config({ storetype => 'LDF', url => 'http://fragments.dbpedia.org/201x/en' }); ok ! defined $store , 'indeed this is not a LDF store'; $store = $pkg->new_with_config({ storetype => 'LDF', url => 'http://fragments.dbpedia.org/2014/en' }); ok $store , 'got a correct store'; throws_ok { $store->add_statement() } 'RDF::Trine::Error::UnimplementedError' , 'add_statement throws error'; throws_ok { $store->remove_statement() } 'RDF::Trine::Error::UnimplementedError' , 'remove_statement throws error'; throws_ok { $store->remove_statements() } 'RDF::Trine::Error::UnimplementedError' , 'remove_statements throws error'; my $model = RDF::Trine::Model->new($store); ok $model , 'got a model'; my $it = $store->get_statements(); ok $it , 'got an iterator on the compelete database'; my $triple = $it->next(); isa_ok $triple , 'RDF::Trine::Statement' , 'triple is an RDF::Trine::Statement'; ok $triple , 'got a triple'; { note("sparql test"); my $sparql =< PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?s ?o ?p} EOF my $it = get_sparql($model,$sparql); ok $it , 'got an iterator'; my $binding = $it->next(); ok $binding , 'got a binding'; ok $binding->{'s'}; ok $binding->{'o'}; ok $binding->{'p'}; } { note("sparql test"); my $sparql =< PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { . } EOF my $it = get_sparql($model,$sparql); ok $it , 'got an iterator'; my $binding = $it->next(); ok $binding , 'got a binding'; is int(keys %$binding) , 0 , 'binding is empty'; } { note("sparql test"); my $sparql =< PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?musician . } EOF my $it = get_sparql($model,$sparql); ok $it , 'got an iterator'; my $binding = $it->next(); ok $binding , 'got a binding'; ok $binding->{'musician'}; } { note("sparql test"); my $sparql =< PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?musician . ?musician foaf:name ?name . } EOF my $it = get_sparql($model,$sparql); ok $it , 'got an iterator'; my $binding = $it->next(); ok $binding , 'got a binding'; ok $binding->{'musician'}; ok $binding->{'name'}; } { note("sparql test utf8"); my $sparql =< PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?p . } EOF my $it = get_sparql($model,$sparql); ok $it , 'got an iterator'; my $binding = $it->(); ok $binding , 'got a binding'; ok $binding->{'p'}; } { note("sparql test utf8"); my $sparql =< PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?o . } LIMIT 1 EOF my $it = get_sparql($model,$sparql); ok $it , 'got an iterator'; my $binding = $it->(); ok $binding , 'got a binding'; ok $binding->{'o'}; } { note("sparql test"); my $sparql =< PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?p a . ?p ?c . ?c "York"\@en . ?musician . } EOF my $it = get_sparql($model,$sparql); ok $it , 'got an iterator'; my $binding = $it->next(); ok $binding , 'got a binding'; ok $binding->{'p'}; ok $binding->{'c'}; ok $binding->{'musician'}; ok defined($it->next()) , 'got only more results'; } # federated test note("federated test"); my $f_store = $pkg->new_with_config({ storetype => 'LDF', url => [qw( http://data.linkeddatafragments.org/dbpedia2014 http://data.linkeddatafragments.org/geonames )] }); ok $f_store , 'got a correct federated store'; throws_ok { $f_store->add_statement() } 'RDF::Trine::Error::UnimplementedError' , 'add_statement throws error'; throws_ok { $f_store->remove_statement() } 'RDF::Trine::Error::UnimplementedError' , 'remove_statement throws error'; throws_ok { $f_store->remove_statements() } 'RDF::Trine::Error::UnimplementedError' , 'remove_statements throws error'; my $f_model = RDF::Trine::Model->new($f_store); ok $f_model , 'got a model'; $it = $f_store->get_statements(); ok $it , 'got an iterator on the compelete database'; $triple = $it->next(); isa_ok $triple , 'RDF::Trine::Statement' , 'triple is an RDF::Trine::Statement'; ok $triple , 'got a triple'; { note("sparql test utf8 [federated]"); my $sparql =< PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { ?p . } EOF my $it = get_sparql($f_model,$sparql); ok $it , 'got an iterator'; my $binding = $it->(); ok $binding , 'got a binding'; ok $binding->{'p'}; } { note("sparql test utf8 [federated]"); my $sparql =< PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX geonames-ontology: SELECT * WHERE { ?s geonames-ontology:wikipediaArticle . } EOF my $it = get_sparql($f_model,$sparql); ok $it , 'got an iterator'; my $binding = $it->(); ok $binding , 'got a binding'; ok $binding->{'s'}; } } done_testing; sub get_sparql { my $model = shift; my $sparql = shift; my $rdf_query = RDF::Query->new( $sparql ); $rdf_query->execute($model); } LDF-pattern-federated.t100644000765000024 2433413547041572 17325 0ustar00hochstenstaff000000000000RDF-LDF-0.25/tuse open ':std', ':encoding(utf8)'; use strict; use warnings; use Test::More; use Test::Exception; use RDF::Trine qw(statement iri variable); use RDF::LDF; use Test::LWP::UserAgent; use Encode; use utf8; RDF::Trine->default_useragent(user_agent()); my $client = RDF::LDF->new(url => [qw( http://example.org/A http://example.org/C http://example.org/B )]); ok $client , 'got a federated client to http://example.org/A , http://example.org/B and http://example.org/C ... '; ok $client->is_fragment_server , 'this server is a ldf server'; { note("single triple pattern"); my $triple = statement(variable('s'), iri('http://dbpedia.org/ontology/birthPlace'), variable('place')); my $iter = $client->get_pattern($triple); isa_ok $iter, 'RDF::Trine::Iterator::Bindings', 'iterator for get_pattern'; my $r = $iter->next; isa_ok $r, 'RDF::Trine::VariableBindings', 'result object'; my $s = $r->{'s'}; isa_ok $s, 'RDF::Trine::Node::Resource', 'expected subject IRI'; is $s->value, 'http://dbpedia.org/resource/Agusti_Pol', 'expected subject IRI value'; } { note("single triple pattern utf8"); my $triple = statement(variable('s'), iri('http://xmlns.com/foaf/0.1/name'), variable('name')); my $iter = $client->get_pattern($triple); isa_ok $iter, 'RDF::Trine::Iterator::Bindings', 'iterator for get_pattern'; my $r = $iter->next; isa_ok $r, 'RDF::Trine::VariableBindings', 'result object'; my $s = $r->{'s'}; isa_ok $s, 'RDF::Trine::Node::Resource', 'expected subject IRI'; is $s->value, 'http://dbpedia.org/resource/François_Schuiten', 'expected subject IRI value'; } { note("two triple pattern BGP"); my $bgp = RDF::Query::Algebra::BasicGraphPattern->new( statement(variable('s'), iri('http://dbpedia.org/ontology/birthPlace'), variable('place')), statement(variable('s'), iri('http://xmlns.com/foaf/0.1/name'), variable('name')), ); my $iter = $client->get_pattern($bgp); isa_ok $iter, 'RDF::Trine::Iterator::Bindings', 'iterator for get_pattern'; my $count = 0; my %seen; while (my $r = $iter->next) { isa_ok $r, 'RDF::Trine::VariableBindings', 'result object'; my $s = $r->{'s'}; $seen{ $s->value }{count}++; push(@{ $seen{ $s->value }{name} }, $r->{'name'}->value); push(@{ $seen{ $s->value }{place} }, $r->{'place'}->value); $count++; } is $count, 3, 'result count'; is_deeply(\%seen, { 'http://dbpedia.org/resource/Agustiar_Batubara' => { 'count' => 2, 'name' => ['Agustiar Batubara', 'Agustiar Batubara'], 'place' => [ 'http://dbpedia.org/resource/Indonesia', 'http://dbpedia.org/resource/Surabaya'], }, 'http://dbpedia.org/resource/Agusti_Pol' => { 'count' => 1, 'name' => [ 'Agusti Pol'], 'place' => [ 'http://dbpedia.org/resource/Andorra'], } }, 'expected counts'); } done_testing; sub add_fragment_response { my $ua = shift; my $url = shift; my $content = shift; my $total = shift // 1; my $next = shift; my $endpoint = $url; $endpoint =~ s{\?.*}{}; my $base = $endpoint; $base =~ s{(http://[^\/]+/).*}{$1}; my $NS = <<'END'; @prefix rdf: . @prefix rdfs: . @prefix owl: . @prefix skos: . @prefix xsd: . @prefix dc: . @prefix dc11: . @prefix foaf: . @prefix geo: . @prefix dbpedia: . @prefix dbpedia-owl: . @prefix dbpprop: . @prefix hydra: . @prefix void: . END my $META = < hydra:member <${endpoint}#dataset> . <${endpoint}#dataset> void:subset <${endpoint}> ; void:uriLookupEndpoint "${endpoint}?{&subject,predicate,object}" ; a void:Dataset, hydra:Collection ; hydra:search [ hydra:mapping [ hydra:property rdf:object ; hydra:variable "object" ], [ hydra:property rdf:predicate ; hydra:variable "predicate" ], [ hydra:property rdf:subject ; hydra:variable "subject" ] ; hydra:template "${endpoint}?{&subject,predicate,object}" ] . END my $FRAGMENT = < dc:description "Triple Pattern Fragment of the 'DBpedia 2014' dataset containing triples matching the pattern { ?s ?p ?o }." ; dc:source <${endpoint}#dataset> ; dc:title "Linked Data Fragment of DBpedia 2014" ; void:subset <${endpoint}> ; a hydra:Collection, hydra:PagedCollection ; hydra:first <$url> ; hydra:itemsPerPage 5 ; void:triples $total ; hydra:totalItems $total . END if (defined($next)) { $FRAGMENT .= <<"END"; <$url>hydra:next<$next> . END } $ua->map_response( qr{^\Q$url\E$}, HTTP::Response->new( '200', 'OK', ['Content-Type' => 'text/turtle;charset=utf-8'], Encode::encode_utf8($NS) . Encode::encode_utf8($META) . Encode::encode_utf8($FRAGMENT) . Encode::encode_utf8($content) ) ); } sub user_agent { my $ua = Test::LWP::UserAgent->new( agent => "RDF:::LDF/$RDF::LDF::VERSION" ); my $birthPlaces = <<'END'; dbpedia:Agusti_Pol dbpedia-owl:birthPlace dbpedia:Andorra . dbpedia:Agustiar_Batubara dbpedia-owl:birthPlace dbpedia:Indonesia, dbpedia:Surabaya . dbpedia:Agustin_Aguayo dbpedia-owl:birthPlace dbpedia:Guadalajara . END my $names = <<'END'; dbpedia:François_Schuiten foaf:name "François Schuiten" . foaf:name "4th arrondissement of Marseille"@en . foaf:name "4th arrondissement of Paris"@en . foaf:name "4th arrondissement of Porto-Novo"@en . foaf:name "4th arrondissement"@en . foaf:name "Fourth Municipality of Naples"@en, "Municipalità 4"@en, "Quarta Municipalità"@en . END my $names2 = <<'END'; dbpedia:Agusti_Pol foaf:name "Agusti Pol" . dbpedia:Agustiar_Batubara foaf:name "Agustiar Batubara" . END my $pol_name = <<'END'; dbpedia:Agusti_Pol foaf:name "Agusti Pol" . END my $batubara_name = <<'END'; dbpedia:Agustiar_Batubara foaf:name "Agustiar Batubara" . END # {A,B,C} all triples add_fragment_response($ua, 'http://example.org/A', $birthPlaces, 3); add_fragment_response($ua, 'http://example.org/B', $names, 6); add_fragment_response($ua, 'http://example.org/C', $names2, 2); add_fragment_response($ua, 'http://example.org/A?', $birthPlaces, 3); add_fragment_response($ua, 'http://example.org/B?', $names, 6); add_fragment_response($ua, 'http://example.org/C?', $names2, 2); # {A,B,C}: ?s dbpedia-owl:birthPlace ?place add_fragment_response($ua, 'http://example.org/A?&subject=%3Fs&predicate=http%3A%2F%2Fdbpedia.org%2Fontology%2FbirthPlace&object=%3Fplace', $birthPlaces, 3); add_fragment_response($ua, 'http://example.org/B?&subject=%3Fs&predicate=http%3A%2F%2Fdbpedia.org%2Fontology%2FbirthPlace&object=%3Fplace', "", 0); add_fragment_response($ua, 'http://example.org/C?&subject=%3Fs&predicate=http%3A%2F%2Fdbpedia.org%2Fontology%2FbirthPlace&object=%3Fplace', "", 0); # {A,B,C}: ?s foaf:name ?name add_fragment_response($ua, 'http://example.org/A?&subject=%3Fs&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', "", 0); add_fragment_response($ua, 'http://example.org/B?&subject=%3Fs&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', $names, 6); add_fragment_response($ua, 'http://example.org/C?&subject=%3Fs&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', $names2, 2); # {A,B,C}: dbpedia:Augusti_Pol foaf:name ?name add_fragment_response($ua, 'http://example.org/A?&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgusti_Pol&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', "", 0); add_fragment_response($ua, 'http://example.org/B?&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgusti_Pol&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', $pol_name,1); add_fragment_response($ua, 'http://example.org/C?&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgusti_Pol&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', "", 0); # {A,B,C}: dbpedia:Agustiar_Batubara foaf:name ?name add_fragment_response($ua, 'http://example.org/A?&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgustiar_Batubara&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', "", 0); add_fragment_response($ua, 'http://example.org/B?&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgustiar_Batubara&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', "", 0); add_fragment_response($ua, 'http://example.org/C?&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgustiar_Batubara&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', $batubara_name, 1); # {a,B,C}: dbpedia:Agustin_Aguayo foaf:name ?name (No results) add_fragment_response($ua, 'http://example.org/A?&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgustin_Aguayo&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', '', 0); add_fragment_response($ua, 'http://example.org/B?&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgustin_Aguayo&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', '', 0); add_fragment_response($ua, 'http://example.org/C?&subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FAgustin_Aguayo&predicate=http%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2Fname&object=%3Fname', '', 0); return $ua; } Store000755000765000024 013547041572 16044 5ustar00hochstenstaff000000000000RDF-LDF-0.25/lib/RDF/TrineLDF.pm100644000765000024 1064313547041572 17173 0ustar00hochstenstaff000000000000RDF-LDF-0.25/lib/RDF/Trine/Storepackage RDF::Trine::Store::LDF; use strict; use warnings; no warnings 'redefine'; use feature qw(state); use utf8; use base qw(RDF::Trine::Store); use RDF::Trine::Store; use RDF::Trine::Iterator; use RDF::LDF; use RDF::Trine::Error qw(:try); sub new { my ($class,%opts) = @_; my $ref = \%opts; $ref->{ldf} = RDF::LDF->new( url => $ref->{url}); return undef unless $ref->{ldf}->is_fragment_server; bless $ref , $class; } sub _new_with_string { my ($class, $cfg) = @_; $class->new(url => $cfg); } sub _new_with_config { my ($class,$cfg) = @_; $class->new(url => $cfg->{url}); } sub get_statements { my ($self,$subject,$predicate,$object,$context) = @_; my $sub = $self->{ldf}->get_statements($subject,$predicate,$object); RDF::Trine::Iterator::Graph->new($sub); } sub get_pattern { my ($self,$bgp,$context) = @_; $self->{ldf}->get_pattern($bgp,$context); } sub get_contexts { undef; } sub add_statement { throw RDF::Trine::Error::UnimplementedError -text => "LDF add_statement support not implemented"; } sub remove_statement { throw RDF::Trine::Error::UnimplementedError -text => "LDF remove_statement support not implemented"; } sub remove_statements { throw RDF::Trine::Error::UnimplementedError -text => "LDF remove_statements support not implemented"; } sub count_statements { my ($self,$subject,$predicate,$object,$context) = @_; my $it = $self->{ldf}->get_statements($subject,$predicate,$object); my ($triples,$info) = $it->(); $info->{hydra_totalItems}; } sub size { shift->count_statements; } sub supports { undef; } 1; =head1 NAME RDF::Trine::Store::LDF - RDF Store proxy for a Linked Data Fragment endpoint =head1 SYNOPSIS use RDF::Trine::Store::LDF; use RDF::Trine::Store; my $store = RDF::Trine::Store->new_with_config({ storetype => 'LDF', url => $url }); my $it = $store->get_statements(); while (my $st = $it->next) { # $st is a RDF::Trine::Statement print "$st\n"; } # Or query the store with SPAQRL use RDF::Query; my $model = RDF::Trine::Model->new($store); my $rdf_query = RDF::Query->new(<execute($model); while (my $s = $iter->next) { # $s is a RDF::Trine::VariableBinding print $s->value . "\n"; } =head1 DESCRIPTION RDF::Trine::Store::LDF provides a RDF::Trine::Store API to interact with a remote Linked Data Fragment endpoint. For details see: . =head1 METHODS Beyond the methods documented below, this class inherits methods from the L class. =over =item new({ url => url }) Returns a new RDF::Trine::Store object that will act as a proxy for the Linked Data Fragment endpoint accessible via the supplied $url. Expertimental: more than one url as an ARRAY reference can be provided for an federated query over many LDF endpoints. =item new_with_config( $hashref ) Returns a new RDF::Trine::Store object configured by a hashref with the url as required key. =item get_statements( $subject, $predicate, $object ) Returns a stream object of all statements matching the specified subject, predicate and objects. Any of the arguments may be undef to match any value. =item get_pattern( $bgp ) Returns an iterator object of all bindings matching the specified graph pattern. =item get_contexts Not supported. =item add_statement ( $statement [, $context] ) Not supported. =item remove_statement ( $statement [, $context]) Not supported. =item remove_statements ( $subject, $predicate, $object [, $context]) Not supported. =item count_statements ( $subject, $predicate, $object ) Returns a count of all the statements matching the specified subject, predicate and object. Any of the arguments may be undef to match any value. =item size Returns the number of statements in the store. =item supports ( [ $feature ] ) Not supported. =back =head1 AUTHOR Patrick Hochstenbach, C<< patrick.hochstenbach at ugent.be >> =head1 CONTRIBUTORS Gregory Todd Williams, C<< greg@evilfunhouse.com >> =head1 LICENSE 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 L for more information. =encoding utf8 =cut