Click here to Skip to main content
11,649,304 members (81,623 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
Add your own
alternative version

Building an AI Chatbot using a Regular Expression Engine

, 21 Jun 2007 GPL3 84.7K 1.9K 56
This article describes how to build an AI Chatterbot using a popular, Regular Expression-based open source Chatterbot engine: Verbots
verbotsdk.zip
mssccprj.scc
ResourceFiles
bin
Debug
ResourceFiles.dll
ResourceFiles.pdb
Release
ResourceFiles.dll
CHANGELOG
COPYING
mssccprj.scc
obj
Debug
buildinfo.inf
ResourceFiles.dll
ResourceFiles.pdb
ResourceFiles.projdata
temp
TempPE
Release
buildinfo.inf
ResourceFiles.dll
ResourceFiles.projdata
temp
TempPE
ResourceFiles.csproj.user
ResourceFiles.csproj.vspscc
vssver.scc
vssver2.scc
Verbot4Library
bin
Debug
Verbot4Library.dll
Verbot4Library.pdb
Release
Verbot4Library.dll
mssccprj.scc
obj
Debug
buildinfo.inf
temp
TempPE
Verbot4Library.dll
Verbot4Library.dll.incr
Verbot4Library.pdb
Verbot4Library.projdata
Release
buildinfo.inf
temp
TempPE
Verbot4Library.dll
Verbot4Library.projdata
Verbot4Library.csproj.user
Verbot4Library.csproj.vspscc
vssver.scc
vssver2.scc
VerbotConsoleApplication
App.ico
bin
Debug
Verbot4Library.dll
VerbotConsoleApplication.exe
VerbotConsoleApplication.pdb
Release
Verbot4Library.dll
VerbotConsoleApplication.exe
mssccprj.scc
obj
Debug
buildinfo.inf
temp
TempPE
VerbotConsoleApplication.exe
VerbotConsoleApplication.pdb
VerbotConsoleApplication.projdata
Release
buildinfo.inf
temp
TempPE
VerbotConsoleApplication.exe
VerbotConsoleApplication.projdata
VerbotConsoleApplication.csproj.user
VerbotConsoleApplication.csproj.vspscc
vssver.scc
VerbotSDK.vssscc
VerbotWindowsApplicationSample
App.ico
bin
Debug
Verbot4Library.dll
Verbot4Library.pdb
VerbotWindowsApplicationSample.exe
VerbotWindowsApplicationSample.pdb
Release
Verbot4Library.dll
VerbotWindowsApplicationSample.exe
mssccprj.scc
obj
Debug
buildinfo.inf
temp
TempPE
VerbotWindowsApplicationSample.exe
VerbotWindowsApplicationSample.pdb
VerbotWindowsApplicationSample.projdata
Release
buildinfo.inf
temp
TempPE
VerbotWindowsApplicationSample.exe
VerbotWindowsApplicationSample.projdata
VerbotWindowsApplicationSample.VerbotWinApp.resources
Resources
sample.ckb
sample.vkb
vssver2.scc
VerbotWindowsApplicationSample.csproj.user
VerbotWindowsApplicationSample.csproj.vspscc
vssver.scc
vssver2.scc
vssver.scc
vssver2.scc
/*
	Copyright 2004-2006 Conversive, Inc.
	http://www.conversive.com
	3806 Cross Creek Rd., Unit F
	Malibu, CA 90265
 
	This file is part of Verbot 4 Library: a natural language processing engine.

    Verbot 4 Library is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Verbot 4 Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Verbot 4 Library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
	
	Verbot 4 Library may also be available under other licenses.
*/

using System;
using System.Xml.Serialization;
using System.Collections;
using System.Security.Permissions;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace Conversive.Verbot4
{
	/// <summary>
	/// Defines a "virtual" class file for use in the Verbot 4 Engine.
	/// </summary>
	[Serializable]
	public class CodeModule : ISerializable
	{
		private string name;
		public string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				this.name = value;
			}
		}

		private CodeLanguages language;
		public CodeLanguages Language
		{
			get
			{
				return this.language;
			}
			set
			{
				this.language = value;
			}
		}

		private string includes;
		public string Includes
		{
			get
			{
				return this.includes;
			}
			set
			{
				this.includes = value;
			}
		}

		private string vars;
		public string Vars
		{
			get
			{
				return this.vars;
			}
			set
			{
				this.vars = value;
			}
		}

		[XmlArrayItem("Function")]
		public ArrayList Functions;

		/*
		 * Unserialized Attributes
		 */

		
		private bool changed;
		[XmlIgnoreAttribute]
		public bool Changed
		{
			get
			{
				return this.changed;
			}
			set
			{
				this.changed = value;
			}
		}

		public CodeModule()
		{
			this.name = "";
			this.language = CodeLanguages.CSharp;
			this.includes = "";
			this.vars = "";
			this.changed = false;
			this.Functions = new ArrayList();

		}

		protected CodeModule(SerializationInfo info, StreamingContext context)
		{
			this.changed = false;
			this.name = info.GetString("n");
			this.language = (CodeLanguages)info.GetValue("l", typeof(CodeLanguages));
			this.includes = info.GetString("i");
			this.vars = info.GetString("v");
			this.Functions = new ArrayList();
			this.Functions = (ArrayList)info.GetValue("f", typeof(ArrayList));
			
			//use a try/catch block around any new vales
		}
		[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter=true)]
		public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("n", this.name);
			info.AddValue("l", this.language);
			info.AddValue("i", this.includes);
			info.AddValue("v", this.vars);
			info.AddValue("f", this.Functions);
		}

		public override string ToString()
		{
			return this.name;
		}

		public Function GetFunction(string id)
		{
			foreach(Function f in this.Functions)
			{
				if(f.Id == id)
					return f;
			}
			return null;
		}

		public Function AddFunction(string name, string id)
		{
			Function f = new Function();
			f.Name = name;
			f.Id = id;
			this.Functions.Add(f);
			return f;
		}

		public void DeleteFunction(string id)
		{
			Function f = GetFunction(id);
			this.Functions.Remove(f);
		}

	}//class CodeModule

	[Serializable]
	public class Function : ISerializable
	{
		private string id;
		public string Id
		{
			get
			{
				return this.id;
			}
			set
			{
				this.id = value;
			}
		}

		private string name;
		public string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				this.name = value;
			}
		}

		private string returnType;
		public string ReturnType
		{
			get
			{
				return this.returnType;
			}
			set
			{
				this.returnType = value;
			}
		}

		private string parameters;
		public string Parameters
		{
			get
			{
				return this.parameters;
			}
			set
			{
				this.parameters = value;
			}
		}

		private string code;
		public string Code
		{
			get
			{
				return this.code;
			}
			set
			{
				this.code = value;
			}
		}

		public Function()
		{
			this.name = "";
			this.returnType = "string";
			this.parameters = "";
			this.code = "";
			this.id = "";
		}

		protected Function(SerializationInfo info, StreamingContext context)
		{
			this.name = info.GetString("n");
			this.returnType = info.GetString("rt");
			this.parameters = info.GetString("p");
			this.code = info.GetString("c");
			this.id = info.GetString("id");
			
			//use a try/catch block around any new vales
		}
		[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter=true)]
		public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("n", this.name);
			info.AddValue("rt", this.returnType);
			info.AddValue("p", this.parameters);
			info.AddValue("c", this.code);
			info.AddValue("id", this.id);
		}

	}//class code module
	
	public enum CodeLanguages
	{
		CSharp,
		PHP
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

MattsterP
Web Developer
United States United States
Matt Palmerlee is a Software Engineer that has been working in the Microsoft.NET environment developing C# WebServices, Windows Applications, Web Applications, and Windows Services since 2003.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150804.4 | Last Updated 21 Jun 2007
Article Copyright 2007 by MattsterP
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid