0

I have an AIML file that I need to interact with using C#. How do I load the document and use C# to query the file from the user input?

<category>
  <pattern>WHAT IS YOUR NAME</pattern>
  <template>My name is John.</template>
</category>

The user input would be the pattern. I need to be able to query the file with the user input and return the corresponding template.

David Crowell
  • 3,711
  • 21
  • 28
Henry
  • 1

1 Answers1

1

Since AIML is an XML dialect, you can use System.Xml.Linq types to parse and query it:

XDocument doc = XDocument.Parse(aiml);
// do your queries
XElement category = doc.Descendants("category").Where(cat => cat.Element("pattern").Value == "WHAT IS YOUR NAME").Single();
string template = category.Element("template").Value;
// ...
Saeb Amini
  • 23,054
  • 9
  • 78
  • 76