當前位置: 首頁>>代碼示例>>Python>>正文


Python aiml.Kernel方法代碼示例

本文整理匯總了Python中aiml.Kernel方法的典型用法代碼示例。如果您正苦於以下問題:Python aiml.Kernel方法的具體用法?Python aiml.Kernel怎麽用?Python aiml.Kernel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aiml的用法示例。


在下文中一共展示了aiml.Kernel方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _load_scripts

# 需要導入模塊: import aiml [as 別名]
# 或者: from aiml import Kernel [as 別名]
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}") 
開發者ID:deepmipt,項目名稱:DeepPavlov,代碼行數:18,代碼來源:aiml_skill.py

示例2: _load_alice

# 需要導入模塊: import aiml [as 別名]
# 或者: from aiml import Kernel [as 別名]
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
        ) 
開發者ID:facebookresearch,項目名稱:ParlAI,代碼行數:10,代碼來源:alice.py

示例3: train

# 需要導入模塊: import aiml [as 別名]
# 或者: from aiml import Kernel [as 別名]
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.') 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:31,代碼來源:chatter_core_init.py

示例4: __init__

# 需要導入模塊: import aiml [as 別名]
# 或者: from aiml import Kernel [as 別名]
def __init__(self):
    self._kernel = aiml.Kernel() 
開發者ID:sld,項目名稱:convai-bot-1337,代碼行數:4,代碼來源:ai.py

示例5: __init__

# 需要導入模塊: import aiml [as 別名]
# 或者: from aiml import Kernel [as 別名]
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() 
開發者ID:deepmipt,項目名稱:DeepPavlov,代碼行數:31,代碼來源:aiml_skill.py

示例6: __init__

# 需要導入模塊: import aiml [as 別名]
# 或者: from aiml import Kernel [as 別名]
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.") 
開發者ID:DevDungeon,項目名稱:Cathy,代碼行數:42,代碼來源:__init__.py


注:本文中的aiml.Kernel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。