Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Difference in query execution in XSB and ErgoAI Studio

28 views
Skip to first unread message

Alex Netkachov

unread,
Aug 17, 2023, 7:29:48 PM8/17/23
to ErgoAI and XSB Users Forum
Hello team.

I've found rather strange difference in behaviour of my query when it is run through XSB command prompt and ErgoAI Studio query window.

Consider the following example:

=== File: example.ergo ===

interface(iCommand).
class(command).
class(asyncCommand).
implements(command, iCommand).
implements(asyncCommand, iCommand).

implementations(?Interface, ?Classes):-
  ?Classes = setof{?Class | implements(?Class, ?Interface)}.

@!{print_implementations(?Type)} !-
  once{implementations(?Type, ?Classes)},
  ?Class \in ?Classes,
  writeln(?Class)@\io.
 
=== end of file ===

In XSB shell:

ergo> add{'C:\\Users\\User\\Projects\\EI\\example'}.
Times (in seconds): elapsed = 0.479; pure CPU = 0.438
Yes
ergo> query{print_implementations(iCommand), 'example.ergo', \@}.
asyncCommand
Times (in seconds): elapsed = 0.008; pure CPU = 0.015
Yes 

Notice that the query only returned one class.

In ErgoAI Studio, however, the result is different when the query is executed through the Ergo Query window (Ctrl+U) - it prints two commands in the Ergo Listener:

asyncCommand
command

Could you please help me understand why it happens and whether it is possible to achieve the same output in XSB shell?

Thanks!

Kind Regards,
Alex

Michael Kifer

unread,
Aug 18, 2023, 1:29:54 PM8/18/23
to ErgoAI-X...@coherentknowledge.com

The thing is that the query window in the studio executes a slightly different query, something like (Query, \false; \true),

which has to do with the peculiarities of the Java interface.

The query window is used mostly to get the explanations. As an query-answer interface to Ergo the query window is quite awkward.


For interactive queries you  should use the studio listener or the ErgoAI shell command window

(what you called "XSB shell"; XSB shell is quite different: it takes only Prolog commands).


--

       --- michael


 

--
You received this message because you are subscribed to the Google Groups "ErgoAI and XSB Users Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ErgoAI-XSB-for...@coherentknowledge.com.
To view this discussion on the web visit https://groups.google.com/a/coherentknowledge.com/d/msgid/ErgoAI-XSB-forum/bc471733-2d1f-4b45-9118-01c53180482cn%40coherentknowledge.com.

Alex Netkachov

unread,
Aug 18, 2023, 1:43:55 PM8/18/23
to ErgoAI and XSB Users Forum, Michael Kifer
Thank you, I will use the shell for querying.
 
Is there a way to make print_implementations run in the similar way in ErgoAI shell command window? If not, what would be the right way to achieve the same behaviour (run writeln(?Class)@\io for every item in the ?Classes set)? 

Thanks!

Kind Regards,
Alex

Michael Kifer

unread,
Aug 18, 2023, 4:32:01 PM8/18/23
to Alex Netkachov, ErgoAI and XSB Users Forum

@!{print_implementations(?Type)} !-
  implementations(?Type, ?Classes),
  ?Class \in ?Classes,
  writeln(?Class)@\io,
  !.


should work for that particular query.

--

       --- michael


 

Alex Netkachov

unread,
Aug 19, 2023, 4:36:49 AM8/19/23
to Michael Kifer, ErgoAI and XSB Users Forum
I've modified the print_implementations query, but it still writes only one result:

@!{print_implementations(?Type)} !-
  implementations(?Type, ?Classes),
  ?Class \in ?Classes,
  writeln(?Class)@\io,
  !.


ergo> query{print_implementations(iCommand), 'example.ergo', \@}.
asyncCommand

Times (in seconds): elapsed = 0.003; pure CPU = 0.000

Yes


Maybe something else can be changed to make it work as expected?

Thanks!

Kind regards,
Alex

Michael Kifer

unread,
Aug 19, 2023, 2:16:56 PM8/19/23
to Alex Netkachov, ErgoAI and XSB Users Forum

I thought you wanted the query to give only one answer. Otherwise, why did you use once{...}?

If you want all classes to be printed then


@!{print_implementations3(?Type)} !-
        implementations(?Type, ?Classes),
        ( ?Class \in ?Classes,
          writeln(?Class)@\io,
          \false
        ; \true
        ).


Note that you are trying to play with non-logical side effects (writing) here, so the solution is also not declarative, ie,

a fail-loop like in Prolog. This fail loop is not needed in order to get the answers to the query itself (which is just yes/no here).

--

       --- michael


 

Alex Netkachov

unread,
Aug 19, 2023, 3:52:36 PM8/19/23
to Michael Kifer, ErgoAI and XSB Users Forum
It works as I want it to now. Thank you very much for your help!

Kind Regards,
Alex
Reply all
Reply to author
Forward
0 new messages