%% an agent wrapper around the prolog version of WordNet 1.7.1 %% Author: Chris Culy %% Date: Summer (northern hemisphere) Solstice 2002 %% Modified: 25 July 2002 %% Copyright 2002 SRI International, All Rights Reserved. %%%%%%%%%%%%%%%%%%% Includes%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%% % agent includes :- use_module(com_tcp, all). :- use_module(oaa, all). % wordnet includes :-ensure_loaded(wn_at). :-ensure_loaded(wn_cs). :-ensure_loaded(wn_ent). :-ensure_loaded(wn_per). :-ensure_loaded(wn_sa). :-ensure_loaded(wn_sim). :-ensure_loaded(wn_vgp). :-ensure_loaded(wn_ant). :-ensure_loaded(wn_fr). :-ensure_loaded(wn_g). :-ensure_loaded(wn_hyp). :-ensure_loaded(wn_mm). :-ensure_loaded(wn_mp). :-ensure_loaded(wn_ms). :-ensure_loaded(wn_ppl). :-ensure_loaded(wn_s). %%%%%%%%%%%%%%%%%%% Initializations %%%%%%%%%%%%%%%%%%%%%%%%%%%%% initial_solvables([ about(_About), wn_get_word(_Wd, _Cat), wn_get_word_info(_Wd, _Cat, _Sense, _Info), wn_get_word_definition(_Wd, _Cat, _Sense, _Def), wn_get_synonymn(_Wd, _Cat, _Sense, _Synonymn), wn_get_antonymn(_Wd, _Cat, _Sense, _Antonymn), wn_get_hypernymn(_Wd, _Cat, _Sense, _Hypernymn), wn_get_hyponymn(_Wd, _Cat, _Sense, _Hyopnymn), wn_get_meronymn(_Wd, _Sense, _Type, _Meronymn), wn_get_holonymn(_Wd, _Sense, _Type, _Holonymn), wn_verify_participial_adj(_Adjective, _Verb), wn_get_verb_frame(_Verb, _Sense, _FrameNumber, _Frame), %simple wrappers for WN preds wn_s(_Synset_id,_W_num,_Word,_Ss_type,_Sense_number,_Tag_count), wn_g(_Synset_id,_Gloss), wn_hyp(_Synset_id,_Synset_id), wn_ent(_Synset_id,_Synset_id), wn_sim(_Synset_id,_Synset_id), wn_mm(_Synset_id,_Synset_id), wn_ms(_Synset_id,_Synset_id), wn_mp(_Synset_id,_Synset_id), wn_cs(_Synset_id,_Synset_id), wn_vgp(_Synset_id,_Synset_id), wn_at(_Synset_id,_Synset_id), wn_ant(_Synset_id,_W_num,_Synset_id,_W_num), wn_sa(_Synset_id,_W_num,_Synset_id,_W_num), wn_ppl(_Synset_id,_W_num,_Synset_id,_W_num), wn_per(_Synset_id,_W_num,_Synset_id,_W_num), wn_fr(_Synset_id,_F_num,_W_num) ]). %standard stuff runtime_entry(start) :- start. start :- initial_solvables(S), com_Connect(parent, [], CInfo), format('Connected to ~p.~n',[CInfo]), oaa_RegisterCallback(app_do_event, user:oaa_AppDoEvent), oaa_Register(parent, sri_wordnet_agent, S, []), app_init, oaa_MainLoop(true). app_init. %%%%%%%Solvables%%%%%%%%%%%%%%% /*Solvable: about(-About) Returns author and copyright information */ oaa_AppDoEvent(about(About)) :- About = 'Version 1.1 Author: Chris Culy Copyright 2002 SRI International, All rights reserved Contact: oaa_staff@sri.com'. /*Solvable: wn_get_word(?Wd, ?Cat) Return a word, category pair from WordNet Mainly useful for looking up all graphemes of a given category. The other 2 relevant solvables (wn_get_word_info, wn_s) won't let OAA filter out duplicates since they contain unique information (e.g. synset) */ oaa_AppDoEvent(wn_get_word(Word, Cat), _GoalParams) :- cat(Cat,RealCat), s(_,_,Word,RealCat,_,_). /* Solvable: wn_get_word_info(?Wd, ?Type, ?Sense, -Info) Looks up a word in word net, returning a list of the args of s/6: synset_id, w_num, quoted word, ss_type, sense_number, tag_count */ oaa_AppDoEvent(wn_get_word_info(Word, Type, SNum, [ID,WNum,Word,Type,SNum,TCount]), _GoalParams) :- s(ID,WNum,Word,Type,SNum,TCount), oaa_TraceMsg('Info:~n ~p~n~n',[ID,WNum,Word,Type,SNum,TCount]). /* Solvable: wn_get_word_definition(+Wd, ?Cat, ?Sense, -Def) Returns the "gloss" of the Wd's synsets If Cat and Sense are not specified, the synset is chosen according to its order in the prolog database. */ oaa_AppDoEvent(wn_get_word_definition(Word, Cat, Sense, Def), _GoalParams) :- cat(Cat, Cat2), s(ID,_,Word,Cat2,Sense,_), g(ID,Def). /* Solvable: wn_get_synonymn(+Wd, ?Cat, ?Sense, -Synonymn) Returns a single synonymn of Wd If Cat and Sense are not specified, the synset is chosen according to its order in the prolog database. */ oaa_AppDoEvent(wn_get_synonymn(Word, Cat, Sense, Syn), _GoalParams) :- cat(Cat, Cat2), s(ID,_,Word,Cat2,Sense,_), s(ID,_,Syn,_,_,_), \+ Word = Syn. /* Solvable: wn_get_antonymn(+Wd, ?Cat, ?Sense, -Antonymn) Returns a single antonymn of Wd If Cat and Sense are not specified, the synset is chosen according to its order in the prolog database. */ oaa_AppDoEvent(wn_get_antonymn(Word, Cat, Sense, Ant), _GoalParams) :- cat(Cat, Cat2), s(ID,WNum,Word,Cat2,Sense,_), ant(ID,WNum,ID2,WNum2), s(ID2,WNum2,Ant,_,_,_). /* Solvable: wn_get_antonymn(+Wd, ?Cat, ?Sense, -Antonymn) Returns a single antonymn of Wd If Cat and Sense are not specified, the synset is chosen according to its order in the prolog database. */ oaa_AppDoEvent(wn_get_antonymn(Word, Cat, Sense, Ant), _GoalParams) :- cat(Cat, Cat2), s(ID,WNum,Word,Cat2,Sense,_), ant(ID,WNum,ID2,WNum2), s(ID2,WNum2,Ant,_,_,_). /* Solvable: wn_get_hypernymn(+Wd, ?Cat, ?Sense, -Hypernymn) Returns a single hypernymn of Wd If Cat and Sense are not specified, the synset is chosen according to its order in the prolog database. */ oaa_AppDoEvent(wn_get_hypernymn(Word, Cat, Sense, Hyper), _GoalParams) :- cat(Cat, Cat2), s(ID,_WNum,Word,Cat2,Sense,_), hyp(ID,ID2), s(ID2,_,Hyper,_,_,_). /* Solvable: wn_get_hyponymn(+Wd, ?Cat, ?Sense, -Hyponymn) Returns a single hyponymn of Wd If Cat and Sense are not specified, the synset is chosen according to its order in the prolog database. */ oaa_AppDoEvent(wn_get_hyponymn(Word, Cat, Sense, Hypo), _GoalParams) :- cat(Cat, Cat2), s(ID,_WNum,Word,Cat2,Sense,_), hyp(ID2,ID), s(ID2,_,Hypo,_,_,_). /* Solvable: wn_get_meronymn(+Wd, ?Sense, ?Type, -Meronymn) Returns a single meronymn of Wd (i.e Wd is part/member/substance of Meronymn) If Cat and Sense are not specified, the synset is chosen according to its order in the prolog database. Type is the type of meronymn: part-of (mp), member-of(mm), substance-of(ms). If it is not specified, any meronymn is returned. */ oaa_AppDoEvent(wn_get_meronymn(Word, Sense, Type, Mero), _GoalParams) :- s(ID,_WNum,Word,n,Sense,_), mer(Type,MerType), meronymn_helper(MerType, ID, ID2), s(ID2,_,Mero,_,_,_). /* Solvable: wn_get_holonymn(+Wd, ?Sense, ?Type, -Holonymn) Returns a single holonymn of Wd (the inverse of meronymn, q.v.) */ oaa_AppDoEvent(wn_get_holonymn(Word, Sense, Type, Holo), _GoalParams) :- s(ID,_WNum,Word,n,Sense,_), mer(Type,MerType), meronymn_helper(MerType, ID2, ID), s(ID2,_,Holo,_,_,_). /* Solvable: wn_verify_participial_adj(?Adjective, ?Verb) Verifies that an adjective is a participal of the verb */ oaa_AppDoEvent(wn_verify_participial_adj(Adjective, Verb), _GoalParams) :- verify_particip_adj(Adjective, Verb). /* Solvable: wn_get_verb_frame(+Verb, ?Sense, ?FrameNumber, -Frame) Returns a single frame for the verb (a frame encodes subcategorization and selectional restrictions. If a sense is not specified, then a general frame for the verb's synset is returned, if there is one. */ oaa_AppDoEvent(wn_get_verb_frame(Verb, Sense, FrameNumber, Frame), _GoalParams) :- s(ID,WNum,Verb,v,Sense,_), (var(Sense) -> WNum2 = 0; WNum2 = WNum), (fr(ID, FrameNumber, WNum2); fr(ID, FrameNumber, 0)), frame(FrameNumber, Frame). /* The rest of the solvables are just wrappers around the WordNet predicates. See the WordNet documentation in prologdb.5* for details. */ oaa_AppDoEvent(wn_s(Synset_id,W_num,Word,Ss_type,Sense_number,Tag_count), _GoalParams) :- s(Synset_id,W_num,Word,Ss_type,Sense_number,Tag_count). oaa_AppDoEvent(wn_g(Synset_id,Gloss), _GoalParams) :- g(Synset_id,Gloss). oaa_AppDoEvent(wn_hyp(Synset_id,Synset_id2), _GoalParams) :- hyp(Synset_id,Synset_id2). oaa_AppDoEvent(wn_ent(Synset_id,Synset_id2), _GoalParams) :- ent(Synset_id,Synset_id2). oaa_AppDoEvent(wn_sim(Synset_id,Synset_id2), _GoalParams) :- sim(Synset_id,Synset_id2). oaa_AppDoEvent(wn_mm(Synset_id,Synset_id2), _GoalParams) :- mm(Synset_id,Synset_id2). oaa_AppDoEvent(wn_ms(Synset_id,Synset_id2), _GoalParams) :- ms(Synset_id,Synset_id2). oaa_AppDoEvent(wn_mp(Synset_id,Synset_id2), _GoalParams) :- mp(Synset_id,Synset_id2). oaa_AppDoEvent(wn_cs(Synset_id,Synset_id2), _GoalParams) :- cs(Synset_id,Synset_id2). oaa_AppDoEvent(wn_vgp(Synset_id,Synset_id2), _GoalParams) :- vgp(Synset_id,_,Synset_id2,_). %incorrectly documented in WordNet oaa_AppDoEvent(wn_at(Synset_id,Synset_id2), _GoalParams) :- at(Synset_id,Synset_id2). oaa_AppDoEvent(wn_ant(Synset_id,W_num,Synset_id2,W_num2), _GoalParams) :- ant(Synset_id,W_num,Synset_id2,W_num2). oaa_AppDoEvent(wn_sa(Synset_id,W_num,Synset_id2,W_num2), _GoalParams) :- sa(Synset_id,W_num,Synset_id2,W_num2). oaa_AppDoEvent(wn_ppl(Synset_id,W_num,Synset_id2,W_num2), _GoalParams) :- ppl(Synset_id,W_num,Synset_id2,W_num2). oaa_AppDoEvent(wn_per(Synset_id,W_num,Synset_id2,W_num2), _GoalParams) :- per(Synset_id,W_num,Synset_id2,W_num2). oaa_AppDoEvent(wn_fr(Synset_id,F_num,W_num), _GoalParams) :- fr(Synset_id,F_num,W_num). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% auxiliary predicates %%%%%%%%%%%%%%%%%%%%%%%%% cat(X,X) :- var(X), !. cat(n,n). cat(noun,n). cat(v,v). cat(verb,v). cat(a,a). cat(adj,a). cat(adjective,a). cat(s,s). cat('adjective satellite',s). cat(r,r). cat(adv,r). cat(adverb,r). mer(X,X) :- var(X), !. mer(mp,mp). mer(part,mp). mer(mm,mm). mer(member,mm). mer(ms,ms). mer(substance,ms). meronymn_helper(Type, ID1,ID2) :- var(Type), !, (mp(ID1,ID2); mm(ID1,ID2); ms(ID1,ID2)). meronymn_helper(mp, ID1, ID2) :- mp(ID1,ID2). meronymn_helper(mm, ID1, ID2) :- mm(ID1,ID2). meronymn_helper(ms, ID1, ID2) :- ms(ID1,ID2). verify_particip_adj(Adjective, Verb) :- nonvar(Adjective), !, s(ID,WNum,Adjective,a,_,_), ppl(ID,WNum,ID2,WNum2), s(ID2,WNum2,Verb,v,_,_). verify_particip_adj(Adjective, Verb) :- s(ID2,WNum2,Verb,v,_,_), ppl(ID,WNum,ID2,WNum2), s(ID,WNum,Adjective,a,_,_). frame(1,'Something ----s'). frame(2,'Somebody ----s'). frame(3,'It is ----ing'). frame(4,'Something is ----ing PP'). frame(5,'Something ----s something Adjective/Noun'). frame(6,'Something ----s Adjective/Noun'). frame(7,'Somebody ----s Adjective'). frame(8,'Somebody ----s something'). frame(9,'Somebody ----s somebody'). frame(10,'Something ----s somebody'). frame(11,'Something ----s something'). frame(12,'Something ----s to somebody'). frame(13,'Somebody ----s on something'). frame(14,'Somebody ----s somebody something'). frame(15,'Somebody ----s something to somebody'). frame(16,'Somebody ----s something from somebody'). frame(17,'Somebody ----s somebody with something'). frame(18,'Somebody ----s somebody of something'). frame(19,'Somebody ----s something on somebody'). frame(20,'Somebody ----s somebody PP'). frame(21,'Somebody ----s something PP'). frame(22,'Somebody ----s PP'). frame(23,'Somebody''s (body part) ----s'). frame(24,'Somebody ----s somebody to INFINITIVE'). frame(25,'Somebody ----s somebody INFINITIVE'). frame(26,'Somebody ----s that CLAUSE'). frame(27,'Somebody ----s to somebody'). frame(28,'Somebody ----s to INFINITIVE'). frame(29,'Somebody ----s whether INFINITIVE'). frame(30,'Somebody ----s somebody into V-ing something'). frame(31,'Somebody ----s something with something'). frame(32,'Somebody ----s INFINITIVE'). frame(33,'Somebody ----s VERB-ing'). frame(34,'It ----s that CLAUSE'). frame(35,'Something ----s INFINITIVE').