Catmandu-RDF-0.28000755001750001750 012625307401 12367 5ustar00vojvoj000000000000README100644001750001750 316612625307401 13336 0ustar00vojvoj000000000000Catmandu-RDF-0.28NAME Catmandu::RDF - Modules for handling RDF data within the Catmandu framework SYNOPSIS Command line client catmandu: catmandu convert RDF --url http://dx.doi.org/10.2474/trol.7.147 --fix 'aref_query(dct_title,title)' to YAML catmandu convert RDF --file rdfdump.nt to RDF --type turtle See documentation of modules for more examples. DESCRIPTION Catmandu::RDF contains modules for handling RDF data within the Catmandu framework. RDF data is encoded/decoded in aREF as implemented with RDF::aREF. Please keep in mind that RDF is a graph-based data structuring format with specialized technologies such as SPARQL and triple stores. Using Catmandu::RDF to transform RDF to RDF (e.g. conversion from one RDF serialization to another) is possible but probably less performant than decent RDF tools. Catmandu::RDF, however, is more conventient to convert between RDF and other data formats. AVAILABLE MODULES Catmandu::Exporter::RDF Serialize RDF data (as RDF/XML, RDF/JSON, Turtle, NTriples, RDFa...) Catmandu::Importer::RDF Parse RDF data (RDF/XML, RDF/JSON, Turtle, NTriples...) or import from a SPARQL endpoint Catmandu::Fix::aref_query Copy values of RDF data in aREF format to a new field SEE ALSO This module is based on Catmandu, RDF::aREF, RDF::Trine, and RDF::NS. COPYRIGHT AND LICENSE Copyright Jakob Voss, 2014- This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Changes100644001750001750 404712625307401 13750 0ustar00vojvoj000000000000Catmandu-RDF-0.28Changelog for Catmandu-RDF 0.28 2015-11-25 11:35:42 CET - streaming export in NTriples format by default (issue #25) 0.27 2015-05-30 14:15:45 CEST - added sparql file option (issue #19) 0.26 2015-05-21 10:38:12 CEST - added support of Linked Data Fragments 0.25 2015-03-27 13:53:59 CET - support streaming of NTriple data 0.24 2015-03-09 13:20:23 CET - added support of SPARQL - fixed some unit tests - rewrote aref_query fix 0.23 2014-12-11 16:41:22 CET - fix bnode mapping bug - simplify calling syntax of aref_query fix 0.22 2014-12-11 15:01:15 CET - align with RDF::aREF 0.22, new options predicate_map 0.20 2014-12-10 15:13:40 CET - tried to fix import from URL encoding (issue #9) 0.19 2014-12-10 14:17:59 CET - add triples importer mode (issue #5) - disable namespaces with ns=0 (issue #8) - support importing from string reference 0.18 2014-10-14 12:53:01 CEST - add field _url on import from url (issue #9) - started fix function aref_query 0.17 2014-10-02 14:26:35 CEST - Migrate to Dist::Milla - Adjust to aREF 0.19 0.15 2014-07-17T11:35:04 - document and test count method - started importer 0.14 2014-01-22T07:18:56 - internally use RDF::Trine::Model - bug detected (issue #3?) - use RDF::aREF 0.09 0.13 2014-01-15T12:15:56 - Merge release - use RDF::aREF 0.08 0.12 2014-01-12T16:39:03 - release 0.12 with fixed dependencies - update dependencies - fixed dist.ini - fixed dependency 0.11 2013-12-02T14:17:01 - documentation - fixed cpanfile - don't test ob Perl 5.10 - split RDF::aREF as independent module 0.10 2013-11-15T11:18:20 - started to support nested input documents - renamed aRef to aREF 0.09 2013-11-13T14:29:24 - migrated from RDF/JSON to aRef - fix link 0.03 2013-09-20T12:42:10 - auto-expand prefixed object-uris - support 'a' as shortcut for 'rdf:type' - extended documentation - implemented basic Exporter - support a subset of JSON-LD - use dzil and travis 0.02 2013-09-06T09:14:51 - documentation 0.01 2013-09-05T09:39:00 - basic RDF Exporter - first draft t000755001750001750 012625307401 12553 5ustar00vojvoj000000000000Catmandu-RDF-0.28url.t100644001750001750 664612625307401 13716 0ustar00vojvoj000000000000Catmandu-RDF-0.28/tuse strict; use warnings; use open ':std', ':encoding(utf8)'; use Test::More; use Catmandu -all; use Catmandu::RDF; use RDF::Trine; use Encode; use HTTP::Response; use Test::LWP::UserAgent; use utf8; RDF::Trine->default_useragent(user_agent()); { note("importing turtle"); my $importer = importer('RDF', url => 'http://www.w3.org/TR/examples/example1.ttl', type => 'turtle'); my $aref = $importer->first; is $aref->{'http://www.w3.org/TR/rdf-syntax-grammar'}->{dc_title}, 'RDF/XML Syntax Specification (Revised)@', 'Import from URL'; } { note("importing rdf/xml"); my $importer = importer('RDF', url => 'http://www.w3.org/TR/examples/example2.rdf', type => 'xml'); my $aref = $importer->first; is $aref->{'http://www.w3.org/TR/rdf-syntax-grammar'}->{dc_title}, 'RDF/XML Syntax Specification (Revised)@', 'Import from URL'; } { note("importing NTriples"); my $importer = importer('RDF', url => 'http://www.w3.org/TR/examples/example3.nt', type => 'NTriples'); my $aref = $importer->first; is $aref->{'http://www.w3.org/TR/rdf-syntax-grammar'}->{dc_title}, 'RDF/XML Syntax Specification (Revised)@', 'Import from URL'; } done_testing; sub user_agent { my $ua = Test::LWP::UserAgent->new( agent => "Catmandu::RDF/$Catmandu::RDF::VERSION" ); my $example =< . \@prefix dc: . \@prefix ex: . dc:title "RDF/XML Syntax Specification (Revised)" ; ex:editor [ ex:fullname "Dave Beckett"; ex:homePage ] . EOF add_response( $ua, 'http://www.w3.org/TR/examples/example1.ttl', 'text/turtle; charset=utf-8', $example ); my $example2 =< EOF add_response( $ua, 'http://www.w3.org/TR/examples/example2.rdf', 'application/rdf+xml; charset=utf-8', $example2 ); my $example3 =< "RDF/XML Syntax Specification (Revised)". _:b1 . _:b1 "Dave Beckett" . _:b1 . EOF add_response( $ua, 'http://www.w3.org/TR/examples/example3.nt', 'text/plain; charset=utf-8', $example3 ); return $ua; } sub add_response { my $ua = shift; my $url = shift; my $content_type = shift; my $content = shift; $ua->map_response( qr{^\Q$url\E$}, HTTP::Response->new( '200', 'OK', ['Content-Type' => $content_type ], Encode::encode_utf8($content) ) ); } LICENSE100644001750001750 4361712625307401 13510 0ustar00vojvoj000000000000Catmandu-RDF-0.28This software is copyright (c) 2014- by -. 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) 2014- by -. 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) 2014- by -. 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 cpanfile100644001750001750 51012625307401 14130 0ustar00vojvoj000000000000Catmandu-RDF-0.28requires 'perl', 'v5.13.1'; requires 'Catmandu', '0.9209'; requires 'RDF::LDF', '0.10'; requires 'RDF::NS', '20140910'; requires 'RDF::Query', '2.913'; requires 'RDF::Trine', '1.013'; requires 'RDF::aREF', '0.25'; test_requires 'Test::More', '0.99'; test_requires 'Test::LWP::UserAgent', '0.025'; test_requires 'Encode', '0'; dist.ini100644001750001750 3312625307401 14050 0ustar00vojvoj000000000000Catmandu-RDF-0.28author=Jakob Voß [@Milla] Build.PL100644001750001750 26112625307401 13723 0ustar00vojvoj000000000000Catmandu-RDF-0.28# This Build.PL for Catmandu-RDF was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.010. use strict; use warnings; use v5.13.1; use Module::Build::Tiny 0.039; Build_PL(); META.yml100644001750001750 201712625307401 13721 0ustar00vojvoj000000000000Catmandu-RDF-0.28--- abstract: 'Modules for handling RDF data within the Catmandu framework' author: - 'Jakob Voß' build_requires: Encode: '0' Test::LWP::UserAgent: '0.025' Test::More: '0.99' configure_requires: Module::Build::Tiny: '0.039' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.036, Dist::Milla version v1.0.15, CPAN::Meta::Converter version 2.150001' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Catmandu-RDF no_index: directory: - t - xt - inc - share - eg - examples requires: Catmandu: '0.9209' RDF::LDF: '0.10' RDF::NS: '20140910' RDF::Query: '2.913' RDF::Trine: '1.013' RDF::aREF: '0.25' perl: v5.13.1 resources: bugtracker: https://github.com/LibreCat/Catmandu-RDF/issues homepage: https://github.com/LibreCat/Catmandu-RDF repository: https://github.com/LibreCat/Catmandu-RDF.git version: '0.28' x_contributors: - 'Jakob Voß ' - 'Patrick Hochstenbach ' MANIFEST100644001750001750 66512625307401 13570 0ustar00vojvoj000000000000Catmandu-RDF-0.28# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.036. Build.PL Changes LICENSE MANIFEST META.json META.yml README cpanfile dist.ini lib/Catmandu/Exporter/RDF.pm lib/Catmandu/Fix/aref_query.pm lib/Catmandu/Importer/RDF.pm lib/Catmandu/RDF.pm t/aref_query.t t/example.rdf t/example.ttl t/example.yml t/exporter-add.t t/exporter.t t/importer.t t/issue-3.t t/query.sparql t/release-pod-syntax.t t/sparql.t t/url.t META.json100644001750001750 354512625307401 14100 0ustar00vojvoj000000000000Catmandu-RDF-0.28{ "abstract" : "Modules for handling RDF data within the Catmandu framework", "author" : [ "Jakob Voß" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.036, Dist::Milla version v1.0.15, CPAN::Meta::Converter version 2.150001", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Catmandu-RDF", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples" ] }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.039" } }, "develop" : { "requires" : { "Dist::Milla" : "v1.0.15", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Catmandu" : "0.9209", "RDF::LDF" : "0.10", "RDF::NS" : "20140910", "RDF::Query" : "2.913", "RDF::Trine" : "1.013", "RDF::aREF" : "0.25", "perl" : "v5.13.1" } }, "test" : { "requires" : { "Encode" : "0", "Test::LWP::UserAgent" : "0.025", "Test::More" : "0.99" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/LibreCat/Catmandu-RDF/issues" }, "homepage" : "https://github.com/LibreCat/Catmandu-RDF", "repository" : { "type" : "git", "url" : "https://github.com/LibreCat/Catmandu-RDF.git", "web" : "https://github.com/LibreCat/Catmandu-RDF" } }, "version" : "0.28", "x_contributors" : [ "Jakob Voß ", "Patrick Hochstenbach " ] } sparql.t100644001750001750 2732512625307401 14433 0ustar00vojvoj000000000000Catmandu-RDF-0.28/tuse strict; use warnings; use open ':std', ':encoding(utf8)'; use Test::More; use Catmandu -all; use Catmandu::RDF; use RDF::Trine; use Encode; use HTTP::Response; use Test::LWP::UserAgent; use utf8; RDF::Trine->default_useragent(user_agent()); { note("importing from sparql endpoint"); my $sparql =< SELECT * WHERE { ?book dc:title ?title . } END my $url = 'http://sparql.org/books/sparql'; my $importer = importer('RDF', url => $url, sparql => $sparql); is $importer->sparql, $sparql, "SPARQL"; $importer = importer('RDF', url => $url, sparql => "SELECT * WHERE { ?book dc:title ?title . }\n"); is $importer->sparql, $sparql, "SPARQL, PREFIX added"; my $ref = $importer->first; ok $ref->{title} , 'got a title'; ok $ref->{book} , 'got a book'; } { note("importing from ldf endpoint"); my $sparql =< } EOF my $url = 'http://fragments.dbpedia.org/2014/en'; my $importer = importer('RDF', url => $url, sparql => $sparql); my $ref = $importer->first; ok $ref->{film} , 'got a film'; } { note("importing from ldf endpoint (utf8)"); my $url = 'http://fragments.dbpedia.org/2014/en'; my $importer = importer('RDF', url => $url, sparql => 't/query.sparql'); my $ref = $importer->first; ok $ref->{name} , 'got a name (file sparql)'; like $ref->{name} , qr/François Schuiten/ , 'utf8 test'; } done_testing; sub user_agent { my $ua = Test::LWP::UserAgent->new( agent => "Catmandu::RDF/${Catmandu::RDF::VERSION}" ); my $example =< http://example.org/book/book7 Harry Potter and the Deathly Hallows EOF add_response( $ua, 'http://sparql.org/books/sparql?query=PREFIX%20dc%3A%20%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E%0ASELECT%20%2A%20WHERE%20%7B%20%3Fbook%20dc%3Atitle%20%3Ftitle%20.%20%7D%0A', 'application/sparql-results+xml; charset=utf-8', $example ); my $example2 =<. \@prefix rdfs: . \@prefix xsd: . \@prefix dc: . \@prefix foaf: . \@prefix dbpedia: . \@prefix dbpedia-owl: . \@prefix dbpprop: . \@prefix hydra: . \@prefix void: . hydra:member . a void:Dataset, hydra:Collection; void:subset ; void:uriLookupEndpoint "http://fragments.dbpedia.org/2014/en{?subject,predicate,object}"; hydra:search _:triplePattern. _:triplePattern hydra:template "http://fragments.dbpedia.org/2014/en{?subject,predicate,object}"; hydra:mapping _:subject, _:predicate, _:object. _:subject hydra:variable "subject"; hydra:property rdf:subject. _:predicate hydra:variable "predicate"; hydra:property rdf:predicate. _:object hydra:variable "object"; hydra:property rdf:object. , , . "literal1", "literalA", "literalB", "literalC"; , . "literal2". void:subset ; a hydra:Collection, hydra:PagedCollection; dc:title "Linked Data Fragment of Test"\@en; dc:description "Triple Pattern Fragment of the 'Test' dataset containing triples matching the pattern { ?s ?p ?o }."\@en; dc:source ; hydra:totalItems "10"^^xsd:integer; void:triples "10"^^xsd:integer; hydra:itemsPerPage "100"^^xsd:integer; hydra:firstPage . EOF add_response( $ua, 'http://fragments.dbpedia.org/2014/en', 'text/turtle; charset=utf-8', $example2 ); my $example2b =<. \@prefix rdfs: . \@prefix owl: . \@prefix skos: . \@prefix xsd: . \@prefix dc: . \@prefix dcterms: . \@prefix dc11: . \@prefix foaf: . \@prefix geo: . \@prefix dbpedia: . \@prefix dbpedia-owl: . \@prefix dbpprop: . \@prefix hydra: . \@prefix void: . hydra:member . a void:Dataset, hydra:Collection; void:subset , ; void:uriLookupEndpoint "http://fragments.dbpedia.org/2014/en{?subject,predicate,object}"; hydra:search _:triplePattern. _:triplePattern hydra:template "http://fragments.dbpedia.org/2014/en{?subject,predicate,object}"; hydra:mapping _:subject, _:predicate, _:object. _:subject hydra:variable "subject"; hydra:property rdf:subject. _:predicate hydra:variable "predicate"; hydra:property rdf:predicate. _:object hydra:variable "object"; hydra:property rdf:object. dcterms:subject . void:subset . a hydra:Collection, hydra:PagedCollection; dcterms:title "Linked Data Fragment of DBpedia 2014"\@en; dcterms:description "Triple Pattern Fragment of the 'DBpedia 2014' dataset containing triples matching the pattern { ?s }."\@en; dcterms:source ; hydra:totalItems "1"^^xsd:integer; void:triples "1"^^xsd:integer; hydra:itemsPerPage "100"^^xsd:integer; hydra:firstPage ; hydra:nextPage . EOF add_response( $ua, 'http://fragments.dbpedia.org/2014/en?predicate=http%3A%2F%2Fpurl.org%2Fdc%2Fterms%2Fsubject&object=http%3A%2F%2Fdbpedia.org%2Fresource%2FCategory%3AFrench_films', 'text/turtle; charset=utf-8', $example2b ); my $example3=<. \@prefix rdfs: . \@prefix owl: . \@prefix skos: . \@prefix xsd: . \@prefix dc: . \@prefix dcterms: . \@prefix dc11: . \@prefix foaf: . \@prefix geo: . \@prefix dbpedia: . \@prefix dbpedia-owl: . \@prefix dbpprop: . \@prefix hydra: . \@prefix void: . hydra:member . a void:Dataset, hydra:Collection; void:subset ; void:uriLookupEndpoint "http://fragments.dbpedia.org/2014/en{?subject,predicate,object}"; hydra:search _:triplePattern. _:triplePattern hydra:template "http://fragments.dbpedia.org/2014/en{?subject,predicate,object}"; hydra:mapping _:subject, _:predicate, _:object. _:subject hydra:variable "subject"; hydra:property rdf:subject. _:predicate hydra:variable "predicate"; hydra:property rdf:predicate. _:object hydra:variable "object"; hydra:property rdf:object. rdfs:label "François Schuiten"\@de, "François Schuiten"\@en, "François Schuiten"\@es, "François Schuiten"\@fr, "François Schuiten"\@it, "François Schuiten"\@nl, "フランソワ・スクイテン"\@ja. void:subset ; a hydra:Collection, hydra:PagedCollection; dcterms:title "Linked Data Fragment of DBpedia 2014"\@en; dcterms:description "Triple Pattern Fragment of the 'DBpedia 2014' dataset containing triples matching the pattern { ?o }."\@en; dcterms:source ; hydra:totalItems "7"^^xsd:integer; void:triples "7"^^xsd:integer; hydra:itemsPerPage "100"^^xsd:integer; hydra:firstPage EOF add_response( $ua, 'http://fragments.dbpedia.org/2014/en?subject=http%3A%2F%2Fdbpedia.org%2Fresource%2FFran%C3%A7ois_Schuiten&predicate=http%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23label', 'text/turtle; charset=utf-8', $example3 ); return $ua; } sub add_response { my $ua = shift; my $url = shift; my $content_type = shift; my $content = shift; $ua->map_response( qr{^\Q$url\E$}, HTTP::Response->new( '200', 'OK', ['Content-Type' => $content_type ], Encode::encode_utf8($content) ) ); }issue-3.t100644001750001750 134112625307401 14367 0ustar00vojvoj000000000000Catmandu-RDF-0.28/tuse strict; use warnings; use Test::More; use Catmandu::Exporter::RDF; my $turtle; my $exporter = Catmandu::Exporter::RDF->new(file => \$turtle, type => 'ttl'); my @arefs = ( { "http://x.org/alice" => { "foaf_knows" => "" }, "http://x.org/bob" => { "a" => "foaf_Person", } }, { "http://x.org/alice" => { "foaf_knows" => "" }, } ); $exporter->add($_) for @arefs; $exporter->commit; $turtle =~ s/ \./ ;/smg; is_deeply [ sort split "\n", $turtle ], [ ' , ;', ' a ;' ]; print $turtle; done_testing; exporter.t100644001750001750 307312625307401 14753 0ustar00vojvoj000000000000Catmandu-RDF-0.28/tuse strict; use warnings; use Test::More; my $pkg; BEGIN { use_ok $pkg = 'Catmandu::Exporter::RDF'; } require_ok $pkg; my $file = ""; my $data = { # example copied from RDF::Trine::Model "http://example.com/subject1" => { "http://example.com/predicate1" => [ 'Foo@en', "Bar^" ], }, "_:bnode1" => { "http://example.com/predicate2" => [ "http://example.com/object2", ], "http://example.com/predicate2" => [ "_:bnode3", ], }, }; my $exporter = $pkg->new(file => \$file, type => 'ttl'); isa_ok $exporter, $pkg; is $exporter->count, 0, 'count is zero'; $exporter->add($data); $exporter->commit; # normalize $file =~ s/("Foo".+), ("Bar".+) ./$2, $1 ./; $file = join "\n", sort split "\n", "$file"; $file .= "\n" unless $file =~ /\n$/m; is $file, <<'RDF', 'serialize Turtle'; "Bar"^^, "Foo"@en . [] [] . RDF is $exporter->count, 1, 'count is always one'; $file = ""; $exporter = $pkg->new(file => \$file); $exporter->add( { _id => '', foaf_knows => { foaf_name => 'alice' } } ); is $file, < _:b1 . _:b1 "alice" . NTRIPLES $exporter->add( { _id => '', foaf_knows => { foaf_name => 'alice' } } ); $exporter->commit; is scalar(split "\n", $file), 4, 'keep blank nodes separated'; is $exporter->count, 2, 'count is 2'; done_testing; importer.t100644001750001750 410712625307401 14743 0ustar00vojvoj000000000000Catmandu-RDF-0.28/tuse strict; use warnings; use Test::More; use Catmandu -all; my $pkg; BEGIN { use_ok $pkg = 'Catmandu::Importer::RDF'; } require_ok $pkg; isa_ok $pkg->new, $pkg; my $aref = importer('YAML', file => 't/example.yml')->first; my $expect = { 'http://example.org' => { a => '', 'http://example.org/foo' => "b\x{e4}r\@en", 'http://purl.org/dc/elements/1.1/title' => "B\x{c4}R@", 'http://purl.org/dc/elements/1.1/extent' => '42^', } }; is_deeply importer('RDF', ns => 0, file => 't/example.ttl')->first, $expect, 'disable namespace prefixes'; foreach my $file (qw(t/example.ttl t/example.rdf)) { is_deeply importer('RDF', file => $file, ns => 1)->first, $aref, "default namespace prefixes ($file)"; } { use utf8; my $ttl = ' "bär"@en .'; my $importer = importer('RDF', type => 'turtle', file => \$ttl); my $aref = $importer->first; is_deeply $aref->{'http://example.org'}->{'http://example.org/foo'}, 'bär@en', 'import from scalar with Unicode'; } { my $importer = importer('RDF', file => 't/example.ttl', triples => 1, predicate_map => 1); my $aref = $importer->to_array; is_deeply [ sort { my (undef,$x) = sort keys %$a; my (undef,$y) = sort keys %$b; $x cmp $y } @$aref ], [ { _id => 'http://example.org', a => 'rdfs_Resource' }, { _id => 'http://example.org', dc_extent => '42^xs_integer' }, { _id => 'http://example.org', dc_title => "B\x{c4}R@" }, { _id => 'http://example.org', 'http://example.org/foo' => "b\x{e4}r\@en" } ], 'import triples'; my $nt = ""; my $exporter = exporter('RDF', type => 'ntriples', file => \$nt); $exporter->add_many($aref); $exporter->commit; $importer = importer('RDF', type => 'ntriples', file => \$nt, ns => 0); is_deeply $importer->first, $expect, 'round-trip export-import-export'; } done_testing; example.rdf100644001750001750 146012625307401 15044 0ustar00vojvoj000000000000Catmandu-RDF-0.28/t bär BÄR 42 example.ttl100644001750001750 36212625307401 15054 0ustar00vojvoj000000000000Catmandu-RDF-0.28/t@prefix rdfs: . a rdfs:Resource ; "b\u00e4r"@en ; "B\u00c4R" ; 42 . example.yml100644001750001750 21212625307401 15044 0ustar00vojvoj000000000000Catmandu-RDF-0.28/t--- 'http://example.org': a: rdfs_Resource dc_title: BÄR@ dc_extent: 42^xs_integer 'http://example.org/foo': bär@en ... aref_query.t100644001750001750 163012625307401 15242 0ustar00vojvoj000000000000Catmandu-RDF-0.28/tuse strict; use warnings; use Test::More; use Catmandu ':all'; use Catmandu::Fix; use Catmandu::Fix::aref_query as => 'my_query'; { my $fixer = Catmandu::Fix->new( fixes => ['aref_query(dc_title,title)'] ); my $rdf = importer('RDF', file => 't/example.ttl')->first; ($rdf->{_uri}) = keys %$rdf; $fixer->fix($rdf); delete $rdf->{ $rdf->{_uri} }; is_deeply $rdf, { '_uri' => 'http://example.org', title => "B\x{c4}R", }, 'simple RDF fix'; } my $rdf = importer('RDF', file => 't/example.ttl')->first; sub fix { my $rdf = shift; my_query($rdf, @_); delete $rdf->{$_[-1]}; } is fix($rdf,'http://example.org','dc_title','label'), "B\x{c4}R"; is fix($rdf,'dc_title','label'), undef; $rdf->{_url} = 'http://example.org'; is fix($rdf,'dc_title','label'), "B\x{c4}R", 'respect _url field'; is fix($rdf,'http://example.com','dc_title','label'), undef; done_testing; query.sparql100644001750001750 20012625307401 15254 0ustar00vojvoj000000000000Catmandu-RDF-0.28/tSELECT ?name WHERE { ?name . } exporter-add.t100644001750001750 555412625307401 15507 0ustar00vojvoj000000000000Catmandu-RDF-0.28/tuse strict; use warnings; use Test::More; use Catmandu::Exporter::RDF; sub check_add(@) { ## no critic my $options = shift; my $data = shift; my $result = shift; my $file = ""; my $exporter = Catmandu::Exporter::RDF->new(file => \$file, %$options); $exporter->add($data); $exporter->commit; if (ref $result) { $result->($file); } else { is $file, $result, $_[0]; } } check_add { type => 'ttl', ns => '20130816' }, { _id => 'http://example.org/', dc_title => 'Subject', } => " \"Subject\" .\n", 'expand predicate URI'; check_add { type => 'ttl', ns => '20130816' }, { _id => 'http://example.org/', dc_title => 'Subject@', } => " \"Subject\" .\n", 'literal object'; check_add { type => 'ttl', ns => '20130816' }, { _id => 'http://example.org/', dct_extent => '42^xsd_integer', } => " 42 .\n", 'literal object with datatype'; check_add { type => 'ttl', ns => '20130816' }, { _id => 'http://example.org/', 'http://example.org/predicate' => { '_id' => 'http://example.com/object' }, } => " .\n", 'uri object'; check_add { type => 'ttl', ns => '20130816' }, { _id => 'http://example.org/', a => 'foaf_Organization', } => " a .\n", '"a" for rdf:type'; =todo check_add { type => 'ttl', ns => '20130816' }, { '_id' => 'http://example.org/', 'http://example.org/predicate' => { }, } => " _:b1 .\n", 'blank node object'; =cut check_add { type => 'ttl', ns => '20130816' }, { _id => 'http://www.gbv.de/', geo_location => { geo_lat => '9.93492', geo_long => '51.5393710', } } => sub { my $ttl = shift; ok $ttl =~ qr{_:[a-zA-Z0-9]+ "9.93492"} && $ttl =~ qr{ "51.5393710"} && $ttl =~ qr{ _:[a-zA-Z0-9]+}, 'nested RDF'; }; ## fixes check_add { type => 'ttl', ns => '20130816', fix => ["move_field('_id','\_id')","prepend('\_id','http://example.org/');"] }, { _id => 123, dc_title => 'Foo', } => " \"Foo\" .\n", 'fix subject URI'; check_add { type => 'ttl', ns => '20130816', fix => [ "append('dc:extent','^xsd:integer');" ] }, { _id => 'http://example.org/', dc_extent => 42, } => " \"42\" .\n", 'fix predicate'; done_testing; Catmandu000755001750001750 012625307401 14612 5ustar00vojvoj000000000000Catmandu-RDF-0.28/libRDF.pm100644001750001750 523612625307401 15731 0ustar00vojvoj000000000000Catmandu-RDF-0.28/lib/Catmandupackage Catmandu::RDF; use namespace::clean; use Catmandu::Sane; use Catmandu::Util qw(is_instance); use Moo::Role; use RDF::NS; our $VERSION = '0.28'; our %TYPE_ALIAS = ( Ttl => 'Turtle', N3 => 'Notation3', Xml => 'RDFXML', XML => 'RDFXML', Json => 'RDFJSON', ); has type => ( is => 'ro', coerce => sub { my $t = ucfirst($_[0]); $TYPE_ALIAS{$t} // $t }, ); has ns => ( is => 'ro', default => sub { RDF::NS->new }, coerce => sub { return $_[0] if is_instance($_[0],'RDF::NS'); return $_[0] if !$_[0]; return RDF::NS->new($_[0]); }, handles => ['uri'], ); 1; __END__ =encoding utf8 =head1 NAME Catmandu::RDF - Modules for handling RDF data within the Catmandu framework =begin markdown # STATUS [![Build Status](https://travis-ci.org/LibreCat/Catmandu-RDF.png)](https://travis-ci.org/LibreCat/Catmandu-RDF) [![Coverage Status](https://coveralls.io/repos/LibreCat/Catmandu-RDF/badge.png)](https://coveralls.io/r/LibreCat/Catmandu-RDF) [![Kwalitee Score](http://cpants.cpanauthors.org/dist/Catmandu-RDF.png)](http://cpants.cpanauthors.org/dist/Catmandu-RDF) =end markdown =head1 SYNOPSIS Command line client C: catmandu convert RDF --url http://dx.doi.org/10.2474/trol.7.147 --fix 'aref_query(dct_title,title)' to YAML catmandu convert RDF --file rdfdump.nt to RDF --type turtle See documentation of modules for more examples. =head1 DESCRIPTION Catmandu::RDF contains modules for handling RDF data within the L framework. RDF data is encoded/decoded in L as implemented with L. Please keep in mind that RDF is a graph-based data structuring format with specialized technologies such as SPARQL and triple stores. Using Catmandu::RDF to transform RDF to RDF (e.g. conversion from one RDF serialization to another) is possible but probably less performant than decent RDF tools. Catmandu::RDF, however, is more conventient to convert between RDF and other data formats. =head1 AVAILABLE MODULES =over =item L Serialize RDF data (as RDF/XML, RDF/JSON, Turtle, NTriples, RDFa...) =item L Parse RDF data (RDF/XML, RDF/JSON, Turtle, NTriples...) or import from a SPARQL endpoint =item L Copy values of RDF data in aREF format to a new field =back =head1 SEE ALSO This module is based on L, L, L, and L. =head1 COPYRIGHT AND LICENSE Copyright Jakob Voss, 2014- This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut release-pod-syntax.t100644001750001750 45612625307401 16611 0ustar00vojvoj000000000000Catmandu-RDF-0.28/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Exporter000755001750001750 012625307401 16422 5ustar00vojvoj000000000000Catmandu-RDF-0.28/lib/CatmanduRDF.pm100644001750001750 712412625307401 17537 0ustar00vojvoj000000000000Catmandu-RDF-0.28/lib/Catmandu/Exporterpackage Catmandu::Exporter::RDF; use namespace::clean; use Catmandu::Sane; use Moo; use RDF::Trine::Serializer; use RDF::Trine::Model; use RDF::aREF; our $VERSION = '0.28'; with 'Catmandu::RDF'; with 'Catmandu::Exporter'; # internal attributes has decoder => ( is => 'lazy' ); has serializer => ( is => 'lazy' ); has model => ( is => 'lazy' ); sub _build_decoder { RDF::aREF::Decoder->new( ns => $_[0]->ns // ($_[0]->ns eq 0 ? { } : RDF::NS->new), callback => $_[0]->model ); } sub _build_serializer { RDF::Trine::Serializer->new($_[0]->type // 'ntriples'); } sub _build_model { my $self = shift; # Streaming output when we have type => NTriples if (lc($self->type // 'ntriples') eq 'ntriples') { sub { require RDF::Trine::Statement; eval { my $st = RDF::aREF::Decoder::trine_statement(@_); $self->fh->print($self->serializer->statement_as_string($st)); }; $self->decoder->error($@) if $@; }; } else { RDF::Trine::Model->new; } } sub add { my ($self, $aref) = @_; $self->decoder->decode($aref, keep_bnode_map => 1); } sub commit { my ($self) = @_; if (ref $self->model eq 'RDF::Trine::Model') { $self->model->end_bulk_ops; $self->decoder->clean_bnodes; $self->serializer->serialize_model_to_file( $self->fh, $self->model ); } } 1; __END__ =head1 NAME Catmandu::Exporter::RDF - serialize RDF data =head1 SYNOPSIS In Perl code: use Catmandu -all; my $exporter = exporter('RDF', file => 'export.rdf', type => 'XML', fix => 'rdf.fix' ); $exporter->add( $aref ); # pass RDF data in aREF encoding $exporter->commit; =head1 DESCRIPTION This L exports RDF data in different RDF serializations. =head1 CONFIGURATION =over =item file =item fh =item encoding =item fix Default configuration options of L. The option C is supported as derived from L. For every C or for every item in C the given fixes will be applied first. =item type A serialization form can be set with option C with default value C. The option must refer to a subclass of L, for instance C for RDF/Turtle with L. The first letter is transformed uppercase, so C<< format => 'turtle' >> will work as well. In addition there are aliases C for C, C for C, C and C for C, C for C. When the option C is set to 'NTriples' the export can be streamed in all other cases the results are exported in bulk after C. =item ns The option C can refer to an instance of or to a constructor argument of L. Use a fixed date, such as "C<20130816>" to make sure your URI namespace prefixes are stable. =back =head1 METHODS See also L. =head2 add( ... ) RDF data is added given in B as implemented with L and defined at L. =head2 count Returns the number of times C has been called. In contrast to other Catmandu exporters, this does not reflect the number of exporter records because RDF data is always merged to one RDF graph. =head2 uri( $uri ) Expand and abbreviated with L. For instance "C" is expanded to "C". =cut =head1 SEE ALSO Serialization is based on L. =encoding utf8 =cut Importer000755001750001750 012625307401 16413 5ustar00vojvoj000000000000Catmandu-RDF-0.28/lib/CatmanduRDF.pm100644001750001750 2146112625307401 17550 0ustar00vojvoj000000000000Catmandu-RDF-0.28/lib/Catmandu/Importerpackage Catmandu::Importer::RDF; use open ':std', ':encoding(utf8)'; use namespace::clean; use Catmandu::Sane; use Moo; use RDF::Trine::Parser; use RDF::Trine::Model; use RDF::Trine::Store::SPARQL; use RDF::Trine::Store::LDF; use RDF::Trine::Store; use RDF::Query; use RDF::LDF; use RDF::aREF; use RDF::aREF::Encoder; use RDF::NS; our $VERSION = '0.28'; with 'Catmandu::RDF'; with 'Catmandu::Importer'; has url => ( is => 'ro' ); has base => ( is => 'ro', lazy => 1, builder => sub { defined $_[0]->file ? "file://".$_[0]->file : "http://example.org/"; } ); has encoder => ( is => 'ro', lazy => 1, builder => sub { my $ns = $_[0]->ns; RDF::aREF::Encoder->new( ns => (($ns // 1) ? $ns : { }), subject_map => !$_[0]->predicate_map, ); } ); has sparql => ( is => 'ro', lazy => 1, trigger => sub { my ($sparql, $ns) = ($_[1], $_[0]->ns); $sparql = do { local (@ARGV,$/) = $sparql; <> } if $sparql =~ /^\S+$/ && -r $sparql; my %prefix; # guess requires prefixes (don't override existing). Don't mind false positives $prefix{$_} = 1 for ($sparql =~ /\s([a-z][a-z0-0_-]*):/mig); delete $prefix{$_} for ($sparql =~ /PREFIX\s+([^:]+):/mg); $_[0]->{sparql} = join "\n", (map { $ns->SPARQL($_) } keys %prefix), $sparql; } ); has sparql_result => ( is => 'ro', default => sub { 'simple' } ); has predicate_map => ( is => 'ro', ); has triples => ( is => 'ro', ); sub generator { my ($self) = @_; if ($self->sparql) { return $self->sparql_generator; } else { return $self->rdf_generator; } } sub sparql_generator { my ($self) = @_; warn "--triples not active for sparql queries" if ($self->triples); warn "--predicate_map not active for sparql queries" if ($self->predicate_map); my $encoder = RDF::aREF::Encoder->new( ns => {} ); # never return qnames sub { state $stream = $self->_sparql_stream; if (defined($stream) && defined(my $row = $stream->next)) { if (ref $row eq 'RDF::Query::VariableBindings' || ref $row eq 'RDF::Trine::VariableBindings') { my $ref = {}; for (keys %$row) { my $val = $row->{$_}; $ref->{$_} = $self->sparql_result eq 'aref' ? $encoder->object($val) : do { # TODO: clean up if ( $val->is_resource ) { $val->uri_value; } elsif ( $val->is_literal) { $val->literal_value; } else { $val->as_string } }; } return $ref; } else { die "Expected a RDF::Query::VariableBindings or RDF::Trine::VariableBindings but got a " . ref($row); } } else { return ($stream = undef); } }; } sub rdf_generator { my ($self) = @_; sub { state $stream = $self->_rdf_stream; return unless $stream; my $aref = { }; if ($self->triples) { if (my $triple = $stream->next) { $aref = $self->encoder->triple( $triple->subject, $triple->predicate, $triple->object ); } else { return ($stream = undef); } } else { # TODO: include namespace mappings if requested $self->encoder->add_hashref( $stream->as_hashref, $aref ); if ($self->url) { $aref->{_url} = $self->url; } $stream = undef; } if ($self->url) { # RDF::Trine::Parser parses data from URL to UTF-8 # but we want internal character sequences _utf8_decode($aref); } return $aref; }; } sub _utf8_decode { if (ref $_[0] eq 'HASH') { # FIXME: UTF-8 in property values foreach (values %{$_[0]}) { ref($_) ? _utf8_decode($_) : utf8::decode($_); } } else { foreach (@{$_[0]}) { ref($_) ? _utf8_decode($_) : utf8::decode($_); } } } sub _sparql_stream { my ($self) = @_; die "need an url" unless $self->url; $self->log->info("parsing: " . $self->sparql); my $store; # Check if this server is an LDF server my $ldf_client = RDF::LDF->new(url => $self->url); if ($ldf_client->is_fragment_server) { $store = RDF::Trine::Store->new_with_config({ storetype => 'LDF', url => $self->url }); } else { $store = RDF::Trine::Store->new_with_config({ storetype => 'SPARQL', url => $self->url }); } unless ($store) { $self->log->error("failed to connect to " . $self->url); return undef; } my $model = RDF::Trine::Model->new($store); my $rdf_query = RDF::Query->new($self->sparql); unless ($rdf_query) { $self->log->error("failed to parse " . $self->sparql); return undef; } my $iterator = $rdf_query->execute($model); unless ($iterator) { $self->log->error("failed to execute " . $self->sparql . " at " . $self->url); return undef; } } sub _rdf_stream { my ($self) = @_; my $model = RDF::Trine::Model->new; my $parser = $self->type ? RDF::Trine::Parser->new( $self->type ) : 'RDF::Trine::Parser'; if ($self->url) { $parser->parse_url_into_model( $self->url, $model ); } else { my $from_scalar = (ref $self->file // '') eq 'SCALAR'; if (!$self->type and $self->file and !$from_scalar) { $parser = $parser->guess_parser_by_filename($self->file); } if ($from_scalar) { $parser->parse_into_model( $self->base, ${$self->file}, $model ); } else { $parser->parse_file_into_model( $self->base, $self->file // $self->fh, $model ); } } return $model->as_stream; } 1; __END__ =head1 NAME Catmandu::Importer::RDF - parse RDF data =head1 SYNOPSIS Command line client C: catmandu convert RDF --url http://d-nb.info/gnd/4151473-7 to YAML catmandu convert RDF --file rdfdump.ttl to JSON # Query a SPARQL endpoint catmandu convert RDF --url http://dbpedia.org/sparql --sparql "SELECT ?film WHERE { ?film dct:subject }" catmandu convert RDF --url http://example.org/sparql --sparql query.rq # Query a Linked Data Fragment endpoint catmandu convert RDF --url http://fragments.dbpedia.org/2014/en --sparql "SELECT ?film WHERE { ?film dct:subject }" In Perl code: use Catmandu::Importer::RDF; my $url = "http://dx.doi.org/10.2474/trol.7.147"; my $rdf = Catmandu::Importer::RDF->new( url => $url )->first; =head1 DESCRIPTION This L can be use to import RDF data from URLs, files or input streams, SPARQL endpoints, and Linked Data Fragment endpoints. By default an RDF graph is imported as single item in aREF format (see L). =head1 CONFIGURATION =over =item url URL to retrieve RDF from. =item type RDF serialization type (e.g. C for RDF/Turtle). =item base Base URL. By default derived from the URL or file name. =item ns Use default namespace prefixes as provided by L to abbreviate predicate and datatype URIs. Set to C<0> to disable abbreviating URIs. Set to a specific date to get stable namespace prefix mappings. =item triples Import each RDF triple as one aREF subject map (default) or predicate map (option C), if enabled. =item predicate_map Import RDF as aREF predicate map, if possible. =item file =item fh =item encoding =item fix Default configuration options of L. =item sparql The SPARQL query to be executed on the URL endpoint (currectly only SELECT is supported). The query can be supplied as string or as filename. The importer tries to automatically add missing PREFIX statements from the default namespace prefixes. =item sparql_result Encoding of SPARQL result values. With C, query results are encoded in aREF format, with URIs in C> and C> (no qNames) and literal nodes appended by C<@> and optional language code. By default (value C), all RDF nodes are simplfied to their literal form. =back =head1 METHODS See L. =head1 SEE ALSO L, L =encoding utf8 =cut Fix000755001750001750 012625307401 15340 5ustar00vojvoj000000000000Catmandu-RDF-0.28/lib/Catmanduaref_query.pm100644001750001750 520112625307401 20176 0ustar00vojvoj000000000000Catmandu-RDF-0.28/lib/Catmandu/Fixpackage Catmandu::Fix::aref_query; use Catmandu::Sane; use Moo; use Catmandu::Fix; our $VERSION = '0.28'; with 'Catmandu::Fix::Base'; has query => ( is => 'ro', coerce => sub { RDF::aREF::Query->new( query => $_[0] ) } # TODO: ns ); has path => ( is => 'ro', ); has subject => ( is => 'ro', ); around 'BUILDARGS', sub { my $orig = shift; my $self = shift; if (@_ == 3) { $orig->($self, subject => $_[0], query => $_[1], path => $_[2] ); } elsif (@_ == 2) { $orig->($self, query => $_[0], path => $_[1] ); } else { $orig->($self, @_); } }; sub emit { my ($self, $fixer) = @_; my $subject = defined $self->subject ? $fixer->emit_string($self->subject) : 'undef'; my $path = $fixer->split_path($self->path); my $query = $fixer->capture($self->query); # TODO: replace/append/single-value mode my $var = $fixer->var; my $origin = $fixer->generate_var; my $values = $fixer->generate_var; my $perl = join "\n", "my ${origin} = ${subject} // ${var}->{_uri} // ${var}->{_url};", "my ${values} = [ ${query}->apply( ${var}, ${origin} ) ];", $fixer->emit_create_path( $var, $path, sub { my $var = shift; join "\n", map { " $_" } '', "if (is_array_ref(${var})) {", " push \@{${var}}, \@{${values}};", "} else {", " if (defined ${var}) {", " unshift \@{${values}}, ${var};", " }", " ${var} = \@{${values}} > 1 ? ${values} : ${values}->[0];", "}" ; }); # print $perl."\n"; return $perl; } 1; __END__ =head1 NAME Catmandu::Fix::aref_query - copy values of RDF in aREF to a new field =head1 SYNOPSIS In Catmandu Fix language aref_query( dc_title => title ) aref_query( query => 'dc_title', field => 'title' ) aref_query( 'http://example.org/subject', dc_title => title ) In Perl code use Catmandu::Fix::aref_query as => 'my_query'; use RDF::aREF; my $rdf = encode_aref("example.ttl"); my_query( $rdf, dc_title => 'title' ); =head1 DESCRIPTION This L can be used to map values of imported RDF, given in L structure =head1 ARGUMENTS =over =item subject Optional subject URI (first argument). By default, the fields C<_uri> and C<_uri> are used. =item query aREF query expression (first or second argument) =item path Field name to map RDF data to (last argument). Existing values are also kept. =back =head1 SEE ALSO Function C in L =cut