Why is the output not as expected?

Vitali
2012-10-01
2012-10-03
  • Vitali

    Vitali - 2012-10-01

    The output should be b1 and b2 for A and I'm getting only b1. What's wrong with my code?
    public static void main(String args) {
    jPrologAPI joPA = new jPrologAPI("a(b1). a(b2).");
    Map output = joPA.queryOnce("a(A).");
    Iterator iterator = output.values().iterator();

    System.out.println(iterator.next());
    System.out.println(iterator.next());
    joPA.stop();

    }
    What's wrong here and how to correct it?
    Thanks.

     
  • Glendon Holst

    Glendon Holst - 2012-10-02

    What you want is 'query' instead of 'queryOnce', and to use 'retry' to get the second solution. Like so:

    h = joPA.query("a(A).");

    // display hashtable h

    h = joPA.retry();

    // display h

    Look in jPrologAPI.java for the functions and their documentation. Good luck!

     
    • Vitali

      Vitali - 2012-10-03

      @Glendon Holst could you please re-review my problem below? It's pretty urgent.

       
  • Vitali

    Vitali - 2012-10-02

    I apologize, I copied the wrong code. That's what I tried initially:
    public static void main(String[] args) {
    jPrologAPI joPA = new jPrologAPI("a(b1). a(b2).");
    Map output = joPA.query("a(Q).");
    System.out.println(output.values().toString());
    joPA.retry();
    System.out.println(output.values().toString());
    joPA.stop();
    }
    I got b1 twice.
    I also tried some other combinations, so I don't know how to continue.
    Could you provide me with more details?
    Thanks.

     
  • Vitali

    Vitali - 2012-10-02

    BTW, if I update the iterator it also doesn't work:
    jPrologAPI joPA = new jPrologAPI("a(b1). a(b2).");
    Map output = joPA.query("a(A).");
    Iterator iterator = output.values().iterator();
    System.out.println(iterator.next());
    joPA.retry();
    iterator = output.values().iterator();
    System.out.println(iterator.next());
    System.out.println(iterator.next());
    joPA.stop();
    Result:
    'b1'
    'b1'
    Exception in thread "main" java.util.NoSuchElementException: Hashtable Enumerator
    at java.util.Hashtable$Enumerator.nextElement(Hashtable.java:1190)
    at java.util.Hashtable$Enumerator.next(Hashtable.java:1201)
    at jlogtest.JLogTest.main(JLogTest.java:26)

     

Log in to post a comment.