Gorgias port

Discussion on porting Prolog applications to Logtalk

Moderator: Paulo Moura

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Gorgias port

Post by Paulo Moura » Wed May 09, 2007 9:39 am

Hi!

I've made a quick Logtalk port of Gorgias, a general argumentation framework that combines the ideas of preference reasoning and abduction. The original Prolog version is available from the URL:

http://www2.cs.ucy.ac.cy/~nkd/gorgias/

The Logtalk port can be downloaded using the URL:

http://logtalk.org/files/ports/gorgias/ ... -2.tar.bz2

Your feedback is appreciated. Note that this is just a quick port, with much room for improvement. It may also contain bugs not present in the original code. Enjoy,

Paulo

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Post by Victor NOEL » Tue May 15, 2007 4:59 pm

Hi,

It looks like there is a problem with the complement predicate, it looks like the rules :
complement(A, B) :- ^^complement(A, B)
doesn't work when added to one of the examples.

This is what i did :
i first tried to run tweety.lgt as it is by default, and when i try to prove :
tweety::prove([fly(tweety)], D).
it returns No like it should.

But if i add to this file these two lines (there is no meaning to it, it is just for the test) :
complement(a, b).
complement(A, B) :- ^^ complement(A, B).

and i try to prove :
tweety::prove([fly(tweety)], D).

it give me a solution because the complement/2 declared in gorgias.lgt are not used !

Maybe there is a problem with the ^^ functor and the categories ?

Thanks :)

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Post by Paulo Moura » Tue May 15, 2007 6:15 pm

Victor NOEL wrote:It looks like there is a problem with the complement predicate, it looks like the rules :
complement(A, B) :- ^^complement(A, B)
doesn't work when added to one of the examples.

This is what i did :
i first tried to run tweety.lgt as it is by default, and when i try to prove :
tweety::prove([fly(tweety)], D).
it returns No like it should.

But if i add to this file these two lines (there is no meaning to it, it is just for the test) :
complement(a, b).
complement(A, B) :- ^^ complement(A, B).

and i try to prove :
tweety::prove([fly(tweety)], D).

it give me a solution because the complement/2 declared in gorgias.lgt are not used !

Maybe there is a problem with the ^^ functor and the categories ?
My mistake, sorry. The ^^/2 operator (aka super call) would work if gorgias was an ancestor object, not a category. In this case, you need to use the alias/3 directive. E.g.:

Code: Select all

:- object(tweety,
	imports(gorgias)).

	:- initialization(::init).

	:- alias(gorgias, complement/2, default_complement/2).

	rule(r1(X), fly(X), [bird(X)]).
	rule(r2(X), neg(fly(X)), [penguin(X)]).

	rule(f1, bird(tweety), []).
	rule(f2, penguin(tweety), []).

	rule(pr1(X), prefer(r2(X), r1(X)), []).

	complement(a, b). 
	complement(A, B) :-
		::default_complement(A, B). 

:- end_object.
A quick expalnation: the definiton of the predicate complement/2 on the object tweety overrides the default definiton on the gorgias category. In order for you to be able to use both the default definitions and the local ones, the alias/3 directive is used to give an alternative name to the predicate complement/2 as (virtually) imported by tweety from the gorgias category.

I've already updated the Gorgias port. You may download it using the URL:

http://logtalk.org/files/ports/gorgias/ ... -3.tar.bz2

All the best,

Paulo
Paulo Moura
Logtalk developer

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Gorgias port

Post by Victor NOEL » Wed Mar 19, 2008 2:44 pm

Hello :)

I am trying to look at gorgias again, and of course, I plan to use it with logtalk :)

While doing tests I noticed two things :

1) the imports in gorgias.lgt should be changed to extends (since lgt 2.31.0)
2) if there is no abducible/2 defined in the theory that imports category gorgias, there is an error !

I don't really know how to handle that, I just know that there is somewhere in resolver.lgt a predicate that try to see if abducible/2 is true for a specific predicate.

Thanks you.

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Gorgias port

Post by Paulo Moura » Wed Mar 19, 2008 10:31 pm

Victor NOEL wrote: I am trying to look at gorgias again, and of course, I plan to use it with logtalk :)
Good to know :-)
Victor NOEL wrote: While doing tests I noticed two things :

1) the imports in gorgias.lgt should be changed to extends (since lgt 2.31.0)
Correct. The change was a consequence of the extended category functionality introduced in version 2.31.0.
Victor NOEL wrote: 2) if there is no abducible/2 defined in the theory that imports category gorgias, there is an error !

I don't really know how to handle that, I just know that there is somewhere in resolver.lgt a predicate that try to see if abducible/2 is true for a specific predicate.
A possible solution would be to add the following clause to the "gorgias" category:

Code: Select all

abducible(_, _) :- fail.
This clause would act as a catch-all rule when the theory does not define itself the predicate abducible/2.

Happy logtalking!

Paulo
Paulo Moura
Logtalk developer

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Gorgias port

Post by Victor NOEL » Thu Mar 20, 2008 7:56 am

Paulo Moura wrote: A possible solution would be to add the following clause to the "gorgias" category:

Code: Select all

abducible(_, _) :- fail.
This clause would act as a catch-all rule when the theory does not define itself the predicate abducible/2.
Ok, I was thinking about something like that but I wasn't sure it was the best way to resolve it :)
Paulo Moura wrote: Happy logtalking!

Paulo
I will :]

Victor

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Gorgias port

Post by Victor NOEL » Thu Apr 03, 2008 9:43 am

Hello,

