Algernon Software

org.algernon
Class Algernon

java.lang.Object
  extended byorg.algernon.app.AlgernonApplication
      extended byorg.algernon.Algernon

public class Algernon
extends AlgernonApplication

Algernon is an inference engine for knowledge-based systems that use a relational or frame-based system representation system. See org.algernon.kb for the required KB interface and for implementations of interfaces for other systems. See the following Algernon web pages:

Example usage:
   Algernon   algy = new Algernon();
   AlgernonKB kb1  = new AlgernonProtegeKB(".../mykb.pprj");
   if (kb1 == null)  // check for error opening the KB
     return;
   algy.addKB(kb1);  // Can add multiple KBs with multiple calls.

   // Now call the load, ask or tell methods.
   ErrorSet errors = new ErrorSet();
   load(".../myfile.txt"); // Load Algernon rules and commands
   LispValue result = ask("((...path...))", errors);
   if (errors.size() > 0)
     algy.printErrors(errors);
   else
       System.out.println(algy.printResultToString("ASK", result));
   ...
 
Algernon was originally implemented by James Crawford and Ben Kuipers circa 1990. It was reimplemented on the Algernon Abstract Machine by Micheal Hewett with help from Ben Kuipers and Spencer Bishop circa 1996. This reimplementation in Java commenced in 2002 by Micheal Hewett.


Field Summary
 LispValue ANY
          Used when defining a relation, indicates unlimited maximum cardinality.
 LispValue ANY_TYPE
           
static int BEST_FIRST
          Controls how the set of activations is processed.
 LispValue BOOLEAN_TYPE
           
static int BREADTH_FIRST
          Controls how the set of activations is processed.
 LispValue CLASS_TYPE
           
 LispValue DEFAULT
          Used when defining a relation.
static String DEFAULT_KBSET_NAME
           
private static int DEFAULT_SERVER_PORT_NUMBER
          Default port number when Algernon is running in Server mode.
static int DEPTH_FIRST
          Controls how the set of activations is processed.
private  Map f_allCommands
           
private  AlgernonServer f_server
           
 LispValue FALSE
          Boolean false = :FALSE.
 LispValue FLOAT_TYPE
           
 LispValue FOREIGN_TYPE
           
 LispValue INCLUSIVE
          Used in structure-traversing commands like :CHILD.
 LispValue INSTANCE_TYPE
           
 LispValue INTEGER_TYPE
           
 LispValue INVERSE
          Used when defining a relation.
 LispValue LISP_TYPE_DOMAINS
           
protected  AlgernonCompiler m_compiler
           
protected  AlgernonCompilerState m_compileSettings
           
protected  int m_dataColumn1
           
protected  int m_dataColumn2
           
protected  int m_dataColumn3
           
private  HashMap m_evaluators
           
protected  int m_executionOrder
           
protected  Map m_KBSets
           
protected  Jatha m_lisp
           
protected  Processor m_processor
           
protected  AlgernonSettings m_processSettings
           
protected  RuleManager m_ruleManager
           
 LispValue MAX_CARDINALITY
          Used when defining a relation.
 LispValue MIN_CARDINALITY
          Used when defining a relation.
static int NEGATED
          Used when processing clauses - stating that the clause is negated.
 LispValue NOT
          This is used in the Algernon macro for adding a known false value to an object-relation.
 LispValue STRING_TYPE
           
 LispValue SYMBOL_TYPE
           
 LispValue TRUE
          Boolean true = :TRUE.
static char VARIABLE_START_CHAR
           
 
Fields inherited from class org.algernon.app.AlgernonApplication
 
Constructor Summary
Algernon()
           
Algernon(AlgernonKB kb)
          Create a new instance of Algernon.
Algernon(AlgernonKBSet kbs)
          Create a new instance of Algernon.
 
Method Summary
 void addClosure(Closure closure)
          Adds a closure to the system.
 void addCommand(LispValue name, Command command)
          Adds a new command to Algernon.
 void addEvaluator(String language, ExternalLanguageEvaluator evaluator)
          Adds a new language evaluator.
 void addKB(AlgernonKB kb)
          Adds a new KB to the list of KBs that Algernon accesses.
 void addKBSet(AlgernonKBSet kbset)
          Adds a new AlgernonKBSet to this instantiation of Algernon.
 void addRule(Rule rule, AlgernonFrame associatedFrame)
          Adds a rule to the system.
 void addToActionQueue(Processor processor, LispValue item)
          Adds an activation to the action queue.
 LispValue ask(Path path, AlgernonKBSet kbSet, String comment, ErrorSet errorSet, BindingList blist, AlgernonSettings processSettings)
          See the single-parameter version for documentation.
 LispValue ask(String path)
          Processes the path in QUERY mode.
 LispValue ask(String path, AlgernonKB kb)
          See the single-parameter version for documentation.
 LispValue ask(String path, AlgernonKB kb, ErrorSet errors)
          See the single-parameter version for documentation.
 LispValue ask(String path, AlgernonKB kb, ErrorSet errors, BindingList blist)
          See the single-parameter version for documentation.
 LispValue ask(String path, AlgernonKBSet kbSet)
          See the single-parameter version for documentation.
 LispValue ask(String path, AlgernonKBSet kbSet, String comment)
          See the single-parameter version for documentation.
 LispValue ask(String path, AlgernonKBSet kbSet, String comment, ErrorSet errorSet)
          See the single-parameter version for documentation.
 LispValue ask(String pathString, AlgernonKBSet kbSet, String comment, ErrorSet errorSet, BindingList blist, AlgernonSettings processSettings)
          See the single-parameter version for documentation.
 LispValue ask(String path, ErrorSet errors)
          See the single-parameter version for documentation.
 LispValue askForValue(String query, LispValue valueType, Collection possibleValues)
          Requires the user to enter an item from the set of possibleValues.
 boolean askYorN(String query)
          Asks the user to confirm whether the query is true.
 void clearAllRules()
          Removes all known rules and rule continuations.
 void clearQueryHistory()
          Clears the entire list of historical queries.
 LispValue compile(Path path, AlgernonKBSet kbSet, int compileMode, ErrorSet errorSet)
          Compiles a path (which may be a rule declaration, a query, an assert or part of a rule) and returns the AAM opcodes for the path.
 LispValue compile(String path, AlgernonKBSet kbSet, int compileMode, ErrorSet errorSet)
          Compiles a path (which may be a rule declaration, a query, an assert or part of a rule) and returns the AAM opcodes for the path.
 Collection compileRule(Rule rule, AlgernonKBSet kbSet)
          Compiles the given rule and returns the compiled code.
 AlgernonKB createKB(Clause clause)
          Called by the USE-KB opcode to create a new KB.
 AlgernonRelation createRelation(AlgernonKB kb, String slotName, Set domains, Set ranges, Integer minCardinality, Integer maxCardinality, Object defaultValue, AlgernonRelation inverseRelation)
          Creates a new relation in the given KB.
 void createRule(Rule rule, AlgernonKBSet kbSet, AlgernonFrame frame)
          Send in a rule instance.
 Object evaluateExpression(String language, LispValue expression)
          Evaluates a method in the given language.
 Boolean evaluateExpressionAsBoolean(String language, LispValue expression)
          Evaluates a method in the given language.
 boolean generalIsa(String child, String parent)
          Returns true if the first argument is an instance or subclass of the second argument.
 boolean generalIsa(String child, String parent, AlgernonKB kb)
          Returns true if the first argument is an instance or subclass of the second argument.
 boolean generalIsa(String child, String parent, AlgernonKBSet kbset)
          Returns true if the first argument is an instance or subclass of the second argument.
 boolean generalNotIsa(String child, String parent)
          Returns true if the first argument is not an instance or subclass of the second argument.
 boolean generalNotIsa(String child, String parent, AlgernonKB kb)
          Returns true if the first argument is not an instance or subclass of the second argument.
 boolean generalNotIsa(String child, String parent, AlgernonKBSet kbset)
          Returns true if the first argument is not an instance or subclass of the second argument.
 Collection getActivatedRules(AlgernonFrame frame, int direction, int type)
          Returns a list of activatable rules that match the given criteria.
 Object getAlgernonBinding(String variable, BindingList bindings)
          Returns the binding of a variable from a result.
