/*
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 org.xml.sax.helpers.AttributesImpl;
import junit.framework.TestCase;
import bitoflife.chatterbean.AliceBot;
import bitoflife.chatterbean.AliceBotMother;
import bitoflife.chatterbean.Context;
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 test
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
人工智能机器人alice的java版源代码 (226个子文件)
idiom.aiml 3KB
AIMLHandlerTest.class 17KB
AliceBotTest.class 9KB
Transformations.class 8KB
TransformationsTest.class 8KB
Context.class 6KB
Category.class 5KB
AIMLHandler.class 5KB
SubstitutionTest.class 5KB
Substitution.class 4KB
Match.class 4KB
That.class 4KB
TransformationsParser.class 4KB
Graphmaster.class 4KB
AliceBotParser.class 4KB
Condition.class 4KB
Tokenizer.class 4KB
AliceBot.class 4KB
AIMLParserTest.class 4KB
TemplateElement.class 3KB
SentenceSplitter.class 3KB
Searcher.class 3KB
GraphmasterTest.class 3KB
Aiml.class 3KB
Topic.class 3KB
Sentence.class 3KB
SubstitutionBuilder.class 3KB
Pattern.class 3KB
TokenizerConfigStream.class 3KB
ReflectionHandler.class 3KB
Transformations$Mapper.class 3KB
Substitution$FindReplaceSuffix.class 2KB
Substitution$FindReplacePrefix.class 2KB
Input.class 2KB
Sequence.class 2KB
TestSuite.class 2KB
Date.class 2KB
Substitution$FindReplaceFragment.class 2KB
LoggerTest.class 2KB
SentenceSplitterTest.class 2KB
SequenceTest.class 2KB
Substitution$FindReplaceWord.class 2KB
System.class 2KB
Javascript.class 2KB
Request.class 2KB
Star.class 2KB
Set.class 2KB
Topicstar.class 2KB
CategoryTest.class 2KB
Thatstar.class 2KB
Chat.class 2KB
AIMLParser.class 2KB
ContextParser$ContextHandler.class 2KB
Get.class 2KB
Bot.class 2KB
AliceBotMother.class 2KB
ContextParserTest.class 2KB
ContextParser.class 2KB
Learn.class 2KB
AliceBotMother.class 2KB
Sentence.class 2KB
Formal.class 2KB
ContextTopicChangeListener.class 2KB
Li.class 2KB
SplitterHandler.class 2KB
TokenizerTest.class 2KB
Escaper.class 2KB
Random.class 2KB
MatchTest.class 2KB
SystemTest.class 1KB
Id.class 1KB
SearcherTest.class 1KB
Gossip.class 1KB
BeanshellInterpreter.class 1KB
SentenceTest.class 1KB
Response.class 1KB
Logger.class 1KB
Template.class 1KB
Person2.class 1KB
Person.class 1KB
Gender.class 1KB
ContextRandomSeedChangeListener.class 1KB
AIMLParserTest$GraphmasterMock.class 1KB
ConfigException.class 1KB
Srai.class 1KB
Size.class 1KB
Match$Section.class 1KB
Version.class 1KB
SequenceMother.class 1KB
Text.class 1KB
GraphmasterMother.class 1KB
AIMLStack.class 962B
Uppercase.class 923B
Lowercase.class 923B
TransformationsMother.class 903B
TemplateElementTest.class 896B
TokenizerMother.class 857B
AIMLParserException.class 809B
Think.class 755B
Br.class 726B
共 226 条
- 1
- 2
- 3
资源评论
- 菜的不能再菜的程序猿2018-12-04垃圾骗积分
- 1231dfgfdgfdgfdg53r2017-05-09多谢共享,学习了
- Alei762018-03-22多谢共享,学习了
tiansui
- 粉丝: 2
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功