/* PARSE_EL : analyseur dcg élémentaire  */

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

 

:- style_check(-singleton).

 

/* loading getsentence and pretty printer */

 

:- [fgetsen, prpr].

 

 

/* call : go. (enter stop. to stop) */

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

  go :-

     repeat,

     getsentence(Sentence,user),

     (Sentence \= [stop] -> true ; abort),

     parseit(Sentence,_,Parse).

   

/* parsing */

%%%%%%%%%%%%%

 

  parseit(Sentence,_,Parse):-

     parse(Sentence,_,Parse),

     nl,

     prpr(Parse,0),

     get_single_char(ZZZ),

     nl,nl,nl,

     fail.

 

 

/* la grammaire */

%%%%%%%%%%%%%%%%%%%

 

  parse(P0,[],[s,Np,Vp]) :-

     sentence(P0,[],[s,Np,Vp]) .

 

  sentence(P0,P2,[s,Np,Vp]) :-

     nounphrase(P0,P1,Np,Number) ,

     verbphrase(P1,P2,Vp, Number).

 

    

  nounphrase(P0,P2,[snp,Det,N],Number) :-

     determiner(P0,P1,Det,Number) ,

     noun(P1,P2,N,Number).

 

  nounphrase(P0,P3,[prepnp,Det,N,Prepphrase],Number) :-

     determiner(P0,P1,Det,Number) ,

     noun(P1,P2,N,Number),

     prepphrase(P2,P3,Prepphrase,Prep).

 

      

  prepphrase(P0, P2, [prepphrase, [prep(Prep)], Np],Prep):-

     prep(P0,P1,[prep(Prep)]),

     nounphrase(P1,P2,Np,Number).

 

 

  verbphrase(P0,P1,[vpi,Vintr],Number) :-

     verbintr(P0,P1,Vintr,Number).

 

  verbphrase(P0,P2,[vpt,Vtr,Np],Number) :-

     verbtr(P0,P1,Vtr,Number) ,

     nounphrase(P1,P2,Np,_).

 

  verbphrase(P0,P2,[vpi,Vintr,Prepphrase],Number) :-

     verbintr(P0,P1,Vintr,Number),

     prepphrase(P1,P2,Prepphrase,Prep).

 

  verbphrase(P0,P3,[vpt,Vtr,Np,Prepphrase],Number) :-

     verbtr(P0,P1,Vtr,Number) ,

     nounphrase(P1,P2,Np,_),

     prepphrase(P2,P3,Prepphrase,Prep) .

 

  verbphrase(P0,P2,[vpprep,Vprep,Prepphrase],Number):-

     vprep(P0,P1,Vprep,Number,Prep),

     prepphrase(P1,P2,Prepphrase,Prep).

 

 

 

/* le lexique */

%%%%%%%%%%%%%%%%

 

 

  verbintr([thinks|X],X,[vintr(thinks)],sing).

  verbintr([think|X],X,[vintr(think)],plural).

  verbintr([thought|X],X,[vintr(thought)],_).

 

  verbtr([buys|X],X,[vtr(buys)],sing).

  verbtr([buy|X],X,[vtr(buy)],plural).

  verbtr([bought|X],X,[vtr(bought)],_).

  verbtr([considers|X],X,[vtr(considers)],sing).

  verbtr([consider|X],X,[vtr(consider)],plural).

  verbtr([considered|X],X,[vtr(considered)],_).

  verbtr([likes|X],X,[vtr(likes)],sing).

  verbtr([like|X],X,[vtr(like)],plural).

  verbtr([liked|X],X,[vtr(liked)],_).

  verbtr([makes|X],X,[vtr(makes)],sing).

  verbtr([make|X],X,[vtr(make)],plural).

  verbtr([made|X],X,[vtr(made)],_).

  verbtr([reads|X],X,[vtr(reads)],sing).

  verbtr([read|X],X,[vtr(read)],plural).

  verbtr([read|X],X,[vtr(read)],_).

  verbtr([sees|X],X,[vtr(sees)],sing).

  verbtr([see|X],X,[vtr(see)],plural).

  verbtr([saw|X],X,[vtr(saw)],_).

  verbtr([sells|X],X,[vtr(sells)],sing).

  verbtr([sell|X],X,[vtr(sell)],plural).

  verbtr([sold|X],X,[vtr(sold)],_).

 

   

  vprep([depends|X],X,[vprep(depends)],sing,on).

  vprep([depend|X],X,[vprep(depend)],plural,on).

  vprep([depended|X],X,[vprep(depended)],_,on).

  vprep([believes|X],X,[vprep(believes)],sing,in). 

  vprep([believed|X],X,[vprep(believed)],_,in). 

  vprep([believe|X],X,[vprep(believe)],plural,in). 

 

  determiner([a|X],X,[det(a)], sing).

  determiner([the|X],X,[det(the)],_).

  determiner([an|X],X,[det(an)],sing).

  determiner(X,X,[det(zero)],_).

  determiner([some|X],X,[det(some)],_).

  determiner([any|X],X,[det(any)],_).

 

  noun([book|X],X,[n(book)],sing).

  noun([books|X],X,[n(books)],plural).

  noun([claim|X],X,[n(claim)],sing).

  noun([claims|X],X,[n(claims)],plural).

  noun([computer|X],X,[n(computer)],sing).

  noun([computers|X],X,[n(computers)],plural).

  noun([man|X],X,[n(man)],sing).

  noun([men|X],X,[n(men)],plural).

  noun([woman|X],X,[n(woman)],sing).

  noun([women|X],X,[n(women)],plural).

              

                             

  prep([on|X],X,[prep(on)]).

  prep([in|X],X,[prep(in)]).

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%