In fact, I can't add abducible(_,_) :- fail. to gorgias.lgt because gorgias.lgt is a category and can't have dynamic (abducible) predicates declared in it :)

So I tried to adopt the trick detailed in http://logtalk.org/manuals/userman/categories.html :
using a predicate abducible_/2 defined in the category and used by the category and let abducible/2 be dynamic :
abducible_(_,_) :- fail.
abducible_(A, B) :- ::abducible(A, B).

But the problem is here again with abducible/2, and I can't see how to do it differently .. If you have an idea it would be good ;)

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Gorgias port

Post by Paulo Moura » Thu Apr 03, 2008 11:28 am

Hi!

You have found a bug. A simpler way to reproduce it is as follows:

Code: Select all

:- category(ctg).

	:- public(test/1).

	:- private(d/1).
	:- dynamic(d/1).

	test(X) :-
		::d(X).

:- end_category.


:- object(obj,
	imports(ctg)).

:- end_object.
After compiling and loading the code above, sending the message test/1 to the object results in an error:

Code: Select all

?- {bug}.
<<< loading source file bug... 
>>> compiling source file bug...
compiling category ctg... compiled
compiling object obj... compiled
>>> bug source file compiled
% bug.pl compiled 0.00 sec, 4,188 bytes
<<< bug source file loaded
(0 warnings)
true.

?- obj::test(X).
ERROR: Undefined procedure: d/1
The correct answer to the message would be an error as the predicate d/1 is declared and dynamic. I'm teaching classes all afternoon. I will look into fixing the problem later at night. Thanks for reporting the problem.

Cheers,

Paulo
Paulo Moura
Logtalk developer

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Gorgias port

Post by Victor NOEL » Thu Apr 03, 2008 11:46 am

Oh ok :)

I will wait for a fix, thanks you for the fast repy :)

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Gorgias port

Post by Paulo Moura » Thu Apr 03, 2008 12:49 pm

Paulo Moura wrote: The correct answer to the message would be an error as the predicate d/1 is declared and dynamic. I'm teaching classes all afternoon. I will look into fixing the problem later at night. Thanks for reporting the problem.
Typo above. The correct answer to the me message would be a failure, of course, not an error.

Cheers,

Paulo
Paulo Moura
Logtalk developer

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Gorgias port

Post by Paulo Moura » Thu Apr 03, 2008 5:45 pm

Victor NOEL wrote: I will wait for a fix, thanks you for the fast repy :)
Fixed in the current development version (r4185):

http://trac.logtalk.org/ticket/5

Please check and report back any remaining problems.

Cheers,

Paulo
Paulo Moura
Logtalk developer

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Gorgias port

Post by Victor NOEL » Fri Apr 04, 2008 9:04 am

Looks like all is working great now (I just applied r4185 to lgt 2.31.4).

I am modifying a little gorgias to better handle all the dynamic predicates, next I will take a look at all the union operation that needed to be sorted to see if it can be better handled.

After that I will post here a better version maybe with little documentation :)

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Gorgias port

Post by Victor NOEL » Fri Apr 04, 2008 9:54 am

Another question :

Is there a reason why there is no set operation on unordered set like in the lists.pl from swi-prolog ? Or maybe there is but I couldn't see it :)

Because lists order is important for gorgias (or at least for me about how I can understand the semantic of the results it give me :) so I don't want to use ordered sets but unordered sets !

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Gorgias port

Post by Victor NOEL » Fri Apr 04, 2008 2:55 pm

And a second one :)

I am trying to use the threaded/1 predicate to do and-parallelism but when I use the :
:- threaded.

directive in the gorgias category, I get this error :
ERROR! domain_error(object_directive, threaded/0)
in directive: :-threaded
above line: 25
ERROR: Unknown error term: error(domain_error(object_directive, threaded/0), directive(threaded))

I guess category can not be threaded but how I can do to use threaded/1 predicate in category without declare it as threaded ?

Edit :
I add a question :
I am trying to parallelize the prove/2 predicate of gorgias.lgt :
resolve/2 gives us multiple Query/Delta0 and I would like to run extend each one in a thread.
I thought about running extend in a threaded_call/1 and after running threaded_exit/1, but I can' find a way to do it, (mostly because there is so much variables ... :)

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Gorgias port

Post by Paulo Moura » Fri Apr 04, 2008 8:13 pm

Victor NOEL wrote:And a second one :)

I am trying to use the threaded/1 predicate to do and-parallelism but when I use the :
:- threaded.

directive in the gorgias category, I get this error :
ERROR! domain_error(object_directive, threaded/0)
in directive: :-threaded
above line: 25
ERROR: Unknown error term: error(domain_error(object_directive, threaded/0), directive(threaded))

I guess category can not be threaded but how I can do to use threaded/1 predicate in category without declare it as threaded ?
You can use any of the multi-threading predicates, including threaded/1, from a category. You just ned to use the directive threaded/0 in all objects importing the category.
Victor NOEL wrote: Edit :
I add a question :
I am trying to parallelize the prove/2 predicate of gorgias.lgt :
resolve/2 gives us multiple Query/Delta0 and I would like to run extend each one in a thread.
I thought about running extend in a threaded_call/1 and after running threaded_exit/1, but I can' find a way to do it, (mostly because there is so much variables ... :)
Take a look to the multi-threading examples in the current Logtalk development version, especially to the "primes" example. If you chose to use the latest development version of Logtalk to take advantage of the multi-threading features, be sure to use the latest development versions of SWI-Prolog or YAP. There is at the moment an incompatibility with the development version of XSB that I hope to be solved soon.

Cheers,

Paulo
Paulo Moura
Logtalk developer

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest