-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from swagfin/bot-playground
Bot playground
- Loading branch information
Showing
10 changed files
with
263 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<aiml version='2.0'> | ||
|
||
<category> | ||
<pattern>BAD ANSWER</pattern> | ||
<template> | ||
<think> | ||
<set name="ThatQuestion"> | ||
<input index="2"/> | ||
</set> | ||
<set name="ThatQuestionTopic"> | ||
<get name="topic"/> | ||
</set> | ||
</think> | ||
<!--check the topic--> | ||
<condition name="ThatQuestionTopic"> | ||
<li value="unknown"> | ||
Hmmm, i can't learn without topic context | ||
<think> | ||
<set name="topic">*</set> | ||
</think> | ||
</li> | ||
<li> | ||
OK. You said "<get name="ThatQuestion"/>" and I replied "<response/>". | ||
<think> | ||
<set name="topic">BotTrainingProgramThatQuestionAnswer</set> | ||
</think> | ||
<srai>SAY</srai> | ||
</li> | ||
</condition> | ||
|
||
</template> | ||
</category> | ||
|
||
<topic name="BotTrainingProgramThatQuestionAnswer"> | ||
<category> | ||
<pattern>SAY ^</pattern> | ||
<template> | ||
<think> | ||
<set name="ThatQuestionAnswer"> | ||
<star/> | ||
</set> | ||
</think> | ||
<condition name="ThatQuestionAnswer"> | ||
<li value="nil">\r\nWhat should I say instead? Reply starting with "Say "</li> | ||
<li> | ||
<!--Set the Topic to what User was In Before Learn--> | ||
<think> | ||
<set name="topic"> | ||
<get name="ThatQuestionTopic" /> | ||
</set> | ||
</think> | ||
<!--Tell Bot to Learn--> | ||
<learnf> | ||
<topic> | ||
<category> | ||
<pattern> | ||
<eval> | ||
<get name="ThatQuestion" /> | ||
</eval> | ||
</pattern> | ||
<template> | ||
<eval> | ||
<get name="ThatQuestionAnswer" /> | ||
</eval> | ||
</template> | ||
</category> | ||
</topic> | ||
</learnf> | ||
<!--Finnaly show success learning message--> | ||
Got it, when am asked “<get name="ThatQuestion" />”, i will now respond “<get name="ThatQuestionAnswer" />” under topic: <get name="ThatQuestionTopic" /> | ||
</li> | ||
</condition> | ||
</template> | ||
</category> | ||
</topic> | ||
</aiml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<aiml version='2.0'> | ||
<category> | ||
<pattern>*</pattern> | ||
<template>Hmmm i have no answer for that</template> | ||
</category> | ||
</aiml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,72 @@ | ||
using System; | ||
using System.Xml; | ||
|
||
namespace Aiml.NET { | ||
public partial class TemplateNode { | ||
/// <summary> | ||
/// Processes the content as AIML and adds it to the bot's brain, temporarily and for the current user only, and thus temporary. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para>Unlike other elements with content, the content of this element is not normally evaluated. | ||
/// However, the special child element <c>eval</c> is replaced with the result of evaluating its own content.</para> | ||
/// <para>This element is defined by the AIML 2.0 specification.</para> | ||
/// </remarks> | ||
/// <seealso cref="AddTriple"/><seealso cref="LearnF"/><seealso cref="Set"/> | ||
public sealed class Learn : TemplateNode { | ||
public XmlNode Node { get; } | ||
namespace Aiml.NET | ||
{ | ||
public partial class TemplateNode | ||
{ | ||
/// <summary> | ||
/// Processes the content as AIML and adds it to the bot's brain, temporarily and for the current user only, and thus temporary. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para>Unlike other elements with content, the content of this element is not normally evaluated. | ||
/// However, the special child element <c>eval</c> is replaced with the result of evaluating its own content.</para> | ||
/// <para>This element is defined by the AIML 2.0 specification.</para> | ||
/// </remarks> | ||
/// <seealso cref="AddTriple"/><seealso cref="LearnF"/><seealso cref="Set"/> | ||
public sealed class Learn : TemplateNode | ||
{ | ||
public XmlNode Node { get; } | ||
|
||
public Learn(XmlNode node) { | ||
this.Node = node; | ||
} | ||
public Learn(XmlNode node) | ||
{ | ||
this.Node = node; | ||
} | ||
|
||
public override string Evaluate(RequestProcess process) { | ||
// Evaluate <eval> tags. | ||
XmlNode node = this.Node.Clone(); | ||
this.ProcessXml(node, process); | ||
public override string Evaluate(RequestProcess process) | ||
{ | ||
// Evaluate <eval> tags. | ||
XmlNode node = this.Node.Clone(); | ||
this.ProcessXml(node, process); | ||
|
||
// Learn the result. | ||
process.Log(LogLevel.Diagnostic, $"In element <learn>: learning new category for {process.User.ID}: {node.OuterXml}"); | ||
AimlLoader loader = new AimlLoader(process.Bot); | ||
loader.ProcessCategory(process.User.Graphmaster, node, null); | ||
// Check if topic exist and check it's Name attribute, Assign if Not specified | ||
XmlNode topicNode = node.SelectSingleNode("/topic"); | ||
if (topicNode != null && topicNode.Attributes["name"] == null) | ||
{ | ||
XmlAttribute nameAttribute = topicNode.OwnerDocument.CreateAttribute("name"); | ||
nameAttribute.Value = process?.User?.Topic ?? "*"; | ||
topicNode.Attributes.Append(nameAttribute); | ||
} | ||
// Learn | ||
process.Log(LogLevel.Diagnostic, $"In element <learn>: learning new category for {process.User.ID}: {node.OuterXml}"); | ||
AimlLoader loader = new AimlLoader(process.Bot); | ||
loader.LoadAIML(process.User.Graphmaster, node, null); | ||
|
||
return string.Empty; | ||
} | ||
return string.Empty; | ||
} | ||
|
||
public static Learn FromXml(XmlNode node, AimlLoader loader) { | ||
return new Learn(node); | ||
} | ||
public static Learn FromXml(XmlNode node, AimlLoader loader) | ||
{ | ||
return new Learn(node); | ||
} | ||
|
||
private void ProcessXml(XmlNode node, RequestProcess process) { | ||
for (int i = 0; i < node.ChildNodes.Count; ++i) { | ||
XmlNode node2 = node.ChildNodes[i]; | ||
if (node2.NodeType == XmlNodeType.Element) { | ||
if (node2.Name.Equals("eval", StringComparison.InvariantCultureIgnoreCase)) { | ||
TemplateElementCollection tags = TemplateElementCollection.FromXml(node2, process.Bot.AimlLoader); | ||
node2.ParentNode.ReplaceChild(node.OwnerDocument.CreateTextNode(tags.Evaluate(process)), node2); | ||
} else | ||
this.ProcessXml(node2, process); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
private void ProcessXml(XmlNode node, RequestProcess process) | ||
{ | ||
for (int i = 0; i < node.ChildNodes.Count; ++i) | ||
{ | ||
XmlNode node2 = node.ChildNodes[i]; | ||
if (node2.NodeType == XmlNodeType.Element) | ||
{ | ||
if (node2.Name.Equals("eval", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
TemplateElementCollection tags = TemplateElementCollection.FromXml(node2, process.Bot.AimlLoader); | ||
node2.ParentNode.ReplaceChild(node.OwnerDocument.CreateTextNode(tags.Evaluate(process)), node2); | ||
} | ||
else | ||
this.ProcessXml(node2, process); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.