View source with formatted comments or as raw
    1/*  Part of ClioPatria SeRQL and SPARQL server
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (C): 2010, University of Amsterdam,
    7		         VU University Amsterdam
    8
    9    This program is free software; you can redistribute it and/or
   10    modify it under the terms of the GNU General Public License
   11    as published by the Free Software Foundation; either version 2
   12    of the License, or (at your option) any later version.
   13
   14    This program is distributed in the hope that it will be useful,
   15    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17    GNU General Public License for more details.
   18
   19    You should have received a copy of the GNU General Public
   20    License along with this library; if not, write to the Free Software
   21    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22
   23    As a special exception, if you link this library with other files,
   24    compiled with a Free Software compiler, to produce an executable, this
   25    library does not by itself cause the resulting executable to be covered
   26    by the GNU General Public License. This exception does not however
   27    invalidate any other reasons why the executable file might be covered by
   28    the GNU General Public License.
   29*/
   30
   31:- module(api_rdflib,
   32	  [ library_ontology/1		% -Name
   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)).   42
   43/** <module> Provide access to the ontology library
   44
   45@see library(semweb/rdf_library)
   46*/
   47
   48:- http_handler(sesame('loadLibraryOntology'),   load_library_ontology,
   49		[time_limit(infinite)]).   50:- http_handler(sesame('listLibraryOntologies'), list_library_ontologies, []).   51
   52%%	load_library_ontology(+Request)
   53%
   54%	Load a named ontology from the ontology library.
   55%
   56%	@tbd	Cannot use concurrent loading as the load as a whole is
   57%		inside an rdf transaction.
   58
   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	).
   80
   81
   82%%	list_library_ontologies(+Request)
   83%
   84%	Reply with a list of available base ontologies
   85
   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		    ]).
  102
  103
  104%%	library_ontology(-Name) is nondet.
  105%
  106%	True if Name is the name of an ontology from the library.
  107
  108library_ontology(O) :-
  109	prepare_ontology_library,
  110	rdf_library_index(O, title(_Title)).
  111
  112
  113%%	prepare_ontology_library is det.
  114%
  115%	Load RDF library manifests from   directories  defined using the
  116%	file_search_path/2 =ontology= alias.
  117
  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	).
  127
  128%%	attribute_decl(+Name, -Options)
  129%
  130%	Copied from Sesame
  131
  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	       ])