The
Family Tree Example
Suppose that we want to represent a
family tree, so that we can ask questions like "is john related to
...", or "list all john's sisters" and so on. The basic entities will be people; the
properties we will want to look at will be father, mother, brother, sister, aunt,
uncle, grandmother, grandfather, mother_in_law, father_in_law, ancestor,
descendent. Below you have three basic
predicates, male, female and parent, which will describe a family by a series
of facts. Take the following family tree as an
example:
James I m. Claudia
|
|
+----------------+-----------------+
| |
Charles I m. Fay
| |
| |
+----------+------------+ |
|
| | |
Catherine
Charles II James II Sophia m.
Sam
|
|
|
George
I
male(james1).
male(charles1).
male(charles2).
male(james2).
male(george1).
male(paul).
male(sam).
female(catherine).
female(
female(sophia).
female(claudia).
female(fay).
/* parent ( child, parent). */
parent(charles1,
james1).
parent(
parent(charles2,
charles1).
parent(catherine,
charles1).
parent(james2,
charles1).
parent(sophia,
parent(george1,
sophia).
parent(george1,
sam).
parent(catherine,
fay).
parent(charles2,
fay).
parent(james2, fay).
parent(sophia,
paul).
parent(elizabeth,claudia).
parent(charles1,
claudia).
/* married ( A,B) - A is married
to B */
married ( james1, claudia).
married( claudia, james1).
married(charles1, fay).
married(fay, charles1).
married(elizabeth, paul).
married(paul,
married(sophia, sam).
married(sam, sophia).
Copy
the above facts into notepad. Add rules to determine each of the following
relationships:
a. father
b. mother
c. brother
d. sister
e. aunt
f. uncle
g. grandmother
h. brother_in_law
i. mother_in_law
j. father_in_law
k. ancestor
l. descendent
Note: You will NOT get credit for typing in the
above relationships as facts.
Helpful hint: Think carefully about what makes someone an aunt.
Be sure to document your program using the standard heading. You do not need to include an input or output description. You DO need to explain what the program does (in your documentation). You do not need a friendly user interface.
Turn in
1. a print out of your program (showing your documentation, the above facts and your rules).
2. a screen capture of a run showing a test of each rule.
3. a floppy with your text file on it (if you need a floppy, I can give you one).
Please name your text file: family.pro