<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%
% CIF to Pillow XML tree transformation module
%
% Tranforms CIF Prolog term structures into Pillow XML representation.
%
% By:	K. Hui
% Date:	2 Apr 2002
%

:- module(cif2xml,[	cif2xml/3,
			query2xml/3,
			result2xml/3
		]).
%
% known URLs
%

:- dynamic(url/2).

url(rdf,'http://www.w3.org/1999/02/22-rdf-syntax-ns').
url(rdfs,'http://www.w3.org/2000/01/rdf-schema').
url(cif_rdfs,'http://www.csd.abdn.ac.uk/~khui/akt/cif/cif-rdfs.xml').
url(cif_compact_rdfs,'http://www.csd.abdn.ac.uk/~khui/akt/cif/cif-compact-rdfs.xml').


:- ['../pillow/pillow'].
:- [cif_util].
:- [concat_atoms].
:- [is_daplex_variable].
:- [query2xml].					%the query2xml extension
:- [prolog_detect].
:- prolog_detect:prolog(Prolog),
	(	(	Prolog=sicstus,
			use_module(library(lists)),
			[flatten]
		);
		(	Prolog=pfdm,
			use_module(library(lists)),
			[flatten]
		);
		(	Prolog=swi,
			[nth]
		);
		true
	).

/*
%
% add_prefix(?Prefix,?Atom,?Result)
%
% ?Prefix 	=	prefix (an atom) to be added to Atom
% ?Atom		=	atom to which Prefix is to be added
% ?Result	=	the resulting atom

% add a prefix to an atom
%
add_prefix(Prefix,Atom,Result) :-
	var(Result),
	name(Atom,Atom_string),
	name(Prefix,Prefix_string),
	append(Prefix_string,Atom_string,Result_string),
	name(Result,Result_string),
	!.

add_prefix(Prefix,Atom,Result) :-
	nonvar(Result),
	name(Result,Result_string),
	append(Prefix_string,Atom_string,Result_string),
	name(Atom,Atom_string),
	name(Prefix,Prefix_string).
*/

%
% map CIF into XML form or the other way round
%
% Params	=	a list of parameters in the format X=Y
%			domain_rdfs=URL		URL of RDFS file that defines the domain
%			constraint_id=HOW	specify how the RDF ID of constraint is generated
%						If 'HOW' equals the atom 'generate', then the predicate will
%						try to generate an ID for each top level constraint.
%						If 'HOW' is a list, then each constraint will take an
%						element from the list as the ID.
%			representation=classic/compact
%

%
% CIF -&gt; XML
%
cif2xml(Params,Cif,Xml) :-
	var(Xml),
	url(rdf,Rdf_url),
	concat_atoms:add_prefix(Rdf_url,'#',Rdf_url_with_hash),
	url(rdfs,Rdfs_url),
	concat_atoms:add_prefix(Rdfs_url,'#',Rdfs_url_with_hash),
	%
	% get the correct URL of CIF RDFS
	%
	member(representation=Rep,Params),
	match_rdfs_url(Rep,Cif_url),
	concat_atoms:add_prefix(Cif_url,'#',Cif_url_with_hash),
	Attribs=[	'xmlns:rdf'=Rdf_url_with_hash,
			'xmlns:rdfs'=Rdfs_url_with_hash,
			'xmlns:cif'=Cif_url_with_hash
		],
	Xml=[X_decl,X_rdf],
	X_decl=xmldecl([version='1.0']),
	X_rdf=env('rdf:RDF',Attribs,X_constraint),
	cif2xml_constraint(Params,[],Cif,_,_,X_constraint),	%start w/ no known ID
	!.

%
% XML -&gt; CIF
%
cif2xml(Params,Cif,Xml) :-
	nonvar(Xml),
	X_decl=xmldecl([version='1.0']),			%XML declaration
	X_rdf=env('rdf:RDF',_,X_constraint),			%RDF content
	member(X_decl,Xml),					%match XML declaration
	member(X_rdf,Xml),					%match RDF subtree
	cif2xml_constraint(Params,[],Cif,_,_,X_constraint).	%start w/ no known ID

%
% match RDFS URL of CIF according to representation
%
match_rdfs_url(classic,Url) :-
	url(cif_rdfs,Url),
	!.
match_rdfs_url(compact,Url) :-
	url(cif_compact_rdfs,Url),
	!.
match_rdfs_url(_,_) :-
	write('*** cif2xml ERROR: parameter "representation" must be "classic" or "compact"'),
	nl,
	fail.



%
% constraint
%

