CLIPS - PHP Extension Documentation

How to Install (Linux)

To quickly install a PHP extension as a loadable module:

  1. Extract the archive and cd to the new clips-x.x.x directory
  2. Run "./configure"
  3. In the Makefile, ensure that EXTENSION_DIR points to your current PHP extension directory
  4. (optional) Make additional changes to the Makefile to fit your system configuration
  5. Run "make"
  6. Run "make install"
  7. Edit the extensions section of your php.ini file and add "extension=clips.so"
  8. Restart the web server
  9. Verify that the extension has been loaded by checking for it in phpinfo()

If the extension fails to load: 1) Go to the PHP extension directory, make sure "clips.so" resides there and the correct permissions are set. 2) Stop and start apache again.

How to Install (Windows)

Copy the php_clips.dll file into your PHP\ext directory. Edit your php.ini file, go to the extensions section, and add "extension=php_clips.dll". Restart the webserver.

Licensing

The CLIPS PHP extension is licensed under the PHP License version 3.0

Compatibility

The extension has been tested under RedHat 9, Fedora and Windows XP with PHP versions 4.3.8 and 5.0.2, and using both Apache 1.3 and Apache 2.0. There are still some issues with stability under Apache 2, this may be due to Apache 2's multithreaded mode, because the original CLIPS library was not designed to run in a mutlithreaded environment.

Example Usage

	clips_clear();
	clips_set_strategy(LEX_STRATEGY);
	clips_load("rules.clp");
	clips_reset();
	
	clips_assert(array("hunter", "brian", "duck"));
	
	clips_run();
	
	$facts = clips_get_fact_list();
	
	print_r($facts);
	

Functions

Environment

Debugging

Deftemplate

Fact

Deffacts

Defrule

Agenda

Defglobal

Deffunction

Defgeneric

Defclass

Instance

Defmodule

ENVIRONMENT FUNCTIONS

back to top

void   clips_init ( )

Initializes a CLIPS environment.

bool   clips_function_call ( string function_name [, string arguments] )

Allows CLIPS system functions, deffunctions and generic functions to be called from PHP.

bool   clips_batch ( string file )

Evaluate a series of commands stored in the specified file. Equivalent CLIPS function: batch*.

bool   clips_load ( string file )

Load a set of constructs into CLIPS from a file. Equivalent CLIPS function: load.

bool   clips_bload ( string file )

Load a set of constructs into CLIPS from a binary CLIPS file. Equivalent CLIPS function: bload.

bool   clips_bsave ( string file )

Save a binary image of constructs currently in the CLIPS environment. Equivalent CLIPS function: bsave.

bool   clips_build ( string construct_string )

Allows a construct to be defined. Equivalent CLIPS function: build.

bool   clips_eval ( string expression )

Allows an expression to be evaluated. Equivalent CLIPS function: eval.

bool   clips_save ( string file )

Saves a set of constructs to the specified file. Equivalent CLIPS function: save.

bool   clips_get_auto_float_dividend ( )

Get the current value of the auto-float dividend behavior. Equivalent CLIPS function: get-auto-float-dividend.

bool   clips_get_dynamic_constraint_checking ( )

Get the current value of the dynamic constraint checking behavior. Equivalent CLIPS function: get-dynamic-constraint-checking.

bool   clips_get_static_constraint_checking ( )

Get the current value of the static constraint checking behavior. Equivalent CLIPS function: get-static-constraint-checking.

bool   clips_get_sequence_operator_recognition ( )

Get the current value of the sequence operator recognition behavior. Equivalent CLIPS function: get-sequence-operator-recognition.

void   clips_set_auto_float_dividend ( bool value )

Set the auto-float dividend behavior. Equivalent CLIPS function: set-auto-float-dividend.

void   clips_set_dynamic_constraint_checking ( bool value )

Set the dynamic constraint checking behavior. Equivalent CLIPS function: set-dynamic-constraint-checking.

void   clips_set_sequence_operator_recognition ( bool value )

Set the sequence operator recognition behavior. Equivalent CLIPS function: set-sequence-operator-recognition.

void   clips_set_static_constraint_checking ( bool value )

