VP search technique
Posted: 20 Aug 2014 19:10
Dear Sir;
Could you help me to know the search technique of VP?
Regards;
AHMED
Could you help me to know the search technique of VP?
Regards;
AHMED
Visual Prolog Discussion forums
https://discuss.visual-prolog.com/
Code: Select all
predicates
p : ().
clauses
p() :-
p(),
p().
Code: Select all
pr_Phra:(string,string,pr_Phra,string*) nondeterm(i,o,o,o).
Code: Select all
pr_Phra(Str,Rest,pr_Phra2(P_Phra1,P_Phra2),PrList):-
frontToken(Str,W1,_),
getW(ID1,W1,_,"pr",_,_,_,_,_,_,_,_,_,_,_,_,_),
ID1<>0,
pr_ph(Str,Rest1,P_Phra1,PrLst1),
frontToken(Rest1,W2,_),
getW(ID2,W2,_,"pr",_,_,_,_,_,_,_,_,_,_,_,_,_),
ID2<>0,
pr_ph(Rest1,Rest,P_Phra2,PrLst2),
PrList=list::append(PrLst1,PrLst2).
pr_Phra(Str,Rest,pr_Phra1(P_Phra),PrList):-
frontToken(Str,W,_),
getW(ID,W,_,"pr",_,_,_,_,_,_,_,_,_,_,_,_,_),
ID<>0,
pr_ph(Str,Rest,P_Phra,PrList).
Code: Select all
pr_ph:(string,string,pr_ph,string*) nondeterm(i,o,o,o).
Code: Select all
pr_ph = pr_ph2(string,string);
pr_ph1(string).
Code: Select all
pr_ph(Str,Rest,pr_ph2(Pr,Pro),PrList):-
frontToken(Str,Pr,Rest1),
getW(ID1,Pr,_,"pr",_,_,_,_,_,_,_,_,_,_,_,_,_),
ID1<>0,
frontToken(Rest1,Pron,Rest),
getW(ID2,Pron,_,"pro",_,_,_,_,_,_,_,_,_,_,_,_,_),
ID2<>0,
PrList=["pr","pro"].
pr_ph(Str,Rest,pr_ph2(Pr,Ad),PrList):-
frontToken(Str,Pr,Rest1),
getW(ID1,Pr,_,"pr",_,_,_,_,_,_,_,_,_,_,_,_,_),
ID1<>0,
frontToken(Rest1,Ad,Rest),
getW(ID2,Ad,_,"ad",_,_,_,_,_,_,_,_,_,_,_,_,_),
ID2<>0,
PrList=["pr","ad"].
pr_ph(Str,Rest,pr_ph1(Pr),PrList):-
frontToken(Str,Pr,Rest),
getW(ID,Pr,_,"pr",_,_,_,_,_,_,_,_,_,_,_,_,_),
ID<>0,
PrList=["pr"].
pr_ph(Str,Rest,pr_ph1(Ad),PrList):-
frontToken(Str,Pr,Rest),
getW(ID,Ad,_,"ad",_,_,_,_,_,_,_,_,_,_,_,_,_),
ID<>0,
PrList=["pr"].
Code: Select all
pr_ph(Str, Rest, pr_ph1(Ad), PrList) :-
frontToken(Str, Pr, Rest),
getW(ID, Ad, _, "ad", _, _, _, _, _, _, _, _, _, _, _, _, _),
ID <> 0,
PrList = ["pr"].
Such warnings should be taken seriously, because very often they are caused by a bug.w507 Unused variable: 'Pr'
Code: Select all
class facts
getW : (integer, string, handle, string, handle, handle, handle, handle, handle, handle, handle, handle, handle, handle, handle, handle, handle).
Code: Select all
class predicates
getWord_nd : (string WordClass, string Input, string Rest [out]) -> string Word nondeterm.
clauses
getWord_nd(WordClass, Input, Rest) = Word :-
frontToken(Input, Word, Rest),
getW(ID, Word, _, WordClass, _, _, _, _, _, _, _, _, _, _, _, _, _),
ID <> 0.
Code: Select all
class predicates
tryGetWord : (string WordClass, string Input, string Rest [out]) -> string Word determ.
clauses
tryGetWord(WordClass, Input, Rest) = Word :-
frontToken(Input, Word, Rest),
getW(ID, Word, _, WordClass, _, _, _, _, _, _, _, _, _, _, _, _, _),
ID <> 0,
!.
Code: Select all
class predicates
pr_Phra : (string, string, pr_Phra, string*) nondeterm (i,o,o,o).
clauses
pr_Phra(Str, Rest, pr_Phra2(P_Phra1, P_Phra2), PrList) :-
_W1 = tryGetWord("pr", Str, _),
pr_ph(Str, Rest1, P_Phra1, PrLst1),
_W2 = tryGetWord("pr", Rest1, _),
pr_ph(Rest1, Rest, P_Phra2, PrLst2),
PrList = list::append(PrLst1, PrLst2).
pr_Phra(Str, Rest, pr_Phra1(P_Phra), PrList) :-
_W = tryGetWord("pr", Str, _),
pr_ph(Str, Rest, P_Phra, PrList).
class predicates
pr_ph : (string, string, pr_ph, string*) nondeterm (i,o,o,o).
clauses
pr_ph(Str, Rest, pr_ph2(Pr, Pron), PrList) :-
Pr = tryGetWord("pr", Str, Rest1),
Pron = tryGetWord("pro", Rest1, Rest),
PrList = ["pr", "pro"].
pr_ph(Str, Rest, pr_ph2(Pr, Ad), PrList) :-
Pr = tryGetWord("pr", Str, Rest1),
Ad = tryGetWord("ad", Rest1, Rest),
PrList = ["pr", "ad"].
pr_ph(Str, Rest, pr_ph1(Pr), PrList) :-
Pr = tryGetWord("pr", Str, Rest),
PrList = ["pr"].
Code: Select all
class predicates
pr_ph : (string, string, pr_ph, string*) nondeterm (i,o,o,o).
clauses
pr_ph(Str, Rest, pr_ph2(Pr, Pron), PrList) :-
Pr = tryGetWord("pr", Str, Rest1),
Pron = tryGetWord("pro", Rest1, Rest),
!, % if we have found a ["pr", "pro"] solution we will not try ["pr", "ad"] and ["pr"]
PrList = ["pr", "pro"].
pr_ph(Str, Rest, pr_ph2(Pr, Ad), PrList) :-
Pr = tryGetWord("pr", Str, Rest1),
Ad = tryGetWord("ad", Rest1, Rest),
!, % if we have found a ["pr", "ad"] solution we will not try ["pr"]
PrList = ["pr", "ad"].
pr_ph(Str, Rest, pr_ph1(Pr), PrList) :-
Pr = tryGetWord("pr", Str, Rest),
PrList = ["pr"].
Code: Select all
clauses
pr(Str, Rest, P, PrList) :-
pr_Phra(Str, Rest, P, PrList),
!. % only consider the first top-level solution
Code: Select all
pr_ph(Str, Rest, pr_ph1(Ad), PrList) :-
frontToken(Str, Ad, Rest),
getW(ID, Ad, _, "ad", _, _, _, _, _, _, _, _, _, _, _, _, _),
ID <> 0,
PrList = ["ad"].
Code: Select all
class predicates
pr_phra : (string, string, pr_Phra, string*) nondeterm (i,o,o,o).
Code: Select all
clauses
Case (1):
pr_phra(Str, Rest, pr_phra2(P_Phra1, P_Phra2), PrList) :-
_W1 = tryGetWord("pr", Str, _),
pr_ph(Str, Rest1, P_Phra1, PrLst1),
_W2 = tryGetWord("pr", Rest1, _),
pr_ph(Rest1, Rest, P_Phra2, PrLst2),
PrList = list::append(PrLst1, PrLst2).
Case (2):
pr_phra(Str, Rest, pr_phra1(P_Phra), PrList) :-
_W = tryGetWord("pr", Str, _),
pr_ph(Str, Rest, P_Phra, PrList).
Code: Select all
(P and Q1) or (P and Q2) <=> P and (Q1 or Q2)
Code: Select all
clauses
pr_phra(Str, Rest, P_Phra, PrList) :-
pr_ph(Str, Rest1, P_Phra1, PrLst1),
if pr_ph(Rest1, Rest, P_Phra2, PrLst2) then
P_Phra =pr_phra2(P_Phra1, P_Phra2),
PrList = list::append(PrLst1, PrLst2)
else
P_Phra = P_Phra1,
PrList = PrLst1
end if.