This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
TP-KRR/pip2/dbms.lp
vandechat96 94a5a22062 first commit
2023-02-28 22:29:48 +01:00

50 lines
1.4 KiB
Plaintext

#show val/2.
% var(X) represent the different variable defined in the query
var(X) :- q1(_,X).
var(X) :- q2(_,X,_).
var(X) :- q2(_,_,X).
var(X) :- q3(_,X,_,_).
var(X) :- q3(_,_,X,_).
var(X) :- q3(_,_,_,X).
var(X) :- q4(_,X,_,_,_).
var(X) :- q4(_,_,X,_,_).
var(X) :- q4(_,_,_,X,_).
var(X) :- q4(_,_,_,_,X).
% const(X) are the constants present in the facts
const(X) :- d1(_,X).
const(X) :- d2(_,X,_).
const(X) :- d2(_,_,X).
const(X) :- d3(_,X,_,_).
const(X) :- d3(_,_,X,_).
const(X) :- d3(_,_,_,X).
const(X) :- d4(_,X,_,_,_).
const(X) :- d4(_,_,X,_,_).
const(X) :- d4(_,_,_,X,_).
const(X) :- d4(_,_,_,_,X).
% choose som valuation for a variable X to a constant Y
{val(X,Y) : var(X), const(Y)}.
% there can only be one valuation for each varibale
:- val(X,Y), val(X,Y1), Y != Y1.
% each variable must be used
:- var(X), not val(X,_).
% if there are some valuations and a querry using the variable of those valuations
% then ther must be a fact in the database that prove it by using the constant of the valuations
:- val(Var,Val), q1(Rel,Var), not d1(Rel, Val).
:- val(Var1,Val1), val(Var2, Val2), q2(Rel,Var1, Var2), not d2(Rel, Val1, Val2).
:- val(Var1, Val1), val(Var2, Val2), val(Var3, Val3), q3(Rel,Var1,Var2,Var3), not d3(Rel,Val1,Val2,Val3).
:- val(Var1, Val1), val(Var2, Val2), val(Var3, Val3), val(Var4, Val4), q4(Rel,Var1,Var2,Var3, Var4), not d4(Rel,Val1,Val2,Val3, Val4).