Re: Help with JPL
"Brody, Justin" <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Nevermind -- I think I figured it out. Thanks so much! ________________________________________ From: swi-prolog-bounces+justin.brody=goucher.edu@lists.iai.uni-bonn.de [swi-prolog-bounces+justin.brody=goucher.edu@lists.iai.uni-bonn.de] on behalf of Brody, Justin [[email protected]] Sent: Wednesday, November 20, 2013 6:44 AM To: Carlo Capelli Cc: [email protected] Subject: Re: [SWIPL] Help with JPL That makes sense. Sadly, I'm not sure how to do that -- would this need the "primitive" level of the API? Thanks for your help! ________________________________ From: Carlo Capelli [[email protected]] Sent: Wednesday, November 20, 2013 5:52 AM To: Brody, Justin Cc: [email protected] Subject: Re: [SWIPL] Help with JPL I think this isn't what you need new Atom("[two, hearts]") you should build a list with 2 atoms instead bye Carlo 2013/11/20 Brody, Justin <[email protected]<mailto:[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 _______________________________________________ SWI-Prolog mailing list [email protected]<mailto:[email protected]> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog _______________________________________________ SWI-Prolog mailing list [email protected] https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog