/* Testing WordNet in Picat. Programs from Brakto "Prolog Programming for Artificial Intelligence", 4th edition. Pages 115ff The WordNet files for Picat v3 are written by Neng-Fa Zhou and are available from: https://github.com/nfzhou/wordnet Note: The first run takes some time since the programs are compiled to .qi files. After that it should run fast.... Run the programs with the -s parameter, e.g. $ picat -s 99999999 -g go wordnet_bratko_test.pi This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % The following are the only used in the examples. import wn_s. import wn_g. import wn_sim. import wn_hyp. import wn_mm. import wn_mp. % The following are not used in the examples. % import wn_ant. % import wn_at. % import wn_cls. % import wn_cs. % import wn_der. % import wn_ent. % import wn_fr. % import wn_ins. % import wn_ms. % import wn_per. % import wn_ppl. % import wn_sa. % import wn_sk. % import wn_syntax. % import wn_vgp. main => go. % Definitions (gloss) of a word % Page 117 % word = plane % synset = 102691156 % type = n % senseNo = 1 % gloss = an aircraft that has a fixed wing and is powered by propellers or jets; "the flight was delayed due to trouble with the airplane" % synset = 103954731 % type = n % senseNo = 5 % gloss = a carpenter"s hand tool with an adjustable blade for smoothing or shaping wood; "the cabinetmaker used a plane for the finish work" % synset = 103955296 % type = n % senseNo = 4 % gloss = a power tool for smoothing or shaping wood % synset = 113861050 % type = n % senseNo = 2 % gloss = (mathematics) an unbounded two-dimensional shape; "we will refer to the plane of the graph as the X-Y plane"; "any line joining two points on a plane lies wholly on that plane" % synset = 113941806 % type = n % senseNo = 3 % gloss = a level of existence or development; "he lived on a worldly plane" % synset = 201249490 % type = v % senseNo = 1 % gloss = cut or remove with or as if with a plane; "The machine shaved off fine layers from the piece of wood" % synset = 201307389 % type = v % senseNo = 3 % gloss = make even or smooth, with or as with a carpenter"s plane; "plane the top of the door" % synset = 201942718 % type = v % senseNo = 2 % gloss = travel on the surface of water % synset = 300910101 % type = s % senseNo = 1 % gloss = having a surface without slope, tilt in which no part is higher or lower than another; "a flat desk"; "acres of level farmland"; "a plane surface"; "skirts sewn with fine flat seams" % go :- Word = plane, println(word=Word), % s(synset_id,w_num,'word',ss_type,sense_number,tag_count). s(Synset,_,Word,Type,SenseNo,_), g(Synset,Gloss), println(synset=Synset), println(type=Type), println(senseNo=SenseNo), println(gloss=Gloss), nl, fail, nl. go. % Page 118 % Similar words % % word = comprehensive % syn1 = 107197889 % syn1 = 300525453 % syn2 = 300526062 % across-the-board % go2 :- Word = 'comprehensive', println(word=Word), s(Syn1,_,Word,_,_,_), println(syn1=Syn1), sim(Syn1,Syn2), println(syn2=Syn2), s(Syn2,_,SimilarWord,_,_,_), println(SimilarWord), % fail, nl. go2. % Page 119 % % [john,gave,a,across-the-board,talk] % [john,gave,a,all-embracing,talk] % [john,gave,a,all-encompassing,talk] % [john,gave,a,all-inclusive,talk] % [john,gave,a,blanket,talk] % [john,gave,a,broad,talk] % [john,gave,a,encompassing,talk] % [john,gave,a,extensive,talk] % [john,gave,a,panoptic,talk] % [john,gave,a,wide,talk] % [john,gave,a,all-around,talk] % [john,gave,a,all-round,talk] % [john,gave,a,well-rounded,talk] % [john,gave,a,citywide,talk] % [john,gave,a,countywide,talk] % [john,gave,a,countrywide,talk] % [john,gave,a,nationwide,talk] % [john,gave,a,cosmopolitan,talk] % [john,gave,a,ecumenical,talk] % [john,gave,a,oecumenical,talk] % [john,gave,a,general,talk] % [john,gave,a,universal,talk] % [john,gave,a,worldwide,talk] % [john,gave,a,world-wide,talk] % [john,gave,a,door-to-door,talk] % [john,gave,a,house-to-house,talk] % [john,gave,a,encyclopedic,talk] % [john,gave,a,encyclopaedic,talk] % [john,gave,a,large,talk] % [john,gave,a,omnibus,talk] % [john,gave,a,plenary,talk] % [john,gave,a,spatiotemporal,talk] % [john,gave,a,spaciotemporal,talk] % [john,gave,a,schoolwide,talk] % [john,gave,a,statewide,talk] % [john,gave,a,super,talk] % [john,gave,a,umbrella,talk] % [john,gave,a,inclusive,talk] % go3 :- rephrase([john,gave,a,comprehensive,talk],comprehensive,NewSentence), println(NewSentence), fail, nl. go3. % Page 119 % % [john,has,a,uncomfortable,computer] % [john,has,a,stale,computer] % [john,has,a,malfunctioning,computer] % [john,has,a,nonfunctional,computer] % [john,has,a,counterfeit,computer] % [john,has,a,imitative,computer] % [john,has,a,atrocious,computer] % [john,has,a,abominable,computer] % [john,has,a,awful,computer] % [john,has,a,dreadful,computer] % [john,has,a,painful,computer] % [john,has,a,terrible,computer] % [john,has,a,unspeakable,computer] % [john,has,a,corked,computer] % [john,has,a,corky,computer] % [john,has,a,deplorable,computer] % [john,has,a,distressing,computer] % [john,has,a,lamentable,computer] % [john,has,a,pitiful,computer] % [john,has,a,sad,computer] % [john,has,a,sorry,computer] % [john,has,a,fearful,computer] % [john,has,a,frightful,computer] % [john,has,a,hard,computer] % [john,has,a,tough,computer] % [john,has,a,hopeless,computer] % [john,has,a,horrid,computer] % [john,has,a,icky,computer] % [john,has,a,crappy,computer] % [john,has,a,lousy,computer] % [john,has,a,rotten,computer] % [john,has,a,shitty,computer] % [john,has,a,stinking,computer] % [john,has,a,stinky,computer] % [john,has,a,ill,computer] % [john,has,a,incompetent,computer] % [john,has,a,unskilled,computer] % [john,has,a,mediocre,computer] % [john,has,a,naughty,computer] % [john,has,a,negative,computer] % [john,has,a,poor,computer] % [john,has,a,pretty,computer] % [john,has,a,rubber,computer] % [john,has,a,no-good,computer] % [john,has,a,severe,computer] % [john,has,a,swingeing,computer] % [john,has,a,uncool,computer] % [john,has,a,unfavorable,computer] % [john,has,a,unfavourable,computer] % [john,has,a,unsuitable,computer] % [john,has,a,evil,computer] % [john,has,a,harmful,computer] % [john,has,a,unhealthy,computer] % [john,has,a,intense,computer] % [john,has,a,unsound,computer] % [john,has,a,nonstandard,computer] % [john,has,a,inferior,computer] % [john,has,a,invalid,computer] % go4 :- rephrase([john,has,a,bad,computer],bad,NewSentence), println(NewSentence), fail, nl. go4. % Page 119 % Does mouse and hamster belong to the same synset? % no % (Which is correct) go5 :- ( s(Syn,_,mouse,T1,Sen1,_), s(Syn,_,hamster,T2,Sen2,_) -> println(yes) ; println(no) ), nl. go5. % Page 120 % Does mouse and hamster belong to some common concept? % s = 102329401 % word = rodent % % s = 102329401 % word = gnawer % go6 :- s(S1,_,mouse,T1,Sens1,_), s(S2,_,hamster,T2,Sens2,_), hyp(S1,S), hyp(S2,S), s(S,_,Word,_,_,_), println(s=S), println(word=Word), nl, fail, nl. go6. % page 122 % path = [rel(hyp,mouse / n / 4,electronic device / n / 1),rel(hyp,electronic device / n / 1,device / n / 1),rel(hyp,keyboard / n / 1,device / n / 1)] go7 :- r($keyboard/T1/Sen1,$mouse/T2/Sen2,3,Path), println(path=Path), fail, nl. go7. % page 122 % path = [rel(hyp,hamster / n / 1,rodent / n / 1),rel(hyp,mouse / n / 1,rodent / n / 1)] % path = [rel(hyp,hamster / n / 1,rodent / n / 1),rel(hyp,mouse / n / 1,gnawer / n / 1)] % path = [rel(hyp,hamster / n / 1,gnawer / n / 1),rel(hyp,mouse / n / 1,rodent / n / 1)] % path = [rel(hyp,hamster / n / 1,gnawer / n / 1),rel(hyp,mouse / n / 1,gnawer / n / 1)] go8 :- r($mouse/T1/Sen1,$hamster/T2/Sen2,3,Path), println(path=Path), fail, nl. go8. % page 122 % path = [rel(hyp,mouse button / n / 1,button / n / 2),rel(mp,mouse button / n / 1,mouse / n / 4)] % path = [rel(hyp,button / n / 6,device / n / 1),rel(hyp,electronic device / n / 1,device / n / 1),rel(hyp,mouse / n / 4,electronic device / n / 1)] go9 :- r($mouse/T1/Sen1,$button/T2/Sen2,3,Path), println(path=Path), fail, nl. go9. % Rephrase a sentence with the synonyms of Word rephrase(Sentence,Word,NewSentence) :- append(Prefix,[Word|Postfix], Sentence), s(Syn1,_,Word,_,_,_), sim(Syn1,Syn2), s(Syn2,_,SimilarWord,_,_,_), append(Prefix,[SimilarWord|Postfix], NewSentence). % Page 121 % Figure 4.16 Searching for paths between words and synsets in WordNet. % r0( Syn1, Syn2, rel( Rel, S1, S2) ): % Syn1 and Syn2 are in relation Rel, in direction from S1 to S2 r0(Syn1, Syn2, rel( Rel, S1, S2) ) :- ( S1 = Syn1, S2 = Syn2; % Choose first and second arg. of relation between Syn1 and Syn2 S1 = Syn2, S2 = Syn1), ( hyp( S1, S2), Rel = hyp; % Check hyp relation mm( S1, S2), Rel = mm; % Check mm relation mp( S1, S2), Rel = mp % Check mp relation ). % r( W1/T1/Sen1, W2/T2/Sen2, MaxLength, WordPath): % Sense Sen1 of word W1 of type T1 is related to sense Sen2 of word W2 of type T2 % by a chain WordPath of basic relations given in WordNet; % chain contains at most MaxLength relations r(W1/T1/Sen1, W2/T2/Sen2, MaxLength, WordPath) :- bp.length( MaxList, MaxLength), % MaxList is a general list of length MaxLength append( SynPath, _, MaxList), % SynPath = list not longer than MaxLength % Shorter lists SynPath are tried first s( Syn1, _, W1, T1, Sen1, _), s( Syn2, _, W2, T2, Sen2, _), s_path( Syn1, Syn2, SynPath), word_path( SynPath, WordPath), mentioned( $W1/T1/Sen1, WordPath), % Word W1 mentioned in WordPath mentioned( $W2/T2/Sen2, WordPath). % Word W2 mentioned in WordPath % s_path( Syn1, Syn2, Path): % Path connects synsets Syn1 and Syn2; Path is list of relationships rel( Rel, S1, S2) s_path(Syn, Syn, [ ]). % Path from synset to itself s_path(Syn1, Syn2, [Rel | L]) :- s_path( Syn1, Syn, L), % Path from Syn1 to one-but-last synset Syn on the path r0( Syn, Syn2, Rel), % Last step on the path: direct relation between Syn and Syn2 not mentioned( Syn2, L). % Syn2 is not mentioned in path L % word_path( SynList, WordList): % WordList is list of relationships between triples Word/Type/Sense % that correspond to synsets in SynList word_path([], []). word_path([rel(Rel,Syn1,Syn2) | SynRels], [ rel(Rel,W1/T1/Sen1,W2/T2/Sen2) | WordRels]) :- s( Syn1, _, W1, T1, Sen1, _), s( Syn2, _, W2, T2, Sen2, _), word_path( SynRels, WordRels). % mentioned( X, RelationChain): X is mentioned in list RelationChain as an argument of a relation mentioned(X, L) :- member(Rel, L), ( Rel = $rel( _, X, _); Rel = $rel( _, _, X) ).