MadJukesInc / WhatTheHellIs.com

Website with simple description of various terms
MIT License
1 stars 0 forks source link

Noun classification #3

Open ThePenguin1140 opened 8 years ago

ThePenguin1140 commented 8 years ago

Figured out a way to help classify nouns using WordNet

from nltk.corpus import wordnet as wn

def isAnimal(animal):
    peng = wn.synsets(animal, pos=wn.NOUN)[0]
    hypernyms = peng.hypernyms()
    while(hypernyms):
        for hypernym in hypernyms:
            if 'animal' in hypernym.name():
                return 'true'
        hypernyms = hypernym.hypernyms();

    return 'false' 

isAnimal('penguin') //true
isAnimal('JFK') //false
isAnimal('dog') //true
isAnimal('tower') //false

The function demonstrates the ability to identify different kind of 'things'. We can use this to customize pages based on content. For example, animals show origin and/or endangerment status etc. while people can show date of birth/death etc, buildings could show locations, date built, and events could show dates or stuff like that.

ThePenguin1140 commented 8 years ago

Resources: http://www.aclweb.org/website/old_anthology/W/W98/W98-0706.pdf http://www.anthology.aclweb.org/W/W03/W03-1022.pdf