Commit 451fd38f by yangpengflag

Initial commit

parents
import aiml
import jieba
kernel = aiml.Kernel()
kernel.learn("std-startup.xml")
kernel.respond("load aiml b")
while True:
response = kernel.respond("".join(jieba.cut(input("请输入你的问题>>>"),cut_all=False)))
s = response.replace(" ","")
print(s)
\ No newline at end of file
<aiml version="1.0.1" encoding="UTF-8">
<category>
<pattern>
你 好
</pattern>
<template>
<!--用随机答复,回答同一个问题-->
<random>
<li>你好啊</li>
<li>好巧哦,你也在啊</li>
<li>hi,很高兴见到你</li>
<li>hello,man</li>
</random>
</template>
</category>
<!--* 匹配所有问题-->
<category>
<pattern>你 好 *</pattern>
<template>
<srai>你 好</srai>
</template>
</category>
<!--pattern中英文必须大写-->
<category>
<pattern>WHAT IS YOUR NAME</pattern>
<template>
HELLO,my name is 喜洋洋
</template>
</category>
<!--set关键字,存储*所接受的输入作为变量username的值以供别处使用,并显示在本次回答中-->
<category>
<pattern>你 好 我是 *</pattern>
<template>
你好啊,<set name="username"><star/></set>,很高兴认识你!
</template>
</category>
<!--get关键字,获取已经设置的变量username,将其所存储的值显示出来-->
<category>
<pattern>晚安啦</pattern>
<template>
Good Night!<get name="username"/>,跟你聊天很愉快,下次再聊,88!
</template>
</category>
<!--star index = "1" 将从上面对话中获取的值,显示在下面答复中;不会吹牛的大周不是一个好司机-->
<category>
<pattern>不会 * 的 * 不是 一个 好 *</pattern>
<template>
真的吗,不会<star index="1"/>的<star index="2"/> ,可能是一个好<star index="3"/>
</template>
<!--真的吗,不会吹牛的大周,可能是一个好司机-->
</category>
<!--that关键字,以前一个回答“湘菜”作为一个基础,根据这个基础触发多种回答,只能触发一次-->
<category>
<pattern>你 喜欢 吃 什么 菜</pattern>
<template>湘菜</template>
</category>
<category>
<pattern>我也是,超喜欢吃!</pattern>
<that>湘菜</that>
<template>太棒了,我知道有家菜做得很好吃,有时间一起去吃吧</template>
</category>
<category>
<pattern>我 喜欢 吃 川菜</pattern>
<that>湘菜</that>
<template>川菜啊,我也很喜欢吃,要约饭吗?</template>
</category>
<!--topic将一个话题作为触发点,以此为一个问答集合-->
<category>
<pattern>快 过年 了</pattern>
<template>是的啊,马上就要<set name="topic">过年</set>了</template>
</category>
<topic name = "过年">
<category>
<pattern>车票 很难 买 啊</pattern>
<template>是的啊,我都抢很多天了,一直没抢到票</template>
</category>
<category>
<pattern>过年 去 哪 玩 啊</pattern>
<template>过年我打算去马尔代夫过夏天去</template>
</category>
</topic>
<!--不同于star index="1"这种将获取的*的值显示出来,think将不显示-->
<category>
<pattern>我 的 名字 是 *</pattern>
<template>你好,欢迎来到王者峡谷!<think><set name="username1"><star/></set> </think></template>
</category>
<category>
<pattern>好啦,我 要 走 了</pattern>
<template>
好的,<get name="username1"/>,下次来玩。
</template>
</category>
</aiml>
\ No newline at end of file
<aiml version="1.0.1" encoding="UTF-8">
<category>
<pattern>LOAD AIML B</pattern>
<template>
<learn>basic_chat.aiml</learn>
</template>
</category>
</aiml>
\ No newline at end of file
def convert(s, num_rows):
"""
:type s: str
:type numRows: int
:rtype: str
LEETCODEISHIRING numrows=3 columnsdiff_length=2*3-2=4
L C I R
E T O E S I I G
E D H N
LCIRETOESIIGEDHN
LEETCODEISHIRING numrows=4 columnsdiff_length=2*4-2=6
L D R
E O E I I
E C I H N
T S G
LDREOEIIECIHNTSG
"""
s_length = len(s) # 得出要处理的字符的长度
columnsdiff_length = 2 * num_rows - 2 # 两列之间的差
result = "" # 定义排列之后的结果字符
if num_rows <= 0:
print("请输入正确的行数,行数必须大于0")
if s_length == 0 or num_rows == 1:
print(s)
return s # 如果要处理的字符长度是0即为空,或输入的行数等于1时即不需要处理,则返回原字符串
for i in range(num_rows): # 从第一行遍历到最后一行
for j in range(i, s_length, columnsdiff_length):
result += s[j] # 第一行和最后一行 还有普通行的整列数字
if i != 0 and i != num_rows - 1 and j - 2 * i + columnsdiff_length < s_length:
result += s[j - 2 * i + columnsdiff_length] # 单列行的数字
print(result)
return result
ss = "LEETCODEISHIRING"
convert(ss, 3)
convert(ss, 4)
# convert(ss, 0)
# convert(ss, 1)
# convert(ss, -1)
def convert1(s, num_rows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
str_length = len(s)
result = ""
if num_rows <= 1:
print(s)
return s
for i in range(num_rows):
c1 = 2 * num_rows - 2 * (i + 1)
c2 = 2 * i
cnt = i
result += s[cnt]
while cnt < str_length:
if c1 != 0:
cnt += c1
if cnt < str_length:
result += s[cnt]
if c2 != 0:
cnt += c2
if cnt < str_length:
result += s[cnt]
print(result)
return result
s2 = "LEETCODEISHIRING"
convert1(s2, 3)
convert1(s2, 4)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment