PROLOG

Portuguese Language Parser

by Alejandro J. C De Baca


% Alejandro J. C De Baca
% Dec 3, 2002
% Natural Language Parsing in Portuguese with PROLOG
%
% This parser/generator extends the English version from [Luger, 2002]
%  with the following features:
%  - Portugues words (obviously)
%  - Subject-Verb agreement (Number/Person)
%  - Article-Noun agreement (Number/Gender)
%  - Adjective-Noun agreement (Number/Gender)
%  - Semantic Constraints regarding subjects and objects of each verb
%
utterance(X, SentenceGraph) :-
 sentence(X, [], SentenceGraph).

sentence(Start, End, SentenceGraph) :-
 nounphrase(Start, Rest, Number, Person, SubjectGraph),
 verbphrase(Rest, End, Number, Person, PredicateGraph, SubjectGraph),
 join([agent(SubjectGraph)], PredicateGraph, SentenceGraph).

sentence(Start, End, SentenceGraph) :-
 verbphrase(Start, End, _, _, SentenceGraph, _).

nounphrase([Noun|End], End, Number, third, NounPhraseGraph) :- 
 noun(Noun, Number, _, NounPhraseGraph).

nounphrase([Article, Noun|End], End, Number, third, NounPhraseGraph) :- 
 article(Article, Number, Gender),
 noun(Noun, Number, Gender, NounPhraseGraph). 

nounphrase([Adjective, Noun|End], End, Number, third, NounPhraseGraph) :-
 adjective(Adjective, Number, Gender),
 noun(Noun, Number, Gender, NounPhraseGraph).

nounphrase([Noun, Adjective|End], End, Number, third, NounPhraseGraph) :-
 noun(Noun, Number, Gender, NounPhraseGraph),
 adjective(Adjective, Number, Gender).

nounphrase([Article, Noun, Adjective|End], End, Number, third, 
           NounPhraseGraph) :-
 article(Article, Number, Gender),
 noun(Noun, Number, Gender, NounPhraseGraph),
 adjective(Adjective, Number, Gender).

nounphrase([Article, Adjective, Noun|End], End, Number, third,
           NounPhraseGraph) :-
 article(Article, Number, Gender),
 adjective(Adjective, Number, Gender),
 noun(Noun, Number, Gender, NounPhraseGraph).

nounphrase([SubjPron|End], End, Number, Person, NounPhraseGraph) :-
 subjectPronoun(SubjPron, Number, Person, NounPhraseGraph).

verbphrase([Verb|End], End, Number, Person, VerbPhraseGraph, _) :-
 verb(Verb, Number, Person, VerbPhraseGraph).

verbphrase([Verb|Rest], End, Number, Person, VerbPhraseGraph, _) :-
 verb(Verb, Number, Person, VerbGraph),
 nounphrase(Rest, End, _,  _, NounPhraseGraph),
 join([object(NounPhraseGraph)], VerbGraph, VerbPhraseGraph).

verbphrase([DirObjPron, Verb|End], End, Number, Person, 
           VerbPhraseGraph, _) :-
 directObjectPronoun(DirObjPron, _, _, ObjectGraph),
 verb(Verb, Number, Person, VerbGraph),
 join([object(ObjectGraph)], VerbGraph, VerbPhraseGraph).

verbphrase([RefObjPron, Verb|End], End, Number, Person, VerbPhraseGraph,
           SubjectGraph) :-
 reflexiveObjectPronoun(RefObjPron, Number, Person),
 verb(Verb, Number, Person, VerbGraph),
 join([object(SubjectGraph)], VerbGraph, VerbPhraseGraph).

verbphrase([IndirObjPron, Verb|End], End, Number, Person, 
           VerbPhraseGraph, _) :-
 indirectObjectPronoun(IndirObjPron, _, _),
 verb(Verb, Number, Person, VerbPhraseGraph).

verbphrase([IndirObjPron, Verb|Rest], End, Number, Person, 
           VerbPhraseGraph, _) :-
 indirectObjectPronoun(IndirObjPron, _, _),
 verb(Verb, Number, Person, VerbGraph),
 nounphrase(Rest, End, _,  _, NounPhraseGraph),
 join([object(NounPhraseGraph)], VerbGraph, VerbPhraseGraph). 

join(X, X, X).
join(A, B, C) :-
 isframe(A), isframe(B), !,
 joinFrames(A, B, C, not_joined).

join(A, B, C) :-
 isframe(A), is_slot(B), !,
 joinSlotToFrame(B, A, C).

join(A, B, C) :-
 isframe(B), is_slot(A), !,
 joinSlotToFrame(A, B, C).

join(A, B, C) :-
 is_slot(A), is_slot(B), !,
 join_slots(A, B, C).

joinFrames([A | B], C, D, OK) :-
 joinSlotToFrame(A, C, E), !,
 joinFrames(B, E, D, ok).

joinFrames([A | B], C, [A | D], OK) :-
 joinFrames(B, C, D, OK), !.

