Advertisement
Guest User

Untitled

a guest
May 29th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 2.57 KB | None | 0 0
  1. /* MicroWatson 2015 */
  2.  
  3. 'Some nigga':-
  4.     write('232').
  5.  
  6.  
  7. micro_watson:-
  8.     write('1. Novels/Films of the 20th Century'),nl,
  9.     write('2. Novels of the 19th Century'),nl,
  10.     write('3. Novels of the 18th Century'),nl,
  11.     write('Please enter a category number!'),nl,
  12.     read(Category),
  13.         (Category == 1 -> micro_watson2; write('Goodbye')).
  14.  
  15. micro_watson2:-
  16.     write('Please give me an answer.'),nl,
  17.     write('micro_watson: '),
  18.         read(Sentence),
  19.     sentence(Sentence,Output),
  20.     write(Output),
  21.         parse(Sentence,_,TargetList),
  22.         write(TargetList).
  23.  
  24. sentence(Sentence,sentence(np(Noun_Phrase),vp(Verb_Phrase))):-
  25.     /* so take a sentence (first arg) and parse it into a noun phrase and a verb phase */
  26.     np(Sentence,Noun_Phrase,Rem),
  27.     write(Noun_Phrase),nl,
  28.     vp(Rem,Verb_Phrase),
  29.     write(Verb_Phrase),nl.
  30.  
  31. /* NP -> Det NP2 */
  32. np([X|T],np(det(X),NP2),Rem):-
  33.     det(X),
  34.     np2(T,NP2,Rem).
  35.  
  36. /* NP -> NP2 */
  37. np(Sentence,Parse,Rem):- np2(Sentence,Parse,Rem).
  38.  
  39. /* NP -> NP PP */
  40. np(Sentence,np(NP,PP),Rem):-
  41.     np(Sentence,NP,Rem1),
  42.     pp(Rem1,PP,Rem).
  43.  
  44. /* NP2 -> Noun */
  45. np2([H|T],np2(noun(H)),T):- noun(H).
  46.  
  47. /* NP2 -> Adj NP2 */
  48. np2([H|T],np2(adj(H),Rest),Rem):- adj(H),np2(T,Rest,Rem).
  49.  
  50. /* PP -> Prep NP */
  51. pp([H|T],pp(prep(H),Parse),Rem):-
  52.     prep(H),
  53.     np(T,Parse,Rem).
  54.  
  55. /* VP -> Verb */
  56. vp([H|[]],verb(H)):-verb(H).
  57.  
  58. /* VP -> Verb Adverb NP */
  59. vp([H|[T|Rest]],vp(verb(H),adverb(T),RestParsed)):-
  60.     verb(H),adverb(T),
  61.     np(Rest,RestParsed,_).
  62.  
  63. /* Vp -> Verb Adverb */
  64. vp([H|[T]],verb(H)):-adverb(T).
  65.  
  66. /* Vp -> Verb NP */
  67. vp([H|Rest],vp(verb(H),RestParsed)):-
  68.     verb(H),
  69.     pp(Rest,RestParsed,_).
  70.  
  71. /* Vp -> Verb PP */
  72. vp([H|Rest],vp(verb(H),RestParsed)):-
  73.     verb(H),
  74.     np(Rest,RestParsed,_).
  75.  
  76. /* extracting SOV */
  77. parse(Sentence,VP_List,TargetList):-
  78.     parse_SOV(Sentence,VP_List,TargetList).
  79.  
  80. parse_SOV(Sentence,VP_List,TargetList):-
  81.     /* Grab the first noun from the sentence and assume it is the subject */
  82.     member(Subject,Sentence),
  83.     noun(Subject),
  84.     /* Grab the first noun from the verb phrase and assume it is the object */
  85.     member(Object,VP_List),
  86.     noun(Object),
  87.     /* Grab the verb from the verb phrase */
  88.     member(Verb,VP_List),
  89.     verb(Verb),
  90.     nl,
  91.     TargetList = parse_sov(subject(Subject),object(Object),verb(Verb)).
  92.  
  93.  
  94. /* dictionary */
  95. det(a).
  96. det(the).
  97. adj(young).
  98. adj(middle_aged).
  99. adj(magic).
  100. adj(faithful).
  101. adj(paranoid).
  102. prep(on).
  103. prep(by).
  104. verb(finds).
  105. verb(destroys).
  106. verb(saves).
  107. verb(is).
  108. noun(expelled).
  109. noun(hobbit).
  110. noun(ring).
  111. noun(valet).
  112. noun(butler).
  113. noun(robot).
  114. noun(day).
  115. noun(holden).
  116. noun(marvin).
  117. adverb(quietly).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement