2:- module(ppDrs,[ppDrs/3]).    3
    4:- use_module(library(lists),[member/2,append/3,select/3]).    5
    6:- [titles].    7
    8:- use_module(string2digit,[string2digit/2]).    9
   10:- use_module(alphaConversionDRT,[alphaConvertDRS/2]).   11
   12
   13/*========================================================================
   14   Dynamic Predicates
   15========================================================================*/
   16
   17:- dynamic counter/1.   18
   19counter(0).
   20
   21
   22/*========================================================================
   23   Postprocessing XDRSs
   24========================================================================*/
   25
   26ppDrs(xdrs(W1,P,E,A1),Context,xdrs(W2,P,E,A3)):- !,
   27   ppWords(W1,0,W2,W3),
   28   numbervars(A1,0,Counter),
   29   retractall(counter(_)),
   30   assert(counter(Counter)),
   31   ppDrs(A1,P,E,W3,Context,drs([],[])-_,A2),
   32   alphaConvertDRS(A2,A3).
   33
   34
   35/*========================================================================
   36   Postprocessing DRSs
   37========================================================================*/
   38
   39ppDrs(merge(A1,A2),P,E,W,C,CD1-CD3,merge(A3,A4)):- !,
   40   ppDrs(A1,P,E,W,C,CD1-CD2,A3), 
   41   ppDrs(A2,P,E,W,C,CD2-CD3,A4).
   42
   43ppDrs(smerge(A1,A2),P,E,W,C,CD1-CD3,smerge(A3,A4)):- !,
   44   ppDrs(A1,P,E,W,C,CD1-CD2,A3), 
   45   ppDrs(A2,P,E,W,C,CD2-CD3,A4).
   46
   47ppDrs(alfa(Type,A1,A2),P,E,W,C,CD1-CD3,alfa(Type,A3,A4)):- !,
   48   ppDrs(A1,P,E,W,C,CD1-CD2,A3),
   49   ppDrs(A2,P,E,W,C,CD2-CD3,A4).
   50
   51ppDrs(B1,P,E,W,Context,CD1-CD2,B3):-
   52   checkDrs(B1,P,E,W,Context,CD1,B2),
   53   ppConds(B2,P,E,W,Context,CD1-CD2,B3).
   54
   55
   56/*========================================================================
   57   Postprocessing DRS-Conditions
   58========================================================================*/
   59
   60ppConds(drs([],[]),_,_,_,_,CD-CD,drs([],[])):- !.
   61
   62ppConds(drs([D|D1],C1),P,E,W,Context,drs(G,H)-CD,drs([D|D2],C2)):- !,
   63   ppConds(drs(D1,C1),P,E,W,Context,drs([D|G],H)-CD,drs(D2,C2)).
   64
   65ppConds(drs([],C1),P,E,W,Context,drs(G,H)-CD,drs(D3,[Cond|C3])):- 
   66   member(Cond,[_:card(_,_,_),_:pred(_,_,_,_),_:rel(_,_,_,_),_:named(_,_,_,_),_:timex(_,_),_:eq(_,_)]),
   67   select(Cond,C1,C2), !,
   68   ppConds(drs([],C2),P,E,W,Context,drs(G,[Cond|H])-CD,drs(D3,C3)).
   69
   70ppConds(drs([],[I:imp(A1,A2)|Conds1]),P,E,W,C,CD1-CD3,drs(D2,[I:imp(A3,A4)|Conds2])):- !,
   71   ppDrs(A1,P,E,W,C,CD1-CD2,A3),
   72   ppDrs(A2,P,E,W,C,CD2-_,A4),
   73   ppConds(drs([],Conds1),P,E,W,C,CD1-CD3,drs(D2,Conds2)).
   74
   75ppConds(drs([],[I:or(A1,A2)|Conds1]),P,E,W,C,CD1-CD3,drs(D2,[I:or(A3,A4)|Conds2])):- !,
   76   ppDrs(A1,P,E,W,C,CD1-_,A3),
   77   ppDrs(A2,P,E,W,C,CD1-_,A4),
   78   ppConds(drs([],Conds1),P,E,W,C,CD1-CD3,drs(D2,Conds2)).
   79
   80ppConds(drs([],[I:whq(A1,A2)|Conds1]),P,E,W,C,CD1-CD3,drs(D2,[I:whq(A3,A4)|Conds2])):- !,
   81   ppDrs(A1,P,E,W,C,CD1-CD2,A3),
   82   ppDrs(A2,P,E,W,C,CD2-_,A4),
   83   ppConds(drs([],Conds1),P,E,W,C,CD1-CD3,drs(D2,Conds2)).
   84
   85ppConds(drs([],[I:whq(Type,A1,Var,A2)|Conds1]),P,E,W,C,CD1-CD3,drs(D2,[I:whq(Type,A3,Var,A4)|Conds2])):- !,
   86   ppDrs(A1,P,E,W,C,CD1-CD2,A3),
   87   ppDrs(A2,P,E,W,C,CD2-_,A4),
   88   ppConds(drs([],Conds1),P,E,W,C,CD1-CD3,drs(D2,Conds2)).
   89
   90ppConds(drs([],[I:not(A1)|Conds1]),P,E,W,C,CD1-CD3,drs(D2,[I:not(A2)|Conds2])):- !,
   91   ppDrs(A1,P,E,W,C,CD1-_,A2),
   92   ppConds(drs([],Conds1),P,E,W,C,CD1-CD3,drs(D2,Conds2)).
   93
   94ppConds(drs([],[I:prop(X,A1)|Conds1]),P,E,W,C,CD1-CD3,drs(D2,[I:prop(X,A2)|Conds2])):- !,
   95   ppDrs(A1,P,E,W,C,CD1-_,A2),
   96   ppConds(drs([],Conds1),P,E,W,C,CD1-CD3,drs(D2,Conds2)).
   97
   98
   99/*========================================================================
  100   Merge DRSs
  101========================================================================*/
  102
  103mergeDrs(drs(D1,C1),drs(D2,C2),drs(D3,C3)):-
  104   append(D1,D2,D3),
  105   append(C1,C2,C3).
  106
  107
  108/*========================================================================
  109   Postprocessing DRS-Conditions
  110========================================================================*/
  111
  112checkDrs(B1,POS,NE,Words,Context,CDRS,B4):-
  113   rule(Check,Remove,Constraints,Add), 
  114   member(Check,B1,CDRS),
  115   remove(Remove,B1,B2),
  116   checkConstraints(Constraints,POS,NE,Words,Context), !,
  117   add(Add,B2,B3),
  118   checkDrs(B3,POS,NE,Words,Context,CDRS,B4).
  119
  120checkDrs(B,_,_,_,_,_,B).
  121
  122
  123/*========================================================================
  124   Member check DRS-Conditions
  125========================================================================*/
  126
  127member(drs([],[]),_,_):- !.
  128
  129member(drs(D1,[C|C1]),drs(D2,C2),B):-
  130   member(C,C2),
  131   member(drs(D1,C1),drs(D2,C2),B).
  132
  133member(drs(D1,[C|C1]),B,drs(D2,C2)):-
  134   member(C,C2),
  135   member(drs(D1,C1),B,drs(D2,C2)).
  136
  137member(drs([D|D1],[]),drs(D2,C2),B):-
  138   member(D,D2),
  139   member(drs(D1,[]),drs(D2,C2),B).
  140
  141member(drs([D|D1],[]),B,drs(D2,C2)):-
  142   member(D,D2),
  143   member(drs(D1,[]),B,drs(D2,C2)).
  144
  145
  146/*========================================================================
  147   Remove DRS-Conditions
  148========================================================================*/
  149
  150remove(drs([],[]),B,B):- !.
  151
  152remove(drs(D1,[C|C1]),drs(D2,C2),B):-
  153   select(C,C2,C3),
  154   remove(drs(D1,C1),drs(D2,C3),B).
  155
  156remove(drs([D|D1],[]),drs(D2,C),B):-
  157   select(D,D2,D3),
  158   remove(drs(D1,[]),drs(D3,C),B).
  159
  160
  161/*========================================================================
  162   Add DRS-Conditions
  163========================================================================*/
  164
  165add(drs([],[]),B,B).
  166
  167add(drs([X|D],C1),drs(D1,C2),B):-
  168   add(drs(D,C1),drs([X|D1],C2),B).
  169
  170add(drs([],[C|C1]),drs(D,C2),B):-
  171   add(drs([],C1),drs(D,[C|C2]),B).
  172
  173
  174/*========================================================================
  175   Check constraints
  176========================================================================*/
  177
  178checkConstraints([],_,_,_,_).
  179
  180checkConstraints([pos(A,POS)|L],P,N,W,Context):- !,
  181   member(B,POS),
  182   member(pos(A,B),P),
  183   checkConstraints(L,P,N,W,Context).
  184
  185checkConstraints([ne(A,NE)|L],P,N,W,Context):- !,
  186   member(B,NE),
  187   member(ne(A,B),N),
  188   checkConstraints(L,P,N,W,Context).
  189
  190checkConstraints([framerole(RIs,Role)|L],P,N,W,Context):- !,
  191   member(role(Role,R1,R2),Context),                   %%% find annotated framenet role
  192   member(RI,RIs), member(word(RI,_,R3,R4),W),         %%% relaxed match with words
  193   R3 >= R1, R4 =< R2, !,
  194   checkConstraints(L,P,N,W,Context).
  195
  196checkConstraints([frametarget(EIs,Frame)|L],P,N,W,Context):- !,
  197   member(target(Frame,T1,T2),Context),                %%% find annotated Target
  198   member(EI,EIs), member(word(EI,_,T3,T4),W),         %%% relaxed match with words
  199   T3 >= T1, T4 =< T2, !,
  200   checkConstraints(L,P,N,W,Context).
  201
  202checkConstraints([current_year(Year)|L],P,N,W,Context):- !,
  203   member(year:Year,Context), !,
  204   checkConstraints(L,P,N,W,Context).
  205
  206checkConstraints([current_month(Month)|L],P,N,W,Context):- !,
  207   member(month:Month,Context), !,
  208   checkConstraints(L,P,N,W,Context).
  209
  210checkConstraints([current_day(Day)|L],P,N,W,Context):- !,
  211   member(day:Day,Context), !,
  212   checkConstraints(L,P,N,W,Context).
  213
  214checkConstraints([C|L],P,N,W,Context):- 
  215   call(ppDrs:C),
  216   checkConstraints(L,P,N,W,Context).
  217
  218
  219/* ------------------------------------------------------------------------------
  220   Dealing with Quotes [new]
  221------------------------------------------------------------------------------ */
  222
  223rule(drs([],[]),
  224     drs([],[[I]:pred(X,quotation,n,2),[J]:pred(X,quotation,n,2)]),
  225
  226     [ I < J ],
  227
  228     drs([],[[I,J]:pred(X,quotation,n,2)])).
  229
  230
  231/* ------------------------------------------------------------------------------
  232   Dealing with Quotes [old, bit of a hack]
  233------------------------------------------------------------------------------ */
  234
  235rule(drs([],[]),
  236     drs([],[I:pred(X,Sym,_,Sense)]),
  237
  238     [ quoted(Sym) ],
  239
  240     drs([],[I:named(X,Sym,quo,Sense)])).
  241
  242
  243rule(drs([],[]),
  244     drs([],[I:named(X,Sym,nam,Sense)]),
  245
  246     [ quoted(Sym) ],
  247
  248     drs([],[I:named(X,Sym,quo,Sense)])).
  249
  250
  251/* ------------------------------------------------------------------------------
  252   Dealing with URLs and emails
  253------------------------------------------------------------------------------ */
  254
  255rule(drs([],[]),
  256     drs([],[I:pred(X,Sym,_,Sense)]),
  257
  258     [ url(Sym) ],
  259
  260     drs([],[I:named(X,Sym,url,Sense)])).
  261
  262
  263rule(drs([],[]),
  264     drs([],[I:named(X,Sym,nam,Sense)]),
  265
  266     [ url(Sym) ],
  267
  268     drs([],[I:named(X,Sym,url,Sense)])).
  269
  270rule(drs([],[]),
  271     drs([],[I:pred(X,Sym,_,Sense)]),
  272
  273     [ email(Sym) ],
  274
  275     drs([],[I:named(X,Sym,ema,Sense)])).
  276
  277
  278rule(drs([],[]),
  279     drs([],[I:named(X,Sym,nam,Sense)]),
  280
  281     [ email(Sym) ],
  282
  283     drs([],[I:named(X,Sym,ema,Sense)])).
  284
  285
  286/* ------------------------------------------------------------------------------
  287   Title, Names
  288------------------------------------------------------------------------------ */
  289
  290rule(drs([],[]),
  291     drs([],[I:named(X,Title,nam,Sense1),J:named(X,Sym,Type,Sense2)]),
  292
  293     [ title(Title,_),
  294       adjacent(I,J,_) ],
  295
  296     drs([],[I:named(X,Title,ttl,Sense1),J:named(X,Sym,Type,Sense2)])).
  297
  298rule(drs([],[I:named(X,_,ttl,_)]),
  299     drs([],[J:named(X,Sym,nam,Sense)]),
  300
  301     [ adjacent(I,J,_) ],
  302
  303     drs([],[J:named(X,Sym,per,Sense)])).
  304
  305rule(drs([],[J:named(X,_,per,_)]),
  306     drs([],[I:named(X,Sym,nam,Sense)]),
  307
  308     [ adjacent(I,J,_) ],
  309
  310     drs([],[I:named(X,Sym,per,Sense)])).
  311
  312rule(drs([],[I:named(X,_,per,_)]),
  313     drs([],[J:named(X,Sym,nam,Sense)]),
  314
  315     [ adjacent(I,J,_) ],
  316
  317     drs([],[J:named(X,Sym,per,Sense)])).
  318
  319
  320/* ------------------------------------------------------------------------------
  321   Ampersand in company names
  322------------------------------------------------------------------------------ */
  323
  324rule(drs([],[]),
  325     drs([],[[I]:pred(X,'&',a,_)]),
  326
  327     [ ne(I,['I-ORG','B-ORG','I-ORGANIZATION']) ],
  328
  329     drs([],[[I]:named(X,'&',org,0)])).
  330
  331
  332/* ------------------------------------------------------------------------------
  333   Proper Names (refining sorts)
  334------------------------------------------------------------------------------ */
  335
  336rule(drs([],[]),
  337     drs([],[[I]:named(X,Sym,nam,Sense)]),
  338
  339     [ ne(I,['I-PER','I-PERSON']) ],
  340
  341     drs([],[[I]:named(X,Sym,per,Sense)])).
  342
  343rule(drs([],[]),
  344     drs([],[[I]:named(X,Sym,nam,Sense)]),
  345
  346     [ ne(I,['I-ORG','B-ORG','I-ORGANIZATION']) ],
  347
  348     drs([],[[I]:named(X,Sym,org,Sense)])).
  349
  350rule(drs([],[]),
  351     drs([],[[I]:named(X,Sym,nam,Sense)]),
  352
  353     [ ne(I,['I-LOC','B-LOC','I-LOCATION']) ],
  354
  355     drs([],[[I]:named(X,Sym,loc,Sense)])).
  356
  357
  358/* ------------------------------------------------------------------------------
  359   Compound numeral expressions  (e.g. "4 billion")
  360------------------------------------------------------------------------------ */
  361
  362rule(drs([],[]),
  363     drs([],[[I]:card(X,Num1,Type),[J]:card(X,1000000000,Type)]), 
  364
  365     [ number(Num1), J is I + 1, 
  366       Num2 is integer(1000000000 * Num1) ],
  367
  368     drs([],[[I,J]:card(X,Num2,Type)])).
  369
  370
  371/* ------------------------------------------------------------------------------
  372   Compound numeral expressions  (e.g. "12 million")
  373------------------------------------------------------------------------------ */
  374
  375rule(drs([],[]),
  376     drs([],[[I]:card(X,Num1,Type),[J]:card(X,1000000,Type)]),
  377
  378     [ number(Num1), J is I + 1, 
  379       Num2 is integer(1000000 * Num1) ],
  380
  381     drs([],[[I,J]:card(X,Num2,Type)])).
  382
  383
  384/* ------------------------------------------------------------------------------
  385   Compound numeral expressions  (e.g. "7 thousand")
  386------------------------------------------------------------------------------ */
  387
  388rule(drs([],[]),
  389     drs([],[[I]:card(X,Num1,Type),[J]:card(X,1000,Type)]),
  390
  391     [ number(Num1), J is I + 1, 
  392       Num2 is integer(1000 * Num1) ],
  393
  394     drs([],[[I,J]:card(X,Num2,Type)])).
  395
  396
  397/* ------------------------------------------------------------------------------
  398   Compound numeral expressions  (e.g. "four feet ten inches")
  399------------------------------------------------------------------------------ */
  400
  401rule(drs([],[]),
  402     drs([],[[I]:card(X,Num1,Type),[J]:pred(X,foot,n,Sense),
  403             [K]:card(X,Num2,Type),[L]:pred(X,inch,n,_)]),
  404
  405     [ number(Num1), number(Num2),
  406       J is I + 1, K is J + 1, L is K + 1,
  407       Num3 is (Num1 + (Num2/100)) ],
  408
  409     drs([],[[I,K]:card(X,Num3,Type),[J,L]:pred(X,foot,n,Sense)])).
  410
  411
  412/* ------------------------------------------------------------------------------
  413   Date expressions (e.g. "March 2, 2004")
  414------------------------------------------------------------------------------ */
  415
  416rule(drs([],[]),
  417     drs([],[[I]:pred(X,Month,a,_),[J]:card(X,Day,ge),[K]:card(X,Year,ge)]),
  418 
  419     [ month(Month,MID),
  420       J is I + 1,
  421       day(Day,DID),
  422       K is I + 3, 
  423       L is I + 2,
  424       number(Year), Year > 1000, Year < 3000,
  425       year(Year,YID) ],
  426
  427     drs([],[[I,J,L,K]:timex(X,date([]:'+',[K]:YID,[I]:MID,[J]:DID))])).
  428
  429rule(drs([],[]),
  430     drs([],[[I]:named(X,Month,nam,_),[J]:card(X,Day,ge),[K]:card(X,Year,ge)]),
  431 
  432     [ month(Month,MID),
  433       J is I + 1,
  434       day(Day,DID),
  435       K is I + 3, 
  436       L is I + 2,
  437       number(Year), Year > 1000, Year < 3000,
  438       year(Year,YID) ],
  439
  440     drs([],[[I,J,L,K]:timex(X,date([]:'+',[K]:YID,[I]:MID,[J]:DID))])).
  441
  442rule(drs([],[]),
  443     drs([],[[I]:named(X,Month,nam,_),[J]:pred(X,Day,_,_),[K]:card(X,Year,ge)]),
  444 
  445     [ month(Month,MID),
  446       J is I + 1, 
  447       day(Day,DID),
  448       K is I + 3,  
  449       L is I + 2,
  450       number(Year), Year > 1000, Year < 3000,
  451       year(Year,YID) ],
  452
  453     drs([],[[I,J,L,K]:timex(X,date([]:'+',[K]:YID,[I]:MID,[J]:DID))])).
  454
  455
  456/* ------------------------------------------------------------------------------
  457   Clocktime expressions (e.g. "at 4 : 30 pm")
  458------------------------------------------------------------------------------ */
  459
  460rule(drs([],[]),
  461     drs([],[[I]:card(X,Hour,ge),[I]:pred(X,thing,n,12),[J]:rel(X,Y,':',_),[K]:card(Y,Minutes,ge),[L]:pred(Y,AMPM,n,_)]),
  462 
  463     [ member(AMPM,[am,pm]),
  464       hour(Hour,AMPM,HourID),
  465       minute(Minutes,MinID) ],
  466
  467     drs([],[[I,J,K,L]:timex(X,time([I]:HourID,[K]:MinID,[]:'XX'))])).
  468
  469rule(drs([],[]),
  470     drs([],[[I]:card(X,Hour,ge),[I]:pred(X,thing,n,12),[J]:rel(X,Y,':',_),[K]:card(Y,Minutes,ge)]),
  471 
  472     [ hour(Hour,pm,HourID),
  473       minute(Minutes,MinID) ],
  474
  475     drs([],[[I,J,K]:timex(X,time([I]:HourID,[K]:MinID,[]:'XX'))])).
  476
  477rule(drs([],[_:rel(_,X,at,_)]),
  478     drs([],[I:card(X,Hour,ge),I:pred(X,thing,n,12)]),
  479 
  480     [ hour(Hour,pm,HourID) ],
  481
  482     drs([],[I:timex(X,time(I:HourID,[]:'XX',[]:'XX'))])).
  483
  484
  485/* ------------------------------------------------------------------------------
  486   Clocktime expressions (e.g. "2200 GMT")
  487------------------------------------------------------------------------------ */
  488
  489rule(drs([],[]),
  490     drs([],[[I]:card(X,Time,ge),[J]:pred(X,gme,n,_)]),
  491
  492     [ gmt(Time,Hour,Minute),
  493       J is I + 1 ],
  494
  495     drs([],[[I,J]:timex(X,time([]:Hour,[]:Minute,[]:'XX'))])).
  496
  497
  498/* ------------------------------------------------------------------------------
  499   Date expressions (e.g. "10th of March , 2004")
  500------------------------------------------------------------------------------ */
  501
  502rule(drs([],[]),
  503     drs([],[[I]:pred(X,Day,_,_),[J]:rel(X,Y,of,_),[K]:named(Y,Month,nam,_),[M]:card(_,Year,ge)]),
  504 
  505     [ day(Day,DID),
  506       J is I + 1, 
  507       month(Month,MID),
  508       K is I + 2, 
  509       L is I + 3,
  510       M is I + 4,
  511       number(Year), Year > 1000, Year < 3000,
  512       year(Year,YID) ],
  513
  514     drs([],[[I,J,K,L,M]:timex(X,date([]:'+',[L]:YID,[K]:MID,[I]:DID))])).
  515
  516rule(drs([],[]),
  517     drs([],[[I]:pred(X,Day,_,_),[J]:rel(X,Y,of,_),[K]:pred(Y,Month,_,_),[M]:card(_,Year,ge)]),
  518 
  519     [ 
  520       day(Day,DID),
  521       J is I + 1,
  522       month(Month,MID),
  523       K is I + 2,
  524       L is I + 3,
  525       M is I + 4,
  526       number(Year), Year > 1000, Year < 3000,
  527       year(Year,YID) ],
  528
  529     drs([],[[I,J,K,L,M]:timex(X,date([]:'+',[L]:YID,[K]:MID,[I]:DID))])).
  530
  531
  532/* ------------------------------------------------------------------------------
  533   Date expressions (e.g. "June 30", "28 July")
  534------------------------------------------------------------------------------ */
  535
  536rule(drs([],[]),
  537     drs([],[[I]:named(X,Month,nam,_),[J]:card(X,Day,ge)]),
  538
  539     [ month(Month,MID),
  540       J is I + 1, 
  541       day(Day,DID) ],
  542    
  543     drs([],[[I,J]:timex(X,date([]:'+',[]:'XXXX',[I]:MID,[J]:DID))])).
  544
  545rule(drs([],[]),
  546     drs([],[[I]:pred(X,Month,_,_),[J]:card(X,Day,ge)]),
  547
  548     [ month(Month,MID),
  549       J is I + 1, 
  550       day(Day,DID) ],
  551    
  552     drs([],[[I,J]:timex(X,date([]:'+',[]:'XXXX',[I]:MID,[J]:DID))])).
  553
  554rule(drs([],[]),
  555     drs([],[[I]:card(X,Day,ge),[J]:named(X,Month,nam,_)]),
  556
  557     [ month(Month,MID),
  558       J is I + 1,  
  559       day(Day,DID) ],
  560    
  561     drs([],[[I,J]:timex(X,date([]:'+',[]:'XXXX',[I]:MID,[J]:DID))])).
  562
  563rule(drs([],[]),
  564     drs([],[[I]:card(X,Day,ge),[J]:pred(X,Month,_,_)]),
  565
  566     [ month(Month,MID),
  567       J is I + 1, 
  568       day(Day,DID) ],
  569    
  570     drs([],[[I,J]:timex(X,date([]:'+',[]:'XXXX',[I]:MID,[J]:DID))])).
  571
  572
  573/* ------------------------------------------------------------------------------
  574   Date expressions (e.g. "June 1998")
  575------------------------------------------------------------------------------ */
  576
  577rule(drs([],[]),
  578     drs([],[[I]:named(X,Month,nam,_),[J]:card(X,Year,ge)]),
  579
  580     [ month(Month,MID),
  581       J is I + 1,
  582       number(Year), Year > 100, Year < 3000,
  583       year(Year,YID) ],
  584
  585     drs([],[[I,J]:timex(X,date([]:'+',[J]:YID,[I]:MID,[]:'XX'))])).
  586
  587
  588/* ------------------------------------------------------------------------------
  589   Date expressions (e.g. "June")
  590------------------------------------------------------------------------------ */
  591
  592rule(drs([],[]),
  593     drs([],[[I]:named(X,Month,nam,_)]),
  594
  595     [ month(Month,MID) ],
  596
  597     drs([],[[I]:timex(X,date([]:'+',[]:'XXXX',[I]:MID,[]:'XX'))])).
  598
  599rule(drs([],[]),
  600     drs([],[[I]:pred(X,Month,n,_)]),
  601
  602     [ month(Month,MID),
  603       pos(I,['NN','NNP']) ],
  604
  605     drs([],[[I]:timex(X,date([]:'+',[]:'XXXX',[I]:MID,[]:'XX'))])).
  606
  607
  608
  609/* ------------------------------------------------------------------------------
  610   Date expressions (years B.C.)
  611------------------------------------------------------------------------------ */
  612
  613rule(drs([],[]),
  614     drs([],[[I]:card(X,Year,ge),[J]:named(X,BC,_,_)]),
  615
  616     [ member(BC,[bc,bce]),
  617       number(Year), 
  618       year(Year,YearFormatted),
  619       J is I + 1 ],
  620
  621     drs([],[[I,J]:timex(X,date([J]:'-',[I]:YearFormatted,[]:'XX',[]:'XX'))])).
  622
  623rule(drs([],[]),
  624     drs([],[[I]:card(X,Year,ge),[J]:pred(X,BC,n,_)]),
  625
  626     [ member(BC,[bc,bce]),
  627       number(Year), 
  628       year(Year,YearFormatted),
  629       J is I + 1 ],
  630
  631     drs([],[[I,J]:timex(X,date([J]:'-',[I]:YearFormatted,[]:'XX',[]:'XX'))])).
  632
  633
  634/* ------------------------------------------------------------------------------
  635   Date expressions (years A.D.)
  636------------------------------------------------------------------------------ */
  637
  638rule(drs([],[]),
  639     drs([],[[I]:card(X,Year,ge),[J]:named(X,AD,_,_)]),
  640
  641     [ member(AD,[ad,ce]),
  642       number(Year), 
  643       year(Year,YearFormatted),
  644       J is I + 1 ],
  645
  646     drs([],[[I,J]:timex(X,date([J]:'+',[I]:YearFormatted,[]:'XX',[]:'XX'))])).
  647
  648rule(drs([],[]),
  649     drs([],[[I]:card(X,Year,ge),[J]:pred(X,AD,n,_)]),
  650
  651     [ member(AD,[ad,ce]),
  652       number(Year), 
  653       year(Year,YearFormatted),
  654       J is I + 1 ],
  655
  656     drs([],[[I,J]:timex(X,date([J]:'+',[I]:YearFormatted,[]:'XX',[]:'XX'))])).
  657
  658rule(drs([],[]),
  659     drs([],[[I]:named(X,AD,_,_),[J]:card(X,Year,ge)]),
  660
  661     [ member(AD,[ad,ce]),
  662       number(Year), 
  663       year(Year,YearFormatted),
  664       J is I + 1 ],
  665
  666     drs([],[[I,J]:timex(X,date([J]:'+',[I]:YearFormatted,[]:'XX',[]:'XX'))])).
  667
  668rule(drs([],[]),
  669     drs([],[[I]:pred(X,AD,n,_),[J]:card(X,Year,ge)]),
  670
  671     [ member(AD,[ad,ce]),
  672       number(Year), 
  673       year(Year,YearFormatted),
  674       J is I + 1 ],
  675
  676     drs([],[[I,J]:timex(X,date([J]:'+',[I]:YearFormatted,[]:'XX',[]:'XX'))])).
  677
  678
  679/* ------------------------------------------------------------------------------
  680   Date expressions (years)
  681------------------------------------------------------------------------------ */
  682
  683rule(drs([],[]),
  684     drs([],[[I]:card(X,Year,ge)]),
  685
  686     [ number(Year), 
  687       Year > 1000, Year < 2100,
  688       year(Year,YID),
  689       ne(I,['I-DAT','I-DATE']) ],
  690
  691     drs([],[[I]:timex(X,date([]:'+',[I]:YID,[]:'XX',[]:'XX'))])).
  692
  693
  694
  695/* ------------------------------------------------------------------------------
  696   Date expressions (e.g. "in/by/for/to/from 1992")
  697------------------------------------------------------------------------------ */
  698
  699rule(drs([],[[J]:rel(_,X,_,_)]),
  700     drs([],[[I]:card(X,Year,ge)]),
  701
  702     [ number(Year), 
  703       Year > 1000, Year < 2100,
  704       year(Year,YID),
  705       I is J + 1 ],
  706
  707     drs([],[[I]:timex(X,date([]:'+',[I]:YID,[]:'XX',[]:'XX'))])).
  708
  709
  710/* ------------------------------------------------------------------------------
  711   Date expressions (decades)
  712------------------------------------------------------------------------------ */
  713
  714rule(drs([],[_:rel(_,X,in,_)]),
  715     drs([],[[I]:pred(X,Decade,_,_)]),
  716
  717     [ decade(Decade,D),
  718       ne(I,['I-DAT','I-DATE']), 
  719       pos(I,['NNS']) ],
  720
  721     drs([],[[I]:timex(X,date([]:'+',[I]:D,[]:'XX',[]:'XX'))])).
  722
  723rule(drs([],[]),
  724     drs([],[[I]:pred(X,Decade,_,_)]),
  725
  726     [ decade(Decade,D) ],
  727
  728     drs([],[[I]:timex(X,date([]:'+',[I]:D,[]:'XX',[]:'XX'))])).
  729
  730
  731/* ------------------------------------------------------------------------------
  732   Date expressions (e.g. 11th century)
  733------------------------------------------------------------------------------ */
  734
  735rule(drs([],[]),
  736     drs([],[[I]:pred(X,Century,a,_),[J]:pred(X,century,n,_)]),
  737
  738     [ J is I + 1, 
  739       century(Century,C) ],
  740
  741     drs([],[[I,J]:timex(X,date([]:'+',[I,J]:C,[]:'XX',[]:'XX'))])).
  742
  743rule(drs([],[]),
  744     drs([[J]:X],[[I]:pred(Y,Century,a,_),[J]:pred(X,century,n,_),[]:rel(X,Y,nn,_)]),
  745
  746     [ J is I + 1, 
  747       century(Century,C) ],
  748
  749     drs([],[[I,J]:timex(Y,date([]:'+',[I,J]:C,[]:'XX',[]:'XX'))])).
  750
  751
  752/* ------------------------------------------------------------------------------
  753   Date expressions (e.g. "the september 11 plot")
  754------------------------------------------------------------------------------ */
  755
  756rule(drs([],[]),
  757     drs([],[[I]:named(X,Month,nam,_),[]:rel(X,Y,nn,Sense),[J]:card(Y,Day,ge)]),
  758
  759     [ month(Month,MID),
  760       J is I + 1, 
  761       day(Day,DID) ],
  762
  763     drs([],[[I,J]:timex(X,date([]:'+',[]:'XXXX',[I]:MID,[J]:DID)),[]:rel(X,Y,nn,Sense)])).
  764
  765
  766/* ------------------------------------------------------------------------------
  767   Date expressions (repair rules)
  768------------------------------------------------------------------------------ */
  769
  770rule(drs([],[]),
  771     drs([],[[L]:timex(X,date([]:'+',[L]:Year,[]:_,[]:_)),[I,J]:timex(Y,date([]:'+',[]:_,[I]:Month,[J]:Day)),[L]:rel(E,X,rel,0),_:rel(E,Y,rel,0)]),
  772
  773     [ J is I + 1,
  774       K is J + 1,
  775       L is K + 1 ],
  776
  777     drs([],[[I,J,K,L]:timex(X,date([]:'+',[L]:Year,[I]:Month,[J]:Day)),[L]:rel(E,X,rel,0)])).
  778
  779
  780/* ------------------------------------------------------------------------------
  781   Date expressions (implicit year)
  782------------------------------------------------------------------------------ */
  783
  784rule(drs([],[]),
  785     drs([],[I:timex(X,date([]:'+',[]:'XXXX',MI:Month,Day))]),
  786
  787     [ current_year(CurrentYear),
  788       current_month(CurrentMonth),
  789       current_day(CurrentDay),
  790       %%% Assuming verb is in past tense
  791       earlier_doy(doy(Month,Day),doy(CurrentMonth,CurrentDay)) ],
  792
  793     drs([],[I:timex(X,date([]:'+',[]:CurrentYear,MI:Month,Day))])).
  794
  795rule(drs([],[]),
  796     drs([],[I:timex(X,date([]:'+',[]:'XXXX',Month,Day))]),
  797
  798     [ current_year(CurrentYear),
  799       %%% Assuming verb is in past tense
  800       last_year(CurrentYear,LastYear) ],
  801
  802     drs([],[I:timex(X,date([]:'+',[]:LastYear,Month,Day))])).
  803
  804
  805/* ------------------------------------------------------------------------------
  806   NN-resolution (e.g. "document collection/grape variety")
  807------------------------------------------------------------------------------ */
  808
  809rule(drs([],[[I]:pred(X,_,n,_),[J]:pred(Y,Collection,n,_)]),
  810     drs([],[[]:rel(X,Y,nn,_)]),
  811
  812     [ member(Collection,[assortment,mixture,variety,potpourri,motley,
  813                          collection,aggregation,accumulation,assemblage,group]),
  814       J is I + 1 ],
  815
  816     drs([],[[]:rel(Y,X,of,1)])).
  817
  818
  819/* ------------------------------------------------------------------------------
  820   Cardinals: just/exactly/at most CARD
  821------------------------------------------------------------------------------ */
  822
  823rule(drs([],[]),
  824     drs([],[[I]:pred(X,just,a,_),[J]:card(X,C,ge)]),
  825    
  826     [ J is I + 1 ],
  827
  828     drs([],[[I,J]:card(X,C,eq)])).
  829
  830rule(drs([],[]),
  831     drs([],[[I]:pred(X,exactly,a,_),[J]:card(X,C,ge)]),
  832    
  833     [ J is I + 1 ],
  834
  835     drs([],[[I,J]:card(X,C,eq)])).
  836
  837rule(drs([],[]),
  838     drs([],[[I]:pred(X,at,_,_),[J]:prop(_,drs([],[[J]:pred(X,most,_,_)])),[K]:card(X,C,ge)]),
  839
  840     [ J is I + 1,
  841       K is J + 1 ],
  842
  843     drs([],[[I,J,K]:card(X,C,le)])).
  844      
  845
  846/* ------------------------------------------------------------------------------
  847   Compound Names
  848------------------------------------------------------------------------------ */
  849
  850rule(drs([],[]),
  851     drs([],[I:named(X,Sym1,Type,Sense),J:named(X,Sym2,nam,_)]),
  852
  853     [ member(Type,[org,loc]),
  854       adjacent(I,J,K),
  855       combineSym(Sym1,Sym2,Sym) ],
  856
  857     drs([],[K:named(X,Sym,Type,Sense)])).
  858
  859rule(drs([],[]),
  860     drs([],[I:named(X,Sym1,nam,_),J:named(X,Sym2,Type,Sense)]),
  861
  862     [ member(Type,[org,loc]),
  863       adjacent(I,J,K),
  864       combineSym(Sym1,Sym2,Sym) ],
  865
  866     drs([],[K:named(X,Sym,Type,Sense)])).
  867
  868rule(drs([],[]),
  869     drs([],[I:named(X,Sym1,Type,Sense),J:named(X,Sym2,Type,_)]),
  870
  871     [ member(Type,[org,loc,nam]),
  872       adjacent(I,J,K),
  873       combineSym(Sym1,Sym2,Sym) ],
  874
  875     drs([],[K:named(X,Sym,Type,Sense)])).
  876
  877
  878/* ------------------------------------------------------------------------------
  879   NN compounds: DATE + NAME / NOUN
  880------------------------------------------------------------------------------ */
  881
  882rule(drs([],[J:named(X,_,_,_)]),
  883     drs([],[I:timex(X,Timex)]),
  884
  885     [ adjacent(I,J,_),
  886       newref(New) ],
  887
  888     drs([I:New],[I:timex(New,Timex),[]:rel(X,New,temp_rel,0)])).
  889
  890rule(drs([],[J:pred(X,_,n,_)]),
  891     drs([],[I:timex(X,Timex)]),
  892
  893     [ adjacent(I,J,_),
  894       newref(New) ],
  895
  896     drs([I:New],[I:timex(New,Timex),[]:rel(X,New,temp_rel,0)])).
  897
  898rule(drs([],[J:pred(X,_,a,_),K:pred(X,_,n,_)]),
  899     drs([],[I:timex(X,Timex)]),
  900
  901     [ adjacent(I,J,_),
  902       adjacent(J,K,_),
  903       newref(New) ],
  904
  905     drs([I:New],[I:timex(New,Timex),[]:rel(X,New,temp_rel,0)])).
  906
  907
  908/* ------------------------------------------------------------------------------
  909   NN compounds: PN + NOUN + NOUN
  910------------------------------------------------------------------------------ */
  911
  912rule(drs([],[J:pred(X,_,n,_)]),
  913     drs([],[H:named(X,Sym0,Type,Sense),I:pred(X,Sym1,n,Sense1)]),
  914
  915     [ adjacent(H,I,_),
  916       adjacent(I,J,_),  
  917       newref(New1),
  918       newref(New2) ],
  919
  920     drs([H:New1,I:New2],[H:named(New1,Sym0,Type,Sense),[]:rel(New1,X,nn,0),
  921                          I:pred(New2,Sym1,n,Sense1),[]:rel(New2,X,nn,0)])).
  922
  923
  924/* ------------------------------------------------------------------------------
  925   NN compounds: NOUN + PN + NOUN
  926------------------------------------------------------------------------------ */
  927
  928rule(drs([],[J:pred(X,_,n,_)]),
  929     drs([],[H:pred(X,Sym0,n,Sense1),I:named(X,Sym1,Type,Sense)]),
  930
  931     [ adjacent(H,I,_),
  932       adjacent(I,J,_),  
  933       newref(New1),
  934       newref(New2) ],
  935
  936     drs([H:New1,I:New2],[H:pred(New1,Sym0,n,Sense1),[]:rel(New1,X,nn,0),
  937                          I:named(New2,Sym1,Type,Sense),[]:rel(New2,X,nn,0)])).
  938
  939
  940/* ------------------------------------------------------------------------------
  941   NN compounds: NOUN + NOUN
  942------------------------------------------------------------------------------ */
  943
  944rule(drs([],[J:pred(X,_,n,_)]),
  945     drs([],[I:pred(X,Sym1,n,Sense1)]),
  946
  947     [ adjacent(I,J,_),
  948       newref(New) ],
  949
  950     drs([I:New],[I:pred(New,Sym1,n,Sense1),[]:rel(New,X,nn,0)])
  951    ).
  952
  953
  954/* ------------------------------------------------------------------------------
  955   NN compounds: NOUN + ADJ + NOUN
  956------------------------------------------------------------------------------ */
  957
  958rule(drs([],[J:pred(X,_,a,_),K:pred(X,_,n,_)]),
  959     drs([],[I:pred(X,Sym,n,Sense)]),
  960
  961     [ adjacent(I,J,_),
  962       adjacent(J,K,_),
  963       newref(New) ],
  964
  965     drs([I:New],[I:pred(New,Sym,n,Sense),[]:rel(New,X,nn,0)])).
  966
  967
  968/* ------------------------------------------------------------------------------
  969   NN compounds: PN + PN + NOUN
  970------------------------------------------------------------------------------ */
  971
  972rule(drs([],[J:pred(X,_,n,_)]),
  973     drs([],[H:named(X,Sym0,per,Sense1),I:named(X,Sym1,per,Sense2)]),
  974
  975     [ adjacent(H,I,HI),
  976       adjacent(I,J,_),  
  977       newref(New) ],
  978
  979     drs([HI:New],[H:named(New,Sym0,per,Sense1),I:named(New,Sym1,per,Sense2),[]:rel(New,X,nn,0)])).
  980
  981
  982/* ------------------------------------------------------------------------------
  983   NN compounds: NAME + NOUN
  984------------------------------------------------------------------------------ */
  985
  986rule(drs([],[J:pred(X,_,n,_)]),
  987     drs([],[I:named(X,Sym1,Type,Sense1)]),
  988
  989     [ adjacent(I,J,_),
  990       newref(New) ],
  991
  992     drs([I:New],[I:named(New,Sym1,Type,Sense1),[]:rel(New,X,nn,0)])).
  993
  994
  995/* ------------------------------------------------------------------------------
  996   NN compounds: NOUN + NAME 
  997------------------------------------------------------------------------------ */
  998
  999rule(drs([],[J:named(X,_,_,_)]),
 1000     drs([],[I:pred(X,Sym1,n,Sense1)]),
 1001
 1002     [ adjacent(I,J,_),
 1003       newref(New) ],
 1004
 1005     drs([I:New],[I:pred(New,Sym1,n,Sense1),[]:rel(New,X,nn,0)])).
 1006
 1007
 1008%
 1009% Rules for James
 1010%
 1011/*
 1012rule(drs([],[]),
 1013     drs([],[[I]:named(X1,Sym1,per),[J]:named(X2,Sym2,per)]),
 1014
 1015     [ X2==X1,
 1016       J is I + 1 ], 
 1017
 1018     drs([],[[I]:named(X1,Sym1,fst),[J]:named(X2,Sym2,sur)])).
 1019
 1020rule(drs([],[]),
 1021     drs([],[[I]:named(X1,Sym1,per),[J]:named(X2,Sym2,per),[K]:named(X3,Sym3,per)]),
 1022
 1023     [ X2==X1,
 1024       X3==X2,
 1025       J is I + 1,
 1026       K is J + 1 ], 
 1027
 1028     drs([],[[I]:named(X1,Sym1,fst),[J]:named(X2,Sym2,fst),[K]:named(X3,Sym3,sur)])).
 1029*/
 1030
 1031
 1032/* ------------------------------------------------------------------------------
 1033   Dimensional Adjectives
 1034------------------------------------------------------------------------------ */
 1035
 1036rule(drs([],[]),
 1037     drs([],[[I]:pred(X,Adj,a,_)]),
 1038    
 1039     [ dimension(Adj,Dim,Sense),
 1040       J is I - 1,
 1041       pos(J,['WRB']) ],
 1042
 1043     drs([],[[I]:pred(X,Dim,n,Sense)])).
 1044
 1045
 1046
 1047/* ------------------------------------------------------------------------------
 1048   Framenet targets
 1049------------------------------------------------------------------------------ */
 1050
 1051rule(drs([],[]),
 1052     drs([],[I:pred(E,Sym,v,0)]),
 1053    
 1054     [ frametarget(I,Frame) ],
 1055
 1056     drs([],[I:pred(E,Sym,v,1),[]:pred(E,Frame,a,99)])):-
 1057   user:option('--framenet',training).
 1058
 1059/*
 1060rule(drs([],[]),
 1061     drs([],[I:pred(E,Sym,n,0)]),
 1062    
 1063     [ frametarget(I,Frame) ],
 1064
 1065     drs([],[I:pred(E,Sym,n,1),[]:pred(E,Frame,a,98)])).
 1066
 1067rule(drs([],[]),
 1068     drs([],[I:named(E,Sym,Type,0)]),
 1069    
 1070     [ frametarget(I,Frame) ],
 1071
 1072     drs([],[I:named(E,Sym,Type,1),[]:pred(E,Frame,a,97)])).
 1073
 1074rule(drs([],[]),
 1075     drs([],[I:pred(E,Sym,a,0)]),
 1076    
 1077     [ frametarget(I,Frame) ],
 1078
 1079     drs([],[I:pred(E,Sym,a,1),[]:pred(E,Frame,a,96)])).
 1080
 1081rule(drs([],[]),
 1082     drs([],[I:rel(E,X,Sym,0)]),
 1083    
 1084     [ frametarget(I,Frame) ],
 1085
 1086     drs([],[I:rel(E,X,Sym,1),[]:pred(E,Frame,a,95)])).
 1087*/
 1088
 1089
 1090/* ------------------------------------------------------------------------------
 1091   Framenet roles
 1092------------------------------------------------------------------------------ */
 1093
 1094% basic two-place relation
 1095%
 1096rule(drs([I2:X],[[]:pred(E,_Frame,a,99)]),
 1097     drs([],[I1:rel(E,X,Rel,0)]),
 1098    
 1099     [ framerole(I2,Role) ],
 1100
 1101     drs([],[I1:rel(E,X,Rel,1),[]:rel(E,X,Role,99)])):-
 1102   user:option('--framenet',training).
 1103
 1104% adverb
 1105%
 1106rule(drs([],[[]:pred(E,_Frame,a,99)]),
 1107     drs([],[I1:pred(E,Sym,a,0)]),
 1108    
 1109     [ framerole(I1,Role) ],
 1110
 1111     drs([],[I1:pred(E,Sym,a,1),[]:rel(E,E,Role,99)])):-
 1112   user:option('--framenet',training).
 1113
 1114% indirect (possessive)
 1115%
 1116rule(drs([I2:Y],[[]:pred(E,_Frame,a,99),[]:rel(E,X,_,99)]),
 1117     drs([],[I1:rel(X,Y,of,0)]),
 1118    
 1119     [ framerole(I2,Role) ],
 1120
 1121     drs([],[I1:rel(X,Y,of,1),[]:rel(E,Y,Role,98)])):-
 1122   user:option('--framenet',training).
 1123
 1124
 1125/*========================================================================
 1126   New Refs
 1127========================================================================*/
 1128
 1129newref(X):-
 1130   counter(Old),
 1131   X='$VAR'(Old),
 1132   New is Old + 1,
 1133   retractall(counter(_)),
 1134   assert(counter(New)).
 1135
 1136
 1137/*========================================================================
 1138   Adjacent Indexes
 1139========================================================================*/
 1140
 1141adjacent(A,B,C):-
 1142   reverse(A,[I|_]),
 1143   B=[J|_],
 1144   J is I + 1,
 1145   append(A,B,C).
 1146
 1147
 1148/*========================================================================
 1149   Combine Symbols
 1150========================================================================*/
 1151
 1152combineSym(Sym1,Sym2,Sym):-
 1153   \+ Sym1='"',
 1154   \+ Sym2='"',
 1155   name(Sym1,Codes1),
 1156   name(Sym2,Codes2),
 1157   append(Codes1,[95|Codes2],Codes),
 1158   name(Sym,Codes).
 1159
 1160
 1161/*========================================================================
 1162   Months
 1163========================================================================*/
 1164
 1165month('january','01').
 1166month('jan','01').
 1167month('february','02').
 1168month('feb','02').
 1169month('march','03').
 1170month('mar','03').
 1171month('april','04').
 1172month('apr','04').
 1173month('may','05').
 1174month('june','06').
 1175month('july','07').
 1176month('august','08').
 1177month('aug','08').
 1178month('september','09').
 1179month('sept','09').
 1180month('sep','09').
 1181month('october','10').
 1182month('oct','10').
 1183month('november','11').
 1184month('nov','11').
 1185month('december','12').
 1186month('dec','12').
 1187
 1188earlier_day('01','02').
 1189earlier_day('02','03').
 1190earlier_day('03','04').
 1191earlier_day('04','05').
 1192earlier_day('05','06').
 1193earlier_day('06','07').
 1194earlier_day('07','08').
 1195earlier_day('08','09').
 1196earlier_day('09','10').
 1197earlier_day('10','11').
 1198earlier_day('11','12').
 1199earlier_day('12','13').
 1200earlier_day('13','14').
 1201earlier_day('14','15').
 1202earlier_day('15','16').
 1203earlier_day('16','17').
 1204earlier_day('17','18').
 1205earlier_day('18','19').
 1206earlier_day('19','20').
 1207earlier_day('20','21').
 1208earlier_day('21','22').
 1209earlier_day('22','23').
 1210earlier_day('23','24').
 1211earlier_day('24','25').
 1212earlier_day('25','26').
 1213earlier_day('26','27').
 1214earlier_day('27','28').
 1215earlier_day('28','29').
 1216earlier_day('29','30').
 1217earlier_day('30','31').
 1218
 1219earlier(A,B):- earlier_day(A,B), !.
 1220earlier(A,B):- earlier_day(A,C), earlier(C,B).
 1221
 1222
 1223earlier_doy(doy(M1,_),doy(M2,_)):-
 1224   earlier(M1,M2), !.
 1225
 1226earlier_doy(doy(M,D1),doy(M,D2)):-
 1227   earlier(D1,D2), !.
 1228
 1229
 1230/*========================================================================
 1231   Format Years
 1232========================================================================*/
 1233
 1234year(Y,F):- 
 1235   atom_chars(Y,Chars),
 1236   ( Chars = [_], atom_chars(F,['0','0','0'|Chars]), !
 1237   ; Chars = [_,_], atom_chars(F,['0','0'|Chars]), ! 
 1238   ; Chars = [_,_,_], atom_chars(F,['0'|Chars]), !
 1239   ; Chars = [_,_,_,_], atom_chars(F,Chars) ).
 1240
 1241
 1242last_year(Year,Last):- 
 1243   atom_codes(Year,[Y1,Y2,Y3,Y4]),
 1244   Y1 > 47, Y1 < 58,
 1245   Y2 > 47, Y2 < 58,
 1246   Y3 > 47, Y3 < 58,
 1247   Y4 > 47, Y4 < 58, !,
 1248   number_codes(NumberYear,[Y1,Y2,Y3,Y4]),
 1249   NumberLast is NumberYear - 1,
 1250   number_codes(NumberLast,Codes),
 1251   atom_codes(Last,Codes).
 1252
 1253last_year(X,X).
 1254
 1255
 1256/*========================================================================
 1257   Centuries
 1258========================================================================*/
 1259
 1260century('1st',     '00XX').
 1261century('first',   '00XX').
 1262century('2nd',     '01XX').
 1263century('second',  '01XX').
 1264century('3rd',     '02XX').
 1265century('third',   '02XX').
 1266century('4th','     03XX').
 1267century('fourth',  '03XX').
 1268century('5th',     '04XX').
 1269century('fifth',   '04XX').
 1270century('6th',     '05XX').
 1271century('sixth',   '05XX').
 1272century('7th',     '06XX').
 1273century('seventh', '06XX').
 1274century('8th',     '07XX').
 1275century('eigth',   '07XX').
 1276century('9th',     '08XX').
 1277century('ninth',   '08XX').
 1278century('10th',    '09XX').
 1279century('tenth',   '09XX').
 1280century('11th',    '10XX').
 1281century('12th',    '11XX').
 1282century('13th',    '12XX').
 1283century('14th',    '13XX').
 1284century('15th',    '14XX').
 1285century('16th',    '15XX').
 1286century('17th',    '16XX').
 1287century('18th',    '17XX').
 1288century('19th',    '18XX').
 1289century('20th',    '19XX').
 1290century('21th',    '20XX').
 1291
 1292
 1293/*========================================================================
 1294   Decades
 1295========================================================================*/
 1296
 1297decade(Date,Decade):-
 1298   name(Date,[A,B,C,48]),
 1299   name(Decade,[A,B,C,88]), !.
 1300
 1301decade('1610s','161X').
 1302decade('1620s','162X').
 1303decade('1630s','163X').
 1304decade('1640s','164X').
 1305decade('1650s','165X').
 1306decade('1660s','166X').
 1307decade('1670s','167X').
 1308decade('1680s','168X').
 1309decade('1690s','169X').
 1310decade('1700s','170X').
 1311decade('1710s','171X').
 1312decade('1720s','172X').
 1313decade('1730s','173X').
 1314decade('1740s','174X').
 1315decade('1750s','175X').
 1316decade('1760s','176X').
 1317decade('1770s','177X').
 1318decade('1780s','178X').
 1319decade('1790s','179X').
 1320decade('1800s','180X').
 1321decade('1810s','181X').
 1322decade('1820s','182X').
 1323decade('1830s','183X').
 1324decade('1840s','184X').
 1325decade('1850s','185X').
 1326decade('1860s','186X').
 1327decade('1870s','187X').
 1328decade('1880s','188X').
 1329decade('1890s','189X').
 1330decade('1900s','190X').
 1331decade('1910s','191X').
 1332decade('1920s','192X').
 1333decade('1930s','193X').
 1334decade('1940s','194X').
 1335decade('1950s','195X').
 1336decade('1960s','196X').
 1337decade('1970s','197X').
 1338decade('1980s','198X').
 1339decade('1990s','199X').
 1340decade('2000s','200X').
 1341
 1342
 1343/*========================================================================
 1344   Days
 1345========================================================================*/
 1346
 1347day(1,'01').
 1348day('1st','01').
 1349day(2,'02').
 1350day('2nd','02').
 1351day(3,'03').
 1352day('3rd','03').
 1353day(4,'04').
 1354day('4th','04').
 1355day(5,'05').
 1356day('5th','05').
 1357day(6,'06').
 1358day('6th','06').
 1359day(7,'07').
 1360day('7th','07').
 1361day(8,'08').
 1362day('8th','08').
 1363day(9,'09').
 1364day('9th','09').
 1365day(10,'10').
 1366day('10th','10').
 1367day(11,'11').
 1368day('11th','11').
 1369day(12,'12').
 1370day('12th','12').
 1371day(13,'13').
 1372day('13th','13').
 1373day(14,'14').
 1374day('14th','14').
 1375day(15,'15').
 1376day('15th','15').
 1377day(16,'16').
 1378day('16th','16').
 1379day(17,'17').
 1380day('17th','17').
 1381day(18,'18').
 1382day('18th','18').
 1383day(19,'19').
 1384day('19th','19').
 1385day(20,'20').
 1386day('20th','20').
 1387day(21,'21').
 1388day('21st','21').
 1389day(22,'22').
 1390day('22nd','22').
 1391day(23,'23').
 1392day('23rd','23').
 1393day(24,'24').
 1394day('24th','24').
 1395day(25,'25').
 1396day('25th','25').
 1397day(26,'26').
 1398day('26th','26').
 1399day(27,'27').
 1400day('27th','27').
 1401day(28,'28').
 1402day('28th','28').
 1403day(29,'29').
 1404day('29th','29').
 1405day(30,'30').
 1406day('30th','30').
 1407day(31,'31').
 1408day('31st','31').
 1409
 1410
 1411/*========================================================================
 1412   Hours
 1413========================================================================*/
 1414
 1415hour(1,am,'01'):-! .
 1416hour(2,am,'02'):-!.
 1417hour(3,am,'03'):-!.
 1418hour(4,am,'04'):-!.
 1419hour(5,am,'05'):-!.
 1420hour(6,am,'06'):-!.
 1421hour(7,am,'07'):-!.
 1422hour(8,am,'08'):-!.
 1423hour(9,am,'09'):-!.
 1424hour(10,am,'10'):-!.
 1425hour(11,am,'11'):-!.
 1426hour(12,am,'12'):-!.
 1427
 1428hour(1,pm,'13'):-! .
 1429hour(2,pm,'14'):-!.
 1430hour(3,pm,'15'):-!.
 1431hour(4,pm,'16'):-!.
 1432hour(5,pm,'17'):-!.
 1433hour(6,pm,'18'):-!.
 1434hour(7,pm,'19'):-!.
 1435hour(8,pm,'20'):-!.
 1436hour(9,pm,'21'):-!.
 1437hour(10,pm,'22'):-!.
 1438hour(11,pm,'23'):-!.
 1439hour(12,pm,'00'):-!.
 1440
 1441minute(Min,MinID):-
 1442   atom_chars(Min,[M1,M2]),
 1443   atom_chars(MinID,[M1,M2]).
 1444
 1445
 1446gmt(GMT,Hour,Minutes):-
 1447   atom_chars(GMT,[H1,H2,M1,M2]),
 1448   atom_chars(Hour,[H1,H2]),
 1449   atom_chars(Minutes,[M1,M2]).
 1450
 1451
 1452/*========================================================================
 1453   Dimensions
 1454========================================================================*/
 1455
 1456dimension(big,size,1).
 1457dimension(small,size,1). 
 1458dimension(large,size,1).
 1459dimension(measurement,size,1).
 1460dimension(close,distance,1).
 1461dimension(far,distance,1).
 1462dimension(cold,temperature,1).
 1463dimension(hot,temperature,1).
 1464dimension(deep,depth,1).
 1465dimension(fast,speed,1).
 1466dimension(heavy,weight,1).
 1467dimension(high,height,1).
 1468dimension(tall,height,1).
 1469dimension(late,timing,1).
 1470dimension(long,length,1).
 1471dimension(wide,width,1).
 1472dimension(broad,breadth,1).
 1473dimension(often,frequency,1).
 1474dimension(old,age,1).
 1475dimension(young,age,1).
 1476
 1477
 1478/*========================================================================
 1479   Quoted strings
 1480========================================================================*/
 1481
 1482quoted(Pred):-
 1483   atom(Pred), 
 1484   atom_chars(Pred,['l','q','o','-'|_]), !.
 1485
 1486
 1487/*========================================================================
 1488   URL 
 1489========================================================================*/
 1490
 1491url(Pred):-
 1492   atom(Pred),
 1493   atom_chars(Pred,Codes),  
 1494   ( Codes = [w,w,w,_,_,_|_] ; Codes = [h,t,t,p,_,_,_,_|_] ), !.
 1495
 1496
 1497/*========================================================================
 1498   Email 
 1499========================================================================*/
 1500
 1501email(Pred):-
 1502   atom(Pred),
 1503   atom_chars(Pred,Codes),  
 1504   member('.',Codes),
 1505   member('@',Codes), !.
 1506
 1507
 1508/*========================================================================
 1509   Postprocessing Words
 1510========================================================================*/
 1511
 1512ppWords([],_,[],[]).
 1513
 1514ppWords([word(I,W1)|L1],OldPos,[word(I,W2)|L2],[word(I,W2,OldPos,NewPos)|L3]):-
 1515   atom(W1), 
 1516   atom_chars(W1,C1),
 1517   length(C1,Len),
 1518   C1 = ['L','Q','O','-'|_], !,
 1519   convertQuotes(C1,C2),      
 1520   atom_chars(W2,C2),
 1521   NewPos is OldPos + Len - 1,
 1522   NextPos is NewPos + 2,
 1523   ppWords(L1,NextPos,L2,L3).
 1524
 1525ppWords([word(I,W)|L1],OldPos,[word(I,W)|L2],[word(I,W,OldPos,NewPos)|L3]):-
 1526   atom_codes(W,C1), 
 1527   removeSpecialChars(C1,C2),
 1528   length(C2,Len),
 1529   NewPos is OldPos + Len - 1,
 1530   NextPos is NewPos + 2,
 1531   ppWords(L1,NextPos,L2,L3).
 1532
 1533ppWords([word(I,W,P1,P2)|L1],Pos,[word(I,W)|L2],[word(I,W,P1,P2)|L3]):-
 1534   ppWords(L1,Pos,L2,L3).
 1535
 1536
 1537removeSpecialChars([],[]).
 1538removeSpecialChars([194|L1],L2):- !, removeSpecialChars(L1,L2).
 1539removeSpecialChars([195|L1],L2):- !, removeSpecialChars(L1,L2).
 1540removeSpecialChars([X|L1],[X|L2]):- !, removeSpecialChars(L1,L2).
 1541
 1542
 1543/*========================================================================
 1544   Postprocessing quoted strings
 1545========================================================================*/
 1546
 1547convertQuotes([],[]).
 1548
 1549convertQuotes(['L','Q','O','-'|L1],['"'|L2]):- !,
 1550   convertQuotes(L1,L2).
 1551
 1552convertQuotes(['-','R','Q','O'|L1],['"'|L2]):- !,
 1553   convertQuotes(L1,L2).
 1554
 1555convertQuotes(['-'|L1],[' '|L2]):- !,
 1556   convertQuotes(L1,L2).
 1557
 1558convertQuotes([X|L1],[X|L2]):-
 1559   convertQuotes(L1,L2)