next up previous contents
Next: Exemples d'analyses Up: Programme Previous: Gestion des frames et

Exemple de grammaire

/*****************************************************************************/
/*                                                                           */
/* Christophe DELORD                                                         */
/*                                                                           */
/* Stage 1997/98 : ENSEEIHT - Traitement du langage naturel                  */
/*                                                                           */
/*****************************************************************************/

:-use_module(lfg).

test:-
    parse([a,girl,handed,the,baby,the,toys]),
    parse([i,want,to,kiss,the,baby]),
    parse([which,baby,did,the,girl,kiss]),
    parse([which,baby,did,the,girl,want,to,kiss]),
    parse([i,promise,the,girl,to,kiss,the,baby]),
    parse([i,persuade,the,girl,to,kiss,the,baby]),
    parse([i,want,the,girl,to,promise,the,boy,to,kiss,the,baby]),
    parse([i,want,the,girl,to,persuade,the,boy,to,kiss,the,baby]),
    parse([the,boy,want,that,the,apple,falls]),
    parse([i,want,that,the,girl,kiss,the,baby]),
    parse([i,want,the,girl,to,kiss,the,baby]),
    parse([i,want,the,girl,to,promise,me,to,kiss,the,baby]),
    parse([which,girl,did,want,me,to,promise,the,boy,to,kiss,the,baby]),
    parse([which,boy,did,the,girl,want,me,to,promise,to,kiss,the,baby]),
    parse([which,baby,did,the,girl,want,me,to,promise,the,boy,to,kiss]),
    parse([which,girl,did,want,me,to,persuade,the,boy,to,kiss,the,baby]),
    parse([which,boy,did,the,girl,want,me,to,persuade,to,kiss,the,baby]),
    parse([which,baby,did,the,girl,want,me,to,persuade,the,boy,to,kiss]),
    parse([which,toys,did,the,girl,want,me,to,handle,the,baby]).

bug2:-
    parse([which,baby,did,promise,me,to,kiss,the,girl]).

bug3:-
    parse([which,baby,did,promise,me,to,persuade,me,to,kiss,the,girl]).

bug:-parse([which,baby,did,the,girl,want,to,kiss]).

test(FRAME):-
    pS(F,[which,baby,did,the,girl,want,to,kiss],[]),
    make_far_links(F,FRAME),
    afficher_frame(FRAME).

parse(S):-
    writef("%r\n\n",['-',70]),
    print(S), nl,
    pS(F,S,[]),
%   afficher_frame(F), nl,
    make_far_links(F,FRAME),
    afficher_frame(FRAME), nl.

pS(F) -->
    pNP(S),     { F:[subject]@=S },
    pVP(V),     { F@=V }.

pS(F) -->
    pNP(NP),    { F:[far_down]@=NP, NP:[qform]@='+' },
    aux,
    pNP(S),     { F:[subject]@=S },
    pVP(VP),    { F@=VP }.

pNP(F) -->
    determiner(DET),    { F@=DET },
    noun(NOUN),         { F@=NOUN }.

pNP(F) -->
    pronoun(P),         { F@=P }.

pNP(F) -->
    empty(NP),          { F:[far_up]@=NP }.

pVP(F) -->
    verb(V),            { F@=V, V:[format]@=(subject,-) }.

pVP(F) -->
    verb(V),        { F@=V, V:[format]@=(subject,-,object,object2) },
    pNP(O),         { F:[object]@=O },
    pNP(O2),        { F:[object2]@=O2 }.

pVP(F) -->
    verb(V),        { F@=V, V:[format]@=(subject,-,object) },
    pNP(O),         { F:[object]@=O }.

pVP(F) -->
    verb(V),        { F@=V, V:[format]@=(subject,-,vcomp) },
    pVP(VC),        { F:[vcomp]@=VC }.

pVP(F) -->
    verb(V),        { F@=V, V:[format]@=(subject,-,object,vcomp) },
    pNP(OBJ),       { F:[object]@=OBJ },
    pVP(VCOMP),     { F:[vcomp]@=VCOMP }.

pVP(F) -->
    particle(P),    { P:[ptrtype]@=to },
    pVP(VP),        { F@=VP }.

