-
Notifications
You must be signed in to change notification settings - Fork 7
/
sparql.psgi
127 lines (92 loc) · 2.54 KB
/
sparql.psgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl
package FakeUser;
use Moose;
has 'cur_lang' => ( is => 'rw', isa => 'Str' );
no Moose;
__PACKAGE__->meta->make_immutable;
package FakeCatalyst;
use Moose;
has 'user' => ( is => 'rw', isa => 'Any' );
has 'config' => ( is => 'ro', isa => 'Any' );
sub user_in_realm { 0 }
no Moose;
__PACKAGE__->meta->make_immutable;
package main;
use strict;
use warnings;
use utf8;
use FindBin qw($Bin);
use lib "$Bin/lib";
use Data::Dumper;
use Plack::Request;
use Plack::Builder;
use Carp qw(confess);
use RDF::Endpoint;
use LWP::MediaTypes qw(add_type);
add_type( 'application/rdf+xml' => qw(rdf xrdf rdfx) );
add_type( 'text/turtle' => qw(ttl) );
add_type( 'text/plain' => qw(nt) );
add_type( 'text/x-nquads' => qw(nq) );
add_type( 'text/json' => qw(json) );
add_type( 'text/html' => qw(html xhtml htm) );
$ENV{RDF_ENDPOINT_SHAREDIR} = "$Bin/root/static/rdf";
my $dump = "$Bin/root/static/built/rdf/";
mkdir($dump);
use Iota;
my $schema = Iota->model('DB');
my $rdf = Iota->model('RDF')->rdf;
use RDF::Trine::Store;
use RDF::Trine::Model;
my $store = RDF::Trine::Store->new_with_config( {
storetype => 'Hexastore',
} );
$rdf->model(RDF::Trine::Model->new( $store ));
my $rdf_domain = $schema->resultset('Network')->search({rdf_identifier => 1})->next->domain_name;
my $fake_c = FakeCatalyst->new( user => FakeUser->new( cur_lang => 'pt-br' ), config => Iota->config );
sub valid_values_for_lex_key {
CatalystX::Plugin::Lexicon::valid_values_for_lex_key( $fake_c, @_ );
}
for my $table (qw/Variable Indicator/){
my $rs = $schema->resultset($table);
my $i = 0;
while (my $object = $rs->next){
$i++;
$object->populate_rdf(
rdf => $rdf,
rdf_domain => $rdf_domain,
valid_values_for_lex_key => \&valid_values_for_lex_key
);
undef $object;
}
print STDERR "# Loaded $i $table...\n";
undef $rs;
}
undef $schema;
undef $fake_c;
my $fname = "$dump/dump.iota.n3";
print STDERR "# Writing to $fname\n";
open(my $f, '>', $fname) or die "cant open $fname $!";
$rdf->serialize( filename =>$f, format => 'ntriples');
print STDERR "# gziping...\n";
`gzip -f $fname`;
print STDERR "# Done\n";
print STDERR "# Starting server now\n";
my $end = RDF::Endpoint->new( $rdf->model, {
update => 0,
html => {
'resource_links' => 1,
embed_images => 1
}
} );
=pod
my $app = sub {
my $env = shift;
my $req = Plack::Request->new($env);
my $resp = $end->run( $req );
return $resp->finalize;
};
builder {
$app;
};
=cut
__END__