--- a/semantics/checker.pl Thu Jan 31 08:01:40 2013 -0500
+++ b/semantics/checker.pl Thu Jan 31 14:34:12 2013 +0000
@@ -8,6 +8,14 @@
ensure(A,I,J) :- \+(member(A,I)), J = [A|I].
+% helper for influence 15
+inferInfluence(Id,X,Y,Attrs1,I,J) :-
+ member(wasInfluencedBy(Id,X,Y,Attrs2),I)
+ -> (append(Attrs1,Attrs2,Attrs),
+ remove(wasInfluencedBy(Id,X,Y,Attrs2),I,J1),
+ J = [wasInfluencedBy(Id,X,Y,Attrs)|J1])
+ ; J = [wasInfluencedBy(Id,X,Y,Attrs)|I].
+
% inference 5
@@ -86,59 +94,57 @@
\+(member(wasAssociatedWith(_,A,Ag2,_,_),I)),
J = [wasAssociatedWith(_,A,Ag2,_,[])|I].
-% inference 15.1
-infer(I,J) :- member(wasGeneratedBy(Id,E,A,_T,Attrs),I),
- \+(member(wasInfluencedBy(Id,E,A,_),I)),
- J = [wasInfluencedBy(Id,E,A,Attrs)|I].
-% Tricky because of attribute inheritance
+% Inference 15: tricky because of attribute inheritance
% Add if no previous influence
% Should merge if there is already an influence, but this is tricky to
% handle without diverging
+% inference 15.1
+infer(I,J) :- member(wasGeneratedBy(Id,E,A,_T,Attrs),I),
+ inferInfluence(Id,E,A,Attrs,I,J).
+
% inference 15.2
infer(I,J) :- member(used(Id,A,E,_T,Attrs),I),
- \+(member(wasInfluencedBy(Id,A,E,_),I)),
- J = [wasInfluencedBy(Id,A,E,Attrs)|I].
+ inferInfluence(Id,A,E,Attrs,I,J).
% inference 15.3
infer(I,J) :- member(wasInformedBy(Id,Y,X,_T,Attrs),I),
- \+(member(wasInfluencedBy(Id,Y,X,_),I)),
- J = [wasInfluencedBy(Id,Y,X,Attrs)|I].
+ inferInfluence(Id,Y,X,Attrs,I,J).
% inference 15.4
infer(I,J) :- member(wasStartedBy(Id,Y,X,_,_T,Attrs),I),
- \+(member(wasInfluencedBy(Id,Y,X,_),I)),
- J = [wasInfluencedBy(Id,Y,X,Attrs)|I].
+ inferInfluence(Id,Y,X,Attrs,I,J).
+
% inference 15.5
infer(I,J) :- member(wasEndedBy(Id,Y,X,_,_T,Attrs),I),
- \+(member(wasInfluencedBy(Id,Y,X,_),I)),
- J = [wasInfluencedBy(Id,Y,X,Attrs)|I].
+ inferInfluence(Id,Y,X,Attrs,I,J).
+
% inference 15.6
infer(I,J) :- member(wasInvalidatedBy(Id,E,A,_T,Attrs),I),
- \+(member(wasInfluencedBy(Id,E,A,_),I)),
- J = [wasInfluencedBy(Id,E,A,Attrs)|I].
+ inferInfluence(Id,E,A,Attrs,I,J).
+
% inference 15.7
infer(I,J) :- member(wasDerivedFrom(Id,Y,X,_A,_G,_U,Attrs),I),
- \+(member(wasInfluencedBy(Id,Y,X,_),I)),
- J = [wasInfluencedBy(Id,Y,X,Attrs)|I].
+ inferInfluence(Id,Y,X,Attrs,I,J).
+
% inference 15.8
infer(I,J) :- member(wasAttributedTo(Id,Y,X,Attrs),I),
- \+(member(wasInfluencedBy(Id,Y,X,_),I)),
- J = [wasInfluencedBy(Id,Y,X,Attrs)|I].
+ inferInfluence(Id,Y,X,Attrs,I,J).
+
% inference 15.9
infer(I,J) :- member(wasAssociatedWith(Id,Y,X,_Pl,Attrs),I),
- \+(member(wasInfluencedBy(Id,Y,X,_),I)),
- J = [wasInfluencedBy(Id,Y,X,Attrs)|I].
+ inferInfluence(Id,Y,X,Attrs,I,J).
+
% inference 15.9
infer(I,J) :- member(actedOnBehalfOf(Id,Y,X,_A,Attrs),I),
- \+(member(wasInfluencedBy(Id,Y,X,_),I)),
- J = [wasInfluencedBy(Id,Y,X,Attrs)|I].
+ inferInfluence(Id,Y,X,Attrs,I,J).
+
% inference 16
@@ -418,22 +424,98 @@
normalize(I,K) :- infer(I,J), !, normalize(J,K).
+constrain(P,O1,O2) :- \+(member(precedes(Start,End),O1)),
+ O2 = [P|O1].
+
+
% Constraint 30
ordering_step(I,O1,O2) :-
member(wasStartedBy(Start,A,_E1,_A1,_T1,_Attrs1),I),
member(wasEndedBy(End,A,_E2,_A2,_T2,_Attrs2),I),
- \+(member(precedes(Start,End),O1)),
- O2 = [precedes(Start,End)|O1].
+ constrain(precedes(Start1,Start2),O1,O2).
+
+%Constraint 31
+ordering_step(I,O1,O2) :-
+ member(wasStartedBy(Start1,A,_E1,_A1,_T1,_Attrs1),I),
+ member(wasStartedBy(Start2,A,_E2,_A2,_T2,_Attrs2),I),
+ constrain(precedes(Start1,Start2),O1,O2).
+
+%Constraint 32
+ordering_step(I,O1,O2) :-
+ member(wasEndedBy(End1,A,_E1,_A1,_T1,_Attrs1),I),
+ member(wasEndedBy(End2,A,_E2,_A2,_T2,_Attrs2),I),
+ constrain(precedes(End1,End2),O1,O2).
+
+% Constraint 33.1
+ordering_step(I,O1,O2) :-
+ member(wasStartedBy(Start,A,_E1,_A1,_T1,_Attrs1),I),
+ member(used(Use,A,_E2,_T2,_Attrs2),I),
+ constrain(precedes(Start,Use),O1,O2).
+
+% Constraint 33.2
+ordering_step(I,O1,O2) :-
+ member(used(Use,A,_E1,_T1,_Attrs1),I),
+ member(wasEndedBy(End,A,_E2,_A2,_T2,_Attrs2),I),
+ constrain(precedes(Use,End),O1,O2).
+
+% Constraint 34.1
+ordering_step(I,O1,O2) :-
+ member(wasStartedBy(Start,A,_E1,_A1,_T1,_Attrs1),I),
+ member(wasGeneratedBy(Gen,_E2,A,_T2,_Attrs2),I),
+ constrain(precedes(Start,Gen),O1,O2).
+
+% Constraint 34.2
+ordering_step(I,O1,O2) :-
+ member(wasGeneratedBy(Use,_E1,A,_T1,_Attrs1),I),
+ member(wasEndedBy(End,A,_E2,_A2,_T2,_Attrs2),I),
+ constrain(precedes(Use,End),O1,O2).
+
+% Constraint 35
+ordering_step(I,O1,O2) :-
+ member(wasInformedBy(_Id,A2,A1,_Attrs),I),
+ member(wasStartedBy(Start,A1,_E1,_A11,_T1,_Attrs1),I),
+ member(wasEndedBy(End,A2,_E2,_A22,_T2,_Attrs2),I),
+ constrain(precedes(Start,End),O1,O2).
+
+% Constraint 36
+ordering_step(I,O1,O2) :-
+ member(wasGeneratedBy(Gen,E,_A1,_T1,_Attrs1),I),
+ member(wasInvalidatedBy(Inv,E,_A2,_T2,_Attrs2),I),
+ constrain(precedes(Gen,Inv),O1,O2).
+
+% Constraint 37
+ordering_step(I,O1,O2) :-
+ member(wasGeneratedBy(Gen,E,_A1,_T1,_Attrs1),I),
+ member(used(Use,_A2,E,_T2,_Attrs2),I),
+ constrain(precedes(Gen,Use),O1,O2).
+
+% Constraint 38
+ordering_step(I,O1,O2) :-
+ member(used(Use,_A1,E,_T1,_Attrs1),I),
+ member(wasInvalidatedBy(Inv,E,_A2,_T2,_Attrs2),I),
+ constrain(precedes(Gen,Inv),O1,O2).
+
+
% TODO: Lots more ordering constraints following this pattern.
ordering_saturate(I,O,O) :- \+(ordering_step(I,O,_)),!.
ordering_saturate(I,O1,O3) :-
ordering_step(I,O1,O2),
+ !,
ordering_saturate(I,O2,O3).
-strict_cycle(_O) :- fail. % TODO: Search graph for cycles containing a strict edge. Prolog 101.
+step(X,Y,O) :- member(precedes(X,Y),O) ; member(strictlyPrecedes(X,Y),O).
+path(X,X,_O,_Visited).
+path(X,Y,O,Visited) :-
+ step(X,Z,O),
+ \+(member(Z,Visited)),
+ path(Z,Y,O,[X|Visited]).
+path(X,Y,O) :- path(X,Y,O,[]).
+
+strict_cycle(O) :- member(strictlyPrecedes(X,Y),O),
+ path(Y,X,O).
ordering_check(I) :-
ordering_saturate(I,[],O),
--- a/semantics/constraints.pl Thu Jan 31 08:01:40 2013 -0500
+++ b/semantics/constraints.pl Thu Jan 31 14:34:12 2013 +0000
@@ -356,7 +356,7 @@
[ prec(gen_1, gen_2)]))).
decl('Constraint', 43, 'wasStartedBy-ordering',
- rules([rule([ gen,start,e,a_1,a_2,t_1,t_2,attrs_1,attrs_2 ],
+ rules([rule([ gen,start,e,a,a_1,a_2,t_1,t_2,attrs_1,attrs_2 ],
[ wasGeneratedBy(gen, e,a_1,t_1,attrs_1) ,
wasStartedBy(start, a,e,a_2,t_2,attrs_2) ],
[ preceq(gen, start)]),
@@ -366,7 +366,7 @@
[ preceq(start, inv)])])).
decl('Constraint', 44, 'wasEndedBy-ordering',
- rules([rule([ gen,end,e,a_1,a_2,t_1,t_2,attrs_1,attrs_2 ],
+ rules([rule([ gen,end,e,a,a_1,a_2,t_1,t_2,attrs_1,attrs_2 ],
[ wasGeneratedBy(gen, e,a_1,t_1,attrs_1) ,
wasEndedBy(end, a,e,a_2,t_2,attrs_2) ],
[ preceq(gen, end)]),
@@ -419,7 +419,7 @@
wasGeneratedBy(gen_1, ag,a_1,t_1,attrs_1) ,
wasGeneratedBy(gen_2, e,a_2,t_2,attrs_2) ],
[ preceq(gen_1, gen_2)]),
- rule([ att,start_1,gen_2,e,e_1,a,a_2,ag,t_1,t_2,attrs,attrs_1,attrs_2 ],
+ rule([ att,start_1,gen_2,e,e_1,a_1,a_2,ag,t_1,t_2,attrs,attrs_1,attrs_2 ],
[ wasAttributedTo(att, e,ag,attrs) ,
wasStartedBy(start_1, ag,e_1,a_1,t_1,attrs_1) ,
wasGeneratedBy(gen_2, e,a_2,t_2,attrs_2) ],
@@ -434,8 +434,8 @@
rule([ del,start_1,end_2, ag_1,ag_2,a,a_1,a_2,e_1,e_2,t_1,t_2,attrs,attrs_1,attrs_2 ],
[ actedOnBehalfOf(del, ag_2,ag_1,a,attrs) ,
wasStartedBy(start_1, ag_1,e_1,a_1,t_1,attrs_1) ,
- wasEndedBy(end2, ag_2,e_2,a_2,t_2,attrs_2) ],
- [ preceq(start_1, end2)])])).
+ wasEndedBy(end_2, ag_2,e_2,a_2,t_2,attrs_2) ],
+ [ preceq(start_1, end_2)])])).
decl('Constraint',51,'impossible-unspecified-derivation-generation-use',