35
36:- module(api_rdflib,
37 [ library_ontology/1 38 ]). 39:- use_module(user(user_db)). 40:- use_module(library(http/http_dispatch)). 41:- use_module(library(http/http_parameters)). 42:- use_module(library(http/html_write)). 43:- use_module(library(semweb/rdf_library)). 44:- use_module(rdfql(rdf_io)). 45:- use_module(sesame). 46:- use_module(components(messages)).
53:- http_handler(sesame('loadLibraryOntology'), load_library_ontology,
54 [time_limit(infinite)]). 55:- http_handler(sesame('listLibraryOntologies'), list_library_ontologies, []).
64load_library_ontology(Request) :-
65 http_parameters(Request,
66 [ repository(Repository),
67 ontology(Ontology, []),
68 resultFormat(Format)
69 ],
70 [ attribute_declarations(attribute_decl)
71 ]),
72 authorized(write(Repository, load(library_ontology(Ontology)))),
73 prepare_ontology_library,
74 api_action(Request,
75 rdf_load_library(Ontology, []),
76 Format,
77 \loaded_library_ontology(Ontology)).
78
79loaded_library_ontology(Id) -->
80 html('Loaded RDF library '),
81 ( { rdf_library_index(Id, title(Title)) }
82 -> html([Id, ' -- ', Title])
83 ; html(Id)
84 ).
91list_library_ontologies(Request) :-
92 authorized(read(status, listBaseOntologies)),
93 http_parameters(Request,
94 [ resultFormat(Format),
95 serialization(Serialization)
96 ],
97 [ attribute_declarations(attribute_decl)
98 ]),
99 catch(findall(row(O), library_ontology(O), Rows0), _,
100 Rows0 = []),
101 sort(Rows0, Rows),
102 write_table(Rows,
103 [ result_format(Format),
104 serialization(Serialization),
105 variables(varnames(ontology))
106 ]).
113library_ontology(O) :-
114 prepare_ontology_library,
115 rdf_library_index(O, title(_Title)).
123prepare_ontology_library :-
124 ( absolute_file_name(rdf(.), Dir,
125 [ file_type(directory),
126 solutions(all)
127 ]),
128 rdf_attach_library(Dir),
129 fail
130 ; true
131 ).
137attribute_decl(repository,
138 [ optional(true),
139 description('Name of the repository (ignored)')
140 ]).
141attribute_decl(resultFormat,
142 [ default(xml),
143 type(oneof([ xml,
144 html,
145 rdf
146 ])),
147 description('Serialization format of the result')
148 ]).
149attribute_decl(ontology,
150 [ description('Name of the ontology to load')
151 ])
Provide access to the ontology library