blib/lib/FAIR/Accessor/Distribution.pm untested

filter: Statementstmt 0.0% 0 / 114 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 27 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 168 CC 9 SCAR 29.6
CC
9
Cov
0%
makeSensibleStatement
42.0
types
12.0
ProjectionModel
6.0
CRAP 19.4
1 package FAIR::Accessor::Distribution;
2 $FAIR::Accessor::Distribution::VERSION = '1.0';
3  
4  
5  
6 use strict;
7 use Moose;
8 use Data::UUID;
9 use RDF::Trine::Store::Memory;
10 use RDF::Trine::Model;
11  
12 with 'FAIR::CoreFunctions';
13  
14 has 'NS' => (
15 is => 'rw',
16 );
17  
18 has 'downloadURL'=> (
19 is => 'rw',
20 isa => 'Str',
21 );
22  
23 has 'source'=> (
24 is => 'rw',
25 isa => 'Str',
26 );
27  
28 has 'subjecttemplate'=> (
29 is => 'rw',
30 isa => 'Str',
31 );
32  
33 has 'subjecttype'=> (
34 is => 'rw',
35 isa => 'Str',
36 );
37  
38 has 'predicate'=> (
39 is => 'rw',
40 isa => 'Str',
41 );
42  
43 has 'objecttemplate'=> (
44 is => 'rw',
45 isa => 'Str',
46 );
47  
48 has 'objecttype'=> (
49 is => 'rw',
50 isa => 'Str',
51 );
52  
53 has 'availableformats'=> (
54 is => 'rw',
55 isa => 'ArrayRef[Str]',
56 );
57  
58 has 'distributionType' => (
59 is => 'rw',
60 isa => 'ArrayRef',
61 default => sub {["dcat:Distribution", "dc:Dataset"]},
62 );
63  
64 has 'baseURI' => (
65 is => 'rw',
66 isa => 'Str',
67 default => "http://datafairport.org/local/Source",
68 );
69  
70  
71 has 'UUID' => (
72 is => 'rw',
73 isa => 'Str',
74 default => sub { my $ug =Data::UUID->new; my $uuid = $ug->create(); return $ug->to_string( $uuid ) }
75 );
76  
77 #has 'model' => (
78 # is => 'rw',
79 # isa => 'RDF::Trine::Model',
80 # default => sub {my $store = RDF::Trine::Store::Memory->new(); return RDF::Trine::Model->new($store)}
81 #);
82  
83 has 'Projectionmodel' => (
84 isa => "RDF::Trine::Model",
85 is => "rw",
86 default => sub {my $store = RDF::Trine::Store::Memory->new(); return RDF::Trine::Model->new($store)}
87 );
88  
89  
90 sub types {
91 my ($self) = @_;
92 my $formats = $self->availableformats();
93 my $formatstr = join ",", @$formats;
94 my @types = @{$self->distributionType};
95 if (($formatstr =~/turtle/) || ($formatstr =~ /rdf/) || ($formatstr =~ /quads/)) {
96 push @types, "void:Dataset";
97 }
98
99 if ($self->source) { # if it has this, then it is TPF
100 push @types, "fair:Projector";
101 }
102 return @types;
103 }
104  
105 sub ProjectionModel {
106 my ($self) = @_;
107 my $uuid = $self->UUID();
108 my $NS = $self->NS();
109  
110 my $model = $self->Projectionmodel;
111
112 my $SRC = "http://datafairport.org/local/Source$uuid";
113 my $MAP = "http://datafairport.org/local/Mappings$uuid";
114 my $SMAP = "http://datafairport.org/local/SubjectMap$uuid";
115 my $POMAP = "http://datafairport.org/local/POMap$uuid";
116 my $OMAP = "http://datafairport.org/local/ObjectMap$uuid";
117 my $SMAP2 = "http://datafairport.org/local/SubjectMap2$uuid";
118
119
120 my $statement;
121
122 # $statement = $self->makeSensibleStatement($SRC, $self->NS->rml('source'), $self->source);
123 $statement = $self->makeSensibleStatement($SRC, $self->NS->rml('source'), $self->downloadURL);
124 $model->add_statement($statement);
125
126
127 $statement = $self->makeSensibleStatement($MAP, $self->NS->rml('logicalSource'), $SRC);
128 $model->add_statement($statement);
129  
130
131 $statement = $self->makeSensibleStatement($SRC, $self->NS->rml('hasMapping'), $MAP);
132 $model->add_statement($statement);
133 # <SRC> rml:referenceFormulation ql:CSV
134 $statement = $self->makeSensibleStatement($SRC, $self->NS->rml('referenceFormulation'), $self->NS->ql('TriplePatternFragments'));
135 $model->add_statement($statement);
136  
137  
138
139 # <MAP> rr:subjectMap <SMAP>
140 $statement = $self->makeSensibleStatement($MAP, $self->NS->rr('subjectMap'), $SMAP);
141 $model->add_statement($statement);
142 # <SMAP> rr:template "http://something/{ID}"
143  
144  
145 my $templateurl = RDF::Trine::Node::Literal->new($self->subjecttemplate);
146 $statement = $self->makeSensibleStatement($SMAP, $self->NS->rr('template'), $templateurl);
147 $model->add_statement($statement);
148  
149 $statement = $self->makeSensibleStatement($SMAP, $self->NS->rr('class'), $self->subjecttype);
150 $model->add_statement($statement);
151  
152
153
154 # <MAP> rr:predicateObjectMap <POMAP>
155 $statement = $self->makeSensibleStatement($MAP, $self->NS->rr('predicateObjectMap'), $POMAP);
156 $model->add_statement($statement);
157 #
158 # <POMAP> rr:predicate {$predicate}
159 $statement = $self->makeSensibleStatement($POMAP, $self->NS->rr('predicate'), $self->predicate);
160 $model->add_statement($statement);
161 # <POMAP> rr:objectMap <OMAP>
162 $statement = $self->makeSensibleStatement($POMAP, $self->NS->rr('objectMap'), $OMAP);
163 $model->add_statement($statement);
164
165
166
167 #
168 # <OMAP> rr:parentTriplesMap <OBJMAP>
169 $statement = $self->makeSensibleStatement($OMAP, $self->NS->rr('parentTriplesMap'), $SMAP2);
170 $model->add_statement($statement);
171 # <OMAP> rr:subjecctMap <SMAP2>
172 # <SMAP2> rr:template "http://somethingelse/{out}
173 if ($self->objecttype =~ /\#string/){
174 $templateurl = RDF::Trine::Node::Literal->new("{value}");
175 } else {
176 $templateurl = RDF::Trine::Node::Literal->new($self->objecttemplate);
177 }
178 $statement = $self->makeSensibleStatement($SMAP2, $self->NS->rr('template'), $templateurl);
179 $model->add_statement($statement);
180  
181 $statement = $self->makeSensibleStatement($SMAP2, $self->NS->rr('class'), $self->objecttype);
182 $model->add_statement($statement);
183  
184 return $model;
185  
186 }
187  
188 sub makeSensibleStatement {
189 my ($self, $s, $p, $o) = @_;
190 my ($subject, $predicate, $object);
191 my $NS = $self->NS();
192
193 if (($s =~ /^http:/) || ($s =~ /^https:/) || ref($s)) {
194 $subject = $s;
195 } else {
196 my ($ns, $sub) = split /:/, $s;
197 $subject = $NS->$ns($sub); # add the namespace
198 }
199
200 if (($p =~ /^http:/) || ($p =~ /^https:/) || ref($p)) {
201 $predicate = $p;
202 } else {
203 my ($ns, $pred) = split /:/, $p;
204 $predicate = $NS->$ns($pred); # add the namespace
205 }
206
207 if (($o =~ /^http:/) || ($o =~ /^https:/) || ref($o)) { # if its a URL or an object
208 $object = $o
209 } elsif ((!($o =~ /\s/)) && ($o =~ /\S+:\S+/)){ # if it looks like a qname tag
210 my ($ns,$obj) = split /:/, $o;
211 if ($NS->$ns($obj)) {
212 $object = $NS->$ns($obj); # add the namespace
213 }
214 } else {
215 $object = $o
216 }
217
218 my $statement = statement($subject, $predicate, $object);
219
220 return $statement;
221
222 }
223  
224  
225 1;
226  
227 __END__
228  
229 =pod
230  
231 =encoding UTF-8
232  
233 =head1 NAME
234  
235 FAIR::Accessor::Distribution
236  
237 =head1 VERSION
238  
239 version 1.0
240  
241 =head1 Name FAIR::Accessor::Distribution
242  
243 =head1 Description
244  
245 This represents a DCAT Distribution for the FAIR Accessor
246  
247 =head1 AUTHOR
248  
249 Mark Denis Wilkinson (markw [at] illuminae [dot] com)
250  
251 =head1 COPYRIGHT AND LICENSE
252  
253 This software is Copyright (c) 2016 by Mark Denis Wilkinson.
254  
255 This is free software, licensed under:
256  
257 The Apache License, Version 2.0, January 2004
258  
259 =cut