Click here to Skip to main content
11,704,107 members (52,992 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 85K 2K 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.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace Conversive.Verbot4
{
	/// <summary>
	/// Toolbox for reading and writing XML serialized files.
	/// </summary>
	public class XMLToolbox
	{
		public delegate void XmlSaveError(Exception e, string stPath);
		public event XmlSaveError OnXmlSaveError;

		public delegate void XmlLoadError(Exception e, string stPath);
		public event XmlLoadError OnXmlLoadError;

		private XmlSerializer xmlSerializer;

		public XMLToolbox(Type type)
		{
			Type[] types = {typeof(KnowledgeBase),
							   typeof(Rule),
							   typeof(Input),
							   typeof(Output),
							   typeof(ResourceFile),
							   typeof(SynonymGroup),
							   typeof(Synonym),
							   typeof(Phrase),
							   typeof(ReplacementProfile),
							   typeof(Replacement),
							   typeof(InputReplacement),
							   typeof(CodeModule),
							   typeof(Function),
							   typeof(Verbot4Preferences),
							   typeof(KnowledgeBaseItem),
							   typeof(KnowledgeBaseInfo),
							   typeof(KnowledgeBaseRating),
							   typeof(Verbot4Skin),
							   typeof(TTSModes),
							   typeof(TTSMode),
							   typeof(Font),
							   typeof(ArrayList)};
			xmlSerializer = new XmlSerializer(type, types);
		}

		private void raiseXmlSaveError(Exception e, string stPath)
		{
			if(this.OnXmlSaveError != null)
			{
				this.OnXmlSaveError(e, stPath);
			}
		}

		private void raiseXmlLoadError(Exception e, string stPath)
		{
			if(this.OnXmlLoadError != null)
			{
				this.OnXmlLoadError(e, stPath);
			}
		}

		public void SaveXML(object o, string stPath)
		{
			try
			{
				FileStream fs = new FileStream(stPath, FileMode.Create);
				StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
				xmlSerializer.Serialize(sw, o);
				sw.Flush();
				sw.Close();
			}
			catch (Exception e)
			{
				this.raiseXmlSaveError(e, stPath);
				//TODO: add a line to an error log
			}	
		}

		public object LoadXML(string stPath)
		{
			object obj = null;
			try
			{
				FileStream fs = new FileStream(stPath, FileMode.Open);
				XmlTextReader xtr = new XmlTextReader(fs);
				obj = xmlSerializer.Deserialize(xtr);
				fs.Flush();
				fs.Close();
				xtr.Close();
				return obj;
			} 
			catch (Exception e)
			{
				this.raiseXmlLoadError(e, stPath);
				//TODO: add a line to an error log
			}
			return obj;
		}
	}
}

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.150819.1 | Last Updated 21 Jun 2007
Article Copyright 2007 by MattsterP
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid