[libmodule-install-rdf-perl] 15/34: write META.ttl example
Jonas Smedegaard
js at alioth.debian.org
Fri Aug 9 14:36:18 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libmodule-install-rdf-perl.
commit 9a60c2a3411430ec7418fdb90cdbbfd00815dec0
Author: Toby Inkster <mail at tobyinkster.co.uk>
Date: Sat Mar 16 12:51:39 2013 +0000
write META.ttl example
--HG--
branch : Module-Install-RDF
---
Makefile.PL | 4 +-
lib/Module/Install/Admin/RDF.pm | 77 ++++++++++++++++++++++++++++++++++++---
lib/Module/Install/RDF.pm | 16 ++++++--
3 files changed, 88 insertions(+), 9 deletions(-)
diff --git a/Makefile.PL b/Makefile.PL
index e7f29c8..61022a4 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1 +1,3 @@
-use inc::Module::Package 'RDF:standard 0.003';
+use inc::Module::Package 'RDF:tobyink 0.010';
+
+write_meta_ttl;
diff --git a/lib/Module/Install/Admin/RDF.pm b/lib/Module/Install/Admin/RDF.pm
index ed8778e..8efdaa4 100644
--- a/lib/Module/Install/Admin/RDF.pm
+++ b/lib/Module/Install/Admin/RDF.pm
@@ -30,16 +30,16 @@ sub rdf_metadata
}
$parser = undef;
-
+
while (<meta/*.{rdf,rdfxml,rdfx}>)
{
my $iri = URI::file->new_abs($_);
$parser ||= RDF::Trine::Parser->new('RDFXML');
$parser->parse_file_into_model("$iri", $_, $model);
}
-
+
$parser = undef;
-
+
while (<meta/*.{pret,pretdsl}>)
{
my $iri = URI::file->new_abs($_);
@@ -47,7 +47,7 @@ sub rdf_metadata
$parser ||= RDF::TrineX::Parser::Pretdsl->new;
$parser->parse_file_into_model("$iri", $_, $model);
}
-
+
return $model;
}
@@ -64,11 +64,78 @@ sub rdf_project_uri
my %counts = map {
$_ => $model->count_statements($_, undef, undef);
- } @candidates;
+ } @candidates;
my @best = sort { $counts{$b} <=> $counts{$a} } @candidates;
return $best[0] if @best;
return undef;
}
+sub write_meta_ttl
+{
+ no warnings;
+
+ my ($self, $file) = @_;
+
+ my %NS = qw(
+ rdf http://www.w3.org/1999/02/22-rdf-syntax-ns#
+ rdfs http://www.w3.org/2000/01/rdf-schema#
+ foaf http://xmlns.com/foaf/0.1/
+ doap http://usefulinc.com/ns/doap#
+ cpan http://purl.org/NET/cpan-uri/person/
+ dcs http://ontologi.es/doap-changeset#
+ cpant http://purl.org/NET/cpan-uri/terms#
+ );
+
+ my $prj = $self->rdf_project_uri;
+ $NS{dist} = $1 if defined $prj && $prj->uri =~ m{^(http://purl\.org/NET/cpan-uri/dist/.+/)project};
+
+ my $ser = eval {
+ require RDF::TrineX::Serializer::MockTurtleSoup;
+ "RDF::TrineX::Serializer::MockTurtleSoup"->new(
+ abbreviate => qr{/NET/cpan-uri/},
+ colspace => 17,
+ indent => "\t",
+ labelling => [
+ "$NS{rdfs}label",
+ "$NS{foaf}name",
+ "$NS{doap}name",
+ ],
+ namespaces => \%NS,
+ priorities => sub {
+ my ($ser, $n, $m) = @_;
+ return 100 if $m->count_statements(
+ $n,
+ RDF::Trine::iri("$NS{rdf}type"),
+ RDF::Trine::iri("$NS{doap}Project"),
+ );
+ return 80 if $m->count_statements(
+ $n,
+ RDF::Trine::iri("$NS{rdf}type"),
+ RDF::Trine::iri("$NS{doap}Version"),
+ );
+ return 60 if $m->count_statements(
+ $n,
+ RDF::Trine::iri("$NS{rdf}type"),
+ RDF::Trine::iri("$NS{foaf}Person"),
+ );
+ return 40 if $m->count_statements(
+ $n,
+ RDF::Trine::iri("$NS{foaf}name"),
+ undef,
+ );
+ return 0;
+ },
+ repeats => 1,
+ );
+ } || do {
+ "RDF::Trine::Serializer::Turtle"->new(
+ namespaces => \%NS,
+ );
+ };
+
+ open my $out, ">", $file or die "Could not open '$file': $!";
+ $ser->serialize_model_to_file($out, $self->rdf_metadata);
+}
+
1;
diff --git a/lib/Module/Install/RDF.pm b/lib/Module/Install/RDF.pm
index fc86df1..d4d2ff6 100644
--- a/lib/Module/Install/RDF.pm
+++ b/lib/Module/Install/RDF.pm
@@ -13,6 +13,14 @@ sub rdf_metadata
$self->admin->rdf_metadata(@_) if $self->is_admin;
}
+sub write_meta_ttl
+{
+ my $self = shift;
+ my $file = shift || "META.yml";
+ $self->admin->write_meta_ttl($file) if $self->is_admin;
+ $self->clean_files($file);
+}
+
1;
__END__
@@ -24,15 +32,17 @@ Module::Install::RDF - advanced metadata for your distribution
In Makefile.PL:
- rdf_metadata;
+ rdf_metadata; # reads "meta/*"
+ write_meta_ttl; # writes "META.ttl"
=head1 DESCRIPTION
This module doesn't really do much on its own, but is a pre-requisite for
L<Module::Install::DOAP>.
-Specifically, it reads all the RDF it can find in the distribution's 'meta'
-directory and exposes it for other modules to make use of.
+Specifically, it reads all the RDF it can find in the distribution's "meta"
+directory and exposes it for other modules to make use of. It also allows you
+to write out a combined graph using Turtle.
=head1 BUGS
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmodule-install-rdf-perl.git
More information about the Pkg-perl-cvs-commits
mailing list