In [1]:
import nltk.classify.util
from nltk.classify import NaiveBayesClassifier
from nltk.corpus import movie_reviews
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.corpus import wordnet

In [2]:
sentence = "The Quick brown fox, Jumps over the lazy little dog. Hello World."

In [3]:
sentence.split(" ")


Out[3]:
['The',
 'Quick',
 'brown',
 'fox,',
 'Jumps',
 'over',
 'the',
 'lazy',
 'little',
 'dog.',
 'Hello',
 'World.']

In [4]:
word_tokenize(sentence)


Out[4]:
['The',
 'Quick',
 'brown',
 'fox',
 ',',
 'Jumps',
 'over',
 'the',
 'lazy',
 'little',
 'dog',
 '.',
 'Hello',
 'World',
 '.']

In [5]:
w = word_tokenize(sentence)
nltk.pos_tag(w)


Out[5]:
[('The', 'DT'),
 ('Quick', 'NNP'),
 ('brown', 'NN'),
 ('fox', 'NN'),
 (',', ','),
 ('Jumps', 'NNP'),
 ('over', 'IN'),
 ('the', 'DT'),
 ('lazy', 'JJ'),
 ('little', 'JJ'),
 ('dog', 'NN'),
 ('.', '.'),
 ('Hello', 'NNP'),
 ('World', 'NNP'),
 ('.', '.')]

In [ ]:
# List of tages: http://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html

nltk.help.upenn_tagset()

In [10]:
syn = wordnet.synsets("computer")
print(syn)
print(syn[0].name())
print(syn[0].definition())

print(syn[1].name())
print(syn[1].definition())


[Synset('computer.n.01'), Synset('calculator.n.01')]
computer.n.01
a machine for performing calculations automatically
calculator.n.01
an expert at calculation (or at operating calculating machines)

In [11]:
syn = wordnet.synsets("talk")
syn[0].examples()


Out[11]:
["let's have more work and less talk around here"]

In [16]:
syn = wordnet.synsets("speak")[0]
print(syn.hypernyms())
print(syn.hyponyms())


[Synset('communicate.v.02')]
[Synset('babble.v.01'), Synset('bark.v.01'), Synset('bay.v.01'), Synset('begin.v.04'), Synset('blubber.v.02'), Synset('blurt_out.v.01'), Synset('bumble.v.03'), Synset('cackle.v.01'), Synset('chatter.v.04'), Synset('chatter.v.05'), Synset('deliver.v.01'), Synset('drone.v.02'), Synset('enthuse.v.02'), Synset('generalize.v.02'), Synset('gulp.v.02'), Synset('hiss.v.03'), Synset('lip_off.v.01'), Synset('mumble.v.01'), Synset('murmur.v.01'), Synset('open_up.v.07'), Synset('peep.v.04'), Synset('rant.v.01'), Synset('rasp.v.02'), Synset('read.v.03'), Synset('shout.v.01'), Synset('sing.v.02'), Synset('slur.v.03'), Synset('snap.v.01'), Synset('snivel.v.01'), Synset('speak_in_tongues.v.01'), Synset('speak_up.v.02'), Synset('swallow.v.04'), Synset('talk_of.v.01'), Synset('tone.v.01'), Synset('tone.v.02'), Synset('troll.v.07'), Synset('verbalize.v.01'), Synset('vocalize.v.05'), Synset('whiff.v.05'), Synset('whisper.v.01'), Synset('yack.v.01')]

In [24]:
syn = wordnet.synsets("good")
for s in syn:
    for l in s.lemmas():
        if (l.antonyms()):
            print(l.antonyms())


[Lemma('evil.n.03.evil')]
[Lemma('evil.n.03.evilness')]
[Lemma('bad.n.01.bad')]
[Lemma('bad.n.01.badness')]
[Lemma('bad.a.01.bad')]
[Lemma('evil.a.01.evil')]
[Lemma('ill.r.01.ill')]

In [25]:
syn = wordnet.synsets("book")
for s in syn:
    print(s.lemmas())


[Lemma('book.n.01.book')]
[Lemma('book.n.02.book'), Lemma('book.n.02.volume')]
[Lemma('record.n.05.record'), Lemma('record.n.05.record_book'), Lemma('record.n.05.book')]
[Lemma('script.n.01.script'), Lemma('script.n.01.book'), Lemma('script.n.01.playscript')]
[Lemma('ledger.n.01.ledger'), Lemma('ledger.n.01.leger'), Lemma('ledger.n.01.account_book'), Lemma('ledger.n.01.book_of_account'), Lemma('ledger.n.01.book')]
[Lemma('book.n.06.book')]
[Lemma('book.n.07.book'), Lemma('book.n.07.rule_book')]
[Lemma('koran.n.01.Koran'), Lemma('koran.n.01.Quran'), Lemma('koran.n.01.al-Qur'an'), Lemma('koran.n.01.Book')]
[Lemma('bible.n.01.Bible'), Lemma('bible.n.01.Christian_Bible'), Lemma('bible.n.01.Book'), Lemma('bible.n.01.Good_Book'), Lemma('bible.n.01.Holy_Scripture'), Lemma('bible.n.01.Holy_Writ'), Lemma('bible.n.01.Scripture'), Lemma('bible.n.01.Word_of_God'), Lemma('bible.n.01.Word')]
[Lemma('book.n.10.book')]
[Lemma('book.n.11.book')]
[Lemma('book.v.01.book')]
[Lemma('reserve.v.04.reserve'), Lemma('reserve.v.04.hold'), Lemma('reserve.v.04.book')]
[Lemma('book.v.03.book')]
[Lemma('book.v.04.book')]

In [ ]: