Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a natural language front end to your family database which works like this: Yes? Print each daughter of fred. winnie alma esther Yes? Do

Write a natural language front end to your family database which works like this: Yes? Print each daughter of fred. winnie alma esther Yes? Do you know what a cousin is ? No, what is a cousin? Yes? Does fred have a daughter? Yes. Yes? Find every cousin of jill. Sorry, I dont know what cousins are! Yes? Does frd have a son? Sorry, I dont know who frd is! 2. Predicates are to be included for the following relations only (others must be learnt): father,mother,son,daughter,brother,sister,wife,husband/2 male,female,person/1 (child/3 & married/2 will be needed in defining these) 3. To assist you in the programming task some procedures are provided in the file $ai/prolog/family.pl which you MUST incorporate in your program (there are also additional hints and optional help predicates in this file).

family.pl

proceed:- prompt(_, 'Yes? '), write('Enter questions or statements ending in ?, ! or .'), nl, repeat, readlist([]|Sentence), process(Sentence), quit(Sentence). %A readlist method reads the sentence readlist(Sentence|[]):-write(Sentence),read(predicate),!.

% A quit message is a message starting with a quitcode quit([H|_]):- quitcode(H).

quitcode(q). quitcode(quit). quitcode(bye). quitcode(stop).

% Echoing is on - retract(echo) turns off; assert(echo) turns on.

:- dynamic echo/0. echo(X):-read(X). assert(echo).

% process either matches and answers a question or prints an error message process(X):- predicate(echo), write(X), nl, fail. process(X):- quit(X), write('Bye for now!'), nl. process(X):- question(X). process(X):- not(question(X)), write('Sorry, I can\'t make any sense of that!'), nl, fail.

:- dynamic question/1. question(X):- readlist([]),predicate(X),nl,fail.

% Relations you want to ask about must be (declared or asserted) dynamic.

% predicate(G) - there is a dynamic predicate with a head matching goal G. predicate(G):- true(clause(G,_)).

% relation(Rel,A) - there is a dynamic predicate with functor Rel & arity A relation(R,1):- G =.. [R,_], predicate(G). relation(R,2):- G =.. [R,_,_], predicate(G).

% Answer yes/no questions - succeed in either case. yesno(G):- true(G), write(yes), nl. yesno(G):- false(G), write(no), nl.

% Print an ack - simple predicates add readability and can be compiled away. ok:- write(ok), nl. true(G):- not(false(G)).

false(G):- not(G).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

What are the role of supervisors ?

Answered: 1 week ago