/*
Copyleft (C) 2005 Hélio Perroni Filho
xperroni@bol.com.br
ICQ: 2490863
This file is part of ChatterBean.
ChatterBean is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
ChatterBean is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with ChatterBean (look at the Documents/ directory); if not, either write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA, or visit (http://www.gnu.org/licenses/gpl.txt).
*/
package bitoflife.chatterbean.aiml;
import bitoflife.chatterbean.AliceBotMother;
import junit.framework.TestCase;
import org.xml.sax.helpers.AttributesImpl;
public class AIMLHandlerTest extends TestCase
{
/*
Attribute Section
*/
private AIMLHandler handler;
private AIMLStack stack;
private AliceBotMother aliceBot = new AliceBotMother();
/*
Event Section
*/
protected void setUp() throws Exception
{
handler = new AIMLHandler();
stack = handler.stack;
}
protected void tearDown()
{
handler = null;
}
/*
Method Section
*/
private char[] toCharArray(String string)
{
int n = string.length();
char[] chars = new char[n];
string.getChars(0, n, chars, 0);
return chars;
}
public void testCharacters() throws Exception
{
char[] text;
AttributesImpl attributes = new AttributesImpl();
handler.startElement(null, null, "template", attributes);
handler.characters(text = toCharArray("Hello."), 0, text.length);
handler.endElement(null, null, "template");
Text expected = new Text("Hello.");
Text actual = (Text) ((Template) stack.peek()).children().get(0);
assertEquals(expected, actual);
}
public void testAiml() throws Exception
{
char[] text;
AttributesImpl attributes = new AttributesImpl();
AttributesImpl aimlAtts = new AttributesImpl();
aimlAtts.addAttribute(null, "version", null, "String", "1.0.1");
handler.startElement(null, null, "aiml", aimlAtts);
handler.startElement(null, null, "category", attributes);
handler.startElement(null, null, "pattern", attributes);
handler.characters(text = toCharArray("HELLO ALICE I AM *"), 0, text.length);
handler.endElement(null, null, "pattern");
handler.startElement(null, null, "template", attributes);
handler.characters(text = toCharArray("Hello "), 0, text.length);
handler.startElement(null, null, "star", attributes);
handler.characters(text = toCharArray(", nice to meet you."), 0, text.length);
handler.endElement(null, null, "template");
handler.endElement(null, null, "category");
handler.endElement(null, null, "aiml");
Aiml actual = (Aiml) stack.peek();
Aiml expected = new Aiml(new Category(new Pattern("HELLO ALICE I AM *"),
new Template("Hello ",
new Star(1),
", nice to meet you.")));
assertEquals(expected, actual);
assertEquals("1.0.1", actual.getVersion());
}
public void testBot() throws Exception
{
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute(null, "name", null, "String", "bot.predicate1");
handler.startElement(null, null, "bot", attributes);
Bot expected = new Bot("bot.predicate1");
Bot actual = (Bot) stack.peek();
assertEquals(expected, actual);
Bot bot2 = new Bot("bot.predicate2");
assertFalse(bot2.equals(actual));
}
public void testCategory() throws Exception
{
char[] text;
AttributesImpl attributes = new AttributesImpl();
handler.startElement(null, null, "category", attributes);
handler.startElement(null, null, "pattern", attributes);
handler.characters(text = toCharArray("HELLO ALICE I AM *"), 0, text.length);
handler.endElement(null, null, "pattern");
handler.startElement(null, null, "that", attributes);
handler.characters(text = toCharArray("TEST"), 0, text.length);
handler.endElement(null, null, "that");
handler.startElement(null, null, "template", attributes);
handler.characters(text = toCharArray("Hello "), 0, text.length);
handler.startElement(null, null, "star", attributes);
handler.characters(text = toCharArray(", nice to meet you."), 0, text.length);
handler.endElement(null, null, "template");
handler.endElement(null, null, "category");
Category actual = (Category) stack.peek();
Category expected = new Category(new Pattern("HELLO ALICE I AM *"),
new That("TEST"),
new Template("Hello ", new Star(1), ", nice to meet you."));
assertEquals(expected, actual);
}
public void testCondition() throws Exception
{
char[] text;
AttributesImpl attributes = new AttributesImpl();
handler.startElement(null, null, "condition", attributes);
attributes = new AttributesImpl();
attributes.addAttribute(null, null, "name", "String", "condition1");
attributes.addAttribute(null, null, "value", "String", "test value1");
handler.startElement(null, null, "li", attributes);
handler.characters(text = toCharArray("Conditioned output 1"), 0, text.length);
handler.endElement(null, null, "li");
attributes = new AttributesImpl();
handler.startElement(null, null, "li", attributes);
handler.characters(text = toCharArray("Else output"), 0, text.length);
handler.endElement(null, null, "li");
handler.endElement(null, null, "condition");
Condition actual = (Condition) stack.peek();
Condition expected = new Condition(null, null,
new Li("condition1", "test value1", "Conditioned output 1"),
new Li(null, null, "Else output"));
assertEquals(expected, actual);
attributes = new AttributesImpl();
attributes.addAttribute(null, null, "name", "String", "condition");
handler.startElement(null, null, "condition", attributes);
attributes = new AttributesImpl();
attributes.addAttribute(null, null, "value", "String", "test value1");
handler.startElement(null, null, "li", attributes);
handler.characters(text = toCharArray("Conditioned output 1"), 0, text.length);
handler.endElement(null, null, "li");
attributes = new AttributesImpl();
handler.startElement(null, null, "li", attributes);
handler.characters(text = toCharArray("Else output"), 0, text.length);
handler.endElement(null, null, "li");
handler.endElement(null, null, "condition");
actual = (Condition) stack.peek();
expected = new Condition("condition1", null,
new Li(null, "test value1", "Conditioned output 1"),
new Li(null, null, "Else output"));
assertEquals(expected, actual);
attributes = new AttributesImpl();
attributes.addAttribute(null, null, "name", "String", "condition");
attributes.addAttribute(null, null, "value", "String", "test value1");
handler.startElement(null, null, "condition", attributes);
handler.characters(text = toCharArray("Conditioned output"), 0, text.length);
handler.endElement(null, null, "condition");
expected = new Condition("condition1", "test value1", "Conditioned output");
actual = (Condition) stack.peek();
assertEquals(expected, actual);
}
public void testDate() throws Exception
{
AttributesImpl attributes = new AttributesIm
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Aiml机器人程序 (330个子文件)
mp3.aiml 758KB
mp2.aiml 748KB
mp1.aiml 744KB
mp5.aiml 731KB
mp0.aiml 720KB
mp4.aiml 711KB
reduction0.safe.aiml 687KB
reduction1.safe.aiml 587KB
reduction3.safe.aiml 451KB
reduction4.safe.aiml 445KB
reduction2.safe.aiml 419KB
mp6.aiml 381KB
knowledge.aiml 326KB
update1.aiml 235KB
that.aiml 198KB
psychology.aiml 80KB
religion.aiml 38KB
stories.aiml 33KB
numbers.aiml 25KB
sex.aiml 18KB
personality.aiml 14KB
salutations.aiml 12KB
movies.aiml 8KB
science.aiml 5KB
pickup.aiml 5KB
primeminister.aiml 5KB
sports.aiml 4KB
primitive-math.aiml 4KB
music.aiml 3KB
interjection.aiml 3KB
stack.aiml 3KB
reductions-update.aiml 2KB
literature.aiml 2KB
iu.aiml 1KB
phone.aiml 446B
聊天机器人文档.doc 618KB
聊天机器人应用描述.doc 138KB
~$天机器人文档.doc 162B
.gitignore 272B
AIMLHandlerTest.java 25KB
AIMLHandlerTest.java 23KB
Transformations.java 11KB
Transformations.java 10KB
TransformationsTest.java 10KB
TransformationsTest.java 10KB
AliceBotTest.java 9KB
ChatterBean.java 9KB
Context.java 7KB
Context.java 6KB
Substitution.java 6KB
Substitution.java 6KB
Graphmaster.java 6KB
SubstitutionTest.java 6KB
SubstitutionTest.java 6KB
AIMLHandler.java 5KB
Match.java 5KB
Match.java 5KB
Sentence.java 5KB
AIMLHandler.java 5KB
DBOperation.java 5KB
Graphmaster.java 5KB
AliceBot.java 4KB
Sentence.java 4KB
Category.java 4KB
AliceBot.java 4KB
Category.java 4KB
CreateIndexTask.java 4KB
ChatterBeanParser.java 4KB
IndexResource.java 4KB
Searcher.java 4KB
AIMLParserTest.java 4KB
AliceBotParser.java 4KB
Condition.java 4KB
Tokenizer.java 4KB
AIMLParserTest.java 4KB
Condition.java 4KB
AliceBotParser.java 4KB
Tokenizer.java 3KB
TestSuite.java 3KB
TransformationsParser.java 3KB
SentenceSplitter.java 3KB
SentenceSplitter.java 3KB
TransformationsParser.java 3KB
That.java 3KB
SubstitutionBuilder.java 3KB
ConfigException.java 3KB
ConfigException.java 3KB
That.java 3KB
SubstitutionBuilder.java 3KB
GraphmasterTest.java 3KB
GraphmasterTest.java 3KB
Pattern.java 3KB
ReflectionHandler.java 3KB
TokenizerConfigStream.java 3KB
GossipLoad.java 3KB
TemplateElement.java 3KB
TokenizerConfigStream.java 3KB
Request.java 3KB
Searcher.java 3KB
Pattern.java 3KB
共 330 条
- 1
- 2
- 3
- 4
资源评论
青鸟飞云
- 粉丝: 11
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- AIS2024 valid
- 最入门的爬虫代码 python.docx
- 爬虫零基础入门-爬取天气预报.pdf
- 最通俗易懂的 MongoDB 非结构化文档存储数据库教程.zip
- 以mongodb为数据库的订单物流小项目.zip
- 腾讯云-mongodb数据库, 项目部署.zip
- 腾讯 APIJSON 的 MongoDB 数据库插件.zip
- 理解非关系型数据库和关系型数据库的区别.zip
- 操作简单的Mongodb网页web管理工具,基于Spring Boot2.0支持mongodb集群.zip
- tms-mongodb-web,提供访问mongodb数据的REST API和可灵活扩展的mongodb web 客户端.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功