Algernon in Java Commands

Command list for Algernon v3.2.0 and higher.

Quick Links

Alphabetical list of Algernon Commands.

Command Arguments Description
:ADD-CLASS ((?var superclass) clause...) Creates a subclass of superclass and asserts each clause. Variables introduced in the clauses section are not visible outside of the :ADD-CLASS macro.
:ADD-FACET (name) Adds a facet to the KB. This command is not yet implemented. Scheduled to be implemented in version 3.4.
:ADD-INSTANCE ((?var class) relations...) Creates an instance of superclass and asserts each clause. Variables introduced in the clauses section are not visible outside of the :ADD-CLASS macro.
:ADD-RULE (class rule1 rule2 ...) Adds rules that will fire if a subclass or instance of class is created or modified.
:ADD-RELATION (name (from-class to-class)) Adds a new relation to the KB.
:ADD-RELATION-RULE (relation rule1 rule2 ...) Not yet implemented. Scheduled for version 3.4. Adds rules that will fire if the given slot is modified on any frame.
:ALL-PATHS (path1 path2...) Succeeds if all of the paths succeed.
:ANY (clause) Evaluates the clause and randomly selects one binding produced by it.
:ASK clause or String Asks the user to confirm whether the clause is true, or asks the user to respond Y/N to a question.
:ASSUME Not yet implemented. Not scheduled for implementation.
:BIND (?var eval-expression) Evaluates the expression and binds the result to the variable.
:BOUNDP ?var Succeeds if the given variable is currently bound.
:BRANCH (?var eval-expression) Like :BIND, except that it binds the variable once for each value in the returned list.
:CHILD (parent child) If parent and child are bound and if child is a child (subclass or instance) of parent, it succeeds. Otherwise, it binds the child variable for each child of parent.
:CLASS (instance class) If instance and class are bound and if the instance is an instance of class (direct or indirect), it succeeds. Otherwise, it binds the class variable for each class of instanceclass, up through the KB root.
:CLEAR-RELATION (frame relation) Removes all values from the relation of frame.
:COUNT (?count ?var clause) Evaluates clause. Binds ?count to the number of bindings produced for the variable ?var.
:COUNT-PATHS (?count path) Evaluates the path and binds ?count to the number of successful paths.
:DATE (?date) or (?date ?time) Binds the given variable(s) to the current date and time. If one variable is given, returns both date and time in one string. If two variables are given, returns date and time as separate strings. The format of each string contains no spaces and is suitable for a file name.
:DELETE (clause) Deletes the given clause from the KB.
:DELETE-CLASS (class) Deletes the given class from the KB.
:DELETE-FACET (facet) Deletes the given facet from the KB.
:DELETE-FRAME (frame) Deletes the given frame from the KB.
:DELETE-INSTANCE (instance) Deletes the given instance from the KB.
:DELETE-RELATION (relation) Deletes the given relation from the KB.
:DIRECT-CLASS (instance class) Confirms that a direct instance-class relationship exists, or retrieves all classes of an instance.
:DIRECT-INSTANCE (class instance) Confirms that a direct class-instance relationship exists, or retrieves all instances of a class.
:DIRECT-SUBCLASS (superclass subclass Confirms that a direct superclass-subclass relationship exists, or retrieves all subclasses of a class.
:DIRECT-SUPERCLASS (subclass superclass) Confirms that a direct subclass-superclass relationship exists, or retrieves all superclasses of a class.
:EVAL (language (expression)) Executes a call out to an external language. Only Java, LISP or the OS are supported at this time. This call always succeeds. Examples:
  (:EVAL (:JAVA (lab.ChemicalRetrieval.getResults ?a ?b ?c)))
  (:EVAL (:LISP (print (+ 3 ?x))))
  (:EVAL (:SHELL "ls -l"))
:FAIL clause Evaluates clause, and succeeds if the clause fails. Synonym of :UNP (unprovable).
  Example: (:FAIL (:CHILD ?a ?b))  ;; succeeds if ?b is not a child of ?a
:FIRE clause Fires forward-chaining rules as if the clause were asserted into the KB.
:FOR (?index ?length ?var clause) Evaluates clause. Binds ?length to the number of bindings produced for the variable ?var and ?index successively to a counter that counts from 1 to ?length.
:FORC-CLASS This command is currently not working ((?var superclass) clause...) FIND or CREATE CLASS. Tries to find a class that is a subclass of superclass and that satisfies the given clauses. If it can't, it creates the class and asserts the clauses.
:FORC-INSTANCE This command is currently not working ((?var class) clause...) FIND or CREATE INSTANCE. Tries to find an instance of class that satisfies the given clauses. If it can't, it creates the instance and asserts the clauses.
:INSTANCE (class instance) Either confirms a class-instance relationship (direct or indirect) or retrieves all instances of a class.
:IS-CLASS (class) Succeeds if the given object is a class in a KB.
:IS-FACET (facet) Succeeds if the given object is a facet in a KB.
:IS-FRAME (frame) Succeeds if the given object is a frame in a KB.
:IS-INSTANCE (instance) Succeeds if the given object is an instance in a KB.
:IS-RELATION (relation) Succeeds if the given object is a relation in a KB.
:LEAF-CLASS (class leaf) Confirms that leaf is a leaf class of class or returns all leaf-classes of class.
:LEAST-COMMON-SUPERCLASS (frame1 frame2 class) Confirms that class is the minimal common superclass of the two frames, or retrieves the minimal common superclass of them.
:LIMIT (number clause) Limits the branching factor from a query retrieval. Evaluates clause and limits the number of returned values to the given value.
:NAME (frame String) If frame is bound, assigns a name to frame. The relation used to store the name is KB-specific.
:NEQ (?x1 ?x2) Succeeds if ?x1 and ?x2 are not the same thing.
:NO-CONTINUATION (clause) Asserts clause but does not create partial rules to continue processing at a later point. This can increase the efficiency of a system if you know that this path can only be satisfied once.
:OR path1 path2... Succeeds if at least one of its sub-paths succeeds.
:PARENT (child parent) Confirms that parent is a parent of child, or retrieves all parents of a child. A parent is always a class.
:PRINT (string-or-var-1 string-or-var-2...) Prints the strings or variables concatenated together without a trailing newline.
:PRINTLN (string-or-var-1 string-or-var-2...) Prints the strings or variables concatenated together with a trailing newline.
:RETRIEVE (clause) Tries to satisfy clause by retrieving from the KB without first executing relevant backward-chaining rules. This can make your program more efficient if you know the value is already in the KB.
:ROOT-CLASS (frame root) Confirms that root is a root class of frame, or retrieves the root class of frame.
:SEARCH (class string variable) String search among all slots of all subclasses and instances of class.
:SEARCH-ALL (string variable) Searches the entire KB for any frame that has a slot value that matches the input.
:SHOW (object) Displays any object or frame.
:SHOW-CODE (rule) Prints the compiled code for a rule to standard output.
:STOP - Immediately halts all Algernon processing. Can be used to stop execution the first time a path succeeds rather than waiting for all paths to be checked.
:SUBCLASS (superclass subclass) Confirms that subclass is a subclass of superclass or else retrieves all subclasses (direct or indirect) of superclass
:SUPERCLASS (subclass superclass) Confirms that superclass is a superclass of subclass or else retrieves all superclasses (direct or indirect) of subclass
:TAXONOMY (class (subclass instance1 instance2) (subclass2 (subclass3)) ...) Creates a tree of subclasses and instances emanating from the starting class (which must already exist in the KB).
:TEMPLATE-RELATION (class relation) Either confirms that the given relation is a template relation of a class or retrieves all template relations of a class.
:TEST (language (expression)) Executes the expression in the specified external language. The expression should return the equivalent of a Boolean for that language. Examples:
   (:TEST (:JAVA (org.algernonx.MyFactory.lengthTest ?sequence)))
   (:TEST (:LISP (> (length ?sequence) 15)))
   (:TEST (:SHELL (sequenceTest.pl ?sequence)))
    
Succeeds if the expression returns true.
:THE-CLASS ((?var class) clause...) Succeeds if there is exactly one class in the KB that satisfies the clauses and is a subclass of class. If there are none, the class is created. If there is one, the variable ?var is bound to it.
:THE-INSTANCE ((?var class) clause...) Succeeds if there is exactly one instance in the KB that satisfies the clauses and is an instance of class. If there are none, the instance is created. If there is one, the variable ?var is bound to it.
:TRACE (level) Sets trace to the given level of verbosity. Possible values, in increasing level of verbosity, are: :SILENT, :NORMAL, :VERBOSE, :DETAIL, :DEBUG. Use :VERBOSE to debug your code, resorting to :DETAIL when necessary. You probably won't find :DEBUG to be helpful. Example:
  (...)  ;; this code works fine
  (:TRACE :VERBOSE)   ;; start debugging
  (...)
  (...)
  (:TRACE :NORMAL)
  
This is a global setting.
:UNBOUNDP (?var) Succeeds if the given variable is currently bound.
:UNP (clause) Unprovable. Synonym for :FAIL. See :FAIL
:USE-KB (name type args...) Adds a KB to the default KB set at runtime.

Categorized list of Algernon Commands

Retrieve or confirm information

:CHILD :CLASS :DIRECT-CLASS
:DIRECT-INSTANCE :DIRECT-SUBCLASS :DIRECT-SUPERCLASS
:FORC-CLASS :FORC-INSTANCE :INSTANCE
:IS-CLASS :IS-FACET :IS-FRAME
:IS-INSTANCE :IS-RELATION :LEAF-CLASS
:LEAST-COMMON-SUPERCLASS :LIMIT :NAME
:PARENT :ROOT-CLASS :SEARCH
:SEARCH-ALL :SUBCLASS :SUPERCLASS
:TEMPLATE-RELATION :THE-CLASS :THE-INSTANCE

Store information

:ADD-CLASS :ADD-FACET :ADD-INSTANCE
:ADD-RULE :ADD-RELATION :ADD-RELATION-RULE
:FORC-CLASS :FORC-INSTANCE :NAME
:TAXONOMY :THE-CLASS :THE-INSTANCE

Delete information

:CLEAR-RELATION :DELETE :DELETE-CLASS
:DELETE-FACET :DELETE-FRAME :DELETE-INSTANCE
:DELETE-RELATION

Control of inference

:ALL-PATHS :ANY :ASSUME
:FAIL :LIMIT :NO-CONTINUATION
:OR :RETRIEVE :STOP
:UNP

Utility

:BIND :BOUNDP :BRANCH
:COUNT :COUNT-PATHS :DATE
:EVAL :FOR :NEQ
:TEST :UNBOUNDP :USE-KB

Input and Output

:ASK :PRINT :PRINTLN
:SHOW

Debugging

:FIRE :TRACE

Back to...

Algernon commands
Algernon Documentation Central
Algernon home page