APE: DRS-string to clause ready for assertion?

How do you convert a string to Prolog fact ?

?- ape('Peter owns a book.',R).
R = '[A,B]\nobject(A,book,countable,na,eq,1)-1/4\npredicate(B,own,named(Peter),A)-1/2\n'.

The APE returns a Discourse-representation-structure as a string.
I want to convert it to Prolog fact and store it in the db, so I can later query it .
Cleaner view :

?- ape('Peter owns a book.').
[A,B]
object(A,book,countable,na,eq,1)-1/4
predicate(B,own,named(Peter),A)-1/2

FYI:

ape(T,Res) :- get_ape_results([text=T, solo=drspp],_, Res).
ape(T) :- ape(T,Res), writeln(Res).

drs instead of drspp returns this string, which cleaner :

?- ape('Peter owns a book.',R).
R = 'drs([A,B],[object(A,book,countable,na,eq,1)-1/4,predicate(B,own,named(\'Peter\'),A)-1/2])'.

You can recover the term with

?- read_term_from_atom('drs([A,B],[object(A,book,countable,na,eq,1)-1/4,predicate(B,own,named(\'Peter\'),A)-1/2])',T,[variable_names(VarNames)]).

In alternative, when you have decided the most useful interface for your task, it’s possible to reuse inner module’ predicates (that is, not exported) just qualifying them with the module. This is - usually - discouraged, but for a so general interface like APE seems to be pretty useful.

When analyzing, from your CLI, just enter

?- use_module(library(ape)).
true.
?- edit(get_ape_results).

and then explore the library by means of right clicks on appropriate goals. Guess you already found this trick…

thanks for the trick.

I’m wondering how do you assert() facts with variables, so you can query them ?

In this case how would I assert() DRS… what I cant wrap my head around is how do you store them… and then map the query to find the fact ?

?- ape('What does Peter own ?',R).
R = 'drs([],[question(drs([A,B],[query(A,what)-1/1,predicate(B,own,named(\'Peter\'),A)-1/4]))])'.

Using variables not pointing at anything, but used as part of the structure as “placeholders/hooks”, confuses me.

Just assert(FactWithVariables) :slight_smile: Variables are the most general term in Prolog, and works in facts the same they do in rules. I think these are a big payload of APE, providing ready (and easy) to use semantic data, waiting for binding to application data.

got it ;), just confused of how to use this in Dialog or Q/A app.
But getting there …

Still trying to get around creating correct sentences …
Straight questions seem doable, but when they become hierarchical will be mess :wink:

Is there some Formalism to extract info from DRS-db … something in the line of SQL/Xpath/?? for DRS.

Something that will permute the Q and the A so they can be matched, even if there is no exact match !! just wondering

?- listing(drs).
drs([A, B], [object(A, book, countable, na, eq, 1)-1/4, predicate(B, own, named('Peter'), A)-1/2]).
drs([], [question(drs([A, B], [query(A, what)-1/1, predicate(B, own, named('Peter'), A)-1/4]))]).
drs([], [question(drs([A, B], [object(A, book, countable, na, eq, 1)-1/5, predicate(B, own, named('Peter'), A)-1/3]))]).

Usually one can use drs2fol/2

exists(  What,
                   exists( Own,
                     ( query(Query,What,what) &
                     predicate(Query,Own,own,named('Peter'),What)))).

Next you will need to use something akin to PTTP or s(CASP) to convert the FOL to the prolog database.

Thanks, @logicmoo . I’m also struggling with DRS over here: Attempto, Prolog, and OWL - #7 by d-vyd