% file: dict.p % version 1.04 % dictionary(Word, Pos, Listing). dictionary(bluebird,noun,[[type, reg]]). dictionary(lily,noun,[[type, reg]]). dictionary(moose,noun,[[type, irr], [singular, moose], [plural, moose]]). dictionary(goose,noun,[[type, irr], [singular, goose], [plural, geese]]). dictionary(run,verb,[[type, irr], [singular, runs], [plural, run],[past, ran]]). dictionary(fly,verb,[[type, irr], [singular, flies], [plural, fly], [past, flew]]). dictionary(grow,verb,[[type, irr], [singular, grows], [plural, grow],[past, grew]]). dictionary(do,verb,[[type, irr], [singular, does], [plural, do],[past, did]]). dictionary(this,det,[[singular, this], [plural, these]]). dictionary(that,det,[[singular, that], [plural, those]]). dictionary(the,det, [[singular, the], [plural, the]]). dictionary(a,det, [[singular, a], [plural, the]]). dictionary(high,adv,[[singular, high], [plural, high]]). dictionary(fast,adv,[[singular, fast], [plural, fast]]). dictionary(far,adv,[[singular, far], [plural, far]]). dictionary(quickly,adv,[[singular, quickly], [plural, quickly]]). dictionary(slowly,adv,[[singular, slowly], [plural, slowly]]). pos(Word,Pos) :- dictionary(Word,Pos,_). in_dict(Word) :- dictionary(Word,_,_). in_dict(Word) :- in_dictionary(Word,_). % in_dictionary(+Word, ?Entry) in_dictionary(Word,Word) :- dictionary(Word,_,_). in_dictionary(Word,Entry) :- singular_of(_,Word,Entry). in_dictionary(Word,Entry) :- plural_of(_,Word,Entry). % singular_of(Word,Singular,Entry) :: Word has singular Singular under % entry Entry singular_of(Word,Singular,Word) :- dictionary(Word,Pos,Listing), get(singular,Word,Pos,Listing,Singular), !. singular_of(Word,Singular,Entry) :- dictionary(Entry,Pos,Listing), in_listing(Word,Listing), get(singular,Word,Pos,Listing,Singular), !. singular_of(Word,Word,Word) :- dictionary(Word,_,_). singular_of(Word,Word,Entry) :- dictionary(Entry,_,Listing), in_listing(Word,Listing). % plural_of(Word,Plural,Entry) :: Word has plural Plural under % entry Entry plural_of(Word,Plural,Word) :- dictionary(Word,Pos,Listing), get(plural,Word,Pos,Listing,Plural), !. plural_of(Word,Plural,Entry) :- dictionary(Entry,Pos,Listing), in_listing(Word,Listing), get(plural,Entry,Pos,Listing,Plural), !. plural_of(Word,Word,Word) :- dictionary(Word,_,_). plural_of(Word,Word,Entry) :- dictionary(Entry,_,Listing), in_listing(Word,Listing). in_listing(Word,[[_, Word] | _]). in_listing(Word,[_ | Rest]) :- in_listing(Word,Rest). extract(Attribute,[[Attribute, Value] | _], Value). extract(Attribute,[_ | Rest], Value) :- extract(Attribute,Rest,Value). get(Attribute,Word,Pos,Listing,Value) :- extract(type,Listing,reg), do_get(Attribute,Word,Pos,Value). get(Attribute,_,_,Listing,Value) :- extract(type,Listing,irr), extract(Attribute,Listing,Value). do_get(singular,Word,noun,Word). do_get(plural,Word,verb,Word). do_get(plural,Word,noun,Plural) :- concat(Word,s,Plural). do_get(singular,Word,verb,Plural) :- concat(Word,s,Plural).