You are on page 1of 10

Prolog

Prolog

Prolog is a general purpose logic programming


language associated with artificial intelligence and
computational linguistics.

The language was first conceived by a group around


Alain Colmerauer in Marseille, France, in the early
1970s and the first Prolog system was developed in
1972 by Colmerauer with Philippe Roussel.

Work Done

Make

and Break functions.

Sentence

Translation.

Sentence Translation
Main

function takes as input a sentence


in english and translates it into
order(order of parts of speech) of Indian
languages.

Basic

approach is to first drop the


articles and then reorder the remaining
sentence into Indian order of parts of
speech.

Code
convert([H|T], L) :- drp_art([H|T], [H1|T1]), check(H1, T1, L).
convert([], []).
drp_art([], []).
drp_art([[H, a]|T], L) :- drp_art(T, L), !.
drp_art([[H, X]|T], [[H, X]|L]) :- drp_art(T, L).
check([H, a], T, L) :- convert(T, L), !.
check([H, n], T, [H|L1]) :- convert(T, L1), !.
check([H, v], T, L) :- convert(T, L1), append(L1, [H], L), !.
check([H, p], [[H1, _]|T1], L) :- convert(T1, L1), append([H1], [H], L2),
append(L2, L1, L), !.
check([H, _], T, [H|L1]) :- convert(T, L1).

Code Explained

Convert function is called first which calls function drp_art


which drops all the articles and passes the remaining
sentence to the check function.

Check function appends the parts of speech so that they


appear in Indian language order.

Used basic differences between the two languages to change


the order.

Nouns should appear first.


Verbs should appear at last.
Prepositions should swap its position with word immediately
after it.

Sample Runs

convert([[the, a], [doctor, n], [went, v], [to, p], [USA, n]], L).
L = [doctor, USA, to, went].

convert([[children, n], [play, v], [outside, n]], L).


L = [children, outside, play].

convert([[MI, n], [is, v], [the, a], [best, ad], [team, n], [in, p],
[the, a], [Ipl, n]], L)
L = [MI, best, team, Ipl, in, is].

Limitations

If there are more than one nouns, the code


doesnt take into the consideration the ordering
of the nouns as in testcase-3. The proper
ordering should be L = [MI, Ipl, in, best, team, is]
and code gives output L = [MI, best, team, Ipl,
in, is].

Also the code doesnt take into consideration all


the parts of speech and concentrates only on
four(noun, article, verb and preposition).

Make and Break functions

Implemented and studied functions in makeand-break.pl to understand various aspects of


prolog.

Studied cut operator to write facts which require


applying not operator on head of the fact.

Cut Operator
Cut

operator basically runs the code only in forward


direction from the point at which it is used and
doesnt backtrack to find out other possibilities.

Example:No

mountain climber likes rain


mc(X):-like(X, rain),!,fail.
mc(X).

Not

operator cannot be applied on the head to


represent no mountaineer.

You might also like