next up previous contents
Next: Grammaire catégorielle généralisé de Up: Application : Grammaires catégorielles Previous: Grammaire catégorielle de base

Sources de la grammaire de base

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

/*****************************************************************************/
/*                                                                           */
/* Analyse de phrases : utilisation de la grammaire catégorielle             */
/*                                                                           */
/*****************************************************************************/

:-use_module(parser).

/*****************************************************************************/
/*                                                                           */
/* Définition des catégories                                                 */
/*                                                                           */
/*****************************************************************************/

:-op(400,yfx,'/').
:-op(400,yfx,'\').

categorie(phrase,s).
categorie(verbe_intransitif,iv).
categorie(nom_commun,cn).
categorie(article,(s/iv)/cn).
categorie(nom_propre,(s/iv)).
categorie(pronom_personnel,(s/iv)).
categorie(verbe_transitif,iv/(s/iv)).
categorie(adjectif,cn/cn).
categorie(adjectif,cn\cn).
categorie(verbe_d_etat,iv/(cn/cn)).
categorie(verbe_d_etat,iv/(cn\cn)).
categorie(pronom_relatif_qui,(((s/iv)\(s/iv))/iv)).
categorie(de_complement_de_nom,((cn\cn)/(s/iv))).
categorie(de_complement_de_nom,((cn\cn)/cn)).
categorie(adverbe,(X/X)):-accepte_adverbe(X).
categorie(adverbe,(X\X)):-accepte_adverbe(X).
categorie(preposition_circonstancielle,(s/s)/(s/iv)).
categorie(preposition_circonstancielle,(s\s)/(s/iv)).
categorie(conjonction_de_coordination,((X/X)\X)).

accepte_adverbe(s).
accepte_adverbe(iv).
accepte_adverbe((iv/(s/iv))).
accepte_adverbe((X/X)).
accepte_adverbe((X\X)).

/*****************************************************************************/
/*                                                                           */
/*  Associations mots/catégories                                             */
/*                                                                           */
/*****************************************************************************/

mot(le,article).
mot(chat,nom_commun).
mot(dort,verbe_intransitif).
mot(souris,nom_commun).
mot(regarde,verbe_transitif).
mot(mange,verbe_transitif).
mot(la,article).
mot(une,article).
mot(qui,pronom_relatif_qui).
mot(du,article).
mot(fromage,nom_commun).
mot(christophe,nom_propre).
mot(vite,adverbe).
mot(tres,adverbe).
mot(blanche,adjectif).
mot(grise,adjectif).
mot(gris,adjectif).
mot(il,pronom_personnel).
mot(court,verbe_intransitif).
mot(dans,preposition_circonstancielle).
mot(jardin,nom_commun).
mot(petit,adjectif).
mot(petite,adjectif).
mot(et,conjonction_de_coordination).
mot(parle,verbe_intransitif).
mot(bien,adverbe).
mot(quant,preposition_circonstancielle).
mot(soleil,nom_commun).
mot(brille,verbe_intransitif).
mot(fait,verbe_transitif).
mot(fait,verbe_d_etat).
mot(est,verbe_d_etat).
mot(beau,adjectif).
mot(mon,article).
mot(oncle,nom_commun).
mot(de,de_complement_de_nom).
mot(ma,article).
mot(tante,nom_commun).

lex(lex(MOT,CAT,[]))-->[MOT],{mot(MOT,T),categorie(T,CAT)}.

/*****************************************************************************/
/*                                                                           */
/*  Etapes de calcul                                                         */
/*                                                                           */
/*****************************************************************************/

afficher_calculs([A,B,CA,CB,CAB|S]):-
    !,
    writef("%t . %t : %t . %t => %t\n",[A,B,CA,CB,CAB]),
    afficher_calculs(S).
afficher_calculs([]).

/*****************************************************************************/
/*                                                                           */
/*  Grammaire catégorielle (version de base)                                 */
/*                                                                           */
/*****************************************************************************/

/*****************************************************************************/
/*                                                                           */
/* Réduction d'une liste de catégories : (x/y).y=x et y.(x\y)=x              */
/*                                                                           */
/*****************************************************************************/

lex([A,B],X,CAB):=lex(A,X/Y,CA),lex(B,Y,CB),
    {append(CA,CB,TMP), append(TMP,[A,B,X/Y,Y,X],CAB)}.
lex([A,B],X,CAB):=lex(A,Y,CA),lex(B,X\Y,CB),
    {append(CA,CB,TMP), append(TMP,[A,B,Y,X\Y,X],CAB)}.

/*****************************************************************************/
/*                                                                           */
/*  Analyse d'une phrase                                                     */
/*                                                                           */
/*****************************************************************************/

analyser(PH):-
    parse(lex(_,s,CALC),PH),
    afficher_calculs(CALC).

test:-
    analyser([la,souris,mange,tres,vite,du,fromage]).



Christophe Delord
1998-09-02