static LispValue getArgs(LispValue value)
          Returns the relation of the clause, which is the first element of the list.
static LispValue getArguments(Clause value)
          Returns the relation of the clause.
 Object getBinding(String variable, BindingList bindings)
          Returns the binding of a variable from a result.
 Command getCommand(LispValue name)
          Retrieves a command by its name (a LispSymbol).
 AlgernonCompiler getCompiler()
          Returns the current compiler used by Algernon.
 ExternalLanguageEvaluator getEvaluator(String language)
          Returns a language evaluator for the given language.
 int getExecutionOrder()
          Returns the value of ExecutionOrder.
static LispValue getFrame(Clause value)
          Returns the frame of the clause.
static LispValue getFrame(LispValue value)
          Returns the frame of the clause, which is the second element of the list.
 String getImportantSupersetSlotName()
          Returns the name of the slot that represents the relation between a class and a superclass for inheritance purposes.
 AlgernonKBSet getKBSet()
          Returns the set of KBs with the default AlgernonKBSet name.
 AlgernonKBSet getKBSet(String name)
          Returns the set of KBs with the given name.
 Jatha getLisp()
           
 LispParser getLispParser()
          Returns a LISP parser.
 OpcodeSet getOpcodeSet()
           
 Processor getProcessor()
           
 RegisterSet getRegisters()
           
static LispValue getRelation(Clause value)
          Returns the relation of the clause.
static LispValue getRelation(LispValue value)
          Returns the relation of the clause, which is the first element of the list.
 Rule getRule(String str)
          Returns the rule with the given name.
 Collection getRules(String str)
          Returns all rules with the given string in their names.
 int getServerPortNumber()
          Returns the port number the server is running on.
 int getTraceLevel()
          Returns the relation of the clause.
 LispValue getValueType(Object o)
          Get the data type of the Java object passed in; we expect this to be Integer, Float, Boolean, Cls, or Instance
 LispValue getValueTypes()
           
 LispValue insertDepthFirst(LispValue item, LispValue queue)
          This is the default actionQueueInsertionFunction.
 LispValue instantiate(LispValue term, LispValue env)
           
 boolean isClassToInstanceRelation(String relationName)
          Returns true if the given string is the name of the relation/slot linking an instance to its class in any KB of the default AlgernonKBSet.
 boolean isClassToInstanceRelation(String relationName, AlgernonKB kb)
          Returns true if the given string is the name of the relation/slot linking an instance to its class in the given KB.
 boolean isClassToInstanceRelation(String relationName, AlgernonKBSet kbset)
          Returns true if the given string is the name of the relation/slot linking an instance to its class in any KB of the given AlgernonKBSet.
 boolean isDisjointRelation(String relationName)
          Returns true if the given string is the name of a relation specifying that two classes are disjoint
 boolean isDisjointRelation(String relationName, AlgernonKB kb)
          Returns true if the given string is the name of a relation specifying that two classes are disjoint in the given KB.
 boolean isDisjointRelation(String relationName, AlgernonKBSet kbset)
          Returns true if the given string is the name of a relation specifying that two classes are disjoint in any KB of the given AlgernonKBSet.
 boolean isFrame(String frameName)
          Returns true if the given string is the name of a frame in any KB.
 boolean isFrame(String frameName, AlgernonKB kb)
          Returns true if the given string is the name of a frame in the given KB.
 boolean isFrame(String frameName, AlgernonKBSet kbset)
          Returns true if the given string is the name of a frame in any KB in the given AlgernonKBSet.
static boolean isGroundClause(Clause clause)
          Returns true if the given clause is ground (contains no variables).
static boolean isGroundPath(Path path)
          Returns true if the given clause is ground (contains no variables).
 boolean isInstance(Clause clause, Clause pattern)
          Determines whether clause is an instance of pattern, returning true or false.
 boolean isInstance(Clause clause, Clause pattern, BindingList clauseBindings, BindingList patternBindings)
          Determines whether clause is an instance of pattern, returning true or false.
 boolean isInstance(LispValue clause, LispValue pattern)
          Determines whether clause is an instance of pattern, returning true or false.
 boolean isInstance(LispValue clause, LispValue pattern, BindingList clauseBindings, BindingList patternBindings)
          Determines whether clause is an instance of pattern, returning true or false.
 boolean isInstanceToClassRelation(String relationName)
          Returns true if the given string is the name of the relation/slot linking an instance to its class in any KB of the default AlgernonKBSet.
 boolean isInstanceToClassRelation(String relationName, AlgernonKB kb)
          Returns true if the given string is the name of the relation/slot linking an instance to its class in the given KB.
 boolean isInstanceToClassRelation(String relationName, AlgernonKBSet kbset)
          Returns true if the given string is the name of the relation/slot linking an instance to its class in any KB of the given AlgernonKBSet.
 boolean isNameRelation(String relationName)
          Returns true if the given string is the name of the relation/attribute linking a frame to its name in any KB.
 boolean isNameRelation(String relationName, AlgernonKB kb)
          Returns true if the given string is the name of the relation/slot linking a frame to its name in the given KB.
 boolean isNameRelation(String relationName, AlgernonKBSet kbset)
          Returns true if the given string is the name of the relation/slot linking a frame to its name in any KB in the given AlgernonKBSet.
 boolean isRelation(String frameName)
          Returns true if the given string is the name of a relation in any KB.
 boolean isRelation(String relationName, AlgernonKB kb)
          Returns true if the given string is the name of a relation in the given KB.
 boolean isRelation(String relationName, AlgernonKBSet kbset)
          Returns true if the given string is the name of a frame in any KB in the given AlgernonKBSet.
 boolean isSubclassToSuperclassRelation(String relationName)
          Returns true if the given string is the name of the relation/attribute linking a class to its superclass in any KB.
 boolean isSubclassToSuperclassRelation(String relationName, AlgernonKB kb)
          Returns true if the given string is the name of the relation/slot linking a frame to its name in the given KB.
 boolean isSubclassToSuperclassRelation(String relationName, AlgernonKBSet kbset)
          Returns true if the given string is the name of the relation/slot linking a frame to its name in any KB in the given AlgernonKBSet.
static boolean isVariable(LispValue value)
          Returns true if the given value represents a variable in the system.
 void kbSetRenamed(AlgernonKBSet kbset, String oldname, String newname)
          Call this when a AlgernonKBSet is renamed.
 void load(String filename)
          Loads and executes a file of Algernon forms.
 void load(String filename, int traceLevel)
          Loads and executes a file of Algernon forms.
 void loadRulesFromKB(Collection rules)
          Loads rules that have been stored in a KB.
 AlgernonClass lookupClass(String name)
          Returns a class with the given name if it can find one in any of the KBs in the default KBSet.
 AlgernonClass lookupClass(String name, AlgernonKB kb)
          Returns a class with the given name if it can find one in the given KB.
 AlgernonClass lookupClass(String name, AlgernonKBSet kbset)
          Returns a class with the given name if it can find one in any of the KBs in the given KBSet.
 Collection lookupDirectInstances(AlgernonClass theClass)
          Returns a list of all direct instances of the given class.
 Collection lookupDirectSubclasses(AlgernonClass theClass)
          Returns a list of all subclasses, whether indirect or direct, of the given class.
 AlgernonFrame lookupFrame(String name)
          Returns a frame with the given name if it can find one in any of the KBs in the default KBSet.
 AlgernonFrame lookupFrame(String name, AlgernonKB kb)
          Returns a frame with the given name if it can find one in the given KB.
 AlgernonFrame lookupFrame(String name, AlgernonKBSet kbset)
          Returns a class with the given name if it can find one in any of the KBs in the given KBSet.
 Collection lookupInstances(AlgernonClass theClass)
          Returns a list of all instances, whether indirect or direct, of the given class.
 AlgernonRelation lookupRelation(String name)
          Returns a relation with the given name if it can find one in any of the KBs in the default KBSet.
 AlgernonRelation lookupRelation(String name, AlgernonKB kb)
          Returns a relation with the given name if it can find one in the given KB.
 AlgernonRelation lookupRelation(String name, AlgernonKBSet kbset)
          Returns a relation with the given name if it can find one in any of the KBs in the given KBSet.
 Collection lookupSubclasses(AlgernonClass theClass)
          Returns a list of all subclasses, whether indirect or direct, of the given class.
static void main(String[] args)
          The command line arguments are files to be processed.
 void printBindingList(int index, int indent, PrintWriter s, BindingList bindings, LispValue varsToPrint)
          Prints a binding list to the given stream.
 void printBindingList(PrintWriter s, BindingList bindings)
          This method has the original Algernon output format.
static void printErrors(ErrorSet errs)
          Prints an ErrorSet to System.err.
static String printErrorsToString(ErrorSet errs)
          Prints an ErrorSet to a String.
 void printResult(PrintWriter s, String operation, LispValue results, LispValue varsToPrint)
          Prints the results of Algernon execution in a nice format.
 void printResults(PrintWriter s, Result result, LispValue varsToPrint)
          Prints the actual binding lists from the execution.
 String printResultToString(String operation, LispValue results)
          Prints the results of Algernon execution in a nice format to a string
 String printResultToString(String operation, LispValue results, LispValue varsToPrint)
          Prints the results of Algernon execution in a nice format to a string
static void printWarnings(ErrorSet errs)
          Only prints warnings to System.err.
static String printWarningsToString(ErrorSet errs)
          Prints only the warnings in an ErrorSet to a String.
 LispValue process(LispValue code, AlgernonKBSet kbset, ErrorSet errors)
          Executes a set of AAM opcodes.
 LispValue queueInsertionFunction(LispValue item, LispValue values)
          Default queue insertion function.
 boolean relationIsFull(AlgernonFrame frame, AlgernonRelation relation)
          Returns true if the frame/relation combination is full - that is, the number of values stored in the slot is equal to the slot's maximum cardinality.
 void removeKB(AlgernonKB kb)
          Removes a KB from the default KB Set.
 void removeKB(AlgernonKB kb, AlgernonKBSet kbset)
          Removes a KB from the given KB Set.
 Iterator ruleNameIterator()
          An iterator that iterates over all Rules in the system.
 boolean serverIsRunning()
          Returns true if the server is running.
 void setCompilerDebug(boolean state)
          Use this to turn compiler debug mode on and off.
 void setExecutionOrder(int newExecutionOrder)
          Sets the value of ExecutionOrder.
 void setTraceLevel(int newTraceLevel)
           
 void shutdownServer()
          Shut down the Algernon server.
 String startServer(int portNumber)
          Starts the Algernon server.
 LispValue tell(Path path, AlgernonKBSet kbSet, String comment, ErrorSet errorSet, AlgernonSettings processSettings)
          See the single-parameter version for documentation.
 LispValue tell(String path)
          Processes the path in ASSERT mode.
 LispValue tell(String path, AlgernonKB kb)
          See the single-parameter version for documentation.
 LispValue tell(String path, AlgernonKB kb, ErrorSet errors)
          See the single-parameter version for documentation.
 LispValue tell(String path, AlgernonKBSet kbSet)
          See the single-parameter version for documentation.
 LispValue tell(String path, AlgernonKBSet kbSet, String comment)
          See the single-parameter version for documentation.
 LispValue tell(String path, AlgernonKBSet kbSet, String comment, ErrorSet errorSet)
          See the single-parameter version for documentation.
 LispValue tell(String pathString, AlgernonKBSet kbSet, String comment, ErrorSet errorSet, AlgernonSettings processSettings)
          See the single-parameter version for documentation.
 LispValue tell(String path, ErrorSet errors)
          See the single-parameter version for documentation.
 LispValue toValueType(Object typeName)
          Converts an object like ":INTEGER" to an official type.
 void trace(int traceLevel, String message)
          Prints a trace message, dependent on the current level of tracing.
 void trace(int traceLevel, String message, boolean newLine)
          Prints a trace message, dependent on the current level of tracing.
 
Methods inherited from class org.algernon.app.AlgernonApplication
getName, getVersionDate, getVersionMajor, getVersionMicro, getVersionMinor, getVersionString, getVersionType, getVersionURL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_KBSET_NAME

public static final String DEFAULT_KBSET_NAME
See Also:
Constant Field Values

VARIABLE_START_CHAR

public static final char VARIABLE_START_CHAR
See Also:
Constant Field Values

NEGATED

public static int NEGATED
Used when processing clauses - stating that the clause is negated.


ANY_TYPE

public LispValue ANY_TYPE

BOOLEAN_TYPE

public LispValue BOOLEAN_TYPE

CLASS_TYPE

public LispValue CLASS_TYPE

FLOAT_TYPE

public LispValue FLOAT_TYPE

FOREIGN_TYPE

public LispValue FOREIGN_TYPE

INSTANCE_TYPE

public LispValue INSTANCE_TYPE

INTEGER_TYPE

public LispValue INTEGER_TYPE

STRING_TYPE

public LispValue STRING_TYPE

SYMBOL_TYPE

public LispValue SYMBOL_TYPE

LISP_TYPE_DOMAINS

public LispValue LISP_TYPE_DOMAINS

DEPTH_FIRST

public static final int DEPTH_FIRST
Controls how the set of activations is processed. Default is DEPTH_FIRST.

See Also:
Constant Field Values

BREADTH_FIRST

public static final int BREADTH_FIRST
Controls how the set of activations is processed. Default is DEPTH_FIRST.

See Also:
Constant Field Values

BEST_FIRST

public static final int BEST_FIRST
Controls how the set of activations is processed. Default is DEPTH_FIRST. BEST_FIRST uses user-supplied heuristics. If none are supplied, execution is equivalent to DEPTH_FIRST.

See Also:
Constant Field Values

NOT

public LispValue NOT
This is used in the Algernon macro for adding a known false value to an object-relation.


TRUE

public LispValue TRUE
Boolean true = :TRUE. Use this when you need to store Boolean values in relations.


FALSE

public LispValue FALSE
Boolean false = :FALSE. Use this when you need to store Boolean values in relations.


INCLUSIVE

public LispValue INCLUSIVE
Used in structure-traversing commands like :CHILD.


MIN_CARDINALITY

public LispValue MIN_CARDINALITY
Used when defining a relation.


MAX_CARDINALITY

public LispValue MAX_CARDINALITY
Used when defining a relation.


DEFAULT

public LispValue DEFAULT
Used when defining a relation.


INVERSE

public LispValue INVERSE
Used when defining a relation.


ANY

public LispValue ANY
Used when defining a relation, indicates unlimited maximum cardinality.


DEFAULT_SERVER_PORT_NUMBER

private static int DEFAULT_SERVER_PORT_NUMBER
Default port number when Algernon is running in Server mode.


f_allCommands

private Map f_allCommands

m_executionOrder

protected int m_executionOrder

m_compiler

protected AlgernonCompiler m_compiler

m_processor

protected Processor m_processor

m_processSettings

protected AlgernonSettings m_processSettings

m_compileSettings

protected AlgernonCompilerState m_compileSettings

m_ruleManager

protected RuleManager m_ruleManager

m_KBSets

protected Map m_KBSets

m_dataColumn1

protected int m_dataColumn1

m_dataColumn2

protected int m_dataColumn2

m_dataColumn3

protected int m_dataColumn3

m_lisp

protected Jatha m_lisp

m_evaluators

private HashMap m_evaluators

f_server

private AlgernonServer f_server
Constructor Detail

Algernon

public Algernon()
         throws AlgernonException

Algernon

public Algernon(AlgernonKB kb)
         throws AlgernonException
Create a new instance of Algernon. Multiple instances can be created and run at the same time, however they should not open the same KB unless it is an in-memory KB or it is designed for simultaneous use by multiple clients.

Parameters:
kb - The instance of AlgernonKB. KBs can be added or removed at runtime.

Algernon

public Algernon(AlgernonKBSet kbs)
         throws AlgernonException
Create a new instance of Algernon. Multiple instances can be created and run at the same time, however they should not open the same KB unless it is an in-memory KB or it is designed for simultaneous use by multiple clients.

Parameters:
kbs - A collection of instances of AlgernonKB. KBs can be added or removed at runtime.
Method Detail

getLispParser

public LispParser getLispParser()
Returns a LISP parser. Always use this accessor function rather than calling new LispParser() so that you can guarantee that all symbols are interned in the correct symbol table.


ask

public LispValue ask(String path)
Processes the path in QUERY mode. This and tell() are the primary user interface functions for processing paths in Algernon. A path can add, modify or delete information in a knowledge base, which may involve activating and firing rules.

The path is validated and compiled into AAM machine code, then executed. A Result is returned. If the returned value is null or the size of the ErrorSet is non-zero, the caller should check the ErrorSet for errors and warnings.

If the result is m_lisp.NIL, the operation failed. Otherwise, use Result.iterator() to iterator over the BindingList objects in the Result.

The execution can be controlled by passing in an instance of AlgernonSettings, in which case they will be in effect for this call only, or by setting the parameters individually as a global setting.

If kbSet is null, the default KBSet will be used. If you specifically don't want to use any KBs in the query, send in an empty KBSet.

Parameters:
path - a String containing a path.
Returns:
Result a List of BindingLists.
See Also:
ErrorSet, BindingList, Result, AlgernonSettings

ask

public LispValue ask(String path,
                     AlgernonKB kb)
See the single-parameter version for documentation.


ask

public LispValue ask(String path,
                     ErrorSet errors)
See the single-parameter version for documentation.


ask

public LispValue ask(String path,
                     AlgernonKB kb,
                     ErrorSet errors)
See the single-parameter version for documentation.


ask

public LispValue ask(String path,
                     AlgernonKB kb,
                     ErrorSet errors,
                     BindingList blist)
See the single-parameter version for documentation.


ask

public LispValue ask(String path,
                     AlgernonKBSet kbSet)
See the single-parameter version for documentation.


ask

public LispValue ask(String path,
                     AlgernonKBSet kbSet,
                     String comment)
See the single-parameter version for documentation.


ask

public LispValue ask(String path,
                     AlgernonKBSet kbSet,
                     String comment,
                     ErrorSet errorSet)
See the single-parameter version for documentation.


ask

public LispValue ask(String pathString,
                     AlgernonKBSet kbSet,
                     String comment,
                     ErrorSet errorSet,
                     BindingList blist,
                     AlgernonSettings processSettings)
See the single-parameter version for documentation.


ask

public LispValue ask(Path path,
                     AlgernonKBSet kbSet,
                     String comment,
                     ErrorSet errorSet,
                     BindingList blist,
                     AlgernonSettings processSettings)
See the single-parameter version for documentation.


tell

public LispValue tell(String path)
Processes the path in ASSERT mode. This and ask() are the primary user interface functions for processing paths in Algernon. A path can add, modify or delete information in a knowledge base, which may involve activating and firing rules.

The path is validated and compiled into AAM machine code, then executed. A ResultSet is returned. If the returned value is null, the caller should check the ErrorSet for errors and warnings.

