* Fixed namespace bug, made entity optional in usage
authorjcheney@inf.ed.ac.uk
Wed, 06 Feb 2013 16:47:03 +0000
changeset 5486 1a88de2de375
parent 5484 ee4e86bf5145
child 5487 d8a3bf21fd58
* Fixed namespace bug, made entity optional in usage
semantics/checker.pl
semantics/prov_xml.pl
--- a/semantics/checker.pl	Wed Feb 06 14:37:33 2013 +0000
+++ b/semantics/checker.pl	Wed Feb 06 16:47:03 2013 +0000
@@ -1,4 +1,10 @@
-% Some horrible Prolog code for PROV-CONSTRAINTS
+% James Cheney, February 6, 2013
+% Some  Prolog code for PROV-CONSTRAINTS
+
+:- consult(prov_xml).
+
+
+
 
 remove(X,[Y|J],J) :- X == Y,!.
 remove(X,[Y|J],[Y|K]) :- X \== Y, remove(X,J,K).
@@ -75,7 +81,8 @@
 
 % inference 12
 infer(I,J) :- member(wasDerivedFrom(_ID,E2,E1,_A,_G,_U,Attrs),I),
-              member('prov:type'='prov:Revision', Attrs),
+              member(Prov:'type'='prov:Revision', Attrs),
+              ns(prov,Prov),
               \+(member(alternateOf(E2,E1),I)),
               J = [alternateOf(E2,E1)|I].
 
@@ -792,7 +799,8 @@
 % Constraint 50.19
 typing_step(I) -->
 	{member(entity(C,Attrs),I),
-	 member('prov:type'='prov:EmptyCollection',Attrs)},
+	 member(Prov:'type'='prov:EmptyCollection',Attrs),
+         ns(prov,Prov)},
 	(ensure(typeOf(C,'prov:Collection')) ;
 	 ensure(typeOf(C,'entity')) ;
 	 ensure(typeOf(C,'prov:EmptyCollection')) ).
--- a/semantics/prov_xml.pl	Wed Feb 06 14:37:33 2013 +0000
+++ b/semantics/prov_xml.pl	Wed Feb 06 16:47:03 2013 +0000
@@ -24,29 +24,56 @@
 	provx(X,J),
 	postprocess(J,K).
 
-provx([],_).
-provx([element(Prov:document,_,Contents)|Elements],J):-
+provx([element(Prov:document,_,Contents)|_Elements],J):-
 	ns(prov,Prov),
-	provx_expressions(Contents,J),
-	provx(Elements,J).
+	provx_expressions(Contents,J,[]).
 
-provx_expressions([],[]):-!.
-
-% This doesn't handle the case of alternate and specialization correctly,
-% since they don't have an id or attributes
-provx_expressions([element(Prov:Name,Attrs,Contents)|Elements],[Expression|J]):-
+provx_expressions([],Es,Es):-!.
+provx_expressions([element(Prov:hadMember,_Attrs,[Collx|Ents])|Elements],Es0,Es2):-
+	% hadMember is a special case, as it contains multiple members,
+	% and each one is separate PROV-N statement
 	ns(prov,Prov),
-	template(Name,TArgs),
+	Collx=element(Prov:collection,CollAttrx,_),
+	attribute_value(Prov:ref,CollAttrx,CollID),
+	provx_members(Ents,CollID,Es0,Es1),
+	!,
+	provx_expressions(Elements,Es1,Es2).
+provx_expressions([element(Prov:Name,Attrs,Contents)|Elements],[Expression|Es0],Es1):-
+	% template args start with id
+	ns(prov,Prov),
+	template(Name,[id|TArgs]),!,
 	attribute_value(Prov:id,Attrs,ID),
 	provx_args(TArgs,Contents,Args),
 	Expression=..[Name,ID|Args],
 	!,
-	provx_expressions(Elements,J).
-provx_expressions([E|_],_):-
+	provx_expressions(Elements,Es0,Es1).
+provx_expressions([element(Prov:Name,_Attrs,Contents)|Elements],[Expression|Es0],Es1):-
+	% no id expected
+	ns(prov,Prov),
+	template(Name,TArgs),
+	TArgs\=[id|_],
+	provx_args(TArgs,Contents,Args),
+	Expression=..[Name|Args],
+	!,
+	provx_expressions(Elements,Es0,Es1).
+provx_expressions([E|_],_,_):-
 	write('Failing on '),write(E),nl,
 	fail.
 
-provx_args([],Elements,[Attrs]):-
+provx_members([],_,Es,Es).
+provx_members([element(Prov:entity,Attrs,Contents)|Elements],
+	      Collection,
+	      [hadMember(Collection,Entity)|Es0],
+	      Es1):-
+	!,
+	ns(prov,Prov),
+	arg_value(Attrs,Contents,Entity),
+	provx_members(Elements,Collection,Es0,Es1).
+provx_members(X,_,_,_):-
+	write('Failing on collection'),write(X),nl.
+
+provx_args([],_,[]).
+provx_args([attrs],Elements,[Attrs]):-
 	% Additional attributes
 	!,
 	provx_attributes(Elements,Attrs).
@@ -77,13 +104,14 @@
 	!,
 	provx_args(TArgs,Elements,Args).
 provx_args(TArgs,Elements,_):-
-	write('Failing on args'),write(Elements),nl,
+	write('Failing on args '),write(Elements),nl,
 	write('Expected '),write(TArgs),nl,
 	fail.
 
 provx_attributes([],[]).
-provx_attributes([element(Key,Attrs,Contents)|Elements],[Key=Value]):-
-	Contents=[Value|_], % Expecting Contents single element list containing atom
+provx_attributes([element(Key,_Attrs,Contents)|Elements],[Key=Value|Attrs]):-
+	% Expecting Contents single element list containing atom
+	Contents=[Value|_], 
 	provx_attributes(Elements,Attrs).
 
 % If no Name=Val pair in Attrs, succeed anyway with Val unbound
@@ -104,35 +132,36 @@
 % Arguments for each type of expression
 % '+' prefix indicates optional argument
 %   - we need a placeholder in Prolog term, but value might not be provided
-template(entity,[]).
-template(activity,[+startTime,+endTime]).
-template(agent,[]).
-
-template(wasGeneratedBy,[entity,+activity,+time]).
-template(used,[activity,entity,+time]).
+template(entity,[id,attrs]).
+template(activity,[id,+startTime,+endTime,attrs]).
+template(agent,[id,attrs]).
 
-template(wasInformedBy,[informed,informant]).
-template(wasStartedBy,[activity,+trigger,+starter,+time]).
-template(wasEndedBy,[activity,+trigger,+ender,+time]).
-template(wasInvalidatedBy,[entity,+activity,+time]).
+template(wasGeneratedBy,[id,entity,+activity,+time,attrs]).
+template(used,[id,activity,+entity,+time,attrs]).
 
-template(wasDerivedFrom,[generatedEntity,usedEntity,-activity,-generation,-usage]).
-template(wasAttributedTo,[entity,agent]).
-template(wasAssociatedWith,[activity,+agent,-plan]).
-template(actedOnBehalfOf,[delegate,responsible,+activity]).
-template(wasInfluencedBy,[influencee,influencer]).
+template(wasInformedBy,[id,informed,informant,attrs]).
+template(wasStartedBy,[id,activity,+trigger,+starter,+time,attrs]).
+template(wasEndedBy,[id,activity,+trigger,+ender,+time,attrs]).
+template(wasInvalidatedBy,[id,entity,+activity,+time,attrs]).
+
+template(wasDerivedFrom,[id,generatedEntity,usedEntity,-activity,-generation,-usage,attrs]).
+template(wasAttributedTo,[id,entity,agent,attrs]).
+template(wasAssociatedWith,[id,activity,+agent,-plan,attrs]).
+template(actedOnBehalfOf,[id,delegate,responsible,+activity,attrs]).
+template(wasInfluencedBy,[id,influencee,influencer,attrs]).
 template(specializationOf,[specificEntity,generalEntity]).
 template(alternateOf,[alternate1,alternate2]).
 
+
 expand(X,Y) :- (X == null -> Y = _; Y = X).
 
 postprocess([],[]).
-postprocess([specializationOf(_,E1,E2,_)|J],
-	    [specializationOf(E1,E2)|K]) :-
-	!,postprocess(J,K).
-postprocess([alternateOf(_,E1,E2,_)|J],
-	    [alternateOf(E1,E2)|K]) :-
-	!,postprocess(J,K).
+%postprocess([specializationOf(_,E1,E2,_)|J],
+%	    [specializationOf(E1,E2)|K]) :-
+%	!,postprocess(J,K).
+%postprocess([alternateOf(_,E1,E2,_)|J],
+%	    [alternateOf(E1,E2)|K]) :-
+%	!,postprocess(J,K).
 postprocess([wasDerivedFrom(ID,E2,E1,A,G1,U1,Attrs)|J],
 	    [wasDerivedFrom(ID,E2,E1,A,G2,U2,Attrs)|K]) :-
 	!,
@@ -142,4 +171,4 @@
 	postprocess(J,K).
     
 postprocess([A|J],[A|K]) :- postprocess(J,K).
-	    
\ No newline at end of file
+