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

query from a set
 
 

I’ve been experimenting with query and limiting the search to a fact set, but I can’t really seem to get it to work as I expected.

Say I have a set of facts in @10, then my intention/expectation for the statement

@11 = ^query(myqueryname surname @10

is to only consider the facts in set 10 - assuming that I can craft the right query commands for “myqueryname”.

But that is where I’m having trouble in that I can’t quite get the commands right. Well that’s not quite true as I got this to work (after a lot of trial and error and debugging).

querymyqueryname "1fmf 2vt: queue fe : match q1 v2"

@11 = ^query(myqueryname surname @10 ? ? @10

but this doesn’t feel clean as I wasn’t expecting to have to use the match parameter.

Are my expectations too high?


(Actually in my final scenario, I do know the subject, so I can use the direct_sv query, so this is more of an academic question at the moment).

 

 

 
  [ # 1 ]

So.. first, a std query (prebuild and tested) seems to work fine.  This works:
u: ( ) createfact (meat eat fish)
  createfact (meat eat meat)
  @1 = query(direct_s meat ? ?)

  query(direct_v ? eat ? -1 @1)

 
  @0object is the answer

So really the issue is I presume in the definition of your query, which I’ll analyze shortly

 

 
  [ # 2 ]

Can you state what you WANT your rule to query (how do you intend it to work), perhaps with example. Otherwise knowing whether or not you needed to do what you did is difficult.

 

 
  [ # 3 ]

I don’t think the standard queries work, or certainly not as I was expecting.

Consider:

u: ()
 ^
createfact(dog eat meat FACTTRANSIENT)
 ^
createfact(dog chase cat FACTTRANSIENT)
 ^
createfact(bear eat meat FACTTRANSIENT)
 ^
createfact(cat eat fish FACTTRANSIENT)
 
 @
= ^query(direct_s dog ? ?)
 
\nThere are ^length(@1facts about a dog:\n
 
^loop()
 
{
  
^"  "
  
^writefact(^next(FACT @1fact))\n
 }

 
 
@= ^query(direct_v eat ? -@1)
 
\nThere are ^length(@2things a dog eats:\n
 
^loop()
 
{
  
^"  "
  
^writefact(^next(FACT @2fact))\n
 } 


This produces:

There are 15 facts about a dog:
   ( 
dog chase cat 0x100 )
   ( 
dog eat meat 0x100 )
   ( 
dog male dog )
   ( 
dog~n member soundmaker 0x10 )
   ( 
dog member moving generic 0x10 )
   ( 
dog member carnivore 0x10 )
   ( 
dog~1n member pet animals 0x10 )
   ( 
dog~n member mammals 0x10 )
   ( 
dog member stronggoodness 0x10 )
   ( 
dog~5 is fellow~)
   ( 
dog~2 is support~)
   ( 
dog~6 is disagreeable woman~)
   ( 
dog~1 is domesticated animal~)
   ( 
dog~1 is canine~)
   ( 
click~2 is catch~)

There are 3 things a dog eats:
   ( 
cat eat fish 0x100 )
   ( 
bear eat meat 0x100 )
   ( 
dog eat meat 0x100 

I was expecting a single fact from the second query, and in the above situation @2object returns fish because (cat eat fish) is the first fact in the set.


From the code for Query() I can see that the fromset parameter is only considered when there is an ‘f’ control character in the first segment. But then for facts from that set to be considered they have to be added to the queue when the choice is ‘@’. Hence using the match parameter as a means to generate that choice.

 

 

 
  [ # 4 ]

The short answer is that the system does not operate as you imagine. But your imagining is perfectly sound and I should make it function that way.  So I will get around to it. No promises on how long to do that.

 

 
  [ # 5 ]

OK, thanks.
I can work with my initial workaround for now, even if it is a little obscure in the syntax.

 

 
  login or register to react
‹‹ JSONGather bug      Detect if output in rule ››