В Visual Prolog 7.5 заданы факты вида parent (a,b): a - родитель для b, и факты вида…
- User
В Visual Prolog 7.5 заданы факты вида parent (a,b): a - родитель для b, и факты вида man©: с - мужчина. Используя эти предикаты, определить: a) отношение grand_nephew(X,Y): X является внучатым племянником для Y (т.е. X - внук сестры или брата Y). б) отношение has cousin Kim(X): у человека X есть двоюродный брат или сестра по имени Kim. Написать полный код Вот пример кода в Visual Prolog 7.5: implement main open core
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 person("Judith",female()). person("Bill",male()). person("John",male()). person("Pam",female()). parent("John","Judith"). parent("Bill","John"). parent("Pam","Bill"). clauses father(Person, Father) :- parent(Person, Father), person(Father, male()). class predicates grandFather : (string Person, string GrandFather) nondeterm (0,0). 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("\grandfather test\n"), grandFather(X, Y), stdIO:: writef("% is the grandfather of %\n", Y, X), fail. run():- stdIO:: write("\n ancestor 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"), programControl:: sleep(9000), succeed().end implement main
goal mainExe::run(main::run).
- Assistant