joinFrames([], A, A, ok).

joinSlotToFrame(A, [B | C], [D | C]) :- joinSlots(A, B, D).

joinSlotToFrame(A, [B | C], [B | D]) :-
 joinSlotToFrame(A, C, D).

joinSlots(A, B, D) :-
 functor(A, FA, _), functor(B, FB, _),
 matchWithInheritance(FA, FB, FN),
 arg(1, A, Value_a), arg(1, B, Value_b),
 join(Value_a, Value_b, New_value),
 D=..[FN | [New_value]].

isframe([_|_]).
isframe([]).
is_slot(A) :- functor(A, _, 1).

matchWithInheritance(X, X, X).
matchWithInheritance(human, animate, human).
matchWithInheritance(animate, human, human).

matchWithInheritance(pet, animate, pet).
matchWithInheritance(animate, pet, pet).
matchWithInheritance(pet, inhuman, pet).
matchWithInheritance(inhuman, pet, pet).

matchWithInheritance(thing, inanimate, thing).
matchWithInheritance(inanimate, thing, thing).
matchWithInheritance(thing, inhuman, thing).
matchWithInheritance(inhuman, thing, thing).

matchWithInheritance(food, inanimate, food).
matchWithInheritance(inanimate, food, food).
matchWithInheritance(food, inhuman, food).
matchWithInheritance(inhuman, food, food).

matchWithInheritance(wildcard, animate, animate).
matchWithInheritance(animate, wildcard, animate).
matchWithInheritance(wildcard, inhuman, inhuman).
matchWithInheritance(inhuman, wildcard, inhuman).
matchWithInheritance(wildcard, human, human).
matchWithInheritance(human, wildcard, human).

article(o, singular, masculine).
article(os, plural, masculine).
article(a, singular, feminine).
article(as, plural, feminine).

article(um, singular, masculine).
article(uns, plural, masculine).
article(uma, singular, feminine).
article(umas, plural, feminine).

noun(homem, singular, masculine, [human(homem)]).
noun(homens, plural, masculine, [human(homens)]).
noun(mulher, singular, feminine, [human(mulher)]).
noun(mulheres, plural, feminine, [human(mulheres)]).
noun(cachorro, singular, masculine, [pet(cachorro)]).
noun(cachorros, plural, masculine, [pet(cachorros)]).
noun(carro, singular, masculine, [thing(carro)]).
noun(carros, plural, masculine, [thing(carros)]).
noun(maca, singular, feminine, [food(maca)]).
noun(macoes, plural, feminine, [food(macoes)]).

subjectPronoun(eu, singular, first, [human(eu)]).
subjectPronoun(tu, singular, second, [human(tu)]).
subjectPronoun(nos, plural, first, [human(nos)]).
subjectPronoun(vos, plural, second, [human(vos)]).
subjectPronoun(ele, singular, third, [wildcard(ele)]).
subjectPronoun(ela, plural, third, [wildcard(ela)]).
subjectPronoun(eles, singular, third, [wildcard(eles)]).
subjectPronoun(elas, plural, third, [wildcard(elas)]).

verb(pago, singular, first, 
     [action([pagar(X)]), agent([human(eu)]), object([human(Y)])]).
verb(pagamos, plural, first,
     [action([pagar(X)]), agent([human(nos)]), object([human(Y)])]).
verb(pagas, singular, second,
     [action([pagar(X)]), agent([human(tu)]), object([human(Y)])]).
verb(pagais, plural, second,
     [action([pagar(X)]), agent([human(vos)]), object([human(Y)])]).
verb(paga, singular, third,
     [action([pagar(X)]), agent([human(X)]), object([human(Y)])]).
verb(pagam, plural, third,
     [action([pagar(X)]), agent([human(X)]), object([human(Y)])]).

verb(vendo, singular, first,
     [action([vender(X)]), agent([human(eu)]), object([inhuman(Y)])]).
verb(vendemos, plural, first,
     [action([vender(X)]), agent([human(nos)]), object([inhuman(Y)])]).
verb(vendes, singular, second,
     [action([vender(X)]), agent([human(te)]), object([inhuman(Y)])]).
verb(vendeis, plural, second,
     [action([vender(X)]), agent([human(vos)]), object([inhuman(Y)])]).
verb(vende, singular, third,
     [action([vender(X)]), agent([human(X)]), object([inhuman(Y)])]).
verb(vendem, plural, third,
     [action([vender(X)]), agent([human(X)]), object([inhuman(Y)])]).

verb(mordo, singular, first,
     [action([morder(X)]), agent([human(eu)]), object([food(Y)])]).
verb(mordemos, plural, first,
     [action([morder(X)]), agent([human(nos)]), object([food(Y)])]).
verb(mordes, singular, second,
     [action([morder(X)]), agent([human(te)]), object([food(Y)])]).
verb(mordeis, plural, second,
     [action([morder(X)]), agent([human(vos)]), object([food(Y)])]).
