Help with JPL
"Brody, Justin" <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hello!
I've been having trouble constructing JPL queries and was hoping for some guidance. I have a predicate in my Prolog KB that takes two cards (each card is a list of size 2) and says whether or not they form a pair.
Some examples:
?- one_pair([ace, hearts], [ace, clubs]).
true.
?- one_pair([ace, hearts], Y).
Y = [ace, clubs] ;
Y = [ace, diamonds] ;
Y = [ace, hearts] ;
Y = [ace, spades].
It is the enumeration I'm really trying to access. Here's my code
Variable Z = new Variable("Z");
Query s = new Query ( new Compound("one_pair", new Term[] { new Atom("[two, hearts]"), Z }));
System.out.println( "here");
while ( s.hasMoreSolutions() ) {
System.out.println( "now here...");
java.util.Hashtable sol3 = s.nextSolution();
System.out.println( sol3.get("Z"));
}
Variable X = new Variable();
Query q = new Query ( new Compound("valid_face", new Term[] { new Variable("X") }));
while ( q.hasMoreSolutions() ) {
java.util.Hashtable sol = q.nextSolution();
System.out.println( sol.get("X"));
}
The second part is testing a simple predicate that lists valid faces and is included because it seems to be working. The first part, which I want to return the possible completions, isn't working. Here's the output:
here
2
3
4
5
6
7
8
9
10
jack
queen
king
ace
Any insights would be appreciated! If I can get this working I also have a more general question (ideally I'd like to be able to use my original version of one_pair, which takes an arbitrary sized list. For example,
?- one_pair([ [2, hearts], [3, clubs], X, Y]).
X = Y, Y = [2, clubs] ;
X = [2, clubs],
Y = [2, diamonds] ;
X = [2, clubs],
Y = [2, hearts] ;
X = [2, clubs],
Y = [2, spades] .
)
But I can work with the n-ary predicate versions I discussed if need be.
Thanks in advance!
-Justin