Parsing a family tree
Now that we are more familiar with logic programming, let's use it to solve an interesting problem. Consider the following family tree:
Figure 2: Sample family tree
John and Megan have three sons – William, David, and Adam. The wives of William, David, and Adam are Emma, Olivia, and Lily respectively. William and Emma have two children – Chris and Stephanie. David and Olivia have five children – Wayne, Tiffany, Julie, Neil, and Peter. Adam and Lily have one child – Sophia. Based on these facts, we can create a program that can tell us the name of Wayne's grandfather or Sophia's uncles. Even though we have not explicitly specified anything about the grandparent or uncle relationships, logic programming can infer them.
These relationships are specified in a file called relationships.json
provided for you. The file looks like the following:
{
"father":
[
{"John"...