I have implemented several chain rules in a way that the last rule obtain the desired result depending on the result of the previous ones.
rule1(X,Y) :-
pred1(X,Z),
pred1(Y,Z).
rule2(Z,T) :-
rule1(X,Y),
pred2(Z,X),
pred2(T,Y).
I need to obtain every fact that has been inferred for each one of the rules. I'm doing this from Java using the jpl library.
String stringFileQuery = "rule1(X,Y)";
System.out.println(stringFileQuery + " "
+ (Query.hasSolution(stringFileQuery) ? "succeeded" : "failed"));
Query fileQuery = new Query(stringFileQuery);
System.out.println("all solutions of " + stringFileQuery);
while (fileQuery.hasMoreSolutions()) {
Map<String, Term> s10 = fileQuery.nextSolution();
System.out.println("First -> " + s10.get("X") + ", Second ->" + 10.get("Y"));
}
How can I obtain all these facts, even in Prolog? In the real program, I have more that two rules.
rule1(X,Y) :- pred1(X,Z), pred1(Y,Z).
andrule2(Z,T) :- rule1(X,Y), pred2(Z,X), pred2(T,Y).
? – SQBrule1(X,Y)
, you'd like to seepred1(X,Z), pred1(Y,Z)
and if you check forrule2(Z,T)
, you'd like to seepred1(X,Z), pred1(Y,Z), pred2(Z,X), pred2(T,Y)
? – SQBpred1(X, Y)
, so I expect the output ...; I put inpred2(Z,T)
, so I expect the output ..."? – SQB