51 lines
1.9 KiB
Plaintext
51 lines
1.9 KiB
Plaintext
% I and J have a different value on the attribute A of functional dependecy F
|
|
% For the left and right part
|
|
diffRight(I,J,F) :- right(F,A), row(I,A,X), row(J,A,Y), X != Y.
|
|
diffLeft(I,J,F) :- left(F,A), row(I,A,X), row(J,A,Y), X != Y.
|
|
|
|
% I and J conflict on functional dependecy F
|
|
violate(I,J,F) :- diffRight(I,J,F), not diffLeft(I,J,F).
|
|
|
|
% Simple projection of the row identifers violated
|
|
violated(I) :- violate(I,G1,G2).
|
|
|
|
% I is in the repair because it conflict with nothing
|
|
reprowID(I) :- row(I,G1,G2), not violated(I).
|
|
% I is in the repair because it conflict with J but it is not in it
|
|
%reprowID(I) :- violated(I), violate(I,J,G), unreprowID(J).
|
|
|
|
% Choose a I that conflict but the other row must not be there
|
|
reprowID(I) :- violated(I), not unreprowID(I).
|
|
unreprowID(I) :- violated(I), not reprowID(I).
|
|
:- violate(I,J,G), reprowID(I), reprowID(J).
|
|
|
|
% There mut be at least one row that remain for a violated functional dependecy F
|
|
represented(F) :- reprowID(I), violate(I,G,F).
|
|
:- left(F,G1), violate(G2,G3,F), not represented(F).
|
|
|
|
|
|
% !!! Small modification : all row R used must be in the repair (reprowID(R))
|
|
% Querry Q is not satisfied by row R if :
|
|
% One attribute A1 match a part of the querry Q in the row R
|
|
% But another attribute A2 do not in the same row R
|
|
qunsat(Q,R) :- qrow(Q,A1,V1), reprowID(R), row(R,A1,V1), qrow(Q,A2,V2), not row(R,A2,V2), A1 != A2.
|
|
% Querry Q is satisfied by row R if :
|
|
% Querry Q match an attribute A in the row R
|
|
% And ther are no attribute of the querry that do not match
|
|
% In other word there can not be qunsat(Q,R)
|
|
qsat(Q,R) :- qrow(Q,A,V), reprowID(R), row(R,A,V), not qunsat(Q,R).
|
|
qsat(Q) :- qsat(Q,G1).
|
|
|
|
% If a particular querry Q is not satisfied then the whole is not
|
|
unsat() :- qrow(Q,G1,G2), not qsat(Q).
|
|
sat() :- not unsat().
|
|
|
|
% !!! NEW
|
|
% Rename reprowID
|
|
#show freprowID/1.
|
|
freprowID(I) :- reprowID(I).
|
|
% Ensure there is at least one unsatisfied querry
|
|
:- sat().
|
|
|
|
|