《智能对话机器人开发实战20讲》--学习笔记--人工智能标记语言(AIML)基础

一、学习笔记

环境要求

  • python 3.5.2
  • aiml

安装

  • pip install aiml

helloworld.py

# -*- coding: utf-8 -*-
import aiml
import sys
import os

def get_module_dir(name):
    path = getattr(sys.modules[name], "__file__", None)
    if not path:
        raise AttributeError("module %s has not attribute __file__" % name)
    return os.path.dirname(os.path.abspath(path))

alice_path = get_module_dir("aiml") + "/botdata/alice"

os.chdir(alice_path)
alice = aiml.Kernel()
alice.learn("startup.xml")
alice.respond("LOAD ALICE")
while True:
    print(alice.respond(input("Enter your message >> ")))


运行结果

Loading startup.xml...done (0.01 seconds)
Loading ai.aiml...done (0.01 seconds)
Loading alice.aiml...done (0.01 seconds)
Loading astrology.aiml...done (0.00 seconds)
Loading atomic.aiml...done (0.14 seconds)
Loading biography.aiml...done (0.05 seconds)
Loading bot.aiml...done (0.18 seconds)
Loading bot_profile.aiml...done (0.00 seconds)
Loading client.aiml...done (0.06 seconds)
Loading client_profile.aiml...done (0.02 seconds)
Loading computers.aiml...done (0.01 seconds)
Loading continuation.aiml...done (0.00 seconds)
Loading date.aiml...done (0.00 seconds)
Loading default.aiml...done (0.27 seconds)
Loading drugs.aiml...done (0.00 seconds)
Loading emotion.aiml...done (0.01 seconds)
Loading food.aiml...done (0.00 seconds)
Loading geography.aiml...done (0.06 seconds)
Loading gossip.aiml...done (0.00 seconds)
Loading history.aiml...done (0.00 seconds)
Loading humor.aiml...done (0.00 seconds)
Loading imponderables.aiml...done (0.00 seconds)
Loading inquiry.aiml...done (0.00 seconds)
Loading interjection.aiml...done (0.00 seconds)
Loading iu.aiml...done (0.00 seconds)
Loading knowledge.aiml...done (0.09 seconds)
Loading literature.aiml...done (0.00 seconds)
Loading loebner10.aiml...done (0.00 seconds)
Loading money.aiml...done (0.00 seconds)
Loading movies.aiml...done (0.00 seconds)
Loading mp0.aiml...done (0.30 seconds)
Loading mp1.aiml...done (0.29 seconds)
Loading mp2.aiml...done (0.29 seconds)
Loading mp3.aiml...done (0.31 seconds)
Loading mp4.aiml...done (0.23 seconds)
Loading mp5.aiml...done (0.32 seconds)
Loading mp6.aiml...done (0.13 seconds)
Loading music.aiml...done (0.00 seconds)
Loading numbers.aiml...done (0.01 seconds)
Loading personality.aiml...done (0.01 seconds)
Loading phone.aiml...done (0.00 seconds)
Loading pickup.aiml...done (0.00 seconds)
Loading politics.aiml...done (0.00 seconds)
Loading primeminister.aiml...done (0.00 seconds)
Loading psychology.aiml...done (0.03 seconds)
Loading reduction.names.aiml...done (0.23 seconds)
Loading reduction0.safe.aiml...done (0.46 seconds)
Loading reduction1.safe.aiml...done (0.29 seconds)
Loading reduction2.safe.aiml...done (0.19 seconds)
Loading reduction3.safe.aiml...done (0.20 seconds)
Loading reduction4.safe.aiml...done (0.33 seconds)
Loading reductions-update.aiml...done (0.00 seconds)
Loading religion.aiml...done (0.01 seconds)
Loading salutations.aiml...done (0.01 seconds)
Loading science.aiml...done (0.00 seconds)
Loading sex.aiml...done (0.01 seconds)
Loading sports.aiml...done (0.00 seconds)
Loading stack.aiml...done (0.00 seconds)
Loading stories.aiml...done (0.02 seconds)
Loading that.aiml...done (0.07 seconds)
Loading update1.aiml...done (0.08 seconds)
Loading update_mccormick.aiml...done (0.00 seconds)
Loading wallace.aiml...done (0.04 seconds)
Loading xfind.aiml...done (0.00 seconds)
Enter your message >> hello world
Hi there!. You know who.
Enter your message >> how do you do
I am functioning within normal parameters.
Enter your message >> nice day
Thank you for your kindness.

startup.xml


    
    
    <category>
        
        
        <pattern>LOAD AIML Bpattern>
        
        
        <template>
            <learn>standard/std-*.aimllearn>
            
            
        template>
    category>
aiml>

二、学习作业


三、课程学习方式

《智能对话机器人开发实战20讲》
地址:https://edu.csdn.net/course/detail/8944
《智能对话机器人开发实战20讲》--学习笔记--人工智能标记语言(AIML)基础_第1张图片

你可能感兴趣的:(《智能对话机器人开发实战20讲》--学习笔记--人工智能标记语言(AIML)基础)