terminal(C, A, B, x(_,terminal,C,D), D) :-
        A=B.
terminal(E, [E|B], C, A, D) :-
        gap(A, B, C, A, D).
gap(x(gap,_,_,_), A, A, B, B).
gap([], A, A, B, B).
virtual(C, A, B, x(_,nonterminal,C,D), D) :-
        A=B.
xgphrase(D, E, F) :-
        tag(D, E, C, F, B, A),
        A,
        C=[],
        B=[].
test(time-A) :-
        statistics(runtime, _),
        chat_parser,
        statistics(runtime, [_,A]).
chat_parser :-
        ten,
        string(A),
        determinate_say(A, _),
        fail.
chat_parser.
string([what,rivers,are,there,?]).
string([does,afghanistan,border,china,?]).
string([what,is,the,capital,of,upper_volta,?]).
string([where,is,the,largest,country,?]).
string([which,country,quote,s,capital,is,london,?]).
string([which,countries,are,european,?]).
string([how,large,is,the,smallest,american,country,?]).
string([what,is,the,ocean,that,borders,african,countries,and,that,borders,asian,countries,?]).
string([what,are,the,capitals,of,the,countries,bordering,the,baltic,?]).
string([which,countries,are,bordered,by,two,seas,?]).
string([how,many,countries,does,the,danube,flow,through,?]).
string([what,is,the,total,area,of,countries,south,of,the,equator,and,not,in,australasia,?]).
string([what,is,the,average,area,of,the,countries,in,each,continent,?]).
string([is,there,more,than,one,country,in,each,continent,?]).
string([is,there,some,ocean,that,does,not,border,any,country,?]).
string([what,are,the,countries,from,which,a,river,flows,into,the,black_sea,?]).
determinate_say(A, B) :-
        say(A, B), !.
is_pp(#(1,_,_,_)).
is_pred(#(_,1,_,_)).
is_chat_trace(#(_,_,1,_)).
is_adv(#(_,_,_,1)).
chat_trace(#(_,_,1,_), #(0,0,0,0)).
chat_trace(#(0,0,1,0)).
adv(#(0,0,0,1)).
empty(#(0,0,0,0)).
np_all(#(1,1,1,0)).
s_all(#(1,0,1,1)).
np_no_chat_trace(#(1,1,0,0)).
myplus(#(J,G,D,A), #(K,H,E,B), #(L,I,F,C)) :-
        or(J, K, L),
        or(G, H, I),
        or(D, E, F),
        or(A, B, C).
minus(#(J,G,D,A), #(K,H,E,B), #(L,I,F,C)) :-
        anot(J, K, L),
        anot(G, H, I),
        anot(D, E, F),
        anot(A, B, C).
or(1, _, 1).
or(0, 1, 1).
or(0, 0, 0).
anot(A, 0, A).
anot(_, 1, 0).
role(subj, _, #(1,0,0)).
role(compl, _, #(0,_,_)).
role(undef, main, #(_,0,_)).
role(undef, aux, #(0,_,_)).
role(undef, decl, _).
role(nil, _, _).
subj_case(#(1,0,0)).
verb_case(#(0,1,0)).
prep_case(#(0,0,1)).
compl_case(#(0,_,_)).
say(A, B) :-
        xgphrase(sentence(B), A, []).
xg__sentence(E, F, B, G, D) :-
        xg__declarative(E, F, A, G, C),
        xg__terminator('.', A, B, C, D).
xg__sentence(E, F, B, G, D) :-
        xg__wh_question(E, F, A, G, C),
        xg__terminator(?, A, B, C, D).
xg__sentence(E, H, B, I, D) :-
        xg__topic(G, H, F, I),
        xg__wh_question(E, F, A, G, C),
        xg__terminator(?, A, B, C, D).
xg__sentence(E, F, B, G, D) :-
        xg__yn_question(E, F, A, G, C),
        xg__terminator(?, A, B, C, D).
xg__sentence(E, F, B, G, D) :-
        xg__imperative(E, F, A, G, C),
        xg__terminator(!, A, B, C, D).
xg__pp(E, A, B, C, D, F, G, H) :-
        C=x(_,nonterminal,pp(E,F,G,H),D),
        A=B.
xg__pp(pp(J,A), K, C, L, E, G, H, I) :-
        xg__prep(J, K, B, L, D),
        prep_case(F),
        xg__np(A, B, C, D, E, _, F, _, G, H, I).
xg__topic(A, I, G, J) :-
        xg__pp(C, I, F, J, H, compl, D, E),
        xg__opt_comma(B, F, G, H),
        x(gap,nonterminal,pp(C,compl,D,E),B)=A.
xg__opt_comma(D, A, B, C) :-
        xg__quote(',', A, B, C, D).
xg__opt_comma(A, B, B, A).
xg__declarative(decl(A), B, C, D, E) :-
        xg__s(A, B, C, D, E, _).
xg__wh_question(whq(H,G), I, C, J, E) :-
        xg__variable_q(H, I, B, J, D, _, A, F),
        xg__question(A, B, C, D, E, F, G).
xg__np(E, A, B, C, D, F, G, H, I, J, K) :-
        C=x(_,nonterminal,np(E,F,G,H,I,J,K),D),
        A=B.
xg__np(np(I,D,[]), E, F, G, H, I, B, def, _, J, C) :-
        is_pp(J),
        xg__pers_pron(D, E, F, G, H, I, A),
        empty(C),
        role(A, decl, B).
xg__np(np(F,K,N), L, C, M, E, F, _, O, G, P, J) :-
        is_pp(P),
        xg__np_head(K, L, B, M, D, F, O+A, H, N),
        np_all(I),
        xg__np_compls(A, B, C, D, E, F, G, H, I, J).
xg__np(part(L,A), M, C, N, E, 3+O, _, indef, G, P, I) :-
        is_pp(P),
        xg__determiner(L, M, J, N, K, O, indef),
        xg__quote(of, J, B, K, D),
        s_all(H),
        prep_case(F),
        xg__np(A, B, C, D, E, 3+plu, F, def, G, H, I).
xg__variable_q(H, I, J, K, A, D, L, E) :-
        xg__whq(H, I, J, K, B, D, C, L),
        chat_trace(F, G),
        x(gap,nonterminal,np(C,D,E,_,_,F,G),B)=A.
xg__variable_q(H, M, J, N, A, L, compl, G) :-
        xg__prep(E, M, I, N, K),
        xg__whq(H, I, J, K, B, L, F, _),
        chat_trace(C, D),
        compl_case(G),
        x(gap,nonterminal,pp(pp(E,F),compl,C,D),B)=A.
xg__variable_q(H, J, K, L, A, F, compl, I) :-
        xg__context_pron(E, J, K, L, B, G),
        chat_trace(C, D),
        verb_case(I),
        x(gap,nonterminal,adv_phrase(pp(E,np(F,np_head(int_det(H),[],G),[])),C,D),B)=A.
xg__variable_q(E, J, H, K, A, _, compl, F) :-
        xg__quote(how, J, G, K, I),
        xg__adj(quant, G, H, I, B, D),
        empty(C),
        verb_case(F),
        x(gap,nonterminal,predicate(adj,value(D,wh(E)),C),B)=A.
xg__adv_phrase(E, A, B, C, D, F, G) :-
        C=x(_,nonterminal,adv_phrase(E,F,G),D),
        A=B.
xg__adv_phrase(pp(H,G), I, B, J, D, E, F) :-
        xg__loc_pred(H, I, A, J, C),
        xg__pp(pp(prep(of),G), A, B, C, D, compl, E, F).
xg__predicate(E, A, B, C, D, F, G) :-
        C=x(_,nonterminal,predicate(E,F,G),D),
        A=B.
xg__predicate(_, B, C, D, E, A, F) :-
        xg__adj_phrase(A, B, C, D, E, F).
xg__predicate(neg, B, C, D, E, A, G) :-
        s_all(F),
        xg__pp(A, B, C, D, E, compl, F, G).
xg__predicate(_, B, C, D, E, A, G) :-
        s_all(F),
        xg__adv_phrase(A, B, C, D, E, F, G).
xg__whq(H, I, C, J, E, F, A, undef) :-
        xg__int_det(H, I, B, J, D, F),
        s_all(G),
        xg__np(A, B, C, D, E, F, _, _, subj, G, _).
xg__whq(F, B, C, D, E, 3+G, np(3+G,wh(F),[]), A) :-
        xg__int_pron(A, B, C, D, E).
xg__int_det(A, B, C, D, E, 3+F) :-
        xg__whose(A, B, C, D, E, F).
xg__int_det(A, B, C, D, E, 3+F) :-
        xg__int_art(A, B, C, D, E, F).
xg__gen_marker(D, A, B, C) :-
        C=x(_,nonterminal,gen_marker,D),
        A=B.
xg__gen_marker(A, E, C, F) :-
        xg__quote(quote, E, B, F, D),
        xg__an_s(A, B, C, D).
xg__np_head0(E, A, B, C, D, F, G) :-
        C=x(_,nonterminal,np_head0(E,F,G),D),
        A=B.
xg__np_head0(name(A), B, C, D, E, 3+sin, def+proper) :-
        xg__name(A, B, C, D, E).
xg__np_head0(np_head(J,G,A), K, C, L, E, 3+F, M+common) :-
        xg__determiner(J, K, H, L, I, F, M),
        xg__adjs(G, H, B, I, D),
        xg__noun(A, B, C, D, E, F).
xg__np_head0(C, D, E, F, A, G, def+proper) :-
        xg__poss_pron(C, D, E, F, B, G),
        x(nogap,nonterminal,gen_marker,B)=A.
xg__np_head0(np_head(A,[],F), B, C, D, E, 3+sin, indef+common) :-
        xg__quantifier_pron(A, B, C, D, E, F).
xg__whose(D, E, F, G, A, C) :-
        xg__quote(whose, E, F, G, B),
        x(nogap,nonterminal,np_head0(wh(D),C,proper),x(nogap,nonterminal,gen_marker,B))=A.
xg__question(G, B, C, D, E, F, A) :-
        subj_question(G),
        role(subj, _, F),
        xg__s(A, B, C, D, E, _).
xg__question(F, G, C, H, E, I, A) :-
        xg__fronted_verb(F, G, B, H, D, I),
        xg__s(A, B, C, D, E, _).
xg__det(E, A, B, C, D, F, G) :-
        C=x(_,nonterminal,det(E,F,G),D),
        A=B.
xg__det(det(C), E, F, G, H, B, D) :-
        terminal(A, E, F, G, H),
        det(A, B, C, D).
xg__det(generic, A, A, B, B, _, generic).
xg__int_art(E, F, G, H, A, D) :-
        xg__int_art(E, F, G, H, B, D, C),
        x(nogap,nonterminal,det(C,D,def),B)=A.
subj_question(subj).
subj_question(undef).
xg__yn_question(q(A), F, C, G, E) :-
        xg__fronted_verb(nil, F, B, G, D, _),
        xg__s(A, B, C, D, E, _).
xg__verb_form(E, A, B, C, D, F, G, H) :-
        C=x(_,nonterminal,verb_form(E,F,G,H),D),
        A=B.
xg__verb_form(B, E, F, G, H, C, D, _) :-
        terminal(A, E, F, G, H),
        verb_form(A, B, C, D).
xg__neg(E, A, B, C, D, F) :-
        C=x(_,nonterminal,neg(E,F),D),
        A=B.
xg__neg(aux+_, A, B, C, D, neg) :-
        xg__quote(not, A, B, C, D).
xg__neg(_, A, A, B, B, pos).
xg__fronted_verb(K, M, I, N, A, L) :-
        xg__verb_form(D, M, H, N, J, E, F, _),
        verb_type(D, aux+_),
        role(K, G, L),
        xg__neg(_, H, I, J, B, C),
        x(gap,nonterminal,verb_form(D,E,F,G),x(nogap,nonterminal,neg(_,C),B))=A.
xg__imperative(imp(A), F, C, G, E) :-
        xg__imperative_verb(D, F, B, G),
        xg__s(A, B, C, D, E, _).
xg__imperative_verb(A, D, E, F) :-
        xg__verb_form(C, D, E, F, B, inf, _, _),
        x(nogap,terminal,you,x(nogap,nonterminal,verb_form(C,imp+fin,2+sin,main),B))=A.
xg__s(s(U,Q,O,A), V, C, W, E, H) :-
        xg__subj(U, V, R, W, S, T, K),
        xg__verb(Q, R, L, S, M, T, K, N),
        empty(P),
        s_all(I),
        xg__verb_args(K, L, B, M, D, N, O, P, J),
        minus(I, J, F),
        myplus(I, J, G),
        xg__verb_mods(A, B, C, D, E, F, G, H).
xg__subj(there, A, B, C, D, _, _+be) :-
        xg__quote(there, A, B, C, D).
xg__subj(A, B, C, D, E, F, _) :-
        s_all(H),
        subj_case(G),
        xg__np(A, B, C, D, E, F, G, _, subj, H, _).
xg__np_head(I, N, C, O, E, J, K, L, M) :-
        xg__np_head0(A, N, B, O, D, F, G),
        xg__possessive(A, B, C, D, E, F, G, H, H, I, J, K, L, M).
xg__np_compls(proper, B, B, C, C, _, _, [], _, A) :-
        empty(A).
xg__np_compls(common, J, C, K, E, A, L, M, N, I) :-
        np_all(O),
        xg__np_mods(A, J, B, K, D, L, F, M, N, G, O, H),
        xg__relative(A, B, C, D, E, F, G, H, I).
xg__possessive(O, S, C, T, E, N, _, [], P, I, J, K, L, M) :-
        xg__gen_case(R, S, Q, T),
        xg__np_head0(A, Q, B, R, D, F, G),
        xg__possessive(A, B, C, D, E, F, G, H, [pp(poss,np(N,O,P))|H], I, J, K, L, M).
xg__possessive(A, B, B, C, C, D, E, F, G, A, D, E, F, G).
xg__gen_case(A, C, D, E) :-
        xg__gen_marker(B, C, D, E),
        x(nogap,terminal,the,B)=A.
xg__an_s(D, A, B, C) :-
        xg__quote(s, A, B, C, D).
xg__an_s(A, B, B, A).
xg__determiner(A, B, C, D, E, F, G) :-
        xg__det(A, B, C, D, E, F, G).
xg__determiner(A, B, C, D, E, F, G) :-
        xg__quant_phrase(A, B, C, D, E, F, G).
xg__quant_phrase(quant(G,A), H, C, I, E, F, J) :-
        xg__quant(G, H, B, I, D, J),
        xg__number(A, B, C, D, E, F).
xg__quant(J, H, B, I, D, indef) :-
        xg__neg_adv(E, H, F, I, G, J),
        xg__comp_adv(E, F, A, G, C),
        xg__quote(than, A, B, C, D).
xg__quant(B, G, D, H, F, indef) :-
        xg__quote(at, G, C, H, E),
        xg__sup_adv(A, C, D, E, F),
        sup_op(A, B).
xg__quant(the, A, B, C, D, def) :-
        xg__quote(the, A, B, C, D).
xg__quant(same, A, A, B, B, indef).
xg__neg_adv(E, A, B, C, D, not+E) :-
        xg__quote(not, A, B, C, D).
xg__neg_adv(A, B, B, C, C, A).
sup_op(least, not+less).
sup_op(most, not+more).
xg__np_mods(A, Q, C, R, E, F, G, [S|H], N, J, _, L) :-
        xg__np_mod(A, Q, B, R, D, F, S, N, M),
        chat_trace(P),
        myplus(P, M, O),
        minus(N, O, I),
        myplus(M, N, K),
        xg__np_mods(A, B, C, D, E, F, G, H, I, J, K, L).
xg__np_mods(_, A, A, B, B, _, C, C, D, D, E, E).
xg__np_mod(_, B, C, D, E, F, A, G, H) :-
        xg__pp(A, B, C, D, E, F, G, H).
xg__np_mod(A, B, C, D, E, _, F, G, H) :-
        xg__reduced_relative(A, B, C, D, E, F, G, H).
xg__verb_mods([M|A], N, C, O, E, J, _, H) :-
        xg__verb_mod(M, N, B, O, D, J, I),
        chat_trace(L),
        myplus(L, I, K),
        minus(J, K, F),
        myplus(I, J, G),
        xg__verb_mods(A, B, C, D, E, F, G, H).
xg__verb_mods([], A, A, B, B, _, C, C).
xg__verb_mod(A, B, C, D, E, F, G) :-
        xg__adv_phrase(A, B, C, D, E, F, G).
xg__verb_mod(B, C, D, E, F, G, A) :-
        is_adv(G),
        xg__adverb(B, C, D, E, F),
        empty(A).
xg__verb_mod(A, B, C, D, E, F, G) :-
        xg__pp(A, B, C, D, E, compl, F, G).
xg__adjs([F|A], G, C, H, E) :-
        xg__pre_adj(F, G, B, H, D),
        xg__adjs(A, B, C, D, E).
xg__adjs([], A, A, B, B).
xg__pre_adj(E, A, B, C, D) :-
        xg__adj(_, A, B, C, D, E).
xg__pre_adj(A, B, C, D, E) :-
        xg__sup_phrase(A, B, C, D, E).
xg__sup_phrase(sup(most,A), B, C, D, E) :-
        xg__sup_adj(A, B, C, D, E).
xg__sup_phrase(sup(F,E), G, B, H, D) :-
        xg__sup_adv(F, G, A, H, C),
        xg__adj(quant, A, B, C, D, E).
xg__comp_phrase(comp(I,L,A), J, C, K, E, H) :-
        xg__comp(I, J, B, K, D, L),
        np_no_chat_trace(G),
        prep_case(F),
        xg__np(A, B, C, D, E, _, F, _, compl, G, H).
xg__comp(H, I, B, J, D, G) :-
        xg__comp_adv(H, I, E, J, F),
        xg__adj(quant, E, A, F, C, G),
        xg__quote(than, A, B, C, D).
xg__comp(more, F, B, G, D, E) :-
        xg__rel_adj(E, F, A, G, C),
        xg__quote(than, A, B, C, D).
xg__comp(same, H, B, I, D, G) :-
        xg__quote(as, H, E, I, F),
        xg__adj(quant, E, A, F, C, G),
        xg__quote(as, A, B, C, D).
xg__relative(A, B, C, D, E, [F], H, _, G) :-
        is_pred(H),
        xg__rel_conj(A, B, C, D, E, _, F, G).
xg__relative(_, A, A, B, B, [], _, C, C).
xg__rel_conj(A, K, C, L, E, F, H, J) :-
        xg__rel(A, K, B, L, D, G, I),
        xg__rel_rest(A, B, C, D, E, F, G, H, I, J).
xg__rel_rest(A, J, C, K, E, I, L, M, _, H) :-
        xg__conj(I, J, B, K, D, F, L, G, M),
        xg__rel_conj(A, B, C, D, E, F, G, H).
xg__rel_rest(_, A, A, B, B, _, C, C, D, D).
xg__rel(K, O, C, P, A, rel(N,H), G) :-
        xg__o_p_e_n(M, O, L, P),
        xg__variable(K, L, I, M, J, N),
        xg__s(H, I, B, J, D, E),
        chat_trace(F),
        minus(E, F, G),
        xg__close(A, B, C, D).
xg__variable(C, G, H, I, A, F) :-
        xg__quote(that, G, H, I, B),
        chat_trace(D, E),
        x(gap,nonterminal,np(np(C,wh(F),[]),C,_,_,_,D,E),B)=A.
xg__variable(L, I, J, K, A, H) :-
        xg__wh(H, I, J, K, B, L, C, D, E),
        chat_trace(F, G),
        x(gap,nonterminal,np(C,D,E,_,_,F,G),B)=A.
xg__variable(L, M, J, N, A, H) :-
        xg__prep(E, M, I, N, K),
        xg__wh(H, I, J, K, B, L, F, _, G),
        chat_trace(C, D),
        compl_case(G),
        x(gap,nonterminal,pp(pp(E,F),compl,C,D),B)=A.
xg__wh(G, C, D, E, F, H, np(H,wh(G),[]), H, B) :-
        xg__rel_pron(A, C, D, E, F),
        role(A, decl, B).
xg__wh(A, L, C, M, E, F, np(N,K,[pp(H,G)]), N, _) :-
        xg__np_head0(K, L, I, M, J, N, _+common),
        xg__prep(H, I, B, J, D),
        xg__wh(A, B, C, D, E, F, G, _, _).
xg__wh(I, J, C, K, E, L, A, F, G) :-
        xg__whose(I, J, B, K, D, L),
        s_all(H),
        xg__np(A, B, C, D, E, F, G, def, subj, H, _).
xg__reduced_relative(A, B, C, D, E, F, H, G) :-
        is_pred(H),
        xg__reduced_rel_conj(A, B, C, D, E, _, F, G).
xg__reduced_rel_conj(A, K, C, L, E, F, H, J) :-
        xg__reduced_rel(A, K, B, L, D, G, I),
        xg__reduced_rel_rest(A, B, C, D, E, F, G, H, I, J).
xg__reduced_rel_rest(A, J, C, K, E, I, L, M, _, H) :-
        xg__conj(I, J, B, K, D, F, L, G, M),
        xg__reduced_rel_conj(A, B, C, D, E, F, G, H).
xg__reduced_rel_rest(_, A, A, B, B, _, C, C, D, D).
xg__reduced_rel(K, O, C, P, A, reduced_rel(N,H), G) :-
        xg__o_p_e_n(M, O, L, P),
        xg__reduced_wh(K, L, I, M, J, N),
        xg__s(H, I, B, J, D, E),
        chat_trace(F),
        minus(E, F, G),
        xg__close(A, B, C, D).
xg__reduced_wh(F, N, L, O, A, J) :-
        xg__neg(_, N, K, O, M, C),
        xg__predicate(C, K, L, M, B, D, E),
        chat_trace(H, I),
        subj_case(G),
        x(nogap,nonterminal,np(np(F,wh(J),[]),F,G,_,_,H,I),x(nogap,nonterminal,verb_form(be,pres+fin,F,main),x(nogap,nonterminal,neg(_,C),x(nogap,nonterminal,predicate(C,D,E),B))))=A.
xg__reduced_wh(F, K, L, M, A, J) :-
        xg__participle(C, K, L, M, B, D, E),
        chat_trace(H, I),
        subj_case(G),
        x(nogap,nonterminal,np(np(F,wh(J),[]),F,G,_,_,H,I),x(nogap,nonterminal,verb(C,_,D,E),B))=A.
xg__reduced_wh(C, N, O, P, A, G) :-
        s_all(Q),
        subj_case(J),
        verb_case(D),
        xg__np(H, N, O, P, B, I, _, K, subj, Q, _),
        chat_trace(L, M),
        chat_trace(E, F),
        x(nogap,nonterminal,np(H,I,J,K,_,L,M),x(gap,nonterminal,np(np(C,wh(G),[]),C,D,_,_,E,F),B))=A.
xg__verb(E, A, B, C, D, F, G, H) :-
        C=x(_,nonterminal,verb(E,F,G,H),D),
        A=B.
xg__verb(verb(A,I,R+fin,J,N), O, E, P, G, Q, B, I) :-
        xg__verb_form(H, O, L, P, M, R+fin, Q, C),
        verb_type(H, K),
        xg__neg(K, L, D, M, F, N),
        xg__rest_verb(C, D, E, F, G, H, A, I, J),
        verb_type(A, B).
xg__rest_verb(aux, I, C, J, E, have, F, G, [perf|H]) :-
        xg__verb_form(A, I, B, J, D, past+part, _, _),
        xg__have(A, B, C, D, E, F, G, H).
xg__rest_verb(aux, J, C, K, E, be, G, H, I) :-
        xg__verb_form(F, J, B, K, D, A, _, _),
        xg__be(A, B, C, D, E, F, G, H, I).
xg__rest_verb(aux, B, C, D, E, do, A, active, []) :-
        xg__verb_form(A, B, C, D, E, inf, _, _).
xg__rest_verb(main, A, A, B, B, C, C, active, []).
xg__have(be, J, C, K, E, G, H, I) :-
        xg__verb_form(F, J, B, K, D, A, _, _),
        xg__be(A, B, C, D, E, F, G, H, I).
xg__have(A, B, B, C, C, A, active, []).
xg__be(past+part, A, A, B, B, C, C, passive, []).
xg__be(pres+part, B, C, D, E, A, F, G, [prog]) :-
        xg__passive(A, B, C, D, E, F, G).
xg__passive(be, C, D, E, F, B, passive) :-
        xg__verb_form(B, C, D, E, F, past+part, _, _),
        verb_type(B, A),
        passive(A).
xg__passive(A, B, B, C, C, A, active).
xg__participle(verb(A,D,inf,E,L), J, G, K, I, B, D) :-
        xg__neg(_, J, F, K, H, L),
        xg__verb_form(A, F, G, H, I, C, _, _),
        participle(C, D, E),
        verb_type(A, B).
passive(_+trans).
passive(_+ditrans).
participle(pres+part, active, [prog]).
participle(past+part, passive, []).
xg__close(D, A, B, C) :-
        C=x(_,nonterminal,close,D),
        A=B.
xg__o_p_e_n(A, C, C, B) :-
        x(gap,nonterminal,close,B)=A.
xg__verb_args(_+A, K, C, L, E, F, J, H, I) :-
        xg__advs(J, K, B, L, D, G, _),
        xg__verb_args(A, B, C, D, E, F, G, H, I).
xg__verb_args(trans, A, B, C, D, active, [arg(dir,E)], _, F) :-
        xg__verb_arg(np, A, B, C, D, E, F).
xg__verb_args(ditrans, I, C, J, E, _, [arg(A,K)|F], _, H) :-
        xg__verb_arg(np, I, B, J, D, K, G),
        xg__object(A, B, C, D, E, F, G, H).
xg__verb_args(be, A, B, C, D, _, [void], E, E) :-
        terminal(there, A, B, C, D).
xg__verb_args(be, A, B, C, D, _, [arg(predicate,E)], _, F) :-
        xg__pred_conj(_, A, B, C, D, E, F).
xg__verb_args(be, A, B, C, D, _, [arg(dir,E)], _, F) :-
        xg__verb_arg(np, A, B, C, D, E, F).
xg__verb_args(have, A, B, C, D, active, [arg(dir,E)], _, F) :-
        xg__verb_arg(np, A, B, C, D, E, F).
xg__verb_args(A, B, B, C, C, _, [], D, D) :-
        no_args(A).
xg__object(A, J, C, K, E, I, G, H) :-
        adv(M),
        minus(M, G, L),
        xg__advs(I, J, B, K, D, F, L),
        xg__obj(A, B, C, D, E, F, G, H).
xg__obj(ind, A, B, C, D, [arg(dir,E)], _, F) :-
        xg__verb_arg(np, A, B, C, D, E, F).
xg__obj(dir, A, A, B, B, [], C, C).
xg__pred_conj(A, J, C, K, E, G, I) :-
        xg__predicate(_, J, B, K, D, F, H),
        xg__pred_rest(A, B, C, D, E, F, G, H, I).
xg__pred_rest(H, I, C, J, E, K, L, _, G) :-
        xg__conj(H, I, B, J, D, A, K, F, L),
        xg__pred_conj(A, B, C, D, E, F, G).
xg__pred_rest(_, A, A, B, B, C, C, D, D).
xg__verb_arg(np, B, C, D, E, A, H) :-
        s_all(G),
        verb_case(F),
        xg__np(A, B, C, D, E, _, F, _, compl, G, H).
xg__advs([H|A], I, C, J, E, F, G) :-
        is_adv(G),
        xg__adverb(H, I, B, J, D),
        xg__advs(A, B, C, D, E, F, G).
xg__advs(A, B, B, C, C, A, _).
xg__adj_phrase(F, B, C, D, E, A) :-
        xg__adj(_, B, C, D, E, F),
        empty(A).
xg__adj_phrase(A, B, C, D, E, F) :-
        xg__comp_phrase(A, B, C, D, E, F).
no_args(trans).
no_args(ditrans).
no_args(intrans).
xg__conj(conj(A,F), B, C, D, E, conj(A,G), H, I, conj(A,H,I)) :-
        xg__conj(A, B, C, D, E, F, G).
xg__noun(B, D, E, F, G, C) :-
        terminal(A, D, E, F, G),
        noun_form(A, B, C).
xg__adj(B, C, D, E, F, adj(A)) :-
        terminal(A, C, D, E, F),
        adj(A, B).
xg__prep(prep(A), B, C, D, E) :-
        terminal(A, B, C, D, E),
        prep(A).
xg__rel_adj(adj(B), C, D, E, F) :-
        terminal(A, C, D, E, F),
        rel_adj(A, B).
xg__sup_adj(adj(B), C, D, E, F) :-
        terminal(A, C, D, E, F),
        sup_adj(A, B).
xg__comp_adv(less, A, B, C, D) :-
        xg__quote(less, A, B, C, D).
xg__comp_adv(more, A, B, C, D) :-
        xg__quote(more, A, B, C, D).
xg__sup_adv(least, A, B, C, D) :-
        xg__quote(least, A, B, C, D).
xg__sup_adv(most, A, B, C, D) :-
        xg__quote(most, A, B, C, D).
xg__rel_pron(B, C, D, E, F) :-
        terminal(A, C, D, E, F),
        rel_pron(A, B).
xg__name(A, F, C, G, E) :-
        xg__opt_the(D, F, B, G),
        terminal(A, B, C, D, E),
        name(A).
xg__int_art(G, E, B, F, D, plu, quant(same,wh(G))) :-
        xg__quote(how, E, A, F, C),
        xg__quote(many, A, B, C, D).
xg__int_art(B, E, F, G, H, C, D) :-
        terminal(A, E, F, G, H),
        int_art(A, B, C, D).
xg__int_pron(B, C, D, E, F) :-
        terminal(A, C, D, E, F),
        int_pron(A, B).
xg__adverb(adv(A), B, C, D, E) :-
        terminal(A, B, C, D, E),
        adverb(A).
xg__poss_pron(pronoun(B), E, F, G, H, C+D) :-
        terminal(A, E, F, G, H),
        poss_pron(A, B, C, D).
xg__pers_pron(pronoun(B), F, G, H, I, C+D, E) :-
        terminal(A, F, G, H, I),
        pers_pron(A, B, C, D, E).
xg__quantifier_pron(B, D, E, F, G, C) :-
        terminal(A, D, E, F, G),
        quantifier_pron(A, B, C).
xg__context_pron(prep(in), A, B, C, D, place) :-
        xg__quote(where, A, B, C, D).
xg__context_pron(prep(at), A, B, C, D, time) :-
        xg__quote(when, A, B, C, D).
xg__number(nb(B), D, E, F, G, C) :-
        terminal(A, D, E, F, G),
        number(A, B, C).
xg__terminator(B, C, D, E, F) :-
        terminal(A, C, D, E, F),
        terminator(A, B).
xg__opt_the(A, B, B, A).
xg__opt_the(D, A, B, C) :-
        xg__quote(the, A, B, C, D).
xg__conj(_, A, B, C, D, list, list) :-
        terminal(',', A, B, C, D).
xg__conj(A, B, C, D, E, list, end) :-
        terminal(A, B, C, D, E),
        conj(A).
xg__loc_pred(B, C, D, E, F) :-
        terminal(A, C, D, E, F),
        loc_pred(A, B).
xg__quote(A, B, C, D, E) :-
        terminal(A, B, C, D, E),
        quote(A).
word(A) :-
        quote(A).
word(A) :-
        conj(A).
word(A) :-
        adverb(A).
word(A) :-
        sup_adj(A, _).
word(A) :-
        rel_adj(A, _).
word(A) :-
        adj(A, _).
word(A) :-
        name(A).
word(A) :-
        terminator(A, _).
word(A) :-
        pers_pron(A, _, _, _, _).
word(A) :-
        poss_pron(A, _, _, _).
word(A) :-
        rel_pron(A, _).
word(A) :-
        verb_form(A, _, _, _).
word(A) :-
        noun_form(A, _, _).
word(A) :-
        prep(A).
word(A) :-
        quantifier_pron(A, _, _).
word(A) :-
        number(A, _, _).
word(A) :-
        det(A, _, _, _).
word(A) :-
        int_art(A, _, _, _).
word(A) :-
        int_pron(A, _).
word(A) :-
        loc_pred(A, _).
quote(how).
quote(whose).
quote(there).
quote(of).
quote(quote).
quote(',').
quote(s).
quote(than).
quote(at).
quote(the).
quote(not).
quote(as).
quote(that).
quote(less).
quote(more).
quote(least).
quote(most).
quote(many).
quote(where).
quote(when).
conj(and).
conj(or).
int_pron(what, undef).
int_pron(which, undef).
int_pron(who, subj).
int_pron(whom, compl).
int_art(what, A, _, int_det(A)).
int_art(which, A, _, int_det(A)).
det(the, A, the(A), def).
det(a, sin, a, indef).
det(an, sin, a, indef).
det(every, sin, every, indef).
det(some, _, some, indef).
det(any, _, any, indef).
det(all, plu, all, indef).
det(each, sin, each, indef).
det(no, _, no, indef).
number(C, A, B) :-
        tr_number(C, A),
        ag_number(A, B).
tr_number(nb(A), A).
tr_number(one, 1).
tr_number(two, 2).
tr_number(three, 3).
tr_number(four, 4).
tr_number(five, 5).
tr_number(six, 6).
tr_number(seven, 7).
tr_number(eight, 8).
tr_number(nine, 9).
tr_number(ten, 10).
ag_number(1, sin).
ag_number(A, plu) :-
        A>1.
quantifier_pron(everybody, every, person).
quantifier_pron(everyone, every, person).
quantifier_pron(everything, every, thing).
quantifier_pron(somebody, some, person).
quantifier_pron(someone, some, person).
quantifier_pron(something, some, thing).
quantifier_pron(anybody, any, person).
quantifier_pron(anyone, any, person).
quantifier_pron(anything, any, thing).
quantifier_pron(nobody, no, person).
quantifier_pron(nothing, no, thing).
prep(as).
prep(at).
prep(of).
prep(to).
prep(by).
prep(with).
prep(in).
prep(on).
prep(from).
prep(into).
prep(through).
noun_form(A, B, plu) :-
        noun_plu(A, B).
noun_form(A, A, sin) :-
        noun_sin(A).
noun_form(proportion, proportion, _).
noun_form(percentage, percentage, _).
root_form(1+sin).
root_form(2+_).
root_form(1+plu).
root_form(3+plu).
verb_root(be).
verb_root(have).
verb_root(do).
verb_root(border).
verb_root(contain).
verb_root(drain).
verb_root(exceed).
verb_root(flow).
verb_root(rise).
regular_pres(have).
regular_pres(do).
regular_pres(rise).
regular_pres(border).
regular_pres(contain).
regular_pres(drain).
regular_pres(exceed).
regular_pres(flow).
regular_past(had, have).
regular_past(bordered, border).
regular_past(contained, contain).
regular_past(drained, drain).
regular_past(exceeded, exceed).
regular_past(flowed, flow).
rel_pron(who, subj).
rel_pron(whom, compl).
rel_pron(which, undef).
poss_pron(my, _, 1, sin).
poss_pron(your, _, 2, _).
poss_pron(his, masc, 3, sin).
poss_pron(her, fem, 3, sin).
poss_pron(its, neut, 3, sin).
poss_pron(our, _, 1, plu).
poss_pron(their, _, 3, plu).
pers_pron(i, _, 1, sin, subj).
pers_pron(you, _, 2, _, _).
pers_pron(he, masc, 3, sin, subj).
pers_pron(she, fem, 3, sin, subj).
pers_pron(it, neut, 3, sin, _).
pers_pron(we, _, 1, plu, subj).
pers_pron(them, _, 3, plu, subj).
pers_pron(me, _, 1, sin, compl(_)).
pers_pron(him, masc, 3, sin, compl(_)).
pers_pron(her, fem, 3, sin, compl(_)).
pers_pron(us, _, 1, plu, compl(_)).
pers_pron(them, _, 3, plu, compl(_)).
terminator('.', _).
terminator(?, ?).
terminator(!, !).
name(_).
loc_pred(east, prep(eastof)).
loc_pred(west, prep(westof)).
loc_pred(north, prep(northof)).
loc_pred(south, prep(southof)).
adj(minimum, restr).
adj(maximum, restr).
adj(average, restr).
adj(total, restr).
adj(african, restr).
adj(american, restr).
adj(asian, restr).
adj(european, restr).
adj(great, quant).
adj(big, quant).
adj(small, quant).
adj(large, quant).
adj(old, quant).
adj(new, quant).
adj(populous, quant).
rel_adj(greater, great).
rel_adj(less, small).
rel_adj(bigger, big).
rel_adj(smaller, small).
rel_adj(larger, large).
rel_adj(older, old).
rel_adj(newer, new).
sup_adj(biggest, big).
sup_adj(smallest, small).
sup_adj(largest, large).
sup_adj(oldest, old).
sup_adj(newest, new).
noun_sin(average).
noun_sin(total).
noun_sin(sum).
noun_sin(degree).
noun_sin(sqmile).
noun_sin(ksqmile).
noun_sin(thousand).
noun_sin(million).
noun_sin(time).
noun_sin(place).
noun_sin(area).
noun_sin(capital).
noun_sin(city).
noun_sin(continent).
noun_sin(country).
noun_sin(latitude).
noun_sin(longitude).
noun_sin(ocean).
noun_sin(person).
noun_sin(population).
noun_sin(region).
noun_sin(river).
noun_sin(sea).
noun_sin(seamass).
noun_sin(number).
noun_plu(averages, average).
noun_plu(totals, total).
noun_plu(sums, sum).
noun_plu(degrees, degree).
noun_plu(sqmiles, sqmile).
noun_plu(ksqmiles, ksqmile).
noun_plu(million, million).
noun_plu(thousand, thousand).
noun_plu(times, time).
noun_plu(places, place).
noun_plu(areas, area).
noun_plu(capitals, capital).
noun_plu(cities, city).
noun_plu(continents, continent).
noun_plu(countries, country).
noun_plu(latitudes, latitude).
noun_plu(longitudes, longitude).
noun_plu(oceans, ocean).
noun_plu(persons, person).
noun_plu(people, person).
noun_plu(populations, population).
noun_plu(regions, region).
noun_plu(rivers, river).
noun_plu(seas, sea).
noun_plu(seamasses, seamass).
noun_plu(numbers, number).
verb_form(A, A, inf, _) :-
        verb_root(A).
verb_form(A, A, pres+fin, B) :-
        regular_pres(A),
        root_form(B),
        verb_root(A).
verb_form(A, B, past+_, _) :-
        regular_past(A, B).
verb_form(am, be, pres+fin, 1+sin).
verb_form(are, be, pres+fin, 2+sin).
verb_form(is, be, pres+fin, 3+sin).
verb_form(are, be, pres+fin, _+plu).
verb_form(was, be, past+fin, 1+sin).
verb_form(were, be, past+fin, 2+sin).
verb_form(was, be, past+fin, 3+sin).
verb_form(were, be, past+fin, _+plu).
verb_form(been, be, past+part, _).
verb_form(being, be, pres+part, _).
verb_form(has, have, pres+fin, 3+sin).
verb_form(having, have, pres+part, _).
verb_form(does, do, pres+fin, 3+sin).
verb_form(did, do, past+fin, _).
verb_form(doing, do, pres+part, _).
verb_form(done, do, past+part, _).
verb_form(flows, flow, pres+fin, 3+sin).
verb_form(flowing, flow, pres+part, _).
verb_form(rises, rise, pres+fin, 3+sin).
verb_form(rose, rise, past+fin, _).
verb_form(risen, rise, past+part, _).
verb_form(borders, border, pres+fin, 3+sin).
verb_form(bordering, border, pres+part, _).
verb_form(contains, contain, pres+fin, 3+sin).
verb_form(containing, contain, pres+part, _).
verb_form(drains, drain, pres+fin, 3+sin).
verb_form(draining, drain, pres+part, _).
verb_form(exceeds, exceed, pres+fin, 3+sin).
verb_form(exceeding, exceed, pres+part, _).
verb_type(have, aux+have).
verb_type(be, aux+be).
verb_type(do, aux+ditrans).
verb_type(rise, main+intrans).
verb_type(border, main+trans).
verb_type(contain, main+trans).
verb_type(drain, main+intrans).
verb_type(exceed, main+trans).
verb_type(flow, main+intrans).
adverb(yesterday).
adverb(tomorrow).
go(A) :-
        test(B),
        nl,
        write(A=[B]),
        nl.
go :-
        go('BMARK_chat:').
p :-
        [chat].