Set the static constraint checking behavior. Equivalent CLIPS function: set-static-constraint-checking.

void   clips_reset ( )

Reset the CLIPS environment. Equivalent CLIPS function: reset.

void   clips_clear ( )

Clear the CLIPS environment. Equivalent CLIPS function: clear.

int   clips_run ( [int run_limit] )

Execute activations in the agenda, returns the number of rules that were fired. Equivalent CLIPS function: run.

DEBUGGING FUNCTIONS

back to top

bool   clips_dribble_active ( )

Determines if the storing of dribble information is active.

bool   clips_dribble_off ( )

Turns off the storing of dribble information, returns FALSE if an error occurred..

bool   clips_dribble_on ( string file )

Turns on the storing of dribble information in the specified file.

bool   clips_get_watch_item ( string item )

Tell whether or not the given item is being watched..

bool   clips_watch ( string item )

Allows the tracing facilities of CLIPS to be activated..

bool   clips_unwatch ( string item )

Allows the tracing facilities of CLIPS to be deactivated..

DEFTEMPLATE FUNCTIONS

back to top

string   clips_deftemplate_module ( )

Get the name of the module in which a deftemplate is defined.

array   clips_get_deftemplate_list ( [string module_name] )

Returns a list of all deftemplates.

bool   clips_is_deftemplate_deletable ( string deftemplate )

Indicates whether or not a particular deftemplate can be deleted.

bool   clips_undeftemplate ( string deftemplate )

Removes a deftemplate from CLIPS. Equivalent CLIPS function: undeftemplate.

FACT FUNCTIONS

back to top

array   clips_get_fact_list ( [string module] )

Retrieve the fact list.

int   clips_assert ( mixed values [, string deftemplate [, string module_name]] )

Asserts a fact into the CLIPS fact-list. Returns the fact-index number of the new fact, or FALSE on failure. 'values' defines the fact and can be represented by a string or an array. If a deftemplate is specified, 'values' must be an array, and must have array keys that correspond to the deftemplate slots.. Equivalent CLIPS function: assert.

bool   clips_get_fact_duplication ( )

Get the current value of the fact duplication behavior. Equivalent CLIPS function: get-fact-duplication.

bool   clips_get_fact_list_changed ( )

Determines if any changes to the fact list have occurred.

bool   clips_load_facts ( string file )

Loads a set of facts from a file into the CLIPS environment. Equivalent CLIPS function: load-facts.

bool   clips_load_facts_from_string ( string facts )

Loads a set of facts from a string into the CLIPS environment. Equivalent CLIPS function: load-facts.

bool   clips_save_facts ( string file [, int save_scope] )

Loads a set of facts from a string into the CLIPS environment, save_scope flags are: LOCAL_SAVE, or VISIBLE_SAVE. Equivalent CLIPS function: save-facts.

void   clips_set_fact_duplication ( bool value )

Set the fact duplication behavior. Equivalent CLIPS function: set-fact-duplication.

void   clips_set_fact_list_changed ( bool value )

Set the internal boolean flag which indicates when changes to the fact list have occurred.

DEFFACTS FUNCTIONS

back to top

string   clips_deffacts_module ( string deffacts_name )

Get the name of the module in which a particular deffacts is defined. Equivalent CLIPS function: deffacts-module.

array   clips_get_deffacts_list ( string module_name )

Retrieve an array of the names of the deffacts in the CLIPS environment. Limits by module if a module name is given. Equivalent CLIPS function: get-deffacts-list.

bool   clips_is_deffacts_deletable ( string deffacts_name )

Tell whether or not a particular deffacts can be deleted.

bool   clips_undeffacts ( string deffacts_name )

Remove a deffacts construct from the CLIPS environment. Equivalent CLIPS function: undeffacts.

DEFRULE FUNCTIONS

back to top

bool   clips_refresh ( string defrule_name )

Refreshes a rule. Equivalent CLIPS function: refresh.

bool   clips_remove_break ( string defrule_name )

Removes a breakpoint for the specified defrule. Equivalent CLIPS function: remove-break.

void   clips_set_break ( string defrule_name )

Adds a breakpoint for the specified defrule. Equivalent CLIPS function: set-break.

