0% found this document useful (0 votes)
34 views

Family Tree

This document defines predicates for determining familial relationships by loading family data from a file and querying it. It defines predicates for father, grandfather, and ancestor relationships and provides sample queries to test each predicate by printing out statements like "X is the father of Y". The main goal runs these sample queries and prints output to test the predicates.

Uploaded by

sahiloo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Family Tree

This document defines predicates for determining familial relationships by loading family data from a file and querying it. It defines predicates for father, grandfather, and ancestor relationships and provides sample queries to test each predicate by printing out statements like "X is the father of Y". The main goal runs these sample queries and prints output to test the predicates.

Uploaded by

sahiloo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

implement main open core constants className = "main". classVersion = "$JustDate: 2007-09-24 $$Revision: 1 $". clauses classInfo(className, classVersion).

domains gender = female(); male(). class facts - familyDB person : (string Name, gender Gender). parent : (string Person, string Parent). class predicates father : (string Person, string Father) nondeterm anyflow. clauses father(Person, Father) :parent(Person, Father), person(Father, male()). class predicates grandFather : (string Person, string GrandFather) nondeterm (o,o). clauses grandFather(Person, GrandFather) :parent(Person, Parent), father(Parent, GrandFather). class predicates ancestor : (string Person, string Ancestor) nondeterm (i,o). clauses ancestor(Person, Ancestor) :parent(Person, Ancestor). ancestor(Person, Ancestor) :parent(Person, P1), ancestor(P1, Ancestor). class predicates reconsult : (string FileName).

clauses reconsult(FileName) :retractFactDB(familyDB), file::consult(FileName, familyDB). clauses run():console::init(), stdIO::write("Load data\n"), reconsult("..\\fa.txt"), stdIO::write("\nfather test\n"), father(X, Y), stdIO::writef("% is the father of %\n", Y, X), fail. run():stdIO::write("\ngrandFather test\n"), grandFather(X, Y), stdIO::writef("% is the grandfather of %\n", Y, X), fail. run():stdIO::write("\nancestor of Pam test\n"), X = "Pam", ancestor(X, Y), stdIO::writef("% is the ancestor of %\n", Y, X), fail. run():stdIO::write("End of test\n"). end implement main goal mainExe::run(main::run).

You might also like