com.kprolog.plc
Class Plc

java.lang.Object
  |
  +--com.kprolog.plc.Plc
All Implemented Interfaces:
java.lang.Runnable

public class Plc
extends java.lang.Object
implements java.lang.Runnable

Plc is an interface between Java and Prolog, implemented via Java Native Interface and reflection.


Constructor Summary
Plc()
          Constructs an instance representing a prolog goal.
Plc(PlcClient client, java.lang.String functor, java.lang.Object[] args)
          Constructs an instance representing a prolog goal.
Plc(java.lang.String functor, java.lang.Object[] args)
          Constructs an instance representing a prolog goal.
 
Method Summary
static java.lang.String arrayToString(java.lang.String open, java.lang.Object[] args, java.lang.String close)
          Converts an array to a list style String.
 boolean call()
          Calls a prolog goal specified by this instance.
static boolean exec(java.lang.String command)
          Parses and executes a prolog command.
 java.lang.Object getPrologResult(int n)
          Get the result returned from prolog for null arguments.
static void main(java.lang.String[] args)
          When invoked as an application, main() starts the Prolog toplevel.
 void run()
          Calls a prolog goal with new thread, and find all the results.
 void setArgs(java.lang.Object[] args)
          Sets the arguments of the goal.
 void setFunctor(java.lang.String functor)
          Sets the functor name of the goal.
static void startPlc(java.lang.String[] args)
          Initializes JIPL interface.
static java.lang.Object toIntegerArray(java.lang.Object src)
          Convert miss interpreted string to an Integer array K-Prolog sometimes miss interprete a list of integer to a string.
 java.lang.String toString()
          Converts to a String representing the goal contents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Plc

public Plc()
Constructs an instance representing a prolog goal.

Plc

public Plc(java.lang.String functor,
           java.lang.Object[] args)
Constructs an instance representing a prolog goal.
Parameters:
functor - functor name of the goal
args - array of arguments, prolog variables are represented by null object reference

Plc

public Plc(PlcClient client,
           java.lang.String functor,
           java.lang.Object[] args)
Constructs an instance representing a prolog goal.
Parameters:
client - reciever of result of the goal
functor - functor name of the goal
args - array of arguments, prolog variables are represented by null object reference
Method Detail

startPlc

public static void startPlc(java.lang.String[] args)
Initializes JIPL interface.
Parameters:
args - as command line options of K-Prolog
{"-a", "ATOM", "-h", "HEAP", "-l", "LOCAL", "-g", "GLOBAL"}
where ATOM etc. are the size of Prolog regions.

exec

public static boolean exec(java.lang.String command)
Parses and executes a prolog command. Deterministic.
Parameters:
command - any prolog command
Returns:
true if command sucesses, false if it fails

main

public static void main(java.lang.String[] args)
When invoked as an application, main() starts the Prolog toplevel.
Parameters:
args - passed to startPlc
See Also:
startPlc(java.lang.String[])

setFunctor

public void setFunctor(java.lang.String functor)
Sets the functor name of the goal.
Parameters:
functor - functor name of the goal

setArgs

public void setArgs(java.lang.Object[] args)
Sets the arguments of the goal.
Parameters:
args - array of arguments

call

public boolean call()
Calls a prolog goal specified by this instance. Deterministic.
Returns:
true if the goal sucesses, false if it fails

run

public void run()
Calls a prolog goal with new thread, and find all the results. Results are passed to the client object.
Specified by:
run in interface java.lang.Runnable
See Also:
PlcClient.success(java.lang.Object[]), PlcClient.fail()

getPrologResult

public java.lang.Object getPrologResult(int n)
Get the result returned from prolog for null arguments.
Parameters:
n - position of argument (0 to args.length-1)

toIntegerArray

public static java.lang.Object toIntegerArray(java.lang.Object src)
Convert miss interpreted string to an Integer array K-Prolog sometimes miss interprete a list of integer to a string. This is very difficult to fix, because Prolog string is a list of integer character codes. For example, [3110] is an list of integer, but this also represents my name -kino in kanji- as a string. So, we may reinterprete it to an Integer array in such case.
Parameters:
src - an argument returned from prolog
Returns:
an Integer array

toString

public java.lang.String toString()
Converts to a String representing the goal contents.
Overrides:
toString in class java.lang.Object

arrayToString

public static java.lang.String arrayToString(java.lang.String open,
                                             java.lang.Object[] args,
                                             java.lang.String close)
Converts an array to a list style String.