Python aiml.Kernel() Examples
The following are 6
code examples of aiml.Kernel().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
aiml
, or try the search function
.
Example #1
Source File: aiml_skill.py From DeepPavlov with Apache License 2.0 | 6 votes |
def _load_scripts(self) -> None: """ Scripts are loaded recursively from files with extensions .xml and .aiml Returns: None """ # learn kernel to all aimls in directory tree: all_files = sorted(self.path_to_aiml_scripts.rglob('*.*')) learned_files = [] for each_file_path in all_files: if each_file_path.suffix in ['.aiml', '.xml']: # learn the script file self.kernel.learn(str(each_file_path)) learned_files.append(each_file_path) if not learned_files: log.warning(f"No .aiml or .xml files found for AIML Kernel in directory {self.path_to_aiml_scripts}")
Example #2
Source File: alice.py From ParlAI with MIT License | 5 votes |
def _load_alice(self): self.kern = aiml.Kernel() self.kern.verbose(False) self.kern.setTextEncoding(None) chdir = os.path.join(aiml.__path__[0], 'botdata', 'alice') self.kern.bootstrap( learnFiles="startup.xml", commands="load alice", chdir=chdir )
Example #3
Source File: chatter_core_init.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def train(ev, core, init=False): """ :param ev: The event object referenced in the event. :type ev: sigma.core.mechanics.event.SigmaEvent :param core: The chatterbot core class. :type core: aiml.Kernel :param init: If the training is initializing or runtime. :type init: bool """ cb_log(ev, init, 'Learning generic AIML interactions...') core.learn(os.sep.join([ev.resource('aiml_files'), '*.aiml'])) cb_log(ev, init, 'Learning properties unique to the client...') with open(ev.resource('properties.yml')) as prop_file: prop_data = yaml.safe_load(prop_file) for prop_key in prop_data: prop_val = prop_data.get(prop_key) chatter_core.setBotPredicate(prop_key, prop_val) cb_log(ev, init, 'Learning additional software details...') version = ev.bot.info.get_version() full_version = f'{version.major}.{version.minor}.{version.patch}' if version.beta: full_version += ' Beta' chatter_core.setBotPredicate('version', full_version) birthday_date = arrow.get(datetime.date(2016, 8, 16)) age = (arrow.utcnow() - birthday_date).days // 365.25 chatter_core.setBotPredicate('age', str(int(age))) chatter_core.setBotPredicate('birthday', birthday_date.format('MMMM DD')) chatter_core.setBotPredicate('birthdate', birthday_date.format('MMMM DD, YYYY')) cb_log(ev, init, 'Loaded Chatter Core.')
Example #4
Source File: ai.py From convai-bot-1337 with GNU General Public License v3.0 | 5 votes |
def __init__(self): self._kernel = aiml.Kernel()
Example #5
Source File: aiml_skill.py From DeepPavlov with Apache License 2.0 | 5 votes |
def __init__(self, path_to_aiml_scripts: str, positive_confidence: float = 0.66, null_response: str = "I don't know what to answer you", null_confidence: float = 0.33, **kwargs ) -> None: """ Construct skill: read AIML scripts, load AIML kernel Args: path_to_aiml_scripts: string path to folder with AIML scripts null_response: Response string to answer if no AIML Patterns matched positive_confidence: The confidence of response if response was found in AIML scripts null_confidence: The confidence when AIML scripts has no rule for responding and system returns null_response """ # we need absolute path (expanded for user home and resolved if it relative path): self.path_to_aiml_scripts = Path(path_to_aiml_scripts).expanduser().resolve() log.info(f"path_to_aiml_scripts is: `{self.path_to_aiml_scripts}`") self.positive_confidence = positive_confidence self.null_confidence = null_confidence self.null_response = null_response self.kernel = aiml.Kernel() # to block AIML output: self.kernel._verboseMode = False self._load_scripts()
Example #6
Source File: __init__.py From Cathy with GNU General Public License v3.0 | 5 votes |
def __init__(self, channel_name, bot_token, database): """ Initialize the bot using the Discord token and channel name to chat in. :param channel_name: Only chats in this channel. No hashtag included. :param bot_token: Full secret bot token :param database: Path for sqlite file to use """ # Store configuration values self.channel_name = channel_name self.token = bot_token self.database = database self.message_count = 0 self.last_reset_time = datetime.now() logging.info("[*] Setting up signal handlers") signal(SIGINT, self.exit_handler) signal(SIGTERM, self.exit_handler) # Setup database logging.info("[*] Initializing database...") self.db = sqlite3.connect(self.database) self.cursor = self.db.cursor() self.setup_database_schema() logging.info('[+] Database initialized') # Load AIML kernel logging.info("[*] Initializing AIML kernel...") start_time = datetime.now() self.aiml_kernel = aiml.Kernel() self.setup_aiml() end_time = datetime.now() logging.info(f"[+] Done initializing AIML kernel. Took {end_time - start_time}") # Set up Discord logging.info("[*] Initializing Discord bot...") self.discord_bot = discord.AutoShardedClient() self.setup_discord_events() logging.info("[+] Done initializing Discord bot.") logging.info("[+] Exiting __init__ function.")