AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Update Knowledge base-search through XML
 
 

I am developing my knowledge base files these days and also I am trying to make an interface to update the templates in the knowledge base.
Say I have the following AIML file.

<?xml version="1.0" encoding="ISO-8859-1"?>
<aiml version="1.0">
 
  <
category>
      <
pattern>WHERE</pattern>
    <
template>Where the heart is.</template>
  </
category>
  


  <
category>
      <
pattern>Hi</pattern>
    <
template>Hello there</template>
  </
category>
 
</
aiml

I want to access the first pattern template. I am using c# for the development and the following coded gives only the InnterText of the specified Tag.

XmlNodeList nodelist = aiml.GetElementsByTagName(“pattern”);
TextBox1.Text = nodelist[0].InnerText;
or
TextBox1.Text = nodelist[0].FirstChild.ChildNodes[0].InnerText;

But what I want is; if I give the pattern node list no as 0 or 1 then I need to read the InnerText of the related template.
Is there a way that I can get the access like that??
Any suggestions????
Thank you.

P.S
Well I can not publish the pattern tag in the message.Though I write it, it does not display.Hope it wont make any complications.

{edit=Dave} I took the liberty of enclosing your AIML code in the proper tags. Please see my post, below: {/edit}

 

 
  [ # 1 ]

To allow for display of AIML snippets (or any other type of code, for that matter), enclose your code with [ code ] [ /code ] tags (without the spaces, of course), as in the example below:

<?xml version="1.0" encoding="ISO-8859-1"?>
<aiml version="1.0">
 
  <
category>
      <
pattern>WHERE</pattern>
    <
template>Where the heart is.</template>
  </
category>
  <
category>


  <
category>
      <
pattern>Hi</pattern>
    <
template>Hello there</template>
  </
category>
  <
category>
</
aiml

As far as the remaining portion of your question, I think that Chuck is best qualified to answer for you. His expertise with the C language is unsurpassed here, whereas mine could be placed in a Dixie Cup, and still have room for a nice, long drink of water. smile

 

 
  [ # 2 ]

Thanks a lot for the reply.I am actually new to Chatbots.Org, this is the first time I posted a code portion.smile
And I have actually searched the whole last night for a solution and I got an answer, but not that much satisfactory.

Here are the results:
In an aiml document if the categories considered as the child nodes and the pattern and template tags considered as child nodes of the category nodes then I can access the 0 th category template as follows:

string path = “E:\WebSite1\my.aiml”;
      FileStream reader = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
      XmlDocument aiml = new XmlDocument();
      aiml.Load(reader);
      XmlNodeList nodelist = aiml.GetElementsByTagName(“category”);


      DropDownList3.Items.Add(nodelist[0].ChildNodes[1].InnerText);

Above code solved the problem for some extent.
But I have some more questions.

I wanted to read a XML file and get the contents to a GridView. Say the file is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<aiml version="1.0">

<
category>
<
pattern>WHERE</pattern>
<
template>Where the heart is.</template>
</
category>
 


<
category>
<
pattern>Hi</pattern>
<
template>Hello there</template>
</
category>

<
category>
<
pattern>WHEREISIS *</pattern>
<
template>
<
random>
<
li>Where the heart is.</li>
<
li>Where it belongs.</li>
<
li>Where <star/> is hard to find.</li>
<
li>do not know where <star/> is.</li>
</
random>
</
template>
</
category>

 
</
aiml

When I read the XML file using the following code, it only displays the contents which are similar to every category node in the file.This moment it shows only the patterns because in the third category, the template tag contains some other tags.

XmlDataDocument doc = new XmlDataDocument();
      doc.DataSet.ReadXml(“E:\WebSite1\std-pickup.aiml”);
      DataSet ds = new DataSet();
      ds=doc.DataSet ;
      GridView1.DataSource = ds;
      GridView1.DataMember = “category”;
      this.GridView1.DataBind();

So my questions are:
*Is there a way to read all the categories to a GridView???Because in an AIML file, the template tag can have other various sub tags also.Any sugesstions???

*Say I have two AIML files called courses.aiml and fee.aiml. Can a category in the courses.aiml file redirect to a category in the fee.aiml file using the <srai> tag or vise versa. Or <sarai> tag related categories should be in the same file???

Two files may be:

fee.aiml category:

<category>
<
pattern>FEE</pattern>
<
template>1000 per month</template>
</
category

courses.aiml category:

<category>
<
pattern>MONTHLY FEE</pattern>
<
template><srai>FEE</srai></template>
</
category

Need help on this matter.Thank you very much.

 

 
  [ # 3 ]

In reference to your first post, Umesha:

<?xml version=“1.0” encoding=“ISO-8859-1”?>
<aiml version=“1.0”>
  <category>
    WHERE</pattern>
  <template>Where the heart is.</template>
  </category>
  <category>
    Hi</pattern>
  <template>Hello there</template>
  </category>
</aiml>

There were two extra category tags in the center.

I built a simple search engine in C# for ASP.NET code samples at:
http://www.b-zg.com which has some GridView sample code.

The first of over a dozen code samples for GridView:
http://www.b-zg.com/CodeSearch/datagrid1.aspx

It would be interesting to make one of these samples read AIML.

 

 
  [ # 4 ]

I am really sorry for asking this.But when I click on the links in http://www.b-zg.com/default.aspx ; it only shows me the example. as in if I click on the http://www.b-zg.com/CodeSearch/datagrid11.aspx it shows me the data grid; but not the code example .How can I check the code??Or the code is not visible??
Thank you.

 

 
  [ # 5 ]

Umesha.

I just wrote a Simple AIML Grid Example:

http://www.b-zg.com/CodeSearch/datagridxml.aspx

The source code can be viewed here:

http://www.b-zg.com/CodeSearch/viewsource.php?f=datagridxml.aspx

The file aiml.xml contains the AIML in your request above:

http://www.b-zg.com/CodeSearch/aiml.xml

Now that we have the basics, let’s see if we can tweak this simple example.

I would recommend Dave Morton, for his talented explanation of AIML, and
PHP expertise on chatbots and chatrooms.

http://forum.alicebot.org/viewtopic.php?f=5&t=26


(And… Thanks Erwin for giving me this link.)


________________________________________________________________

{EDIT = Umesha,
Check this out: http://forums.asp.net/t/1235043.aspx
  ( I prefer using a foreach loop )
}

 

 
  [ # 6 ]

Hi, thanks a lot…......I did try that also…but it gave me the same answer….....it works perfectly when all the categories has same children like pattern and template.But when in a category one template has the different sub tags also as follows:

<category>
<
pattern>WHEREISIS *</pattern>
<
template><random><li>
Where the heart is.</li>
</
random></template>
</
category

Then it reads only the pattern tag InnerText of all the categories but it does not return any template InnerText because the template are not same in the file.
Is there any way that I can say that check in the sub children nodes also like using a for loop for each sub tag and bind those to a GriedView????
I am still searching on it but did not come up with any positive answer yet. Any suggestions ???
Thank you smilesmile

 

 
  login or register to react