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 !!
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],[]).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.