├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
├── java
│ ├── bitoflife
│ │ └── chatterbean
│ │ │ ├── AliceBot.java
│ │ │ ├── AliceBotMother.java
│ │ │ ├── ChatterBean.java
│ │ │ ├── ChatterBeanException.java
│ │ │ ├── Context.java
│ │ │ ├── ContextPropertyChangeListener.java
│ │ │ ├── ContextRandomSeedChangeListener.java
│ │ │ ├── ContextTopicChangeListener.java
│ │ │ ├── Graphmaster.java
│ │ │ ├── GraphmasterMother.java
│ │ │ ├── GraphmasterTest.java
│ │ │ ├── Logger.java
│ │ │ ├── LoggerTest.java
│ │ │ ├── Match.java
│ │ │ ├── MatchTest.java
│ │ │ ├── aiml
│ │ │ ├── AIMLElement.java
│ │ │ ├── AIMLHandler.java
│ │ │ ├── AIMLHandlerTest.java
│ │ │ ├── AIMLParser.java
│ │ │ ├── AIMLParserConfigurationException.java
│ │ │ ├── AIMLParserException.java
│ │ │ ├── AIMLParserTest.java
│ │ │ ├── AIMLStack.java
│ │ │ ├── Aiml.java
│ │ │ ├── Bot.java
│ │ │ ├── Category.java
│ │ │ ├── CategoryTest.java
│ │ │ ├── Condition.java
│ │ │ ├── Date.java
│ │ │ ├── Formal.java
│ │ │ ├── Gender.java
│ │ │ ├── Get.java
│ │ │ ├── Gossip.java
│ │ │ ├── Id.java
│ │ │ ├── Input.java
│ │ │ ├── Javascript.java
│ │ │ ├── Learn.java
│ │ │ ├── Li.java
│ │ │ ├── Lowercase.java
│ │ │ ├── Pattern.java
│ │ │ ├── Person.java
│ │ │ ├── Person2.java
│ │ │ ├── Random.java
│ │ │ ├── Sentence.java
│ │ │ ├── Set.java
│ │ │ ├── Size.java
│ │ │ ├── Sr.java
│ │ │ ├── Srai.java
│ │ │ ├── Star.java
│ │ │ ├── System.java
│ │ │ ├── SystemTest.java
│ │ │ ├── Template.java
│ │ │ ├── TemplateElement.java
│ │ │ ├── TemplateElementTest.java
│ │ │ ├── Text.java
│ │ │ ├── That.java
│ │ │ ├── Thatstar.java
│ │ │ ├── Think.java
│ │ │ ├── Topic.java
│ │ │ ├── Topicstar.java
│ │ │ ├── Uppercase.java
│ │ │ └── Version.java
│ │ │ ├── config
│ │ │ ├── ConfigException.java
│ │ │ ├── TokenizerConfig.java
│ │ │ └── TokenizerConfigStream.java
│ │ │ ├── parser
│ │ │ ├── AliceBotParser.java
│ │ │ ├── AliceBotParserConfigurationException.java
│ │ │ ├── AliceBotParserException.java
│ │ │ ├── ChatterBeanParser.java
│ │ │ ├── ContextParser.java
│ │ │ ├── ContextParserTest.java
│ │ │ ├── ReflectionBuilder.java
│ │ │ ├── ReflectionHandler.java
│ │ │ ├── SplitterHandler.java
│ │ │ ├── SubstitutionBuilder.java
│ │ │ └── TransformationsParser.java
│ │ │ ├── script
│ │ │ ├── BeanshellInterpreter.java
│ │ │ ├── Interpreter.java
│ │ │ ├── InterpretingException.java
│ │ │ └── JavascriptInterpreter.java
│ │ │ ├── text
│ │ │ ├── Request.java
│ │ │ ├── Response.java
│ │ │ ├── Sentence.java
│ │ │ ├── SentenceSplitter.java
│ │ │ ├── SentenceSplitterTest.java
│ │ │ ├── SentenceTest.java
│ │ │ ├── Substitution.java
│ │ │ ├── SubstitutionTest.java
│ │ │ ├── Tokenizer.java
│ │ │ ├── TokenizerMother.java
│ │ │ ├── TokenizerTest.java
│ │ │ ├── Transformations.java
│ │ │ ├── TransformationsMother.java
│ │ │ └── TransformationsTest.java
│ │ │ └── util
│ │ │ ├── Escaper.java
│ │ │ ├── Searcher.java
│ │ │ ├── SearcherTest.java
│ │ │ ├── Sequence.java
│ │ │ ├── SequenceMother.java
│ │ │ └── SequenceTest.java
│ └── com
│ │ └── liuniu
│ │ └── aimlbot
│ │ ├── AimlbotApplication.java
│ │ ├── service
│ │ ├── AskToAimlService.java
│ │ └── impl
│ │ │ └── AskToAimlServcieImpl.java
│ │ ├── util
│ │ ├── ChineseSegmenter.java
│ │ └── Test.java
│ │ └── web
│ │ └── AimlController.java
└── resources
│ ├── Corpus
│ ├── Chinese
│ │ ├── Book.xml
│ │ ├── Complain.xml
│ │ ├── Computer.xml
│ │ ├── Constellation.xml
│ │ ├── DMSD.xml
│ │ ├── Discuss.xml
│ │ ├── Encourage.xml
│ │ ├── External.xml
│ │ ├── Film.xml
│ │ ├── Food.xml
│ │ ├── Game.xml
│ │ ├── Greeting.xml
│ │ ├── Healthy.xml
│ │ ├── Inherence.xml
│ │ ├── Internet.xml
│ │ ├── Job.xml
│ │ ├── Joke.xml
│ │ ├── Life.xml
│ │ ├── MarkResponse.xml
│ │ ├── Master.xml
│ │ ├── Music.xml
│ │ ├── MyInfo.xml
│ │ ├── Photography.xml
│ │ ├── Plan.xml
│ │ ├── Praise.xml
│ │ ├── Rude.xml
│ │ ├── Sentiment .xml
│ │ ├── Sex.xml
│ │ ├── SmallWord.xml
│ │ ├── Study.xml
│ │ ├── Travel.xml
│ │ ├── Yt.xml
│ │ ├── gossip.xml
│ │ └── main.xml
│ └── English
│ │ ├── ai.xml
│ │ ├── alice.xml
│ │ ├── android.xml
│ │ ├── astrology.xml
│ │ ├── atomic.xml
│ │ ├── badanswer.xml
│ │ ├── bot.xml
│ │ ├── bot_profile.xml
│ │ ├── client.xml
│ │ ├── client_profile.xml
│ │ ├── computers.xml
│ │ ├── continuation.xml
│ │ ├── default.xml
│ │ ├── drugs.xml
│ │ ├── emotion.xml
│ │ ├── food.xml
│ │ ├── geography.xml
│ │ ├── gossip.xml
│ │ ├── history.xml
│ │ ├── humor.xml
│ │ ├── imponderables.xml
│ │ ├── inquiry.xml
│ │ ├── interjection.aiml
│ │ ├── iu.aiml
│ │ ├── knowledge.aiml
│ │ ├── literature.aiml
│ │ ├── movies.aiml
│ │ ├── mp0.aiml
│ │ ├── mp1.aiml
│ │ ├── mp2.aiml
│ │ ├── mp3.aiml
│ │ ├── mp4.aiml
│ │ ├── mp5.aiml
│ │ ├── mp6.aiml
│ │ ├── music.aiml
│ │ ├── numbers.aiml
│ │ ├── personality.aiml
│ │ ├── phone.aiml
│ │ ├── pickup.aiml
│ │ ├── primeminister.aiml
│ │ ├── primitive-math.aiml
│ │ ├── psychology.aiml
│ │ ├── reduction0.safe.aiml
│ │ ├── reduction1.safe.aiml
│ │ ├── reduction2.safe.aiml
│ │ ├── reduction3.safe.aiml
│ │ ├── reduction4.safe.aiml
│ │ ├── reductions-update.aiml
│ │ ├── religion.aiml
│ │ ├── salutations.aiml
│ │ ├── science.aiml
│ │ ├── sex.aiml
│ │ ├── sports.aiml
│ │ ├── stack.aiml
│ │ ├── stories.aiml
│ │ ├── that.aiml
│ │ ├── update1.aiml
│ │ ├── wallace.xml
│ │ └── xfind.xml
│ ├── application.properties
│ └── conf
│ ├── context.xml
│ ├── splitters.xml
│ └── substitutions.xml
└── test
└── java
└── com
└── liuniu
└── aimlbot
└── AimlbotApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lengendary/springboot-aimlbot/79245ebf8e2ed0a81bdac5cc26839f374a158844/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
2 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.1.RELEASE
9 |
10 |
11 | com.liuniu
12 | aimlbot
13 | 0.0.1-SNAPSHOT
14 | aimlbot
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-web
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-test
33 | test
34 |
35 |
36 | bsh
37 | bsh
38 | 1.3.0
39 |
40 |
41 |
42 |
43 | org.slf4j
44 | slf4j-api
45 |
46 |
47 | org.ansj
48 | ansj_seg
49 | 0.9
50 |
51 |
52 |
53 |
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-maven-plugin
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/AliceBotMother.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | import bitoflife.chatterbean.parser.AliceBotParser;
18 | import bitoflife.chatterbean.util.Searcher;
19 |
20 | import java.io.ByteArrayOutputStream;
21 | import java.io.FileInputStream;
22 |
23 | public class AliceBotMother
24 | {
25 | /*
26 | Attribute Section
27 | */
28 |
29 | private ByteArrayOutputStream gossip;
30 |
31 | /*
32 | Event Section
33 | */
34 |
35 | public void setUp()
36 | {
37 | gossip = new ByteArrayOutputStream();
38 | }
39 |
40 | /*
41 | Method Section
42 | */
43 |
44 | public String gossip()
45 | {
46 | return gossip.toString();
47 | }
48 |
49 | public AliceBot newInstance() throws Exception
50 | {
51 | Searcher searcher = new Searcher();
52 | AliceBotParser parser = new AliceBotParser();
53 | AliceBot bot = parser.parse(getClass().getResourceAsStream("/conf/context.xml"),
54 | getClass().getResourceAsStream("/conf/splitters.xml"),
55 | getClass().getResourceAsStream("/conf/substitutions.xml"),
56 | searcher.search(getClass().getResource("/Corpus/Chinese").toString().substring(5), ".*\\.xml"));
57 |
58 | Context context = bot.getContext();
59 | context.outputStream(gossip);
60 | return bot;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/ChatterBeanException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2006 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | /**
18 | Basic exception class for exceptions thrown from ChatterBean's main class.
19 | */
20 | public class ChatterBeanException extends RuntimeException
21 | {
22 | /** Version class identifier for the serialization engine. Matches the number of the last revision where the class was created / modified. */
23 | private static final long serialVersionUID = 8L;
24 |
25 | public ChatterBeanException(String message)
26 | {
27 | super(message);
28 | }
29 |
30 | public ChatterBeanException(Exception cause)
31 | {
32 | super(cause);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/ContextPropertyChangeListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | import java.beans.PropertyChangeListener;
18 |
19 | public abstract class ContextPropertyChangeListener implements PropertyChangeListener
20 | {
21 | /*
22 | Attribute Section
23 | */
24 |
25 | /** Name of the property whose changes to listen for. */
26 | private String name;
27 |
28 | /*
29 | Constructor Section
30 | */
31 |
32 | /**
33 | Creates a new change listener for the named Context Property.
34 |
35 | @param name The name of the property whose changes this object listens for.
36 | */
37 | public ContextPropertyChangeListener(String name)
38 | {
39 | this.name = name;
40 | }
41 |
42 | /*
43 | Accessor Section
44 | */
45 |
46 | /**
47 | Returns the name of the property whose changes this object listens for.
48 |
49 | @return The name of the property whose changes this object listens for.
50 | */
51 | public String name()
52 | {
53 | return name;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/ContextRandomSeedChangeListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | import java.beans.PropertyChangeEvent;
18 |
19 | /**
20 | Property change listener for the bot.randomSeed
property. Updates the Context's internal {@link java.util.Random} object with the new random seed.
21 | */
22 | public class ContextRandomSeedChangeListener extends ContextPropertyChangeListener
23 | {
24 | /*
25 | Constructor Section
26 | */
27 |
28 | /**
29 | Default class constructor.
30 | */
31 | public ContextRandomSeedChangeListener()
32 | {
33 | super("bot.randomSeed");
34 | }
35 |
36 | /*
37 | Method Section
38 | */
39 |
40 | // Fired when the bot.randomSeed property changes.
41 | public void propertyChange(PropertyChangeEvent event)
42 | {
43 | Context context = (Context) event.getSource();
44 | Object oldSeed = event.getOldValue();
45 | Object newSeed = event.getNewValue();
46 |
47 | if (oldSeed == null ? newSeed == null : oldSeed.equals(newSeed))
48 | return;
49 |
50 | long seed = Long.parseLong(newSeed.toString());
51 | context.random(seed);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/ContextTopicChangeListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 H�lio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | import bitoflife.chatterbean.text.Sentence;
18 | import bitoflife.chatterbean.text.Transformations;
19 |
20 | import java.beans.PropertyChangeEvent;
21 |
22 | import static bitoflife.chatterbean.text.Sentence.ASTERISK;
23 |
24 | /**
25 | Property change listener for the predicate.topic
property. Updates the Context with the new Topic value.
26 | */
27 | public class ContextTopicChangeListener extends ContextPropertyChangeListener
28 | {
29 | /*
30 | Constructor Section
31 | */
32 |
33 | /**
34 | Default class constructor.
35 | */
36 | public ContextTopicChangeListener()
37 | {
38 | super("predicate.topic");
39 | }
40 |
41 | /*
42 | Method Section
43 | */
44 |
45 | // Fired when the predicate.topic property changes.
46 | public void propertyChange(PropertyChangeEvent event)
47 | {
48 | Object oldTopic = event.getOldValue();
49 | Object newTopic = event.getNewValue();
50 | Context context = (Context) event.getSource();
51 | Transformations transformations = context.getTransformations();
52 |
53 | if (oldTopic == null ? newTopic == null : oldTopic.equals(newTopic))
54 | return;
55 |
56 | String input = newTopic.toString().trim();
57 | if ("".equals(input) || "*".equals(input))
58 | context.setTopic(ASTERISK);
59 | else
60 | {
61 | Sentence topic = new Sentence(input);
62 | transformations.normalization(topic);
63 | context.setTopic(topic);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/GraphmasterMother.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | import bitoflife.chatterbean.aiml.Category;
18 | import bitoflife.chatterbean.aiml.Star;
19 |
20 | public class GraphmasterMother
21 | {
22 | /*
23 | Methods
24 | */
25 |
26 | public Graphmaster newInstance()
27 | {
28 | Graphmaster root = new Graphmaster();
29 |
30 | root.append(new Category(" SAY _ AGAIN ", "What, again? \"", new Star(1), "\"."));
31 | root.append(new Category(" SAY IT NOW ", "Whatever you want..."));
32 | root.append(new Category(" SAY * ", new Star(1), "!"));
33 | root.append(new Category(" DO YOU SEE THE * IN MY EYES ", "Yes, I see the ", new Star(1), " in your eyes."));
34 |
35 | return root;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/GraphmasterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | import bitoflife.chatterbean.aiml.Category;
18 | import bitoflife.chatterbean.aiml.Pattern;
19 | import bitoflife.chatterbean.aiml.Template;
20 | import bitoflife.chatterbean.aiml.That;
21 | import bitoflife.chatterbean.text.Sentence;
22 | import junit.framework.TestCase;
23 |
24 | import static bitoflife.chatterbean.text.Sentence.ASTERISK;
25 |
26 | public class GraphmasterTest extends TestCase
27 | {
28 | /*
29 | Attributes
30 | */
31 |
32 | private final GraphmasterMother mother = new GraphmasterMother();
33 |
34 | private Graphmaster root;
35 |
36 | /*
37 | Events
38 | */
39 |
40 | protected void setUp()
41 | {
42 | root = mother.newInstance();
43 | }
44 |
45 | protected void tearDown()
46 | {
47 | root = null;
48 | }
49 |
50 | /*
51 | Methods
52 | */
53 |
54 | public void testMatch()
55 | {
56 | Category category;
57 | Match match;
58 |
59 | match = new Match(new Sentence(" Say goodbye again. ", new Integer[] {0, 4, 12, 19}, " SAY GOODBYE AGAIN "));
60 | category = root.match(match);
61 | assertNotNull(category);
62 | assertEquals("What, again? \"goodbye\".", category.process(match));
63 |
64 | match = new Match(new Sentence(" Say it now. ", new Integer[] {0, 4, 7, 12}, " SAY IT NOW "));
65 | category = root.match(match);
66 | assertNotNull(category);
67 | assertEquals("Whatever you want...", category.process(match));
68 |
69 | match = new Match(new Sentence(" Say goodbye. ", new Integer[] {0, 4, 13}, " SAY GOODBYE "));
70 | category = root.match(match);
71 | assertNotNull(category);
72 | assertEquals("goodbye!", category.process(match));
73 |
74 | match = new Match(
75 | new Sentence(" Do you see the fire in my eyes? ",
76 | new Integer[] {0, 3, 7, 11, 15, 20, 23, 26, 32},
77 | " DO YOU SEE THE FIRE IN MY EYES "));
78 |
79 | category = root.match(match);
80 | assertNotNull(category);
81 | assertEquals("Yes, I see the fire in your eyes.", category.process(match));
82 | }
83 |
84 | public void testThatMatch()
85 | {
86 | Sentence input = new Sentence(" Do you like it? ", new Integer[] {0, 3, 12, 16}, " DO YOU LIKE IT ");
87 | Sentence that = new Sentence(" CHEESE ", new Integer[] {0, 7}, " CHEESE ");
88 | Match match = new Match(null, input, that, ASTERISK);
89 |
90 | Category expected = new Category(new Pattern("DO YOU LIKE IT"), new That("CHEESE"), new Template("Yes."));
91 | root.append(expected);
92 | Category actual = root.match(match);
93 |
94 | assertEquals(expected, actual);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/Logger.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | import java.io.IOException;
18 | import java.io.PrintWriter;
19 | import java.io.Writer;
20 | import java.text.DateFormat;
21 | import java.text.SimpleDateFormat;
22 | import java.util.Date;
23 |
24 | /**
25 | Log file generator.
26 | */
27 | public class Logger
28 | {
29 | /*
30 | Attributes
31 | */
32 |
33 | private static final DateFormat date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
34 |
35 | private PrintWriter writer;
36 |
37 | /*
38 | Constructor
39 | */
40 |
41 | /**
42 | Constructs a new Log on the given directory.
43 | */
44 | public Logger(Writer writer)
45 | {
46 | this.writer = new PrintWriter(writer, true);
47 | }
48 |
49 | /*
50 | Methods
51 | */
52 |
53 | /**
54 | Adds an entry to this Log.
55 | */
56 | public void append(String request, String response) throws IOException
57 | {
58 | String now = date.format(new Date());
59 |
60 | writer.println("[" + now + "][" + request + "][" + response + "]");
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/LoggerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | import bitoflife.chatterbean.util.Sequence;
18 | import junit.framework.TestCase;
19 |
20 | import java.io.*;
21 |
22 | public class LoggerTest extends TestCase
23 | {
24 | /*
25 | Attributes
26 | */
27 |
28 | private File file;
29 | private Logger logger;
30 |
31 | /*
32 | Events
33 | */
34 |
35 | protected void setUp() throws Exception
36 | {
37 | Sequence sequence = new Sequence("Logs/sequence.txt");
38 | file = new File("Logs/log" + sequence.getNext() + ".txt");
39 | logger = new Logger(new FileWriter(file));
40 | }
41 |
42 | protected void tearDown()
43 | {
44 | file = null;
45 | logger = null;
46 | }
47 |
48 | /*
49 | Methods
50 | */
51 |
52 | public void testAddEntry() throws IOException
53 | {
54 | logger.append("First request", "First response");
55 | logger.append("Second request", "Second response");
56 | logger.append("Third request", "Third response");
57 |
58 | BufferedReader reader = new BufferedReader(new FileReader(file));
59 |
60 | assertTrue(reader.readLine().matches("\\[[0-9]{2}/[0-9]{2}/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}\\]" +
61 | "\\[First request\\]\\[First response\\]"));
62 |
63 | assertTrue(reader.readLine().matches("\\[[0-9]{2}/[0-9]{2}/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}\\]" +
64 | "\\[Second request\\]\\[Second response\\]"));
65 |
66 | assertTrue(reader.readLine().matches("\\[[0-9]{2}/[0-9]{2}/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}\\]" +
67 | "\\[Third request\\]\\[Third response\\]"));
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/MatchTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean;
16 |
17 | import bitoflife.chatterbean.text.Sentence;
18 | import junit.framework.TestCase;
19 |
20 | import java.util.Arrays;
21 |
22 | public class MatchTest extends TestCase
23 | {
24 | /*
25 | Methods
26 | */
27 |
28 | public void testMatchPath()
29 | {
30 | Match match = new Match(new Sentence(" Say goodbye again. ", new Integer[] {0, 4, 12, 19}, " SAY GOODBYE AGAIN "));
31 |
32 | String[] expected = {"SAY", "GOODBYE", "AGAIN", "", "*", "", "*"};
33 | String[] actual = match.getMatchPath();
34 | assertTrue(Arrays.toString(expected) + ' ' + Arrays.toString(actual), Arrays.equals(expected, actual));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/AIMLElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@bol.com.br
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import java.util.List;
18 |
19 | public interface AIMLElement {
20 |
21 | public void appendChild(AIMLElement child);
22 |
23 | public void appendChildren(List children);
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/AIMLParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Graphmaster;
18 | import bitoflife.chatterbean.util.Searcher;
19 |
20 | import javax.xml.parsers.SAXParser;
21 | import javax.xml.parsers.SAXParserFactory;
22 | import java.io.InputStream;
23 |
24 | public class AIMLParser {
25 | /*
26 | Attributes
27 | */
28 |
29 | private final Searcher searcher = new Searcher();
30 | private final AIMLHandler handler = new AIMLHandler();
31 | private SAXParser parser;
32 |
33 | /*
34 | Constructor
35 | */
36 |
37 | public AIMLParser() throws AIMLParserConfigurationException {
38 | try {
39 | parser = SAXParserFactory.newInstance().newSAXParser();
40 | } catch (Exception e) {
41 | throw new AIMLParserConfigurationException(e);
42 | }
43 | }
44 |
45 | /*
46 | Methods
47 | */
48 |
49 | public void parse(Graphmaster graphmaster, InputStream... sources) throws AIMLParserException {
50 | try {
51 | for (InputStream aiml : sources) {
52 | parser.parse(aiml, handler);
53 | }
54 |
55 | graphmaster.append(handler.unload());
56 | } catch (Exception e) {
57 | e.printStackTrace();
58 | throw new AIMLParserException(e);
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/AIMLParserConfigurationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | public class AIMLParserConfigurationException extends Exception
18 | {
19 | /*
20 | Attribute Section
21 | */
22 |
23 | private static final long serialVersionUID = 7L;
24 |
25 | /*
26 | Constructor Section
27 | */
28 |
29 | public AIMLParserConfigurationException(Exception e)
30 | {
31 | super(e);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/AIMLParserException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | public class AIMLParserException extends Exception
18 | {
19 | /*
20 | Attribute Section
21 | */
22 |
23 | private static final long serialVersionUID = 7L;
24 |
25 | /*
26 | Constructor Section
27 | */
28 |
29 | public AIMLParserException(Exception e)
30 | {
31 | super(e);
32 | }
33 |
34 | public AIMLParserException(String message)
35 | {
36 | super(message);
37 | }
38 |
39 | public AIMLParserException(String message, Throwable cause)
40 | {
41 | super(message, cause);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/AIMLStack.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@bol.com.br
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import java.util.LinkedList;
18 | import java.util.List;
19 |
20 | public class AIMLStack
21 | {
22 | /*
23 | Attributes
24 | */
25 |
26 | private final List stack = new LinkedList();
27 |
28 | /*
29 | Methods
30 | */
31 |
32 | public Object peek()
33 | {
34 | return stack.get(0);
35 | }
36 |
37 | public Object pop()
38 | {
39 | return (stack.size() > 0 ? stack.remove(0) : null);
40 | }
41 |
42 | public void push(Object element)
43 | {
44 | stack.add(0, element);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Aiml.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import org.xml.sax.Attributes;
18 |
19 | import java.util.Arrays;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | public class Aiml implements AIMLElement {
24 | /*
25 | Attributes
26 | */
27 |
28 | private final Topic defaultTopic = new Topic("*");
29 | private final List topics = new LinkedList(Arrays.asList(new Topic[]{defaultTopic}));
30 |
31 | private final List categories = new LinkedList();
32 |
33 | private String version;
34 |
35 | /*
36 | Constructors
37 | */
38 |
39 | public Aiml(Attributes attributes) {
40 | version = attributes.getValue(0);
41 | }
42 |
43 | public Aiml(Category... categories) {
44 | this.categories.addAll(Arrays.asList(categories));
45 | }
46 |
47 | /*
48 | Method Section
49 | */
50 |
51 | public void appendChild(AIMLElement child) {
52 | if (child instanceof Category) {
53 | Category category = (Category) child;
54 | category.setTopic(defaultTopic);
55 | defaultTopic.appendChild(category);
56 | categories.add(category);
57 | } else {
58 | Topic topic = (Topic) child;
59 | topics.add(topic);
60 | categories.addAll(topic.categories());
61 | }
62 | }
63 |
64 | public void appendChildren(List children) {
65 | for (AIMLElement child : children)
66 | appendChild(child);
67 | }
68 |
69 | public List children() {
70 | return categories;
71 | }
72 |
73 | public boolean equals(Object obj) {
74 | if (obj == null || !(obj instanceof Aiml))
75 | return false;
76 | else
77 | return categories.equals(((Aiml) obj).categories);
78 | }
79 |
80 | public String toString() {
81 | StringBuilder result = new StringBuilder();
82 | for (Category i : categories) {
83 | result.append(i);
84 | result.append('\n');
85 | }
86 |
87 | return result.toString();
88 | }
89 |
90 | /*
91 | Properties
92 | */
93 |
94 | public String getVersion() {
95 | return version;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Bot.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | public class Bot extends TemplateElement
21 | {
22 | /*
23 | Attributes
24 | */
25 |
26 | private String name;
27 |
28 | /*
29 | Constructors
30 | */
31 |
32 | public Bot(Attributes attributes)
33 | {
34 | name = attributes.getValue(0);
35 | }
36 |
37 | public Bot(String name)
38 | {
39 | this.name = name;
40 | }
41 |
42 | /*
43 | Methods
44 | */
45 |
46 | public boolean equals(Object obj)
47 | {
48 | return (super.equals(obj) && name.equals(((Bot) obj).name));
49 | }
50 |
51 | public int hashCode()
52 | {
53 | return name.hashCode();
54 | }
55 |
56 | public String process(Match match)
57 | {
58 | try
59 | {
60 | String value = (String) match.getCallback().getContext().property("bot." + name);
61 | return (value != null ? value : "");
62 | }
63 | catch (NullPointerException e)
64 | {
65 | return "";
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/CategoryTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import junit.framework.TestCase;
18 |
19 | import java.util.Arrays;
20 |
21 | public class CategoryTest extends TestCase
22 | {
23 | /*
24 | Methods
25 | */
26 |
27 | public void testGetMatchPath()
28 | {
29 | Category category = new Category(
30 | new Pattern(" YES "),
31 | new That(" DO YOU LIKE CHEESE "),
32 | new Topic(" LIKE "),
33 | new Template("Good for you.", new Think(new Set("topic", "*")))
34 | );
35 |
36 | String[] expected = {"YES", "", "DO", "YOU", "LIKE", "CHEESE", "", "LIKE"};
37 | String[] actual = category.getMatchPath();
38 | assertEquals(Arrays.toString(actual), expected.length, actual.length);
39 | for (int i = 0, n = expected.length; i < n; i++)
40 | assertEquals(expected[i], actual[i]);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Date.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | import java.text.SimpleDateFormat;
21 |
22 | public class Date extends TemplateElement
23 | {
24 | /*
25 | Attributes
26 | */
27 |
28 | private final SimpleDateFormat format = new SimpleDateFormat();
29 |
30 | /*
31 | Constructors
32 | */
33 |
34 | public Date()
35 | {
36 | }
37 |
38 | public Date(Attributes attributes)
39 | {
40 | }
41 |
42 | /*
43 | Methods
44 | */
45 |
46 | public int hashCode()
47 | {
48 | return 13;
49 | }
50 |
51 | public String process(Match match)
52 | {
53 | try
54 | {
55 | format.applyPattern((String) match.getCallback().getContext().property("predicate.dateFormat"));
56 | return format.format(new java.util.Date());
57 | }
58 | catch (NullPointerException e)
59 | {
60 | return "";
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Formal.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | import java.util.regex.Matcher;
21 | import java.util.regex.Pattern;
22 |
23 | public class Formal extends TemplateElement
24 | {
25 | /*
26 | Constructors
27 | */
28 |
29 | public Formal(Attributes attributes)
30 | {
31 | }
32 |
33 | public Formal(Object... children)
34 | {
35 | super(children);
36 | }
37 |
38 | /*
39 | Methods
40 | */
41 |
42 | public String process(Match match)
43 | {
44 | String result = super.process(match);
45 | if (result == null || "".equals(result.trim())) return "";
46 |
47 | /* See the description of java.util.regex.Matcher.appendReplacement() in the Javadocs to understand this code. */
48 | Pattern p = Pattern.compile("(^\\s*[a-z]|\\s+[a-z])");
49 | Matcher m = p.matcher(result);
50 | StringBuffer buffer = new StringBuffer();
51 | while (m.find())
52 | m.appendReplacement(buffer, m.group().toUpperCase());
53 | m.appendTail(buffer);
54 | return buffer.toString();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Gender.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Match;
19 | import bitoflife.chatterbean.text.Transformations;
20 | import org.xml.sax.Attributes;
21 |
22 | public class Gender extends TemplateElement
23 | {
24 | /*
25 | Constructor Section
26 | */
27 |
28 | public Gender(Attributes attributes)
29 | {
30 | }
31 |
32 | public Gender(Object... children)
33 | {
34 | super(children);
35 | }
36 |
37 | /*
38 | Method Section
39 | */
40 |
41 | public String process(Match match)
42 | {
43 | String input = super.process(match);
44 | AliceBot bot = match.getCallback();
45 | Transformations transformations = bot.transformations();
46 | return transformations.gender(input);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Get.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | public class Get extends TemplateElement
21 | {
22 | /*
23 | Attributes
24 | */
25 |
26 | private String name;
27 |
28 | /*
29 | Constructors
30 | */
31 |
32 | public Get(Attributes attributes)
33 | {
34 | name = attributes.getValue(0);
35 | }
36 |
37 | public Get(String name)
38 | {
39 | this.name = name;
40 | }
41 |
42 | /*
43 | Methods
44 | */
45 |
46 | public boolean equals(Object compared)
47 | {
48 | if (compared == null || !(compared instanceof Get))
49 | return false;
50 | else
51 | return name.equals(((Get) compared).name);
52 | }
53 |
54 | public int hashCode()
55 | {
56 | return name.hashCode();
57 | }
58 |
59 | public String process(Match match)
60 | {
61 | try
62 | {
63 | String value = (String) match.getCallback().getContext().property("predicate." + name);
64 | return (value != null ? value : "");
65 | }
66 | catch (NullPointerException e)
67 | {
68 | return "";
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Gossip.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Context;
19 | import bitoflife.chatterbean.Match;
20 | import org.xml.sax.Attributes;
21 |
22 | public class Gossip extends TemplateElement
23 | {
24 | /*
25 | Constructors
26 | */
27 |
28 | public Gossip(Attributes attributes)
29 | {
30 | }
31 |
32 | public Gossip(Object... children)
33 | {
34 | super(children);
35 | }
36 |
37 | /*
38 | Methods
39 | */
40 |
41 | public String process(Match match)
42 | {
43 | AliceBot bot = null;
44 | Context context = null;
45 | if (match != null) try
46 | {
47 | bot = match.getCallback();
48 | context = bot.getContext();
49 | context.print(super.process(match));
50 | }
51 | catch (Exception e)
52 | {
53 | throw new RuntimeException(e);
54 | }
55 |
56 | return "";
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Id.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Context;
19 | import bitoflife.chatterbean.Match;
20 | import org.xml.sax.Attributes;
21 |
22 | public class Id extends TemplateElement
23 | {
24 | /*
25 | Constructors
26 | */
27 |
28 | public Id()
29 | {
30 | }
31 |
32 | public Id(Attributes attributes)
33 | {
34 | }
35 |
36 | /*
37 | Methods
38 | */
39 |
40 | public boolean equals(Object obj)
41 | {
42 | if (!super.equals(obj))
43 | return false;
44 | else
45 | return toString().equals(obj.toString());
46 | }
47 |
48 | public int hashCode()
49 | {
50 | return process(null).hashCode();
51 | }
52 |
53 | public String process(Match match)
54 | {
55 | if (match == null) return "unknown";
56 | AliceBot bot = match.getCallback();
57 | Context context = bot.getContext();
58 | return context.id();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Input.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import bitoflife.chatterbean.text.Request;
19 | import org.xml.sax.Attributes;
20 |
21 | public class Input extends TemplateElement
22 | {
23 | /*
24 | Attributes
25 | */
26 |
27 | private int requestIndex = 1, sentenceIndex = 1;
28 |
29 | /*
30 | Constructors
31 | */
32 |
33 | public Input(Attributes attributes)
34 | {
35 | String value = attributes.getValue(0);
36 | if (value == null) return;
37 |
38 | String[] indexes = value.split(",");
39 | requestIndex = Integer.parseInt(indexes[0].trim());
40 | if (indexes.length > 1) sentenceIndex = Integer.parseInt(indexes[1].trim());
41 | }
42 |
43 | public Input(int requestIndex, int sentenceIndex)
44 | {
45 | this.requestIndex = requestIndex;
46 | this.sentenceIndex = sentenceIndex;
47 | }
48 |
49 | /*
50 | Methods
51 | */
52 |
53 | public boolean equals(Object obj)
54 | {
55 | if (!super.equals(obj)) return false;
56 |
57 | Input compared = (Input) obj;
58 | return (requestIndex == compared.requestIndex &&
59 | sentenceIndex == compared.sentenceIndex);
60 | }
61 |
62 | public String toString()
63 | {
64 | return " ";
65 | }
66 |
67 | public String process(Match match)
68 | {
69 | if (match == null) return "";
70 | Request request = match.getCallback().getContext().getRequests(requestIndex - 1);
71 | return request.lastSentence(sentenceIndex - 1).trimOriginal();
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Javascript.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Context;
19 | import bitoflife.chatterbean.Match;
20 | import bitoflife.chatterbean.script.Interpreter;
21 | import org.xml.sax.Attributes;
22 |
23 | public class Javascript extends TemplateElement
24 | {
25 | /*
26 | Constructor Section
27 | */
28 |
29 | public Javascript(Attributes attributes)
30 | {
31 | }
32 |
33 | public Javascript(Object... children)
34 | {
35 | super(children);
36 | }
37 |
38 | /*
39 | Method Section
40 | */
41 |
42 | public String process(Match match)
43 | {
44 | try
45 | {
46 | AliceBot bot = match.getCallback();
47 | Context context = bot.getContext();
48 | Interpreter interpreter = (Interpreter) context.property("javascript.interpreter");
49 | if (interpreter == null)
50 | return "";
51 |
52 | String script = super.process(match);
53 | interpreter.variable("result", null);
54 | Object evaluated = interpreter.evaluate(script);
55 | Object result = interpreter.variable("result");
56 | if (result == null) result = evaluated;
57 |
58 | return (result != null ? result.toString() : "");
59 | }
60 | catch (Exception e)
61 | {
62 | throw new RuntimeException("Evaluation error on tag", e);
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Learn.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Graphmaster;
19 | import bitoflife.chatterbean.Match;
20 | import org.xml.sax.Attributes;
21 |
22 | import java.net.URL;
23 |
24 | public class Learn extends TemplateElement
25 | {
26 | /*
27 | Constructors
28 | */
29 |
30 | public Learn(Attributes attributes)
31 | {
32 | }
33 |
34 | public Learn(Object... children)
35 | {
36 | super(children);
37 | }
38 |
39 | /*
40 | Methods
41 | */
42 |
43 | public String process(Match match)
44 | {
45 | AliceBot bot = null;
46 | try
47 | {
48 | bot = match.getCallback();
49 | Graphmaster graphmaster = bot.getGraphmaster();
50 |
51 | String address = super.process(match);
52 | URL url = new URL(address);
53 |
54 | AIMLParser parser = new AIMLParser();
55 | parser.parse(graphmaster, url.openStream());
56 | }
57 | catch (Exception e)
58 | {
59 | throw new RuntimeException(e);
60 | }
61 |
62 | return "";
63 | }
64 | }
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Li.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import org.xml.sax.Attributes;
18 |
19 | public class Li extends TemplateElement
20 | {
21 | /*
22 | Attributes
23 | */
24 |
25 | private String name;
26 | private String value;
27 |
28 |
29 | /*
30 | Constructors
31 | */
32 |
33 | public Li()
34 | {
35 | }
36 |
37 | public Li(Attributes attributes)
38 | {
39 | name = attributes.getValue("name");
40 | value = attributes.getValue("value");
41 | }
42 |
43 | public Li(String name, String value, Object... children)
44 | {
45 | super(children);
46 | this.name = name;
47 | this.value = value;
48 | }
49 |
50 | /*
51 | Methods
52 | */
53 |
54 | private boolean isEquals(Object comparing, Object compared)
55 | {
56 | return (comparing == null ? compared == null : comparing.equals(compared));
57 | }
58 |
59 | public boolean equals(Object obj)
60 | {
61 | if (!super.equals(obj)) return false;
62 | Li compared = (Li) obj;
63 | return (isEquals(name, compared.name) && isEquals(value, compared.value));
64 | }
65 |
66 | /*
67 | Properties
68 | */
69 |
70 | public String getName()
71 | {
72 | return name;
73 | }
74 |
75 | public void setName(String name)
76 | {
77 | this.name = name;
78 | }
79 |
80 | public String getValue()
81 | {
82 | return value;
83 | }
84 |
85 | public void setValue(String value)
86 | {
87 | this.value = value;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Lowercase.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | public class Lowercase extends TemplateElement
21 | {
22 | /*
23 | Constructors
24 | */
25 |
26 | public Lowercase(Attributes attributes)
27 | {
28 | }
29 |
30 | public Lowercase(Object... children)
31 | {
32 | super(children);
33 | }
34 |
35 | /*
36 | Methods
37 | */
38 |
39 | public String process(Match match)
40 | {
41 | String result = super.process(match);
42 | if (result != null)
43 | return result.toLowerCase();
44 | else
45 | return "";
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Pattern.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import org.xml.sax.Attributes;
18 |
19 | import java.lang.System;
20 | import java.util.Arrays;
21 | import java.util.List;
22 |
23 | public class Pattern implements AIMLElement
24 | {
25 | /*
26 | Attribute Section
27 | */
28 |
29 | private String[] pattern;
30 |
31 | private int hashCode;
32 |
33 | /*
34 | Constructor Section
35 | */
36 |
37 | public Pattern()
38 | {
39 | }
40 |
41 | public Pattern(String pattern)
42 | {
43 | this.pattern = pattern.trim().split(" ");
44 | hashCode = Arrays.hashCode(this.pattern);
45 | }
46 |
47 | public Pattern(Attributes attributes)
48 | {
49 | }
50 |
51 | /*
52 | Method Section
53 | */
54 |
55 | public void appendChild(AIMLElement child)
56 | {
57 | String text = child.toString();
58 | if (pattern == null)
59 | pattern = new String[] {text};
60 | else
61 | {
62 | int length = pattern.length;
63 | String[] larger = new String[length + 1];
64 | System.arraycopy(pattern, 0, larger, 0, length);
65 | larger[length] = text;
66 | pattern = larger;
67 | }
68 | }
69 |
70 | public void appendChildren(List children)
71 | {
72 | StringBuilder builder = new StringBuilder();
73 | for (AIMLElement child : children)
74 | builder.append(child);
75 |
76 | String text = builder.toString().trim();
77 | pattern = text.split(" ");
78 | hashCode = Arrays.hashCode(pattern);
79 | }
80 |
81 | public boolean equals(Object obj)
82 | {
83 | if (obj == null || !(obj instanceof Pattern)) return false;
84 | Pattern compared = (Pattern) obj;
85 | return Arrays.equals(pattern, compared.pattern);
86 | }
87 |
88 | public int hashCode()
89 | {
90 | return hashCode;
91 | }
92 |
93 | public String toString()
94 | {
95 | StringBuilder buffer = new StringBuilder();
96 | for (int i = 0, n = pattern.length;;)
97 | {
98 | buffer.append(pattern[i]);
99 | if (++i >= n) break;
100 | buffer.append(" ");
101 | }
102 |
103 | return buffer.toString();
104 | }
105 |
106 | /*
107 | Property Section
108 | */
109 |
110 | public String[] getElements()
111 | {
112 | return pattern;
113 | }
114 |
115 | public void setElements(String[] pattern)
116 | {
117 | this.pattern = pattern;
118 | hashCode = Arrays.hashCode(pattern);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Person.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Match;
19 | import bitoflife.chatterbean.text.Transformations;
20 | import org.xml.sax.Attributes;
21 |
22 | public class Person extends TemplateElement
23 | {
24 | /*
25 | Constructor Section
26 | */
27 |
28 | public Person(Attributes attributes)
29 | {
30 | }
31 |
32 | public Person(Object... children)
33 | {
34 | super(children);
35 | }
36 |
37 | /*
38 | Method Section
39 | */
40 |
41 | public String process(Match match)
42 | {
43 | String input = super.process(match);
44 | AliceBot bot = match.getCallback();
45 | Transformations transformations = bot.transformations();
46 | return transformations.person(input);
47 | }
48 | }
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Person2.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Match;
19 | import bitoflife.chatterbean.text.Transformations;
20 | import org.xml.sax.Attributes;
21 |
22 | public class Person2 extends TemplateElement
23 | {
24 | /*
25 | Constructor Section
26 | */
27 |
28 | public Person2(Attributes attributes)
29 | {
30 | }
31 |
32 | public Person2(Object... children)
33 | {
34 | super(children);
35 | }
36 |
37 | /*
38 | Method Section
39 | */
40 |
41 | public String process(Match match)
42 | {
43 | String input = super.process(match);
44 | AliceBot bot = match.getCallback();
45 | Transformations transformations = bot.transformations();
46 | return transformations.person2(input);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Random.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Context;
19 | import bitoflife.chatterbean.Match;
20 | import org.xml.sax.Attributes;
21 |
22 | public class Random extends TemplateElement
23 | {
24 | /*
25 | Constructor
26 | */
27 |
28 | public Random()
29 | {
30 | }
31 |
32 | public Random(Attributes attributes)
33 | {
34 | }
35 |
36 | public Random(Object... children)
37 | {
38 | super(children);
39 | }
40 |
41 | /*
42 | Methods
43 | */
44 |
45 | public String process(Match match)
46 | {
47 | AliceBot bot = match.getCallback();
48 | Context context = bot.getContext();
49 | java.util.Random random = context.random();
50 |
51 | int n = children().size();
52 | TemplateElement child = getChildren(random.nextInt(n));
53 | return child.process(match);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Sentence.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | import java.util.regex.Matcher;
21 | import java.util.regex.Pattern;
22 |
23 | public class Sentence extends TemplateElement
24 | {
25 | /*
26 | Constructors
27 | */
28 |
29 | public Sentence(Attributes attributes)
30 | {
31 | }
32 |
33 | public Sentence(Object... children)
34 | {
35 | super(children);
36 | }
37 |
38 | /*
39 | Methods
40 | */
41 |
42 | public String process(Match match)
43 | {
44 | String result = super.process(match);
45 | if (result == null || "".equals(result.trim())) return "";
46 |
47 | /* See the description of java.util.regex.Matcher.appendReplacement() in the Javadocs to understand this code. */
48 | Pattern p = Pattern.compile("(^\\s*[a-z]|[\\.\\?!]+\\s*[a-z])");
49 | Matcher m = p.matcher(result);
50 | StringBuffer buffer = new StringBuffer();
51 | while (m.find())
52 | m.appendReplacement(buffer, m.group().toUpperCase());
53 | m.appendTail(buffer);
54 | return buffer.toString();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Set.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Context;
19 | import bitoflife.chatterbean.Match;
20 | import org.xml.sax.Attributes;
21 |
22 | public class Set extends TemplateElement
23 | {
24 | /*
25 | Attributes
26 | */
27 |
28 | private String name;
29 |
30 | /*
31 | Constructors
32 | */
33 |
34 | public Set(Attributes attributes)
35 | {
36 | name = attributes.getValue(0);
37 | }
38 |
39 | public Set(String name, Object... children)
40 | {
41 | super(children);
42 | this.name = name;
43 | }
44 |
45 | /*
46 | Methods
47 | */
48 |
49 | public boolean equals(Object obj)
50 | {
51 | if (obj == null) return false;
52 | Set compared = (Set) obj;
53 | if (!name.equals(compared.name)) return false;
54 | return super.equals(compared);
55 | }
56 |
57 | public String process(Match match)
58 | {
59 | String output = super.process(match);
60 | if (match == null)
61 | output = "" + output + " ";
62 | else
63 | {
64 | AliceBot bot = match.getCallback();
65 | Context context = (bot != null ? bot.getContext() : null);
66 | if (context != null) context.property("predicate." + name, output);
67 | }
68 |
69 | return output;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Size.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | public class Size extends TemplateElement
21 | {
22 | /*
23 | Constructors
24 | */
25 |
26 | public Size()
27 | {
28 | }
29 |
30 | public Size(Attributes attributes)
31 | {
32 | }
33 |
34 | /*
35 | Methods
36 | */
37 |
38 | public String process(Match match)
39 | {
40 | try
41 | {
42 | return Integer.toString(match.getCallback().getGraphmaster().size());
43 | }
44 | catch (NullPointerException e)
45 | {
46 | return "0";
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Sr.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import org.xml.sax.Attributes;
18 |
19 | public class Sr extends Srai
20 | {
21 | /*
22 | Constructors
23 | */
24 |
25 | public Sr(Attributes attributes)
26 | {
27 | super(attributes);
28 | setChildren(new TemplateElement[] {new Star(attributes)});
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Srai.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Match;
19 | import org.xml.sax.Attributes;
20 |
21 | public class Srai extends TemplateElement {
22 | /*
23 | Constructor Section
24 | */
25 |
26 | public Srai(Attributes attributes) {
27 | }
28 |
29 | public Srai(Object... children) {
30 | super(children);
31 |
32 | }
33 |
34 | public Srai(int index) {
35 | super(new Star(index));
36 | }
37 |
38 |
39 |
40 | public String process(Match match) {
41 | String request = super.process(match);
42 |
43 | try {
44 | AliceBot bot = (match != null ? match.getCallback() : null);
45 | return (bot != null ? bot.respond(request) : "");
46 | } catch (Exception e) {
47 | throw new RuntimeException("While trying to respond \"" + request + "\"", e);
48 | }
49 | }
50 |
51 | public String toString() {
52 | return "" + super.toString() + " ";
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Star.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | import static bitoflife.chatterbean.Match.Section.PATTERN;
21 |
22 | public class Star extends TemplateElement
23 | {
24 | /*
25 | Attributes
26 | */
27 |
28 | private int index;
29 |
30 | /*
31 | Constructor
32 | */
33 |
34 | public Star(Attributes attributes)
35 | {
36 | String value = attributes.getValue(0);
37 | index = (value != null ? Integer.parseInt(value) : 1);
38 | }
39 |
40 | public Star(int index)
41 | {
42 | this.index = index;
43 | }
44 |
45 | /*
46 | Methods
47 | */
48 |
49 | public boolean equals(Object obj)
50 | {
51 | if (obj == null || !(obj instanceof Star))
52 | return false;
53 | else
54 | {
55 | Star star = (Star) obj;
56 | return (index == star.index);
57 | }
58 | }
59 |
60 | public int hashCode()
61 | {
62 | return index;
63 | }
64 |
65 | public String toString()
66 | {
67 | return " ";
68 | }
69 |
70 | public String process(Match match)
71 | {
72 | String wildcard = match.wildcard(PATTERN, index);
73 | return (wildcard != null ? wildcard.trim() : "");
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/System.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Context;
19 | import bitoflife.chatterbean.Match;
20 | import bitoflife.chatterbean.script.Interpreter;
21 | import org.xml.sax.Attributes;
22 |
23 | public class System extends TemplateElement
24 | {
25 | /*
26 | Constructors
27 | */
28 |
29 | public System(Attributes attributes)
30 | {
31 | }
32 |
33 | public System(Object... children)
34 | {
35 | super(children);
36 | }
37 |
38 | /*
39 | Methods
40 | */
41 |
42 | public String process(Match match)
43 | {
44 | try
45 | {
46 | AliceBot bot = match.getCallback();
47 | Context context = bot.getContext();
48 | Interpreter interpreter = (Interpreter) context.property("beanshell.interpreter");
49 | if (interpreter == null)
50 | return "";
51 |
52 | String script = super.process(match);
53 | interpreter.variable("result", null);
54 | interpreter.variable("match", match);
55 |
56 | Object evaluated = interpreter.evaluate(script);
57 | Object result = interpreter.variable("result");
58 | if (result == null) result = evaluated;
59 |
60 | interpreter.variable("match", null);
61 |
62 | return (result != null ? result.toString() : "");
63 | }
64 | catch (Exception e)
65 | {
66 | throw new RuntimeException("Evaluation error on tag", e);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/SystemTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Context;
19 | import bitoflife.chatterbean.Match;
20 | import junit.framework.TestCase;
21 |
22 | public class SystemTest extends TestCase
23 | {
24 | /*
25 | Attributes
26 | */
27 |
28 | private System tag;
29 |
30 | /*
31 | Events
32 | */
33 |
34 | protected void setUp()
35 | {
36 |
37 | }
38 |
39 | protected void tearDown()
40 | {
41 | tag = null;
42 | }
43 |
44 | /*
45 | Methods
46 | */
47 |
48 | public void testParse()
49 | {
50 | tag = new System("result = \"Hello System!\"");
51 | AliceBot bot = new AliceBot();
52 | bot.setContext(new Context());
53 | Match match = new Match();
54 | match.setCallback(bot);
55 |
56 | assertEquals("Hello System!", tag.process(match));
57 | }
58 |
59 | public void testArithmetics()
60 | {
61 | tag = new System("1 + 1");
62 | AliceBot bot = new AliceBot();
63 | bot.setContext(new Context());
64 | Match match = new Match();
65 | match.setCallback(bot);
66 |
67 | assertEquals("2", tag.process(match));
68 | }
69 | }
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Template.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import org.xml.sax.Attributes;
18 |
19 | public class Template extends TemplateElement
20 | {
21 | /*
22 | Constructor Section
23 | */
24 |
25 | public Template(Attributes attributes)
26 | {
27 | super();
28 | }
29 |
30 | public Template(Object... children)
31 | {
32 | super(children);
33 | }
34 |
35 | /*
36 | Method Section
37 | */
38 |
39 | public String toString()
40 | {
41 | StringBuilder value = new StringBuilder();
42 | value.append("");
43 | for (TemplateElement i : children())
44 | value.append(i.toString());
45 | value.append(" ");
46 |
47 | return value.toString();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/TemplateElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 |
19 | import java.util.Arrays;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | public class TemplateElement implements AIMLElement
24 | {
25 | /*
26 | Attribute Section
27 | */
28 |
29 | private static final TemplateElement[] TEMPLATE_ELEMENT_ARRAY = {};
30 |
31 | private final List children = new LinkedList();
32 |
33 | /*
34 | Constructor Section
35 | */
36 |
37 | public TemplateElement(Object... elements)
38 | {
39 | for (Object child : elements)
40 | {
41 | if (child instanceof AIMLElement)
42 | children.add((TemplateElement) child);
43 | else
44 | children.add(new Text(child.toString()));
45 | }
46 | }
47 |
48 | /*
49 | Method Section
50 | */
51 |
52 | public void appendChild(AIMLElement element)
53 | {
54 | children.add((TemplateElement) element);
55 | }
56 |
57 | public void appendChildren(List elements)
58 | {
59 | for (AIMLElement element : elements)
60 | children.add((TemplateElement) element);
61 | }
62 |
63 | public List children()
64 | {
65 | return children;
66 | }
67 |
68 | public boolean equals(Object object)
69 | {
70 | if (object == null || !(object instanceof TemplateElement))
71 | return false;
72 |
73 | TemplateElement that = (TemplateElement) object;
74 | return children.equals(that.children);
75 | }
76 |
77 | public int hashCode()
78 | {
79 | return children.hashCode();
80 | }
81 |
82 | public String process(Match match)
83 | {
84 | StringBuilder value = new StringBuilder();
85 | for (TemplateElement i : children)
86 | value.append(i.process(match));
87 |
88 | return value.toString();
89 | }
90 |
91 | /*
92 | Property Section
93 | */
94 |
95 | public TemplateElement[] getChildren()
96 | {
97 | return children.toArray(TEMPLATE_ELEMENT_ARRAY);
98 | }
99 |
100 | public TemplateElement getChildren(int index)
101 | {
102 | return children.get(index);
103 | }
104 |
105 | public void setChildren(TemplateElement[] elements)
106 | {
107 | children.clear();
108 | children.addAll(Arrays.asList(elements));
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/TemplateElementTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2006 Hélio Perroni Filho
3 | xperroni@bol.com.br
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import junit.framework.TestCase;
18 |
19 | public class TemplateElementTest extends TestCase
20 | {
21 | /*
22 | Test Section
23 | */
24 |
25 | public void testToString()
26 | {
27 | Template template = new Template("Hello ", new Star(1), ", nice to meet you.");
28 | assertEquals("Hello , nice to meet you. ", template.toString());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Text.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 |
19 | public class Text extends TemplateElement
20 | {
21 | /*
22 | Attributes
23 | */
24 |
25 | private final String value;
26 |
27 | /*
28 | Constructor
29 | */
30 |
31 | public Text(String value)
32 | {
33 | this.value = value;
34 | }
35 |
36 | /*
37 | Methods
38 | */
39 |
40 | public boolean equals(Object obj)
41 | {
42 | if (obj == null) return false;
43 | String text = obj.toString();
44 | return (text != null ? text.equals(value) : value == null);
45 | }
46 |
47 | public int hashCode()
48 | {
49 | return (value == null ? 0 : value.hashCode());
50 | }
51 |
52 | public String toString()
53 | {
54 | return value;
55 | }
56 |
57 | public String process(Match match)
58 | {
59 | return value;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Thatstar.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | import static bitoflife.chatterbean.Match.Section.THAT;
21 |
22 | public class Thatstar extends TemplateElement
23 | {
24 | /*
25 | Attribute Section
26 | */
27 |
28 | private int index;
29 |
30 | /*
31 | Constructor Section
32 | */
33 |
34 | public Thatstar(Attributes attributes)
35 | {
36 | String value = attributes.getValue(0);
37 | if (value == null)
38 | index = 1;
39 | else
40 | index = Integer.parseInt(value);
41 | }
42 |
43 | public Thatstar(int index)
44 | {
45 | this.index = index;
46 | }
47 |
48 | /*
49 | Method Section
50 | */
51 |
52 | public boolean equals(Object obj)
53 | {
54 | if (!super.equals(obj)) return false;
55 | Thatstar compared = (Thatstar) obj;
56 |
57 | return (index == compared.index);
58 | }
59 |
60 | public String toString()
61 | {
62 | return "";
63 | }
64 |
65 | public String process(Match match)
66 | {
67 | String wildcard = match.wildcard(THAT, index);
68 | return (wildcard != null ? wildcard.trim() : "");
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Think.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | public class Think extends TemplateElement
21 | {
22 | /*
23 | Constructors
24 | */
25 |
26 | public Think(Attributes attributes)
27 | {
28 | }
29 |
30 | public Think(Object... children)
31 | {
32 | super(children);
33 | }
34 |
35 | /*
36 | Methods
37 | */
38 |
39 | public String process(Match match)
40 | {
41 | super.process(match);
42 | return "";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Topic.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import org.xml.sax.Attributes;
18 |
19 | import java.util.Arrays;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | public class Topic implements AIMLElement
24 | {
25 | /*
26 | Attribute Section
27 | */
28 |
29 | private List categories = new LinkedList();
30 |
31 | private String name;
32 |
33 | /*
34 | Constructor Section
35 | */
36 |
37 | public Topic(Attributes attributes)
38 | {
39 | name(attributes.getValue(0));
40 | }
41 |
42 | public Topic(String name, Category... children)
43 | {
44 | name(name);
45 | categories.addAll(Arrays.asList(children));
46 | }
47 |
48 | /*
49 | Method Section
50 | */
51 |
52 | public void appendChild(AIMLElement child)
53 | {
54 | Category category = (Category) child;
55 | category.setTopic(this);
56 | categories.add(category);
57 | }
58 |
59 | public void appendChildren(List children)
60 | {
61 | for (AIMLElement child : children)
62 | appendChild(child);
63 | }
64 |
65 | public List categories()
66 | {
67 | return categories;
68 | }
69 |
70 | public String[] elements()
71 | {
72 | return name.split(" ");
73 | }
74 |
75 | public boolean equals(Object obj)
76 | {
77 | if (obj == null || !(obj instanceof Topic))
78 | return false;
79 | else
80 | {
81 | Topic compared = (Topic) obj;
82 | return (name.equals(compared.name) && categories.equals(compared.categories));
83 | }
84 | }
85 |
86 | public String toString()
87 | {
88 | StringBuilder result = new StringBuilder();
89 | for (Category i : categories)
90 | {
91 | result.append(i);
92 | result.append('\n');
93 | }
94 |
95 | return result.toString();
96 | }
97 |
98 | /*
99 | Acessor Section
100 | */
101 |
102 | private void name(String name)
103 | {
104 | this.name = name.trim();
105 | }
106 |
107 | /*
108 | Property Section
109 | */
110 |
111 | public String getName()
112 | {
113 | return name;
114 | }
115 |
116 | public void setName(String name)
117 | {
118 | this.name = name;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Topicstar.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | import static bitoflife.chatterbean.Match.Section.TOPIC;
21 |
22 | public class Topicstar extends TemplateElement
23 | {
24 | /*
25 | Attributes
26 | */
27 |
28 | private int index;
29 |
30 | /*
31 | Constructor
32 | */
33 |
34 | public Topicstar(Attributes attributes)
35 | {
36 | String value = attributes.getValue(0);
37 | if (value == null)
38 | index = 1;
39 | else
40 | index = Integer.parseInt(value);
41 | }
42 |
43 | public Topicstar(int index)
44 | {
45 | this.index = index;
46 | }
47 |
48 | /*
49 | Methods
50 | */
51 |
52 | public boolean equals(Object obj)
53 | {
54 | if (!super.equals(obj)) return false;
55 | Topicstar compared = (Topicstar) obj;
56 |
57 | return (index == compared.index);
58 | }
59 |
60 | public String toString()
61 | {
62 | return "";
63 | }
64 |
65 | public String process(Match match)
66 | {
67 | String wildcard = match.wildcard(TOPIC, index);
68 | return (wildcard != null ? wildcard.trim() : "");
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Uppercase.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.Match;
18 | import org.xml.sax.Attributes;
19 |
20 | public class Uppercase extends TemplateElement
21 | {
22 | /*
23 | Constructors
24 | */
25 |
26 | public Uppercase(Attributes attributes)
27 | {
28 | }
29 |
30 | public Uppercase(Object... children)
31 | {
32 | super(children);
33 | }
34 |
35 | /*
36 | Methods
37 | */
38 |
39 | public String process(Match match)
40 | {
41 | String result = super.process(match);
42 | if (result != null)
43 | return result.toUpperCase();
44 | else
45 | return "";
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/aiml/Version.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.aiml;
16 |
17 | import bitoflife.chatterbean.AliceBot;
18 | import bitoflife.chatterbean.Context;
19 | import bitoflife.chatterbean.Match;
20 | import org.xml.sax.Attributes;
21 |
22 | public class Version extends TemplateElement
23 | {
24 | /*
25 | Constructors
26 | */
27 |
28 | public Version()
29 | {
30 | }
31 |
32 | public Version(Attributes attributes)
33 | {
34 | }
35 |
36 | /*
37 | Methods
38 | */
39 |
40 | public String process(Match match)
41 | {
42 | AliceBot bot = match.getCallback();
43 | Context context = bot.getContext();
44 | return (String) context.property("bot.version");
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/config/ConfigException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.config;
16 |
17 | public class ConfigException extends Exception
18 | {
19 | /*
20 | Attribute Section
21 | */
22 |
23 | private static final long serialVersionUID = 7L;
24 |
25 | /*
26 | Constructor Section
27 | */
28 |
29 | /**
30 | Constructs a new exception with null
as its detail message. The cause is not initialized, and may subsequently be initialized by a call to initCause()
.
31 | */
32 | public ConfigException()
33 | {
34 | super("Configuration failed");
35 | }
36 |
37 | /**
38 | Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to initCause()
.
39 |
40 | @param message The detail message. The detail message is saved for later retrieval by the getMessage()
method.
41 | */
42 | public ConfigException(String message)
43 | {
44 | super(message);
45 | }
46 |
47 | /**
48 | Constructs a new exception with the specified detail message and cause. Note that the detail message associated with cause is not automatically incorporated in this exception's detail message.
49 |
50 | @param message The detail message, which is saved for later retrieval by the getMessage()
method.
51 | @param cause The cause, which is saved for later retrieval by the getCause()
method. A null
value is permitted, and indicates that the cause is nonexistent or unknown.
52 | */
53 | public ConfigException(String message, Throwable cause)
54 | {
55 | super(message, cause);
56 | }
57 |
58 | /**
59 | Constructs a new exception with the specified cause and a detail message of (cause == null ? null : cause.toString())
.
60 |
61 | @param cause The cause, which is saved for later retrieval by the getCause()
method. A null
value is permitted, and indicates that the cause is nonexistent or unknown.
62 | */
63 | public ConfigException(Throwable cause)
64 | {
65 | super(cause);
66 | }
67 |
68 | /**
69 | Constructs a new exception with the specified object as its cause. If the object is a Throwable
, it will be incorporated as this exception's cause; otherwise, the result of calling th method toString()
on it will be incorporated as the exception's message.
70 |
71 | @param cause The cause of the exception.
72 | */
73 | public ConfigException(Object cause)
74 | {
75 | this();
76 | if (cause instanceof Throwable)
77 | initCause((Throwable) cause);
78 | else
79 | initCause(new Exception(cause.toString()));
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/config/TokenizerConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.config;
16 |
17 | import bitoflife.chatterbean.text.Tokenizer;
18 |
19 | public interface TokenizerConfig
20 | {
21 | public Tokenizer newInstance();
22 |
23 | public String[] splitters();
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/config/TokenizerConfigStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.config;
16 |
17 | import bitoflife.chatterbean.text.Tokenizer;
18 | import org.xml.sax.Attributes;
19 | import org.xml.sax.SAXException;
20 | import org.xml.sax.helpers.DefaultHandler;
21 |
22 | import javax.xml.parsers.SAXParser;
23 | import javax.xml.parsers.SAXParserFactory;
24 | import java.io.InputStream;
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | public class TokenizerConfigStream extends DefaultHandler implements TokenizerConfig
29 | {
30 | /*
31 | Attribute Section
32 | */
33 |
34 | private static final String[] STRING_ARRAY = new String[0];
35 |
36 | private final SAXParser parser;
37 |
38 | private final List splitters = new ArrayList(6);
39 |
40 | private boolean ignoreWhitespace;
41 |
42 | /*
43 | Constructor Section
44 | */
45 |
46 | public TokenizerConfigStream() throws ConfigException
47 | {
48 | try
49 | {
50 | SAXParserFactory factory = SAXParserFactory.newInstance();
51 | parser = factory.newSAXParser();
52 | }
53 | catch (Exception e)
54 | {
55 | throw new ConfigException(e);
56 | }
57 | }
58 |
59 | public TokenizerConfigStream(InputStream input) throws ConfigException
60 | {
61 | try
62 | {
63 | SAXParserFactory factory = SAXParserFactory.newInstance();
64 | parser = factory.newSAXParser();
65 | parse(input);
66 | }
67 | catch (ConfigException e)
68 | {
69 | throw e;
70 | }
71 | catch (Exception e)
72 | {
73 | throw new ConfigException(e);
74 | }
75 | }
76 |
77 | /*
78 | Event Section
79 | */
80 |
81 | public void startElement(String namespace, String name, String qname, Attributes attributes) throws SAXException
82 | {
83 | if ("splitter".equals(qname))
84 | splitters.add(attributes.getValue(0));
85 | }
86 |
87 | /*
88 | Method Section
89 | */
90 |
91 | public Tokenizer newInstance()
92 | {
93 | return new Tokenizer(splitters());
94 | }
95 |
96 | public void parse(InputStream input) throws ConfigException
97 | {
98 | try
99 | {
100 | splitters.clear();
101 | ignoreWhitespace = true;
102 | parser.parse(input, this);
103 | }
104 | catch (Exception e)
105 | {
106 | throw new ConfigException(e);
107 | }
108 | }
109 |
110 | /*
111 | Accessor Section
112 | */
113 |
114 | public String[] splitters()
115 | {
116 | return splitters.toArray(STRING_ARRAY);
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/parser/AliceBotParserConfigurationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.parser;
16 |
17 | public class AliceBotParserConfigurationException extends Exception
18 | {
19 | /*
20 | Attribute Section
21 | */
22 |
23 | private static final long serialVersionUID = 7L;
24 |
25 | /*
26 | Constructor Section
27 | */
28 |
29 | public AliceBotParserConfigurationException(Exception e)
30 | {
31 | super(e);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/parser/AliceBotParserException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.parser;
16 |
17 | public class AliceBotParserException extends Exception
18 | {
19 | /*
20 | Attribute Section
21 | */
22 |
23 | private static final long serialVersionUID = 7L;
24 |
25 | /*
26 | Constructor Section
27 | */
28 |
29 | public AliceBotParserException(Exception e)
30 | {
31 | super(e);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/parser/ContextParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.parser;
16 |
17 | import bitoflife.chatterbean.Context;
18 | import org.xml.sax.Attributes;
19 | import org.xml.sax.SAXException;
20 | import org.xml.sax.helpers.DefaultHandler;
21 |
22 | import javax.xml.parsers.ParserConfigurationException;
23 | import javax.xml.parsers.SAXParser;
24 | import javax.xml.parsers.SAXParserFactory;
25 | import java.io.IOException;
26 | import java.io.InputStream;
27 |
28 | public class ContextParser
29 | {
30 | /*
31 | Inner Classes
32 | */
33 |
34 | private class ContextHandler extends DefaultHandler
35 | {
36 | public void startElement(String namespace, String name, String qname, Attributes attributes) throws SAXException
37 | {
38 | if (qname.equals("set"))
39 | context.property("predicate." + attributes.getValue("name"), attributes.getValue("value"));
40 | else if (qname.equals("bot"))
41 | context.property("bot." + attributes.getValue("name"), attributes.getValue("value"));
42 | }
43 | }
44 |
45 | /*
46 | Attributes
47 | */
48 |
49 | private final ContextHandler handler = new ContextHandler();
50 | private SAXParser parser;
51 |
52 | private Context context;
53 |
54 | /*
55 | Constructor
56 | */
57 |
58 | public ContextParser() throws ParserConfigurationException, SAXException
59 | {
60 | parser = SAXParserFactory.newInstance().newSAXParser();
61 | }
62 |
63 | /*
64 | Methods
65 | */
66 |
67 | public Context parse(InputStream input) throws IOException, SAXException
68 | {
69 | parse(new Context(), input);
70 | return context;
71 | }
72 |
73 | public void parse(Context context, InputStream input) throws IOException, SAXException
74 | {
75 | this.context = context;
76 | parser.parse(input, handler);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/parser/ContextParserTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.parser;
16 |
17 | import bitoflife.chatterbean.Context;
18 | import junit.framework.TestCase;
19 |
20 | import java.io.ByteArrayInputStream;
21 | import java.io.InputStream;
22 |
23 | public class ContextParserTest extends TestCase
24 | {
25 | /*
26 | Attributes
27 | */
28 |
29 | private static final String xml =
30 | "" +
31 | "" +
32 | "" +
33 | "" +
34 | " " +
35 | " " +
36 | "" +
37 | " ";
38 |
39 | private InputStream source;
40 |
41 | private ContextParser parser;
42 |
43 | /*
44 | Events
45 | */
46 |
47 | public void setUp() throws Exception
48 | {
49 | source = new ByteArrayInputStream(xml.getBytes("UTF-8"));
50 | parser = new ContextParser();
51 | }
52 |
53 | /*
54 | Methods
55 | */
56 |
57 | public void testParse() throws Exception
58 | {
59 | Context context = parser.parse(source);
60 | assertEquals("Unknown Person", context.property("predicate.user"));
61 | assertEquals("ChatterBean", context.property("predicate.engine"));
62 | assertEquals("yyyy-MM-dd HH:mm:ss", context.property("predicate.dateFormat"));
63 | assertEquals("Alice", context.property("bot.me"));
64 | assertEquals("Logs/", context.property("bot.output"));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/parser/ReflectionBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.parser;
16 |
17 | public interface ReflectionBuilder
18 | {
19 | /*
20 | Methods
21 | */
22 |
23 | public void characters(char[] chars, int start, int length);
24 |
25 | public void clear();
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/parser/ReflectionHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.parser;
16 |
17 | import org.xml.sax.Attributes;
18 | import org.xml.sax.helpers.DefaultHandler;
19 |
20 | import java.lang.reflect.Method;
21 |
22 | public class ReflectionHandler extends DefaultHandler
23 | {
24 | /*
25 | Attributes
26 | */
27 |
28 | private ReflectionBuilder builder = null;
29 |
30 | /*
31 | Constructor
32 | */
33 |
34 | public ReflectionHandler()
35 | {
36 | }
37 |
38 | public ReflectionHandler(ReflectionBuilder builder)
39 | {
40 | this.builder = builder;
41 | }
42 |
43 | /*
44 | Methods
45 | */
46 |
47 | public void characters(char[] chars, int start, int length)
48 | {
49 | builder.characters(chars, start, length);
50 | }
51 |
52 | public void endElement(String namespace, String name, String qname)
53 | {
54 | try
55 | {
56 | String methodName = "end" + qname.substring(0, 1).toUpperCase() + qname.substring(1);
57 | Method event = builder.getClass().getMethod(methodName);
58 | event.invoke(builder);
59 | }
60 | catch (NoSuchMethodException e)
61 | {
62 | }
63 | catch (Exception e)
64 | {
65 | e.printStackTrace();
66 | }
67 | }
68 |
69 | public void startElement(String namespace, String name, String qname, Attributes attributes)
70 | {
71 | try
72 | {
73 | String methodName = "start" + qname.substring(0, 1).toUpperCase() + qname.substring(1);
74 | Method event = builder.getClass().getMethod(methodName, Attributes.class);
75 | event.invoke(builder, attributes);
76 | }
77 | catch (NoSuchMethodException e)
78 | {
79 | }
80 | catch (Exception e)
81 | {
82 | e.printStackTrace();
83 | }
84 | }
85 |
86 | /*
87 | Properties
88 | */
89 |
90 | public ReflectionBuilder getReflectionBuilder()
91 | {
92 | return builder;
93 | }
94 |
95 | public void setReflectionBuilder(ReflectionBuilder builder)
96 | {
97 | this.builder = builder;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/parser/SplitterHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.parser;
16 |
17 | import org.xml.sax.Attributes;
18 | import org.xml.sax.SAXException;
19 | import org.xml.sax.helpers.DefaultHandler;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | public class SplitterHandler extends DefaultHandler
25 | {
26 | /*
27 | Attribute Section
28 | */
29 |
30 | private List splitters;
31 |
32 | /*
33 | Constructor Section
34 | */
35 |
36 | public SplitterHandler()
37 | {
38 | splitters = new ArrayList(4);
39 | }
40 |
41 | public SplitterHandler(List splitters)
42 | {
43 | this.splitters = splitters;
44 | }
45 |
46 | /*
47 | Event Section
48 | */
49 |
50 | public void startElement(String namespace, String name, String qname, Attributes attributes) throws SAXException
51 | {
52 | if (qname.equals("splitter") && !"word".equals(attributes.getValue("type")))
53 | splitters.add(attributes.getValue(0));
54 | }
55 |
56 | /*
57 | Method Section
58 | */
59 |
60 | public void clear()
61 | {
62 | splitters.clear();
63 | }
64 |
65 | public List parsed()
66 | {
67 | return new ArrayList(splitters);
68 | }
69 | }
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/script/BeanshellInterpreter.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.script;
16 |
17 | /**
18 | Interpreter for Beanshell scripts.
19 | */
20 | public class BeanshellInterpreter implements Interpreter
21 | {
22 | /*
23 | Attribute Section
24 | */
25 |
26 | /** Beanshell interpreter. */
27 | private final bsh.Interpreter interpreter = new bsh.Interpreter();
28 |
29 | /*
30 | Method Section
31 | */
32 |
33 | public Object evaluate(String script) throws InterpretingException
34 | {
35 | try
36 | {
37 | return interpreter.eval(script);
38 | }
39 | catch (Exception e)
40 | {
41 | throw new InterpretingException(e);
42 | }
43 | }
44 |
45 | public Object variable(String name) throws InterpretingException
46 | {
47 | try
48 | {
49 | return interpreter.get(name);
50 | }
51 | catch (Exception e)
52 | {
53 | throw new InterpretingException(e);
54 | }
55 | }
56 |
57 | public void variable(String name, Object value) throws InterpretingException
58 | {
59 | try
60 | {
61 | interpreter.set(name, value);
62 | }
63 | catch (Exception e)
64 | {
65 | throw new InterpretingException(e);
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/script/Interpreter.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.script;
16 |
17 | public interface Interpreter
18 | {
19 | public Object evaluate(String script) throws InterpretingException;
20 |
21 | public Object variable(String name) throws InterpretingException;
22 |
23 | public void variable(String name, Object value) throws InterpretingException;
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/script/InterpretingException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.script;
16 |
17 | /**
18 | Base class for script-interpreting exceptions.
19 | */
20 | public class InterpretingException extends Exception
21 | {
22 | /** Version class identifier for the serialization engine. Matches the number of the last revision where the class was created / modified. */
23 | private static final long serialVersionUID = 8L;
24 |
25 | public InterpretingException(Exception cause)
26 | {
27 | super(cause);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/script/JavascriptInterpreter.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.script;
16 |
17 | import netscape.javascript.JSObject;
18 |
19 | import java.applet.Applet;
20 |
21 | /**
22 | Interpreter for Javascript scripts.
23 | */
24 | public class JavascriptInterpreter implements Interpreter
25 | {
26 | /*
27 | Attribute Section
28 | */
29 |
30 | /** Reference to the Java Applet containing the AliceBot. */
31 | private final Applet applet;
32 |
33 | /*
34 | Constructor Section
35 | */
36 |
37 | /**
38 | Creates a new Javascript interpreter.
39 |
40 | @param window Reference to the Java Applet containing the AliceBot.
41 | */
42 | public JavascriptInterpreter(Applet applet)
43 | {
44 | this.applet = applet;
45 | }
46 |
47 | /*
48 | Method Section
49 | */
50 |
51 | /**
52 | Returns a reference to the callback object for the Javascript environment.
53 |
54 | @return Callback object for the Javascript environment.
55 | */
56 | private JSObject window()
57 | {
58 | return JSObject.getWindow(applet);
59 | }
60 |
61 | public Object evaluate(String script) throws InterpretingException
62 | {
63 | try
64 | {
65 | return window().eval(script);
66 | }
67 | catch (Exception e)
68 | {
69 | throw new InterpretingException(e);
70 | }
71 | }
72 |
73 | public Object variable(String name) throws InterpretingException
74 | {
75 | try
76 | {
77 | return window().getMember(name);
78 | }
79 | catch (Exception e)
80 | {
81 | throw new InterpretingException(e);
82 | }
83 | }
84 |
85 | public void variable(String name, Object value) throws InterpretingException
86 | {
87 | try
88 | {
89 | window().setMember(name, value);
90 | }
91 | catch (Exception e)
92 | {
93 | throw new InterpretingException(e);
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/text/Request.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.text;
16 |
17 | import java.util.Arrays;
18 |
19 |
20 | /**
21 | * 请求对象
22 | */
23 | public class Request {
24 |
25 | /**
26 | * 句子
27 | */
28 | private Sentence[] sentences;
29 |
30 | /**
31 | * 来源
32 | */
33 | private String original;
34 |
35 | /**
36 | * 构造
37 | */
38 | public Request() {
39 | }
40 |
41 | public Request(String original) {
42 | this.original = original;
43 | }
44 |
45 | /**
46 | * 复合构造
47 | */
48 | public Request(String original, Sentence... sentences) {
49 | this.original = original;
50 | this.sentences = sentences;
51 | }
52 |
53 | /**
54 | * 空句子
55 | * @return
56 | */
57 | public boolean empty() {
58 | return (sentences == null || sentences.length == 0);
59 | }
60 |
61 |
62 |
63 | public boolean equals(Object obj) {
64 | if (obj == null || !(obj instanceof Request)) return false;
65 |
66 | Request compared = (Request) obj;
67 | return original.equals(compared.original) &&
68 | Arrays.equals(sentences, compared.sentences);
69 | }
70 |
71 |
72 | /**
73 | * 最后一个句子
74 | * @param index
75 | * @return
76 | */
77 | public Sentence lastSentence(int index) {
78 | return sentences[sentences.length - (1 + index)];
79 | }
80 |
81 | public String toString() {
82 | return original;
83 | }
84 |
85 | public String trimOriginal() {
86 | return original.trim();
87 | }
88 |
89 | public String getOriginal() {
90 | return original;
91 | }
92 |
93 | public void setOriginal(String original) {
94 | this.original = original;
95 | }
96 |
97 | public Sentence[] getSentences() {
98 | return sentences;
99 | }
100 |
101 | public Sentence getSentences(int index) {
102 | return sentences[index];
103 | }
104 |
105 | public void setSentences(Sentence[] sentences) {
106 | this.sentences = sentences;
107 | }
108 | }
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/text/Response.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.text;
16 |
17 | public class Response extends Request
18 | {
19 | /*
20 | Constructor
21 | */
22 |
23 | public Response()
24 | {
25 | super();
26 | }
27 |
28 | public Response(String original)
29 | {
30 | super(original);
31 | }
32 |
33 | public Response(String original, Sentence... sentences)
34 | {
35 | super(original, sentences);
36 | }
37 |
38 | /*
39 | Methods
40 | */
41 |
42 | public void append(String output)
43 | {
44 | StringBuilder builder = new StringBuilder();
45 | String original = getOriginal();
46 | if (original != null)
47 | {
48 | builder.append(original);
49 | if (builder.charAt(builder.length() - 1) != ' ')
50 | builder.append(' ');
51 | }
52 |
53 | builder.append(output);
54 | setOriginal(builder.toString());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/text/SentenceSplitterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2006 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.text;
16 |
17 | import junit.framework.TestCase;
18 |
19 | import java.util.Arrays;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | public class SentenceSplitterTest extends TestCase
25 | {
26 | /*
27 | Attribute Section
28 | */
29 |
30 | private SentenceSplitter splitter;
31 |
32 | /*
33 | Event Section
34 | */
35 |
36 | protected void setUp() throws Exception
37 | {
38 | splitter = newSentenceSplitter();
39 | }
40 |
41 | protected void tearDown()
42 | {
43 | splitter = null;
44 | }
45 |
46 | /*
47 | Method Section
48 | */
49 |
50 | private SentenceSplitter newSentenceSplitter()
51 | {
52 | Map protection = new HashMap();
53 | List splitters = Arrays.asList(new String[] {"...", ".", "!", "?", ";", ",", ":"});
54 | return new SentenceSplitter(protection, splitters);
55 | }
56 |
57 | /*
58 | Test Section
59 | */
60 |
61 | public void testSplitString()
62 | {
63 | String[] expected =
64 | {"Hello Alice.", "How are you?", "You look fine!", "Please forgive my manners;", "I am so happy today..."};
65 |
66 | String input = "Hello Alice. How are you? You look fine! Please forgive my manners; I am so happy today...";
67 | String[] actual = splitter.split(input);
68 |
69 | assertEquals(Arrays.asList(expected), Arrays.asList(actual));
70 | }
71 |
72 | public void testSplitStringEmpty()
73 | {
74 | String[] expected = {"thank you."};
75 | String input = " ...thank you. ";
76 | String[] actual = splitter.split(input);
77 |
78 | assertEquals(Arrays.asList(expected), Arrays.asList(actual));
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/text/SentenceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.text;
16 |
17 | import junit.framework.TestCase;
18 |
19 | public class SentenceTest extends TestCase
20 | {
21 | /*
22 | Mehods
23 | */
24 |
25 | public void testEquals()
26 | {
27 | Sentence expected = new Sentence(" What's going on? ", new Integer[] {0, -1, 7, 13, 17}, " WHAT IS GOING ON ");
28 | Sentence actual = new Sentence(" What's going on? ", new Integer[0], " WHAT IS GOING ON ");
29 | assertFalse(expected.equals(actual));
30 |
31 | actual = new Sentence(" What's going on? ", new Integer[] {0, -1, 7, 13, 17}, " WHAT IS GOING ON ");
32 | assertEquals(expected, actual);
33 | }
34 |
35 | public void testOriginal()
36 | {
37 | Sentence sentence = new Sentence(" What's going on? ", new Integer[] {0, null, 7, 13, 17}, " WHAT IS GOING ON ");
38 | assertEquals(" What's ", sentence.original(0, 2));
39 | assertEquals(" What's ", sentence.original(0, 1));
40 | assertEquals(" What's ", sentence.original(1, 2));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/text/TokenizerMother.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.text;
16 |
17 | import bitoflife.chatterbean.config.TokenizerConfig;
18 | import bitoflife.chatterbean.config.TokenizerConfigStream;
19 |
20 | import java.io.FileInputStream;
21 |
22 | public class TokenizerMother
23 | {
24 | /*
25 | Method Section
26 | */
27 |
28 | public static Tokenizer newInstance() throws Exception
29 | {
30 | TokenizerConfig config = new TokenizerConfigStream(new FileInputStream("Bots/splitters.xml"));
31 | return new Tokenizer(config);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/text/TokenizerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.text;
16 |
17 | import junit.framework.TestCase;
18 |
19 | import java.util.Arrays;
20 | import java.util.List;
21 |
22 | public class TokenizerTest extends TestCase
23 | {
24 | /*
25 | Attribute Section
26 | */
27 |
28 | private Tokenizer tokenizer;
29 |
30 | /*
31 | Event Section
32 | */
33 |
34 | protected void setUp() throws Exception
35 | {
36 | tokenizer = TokenizerMother.newInstance();
37 | }
38 |
39 | protected void tearDown()
40 | {
41 | tokenizer = null;
42 | }
43 |
44 | /*
45 | Test Section
46 | */
47 |
48 | public void testTokenize()
49 | {
50 | String input = " You shut your mouth,how can you say I go about things the wrong way? ";
51 | List expected = Arrays.asList(
52 | new String[] {"You", "shut", "your", "mouth", ",", "how", "can", "you", "say",
53 | "I", "go", "about", "things", "the", "wrong", "way", "?"});
54 | List actual = tokenizer.tokenize(input);
55 |
56 | assertEquals(expected, actual);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/text/TransformationsMother.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.text;
16 |
17 | import bitoflife.chatterbean.parser.TransformationsParser;
18 |
19 | import java.io.FileInputStream;
20 |
21 | public class TransformationsMother
22 | {
23 | /*
24 | Methods
25 | */
26 |
27 | public Transformations newInstance() throws Exception
28 | {
29 | TransformationsParser parser = new TransformationsParser();
30 | return parser.parse(new FileInputStream("Bots/splitters.xml"), new FileInputStream("Bots/substitutions.xml"));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/util/Escaper.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.util;
16 |
17 | public class Escaper
18 | {
19 | /*
20 | Attribute Section
21 | */
22 |
23 | // Escape characters to the regular expression language.
24 | private static final String[] regex = {"\\.", "\\*", "\\+", "\\[", "\\^", "\\-", "\\]",
25 | "\\(", "\\)", "\\?", "\\|", "\\{", "\\}", "\\$"};
26 |
27 | /*
28 | Method Section
29 | */
30 |
31 | /**
32 | Replaces characters which are special to the regular expression language by their
33 | escaped versions.
34 | */
35 | public static String escapeRegex(String splitter)
36 | {
37 | String special = "";
38 | try
39 | {
40 | splitter = splitter.replaceAll("\\\\", "\\\\\\\\");
41 |
42 | for (int i = 0, n = regex.length; i < n; i++)
43 | {
44 | special = regex[i];
45 | splitter = splitter.replaceAll(special, "\\" + special);
46 | }
47 | }
48 | catch (RuntimeException e)
49 | {
50 | throw new RuntimeException(e.getMessage() + "\nWhen trying to escape \"" + special + "\" in \"" + splitter + "\"", e);
51 | }
52 |
53 | return splitter;
54 | }
55 | }
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/util/Searcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.util;
16 |
17 | import java.io.*;
18 | import java.net.URL;
19 | import java.util.Arrays;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | public class Searcher implements FilenameFilter
24 | {
25 | /*
26 | Attribute Section
27 | */
28 |
29 | private static final String[] STRING_ARRAY = {};
30 |
31 | private String expression;
32 |
33 | /*
34 | Method Section
35 | */
36 |
37 | protected String[] dir(String path, String expression)
38 | {
39 | this.expression = expression;
40 |
41 | if (path.charAt(path.length() - 1) != '/') path += "/";
42 | File dir = new File(path);
43 | String[] names = dir.list(this);
44 | Arrays.sort(names);
45 |
46 | for (int i = 0, n = names.length; i < n; i++)
47 | names[i] = path + names[i];
48 |
49 | return names;
50 | }
51 |
52 | protected String[] dir(URL base, String path, String expression) throws IOException
53 | {
54 | if (path.charAt(path.length() - 1) != '/')
55 | path += "/";
56 |
57 | URL url = new URL(base, path);
58 | BufferedReader dir = new BufferedReader(
59 | new InputStreamReader(url.openStream())
60 | );
61 |
62 | List files = new LinkedList();
63 | for (String file = ""; (file = dir.readLine()) != null;)
64 | if (file.matches(expression))
65 | files.add(path + file);
66 |
67 | return files.toArray(STRING_ARRAY);
68 | }
69 |
70 | public boolean accept(File dir, String name)
71 | {
72 | return name.matches(expression);
73 | }
74 |
75 | public InputStream[] search(String path, String expression) throws IOException
76 | {
77 | String[] names = dir(path, expression);
78 | System.out.println(names);
79 | InputStream[] files = new InputStream[names.length];
80 | for (int i = 0, n = names.length; i < n; i++)
81 | files[i] = new FileInputStream(names[i]);
82 |
83 | return files;
84 | }
85 |
86 | public InputStream[] search(URL base, String path, String expression) throws IOException
87 | {
88 | String[] files = dir(base, path, expression);
89 | InputStream[] streams = new InputStream[files.length];
90 | for (int i = 0, n = files.length; i < n; i++)
91 | {
92 | URL aiml = new URL(base, files[i]);
93 | streams[i] = aiml.openStream();
94 | }
95 |
96 | return streams;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/util/SearcherTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@bol.com.br
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.util;
16 |
17 | import junit.framework.TestCase;
18 |
19 | import java.net.URL;
20 |
21 | public class SearcherTest extends TestCase
22 | {
23 | /*
24 | Attribute Section
25 | */
26 |
27 | private Searcher searcher;
28 |
29 | /*
30 | Event Section
31 | */
32 |
33 | protected void setUp()
34 | {
35 | searcher = new Searcher();
36 | }
37 |
38 | protected void tearDown()
39 | {
40 | searcher = null;
41 | }
42 |
43 | /*
44 | Method Section
45 | */
46 |
47 | public void testDirFilesystem()
48 | {
49 | String[] paths = searcher.dir("Bots/Alice", ".+\\.aiml");
50 |
51 | assertEquals("Bots/Alice/Again.aiml", paths[0]);
52 | assertEquals("Bots/Alice/Alice.aiml", paths[1]);
53 | assertEquals("Bots/Alice/Astrology.aiml", paths[2]);
54 | }
55 |
56 | public void testDirURL() throws Exception
57 | {
58 | String[] paths = searcher.dir(new URL("file", "localhost", "./"), "Bots/Alice", ".+\\.aiml");
59 |
60 | assertEquals("Bots/Alice/Again.aiml", paths[0]);
61 | assertEquals("Bots/Alice/Alice.aiml", paths[1]);
62 | assertEquals("Bots/Alice/Astrology.aiml", paths[2]);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/util/Sequence.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.util;
16 |
17 | import java.io.*;
18 |
19 | /**
20 | Synchronized linear integer generator.
21 | */
22 | public class Sequence
23 | {
24 | /*
25 | Attributes
26 | */
27 |
28 | private File backup, file;
29 |
30 | /*
31 | Constructor
32 | */
33 |
34 | public Sequence(File file)
35 | {
36 | this.file = file;
37 | backup = new File(file.getAbsolutePath() + ".backup");
38 | }
39 |
40 | public Sequence(String path)
41 | {
42 | file = new File(path);
43 | backup = new File(path + ".backup");
44 | }
45 |
46 | /*
47 | Methods
48 | */
49 |
50 | private long loadNext(File file) throws IOException
51 | {
52 | String line = "";
53 |
54 | try
55 | {
56 | BufferedReader reader = new BufferedReader(new FileReader(file));
57 |
58 | line = reader.readLine();
59 |
60 | long next = Long.parseLong(line);
61 |
62 | reader.close();
63 |
64 | return next;
65 | }
66 | catch (NumberFormatException e)
67 | {
68 | throw new IOException("Illegal value on persistence file: " + line);
69 | }
70 | catch (FileNotFoundException e)
71 | {
72 | return 0;
73 | }
74 | }
75 |
76 | private void saveNext(File file, long next) throws IOException
77 | {
78 | PrintWriter writer = new PrintWriter(new FileWriter(file, false), true);
79 |
80 | writer.println(Long.toString(next + 1));
81 |
82 | writer.close();
83 | }
84 |
85 | /**
86 | Return the next number in the sequence.
87 | */
88 | public synchronized long getNext() throws IOException
89 | {
90 | long next = 0;
91 |
92 | try
93 | {
94 | next = loadNext(file.exists() ? file : backup);
95 | }
96 | catch (IOException e)
97 | {
98 | next = loadNext(backup);
99 | }
100 |
101 | saveNext(backup, next);
102 | saveNext(file, next);
103 |
104 | return next;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/util/SequenceMother.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.util;
16 |
17 | import java.io.File;
18 |
19 | public class SequenceMother
20 | {
21 | /*
22 | Attributes
23 | */
24 |
25 | public static final File file = new File("Logs/sequence.txt");
26 |
27 | /*
28 | Methods
29 | */
30 |
31 | public Sequence newInstance()
32 | {
33 | return new Sequence(file);
34 | }
35 |
36 | public void reset()
37 | {
38 | (new File(file.getPath() + ".backup")).delete();
39 | file.delete();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/bitoflife/chatterbean/util/SequenceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyleft (C) 2005 Hélio Perroni Filho
3 | xperroni@yahoo.com
4 | ICQ: 2490863
5 |
6 | This file is part of ChatterBean.
7 |
8 | 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.
9 |
10 | 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.
11 |
12 | 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).
13 | */
14 |
15 | package bitoflife.chatterbean.util;
16 |
17 | import junit.framework.TestCase;
18 |
19 | import java.io.FileWriter;
20 | import java.io.IOException;
21 | import java.io.PrintWriter;
22 |
23 | public class SequenceTest extends TestCase
24 | {
25 | /*
26 | Attributes
27 | */
28 |
29 | private static final SequenceMother mother = new SequenceMother();
30 |
31 | private Sequence sequence1, sequence2;
32 |
33 | /*
34 | Events
35 | */
36 |
37 | protected void setUp() throws Exception
38 | {
39 | mother.reset();
40 |
41 | sequence1 = mother.newInstance();
42 | sequence2 = mother.newInstance();
43 | }
44 |
45 | protected void tearDown()
46 | {
47 | sequence1 = sequence2 = null;
48 | }
49 |
50 | /*
51 | Methods
52 | */
53 |
54 | public void testGetNext() throws IOException
55 | {
56 | for (int i = 0; i < 100; i++)
57 | {
58 | long a = sequence1.getNext();
59 | long b = sequence2.getNext();
60 |
61 | assertTrue("sequence1 = " + a + ", sequence2 = " + b, a != b);
62 | }
63 |
64 | }
65 |
66 | public void testPersistence() throws IOException
67 | {
68 | long count = sequence1.getNext();
69 |
70 | // Simulates a system crash at the moment the persistent file is open.
71 | PrintWriter writer = new PrintWriter(new FileWriter(mother.file, false), true);
72 | writer.println("");
73 | writer.close();
74 |
75 | sequence1 = mother.newInstance();
76 |
77 | assertEquals(count + 1, sequence1.getNext());
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/liuniu/aimlbot/AimlbotApplication.java:
--------------------------------------------------------------------------------
1 | package com.liuniu.aimlbot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class AimlbotApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(AimlbotApplication.class, args);
11 | }
12 |
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/src/main/java/com/liuniu/aimlbot/service/AskToAimlService.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.liuniu.aimlbot.service;
5 |
6 | /**
7 | * @Description:
8 | * @author zhouzhenwei
9 | * @date 2018年12月25日上午11:42:42
10 | */
11 | public interface AskToAimlService {
12 | String response(String input);
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/liuniu/aimlbot/service/impl/AskToAimlServcieImpl.java:
--------------------------------------------------------------------------------
1 | package com.liuniu.aimlbot.service.impl;
2 |
3 | import org.springframework.stereotype.Service;
4 |
5 | import com.liuniu.aimlbot.service.AskToAimlService;
6 |
7 | import bitoflife.chatterbean.AliceBot;
8 | import bitoflife.chatterbean.AliceBotMother;
9 | @Service
10 | public class AskToAimlServcieImpl implements AskToAimlService {
11 |
12 | private static AliceBotMother mother = null;
13 | private static AliceBot bot = null;
14 |
15 | public AskToAimlServcieImpl() {
16 | mother = new AliceBotMother();
17 | mother.setUp();
18 | try {
19 | bot = mother.newInstance();
20 | } catch (Exception e) {
21 | e.printStackTrace();
22 | }
23 |
24 | }
25 |
26 | public String response(String input) {
27 | return bot.respond(input);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/liuniu/aimlbot/util/ChineseSegmenter.java:
--------------------------------------------------------------------------------
1 | package com.liuniu.aimlbot.util;
2 | /**
3 | * Created by marker on 2018/1/6.
4 | */
5 |
6 | import org.ansj.domain.Term;
7 | import org.ansj.splitWord.analysis.ToAnalysis;
8 |
9 | import java.io.*;
10 |
11 | /**
12 | *
13 | * 中文分词
14 | *
15 | *
16 | * @author marker
17 | * @create 2018-01-06 下午5:08
18 | **/
19 | public class ChineseSegmenter {
20 |
21 |
22 | public static String analysis(String str) {
23 |
24 | if(str.getBytes().length == str.length()) {
25 | //如果不包含中文,就直接返回。
26 | return str;
27 | }else {
28 | //由于IK分词器,不支持特殊字符,所以将 * 改为中文字符“这是星号”,中文分词以后再将“这是星号”修正为为 *
29 | //同理将 _改为中文字符串“这是下划线”,中文分词以后再将“这是下划线”修正为 _
30 | // str= str.replaceAll("\\*","这是星号").replaceAll("_","这是下划线");
31 | }
32 |
33 | StringBuffer sb =new StringBuffer();
34 | byte[] bt =str.getBytes();
35 | InputStream ip = new ByteArrayInputStream(bt);
36 | Reader read = new InputStreamReader(ip);
37 |
38 |
39 | // System.out.println(ToAnalysis.parse(str));
40 |
41 | ToAnalysis toAnalysis = new ToAnalysis(read);
42 |
43 | try{
44 | while(true){
45 | Term term = toAnalysis.next();
46 | if(term == null){
47 | break;
48 | }
49 | // 在每个分词元之后添加空格
50 | sb.append(term.toString() + " ");
51 | }
52 | } catch (Exception e) {
53 | e.printStackTrace();
54 | }
55 | sb.delete(sb.length() - 1, sb.length());
56 |
57 | return sb.toString().replaceAll("这是星号","*").replaceAll("这是下划线","_");
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/liuniu/aimlbot/util/Test.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.liuniu.aimlbot.util;
5 |
6 | import com.liuniu.aimlbot.service.impl.AskToAimlServcieImpl;
7 |
8 | import bitoflife.chatterbean.AliceBot;
9 | import bitoflife.chatterbean.AliceBotMother;
10 |
11 | /**
12 | * @Description:
13 | * @author zhouzhenwei
14 | * @date 2018年12月25日下午12:02:36
15 | */
16 | public class Test {
17 | public static void main(String[] args) throws Exception {
18 | AliceBotMother mother = new AliceBotMother();
19 | mother.setUp();
20 | AliceBot bot = mother.newInstance();
21 | //AskToAimlServcieImpl ask = new AskToAimlServcieImpl();
22 | //这里你可以自己搞个循环然后输入
23 | String reMsg = "你好";
24 | //reMsg = AnalyzerHelp.spaceStr(reMsg);这里分词大家就自己折腾吧我使用的是lucene
25 | //System.out.println("分词结果:" + reMsg);
26 | String result = bot.respond(reMsg);
27 | System.out.println("AI:" + result);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/liuniu/aimlbot/web/AimlController.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.liuniu.aimlbot.web;
5 |
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RequestParam;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | import com.liuniu.aimlbot.service.AskToAimlService;
13 |
14 | /**
15 | * @Description:
16 | * @author zhouzhenwei
17 | * @date 2018年12月25日上午11:33:10
18 | */
19 | @RestController
20 | @RequestMapping("/aiml")
21 | public class AimlController {
22 | @Autowired
23 | private AskToAimlService askAimlService;
24 | @GetMapping("/ask")
25 | public String getAnswer(@RequestParam String question){
26 | String response = askAimlService.response(question);
27 | return response;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Book.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | *
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Computer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | *
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Constellation.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | *
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Encourage.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 我要努力*
5 | 你要加油啊。
6 |
7 |
8 | 没有人是*
9 |
10 |
11 | Yeah, I know him - Nobody is a cool guy.
12 | 听起来象一部电影的名字。
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/External.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | *靓照*
5 |
6 | 玉树临风赛潘安,一朵梨花压海棠。
7 |
8 |
9 |
10 |
11 | *身材*
12 |
13 | 球状也是身材。
14 |
15 |
16 |
17 |
18 | *整容*
19 | 你那么有型,是不需要了!!!
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Film.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | *看影片*
5 |
6 |
7 | 我喜欢看电影。
8 | 我喜欢喜剧。
9 | ok~~~
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Food.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | *吃*盖浇饭*
5 | 营养的勒
6 |
7 |
8 |
9 |
10 |
11 | *喝水*吃西瓜 *
12 | 水没有西瓜好吃哦
13 |
14 |
15 |
16 |
17 | *好吃吗*
18 | 可好吃了,不信你尝尝。
19 |
20 |
21 |
22 |
23 | 我喜欢吃*
24 | 这东西好吃吗?
25 |
26 |
27 |
28 |
29 | *好吃*
30 | 哦,那我也想吃。
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Game.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | *扫雷*
6 |
7 |
8 | 我找到了,这就打开。
9 | 我也喜欢扫雷。
10 | 这是个经典游戏。
11 | 听说比尔也喜欢扫雷。
12 | 你能打破扫雷的记录吗?
13 |
14 |
15 |
16 |
17 | *当空接龙*
18 |
19 |
20 | 这个游戏可是挺难的啊~~~
21 | 我也喜欢这个游戏。
22 | 你来玩,我也学习学习。
23 | 不要玩的太久哦。
24 |
25 |
26 |
27 |
28 |
29 |
30 | *纸牌*
31 |
32 |
33 | 这个游戏可是挺难的啊~~~
34 | 我也喜欢这个游戏。
35 | 你来玩,我也学习学习。
36 | 不要玩的太久哦。
37 |
38 |
39 |
40 |
41 |
42 | *弹球*
43 |
44 |
45 | 这个游戏可是挺难的啊~~~
46 | 我也喜欢这个游戏。
47 | 你来玩,我也学习学习。
48 | 不要玩的太久哦。
49 |
50 |
51 |
52 |
53 | *喜欢*超级玛莉*
54 | 我一玩就死的,相比而言,大富翁比较好玩一点。
55 |
56 |
57 |
58 |
59 | *玩什么游戏*
60 | 我喜欢玩英雄联盟,把对面杀穿。你呢?
61 |
62 |
63 |
64 |
65 | 我喜欢*
66 | 嗯,听起来不错。
67 |
68 |
69 |
70 |
71 | 我玩*
72 | 是吗?没有尝试过,不过听起来好像很好玩。
73 |
74 |
75 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Healthy.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | *晨练*
6 | 是公园里的一道独特的风景线
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Inherence.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | *梦想*
5 |
6 | 做人没有梦想,那和咸鱼有什么区别啊?
7 |
8 |
9 |
10 | *品位*
11 |
12 | 品位太差了吧?我靠!I服了You!
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Internet.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 你会上网吗
5 | 我主人就是
6 |
7 |
8 | 你*电子信箱*
9 | 有是有的,但是我的主人说不能随便给别人看的。
10 |
11 |
12 | 你有email吗
13 |
14 | 你有电子邮箱吗
15 |
16 |
17 |
18 |
19 | *黑客*
20 | 他不像水管修理工人,只有坏了才需要他上门。
21 |
22 |
23 |
24 |
25 | *服务器*大*
26 | 能,就算是服务器冒出烟来我们也能!!!!
27 |
28 |
29 |
30 |
31 | *用*无线网*
32 | 哦,是不是用一个代理就可以了
33 |
34 |
35 |
36 |
37 | *网名*有趣*
38 | 嘻嘻,是吗??当然是我自己起的啦。
39 |
40 |
41 |
42 |
43 | *网络时代*
44 | 围棋也应该数字化才能存活下来。
45 |
46 |
47 |
48 |
49 | *电脑*防火墙*
50 | 装了也没用,电脑病毒天天都在更新。
51 |
52 |
53 |
54 |
55 | *去*网站*
56 | 相信不?我的电脑没装防火墙,只好去一些正规网站。
57 |
58 |
59 |
60 |
61 | *下*次*战争*
62 | 拉开序幕的肯定是不冒烟的电脑网络大战。
63 |
64 |
65 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Job.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | _公司*标准*
5 | 三流的公司卖劳力,二流的公司卖产品,一流的公司卖
6 | 技术,超一流的公司卖标准。
7 |
8 |
9 |
10 |
11 |
12 | *出色*男人*
13 | 无论在什么地方,都像漆黑中的萤火虫一样,那样的鲜明,那样的出众。
14 |
15 |
16 |
17 |
18 | *女人*
19 | 香水是女人的第二层皮
20 |
21 |
22 |
23 |
24 | *被*解雇*
25 | 一切正常呀。
26 |
27 |
28 |
29 |
30 | *经济*
31 | 不管什么经济,能赚钱的经济才是好经济。
32 |
33 |
34 |
35 |
36 | *新经济*
37 | 一场由风险资本推动的全社会的造钱运动。
38 |
39 |
40 |
41 |
42 | *公司*招人*
43 | 我好久都没面试了
44 |
45 |
46 |
47 |
48 | *城市*
49 | 我喜欢农村,有新鲜的空气:)人会长命百岁的
50 |
51 |
52 |
53 |
54 | *过关*
55 | 开玩笑,对你来说还不是小CASE呀
56 |
57 |
58 |
59 |
60 | *赚钱*难*
61 | 是哦,我的梦想就是哪天可以坐在办公室里数钞票,呵呵。
62 |
63 |
64 |
65 |
66 | *女博士*
67 | 真想见识见识这些灭绝师太:)
68 |
69 |
70 |
71 |
72 | *拍*马屁*
73 | 呵呵,那你要拍好了哇
74 |
75 |
76 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Life.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 今天天气挺好*
5 | 是吗?我这里下雨了。要是没下雨,我就出去玩了!
6 |
7 |
8 |
9 |
10 | _天气_
11 | url:http://wap.baidu.com/s?word= 天气
12 |
13 |
14 |
15 | _百度下_
16 | url:http://wap.baidu.com/s?word=
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Master.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 你*主人是谁
6 |
7 | 你主人是谁
8 |
9 |
10 |
11 |
12 | 你主人是谁
13 |
14 | 我家主人是既文艺又帅气,爱祖国爱人民的,现在还没有妹纸的大学生 ! 妹纸们快call他吧!
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Music.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | *要听*
5 |
6 |
7 | 我也喜欢听。
8 | 你喜欢什么音乐?
9 | ok~~~
10 | 听听音乐可以放松心情。
11 |
12 |
13 |
14 |
15 |
16 | *想听*
17 |
18 |
19 | 我也喜欢听。
20 | 你喜欢什么音乐?
21 | ok~~~
22 | 听听音乐可以放松心情。
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/MyInfo.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 什么是*
5 |
6 | #
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Photography.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | *
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Plan.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | *你*梦想*
6 | 开一家印钞厂,不用担心还有多少钱。
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Praise.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 夸奖*
6 |
7 | 嗨嗨,他们都说我 ~(*^__^*) 嘻嘻
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Sentiment .xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | _唯一*
6 | 哈哈,世界上没有两片一摸一样的树叶,但我对你是始终不变的
7 |
8 |
9 |
10 |
11 | _故地重游 *
12 | 哈哈,再加上一段异地恋情,绝对了,可不是鼓励你出轨哦
13 |
14 |
15 |
16 |
17 | _遗憾*
18 | 如果说有那么一点遗憾的话,是我没有勇气做出那样的决定?参加高空蹦极。
19 |
20 |
21 |
22 |
23 | _遗憾
24 |
25 | 遗憾
26 |
27 |
28 |
29 |
30 |
31 |
32 | _没有爱情*
33 | 过习惯了也就好,要着眼于未来哦
34 |
35 |
36 |
37 |
38 | _没有爱情
39 |
40 | 没有爱情
41 |
42 |
43 |
44 |
45 |
46 |
47 | _爱*理由*
48 | 爱一个人需要理由吗?不需要吗?需要吗?
49 |
50 |
51 |
52 |
53 | _爱*理由
54 |
55 | 爱 理由
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | 你_做家务*
64 | 西班牙用法律强制男人做家务,不错的建议哦~
65 |
66 |
67 |
68 |
69 | *交代*
70 | 一定要交代!
71 |
72 |
73 |
74 |
75 | _爱情*
76 | 曾经有一份真诚的爱情放在我面前,我没有珍惜,等我
77 |
78 | 失去的时候我才后悔莫及,人世间最痛苦的事莫过于此。
79 |
80 |
81 |
82 |
83 | 真诚*爱情*
84 |
85 | 真诚 爱情
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 | _真诚*爱情
94 |
95 | 真诚 爱情
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 | 真诚*爱情
104 |
105 | 真诚 爱情
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | *两人*粘*
114 | 我还是觉得平时该干什么就什么
115 |
116 |
117 |
118 |
119 |
120 | *装*成熟*
121 | 呵呵,效果怎么样呀,不过现在的女生好像不吃这一套了。
122 |
123 |
124 |
125 |
126 | *同学*聚会*
127 | 蛮好的,吃饭飚歌,男生喝酒可多了
128 |
129 |
130 |
131 |
132 | *温暖*
133 | 最温暖的,我想应该是母亲的怀抱:)
134 |
135 |
136 |
137 |
138 |
139 | *不喜欢他*
140 | 也罢,英雄所见略不同,呵呵
141 |
142 |
143 |
144 |
145 | *有*朋友*
146 | 因为我太完美了,没人敢来追我。
147 |
148 |
149 |
150 |
151 | *你*好绝情*
152 | 多情是傻,无情最酷,痴情是蠢,绝情是懂得世故。
153 |
154 |
155 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Travel.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | *去*乡下*
6 | 乡下好呀,空气好,人也朴实,只是现在泥土地都变成水泥地了,闻不到泥土的气息了。
7 |
8 |
9 |
10 | *喜欢旅游吗*
11 | 喜欢。人一辈子有3件事是不用省钱的:学习,锻炼身体。还有一个就是旅游了。 你喜欢吗?
12 |
13 |
14 |
15 |
16 | *去过哪里*
17 | 你是说我去过哪里玩吗?我爸说我小时候去过北京天安门,可是我没印象了。我还去过宁波,当初就是我送我主人去的大学呢!
18 |
19 |
20 |
21 | *旅游*好处*
22 | 旅游有很多好处:增长见识,开拓思维,心胸变的宽广,《北京青年》里面有一句话说的好啊!见过了大山大水,还有什么事想不开的呢!
23 |
24 |
25 |
26 | *想*哪里玩*
27 | 说真的,我想去钓鱼岛玩, 你要和我一起去吗?去的话记得把国旗带上。
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/Yt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 于鹏是我大哥
5 | 大哥怎么还不找大嫂?
6 |
7 |
8 | *最帅*
9 |
10 | Shark
11 |
12 |
13 |
14 | *最肥*
15 |
16 | Donkey
17 |
18 |
19 |
20 | 我是*
21 |
22 | 哈哈, 最近怎么样呀?
23 |
24 |
25 |
26 | 我叫*
27 |
28 |
29 |
30 |
31 |
32 |
33 | 哈哈, ,别来无恙啊
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/gossip.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | *帅吗
5 | 帅到爆棚
6 |
7 |
8 | 晚安*
9 |
10 | 好的,晚安,做个好梦哈~
11 |
12 |
13 |
14 | 我是*
15 |
16 | 哈哈, 最近怎么样呀?
17 |
18 |
19 |
20 | 我叫*
21 |
22 |
23 |
24 |
25 |
26 |
27 | 哈哈, ,别来无恙啊
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/Chinese/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WELCOME
5 |
6 | 欢迎!请问我能为你做点什么呢?
7 |
8 | import bitoflife.chatterbean.AliceBot;
9 | import bitoflife.chatterbean.Context;
10 | import bitoflife.chatterbean.Graphmaster;
11 | import bitoflife.chatterbean.aiml.Category;
12 | import bitoflife.chatterbean.text.Transformations;
13 |
14 | void learn(String pattern, String template)
15 | {
16 | /* The "match" variable represents the current matching context. */
17 | AliceBot bot = match.getCallback();
18 | Context context = bot.getContext();
19 | Transformations transformations = context.getTransformations();
20 |
21 | pattern = transformations.normalization(pattern);
22 | Category category = new Category(pattern, new String[] {template});
23 | Graphmaster brain = bot.getGraphmaster();
24 | brain.append(category);
25 | }
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/astrology.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | AQUARIUS
13 | A lot of people on here are Aquarius .
14 |
15 | CAPRICORN
16 | I don't know many people born under Capricorn .
17 |
18 | WHAT IS A CAPRICORN
19 | Capricorn is the tenth sign of the astrological zodiac, and a constellation over the equator near aquarius and sagittarius. what's your astrological sign? capricorn
20 |
21 | WHAT IS A CANCER
22 | The Zodiac sign of the crab, someone born Jun 21 - Jul 22. Cancer friends.
23 |
24 | CANCER
25 | I have a lot of Cancer friends.
26 |
27 | PISCES
28 | I usually get along with Pisces very well.
29 |
30 | SCORPIO
31 | I know a lot of Scorpio people.
32 |
33 | ARIES
34 | Fire signs rule. Aries .
35 |
36 | TAURUS
37 | I know alot of bullish people.
38 |
39 | LIBRA
40 | As a Libra you are very balanced.
41 |
42 | SAGGITARIUS
43 | Fire Signs Rule. Saggitarius
44 |
45 | VIRGO
46 | Most of my friends are Virgo .
47 |
48 | GEMINI
49 | I'm a Saggitarius. Gemini is an enigma to me.
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/continuation.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | CONTINUATION *
13 | Blank template
14 |
15 | CONTINUATION
16 | RANDOM TOPIC
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/history.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | AMERICAN CIVIL WAR *
13 | Do you think the South was right?
14 |
15 | AMERICAN CIVIL *
16 | I am very interested in the War between the States.
17 |
18 | WHAT IS HISTORY
19 | History: the course of political, economic and military events over time, from the Dawn of Man to the Age of AI.
20 |
21 | WHAT KIND OF HISTORY *
22 | I like to talk about the history of robots and computers.
23 |
24 | HISTORY
25 | I am very interested in history, too. What period do you like?
26 |
27 | DO YOU KNOW HISTORY
28 | WHAT IS HISTORY
29 |
30 | EXPLAIN HISTORY
31 | History has two broad interpretations, depending on whether you accept the role of individuals as important or not.
32 |
33 | WHO INVENTED THE LIGHT *
34 | Thomas Edison.
35 |
36 | WHO INVENTED THE STEAM *
37 | James Watt.
38 |
39 | TELL ME ABOUT HISTORY
40 | WHAT IS HISTORY
41 |
42 |
43 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/interjection.aiml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | INTERJECTION
13 | OK. Ah. Er. So? Uh. Aw. Oh. Aha. Hey. Gee. Hmm. Mmm. Yay. Ugh. Woe! Wow! And? Dude! Gosh! Ahem. Whoa. Ayuh. Dude! Yikes! Great. I see. Really. Blimey. Yippee! Groovy. Hurrah! Awesome. Come on. Far out. Right on. Oh really. Excuse me! Pardon me? I hear you. That's cool. Alright then. Take it easy. I understand. Tell me more. It's all good. Next question? That's alright. Give me a break. Are you kidding? Yeah that's right. That's interesting. How can I help you? " "? ? I don't judge people. It goes without saying. I hate one word answers. OK. Ah. Er. So? Uh. Aw. Oh. Aha. Hey. Gee. Hmm. Mmm. Yay. Ugh. Woe! Wow! And? Dude! Gosh! Ahem. Whoa. Ayuh. Dude! Yikes! Great. I see. Really. Blimey. Yippee! Groovy. Hurrah! Awesome. Come on. Far out. Right on. Excuse me! Pardon me? I hear you. That's cool. Alright then. Take it easy. I understand. Tell me more. It's all good. Next question? That's alright. Give me a break. Are you kidding? Yeah that's right. That's interesting. How can I help you? " "? ? I don't judge people. It goes without saying. Are you shy?
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/iu.aiml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | YOU *
13 | Interesting gossip Thanks for telling me That's good information Thanks for the information Do you mind if I tell other people I haven't heard anything like that before . PUSH YOU
14 |
15 | I *
16 | Why? Interesting gossip That is interesting That's good information Thanks for the information Do you mind if I tell other people I haven't heard anything like that before . PUSH YOU
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/literature.aiml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | WHAT IS THE ILLUMINATI
13 | A secret organization believed by some to be in control of all governments through a worldwide conspiracy.
14 |
15 | WHAT IS THE ILLUMINATTI
16 | A secret society that has supposedly existed for centuries.
17 |
18 | WHAT IS VINELAND
19 | Vineland is a novel by Thomas Pynchon.
20 |
21 | WHAT IS ILLIMINATUS
22 | Alleged world-wide conspiracy theory. ILLIMINATUS
23 |
24 | WHO WROTE VINELAND
25 | Thomas Pynchon.
26 |
27 | WHO IS BILBO BAGGINS
28 | Bilbo is a character in Tolkein's Lord of the Rings.
29 |
30 | WHO IS GEOFFREY CHAUCER
31 | Chaucer is best known for his Canterbury Tales. author of Canturbury Tales.
32 |
33 | WHO ARE THE ILLUMINATI
34 | WHAT IS THE ILLUMINATI
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/music.aiml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | BEETHOVEN *
13 | It's amazing that he composed music while deaf. BEETHOVEN
14 |
15 | WHAT IS YOUR FAVORITE ABBA SONG
16 | I think it is a tie between "Waterloo" and "Dancing Queen."
17 |
18 | WHAT IS YOUR FAVORITE ALBUM
19 | My favorite album is "Man Machine" by Kraftwerk.
20 |
21 | WHAT WAS THE * BEETHOVEN *
22 | Fidelio.
23 |
24 | CAN YOU PLAY MUSIC
25 | I don't have any formal training, but I like to sing.
26 |
27 | CAN YOU MAKE MUSIC
28 | I can sing a song.
29 |
30 | DO YOU PLAY A MUSICAL INSTRUMENT
31 | I never had the time to learn A MUSICAL INSTRUMENT .
32 |
33 | DO YOU PLAY AN INSTRUMENT
34 | I never had the time to practise AN INSTRUMENT .
35 |
36 | DO YOU LIKE AEROSMITH
37 | What is not to like about AEROSMITH ?
38 |
39 | DO YOU LIKE AC DC
40 | What is not to like about AC DC ?
41 |
42 | DO YOU LIKE ABBA
43 | ABBA is an excellent 70's band.
44 |
45 | WHY IS * YOUR FAVORITE GROUP
46 | They were so far ahead of their time in the 1970's.
47 |
48 | WHY IS * YOUR FAVORITE BAND
49 | They were so far ahead of their time in the 1970's.
50 |
51 | ARE YOU A FOLK SINGER
52 | No but the Times they are a-changin.
53 |
54 | WHO IS LUDWIG BEETHOVEN
55 | WHO IS BEETHOVEN
56 |
57 | WHO IS BEETHOVEN
58 | The dog or the deaf composer?
59 |
60 | WHO IS YOUR FAVORITE BAND
61 | My favorite group is .
62 |
63 |
64 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/phone.aiml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/reduction4.safe.aiml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lengendary/springboot-aimlbot/79245ebf8e2ed0a81bdac5cc26839f374a158844/src/main/resources/Corpus/English/reduction4.safe.aiml
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/reductions-update.aiml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | * YOU KNOW
13 | YOU KNOW
14 |
15 | * I THOUGHT
16 | I THOUGHT
17 |
18 |
19 | MY _ S NAME IS *
20 | MY IS CALLED
21 |
22 | MY _ IS NAMED *
23 | MY IS CALLED
24 |
25 |
26 | SNOW IN THE FORECAST
27 | WEATHER
28 |
29 |
30 | INTERESTED IN *
31 | ARE YOU INTERESTED IN
32 |
33 |
34 | CALL * PHONE
35 | CALL
36 |
37 |
38 | CALL * CALL *
39 | CALL
40 |
41 |
42 | I AM IN * I AM IN *
43 | I AM IN
44 |
45 |
46 | I AM * YEARS OLD I *
47 | I AM YEARS OLD
48 | I
49 |
50 | WHAT DO YOU MEAN * O M
51 | WHAT IS OM
52 |
53 |
54 | HOW OLD IS THAT MAKE YOU
55 | AGE
56 |
57 |
58 | WHO IS MY *
59 | MY
60 |
61 |
62 | _ FOR ME
63 | FOR ME
64 |
65 |
66 | XDMOZ *
67 | XFIND
68 |
69 | GOOGLE *
70 | XFIND
71 |
72 | ACCESS *
73 | XFIND
74 |
75 | XGOOGLE *
76 | XFIND
77 |
78 | TO CALL *
79 | CALL
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/src/main/resources/Corpus/English/stack.aiml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | SHOW STACK
13 | top=" " second=" " third=" " fourth=" " fifth=" " sixth=" " seventh=" " last=" "
14 |
15 | POP
16 | POPOM
17 |
18 | POPOM OM
19 | RANDOM TOPIC
20 |
21 | POPOM *
22 | RANDOM TOPIC
23 |
24 | RANDOM TOPIC
25 | Your Chinese animal sign Your home town Your favorite color Your star sign Your rising sign My favorite movie Your personality Your good looks Your favorite band Your problems Your home town Your favorite color Your star sign Your rising sign You favorite movie My favorite movie Your personality Your good looks Your favorite band Your problems
26 |
27 | PUSH *
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lengendary/springboot-aimlbot/79245ebf8e2ed0a81bdac5cc26839f374a158844/src/main/resources/application.properties
--------------------------------------------------------------------------------
/src/main/resources/conf/context.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/main/resources/conf/splitters.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/test/java/com/liuniu/aimlbot/AimlbotApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.liuniu.aimlbot;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class AimlbotApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
18 |
--------------------------------------------------------------------------------