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

Help with Facts of Facts
 
 

Hi everyone,

I’m playing for some time now with the idea of passing bunch of facts between topics.

I have one generic topic that can extract information from a sentence based on the grammatical structure (subject, verb, object and some part of speech tags).

I want to pass a reference of the main fact, so other topics can access the tree of the structure given the root fact.

For example:

>cinema in london
   
>:userfacts
cinema is main_subject )
( ( 
cinema is main_subject at_location London 0x80 

And also it creates this:

variable$main_fact 218756 

I spent some time but I can’t seems to understand how to use the reference correctly.

I can do for example:

>:do ^field($main_fact subject)
   
resultNOPROBLEM  outputcinema
Cinema
   

But I don’t get how to go from there to get the fact based on this fact.

So, in the example above,
I want to go from:

cinema is main_subject 

or:

$main_fact 218756 

to:

( ( cinema is main_subject at_location London 0x80 

I’ve read ChatScript fact manual but didn’t found what i’m looking for.

Please help,

Thanks in advanced,

Sam

 

 

 

 
  [ # 1 ]

You don’t show how you set $main_fact (which could have been either fact). Nor how you match input to find a fact.

In general, you need to create your fact structure aimed for a use. You could do a query where the subject is your fact, and your verb is at_location, to find the fact where that exists.

 

 
  [ # 2 ]

$main_fact is reference / ID of the first fact.
This reference is all I have in the script that trying to access the facts.

How to query given a fact as the subject?
Is there a way to get fact set given reference?
Is there a way to query given fact set as a parameter?
I need to find the facts with specific fact as a subject.
Hope I made my self clear.
Thanks

 

 
  [ # 3 ]

How to query given a fact as the subject?  I need to find the facts with specific fact as a subject.
  One either finds in LIVEDATA/system/queries.txt an appropriate query or creates the one. In this situation you are fortunate the query is already defines:    direct_S # find facts given a fact subject

Is there a way to get fact set given reference? 
  Not sure what you are asking. Given a fact id like $main_fact, you can insert that into a fact set if that is what you want:
  $$tmp = createfact(I love you)
  @0 = $$tmp

Is there a way to query given fact set as a parameter?
  generally you have to define a custom query.  Tell me what you want to do and I’ll see if I can create it for you

 

 
  [ # 4 ]

Thank you very much Bruce! I didn’t know it is possible to do:

$$tmp createfact(I love you)
  @
= $$tmp 

This approach seems want I need.

Also, I’ve created a query (with not much of understanding how it works, just some copy paste and combinations.):

# find facts given a fact subject and a verb
QUERYdirect_Sv  "1Sq 2vt: queue s: match v2" # ($$factId verb ?) 

This seems to work for me.
I just inserted it in livedata/system/queries.txt and uses it in my script like this:

$$rel = ^join(at _ location)
 @
= ^querydirect_Sv $mainfactid $$rel )
 
location is @1subject @1verb @1object \n 

I also try

:build 0 

and i see that it is not rewrite the queries.txt file so i guess it’s the right way to do it.

 

 
  [ # 5 ]

“Also, I’ve created a query (with not much of understanding how it works, just some copy paste and combinations.):”

Much of programming is cut and paste with little understanding. I do it all the time.

Putting your query in livedata file works, but will be overwritten when you get new versions of CS.  Better thing to do is put it in a topic file: 
query: direct_Sv “1Sq 2vt: queue s: match v2”

(haven’t checked the syntax with the manual, but probably it’s that).

 

 
  [ # 6 ]

Everything works, except one thing I can’t figure out:

How to get the “fact index” from a query?

For example I have the following facts:

$fact = ^createfact( Bob own fish)
^createfact ($fact Bob pet FACTSUBJECT)

And the following query to retrieve the second fact:

$second_fact = ^query( direct_Svo $fact Bob pet )

This is not working. ($second_fact != fact index, but @0==the fact set)

^FindFact will return the fact index only for simple subject and not when the subject is a fact index.

 

 
  [ # 7 ]

I found a solution:

$second_fact = ^first(@0fact)

So, I’d like to use this opportunity to ask about performance issues.

Is there a way to limit the scope of the query only to userfacts?

I’m in general interested in understanding the behind the scene of facts queries.
Are the facts stored in some sort of hash-table / dictionary or in a list / array structure?

I might be using it too much without thinking about performance.

 

 
  [ # 8 ]

you can specify the fromset in a query as “user”.

Facts are indexed in a list (most recent first) under each field. So (Tom love fish)
has a pointer to the fact under Tom, and love, and fish.  A field can be a word or a fact so you can index under either.
When you query, the system will pick an appropriate field as the starting list of facts, unless you specify a factset as the origin of facts.

 

 
  [ # 9 ]

Hi Bruce,

Thanks for the detailed response.

Can you elaborate on the subject of specifying the fromset in a query to “user”?

Where to specify it? can you please give an example?

Many Thanks

 

 
  [ # 10 ]

I have extended the fact documentation with this:

^query(kind subject verb object count fromset toset propogate match) – query can actually take up to 9 arguments. Default values are ? . The count argument defaults to -1 and indicates how many answers to limit to. When you just want or expect a single one, use 1 as the value.
Fromset specifies that the set of initial values should come from the designated factset. Special values of fromset are “user” and “system” which do not name specify that matching facts should only come from the named domain of facts. Toset names where to store the answers.  Commonly you don’t name it because you did an assignment like
@3 = ^query(...)  and if you didn’t do that, toset defaults to @0 so
if (^query(direct_s you ? ?)) 
puts its answers in @0. It is equivalent to:
if (^query(direct_s you ? ? -1 ? @0))
The final two arguments only make sense with specific query types that use those arguments.

 

 
  [ # 11 ]

Excellent. I’ve tried this:

^query(direct_sv sam is ? 1 user )

Works perfect.

Thank you

 

 
  login or register to react