Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
interact_with_knowrob_via_ros [2013/01/09 21:13] – [Client libraries] tenorthinteract_with_knowrob_via_ros [2013/02/12 17:41] – external edit 127.0.0.1
Line 10: Line 10:
 ===== Client libraries ===== ===== Client libraries =====
 The communication with the //json_prolog// service uses a [[http://json.org/|JSON-encoded]] format for representing the Prolog terms that form the query. While you can construct these terms manually and call the service directly, it is usally much easier to use one of the provided client libraries. There are libraries for Python, C++, Java and Lisp. Example clients are available in the //json_prolog/examples// folder; below is the code for sending KnowRob queries from Python via //json_prolog//. The communication with the //json_prolog// service uses a [[http://json.org/|JSON-encoded]] format for representing the Prolog terms that form the query. While you can construct these terms manually and call the service directly, it is usally much easier to use one of the provided client libraries. There are libraries for Python, C++, Java and Lisp. Example clients are available in the //json_prolog/examples// folder; below is the code for sending KnowRob queries from Python via //json_prolog//.
 +
 +
 +==== Python client ====
  
 <code python> <code python>
Line 29: Line 32:
  
 </code> </code>
 +
 +==== C++ client ====
  
 <code c++> <code c++>
Line 61: Line 66:
  
 </code> </code>
 +
 +==== Java client ====
 +
 +<code java> 
 +import edu.tum.cs.ias.knowrob.json_prolog.Prolog;
 +import edu.tum.cs.ias.knowrob.json_prolog.PrologBindings;
 +import edu.tum.cs.ias.knowrob.json_prolog.PrologQueryProxy;
 +
 +
 +public class JSONPrologTestClient {
 +
 + public static void main(String args[]) {
 +
 + Prolog pl = new Prolog();
 + PrologQueryProxy bdgs = pl.query("member(A, [1, 2, 3, 4]), B = ['x', A], C = foo(bar, A, B)");
 +
 +  
 + for(PrologBindings bdg : bdgs) {
 +
 +      System.out.println("Found solution: ");
 +      System.out.println("A = " + bdg.getBdgs_().get("A") );
 +      System.out.println("B = " + bdg.getBdgs_().get("B") );
 +      System.out.println("C = " + bdg.getBdgs_().get("C") );
 +    }
 +  }
 +}
 +</code>
 +