# Assignment 6: Building Knowledge Bases in PROLOG

## Due: Monday, December 6, 2021

This exercise has two parts. Please read the entire assignment carefully before starting. Define ONLY the relationships you will need to use for answering the queries. Comment your code generously. Be sure to include your names at the top of each code file in a comment. Start early!

PART 1:

Write first-order predicate calculus wffs to derive the following relationships:

Spouse, husband, wife, father, mother, sibling, brother, sister, grandparent, grandfather, grandmother, grandchild, grandson, granddaughter, ancestor, child, son, daughter, descendant, uncle, aunt, cousin, nephew, neice, greatgrand/parent/father/mother/child/son/daughter, etc.

In writing the above, you may use the following relations which will be used to represent facts:

Male(x) : x is a male
Female(x) : x is a female
Parent(x, y) : x is a parent of y
Married(x, y) : x is married to y

As above, first give interpretations of any new relations you introduce. Next, translate the wffs obtained into PROLOG rules. Below, we capture the Simpsons (from the TV series) family tree in the Prolog facts shown.

Time to test what you have. Use the following facts to test the rules above:

% males and females
male(abraham).
male(clancy).
male(herb).
male(homer).
male(bart).
female(mona).
female(jackie).
female(marge).
female(patty).
female(selma).
female(lisa).
female(maggie).
female(ling).

% maritals
married(abraham, mona).
married(mona, abraham).
married(clancy, jackie).
married(jackie, clancy).
married(homer, marge).
married(marge, homer).

% parents
parent(abraham, herb).
parent(mona, herb).
parent(abraham, homer).
parent(mona, homer).
parent(clancy, marge).
parent(jackie, marge).
parent(clancy, patty).
parent(jackie, patty).
parent(clancy, selma).
parent(jackie, selma).
parent(homer, bart).
parent(marge, bart).
parent(homer, lisa).
parent(marge, lisa).
parent(homer, maggie).
parent(marge, maggie).
parent(selma, ling).

Write and show the results of the following queries:

1. Who are all the females in this family tree?
2. Who are the children of Marge?
3. Who are the grandparents of Maggie?
4. Who is the father of Homer?
5. Who is the father of Ling?
6. Who is the mother of Ling?
7. Who are all the grandparents?
8. Who are the aunts of Bart?
9. Who are the uncles of Bart?
10. Who are the ancestors of Lisa?
11. Is Patty an aunt of Maggie?

PART 2:

Next, using the relations used above (male/female/married/parent), encode the family tree shown below:

The image below also lists Last Names. Also, note that there are two people named Lily and James (call them LillyEvans, Lily Potter, James Potter I, and James Potter 2.

Using the same set of rules about relationships you defined in PART 1 above (for spouse/husband/wife/.../daughter), encode and issue the following querries:

1. Who is the father of Harry Potter?
2. Who is the mother of Ginny Weasley?
3. Who are Harry Potter's siblings?
4. Who are Ginny Weasley's siblings?
5. Does Harry Potter have a grandmother? Greatgrandmother?
6. Does Harry Potter have a cousin? Who is it?
7. Who are Harry Potter's aunts and uncles?
8. Who is Bill Weasley married to? Who is Ron Weasley married to?
9. Who are the greatgrandchildren of Mr/Mrs Potter (Mr. and Mrs Potter are James Potter's parents)
10. Who are the greatgrandchildren of Septimus/Cederella Weasley?

What to hand in:

A formatted print out of the following:

1. The first-order wffs you wrote for family relationships (Learn to use the equation editor in your word processor-LaTeX or Word). Their encoding in PROLOG.
2. A print out of the COMPLETE answers to all of the querries for PART 1.
3. The Harry Potter facts database you used.
4. A print out of the COMPLETE answers to the querries for PART 2.
5. A short 1-2 paragraph narrative/reflection on this exercise.