Jump to content
  • Advertisement
Sign in to follow this  
KurtLives

XML

This topic is 4723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody. In the last couple of days I've been trying to read an XML file, and randomly select a sentence to ouput depending on what the user inputs... In other words, the user enters "Hi" into a textbox, and from my XML file it outputs the sentence in the default "Hi" category. I have tried my best at giving it a go, and have been going through the AIML (http://www.alicebot.org/aiml.html) information but I'm totally stuck. Could someone point me in the right direction? Thanks a lot, - Kurt

Share this post


Link to post
Share on other sites
Advertisement
Sounds like you need to parse the Xml file into some 'dictionary' lookup in memory and respond according to that.

Imagine your Xml entries look like this:


<response key="hi">Hello, this is some text</response>
<response key="hi">y helo thar</response>
<response key="hello">Hey there</response>



You will probably want to store the words in a structure:-


struct WordNode
{
std::string wordKey;
std::vector< std::string > responses;

void addResponse( std::string &a_text ) { responses.push_back( a_text ); }
std::string randomResponse() { // Take a random number and go to that vector pos }
};


And these would be stored in a map:


std::map< std::string, WordNode > wordResponses;


Every time you encounter a word in the Xml file, you should look to see if one exists in the map - if so add another response to the node, if it doesn't exist create a new node and add it to the map.

Whenever the user enters a word you should look to see if it exists in the map, if so pick a random response from it, if not then report an error. For best results, you'd probably want to store your keywords in lower/upper case and convert the user input in the same way.

Anyway, just an idea and good luck!

Share this post


Link to post
Share on other sites
Thanks for the reply.

I forgot to mention that I'm writing this in C#, can what you said be done in it too?

- Kurt

Share this post


Link to post
Share on other sites

C# in .Net has excellent XML functionality. Just look up XmlDocument or XmlTextreader in MSDN... You will find some examples of reading nodes...

Edo

Share this post


Link to post
Share on other sites
Quote:
Original post by KurtLives
Hi everybody.

In the last couple of days I've been trying to read an XML file, and randomly select a sentence to ouput depending on what the user inputs...

In other words, the user enters "Hi" into a textbox, and from my XML file it outputs the sentence in the default "Hi" category.

I have tried my best at giving it a go, and have been going through the AIML (http://www.alicebot.org/aiml.html) information but I'm totally stuck. Could someone point me in the right direction?

Thanks a lot,

- Kurt


you should look at what we are doing in the alpha project.... (its a chatbot, made to beat the current best.). (Contact me at Amadscientist10@hotmail.com

In another point, what your doing isn't the best of options. (you will never get a full text match on anything other then "hi").

Try keyword matching.

And xml isn't the best format for this...

From,
Nice coder

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!