Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I need some help on PROLOG! can anyone help me please? this is to review

ID: 3556785 • Letter: H

Question

Hello, I need some help on PROLOG!
can anyone help me please? this is to review for my final exam tomorrow !!

One of the things that Prolog is used to do is Natural Language Processing. In this exercise, you will write a small Prolog program that is able to determine that is able to determine whether some sentences are proper sentences according to a small grammar. The above lexicon is for the flight domain a different one. The grammar is obviously a a limited one-there are many things you cannot say - but it doesn't matter.

Explanation / Answer

s(Start, Remainder) :-
   np(Start, Intermediate),
   vp(Intermediate, Remainder).

   vp(Start, Remainder) :-
   verb_group(Start, Intermediate),
   np(Intermediate, Remainder).

   vp(Start, Remainder) :-
   verb(Start, Intermediate),
   np(Intermediate, Remainder).

   verb_group(Start, Remainder) :-
   aux(Start, Intermediate),
   verb(Intermediate, Remainder).

   np(Start, Remainder) :-
   pronoun(Start, Remainder).

   np(Start, Remainder) :-
   noun(Start, Remainder).

   np(Start, Remainder) :-
   adj(Start, Intermediate),
   noun(Intermediate, Remainder).

   adj([flying|Rest], Rest).

   aux([are|Rest], Rest).

   noun([planes|Rest], Rest).

   pronoun([they|Rest], Rest).

   verb([are|Rest], Rest).
   verb([flying|Rest], Rest).

rewrite the whole grammar.
   s -->
   np,
   vp.

   vp -->
   verb_group,
   np.

   vp -->
   verb,
   np.

   verb_group -->
   aux,
   verb.

   np -->
   pronoun.

   np -->
   noun.

   np -->
   adj,
   noun.

   adj --> [flight].

   aux --> [want].

   noun --> [Morning].

   pronoun --> [I].

   verb --> [want].
   verb --> [flight].


pronoun(I)
We need to add an argument to each clause in represent the tree. This is how it is done for pre-terminals:
   adj(adj(flight)) --> [flight].

   aux(aux(want)) --> [want].

   noun(noun(Morning)) --> [Morning].

   pronoun(pronoun(I)) --> [I].

   verb(verb(want)) --> [want].
   verb(verb(flying)) --> [flying].
   np(pronoun(I))

   np(Pronoun)

   np(np(Pronoun)) -->
   pronoun(Pronoun).

   | ?- np(Tree, [I],[]).

   s(s(NP)) -->
   np(NP),
   vp(VP).

   vp(vp(VG, NP)) -->
   verb_group(VG),
   np(NP).

   vp(vp(Verb, NP)) -->
   verb(Verb),
   np(NP).

   verb_group(verb_group(Aux, Verb)) -->
   aux(Aux),
   verb(Verb).

   np(np(Noun)) -->
   noun(Noun).

   np(np(Adj, Noun)) -->
   adj(Adj),
   noun(Noun).

   | ?- s(Tree, [I,want,flight,Morning],[]).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote