Advertisement
paper-m4rio

nlu.pl

Dec 11th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 7.32 KB | None | 0 0
  1. /******************* database **********************/
  2.  
  3. male(austin).
  4. male(brock).
  5. male(callum).
  6. male(dominic).
  7. male(eastwood).
  8. male(ferris).
  9. male(guy).
  10. male(houston).
  11. male(irving).
  12. male(jace).
  13. male(kingston).
  14. male(landon).
  15. male(mickey).
  16.  
  17. female(natalia).
  18. female(ophelia).
  19. female(phoenix).
  20. female(quinn).
  21. female(renee).
  22. female(sky).
  23. female(tessa).
  24. female(ursula).
  25. female(victoria).
  26. female(waverly).
  27. female(xenia).
  28. female(ysabelle).
  29. female(zahra).
  30.  
  31. person(P) :- male(P).
  32. person(P) :- female(P).
  33.  
  34. home(austin,toronto).
  35. home(brock,montreal).
  36. home(callum,vancouver).
  37. home(dominic,vancouver).
  38. home(eastwood,toronto).
  39. home(ferris,brampton).
  40. home(guy,brampton).
  41. home(houston,tokyo).
  42. home(irving,orlando).
  43. home(jace,newYork).
  44. home(kingston,newYork).
  45. home(landon,london).
  46. home(mickey,beijing).
  47. home(natalia,toronto).
  48. home(ophelia,montreal).
  49. home(phoenix,vancouver).
  50. home(quinn,vancouver).
  51. home(renee,toronto).
  52. home(sky,brampton).
  53. home(tessa,boston).
  54. home(ursula,tokyo).
  55. home(victoria,orlando).
  56. home(waverly,newYork).
  57. home(xenia,london).
  58. home(ysabelle,beijing).
  59. home(zahra,london).
  60.  
  61. city(toronto).
  62. city(montreal).
  63. city(vancouver).
  64. city(brampton).
  65. city(orlando).
  66. city(boston).
  67. city(newYork).
  68. city(tokyo).
  69. city(beijing).
  70. city(london).
  71.  
  72. country(canada).
  73. country(usa).
  74. country(england).
  75. country(japan).
  76. country(china).
  77. country(kenya).
  78. country(spain).
  79. country(australia).
  80. country(greece).
  81. country(jamaica).
  82.  
  83. location(toronto,canada).
  84. location(montreal,canada).
  85. location(vancouver,canada).
  86. location(brampton,canada).
  87. location(orlando,usa).
  88. location(boston,usa).
  89. location(newYork,usa).
  90. location(tokyo,japan).
  91. location(beijing,china).
  92. location(london,england).
  93.  
  94. population(toronto,1000000). /* big */
  95. population(montreal,45000). /* small */
  96. population(vancouver,500000). /* big */
  97. population(brampton,20000). /* small */
  98.  
  99. population(orlando,3000). /* small */
  100. population(newYork,700000). /* big */
  101. population(boston,51000). /* big */
  102.  
  103. population(tokyo,72000). /* big */
  104. population(beijing,10000). /* small */
  105. population(london,49000). /* small */
  106.  
  107. married(austin,natalia).
  108. married(natalia,austin).
  109. married(brock,ophelia).
  110. married(ophelia,brock).
  111. married(callum,phoenix).
  112. married(phoenix,callum).
  113. married(dominic,quinn).
  114. married(quinn,dominic).
  115. married(eastwood,renee).
  116. married(renee,eastwood).
  117. married(guy,sky).
  118. married(sky,guy).
  119. married(houston,ursula).
  120. married(ursula,houston).
  121. married(irving,victoria).
  122. married(victoria,irving).
  123. married(kingston,waverly).
  124. married(waverly,kingston).
  125. married(landon,xenia).
  126. married(xenia,landon).
  127. married(mickey,ysabelle).
  128. married(ysabelle,mickey).
  129.  
  130. parent(austin,callum).
  131. parent(natalia,callum).
  132. parent(brock,phoenix).
  133. parent(ophelia,phoenix).
  134. parent(callum,dominic).
  135. parent(phoenix,dominic).
  136. parent(callum,eastwood).
  137. parent(phoenix,eastwood).
  138. parent(dominic,ferris).
  139. parent(quinn,ferris).
  140. parent(dominic,sky).
  141. parent(quinn,sky).
  142. parent(guy,tessa).
  143. parent(sky,tessa).
  144. parent(houston,irving).
  145. parent(ursula,irving).
  146. parent(houston,jace).
  147. parent(ursula,jace).
  148. parent(houston,waverly).
  149. parent(ursula,waverly).
  150. parent(landon,mickey).
  151. parent(xenia,mickey).
  152. parent(mickey,zahra).
  153. parent(ysabelle,zahra).
  154.  
  155. friend(austin,brock).
  156. friend(brock,austin).
  157. friend(eastwood,jace).
  158. friend(jace,eastwood).
  159. friend(guy,mickey).
  160. friend(mickey,guy).
  161. friend(natalia,ophelia).
  162. friend(ophelia,natalia).
  163. friend(quinn,renee).
  164. friend(renee,quinn).
  165. friend(sky,ysabelle).
  166. friend(ysabelle,sky).
  167. friend(tessa,zahra).
  168. friend(zahra,tessa).
  169. friend(victoria,waverly).
  170. friend(waverly,victoria).
  171.  
  172. father(X,Y) :- male(X), parent(X,Y).
  173. mother(X,Y) :- female(X), parent(X,Y).
  174. brother(X,Y) :- male(X), parent(Z,X), parent(Z,Y), not(X=Y).
  175. sister(X,Y) :- female(X), parent(Z,X), parent(Z,Y), not(X=Y).
  176. grandfather(X,Y) :- father(X,Z), parent(Z,Y).
  177. grandmother(X,Y) :- mother(X,Z), parent(Z,Y).
  178. uncle(X,Y) :- brother(X,Z), parent(Z,Y).
  179. auntie(X,Y) :- sister(X,Z), parent(Z,Y).
  180. % an ancestor is a parent, grandparent, great-grandparent, great-great-grandparent, and so forth
  181. ancestor(X,Y) :- parent(X,Y).
  182. ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y).
  183. % a relative is someone you share a common ancestor with
  184. relative(X,Y) :- ancestor(X,Y), not(X=Y).
  185. relative(X,Y) :- ancestor(Y,X), not(X=Y).
  186. relative(X,Y) :- ancestor(Z,X), ancestor(Z,Y), not(X=Y).
  187.  
  188. /******************* lexicon **********************/
  189.  
  190. article(a). article(an). article(any).
  191.  
  192. common_noun(man,X) :- male(X).
  193. common_noun(woman,X) :- female(X).
  194. common_noun(person,X) :- person(X).
  195. common_noun(city,X) :- city(X).
  196. common_noun(country,X) :- country(X).
  197. common_noun(parent,X) :- parent(X,_).
  198. common_noun(friend,X) :- friend(X,_).
  199. common_noun(father,X) :- father(X,_).
  200. common_noun(mother,X) :- mother(X,_).
  201. common_noun(husband,X) :- male(X), married(X,_).
  202. common_noun(wife,X) :- female(X), married(_,X).
  203. common_noun(child,X) :- parent(_,X).
  204. common_noun(brother,X) :- brother(X,_).
  205. common_noun(sister,X) :- sister(X,_).
  206. common_noun(grandfather,X) :- grandfather(X,_).
  207. common_noun(grandmother,X) :- grandmother(X,_).
  208. common_noun(uncle,X) :- uncle(X,_).
  209. common_noun(auntie,X) :- auntie(X,_).
  210. common_noun(relative,X) :- relative(X,_).
  211. common_noun(ancestor,X) :- ancestor(X,_).
  212.  
  213. adjective(large,X) :- population(X,Y), Y >= 50000.
  214. adjective(small,X) :- population(X,Y), Y < 50000.
  215. adjective(largest,X) :- location(X,Z), population(X,Y), Y >= 50000, \+ (location(X2,Z), population(X2,Y2), Y2 >= 50000, not(X=X2), Y2 > Y).
  216. adjective(smallest,X) :- location(X,Z), population(X,Y), Y < 50000, \+ (location(X2,Z), population(X2,Y2), Y2 < 50000, not(X=X2), Y2 < Y).
  217. adjective(single,X) :- not(married(X,_)).
  218. adjective(married,X) :- married(X,_).
  219. adjective(american,X) :- home(X,C), location(C,usa).
  220. adjective(canadian,X) :- home(X,C), location(C,canada).
  221. adjective(chinese,X) :- home(X,C), location(C,china).
  222.  
  223. preposition(with,X,Y) :- friend(Y,X).
  224. preposition(with,X,Y) :- married(Y,X).
  225. preposition(with,X,Y) :- relative(Y,X).
  226. preposition(with,X,Y) :- ancestor(Y,X).
  227. preposition(of,X,Y) :- friend(Y,X).
  228. preposition(of,X,Y) :- married(Y,X).
  229. preposition(of,X,Y) :- relative(Y,X).
  230. preposition(of,X,Y) :- ancestor(Y,X).
  231. preposition(from,X,Y) :- home(X,Y).
  232. preposition(from,X,Y) :- home(X,C), location(C,Y).
  233. preposition(in,X,Y) :- location(X,Y).
  234.  
  235. proper_noun(X) :- not(article(X)), not(adjective(X,_)), not(common_noun(X,_)), not(preposition(X,_,_)).
  236.  
  237. /******************* parser **********************/
  238.  
  239. who(Words,Ref) :- np(Words,Ref).
  240. what(Words,Ref) :- np(Words,Ref).
  241.  
  242. /* Noun phrase can be a proper name or can start with an article */
  243.  
  244. np([Name],Name) :- proper_noun(Name).
  245. np([Art|Rest],Who) :- article(Art), np2(Rest,Who).
  246.  
  247. /* If a noun phrase starts with an article,then it must be followed
  248. by another noun phrase that starts either with an adjective
  249. or with a common noun. */
  250.  
  251. np2([Adj|Rest],Who) :- adjective(Adj,Who), np2(Rest,Who).
  252. np2([Noun|Rest],Who) :- common_noun(Noun,Who), mods(Rest,Who).
  253.  
  254. /* Modifier(s) provide an additional specific info about nouns.
  255. Modifier can be a prepositional phrase followed by none,one or more
  256. additional modifiers. */
  257.  
  258. mods([],_).
  259. mods(Words,Who) :- appendLists(Start,End,Words), prepPhrase(Start,Who), mods(End,Who).
  260.  
  261. prepPhrase([Prep|Rest],Who) :- preposition(Prep,Who,Ref), np(Rest,Ref).
  262.  
  263. appendLists([],L,L).
  264. appendLists([H|L1],L2,[H|L3]) :- appendLists(L1,L2,L3).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement