-
Notifications
You must be signed in to change notification settings - Fork 0
/
lle_data.pl
72 lines (47 loc) · 1.74 KB
/
lle_data.pl
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
:- module(lle_data, []).
/** <module> LOD Laundromat: data
Serves data cleaned by the LOD Washing Machine.
@author Wouter Beek
@version 2014/08, 2015/01
*/
:- use_module(library(http/http_cors)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_path)).
:- use_module(library(http/http_server_files)).
:- use_module(library(http/http_session)). % HTTP session support.
:- use_module(plUri(uri_query)).
:- use_module(plHttp(request_ext)).
:- http_handler(lle(data), clean_data, [prefix]).
clean_data(Request):-
data_md5(Request, Md5),
data_kind(Request, Kind),
lle_data_file(Md5, Kind, File),
http_reply_file(File, [], Request).
%! data_kind(+Request:list(nvpair), -Kind:oneof([clean,dirty])) is det.
data_kind(Request, Kind):-
request_query_nvpair(Request, kind, Kind), !.
data_kind(_, clean).
%! data_md5(+Request:list(nvpair), -Md5:atom) is det.
data_md5(Request, Md5):-
memberchk(path(Path), Request),
atomic_list_concat(['',data,Md5], '/', Path), !.
data_md5(Request, Md5):-
request_query_nvpair(Request, md5, Md5).
%! lle_data_file(
%! +Md5:atom,
%! +Kind:oneof([clean,dirty]),
%! -Spec:compound
%! ) is det.
lle_data_file(Md5, Kind, Spec):-
absolute_file_name(data(Md5), Md5Dir, [access(read),file_type(directory)]),
lle_data_file_exists(Md5Dir, Kind, Name),
atomic_list_concat([Md5,Name], '/', RelativePath),
Spec = data(RelativePath).
lle_data_file_exists(Md5Dir, Kind, TriplesName):-
atomic_list_concat([Kind,nt,gz], '.', TriplesName),
directory_file_path(Md5Dir, TriplesName, DataFile),
exists_file(DataFile), !.
lle_data_file_exists(Md5Dir, Kind, QuadsName):-
atomic_list_concat([Kind,nq,gz], '.', QuadsName),
directory_file_path(Md5Dir, QuadsName, DataFile),
exists_file(DataFile).