For Programmers: Free Programming Magazines  


Home > Archive > Prolog > January 2007 > Newbie questions about expert system shells









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie questions about expert system shells
tippytop38@yahoo.com

2007-01-16, 7:06 pm

hello all. i did a little prolog work back in school, but consider me
a newbie...

i wanted to put together an expert system with a web front end, and i'm
a little bit stuck. in googling around for somewhere to start, i found
a number of "expert system shells" that all seem to have the following
2 characteristics:

1) they make explicit calls to I/O routines to read user responses (not
helpful if you want to call into the expert system from a web-server
for example)
2) they all seem to re-implement backward chaining (for example
http://www.cee.hw.ac.uk/~alison/ai3...ction2_5_4.html look at
b_chain/*)

so I guess my first question is, i thought built in backward chaining
is the idea behind prolog, why do these shells re-implement it?

in any case, here's where i want to go. i need to turn the "shell" on
its head, changing the interaction to be more "iterator-style". so at
any given time, i want to be able to make a call into prolog that tells
me what the next "question" i need to ask is.

for example, given the following rules:

a(X) :- b(X)
b(Y) :- c(Y)

I would like to be able to issue the following query (or something like
it):

next-question(a(thing), M)

and have it evaluate to:

M=b(thing)
M=c(thing)

or possibly just one of those two. is something like that possible?
if so, what constructs should i be looking at to make that happen?
ultimately then I would like to be able to issue something like
"assert(b(thing))" and have the system tell me that "a(thing) has been
proven", but I figure once i have the first step working, that should
be straightforward.

thanks in advance for any help,
M

Markus Triska

2007-01-16, 7:06 pm

tippytop38@yahoo.com wrote:

> so I guess my first question is, i thought built in backward chaining
> is the idea behind prolog, why do these shells re-implement it?


Potential reasons:

1) They want different syntax for their rules (instead of standard
Prolog clause notation).

2) They want a different search strategy or more control over which
and how calls are performed etc.

> for example, given the following rules:
>
> a(X) :- b(X)
> b(Y) :- c(Y)
>
> I would like to be able to issue the following query (or something like
> it):
>
> next-question(a(thing), M)
>
> and have it evaluate to:
>
> M=b(thing)
> M=c(thing)


This is (2) from above. Consider the very simple meta-interpreter:

a(X) :- b(X).
b(Y) :- c(Y).

mi(true) :- !.
mi((A,B)) :- !, mi(A), mi(B).
mi(Goal) :-
( clause(Goal, Body) *->
mi(Body)
; format("do we have: ~w ? (y/n) ", [Goal]),
( get_single_char(0'y) ->
assert(Goal)
; fail
)
).

And the query:

%?- mi(a(thing)).
%@% do we have: c(thing) ? (y/n) n
%@% No

and:

%?- mi(a(thing)).
%@% do we have: c(thing) ? (y/n) y
%@% Yes

after which we also have:

%?- c(X).
%@% X = thing ;
%@% No

in the knowledge base.

All the best,
Markus Triska
tippytop38@yahoo.com

2007-01-16, 7:06 pm

markus,

thanks so much! i think the combination of the simple meta-interpreter
and understanding how clause/2 works will get me where i need to go.

one quick question. what is the difference between *-> and ->?
gprolog barfed on the first, though swi-prolog accepts both. given
that it's all punctuation, i'm having trouble getting google to explain
it to me.

thanks again.
M



Markus Triska wrote:
> tippytop38@yahoo.com wrote:
>
>
> Potential reasons:
>
> 1) They want different syntax for their rules (instead of standard
> Prolog clause notation).
>
> 2) They want a different search strategy or more control over which
> and how calls are performed etc.
>
>
> This is (2) from above. Consider the very simple meta-interpreter:
>
> a(X) :- b(X).
> b(Y) :- c(Y).
>
> mi(true) :- !.
> mi((A,B)) :- !, mi(A), mi(B).
> mi(Goal) :-
> ( clause(Goal, Body) *->
> mi(Body)
> ; format("do we have: ~w ? (y/n) ", [Goal]),
> ( get_single_char(0'y) ->
> assert(Goal)
> ; fail
> )
> ).
>
> And the query:
>
> %?- mi(a(thing)).
> %@% do we have: c(thing) ? (y/n) n
> %@% No
>
> and:
>
> %?- mi(a(thing)).
> %@% do we have: c(thing) ? (y/n) y
> %@% Yes
>
> after which we also have:
>
> %?- c(X).
> %@% X = thing ;
> %@% No
>
> in the knowledge base.
>
> All the best,
> Markus Triska


Markus Triska

2007-01-16, 7:06 pm

tippytop38@yahoo.com wrote:

> one quick question. what is the difference between *-> and ->?
> gprolog barfed on the first, though swi-prolog accepts both. given
> that it's all punctuation, i'm having trouble getting google to
> explain it to me.


Try

?- help(*-> ).

in SWI Prolog.

All the best,
Markus Triska
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com