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

Representing an Inventory
 
 

I was wondering how you would represent an inventory? For instance, how can you say a library has a certain number of each kind of book?

 

 
  [ # 1 ]

I think I have it:

Table: library_inventory (^library ^work ^quantity)
^createfact((^library own ^work) number ^quantity)
Data:
“Dutch Royal Archives”  “Fahrenheit 451”  1
“George Peabody Library”  “2001: A Space Odyssey”  1
“Kremsmuenster Abbey Library”  “Neuromancer”  2

 

 
  [ # 2 ]

That should be:

Table: library_inventory (^library ^work ^quantity)
^createfact((^library own ^work) count ^quantity)
Data:
“Dutch Royal Archives”  “Fahrenheit 451”  1
“George Peabody Library”  “2001: A Space Odyssey” 1
“Kremsmuenster Abbey Library”  “Neuromancer”  2

 

 
  [ # 3 ]

I tried these queries on it:

#! has book
a: ( \[has book \] )  if ( ^query( direct_svo “George Peabody Library” own “2001: A Space Odyssey”) ) { Yes. } else { No. }

#! book number
a: ( \[book number \] )  @0 = ^query( direct_svo “Dutch Royal Archives” count “Fahrenheit 451”) They have this many of Fahrenheit 451 @0object

[has book] returned

“Yes.”

[book number] returned

“They have this many of Fahrenheit 451”

Is there a way to get the value inside @0 to print to the user?

 

 

 
  [ # 4 ]

I think I see what is going on. There is something wrong with the way the table is set up. Hmm…

 

 
  [ # 5 ]

Looks like I won’t need this exact functionality after all. But I would like to know what I am doing wrong, in case I need to build my own tables on future. The more examples of there are of these on the forum, the better.

 

 
  [ # 6 ]

so… you store facts like this:

^createfact((^library own ^work) count ^quantity)

yet you try to retrieve facts like this:
^query( direct_svo “Dutch Royal Archives” count “Fahrenheit 451”)

which clearly does not match your representation.

 

 
  [ # 7 ]

^createfact( ^library ^work ^count) 

would be a much simpler representation, allowing you to ask how many copies of a work a library has, or if it fails, that is has none.

 

 
  [ # 8 ]

Thanks for your help Bruce. I was overcomplicating things as usual.

 

 
  [ # 9 ]

I’ve been messing around with this again. Here’s some code that might help a newbie get started

#create the table

Tablelibrary_inventory (^library ^work ^count
 ^
createfact( ^library ^work ^count)   

Data:
"Dutch Royal Archives"    "Fahrenheit 451"   10
"George Peabody Library"   "2001: A Space Odyssey"  17
"Kremsmuenster Abbey Library"  "Neuromancer"    
#how many copies of a book in a library

u: (book
 @
= ^querydirect_sv "Dutch Royal Archives" "Fahrenheit 451")
 
We have @0object copies
 

 
  [ # 10 ]

Adding and removing facts one at a time

u: (add
 @
= ^querydirect_sv "Dutch Royal Archives" "Lord of the Rings")
 if (@
0)
 
{  
  $qty 
first(@0object) + 1
  
^delete(@0)
  ^
createfact"Dutch Royal Archives" "Lord of the Rings" $qty)
  
$qty books in archive
 }
 
else
 
{
  
^createfact"Dutch Royal Archives" "Lord of the Rings" 1)
  
1 book in archive
 } 
u: ("remove xxx"
 @
= ^querydirect_sv "Dutch Royal Archives" "Lord of the Rings")
 if (@
0)
 
{
  $qty 
first(@0object) - 
  
if ($qty >= 0)
  
{
   
^delete(@0)
   ^
createfact"Dutch Royal Archives" "Lord of the Rings" $qty)
   
$qty books in archive xxx
  }
  
else
  
{
   No book to remove
.
  
}
 }
 
else
 
{
  No book to remove
.
 
u: (book 1
 @
= ^querydirect_sv "Dutch Royal Archives" "Lord of the Rings")
 if (!@
0{We have no copies.}
 
else {We have @0object copies.
 

 
  [ # 11 ]

Bug fix for the above:

Replace:

^delete(@0)

With:

^delete(^query( direct_sv “Dutch Royal Archives” “Lord of the Rings”))

 

 
  [ # 12 ]

Here’s some working code from the Fact Manual, ADVANCED FACTS, Facts of Facts

u: ("xxx1"
 ^
createfactbob has (10 smelly fish))
 ^
createfactbob has (6 hairy dog))
 
 
facts added
 
u
: ("xxx2"
 @
= ^querydirect_sv bob has)
 if (@
0)
 
{
  loop
()
  
{
   _1 
= ^last(@0all)
   ^
fact_3 subject) ^fact_3 verb) ^fact_3 object), 
  
}
 } 

 

 

 

 
  login or register to react