Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clauses
- person("Judith",female()).
- person("Bill",male()).
- person("John",male()).
- person("Pam",female()).
- parent("John","Judith").
- parent("Bill","John").
- parent("Pam","Bill").
- implement main
- open core
- domains
- gender = female; male.
- class facts - familyDB
- person : (string Name, gender Gender).
- parent : (string Person, string Parent).
- class predicates
- brother : (string X, string Y) nondeterm anyflow.
- clauses
- brother(X, Y) :-
- parent(X, Z),
- parent(Y, Z),
- person(Y, male()),
- Y <> X.
- class predicates
- cousin : (string X, string Y) nondeterm anyflow. %y - двоюродный брат
- clauses
- cousin(X, Y) :-
- parent(X, Z),
- parent(Y, G),
- parent(Z, F),
- parent(G, F),
- Z <> G,
- person(Y, male()),
- Y <> X.
- class predicates
- cousine : (string X, string Y) nondeterm anyflow. %y - двоюродная сестра
- clauses
- cousine(X, Y) :-
- parent(X, Z),
- parent(Y, G),
- parent(Z, F),
- parent(G, F),
- Z <> G,
- person(Y, female()),
- Y <> X.
- class predicates
- uncle : (string X, string Y) nondeterm anyflow. %y - дядя
- clauses
- uncle(X, Y) :-
- parent(Y, F),
- parent(Z, F),
- parent(X, Z),
- not(parent(X, Y)),
- person(Y, male()).
- class predicates
- nephew : (string X, string Y) nondeterm anyflow. %y - племянник
- clauses
- nephew(X, Y) :-
- parent(X, Z),
- parent(F, Z),
- X <> F,
- parent(Y, F),
- person(Y, male()).
- class predicates
- grandnephew : (string X, string Y) nondeterm anyflow. %y - внучатый племянник
- clauses
- grandnephew(X, Y) :-
- parent(X, Z),
- parent(F, Z),
- X <> F,
- parent(G, F),
- parent(Y, G),
- person(Y, male()).
- class predicates
- grandson : (string X, string Y) nondeterm anyflow. %y - внук
- clauses
- grandson(X, Y) :-
- parent(Z, X),
- parent(Y, Z),
- person(Y, male()).
- class predicates
- aunt : (string X, string Y) nondeterm anyflow. %y - тётя
- clauses
- aunt(X, Y) :-
- parent(Y, F),
- parent(Z, F),
- parent(X, Z),
- not(parent(X, Y)),
- person(Y, female()).
- class predicates
- niece : (string X, string Y) nondeterm anyflow. %y - племянница
- clauses
- niece(X, Y) :-
- parent(X, Z),
- parent(F, Z),
- X <> F,
- parent(Y, F),
- person(Y, female()).
- class predicates
- grandniece : (string X, string Y) nondeterm anyflow. %y - внучатая племянница
- clauses
- grandniece(X, Y) :-
- parent(X, Z),
- parent(F, Z),
- X <> F,
- parent(G, F),
- parent(Y, G),
- person(Y, female()).
- class predicates
- granddaughter : (string X, string Y) nondeterm anyflow. %y - внучка
- clauses
- granddaughter(X, Y) :-
- parent(Z, X),
- parent(Y, Z),
- person(Y, female()).
- class predicates
- sister : (string X, string Y) nondeterm anyflow.
- clauses
- sister(X, Y) :-
- parent(X, Z),
- parent(Y, Z),
- person(Y, female()),
- X <> Y.
- 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 anyflow.
- clauses
- grandFather(Person, GrandFather) :-
- parent(Person, Parent),
- father(Parent, GrandFather).
- class predicates
- mother : (string Person, string Mother) nondeterm anyflow.
- clauses
- mother(Person, Mother) :-
- parent(Person, Mother),
- person(Mother, female()).
- class predicates
- grandMother : (string Person, string GrandMother) nondeterm anyflow.
- clauses
- grandMother(Person, GrandMother) :-
- parent(Person, Parent),
- mother(Parent, GrandMother).
- class predicates
- ancestor : (string Person, string Ancestor) nondeterm anyflow.
- 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("\nТест на отцов\n"),
- father(X, Y),
- stdIO::writef("% является отцом %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на матерей\n"),
- mother(X, Y),
- stdIO::writef("% является матерью %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на братьев\n"),
- brother(X, Y),
- stdIO::writef("% является братом %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на двоюродных братьев\n"),
- cousin(X, Y),
- stdIO::writef("% является двоюродным братом %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на сестер\n"),
- sister(X, Y),
- stdIO::writef("% является сестрой %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на двоюродных сестер\n"),
- cousine(X, Y),
- stdIO::writef("% является двоюродной сестрой %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на дядей\n"),
- uncle(X, Y),
- stdIO::writef("% является дядей %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на племянников\n"),
- nephew(X, Y),
- stdIO::writef("% является племянником %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на внучатых племянников\n"),
- grandnephew(X, Y),
- stdIO::writef("% является внучатым племянником %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на внуков\n"),
- grandson(X, Y),
- stdIO::writef("% является внуком %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на дедушек\n"),
- grandFather(X, Y),
- stdIO::writef("% является дедушкой %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на бабушек\n"),
- grandMother(X, Y),
- stdIO::writef("% является бабушкой %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на тёть\n"),
- aunt(X, Y),
- stdIO::writef("% является тётей %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на племянниц\n"),
- niece(X, Y),
- stdIO::writef("% является племянницей %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на внучатая племянница\n"),
- grandniece(X, Y),
- stdIO::writef("% является внучатой племянницой %\n", Y, X),
- fail.
- run() :-
- stdIO::write("\nТест на внучек\n"),
- granddaughter(X, Y),
- stdIO::writef("% является внучкой %\n", Y, X),
- fail.
- run() :-
- X = "Pam",
- stdIO::writef("\nТест на предков %\n", X),
- ancestor(X, Y),
- stdIO::writef("% является предком %\n", Y, X),
- fail.
- run() :-
- stdIO::write("Конец теста\n").
- end implement main
- goal
- mainExe::run(main::run).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement