pyaiml21.kernel.Kernel

class pyaiml21.kernel.Kernel(gm_cls: typing.Type[pyaiml21.graphmaster.graphmaster.GraphMaster] = <class 'pyaiml21.graphmaster.graphmaster.GraphMaster'>, *args, **kwargs)[source][source]

Backwards compatible way to work with the interpreter.

This class represents the whole interpreter, keeps the track of a bot and loading and manipulation with its files, configuration, etc.

Note that some methods are missing, or have changed type signature.

Methods

add_properties

Add properties to the bot.

add_substitutions

Update the substitutions of the bot.

brain_size

Find the number of categories stored in the brain.

getBotPredicate

Get the corresponding bot property.

getPredicate

Return bot the specified bot's property.

getSessionData

Return a copy of session predicates.

get_predicate

Find and return the value of a bot's _predicate.

get_property

Return the bot's property value.

get_session

Access arbitrary bot-user session.

init_new_user

Create a chat session for a new user, user must be a new user.

learn

Load and learn content of the given aiml file.

learn_aiml

Load .aiml file and store its contents in the (global) graphmaster.

learn_aimlif

Load .aimlif file and store its contents in the (global) graphmaster.

learn_category

Learn category online, during the evaluation of the response.

loadBrain

Attempt to load the brain global for all users from the specified file.

load_map

Learn and store AIML map m.

load_patterns

Learn pattern tags.

load_set

Learn and store AIML set s.

load_tags

Learn <template> tags.

preprocess

Normalize the text fed to the graphmaster.

resetBrain

Reset bot's brain.

respond

Search graphmaster and return the reply to input_.

saveBrain

Store the global brain into the specified file.

search_brain

Search the bot's brain and return the appropriate template node.

setBotPredicate

Set the corresponding bot property to the value.

setPredicate

Set the corresponding _predicate.

vocabulary

Find the number of distinct words stored as nodes in the bot's brain.

Attributes

getBotPredicate(name: str) Optional[str][source][source]

Get the corresponding bot property.

Parameters

name – name of the property

getPredicate(name: str, sessionID: Optional[str] = None) str[source][source]

Return bot the specified bot’s property.

Parameters
  • name – name of the property

  • sessionID – id of the session

Returns

property value or empty string of not set

getSessionData(sessionID: Optional[str]) Dict[str, str][source][source]

Return a copy of session predicates.

Parameters

sessionID – id of the session

Returns

session predicates or empty dict if session is not found

learn(filename: str) None[source][source]

Load and learn content of the given aiml file.

Parameters

filename – .aiml or .aimlif with categories to learn

loadBrain(brain_file: str) None[source][source]

Attempt to load the brain global for all users from the specified file.

Does not load configuration files, nor the custom tags.

Parameters

brain_file – filename from which to load the brain

resetBrain() None[source][source]

Reset bot’s brain.

Remove the content of bot’s brain, equivalent to starting a new instance of the bot with the same name.

saveBrain(filename: str) None[source][source]

Store the global brain into the specified file.

Does not save configuration files, nor the custom tags.

Parameters

filename – filename to save the brain into

setBotPredicate(name: str, value: str) None[source][source]

Set the corresponding bot property to the value.

Parameters
  • name – name of the property

  • value – desired value

setPredicate(name: str, value: str, sessionID: Optional[str] = None) None[source][source]

Set the corresponding _predicate.

Parameters
  • name – name of the _predicate to set

  • value – desired _predicate value

  • sessionID – userID / sessionID to set _predicate for; or None to set global bot’s _predicate