CLIPS

Release:

1.0.3

Date:

Feb 18, 2024

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: str)

Evaluate the commands contained in the specific path.

Equivalent to the CLIPS (batch*) function.

build(construct: str)

Build a single construct in CLIPS.

Equivalent to the CLIPS (build) function.

clear()

Clear the CLIPS environment.

Equivalent to the CLIPS (clear) function.

eval(expression: str) type

Evaluate an expression returning its value.

Equivalent to the CLIPS (eval) function.

load(path: str, binary: bool = False)

Load a set of constructs into the CLIPS data base.

If constructs were saved in binary format, the binary parameter should be set to True.

Equivalent to the CLIPS (load) function.

reset()

Reset the CLIPS environment.

Equivalent to the CLIPS (reset) function.

save(path: str, binary=False)

Save a set of constructs into the CLIPS data base.

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

Equivalent to the CLIPS (load) function.

clips.facts module

This module contains the definition of:

  • ImpliedFact class

  • TemplateFact class

  • Template class

  • TemplateSlot class

  • DefinedFacts class

  • Facts namespace class

class clips.facts.DefinedFacts(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

Bases: object

The DefinedFacts constitute a set of a priori or initial knowledge specified as a collection of facts of user defined classes.

When the CLIPS environment is reset, every fact specified within a deffacts construct in the CLIPS knowledge base is added to the DefinedFacts list.

property deletable: bool

True if the DefinedFacts can be undefined.

property module: Module

The module in which the DefinedFacts is defined.

Python equivalent of the CLIPS (deffacts-module) command.

property name: str

DefinedFacts name.

undefine()

Undefine the DefinedFacts.

Equivalent to the CLIPS (undeffacts) function.

The object becomes unusable after this method has been called.

class clips.facts.Fact(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, fact: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: object

CLIPS Fact base class.

property exists: bool

True if the fact has been asserted within CLIPS.

Equivalent to the CLIPS (fact-existp) function.

property index: int

The fact index.

retract()

Retract the fact from the CLIPS environment.

property template: 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: str) -> (<class 'clips.facts.ImpliedFact'>, <class 'clips.facts.TemplateFact'>)

Assert a fact as string.

defined_facts() iter

Iterate over the DefinedFacts.

property fact_duplication: bool

Whether or not duplicate facts are allowed.

facts() iter

Iterate over the asserted Facts.

find_defined_facts(name: str) DefinedFacts

Find the DefinedFacts by its name.

find_template(name: str) Template

Find the Template by its name.

load_facts(facts: str)

Load a set of facts into the CLIPS data base.

Equivalent to the CLIPS (load-facts) function.

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

save_facts(path, mode=SaveMode.LOCAL_SAVE)

Save the facts in the system to the specified file.

Equivalent to the CLIPS (save-facts) function.

templates() iter

Iterate over the defined Templates.

class clips.facts.ImpliedFact(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, fact: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: Fact

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

Implied Fact cannot be build or modified. They can be asserted via the Environment.assert_string() method.

class clips.facts.Template(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

Bases: object

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

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

Templates allow to assert new facts within the CLIPS environment.

Implied facts are associated to implied templates. Implied templates have a limited set of features.

assert_fact(**slots) TemplateFact

Assert a new fact with the given slot values.

Only deftemplates that have been explicitly defined can be asserted with this function.

Equivalent to the CLIPS (assert) function.

property deletable: bool

True if the Template can be undefined.

facts() iter

Iterate over the asserted Facts belonging to this Template.

property implied: bool

True if the Template is implied.

property module: Module

The module in which the Template is defined.

Python equivalent of the CLIPS deftemplate-module command.

property name: str

Template name.

property slots: tuple

The slots of the template.

undefine()

Undefine the Template.

Equivalent to the CLIPS (undeftemplate) function.

The object becomes unusable after this method has been called.

property watch: bool

Whether or not the Template is being watched.

class clips.facts.TemplateFact(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, fact: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: Fact

A Template or Unordered Fact represents its data as a dictionary where each slot name is a key.

TemplateFact slot values can be modified. The Fact will be re-evaluated against the rule network once modified.

modify_slots(**slots)

Modify one or more slot values of the Fact.

Fact must be asserted within the CLIPS engine.

Equivalent to the CLIPS (modify) function.

class clips.facts.TemplateSlot(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, tpl: str, name: str)

Bases: object

Template Facts organize the information within Slots.

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

property allowed_values: tuple

A tuple containing the allowed values for this Slot.

Equivalent to the CLIPS (slot-allowed-values) function.

property cardinality: tuple

A tuple containing the cardinality for this Slot.

Equivalent to the CLIPS (deftemplate-slot-cardinality) function.

property default_type: TemplateSlotDefaultType

The default value type for this Slot.

Equivalent to the CLIPS (deftemplate-slot-defaultp) function.

property default_value: type

The default value for this Slot.

Equivalent to the CLIPS (deftemplate-slot-default-value) function.

property multifield: bool

True if the slot is a multifield slot.

property name: str

The slot name.

property range: tuple

A tuple containing the numeric range for this Slot.

Equivalent to the CLIPS (deftemplate-slot-range) function.

property types: tuple

A tuple containing the value types for this Slot.

Equivalent to the CLIPS (deftemplate-slot-types) function.

clips.agenda module

This module contains the definition of:

  • Agenda class

  • Rule class

  • Activation class

class clips.agenda.Activation(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, act: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

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.

property name: str

Activation Rule name.

property salience: int

Activation salience value.

class clips.agenda.Agenda(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: object

In CLIPS, when all the conditions to activate a rule are met, The Rule action is placed within 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() iter

Iterate over the Activations in the Agenda.

property agenda_changed: bool

True if any rule activation changes have occurred.

clear_focus()

Remove all modules from the focus stack.

Equivalent to the CLIPS (clear-focus-stack) function.

delete_activations()

Delete all activations in the agenda.

find_rule(name: str) Rule

Find a Rule by name.

property focus: Module

The module associated with the current focus.

Equivalent to the CLIPS (get-focus) function.

refresh(module: Module = None)

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

Equivalent to the CLIPS (refresh-agenda) function.

If no Module is specified, the agendas of all modules are refreshed.

reorder(module: Module = None)

Reorder the Activations in the Agenda.

If no Module is specified, the agendas of all modules are reordered.

To be called after changing the conflict resolution strategy.

rules() iter

Iterate over the defined Rules.

run(limit: int = None) int

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.

property salience_evaluation: SalienceEvaluation

The salience evaluation behavior.

Equivalent to the CLIPS (get-salience-evaluation) command.

property strategy: Strategy

The current conflict resolution strategy.

Equivalent to the CLIPS (get-strategy) function.

class clips.agenda.Rule(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

Bases: object

A CLIPS rule.

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

add_breakpoint()

Add a breakpoint for the Rule.

Equivalent to the CLIPS (add-break) function.

property deletable: bool

True if the Rule can be deleted.

matches(verbosity: Verbosity = Verbosity.TERSE)

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

property module: Module

The module in which the Rule is defined.

Equivalent to the CLIPS (defrule-module) function.

property name: str

Rule name.

refresh()

Refresh the Rule.

Equivalent to the CLIPS (refresh) function.

remove_breakpoint()

Remove a breakpoint for the Rule.

Equivalent to the CLIPS (remove-break) function.

undefine()

Undefine the Rule.

Equivalent to the CLIPS (undefrule) function.

The object becomes unusable after this method has been called.

property watch_activations: bool

Whether or not the Rule Activations are being watched.

property watch_firings: bool

Whether or not the Rule firings are being watched.

clips.agenda.activation_pp_string(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, ist: <MagicMock name='mock.ffi.CData' id='139990491722512'>) str

clips.classes module

This module contains the definition of:

  • Classes namespace class

  • Class class

  • Instance class

  • ClassSlot class

  • MessageHandler class

  • DefinedInstances class

class clips.classes.Class(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

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.

property abstract: bool

True if the class is abstract.

property deletable: bool

True if the Class can be deleted.

find_message_handler(name: str, handler_type: str = 'primary') MessageHandler

Returns the MessageHandler given its name and type.

instances() iter

Iterate over the instances of the class.

make_instance(instance_name: str = None, **slots) Instance

Make a new Instance from this Class.

Equivalent to the CLIPS (make-instance) function.

message_handlers() iter

Iterate over the message handlers of the class.

property module: Module

The module in which the Class is defined.

Equivalent to the CLIPS (defclass-module) function.

property name: str

Class name.

property reactive: bool

True if the class is reactive.

slots(inherited: bool = False) iter

Iterate over the Slots of the class.

subclass(defclass: Class) bool

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

subclasses(inherited: bool = False) iter

Iterate over the subclasses of the class.

Equivalent to the CLIPS (class-subclasses) function.

superclass(defclass: Class) bool

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

superclasses(inherited=False) iter

Iterate over the superclasses of the class.

Equivalent to the CLIPS class-superclasses command.

undefine()

Undefine the Class.

Equivalent to the CLIPS (undefclass) command.

The object becomes unusable after this method has been called.

property watch_instances: bool

Whether or not the Class Instances are being watched.

property watch_slots: bool

Whether or not the Class Slots are being watched.

class clips.classes.ClassSlot(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, cls: str, name: str)

Bases: object

A Class Instances organize the information within Slots.

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

property accessible: bool

True if the Slot is directly accessible.

allowed_classes() iter

Iterate over the allowed classes for this slot.

Equivalent to the CLIPS (slot-allowed-classes) function.

property allowed_values: tuple

A tuple containing the allowed values for this Slot.

Equivalent to the CLIPS (slot-allowed-values) function.

property cardinality: tuple

A tuple containing the cardinality for this Slot.

Equivalent to the CLIPS slot-cardinality function.

property default_value: type

The default value for this Slot.

Equivalent to the CLIPS (slot-default-value) function.

property facets: tuple

A tuple containing the facets for this Slot.

Equivalent to the CLIPS (slot-facets) function.

property initializable: bool

True if the Slot is initializable.

property name

The Slot name.

property public: bool

True if the Slot is public.

property range: tuple

A tuple containing the numeric range for this Slot.

Equivalent to the CLIPS (slot-range) function.

property sources: tuple

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

Equivalent to the CLIPS (slot-sources) function.

property types: tuple

A tuple containing the value types for this Slot.

Equivalent to the CLIPS (slot-types) function.

property writable: bool

True if the Slot is writable.

class clips.classes.Classes(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: object

Classes and Instances namespace class.

Note

All the Classes methods are accessible through the Environment class.

classes() iter

Iterate over the defined Classes.

property default_mode: ClassDefaultMode

Return the current class defaults mode.

Equivalent to the CLIPS (get-class-defaults-mode) function.

defined_instances() iter

Iterate over the DefinedInstances.

find_class(name: str) Class

Find the Class by the given name.

find_defined_instances(name: str) DefinedInstances

Find the DefinedInstances by its name.

find_instance(name: str, module: Module = None) Instance

Find the Instance by the given name.

instances() iter

Iterate over the defined Instancees.

property instances_changed: bool

True if any instance has changed since last check.

load_instances(instances: str) int

Load a set of instances into the CLIPS data base.

Equivalent to the CLIPS (load-instances) function.

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

restore_instances(instances: str) int

Restore a set of instances into the CLIPS data base.

Equivalent to the CLIPS (restore-instances) function.

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

save_instances(path: str, binary: bool = False, mode: SaveMode = SaveMode.LOCAL_SAVE) int

Save the instances in the system to the specified file.

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

Equivalent to the CLIPS (save-instances) function.

class clips.classes.DefinedInstances(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

Bases: object

The DefinedInstances constitute a set of a priori or initial knowledge specified as a collection of instances of user defined classes.

When the CLIPS environment is reset, every instance specified within a definstances construct in the CLIPS knowledge base is added to the DefinedInstances list.

property deletable: bool

True if the DefinedInstances can be undefined.

property module: Module

The module in which the DefinedInstances is defined.

Python equivalent of the CLIPS (definstances-module) command.

property name: str

The DefinedInstances name.

undefine()

Undefine the DefinedInstances.

Equivalent to the CLIPS (undefinstances) function.

The object becomes unusable after this method has been called.

class clips.classes.Instance(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, ist: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: object

A Class Instance is an occurrence of an object.

A Class Instance represents its data as a dictionary where each slot name is a key.

Class Instance slot values can be modified. The Instance will be re-evaluated against the rule network once modified.

delete()

Directly delete the instance.

property instance_class: Class

Instance class.

modify_slots(**slots)

Modify one or more slot values of the Instance.

Instance must exist within the CLIPS engine.

Equivalent to the CLIPS (modify-instance) function.

property name: str

Instance name.

send(message: str, arguments: str = None) type

Send a message to the Instance.

The output value of the message handler is returned.

Equivalent to the CLIPS (send) function.

unmake()

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

class clips.classes.MessageHandler(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, cls: str, idx: int)

Bases: object

MessageHandlers are the CLIPS equivalent of instance methods in Python.

property deletable: bool

True if the MessageHandler can be deleted.

property name: str

MessageHandler name.

property type: str

MessageHandler type.

undefine()

Undefine the MessageHandler.

Equivalent to the CLIPS (undefmessage-handler) function.

The object becomes unusable after this method has been called.

property watch: bool

True if the MessageHandler is being watched.

clips.classes.classes(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, names: (<class 'list'>, <class 'tuple'>)) iter

clips.functions module

This module contains the definition of:

  • Function class

  • Generic class

  • Method class

  • Functions namespace class

class clips.functions.Function(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

Bases: object

A CLIPS user defined Function.

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

property deletable: bool

True if the Function can be deleted.

property module: Module

The module in which the Function is defined.

Equivalent to the CLIPS (deffunction-module) functions.

property name: str

Function name.

undefine()

Undefine the Function.

Equivalent to the CLIPS (undeffunction) command.

The object becomes unusable after this method has been called.

property watch: bool

Whether or not the Function is being watched.

class clips.functions.Functions(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: object

Functions, Generics and Methods namespace class.

Note

All the Functions methods are accessible through the Environment class.

call(function: str, *arguments) type

Call the CLIPS function with the given arguments.

clear_error_state()

Clear the CLIPS environment error state.

Equivalent to the CLIPS (clear-error) function.

define_function(function: callable, name: str = 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.

property error_state: None | CLIPSError

Get the CLIPS environment error state.

Equivalent to the CLIPS (get-error) function.

find_function(name: str) Function

Find the Function by its name.

find_generic(name: str) Generic

Find the Generic by its name.

functions()

Iterates over the defined Globals.

generics() iter

Iterates over the defined Generics.

class clips.functions.Generic(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

Bases: object

A CLIPS Generic Function.

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

property deletable: bool

True if the Generic can be deleted.

methods() iter

Iterates over the defined Methods.

property module: Module

The module in which the Generic is defined.

Equivalent to the CLIPS (defgeneric-module) generics.

property name: str

Generic name.

undefine()

Undefine the Generic.

Equivalent to the CLIPS (undefgeneric) command.

The object becomes unusable after this method has been called.

property watch: bool

Whether or not the Generic is being watched.

class clips.functions.Method(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, gnc: str, idx: int)

Bases: object

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

property deletable

True if the Template can be undefined.

property description: str
property restrictions: tuple
undefine()

Undefine the Method.

Equivalent to the CLIPS (undefmethod) command.

The object becomes unusable after this method has been called.

property watch: bool

Whether or not the Method is being watched.

clips.modules module

This module contains the definition of:

  • Modules namespace class

  • Module class

  • Global class

class clips.modules.Global(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

Bases: object

A CLIPS global variable.

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

property deletable: bool

True if the Global can be deleted.

property module: Module

The module in which the Global is defined.

Equivalent to the CLIPS (defglobal-module) function.

property name: str

Global name.

undefine()

Undefine the Global.

Equivalent to the CLIPS (undefglobal) function.

The object becomes unusable after this method has been called.

property value: type

Global value.

property watch: bool

Whether or not the Global is being watched.

class clips.modules.Module(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

Bases: object

Modules are namespaces restricting the CLIPS constructs scope.

property name: str

Module name.

class clips.modules.Modules(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: object

Globals and Modules namespace class.

Note

All the Modules methods are accessible through the Environment class.

property current_module: Module

The current module.

Equivalent to the CLIPS (get-current-module) function.

find_global(name: str) Module

Find the Global by its name.

find_module(name: str) Module

Find the Module by its name.

globals() iter

Iterates over the defined Globals.

property globals_changed: bool

True if any Global has changed since last check.

modules() iter

Iterates over the defined Modules.

property reset_globals: bool

True if Globals reset behaviour is enabled.

clips.routers module

This module contains the definition of:

  • Router class

  • LoggingRouter class

  • Routers namespace class

class clips.routers.ErrorRouter

Bases: Router

Router capturing error messages for CLIPSError exceptions.

property last_message: str
query(name: str)

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

write(name: str, message: str)

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

class clips.routers.LoggingRouter

Bases: Router

Python logging Router.

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

It captures CLIPS output and re-directs it to Python logging library.

LOGGERS = {'stderr': <function error>, 'stdout': <function info>, 'stdwrn': <function warning>}
log_message(name: str)
query(name: str) bool

Capture log from CLIPS output routers.

write(name: str, message: str)

If the message is a new-line terminate sentence, log it at according to the mapped level.

Otherwise, append it to the message string.

class clips.routers.Router(name: str, priority: int)

Bases: object

activate()

Activate the Router.

deactivate()

Deactivate the Router.

delete()

Delete the Router.

exit(_exitcode: int)
property name: str

The Router name.

property priority: int

The Router priority.

query(_name: str) bool

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

read(_name: str) int

Callback implementation for the Environment.read_router function.

share_message(name: str, message: str)

Share the captured message with other Routers.

unread(_name: str, _char: int) int

Callback implementation for the Environment.unread_router function.

write(_name: str, _message: str)

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

class clips.routers.Routers(env)

Bases: object

Routers namespace class.

Note

All the Routers methods are accessible through the Environment class.

add_router(router: Router)

Add the given Router to the Environment.

read_router(router_name: str) int

Query the Router by the given name calling its read callback.

routers() iter

The User defined routers installed within the Environment.

unread_router(router_name: str, characters: int) int

Query the Router by the given name calling its unread callback.

write_router(router_name: str, *args)

Send the given arguments to the given Router for writing.

clips.common module

exception clips.common.CLIPSError(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, message: str = None, code: int = None)

Bases: RuntimeError

An error occurred within the CLIPS Environment.

class clips.common.CLIPSType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

EXTERNAL_ADDRESS = 5
FACT_ADDRESS = 6
FLOAT = 0
INSTANCE_ADDRESS = 7
INSTANCE_NAME = 8
INTEGER = 1
MULTIFIELD = 4
STRING = 3
SYMBOL = 2
VOID = 9
class clips.common.ClassDefaultMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

CONSERVATION_MODE = 1
CONVENIENCE_MODE = 0
class clips.common.EnvBuilders(fact, instance, function, string, multifield)

Bases: tuple

fact

Alias for field number 0

function

Alias for field number 2

instance

Alias for field number 1

multifield

Alias for field number 4

string

Alias for field number 3

class clips.common.EnvData(builders, modifiers, routers, user_functions)

Bases: tuple

builders

Alias for field number 0

modifiers

Alias for field number 1

routers

Alias for field number 2

user_functions

Alias for field number 3

class clips.common.EnvModifiers(fact, instance)

Bases: tuple

fact

Alias for field number 0

instance

Alias for field number 1

class clips.common.PutSlotError(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

PSE_ALLOWED_CLASSES_ERROR = 1
PSE_ALLOWED_VALUES_ERROR = 1
PSE_CARDINALITY_ERROR = 1
PSE_INVALID_TARGET_ERROR = 1
PSE_NO_ERROR = 1
PSE_NULL_POINTER_ERROR = 1
PSE_RANGE_ERROR = 1
PSE_SLOT_NOT_FOUND_ERROR = 1
PSE_TYPE_ERROR = 1
class clips.common.SalienceEvaluation(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

EVERY_CYCLE = 1
WHEN_ACTIVATED = 1
WHEN_DEFINED = 1
class clips.common.SaveMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

LOCAL_SAVE = 1
VISIBLE_SAVE = 1
class clips.common.Strategy(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

BREADTH = 1
COMPLEXITY = 4
DEPTH = 0
LEX = 2
MEA = 3
RANDOM = 6
SIMPLICITY = 5
class clips.common.TemplateSlotDefaultType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

DYNAMIC_DEFAULT = 1
NO_DEFAULT = 1
STATIC_DEFAULT = 1
class clips.common.UserFunctions(functions, external_addresses)

Bases: tuple

external_addresses

Alias for field number 1

functions

Alias for field number 0

class clips.common.Verbosity(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

SUCCINT = 1
TERSE = 2
VERBOSE = 0
clips.common.delete_environment_data(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>)
clips.common.environment_builder(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str) <MagicMock name='mock.ffi.CData' id='139990491722512'>

Retrieve Environment specific builder.

clips.common.environment_data(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str) type

Retrieve Environment specific data.

clips.common.environment_modifier(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str) <MagicMock name='mock.ffi.CData' id='139990491722512'>

Retrieve Environment specific modifier.

clips.common.initialize_environment_data(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>) EnvData

Module contents

exception clips.CLIPSError(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, message: str = None, code: int = None)

Bases: RuntimeError

An error occurred within the CLIPS Environment.

class clips.Class(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

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.

property abstract: bool

True if the class is abstract.

property deletable: bool

True if the Class can be deleted.

find_message_handler(name: str, handler_type: str = 'primary') MessageHandler

Returns the MessageHandler given its name and type.

instances() iter

Iterate over the instances of the class.

make_instance(instance_name: str = None, **slots) Instance

Make a new Instance from this Class.

Equivalent to the CLIPS (make-instance) function.

message_handlers() iter

Iterate over the message handlers of the class.

property module: Module

The module in which the Class is defined.

Equivalent to the CLIPS (defclass-module) function.

property name: str

Class name.

property reactive: bool

True if the class is reactive.

slots(inherited: bool = False) iter

Iterate over the Slots of the class.

subclass(defclass: Class) bool

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

subclasses(inherited: bool = False) iter

Iterate over the subclasses of the class.

Equivalent to the CLIPS (class-subclasses) function.

superclass(defclass: Class) bool

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

superclasses(inherited=False) iter

Iterate over the superclasses of the class.

Equivalent to the CLIPS class-superclasses command.

undefine()

Undefine the Class.

Equivalent to the CLIPS (undefclass) command.

The object becomes unusable after this method has been called.

property watch_instances: bool

Whether or not the Class Instances are being watched.

property watch_slots: bool

Whether or not the Class Slots are being watched.

class clips.ClassDefaultMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

CONSERVATION_MODE = 1
CONVENIENCE_MODE = 0
class clips.Environment

Bases: object

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

batch_star(path: str)

Evaluate the commands contained in the specific path.

Equivalent to the CLIPS (batch*) function.

build(construct: str)

Build a single construct in CLIPS.

Equivalent to the CLIPS (build) function.

clear()

Clear the CLIPS environment.

Equivalent to the CLIPS (clear) function.

eval(expression: str) type

Evaluate an expression returning its value.

Equivalent to the CLIPS (eval) function.

load(path: str, binary: bool = False)

Load a set of constructs into the CLIPS data base.

If constructs were saved in binary format, the binary parameter should be set to True.

Equivalent to the CLIPS (load) function.

reset()

Reset the CLIPS environment.

Equivalent to the CLIPS (reset) function.

save(path: str, binary=False)

Save a set of constructs into the CLIPS data base.

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

Equivalent to the CLIPS (load) function.

class clips.ImpliedFact(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, fact: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: Fact

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

Implied Fact cannot be build or modified. They can be asserted via the Environment.assert_string() method.

class clips.Instance(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, ist: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: object

A Class Instance is an occurrence of an object.

A Class Instance represents its data as a dictionary where each slot name is a key.

Class Instance slot values can be modified. The Instance will be re-evaluated against the rule network once modified.

delete()

Directly delete the instance.

property instance_class: Class

Instance class.

modify_slots(**slots)

Modify one or more slot values of the Instance.

Instance must exist within the CLIPS engine.

Equivalent to the CLIPS (modify-instance) function.

property name: str

Instance name.

send(message: str, arguments: str = None) type

Send a message to the Instance.

The output value of the message handler is returned.

Equivalent to the CLIPS (send) function.

unmake()

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

class clips.InstanceName(symbol)

Bases: Symbol

Python equivalent of a CLIPS INSTANCE_NAME.

class clips.LoggingRouter

Bases: Router

Python logging Router.

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

It captures CLIPS output and re-directs it to Python logging library.

LOGGERS = {'stderr': <function error>, 'stdout': <function info>, 'stdwrn': <function warning>}
log_message(name: str)
query(name: str) bool

Capture log from CLIPS output routers.

write(name: str, message: str)

If the message is a new-line terminate sentence, log it at according to the mapped level.

Otherwise, append it to the message string.

class clips.Router(name: str, priority: int)

Bases: object

activate()

Activate the Router.

deactivate()

Deactivate the Router.

delete()

Delete the Router.

exit(_exitcode: int)
property name: str

The Router name.

property priority: int

The Router priority.

query(_name: str) bool

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

read(_name: str) int

Callback implementation for the Environment.read_router function.

share_message(name: str, message: str)

Share the captured message with other Routers.

unread(_name: str, _char: int) int

Callback implementation for the Environment.unread_router function.

write(_name: str, _message: str)

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

class clips.SalienceEvaluation(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

EVERY_CYCLE = 1
WHEN_ACTIVATED = 1
WHEN_DEFINED = 1
class clips.SaveMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

LOCAL_SAVE = 1
VISIBLE_SAVE = 1
class clips.Strategy(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

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

Bases: str

Python equivalent of a CLIPS SYMBOL.

class clips.Template(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, name: str)

Bases: object

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

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

Templates allow to assert new facts within the CLIPS environment.

Implied facts are associated to implied templates. Implied templates have a limited set of features.

assert_fact(**slots) TemplateFact

Assert a new fact with the given slot values.

Only deftemplates that have been explicitly defined can be asserted with this function.

Equivalent to the CLIPS (assert) function.

property deletable: bool

True if the Template can be undefined.

facts() iter

Iterate over the asserted Facts belonging to this Template.

property implied: bool

True if the Template is implied.

property module: Module

The module in which the Template is defined.

Python equivalent of the CLIPS deftemplate-module command.

property name: str

Template name.

property slots: tuple

The slots of the template.

undefine()

Undefine the Template.

Equivalent to the CLIPS (undeftemplate) function.

The object becomes unusable after this method has been called.

property watch: bool

Whether or not the Template is being watched.

class clips.TemplateFact(env: <MagicMock name='mock.ffi.CData' id='139990491722512'>, fact: <MagicMock name='mock.ffi.CData' id='139990491722512'>)

Bases: Fact

A Template or Unordered Fact represents its data as a dictionary where each slot name is a key.

TemplateFact slot values can be modified. The Fact will be re-evaluated against the rule network once modified.

modify_slots(**slots)

Modify one or more slot values of the Fact.

Fact must be asserted within the CLIPS engine.

Equivalent to the CLIPS (modify) function.

class clips.TemplateSlotDefaultType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

DYNAMIC_DEFAULT = 1
NO_DEFAULT = 1
STATIC_DEFAULT = 1
class clips.Verbosity(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

SUCCINT = 1
TERSE = 2
VERBOSE = 0