All pastes #536430 Raw Edit

contract_aux

public text v1 · immutable
·published 2007-06-04 11:46 UTC
rendered paste body
:- ensure_loaded('../morfo/morfo.pl').
:- ensure_loaded('../data/wn_s_mod.pl').
:- ensure_loaded('../data/wn_det.pl').

% cend(?Second, ?CEnd)
cend(is,        s).             % it's (it is)
cend(am,        m).             % I'm   
cend(are,       re).            % they're
cend(has,       s).             % it's (it has)
cend(have,      ve).            % they've
cend(would,     d).             % they'd
cend(had,       d).             % they'd
cend(not,       t).             % can't 
cend(us,        s).             % let's 
cend(will,      ll).            % she'll
cend(and,       n).             % A'n B (tveksam? :)

valid_triple(First,is,Third):- is_first_person_sing(First),\+is_past(Third),!.
valid_triple(_,is,Third):- is_art(Third),!.
valid_triple(_,is,Third):- is_ing(Third),!.
valid_triple(_,is,Third):- is_adj(Third),!.
valid_triple(_,is,Third):- is_adv(Third),!.
valid_triple(_,is,Third):- is_otherwise_pf_compatible(Third),!.
valid_triple(_,has,Third):- is_past(Third),!.
valid_triple(CHead,us,_):- ci_compare(CHead,let),!.     % ok om "let us"
valid_triple(CHead,not,_):- word_ends_with(n,CHead),!.  % "not" ok om CHead slutar på "n"
valid_triple(_,had,Third):- is_past(Third),!.   % "had X" om X är i dåtid
valid_triple(_,would,Third):- \+is_past(Third),!.       %  "would X" om X inte är i dåtid
valid_triple(_,am,_):- !.
valid_triple(_,are,_):- !.
valid_triple(_,have,_):- !.
valid_triple(_,will,_):- !.
valid_triple(_,and,_):- !.
valid_triple(CHead,_,_):- downcase_atom(CHead,CHead_),irregular_chead(CHead_,_,_),!.
valid_triple(CHead,Second,Third):- word_ends_with(n,CHead),reverse_pron_contract(_,Third,Second,_,Third),!.
%             isn,  it,    not                                                   is not   it    It Not

% is_past(+Third)
is_past(Word):- atom(Word),downcase_atom(Word,W),morfo(W,_,Suffix),past_suffix(Suffix).
past_suffix(-en).
past_suffix(-ed).
past_suffix(-past).

% is_adv(+Third)
is_adv(Word):- s(_,_,Adv,r,_,_),ci_compare(Word,Adv).

% is_adj(+Third)
is_adj(Word):- s(_,_,Adj,a,_,_),ci_compare(Word,Adj).
is_adj(Word):- s(_,_,Adj,s,_,_),ci_compare(Word,Adj).

% is_art(+Third)
is_art(Word):- det(_,_,Art,det,_,_),ci_compare(Word,Art).

% is_noun(+Third)
is_noun(Word):- s(_,_,Noun,n,_,_),ci_compare(Word,Noun).

% is_ing(+Third)
is_ing(Word):- atom(Word),downcase_atom(Word,W),morfo(W,_,-ing).

% is_otherwise_pf_compatible(+Third)
is_otherwise_pf_compatible(Word):-
        \+var(Word),
        downcase_atom(Word,W),
        member(W,[
                not,no,neither,either,both,
                before,as,
                here,there,
                i,you,he,she,it,this,that,we,they,
                me,him,us,them,
                my,your,his,her,its,our,their,
                mine,yours,hers,ours,theirs
        ]).

% is_first_person_sing(+Word)
is_first_person_sing(Word):-
        atom(Word),
        downcase_atom(Word,W),
        member(W,[
                he,she,it,
                mine
        ]).

% chead(+CHead, ?NewCHead, ?Second).
chead(CHead,NewCHead,Second):-
        downcase_atom(CHead,CHead_),
        irregular_chead(CHead_,NewCHead,Second).
chead(CHead,NewCHead,not):-
        downcase_atom(CHead,CHead_),
        \+irregular_chead(CHead_,NewCHead,not),
        word_ends_with(n,CHead),
        atom_chars(CHead,List),
        append(NewList,[N],List),
        downcase_atom(N,n),
        atom_chars(NewCHead,NewList),!.
chead(CHead,CHead,_):-
        downcase_atom(CHead,CHead_),
        \+irregular_chead(CHead_,_,_).


% is not it >> is it not
% regular_pron_contract(is, not, it, It, Not)
% regular_pron_contract(?First, ?Second, +Third, ?NewSecond, ?NewThird)
reverse_pron_contract(_,not,Third,Third,not):-
        atom(Third),
        downcase_atom(Third,Third_),
        member(Third_,[ i,you,he,she,it,this,that,we,they,
                        mine,yours,hers,ours,theirs]).

ci_compare(Atom1, Atom2):-
        atom(Atom1),atom(Atom1),
        downcase_atom(Atom1,A1),
        downcase_atom(Atom2,A2),
        A1==A2.