I am presently in the midst of producing a sentence parser/expert system hybrid in Prolog that should ideally parse a sentence into three different lists, which then matches it with a specific recommendation determined via the content of those three lists.
Currently, this is how my parser looks:
sentence(Sentence, sentence(np(Noun_Phrase), vp(Verb_Phrase))):-
np(Sentence, Noun_Phrase, Rem),
vp(Rem, Verb_Phrase, []), !.
np([X|Sentence], np(det(X), NP2), Rem):-
det(X),
np2(Sentence, NP2, Rem).
np(Sentence, Noun_Phrase, Rem):-
np2(Sentence, Noun_Phrase, Rem).
np(Sentence,np(Noun_Phrase, Prep_Phrase), Rem):-
%append(X, Y, Sentence),
pp(Sentence, Prep_Phrase, Rem),
np(Rem, Noun_Phrase, []).
np2([X|Rem], np2(noun(X)), Rem):-
noun(X).
np2([X|Sentence], np2(adj(X), Noun_Phrase), Rem):-
adj(X),
np2(Sentence, Noun_Phrase, Rem).
pp([X|Sentence], pp(prep(X), Noun_Phrase), Rem):-
prep(X),
np(Sentence, Noun_Phrase, Rem).
vp([X|Sentence], vp(verb(X), Prep_Phrase), Rem) :-
verb(X),
pp(Sentence, Prep_Phrase, Rem).
vp([X|Sentence], vp(verb(X), Noun_Phrase), Rem) :-
verb(X),
np(Sentence, Noun_Phrase, Rem).
vp([X|Rem], vp(verb(X)), Rem) :-
verb(X).
It is not ideal as it uses a cut to circumvent an earlier problem that went relatively undiagnosed, but the parser as a whole does it's job relatively well. I understand that not all sentences can be parsed in this manner, but for the examples given, this is what was recommended. As can be observed from what has been presented above, there are 5 types of words; adjectives, determiners, nouns, prepositions and verbs.
To obtain a sentence parse, this is the way that the input must be structured:
sentence([a,very,young,boy,loves,a,manual,problem], S).However, following this parse what must be done afterwards is to turn it into a minimalist expert system of sorts, where it analyzes each word in a sentence structure and determines a specific outcome. This is where I am stuck and despite the best attempts from peers, have not been able to figure out a viable solution. Previously I used sublists which worked, but was then informed that I should not achieve the goal in this manner and so this idea was scrapped. The example given to us in the project brief was as follows:
present(construction_kit, subject(very,young,boy), verb(loves), object(manual,problem)).
present(golfing_sweater, subject(young,father), verb(loves), object(golf).In simplest terms, following the parse what should then be done is to have the sentence analyzed and a present from a set list/database assigned to it depending on the words used in a given statement. This is the point that I have been unable to progress from.