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

How to query facts of facts
 
 

There are examples of putting a fact reference as a member of another fact.
For example
$_temp = ^createfact( jenkins member dev)
$_myfact = ^createfact( myurl location $_temp factobject)

Now i want to find myurl if i am given dev jenkins.

$_item = ^findfact( jenkins member dev)
$_result = ^query( direct_vo ? Location $_item 1 ? @0subject)

 

 
  [ # 1 ]

First, I ask why is jenkins a member of dev… why do you care for that verb. If (jenkins myurl dev) it would be simple.

 

 
  [ # 2 ]

But if you are determined then….
$_tmp = ^findfact(jenkins member dev)
^query(direct_vo ? location $_tmp)

probably works

 

 
  [ # 3 ]

Bruce,

In my example, ‘dev’ is an adjective, not a verb. I am describing resource locations for items on our various environments ( production, QA, development, local) Each of these environments have a copy of each application. We have separate copies of Jenkins on dev and QA. I would also like to be able to give a list of the items on each environment.

I could not think of another way of representing the data.  I am open to suggestions.

 

 
  [ # 4 ]

Bruce,

That syntax does not give the result we want. It looks like the query engine is looking for the literal string and not a fact reference.

This code:

$$_itemfact = ^query(direct_svo jenkins member dev 1 ? @10fact)
 $
$_urlfact = ^query(direct_vo location $$_itemfact 1 ? @10fact

produces this result in the user log.
with :trace ~test-facts-of-facts

....,...    Found:215305: ( jenkins member dev x100000 )
....,... 
result: @10[1] e.g. ( jenkins member dev x100000 )
....,...
NOPROBLEM ^query(direct_svo) => `215305`
....,..$
$_itemfact = ^query(215305)
....,..
System call ^query(`direct_vo ? location $$_itemfact 1 ? @10fact`)
....,...
QUERY: @10 direct_vo 
....,... control1oq 2vTqueue omatch v2  s/v/o:[location 215305] count:1 toset:@10fact 
....,[email protected]@@ Control1 mark/queue1oq 2vT
....,...
....,...
Tag+Queue215305 #1(3646)  215305+
....,...
....,...
Taglocation #2(3647)  don't expand  location. 
....,[email protected]@@ Control3 match requirements2
....,... verb must be #2 Start processing loop
....,... result: @10 none found 
....,...NOPROBLEM ^query(direct_vo) => `` 
 

 
  [ # 5 ]

By “verb” I mean the field name of the fact. It has nothing to do with real part of speech, except that a typical use of facts can involve representing a sentence of subject, verb, object and CS has biases on which field to use to search on first to query things.

Nowadays I would represent most everything using JSON. Then one might access data via something like
$resources.dev.jenkins.url

 

 
  [ # 6 ]

“That syntax does not give the result we want. It looks like the query engine is looking for the literal string and not a fact reference.”


Right. my fault.  I could give you a better query, but I recommend using JSON representation for real clarity

 

 
  [ # 7 ]

Likewise, for JSON, you can indirect access via things like
$resources.$_environment.$_resource.url

 

 
  [ # 8 ]

I see how that represents the data and how to do the lookup .

As a follow up:

1) How do I get the json to be global for all users of the bot?

2) When is the appropriate time to use tables/facts, vs JSON vs variables?

 

 
  [ # 9 ]

Any data created during compilation is global for all users of the bot.
You can init fact data by creating a dummy table and then doing what you want it in, eg
table: ^init(^junk)
  whatever code you want
DATA:
junk

Any data created during ^csboot is global for all users of the bot.

Variables are good for holding single data, unrelated to other data.
Facts are good for holding relationship data.
JSON is a clean way to create lots of related facts (like creating a record, array, structure in other languages).

 

 
  [ # 10 ]

of course the table could have been doing REAL declarations of the facts,...

table: ^init (^environment ^resource ^url)
  code to represent this
DATA:
prod jenkins ww.xxx
dev jenkins ww.yyy

 

 
  [ # 11 ]

^cs_boot in addition to creating facts via its own code, can read website data to dynamically import data at start of server that is visible to all users.  And one can hot-load the server on the fly and force ^csboot to rerun its data loading in between user requests

 

 
  [ # 12 ]

thanks Bruce,

I will try your table suggestion to create the json. I will post my results next week.

 

 
  [ # 13 ]

As a tip, if you are creating JSON in ^csboot() or from table script in the bot compilation then use ^jsonlabel() to make sure the JSON objects have a distinct name.

 

 
  [ # 14 ]

Thanks for the info. I am a little late responding, but I got diverted. I was able to take your suggestions and get a positive outcome. This is for another use-case but I think the example will show a nice solution to the folks coming after us.

In this use case, I have a lot of information that I need to accumulate to make a query to a service. The query has:
* a bunch of “magic string’ parameters
* some parameters that I need reasonable defaults
* some that I expect the user to add as they refine their search results
* some parameters that are an array of options

I decided to create a default json structure that will contain the “magic strings’ and the reasonable defaults and accommodate the array options. When the user enters the topic I will make a copy of the structure and change elements to match the info I get from the user. I have a macro that can convert the json structure into the correct format for the service. (sorry, but the original developers did not think to accept json as input)

tableservice_provider(^globalName)
 ^
jsonlabel(pf)
 $
$tmp = ^join( $ ^globalName)
 
$default = ^jsonparsepermanent NOFAIL ^'
 {
  url : "https://api.bcbsal.org/providerfinder/search" ,
  locationsearch : "true",
  apikey : 557-53fe1a15-42ef-4133-808e-438800ebcf8c,
  indent : "true"
  wt : json,
  facet : {
   search : "true",
   mincount : 0,
   things : [ "category", "specialty", "gender" ]
  },
  key : *,
  rows : 5,
  location : {
   lat : "33.4359416", 
   long : "-86.44345",
   address : "Hoover Alabma"
  },
  radius: 25,
  start: 0,
  criteria: "%7B!geofilt%7D",
  filters:[
   { id: category ,
     vals: [ Dentist ]
   }
  ]
 }'
)
 ^
jsonlabel("")
 ^$
$tmp $default
data

pfData 

then I have macros like

outputmacro: ^pfs_initialize()
$userpfData = ^jsoncopypermanent $pfData)

outputmacro: ^pfs_queryString()
if(
null == $userpfData){
 
^pfs_initialize()
}
$$_item 0
$$_size = ^length$userpfData.facet.things )
$_facets = ^join(
  
facetsearch$userpfData.facet.search &
  
facet.mincount$userpfData.facet.mincount 
  
)
^
loop( $$_size )
 
$$_itemplus1 = $$_item 1
 $_facets 
= ^join($_facets facet $$_itemplus1 $userpfData.facet.things[$$_item] )
 $
$_item += 1
}

....

## join is a great way to put together a query string!!

$$_query = ^join$userpfData.url ?
    
indent$userpfData.indent &
    
locationsearch$userpfData.locationsearch &
    
apikey$userpfData.apikey &
    
wt$userpfData.wt &
    
start$userpfData.start &
    
criteria$userpfData.criteria &
    
gissendaner=stephen &
    
$_facets &
    
key $userpfData.key &      
    
radius$userpfData.radius &
    
rows$userpfData.rows )
^
log\n\n %%% $$_query \n\n)

outputmaro: ^pfs_addFilter( ^filterValue)
$userpfData.key = ^filterValue

## called when the user no longer needs to refine their results
outputmacro: ^pfs_clearQuery()
  
$userpfData null 


You get the idea. The user can get initial results, and then the bot can help them refine the results and resubmit the query over and over with additional criteria.

Thanks for all the help!!!

 

 

 
  [ # 15 ]

Bruce,

One final question.

What is the use-case for the facts of facts examples in the manuals?

 

 
  login or register to react