AI Zone Admin Forum Add your forum

CHATBOT MEETUP CHATBOT MEETUP CHATBOT MEETUP CHATBOT CHATBOT MEETUP CHATBOT MEETUP CHATBOT MEETUP CHATBOT MEETUP

On June 28th, 2017 we're organizing our next Chatbot Meetup in Amsterdam, The Netherlands. Feel free to join!'

Storing the variables in list
 
 

How can i store the $period values in a list or a String ?
The output should be of the following type:

The period stored in the facts were “weekly”, “monthly”,  “yearly” 

Here is my code:

if(^query(direct_s $brand ? ? )) {
@0 = ^query(direct_s $brand ? ? )
@1 = ^query(direct_s $brand ? ? )
^loop($$_len){
$period = next(FACT @0verb )
$time = next(FACT @1object )
if($period != $$type ){
$difference = %fulltime - $time
if($difference < 50){
$period
}
}
}
}

Help me resolve this

 

 
  [ # 1 ]

$text = null
if(^query(direct_s $brand ? ? )) {
@0 = ^query(direct_s $brand ? ? )
@1 = ^query(direct_s $brand ? ? )
^loop($$_len){
$period = next(FACT @0verb )
$time = next(FACT @1object )
if($period != $$type ){
$difference = %fulltime - $time
if($difference < 50){
$value = \" $period \"
$text = ^join($text "_" $value )
}
}
}
}
$text

Is this the right way to implement the above ?

 

 
  [ # 2 ]

a) rather than replicating your queries you can do this with a single query

loop() —no need for $$len which is never initiallized in our code
{
_0 = ^first(@0all)
$period = _1
$time = _2

b) you want a list of periods, the use of JOIN is reasonable, or equivalently a dynamic string like
$text = ^”$text $value”
But I wouldnt use underscore as the separator, i’d use a space.

 

 
  [ # 3 ]

Thanks Bruce, this was useful.

 

 
  login or register to react