35
36:- module(rdf_html,
37 [
38 ]). 39:- use_module(library(http/html_write)). 40:- use_module(library(http/http_dispatch)). 41:- use_module(library(http/html_head)). 42:- use_module(library(semweb/rdf_db)). 43:- use_module(library(semweb/rdfs)). 44
45:- use_module(components(label)).
54
64:- multifile
65 rdf_io:write_table/4,
66 rdf_io:write_graph/4. 67
68rdf_io:write_table(html, _Serialization, Rows, Options) :-
69 !,
70 length(Rows, Count),
71 reply_html_page(cliopatria(default),
72 title('Query result'),
73 [ \query_statistics([count(Count)|Options], rows),
74 \select_result_table(Rows, Options),
75 \new_query
76 ]).
77
78select_result_table(Rows, Options) -->
79 html_requires(css('rdf.css')),
80 html(table([ class(block)
81 ],
82 [ \variables(Options)
83 | \rows(Rows, Options, odd)
84 ])).
85
86
87variables(Options) -->
88 { memberchk(variables(Vars), Options),
89 Vars =.. [_|Names]
90 },
91 !,
92 html(tr(\varnames(Names))).
93
94varnames([]) -->
95 [].
96varnames([Name|T]) -->
97 html(th(Name)),
98 varnames(T).
99
100rows([], _, _) --> [].
101rows([H|T], Options, Class) -->
102 { H =.. [_|Cells],
103 odd_even(Class, NextClass)
104 },
105 html(tr(class(Class), \cells(Cells, Options))),
106 rows(T, Options, NextClass).
107
108cells([], _) -->
109 [].
110cells([H|T], Options) -->
111 cell(H, Options),
112 cells(T, Options).
113
114cell(H, _) -->
115 { var(H) },
116 !,
117 html(td(span(class(rdf_unbound), '<unbound>'))).
118cell(H, Options) -->
119 html(td(\rdf_link(H, Options))).
120
121odd_even(odd, even).
122odd_even(even, odd).
123
124
125
140rdf_io:write_graph(html, _Serialization, Triples, Options) :-
141 length(Triples, Count),
142 reply_html_page(cliopatria(default),
143 title('Query result'),
144 [ \query_statistics([count(Count)|Options], triples),
145 \consult_result_table(Triples, Options)
146 ]).
147
148
149consult_result_table(Triples, Options) -->
150 html_requires(css('rdf.css')),
151 html(table([ class(block)
152 ],
153 [ tr([th('Subject'), th('Predicate'), th('Object')])
154 | \triples(Triples, Options, odd)
155 ])).
156
157triples([], _, _) -->
158 [].
159triples([H|T], Options, Class) -->
160 { odd_even(Class, NextClass) },
161 triple(H, Options, Class),
162 triples(T, Options, NextClass).
163
164triple(rdf(S,P,O), Options, Class) -->
165 html(tr(class(Class),
166 [ td(\rdf_link(S, Options)),
167 td(\rdf_link(P, Options)),
168 td(\rdf_link(O, Options))])).
176query_statistics(Options, Units) -->
177 { memberchk(cputime(CPU), Options),
178 memberchk(count(Count), Options)
179 },
180 !,
181 html(p(class(msg_informational),
182 'Query completed in ~3f seconds ~D ~w'-[CPU, Count, Units])).
183query_statistics(_, _) -->
184 [].
188new_query -->
189 { http_link_to_id(query_form, [], QueryForm)
190 },
191 html([ br(clear(all)),
192 a([class('new-query'), href(QueryForm)], 'New query')
193 ])
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
. */