30
31:- module(api_rdflib,
32 [ library_ontology/1 33 ]). 34:- use_module(user(user_db)). 35:- use_module(library(http/http_dispatch)). 36:- use_module(library(http/http_parameters)). 37:- use_module(library(http/html_write)). 38:- use_module(library(semweb/rdf_library)). 39:- use_module(rdfql(rdf_io)). 40:- use_module(sesame). 41:- use_module(components(messages)).
48:- http_handler(sesame('loadLibraryOntology'), load_library_ontology,
49 [time_limit(infinite)]). 50:- http_handler(sesame('listLibraryOntologies'), list_library_ontologies, []).
59load_library_ontology(Request) :-
60 http_parameters(Request,
61 [ repository(Repository),
62 ontology(Ontology, []),
63 resultFormat(Format)
64 ],
65 [ attribute_declarations(attribute_decl)
66 ]),
67 authorized(write(Repository, load(library_ontology(Ontology)))),
68 prepare_ontology_library,
69 api_action(Request,
70 rdf_load_library(Ontology, []),
71 Format,
72 \loaded_library_ontology(Ontology)).
73
74loaded_library_ontology(Id) -->
75 html('Loaded RDF library '),
76 ( { rdf_library_index(Id, title(Title)) }
77 -> html([Id, ' -- ', Title])
78 ; html(Id)
79 ).
86list_library_ontologies(Request) :-
87 authorized(read(status, listBaseOntologies)),
88 http_parameters(Request,
89 [ resultFormat(Format),
90 serialization(Serialization)
91 ],
92 [ attribute_declarations(attribute_decl)
93 ]),
94 catch(findall(row(O), library_ontology(O), Rows0), _,
95 Rows0 = []),
96 sort(Rows0, Rows),
97 write_table(Rows,
98 [ result_format(Format),
99 serialization(Serialization),
100 variables(varnames(ontology))
101 ]).
108library_ontology(O) :-
109 prepare_ontology_library,
110 rdf_library_index(O, title(_Title)).
118prepare_ontology_library :-
119 ( absolute_file_name(rdf(.), Dir,
120 [ file_type(directory),
121 solutions(all)
122 ]),
123 rdf_attach_library(Dir),
124 fail
125 ; true
126 ).
132attribute_decl(repository,
133 [ optional(true),
134 description('Name of the repository (ignored)')
135 ]).
136attribute_decl(resultFormat,
137 [ default(xml),
138 type(oneof([ xml,
139 html,
140 rdf
141 ])),
142 description('Serialization format of the result')
143 ]).
144attribute_decl(ontology,
145 [ description('Name of the ontology to load')
146 ])
Provide access to the ontology library
library(semweb/rdf_library)
*/