The execution can be controlled by passing in an instance of AlgernonSettings, in which case they will be in effect for this call only, or by setting the parameters individually as a global setting.

Parameters:
path - a String containing a path.
See Also:
ErrorSet, AlgernonSettings

tell

public LispValue tell(String path,
                      AlgernonKB kb)
See the single-parameter version for documentation.


tell

public LispValue tell(String path,
                      ErrorSet errors)
See the single-parameter version for documentation.


tell

public LispValue tell(String path,
                      AlgernonKB kb,
                      ErrorSet errors)
See the single-parameter version for documentation.


tell

public LispValue tell(String path,
                      AlgernonKBSet kbSet)
See the single-parameter version for documentation.


tell

public LispValue tell(String path,
                      AlgernonKBSet kbSet,
                      String comment)
See the single-parameter version for documentation.


tell

public LispValue tell(String path,
                      AlgernonKBSet kbSet,
                      String comment,
                      ErrorSet errorSet)
See the single-parameter version for documentation.


tell

public LispValue tell(String pathString,
                      AlgernonKBSet kbSet,
                      String comment,
                      ErrorSet errorSet,
                      AlgernonSettings processSettings)
See the single-parameter version for documentation.


tell

public LispValue tell(Path path,
                      AlgernonKBSet kbSet,
                      String comment,
                      ErrorSet errorSet,
                      AlgernonSettings processSettings)
See the single-parameter version for documentation.


printErrors

public static void printErrors(ErrorSet errs)
Prints an ErrorSet to System.err.


printWarnings

public static void printWarnings(ErrorSet errs)
Only prints warnings to System.err.


printErrorsToString

public static String printErrorsToString(ErrorSet errs)
Prints an ErrorSet to a String.


printWarningsToString

public static String printWarningsToString(ErrorSet errs)
Prints only the warnings in an ErrorSet to a String.


addKBSet

public void addKBSet(AlgernonKBSet kbset)
Adds a new AlgernonKBSet to this instantiation of Algernon. The AlgernonKBSet must have a unique name.


clearQueryHistory

public void clearQueryHistory()
Clears the entire list of historical queries. Do this when deleting all rules, or when you want to redo queries.


addRule

public void addRule(Rule rule,
                    AlgernonFrame associatedFrame)
Adds a rule to the system. The rule should contain the class or slot it is associated with, and its type (forward or backward chaining).


addClosure

public void addClosure(Closure closure)
Adds a closure to the system. A closure is a rule plus bindings.


clearAllRules

public void clearAllRules()
Removes all known rules and rule continuations.


getLisp

public Jatha getLisp()

compile

public LispValue compile(Path path,
                         AlgernonKBSet kbSet,
                         int compileMode,
                         ErrorSet errorSet)
                  throws AlgernonException
Compiles a path (which may be a rule declaration, a query, an assert or part of a rule) and returns the AAM opcodes for the path. Send in two Collections if you want to collect warnings and errors. Otherwise, they will be thrown.

Throws:
AlgernonException

compile

public LispValue compile(String path,
                         AlgernonKBSet kbSet,
                         int compileMode,
                         ErrorSet errorSet)
                  throws AlgernonException
Compiles a path (which may be a rule declaration, a query, an assert or part of a rule) and returns the AAM opcodes for the path. Send in two Collections if you want to collect warnings and errors. Otherwise, they will be thrown.

Throws:
AlgernonException

compileRule

public Collection compileRule(Rule rule,
                              AlgernonKBSet kbSet)
Compiles the given rule and returns the compiled code.


createRule

public void createRule(Rule rule,
                       AlgernonKBSet kbSet,
                       AlgernonFrame frame)
Send in a rule instance. This function adds it to the RuleManager, compiles it, and creates and compiles any necessary rule continuations.


evaluateExpression

public Object evaluateExpression(String language,
                                 LispValue expression)
Evaluates a method in the given language. The language should be a string like "JAVA". The only languages supported right now are JAVA, LISP and SHELL.

See Also:
ExternalLanguageEvaluator

evaluateExpressionAsBoolean

public Boolean evaluateExpressionAsBoolean(String language,
                                           LispValue expression)
Evaluates a method in the given language. The language should be a string like "JAVA". The only language supported right now is JAVA.


addEvaluator

public void addEvaluator(String language,
                         ExternalLanguageEvaluator evaluator)
Adds a new language evaluator. Algernon has built-in evaluators for Java, LISP and UNIX Shell expressions. If you add one for any of those languages, it will override the existing one. The language name is used in the Algernon :TEST, :EVAL and :BIND expressions as a keyword. For example:
   addEvaluator("PERL", new myPerlEvaluator());
 enables the form:
   (:TEST (:PERL (3 > (length ?sequence))))
 
All language strings are converted to upper case.

Parameters:
language - a String such as "JAVA" or "LISP".
evaluator - the language evaluator for that language.

getEvaluator

public ExternalLanguageEvaluator getEvaluator(String language)
Returns a language evaluator for the given language. The language should be a string such as "JAVA".


load

public void load(String filename)
          throws IOException
Loads and executes a file of Algernon forms. Each form must be:
   (tell )
  or
   (ask  )
 
TraceLevel is Tracer.NORMAL by default.

Throws:
IOException

load

public void load(String filename,
                 int traceLevel)
          throws IOException
Loads and executes a file of Algernon forms. Each form must be:
   (tell )
  or
   (ask  )
 
TraceLevel is Tracer.NORMAL by default.

Throws:
IOException

ruleNameIterator

public Iterator ruleNameIterator()
An iterator that iterates over all Rules in the system. Objects returned are rules.


process

public LispValue process(LispValue code,
                         AlgernonKBSet kbset,
                         ErrorSet errors)
                  throws AlgernonException
Executes a set of AAM opcodes. Returns the final binding list.

Throws:
AlgernonException

addKB

public void addKB(AlgernonKB kb)
Adds a new KB to the list of KBs that Algernon accesses.


removeKB

public void removeKB(AlgernonKB kb)
Removes a KB from the default KB Set.


removeKB

public void removeKB(AlgernonKB kb,
                     AlgernonKBSet kbset)
Removes a KB from the given KB Set.


getKBSet

public AlgernonKBSet getKBSet()
Returns the set of KBs with the default AlgernonKBSet name.


getKBSet

public AlgernonKBSet getKBSet(String name)
Returns the set of KBs with the given name.


getFrame

public static LispValue getFrame(LispValue value)
Returns the frame of the clause, which is the second element of the list.


getFrame

public static LispValue getFrame(Clause value)
Returns the frame of the clause.


getRelation

public static LispValue getRelation(LispValue value)
Returns the relation of the clause, which is the first element of the list.


getRelation

public static LispValue getRelation(Clause value)
Returns the relation of the clause.


getRule

public Rule getRule(String str)
Returns the rule with the given name.