%
% universally quantified constraint
%
% CIF &lt;-&gt; XML
%
cif2xml_constraint(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_impliesconstr(Params,Known,Cif,New_params,New_known,Xml),	%get cif:impliesconstr
	!.

%
% existentially quantified constraint
%
% CIF &lt;-&gt; XML
%
cif2xml_constraint(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_existsconstr(Params,Known,Cif,New_params,New_known,Xml),	%get cif:existsconstr
	!.

%
% a list, which is an unquantified constraint
%
% CIF -&gt; XML
%
cif2xml_constraint(Params,Known,[C],New_params,New_known,Xml) :-		%a singleton list
	var(Xml),
	cif2xml_constraint(Params,Known,C,New_params,New_known,Xml),
	!.


%
% a list of constraints, considered logical and
%
% CIF -&gt; XML
%
cif2xml_constraint(Params,Known,Cif,New_params,New_known,Xml) :-		%a list is an AND
	var(Xml),
	is_list(Cif),								%a list is a logical_and
	cif2xml_unquantified_constraint(Params,Known,Cif,New_params,New_known,Xml),
	!.

%
% unquantified constraint
%
% XML -&gt; CIF
%
cif2xml_constraint(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),
	cif2xml_unquantified_constraint(Params,Known,Cif,New_params,New_known,Xml).


%
% impliesconstr, CIF -&gt; XML
%
cif2xml_impliesconstr(Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%XML is not
	Cif=restrict_subquery(all(Var),Gen,Pred),			%restrict_subquery/3
	%
	% cif:impliesconstr
	%
	Xml=env('cif:impliesconstr',Attribs,[X_qvar,X_if,X_then]),				%cif:impliesconstr
	get_constraint_id_attrib(Params,Known,Attribs,New_params,Params_no_id,Temp_known1),	%get constraint ID, depending on params
	%
	% cif:qvar, cif:impliesconstr_if &amp; cif:impliesconstr_then
	%
	X_qvar=env('cif:qvar',[],[X_setmem]),							%cif:qvar
	X_if=env('cif:impliesconstr_if',[],[X_boolpred]),					%cif:impliesconstr_if
	X_then=env('cif:impliesconstr_then',[],[X_constraint]),					%cif:impliesconstr_then
	%
	% get X_setmem, X_boolpred &amp; X_constraint
	%
	Patterns=[generate(_,Var),generate(_,_,_,_,Var)],					%pattern that matches generate/2 &amp; generate/5
	match_pattern(Gen,Patterns,Generators,Condition),					%get generators of this var &amp; extra condition
	%
	% recursively parse the 3 parts
	%
	(	(	Condition=[],								%if condition is empty, take it as a true
			!,
			If_to_parse=icode_true
		);
		If_to_parse=Condition
	),
	(	(	Pred=[],								%if pred is empty, take it as a true
			!,
			Then_to_parse=icode_true
		);
		Then_to_parse=Pred
	),
	%
	% recursively parse these
	%
	% we use the params list with "constraint_id" to suppress generation
	% of the rdf:ID attribute in nested constraints
	%
	cif2xml_generator(Params_no_id,Temp_known1,gen(Var,Generators),_,Temp_known2,X_setmem),		%get cif:setmem
	cif2xml_boolpred(Params_no_id,Temp_known2,If_to_parse,_,Temp_known3,X_boolpred),		%get cif:boolpred
	cif2xml_constraint(Params_no_id,Temp_known3,Then_to_parse,_,New_known,X_constraint).		%get cif:constraint

%
% impliesconstr,  XML -&gt; CIF
%
cif2xml_impliesconstr(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),							%XML is not
	Cif=restrict_subquery(all(Var),Gen,Pred),			%restrict_subquery/3
	%
	% cif:impliesconstr
	%
	Xml=env('cif:impliesconstr',Attribs,X_list),						%cif:impliesconstr
	get_constraint_id_attrib(Params,Known,Attribs,Temp_params1,_,Temp_known1),		%get constraint ID
	%
	% cif:impliesconstr_qvar, cif:impliesconstr_if &amp; cif:impliesconstr_then
	%
	X_qvar=env('cif:qvar',[],[X_setmem]),							%cif:qvar
	X_if=env('cif:impliesconstr_if',[],[X_boolpred]),					%cif:impliesconstr_if
	X_then=env('cif:impliesconstr_then',[],[X_constraint]),					%cif:impliesconstr_then
	member(X_qvar,X_list),									%get cif:impliesconstr_qvar
	member(X_if,X_list),									%get cif:impliesconstr_if
	member(X_then,X_list),									%get cif:impliesconstr_then
	%
	% get X_setmem, X_boolpred &amp; X_constraint
	%
	cif2xml_generator(Temp_params1,Temp_known1,gen(Var,Generators),Temp_params2,Temp_known2,X_setmem),	%get cif:setmem
	cif2xml_boolpred(Temp_params2,Temp_known2,If_to_parse,Temp_params3,Temp_known3,X_boolpred),		%get cif:boolpred
	cif2xml_constraint(Temp_params3,Temp_known3,Then_to_parse,New_params,New_known,X_constraint),		%get cif:constraint
	%
	% make up gen &amp; pred of restrict_subquery/3
	%
	(	(	If_to_parse=[],
			Gen=Generators
		);
		(	If_to_parse=icode_true,
			Gen=Generators
		);
		(	If_to_parse=[icode_true],
			Gen=Generators
		);
        	append_cif(Generators,If_to_parse,Gen)							%compose the generator
	),
	(	(	is_list(Then_to_parse),
			Pred=Then_to_parse
		);
		Pred=[Then_to_parse]
	),
	!.




%
% get/generate constraint ID depending on parameters supplied
%

%
% system generated ID
%

%
% CIF -&gt; XML
%
get_constraint_id_attrib(Params,Known,Attribs,Params,Params_no_id,New_known) :-
	var(Attribs),								%CIF -&gt; XML
	Attribs=['rdf:ID'=Rdf_id],
	member(constraint_id=generate,Params),					%user wants to generate ID
	cif_util:generate_counter(constraint,'constr',Rdf_id),			%generate constraint ID
	New_known=[id(constraint,Rdf_id)|Known],				%1 more constraint known
	delete(Params,constraint_id=generate,Params_no_id),			%remove constraint_id param from list
	!.
%
% user provides a list of ID
%
get_constraint_id_attrib(Params,Known,Attribs,New_params,Params_no_id,New_known) :-
	var(Attribs),								%CIF -&gt; XML
	Attribs=['rdf:ID'=Rdf_id],
	member(constraint_id=Id_list,Params),			%user supplies a list of ID
	Id_list=[Rdf_id|Ids],					%take 1st ID
	delete(Params,constraint_id=Id_list,Temp),
	New_params=[constraint_id:Ids|Temp],
	New_known=[id(constraint,Rdf_id)|Known],		%1 more constraint known
	delete(Params,constraint_id=Id_list,Params_no_id),	%remove constraint_id param from list
	!.
%
% no ID to be used
%
get_constraint_id_attrib(Params,Known,Attribs,Params,Params,Known) :-
	var(Attribs),								%CIF -&gt; XML
	Attribs=[].

%
% XML -&gt; CIF
%
get_constraint_id_attrib(Params,Known,Attribs,Params,Params,New_known) :-
	nonvar(Attribs),
	member('rdf:ID'=Rdf_id,Attribs),			%find 'rdf:ID' in attrib list
	New_known=[id(constraint,Rdf_id)|Known],		%1 more constraint known
	!.

get_constraint_id_attrib(Params,Known,Attribs,Params,Params,Known) :-
	nonvar(Attribs).					%no 'rdf:ID' found, never mind!


%
% generator (is a cif:setmem)
%

%
% CIF -&gt; XML
%
cif2xml_generator(Params,Known,Cif,New_params,New_known,X_setmem) :-
	var(X_setmem),
	Cif=gen(Var,Generators),
	match_pattern(Generators,generate(_,Var),Gen2,Gen5),				%separate generate/2 &amp; generate/5
	cif2xml_generator(Params,Known,gen(Var,Gen2,Gen5),New_params,New_known,X_setmem),
	!.

cif2xml_generator(Params,Known,Cif,New_params,New_known,X_setmem) :-
	var(X_setmem),
	Cif=gen(Var,_,Gen5),								%we prefer to take generate/5 of the var 1st
	Gen5=[Gen|_],									%at least 1 generate/5
	cif2xml_setmem(Params,Known,gen(Var,Gen),New_params,New_known,X_setmem),	%get cif:setmem
	!.
cif2xml_generator(Params,Known,Cif,New_params,New_known,X_setmem) :-
	var(X_setmem),
	Cif=gen(Var,Gen2,[]),								%if there is no generate/5, we work on generate/2
	Gen2=[Gen|_],
	cif2xml_setmem(Params,Known,gen(Var,Gen),New_params,New_known,X_setmem),	%get cif:setmem
	!.

%
% XML -&gt; CIF
%
cif2xml_generator(Params,Known,Cif,New_params,New_known,X_setmem) :-
	cif2xml_setmem(Params,Known,gen(Var,Gen),New_params,New_known,X_setmem),	%get cif:setmem
	member(Gen,[generate(_,Var),generate(_,_,_,_,Var)]),
	Cif=gen(Var,[Gen]).


%
% existsconstr
%

%
% CIF -&gt; XML
%
cif2xml_existsconstr(Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),								%CIF -&gt; XML
	(	Cif=restrict_subquery(some(Var),Gen,Pred);			%restrict_subquery/3
		Cif=restrict_subquery(exists(Var),Gen,Pred)			%some or exists
	),
	%
	% cif:existsconstr
	%
	Xml=env('cif:existsconstr',Attribs,[X_qvar,X_suchthat]),		%cif:existsconstr
	X_qvar=env('cif:existsconstr_qvar',[],[X_setmem]),			%cif:existsconstr_qvar
	X_suchthat=env('cif:existsconstr_suchthat',[],[X_constraint]),		%cif:existsconstr_suchthat
	%
	% generate constraint ID
	%
	get_constraint_id_attrib(Params,Known,Attribs,New_params,Params_no_id,Temp_known1),	%get constraint ID, depending on params
	%
	%
	% get X_qvar &amp; X_suchthat
	%
	Patterns=[generate(_,Var),generate(_,_,_,_,Var)],			%pattern for matching generate/2 &amp; /5
	match_pattern(Gen,Patterns,Generators,Non_gens),			%get generators &amp; non-gen
	append_cif(Non_gens,Pred,Suchthat),					%append pred to non-gen
	(	(	Suchthat=[],						%if pred is empty, take it as a true
			!,
			Suchthat_to_parse=icode_true
		);
		Suchthat_to_parse=Suchthat
	),
	%
	% these guys will have no constraint_id param
	%
	cif2xml_generator(Params_no_id,Temp_known1,gen(Var,Generators),_,Temp_known2,X_setmem),		%get cif:setmem
	cif2xml_constraint(Params_no_id,Temp_known2,Suchthat_to_parse,_,New_known,X_constraint),	%get cif:constraint
	!.


%
% XML -&gt; CIF
%
cif2xml_existsconstr(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%XML -&gt; CIF
	Cif=restrict_subquery(some(Var),Gen,Pred),				%restrict_subquery/3
	%
	% cif:existsconstr
	%
	Xml=env('cif:existsconstr',Attribs,X_list),				%cif:existsconstr
	X_qvar=env('cif:existsconstr_qvar',[],[X_setmem]),			%cif:existsconstr_qvar
	X_suchthat=env('cif:existsconstr_suchthat',[],[X_constraint]),		%cif:existsconstr_suchthat
	%
	% match X_qvar &amp; X_suchthat
	%
	member(X_qvar,X_list),
	member(X_suchthat,X_list),
	%
	% get constraint ID from XML
	%
	get_constraint_id_attrib(Params,Known,Attribs,Temp_params1,_,Temp_known1),		%get constraint ID
	%
	%
	%
	cif2xml_generator(Temp_params1,Temp_known1,gen(Var,Generators),Temp_params2,Temp_known2,X_setmem),		%get cif:setmem
	cif2xml_constraint(Temp_params2,Temp_known2,Suchthat_to_parse,New_params,New_known,X_constraint),	%get cif:constraint
	Gen=Generators,
	(	(	is_list(Suchthat_to_parse),
			Pred=Suchthat_to_parse
		);
		Pred=[Suchthat_to_parse]
	),
	!.


%
% unquantified_constraint
%
% CIF &lt;-&gt; XML
%
cif2xml_unquantified_constraint(Params,Known,Cif,New_params,New_known,Xml) :-
	Xml=env('cif:unquantified_constraint',[],[X_body]),
	X_body=env('cif:unquantified_constraint_body',[],X_boolpred),
	cif2xml_boolpred(Params,Known,Cif,New_params,New_known,X_boolpred).

%
% setmem
%
% CIF &lt;-&gt; XML
%
cif2xml_setmem(Params,Known,gen(Var,Gen),New_params,New_known,Xml) :-
	Xml=env('cif:setmem',[],[X_var,X_set]),						%cif:setmem
	X_var=env('cif:setmem_var',[],[X_variable]),					%cif:setmem_var
	X_set=env('cif:setmem_set',[],[X_setexpr]),					%cif:setmem_set
	cif2xml_variable(Params,Known,Var,Temp_params,Temp_known,X_variable),		%get cif:variable
	cif2xml_setexpr(Temp_params,Temp_known,Gen,New_params,New_known,X_setexpr),	%get cif:setexpr
	(	Gen=generate(_,_,_,_,Var);
		Gen=generate(_,Var)
	),
	!.


%
% boolpred
%
cif2xml_boolpred(Params,Known,Cif,New_params,New_known,Xml) :-
	member(representation=Rep,Params),
	cif2xml_boolpred(Rep,Params,Known,Cif,New_params,New_known,Xml).

%
% classic &amp; compact
%
cif2xml_boolpred(Form,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_boolor(Form,Params,Known,Cif,New_params,New_known,Xml),		%in either form, boolor is a subclass of boolpred
	!.

%
% classic only
%
cif2xml_boolpred(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_boolterm(classic,Params,Known,Cif,New_params,New_known,Xml),	%cif:term
	!.

%
% compact only
%
cif2xml_boolpred(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_booland(compact,Params,Known,Cif,New_params,New_known,Xml),	%cif:booland
	!.

cif2xml_boolpred(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_negpred(compact,Params,Known,Cif,New_params,New_known,Xml),	%cif:boolnegfac
	!.

cif2xml_boolpred(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_boolprim(compact,Params,Known,Cif,New_params,New_known,Xml),	%cif:boolprim
	!.


%
% boolprim
%
cif2xml_boolprim(_,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_boolconst(Params,Known,Cif,New_params,New_known,Xml),	%cif:boolconst
	!.

cif2xml_boolprim(_,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_setmem(Params,Known,Cif,New_params,New_known,Xml),	%cif:setmem
	!.

cif2xml_boolprim(_,Params,Known,Cif,New_params,New_known,Xml) :-
%	Cif=expression(_,_,expr(_,_,_)),
	cif2xml_comparison(Params,Known,Cif,New_params,New_known,Xml),	%cif:comparison
	!.

cif2xml_boolprim(_,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_recpred(Params,Known,Cif,New_params,New_known,Xml).	%cif:recpred

%
% variable
%

%
% CIF -&gt; XML
%
cif2xml_variable(Params,Known,Cif,Params,Known,Xml) :-
	var(Xml),
	Cif=var(_),
	member(id(variable,Cif,Id),Known),			%variable known
	concat_atoms:add_prefix('#',Id,Rdf_id),				%make RDF ID
	Xml=elem('cif:variable',['rdf:about'=Rdf_id]),		%ref back to variable
	!.

cif2xml_variable(Params,Known,Cif,Params,New_known,Xml) :-
	var(Xml),
	Cif=var(Name),
	Xml=env('cif:variable',Attribs,[X_varname]),		%cif:varname
	X_varname=env('cif:varname',[],[Name]),
	Attribs=['rdf:ID'=Rdf_id],
	Rdf_id=Id,
	Id=Name,
	New_known=[id(variable,Cif,Id)|Known],			%1 more variable known
	!.

%
% XML -&gt; CIF
%
cif2xml_variable(Params,Known,Cif,Params,New_known,Xml) :-
	var(Cif),
	nonvar(Xml),
	Xml=env('cif:variable',_Attribs,[X_varname]),		%cif:varname
	X_varname=env('cif:varname',[],[Name]),
	Cif=var(Name),
	Name=Id,
	New_known=[id(variable,Cif,Id)|Known].			%1 more variable known

cif2xml_variable(Params,Known,Cif,Params,Known,Xml) :-
	var(Cif),
	nonvar(Xml),
	Xml=elem('cif:variable',['rdf:about'=Rdf_id]),		%ref back to variable
	concat_atoms:add_prefix('#',Id,Rdf_id),				%make RDF ID
	Cif=var(Id).


%
% setexpr
%
cif2xml_setexpr(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_mvfncall(Params,Known,Cif,New_params,New_known,Xml).	%get cif:mvfncall

cif2xml_setexpr(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_entset(Params,Known,Cif,New_params,New_known,Xml).	%get cif:entset

cif2xml_setexpr(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_intset(Params,Known,Cif,New_params,New_known,Xml).	%get cif:entset

cif2xml_setexpr(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_explicit_set(Params,Known,Cif,New_params,New_known,Xml).

%
% intset
%
% CIF-&gt; XML
%
cif2xml_intset(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Cif),
	var(Xml),
	Cif=expression(_,_,int_set(Start,End,_)),
	Xml=env('cif:intset',[],[X_start,X_end,X_var]),			%cif:intset
	X_start=env('cif:intset_start',[],[X_integer1]),
	X_end=env('cif:intset_end',[],[X_integer2]),
	X_var=env('cif:intset_var',[],[X_variable]),
	cif2xml_integermet(Params,Known,Start,Temp_params1,Temp_known1,X_integer1),
	cif2xml_integermet(Temp_params1,Temp_known1,End,Temp_params2,Temp_known2,X_integer2),
	cif2xml_variable(Temp_params2,Temp_known2,End,New_params,New_known,X_variable).

%
% XML -&gt; CIF
%
cif2xml_intset(Params,Known,Cif,New_params,New_known,Xml) :-
	var(Cif),
	nonvar(Xml),
	Cif=expression(Gen_var,Required_vars,int_set(Start,End,Gen_var)),
	Xml=env('cif:intset',[],X_list),				%cif:intset
	X_start=env('cif:intset_start',[],[X_integer1]),
	X_end=env('cif:intset_end',[],[X_integer2]),
	X_var=env('cif:intset_var',[],[X_variable]),
	member(X_start,X_list),						%match X_start
	member(X_end,X_list),						%match X_end
	member(X_var,X_list),						%match X_var
	cif2xml_integermet(Params,Known,Start,Temp_params1,Temp_known1,X_integer1),
	cif2xml_integermet(Temp_params1,Temp_known1,End,Temp_params2,Temp_known2,X_integer2),
	cif2xml_variable(Temp_params2,Temp_known2,End,New_params,New_known,X_variable),
	make_needed_vars_list([Start,End],Required_vars).		%depending on Start/End is var or not, we have a list of req. vars

%
% explicit set
%
% CIF &lt;-&gt; XML
%
cif2xml_explicit_set(Params,Known,Cif,New_params,New_known,Xml) :-
	Cif=generate_subquery(_,_,explicit(Element_list),_,_),
	Xml=env('cif:explicit_set',[],X_element_list),
	cif2xml_explicit_set_elements(Params,Known,Element_list,New_params,New_known,X_element_list).

%
% a list of elements for explicit_set class
%
cif2xml_explicit_set_elements(Params,Known,[],Params,Known,[]).
cif2xml_explicit_set_elements(Params,Known,[E|Es],New_params,New_known,[X|Xs]) :-
	E=expression(_,_,expr(_)),
	X=env('cif:explicit_set_element',[],[X_expr]),
	cif2xml_expr(Params,Known,E,Temp_params,Temp_known,X_expr),
	cif2xml_explicit_set_elements(Temp_params,Temp_known,Es,New_params,New_known,Xs).

%
% expr
%
cif2xml_expr(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_setexpr(Params,Known,Cif,New_params,New_known,Xml),	%cif:setexpr
	!.

cif2xml_expr(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_singleton(Params,Known,Cif,New_params,New_known,Xml),	%cif:singleton
	!.

cif2xml_expr(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_boolpred(Params,Known,Cif,New_params,New_known,Xml).	%cif:boolpred

%
% boolterm (only in classic)
%
% CIF &lt;-&gt; XML
%
cif2xml_boolterm(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_booland(classic,Params,Known,Cif,New_params,New_known,Xml),	%cif:booland
	!.

cif2xml_boolterm(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_boolfac(classic,Params,Known,Cif,New_params,New_known,Xml).	%cif:boolfac


%
% boolor
%
% CIF -&gt; XML
%
% classic -&gt; classic
%
cif2xml_boolor(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	Cif=logical_or(Lhs,Rhs),					%classic -&gt; classic
	Xml=env('cif:boolor',[],[X_op1,X_op2]),				%cif:boolor
	X_op1=env('cif:boolor_op1',[],[X_boolpred1]),			%cif:boolor_op1
	X_op2=env('cif:boolor_op2',[],[X_boolpred2]),			%cif:boolor_op2
	cif2xml_boolterm(classic,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolpred(classic,Temp_params,Temp_known,Rhs,New_params,New_known,X_boolpred2),
	!.

%
% compact -&gt; compact
%
cif2xml_boolor(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	Cif=logical_or([C]),						%compact CIF, 1 element only
	cif2xml_boolpred(compact,Params,Known,C,New_params,New_known,Xml),
	!.

cif2xml_boolor(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	Cif=logical_or(Cif_boolpreds),					%compact -&gt; compact
	Cif_boolpreds=[_,_|_],						%2 elements or more
	Xml=env('cif:boolor',[],X_ops),					%cif:boolor
	cif2xml_boolpred_list(compact,Params,Known,Cif_boolpreds,New_params,New_known,X_boolpreds),	%map the list of operands
	X_op_template=env('cif:boolor_op',[],X_boolpred),		%cif:boolor_op template
	findall(X_op_template,member(X_boolpred,X_boolpreds),X_ops),	%make up list of cif:boolor_op
	!.

%
% compact -&gt; classic
%
cif2xml_boolor(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	Cif=logical_or([C]),						%compact CIF, 1 element only
	cif2xml_boolpred(classic,Params,Known,C,New_params,New_known,Xml),
	!.

cif2xml_boolor(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	Cif=logical_or([Lhs,Rhs|Rest]),					%compact CIF, 2 or more elements
	Xml=env('cif:boolor',[],[X_op1,X_op2]),				%cif:boolor
	X_op1=env('cif:boolor_op1',[],[X_boolpred1]),			%cif:boolor_op1
	X_op2=env('cif:boolor_op2',[],[X_boolpred2]),			%cif:boolor_op2
	cif2xml_boolterm(classic,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolpred(classic,Temp_params,Temp_known,logical_or([Rhs|Rest]),New_params,New_known,X_boolpred2),
	!.

%
% classic -&gt; compact
%
cif2xml_boolor(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	Cif=logical_or(Lhs,Rhs),					%classic -&gt; compact
	Xml=env('cif:boolor',[],[X_op1,X_op2]),				%cif:boolor
	X_op1=env('cif:boolor_op',[],[X_boolpred1]),			%cif:boolor_op1
	X_op2=env('cif:boolor_op',[],[X_boolpred2]),			%cif:boolor_op2
	cif2xml_boolterm(compact,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolpred(compact,Temp_params,Temp_known,Rhs,New_params,New_known,X_boolpred2),
	!.



%
% XML -&gt; CIF
%
% classic -&gt; classic
%
cif2xml_boolor(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),							%XML -&gt; CIF
	Xml=env('cif:boolor',[],X_list),				%cif:boolor
	X_op1=env('cif:boolor_op1',[],[X_boolpred1]),			%classic cif:boolor_op1 template
	X_op2=env('cif:boolor_op2',[],[X_boolpred2]),
	member(X_op1,X_list),
	member(X_op2,X_list),
	cif2xml_boolterm(classic,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolpred(classic,Temp_params,Temp_known,Rhs,New_params,New_known,X_boolpred2),
	Cif=logical_or(Lhs,Rhs),					%classic CIF
	!.

%
% compact -&gt; compact
%
cif2xml_boolor(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%XML -&gt; CIF
	Xml=env('cif:boolor',[],X_list),					%cif:boolor
	X_op_template=env('cif:boolor_op',[],[X_boolpred_template]),		%compact cif:op template
	findall(X_boolpred_template,member(X_op_template,X_list),X_boolpreds),	%match all boolpred
	X_boolpreds=[X_single_boolpred],					%only 1 element
	cif2xml_boolpred(compact,Params,Known,Cif,New_params,New_known,X_single_boolpred),
	!.

cif2xml_boolor(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%XML -&gt; CIF
	Xml=env('cif:boolor',[],X_list),					%cif:boolor
	X_op_template=env('cif:boolor_op',[],[X_boolpred_template]),		%compact cif:boolor_op template
	findall(X_boolpred_template,member(X_op_template,X_list),X_boolpreds),	%match all boolpred
	X_boolpreds=[_,_|_],							%2 or more elements
	cif2xml_boolpred_list(compact,Params,Known,Cif_boolpreds,New_params,New_known,X_boolpreds),	%map X_boolpreds into list of CIF
	Cif=logical_or(Cif_boolpreds),						%compact CIF
	!.

%
% compact -&gt; classic
%
cif2xml_boolor(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%XML -&gt; CIF
	Xml=env('cif:boolor',[],X_list),					%cif:boolor
	X_op_template=env('cif:boolor_op',[],[X_boolpred_template]),		%compact cif:boolor_op template
	findall(X_boolpred_template,member(X_op_template,X_list),X_boolpreds),	%find all X_boolpred
	X_boolpreds=[X_single_boolpred],						%only 1 operand, compact -&gt; classic
	cif2xml_boolpred(classic,Params,Known,Cif,New_params,New_known,X_single_boolpred),
	!.

cif2xml_boolor(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%XML -&gt; CIF
	Xml=env('cif:boolor',[],X_list),					%cif:boolor
	X_op_template=env('cif:boolor_op',[],[X_boolpred_template]),		%compact cif:op template
	findall(X_boolpred_template,member(X_op_template,X_list),X_boolpreds),	%find all X_boolpred
	X_boolpreds=[X_boolpred1,X_boolpred2|X_boolpred_rest],			%2 elements or more, compact -&gt; classic
	Cif=logical_or(Lhs,Rhs),
	cif2xml_boolpred(classic,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	%
	% now we have to make up a cif:boolor so that the remaining XML ops can be parsed
	%
	Xml_remaining=env('cif:boolop',[],Xml_remaining_ops),
	Xml_remaining_ops=[Xml_remaining_op1,Xml_remaining_op2],
	Xml_remaining_op1=env('cif:boolor_op',[],[X_boolpred2]),
	Xml_remaining_op2=env('cif:boolor_op',[],X_boolpred_rest),
	cif2xml_boolpred(classic,Temp_params,Temp_known,Rhs,New_params,New_known,Xml_remaining),
	(	(	Rhs=logical_or(Or_list),
			is_list(Or_list),
			!,
			Cif=logical_or([Lhs|Or_list])
		);
		Cif=logical_or([Lhs,Rhs])
	),
	!.

%
% classic -&gt; compact
%
cif2xml_boolor(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),							%XML -&gt; CIF
	Cif=logical_or(Lhs,Rhs),
	Xml=env('cif:boolor',[],X_list),				%cif:boolor
	X_op1=env('cif:boolor_op1',[],[X_boolpred1]),				%compact cif:boolor_op template
	X_op2=env('cif:boolor_op2',[],[X_boolpred2]),				%compact cif:boolor_op template
	member(X_op1,X_list),
	member(X_op2,X_list),
	cif2xml_boolpred(compact,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolpred(compact,Temp_params,Temp_known,Rhs,New_params,New_known,X_boolpred2),
	(	(	Rhs=logical_or(Or_list),
			is_list(Or_list),
			!,
			Cif=logical_or([Lhs|Rhs])
		);
		Cif=logical_or([Lhs,Rhs])
	),
	!.

%
% map a list of boolpred
%
% CIF &lt;-&gt; XML
%
cif2xml_boolpred_list(_,Params,Known,[],Params,Known,[]).
cif2xml_boolpred_list(Form,Params,Known,[C|Cs],New_params,New_known,[X|Xs]) :-
	cif2xml_boolpred(Form,Params,Known,C,Temp_params,Temp_known,X),
	cif2xml_boolpred_list(Form,Temp_params,Temp_known,Cs,New_params,New_known,Xs).


%
% booland
%
% CIF -&gt; XML
%

%
% classic -&gt; classic
%
cif2xml_booland(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	Cif=logical_and(Lhs,Rhs),					%classic -&gt; classic
	Xml=env('cif:booland',[],[X_op1,X_op2]),			%cif:booland
	X_op1=env('cif:booland_op1',[],[X_boolpred1]),			%cif:booland_op1
	X_op2=env('cif:booland_op2',[],[X_boolpred2]),			%cif:booland_op2
	cif2xml_boolfac(classic,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolterm(classic,Temp_params,Temp_known,Rhs,New_params,New_known,X_boolpred2),
	!.

%
% compact -&gt; compact
%
cif2xml_booland(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	(	Cif=logical_and([C]);					%compact CIF, 1 element only
		Cif=[C]
	),
	cif2xml_boolpred(compact,Params,Known,C,New_params,New_known,Xml),
	!.

cif2xml_booland(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	(	Cif=logical_and(Cif_boolpreds);				%compact CIF
		Cif=Cif_boolpreds
	),
	Cif_boolpreds=[_,_|_],						%2 elements or more
	Xml=env('cif:booland',[],X_ops),				%cif:booland
	cif2xml_boolpred_list(compact,Params,Known,Cif_boolpreds,New_params,New_known,X_boolpreds),	%map a list of operands
	X_op_template=env('cif:booland_op',[],[X_boolpred]),		%cif:booland_op template
	findall(X_op_template,member(X_boolpred,X_boolpreds),X_ops),	%make up list of cif:booland_op
	!.

%
% compact -&gt; classic
%
cif2xml_booland(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	(	Cif=logical_and([C]);					%compact CIF, 1 element only
		Cif=[C]
	),
	cif2xml_boolpred(classic,Params,Known,C,New_params,New_known,Xml),
	!.

cif2xml_booland(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	(	Cif=logical_and([Lhs,Rhs|Rest]);			%compact CIF, 2 or more elements
		Cif=[Lhs,Rhs|Rest]
	),
	Xml=env('cif:booland',[],[X_op1,X_op2]),			%cif:booland
	X_op1=env('cif:booland_op1',[],[X_boolpred1]),			%cif:booland_op1
	X_op2=env('cif:booland_op2',[],[X_boolpred2]),			%cif:booland_op2
	cif2xml_boolfac(classic,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolterm(classic,Temp_params,Temp_known,logical_and([Rhs|Rest]),New_params,New_known,X_boolpred2),
	!.

%
% classic -&gt; compact
%
cif2xml_booland(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),							%CIF -&gt; XML
	Cif=logical_and(Lhs,Rhs),					%classic -&gt; compact
	Xml=env('cif:booland',[],[X_op1,X_op2]),			%cif:booland
	X_op1=env('cif:booland_op',[],[X_boolpred1]),			%cif:booland_op1
	X_op2=env('cif:booland_op',[],[X_boolpred2]),			%cif:booland_op2
	cif2xml_boolfac(compact,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolterm(compact,Temp_params,Temp_known,Rhs,New_params,New_known,X_boolpred2),
	!.

%
% XML -&gt; CIF
%
% classic -&gt; classic
%
cif2xml_booland(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),							%XML -&gt; CIF
	Xml=env('cif:booland',[],X_list),				%cif:boolor
	X_op1=env('cif:booland_op1',[],[X_boolpred1]),			%classic XML op template
	X_op2=env('cif:booland_op2',[],[X_boolpred2]),
	member(X_op1,X_list),
	member(X_op2,X_list),
	Cif=logical_and(Lhs,Rhs),					%classic CIF
	cif2xml_boolfac(classic,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolterm(classic,Temp_params,Temp_known,Rhs,New_params,New_known,X_boolpred2),
	!.

%
% compact -&gt; compact
%
cif2xml_booland(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%XML -&gt; CIF
	Xml=env('cif:booland',[],X_list),
	X_op_template=env('cif:booland_op',[],[X_boolpred_template]),		%compact cif:booland_op template
	findall(X_boolpred_template,member(X_op_template,X_list),X_boolpreds),	%find all X_boolpred
	X_boolpreds=[X_single_boolpred],					%only 1 operand
	cif2xml_boolpred(compact,Params,Known,Cif,New_params,New_known,X_single_boolpred),
	!.

cif2xml_booland(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%XML -&gt; CIF
	Xml=env('cif:booland',[],X_list),					%cif:booland
	X_op_template=env('cif:booland_op',[],[X_boolpred_template]),		%compact cif:booland_op template
	findall(X_boolpred_template,member(X_op_template,X_list),X_boolpreds),	%find all X_boolpred
	X_boolpreds=[_,_|_],							%2 element sor more
%	Cif=logical_and(Cif_boolpreds),						%compact CIF
	Cif=Cif_boolpreds,							%*** take shorthand version
	cif2xml_boolpred_list(compact,Params,Known,Cif_boolpreds,New_params,New_known,X_boolpreds),
	!.

%
% classic -&gt; compact
%
cif2xml_booland(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),							%XML -&gt; CIF
	Xml=env('cif:booland',[],X_list),				%cif:boolor
	X_op1=env('cif:booland_op1',[],[X_boolpred1]),			%classic cif:booland_op1 template
	X_op2=env('cif:booland_op2',[],[X_boolpred2]),
	member(X_op1,X_list),
	member(X_op2,X_list),
	cif2xml_boolpred(compact,Params,Known,Lhs,Temp_params,Temp_known,X_boolpred1),
	cif2xml_boolpred(compact,Temp_params,Temp_known,Rhs,New_params,New_known,X_boolpred2),
	(	(	is_list(Rhs),
			!,
			Cif=[Lhs|Rhs]
		);
		Cif=[Lhs,Rhs]
	),
	!.

%
% compact -&gt; classic
%
cif2xml_booland(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%XML -&gt; CIF
	Xml=env('cif:booland',[],X_list),					%cif:booland
	X_op_template=env('cif:booland_op',[],[X_boolpred_template]),		%compact cif:booland_op template
	findall(X_boolpred_template,member(X_op_template,X_list),X_boolpreds),	%find all X_boolpred
	X_boolpreds=[X_boolpred],						%only 1 operand
	cif2xml_boolpred(classic,Params,Known,Cif,New_params,New_known,X_boolpred),
	!.

cif2xml_booland(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%XML -&gt; CIF
	Xml=env('cif:booland',[],X_list),					%cif:booland
	X_op_template=env('cif:booland_op',[],[X_boolpred_template]),		%compact cif:booland_op template
	findall(X_boolpred_template,member(X_op_template,X_list),X_boolpreds),	%find all X_boolpred
	X_boolpreds=[X_boolfac,X_boolterm|X_boolpred_rest],			%2 elements or more
	cif2xml_boolpred(classic,Params,Known,Lhs,Temp_params,Temp_known,X_boolfac),
	%
	% now we have to make up a cif:booland so that the remaining XML ops can be parsed
	%
	Xml_remaining=env('cif:booland',[],Xml_remaining_ops),
	Xml_remaining_ops=[Xml_remaining_op1,Xml_remaining_op2],
	Xml_remaining_op1=env('cif:booland_op',[],[X_boolterm]),
	Xml_remaining_op2=env('cif:booland_op',[],X_boolpred_rest),
	cif2xml_boolpred(classic,Temp_params,Temp_known,Rhs,New_params,New_known,Xml_remaining),
	%
	%***shorthand version
	%
	(	(	is_list(Rhs),
			!,
			Cif=[Lhs|Rhs]
		);
		Cif=[Lhs,Rhs]
	),
	!.

%
% boolfac
%

%
% CIF -&gt; XML
%
cif2xml_boolfac(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),								%CIF -&gt; XML
	Cif=[Something],
	cif2xml_boolprim(classic,Params,Known,Something,New_params,New_known,Xml),	%cif:boolprim
	!.

cif2xml_boolfac(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),								%CIF -&gt; XML
	cif2xml_boolprim(classic,Params,Known,Cif,New_params,New_known,Xml),		%cif:boolprim
	!.

%
% XML -&gt; CIF
%
cif2xml_boolfac(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),								%CIF -&gt; XML
	cif2xml_boolprim(classic,Params,Known,Cif,New_params,New_known,Xml),		%cif:boolprim
	!.

cif2xml_boolfac(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_negfac(classic,Params,Known,Cif,New_params,New_known,Xml).			%cif:negfac

%
% comparison
%

%
% CIF -&gt; XML
%
cif2xml_comparison(Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),
	Cif=expression(_,_,expr(Op,Op1,Op2)),
	Xml=env('cif:comparison',[],[X_comparison_operator,X_comparison_operand1,X_comparison_operand2]),	%cif:comparison
	X_comparison_operator=env('cif:comparison_operator',[],[X_operator]),					%cif:comparison_operator
	X_comparison_operand1=env('cif:comparison_op1',[],[X_operand1]),					%cif:comparison_op1
	X_comparison_operand2=env('cif:comparison_op2',[],[X_operand2]),					%cif:comparison_op2
	cif2xml_comparison_operator(Op,X_operator),								%get operator
	cif2xml_operand(Params,Known,Op1,Temp_params,Temp_known1,X_operand1),					%get cif:operand
	cif2xml_operand(Temp_params,Temp_known1,Op2,New_params,New_known,X_operand2),				%get cif:operand
	!.

%
% XML -&gt; CIF
%
cif2xml_comparison(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),
	Cif=expression([],Needed_vars,expr(Op,Op1,Op2)),
	Xml=env('cif:comparison',[],X_list),							%cif:comparison
	X_comparison_operator=env('cif:comparison_operator',[],[X_operator]),					%cif:comparison_operator
	X_comparison_operand1=env('cif:comparison_op1',[],[X_operand1]),					%cif:comparison_op1
	X_comparison_operand2=env('cif:comparison_op2',[],[X_operand2]),					%cif:comparison_op2
	member(X_comparison_operator,X_list),
	member(X_comparison_operand1,X_list),
	member(X_comparison_operand2,X_list),
	cif2xml_comparison_operator(Op,X_operator),								%get operator
	cif2xml_operand(Params,Known,Op1,Temp_params,Temp_known1,X_operand1),					%get cif:operand
	cif2xml_operand(Temp_params,Temp_known1,Op2,New_params,New_known,X_operand2),				%get cif:operand
	make_needed_vars_list([Op1,Op2],Needed_vars).

%
% arith_expr
%

%
% CIF -&gt; XML
%
cif2xml_arith_expr(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Cif),
	var(Xml),
	Cif=expression([Result],_,expr(Op,Op1,Op2)),
	Xml=env('cif:arith_expr',[],[X_arith_operator,X_arith_operand1,X_arith_operand2,X_arith_result]),	%cif:arith_expr
	X_arith_operator=env('cif:arith_expr_operator',[],[X_operator]),					%cif:arith_operator
	X_arith_operand1=env('cif:arith_expr_operand1',[],[X_operand1]),					%cif:arith_operand1
	X_arith_operand2=env('cif:arith_expr_operand2',[],[X_operand2]),					%cif:arith_operand2
	X_arith_result=env('cif:arith_expr_result',[],[X_result]),						%cif:arith_operand2
	cif2xml_arith_operator(Op,X_operator),									%get operator
	cif2xml_operand(Params,Known,Op1,Temp_params1,Temp_known1,X_operand1),					%get cif:operand1
	cif2xml_operand(Temp_params1,Temp_known1,Op2,Temp_params2,Temp_known2,X_operand2),			%get cif:operand2
	cif2xml_variable(Temp_params2,Temp_known2,Result,New_params,New_known,X_result).			%get cif:operand2

%
% XML -&gt; CIF
%
cif2xml_arith_expr(Params,Known,Cif,New_params,New_known,Xml) :-
	var(Cif),
	nonvar(Xml),
	Cif=expression(Result_var,Needed_vars,expr(Op,Op1,Op2)),
	Xml=env('cif:arith_expr',[],X_list),						%cif:arith_expr
	X_arith_operator=env('cif:arith_expr_operator',[],[X_operator]),					%cif:arith_operator
	X_arith_operand1=env('cif:arith_expr_operand1',[],[X_operand1]),					%cif:arith_operand1
	X_arith_operand2=env('cif:arith_expr_operand2',[],[X_operand2]),					%cif:arith_operand2
	X_arith_result=env('cif:arith_expr_result',[],[X_result]),						%cif:arith_operand2
	member(X_arith_operator,X_list),
	member(X_arith_operand1,X_list),
	member(X_arith_operand2,X_list),
	member(X_arith_result,X_list),
	cif2xml_arith_operator(Op,X_operator),									%get operator
	cif2xml_operand(Params,Known,Op1,Temp_params1,Temp_known1,X_operand1),					%get cif:operand1
	cif2xml_operand(Temp_params1,Temp_known1,Op2,Temp_params2,Temp_known2,X_operand2),			%get cif:operand2
	cif2xml_variable(Temp_params2,Temp_known2,Result_var,New_params,New_known,X_result),			%get cif:operand2
	make_needed_vars_list([Op1,Op2],Needed_vars).

%
% make up the list of needed variable from operands
%
make_needed_vars_list([],[]).
make_needed_vars_list([Op|Ops],[Op|Ns]) :-
	is_daplex_variable(Op),
	!,
	make_needed_vars_list(Ops,Ns).
make_needed_vars_list([_|Ops],Ns) :-
	make_needed_vars_list(Ops,Ns).


%
% arith_operator
%
cif2xml_arith_operator(Op,Xml) :-
	member(Op,[	'+',
			'-',
			'*',
			'/'
		]),
	Xml=env('cif:arith_operator',[],Op).


%
% operand
%
cif2xml_operand(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_variable(Params,Known,Cif,New_params,New_known,Xml),		%get cif:variable
	!.

cif2xml_operand(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_constant(Params,Known,Cif,New_params,New_known,Xml).		%get cif:constant

%
% recpred
%
cif2xml_recpred(Params,Known,Cif,New_params,New_known,Xml) :-
	Xml=env('cif:recpred',[],[X_recpred_body]),				%cif:recpred
	X_recpred_body=env('cif:recpred_body',[],[X_boolpred]),			%cif:recpred_body
	cif2xml_boolpred(Params,Known,Cif,New_params,New_known,X_boolpred).	%get cif:boolpred

%
% singleton
%

%
% *** omitting "svfncall" for the moment
%
%cif2xml_singleton(Params,Known,Cif,New_params,New_known,Xml) :-
%	cif2xml_svfncall(Params,Known,Cif,New_params,New_known,Xml),		%get cif:svfncall
%	!.

cif2xml_singleton(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_operand(Params,Known,Cif,New_params,New_known,Xml),		%get cif:operand
	!.

cif2xml_singleton(Params,Known,Cif,New_params,New_known,Xml) :-
%	Cif=expression(_,_,expr(_,_,_)),
	cif2xml_arith_expr(Params,Known,Cif,New_params,New_known,Xml).		%get cif:arith_expr

cif2xml_singleton(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_casting_expr(Params,Known,Cif,New_params,New_known,Xml).

%
% constant
%
cif2xml_constant(Params,Known,Cif,New_params,New_known,Xml) :-
	Cif=icode_true,
	cif2xml_boolconst(Params,Known,Cif,New_params,New_known,Xml),
	!.

cif2xml_constant(Params,Known,Cif,New_params,New_known,Xml) :-
	Cif=icode_false,
	cif2xml_boolconst(Params,Known,Cif,New_params,New_known,Xml),
	!.

cif2xml_constant(Params,Known,Cif,New_params,New_known,Xml) :-
%	nonvar(Cif),
%	integer(Cif),
	cif2xml_integerconst(Params,Known,Cif,New_params,New_known,Xml),
	!.

%cif2xml_constant(Params,Known,Cif,New_params,New_known,Xml) :-
%	var(Cif),
%	cif2xml_integerconst(Params,Known,Cif,New_params,New_known,Xml),
%	!.

cif2xml_constant(Params,Known,Cif,New_params,New_known,Xml) :-
%	nonvar(Cif),
%	number(Cif),
	cif2xml_floatconst(Params,Known,Cif,New_params,New_known,Xml),
	!.

%cif2xml_constant(Params,Known,Cif,New_params,New_known,Xml) :-
%	var(Cif),
%	cif2xml_floatconst(Params,Known,Cif,New_params,New_known,Xml),
%	!.

cif2xml_constant(Params,Known,Cif,Params,New_known,Xml) :-
%	nonvar(Cif),
%	atom(Cif),
	cif2xml_stringconst(Params,Known,Cif,_,New_known,Xml).

%cif2xml_constant(Params,Known,Cif,New_params,New_known,Xml) :-
%	var(Cif),
%	cif2xml_stringconst(Params,Known,Cif,New_params,New_known,Xml).

%
% boolconst
%
cif2xml_boolconst(Params,Known,Cif,Params,Known,Xml) :-
	Cif=icode_true,
	Xml=env('cif:boolconst',[],[X_constant_value]),		%cif:boolconst
	X_constant_value=env('cif:constant_value',[],'True').	%cif:constant_value, inherited from constant

cif2xml_boolconst(Params,Known,Cif,Params,Known,Xml) :-
	Cif=icode_false,
	Xml=env('cif:boolconst',[],[X_constant_value]),		%cif:boolconst
	X_constant_value=env('cif:constant_value',[],'False').	%cif:constant_value, inherited from constant

%
% integerconst
%

%
% CIF -&gt; XML
%
cif2xml_integerconst(Params,Known,Cif,Params,Known,Xml) :-
	nonvar(Cif),
	var(Xml),
	integer(Cif),
	Xml=env('cif:integerconst',[],[X_constant_value]),
	X_constant_value=env('cif:constant_value',[],[Cif]),	%cif:constant_value, inherited from constant
	!.

%
% XML -&gt; CIF
%
cif2xml_integerconst(Params,Known,Cif,Params,Known,Xml) :-
	var(Cif),
	nonvar(Xml),
	Xml=env('cif:integerconst',[],[X_constant_value]),
	X_constant_value=env('cif:constant_value',[],[Cif]),	%cif:constant_value, inherited from constant
	!.

%
% floatconst
%

%
% CIF -&gt; XML
%
cif2xml_floatconst(Params,Known,Cif,Params,Known,Xml) :-
	nonvar(Cif),
	var(Xml),
	number(Cif),
	Xml=env('cif:floatconst',[],[X_constant_value]),
	X_constant_value=env('cif:constant_value',[],[Cif]).	%cif:constant_value, inherited from constant

%
% XML -&gt; CIF
%
cif2xml_floatconst(Params,Known,Cif,Params,Known,Xml) :-
	var(Cif),
	nonvar(Xml),
	Xml=env('cif:floatconst',[],[X_constant_value]),
	X_constant_value=env('cif:constant_value',[],[Cif]).	%cif:constant_value, inherited from constant

%
% stringconst
%

%
% CIF -&gt; XML
%
cif2xml_stringconst(Params,Known,Cif,Params,Known,Xml) :-
	nonvar(Cif),
	var(Xml),
	atom(Cif),
	Xml=env('cif:stringconst',[],[X_constant_value]),
	X_constant_value=env('cif:constant_value',[],[Cif]).	%cif:constant_value, inherited from constant

%
% XML -&gt; CIF
%
cif2xml_stringconst(Params,Known,Cif,Params,Known,Xml) :-
	var(Cif),
	nonvar(Xml),
	Xml=env('cif:stringconst',[],[X_constant_value]),
	X_constant_value=env('cif:constant_value',[],[Cif]).	%cif:constant_value, inherited from constant


%
% relative/3
%

%
% CIF -&gt; XML
%
cif2xml_casting_expr(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Cif),
	var(Xml),
	Cif=relative(Class,Instance,Result_var),
	Xml=env('cif:casting_expr',[],[X_class,X_instance,X_result_var]),
	X_class=env('cif:casting_expr_class',[],[X_entmet]),
	X_instance=env('cif:casting_expr_from',[],[X_objmet]),
	X_result_var=env('cif:casting_expr_to',[],[X_variable]),
	cif2xml_entmet(Params,Known,Class,Temp_params1,Temp_known1,X_entmet),
	cif2xml_objmet(Temp_params1,Temp_known1,Instance,Temp_params2,Temp_known2,X_objmet),
	cif2xml_variable(Temp_params2,Temp_known2,Result_var,New_params,New_known,X_variable).

%
% XML -&gt; CIF
%
cif2xml_casting_expr(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),
	var(Cif),
	Cif=relative(Class,Instance,Result_var),
	Xml=env('cif:casting_expr',[],X_list),
	X_class=env('cif:casting_expr_class',[],[X_entmet]),
	X_instance=env('cif:casting_expr_from',[],[X_objmet]),
	X_result_var=env('cif:casting_expr_to',[],[X_variable]),
	member(X_class,X_list),
	member(X_instance,X_list),
	member(X_result_var,X_list),
	cif2xml_entmet(Params,Known,Class,Temp_params1,Temp_known1,X_entmet),
	cif2xml_objmet(Temp_params1,Temp_known1,Instance,Temp_params2,Temp_known2,X_objmet),
	cif2xml_variable(Temp_params2,Temp_known2,Result_var,New_params,New_known,X_variable).


%
% mvfncall
%

%
% CIF -&gt; XML
%
cif2xml_mvfncall(Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),
	Cif=generate(_,_,Args,_,_),
	Xml=env('cif:mvfncall',[],[X_prop|X_args]),					%cif:mvfncall
	%
	% cif:mvfncall_prop
	%
	X_prop=env('cif:mvfncall_prop',[],[X_propmet]),					%cif:mvfncall_prop
	cif2xml_propmet(Params,Known,Cif,Temp_params1,Temp_known1,X_propmet),
	%
	% a list of cif:mvfncall_arg
	%
	cif2xml_args(Temp_params1,Temp_known1,Args,New_params,New_known,X_args).	%list of cif:mvfncall_arg

%
% XML -&gt; CIF
%
cif2xml_mvfncall(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),
	Cif=generate(_,_,Args,_,_),
	Xml=env('cif:mvfncall',[],X_list),						%cif:mvfncall
	%
	% match cif:mvfncall_prop &amp; mvfncall_firstargtype
	%
	X_prop=env('cif:mvfncall_prop',[],[X_propmet]),					%cif:mvfncall_prop
	member(X_prop,X_list),								%match cif:mvfncall_prop from list
	%
	% first list of cif:mvfncall_arg
	%
	delete(X_list,X_prop,X_args),							%remove cif:mvfncall_prop from list
	cif2xml_propmet(Params,Known,Cif,Temp_params1,Temp_known1,X_propmet),		%get list of cif:mvfncall_arg
	cif2xml_args(Temp_params1,Temp_known1,Args,New_params,New_known,X_args).	%get args


%
% a list of cif:mvfncall_arg
%
cif2xml_args(Params,Known,[],Params,Known,[]).
cif2xml_args(Params,Known,[A|As],New_params,New_known,[X|Xs]) :-
	X=env('cif:mvfncall_arg',[],[X_arg]),
	cif2xml_objmet(Params,Known,A,Temp_params,Temp_known,X_arg),
	cif2xml_args(Temp_params,Temp_known,As,New_params,New_known,Xs).

%
% entset
%
cif2xml_entset(Params,Known,Cif,New_params,New_known,Xml) :-
	Cif=generate(Class,_),
	Xml=env('cif:entset',[],[X_entclass]),					%cif:entset
	X_entclass=env('cif:entset_entclass',[],[X_entmet]),			%cif:entset_entclass
	cif2xml_entmet(Params,Known,Class,New_params,New_known,X_entmet).	%get cif:entmet


%
% objmet
%
cif2xml_objmet(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_simplemet(Params,Known,Cif,New_params,New_known,Xml),		%get cif:simplemet
	!.
cif2xml_objmet(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_entmet(Params,Known,Cif,New_params,New_known,Xml),		%get cif:entmet
	!.

cif2xml_objmet(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_propmet(Params,Known,Cif,New_params,New_known,Xml),		%get cif:propmet
	!.

cif2xml_objmet(Params,Known,Cif,New_params,New_known,Xml) :-
	cif2xml_expr(Params,Known,Cif,New_params,New_known,Xml).		%get cif:expr




%
% negfac
%

%
% classic only
%

%
% CIF -&gt; XML
%
cif2xml_negfac(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	Cif=icode_not(Body),
	Xml=env('cif:negfac',[],[X_negop,X_negfac_body]),			%cif:negfac
	X_negop=env('cif:negfac_negop',[],['-']),				%cif:negfac_negop
	X_negfac_body=env('cif:negfac_body',[],[X_boolprim]),			%cif:negfac_body
	cif2xml_boolprim(classic,Params,Known,Body,New_params,New_known,X_boolprim),	%get cif:boolprim
	!.
%
% XML -&gt; CIF
%
cif2xml_negfac(classic,Params,Known,Cif,New_params,New_known,Xml) :-
	Cif=icode_not(Body),
	Xml=env('cif:negfac',[],X_list),					%cif:negfac
	X_negop=env('cif:negfac_negop',[],[_]),					%cif:negfac_negop
	X_negfac_body=env('cif:negfac_body',[],[X_boolprim]),			%cif:negfac_body
	member(X_negop,X_list),
	member(X_negfac_body,X_list),
	cif2xml_boolprim(classic,Params,Known,Body,New_params,New_known,X_boolprim),	%get cif:boolprim
	!.

%

%
% negpred

%
% compact only
%

%
% CIF -&gt; XML
%
cif2xml_negpred(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),
	Cif=icode_not(Body),
	Xml=env('cif:negpred',[],[X_negpred_body]),				%cif:negpred
	X_negpred_body=env('cif:negfac_body',[],[X_boolprim]),			%cif:negpred_body
	cif2xml_boolpred(compact,Params,Known,Body,New_params,New_known,X_boolprim).	%get cif:boolprim

%
% XML -&gt; CIF
%
cif2xml_negpred(compact,Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),
	Cif=icode_not(Body),
	Xml=env('cif:negpred',[],[X_negpred_body]),				%cif:negpred
	X_negpred_body=env('cif:negfac_body',[],[X_boolprim]),			%cif:negpred_body
	cif2xml_boolpred(compact,Params,Known,Body,New_params,New_known,X_boolprim).	%get cif:boolprim
	
	
%
% propmet
%

%
% CIF -&gt; XML
%
cif2xml_propmet(Params,Known,Cif,Params,Known,Xml) :-
	var(Xml),									%CIF-&gt;XML
	Cif=generate(Fname,[Type|_],_,Result_type,_),
	%
	% see if propmet already appeared
	%
	member(id(propmet,Fname,Type,Result_type,Id),Known),				%already appeared
	Xml=elem('cif:propmet',Attribs),	%cif:propmet
	Attribs=['rdf:ID'=Id],
	!.

cif2xml_propmet(Params,Known,Cif,New_params,New_known,Xml) :-
	var(Xml),									%CIF-&gt;XML
	Cif=generate(Fname,[Type|_],_,Result_type,_),
	%
	%
	Xml=env('cif:propmet',Attribs,[X_fname,X_rdfname,X_firstargtype,X_resulttype]),	%cif:propmet
	Attribs=['rdf:ID'=Id],
	Id=Fname,
	X_fname=env('cif:propmet_fname',[],[Fname]),					%cif:propmet_fname
	X_rdfname=env('cif:propmet_rdfname',[],[Rdf_name]),				%cif:propmet_rdfname
	X_firstargtype=env('cif:propmet_firstargtype',[],X_objmet1),			%cif:propmet_firstargtype
	X_resulttype=env('cif:propmet_resulttype',[],[X_objmet2]),			%cif:propmet_resulttype
	%
	% make up cif:propmet_rdfname
	%
	member(domain_rdfs=Url,Params),							%get domain RDFS' URL
	concat_atoms:concat_atoms([Url,'#',Fname],Rdf_name),				%make up Rdf_name
	%
	% get the 2 cif:entmet
	%
	cif2xml_objmet(Params,Known,Type,Temp_params,Temp_known,X_objmet1),
	cif2xml_objmet(Temp_params,Temp_known,Result_type,New_params,Temp_known2,X_objmet2),
	New_known=[id(propmet,Fname,Type,Result_type,Id)|Temp_known2].			%1 more propmet known

%
% XML -&gt; CIF
%
cif2xml_propmet(Params,Known,Cif,Params,Known,Xml) :-
	nonvar(Xml),									%XML-&gt;CIF
	Xml=elem('cif:propmet',Attribs),						%cif:propmet
	Cif=generate(Fname,[Type],_,Result_type,_),
	member('rdf:about'=Rdf_id,Attribs),							%match ID
	concat_atoms:add_prefix('#',Id,Rdf_id),
	member(id(propmet,Fname,Type,Result_type,Id),Known),				%use ID to find propmet record
	!.

cif2xml_propmet(Params,Known,Cif,New_params,New_known,Xml) :-
	nonvar(Xml),									%XML-&gt;CIF
	Cif=generate(Fname,[Type],_,Result_type,_),
	Xml=env('cif:propmet',Attribs,X_list),						%cif:propmet
	X_fname=env('cif:propmet_fname',[],[Fname]),
%	X_rdfname=env('cif:propmet_rdfname',[],[Rdf_name]),				%cif:propmet_rdfname
	X_firstargtype=env('cif:propmet_firstargtype',[],X_objmet1),			%cif:propmet_firstargtype
	X_resulttype=env('cif:propmet_resulttype',[],[X_objmet2]),			%cif:propmet_resulttype
	%
	% match cif:propmet_fname, cif:propmet_rdfname, cif:propmet_firstargtype
	% &amp; cif:propmet_resulttype from list
	%
	member(X_fname,X_list),								%instantiate X_fname
%	member(X_rdfname,X_list),							%instantiate X_rdfname
	member(X_firstargtype,X_list),							%instantiate X_firstargtype
	member(X_resulttype,X_list),							%instantiate X_resulttype
	%
	% get X_entmet1 &amp; 2
	%
	cif2xml_objmet(Params,Known,Type,Temp_params1,Temp_known1,X_objmet1),
	cif2xml_objmet(Temp_params1,Temp_known1,Result_type,New_params,Temp_known2,X_objmet2),
	%
	% optional rdf:ID attribute
	%
	(	(	member('rdf:ID'=Id,Attribs),
			New_known=[id(propmet,Fname,Type,Type,Result_type,Id)|Temp_known2]
		);
		New_known=Temp_known2
	).


%
% entmet
%

%
% CIF -&gt; XML
%

%
% class has already appeared, use rdf:about to refer to it
%
cif2xml_entmet(Params,Known,Class,Params,Known,Xml) :-
	nonvar(Class),
	atom(Class),
	member(id(entmet,Class,Id),Known),				%cif:entmet has already appeared
	Xml=elem('cif:entmet',['rdf:about'=Rdf_id]),
	concat_atoms:add_prefix('#',Id,Rdf_id),
	!.

%
% class hasn't appeared yet, put in cif:entmet subtree
%
cif2xml_entmet(Params,Known,Class,Params,New_known,Xml) :-
	nonvar(Class),
	atom(Class),
	Xml=env('cif:entmet',Attribs,[X_entmet_rdfname]),
	Attribs=['rdf:ID'=Id],
	X_entmet_rdfname=env('cif:entmet_rdfname',[],[X_rdfname]),
	member(domain_rdfs=Url,Params),
	concat_atoms:add_prefix(Url,'#',Temp),
	concat_atoms:add_prefix(Temp,Class,X_rdfname),
	concat_atoms(['entmet_',Class],Id),
	New_known=[id(entmet,Class,Id)|Known],
	!.

%
% XML -&gt; CIF
%

%
% subtree of cif:enmet exists
%
cif2xml_entmet(Params,Known,Class,Params,New_known,Xml) :-
	var(Class),
	Xml=env('cif:entmet',Attribs,[X_entmet_rdfname]),
	X_entmet_rdfname=env('cif:entmet_rdfname',[],[X_rdfname]),
	%
	% a faster implementation
	%
	name(X_rdfname,Rdfname_string),
	name('#',Hash_string),
	append(Hash_string,Class_string,Hash_and_class_string),
	append(_,Hash_and_class_string,Rdfname_string),
	name(Class,Class_string),
	%
	% add ID into list if specified
	%
	(
		(	member('rdf:ID'=Id,Attribs),
			New_known=[id(entmet,Class,Id)|Known]
		);
		New_known=Known
	),
	!.

%
% cif:entmet subtree does not exist, but rdf:about instead
%
cif2xml_entmet(Params,Known,Class,Params,Known,Xml) :-
	var(Class),
	Xml=elem('cif:entmet',Attribs),
	member('rdf:about'=Rdf_id,Attribs),				%match ID
	concat_atoms:add_prefix('#',Id,Rdf_id),
	member(id(entmet,Class,Id),Known),				%use ID to locate class
	!.

%
% simplemet
%

%
% CIF -&gt; XML
%
cif2xml_simplemet(Params,Known,Cif,Params,Known,Xml) :-
	var(Xml),
	atom(Cif),
	cif_to_simplemet(Cif,Simplemet),
	member(id(simplemet,Simplemet,Id),Known),		%class already appeared
	concat_atoms(['cif:',Simplemet],Tag),			%compose tag name
	Xml=elem(Tag,Attribs),
	Attribs=['rdf:about'=Rdf_id],
	concat_atoms:add_prefix('#',Id,Rdf_id),
	!.

cif2xml_simplemet(Params,Known,Cif,Params,New_known,Xml) :-
	var(Xml),
	cif_to_simplemet(Cif,Simplemet),			%map "integer" to "integermet", etc.
	concat_atoms(['cif:',Simplemet],Tag),			%compose tag
	Xml=env(Tag,Attribs,[X_simplemet_data_type]),
	Attribs=['rdf:ID'=Id],
	Id=Simplemet,
	X_simplemet_data_type=env('cif:simplemet_data_type',[],[Cif]),	%cif:simplemet_data_type, inherited from simplemet
	New_known=[id(simplemet,Simplemet,Id)|Known].			%add simplemet into known list

%
% XML -&gt; CIF
%

%
% a simplemet (i.e. integermet, etc.) using rdf:about, w/ no subtree underneath
%
cif2xml_simplemet(Params,Known,Cif,Params,Known,Xml) :-
	nonvar(Xml),
	Xml=elem(Tag,Attribs),
	concat_atoms:add_prefix('cif:',Simplemet,Tag),				%get simpletmet name, i.e integermet, etc.
	member('rdf:about'=Rdf_id,Attribs),				%match ID
	concat_atoms:add_prefix('#',Id,Rdf_id),
	member(id(simplemet,Simplemet,Id),Known),			%use ID to find known record from list
	cif_to_simplemet(Cif,Simplemet),				%map simplemet to cif
	!.

%
% a simplemet (i.e. integermet, etc.) w/ rdf:ID &amp; subtree
%
cif2xml_simplemet(Params,Known,Cif,Params,New_known,Xml) :-
	nonvar(Xml),
	Xml=env(_,Attribs,[X_simplemet_data_type]),
	X_simplemet_data_type=env('cif:simplemet_data_type',[],[Cif]),	%cif:simplemet_data_type, inherited from simplemet
	member('rdf:ID'=Id,Attribs),					%match ID
	cif_to_simplemet(Cif,Simplemet),				%map simplemet to cif
	New_known=[id(simplemet,Simplemet,Id)|Known].			%add simplemet into known list

%
% map CIF to simplemet name, i.e. integermet, etc.
%
cif_to_simplemet(Cif,Simplemet) :-
	Cif_list=[	integer,
			float,
			boolean,
			string
		],
	Simplemet_list=[	integermet,
				floatmet,
				booleanmet,
				stringmet
			],
	nth(Index,Cif_list,Cif),
	nth(Index,Simplemet_list,Simplemet).


%
% mapping a CIF operator into XML
%
cif2xml_comparison_operator(Op,Xml) :-
	Cif_ops=[	'=',
			'&lt;&gt;',
			'&lt;',
			'=&lt;',
			'&gt;',
			'&gt;='
		],
	Xml_ops=[	'=',
			'&amp;lt;&amp;gt;',
			'&amp;lt;',
			'=&amp;lt;',
			'&amp;gt;',
			'&amp;gt;='
		],
	nth(Index,Cif_ops,Op),
	nth(Index,Xml_ops,Xml).

marker.

</pre></body></html>