CLIPS

Release:0.3.3
Date:Oct 14, 2019

Namespaces

To keep the design simple and modular, the CLIPS functions are organised into namespaces.

A namespace is a way to group a set of APIs which belong to the same domain into a category.

The User shall not worry about the namespaces themselves as all the APIs are accessible through the Environment class.

Submodules

clips.environment module

class clips.environment.Environment

Bases: object

The environment class encapsulates an independent CLIPS engine with its own data structures.

batch_star(path)

Evaluate the commands contained in the specific path.

The Python equivalent of the CLIPS batch* command.

build(construct)

Build a single construct in CLIPS.

The Python equivalent of the CLIPS build command.

clear()

Clear the CLIPS environment.

The Python equivalent of the CLIPS clear command.

define_function(function, name=None)

Define the Python function within the CLIPS environment.

If a name is given, it will be the function name within CLIPS. Otherwise, the name of the Python function will be used.

The Python function will be accessible within CLIPS via its name as if it was defined via the deffunction construct.

eval(construct)

Evaluate an expression returning its value.

The Python equivalent of the CLIPS eval command.

load(path)

Load a set of constructs into the CLIPS data base.

Constructs can be in text or binary format.

The Python equivalent of the CLIPS load command.

reset()

Reset the CLIPS environment.

The Python equivalent of the CLIPS reset command.

save(path, binary=False)

Save a set of constructs into the CLIPS data base.

If binary is True, the constructs will be saved in binary format.

The Python equivalent of the CLIPS load command.

clips.facts module

This module contains the definition of:

  • Facts namespace class
  • ImpliedFact class
  • TemplateFact class
  • Template class
  • TemplateSlot class
class clips.facts.Fact(env, fact)

Bases: object

CLIPS Fact base class.

asserted

True if the fact has been asserted within CLIPS.

assertit()

Assert the fact within the CLIPS environment.

index

The fact index.

retract()

Retract the fact from the CLIPS environment.

template

The associated Template.

class clips.facts.Facts(env)

Bases: object

Facts and Templates namespace class.

Note

All the Facts methods are accessible through the Environment class.

assert_string(string)

Assert a fact as string.

facts()

Iterate over the asserted Facts.

find_template(name)

Find the Template by its name.

load_facts(facts)

Load a set of facts into the CLIPS data base.

The C equivalent of the CLIPS load-facts command.

Facts can be loaded from a string or from a text file.

save_facts(path, mode=<SaveMode.LOCAL_SAVE: 0>)

Save the facts in the system to the specified file.

The Python equivalent of the CLIPS save-facts command.

templates()

Iterate over the defined Templates.

class clips.facts.ImpliedFact(env, fact)

Bases: clips.facts.Fact

An Implied Fact or Ordered Fact represents its data as a list of elements similarly as for a Multifield.

append(value)

Append an element to the fact.

assertit()

Assert the fact within CLIPS.

extend(values)

Append multiple elements to the fact.

class clips.facts.Template(env, tpl)

Bases: object

A Fact Template is a formal representation of the fact data structure.

In CLIPS, Templates are defined via the (deftemplate) statement.

Templates allow to create new facts to be asserted within the CLIPS environment.

Implied facts are associated to implied templates. Implied templates have a limited set of features. For example, they do not support slots.

deletable

True if the Template can be deleted.

implied

True if the Template is implied.

module

The module in which the Template is defined.

Python equivalent of the CLIPS deftemplate-module command.

name

Template name.

new_fact()

Create a new Fact from this template.

slots()

Iterate over the Slots of the Template.

undefine()

Undefine the Template.

Python equivalent of the CLIPS undeftemplate command.

The object becomes unusable after this method has been called.

watch

Whether or not the Template is being watched.

class clips.facts.TemplateFact(env, fact)

Bases: clips.facts.Fact

An Template Fact or Unordered Fact is a dictionary where each slot name is a key.

update(sequence=None, **mapping)

Add multiple elements to the fact.

class clips.facts.TemplateSlot(env, tpl, name)

Bases: object

Template Facts organize the information within Slots.

Slots might restrict the type or amount of data they store.

allowed_values

A tuple containing the allowed values for this Slot.

The Python equivalent of the CLIPS slot-allowed-values function.

cardinality

A tuple containing the cardinality for this Slot.

The Python equivalent of the CLIPS deftemplate-slot-cardinality function.

default_type

The default value type for this Slot.

The Python equivalent of the CLIPS deftemplate-slot-defaultp function.

default_value

The default value for this Slot.

The Python equivalent of the CLIPS deftemplate-slot-default-value function.

multifield

True if the slot is a multifield slot.

name

The slot name.

range

A tuple containing the numeric range for this Slot.

The Python equivalent of the CLIPS deftemplate-slot-range function.

types

A tuple containing the value types for this Slot.

The Python equivalent of the CLIPS deftemplate-slot-types function.

clips.facts.fact_pp_string(env, fact)
clips.facts.new_fact(env, fact)
clips.facts.slot_value(env, fact, slot)
clips.facts.slot_values(env, fact, tpl)
clips.facts.template_pp_string(env, template)

clips.agenda module

This module contains the definition of:

  • Agenda class
  • Rule class
  • Activation class
class clips.agenda.Activation(env, act)

Bases: object

When all the constraints of a Rule are satisfied, the Rule becomes active.

Activations are organized within the CLIPS Agenda.

delete()

Remove the activation from the agenda.

name

Activation Rule name.

salience

Activation salience value.

class clips.agenda.Agenda(env)

Bases: object

In CLIPS, when all the conditions to activate a rule are met, The Rule action is placed on the Agenda.

The CLIPS Agenda is responsible of sorting the Rule Activations according to their salience and the conflict resolution strategy.

Note

All the Agenda methods are accessible through the Environment class.

activations()

Iterate over the Activations in the Agenda.

agenda_changed

True if any rule activation changes have occurred.

clear()

Deletes all activations in the agenda.

clear_focus()

Remove all modules from the focus stack.

The Python equivalent of the CLIPS clear-focus-stack command.

find_rule(rule)

Find a Rule by name.

focus

The module associated with the current focus.

The Python equivalent of the CLIPS get-focus function.

refresh(module=None)

Recompute the salience values of the Activations on the Agenda and then reorder the agenda.

The Python equivalent of the CLIPS refresh-agenda command.

If no Module is specified, the current one is used.

reorder(module=None)

Reorder the Activations in the Agenda.

If no Module is specified, the current one is used.

To be called after changing the conflict resolution strategy.

rules()

Iterate over the defined Rules.

run(limit=None)

Runs the activations in the agenda.

If limit is not None, the first activations up to limit will be run.

Returns the number of activation which were run.

salience_evaluation

The salience evaluation behavior.

The Python equivalent of the CLIPS get-salience-evaluation command.

strategy

The current conflict resolution strategy.

The Python equivalent of the CLIPS get-strategy function.

class clips.agenda.Rule(env, rule)

Bases: object

A CLIPS rule.

In CLIPS, Rules are defined via the (defrule) statement.

add_breakpoint()

Add a breakpoint for the Rule.

The Python equivalent of the CLIPS add-break command.

deletable

True if the Rule can be deleted.

matches(verbosity=<Verbosity.TERSE: 2>)

Shows partial matches and activations.

Returns a tuple containing the combined sum of the matches for each pattern, the combined sum of partial matches and the number of activations.

The verbosity parameter controls how much to output:

  • Verbosity.VERBOSE: detailed matches are printed to stdout
  • Verbosity.SUCCINT: a brief description is printed to stdout
  • Verbosity.TERSE: (default) nothing is printed to stdout
module

The module in which the Rule is defined.

Python equivalent of the CLIPS defrule-module command.

name

Rule name.

refresh()

Refresh the Rule.

The Python equivalent of the CLIPS refresh command.

remove_breakpoint()

Remove a breakpoint for the Rule.

The Python equivalent of the CLIPS remove-break command.

undefine()

Undefine the Rule.

Python equivalent of the CLIPS undefrule command.

The object becomes unusable after this method has been called.

watch_activations

Whether or not the Rule Activations are being watched.

watch_firings

Whether or not the Rule firings are being watched.

clips.agenda.activation_pp_string(env, activation)

clips.classes module

This module contains the definition of:

  • Classes namespace class
  • Class class
  • Instance class
  • ClassSlot class
  • MessageHandler class
class clips.classes.Class(env, cls)

Bases: object

A Class is a template for creating instances of objects.

In CLIPS, Classes are defined via the (defclass) statement.

Classes allow to create new instances to be added within the CLIPS environment.

abstract

True if the class is abstract.

deletable

True if the Class can be deleted.

find_message_handler(handler_name, handler_type='primary')

Returns the MessageHandler given its name and type for this class.

instances()

Iterate over the instances of the class.

message_handlers()

Iterate over the message handlers of the class.

module

The module in which the Class is defined.

Python equivalent of the CLIPS defglobal-module command.

name

Class name.

new_instance(name)

Create a new raw instance from this Class.

No slot overrides or class default initializations are performed for the instance.

This function bypasses message-passing.

reactive

True if the class is reactive.

slots(inherited=False)

Iterate over the Slots of the class.

subclass(klass)

True if the Class is a subclass of the given one.

subclasses(inherited=False)

Iterate over the subclasses of the class.

This function is the Python equivalent of the CLIPS class-subclasses command.

superclass(klass)

True if the Class is a superclass of the given one.

superclasses(inherited=False)

Iterate over the superclasses of the class.

This function is the Python equivalent of the CLIPS class-superclasses command.

undefine()

Undefine the Class.

Python equivalent of the CLIPS undefclass command.

The object becomes unusable after this method has been called.

watch_instances

Whether or not the Class Instances are being watched.

watch_slots

Whether or not the Class Slots are being watched.

class clips.classes.ClassSlot(env, cls, name)

Bases: object

A Class Instances organize the information within Slots.

Slots might restrict the type or amount of data they store.

accessible

True if the Slot is directly accessible.

allowed_classes()

Iterate over the allowed classes for this slot.

The Python equivalent of the CLIPS slot-allowed-classes function.

allowed_values

A tuple containing the allowed values for this Slot.

The Python equivalent of the CLIPS slot-allowed-values function.

cardinality

A tuple containing the cardinality for this Slot.

The Python equivalent of the CLIPS slot-cardinality function.

default_value

The default value for this Slot.

The Python equivalent of the CLIPS slot-default-value function.

facets

A tuple containing the facets for this Slot.

The Python equivalent of the CLIPS slot-facets function.

initializable

True if the Slot is initializable.

name

The Slot name.

public

True if the Slot is public.

range

A tuple containing the numeric range for this Slot.

The Python equivalent of the CLIPS slot-range function.

sources

A tuple containing the names of the Class sources for this Slot.

The Python equivalent of the CLIPS slot-sources function.

types

A tuple containing the value types for this Slot.

The Python equivalent of the CLIPS slot-types function.

writable

True if the Slot is writable.

class clips.classes.Classes(env)

Bases: object

Classes and Instances namespace class.

Note

All the Classes methods are accessible through the Environment class.

classes()

Iterate over the defined Classes.

default_mode

Return the current class defaults mode.

The Python equivalent of the CLIPS get-class-defaults-mode command.

find_class(name)

Find the Class by its name.

find_instance(name, module=None)

Find the Instance by its name.

instances()

Iterate over the defined Instancees.

instances_changed

True if any instance has changed.

load_instances(instances)

Load a set of instances into the CLIPS data base.

The C equivalent of the CLIPS load-instances command.

Instances can be loaded from a string, from a file or from a binary file.

make_instance(command)

Create and initialize an instance of a user-defined class.

command must be a string in the form:

(<instance-name> of <class-name> <slot-override>*) <slot-override> :== (<slot-name> <constant>*)

Python equivalent of the CLIPS make-instance command.

restore_instances(instances)

Restore a set of instances into the CLIPS data base.

The Python equivalent of the CLIPS restore-instances command.

Instances can be passed as a set of strings or as a file.

save_instances(path, binary=False, mode=<SaveMode.LOCAL_SAVE: 0>)

Save the instances in the system to the specified file.

If binary is True, the instances will be saved in binary format.

The Python equivalent of the CLIPS save-instances command.

class clips.classes.Instance(env, ist)

Bases: object

A Class Instance is an occurrence of an object.

Instances represent the data as dictionaries where each slot is a key.

delete()

Delete the instance.

instance_class

Instance class.

name

Instance name.

send(message, arguments=None)

Send a message to the Instance.

Message arguments must be provided as a string.

unmake()

This method is equivalent to delete except that it uses message-passing instead of directly deleting the instance.

class clips.classes.MessageHandler(env, cls, idx)

Bases: object

MessageHandlers are the CLIPS equivalent of instance methods in Python.

deletable

True if the MessageHandler can be deleted.

name

MessageHandler name.

type

MessageHandler type.

undefine()

Undefine the MessageHandler.

Python equivalent of the CLIPS undefmessage-handler command.

The object becomes unusable after this method has been called.

watch

True if the MessageHandler is being watched.

clips.classes.classes(env, names)
clips.classes.instance_pp_string(env, ist)

clips.functions module

This module contains the definition of:

  • Functions namespace class
  • Function class
  • Generic class
  • Method class
class clips.functions.Function(env, fnc)

Bases: object

A CLIPS user defined function.

In CLIPS, Functions are defined via the (deffunction) statement.

deletable

True if the Function can be deleted.

module

The module in which the Function is defined.

Python equivalent of the CLIPS deffunction-module command.

name

Function name.

undefine()

Undefine the Function.

Python equivalent of the CLIPS undeffunction command.

The object becomes unusable after this method has been called.

watch

Whether or not the Function is being watched.

class clips.functions.Functions(env)

Bases: object

Functions, Generics and Methods namespace class.

Note

All the Functions methods are accessible through the Environment class.

find_function(name)

Find the Function by its name.

find_generic(name)

Find the Generic by its name.

functions()

Iterates over the defined Globals.

generics()

Iterates over the defined Generics.

class clips.functions.Generic(env, gnc)

Bases: object

A CLIPS generic function.

In CLIPS, Functions are defined via the (defgeneric) statement.

deletable
methods()
module
name
undefine()

Undefine the Generic.

Python equivalent of the CLIPS undefgeneric command.

The object becomes unusable after this method has been called.

watch
class clips.functions.Method(env, gnc, idx)

Bases: object

Methods implement the generic logic according to the input parameter types.

deletable
description
restrictions
undefine()

Undefine the Method.

Python equivalent of the CLIPS undefmethod command.

The object becomes unusable after this method has been called.

watch

clips.modules module

This module contains the definition of:

  • Modules namespace class
  • Module class
  • Global class
class clips.modules.Global(env, glb)

Bases: object

A CLIPS global variable.

In CLIPS, Globals are defined via the (defglobal) statement.

deletable

True if the Global can be deleted.

module

The module in which the Global is defined.

Python equivalent of the CLIPS defglobal-module command.

name

Global name.

undefine()

Undefine the Global.

Python equivalent of the CLIPS undefglobal command.

The object becomes unusable after this method has been called.

value

Global value.

watch

Whether or not the Global is being watched.

class clips.modules.Module(env, mdl)

Bases: object

Modules are namespaces restricting the CLIPS constructs scope.

