Ida GeorgeAlexandar
\ /
\ /
George
In this case, the work around is handled by using the middle name with one
of them. Unfortunately, this cannot be extend to be consistent,
because George jr. (the father) also has the middle name
Alexandar.
George isn't as common a name anymore, but consider the name, John Perry (a former TA). There's a John Perry who teaches piano at USC, a John Perry who's a philosophy professor at UC Berkeley, a John Perry who's a children's author. There's even at least one other John Perry here at UCLA.
Consider this solution: for each person in our dataset, store all the relevant information about them in this way:
person(firstname,middlename,lastname,gender,dateofbirth).
where dateofbirth is a list of three elements -
[year,month,day]. Thus, the representation for John Perry would be:
person(john,robert,perry,male,[1962,11,6]).
We would only need to store these records and parent records to
figure everything else out. A parent record would look like this:
parent(person(george,alexandar,perry,male,[1870,9,27]),
person(george,alexandar,perry,male,[1919,6,1])).
At this point, you may be thinking, "Ack! Now I have to deal with
all those extra fields any time I want to do something." Not so!
Remember the don't care variable in Prolog, _, allows you to
ignore stuff you don't care about. Thus, you could write a second
function parentName(P,C), which only deals with the first names:
parentName(P,C) :-
parent(person(P,_,_,_,_),person(C,_,_,_,_)).
Now I don't have to have the messy georgeAlexandar term, it'll
just find that George is the parent of George, and it'll
know which George is which.
To extend this example slightly, we could define other predicates
to map us back into the simple first-name relationships we were
used to from the previous page:
male(X) :- person(X,_,_,male,_).
female(X) :- person(X,_,_,female,_).
mother(M,C) :-
parent(person(M,_,_,female,_),person(C,_,_,_,_)).
father(F,C) :-
parent(person(F,_,_,female,_),person(C,_,_,_,_)).
Again, try to define son and daughter relations, if you'd like.