line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
1616
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
96
|
|
2
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
119
|
|
3
|
|
|
|
|
|
|
package Conclave::OTK::Backend::File; |
4
|
|
|
|
|
|
|
# ABSTRACT: OTK file based backend |
5
|
3
|
|
|
3
|
|
15
|
use parent qw/Conclave::OTK::Backend/; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
19
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
2220
|
use RDF::Trine; |
|
3
|
|
|
|
|
4383962
|
|
|
3
|
|
|
|
|
154
|
|
8
|
3
|
|
|
3
|
|
31
|
use RDF::Trine::Model; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
68
|
|
9
|
3
|
|
|
3
|
|
18
|
use RDF::Trine::Parser; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
67
|
|
10
|
3
|
|
|
3
|
|
17
|
use RDF::Trine::Store::Memory; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
87
|
|
11
|
3
|
|
|
3
|
|
14
|
use RDF::Trine::Serializer::RDFXML; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
77
|
|
12
|
3
|
|
|
3
|
|
3132
|
use RDF::Query; |
|
3
|
|
|
|
|
1564598
|
|
|
3
|
|
|
|
|
127
|
|
13
|
3
|
|
|
3
|
|
3815
|
use Path::Tiny; |
|
3
|
|
|
|
|
27810
|
|
|
3
|
|
|
|
|
187
|
|
14
|
3
|
|
|
3
|
|
25
|
use Data::Dumper; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
2234
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$ENV{PATH} = undef; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
5
|
|
|
5
|
1
|
3109
|
my ($class, $base_uri, %opts) = @_; |
20
|
5
|
|
|
|
|
15
|
my $self = bless({}, $class); |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
11
|
my $filename = 'model.xml'; |
23
|
5
|
100
|
|
|
|
22
|
$filename = $opts{filename} if $opts{filename}; |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
21
|
$self->{base_uri} = $base_uri; |
26
|
5
|
|
|
|
|
13
|
$self->{filename} = $filename; |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
18
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
#my $store = RDF::Trine::Store::Memory->new; |
31
|
|
|
|
|
|
|
#my $model = RDF::Trine::Model->new($store); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#my $serializer = RDF::Trine::Serializer::NQuads->new(); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub init { |
36
|
3
|
|
|
3
|
1
|
2097
|
my ($self, $rdfxml) = @_; |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
40
|
my $store = RDF::Trine::Store::Memory->new; |
39
|
3
|
|
|
|
|
148
|
my $model = RDF::Trine::Model->new($store); |
40
|
3
|
|
|
|
|
84
|
my $parser = RDF::Trine::Parser->new('rdfxml'); |
41
|
3
|
|
|
|
|
75482
|
my $serializer = RDF::Trine::Serializer::RDFXML->new( base_uri => $self->{base_uri} ); |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
81
|
$parser->parse_into_model($self->{base_uri}, $rdfxml, $model); |
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
105356
|
open(my $fh, '>', $self->{filename}); |
46
|
3
|
|
|
|
|
28
|
$serializer->serialize_model_to_file($fh, $model); |
47
|
3
|
|
|
|
|
7253
|
close($fh); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub update { |
51
|
8
|
|
|
8
|
1
|
23
|
my ($self, $sparql) = @_; |
52
|
|
|
|
|
|
|
|
53
|
8
|
|
|
|
|
96
|
my $query = RDF::Query->new($sparql, {update => 1}); |
54
|
|
|
|
|
|
|
|
55
|
8
|
|
|
|
|
93844
|
my $parser = RDF::Trine::Parser->new('rdfxml'); |
56
|
8
|
|
|
|
|
8633
|
my $serializer = RDF::Trine::Serializer::RDFXML->new( base_uri => $self->{base_uri} ); |
57
|
8
|
|
|
|
|
190
|
my $file = path($self->{filename}); |
58
|
8
|
|
|
|
|
314
|
my $data = $file->slurp_utf8; |
59
|
8
|
|
|
|
|
1474
|
my $store = RDF::Trine::Store::Memory->new; |
60
|
8
|
|
|
|
|
360
|
my $model = RDF::Trine::Model->new($store); |
61
|
8
|
|
|
|
|
186
|
$parser->parse_into_model($self->{base_uri}, $data, $model); |
62
|
|
|
|
|
|
|
|
63
|
8
|
|
|
|
|
383450
|
my $iterator = $query->execute($model); |
64
|
|
|
|
|
|
|
|
65
|
8
|
|
|
|
|
50816
|
open(my $fh, '>', $self->{filename}); |
66
|
8
|
|
|
|
|
102
|
$serializer->serialize_model_to_file($fh, $model); |
67
|
8
|
|
|
|
|
90511
|
close($fh); |
68
|
|
|
|
|
|
|
|
69
|
8
|
|
|
|
|
503
|
return $iterator; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub query { |
73
|
14
|
|
|
14
|
1
|
37
|
my ($self, $sparql) = @_; |
74
|
|
|
|
|
|
|
|
75
|
14
|
|
|
|
|
125
|
my $query = RDF::Query->new($sparql); |
76
|
|
|
|
|
|
|
|
77
|
14
|
|
|
|
|
177569
|
my $parser = RDF::Trine::Parser->new('rdfxml'); |
78
|
14
|
|
|
|
|
15243
|
my $file = path($self->{filename}); |
79
|
14
|
|
|
|
|
545
|
my $data = $file->slurp_utf8; |
80
|
14
|
|
|
|
|
4206
|
my $store = RDF::Trine::Store::Memory->new; |
81
|
14
|
|
|
|
|
633
|
my $model = RDF::Trine::Model->new($store); |
82
|
14
|
|
|
|
|
322
|
$parser->parse_into_model($self->{base_uri}, $data, $model); |
83
|
14
|
|
|
|
|
997449
|
my $iterator = $query->execute($model); |
84
|
|
|
|
|
|
|
|
85
|
14
|
|
|
|
|
134371
|
my @result; |
86
|
14
|
|
|
|
|
69
|
while (my $triple = $iterator->next) { |
87
|
15
|
100
|
|
|
|
19089
|
if (scalar(keys %$triple) == 1) { |
88
|
11
|
|
|
|
|
36
|
foreach (keys %$triple) { |
89
|
11
|
|
|
|
|
75
|
push @result, $triple->{$_}->[1]; # FIXME |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { |
93
|
|
|
|
|
|
|
# FIXME |
94
|
4
|
|
|
|
|
15
|
my $str = $triple->as_string; |
95
|
4
|
50
|
|
|
|
374
|
if ($str =~ m/{\s*.*?=<(.*?)>,\s*.*?=<(.*?)>,\s*.*?=("|<)(.*?)("|>)/) { |
96
|
4
|
|
|
|
|
38
|
push @result, [($1,$2,$4)]; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
14
|
|
|
|
|
4553
|
return @result; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub delete { |
105
|
1
|
|
|
1
|
1
|
3
|
my ($self) = @_; |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
263
|
unlink $self->{filename}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=pod |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=encoding UTF-8 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 NAME |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Conclave::OTK::Backend::File - OTK file based backend |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 VERSION |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
version 0.01 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Nuno Carvalho <smash@cpan.org> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This software is copyright (c) 2014-2015 by Nuno Carvalho <smash@cpan.org>. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
135
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |