├── README.md ├── dotnet ├── .gitignore ├── ChatterBotAPI.sln ├── ChatterBotAPI │ ├── ChatterBot.cs │ ├── ChatterBotAPI.csproj │ ├── ChatterBotFactory.cs │ ├── ChatterBotSession.cs │ ├── ChatterBotThought.cs │ ├── ChatterBotType.cs │ ├── Cleverbot.cs │ ├── Makefile.am │ ├── Pandorabots.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Utils.cs │ └── chatterbotapi.pc.in ├── ChatterBotAPITest │ ├── ChatterBotAPITest.csproj │ ├── Main.cs │ ├── Makefile.am │ ├── Properties │ │ └── AssemblyInfo.cs │ └── chatterbotapitest.in ├── ChatterBotAPITestVB │ ├── Application.vb │ ├── AssemblyInfo.vb │ └── ChatterBotAPITestVB.vbproj ├── Makefile.am ├── Makefile.include ├── autogen.sh ├── configure.ac └── expansions.m4 ├── java ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── google │ │ └── code │ │ └── chatterbotapi │ │ ├── ChatterBot.java │ │ ├── ChatterBotFactory.java │ │ ├── ChatterBotSession.java │ │ ├── ChatterBotThought.java │ │ ├── ChatterBotType.java │ │ ├── Cleverbot.java │ │ ├── Pandorabots.java │ │ └── Utils.java │ └── test │ └── java │ └── com │ └── google │ └── code │ └── chatterbotapi │ └── test │ └── ChatterBotApiTest.java ├── lgpl-3.0.txt ├── php ├── ChatterBotApiTestOOP.php ├── chatterbotapi.php ├── chatterbotapitest.php ├── composer.json ├── phpunit.xml ├── src │ └── ChatterBotApi │ │ ├── AbstractBot.php │ │ ├── AbstractSession.php │ │ ├── ChatterBotFactory.php │ │ ├── ChatterBotThought.php │ │ ├── ChatterBotType.php │ │ ├── IOException.php │ │ ├── Implementation │ │ ├── CleverBot │ │ │ ├── CleverBot.php │ │ │ └── Session.php │ │ └── PandoraBots │ │ │ ├── PandoraBots.php │ │ │ └── Session.php │ │ └── Utils.php └── tests │ └── ChatterBotApi │ ├── ChatterBotFactoryTest.php │ ├── ChatterBotThoughtTest.php │ ├── ChatterBotTypeTest.php │ ├── IOExceptionTest.php │ └── UtilsTest.php └── python ├── chatterbotapi.py ├── chatterbotapi.pyc └── chatterbotapitest.py /README.md: -------------------------------------------------------------------------------- 1 | # Chatter Bot API 2 | 3 | A Mono/.NET, JAVA, Python and PHP chatter bot API that supports [Cleverbot](http://www.cleverbot.com/), [JabberWacky](http://jabberwacky.com/) and [Pandorabots](http://www.pandorabots.com/). 4 | 5 | For a Ruby version, have a look at [Gabriele Cirulli cleverbot-api implementation](https://github.com/gabrielecirulli/cleverbot-api). 6 | 7 | If you are planing using the .NET version, maybe [this fork by Schumix](https://github.com/Schumix/ChatterBotApi) is worth looking at. 8 | 9 | ## News 10 | 11 | **2014-10-11**: Moved to GitHub! 12 | 13 | **2014-08-04**: The Java version is now on The Maven Central Repository. This is a request I get from time to time. I was too lazy to do it until now. But this time a user was kind enough, so I kick myself and did it (thanks Hardik!). [Just add this dependency to your pom file](#maven). 14 | 15 | **2014-03-31**: Cleverbot seems to stops working from time to time. You should expect it to be really unstable until I find a fix. 16 | 17 | **2014-02-02**: Cleverbot stops working. Thanks to Matthew to let me know. 18 | 19 | **2013-11-15**: Cleverbot stops working, they changed their API again. I am working on this. 20 | 21 | **2013-08-29**: There is a bug with Cleverbot in any language right now. I will fix it as soon as possible. A bug with Cleverbot is now fixed in the new 1.3 revision release. Enjoy! (Kevin, Alienmario, Rai: Thanks to you guys for letting me know) 22 | 23 | ## Download 24 | 25 | I encourage you to download a compiled version of the library (*TBA*), and try the example below in this page. I tried to keep all the libraries free from dependencies, so you do not need to download anything else. 26 | 27 | Be sure to always use the latest version of the library, as the Cleverbot/JabberWacky Web Service is changing over time. I suppose it is not meant to be public. 28 | 29 | ### Maven 30 | 31 | Just add this dependency to your pom file: 32 | 33 | ```xml 34 | 35 | ca.pjer 36 | chatter-bot-api 37 | 1.3.2 38 | 39 | ``` 40 | 41 | ## Going further 42 | 43 | If you like what you see, browse and comment the source code. If you found a bug or something missing, consult the [Issues section](https://github.com/pierredavidbelanger/chatter-bot-api/issues) before posting a new defect or a new enhancement. Also I will gladly accept [Pull Requests](https://github.com/pierredavidbelanger/chatter-bot-api/pulls) 44 | 45 | ## Disclaimer 46 | 47 | I am not the owner of Cleverbot/JabberWacky nor Pandorabots. 48 | 49 | My work (the Cleverbot/JabberWacky part) is based on [pycleverbot](https://code.google.com/p/pycleverbot/), a Python bindings for the Cleverbot. 50 | 51 | ## Contact 52 | 53 | You can also let [me](https://github.com/pierredavidbelanger) know what you think. 54 | 55 | ## Examples 56 | 57 | ### Mono/.NET C# 58 | 59 | ```csharp 60 | using System; 61 | 62 | using ChatterBotAPI; 63 | 64 | namespace ChatterBotAPITest { 65 | 66 | class MainClass { 67 | 68 | public static void Main(string[] args) { 69 | ChatterBotFactory factory = new ChatterBotFactory(); 70 | 71 | ChatterBot bot1 = factory.Create(ChatterBotType.CLEVERBOT); 72 | ChatterBotSession bot1session = bot1.CreateSession(); 73 | 74 | ChatterBot bot2 = factory.Create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477"); 75 | ChatterBotSession bot2session = bot2.CreateSession(); 76 | 77 | string s = "Hi"; 78 | while (true) { 79 | 80 | Console.WriteLine("bot1> " + s); 81 | 82 | s = bot2session.Think(s); 83 | Console.WriteLine("bot2> " + s); 84 | 85 | s = bot1session.Think(s); 86 | } 87 | } 88 | } 89 | } 90 | ``` 91 | 92 | ### Mono/.NET VB 93 | 94 | ```vbnet 95 | Imports ChatterBotAPI 96 | 97 | Public Class Application 98 | 99 | Public Shared Sub Main() 100 | Dim factory As ChatterBotFactory = new ChatterBotFactory() 101 | 102 | Dim bot1 As ChatterBot = factory.Create(ChatterBotType.CLEVERBOT) 103 | Dim bot1session As ChatterBotSession = bot1.CreateSession() 104 | 105 | Dim bot2 As ChatterBot = factory.Create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477") 106 | Dim bot2session As ChatterBotSession = bot2.CreateSession() 107 | 108 | Dim s As String = "Hi" 109 | Do While true 110 | 111 | Console.WriteLine("bot1> " + s) 112 | 113 | s = bot2session.Think(s) 114 | Console.WriteLine("bot2> " + s) 115 | 116 | s = bot1session.Think(s) 117 | Loop 118 | End Sub 119 | End Class 120 | ``` 121 | 122 | ### JAVA 123 | 124 | ```java 125 | package com.google.code.chatterbotapi.test; 126 | 127 | import com.google.code.chatterbotapi.*; 128 | 129 | public class ChatterBotApiTest { 130 | 131 | public static void main(String[] args) throws Exception { 132 | ChatterBotFactory factory = new ChatterBotFactory(); 133 | 134 | ChatterBot bot1 = factory.create(ChatterBotType.CLEVERBOT); 135 | ChatterBotSession bot1session = bot1.createSession(); 136 | 137 | ChatterBot bot2 = factory.create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477"); 138 | ChatterBotSession bot2session = bot2.createSession(); 139 | 140 | String s = "Hi"; 141 | while (true) { 142 | 143 | System.out.println("bot1> " + s); 144 | 145 | s = bot2session.think(s); 146 | System.out.println("bot2> " + s); 147 | 148 | s = bot1session.think(s); 149 | } 150 | } 151 | } 152 | ``` 153 | 154 | ### Python 155 | 156 | ```python 157 | from chatterbotapi import ChatterBotFactory, ChatterBotType 158 | 159 | factory = ChatterBotFactory() 160 | 161 | bot1 = factory.create(ChatterBotType.CLEVERBOT) 162 | bot1session = bot1.create_session() 163 | 164 | bot2 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477') 165 | bot2session = bot2.create_session() 166 | 167 | s = 'Hi' 168 | while (1): 169 | 170 | print 'bot1> ' + s 171 | 172 | s = bot2session.think(s); 173 | print 'bot2> ' + s 174 | 175 | s = bot1session.think(s); 176 | ``` 177 | 178 | ### PHP 179 | 180 | ```php 181 | create(ChatterBotType::CLEVERBOT); 187 | $bot1session = $bot1->createSession(); 188 | 189 | $bot2 = $factory->create(ChatterBotType::PANDORABOTS, 'b0dafd24ee35a477'); 190 | $bot2session = $bot2->createSession(); 191 | 192 | $s = 'Hi'; 193 | while (1) 194 | { 195 | echo "bot1> $s\n"; 196 | 197 | $s = $bot2session->think($s); 198 | echo "bot2> $s\n"; 199 | 200 | $s = $bot1session->think($s); 201 | } 202 | ?> 203 | ``` 204 | -------------------------------------------------------------------------------- /dotnet/.gitignore: -------------------------------------------------------------------------------- 1 | # Autosave files 2 | *~ 3 | 4 | *.pc 5 | *.gmo 6 | *.obj 7 | *.pidb 8 | *.mdb 9 | */bin/* 10 | Run/ 11 | 12 | # build stuff 13 | ChatterBotAPI/chatterbotapi.pc.in 14 | 15 | # ignore thumbnails created by windows 16 | Thumbs.db 17 | # Ignore files build by Visual Studio 18 | *.obj 19 | *.exe 20 | *.pdb 21 | *.user 22 | *.aps 23 | *.pch 24 | *.vspscc 25 | *_i.c 26 | *_p.c 27 | *.ncb 28 | *.suo 29 | *.tlb 30 | *.tlh 31 | *.bak 32 | *.cache 33 | *.ilk 34 | *.log 35 | [Bb]in 36 | [Dd]ebug*/ 37 | *.lib 38 | *.sbr 39 | obj/ 40 | [Rr]elease*/ 41 | _ReSharper*/ 42 | [Tt]est[Rr]esult* 43 | UpgradeLog.XML 44 | UpgradeLog.htm 45 | *.ReSharper 46 | *.userprefs 47 | 48 | # http://www.gnu.org/software/automake 49 | 50 | Makefile 51 | Makefile.in 52 | 53 | # http://www.gnu.org/software/autoconf 54 | 55 | /autom4te.cache 56 | /aclocal.m4 57 | /compile 58 | /configure 59 | /depcomp 60 | /install-sh 61 | /missing 62 | /config.status 63 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatterBotAPI", "ChatterBotAPI\ChatterBotAPI.csproj", "{2E624962-F155-432C-A90A-E1CE75DEE9EA}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatterBotAPITest", "ChatterBotAPITest\ChatterBotAPITest.csproj", "{DA59F247-C17B-4A92-BB03-CB458C6916F0}" 7 | EndProject 8 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ChatterBotAPITestVB", "ChatterBotAPITestVB\ChatterBotAPITestVB.vbproj", "{4D5C5614-9C76-4464-AB6E-A4349784F123}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {2E624962-F155-432C-A90A-E1CE75DEE9EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {2E624962-F155-432C-A90A-E1CE75DEE9EA}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {2E624962-F155-432C-A90A-E1CE75DEE9EA}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {2E624962-F155-432C-A90A-E1CE75DEE9EA}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {4D5C5614-9C76-4464-AB6E-A4349784F123}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {4D5C5614-9C76-4464-AB6E-A4349784F123}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {4D5C5614-9C76-4464-AB6E-A4349784F123}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {4D5C5614-9C76-4464-AB6E-A4349784F123}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {DA59F247-C17B-4A92-BB03-CB458C6916F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {DA59F247-C17B-4A92-BB03-CB458C6916F0}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {DA59F247-C17B-4A92-BB03-CB458C6916F0}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {DA59F247-C17B-4A92-BB03-CB458C6916F0}.Release|Any CPU.Build.0 = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(MonoDevelopProperties) = preSolution 30 | StartupItem = ChatterBotAPITestVB\ChatterBotAPITestVB.vbproj 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/ChatterBot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | /* 4 | ChatterBotAPI 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | namespace ChatterBotAPI { 21 | 22 | public interface ChatterBot { 23 | 24 | ChatterBotSession CreateSession(); 25 | } 26 | } -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/ChatterBotAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {2E624962-F155-432C-A90A-E1CE75DEE9EA} 9 | Library 10 | ChatterBotAPI 11 | ChatterBotAPI 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\Debug 18 | DEBUG 19 | prompt 20 | 4 21 | 22 | 23 | none 24 | false 25 | bin\Release 26 | prompt 27 | 4 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/ChatterBotFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | /* 4 | ChatterBotAPI 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | namespace ChatterBotAPI { 21 | 22 | public class ChatterBotFactory { 23 | 24 | public ChatterBot Create(ChatterBotType type) { 25 | return Create(type, null); 26 | } 27 | 28 | public ChatterBot Create(ChatterBotType type, object arg) { 29 | switch (type) { 30 | case ChatterBotType.CLEVERBOT: 31 | return new Cleverbot("http://www.cleverbot.com/webservicemin", 26); 32 | case ChatterBotType.JABBERWACKY: 33 | return new Cleverbot("http://jabberwacky.com/webservicemin", 20); 34 | case ChatterBotType.PANDORABOTS: 35 | if (arg == null) throw new ApplicationException("PANDORABOTS needs a botid arg"); 36 | return new Pandorabots(arg.ToString()); 37 | } 38 | return null; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/ChatterBotSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | /* 4 | ChatterBotAPI 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | namespace ChatterBotAPI { 21 | 22 | public interface ChatterBotSession { 23 | 24 | ChatterBotThought Think(ChatterBotThought thought); 25 | 26 | string Think(string text); 27 | } 28 | } -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/ChatterBotThought.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | /* 4 | ChatterBotAPI 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | namespace ChatterBotAPI { 21 | 22 | public class ChatterBotThought { 23 | 24 | public string[] Emotions { get; set; } 25 | 26 | public string Text { get; set; } 27 | } 28 | } -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/ChatterBotType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | /* 4 | ChatterBotAPI 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | namespace ChatterBotAPI { 21 | 22 | public enum ChatterBotType { 23 | CLEVERBOT, 24 | JABBERWACKY, 25 | PANDORABOTS 26 | } 27 | } -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/Cleverbot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using System.Collections.Generic; 4 | 5 | /* 6 | ChatterBotAPI 7 | Copyright (C) 2011 pierredavidbelanger@gmail.com 8 | 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with this program. If not, see . 21 | */ 22 | namespace ChatterBotAPI { 23 | 24 | class Cleverbot: ChatterBot { 25 | private readonly string url; 26 | private readonly int endIndex; 27 | 28 | public Cleverbot(string url, int endIndex) { 29 | this.url = url; 30 | this.endIndex = endIndex; 31 | } 32 | 33 | public ChatterBotSession CreateSession() { 34 | return new CleverbotSession(url, endIndex); 35 | } 36 | } 37 | 38 | class CleverbotSession: ChatterBotSession { 39 | private readonly string url; 40 | private readonly int endIndex; 41 | private readonly IDictionary vars; 42 | 43 | public CleverbotSession(string url, int endIndex) { 44 | this.url = url; 45 | this.endIndex = endIndex; 46 | vars = new Dictionary(); 47 | vars["start"] = "y"; 48 | vars["icognoid"] = "wsf"; 49 | vars["fno"] = "0"; 50 | vars["sub"] = "Say"; 51 | vars["islearning"] = "1"; 52 | vars["cleanslate"] = "false"; 53 | } 54 | 55 | public ChatterBotThought Think(ChatterBotThought thought) { 56 | vars["stimulus"] = thought.Text; 57 | 58 | string formData = Utils.ParametersToWWWFormURLEncoded(vars); 59 | string formDataToDigest = formData.Substring(9, endIndex); 60 | string formDataDigest = Utils.MD5(formDataToDigest); 61 | vars["icognocheck"] = formDataDigest; 62 | 63 | string response = Utils.Post(url, vars); 64 | 65 | string[] responseValues = response.Split('\r'); 66 | 67 | //vars[""] = Utils.StringAtIndex(responseValues, 0); ?? 68 | vars["sessionid"] = Utils.StringAtIndex(responseValues, 1); 69 | vars["logurl"] = Utils.StringAtIndex(responseValues, 2); 70 | vars["vText8"] = Utils.StringAtIndex(responseValues, 3); 71 | vars["vText7"] = Utils.StringAtIndex(responseValues, 4); 72 | vars["vText6"] = Utils.StringAtIndex(responseValues, 5); 73 | vars["vText5"] = Utils.StringAtIndex(responseValues, 6); 74 | vars["vText4"] = Utils.StringAtIndex(responseValues, 7); 75 | vars["vText3"] = Utils.StringAtIndex(responseValues, 8); 76 | vars["vText2"] = Utils.StringAtIndex(responseValues, 9); 77 | vars["prevref"] = Utils.StringAtIndex(responseValues, 10); 78 | //vars[""] = Utils.StringAtIndex(responseValues, 11); ?? 79 | vars["emotionalhistory"] = Utils.StringAtIndex(responseValues, 12); 80 | vars["ttsLocMP3"] = Utils.StringAtIndex(responseValues, 13); 81 | vars["ttsLocTXT"] = Utils.StringAtIndex(responseValues, 14); 82 | vars["ttsLocTXT3"] = Utils.StringAtIndex(responseValues, 15); 83 | vars["ttsText"] = Utils.StringAtIndex(responseValues, 16); 84 | vars["lineRef"] = Utils.StringAtIndex(responseValues, 17); 85 | vars["lineURL"] = Utils.StringAtIndex(responseValues, 18); 86 | vars["linePOST"] = Utils.StringAtIndex(responseValues, 19); 87 | vars["lineChoices"] = Utils.StringAtIndex(responseValues, 20); 88 | vars["lineChoicesAbbrev"] = Utils.StringAtIndex(responseValues, 21); 89 | vars["typingData"] = Utils.StringAtIndex(responseValues, 22); 90 | vars["divert"] = Utils.StringAtIndex(responseValues, 23); 91 | 92 | ChatterBotThought responseThought = new ChatterBotThought(); 93 | 94 | responseThought.Text = Utils.StringAtIndex(responseValues, 16); 95 | 96 | return responseThought; 97 | } 98 | 99 | public string Think(string text) { 100 | return Think(new ChatterBotThought() { Text = text }).Text; 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = 3 | 4 | # Warning: This is an automatically generated file, do not edit! 5 | 6 | if ENABLE_DEBUG 7 | ASSEMBLY_COMPILER_COMMAND = dmcs 8 | ASSEMBLY_COMPILER_FLAGS = -noconfig -codepage:utf8 -warn:4 -optimize- -debug "-define:DEBUG" 9 | ASSEMBLY = bin/Debug/ChatterBotAPI.dll 10 | ASSEMBLY_MDB = $(ASSEMBLY).mdb 11 | COMPILE_TARGET = library 12 | PROJECT_REFERENCES = 13 | BUILD_DIR = bin/Debug 14 | 15 | CHATTERBOTAPI_DLL_MDB_SOURCE=bin/Debug/ChatterBotAPI.dll.mdb 16 | CHATTERBOTAPI_DLL_MDB=$(BUILD_DIR)/ChatterBotAPI.dll.mdb 17 | 18 | endif 19 | 20 | if ENABLE_RELEASE 21 | ASSEMBLY_COMPILER_COMMAND = dmcs 22 | ASSEMBLY_COMPILER_FLAGS = -noconfig -codepage:utf8 -warn:4 -optimize- 23 | ASSEMBLY = bin/Release/ChatterBotAPI.dll 24 | ASSEMBLY_MDB = 25 | COMPILE_TARGET = library 26 | PROJECT_REFERENCES = 27 | BUILD_DIR = bin/Release 28 | 29 | CHATTERBOTAPI_DLL_MDB= 30 | 31 | endif 32 | 33 | AL=al 34 | SATELLITE_ASSEMBLY_NAME=$(notdir $(basename $(ASSEMBLY))).resources.dll 35 | 36 | PROGRAMFILES = \ 37 | $(CHATTERBOTAPI_DLL_MDB) 38 | 39 | LINUX_PKGCONFIG = \ 40 | $(CHATTERBOTAPI_PC) 41 | 42 | 43 | RESGEN=resgen2 44 | 45 | all: $(ASSEMBLY) $(PROGRAMFILES) $(LINUX_PKGCONFIG) 46 | 47 | FILES = \ 48 | ChatterBotFactory.cs \ 49 | ChatterBotType.cs \ 50 | ChatterBot.cs \ 51 | ChatterBotSession.cs \ 52 | Cleverbot.cs \ 53 | ChatterBotThought.cs \ 54 | Utils.cs \ 55 | Pandorabots.cs \ 56 | Properties/AssemblyInfo.cs 57 | 58 | DATA_FILES = 59 | 60 | RESOURCES = 61 | 62 | EXTRAS = \ 63 | Properties \ 64 | chatterbotapi.pc.in 65 | 66 | REFERENCES = \ 67 | System \ 68 | System.Web \ 69 | System.Xml 70 | 71 | DLL_REFERENCES = 72 | 73 | CLEANFILES = $(PROGRAMFILES) $(LINUX_PKGCONFIG) 74 | 75 | include $(top_srcdir)/Makefile.include 76 | 77 | CHATTERBOTAPI_PC = $(BUILD_DIR)/chatterbotapi.pc 78 | 79 | $(eval $(call emit-deploy-wrapper,CHATTERBOTAPI_PC,chatterbotapi.pc)) 80 | 81 | 82 | $(eval $(call emit_resgen_targets)) 83 | $(build_xamlg_list): %.xaml.g.cs: %.xaml 84 | xamlg '$<' 85 | 86 | $(ASSEMBLY_MDB): $(ASSEMBLY) 87 | 88 | $(ASSEMBLY): $(build_sources) $(build_resources) $(build_datafiles) $(DLL_REFERENCES) $(PROJECT_REFERENCES) $(build_xamlg_list) $(build_satellite_assembly_list) 89 | mkdir -p $(shell dirname $(ASSEMBLY)) 90 | $(ASSEMBLY_COMPILER_COMMAND) $(ASSEMBLY_COMPILER_FLAGS) -out:$(ASSEMBLY) -target:$(COMPILE_TARGET) $(build_sources_embed) $(build_resources_embed) $(build_references_ref) 91 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/Pandorabots.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using System.Collections.Generic; 4 | 5 | /* 6 | ChatterBotAPI 7 | Copyright (C) 2011 pierredavidbelanger@gmail.com 8 | 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with this program. If not, see . 21 | */ 22 | namespace ChatterBotAPI { 23 | 24 | class Pandorabots: ChatterBot { 25 | private readonly string botid; 26 | 27 | public Pandorabots(string botid) { 28 | this.botid = botid; 29 | } 30 | 31 | public ChatterBotSession CreateSession() { 32 | return new PandorabotsSession(botid); 33 | } 34 | } 35 | 36 | class PandorabotsSession: ChatterBotSession { 37 | private readonly IDictionary vars; 38 | 39 | public PandorabotsSession(string botid) { 40 | vars = new Dictionary(); 41 | vars["botid"] = botid; 42 | vars["custid"] = Guid.NewGuid().ToString(); 43 | } 44 | 45 | public ChatterBotThought Think(ChatterBotThought thought) { 46 | vars["input"] = thought.Text; 47 | 48 | string response = Utils.Post("http://www.pandorabots.com/pandora/talk-xml", vars); 49 | 50 | ChatterBotThought responseThought = new ChatterBotThought(); 51 | responseThought.Text = Utils.XPathSearch(response, "//result/that/text()"); 52 | 53 | return responseThought; 54 | } 55 | 56 | public string Think(string text) { 57 | return Think(new ChatterBotThought() { Text = text }).Text; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | /* 5 | ChatterBotAPI 6 | Copyright (C) 2011 pierredavidbelanger@gmail.com 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with this program. If not, see . 20 | */ 21 | 22 | [assembly: AssemblyTitle("ChatterBotAPI")] 23 | [assembly: AssemblyDescription("")] 24 | [assembly: AssemblyConfiguration("")] 25 | [assembly: AssemblyCompany("")] 26 | [assembly: AssemblyProduct("")] 27 | [assembly: AssemblyCopyright("pierredavidbelanger")] 28 | [assembly: AssemblyTrademark("")] 29 | [assembly: AssemblyCulture("")] 30 | 31 | [assembly: AssemblyVersion("1.1.*")] -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/Utils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Net; 6 | using System.Text; 7 | using System.Web; 8 | using System.Web.Security; 9 | using System.Xml.XPath; 10 | 11 | /* 12 | ChatterBotAPI 13 | Copyright (C) 2011 pierredavidbelanger@gmail.com 14 | 15 | This program is free software: you can redistribute it and/or modify 16 | it under the terms of the GNU Lesser General Public License as published by 17 | the Free Software Foundation, either version 3 of the License, or 18 | (at your option) any later version. 19 | 20 | This program is distributed in the hope that it will be useful, 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | GNU Lesser General Public License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public License 26 | along with this program. If not, see . 27 | */ 28 | namespace ChatterBotAPI { 29 | 30 | static class Utils { 31 | 32 | public static string ParametersToWWWFormURLEncoded(IDictionary parameters) { 33 | string wwwFormUrlEncoded = null; 34 | foreach (string parameterKey in parameters.Keys) { 35 | string parameterValue = parameters[parameterKey]; 36 | string parameter = string.Format("{0}={1}", HttpUtility.UrlEncode(parameterKey), HttpUtility.UrlEncode(parameterValue)); 37 | if (wwwFormUrlEncoded == null) { 38 | wwwFormUrlEncoded = parameter; 39 | } else { 40 | wwwFormUrlEncoded = string.Format("{0}&{1}", wwwFormUrlEncoded, parameter); 41 | } 42 | } 43 | return wwwFormUrlEncoded; 44 | } 45 | 46 | public static string MD5(string input) { 47 | return FormsAuthentication.HashPasswordForStoringInConfigFile(input, "MD5"); 48 | } 49 | 50 | public static string Post(string url, IDictionary parameters) { 51 | string postData = ParametersToWWWFormURLEncoded(parameters); 52 | byte[] postDataBytes = Encoding.ASCII.GetBytes(postData); 53 | 54 | WebRequest webRequest = WebRequest.Create(url); 55 | webRequest.Method = "POST"; 56 | webRequest.ContentType = "application/x-www-form-urlencoded"; 57 | webRequest.ContentLength = postDataBytes.Length; 58 | 59 | Stream outputStream = webRequest.GetRequestStream(); 60 | outputStream.Write(postDataBytes, 0, postDataBytes.Length); 61 | outputStream.Close(); 62 | 63 | WebResponse webResponse = webRequest.GetResponse(); 64 | StreamReader responseStreamReader = new StreamReader(webResponse.GetResponseStream()); 65 | return responseStreamReader.ReadToEnd().Trim(); 66 | } 67 | 68 | public static string XPathSearch(string input, string expression) { 69 | XPathDocument document = new XPathDocument(new MemoryStream(Encoding.ASCII.GetBytes(input))); 70 | XPathNavigator navigator = document.CreateNavigator(); 71 | return navigator.SelectSingleNode(expression).Value.Trim(); 72 | } 73 | 74 | public static string StringAtIndex(string[] strings, int index) { 75 | if (index >= strings.Length) return ""; 76 | return strings[index]; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPI/chatterbotapi.pc.in: -------------------------------------------------------------------------------- 1 | Name: ChatterBotAPI 2 | Description: ChatterBotAPI 3 | Version: 0.1 4 | 5 | Requires: 6 | Libs: -r:@expanded_libdir@/@PACKAGE@/ChatterBotAPI.dll 7 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPITest/ChatterBotAPITest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {DA59F247-C17B-4A92-BB03-CB458C6916F0} 9 | Exe 10 | ChatterBotAPITest 11 | ChatterBotAPITest 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\Debug 18 | DEBUG 19 | prompt 20 | 4 21 | false 22 | 23 | 24 | none 25 | false 26 | bin\Release 27 | prompt 28 | 4 29 | true 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | {2E624962-F155-432C-A90A-E1CE75DEE9EA} 42 | ChatterBotAPI 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPITest/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using ChatterBotAPI; 4 | 5 | /* 6 | ChatterBotAPI 7 | Copyright (C) 2011 pierredavidbelanger@gmail.com 8 | 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with this program. If not, see . 21 | */ 22 | namespace ChatterBotAPITest { 23 | 24 | class MainClass { 25 | 26 | public static void Main(string[] args) { 27 | ChatterBotFactory factory = new ChatterBotFactory(); 28 | 29 | ChatterBot bot1 = factory.Create(ChatterBotType.CLEVERBOT); 30 | ChatterBotSession bot1session = bot1.CreateSession(); 31 | 32 | ChatterBot bot2 = factory.Create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477"); 33 | ChatterBotSession bot2session = bot2.CreateSession(); 34 | 35 | string s = "Hi"; 36 | while (true) { 37 | 38 | Console.WriteLine("bot1> " + s); 39 | 40 | s = bot2session.Think(s); 41 | Console.WriteLine("bot2> " + s); 42 | 43 | s = bot1session.Think(s); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPITest/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = 3 | 4 | # Warning: This is an automatically generated file, do not edit! 5 | 6 | if ENABLE_DEBUG 7 | ASSEMBLY_COMPILER_COMMAND = dmcs 8 | ASSEMBLY_COMPILER_FLAGS = -noconfig -codepage:utf8 -warn:4 -optimize- -debug "-define:DEBUG" 9 | ASSEMBLY = bin/Debug/ChatterBotAPITest.exe 10 | ASSEMBLY_MDB = $(ASSEMBLY).mdb 11 | COMPILE_TARGET = exe 12 | PROJECT_REFERENCES = \ 13 | ../ChatterBotAPI/bin/Debug/ChatterBotAPI.dll 14 | BUILD_DIR = bin/Debug 15 | 16 | CHATTERBOTAPITEST_EXE_MDB_SOURCE=bin/Debug/ChatterBotAPITest.exe.mdb 17 | CHATTERBOTAPITEST_EXE_MDB=$(BUILD_DIR)/ChatterBotAPITest.exe.mdb 18 | CHATTERBOTAPI_DLL_SOURCE=../ChatterBotAPI/bin/Debug/ChatterBotAPI.dll 19 | CHATTERBOTAPI_DLL_MDB_SOURCE=../ChatterBotAPI/bin/Debug/ChatterBotAPI.dll.mdb 20 | CHATTERBOTAPI_DLL_MDB=$(BUILD_DIR)/ChatterBotAPI.dll.mdb 21 | 22 | endif 23 | 24 | if ENABLE_RELEASE 25 | ASSEMBLY_COMPILER_COMMAND = dmcs 26 | ASSEMBLY_COMPILER_FLAGS = -noconfig -codepage:utf8 -warn:4 -optimize- 27 | ASSEMBLY = bin/Release/ChatterBotAPITest.exe 28 | ASSEMBLY_MDB = 29 | COMPILE_TARGET = exe 30 | PROJECT_REFERENCES = \ 31 | ../ChatterBotAPI/bin/Release/ChatterBotAPI.dll 32 | BUILD_DIR = bin/Release 33 | 34 | CHATTERBOTAPITEST_EXE_MDB= 35 | CHATTERBOTAPI_DLL_SOURCE=../ChatterBotAPI/bin/Release/ChatterBotAPI.dll 36 | CHATTERBOTAPI_DLL_MDB= 37 | 38 | endif 39 | 40 | AL=al 41 | SATELLITE_ASSEMBLY_NAME=$(notdir $(basename $(ASSEMBLY))).resources.dll 42 | 43 | PROGRAMFILES = \ 44 | $(CHATTERBOTAPITEST_EXE_MDB) \ 45 | $(CHATTERBOTAPI_DLL) \ 46 | $(CHATTERBOTAPI_DLL_MDB) 47 | 48 | BINARIES = \ 49 | $(CHATTERBOTAPITEST) 50 | 51 | 52 | RESGEN=resgen2 53 | 54 | all: $(ASSEMBLY) $(PROGRAMFILES) $(BINARIES) 55 | 56 | FILES = \ 57 | Main.cs \ 58 | Properties/AssemblyInfo.cs 59 | 60 | DATA_FILES = 61 | 62 | RESOURCES = 63 | 64 | EXTRAS = \ 65 | Properties \ 66 | chatterbotapitest.in 67 | 68 | REFERENCES = \ 69 | System 70 | 71 | DLL_REFERENCES = 72 | 73 | CLEANFILES = $(PROGRAMFILES) $(BINARIES) 74 | 75 | include $(top_srcdir)/Makefile.include 76 | 77 | CHATTERBOTAPI_DLL = $(BUILD_DIR)/ChatterBotAPI.dll 78 | CHATTERBOTAPITEST = $(BUILD_DIR)/chatterbotapitest 79 | 80 | $(eval $(call emit-deploy-target,CHATTERBOTAPI_DLL)) 81 | $(eval $(call emit-deploy-target,CHATTERBOTAPI_DLL_MDB)) 82 | $(eval $(call emit-deploy-wrapper,CHATTERBOTAPITEST,chatterbotapitest,x)) 83 | 84 | 85 | $(eval $(call emit_resgen_targets)) 86 | $(build_xamlg_list): %.xaml.g.cs: %.xaml 87 | xamlg '$<' 88 | 89 | $(ASSEMBLY_MDB): $(ASSEMBLY) 90 | 91 | $(ASSEMBLY): $(build_sources) $(build_resources) $(build_datafiles) $(DLL_REFERENCES) $(PROJECT_REFERENCES) $(build_xamlg_list) $(build_satellite_assembly_list) 92 | mkdir -p $(shell dirname $(ASSEMBLY)) 93 | $(ASSEMBLY_COMPILER_COMMAND) $(ASSEMBLY_COMPILER_FLAGS) -out:$(ASSEMBLY) -target:$(COMPILE_TARGET) $(build_sources_embed) $(build_resources_embed) $(build_references_ref) 94 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPITest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | /* 5 | ChatterBotAPI 6 | Copyright (C) 2011 pierredavidbelanger@gmail.com 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with this program. If not, see . 20 | */ 21 | 22 | [assembly: AssemblyTitle("ChatterBotAPITest")] 23 | [assembly: AssemblyDescription("")] 24 | [assembly: AssemblyConfiguration("")] 25 | [assembly: AssemblyCompany("")] 26 | [assembly: AssemblyProduct("")] 27 | [assembly: AssemblyCopyright("pierredavidbelanger")] 28 | [assembly: AssemblyTrademark("")] 29 | [assembly: AssemblyCulture("")] 30 | 31 | [assembly: AssemblyVersion("1.0.*")] -------------------------------------------------------------------------------- /dotnet/ChatterBotAPITest/chatterbotapitest.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exec mono "@expanded_libdir@/@PACKAGE@/ChatterBotAPITest.exe" "$@" 4 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPITestVB/Application.vb: -------------------------------------------------------------------------------- 1 | 2 | Imports ChatterBotAPI 3 | 4 | ' ChatterBotAPI 5 | ' Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | ' 7 | ' This program is free software: you can redistribute it and/or modify 8 | ' it under the terms of the GNU Lesser General Public License as published by 9 | ' the Free Software Foundation, either version 3 of the License, or 10 | ' (at your option) any later version. 11 | ' 12 | ' This program is distributed in the hope that it will be useful, 13 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ' GNU Lesser General Public License for more details. 16 | ' 17 | ' You should have received a copy of the GNU Lesser General Public License 18 | ' along with this program. If not, see . 19 | Public Class Application 20 | 21 | Public Shared Sub Main() 22 | Dim factory As ChatterBotFactory = new ChatterBotFactory() 23 | 24 | Dim bot1 As ChatterBot = factory.Create(ChatterBotType.CLEVERBOT) 25 | Dim bot1session As ChatterBotSession = bot1.CreateSession() 26 | 27 | Dim bot2 As ChatterBot = factory.Create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477") 28 | Dim bot2session As ChatterBotSession = bot2.CreateSession() 29 | 30 | Dim s As String = "Hi" 31 | Do While true 32 | 33 | Console.WriteLine("bot1> " + s) 34 | 35 | s = bot2session.Think(s) 36 | Console.WriteLine("bot2> " + s) 37 | 38 | s = bot1session.Think(s) 39 | Loop 40 | End Sub 41 | End Class 42 | 43 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPITestVB/AssemblyInfo.vb: -------------------------------------------------------------------------------- 1 | Imports System.Reflection 2 | Imports System.Runtime.CompilerServices 3 | 4 | ' ChatterBotAPI 5 | ' Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | ' 7 | ' This program is free software: you can redistribute it and/or modify 8 | ' it under the terms of the GNU Lesser General Public License as published by 9 | ' the Free Software Foundation, either version 3 of the License, or 10 | ' (at your option) any later version. 11 | ' 12 | ' This program is distributed in the hope that it will be useful, 13 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ' GNU Lesser General Public License for more details. 16 | ' 17 | ' You should have received a copy of the GNU Lesser General Public License 18 | ' along with this program. If not, see . 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /dotnet/ChatterBotAPITestVB/ChatterBotAPITestVB.vbproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {4D5C5614-9C76-4464-AB6E-A4349784F123} 9 | Exe 10 | ChatterBotAPITestVB 11 | ChatterBotAPITestVB 12 | v3.5 13 | 14 | 15 | true 16 | bin\Debug 17 | prompt 18 | false 19 | false 20 | 21 | false 22 | 23 | 24 | bin\Release 25 | prompt 26 | false 27 | false 28 | 29 | false 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | {2E624962-F155-432C-A90A-E1CE75DEE9EA} 42 | ChatterBotAPI 43 | 44 | 45 | -------------------------------------------------------------------------------- /dotnet/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = expansions.m4 3 | 4 | #Warning: This is an automatically generated file, do not edit! 5 | if ENABLE_DEBUG 6 | SUBDIRS = ChatterBotAPI ChatterBotAPITest 7 | endif 8 | if ENABLE_RELEASE 9 | SUBDIRS = ChatterBotAPI ChatterBotAPITest 10 | endif 11 | -------------------------------------------------------------------------------- /dotnet/Makefile.include: -------------------------------------------------------------------------------- 1 | VALID_CULTURES = ar bg ca zh-CHS zh-Hans cs da de el en es fi fr he hu is it ja ko nl no pl pt rm ro ru hr sk sq sv th tr ur id uk be sl et lv lt tg fa vi hy az eu mk tn xh zu af ka fo hi mt se ga ms kk ky sw uz bn pa gu or ta te kn ml as mr mn bo cy km lo gl kok si am tzm ne ps fil ha yo nso kl ig ii br gsw sah rw gd ar-SA bg-BG ca-ES zh-TW cs-CZ da-DK de-DE el-GR en-US fi-FI fr-FR he-IL hu-HU is-IS it-IT ja-JP ko-KR nl-NL nb-NO pl-PL pt-BR rm-CH ro-RO ru-RU hr-HR sk-SK sq-AL sv-SE th-TH tr-TR ur-PK id-ID uk-UA be-BY sl-SI et-EE lv-LV lt-LT tg-Cyrl-TJ fa-IR vi-VN hy-AM az-Latn-AZ eu-ES mk-MK tn-ZA xh-ZA zu-ZA af-ZA ka-GE fo-FO hi-IN mt-MT se-NO sw-KE uz-Latn-UZ bn-IN gu-IN or-IN ta-IN te-IN kn-IN ml-IN as-IN mr-IN bo-CN cy-GB km-KH lo-LA gl-ES kok-IN si-LK am-ET ne-NP ps-AF fil-PH ha-Latn-NG yo-NG nso-ZA kl-GL ig-NG ii-CN br-FR sah-RU rw-RW gd-GB ar-IQ zh-CN de-CH en-GB es-MX fr-BE it-CH nl-BE nn-NO pt-PT sv-FI az-Cyrl-AZ ga-IE uz-Cyrl-UZ bn-BD ar-EG zh-HK de-AT en-AU es-ES fr-CA se-FI ar-LY zh-SG de-LU en-CA es-GT fr-CH hr-BA ar-DZ zh-MO de-LI en-NZ es-CR fr-LU bs-Latn-BA ar-MA en-IE es-PA fr-MC sr-Latn-BA ar-TN en-ZA es-DO sr-Cyrl-BA ar-OM en-JM es-VE bs-Cyrl-BA ar-YE es-CO sr-Latn-RS ar-SY en-BZ es-PE sr-Cyrl-RS ar-JO en-TT es-AR sr-Latn-ME ar-LB en-ZW es-EC sr-Cyrl-ME ar-KW en-PH es-CL ar-AE es-UY ar-BH es-PY ar-QA en-IN es-BO es-SV en-SG es-HN es-NI es-PR es-US bs-Cyrl bs-Latn sr-Cyrl sr-Latn az-Cyrl zh nn bs az-Latn uz-Cyrl mn-Cyrl zh-Hant zh-CHT nb sr tg-Cyrl uz-Latn tzm-Latn ha-Latn 2 | 3 | s2q=$(subst \ ,?,$1) 4 | q2s=$(subst ?,\ ,$1) 5 | # use this when result will be quoted 6 | unesc2=$(subst ?, ,$1) 7 | 8 | build_sources = $(FILES) $(GENERATED_FILES) 9 | build_sources_esc= $(call s2q,$(build_sources)) 10 | # use unesc2, as build_sources_embed is quoted 11 | build_sources_embed= $(call unesc2,$(build_sources_esc:%='$(srcdir)/%')) 12 | 13 | comma__=, 14 | get_resource_name = $(firstword $(subst $(comma__), ,$1)) 15 | get_culture = $(lastword $(subst ., ,$(basename $1))) 16 | is_cultured_resource = $(and $(word 3,$(subst ., ,$1)), $(filter $(VALID_CULTURES),$(lastword $(subst ., ,$(basename $1))))) 17 | 18 | RESOURCES_ESC=$(call s2q,$(RESOURCES)) 19 | 20 | build_resx_list = $(foreach res, $(RESOURCES_ESC), $(if $(filter %.resx, $(call get_resource_name,$(res))),$(res),)) 21 | build_non_culture_resx_list = $(foreach res, $(build_resx_list),$(if $(call is_cultured_resource,$(call get_resource_name,$(res))),,$(res))) 22 | build_non_culture_others_list = $(foreach res, $(filter-out $(build_resx_list),$(RESOURCES_ESC)),$(if $(call is_cultured_resource,$(call get_resource_name,$(res))),,$(res))) 23 | build_others_list = $(build_non_culture_others_list) 24 | build_xamlg_list = $(filter %.xaml.g.cs, $(FILES)) 25 | 26 | # resgen all .resx resources 27 | build_resx_files = $(foreach res, $(build_resx_list), $(call get_resource_name,$(res))) 28 | build_resx_resources_esc = $(build_resx_files:.resx=.resources) 29 | build_resx_resources = $(call q2s,$(build_resx_resources_esc)) 30 | 31 | # embed resources for the main assembly 32 | build_resx_resources_hack = $(subst .resx,.resources, $(build_non_culture_resx_list)) 33 | # use unesc2, as build_resx_resources_embed is quoted 34 | build_resx_resources_embed = $(call unesc2,$(build_resx_resources_hack:%='-resource:%')) 35 | build_others_files = $(call q2s,$(foreach res, $(build_others_list),$(call get_resource_name,$(res)))) 36 | build_others_resources = $(build_others_files) 37 | # use unesc2, as build_others_resources_embed is quoted 38 | build_others_resources_embed = $(call unesc2,$(build_others_list:%='-resource:$(srcdir)/%')) 39 | 40 | build_resources = $(build_resx_resources) $(build_others_resources) 41 | build_resources_embed = $(build_resx_resources_embed) $(build_others_resources_embed) 42 | 43 | # -usesourcepath is available only for resgen2 44 | emit_resgen_target_1=$(call q2s,$1) : $(call q2s,$(subst .resources,.resx,$1)); cd '$$(shell dirname '$$<')' && MONO_IOMAP=drive $$(RESGEN) '$$(shell basename '$$<')' '$$(shell basename '$$@')' 45 | emit_resgen_target_2=$(call q2s,$1) : $(call q2s,$(subst .resources,.resx,$1)); MONO_IOMAP=drive $$(RESGEN) -usesourcepath '$$<' '$$@' 46 | 47 | emit_resgen_target=$(if $(filter resgen2,$(RESGEN)),$(emit_resgen_target_2),$(emit_resgen_target_1)) 48 | emit_resgen_targets=$(foreach res,$(build_resx_resources_esc),$(eval $(call emit_resgen_target,$(res)))) 49 | 50 | build_references_ref = $(call q2s,$(foreach ref, $(call s2q,$(REFERENCES)), $(if $(filter -pkg:%, $(ref)), $(ref), $(if $(filter -r:%, $(ref)), $(ref), -r:$(ref))))) 51 | build_references_ref += $(call q2s,$(foreach ref, $(call s2q,$(DLL_REFERENCES)), -r:$(ref))) 52 | build_references_ref += $(call q2s,$(foreach ref, $(call s2q,$(PROJECT_REFERENCES)), -r:$(ref))) 53 | 54 | s2q2s=$(call unesc2,$(call s2q,$1)) 55 | cp_actual=test -z $1 || cp $1 $2 56 | cp=$(call cp_actual,'$(call s2q2s,$1)','$(call s2q2s,$2)') 57 | 58 | rm_actual=test -z '$1' || rm -f '$2' 59 | rm=$(call rm_actual,$(call s2q2s,$1),$(call s2q2s,$2)/$(shell basename '$(call s2q2s,$1)')) 60 | 61 | EXTRA_DIST += $(build_sources) $(build_resx_files) $(build_others_files) $(ASSEMBLY_WRAPPER_IN) $(EXTRAS) $(DATA_FILES) $(build_culture_res_files) 62 | CLEANFILES += $(ASSEMBLY) $(ASSEMBLY).mdb $(BINARIES) $(build_resx_resources) $(build_satellite_assembly_list) 63 | DISTCLEANFILES = $(GENERATED_FILES) $(pc_files) $(BUILD_DIR)/* 64 | 65 | programfilesdir = $(pkglibdir) 66 | programfiles_DATA = $(ASSEMBLY) 67 | bin_SCRIPTS = $(BINARIES) 68 | 69 | programfilesdir = @libdir@/@PACKAGE@ 70 | programfiles_DATA = $(PROGRAMFILES) 71 | linuxpkgconfigdir = @libdir@/pkgconfig 72 | linuxpkgconfig_DATA = $(LINUX_PKGCONFIG) 73 | 74 | 75 | # macros 76 | 77 | # $(call emit-deploy-target,deploy-variable-name) 78 | define emit-deploy-target 79 | $($1): $($1_SOURCE) 80 | mkdir -p '$$(shell dirname '$$@')' 81 | cp '$$<' '$$@' 82 | endef 83 | 84 | # $(call emit-deploy-wrapper,wrapper-variable-name,wrapper-sourcefile,x) 85 | # assumes that for a wrapper foo.pc its source template is foo.pc.in 86 | # if $3 is non-empty then wrapper is marked exec 87 | define emit-deploy-wrapper 88 | $($1): $2 89 | mkdir -p '$$(shell dirname '$$@')' 90 | cp '$$<' '$$@' 91 | $(if $3,chmod +x '$$@') 92 | 93 | endef 94 | 95 | # generating satellite assemblies 96 | 97 | culture_resources = $(foreach res, $(RESOURCES_ESC), $(if $(call is_cultured_resource,$(call get_resource_name, $(res))),$(res))) 98 | cultures = $(sort $(foreach res, $(culture_resources), $(call get_culture,$(call get_resource_name,$(res))))) 99 | culture_resource_dependencies = $(call q2s,$(BUILD_DIR)/$1/$(SATELLITE_ASSEMBLY_NAME): $(subst .resx,.resources,$2)) 100 | culture_resource_commandlines = $(call unesc2,cmd_line_satellite_$1 += '/embed:$(subst .resx,.resources,$2)') 101 | build_satellite_assembly_list = $(call q2s,$(cultures:%=$(BUILD_DIR)/%/$(SATELLITE_ASSEMBLY_NAME))) 102 | build_culture_res_files = $(call q2s,$(foreach res, $(culture_resources),$(call get_resource_name,$(res)))) 103 | install_satellite_assembly_list = $(subst $(BUILD_DIR),$(DESTDIR)$(libdir)/$(PACKAGE),$(build_satellite_assembly_list)) 104 | 105 | $(eval $(foreach res, $(culture_resources), $(eval $(call culture_resource_dependencies,$(call get_culture,$(call get_resource_name,$(res))),$(call get_resource_name,$(res)))))) 106 | $(eval $(foreach res, $(culture_resources), $(eval $(call culture_resource_commandlines,$(call get_culture,$(call get_resource_name,$(res))),$(res))))) 107 | 108 | $(build_satellite_assembly_list): $(BUILD_DIR)/%/$(SATELLITE_ASSEMBLY_NAME): 109 | mkdir -p '$(@D)' 110 | $(AL) -out:'$@' -culture:$* -t:lib $(cmd_line_satellite_$*) 111 | 112 | $(install_satellite_assembly_list): 113 | mkdir -p '$(@D)' 114 | cp $(subst $(DESTDIR)$(libdir)/$(PACKAGE), $(BUILD_DIR), $@) $@ 115 | 116 | install-satellite-assemblies: $(install_satellite_assembly_list) 117 | 118 | uninstall-satellite-assemblies: 119 | rm -rf $(install_satellite_assembly_list) -------------------------------------------------------------------------------- /dotnet/autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | PROJECT=ChatterBotAPI 4 | FILE= 5 | CONFIGURE=configure.ac 6 | 7 | : ${AUTOCONF=autoconf} 8 | : ${AUTOHEADER=autoheader} 9 | : ${AUTOMAKE=automake} 10 | : ${LIBTOOLIZE=libtoolize} 11 | : ${ACLOCAL=aclocal} 12 | : ${LIBTOOL=libtool} 13 | 14 | srcdir=`dirname $0` 15 | test -z "$srcdir" && srcdir=. 16 | 17 | ORIGDIR=`pwd` 18 | cd $srcdir 19 | TEST_TYPE=-f 20 | aclocalinclude="-I . $ACLOCAL_FLAGS" 21 | 22 | DIE=0 23 | 24 | ($AUTOCONF --version) < /dev/null > /dev/null 2>&1 || { 25 | echo 26 | echo "You must have autoconf installed to compile $PROJECT." 27 | echo "Download the appropriate package for your distribution," 28 | echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" 29 | DIE=1 30 | } 31 | 32 | ($AUTOMAKE --version) < /dev/null > /dev/null 2>&1 || { 33 | echo 34 | echo "You must have automake installed to compile $PROJECT." 35 | echo "Get ftp://sourceware.cygnus.com/pub/automake/automake-1.4.tar.gz" 36 | echo "(or a newer version if it is available)" 37 | DIE=1 38 | } 39 | 40 | (grep "^AM_PROG_LIBTOOL" $CONFIGURE >/dev/null) && { 41 | ($LIBTOOL --version) < /dev/null > /dev/null 2>&1 || { 42 | echo 43 | echo "**Error**: You must have \`libtool' installed to compile $PROJECT." 44 | echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.2d.tar.gz" 45 | echo "(or a newer version if it is available)" 46 | DIE=1 47 | } 48 | } 49 | 50 | if test "$DIE" -eq 1; then 51 | exit 1 52 | fi 53 | 54 | #test $TEST_TYPE $FILE || { 55 | # echo "You must run this script in the top-level $PROJECT directory" 56 | # exit 1 57 | #} 58 | 59 | if test -z "$*"; then 60 | echo "I am going to run ./configure with no arguments - if you wish " 61 | echo "to pass any to it, please specify them on the $0 command line." 62 | fi 63 | 64 | case $CC in 65 | *xlc | *xlc\ * | *lcc | *lcc\ *) am_opt=--include-deps;; 66 | esac 67 | 68 | (grep "^AM_PROG_LIBTOOL" $CONFIGURE >/dev/null) && { 69 | echo "Running $LIBTOOLIZE ..." 70 | $LIBTOOLIZE --force --copy 71 | } 72 | 73 | echo "Running $ACLOCAL $aclocalinclude ..." 74 | $ACLOCAL $aclocalinclude 75 | 76 | echo "Running $AUTOMAKE --gnu $am_opt ..." 77 | $AUTOMAKE --add-missing --gnu $am_opt 78 | 79 | echo "Running $AUTOCONF ..." 80 | $AUTOCONF 81 | 82 | echo Running $srcdir/configure $conf_flags "$@" ... 83 | $srcdir/configure --enable-maintainer-mode $conf_flags "$@" \ 84 | -------------------------------------------------------------------------------- /dotnet/configure.ac: -------------------------------------------------------------------------------- 1 | dnl Warning: This is an automatically generated file, do not edit! 2 | dnl Process this file with autoconf to produce a configure script. 3 | AC_PREREQ([2.54]) 4 | AC_INIT([ChatterBotAPI], [0.1]) 5 | AM_INIT_AUTOMAKE([foreign]) 6 | AM_MAINTAINER_MODE 7 | 8 | dnl pkg-config 9 | AC_PATH_PROG(PKG_CONFIG, pkg-config, no) 10 | if test "x$PKG_CONFIG" = "xno"; then 11 | AC_MSG_ERROR([You need to install pkg-config]) 12 | fi 13 | 14 | SHAMROCK_EXPAND_LIBDIR 15 | SHAMROCK_EXPAND_BINDIR 16 | SHAMROCK_EXPAND_DATADIR 17 | 18 | AC_PROG_INSTALL 19 | 20 | AC_PATH_PROG(DMCS, dmcs, no) 21 | if test "x$DMCS" = "xno"; then 22 | AC_MSG_ERROR([dmcs Not found]) 23 | fi 24 | 25 | 26 | AC_ARG_ENABLE(debug, 27 | AC_HELP_STRING([--enable-debug], 28 | [Use 'DEBUG' Configuration [default=NO]]), 29 | enable_debug=yes, enable_debug=no) 30 | AM_CONDITIONAL(ENABLE_DEBUG, test x$enable_debug = xyes) 31 | if test "x$enable_debug" = "xyes" ; then 32 | CONFIG_REQUESTED="yes" 33 | fi 34 | AC_ARG_ENABLE(release, 35 | AC_HELP_STRING([--enable-release], 36 | [Use 'RELEASE' Configuration [default=YES]]), 37 | enable_release=yes, enable_release=no) 38 | AM_CONDITIONAL(ENABLE_RELEASE, test x$enable_release = xyes) 39 | if test "x$enable_release" = "xyes" ; then 40 | CONFIG_REQUESTED="yes" 41 | fi 42 | if test -z "$CONFIG_REQUESTED" ; then 43 | AM_CONDITIONAL(ENABLE_RELEASE, true) 44 | enable_release=yes 45 | fi 46 | 47 | 48 | dnl package checks, common for all configs 49 | 50 | dnl package checks, per config 51 | 52 | 53 | AC_CONFIG_FILES([ 54 | ChatterBotAPI/chatterbotapi.pc 55 | ChatterBotAPI/Makefile 56 | ChatterBotAPITest/chatterbotapitest 57 | ChatterBotAPITest/Makefile 58 | Makefile 59 | 60 | ]) 61 | 62 | AC_OUTPUT 63 | -------------------------------------------------------------------------------- /dotnet/expansions.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([SHAMROCK_EXPAND_LIBDIR], 2 | [ 3 | expanded_libdir=`( 4 | case $prefix in 5 | NONE) prefix=$ac_default_prefix ;; 6 | *) ;; 7 | esac 8 | case $exec_prefix in 9 | NONE) exec_prefix=$prefix ;; 10 | *) ;; 11 | esac 12 | eval echo $libdir 13 | )` 14 | AC_SUBST(expanded_libdir) 15 | ]) 16 | 17 | AC_DEFUN([SHAMROCK_EXPAND_BINDIR], 18 | [ 19 | expanded_bindir=`( 20 | case $prefix in 21 | NONE) prefix=$ac_default_prefix ;; 22 | *) ;; 23 | esac 24 | case $exec_prefix in 25 | NONE) exec_prefix=$prefix ;; 26 | *) ;; 27 | esac 28 | eval echo $bindir 29 | )` 30 | AC_SUBST(expanded_bindir) 31 | ]) 32 | 33 | AC_DEFUN([SHAMROCK_EXPAND_DATADIR], 34 | [ 35 | case $prefix in 36 | NONE) prefix=$ac_default_prefix ;; 37 | *) ;; 38 | esac 39 | 40 | case $exec_prefix in 41 | NONE) exec_prefix=$prefix ;; 42 | *) ;; 43 | esac 44 | 45 | expanded_datadir=`(eval echo $datadir)` 46 | expanded_datadir=`(eval echo $expanded_datadir)` 47 | 48 | AC_SUBST(expanded_datadir) 49 | ]) 50 | 51 | -------------------------------------------------------------------------------- /java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | ca.pjer 9 | chatter-bot-api 10 | 1.3.2 11 | 12 | Chatter Bot API 13 | 14 | A JAVA (also Mono/.NET, Python and PHP) chatter bot API 15 | that supports Cleverbot, JabberWacky and Pandorabots. 16 | 17 | https://code.google.com/p/chatter-bot-api/ 18 | 19 | 20 | UTF-8 21 | 1.5 22 | 23 | 24 | 25 | 26 | GNU LESSER GENERAL PUBLIC LICENSE 27 | http://www.gnu.org/licenses/lgpl-3.0.txt 28 | 29 | 30 | 31 | 32 | 33 | Pierre-David Bélanger 34 | pierredavidbelanger@gmail.com 35 | PjEr.ca 36 | http://www.pjer.ca/ 37 | 38 | 39 | 40 | 41 | scm:svn:https://chatter-bot-api.googlecode.com/svn/trunk/ 42 | scm:svn:https://chatter-bot-api.googlecode.com/svn/trunk/ 43 | https://chatter-bot-api.googlecode.com/svn/trunk/ 44 | 45 | 46 | 47 | 48 | ossrh 49 | https://oss.sonatype.org/content/repositories/snapshots/ 50 | 51 | 52 | ossrh 53 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.apache.maven.plugins 61 | maven-compiler-plugin 62 | 3.1 63 | 64 | 1.5 65 | 1.5 66 | 67 | 68 | 69 | org.apache.maven.plugins 70 | maven-source-plugin 71 | 2.2.1 72 | 73 | 74 | attach-sources 75 | 76 | jar-no-fork 77 | 78 | 79 | 80 | 81 | 82 | org.apache.maven.plugins 83 | maven-javadoc-plugin 84 | 2.9.1 85 | 86 | 87 | attach-javadocs 88 | 89 | jar 90 | 91 | 92 | 93 | 94 | 95 | org.apache.maven.plugins 96 | maven-gpg-plugin 97 | 1.5 98 | 99 | 100 | sign-artifacts 101 | verify 102 | 103 | sign 104 | 105 | 106 | 107 | 108 | 109 | 110 | org.sonatype.plugins 111 | nexus-staging-maven-plugin 112 | 1.6.2 113 | true 114 | 115 | ossrh 116 | https://oss.sonatype.org/ 117 | true 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /java/src/main/java/com/google/code/chatterbotapi/ChatterBot.java: -------------------------------------------------------------------------------- 1 | package com.google.code.chatterbotapi; 2 | 3 | /* 4 | chatter-bot-api 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | public interface ChatterBot { 21 | 22 | ChatterBotSession createSession(); 23 | } -------------------------------------------------------------------------------- /java/src/main/java/com/google/code/chatterbotapi/ChatterBotFactory.java: -------------------------------------------------------------------------------- 1 | package com.google.code.chatterbotapi; 2 | 3 | /* 4 | chatter-bot-api 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | public class ChatterBotFactory { 21 | 22 | public ChatterBot create(ChatterBotType type) throws Exception { 23 | return create(type, null); 24 | } 25 | 26 | public ChatterBot create(ChatterBotType type, Object arg) throws Exception { 27 | switch (type) { 28 | case CLEVERBOT: 29 | return new Cleverbot("http://www.cleverbot.com/webservicemin", 35); 30 | case JABBERWACKY: 31 | return new Cleverbot("http://jabberwacky.com/webservicemin", 29); 32 | case PANDORABOTS: 33 | if (arg == null) { 34 | throw new Exception("PANDORABOTS needs a botid arg"); 35 | } 36 | return new Pandorabots(arg.toString()); 37 | } 38 | return null; 39 | } 40 | } -------------------------------------------------------------------------------- /java/src/main/java/com/google/code/chatterbotapi/ChatterBotSession.java: -------------------------------------------------------------------------------- 1 | package com.google.code.chatterbotapi; 2 | 3 | /* 4 | chatter-bot-api 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | public interface ChatterBotSession { 21 | 22 | ChatterBotThought think(ChatterBotThought thought) throws Exception; 23 | 24 | String think(String text) throws Exception; 25 | } -------------------------------------------------------------------------------- /java/src/main/java/com/google/code/chatterbotapi/ChatterBotThought.java: -------------------------------------------------------------------------------- 1 | package com.google.code.chatterbotapi; 2 | 3 | /* 4 | chatter-bot-api 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | public class ChatterBotThought { 21 | private String[] emotions; 22 | private String text; 23 | 24 | public String[] getEmotions() { 25 | return emotions; 26 | } 27 | 28 | public void setEmotions(String[] emotions) { 29 | this.emotions = emotions; 30 | } 31 | 32 | public String getText() { 33 | return text; 34 | } 35 | 36 | public void setText(String text) { 37 | this.text = text; 38 | } 39 | } -------------------------------------------------------------------------------- /java/src/main/java/com/google/code/chatterbotapi/ChatterBotType.java: -------------------------------------------------------------------------------- 1 | package com.google.code.chatterbotapi; 2 | 3 | /* 4 | chatter-bot-api 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | */ 20 | public enum ChatterBotType { 21 | CLEVERBOT, 22 | JABBERWACKY, 23 | PANDORABOTS 24 | } -------------------------------------------------------------------------------- /java/src/main/java/com/google/code/chatterbotapi/Cleverbot.java: -------------------------------------------------------------------------------- 1 | package com.google.code.chatterbotapi; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | /* 7 | chatter-bot-api 8 | Copyright (C) 2011 pierredavidbelanger@gmail.com 9 | 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU Lesser General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public License 21 | along with this program. If not, see . 22 | */ 23 | class Cleverbot implements ChatterBot { 24 | private final String url; 25 | private int endIndex; 26 | 27 | public Cleverbot(String url, int endIndex) { 28 | this.url = url; 29 | this.endIndex = endIndex; 30 | } 31 | 32 | @Override 33 | public ChatterBotSession createSession() { 34 | return new Session(); 35 | } 36 | 37 | private class Session implements ChatterBotSession { 38 | private final Map vars; 39 | 40 | public Session() { 41 | vars = new LinkedHashMap(); 42 | vars.put("start", "y"); 43 | vars.put("icognoid", "wsf"); 44 | vars.put("fno", "0"); 45 | vars.put("sub", "Say"); 46 | vars.put("islearning", "1"); 47 | vars.put("cleanslate", "false"); 48 | } 49 | 50 | @Override 51 | public ChatterBotThought think(ChatterBotThought thought) throws Exception { 52 | vars.put("stimulus", thought.getText()); 53 | 54 | String formData = Utils.parametersToWWWFormURLEncoded(vars); 55 | String formDataToDigest = formData.substring(9, endIndex); 56 | String formDataDigest = Utils.md5(formDataToDigest); 57 | vars.put("icognocheck", formDataDigest); 58 | 59 | String response = Utils.post(url, vars); 60 | 61 | String[] responseValues = response.split("\r"); 62 | 63 | //vars.put("", Utils.stringAtIndex(responseValues, 0)); ?? 64 | vars.put("sessionid", Utils.stringAtIndex(responseValues, 1)); 65 | vars.put("logurl", Utils.stringAtIndex(responseValues, 2)); 66 | vars.put("vText8", Utils.stringAtIndex(responseValues, 3)); 67 | vars.put("vText7", Utils.stringAtIndex(responseValues, 4)); 68 | vars.put("vText6", Utils.stringAtIndex(responseValues, 5)); 69 | vars.put("vText5", Utils.stringAtIndex(responseValues, 6)); 70 | vars.put("vText4", Utils.stringAtIndex(responseValues, 7)); 71 | vars.put("vText3", Utils.stringAtIndex(responseValues, 8)); 72 | vars.put("vText2", Utils.stringAtIndex(responseValues, 9)); 73 | vars.put("prevref", Utils.stringAtIndex(responseValues, 10)); 74 | //vars.put("", Utils.stringAtIndex(responseValues, 11)); ?? 75 | vars.put("emotionalhistory", Utils.stringAtIndex(responseValues, 12)); 76 | vars.put("ttsLocMP3", Utils.stringAtIndex(responseValues, 13)); 77 | vars.put("ttsLocTXT", Utils.stringAtIndex(responseValues, 14)); 78 | vars.put("ttsLocTXT3", Utils.stringAtIndex(responseValues, 15)); 79 | vars.put("ttsText", Utils.stringAtIndex(responseValues, 16)); 80 | vars.put("lineRef", Utils.stringAtIndex(responseValues, 17)); 81 | vars.put("lineURL", Utils.stringAtIndex(responseValues, 18)); 82 | vars.put("linePOST", Utils.stringAtIndex(responseValues, 19)); 83 | vars.put("lineChoices", Utils.stringAtIndex(responseValues, 20)); 84 | vars.put("lineChoicesAbbrev", Utils.stringAtIndex(responseValues, 21)); 85 | vars.put("typingData", Utils.stringAtIndex(responseValues, 22)); 86 | vars.put("divert", Utils.stringAtIndex(responseValues, 23)); 87 | 88 | ChatterBotThought responseThought = new ChatterBotThought(); 89 | 90 | responseThought.setText(Utils.stringAtIndex(responseValues, 16)); 91 | 92 | return responseThought; 93 | } 94 | 95 | @Override 96 | public String think(String text) throws Exception { 97 | ChatterBotThought thought = new ChatterBotThought(); 98 | thought.setText(text); 99 | return think(thought).getText(); 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /java/src/main/java/com/google/code/chatterbotapi/Pandorabots.java: -------------------------------------------------------------------------------- 1 | package com.google.code.chatterbotapi; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | import java.util.UUID; 6 | 7 | /* 8 | chatter-bot-api 9 | Copyright (C) 2011 pierredavidbelanger@gmail.com 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Lesser General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public License 22 | along with this program. If not, see . 23 | */ 24 | class Pandorabots implements ChatterBot { 25 | private final String botid; 26 | 27 | public Pandorabots(String botid) { 28 | this.botid = botid; 29 | } 30 | 31 | @Override 32 | public ChatterBotSession createSession() { 33 | return new Session(); 34 | } 35 | 36 | private class Session implements ChatterBotSession { 37 | private final Map vars; 38 | 39 | public Session() { 40 | vars = new LinkedHashMap(); 41 | vars.put("botid", botid); 42 | vars.put("custid", UUID.randomUUID().toString()); 43 | } 44 | 45 | @Override 46 | public ChatterBotThought think(ChatterBotThought thought) throws Exception { 47 | vars.put("input", thought.getText()); 48 | 49 | String response = Utils.post("http://www.pandorabots.com/pandora/talk-xml", vars); 50 | 51 | ChatterBotThought responseThought = new ChatterBotThought(); 52 | 53 | responseThought.setText(Utils.xPathSearch(response, "//result/that/text()")); 54 | 55 | return responseThought; 56 | } 57 | 58 | @Override 59 | public String think(String text) throws Exception { 60 | ChatterBotThought thought = new ChatterBotThought(); 61 | thought.setText(text); 62 | return think(thought).getText(); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /java/src/main/java/com/google/code/chatterbotapi/Utils.java: -------------------------------------------------------------------------------- 1 | package com.google.code.chatterbotapi; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.ByteArrayInputStream; 5 | import java.io.InputStreamReader; 6 | import java.io.OutputStreamWriter; 7 | import java.io.Reader; 8 | import java.io.StringWriter; 9 | import java.math.BigInteger; 10 | import java.net.URL; 11 | import java.net.URLConnection; 12 | import java.net.URLEncoder; 13 | import java.security.MessageDigest; 14 | import java.util.Map; 15 | import javax.xml.parsers.DocumentBuilder; 16 | import javax.xml.parsers.DocumentBuilderFactory; 17 | import javax.xml.xpath.XPath; 18 | import javax.xml.xpath.XPathConstants; 19 | import javax.xml.xpath.XPathExpression; 20 | import javax.xml.xpath.XPathFactory; 21 | import org.w3c.dom.Document; 22 | 23 | /* 24 | chatter-bot-api 25 | Copyright (C) 2011 pierredavidbelanger@gmail.com 26 | 27 | This program is free software: you can redistribute it and/or modify 28 | it under the terms of the GNU Lesser General Public License as published by 29 | the Free Software Foundation, either version 3 of the License, or 30 | (at your option) any later version. 31 | 32 | This program is distributed in the hope that it will be useful, 33 | but WITHOUT ANY WARRANTY; without even the implied warranty of 34 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 | GNU Lesser General Public License for more details. 36 | 37 | You should have received a copy of the GNU Lesser General Public License 38 | along with this program. If not, see . 39 | */ 40 | class Utils { 41 | 42 | public static String parametersToWWWFormURLEncoded(Map parameters) throws Exception { 43 | StringBuilder s = new StringBuilder(); 44 | for (Map.Entry parameter : parameters.entrySet()) { 45 | if (s.length() > 0) { 46 | s.append("&"); 47 | } 48 | s.append(URLEncoder.encode(parameter.getKey(), "UTF-8")); 49 | s.append("="); 50 | s.append(URLEncoder.encode(parameter.getValue(), "UTF-8")); 51 | } 52 | return s.toString(); 53 | } 54 | 55 | public static String md5(String input) throws Exception { 56 | MessageDigest md5 = MessageDigest.getInstance("MD5"); 57 | md5.update(input.getBytes("UTF-8")); 58 | BigInteger hash = new BigInteger(1, md5.digest()); 59 | return String.format("%1$032X", hash); 60 | } 61 | 62 | public static String post(String url, Map parameters) throws Exception { 63 | URLConnection connection = new URL(url).openConnection(); 64 | connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"); 65 | connection.setDoOutput(true); 66 | connection.setDoInput(true); 67 | OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream()); 68 | osw.write(parametersToWWWFormURLEncoded(parameters)); 69 | osw.flush(); 70 | osw.close(); 71 | Reader r = new BufferedReader(new InputStreamReader(connection.getInputStream())); 72 | StringWriter w = new StringWriter(); 73 | char[] buffer = new char[1024]; 74 | int n = 0; 75 | while ((n = r.read(buffer)) != -1) { 76 | w.write(buffer, 0, n); 77 | } 78 | r.close(); 79 | return w.toString(); 80 | } 81 | 82 | public static String xPathSearch(String input, String expression) throws Exception { 83 | DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 84 | XPath xPath = XPathFactory.newInstance().newXPath(); 85 | XPathExpression xPathExpression = xPath.compile(expression); 86 | Document document = documentBuilder.parse(new ByteArrayInputStream(input.getBytes("UTF-8"))); 87 | String output = (String) xPathExpression.evaluate(document, XPathConstants.STRING); 88 | return output == null ? "" : output.trim(); 89 | } 90 | 91 | public static String stringAtIndex(String[] strings, int index) { 92 | if (index >= strings.length) return ""; 93 | return strings[index]; 94 | } 95 | } -------------------------------------------------------------------------------- /java/src/test/java/com/google/code/chatterbotapi/test/ChatterBotApiTest.java: -------------------------------------------------------------------------------- 1 | package com.google.code.chatterbotapi.test; 2 | 3 | import com.google.code.chatterbotapi.*; 4 | 5 | /* 6 | chatter-bot-api 7 | Copyright (C) 2011 pierredavidbelanger@gmail.com 8 | 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with this program. If not, see . 21 | */ 22 | public class ChatterBotApiTest { 23 | 24 | public static void main(String[] args) throws Exception { 25 | ChatterBotFactory factory = new ChatterBotFactory(); 26 | 27 | ChatterBot bot1 = factory.create(ChatterBotType.CLEVERBOT); 28 | ChatterBotSession bot1session = bot1.createSession(); 29 | 30 | ChatterBot bot2 = factory.create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477"); 31 | ChatterBotSession bot2session = bot2.createSession(); 32 | 33 | String s = "Hi"; 34 | while (true) { 35 | 36 | System.out.println("bot1> " + s); 37 | 38 | s = bot2session.think(s); 39 | System.out.println("bot2> " + s); 40 | 41 | s = bot1session.think(s); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /lgpl-3.0.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /php/ChatterBotApiTestOOP.php: -------------------------------------------------------------------------------- 1 | . 18 | */ 19 | 20 | /** 21 | * This tests were written by: 22 | * Christian Gärtner 23 | */ 24 | 25 | require 'vendor/autoload.php'; 26 | 27 | 28 | use ChatterBotApi\ChatterBotType; 29 | use ChatterBotApi\ChatterBotThought; 30 | use ChatterBotApi\ChatterBotFactory; 31 | 32 | $bot1 = ChatterBotFactory::create(ChatterBotType::CLEVERBOT); 33 | $bot1session = $bot1->createSession(); 34 | 35 | $bot2 = ChatterBotFactory::create(ChatterBotType::PANDORABOTS, ChatterBotType::PANDORABOTS_DEFAULT_ID); 36 | $bot2session = $bot2->createSession(); 37 | 38 | $th = ChatterBotThought::make('Hi'); 39 | 40 | while (1) 41 | { 42 | echo "bot1> $th\n"; 43 | 44 | try { 45 | $th = $bot2session->think($th->message()); 46 | } catch (IOException $e) { 47 | echo $e; 48 | } catch (Exception $e) { 49 | // Ignore these 50 | } 51 | 52 | echo "bot2> $th\n"; 53 | 54 | try { 55 | $th = $bot1session->think($th->message()); 56 | } catch (IOException $e) { 57 | echo $e; 58 | } catch (Exception $e) { 59 | // Ignore these 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /php/chatterbotapi.php: -------------------------------------------------------------------------------- 1 | . 18 | */ 19 | 20 | ################################################# 21 | # API 22 | ################################################# 23 | 24 | class ChatterBotType 25 | { 26 | const CLEVERBOT = 1; 27 | const JABBERWACKY = 2; 28 | const PANDORABOTS = 3; 29 | } 30 | 31 | class ChatterBotFactory 32 | { 33 | public function create($type, $arg = null) 34 | { 35 | switch ($type) 36 | { 37 | case ChatterBotType::CLEVERBOT: 38 | { 39 | return new _Cleverbot('http://www.cleverbot.com/webservicemin', 26); 40 | } 41 | case ChatterBotType::JABBERWACKY: 42 | { 43 | return new _Cleverbot('http://jabberwacky.com/webservicemin', 20); 44 | } 45 | case ChatterBotType::PANDORABOTS: 46 | { 47 | if ($arg == null) { 48 | throw new Exception('PANDORABOTS needs a botid arg'); 49 | } 50 | return new _Pandorabots($arg); 51 | } 52 | } 53 | } 54 | } 55 | 56 | abstract class ChatterBot 57 | { 58 | public function createSession() 59 | { 60 | return null; 61 | } 62 | } 63 | 64 | abstract class ChatterBotSession 65 | { 66 | public function thinkThought($thought) 67 | { 68 | return $thought; 69 | } 70 | 71 | public function think($text) 72 | { 73 | $thought = new ChatterBotThought(); 74 | $thought->setText($text); 75 | return $this->thinkThought($thought)->getText(); 76 | } 77 | } 78 | 79 | class ChatterBotThought 80 | { 81 | private $text; 82 | 83 | public function getText() 84 | { 85 | return $this->text; 86 | } 87 | 88 | public function setText($text) 89 | { 90 | $this->text = $text; 91 | } 92 | } 93 | 94 | ################################################# 95 | # Cleverbot impl 96 | ################################################# 97 | 98 | class _Cleverbot extends ChatterBot 99 | { 100 | private $url; 101 | private $endIndex; 102 | 103 | public function __construct($url, $endIndex) 104 | { 105 | $this->url = $url; 106 | $this->endIndex = $endIndex; 107 | } 108 | 109 | public function getUrl() 110 | { 111 | return $this->url; 112 | } 113 | 114 | public function setUrl($url) 115 | { 116 | $this->url = $url; 117 | } 118 | 119 | public function getEndIndex() 120 | { 121 | return $this->endIndex; 122 | } 123 | 124 | public function setEndIndex($endIndex) 125 | { 126 | $this->endIndex = $endIndex; 127 | } 128 | 129 | public function createSession() 130 | { 131 | return new _CleverbotSession($this); 132 | } 133 | } 134 | 135 | class _CleverbotSession extends ChatterBotSession 136 | { 137 | private $bot; 138 | private $vars; 139 | 140 | public function __construct($bot) 141 | { 142 | $this->bot = $bot; 143 | $this->vars = array(); 144 | $this->vars['start'] = 'y'; 145 | $this->vars['icognoid'] = 'wsf'; 146 | $this->vars['fno'] = '0'; 147 | $this->vars['sub'] = 'Say'; 148 | $this->vars['islearning'] = '1'; 149 | $this->vars['cleanslate'] = 'false'; 150 | } 151 | 152 | public function thinkThought($thought) 153 | { 154 | $this->vars['stimulus'] = $thought->getText(); 155 | $data = http_build_query($this->vars); 156 | $dataToDigest = substr($data, 9, $this->bot->getEndIndex()); 157 | $dataDigest = md5($dataToDigest); 158 | $this->vars['icognocheck'] = $dataDigest; 159 | $response = _utils_post($this->bot->getUrl(), $this->vars); 160 | $responseValues = explode("\r", $response); 161 | //self.vars['??'] = _utils_string_at_index($responseValues, 0); 162 | $this->vars['sessionid'] = _utils_string_at_index($responseValues, 1); 163 | $this->vars['logurl'] = _utils_string_at_index($responseValues, 2); 164 | $this->vars['vText8'] = _utils_string_at_index($responseValues, 3); 165 | $this->vars['vText7'] = _utils_string_at_index($responseValues, 4); 166 | $this->vars['vText6'] = _utils_string_at_index($responseValues, 5); 167 | $this->vars['vText5'] = _utils_string_at_index($responseValues, 6); 168 | $this->vars['vText4'] = _utils_string_at_index($responseValues, 7); 169 | $this->vars['vText3'] = _utils_string_at_index($responseValues, 8); 170 | $this->vars['vText2'] = _utils_string_at_index($responseValues, 9); 171 | $this->vars['prevref'] = _utils_string_at_index($responseValues, 10); 172 | //$this->vars['??'] = _utils_string_at_index($responseValues, 11); 173 | $this->vars['emotionalhistory'] = _utils_string_at_index($responseValues, 12); 174 | $this->vars['ttsLocMP3'] = _utils_string_at_index($responseValues, 13); 175 | $this->vars['ttsLocTXT'] = _utils_string_at_index($responseValues, 14); 176 | $this->vars['ttsLocTXT3'] = _utils_string_at_index($responseValues, 15); 177 | $this->vars['ttsText'] = _utils_string_at_index($responseValues, 16); 178 | $this->vars['lineRef'] = _utils_string_at_index($responseValues, 17); 179 | $this->vars['lineURL'] = _utils_string_at_index($responseValues, 18); 180 | $this->vars['linePOST'] = _utils_string_at_index($responseValues, 19); 181 | $this->vars['lineChoices'] = _utils_string_at_index($responseValues, 20); 182 | $this->vars['lineChoicesAbbrev'] = _utils_string_at_index($responseValues, 21); 183 | $this->vars['typingData'] = _utils_string_at_index($responseValues, 22); 184 | $this->vars['divert'] = _utils_string_at_index($responseValues, 23); 185 | $responseThought = new ChatterBotThought(); 186 | $responseThought->setText(_utils_string_at_index($responseValues, 16)); 187 | return $responseThought; 188 | } 189 | } 190 | 191 | ################################################# 192 | # Pandorabots impl 193 | ################################################# 194 | 195 | class _Pandorabots extends ChatterBot 196 | { 197 | private $botid; 198 | 199 | public function __construct($botid) 200 | { 201 | $this->botid = $botid; 202 | } 203 | 204 | public function getBotid() 205 | { 206 | return $this->botid; 207 | } 208 | 209 | public function setBotid($botid) 210 | { 211 | $this->botid = $botid; 212 | } 213 | 214 | public function createSession() 215 | { 216 | return new _PandorabotsSession($this); 217 | } 218 | } 219 | 220 | class _PandorabotsSession extends ChatterBotSession 221 | { 222 | private $vars; 223 | 224 | public function __construct($bot) 225 | { 226 | $this->vars = array(); 227 | $this->vars['botid'] = $bot->getBotid(); 228 | $this->vars['custid'] = uniqid(); 229 | } 230 | 231 | public function thinkThought($thought) 232 | { 233 | $this->vars['input'] = $thought->getText(); 234 | $response = _utils_post('http://www.pandorabots.com/pandora/talk-xml', $this->vars); 235 | $element = new SimpleXMLElement($response); 236 | $result = $element->xpath('//result/that/text()'); 237 | $responseThought = new ChatterBotThought(); 238 | $responseThought->setText(trim($result[0][0])); 239 | return $responseThought; 240 | } 241 | } 242 | 243 | ################################################# 244 | # Utils 245 | ################################################# 246 | 247 | function _utils_post($url, $params) 248 | { 249 | $contextParams = array(); 250 | $contextParams['http'] = array(); 251 | $contextParams['http']['method'] = 'POST'; 252 | $contextParams['http']['content'] = http_build_query($params); 253 | $contextParams['http']['header'] = "Content-type: application/x-www-form-urlencoded\r\n"; 254 | $context = stream_context_create($contextParams); 255 | $fp = fopen($url, 'rb', false, $context); 256 | $response = stream_get_contents($fp); 257 | fclose($fp); 258 | return $response; 259 | } 260 | 261 | function _utils_string_at_index($strings, $index) 262 | { 263 | if (count($strings) > $index) 264 | { 265 | return $strings[$index]; 266 | } 267 | else 268 | { 269 | return ''; 270 | } 271 | } 272 | ?> 273 | -------------------------------------------------------------------------------- /php/chatterbotapitest.php: -------------------------------------------------------------------------------- 1 | . 18 | */ 19 | 20 | require 'chatterbotapi.php'; 21 | 22 | $factory = new ChatterBotFactory(); 23 | 24 | $bot1 = $factory->create(ChatterBotType::CLEVERBOT); 25 | $bot1session = $bot1->createSession(); 26 | 27 | $bot2 = $factory->create(ChatterBotType::PANDORABOTS, 'b0dafd24ee35a477'); 28 | $bot2session = $bot2->createSession(); 29 | 30 | $s = 'Hi'; 31 | while (1) 32 | { 33 | echo "bot1> $s\n"; 34 | 35 | $s = $bot2session->think($s); 36 | echo "bot2> $s\n"; 37 | 38 | $s = $bot1session->think($s); 39 | } 40 | ?> -------------------------------------------------------------------------------- /php/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "autoload": { 3 | "psr-0": { 4 | "ChatterBotApi\\": "src/" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /php/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 16 | 17 | 18 | ./vendor 19 | 20 | 21 | 22 | 23 | 24 | ./tests/ 25 | 26 | 27 | -------------------------------------------------------------------------------- /php/src/ChatterBotApi/AbstractBot.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | /** 22 | * Abstract for all ChatterBots 23 | */ 24 | abstract class AbstractBot 25 | { 26 | /** 27 | * Create the session 28 | * @return \ChatterBotApi\ChatterBotSession The new session instance 29 | */ 30 | public function createSession() 31 | { 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /php/src/ChatterBotApi/AbstractSession.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | /** 22 | * Abstract for all ChatterBot Sessions 23 | */ 24 | abstract class AbstractSession 25 | { 26 | /** 27 | * Return new thought based on given thought 28 | * @param \ChatterBotApi\ChatterBotThought $thought The previous thought 29 | * @return \ChatterBotApi\ChatterBotThought The new thought. 30 | */ 31 | public function thinkThought(ChatterBotThought $thought) 32 | { 33 | return $thought; 34 | } 35 | 36 | /** 37 | * Return a new thought based on given string 38 | * @param string $text The text 39 | * 40 | * @return \ChatterBotApi\ChatterBotThought The new thought. 41 | */ 42 | public function think($text) 43 | { 44 | $thought = ChatterBotThought::make($text); 45 | return $this->thinkThought($thought); 46 | } 47 | } -------------------------------------------------------------------------------- /php/src/ChatterBotApi/ChatterBotFactory.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | use Exception; 22 | use InvalidArgumentException; 23 | use ChatterBotApi\Implementation\CleverBot\CleverBot; 24 | use ChatterBotApi\Implementation\PandoraBots\PandoraBots; 25 | 26 | /** 27 | * The ChatterBotFactory 28 | */ 29 | class ChatterBotFactory 30 | { 31 | /** 32 | * Create a new a ChatterBot 33 | * @param int $type The ChatterBotType (hint: use the ChatterBotType constants) 34 | * @param string $arg BotId (only needed when using a PandoraBot) 35 | * 36 | * @return \ChatterBotApi\ChatterBot The new Bot instance 37 | * 38 | * @throws \Exception When type not recognized or no BotId bassed to the PandoraBot 39 | */ 40 | public static function create($type, $arg = null) 41 | { 42 | switch ($type) { 43 | case ChatterBotType::CLEVERBOT: 44 | return new Cleverbot('http://www.cleverbot.com/webservicemin'); 45 | 46 | 47 | case ChatterBotType::JABBERWACKY: 48 | return new Cleverbot('http://jabberwacky.com/webservicemin'); 49 | 50 | case ChatterBotType::PANDORABOTS: 51 | if ($arg == null) { 52 | throw new Exception('PANDORABOTS needs a botid arg'); 53 | } 54 | return new PandoraBots($arg); 55 | 56 | default: 57 | throw new InvalidArgumentException('Type not recognized'); 58 | 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /php/src/ChatterBotApi/ChatterBotThought.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | /** 22 | * A ChatterBot thought 23 | */ 24 | class ChatterBotThought 25 | { 26 | /** 27 | * The associated Text 28 | * @var string 29 | */ 30 | private $text; 31 | 32 | /** 33 | * Factory Method. 34 | * @param string $text [description] 35 | * @return \ChatterBotApi\ChatterBotThought The new instance 36 | */ 37 | public static function make($text = '') 38 | { 39 | return new static($text); 40 | } 41 | 42 | /** 43 | * Contructor. 44 | * @param string $text The text 45 | */ 46 | public function __construct($text = '') 47 | { 48 | $this->setText($text); 49 | } 50 | 51 | /** 52 | * Magic Method __toString 53 | * @return string The text 54 | */ 55 | public function __toString() 56 | { 57 | return (string) $this->text; 58 | } 59 | 60 | /** 61 | * Wrapper for getText() 62 | * @uses getText() 63 | * @return string The text 64 | */ 65 | public function message() 66 | { 67 | return $this->getText(); 68 | } 69 | 70 | /** 71 | * Get the text of this thought 72 | * @return string The text 73 | */ 74 | public function getText() 75 | { 76 | return $this->text; 77 | } 78 | 79 | /** 80 | * Set the text of this thought 81 | * @param string $text The text 82 | */ 83 | public function setText($text) 84 | { 85 | $this->text = $text; 86 | } 87 | } -------------------------------------------------------------------------------- /php/src/ChatterBotApi/ChatterBotType.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | /** 22 | * The ChatterBot type 23 | */ 24 | class ChatterBotType 25 | { 26 | /** 27 | * CleverBot 28 | * @var int 1 29 | */ 30 | const CLEVERBOT = 1; 31 | 32 | /** 33 | * JabberWacky 34 | * @var int 2 35 | */ 36 | const JABBERWACKY = 2; 37 | 38 | /** 39 | * PandoraBot 40 | * @var int 3 41 | */ 42 | const PANDORABOTS = 3; 43 | 44 | /** 45 | * A "good" bot ID 46 | * @var string 47 | */ 48 | const PANDORABOTS_DEFAULT_ID = 'b0dafd24ee35a477'; 49 | } -------------------------------------------------------------------------------- /php/src/ChatterBotApi/IOException.php: -------------------------------------------------------------------------------- 1 | . 20 | */ 21 | 22 | use Exception; 23 | 24 | /** 25 | * An IO Exception 26 | * @author Christian Gärtner 27 | */ 28 | class IOException extends Exception 29 | { 30 | private $path; 31 | 32 | public function __construct($message, $code = 0, $path = null, Exception $previous = null) 33 | { 34 | if ($path === '' && $path !== null) { 35 | $path = ''; 36 | } 37 | $this->path = $path; 38 | parent::__construct($message, $code, $previous); 39 | } 40 | 41 | /** 42 | * Magic Function. __toString 43 | * @return string The exception message 44 | * @Override 45 | */ 46 | public function __toString() 47 | { 48 | return __CLASS__ . ": [{$this->code}]: {$this->message}\nIO path: {$this->path}\n"; 49 | } 50 | 51 | /** 52 | * Returns the path of this IOException 53 | * @return string The path 54 | */ 55 | public function getPath() 56 | { 57 | return $this->path; 58 | } 59 | } -------------------------------------------------------------------------------- /php/src/ChatterBotApi/Implementation/CleverBot/CleverBot.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | use ChatterBotApi\AbstractBot; 22 | 23 | /** 24 | * A cleverbot 25 | */ 26 | class CleverBot extends AbstractBot 27 | { 28 | /** 29 | * The url for this chatterbot 30 | * @var string 31 | */ 32 | private $url; 33 | 34 | /** 35 | * Constructor. 36 | * @param string $url The url for this chatterbot 37 | */ 38 | public function __construct($url) 39 | { 40 | $this->url = $url; 41 | } 42 | 43 | /** 44 | * Get the url of this chatterbot 45 | * @return string The url 46 | */ 47 | public function getUrl() 48 | { 49 | return $this->url; 50 | } 51 | 52 | /** 53 | * Set the url for this chatterbot 54 | * @param string $url The url 55 | */ 56 | public function setUrl($url) 57 | { 58 | $this->url = $url; 59 | } 60 | 61 | /** 62 | * Create a new Session for this bot 63 | * @return \ChatterBotApi\Implementation\CleverBot\Session The new Session 64 | */ 65 | public function createSession() 66 | { 67 | return new Session($this); 68 | } 69 | } -------------------------------------------------------------------------------- /php/src/ChatterBotApi/Implementation/CleverBot/Session.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | use Exception; 22 | use ChatterBotApi\Utils; 23 | use ChatterBotApi\AbstractSession; 24 | use ChatterBotApi\ChatterBotThought; 25 | 26 | class Session extends AbstractSession 27 | { 28 | /** 29 | * The assoc. bot of this session 30 | * @var \ChatterBotApi\Implementation\CleverBot\CleverBot 31 | */ 32 | private $bot; 33 | 34 | /** 35 | * Varibales used for creating the request 36 | * @var array 37 | */ 38 | private $vars; 39 | 40 | /** 41 | * Constructor. 42 | * @param \ChatterBotApi\Implementation\CleverBot\CleverBot $bot The bot 43 | */ 44 | public function __construct(CleverBot $bot) 45 | { 46 | $this->bot = $bot; 47 | $this->vars = array(); 48 | $this->vars['start'] = 'y'; 49 | $this->vars['icognoid'] = 'wsf'; 50 | $this->vars['fno'] = '0'; 51 | $this->vars['sub'] = 'Say'; 52 | $this->vars['islearning'] = '1'; 53 | $this->vars['cleanslate'] = 'false'; 54 | } 55 | 56 | /** 57 | * Return new thought based on given thought 58 | * @param \ChatterBotApi\ChatterBotTought $thought The previous thought 59 | * @return \ChatterBotApi\ChatterBotTought The new thought. 60 | */ 61 | public function thinkThought(ChatterBotThought $thought) 62 | { 63 | $this->vars['stimulus'] = $thought->getText(); 64 | 65 | $data = http_build_query($this->vars); 66 | 67 | $dataToDigest = substr($data, 9, 20); 68 | 69 | $dataDigest = md5($dataToDigest); 70 | 71 | $this->vars['icognocheck'] = $dataDigest; 72 | 73 | $response = Utils::post($this->bot->getUrl(), $this->vars); 74 | 75 | $responseValues = explode("\r", $response); 76 | 77 | // $this->vars['??'] = Utils::stringAtIndex($responseValues, 0); 78 | $this->vars['sessionid'] = Utils::stringAtIndex($responseValues, 1); 79 | $this->vars['logurl'] = Utils::stringAtIndex($responseValues, 2); 80 | $this->vars['vText8'] = Utils::stringAtIndex($responseValues, 3); 81 | $this->vars['vText7'] = Utils::stringAtIndex($responseValues, 4); 82 | $this->vars['vText6'] = Utils::stringAtIndex($responseValues, 5); 83 | $this->vars['vText5'] = Utils::stringAtIndex($responseValues, 6); 84 | $this->vars['vText4'] = Utils::stringAtIndex($responseValues, 7); 85 | $this->vars['vText3'] = Utils::stringAtIndex($responseValues, 8); 86 | $this->vars['vText2'] = Utils::stringAtIndex($responseValues, 9); 87 | $this->vars['prevref'] = Utils::stringAtIndex($responseValues, 10); 88 | // $this->vars['??'] = Utils::stringAtIndex($responseValues, 11); 89 | $this->vars['emotionalhistory'] = Utils::stringAtIndex($responseValues, 12); 90 | $this->vars['ttsLocMP3'] = Utils::stringAtIndex($responseValues, 13); 91 | $this->vars['ttsLocTXT'] = Utils::stringAtIndex($responseValues, 14); 92 | $this->vars['ttsLocTXT3'] = Utils::stringAtIndex($responseValues, 15); 93 | $this->vars['ttsText'] = Utils::stringAtIndex($responseValues, 16); 94 | $this->vars['lineRef'] = Utils::stringAtIndex($responseValues, 17); 95 | $this->vars['lineURL'] = Utils::stringAtIndex($responseValues, 18); 96 | $this->vars['linePOST'] = Utils::stringAtIndex($responseValues, 19); 97 | $this->vars['lineChoices'] = Utils::stringAtIndex($responseValues, 20); 98 | $this->vars['lineChoicesAbbrev'] = Utils::stringAtIndex($responseValues, 21); 99 | $this->vars['typingData'] = Utils::stringAtIndex($responseValues, 22); 100 | $this->vars['divert'] = Utils::stringAtIndex($responseValues, 23); 101 | 102 | if ('' == Utils::stringAtIndex($responseValues, 16)) { 103 | throw new Exception('Empty Response'); 104 | } 105 | return ChatterBotThought::make(Utils::stringAtIndex($responseValues, 16)); 106 | } 107 | } -------------------------------------------------------------------------------- /php/src/ChatterBotApi/Implementation/PandoraBots/PandoraBots.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | use ChatterBotApi\AbstractBot; 22 | 23 | /** 24 | * A Pandora Bot 25 | */ 26 | class PandoraBots extends AbstractBot 27 | { 28 | /** 29 | * The BotID 30 | * @var string 31 | */ 32 | private $botid; 33 | 34 | /** 35 | * Constructor. 36 | * @param string $botid The Bot ID 37 | */ 38 | public function __construct($botid) 39 | { 40 | $this->botid = $botid; 41 | } 42 | 43 | /** 44 | * Returns the bot ID 45 | * @return string The bot ID 46 | */ 47 | public function getId() 48 | { 49 | return $this->botid; 50 | } 51 | 52 | /** 53 | * Set the bot ID 54 | * @param string $botid The bot ID 55 | */ 56 | public function setId($botid) 57 | { 58 | $this->botid = $botid; 59 | } 60 | 61 | /** 62 | * Create a new Session for this bot 63 | * @return \ChatterBotApi\Implementation\PandoraBots\Session The new Session 64 | */ 65 | public function createSession() 66 | { 67 | return new Session($this); 68 | } 69 | } -------------------------------------------------------------------------------- /php/src/ChatterBotApi/Implementation/PandoraBots/Session.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | use Exception; 22 | use SimpleXMLElement; 23 | use ChatterBotApi\Utils; 24 | use ChatterBotApi\AbstractSession; 25 | use ChatterBotApi\ChatterBotThought; 26 | 27 | class Session extends AbstractSession 28 | { 29 | /** 30 | * Varibales used for creating the request 31 | * @var array 32 | */ 33 | private $vars; 34 | 35 | /** 36 | * Constructor. 37 | * @param \ChatterBotApi\Implementation\PandoraBots $bot The bot 38 | */ 39 | public function __construct(PandoraBots $bot) 40 | { 41 | $this->vars = array(); 42 | $this->vars['botid'] = $bot->getId(); 43 | $this->vars['custid'] = uniqid(); 44 | } 45 | 46 | /** 47 | * Return new thought based on given thought 48 | * @param \ChatterBotApi\ChatterBotTought $thought The previous thought 49 | * @return \ChatterBotApi\ChatterBotTought The new thought. 50 | * 51 | * @throws \Exception If response is empty (when input string is empty) 52 | */ 53 | public function thinkThought(ChatterBotThought $thought) 54 | { 55 | $this->vars['input'] = $thought->getText(); 56 | 57 | 58 | $response = Utils::post('http://www.pandorabots.com/pandora/talk-xml', $this->vars); 59 | 60 | $element = new SimpleXMLElement($response); 61 | 62 | $result = $element->xpath('//result/that/text()'); 63 | 64 | if (isset($result[0][0])) { 65 | return ChatterBotThought::make($result[0][0]); 66 | } else { 67 | throw new Exception('Empty Response'); 68 | 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /php/src/ChatterBotApi/Utils.php: -------------------------------------------------------------------------------- 1 | . 19 | */ 20 | 21 | /** 22 | * Utils class 23 | */ 24 | class Utils 25 | { 26 | /** 27 | * Post to the given URL 28 | * @param string $url The target url 29 | * @param array $params The parameters 30 | * @return string The response 31 | */ 32 | public static function post($url, $params) 33 | { 34 | $contextParams = array(); 35 | $contextParams['http'] = array(); 36 | $contextParams['http']['method'] = 'POST'; 37 | $contextParams['http']['content'] = http_build_query($params); 38 | $contextParams['http']['header'] = "Content-Type: application/x-www-form-urlencoded\r\n"; 39 | $context = stream_context_create($contextParams); 40 | $fp = @fopen($url, 'rb', false, $context); 41 | if (!$fp) { 42 | throw new IOException('Connection refused', 0, $url); 43 | } 44 | 45 | $response = @stream_get_contents($fp); 46 | 47 | if ($response === false || $response === null) { 48 | throw new IOException('Cannot grab data', 0, $url); 49 | } 50 | fclose($fp); 51 | return $response; 52 | } 53 | 54 | /** 55 | * Returns the string at the given index 56 | * @param array $strings The strings 57 | * @param int $index The index 58 | * @return string The string | '' 59 | */ 60 | public static function stringAtIndex($strings, $index) 61 | { 62 | if (count($strings) > $index && isset($strings[$index])) { 63 | return $strings[$index]; 64 | } else { 65 | return ''; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /php/tests/ChatterBotApi/ChatterBotFactoryTest.php: -------------------------------------------------------------------------------- 1 | . 18 | */ 19 | 20 | use ChatterBotApi\ChatterBotFactory; 21 | 22 | /** 23 | * PHPUnit Test 24 | */ 25 | class ChatterBotFactoryTest extends PHPUnit_Framework_TestCase 26 | { 27 | /** 28 | * @dataProvider createData 29 | */ 30 | public function testCreate($type, $arg, $exp) 31 | { 32 | $this->assertInstanceOf($exp, ChatterBotFactory::create($type, $arg)); 33 | } 34 | 35 | public function createData() 36 | { 37 | return array( 38 | array(1, null, 'ChatterBotApi\\Implementation\\CleverBot\\CleverBot'), 39 | array(1, null, 'ChatterBotApi\\AbstractBot'), 40 | 41 | array(2, null, 'ChatterBotApi\\Implementation\\CleverBot\\CleverBot'), 42 | array(2, null, 'ChatterBotApi\\AbstractBot'), 43 | 44 | array(3, 'b0dafd24ee35a477', 'ChatterBotApi\\Implementation\\PandoraBots\\PandoraBots'), 45 | array(3, 'b0dafd24ee35a477', 'ChatterBotApi\\AbstractBot') 46 | ); 47 | } 48 | 49 | /** 50 | * @expectedException Exception 51 | */ 52 | public function testCreateException() 53 | { 54 | ChatterBotFactory::create(3); 55 | } 56 | 57 | /** 58 | * @expectedException InvalidArgumentException 59 | */ 60 | public function testCreateInvalidArgumentException() 61 | { 62 | ChatterBotFactory::create('Foo'); 63 | } 64 | } -------------------------------------------------------------------------------- /php/tests/ChatterBotApi/ChatterBotThoughtTest.php: -------------------------------------------------------------------------------- 1 | . 18 | */ 19 | 20 | use ChatterBotApi\ChatterBotThought; 21 | 22 | /** 23 | * PHPUnit Test 24 | */ 25 | class ChatterBotThoughtTest extends PHPUnit_Framework_TestCase 26 | { 27 | public function testMake() 28 | { 29 | $this->assertInstanceOf('ChatterBotApi\ChatterBotThought', ChatterBotThought::make()); 30 | } 31 | 32 | /** 33 | * @dataProvider constructData 34 | */ 35 | public function testConstruct($text, $exp) 36 | { 37 | if ($text === null) { 38 | $t = new ChatterBotThought(); 39 | } else { 40 | $t = new ChatterBotThought($text); 41 | } 42 | 43 | $rp = new ReflectionProperty($t, 'text'); 44 | $rp->setAccessible(true); 45 | 46 | $this->assertEquals($exp, $rp->getValue($t)); 47 | 48 | } 49 | 50 | public function constructData() 51 | { 52 | return array( 53 | array(null, ''), 54 | array('Foo', 'Foo') 55 | ); 56 | } 57 | 58 | public function testToString() 59 | { 60 | $t = ChatterBotThought::make('Foo'); 61 | 62 | $this->assertEquals('Foo', (string) $t); 63 | } 64 | 65 | public function testGetText() 66 | { 67 | $t = ChatterBotThought::make('Foo'); 68 | 69 | $this->assertEquals('Foo', $t->getText()); 70 | } 71 | 72 | public function testSetText() 73 | { 74 | $t = ChatterBotThought::make('Foo'); 75 | $t->setText('Bar'); 76 | $this->assertEquals('Bar', $t->getText()); 77 | } 78 | 79 | public function testMessage() 80 | { 81 | $t = ChatterBotThought::make('Foo'); 82 | 83 | $this->assertEquals('Foo', $t->message()); 84 | } 85 | } -------------------------------------------------------------------------------- /php/tests/ChatterBotApi/ChatterBotTypeTest.php: -------------------------------------------------------------------------------- 1 | . 18 | */ 19 | 20 | use ChatterBotApi\ChatterBotType; 21 | 22 | /** 23 | * PHPUnit Test 24 | */ 25 | class ChatterBotTypeTest extends PHPUnit_Framework_TestCase 26 | { 27 | public function testCleverbot() 28 | { 29 | $this->assertEquals(1, ChatterBotType::CLEVERBOT); 30 | } 31 | 32 | public function testJabberWacky() 33 | { 34 | $this->assertEquals(2, ChatterBotType::JABBERWACKY); 35 | } 36 | 37 | public function testPandoraBots() 38 | { 39 | $this->assertEquals(3, ChatterBotType::PANDORABOTS); 40 | } 41 | 42 | public function testPandoraBotsID() 43 | { 44 | $this->assertEquals('b0dafd24ee35a477', ChatterBotType::PANDORABOTS_DEFAULT_ID); 45 | } 46 | } -------------------------------------------------------------------------------- /php/tests/ChatterBotApi/IOExceptionTest.php: -------------------------------------------------------------------------------- 1 | . 18 | */ 19 | 20 | use ChatterBotApi\IOException; 21 | 22 | /** 23 | * PHPUnit Test 24 | */ 25 | class IOExceptionTest extends PHPUnit_Framework_TestCase 26 | { 27 | /** 28 | * @dataProvider contructData 29 | */ 30 | public function testContruct($path, $exp) 31 | { 32 | $e = new IOException('Foo', 1, $path); 33 | 34 | $rp = new ReflectionProperty($e, 'path'); 35 | $rp->setAccessible(true); 36 | 37 | $this->assertEquals($exp, $rp->getValue($e)); 38 | } 39 | 40 | public function contructData() 41 | { 42 | return array( 43 | array('foo/bar', 'foo/bar'), 44 | array('', ''), 45 | array(null, null), 46 | ); 47 | } 48 | 49 | public function testGetpath() 50 | { 51 | $e = new IOException('Foo', 1, 'foo/bar'); 52 | 53 | $this->assertEquals('foo/bar', $e->getPath()); 54 | } 55 | 56 | public function testToString() 57 | { 58 | $e = new IOException('Foo', 1, 'foo/bar'); 59 | 60 | $this->assertEquals("ChatterBotApi\IOException: [1]: Foo\nIO path: foo/bar\n", (string) $e); 61 | } 62 | } -------------------------------------------------------------------------------- /php/tests/ChatterBotApi/UtilsTest.php: -------------------------------------------------------------------------------- 1 | . 18 | */ 19 | 20 | use ChatterBotApi\Utils; 21 | 22 | /** 23 | * PHPUnit Test 24 | */ 25 | class UtilsTest extends PHPUnit_Framework_TestCase 26 | { 27 | /** 28 | * @dataProvider stringAtIndexData 29 | */ 30 | public function testStringAtIndex($strings, $index, $exp) 31 | { 32 | $this->assertEquals($exp, Utils::stringAtIndex($strings, $index)); 33 | } 34 | 35 | public function stringAtIndexData() 36 | { 37 | return array( 38 | array( 39 | array('Foo', 'Bar', 'Baz'), 40 | 0, 41 | 'Foo' 42 | ), 43 | array( 44 | array('Foo', 'Bar', 'Baz'), 45 | 1, 46 | 'Bar' 47 | ), 48 | array( 49 | array('Foo', 'Bar', 'Baz'), 50 | 2, 51 | 'Baz' 52 | ), 53 | array( 54 | array('Foo', 'Bar', 'Baz'), 55 | 8, 56 | '' 57 | ), 58 | ); 59 | } 60 | } -------------------------------------------------------------------------------- /python/chatterbotapi.py: -------------------------------------------------------------------------------- 1 | import hashlib 2 | import urllib 3 | import urllib2 4 | import uuid 5 | import xml.dom.minidom 6 | 7 | """ 8 | chatterbotapi 9 | Copyright (C) 2011 pierredavidbelanger@gmail.com 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Lesser General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public License 22 | along with this program. If not, see . 23 | """ 24 | 25 | ################################################# 26 | # API 27 | ################################################# 28 | 29 | class ChatterBotType: 30 | 31 | CLEVERBOT = 1 32 | JABBERWACKY = 2 33 | PANDORABOTS = 3 34 | 35 | class ChatterBotFactory: 36 | 37 | def create(self, type, arg = None): 38 | if type == ChatterBotType.CLEVERBOT: 39 | return _Cleverbot('http://www.cleverbot.com/webservicemin', 35) 40 | elif type == ChatterBotType.JABBERWACKY: 41 | return _Cleverbot('http://jabberwacky.com/webservicemin', 29) 42 | elif type == ChatterBotType.PANDORABOTS: 43 | if arg == None: 44 | raise Exception('PANDORABOTS needs a botid arg') 45 | return _Pandorabots(arg) 46 | return None 47 | 48 | class ChatterBot: 49 | 50 | def create_session(self): 51 | return None 52 | 53 | class ChatterBotSession: 54 | 55 | def think_thought(self, thought): 56 | return thought 57 | 58 | def think(self, text): 59 | thought = ChatterBotThought() 60 | thought.text = text 61 | return self.think_thought(thought).text 62 | 63 | class ChatterBotThought: 64 | 65 | pass 66 | 67 | ################################################# 68 | # Cleverbot impl 69 | ################################################# 70 | 71 | class _Cleverbot(ChatterBot): 72 | 73 | def __init__(self, url, endIndex): 74 | self.url = url 75 | self.endIndex = endIndex 76 | 77 | def create_session(self): 78 | return _CleverbotSession(self) 79 | 80 | class _CleverbotSession(ChatterBotSession): 81 | 82 | def __init__(self, bot): 83 | self.bot = bot 84 | self.vars = {} 85 | self.vars['start'] = 'y' 86 | self.vars['icognoid'] = 'wsf' 87 | self.vars['fno'] = '0' 88 | self.vars['sub'] = 'Say' 89 | self.vars['islearning'] = '1' 90 | self.vars['cleanslate'] = 'false' 91 | 92 | def think_thought(self, thought): 93 | self.vars['stimulus'] = thought.text 94 | data = urllib.urlencode(self.vars) 95 | data_to_digest = data[9:self.bot.endIndex] 96 | data_digest = hashlib.md5(data_to_digest).hexdigest() 97 | data = data + '&icognocheck=' + data_digest 98 | url_response = urllib2.urlopen(self.bot.url, data) 99 | response = url_response.read() 100 | response_values = response.split('\r') 101 | #self.vars['??'] = _utils_string_at_index(response_values, 0) 102 | self.vars['sessionid'] = _utils_string_at_index(response_values, 1) 103 | self.vars['logurl'] = _utils_string_at_index(response_values, 2) 104 | self.vars['vText8'] = _utils_string_at_index(response_values, 3) 105 | self.vars['vText7'] = _utils_string_at_index(response_values, 4) 106 | self.vars['vText6'] = _utils_string_at_index(response_values, 5) 107 | self.vars['vText5'] = _utils_string_at_index(response_values, 6) 108 | self.vars['vText4'] = _utils_string_at_index(response_values, 7) 109 | self.vars['vText3'] = _utils_string_at_index(response_values, 8) 110 | self.vars['vText2'] = _utils_string_at_index(response_values, 9) 111 | self.vars['prevref'] = _utils_string_at_index(response_values, 10) 112 | #self.vars['??'] = _utils_string_at_index(response_values, 11) 113 | self.vars['emotionalhistory'] = _utils_string_at_index(response_values, 12) 114 | self.vars['ttsLocMP3'] = _utils_string_at_index(response_values, 13) 115 | self.vars['ttsLocTXT'] = _utils_string_at_index(response_values, 14) 116 | self.vars['ttsLocTXT3'] = _utils_string_at_index(response_values, 15) 117 | self.vars['ttsText'] = _utils_string_at_index(response_values, 16) 118 | self.vars['lineRef'] = _utils_string_at_index(response_values, 17) 119 | self.vars['lineURL'] = _utils_string_at_index(response_values, 18) 120 | self.vars['linePOST'] = _utils_string_at_index(response_values, 19) 121 | self.vars['lineChoices'] = _utils_string_at_index(response_values, 20) 122 | self.vars['lineChoicesAbbrev'] = _utils_string_at_index(response_values, 21) 123 | self.vars['typingData'] = _utils_string_at_index(response_values, 22) 124 | self.vars['divert'] = _utils_string_at_index(response_values, 23) 125 | response_thought = ChatterBotThought() 126 | response_thought.text = _utils_string_at_index(response_values, 16) 127 | return response_thought 128 | 129 | ################################################# 130 | # Pandorabots impl 131 | ################################################# 132 | 133 | class _Pandorabots(ChatterBot): 134 | 135 | def __init__(self, botid): 136 | self.botid = botid 137 | 138 | def create_session(self): 139 | return _PandorabotsSession(self) 140 | 141 | class _PandorabotsSession(ChatterBotSession): 142 | 143 | def __init__(self, bot): 144 | self.vars = {} 145 | self.vars['botid'] = bot.botid 146 | self.vars['custid'] = uuid.uuid1() 147 | 148 | def think_thought(self, thought): 149 | self.vars['input'] = thought.text 150 | data = urllib.urlencode(self.vars) 151 | url_response = urllib2.urlopen('http://www.pandorabots.com/pandora/talk-xml', data) 152 | response = url_response.read() 153 | response_dom = xml.dom.minidom.parseString(response) 154 | response_thought = ChatterBotThought() 155 | that_elements = response_dom.getElementsByTagName('that') 156 | if that_elements is None or len(that_elements) == 0 or that_elements[0] is None: 157 | return '' 158 | that_elements_child_nodes = that_elements[0].childNodes 159 | if that_elements_child_nodes is None or len(that_elements_child_nodes) == 0 or that_elements_child_nodes[0] is None: 160 | return '' 161 | that_elements_child_nodes_data = that_elements_child_nodes[0].data 162 | if that_elements_child_nodes_data is None: 163 | return '' 164 | response_thought.text = that_elements_child_nodes_data.strip() 165 | return response_thought 166 | 167 | ################################################# 168 | # Utils 169 | ################################################# 170 | 171 | def _utils_string_at_index(strings, index): 172 | if len(strings) > index: 173 | return strings[index] 174 | else: 175 | return '' 176 | -------------------------------------------------------------------------------- /python/chatterbotapi.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Schumix/ChatterBotApi/3e60051a0283f9b8916a4dd2ae169c75efb24402/python/chatterbotapi.pyc -------------------------------------------------------------------------------- /python/chatterbotapitest.py: -------------------------------------------------------------------------------- 1 | from chatterbotapi import ChatterBotFactory, ChatterBotType 2 | 3 | """ 4 | chatterbotapi 5 | Copyright (C) 2011 pierredavidbelanger@gmail.com 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | factory = ChatterBotFactory() 22 | 23 | bot1 = factory.create(ChatterBotType.CLEVERBOT) 24 | bot1session = bot1.create_session() 25 | 26 | bot2 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477') 27 | bot2session = bot2.create_session() 28 | 29 | s = 'Hi' 30 | while (1): 31 | 32 | print 'bot1> ' + s 33 | 34 | s = bot2session.think(s); 35 | print 'bot2> ' + s 36 | 37 | s = bot1session.think(s); 38 | --------------------------------------------------------------------------------