RDF/RDB2RDF/R2RML.pm

filter: Statementstmt 72.6% 204 / 281 Branchbran 47.3% 70 / 148 Conditioncond 56.7% 21 / 37 MC/DCmcdc 30.0% 6 / 20 Subroutinesub 91.3% 21 / 23 Podpod 100% 2 / 2 totaltotal 63.4% 324 / 511 CC 107 SCAR 36.8
CC
107
Cov
63%
_r2rml_RefObjectMap
110.0
_r2rml_TriplesMap
55.6
_r2rml_ObjectMap
51.0
CRAP 39.7
« RDF/RDB2RDF/Simple.pm ↑ Summary RDF/RDB2RDF.pm »
1 package RDF::RDB2RDF::R2RML;
2  
3 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Digest::MD5 qw[md5_hex];
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use RDF::Trine qw[statement blank literal];
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use RDF::Trine::Namespace qw[rdf rdfs owl xsd];
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Scalar::Util qw[blessed];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Storable qw[dclone];
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 our $rr = RDF::Trine::Namespace->new('http://www.w3.org/ns/r2rml#');
14 5 our $rrx = RDF::Trine::Namespace->new('http://purl.org/r2rml-ext/');
15  
16 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use base qw[
Subroutine BEGIN: called CC=1 SCAR=0.0
18 RDF::RDB2RDF::Simple
19 5 ];
20  
21 5 our $AUTHORITY = 'cpan:TOBYINK';
22 5 our $VERSION = '0.008';
23  
24 sub _COL_
25 18 ▶{
Subroutine _COL_: called CC=1 SCAR=0.0
26 package
27 RDF::RDB2RDF::R2RML::_COL_;
28 5 ▶ use overload fallback => 1, q[""] => sub { ${+shift} };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
29 18 bless \$_[0];
30 }
31  
32 sub new
33 4 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
34 4 my ($class, $r2rml) = @_;
35 4 my $self = $class->SUPER::new();
36 4 $self->_r2rml($r2rml);
37 4 return $self;
38 }
39  
40 sub process_turtle
41 0 ▶{
Subroutine process_turtle: not called CC=2 SCAR=17.9
Pod documented
42 0 my ($self, $dbh, %options) = @_;
43 0 my $rv = $self->SUPER::process_turtle($dbh, %options);
44
45 0 ▶ unless ($options{no_r2rml})
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"no_r2rml"}) 0 0 0
46 {
47 my $r2rml = RDF::Trine::Serializer
48 ->new('Turtle', namespaces => { $self->namespaces })
49 0 ->serialize_model_to_string($self->{r2rml});
50 0 $r2rml =~ s/^/# /gm;
51 0 $rv = "# R2RML\n#\n${r2rml}\n${rv}";
52 }
53 }
54  
55 sub _r2rml
56 4 ▶{
Subroutine _r2rml: called CC=4 SCAR=14.0
57 4 my ($self, $r2rml) = @_;
58
59 4 ▶ unless (blessed($r2rml) and $r2rml->isa('RDF::Trine::Model'))
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($r2rml) and $r2rml->isa("RDF::Trine::Model")) 4 0 4
Condition33%1/3
builtin::blessed($r2rml) and $r2rml->isa("RDF::Trine::Model")
!ll&&!rl&&r
400
MC/DC0%0/2
builtin::blessed($r2rml) and $r2rml->isa("RDF::Trine::Model")
builtin::blessed($r2rml) $r2rml->isa("RDF::Trine::Model")
Truth table33%1/3
A and B
A= builtin::blessed($r2rml)B= $r2rml->isa("RDF::Trine::Model")
ABresult
0X0
100
111
60 {
61 4 $self->{namespaces} = RDF::Trine::NamespaceMap->new;
62 4 my $parser = RDF::Trine::Parser->new('Turtle', namespaces=>$self->{namespaces});
63 4 my $model = RDF::Trine::Model->temporary_model;
64 4 $parser->parse_into_model('http://example.com/', $r2rml, $model);
65 4 $r2rml = $model;
66 }
67
68 4 my @TMC = values %{ {
69 4 map { $_->as_ntriples => $_ }
70 (
71 $r2rml->subjects($rdf->type, $rr->TriplesMap),
72 $r2rml->subjects($rdf->type, $rr->TriplesMapClass),
73 $r2rml->subjects($rr->subjectMap, undef),
74 )
75 } };
76
77 4 foreach my $tmc (@TMC)
78 {
79 11 $self->_r2rml_TriplesMap($r2rml, $tmc);
80 }
81
82 4 $self->{r2rml} = $r2rml;
83 }
84  
85 sub _r2rml_TriplesMap
86 11 ▶{
Subroutine _r2rml_TriplesMap: called CC=29 SCAR=40.2
87 11 my ($self, $r2rml, $tmc) = @_;
88 11 my $mapping = {};
89
90 11 ▶ if ( $self->{tmc}{$tmc} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tmc"}{$tmc}) 0 11 11
91 {
92 0 return $self->{tmc}{$tmc};
93 }
94
95 11 my ($tablename, $sqlquery);
96 11 foreach ($r2rml->objects_for_predicate_list($tmc, $rr->SQLQuery, $rr->sqlQuery))
97 {
98 0 ▶ next unless $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->is_literal 0 0 0
99 0 $sqlquery = $_->literal_value;
100 0 last;
101 }
102 11 ▶ if ($sqlquery)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlquery) { } 0 11 11
103 {
104 0 $tablename = sprintf('+q%s', md5_hex($sqlquery));
105 0 $mapping->{sql} = $sqlquery;
106 }
107 else
108 {
109 11 foreach ($r2rml->objects($tmc, $rr->tableName))
110 {
111 4 ▶ next unless $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->is_literal 0 4 4
112 4 $tablename = $_->literal_value;
113 4 last;
114 }
115 11 ▶ if ($tablename)
Branch: 1 branch
BranchTrueFalseTotal
if ($tablename) 4 7 11
116 {
117 4 foreach ($r2rml->objects($tmc, $rr->tableOwner))
118 {
119 0 ▶ next unless $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->is_literal 0 0 0
120 0 $tablename = sprintf('%s.%s', $_->literal_value, $tablename);
121 0 last;
122 }
123 }
124 }
125
126 11 ▶ unless ($tablename)
Branch: 1 branch
BranchTrueFalseTotal
unless ($tablename) 7 4 11
127 {
128 7 LOGICALTABLE: foreach my $lt ($r2rml->objects($tmc, $rr->logicalTable))
129 {
130 7 ▶ next LOGICALTABLE if $lt->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
if $lt->is_literal 0 7 7
131  
132 7 foreach ($r2rml->objects_for_predicate_list($lt, $rr->sqlQuery, $rr->SQLQuery))
133 {
134 2 ▶ next unless $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->is_literal 0 2 2
135 2 $sqlquery = $_->literal_value;
136 2 last;
137 }
138 7 ▶ if ($sqlquery)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlquery) 2 5 7
139 {
140 2 $tablename = sprintf('+q%s', md5_hex($sqlquery));
141 2 $mapping->{sql} = $sqlquery;
142 2 last LOGICALTABLE;
143 }
144  
145 5 TABLENAME: foreach ($r2rml->objects($lt, $rr->tableName))
146 {
147 5 ▶ next TABLENAME unless $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->is_literal 0 5 5
148 5 $tablename = $_->literal_value;
149 5 last TABLENAME;
150 }
151 5 ▶ if ($tablename)
Branch: 1 branch
BranchTrueFalseTotal
if ($tablename) 5 0 5
152 {
153 5 TABLEOWNER: foreach ($r2rml->objects($tmc, $rr->tableOwner))
154 {
155 0 ▶ next TABLEOWNER unless $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->is_literal 0 0 0
156 0 $tablename = sprintf('%s.%s', $_->literal_value, $tablename);
157 0 last TABLEOWNER ;
158 }
159 5 last LOGICALTABLE;
160 }
161 }
162 }
163
164 11 ▶ return unless $tablename;
Branch: 1 branch
BranchTrueFalseTotal
unless $tablename 0 11 11
165 11 $self->{tmc}{$tmc} = $mapping;
166 11 ▶ $mapping->{from} = $tablename unless defined $mapping->{sql};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mapping->{"sql"} 9 2 11
167
168 11 foreach ($r2rml->objects($tmc, $rr->subjectMap))
169 {
170 11 ▶ next if $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
if $_->is_literal 0 11 11
171 11 $self->_r2rml_SubjectMap($r2rml, $_, $mapping);
172 11 last;
173 }
174
175 11 ▶ unless ($mapping->{about})
Branch: 1 branch
BranchTrueFalseTotal
unless ($mapping->{"about"}) 0 11 11
176 {
177 0 ($mapping->{about}) = grep { !$_->is_literal } $r2rml->objects_for_predicate_list($tmc, $rr->subject);
178 }
179  
180 11 foreach ($r2rml->objects($tmc, $rr->predicateObjectMap))
181 {
182 17 ▶ next if $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
if $_->is_literal 0 17 17
183 17 $self->_r2rml_PredicateObjectMap($r2rml, $_, $mapping);
184 }
185  
186 11 my $key = $tablename;
187 11 ▶ while (defined $self->{mappings}{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"mappings"}{$key}) 3 11 14
188 {
189 3 $key = sprintf('+t%s', md5_hex($key));
190 }
191
192 11 $self->{mappings}{$key} = $mapping;
193
194 11 return $mapping;
195 }
196  
197 sub _r2rml_graph
198 28 ▶{
Subroutine _r2rml_graph: called CC=8 SCAR=33.3
199 28 my ($self, $r2rml, $thing) = @_;
200
201 my ($graph) =
202 6 ▶ map { $_->is_resource ? $_->uri : $_->as_ntriples }
Branch: 1 branch
BranchTrueFalseTotal
$_->is_resource ? : 6 0 6
203 28 grep { !$_->is_literal }
204 $r2rml->objects($thing, $rr->graph);
205 28 ▶ return $graph if $graph;
Branch: 1 branch
BranchTrueFalseTotal
if $graph 6 22 28
206  
207 22 foreach my $map ($r2rml->objects($thing, $rr->graphMap))
208 {
209 ($graph) =
210 0 ▶ map { $_->is_resource ? $_->uri : $_->as_ntriples }
Branch: 1 branch
BranchTrueFalseTotal
$_->is_resource ? : 0 0 0
211 0 grep { !$_->is_literal }
212 $r2rml->objects_for_predicate_list($thing, $rr->constant, $rr->graph);
213 0 ▶ return $graph if $graph;
Branch: 1 branch
BranchTrueFalseTotal
if $graph 0 0 0
214
215 ($graph) =
216 0 map { sprintf('{%s}', $_->literal_value) }
217 0 grep { $_->is_literal }
218 $r2rml->objects($thing, $rr->column);
219 0 ▶ return _COL_ $graph if $graph;
Branch: 1 branch
BranchTrueFalseTotal
if $graph 0 0 0
220  
221 ($graph) =
222 0 map { $_->literal_value }
223 0 grep { $_->is_literal }
224 $r2rml->objects($thing, $rr->template);
225 0 ▶ return $graph if $graph;
Branch: 1 branch
BranchTrueFalseTotal
if $graph 0 0 0
226 }
227
228 22 return;
229 }
230  
231 sub _r2rml_SubjectMap
232 11 ▶{
Subroutine _r2rml_SubjectMap: called CC=13 SCAR=28.8
233 11 my ($self, $r2rml, $smc, $mapping) = @_;
234
235 # the easy bit
236 11 $mapping->{typeof} = [ grep { !$_->is_literal } $r2rml->objects($smc, $rr->class) ];
237
238 # graph
239 11 $mapping->{graph} = $self->_r2rml_graph($r2rml, $smc);
240  
241 # subject
242 ($mapping->{about}) =
243 0 ▶ map { $_->is_resource ? $_->uri : $_->as_ntriples }
Branch: 1 branch
BranchTrueFalseTotal
$_->is_resource ? : 0 0 0
244 0 grep { !$_->is_literal }
245 $r2rml->objects_for_predicate_list($smc, $rr->constant, $rr->subject);
246 11 ▶ unless ($mapping->{about})
Branch: 1 branch
BranchTrueFalseTotal
unless ($mapping->{"about"}) 11 0 11
247 {
248 11 my ($col) = grep { $_->is_literal } $r2rml->objects($smc, $rr->column);
249 11 ▶ $mapping->{about} = _COL_ sprintf('{%s}', $col->literal_value) if $col;
Branch: 1 branch
BranchTrueFalseTotal
if $col 4 7 11
250 11 ▶ $mapping->{_about_is_column} = 1 if $col;
Branch: 1 branch
BranchTrueFalseTotal
if $col 4 7 11
251 }
252 11 ▶ unless ($mapping->{about})
Branch: 1 branch
BranchTrueFalseTotal
unless ($mapping->{"about"}) 7 4 11
253 {
254 7 my ($tmpl) = grep { $_->is_literal } $r2rml->objects($smc, $rr->template);
255 7 ▶ $mapping->{about} = $tmpl->literal_value if $tmpl;
Branch: 1 branch
BranchTrueFalseTotal
if $tmpl 7 0 7
256 7 ▶ $mapping->{_about_is_template} = 1 if $tmpl;
Branch: 1 branch
BranchTrueFalseTotal
if $tmpl 7 0 7
257 }
258
259 # termtype
260 my ($termtype) =
261 map {
262 11 ▶ if ($_->as_ntriples =~ /(uri|iri|blank|blanknode|literal).?$/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($_->as_ntriples =~ /(uri|iri|blank|blanknode|literal).?$/i) { } 2 0 2
263 2 { { uri=>'IRI', iri=>'IRI', blank=>'BlankNode', blanknode=>'BlankNode', literal=>'Literal' }->{lc $1} }
264 else
265 0 { $_->as_ntriples }
266 }
267 $r2rml->objects_for_predicate_list($smc, $rr->termType, $rr->termtype);
268 11 ▶ $termtype //= '';
Condition100%2/2
$termtype //= ""
l!l
29
MC/DC100%1/1
$termtype //= ""
$termtype
Truth table100%2/2
A
A= $termtype
Aresult
11
00
269
270 11 ▶ if ($mapping->{about} and $termtype =~ /^blank/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($mapping->{"about"} and $termtype =~ /^blank/i) 0 11 11
Condition33%1/3
$mapping->{"about"} and $termtype =~ /^blank/i
!ll&&!rl&&r
0110
MC/DC0%0/2
$mapping->{"about"} and $termtype =~ /^blank/i
$mapping->{"about"} $termtype =~ /^blank/i
Truth table33%1/3
A and B
A= $mapping->{"about"}B= $termtype =~ /^blank/i
ABresult
0X0
100
111
271 {
272 $mapping->{about} = sprintf('_:%s', $mapping->{about})
273 0 ▶ unless $mapping->{about} =~ /^_:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mapping->{"about"} =~ /^_:/ 0 0 0
274 }
275 }
276  
277 sub _r2rml_PredicateObjectMap
278 17 ▶{
Subroutine _r2rml_PredicateObjectMap: called CC=16 SCAR=33.4
279 17 my ($self, $r2rml, $pomc, $mapping) = @_;
280
281 # graph
282 17 my $graph = $self->_r2rml_graph($r2rml, $pomc);
283  
284 # predicates
285 17 my @predicates;
286 17 foreach ($r2rml->objects($pomc, $rr->predicateMap))
287 {
288 13 ▶ next if $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
if $_->is_literal 0 13 13
289 13 push @predicates, $self->_r2rml_PredicateMap($r2rml, $_);
290 }
291  
292 push @predicates,
293 9 map { $_->uri }
294 17 grep { $_->is_resource }
295 $r2rml->objects_for_predicate_list($pomc, $rr->predicate);
296  
297 # objects
298 17 my @objects;
299 17 foreach ($r2rml->objects($pomc, $rr->objectMap))
300 {
301 16 ▶ next if $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
if $_->is_literal 0 16 16
302 16 my $obj = $self->_r2rml_ObjectMap($r2rml, $_);
303 16 ▶ push @objects, $obj if defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj 16 0 16
304 }
305  
306 push @objects,
307 map {
308 17 my $x = {};
309 1 ▶ if ($_->is_literal)
Branch: 3 branches
BranchTrueFalseTotal
if ($_->is_literal) { } 0 1 1
elsif ($_->is_resource) { } 1 0 1
elsif ($_->is_blank) { } 0 0 0
310 {
311 0 $x->{content} = $_->literal_value;
312 0 $x->{lang} = $_->literal_value_language;
313 0 $x->{datatype} = $_->literal_datatype;
314 0 $x->{kind} = 'property';
315 }
316 elsif ($_->is_resource)
317 {
318 1 $x->{resource} = $_->uri;
319 1 $x->{kind} = 'rel';
320 }
321 elsif ($_->is_blank)
322 {
323 0 $x->{resource} = $_->as_ntriples;
324 0 $x->{kind} = 'rel';
325 }
326 1 $x;
327 }
328 $r2rml->objects_for_predicate_list($pomc, $rr->object);
329  
330 17 foreach ($r2rml->objects($pomc, $rr->refObjectMap))
331 {
332 0 ▶ next if $_->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
if $_->is_literal 0 0 0
333 0 my $obj = $self->_r2rml_RefObjectMap($r2rml, $_);
334 0 ▶ push @objects, $obj if defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj 0 0 0
335 }
336  
337 17 foreach my $obj (@objects)
338 {
339 17 foreach my $p (@predicates)
340 {
341 22 my $o = dclone($obj);
342 22 ▶ my $column = delete $o->{column} || '_';
Condition100%2/2
delete $o->{'column'} || '_'
l!l
166
MC/DC100%1/1
delete $o->{'column'} || '_'
delete $o->{'column'}
Truth table100%2/2
A
A= delete $o->{'column'}
Aresult
11
00
343 22 ▶ my $kind = delete $o->{kind} || 'property';
Condition50%1/2
delete $o->{'kind'} || 'property'
l!l
220
MC/DC0%0/1
delete $o->{'kind'} || 'property'
delete $o->{'kind'}
Truth table50%1/2
A
A= delete $o->{'kind'}
Aresult
11
00
344 22 $o->{$kind} = $p;
345
346 22 push @{ $mapping->{columns}{$column} }, $o;
347 }
348 }
349 }
350  
351 sub _r2rml_PredicateMap
352 13 ▶{
Subroutine _r2rml_PredicateMap: called CC=5 SCAR=17.8
353 13 my ($self, $r2rml, $pmc) = @_;
354
355 13 my ($p) = map { $_->uri } grep { $_->is_resource } $r2rml->objects_for_predicate_list($pmc, $rr->constant, $rr->predicate);
356 13 ▶ unless ($p)
Branch: 1 branch
BranchTrueFalseTotal
unless ($p) 1 12 13
357 {
358 1 my ($col) = grep { $_->is_literal } $r2rml->objects($pmc, $rr->column);
359 1 ▶ $p = _COL_ sprintf('{%s}', $col->literal_value) if $col;
Branch: 1 branch
BranchTrueFalseTotal
if $col 1 0 1
360 }
361 13 ▶ unless ($p)
Branch: 1 branch
BranchTrueFalseTotal
unless ($p) 0 13 13
362 {
363 0 my ($tmpl) = grep { $_->is_literal } $r2rml->objects($pmc, $rr->template);
364 0 ▶ $p = $tmpl->literal_value if $tmpl;
Branch: 1 branch
BranchTrueFalseTotal
if $tmpl 0 0 0
365 }
366  
367 13 return ($p);
368 }
369  
370 sub _r2rml_ObjectMap
371 16 ▶{
Subroutine _r2rml_ObjectMap: called CC=28 SCAR=39.3
372 16 my ($self, $r2rml, $omc) = @_;
373
374 16 my ($datatype, $lang_col, $language, $termtype, $column);
375 my ($o) = map {
376 0 ▶ if ($_->is_resource) { $termtype = 'IRI'; $_->value; }
Branch: 3 branches
BranchTrueFalseTotal
if ($_->is_resource) { } 0 0 0
elsif ($_->is_blank) { } 0 0 0
elsif ($_->is_literal) { } 0 0 0
377 0 elsif ($_->is_blank) { $termtype = 'BlankNode'; $_->as_ntriples; }
378 0 elsif ($_->is_literal) { $datatype = $_->literal_datatype; $language = $_->literal_value_language; $termtype = 'Literal'; $_->literal_value; }
379 0 else { $_->as_ntriples; }
380 }
381 $r2rml->objects_for_predicate_list($omc, $rr->constant, $rr->object);
382 16 ▶ unless (defined $o)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 16 0 16
383 {
384 16 my ($col) = grep { $_->is_literal } $r2rml->objects($omc, $rr->column);
385 16 ▶ $o = _COL_ sprintf('{%s}', $col->literal_value) if $col;
Branch: 1 branch
BranchTrueFalseTotal
if $col 13 3 16
386 16 ▶ $column = $col->literal_value if $col;
Branch: 1 branch
BranchTrueFalseTotal
if $col 13 3 16
387 }
388 16 ▶ unless (defined $o)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $o) 3 13 16
389 {
390 3 my ($tmpl) = grep { $_->is_literal } $r2rml->objects($omc, $rr->template);
391 3 ▶ $o = $tmpl->literal_value if $tmpl;
Branch: 1 branch
BranchTrueFalseTotal
if $tmpl 3 0 3
392 }
393  
394 ($datatype) =
395 0 map { $_->uri }
396 0 ▶ grep { $_->is_resource }
Branch: 1 branch
BranchTrueFalseTotal
unless $datatype 16 0 16
397 $r2rml->objects($omc, $rr->datatype)
398 unless $datatype;
399 ($language) =
400 4 map { $_->literal_value }
401 16 ▶ grep { $_->is_literal }
Branch: 1 branch
BranchTrueFalseTotal
unless $language 16 0 16
402 $r2rml->objects($omc, $rr->language)
403 unless $language;
404 ($lang_col) =
405 3 map { $_->literal_value }
406 16 grep { $_->is_literal }
407 $r2rml->objects($omc, $rrx->languageColumn);
408 ($termtype) =
409 map {
410 16 ▶ if ($_->as_ntriples =~ /(uri|iri|blank|blanknode|literal).?$/i)
Branch: 2 branches
BranchTrueFalseTotal
unless $termtype 16 0 16
if ($_->as_ntriples =~ /(uri|iri|blank|blanknode|literal).?$/i) { } 9 0 9
411 9 { { uri=>'IRI', iri=>'IRI', blank=>'BlankNode', blanknode=>'BlankNode', literal=>'Literal' }->{lc $1} }
412 else
413 0 { $_->as_ntriples }
414 }
415 $r2rml->objects_for_predicate_list($omc, $rr->termType, $rr->termtype)
416 unless $termtype;
417
418 16 ▶ $termtype ||= 'Literal' if $datatype || $language || $lang_col || defined $column;
Branch: 1 branch
BranchTrueFalseTotal
if $datatype or $language or $lang_col or defined $column 13 3 16
Condition90%10/11
$datatype or $language or $lang_col or defined $column
l!l&&r!l&&!r
583
$datatype or $language or $lang_col
l!l&&r!l&&!r
4111
$datatype or $language
l!l&&r!l&&!r
0412
$termtype ||= "Literal"
l!l
67
MC/DC75%3/4
$datatype or $language or $lang_col or defined $column
$datatype $language $lang_col defined $column
MC/DC100%1/1
$termtype ||= "Literal"
$termtype
Truth table80%4/5
A or B or C or D
A= $datatypeB= $languageC= $lang_colD= defined $column
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table100%2/2
A
A= $termtype
Aresult
11
00
419 16 ▶ $termtype ||= 'IRI';
Condition50%1/2
$termtype ||= "IRI"
l!l
160
MC/DC0%0/1
$termtype ||= "IRI"
$termtype
Truth table50%1/2
A
A= $termtype
Aresult
11
00
420
421 16 ▶ $o = sprintf('_:%s', $o)
Branch: 1 branch
BranchTrueFalseTotal
if not ref $o and $termtype =~ /^blank/i and not $o =~ /^_:/ 0 16 16
Condition50%3/6
not ref $o and $termtype =~ /^blank/i and not $o =~ /^_:/
!ll&&!rl&&r
1600
not ref $o and $termtype =~ /^blank/i
!ll&&!rl&&r
1330
MC/DC0%0/3
not ref $o and $termtype =~ /^blank/i and not $o =~ /^_:/
not ref $o $termtype =~ /^blank/i not $o =~ /^_:/
Truth table50%2/4
not(A) and B and not(C)
A= not ref $oB= $termtype =~ /^blank/iC= not $o =~ /^_:/
ABCresult
0XX0
10X0
1100
1111
422 if (!ref $o) && $termtype =~ /^blank/i && $o !~ /^_:/;
423
424 16 my $map = {};
425
426 16 ▶ if ($column)
Branch: 1 branch
BranchTrueFalseTotal
if ($column) { } 13 3 16
427 {
428 #$column = $1 if $column =~ m{^"(.+)"$};
429 13 $map->{column} = $column;
430 }
431 else
432 {
433 3 ▶ my $x = ($termtype =~ /literal/i) ? 'content' : 'resource';
Branch: 1 branch
BranchTrueFalseTotal
$termtype =~ /literal/i ? : 0 3 3
434 3 $map->{$x} = $o;
435 }
436
437 16 ▶ $map->{datatype} = $datatype if $datatype;
Branch: 1 branch
BranchTrueFalseTotal
if $datatype 0 16 16
438 16 ▶ $map->{lang} = $language if $language;
Branch: 1 branch
BranchTrueFalseTotal
if $language 4 12 16
439 16 ▶ $map->{kind} = ($termtype =~ /literal/i) ? 'property' : 'rel';
Branch: 1 branch
BranchTrueFalseTotal
$termtype =~ /literal/i ? : 11 5 16
440 16 ▶ $map->{lang_col} = $lang_col if $lang_col;
Branch: 1 branch
BranchTrueFalseTotal
if $lang_col 3 13 16
441  
442 16 return $map;
443 }
444  
445 sub _r2rml_RefObjectMap
446 0 ▶{
Subroutine _r2rml_RefObjectMap: not called CC=10 SCAR=47.0
447 0 my ($self, $r2rml, $romc) = @_;
448
449 0 my $parent;
450 0 PARENT: foreach my $ptm ($r2rml->objects($romc, $rr->parentTriplesMap))
451 {
452 0 ▶ next PARENT if $ptm->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
if $ptm->is_literal 0 0 0
453 0 $parent = $self->_r2rml_TriplesMap($r2rml, $ptm);
454 0 ▶ last PARENT if $parent;
Branch: 1 branch
BranchTrueFalseTotal
if $parent 0 0 0
455 }
456 0 ▶ return unless $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
457
458 0 my $joins = [];
459 0 JOIN: foreach my $jc ($r2rml->objects($romc, $rr->joinCondition))
460 {
461 0 my ($p) = grep { $_->is_literal }
462 $r2rml->objects($jc, $rr->parent);
463 0 my ($c) = grep { $_->is_literal }
464 $r2rml->objects($jc, $rr->child);
465
466 0 ▶ if ($p && $c)
Branch: 1 branch
BranchTrueFalseTotal
if ($p and $c) 0 0 0
Condition0%0/3
$p and $c
!ll&&!rl&&r
000
MC/DC0%0/2
$p and $c
$p $c
Truth table0%0/3
A and B
A= $pB= $c
ABresult
0X0
100
111
467 {
468 0 push @$joins, { parent => $p->literal_value, child => $c->literal_value };
469 }
470 }
471
472 return {
473 column => '_',
474 join => $parent->{sql} || $parent->{from},
475 on => $joins,
476 resource => $parent->{about},
477 0 ▶ method => $parent->{sql} ? 'subquery' : 'table',
Branch: 1 branch
BranchTrueFalseTotal
$parent->{'sql'} ? : 0 0 0
Condition0%0/3
$parent->{'sql'} || $parent->{'from'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$parent->{'sql'} || $parent->{'from'}
$parent->{'sql'} $parent->{'from'}
Truth table0%0/3
A || B
A= $parent->{'sql'}B= $parent->{'from'}
ABresult
1X1
011
000
478 };
479 }
480  
481 5 1;
482  
483 __END__
« RDF/RDB2RDF/Simple.pm ↑ Summary RDF/RDB2RDF.pm »