bool   clips_defrule_has_breakpoint ( string defrule_name )

Tell whether or not a particular defrule has a breakpoint set.

string   clips_defrule_module ( string defrule_name )

Get the name of the module in which a defrule is defined. Equivalent CLIPS function: defrule-module.

array   clips_get_defrule_list ( [string module_name] )

Retrieve an array of the names of the defrules in the CLIPS environment. Limits by module if a module name is given. Equivalent CLIPS function: get-defrule-list.

bool   clips_get_incremental_reset ( )

Get the current value of the incremental reset behavior. Equivalent CLIPS function: get-incremental-reset.

void   clips_set_incremental_reset ( bool value )

Set the incremental reset behavior. Equivalent CLIPS function: set-incremental-reset.

bool   clips_is_defrule_deletable ( string defrule )

Tell whether or not a defrule can be deleted.

bool   clips_undefrule ( string defrule )

Removes a defrule construct from the CLIPS environment. Equivalent CLIPS function: undefrule.

AGENDA FUNCTIONS

back to top

void   clips_clear_focus_stack ( )

Remove all modules from the focus stack. Equivalent CLIPS function: clear-focus-stack.

bool   clips_get_agenda_changed ( )

Tell whether or not there have been any changes to the agenda of rule activations.

void   clips_set_agenda_changed ( bool value )

Set the internal boolean flag indicating that the agenda of rule activations has been changed.

string   clips_get_focus ( )

Get the name of the module associated with the current focus. Equivalent CLIPS function: get-focus.

array   clips_get_focus_stack ( )

Get an array of module names in the focus stack. Equivalent CLIPS function: get-focus-stack.

int   clips_get_salience_evaluation ( )

Get the current value of the salience evaluation behavior. Equivalent CLIPS function: get-salience-evaluation.

void   clips_set_salience_evaluation ( int flag )

Set the current value of the salience evaluation behavior (WHEN_DEFINED, WHEN_ACTIVATED or EVERY_CYCLE). Equivalent CLIPS function: set-salience-evaluation.

void   clips_set_strategy ( int flag )

Set the conflict resolution strategy (DEPTH_STRATEGY, BREADTH_STRATEGY, LEX_STRATEGY, MEA_STRATEGY, COMPLEXITY_STRATEGY, SIMPLICITY_STRATEGY, RANDOM_STRATEGY). Equivalent CLIPS function: set-strategy.

int   clips_get_strategy ( )

Get the current conflict resolution strategy. Equivalent CLIPS function: get-strategy.

string   clips_pop_focus ( )

Remove the current focus from the focus stack and return the module name associated with that focus. Equivalent CLIPS function: pop-focus.

bool   clips_focus ( string module_name )

Sets the current focus to the specified module. Equivalent CLIPS function: focus.

void   clips_refresh_agenda ( string module_name )

Recomputes the salience values for all activations on the agenda and then reorders the agenda. Equivalent CLIPS function: refresh-agenda.

void   clips_reorder_agenda ( string module_name )

Reorders the agenda based on the current conflict resolution strategy and current activation saliences.

DEFGLOBAL FUNCTIONS

back to top

string   clips_defglobal_module ( string defglobal_name )

Get the name of the module in which a defglobal is defined. Equivalent CLIPS function: defglobal-module.

mixed   clips_get_defglobal_value ( string defglobal_name )

Retrieve the value of a defglobal.

bool   clips_get_globals_changed ( )

Tell whether or not any changes to global variables have occurred.

bool   clips_get_reset_globals ( )

Get the current value of the reset global variables behavior. Equivalent CLIPS function: get-reset-globals.

string   clips_is_defglobal_deletable ( string defglobal_name )

Tell whether or not a particular defglobal can be deleted.

void   clips_set_defglobal_value ( string defglobal_name, mixed value )

Set the value of a defglobal.

bool   clips_undefglobal ( string defglobal_name )

Remove a defglobal from the CLIPS environment. Equivalent CLIPS function: undefglobal.

DEFFUNCTION FUNCTIONS

back to top

string   clips_deffunction_module ( string deffunction_name )

Get the name of the module in which a deffunction is defined. Equivalent CLIPS function: deffunction-module.

array   clips_get_deffunction_list ( string module )

Retrieve a list of the current deffunctions in the CLIPS environment. Equivalent CLIPS function: get-deffunction-list.

bool   clips_is_deffunction_deletable ( string deffunction_name )

Tell whether or not a particular deffunction can be deleted.

bool   clips_undeffunction ( string deffunction_name )

Remove a deffunction from the CLIPS environment. Equivalent CLIPS function: undeffunction.

DEFGENERIC FUNCTIONS

back to top

string   clips_defgeneric_module ( string defgeneric_name )

Get the name of the module in which a defgeneric is defined. Equivalent CLIPS function: defgeneric-module.

array   clips_get_defgeneric_list ( [string module_name] )

Retrieve a list of the current defgenerics in the CLIPS environment. Equivalent CLIPS function: get-defgeneric-list.

bool   clips_is_defgeneric_deletable ( string defgeneric_name )

Tell whether or not a particular defgeneric can be deleted.

bool   clips_undefgeneric ( string defgeneric_name )

Remove a defgeneric from the CLIPS environment. Equivalent CLIPS function: undefgeneric.

DEFCLASS FUNCTIONS

back to top

bool   clips_class_abstract ( string class_name )

Tell whether or not a class is abstract. Equivalent CLIPS function: class-abstractp.

bool   clips_class_reactive ( string class_name )

Tell whether or not a class is reactive. Equivalent CLIPS function: class-reactivep.

array   clips_class_slots ( string class_name [, bool inherit] )

Groups the names of the slots of a class into an array. Equivalent CLIPS function: class-slots.

array   clips_class_subclasses ( string class_name [, bool inherit] )

Groups the names of subclasses of a class into an array. Equivalent CLIPS function: class-subclasses.

array   clips_class_superclasses ( string class_name [, bool inherit] )

Groups the names of parent classes of a class into an array. Equivalent CLIPS function: class-superclasses.

string   clips_defclass_module ( string class_name )

Get the name of the module in which a defclass is defined. Equivalent CLIPS function: defclass-module.

int   clips_get_class_defaults_mode ( )

Get the current class defaults mode. Equivalent CLIPS function: get-class-defaults-mode.

void   clips_set_class_defaults_mode ( int mode )

Set the current class defaults mode (CONVENIENCE_MODE or CONSERVATION_MODE). Equivalent CLIPS function: set-class-defaults-mode.

array   clips_get_defclass_list ( [string module_name] )

Retrieve a list of the current defclasss in the CLIPS environment. Equivalent CLIPS function: get-defclass-list.

bool   clips_is_defclass_deletable ( string class_name )

Tell whether or not a particular class and all its subclasses can be deleted.

bool   clips_subclass ( string class1, string class2 )

Returns TRUE if the first defclass is a subclass of the second defclass, FALSE otherwise.

bool   clips_superclass ( string class1, string class2 )

Returns TRUE if the first defclass is a parent to the second defclass, FALSE otherwise.

bool   clips_undefclass ( string class_name )

Remove a class and all its subclasses from the CLIPS environment. Equivalent CLIPS function: undefclass.

INSTANCE FUNCTIONS

back to top

bool   clips_get_instances_changed ( )

Determine whether or not any changes to instances of user-defined instances have occurred.

void   clips_set_instances_changed ( bool value )

Set the internal boolean flag which indicates when changes to instances of user-defined classes have occurred.

array   clips_get_instance_list ( string class_name [, bool include_subclasses] )

Retrieves a list of instances in the CLIPS environment of the given defclass.

bool   clips_create_instance ( array values, string defclass, string name [, string module] )

Create a new instance with the specified name of the specified class. 'values' defines the instance and must be represented by an array with keys that correspond to the defclass slots.

bool   clips_make_instance ( string make_command [, string module] )

Create and initialize an instance of a class from a string.

DEFMODULE FUNCTIONS

back to top

array   clips_get_defmodule_list ( )

Retrieve a list of defmodules in the CLIPS environemnt. Equivalent CLIPS function: get-defmodule-list.

void   clips_set_current_module ( string module_name )

Set the current module. Equivalent CLIPS function: set-current-module.