name

Global name.

class clips.modules.Modules(env)

Bases: object

Globals and Modules namespace class.

Note

All the Modules methods are accessible through the Environment class.

current_module

The current module.

The Python equivalent of the CLIPS get-current-module function.

find_global(name)

Find the Global by its name.

find_module(name)

Find the Module by its name.

globals()

Iterates over the defined Globals.

globals_changed

True if any Global has changed.

modules()

Iterates over the defined Modules.

clips.router module

class clips.router.LoggingRouter

Bases: clips.router.Router

Python logging Router.

A helper Router to get Python standard logging facilities integrated with CLIPS.

LOGGERS = {'stdout': <function info>, 'wclips': <function info>, 'wdialog': <function info>, 'wdisplay': <function info>, 'werror': <function error>, 'wtrace': <function debug>, 'wwarning': <function warning>}
log_message(name)
print(name, message)

If the query method returned True for the given logical name, this method will be called with the forwarded message.

query(name)

This method should return True if the provided logical name is handled by the Router.

class clips.router.Router(name, priority)

Bases: object

activate()

Activate the Router.

add_to_environment(environment)

Add the router to the given environment.

deactivate()

Deactivate the Router.

delete()

Delete the Router.

exit(_exitcode)
getc(_name)
name

The Router name.

print(_name, _message)

If the query method returned True for the given logical name, this method will be called with the forwarded message.

query(_name)

This method should return True if the provided logical name is handled by the Router.

ungetc(_name, _char)

clips.common module

class clips.common.CLIPSType

Bases: enum.IntEnum

An enumeration.

EXTERNAL_ADDRESS = 5
FACT_ADDRESS = 6
FLOAT = 0
INSTANCE_ADDRESS = 7
INSTANCE_NAME = 8
INTEGER = 1
MULTIFIELD = 4
STRING = 3
SYMBOL = 2
class clips.common.ClassDefaultMode

Bases: enum.IntEnum

An enumeration.

CONSERVATION_MODE = 1
CONVENIENCE_MODE = 0
class clips.common.EnvData(user_functions, routers)

Bases: tuple

routers

Alias for field number 1

user_functions

Alias for field number 0

class clips.common.InstanceName

Bases: clips.common.Symbol

Instance names are CLIPS SYMBOLS.

class clips.common.SalienceEvaluation

Bases: enum.IntEnum

An enumeration.

EVERY_CYCLE = 2
WHEN_ACTIVATED = 1
WHEN_DEFINED = 0
class clips.common.SaveMode

Bases: enum.IntEnum

An enumeration.

LOCAL_SAVE = 0
VISIBLE_SAVE = 1
class clips.common.Strategy

Bases: enum.IntEnum

An enumeration.

BREADTH = 1
COMPLEXITY = 4
DEPTH = 0
LEX = 2
MEA = 3
RANDOM = 6
SIMPLICITY = 5
class clips.common.Symbol

Bases: str

Python equivalent of a CLIPS SYMBOL.

class clips.common.TemplateSlotDefaultType

Bases: enum.IntEnum

An enumeration.

DYNAMIC_DEFAULT = 2
NO_DEFAULT = 0
STATIC_DEFAULT = 1
class clips.common.Verbosity

Bases: enum.IntEnum

An enumeration.

SUCCINT = 1
TERSE = 2
VERBOSE = 0

clips.error module

exception clips.error.CLIPSError(env)

Bases: RuntimeError

An error occurred within the CLIPS Environment.

class clips.error.ErrorRouter(*parameters)

Bases: clips.router.Router

last_message
print(name, message)

If the query method returned True for the given logical name, this method will be called with the forwarded message.

query(name)

This method should return True if the provided logical name is handled by the Router.

Module contents

exception clips.CLIPSError(env)

Bases: RuntimeError

An error occurred within the CLIPS Environment.

class clips.Environment

Bases: object

The environment class encapsulates an independent CLIPS engine with its own data structures.

