I have created a sentence parser in prolog. It successfully parses sentences that are inputted with...
?- sentence([input,sentence,here],Parse).
This is the code I'm using to parse the sentence:
np([X|T],np(det(X),NP2),Rem):- /* Det NP2 */
det(X),
np2(T,NP2,Rem).
np(Sentence,Parse,Rem):- np2(Sentence,Parse,Rem). /* NP2 */
np(Sentence,np(NP,PP),Rem):- /* NP PP */
np(Sentence,NP,Rem1),
pp(Rem1,PP,Rem).
np2([H|T],np2(noun(H)),T):- noun(H). /* Noun */
np2([H|T],np2(adj(H),Rest),Rem):- adj(H),np2(T,Rest,Rem).
pp([H|T],pp(prep(H),Parse),Rem):- /* PP NP */
prep(H),
np(T,Parse,Rem).
vp([H| []], vp(verb(H))):- /* Verb */
verb(H).
vp([H|T], vp(verb(H), Rem)):- /* VP PP */
vp(H, Rem),
pp(T, Rem, _).
vp([H|T], vp(verb(H), Rem)):- /* Verb NP */
verb(H),
np(T, Rem, _).
I should mention that the output would be: sentence(np(det(a), np2(adj(very), np2(adj(young), np2(noun(boy))))), vp(verb(loves), np(det(a), np2(adj(manual), np2(noun(problem)))))).
Using the predefined vocabulary: det(a), adj(very), adj(young), noun(boy), verb(loves), det(a), adj(manual), noun(problem)
.
What I want to do is pass the parsed output to predicates that would separate the words into three different categories, which are "subject, verb, and object".
(1) The subject will hold the first two adjectives and then a noun.
(2) The verb will hold the verb from the "verb phrase".
(3) And the object will hold the adjectives and nouns in the "verb phrase".
All determiners should be ignored.
For example, I would want a predicate that would look for adjectives in the output.
I have tried many things to try and get this working but none work. Any help will be much appreciated.