Re: how to assert into the db with rdbms
Thomas Russ <[email protected]> Fri, 18 May 2007 15:40:26 -0700
| Newsgroups | gmane.comp.ai.powerloom |
|---|---|
| Message-ID | <[email protected]> |
On May 18, 2007, at 3:19 PM, Kambiz Darabi wrote: > Thomas Russ <[email protected]> wrote: >> >> On May 18, 2007, at 8:29 AM, Kambiz Darabi wrote: >> >>> But, how can I assert facts into the database? >> >> This part of our database functionality is not yet completed. >> We are having some technical difficulties with proper handling of >> Function assertions. >> >> If you only use concepts and relations, we have something >> experimental that works, but it isn't released, not even in the new >> snapshots. >> > > As I understand, powerloom is in use in projects with very large > knowledge bases. Did you create the databases separately (using other > DB interfaces) and just did the reasoning in PL? Correct. In our work with large databases, we treated them as read-only storage systems. We did not write any updates to the tables. > > I would like to use PL to derive new facts from assertions which are > entered into the system. PL would then be a semantic layer on top of > the RDBMS, which would be capable of checking and augmenting the > information on the way to the database. > > Is such a use feasible with the current capabilities of PL? Mostly so. As long as relations and not functions are used. Also, I haven't done any testing with concepts, per se, so they may or may not work. > > Is there a chance of getting the part which allows to assert concepts > and relations? Yes, since you asked so nicely. As it turns out, I think that all of the necessary infrastructure is present in the latest snapshot. All of my RDBMS changes are checked in to our repository, so the code should be present. I'll outline what needs to be done, but I don't have time this week to test it. First of all you will need to make sure that you construct a system that includes the Stella/PowerLoom RDBMS system. IIRC the standard PowerLoom build (not PLI) does that. If you are already using the RDBMS system to successfully retrieve values from the database you should have this already set up. What is needed to activate writing is a couple of key assertions in your knowledge base. For each relation that you want to have writing enabled, you need to include the rdbms/db-relation-update-demon as its update-proposition demon. An example is below: (defmodule "FOO" :includes ("PL-USER") :uses ("RDBMS" "LOGIC" "STELLA")) (defdb foo-db :host "localhost" :db-name "foo" :user "user" :server-type "MYSQL") (deftable rdb foo-db "r" (?x ?y)) (assert (update-proposition-demon rdb rdbms/db-relation-update-demon)) You will need an assertion for each table you want. Notice the "rdb" table name in the assertion. > >>> >>> Another problem is: I can use defquery to define queries >>> involving one >>> single table, but I don't manage to define sql table joins >>> correctly. >>> >>> [...] >>> >>> 2) defquery with an SQL join >> >> Something like this should work: >> >> Assume DB tables >> employees: employeeName employeeDepartment >> departments: department managerName >> >> (DEFQUERY employeeBoss ((?employeeName STRING) (?bossName STRING)) >> :QUERY-PATTERN >> (RDBMS/SQL-QUERY our-db >> "SELECT employeeName, managerName FROM employees, departments >> WHERE #${employeeName='?employeeName'} >> AND #${managerName='?managerName'} >> AND employeeDepartment = department >> ")) >> >> What are you trying that is failing? > > > Given this: > > create table parents (id integer, name varchar(255)); > create table child (id integer, parentid integer, name varchar(255)); > insert into parents values (1, 'John'); > insert into child values (1, 1, 'Kevin'); > insert into child values (2, 1, 'Mary'); > > what would be the query pattern for: > > (DEFQUERY parent-child ((?parentid integer) (?parentname STRING) (? > childname STRING)) > ... Untested answer, but this should be close: "SELECT parents.id, parents.name, child.name FROM parents, child WHERE #${parents.id=?parentid} AND #${parents.name='?parentname'} AND #${child.name='?childname'}" The only tricky part in the template syntax is that the "?" uses the PowerLoom name and the other part uses the database name. There may also be some issues with case sensitivity, but I don't have time to check that right now -- sorry.