0

I use jpl libraries to connect prolog and java. In prolog, I can execute query :

?- meaning_forms([apple,is,fruit],X). 

output is : X = [is_a(x1, x2), objectx(x1, apple), objectx(x2, fruit)].

But in java, I can’t see output of this query. I tried some code in java :

Variable X = new Variable("X");
Query   q4 = new Query("meaning_forms", new Term[]{new Atom("apple,is,fruit"),X});
while ( q4.hasMoreElements() ) {
    java.util.Hashtable solution = (Hashtable) q4.nextElement();
    System.out.println( "X = " + (Term) solution.get("X"));
}

There is no output in java . Any solution to this case?

false
  • 10,264
  • 13
  • 101
  • 209
deniss
  • 9
  • 2
  • Your expression, `new Query("meaning_forms", new Term[]{new Atom("apple,is,fruit"),X});` will generate a query that looks like, `meaning_forms( 'apple, is, fruit', X )`, so the first argument won't be an array. I think you need something like, `new Query("meaning_forms", new Term[] { Util.termArrayToList(new Term[] { new Atom("apple"), new Atom("is"), new Atom("fruit") }) ,X });`, or some such... :) – lurker May 13 '15 at 16:42

1 Answers1

1
Hashtable[] solutions = q4.allSolutions();
for (int i = 0 ; i < solutions.length; ++i) {
    System.out.println("X = " + solutions[i].get(X));
}

See also http://www.swi-prolog.org/packages/jpl/java_api/getting_started.html

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138