[libcatmandu-rdf-perl] 02/20: Adding the rdf-ldf reconciliation fix

Jonas Smedegaard dr at jones.dk
Sat Oct 28 03:10:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag upstream/0.32
in repository libcatmandu-rdf-perl.

commit 4c7e54a465154f4e7944a4d3ba33d6ef5addf482
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date:   Mon Nov 28 16:27:28 2016 +0100

    Adding the rdf-ldf reconciliation fix
---
 Build.PL                               |  4 +-
 META.json                              |  6 +--
 lib/Catmandu/Fix/rdf_ldf_statements.pm | 93 ++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+), 5 deletions(-)

diff --git a/Build.PL b/Build.PL
index d159d02..09b9a1e 100644
--- a/Build.PL
+++ b/Build.PL
@@ -1,7 +1,7 @@
-# This Build.PL for Catmandu-RDF was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.014.
+# 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.034;
+use Module::Build::Tiny 0.039;
 Build_PL();
diff --git a/META.json b/META.json
index 4e3c511..1c3ccc0 100644
--- a/META.json
+++ b/META.json
@@ -4,7 +4,7 @@
       "Jakob Voß"
    ],
    "dynamic_config" : 0,
-   "generated_by" : "Dist::Zilla version 5.035, Dist::Milla version v1.0.8, CPAN::Meta::Converter version 2.150001",
+   "generated_by" : "Dist::Zilla version 5.035, Dist::Milla version v1.0.15, CPAN::Meta::Converter version 2.150001",
    "license" : [
       "perl_5"
    ],
@@ -26,12 +26,12 @@
    "prereqs" : {
       "configure" : {
          "requires" : {
-            "Module::Build::Tiny" : "0.034"
+            "Module::Build::Tiny" : "0.039"
          }
       },
       "develop" : {
          "requires" : {
-            "Dist::Milla" : "v1.0.8",
+            "Dist::Milla" : "v1.0.15",
             "Test::Pod" : "1.41"
          }
       },
diff --git a/lib/Catmandu/Fix/rdf_ldf_statements.pm b/lib/Catmandu/Fix/rdf_ldf_statements.pm
new file mode 100644
index 0000000..4283ff0
--- /dev/null
+++ b/lib/Catmandu/Fix/rdf_ldf_statements.pm
@@ -0,0 +1,93 @@
+package Catmandu::Fix::rdf_ldf_statements;
+
+use Catmandu::Sane;
+use Moo;
+use RDF::LDF;
+use Catmandu::Fix::Has;
+
+has path      => (fix_arg => 1);
+has subject   => (fix_opt => 1, default => sub { undef });
+has predicate => (fix_opt => 1, default => sub { undef });
+has url       => (fix_opt => 1, default => sub { undef });
+
+has client    => (is => 'lazy');
+
+with 'Catmandu::Fix::SimpleGetValue';
+
+sub _build_client {
+    my ($self) = @_;
+    my $url = $self->url // 'http://data.linkeddatafragments.org/viaf';
+    RDF::LDF->new(url => $url);
+}
+
+sub emit_value {
+    my ($self,$var,$fixer) = @_;
+    my $subject_var   = $fixer->capture($self->subject);
+    my $predicate_var = $fixer->capture($self->predicate);
+    my $client_var    = $fixer->capture($self->client);
+    my $it            = $fixer->generate_var;
+    my $st            = $fixer->generate_var;
+
+    my $perl = <<EOF;
+if (is_value(${var})) {
+    my ${it} = ${client_var}->get_statements(${subject_var},${predicate_var},${var});
+    if (${it}) {
+      ${var} = [];
+      while (my ${st} = ${it}->()) {
+          push \@{${var}} , ${st}->subject->uri;
+      }
+    }
+}
+EOF
+    $perl;
+}
+
+=head1 NAME
+
+Catmandu::Fix::rdf_ldf_statements - lookup an object into a LDF endpoint
+
+=head1 SYNOPSIS
+
+    # Replace a name with an array of matching VIAF records
+    # name: "\"Einstein, Albert, 1879-1955\""
+    rdf_ldf_statements(name,url:"http://data.linkedatafragments.org/viaf",predicate:"http://schema.org/alternateName")
+
+    # name:
+    #   - http://viaf.org/viaf/75121530
+
+=head1 DESCRIPTION
+
+This L<Catmandu::Fix> can be used to find at a Linked Data Fragments endpoint
+all subject URIs for which the object has a specific value found at a path. E.g.
+
+   rdf_ldf_statements(name,url:"http://data.linkedatafragments.org/viaf")
+
+ means, search at the endpoint http://data.linkedatafragments.org/viaf all the
+ subjects for which the object is the value found in 'name', and replace the name value
+ with all the found subjects.
+
+=head1 ARGUMENTS
+
+=over
+
+=item subject
+
+Optional subject URI to be used in the LDF query
+
+=item predicate
+
+Optional predicate URI to be used in the LDF query
+
+=item url
+
+Required URL to the Linked Data Fragments endpoint
+
+=back
+
+=head1 SEE ALSO
+
+L<Catmandu::Fix>
+
+=cut
+
+1;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-rdf-perl.git



More information about the Pkg-perl-cvs-commits mailing list