title: prolog natural language parsing
body: <p>i have a college assignment to make a prolog program parse natural language, ie it should output </p>
  
  <pre><code>P = np(det(the), np2(noun(cat))), vp(verb(sat), pp(prep(on), np(det(the), np2(noun(mat)))))
  L = []
  </code></pre>
  
  <p>when i input np([the, cat, sat, on, the, mat],P,L).</p>
  
  <p>instead, the verb and noun phrases are being split and coming out seperatly, like:</p>
  
  <pre><code>P = np(det(the), np2(noun(cat))),
  L = [sat, on, the, mat]
  </code></pre>
  
  <p>i was wondering if anyone could point out where i am going wrong, it would be most appreciated, my code is:</p>
  
  <pre><code>sentence(Sentence,sentence(np(Noun_Phrase)), (vp(Verb_Phrase))):-
  /* so take a sentence (first arg) and parse it into a noun phrase and a verb phase */
      np(Sentence,Noun_Phrase, Rem),
      vp(Rem, Verb_Phrase).
  
  np([X|T],np(det(X),NP2),Rem):-
      det(X),
      np2(T,NP2,Rem).
  np(Sentence,Parse,Rem):- np2(Sentence,Parse,Rem).
  np(Sentence,np(NP,PP),Rem):-
      np(Sentence,NP,Rem1),
      pp(Rem1,PP,Rem).
  
  np2([H|T],np2(noun(H)),T):- noun(H).  
  np2([H|T],np2(adj(H),Rest),Rem):- adj(H),np2(T,Rest,Rem).  
  pp([H|T],pp(prep(H),Parse),Rem):-
      prep(H),
      np(T,Parse,Rem).
  
  vp([H|[]],vp(verb(H))):- verb(H).
  vp([H|Rest],vp(verb(H),RestParsed),Rem):- verb(H), pp(Rest, RestParsed, Rem).
  vp([H|Rest],vp(verb(H),RestParsed),Rem):- verb(H), np(Rest, RestParsed, Rem).
  
  det(the).
  det(with).
  noun(cat).
  noun(mat).
  noun(mouse).
  noun(rabbit).
  noun(moon).
  verb(sat).
  verb(ate).
  verb(ran_away).
  prep(on).
  adj(big).
  adj(fat).
  adj(comfy).
  adj(yellow).
  adj(silvery).
  adj(orange).
  </code></pre>