getRules

public Collection getRules(String str)
Returns all rules with the given string in their names. If the string to match is null, returns all rules.


getActivatedRules

public Collection getActivatedRules(AlgernonFrame frame,
                                    int direction,
                                    int type)
Returns a list of activatable rules that match the given criteria. Forwards to the Rule Manager.

See Also:
RuleManager

getTraceLevel

public int getTraceLevel()
Returns the relation of the clause.


getArgs

public static LispValue getArgs(LispValue value)
Returns the relation of the clause, which is the first element of the list.


getArguments

public static LispValue getArguments(Clause value)
Returns the relation of the clause.


getBinding

public Object getBinding(String variable,
                         BindingList bindings)
Returns the binding of a variable from a result. Pass in a BindingList (which is an element of a Result). This returns either a Java Object or a KB object (typically a Protege Instance). If you want to receive an AlgernonFrame instead of a KB-specific object, use getAlgernonBinding instead of this method.

To get the bindings from a result, do this:

   LispValue result = algy.ask("...");

   if (result == null)
     ...
   else
   {
     for (Iterator iterator = ((Result)result).iterator(); iterator.hasNext();)
     {
       BindingList bl = (BindingList) iterator.next();
       Object value = algy.getBinding("?x", bl);

       // Object will either be a Java Object (Integer, Float, etc.)
       // or a KB object (typically a Protege Instance).
       // If you want Algernon objects, use getAlgernonBinding().
     }
   }
 

Parameters:
variable - a string containing the variable name (case-sensitive)
bindings - a BindingList obtained by iterating through a result.
See Also:
getAlgernonBinding(java.lang.String, org.algernon.datatype.BindingList)

getAlgernonBinding

public Object getAlgernonBinding(String variable,
                                 BindingList bindings)
Returns the binding of a variable from a result. Pass in a BindingList (which is an element of a Result). This returns either a Java Object or a an AlgernonFrame object. If you want to receive a KB-specific object (such as a Protege Instance), use getBinding instead of this method.

To get the bindings from a result, do this:

   LispValue result = algy.ask("...");

   if (result == null)
     ...
   else
   {
     for (Iterator iterator = ((Result)result).iterator(); iterator.hasNext();)
     {
       BindingList bl = (BindingList) iterator.next();
       Object value = algy.getAlgernonBinding("?x", bl);

       // Object will either be a Java Object (Integer, Float, etc.)
       // or an instance of AlgernonFrame.  If you want KB-specific
       // objects (e.g. a Protege Instance), use getBinding().
     }
   }
 

Parameters:
variable - a string containing the variable name (case-sensitive)
bindings - a BindingList obtained by iterating through a result.
See Also:
getBinding(java.lang.String, org.algernon.datatype.BindingList)

getCompiler

public AlgernonCompiler getCompiler()
Returns the current compiler used by Algernon.


getImportantSupersetSlotName

public String getImportantSupersetSlotName()
Returns the name of the slot that represents the relation between a class and a superclass for inheritance purposes. This class forwards the call to AlgernonKBSet.


isVariable

public static boolean isVariable(LispValue value)
Returns true if the given value represents a variable in the system. A variable is a symbol starting with a question mark.


getExecutionOrder

public int getExecutionOrder()
Returns the value of ExecutionOrder.


setExecutionOrder

public void setExecutionOrder(int newExecutionOrder)
Sets the value of ExecutionOrder.


addToActionQueue

public void addToActionQueue(Processor processor,
                             LispValue item)
                      throws AlgernonDataException
Adds an activation to the action queue. Order is controlled by the ExecutionOrder, which is DEPTH_FIRST, BREADTH_FIRST or user-defined.

Throws:
AlgernonDataException

createRelation

public AlgernonRelation createRelation(AlgernonKB kb,
                                       String slotName,
                                       Set domains,
                                       Set ranges,
                                       Integer minCardinality,
                                       Integer maxCardinality,
                                       Object defaultValue,
                                       AlgernonRelation inverseRelation)
                                throws AlgernonDataException
Creates a new relation in the given KB. Forwards the call to the AlgernonKB class.

Throws:
AlgernonDataException

queueInsertionFunction

public LispValue queueInsertionFunction(LispValue item,
                                        LispValue values)
Default queue insertion function.


insertDepthFirst

public LispValue insertDepthFirst(LispValue item,
                                  LispValue queue)
This is the default actionQueueInsertionFunction.


instantiate

public LispValue instantiate(LispValue term,
                             LispValue env)

isInstance

public boolean isInstance(LispValue clause,
                          LispValue pattern)
Determines whether clause is an instance of pattern, returning true or false. This function is similar to BindingSet.unify except that variables in clause are treated as constants.


isInstance

public boolean isInstance(Clause clause,
                          Clause pattern)
Determines whether clause is an instance of pattern, returning true or false. This function is similar to BindingSet.unify except that variables in clause are treated as constants.


isInstance

public boolean isInstance(Clause clause,
                          Clause pattern,
                          BindingList clauseBindings,
                          BindingList patternBindings)
Determines whether clause is an instance of pattern, returning true or false. This function is similar to BindingSet.unify except that variables in clause are treated as constants.


isInstance

public boolean isInstance(LispValue clause,
                          LispValue pattern,
                          BindingList clauseBindings,
                          BindingList patternBindings)
Determines whether clause is an instance of pattern, returning true or false. This function is similar to BindingSet.unify except that variables in clause are treated as constants.


kbSetRenamed

public void kbSetRenamed(AlgernonKBSet kbset,
                         String oldname,
                         String newname)
Call this when a AlgernonKBSet is renamed.


printResultToString

public String printResultToString(String operation,
                                  LispValue results,
                                  LispValue varsToPrint)
Prints the results of Algernon execution in a nice format to a string


printResultToString

public String printResultToString(String operation,
                                  LispValue results)
Prints the results of Algernon execution in a nice format to a string


printResult

public void printResult(PrintWriter s,
                        String operation,
                        LispValue results,
                        LispValue varsToPrint)
Prints the results of Algernon execution in a nice format.


printResults

public void printResults(PrintWriter s,
                         Result result,
                         LispValue varsToPrint)
Prints the actual binding lists from the execution.


printBindingList

public void printBindingList(int index,
                             int indent,
                             PrintWriter s,
                             BindingList bindings,
                             LispValue varsToPrint)
Prints a binding list to the given stream. Each binding list is numbered and indented appropriately. The caller must guarantee that varsToPrint is not NIL.


printBindingList

public void printBindingList(PrintWriter s,
                             BindingList bindings)
This method has the original Algernon output format. Prints a binding list to the given stream.


setTraceLevel

public void setTraceLevel(int newTraceLevel)

relationIsFull

public boolean relationIsFull(AlgernonFrame frame,
                              AlgernonRelation relation)
                       throws AlgernonException
Returns true if the frame/relation combination is full - that is, the number of values stored in the slot is equal to the slot's maximum cardinality.

Throws:
AlgernonException

isGroundClause

public static boolean isGroundClause(Clause clause)
Returns true if the given clause is ground (contains no variables).


isGroundPath

public static boolean isGroundPath(Path path)
Returns true if the given clause is ground (contains no variables).


isFrame

public boolean isFrame(String frameName)
                throws AlgernonDataException
Returns true if the given string is the name of a frame in any KB.

Throws:
AlgernonDataException

isFrame

public boolean isFrame(String frameName,
                       AlgernonKB kb)
                throws AlgernonDataException
Returns true if the given string is the name of a frame in the given KB.

Throws:
AlgernonDataException

isFrame

public boolean isFrame(String frameName,
                       AlgernonKBSet kbset)
                throws AlgernonDataException
Returns true if the given string is the name of a frame in any KB in the given AlgernonKBSet.

Throws:
AlgernonDataException

isNameRelation

public boolean isNameRelation(String relationName)
                       throws AlgernonDataException
Returns true if the given string is the name of the relation/attribute linking a frame to its name in any KB.

Throws:
AlgernonDataException

isNameRelation

public boolean isNameRelation(String relationName,
                              AlgernonKB kb)
Returns true if the given string is the name of the relation/slot linking a frame to its name in the given KB.


isNameRelation

public boolean isNameRelation(String relationName,
                              AlgernonKBSet kbset)
                       throws AlgernonDataException
Returns true if the given string is the name of the relation/slot linking a frame to its name in any KB in the given AlgernonKBSet.

Throws:
AlgernonDataException

isInstanceToClassRelation

public boolean isInstanceToClassRelation(String relationName)
Returns true if the given string is the name of the relation/slot linking an instance to its class in any KB of the default AlgernonKBSet.


isInstanceToClassRelation

public boolean isInstanceToClassRelation(String relationName,
                                         AlgernonKBSet kbset)
Returns true if the given string is the name of the relation/slot linking an instance to its class in any KB of the given AlgernonKBSet.


isInstanceToClassRelation

public boolean isInstanceToClassRelation(String relationName,
                                         AlgernonKB kb)
Returns true if the given string is the name of the relation/slot linking an instance to its class in the given KB.


isClassToInstanceRelation

public boolean isClassToInstanceRelation(String relationName)
Returns true if the given string is the name of the relation/slot linking an instance to its class in any KB of the default AlgernonKBSet.


isClassToInstanceRelation

public boolean isClassToInstanceRelation(String relationName,
                                         AlgernonKBSet kbset)
Returns true if the given string is the name of the relation/slot linking an instance to its class in any KB of the given AlgernonKBSet.


isClassToInstanceRelation

public boolean isClassToInstanceRelation(String relationName,
                                         AlgernonKB kb)
Returns true if the given string is the name of the relation/slot linking an instance to its class in the given KB.


isDisjointRelation

public boolean isDisjointRelation(String relationName)
Returns true if the given string is the name of a relation specifying that two classes are disjoint


isDisjointRelation

public boolean isDisjointRelation(String relationName,
                                  AlgernonKB kb)
Returns true if the given string is the name of a relation specifying that two classes are disjoint in the given KB.


isDisjointRelation

public boolean isDisjointRelation(String relationName,
                                  AlgernonKBSet kbset)
Returns true if the given string is the name of a relation specifying that two classes are disjoint in any KB of the given AlgernonKBSet.


isSubclassToSuperclassRelation

public boolean isSubclassToSuperclassRelation(String relationName)
Returns true if the given string is the name of the relation/attribute linking a class to its superclass in any KB.


isSubclassToSuperclassRelation

public boolean isSubclassToSuperclassRelation(String relationName,
                                              AlgernonKB kb)
Returns true if the given string is the name of the relation/slot linking a frame to its name in the given KB.


isSubclassToSuperclassRelation

public boolean isSubclassToSuperclassRelation(String relationName,
                                              AlgernonKBSet kbset)
Returns true if the given string is the name of the relation/slot linking a frame to its name in any KB in the given AlgernonKBSet.


isRelation

public boolean isRelation(String frameName)
                   throws AlgernonDataException
Returns true if the given string is the name of a relation in any KB.

Throws:
AlgernonDataException

isRelation

public boolean isRelation(String relationName,
                          AlgernonKB kb)
                   throws AlgernonDataException
Returns true if the given string is the name of a relation in the given KB.

Throws:
AlgernonDataException

isRelation

public boolean isRelation(String relationName,
                          AlgernonKBSet kbset)
                   throws AlgernonDataException
Returns true if the given string is the name of a frame in any KB in the given AlgernonKBSet.

Throws:
AlgernonDataException

generalIsa

public boolean generalIsa(String child,
                          String parent)
                   throws AlgernonDataException
Returns true if the first argument is an instance or subclass of the second argument. Both arguments must be frames. This version checks all known KBs in all known KBSets.

Throws:
AlgernonDataException

generalIsa

public boolean generalIsa(String child,
                          String parent,
                          AlgernonKB kb)
                   throws AlgernonDataException
Returns true if the first argument is an instance or subclass of the second argument. Both arguments must be frames. This version checks the given KB.

Throws:
AlgernonDataException

generalIsa

public boolean generalIsa(String child,
                          String parent,
                          AlgernonKBSet kbset)
                   throws AlgernonDataException
Returns true if the first argument is an instance or subclass of the second argument. Both arguments must be frames. This version checks all KBs in the given AlgernonKBSet.

Throws:
AlgernonDataException

generalNotIsa

public boolean generalNotIsa(String child,
                             String parent)
                      throws AlgernonDataException
Returns true if the first argument is not an instance or subclass of the second argument. Both arguments must be frames. This version checks all known KBs in all known KBSets.

Throws:
AlgernonDataException

generalNotIsa

public boolean generalNotIsa(String child,
                             String parent,
                             AlgernonKB kb)
Returns true if the first argument is not an instance or subclass of the second argument. Both arguments must be frames. This version checks the given KB.


generalNotIsa

public boolean generalNotIsa(String child,
                             String parent,
                             AlgernonKBSet kbset)
                      throws AlgernonDataException
Returns true if the first argument is not an instance or subclass of the second argument. Both arguments must be frames. This version checks all KBs in the given AlgernonKBSet.

Throws:
AlgernonDataException

lookupClass

public AlgernonClass lookupClass(String name)
                          throws AlgernonDataException
Returns a class with the given name if it can find one in any of the KBs in the default KBSet. Otherwise returns null.

Throws:
AlgernonDataException

lookupClass

public AlgernonClass lookupClass(String name,
                                 AlgernonKB kb)
                          throws AlgernonDataException
Returns a class with the given name if it can find one in the given KB. Otherwise returns null.

Throws:
AlgernonDataException

lookupClass

public AlgernonClass lookupClass(String name,
                                 AlgernonKBSet kbset)
                          throws AlgernonDataException
Returns a class with the given name if it can find one in any of the KBs in the given KBSet. Otherwise returns null.

Throws:
AlgernonDataException

lookupFrame

public AlgernonFrame lookupFrame(String name)
                          throws AlgernonDataException
Returns a frame with the given name if it can find one in any of the KBs in the default KBSet. Otherwise returns null.

Throws:
AlgernonDataException

lookupFrame

public AlgernonFrame lookupFrame(String name,
                                 AlgernonKB kb)
                          throws AlgernonDataException
Returns a frame with the given name if it can find one in the given KB. Otherwise returns null.

Throws:
AlgernonDataException

lookupFrame

public AlgernonFrame lookupFrame(String name,
                                 AlgernonKBSet kbset)
                          throws AlgernonDataException
Returns a class with the given name if it can find one in any of the KBs in the given KBSet. Otherwise returns null.

Throws:
AlgernonDataException

lookupRelation

public AlgernonRelation lookupRelation(String name)
                                throws AlgernonDataException
Returns a relation with the given name if it can find one in any of the KBs in the default KBSet. Otherwise returns null.

Throws:
AlgernonDataException

lookupRelation

public AlgernonRelation lookupRelation(String name,
                                       AlgernonKB kb)
                                throws AlgernonDataException
Returns a relation with the given name if it can find one in the given KB. Otherwise returns null.

Throws:
AlgernonDataException

lookupRelation

public AlgernonRelation lookupRelation(String name,
                                       AlgernonKBSet kbset)
                                throws AlgernonDataException
Returns a relation with the given name if it can find one in any of the KBs in the given KBSet. Otherwise returns null.

Throws:
AlgernonDataException

lookupDirectInstances

public Collection lookupDirectInstances(AlgernonClass theClass)
Returns a list of all direct instances of the given class. The argument must be an instance of AlgernonClass.

Parameters:
theClass - the class whose instances are returned.
Returns:
a list of all instances, direct and indirect.

lookupInstances

public Collection lookupInstances(AlgernonClass theClass)
Returns a list of all instances, whether indirect or direct, of the given class. The argument must be an instance of AlgernonClass.

Parameters:
theClass - the class whose instances are returned.
Returns:
a list of all instances, direct and indirect.

lookupSubclasses

public Collection lookupSubclasses(AlgernonClass theClass)
Returns a list of all subclasses, whether indirect or direct, of the given class. The argument must be an instance of AlgernonClass.

Parameters:
theClass - the class whose instances are returned.
Returns:
a list of all instances, direct and indirect.

lookupDirectSubclasses

public Collection lookupDirectSubclasses(AlgernonClass theClass)
Returns a list of all subclasses, whether indirect or direct, of the given class. The argument must be an instance of AlgernonClass.

Parameters:
theClass - the class whose instances are returned.
Returns:
a list of all instances, direct and indirect.

trace

public void trace(int traceLevel,
                  String message)
Prints a trace message, dependent on the current level of tracing.

See Also:
Tracer

trace

public void trace(int traceLevel,
                  String message,
                  boolean newLine)
Prints a trace message, dependent on the current level of tracing.

See Also:
Tracer

askYorN

public boolean askYorN(String query)
                throws AlgernonRuntimeException
Asks the user to confirm whether the query is true. User must enter Y, N, T or F. Uses System.in and System.out as the input and output streams.

Parameters:
query - The query to ask of the user. Printed directly to the console.
Throws:
AlgernonRuntimeException

askForValue

public LispValue askForValue(String query,
                             LispValue valueType,
                             Collection possibleValues)
                      throws AlgernonRuntimeException
Requires the user to enter an item from the set of possibleValues.

Parameters:
query - The query printed for the user.
valueType - The type of value requested: BOOLEAN_TYPE, INTEGER_TYPE, etc.
possibleValues - a set of legal answers.
Returns:
the value selected.
Throws:
AlgernonRuntimeException
See Also:
BOOLEAN_TYPE, FLOAT_TYPE, CLASS_TYPE, INTEGER_TYPE, SYMBOL_TYPE, STRING_TYPE

main

public static void main(String[] args)
The command line arguments are files to be processed.
   -s  silent - does not print any messages.
 

Parameters:
args - files to be sent to Algernon.load().
See Also:
load(java.lang.String)

loadRulesFromKB

public void loadRulesFromKB(Collection rules)
                     throws IOException,
                            AlgernonDataException
Loads rules that have been stored in a KB. Pass in a collection of AlgernonInstances, each of which defines a rule. An acceptable instance has the following required relations: The following slots are optional: The rule can have other slots, but those will be ignored.

Parameters:
rules - A Collection of AlgernonInstances that contain the required slots.
Throws:
IOException
AlgernonDataException

serverIsRunning

public boolean serverIsRunning()
Returns true if the server is running.


getServerPortNumber

public int getServerPortNumber()
Returns the port number the server is running on.


startServer

public String startServer(int portNumber)
Starts the Algernon server. If it can't start, returns a string containing an error message. Check serverIsRunning() after calling this to verify that it worked.


shutdownServer

public void shutdownServer()
Shut down the Algernon server.


addCommand

public void addCommand(LispValue name,
                       Command command)
Adds a new command to Algernon. Used by the compiler.


getCommand

public Command getCommand(LispValue name)
Retrieves a command by its name (a LispSymbol).


getProcessor

public Processor getProcessor()

getOpcodeSet

public OpcodeSet getOpcodeSet()

getRegisters

public RegisterSet getRegisters()

getValueTypes

public LispValue getValueTypes()

toValueType

public LispValue toValueType(Object typeName)
Converts an object like ":INTEGER" to an official type.

Parameters:
typeName -
Returns:
the Algernon type associated with the symbol.

getValueType

public LispValue getValueType(Object o)
Get the data type of the Java object passed in; we expect this to be Integer, Float, Boolean, Cls, or Instance


createKB

public AlgernonKB createKB(Clause clause)
                    throws AlgernonDataException
Called by the USE-KB opcode to create a new KB. The input is the :USE-KB clause. Syntax is:
   (:USE-KB name type arg1 arg2...)
   (:USE-KB :KB-1 Protege "mypath/myKB.pprj")
   (:USE-KB :KB-2 Google  "com.google.soap.search" "google-api-key")
   (:USE-KB :KB-3 Hibernate "your.java.api.interface package" "your.java.api.impl package")
   (:USE-KB :KB-4 JavaAPI   "your.java.api.interface package" "your.java.api.impl package")
 

Parameters:
clause -
Throws:
AlgernonDataException

setCompilerDebug

public void setCompilerDebug(boolean state)
Use this to turn compiler debug mode on and off. Use (:TRACE :DEBUG-COMPILER-ON) and (:TRACE :DEBUG-COMPILER-OFF) at the user level.


Algernon Software