Click here to Skip to main content
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
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.Security.Permissions;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;
using System.Text;

namespace Conversive.Verbot4
{
	/// <summary>
	/// Defines a list of equivalent words or phrases.
	/// </summary>
	public class SynonymGroup
	{
		[XmlArrayItem("Synonym")]
		public ArrayList Synonyms;

		public SynonymGroup()
		{
			this.changed = false;
			this.Synonyms = new ArrayList();
		}

		/*
		 * Unserialized Attributes
		 */

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

		/*
		 * Modifier Methods
		 */

		public string AddSynonym(string synonymName)
		{
			Synonym synonymNew = new Synonym();
			synonymNew.Id = GetNewSynoymId();
			synonymNew.Name = synonymName;
			this.Synonyms.Add(synonymNew);
			return synonymNew.Id;
		}

		/*
		 * Accessor Methods
		 */

		public string GetNewSynoymId()
		{
			return TextToolbox.GetNewId();
		}

		public Synonym GetSynonym(string id)
		{
			//return null if not found
			foreach(Synonym s in this.Synonyms)
			{
				if(s.Id == id)
				{
					return s;
				}
			}
			return null;
		}//GetPhrase(string id)

	}//class SynonymGroup

	[Serializable]
	public class Synonym : ISerializable
	{
		private string name;
		public string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				this.name = value;
			}
		}

		private string id;
		public string Id
		{
			get
			{
				return this.id;
			}
			set
			{
				this.id = value;
			}
		}

		[XmlArrayItem("Phrase")]
		public ArrayList Phrases;

		public Synonym()
		{
			this.name = "";
			this.Phrases = new ArrayList();
		}

		protected Synonym(SerializationInfo info, StreamingContext context)
		{
			this.name = info.GetString("n");
			this.Phrases = (ArrayList)info.GetValue("p", 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("p", this.Phrases);
		}

		/*
		 * Modifier Methods
		 */

		public string AddPhrase(string phraseText)
		{
			Phrase phraseNew = new Phrase();
			phraseNew.Id = GetNewPhraseId();
			phraseNew.Text = phraseText;
			this.Phrases.Add(phraseNew);
			return phraseNew.Id;
		}

		/*
		 * Accessor Methods
		 */

		public string GetNewPhraseId()
		{
			return TextToolbox.GetNewId();
		}

		public Phrase GetPhrase(string id)
		{
			//return null if not found
			foreach(Phrase p in this.Phrases)
			{
				if(p.Id == id)
				{
					return p;
				}
			}
			return null;
		}//GetPhrase(string id)

		public string GetPhrases()
		{
			StringBuilder sb = new StringBuilder();
			bool first = true;
			foreach(Phrase p in this.Phrases)
			{
				if(!first)
					sb.Append("|");
				sb.Append(p.Text);
				first = false;
			}
			return sb.ToString();
		}//GetPhrases()
	}//class Synonym

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

		private string text;
		public string Text
		{
			get
			{
				return this.text;
			}
			set
			{
				this.text = value;
			}
		}

		public Phrase()
		{
			this.text = "";
			this.id = "";
		}

		public int CompareTo(Object other)
		{
			Phrase siOther = (Phrase)other;
			return ((-1) * this.text.Length.CompareTo(siOther.text.Length));
		}

		protected Phrase(SerializationInfo info, StreamingContext context)
		{
			this.text = info.GetString("t");
			this.id = info.GetString("i");
			//use a try/catch block around any new vales
		}
		[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter=true)]
		public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("t", this.text);
			info.AddValue("i", this.id);
		}
	}//Synonym
}//namespace Conversive.Verbot4

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.

| Advertise | Privacy | Mobile
Web04 | 2.8.141022.1 | Last Updated 21 Jun 2007
Article Copyright 2007 by MattsterP
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid