/*

This code is pretty ugly/experimental.   Bits of it are clever, bits
of it are too clever, bits of it are lousy, bits of it are unused.

There are some design decisions that I waffled on.  I think probably
the wiki should be scraped to RDF and then the RDF used to generate
the TR, but in some ways that's more work than what I (mostly) did
here, and might be even slower.

I really want this code to be able to fetch dated old data from the
wiki -- so that you can ask it for a document as it was on the wiki at
some time -- so "permanent URIs" can be generated for versions without
needing to store anything outside the wiki -- but it's not implemented.

*/

file_search_path(semwalker, '/u/home/sandro/cvs/dev.w3.org/2004/semwalker/').
:- ensure_loaded(semwalker(qtest_header)).
:- ensure_loaded(semwalker(qtest)).
:- ensure_loaded(semwalker(html)).


:- ensure_loaded(scrape_wiki).
:- ensure_loaded(generate_w3c_tr).

go(Source, Output) :-
	run_qtests,
	wiki_tr(Source,'',Generated_HTML),
	tell(Output),
	telling(S),
	set_stream(S, encoding(utf8)),
	write_html(Generated_HTML),
	told.

d(Doc) :-
	scrape_data_page(Doc,
			 'http://www.w3.org/2005/rules/wg/wiki/UCR', _Date),
	% length(Doc, _),		% close off the list
	true.

ucr :-
	run_qtests,
	wiki_tr('http://www.w3.org/2005/rules/wg/wiki/UCR','',Out),
	shell('> ucr.html'),
	tell('ucr.html'),
	telling(S),
	set_stream(S, encoding(utf8)),
	write_html(Out),
	told,
	sleep(1).
	% shell('nso ucr.html').

core :-
	run_qtests,
	wiki_tr('http://www.w3.org/2005/rules/wg/wiki/CORE','',Out),
	shell('> core.html'),
	tell('core.html'),
	telling(S),
	set_stream(S, encoding(utf8)),
	write_html(Out),
	told,
	sleep(1).
	% shell('nso core.html').

t1 :-
	run_qtests,
	wiki_tr('http://www.w3.org/2005/rules/wg/wiki/wikitr_demo','',Out),
	% format('Result: ~q\n', [Out]),
	shell('rm -f out.html'),
	tell('out.html'),
	write_html(Out),
	told,
	sleep(1),
	shell('nso out.html').

t2(X) :-
	wiki_content('http://www.w3.org/2005/rules/wg/wiki/wikitr_demo', X).

wiki_tr(DataPage, Date, H) :-
	scrape_data_page(Doc, DataPage, Date),
	% length(Doc, _),		% close off the list
	%doc(Doc, classAbbr, Code),
	% format(user_error, 'Doc: ~q\n', [Doc]),
	page(Doc, H).
	

t3(Doc) :-
	run_qtests,
	DataPage = 'http://www.w3.org/2005/rules/wg/wiki/UCR',
	scrape_data_page(Doc, DataPage, _Date).