verb(morde, singular, third,
     [action([morder(X)]), agent([human(X)]), object([food(Y)])]).
verb(mordem, plural, third,
     [action([morder(X)]), agent([human(X)]), object([food(Y)])]).
verb(morde, singular, third,
     [action([morder(X)]), agent([pet(X)]), object([animate(Y)])]).
verb(mordem, plural, third,
     [action([morder(X)]), agent([pet(X)]), object([animate(Y)])]).

verb(falo, singular, first,
     [action([falar(X)]), agent([human(eu)]), object([])]).
verb(falamos, plural, first,
     [action([falar(X)]), agent([human(nos)]), object([])]).
verb(falas, singular, second,
     [action([falar(X)]), agent([human(te)]), object([])]).
verb(falais, plural, second,
     [action([falar(X)]), agent([human(vos)]), object([])]).
verb(fala, singular, third,
     [action([falar(X)]), agent([human(X)]), object([])]).
verb(falam, plural, third,
     [action([falar(X)]), agent([human(X)]), object([])]).

verb(dou, singular, first,
     [action([dar(X)]), agent([animate(eu)]), object([inhuman(Y)])]).
verb(damos, plural, first,
     [action([dar(X)]), agent([animate(nos)]), object([inhuman(Y)])]).
verb(das, singular, second,
     [action([dar(X)]), agent([animate(te)]), object([inhuman(Y)])]).
verb(dais, plural, second,
     [action([dar(X)]), agent([animate(vos)]), object([inhuman(Y)])]).
verb(da, singular, third,
     [action([dar(X)]), agent([animate(X)]), object([inhuman(Y)])]).
verb(dao, plural, third,
     [action([dar(X)]), agent([animate(X)]), object([inhuman(Y)])]).

verb(levanto, singular, first,
     [action([levantar(X)]), agent([animate(eu)]), object([wildcard(Y)])]).
verb(levantamos, plural, first,
     [action([levantar(X)]), agent([animate(nos)]), object([wildcard(Y)])]).
verb(levantas, singular, second,
     [action([levantar(X)]), agent([animate(te)]), object([wildcard(Y)])]).
verb(levantais, plural, second,
     [action([levantar(X)]), agent([animate(vos)]), object([wildcard(Y)])]).
verb(levanta, singular, third,
     [action([levantar(X)]), agent([animate(X)]), object([wildcard(Y)])]).
verb(levantam, plural, third,
     [action([levantar(X)]), agent([animate(X)]), object([wildcard(Y)])]).

directObjectPronoun(me, singular, first, [human(me)]).
directObjectPronoun(nos, plural, first, [human(nos)]).
directObjectPronoun(te, singular, second, [human(te)]).
directObjectPronoun(vos, plural, second, [human(vos)]).
directObjectPronoun(o, singular, third, [animate(o)]).
directObjectPronoun(o, singular, third, [inanimate(o)]).
directObjectPronoun(os, plural, third, [animate(os)]).
directObjectPronoun(os, plural, third, [inanimate(os)]).
directObjectPronoun(a, singular, third, [animate(a)]).
directObjectPronoun(a, singular, third, [inanimate(a)]).
directObjectPronoun(as, plural, third, [animate(as)]).
directObjectPronoun(as, plural, third, [inanimate(as)]).

indirectObjectPronoun(me, singular, first).
indirectObjectPronoun(nos, plural, first).
indirectObjectPronoun(te, singular, second).
indirectObjectPronoun(vos, plural, second).
indirectObjectPronoun(lhe, singular, third).
indirectObjectPronoun(lhes, plural, third).

reflexiveObjectPronoun(me, singular, first).
reflexiveObjectPronoun(nos, plural, first).
reflexiveObjectPronoun(te, singular, second).
reflexiveObjectPronoun(vos, plural, second).
reflexiveObjectPronoun(se, singular, third).
reflexiveObjectPronoun(se, plural, third).

adjective(amigavel, singular, masculine).
adjective(amigaveis, plural, masculine).
adjective(amigavel, singular, feminine).
adjective(amigaveis, plural, feminine).

adjective(bonito, singular, masculine).
adjective(bonita, singular, feminine).
adjective(bonitos, plural, masculine).
adjective(bonitas, plural, feminine).

adjective(feio, singular, masculine).
adjective(feios, plural, masculine).
adjective(feia, singular, feminine).
adjective(feias, plural, feminine).

adjective(este, singular, masculine).
adjective(estes, plural, masculine).
adjective(esta, singular, feminine).
adjective(estas, plural, feminine).

adjective(esse, singular, masculine).
adjective(esses, plural, masculine).
adjective(essa, singular, feminine).
adjective(essas, plural, feminine).

adjective(grande, singular, masculine).
adjective(grande, plural, masculine).
adjective(grandes, singular, feminine).
adjective(grandes, plural, feminine).

adjective(pequeno, singular, masculine).
adjective(pequenos, plural, masculine).
adjective(pequena, singular, feminine).
adjective(pequenas, plural, feminine).

  

Close Window