pVP(F) -->
    verb(V),        { F@=V, V:[format]@=(subject,_,relative) },
    that,
    pS(REL),        { F:[relative]@=REL }.

pVP(F) -->
    verb(V),        { F@=V, V:[format]@=(subject,_,object,vcomp) },
    pNP(OBJ),       { F:[object]@=OBJ },
    particle(P),    { P:[ptrtype]@=to },
    pVP(VP),        { F:[vcomp]@=VP }.

empty(_) --> [].

pronoun(F)-->
    [i],    {   F:[qform]@='-',
                F:[predicate]@=i
            }.

pronoun(F)-->
    [me],   {   F:[qform]@='-',
                F:[predicate]@=i
            }.

pronoun(F)-->
    [he],   {   F:[qform]@='-',
                F:[number]@=singular,
                F:[predicate]@=he
            }.

pronoun(F)-->
    [him],  {   F:[qform]@='-',
                F:[number]@=singular,
                F:[predicate]@=he
            }.

determiner(F)-->
    [a],    {   F:[qform]@='-',
                F:[number]@=singular,
                F:[definiteness]@=indefinite
            }.

determiner(F)-->
    [the],  {   F:[qform]@='-',
                F:[definiteness]@=definite
            }.

determiner(F)-->
    [which],    {   F:[qform]@='+'
                }.

noun(F)-->
    [girl], {   F:[number]@=singular,
                F:[predicate]@=girl
            }.

noun(F)-->
    [boy],  {   F:[number]@=singular,
                F:[predicate]@=boy
            }.

noun(F)-->
    [baby], {   F:[number]@=singular,
                F:[predicate]@=baby
            }.

noun(F)-->
    [toys], {   F:[number]@=plural,
                F:[predicate]@=toy
            }.

noun(F)-->
    [apple],    {   F:[number]@=singular,
                    F:[predicate]@=apple
                }.

verb(F)-->
    [handed],   {   F:[tense]@=past,
                    F:[predicate]@=hand(F:[subject,predicate],
                                F:[object,predicate],F:[object2,predicate]),
                    F:[format]@=(subject,-,object,object2)
                }.

verb(F)-->
    [handle],   {   F:[predicate]@=hand(F:[subject,predicate],
                                F:[object,predicate],F:[object2,predicate]),
                    F:[format]@=(subject,-,object,object2)
                }.

verb(F)-->
    [kiss],     {   F:[predicate]@=kiss(F:[subject,predicate],
                                F:[object,predicate]),
                    F:[format]@=(subject,-,object)
                }.

verb(F)-->
    [falls],    {   F:[predicate]@=fall(F:[subject,predicate]),
                    F:[format]@=(subject,-)
                }.

verb(F)-->
    [eats],     {   F:[predicate]@=eats(F:[subject,predicate],
                                F:[object,predicate]),
                    F:[format]@=(subject,-,object)
                }.

verb(F)-->
    [want],     {   F:[predicate]@=want(F:[subject,predicate],
                                F:[vcomp,predicate]),
                    F:[vcomp,subject]@=F:[subject],
                    F:[format]@=(subject,-,vcomp)
                }.

verb(F)-->
    [want],     {   F:[predicate]@=want(F:[subject,predicate],
                                F:[relative,predicate]),
                    F:[format]@=(subject,-,relative)
                }.

verb(F)-->
    [want],     {   F:[predicate]@=want(F:[subject,predicate],
                                F:[vcomp,predicate]),
                    F:[vcomp,subject]@=F:[object],
                    F:[format]@=(subject,-,object,vcomp)
                }.

verb(F)-->
    [persuade], {   F:[predicate]@=persuade(F:[subject,predicate],
                                F:[object,predicate],
                                F:[vcomp,predicate]),
                    F:[vcomp,subject]@=F:[object],
                    F:[format]@=(subject,-,object,vcomp)
                }.

verb(F)-->
    [promise],  {   F:[predicate]@=promise(F:[subject,predicate],
                                F:[object,predicate],
                                F:[vcomp,predicate]),
                    F:[vcomp,subject]@=F:[subject],
                    F:[format]@=(subject,-,object,vcomp)
                }.

particle(F)-->
    [to],       {   F:[ptrtype]@=to
                }.

aux-->
    [did].

that-->
    [that].



Christophe Delord
1998-09-02