batch_star(path)

Evaluate the commands contained in the specific path.

The Python equivalent of the CLIPS batch* command.

build(construct)

Build a single construct in CLIPS.

The Python equivalent of the CLIPS build command.

clear()

Clear the CLIPS environment.

The Python equivalent of the CLIPS clear command.

define_function(function, name=None)

Define the Python function within the CLIPS environment.

If a name is given, it will be the function name within CLIPS. Otherwise, the name of the Python function will be used.

The Python function will be accessible within CLIPS via its name as if it was defined via the deffunction construct.

eval(construct)

Evaluate an expression returning its value.

The Python equivalent of the CLIPS eval command.

load(path)

Load a set of constructs into the CLIPS data base.

Constructs can be in text or binary format.

The Python equivalent of the CLIPS load command.

reset()

Reset the CLIPS environment.

The Python equivalent of the CLIPS reset command.

save(path, binary=False)

Save a set of constructs into the CLIPS data base.

If binary is True, the constructs will be saved in binary format.

The Python equivalent of the CLIPS load command.

class clips.Router(name, priority)

Bases: object

activate()

Activate the Router.

add_to_environment(environment)

Add the router to the given environment.

deactivate()

Deactivate the Router.

delete()

Delete the Router.

exit(_exitcode)
getc(_name)
name

The Router name.

print(_name, _message)

If the query method returned True for the given logical name, this method will be called with the forwarded message.

query(_name)

This method should return True if the provided logical name is handled by the Router.

ungetc(_name, _char)
class clips.LoggingRouter

Bases: clips.router.Router

Python logging Router.

A helper Router to get Python standard logging facilities integrated with CLIPS.

LOGGERS = {'stdout': <function info>, 'wclips': <function info>, 'wdialog': <function info>, 'wdisplay': <function info>, 'werror': <function error>, 'wtrace': <function debug>, 'wwarning': <function warning>}
log_message(name)
print(name, message)

If the query method returned True for the given logical name, this method will be called with the forwarded message.

query(name)

This method should return True if the provided logical name is handled by the Router.

class clips.ImpliedFact(env, fact)

Bases: clips.facts.Fact

An Implied Fact or Ordered Fact represents its data as a list of elements similarly as for a Multifield.

append(value)

Append an element to the fact.

assertit()

Assert the fact within CLIPS.

extend(values)

Append multiple elements to the fact.

class clips.TemplateFact(env, fact)

Bases: clips.facts.Fact

An Template Fact or Unordered Fact is a dictionary where each slot name is a key.

update(sequence=None, **mapping)

Add multiple elements to the fact.

class clips.Strategy

Bases: enum.IntEnum

An enumeration.

BREADTH = 1
COMPLEXITY = 4
DEPTH = 0
LEX = 2
MEA = 3
RANDOM = 6
SIMPLICITY = 5
class clips.SalienceEvaluation

Bases: enum.IntEnum

An enumeration.

EVERY_CYCLE = 2
WHEN_ACTIVATED = 1
WHEN_DEFINED = 0
class clips.Verbosity

Bases: enum.IntEnum

An enumeration.

SUCCINT = 1
TERSE = 2
VERBOSE = 0
class clips.ClassDefaultMode

Bases: enum.IntEnum

An enumeration.

CONSERVATION_MODE = 1
CONVENIENCE_MODE = 0
class clips.TemplateSlotDefaultType

Bases: enum.IntEnum

An enumeration.

DYNAMIC_DEFAULT = 2
NO_DEFAULT = 0
STATIC_DEFAULT = 1
class clips.Symbol

Bases: str

Python equivalent of a CLIPS SYMBOL.

class clips.InstanceName

Bases: clips.common.Symbol

Instance names are CLIPS SYMBOLS.

class clips.SaveMode

Bases: enum.IntEnum

An enumeration.

LOCAL_SAVE = 0
VISIBLE_SAVE = 1