Go to the NLTK Wordnet webpage and Chris Potts's Wordnet page and learn some basics about the NLTK wordnet interface.
For background on NLTK go to this web page
>>> all_noun_forms = set() >>> for synset in wn.all_synsets('n'): for l in synset.lemmas: all_noun_forms.add(l.name)How many nouns are there in wordnet? Very different question: How many noun synsets are there? What noun has the largest number of senses [Each synset of a noun corresponds to a sense]? What noun has the largest number of noun senses?
>>> nltk_get_synonyms('dog','n') ['dog', 'Canis familiaris', 'domestic dog', 'frump', 'hound', 'bounder', 'blackguard', 'cad', 'heel', 'wiener', 'frankfurter', 'hot dog', 'wienerwurst', 'frank', 'weenie', 'hotdog', 'pawl', 'click', 'detent', 'andiron', 'firedog', 'dog-iron'][This is the actual answer you should get for this noun.] Called on a form (a string) it should return a list of forms. (strings). They should NOT be synsets and they should not be lemmas. They should be strings. The list should have NO duplicates. You should write your code to gurantee there are no duplicates.
>>> bas = wn.synsets('basenji','n')[0] >>> get_co_hyponyms(bas) [Synset('puppy.n.01'), Synset('great_pyrenees.n.01'), Synset('basenji.n.01'), Synset('newfoundland.n.01'), Synset('lapdog.n.01'), Synset('poodle.n.01'), Synset('leonberg.n.01'), Synset('toy_dog.n.01'), Synset('spitz.n.01'), Synset('pooch.n.01'), Synset('cur.n.01'), Synset('mexican_hairless.n.01'), Synset('hunting_dog.n.01'), Synset('working_dog.n.01'), Synset('dalmatian.n.02'), Synset('pug.n.01'), Synset('corgi.n.01'), Synset('griffon.n.02')]basenji, dalmatian, pug, and corgi are all cohyponyms. Soemwhat less intuitively basenji and puppy are also co_hyponyms. This is the correct result given the relations in Wordnet, but it is not entirely satisfying. What is the difference in the relationship between basenji, dalmatian, pug, and corgi and basenji and puppy? What is Wordnet missing here? Turn in your program and the answers to these questions.
Write a program to find the graph neighborhood surrounding a synset. There are many kinds of links one could follow in Wordnet, so to be concrete, I will give you two different options for a WordNet graph. You can do either to receive full credit for this extra credit problem:
>>> wn_neighborhood('dog', distance = 2) ['heel', 'blackguard', 'cad', 'hound', 'bounder', 'CAD', 'computer-aided design', 'get through', 'bum', 'cross', 'course', 'wiener', 'after part', 'shadow', 'racecourse', 'cut', 'caterpillar tread', 'sink in', 'shack', 'tail', 'tush', 'give chase', 'snap', 'free-spoken', 'tatter', 'get across', 'cartroad', 'dock', 'candid', 'penetrate', 'ticket', 'tick', 'weenie', 'rear', 'drag', 'tag end', 'hound dog', 'chamfer', 'hunt', 'list', 'fanny', 'roast', 'plainspoken', 'guy', 'raceway', 'forthright', 'caterpillar track', 'traverse', 'laugh at', 'poop', 'Salmon P. Chase', 'come home', 'empennage', 'frankfurter', 'dawn', 'click', 'lead', 'bottom', 'Frank', 'outspoken', 'label', 'Norbert Wiener', 'behind', 'wienerwurst', 'jest at', 'ass', 'quarter', 'frank', 'quest for', 'get over', 'pursuit', 'path', 'make fun', 'quest after', 'prat', 'frump', 'drop behind', 'backside', 'pass over', 'ridicule', 'cut through', 'shred', 'bob', 'Chase', 'get behind', 'drop back', 'pursual', 'flick', 'chase after', 'rag', 'point-blank', 'clack', 'stern', 'clapperclaw', 'rear end', 'shout', 'rails', 'mark', 'Canis familiaris', 'chink', 'rump', 'domestic dog', 'cluck', 'tooshie', 'hind end', 'trail', 'posterior', 'train', 'hindquarters', 'butt', 'nates', 'seat', 'chatter', 'furrow', 'leaper', 'buttocks', 'pursue', 'runway', 'derriere', 'Wiener', 'fag end', 'can', 'fundament', 'following', 'go after', 'pawl', 'mouse click', 'straight-from-the-shoulder', 'racetrack', 'tag', 'tail assembly', 'fall into place', 'rib', 'keister', 'chase', 'andiron', 'tail end', 'Salmon Portland Chase', 'suction stop', 'hot dog', 'red hot', 'buns', 'clink', 'blunt', 'trace', 'track', 'cart track', 'rail', 'data track', 'poke fun', 'running', 'abuse', 'postmark', 'cut across', 'arse', 'firedog', 'shadower', 'cover', 'dog', 'hang back', 'detent', 'dog-iron', 'reheel', 'hotdog']
Take your program out for a spin by trying to find larger and larger neighborhoods around the word dog. Is there a maximal neighborhood you can get to following synonymy links? That is, is there a path length past which the set of synonyms doesnt grow any more? If so, what is the size of the set of forms found? What is the length of the path? Turn in your program and the answers to these questions.