View source with raw comments or as raw
    1/*  $Id$
    2
    3    Part of SWI-Prolog
    4
    5    Author:        Jan Wielemaker
    6    E-mail:        J.Wielemaker@cs.vu.nl
    7    WWW:           http://www.swi-prolog.org
    8    Copyright (C): 2004-2010, University of Amsterdam
    9			      VU University Amsterdam
   10
   11    This program is free software; you can redistribute it and/or
   12    modify it under the terms of the GNU General Public License
   13    as published by the Free Software Foundation; either version 2
   14    of the License, or (at your option) any later version.
   15
   16    This program is distributed in the hope that it will be useful,
   17    but WITHOUT ANY WARRANTY; without even the implied warranty of
   18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19    GNU General Public License for more details.
   20
   21    You should have received a copy of the GNU Lesser General Public
   22    License along with this library; if not, write to the Free Software
   23    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24
   25    As a special exception, if you link this library with other files,
   26    compiled with a Free Software compiler, to produce an executable, this
   27    library does not by itself cause the resulting executable to be covered
   28    by the GNU General Public License. This exception does not however
   29    invalidate any other reasons why the executable file might be covered by
   30    the GNU General Public License.
   31*/
   32
   33:- module(rdf_html,
   34	  [
   35	  ]).   36:- use_module(library(http/html_write)).   37:- use_module(library(http/http_dispatch)).   38:- use_module(library(http/html_head)).   39:- use_module(library(semweb/rdf_db)).   40:- use_module(library(semweb/rdfs)).   41
   42:- use_module(components(label)).

Write query-results as HTML table.

This module writes a SPARQL-table as an HTML table. It acts as a hook into rdf_io.pl. */

   51		 /*******************************
   52		 *	  RESULT TABLES		*
   53		 *******************************/
 rdf_io:write_table(+Format, +Serialization, +Rows, +Options) is semidet
Write a result-table in human-readable HTML format
Arguments:
Format- This clause only succeeds of Format is html
   61:- multifile
   62	rdf_io:write_table/4,
   63	rdf_io:write_graph/4.   64
   65rdf_io:write_table(html, _Serialization, Rows, Options) :- !,
   66	length(Rows, Count),
   67	reply_html_page(cliopatria(default),
   68			title('Query result'),
   69			[ \query_statistics([count(Count)|Options], rows),
   70			  \select_result_table(Rows, Options),
   71			  \new_query
   72			]).
   73
   74select_result_table(Rows, Options) -->
   75	html_requires(css('rdf.css')),
   76	html(table([ class(block)
   77		   ],
   78		   [ \variables(Options)
   79		   | \rows(Rows, Options, odd)
   80		   ])).
   81
   82
   83variables(Options) -->
   84	{ memberchk(variables(Vars), Options),
   85	  Vars =.. [_|Names]
   86	}, !,
   87	html(tr(\varnames(Names))).
   88
   89varnames([]) -->
   90	[].
   91varnames([Name|T]) -->
   92	html(th(Name)),
   93	varnames(T).
   94
   95rows([], _, _) --> [].
   96rows([H|T], Options, Class) -->
   97	{ H =.. [_|Cells],
   98	  odd_even(Class, NextClass)
   99	},
  100	html(tr(class(Class), \cells(Cells, Options))),
  101	rows(T, Options, NextClass).
  102
  103cells([], _) -->
  104	[].
  105cells([H|T], Options) -->
  106	cell(H, Options),
  107	cells(T, Options).
  108
  109cell(H, _) -->
  110	{ var(H) }, !,
  111	html(td(span(class(rdf_unbound), '<unbound>'))).
  112cell(H, Options) -->
  113	html(td(\rdf_link(H, Options))).
  114
  115odd_even(odd, even).
  116odd_even(even, odd).
  117
  118
  119		 /*******************************
  120		 *	    GRAPH OUTPUT	*
  121		 *******************************/
 rdf_io:write_graph(+Format, +Serialization, +Triples, +Options)
Write an RDF result-graph as an HTML table, where resources are links to the ClioPatria local view.
Arguments:
Format- must be html
Serialization- is ignored
Triples- is a list of rdf(S,P,O) triples
Options- is passed to rdf_link//2. It normally defines the preferred resource representation.
  134rdf_io:write_graph(html, _Serialization, Triples, Options) :-
  135	length(Triples, Count),
  136	reply_html_page(cliopatria(default),
  137			title('Query result'),
  138			[ \query_statistics([count(Count)|Options], triples),
  139			  \consult_result_table(Triples, Options)
  140			]).
  141
  142
  143consult_result_table(Triples, Options) -->
  144	html_requires(css('rdf.css')),
  145	html(table([ class(block)
  146		   ],
  147		   [ tr([th('Subject'), th('Predicate'), th('Object')])
  148		   | \triples(Triples, Options, odd)
  149		   ])).
  150
  151triples([], _, _) -->
  152	[].
  153triples([H|T], Options, Class) -->
  154	{ odd_even(Class, NextClass) },
  155	triple(H, Options, Class),
  156	triples(T, Options, NextClass).
  157
  158triple(rdf(S,P,O), Options, Class) -->
  159	html(tr(class(Class),
  160		[ td(\rdf_link(S, Options)),
  161		  td(\rdf_link(P, Options)),
  162		  td(\rdf_link(O, Options))])).
 query_statistics(+Options, +Units)// is det
Emit a short line above the page summarizing resource usage and result size.
  170query_statistics(Options, Units) -->
  171	{ memberchk(cputime(CPU), Options),
  172	  memberchk(count(Count), Options)
  173	}, !,
  174	html(p(class(msg_informational),
  175	       'Query completed in ~3f seconds ~D ~w'-[CPU, Count, Units])).
  176query_statistics(_, _) -->
  177	[].
 new_query//
  181new_query -->
  182	{ http_link_to_id(query_form, [], QueryForm)
  183	},
  184	html([ br(clear(all)),
  185	       a([class('new-query'), href(QueryForm)], 'New query')
  186	     ])