Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 30th, 2006, 4:36 AM   #1
zander
Newbie
 
zander's Avatar
 
Join Date: Jan 2006
Location: scotland
Posts: 3
Rep Power: 0 zander is on a distinguished road
prolog

hey does anyone use prolog? i'm doing a module on it in university and can't get to grips with it at all. it's completely different from object oriented languages that i've done, and i can't seem to make the connections between the rules, predicates and operators. predicates just seem to be created without any connection to anything else in the program

here's some this is the program that were working on the enbolded bits are the bits i don't understand.its really just where the predicates come from and what connection they have to the rest of the program.
Quote:

% EXPERT SYSTEM RULES (EXPERT KNOWLEDGE BASE)

rule(if eats(X, Y) and living(Y) then carnivore(X)).
rule(if carnivore(X) and big(X) then dangerous(X)).
rule(if has_feathers(X) then bird(X)).
rule(if bird(X) and small(X) then good_pet(X)).
rule(if cuddly(X) then good_pet(X)).


find_good_pet :-
retractall(kbfact(_)),

check_hypotheses([good_pet(lenny),good_pet(eddie),good_pet(tweety)]).

bird(a_kind_of,animal).
bird(moving_method,fly).
bird(active_at,daylight).
pigeon(a_kind_of,bird).
pigeon(colour,black).
pigeon(size,small).

% ------------------------------------------------------------------
% MAIN EXPERT SYSTEM SHELL CODE

% check_hypothesis(+Hypotheses)
% Succeeds when one of the hypotheses is proved true, or it
% has tried them all.
% Picks a hypothesis, and uses b_chain to find out if it is true.
% If it is true then b_chain succeeds and check_hypothesis writes out
the
% appropriate recommendation. If false it backtracks to 'on' to find
% another hypothesis to try.
% Once it has tried all the hypotheses it will backtrack to second
% check_hypothesis clause and write an appropriate message.

check_hypothesis(Hypoth) :-
bchain(Hypoth), % b_chain to check if true
atext(Hypoth, Text), % get hold of appropriate text
write_list(Text). % write out the recommendation

check_hypotheses(Hypotheses) :-
member(Hypoth, Hypotheses), % get a member of hypotheses
check_hypothesis(Hypoth).
check_hypotheses(_) :-
write('None of the possible hypotheses seems to be true\n').

% bchain(+Goal)
% Succeeds if Goal is true, given rules + facts supplied by user as
% backward chaining proceeds.

bchain(G1 and G2):- % G1 and G2 are true if
bchain(G1), % G1 can be proven in turn
bchain(G2). % and G2 can be too
bchain(Goal) :- % G's true if its a fact!
Goal \= (_G1 and _G2),
kbfact(Goal).
bchain(Goal):- % Goal is true if
rule(if Preconditions then Goal), % there is a rule concluding it
bchain(Preconditions). % and its Preconditions can be
% proven by backward chaining

bchain(Goal):- % Goal is true if
prompt_user(Goal).

% prompt_user(+Goal)
% True if there is some text to use to ask the user about it,
% and when you ask the user they say yes.

prompt_user(Goal) :-
qtext(Goal, Text),
write_list(Text),
format(" >> "),
get_reply(Reply),
process(Reply,Goal).

process(yes,Goal):-
assert( kbfact(Goal)).
process(why,Goal):-
tell_why(Goal),
!,
prompt_user(Goal).

get_reply(Reply):-
read(Answer),
means(Answer,Reply),
!.
get_reply(Reply):-
format("Answer unknown, please try again. >> "),
get_reply(Reply).

write_list([]).
write_list([Word|Words]) :-
format("~w", [Word]),
write_list(Words).
i know i'm being really vague but, any comments would be really appreciated.
zander is offline   Reply With Quote
Old Nov 10th, 2006, 2:08 AM   #2
jsilver608
Newbie
 
Join Date: Oct 2006
Posts: 20
Rep Power: 0 jsilver608 is on a distinguished road
Here is a site that may help you out:

http://www.csupomona.edu/~jrfisher/w.../contents.html
__________________
High Performance PHP
http://www.whenpenguinsattack.com
jsilver608 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
prolog help totos571 Other Programming Languages 1 Jun 4th, 2005 9:11 AM
Programming Prolog in C++ apcx C++ 8 Apr 30th, 2005 7:12 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC