:- [test_constraint].				%load in constraint examples
:- [test_query].				%load in query examples
:- [test_result].				%load result examples

:- ['../fusing_mediator/transform'].		%constraint tranformation module
:- ['../../prolog/pillow/pillow'].
:- ['../../prolog/util/print_cif'].
:- ['../../prolog/util/print_xml'].
:- ['../../prolog/util/prolog_detect'].
:- ['../../prolog/util/cif2xml'].					%load the cif<->xml module

:- prolog_detect:prolog(Prolog),
	(	(	Prolog=sicstus,
			use_module(library(lists))
		);
		(	Prolog=pfdm,
			use_module(library(lists))
		);
		true
	).


go(constraint) :-
	Params1=[	domain_rdfs='http://www.csd.abdn.ac.uk/~schalmer/schema/pc_schema',
			constraint_id=[eg1,eg2],
%			representation=classic
			representation=compact
		],
	Params2=[	domain_rdfs='http://www.csd.abdn.ac.uk/~schalmer/schema/pc_schema',
			constraint_id=[eg1,eg2],
%			representation=classic
			representation=compact
		],
	write('***CIF constraint***'),
	nl,
	get_constraint(C),
	print_cif(C),
	nl,
	write('***XML constraint***'),
	nl,
	cif2xml:cif2xml(Params1,C,X),
	print_xml(X),
	nl,
	write('***CIF constraint parsed from XML***'),
	nl,
	cif2xml:cif2xml(Params2,C_parsed,X),
	print_cif(C_parsed),
	nl.

go(query) :-
	Params1=[	domain_rdfs='http://www.csd.abdn.ac.uk/~schalmer/schema/pc_schema',
			constraint_id=[eg1,eg2],
%			representation=classic
			representation=compact
		],
	Params2=[	domain_rdfs='http://www.csd.abdn.ac.uk/~schalmer/schema/pc_schema',
			constraint_id=[eg1,eg2],
%			representation=classic
			representation=compact
		],
	write('***CIF query***'),
	nl,
	get_query(Q),
	print_cif(Q),
	nl,
	write('***XML query'),
	nl,
	cif2xml:query2xml(Params1,Q,X),
	print_xml:print_xml(X),
	nl,
	cif2xml:query2xml(Params2,Q_parsed,X),
	print_cif:print_cif(Q_parsed),
	nl.

go(result) :-
	Params1=[	domain_rdfs='http://www.csd.abdn.ac.uk/~schalmer/schema/pc_schema',
			constraint_id=[eg1,eg2],
%			representation=classic
			representation=compact
		],
	Params2=[	domain_rdfs='http://www.csd.abdn.ac.uk/~schalmer/schema/pc_schema',
			constraint_id=[eg1,eg2],
%			representation=classic
			representation=compact
		],
	write('***result***'),
	nl,
	get_result(R),
	write(R),
	nl,
	write('***XML result****'),
	nl,
	cif2xml:result2xml(Params1,R,X),
	print_xml(X),
	nl,
	write('***result parsed***'),
	nl,
	cif2xml:result2xml(Params2,R_parsed,X),
	write(R_parsed),
	nl.

get_constraint(Filled) :-
	test_constraint:constraint(C),
	transform:push_negation(C,Pushed),
	transform:rewrite(Pushed,Rewritten),
	transform:fillmissing(Rewritten,Filled).


get_query(Query) :-
	test_query:query(Query).
