Advertisement
Guest User

Untitled

a guest
Sep 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. %{ knowledge starts from here
  2. %% the database knows these people
  3. person('Mary Brod').
  4. person('Carl Stuckart').
  5. person('Rudolf Fisher').
  6. person('Amanda Least').
  7. person('Minority Report').
  8.  
  9. %% when they are born
  10. born('Mary Brod', date(1988, 3, 11)).
  11. born('Carl Stuckart', date(1978, 5, 10)).
  12. born('Rudolf Fisher', date(1978, 5, 10)).
  13. born('Amanda Least', date(1988, 11, 3)).
  14. born('Minority Report', date(1997, 11, 3)).
  15.  
  16. %% their gender
  17. gender('Mary Brod', female).
  18. gender('Carl Stuckart', male).
  19. gender('Rudolf Fisher', male).
  20. gender('Amanda Least', female).
  21. gender('Minority Report', male).
  22.  
  23. %% their sex orientation
  24. likesGender('Mary Brod', [female, male]).
  25. likesGender('Carl Stuckart', [female]).
  26. likesGender('Rudolf Fisher', [female]).
  27. likesGender('Amanda Least', [male]).
  28. likesGender('Minority Report', [female]).
  29.  
  30. %% who knows who (reciprocal)
  31. knows('Mary Brod', 'Amanda Least').
  32. knows('Mary Brod', 'Carl Stuckart').
  33. knows('Mary Brod', 'Minority Report').
  34. knows('Carl Stuckart', 'Mary Brod').
  35. knows('Carl Stuckart', 'Rudolf Fisher').
  36. knows('Carl Stuckart', 'Minority Report').
  37. knows('Rudolf Fisher', 'Carl Stuckart').
  38. knows('Rudolf Fisher', 'Amanda Least').
  39. knows('Rudolf Fisher', 'Minority Report').
  40. knows('Amanda Least', 'Mary Brod').
  41. knows('Amanda Least', 'Rudolf Fisher').
  42. knows('Amanda Least', 'Minority Report').
  43. knows('Minority Report', 'Mary Brod').
  44. knows('Minority Report', 'Carl Stuckart').
  45. knows('Minority Report', 'Rudolf Fisher').
  46. knows('Minority Report', 'Amanda Least').
  47.  
  48. %% who knows who (unidirectional)
  49. knows('Carl Stuckart', 'Amanda Least').
  50. knows('Rudolf Fisher', 'Mary Brod').
  51.  
  52. %% people like people (or maybe not); a rather broad term
  53. likes('Mary Brod', 'Carl Stuckart').
  54. likes('Carl Stuckart', 'Mary Brod').
  55. likes('Carl Stuckart', 'Rudolf Fisher').
  56. likes('Rudolf Fisher', 'Amanda Least').
  57. likes('Amanda Least', 'Mary Brod').
  58. likes('Amanda Least', 'Rudolf Fisher').
  59. likes('Mary Brod', 'Minority Report').
  60. likes('Carl Stuckart', 'Minority Report').
  61. likes('Rudolf Fisher', 'Minority Report').
  62. likes('Amanda Least', 'Minority Report').
  63. likes('Minority Report', 'Mary Brod').
  64. likes('Minority Report', 'Carl Stuckart').
  65. likes('Minority Report', 'Rudolf Fisher').
  66. likes('Minority Report', 'Amanda Least').
  67.  
  68.  
  69. %% people may be in love (unrequited or not), and even with
  70. %% more than one person.
  71. loves('Mary Brod', 'Amanda Least').
  72. loves('Carl Stuckart', 'Amanda Least').
  73. loves('Rudolf Fisher', 'Mary Brod').
  74. loves('Rudolf Fisher', 'Amanda Least').
  75. loves('Amanda Least', 'Rudolf Fisher').
  76.  
  77. %} knowledge ends here
  78.  
  79. %% friendship is reciprocal knowledge
  80. friends(P1, P2) :- knows(P1, P2), knows(P2, P1).
  81.  
  82. %% get year from gprolog dt struct given by date_time
  83. get_year(Y, dt(Y, _, _, _, _, _)).
  84.  
  85. %% compute the current age of a person (simplified)
  86. age(Person, AgeYear) :-
  87. person(Person),
  88. date_time(Dt),
  89. get_year(Yc, Dt),
  90. born(Person, date(Yb, _, _)),
  91. AgeYear is Yc - Yb.
  92.  
  93.  
  94. %% two persons could have sex if they like/love each other and their
  95. %% sex orientations match the gender of the probable partner,
  96. %% and if they are in age for each other or, if underaged,
  97. %% the difference is not more than 5
  98. canHaveSex(P1, P2) :-
  99. (likes(P1, P2) ; loves(P1, P2)),
  100. (likes(P2, P1) ; loves(P2, P1)),
  101. gender(P1, G1), gender(P2, G2),
  102. likesGender(P1, L1), likesGender(P2, L2),
  103. member(G1, L2), member(G2, L1),
  104. age(P1, Age1), age(P2, Age2),
  105. ( (Age1 >= 18, Age2 >= 18) ;
  106. ( abs(Age1 - Age2) < 6, (Age1 > 13, Age2 > 13) )
  107. ).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement