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..

Pick random content from set?
 
 

Hi

I’m trying to make a chatboots that asks the capitals of countries. I have a set file with the countries and a map with the relation country:capital. Is there a way the bot can generate a sentence de like: Which is the capital of ?

Thanks a lot!

 

 
  [ # 1 ]

You do not need sets or maps.  I believe you need to do something like:

<category>Ask me for the capital of a country</pattern>
  <template>What is the capital of <random>
      <li>France</li>
      <li>Brazil</li>
      <li>China</li>
      </random>?
  </template>
</category>

Because there are no arrays and no indexes and no random “functions” or functions at all in AIML.  The only implementation of random is through the random “tag” which selects between <li> options and does not use maps or sets that I am aware of.  Others can correct me if I am wrong.

You could create a category that returned a random number of say 1 to 10.  Then you could create a map that mapped the numbers 1 to 10 to ten different country names and in that way “look up” a random element of a map, but that would be a two step process and why not just hard code the country names in the <li> tags to start with?

 

 
  [ # 2 ]

Here is an example of the latter method where you can use a map (that has numbers as “names” and countries as “values”):


<category>pick a random country</pattern>
  <template><map><name>Countries</name><srai>XRANDOM 1 10</srai></map></template>
</category>


<category>pick a random number from 1 to 10</pattern>
  <template><srai>XRANDOM 1 10</srai></template>
</category>

<category>XRANDOM 1 10</pattern>
  <template><random>
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
      <li>7</li>
      <li>8</li>
      <li>9</li>
      <li>10</li>
      </random>
  </template>
</category>

 

 
  [ # 3 ]

Now if someone could please post an example of

<category>XRANDOM * *</category>

where any two numbers can be passed for the asterisks.


(I think most math and functions are done outside of AIML and integrated in the client or through system or api calls.)

 

 
  [ # 4 ]

Hi Alaric

Thanks a lot for your replies. I wanted to use random with set to avoid having hardcoded the contents in the AIML files, putting the knowledge in the config files, that will make the system more flexible.

Ideally, I would like to ba eble to write in the template something like

<random><set>country</set></random

meaning that “pick a random element from the set ‘country’”

Nevertheless your approach having in the AIML a list of numbers an pick a random element from there is very interesting, I will try it!

Thanks

 

 
  [ # 5 ]

Alaric is correct but as he advises, you should make a list of random countries rather than numbers. It’s more efficient.

XRANDOM * * hmmm… Challenge accepted smile

 

 
  [ # 6 ]

I’m wondering if there are other possible ways to do this? I am in a similar situation, needing to use values from maps rather than content hardcoded in randomized <li>s.

 

 
  login or register to react