Correo dos exerccios de engenharia do conhecimento em

  • Slides: 11
Download presentation
Correção dos exercícios de engenharia do conhecimento em Prolog Jacques Robin, DI-UFPE www. di.

Correção dos exercícios de engenharia do conhecimento em Prolog Jacques Robin, DI-UFPE www. di. ufpe. br/~jr

Estudo de caso: a terrível novela Requisitos em Inglês 1. A soap opera is

Estudo de caso: a terrível novela Requisitos em Inglês 1. A soap opera is a TV show whose characters include a husband, a wife and a mailman such that: 2. the wife and the mailman blackmail each other 3. everybody is either alcoholic, drug addict or gay 4. Dick is gay, Jane is alcoholic and Harry is a drug addict 5. the wife is always an alcoholic and the long-lost sister of her husband 6. the husband is always called Dick and the lover of the mailman 7. the long-lost sister of any gay is called either Jane or Cleopatra 8. Harry is the lover of every gay 9. Jane blackmails every drug addicted lover of Dick 10. soap operas are invariably terrible! 0. Who are the characters of a terrible TV show?

Correção do exercício 1: A terrível novela em L 1

Correção do exercício 1: A terrível novela em L 1

Correção do exercício 2: A terrível novela em Prolog tv. Show(Cast, Qual) : soap.

Correção do exercício 2: A terrível novela em Prolog tv. Show(Cast, Qual) : soap. Opera(Cast, Qual). soap. Opera([dick, W, M], terrible) : soap. Cast([dick, W, M]), blackmail(W, M), alcoholic(W), long. Lost. Sister(W, dick), lover(M, dick). soap. Cast([]). soap. Cast([H|T]) : - soap. Char(H), soap. Cast(T). soap. Char(C) : - alcoholic(C). soap. Char(C) : - drug. Addict(C). soap. Char(C) : - gay(C). gay(dick). alcoholic(jane). drug. Addict(harry). lover(Harry, G) : - gay(G). long. Lost. Sister(jane, G) : - gay(G). long. Lost. Sister(cleopatra, G) : - gay(G). blackmail(jane, M) : - lover(M, dick), drug. Addict(M). ? -tv. Show(Cast, terrible). * Cast = [dick, jane, harry].

Estudo de caso: o banco de dados acadêmico Requisitos em Inglês 1. Bob is

Estudo de caso: o banco de dados acadêmico Requisitos em Inglês 1. Bob is 40 and is the manager of the CS department. 2. His assistants are John and Sally. 3. Mary’s highest degree is an MS. 4. She works at the CS department and is friend to Bob and Sally. 5. Every faculty is a midaged person who writes article, makes in the average $50, 000 a year and owns a degree of some kind, typically a Ph. D. 6. A faculty’s boss is both a faculty and a manager. 7. Every person has a name, friends who must be persons, and children who also must be persons. 8. Every employee is affiliated to some department, has a boss who is also na employee and joint work on reports with other employees. 9. Every department has a manager who is an employee and assistants who are both employees and students 10. A boss is an employee who is the manager of another employee of the same department. 11. A joint work is a paper that is written by two faculties 0 a: Who are the midaged employees of the CS department and who are their boss? 0 b: Who published jointly with Mary in the Journal of the ACM? 0 c: Where did Mary published joint work with Phil?

Correção do exercício 3: O banco de dados acadêmico em Prolog 1/ fatos ground

Correção do exercício 3: O banco de dados acadêmico em Prolog 1/ fatos ground person(bob). age(bob, 40). works(bob, cs, faculty). manager(cs, bob). dept(cs). works(john, cs, assistant). study(john, cs). works(sally, cs, assistant). study(sally, cs). hi. Deg(mary, ms). works(mary, cs, faculty). friends(mary, bob). friends(mary, sally). works(phil, cs, faculty). degree(phd). degree(ms). journal(jacm). conf(cacm). article(flogic, [john, sally, mary, bob], jacm). article(florid, [phil, mary, bob], cacm).

Correção do exercício 3: O banco de dados acadêmico em Prolog 2/ regras de

Correção do exercício 3: O banco de dados acadêmico em Prolog 2/ regras de dedução hi. Deg(F, phd) : - works(F, _, faculty), not hi. Deg(F, ms). salary(P, 5000) : - works(F, _, faculty), not salary(F, _). midaged(F) : - age(F, A), !, integer(A), A >= 30, A =< 60. midaged(F) : - works(F, _, faculty). works(B, D, faculty) : - manager(D, B), works(E, D, faculty), !. activity(F, paper. Writing) : works(F, _, faculty). works(S, D, assistant) : - study(S, D), dept(D), works(S, D, _), !. works(M, D, _) : - manager(M, D). boss(B, E) : - manager(D, B), works(E, D, _). person(P 2) : - friends(P 1, P 2), person(P 1). person(C) : - parent(A, C), person(A). person(P) : - study(P, D), dept(D). person(P) : - works(P, _, D), dept(D). report(T, Al, J) : - article(T, Al, J), journal(J). report(T, Al, C) : - article(T, Al, C), conf(C). report(T, Al, D) : - techrep(T, Al, D), dept(D). joint. Work(W, F 1, F 2, P) : - works(F 1, _, faculty), works(F 2, _, faculty), F 1 = F 2, report(W, Fl, P), member(F 1, Fl), member(F 2, Fl). member(H, [H|T]). member(X, [H|T]) : - member(X, T).

Correção do exercício 3: O banco de dados acadêmico em Prolog 3/ consultas midaged.

Correção do exercício 3: O banco de dados acadêmico em Prolog 3/ consultas midaged. Worker. Of(E, D) : - works(E, D, _), midaged(E). boss. Of. Midaged. Worker. Of(B, D) : midaged. Worker. Of(E, D), boss(B, E). ? setof(E, midaged. Worker. Of(E, cs), Le), setof(B, boss. Of. Midaged. Worker. Of(B, cs), Lb). * E = _20, Le = [bob, mary], B = _51, Lb = [bob]; * no. ? setof(F, joint. Work(_, F, mary, jacm), Lf). * F = _20, Lf = [bob]; * no. ? setof(P, joint. Work(_, phil, mary, P), Lp). * P = _20, Lp = [cacm]; * no

Correção do exercício 4: O banco de dados acadêmico em L 1 1/ formulas

Correção do exercício 4: O banco de dados acadêmico em L 1 1/ formulas ground

Correção do exercício 4: O banco de dados acadêmico em L 1 2/ formulas

Correção do exercício 4: O banco de dados acadêmico em L 1 2/ formulas quantificadas

Correção do exercício 4: O banco de dados acadêmico em L 1 3/ consultas

Correção do exercício 4: O banco de dados acadêmico em L 1 3/ consultas