royaltca
Pro
Posts: 33
Joined: Mon Mar 30, 2015 5:18 pm

Any way to do this using JS?

Thu Jun 18, 2015 8:55 pm

Hi, is there any possibility to check if an argument given to the funcion in JS is a part of SIML Set? It would simply make my life easier, cuz adding 20000 words to the map is a time consuming process and I even need seven maps.. :)

The simple code below would reduce my map size to almost nothing.. :)

For Example:

Code: Select all

  function convertNoun(str,ending)
{
  if (str belongs to the set)
{
 return str.substr(0,str.length-1)+ending;
}
}

User avatar
Fantom
Help & Support
Posts: 304
Joined: Fri Oct 25, 2013 9:20 pm

Re: Any way to do this using JS?

Thu Jun 18, 2015 9:41 pm

Example code to check if "ant" exists in the SIML set Animal

SIML Code

<Model>
  <Pattern>Contains Animal</Pattern>
  <Response>
  <Js>
	(function(){
	 if(Bot.Sets["Animal"].Contains("ant")){
	   return true;
	 }
	 else{
	  return false;
	 }
	})();
  </Js>
  </Response>
</Model>

royaltca
Pro
Posts: 33
Joined: Mon Mar 30, 2015 5:18 pm

Re: Any way to do this using JS?

Thu Jun 18, 2015 11:04 pm

Man! This is awesome! Works perfect for me! What else can I do with Bot.Sets?

For example I have two sets:

A:
być
grać
wygrać
B:
byłem
grałem
wygrałem

Now I want JS code to give me position of "być" in A Set:

let's say

Code: Select all

var i = Bot.Sets['A'].IndexOf('być');
and next step is to get the element from second set at the same position

Code: Select all

var element = Bot.Sets['B'].ElementAt(i);
any way to do this?

User avatar
Fantom
Help & Support
Posts: 304
Joined: Fri Oct 25, 2013 9:20 pm

Re: Any way to do this using JS?

Fri Jun 19, 2015 1:58 am

why would you want to use JavaScript for it :? why dont u try a Map :) something like this...

SIML Code

<Map Name="A" Reverse="B">
  <MapItem Content="być" Value="byłem" />
  <MapItem Content="grać" Value="grałem" />
  <MapItem Content="wygrać" Value="wygrałem" />
</Map>
this will automatically create a map "B" and will swap the value and content of map "A".

More on Reverse Map

If you still want to use Js let me know I will try to find a solution for you ;)

royaltca
Pro
Posts: 33
Joined: Mon Mar 30, 2015 5:18 pm

Re: Any way to do this using JS?

Sat Jun 27, 2015 3:37 am

Still prefer JS. For my language there is too much work with Maps.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest