Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
('I am tired of this stuff.', 'neg'),
("I can't deal with this", 'neg'),
('He is my sworn enemy!', 'neg'),
('My boss is horrible.', 'neg')
]
test = [
('The beer was good.', 'pos'),
('I do not enjoy my job', 'neg'),
("I ain't feeling dandy today.", 'neg'),
("I feel amazing!", 'pos'),
('Gary is a friend of mine.', 'pos'),
("I can't believe I'm doing this.", 'neg')
]
classifier = NaiveBayesClassifier(train)
class WordListTest(TestCase):
def setUp(self):
self.words = 'Beautiful is better than ugly'.split()
self.mixed = ['dog', 'dogs', 'blob', 'Blobs', 'text']
def test_len(self):
wl = tb.WordList(['Beautiful', 'is', 'better'])
assert_equal(len(wl), 3)
def test_slicing(self):
wl = tb.WordList(self.words)
first = wl[0]
assert_true(isinstance(first, tb.Word))
assert_equal(first, 'Beautiful')
def test_upper(self):
blob = tb.TextBlob('lorem ipsum')
assert_true(is_blob(blob.upper()))
assert_equal(blob.upper(), tb.TextBlob('LOREM IPSUM'))
def test_sentiment_of_emoticons(self):
b1 = tb.TextBlob("Faces have values =)")
b2 = tb.TextBlob("Faces have values")
assert_true(b1.sentiment[0] > b2.sentiment[0])
def test_senences_with_space_before_punctuation(self):
text = "Uh oh. This sentence might cause some problems. : Now we're ok."
b = tb.TextBlob(text)
assert_equal(len(b.sentences), 3)
def test_discrete_sentiment(self):
blob = tb.TextBlob("I feel great today.", analyzer=NaiveBayesAnalyzer())
assert_equal(blob.sentiment[0], 'pos')
def test_define(self):
w = tb.Word("hack")
synsets = w.get_synsets(wn.NOUN)
definitions = w.define(wn.NOUN)
assert_equal(len(synsets), len(definitions))
def test_lemmatize(self):
w = tb.Word("cars")
assert_equal(w.lemmatize(), "car")
w = tb.Word("wolves")
assert_equal(w.lemmatize(), "wolf")
w = tb.Word("went")
assert_equal(w.lemmatize("v"), "go") # wordnet tagset
assert_equal(w.lemmatize("VBD"), "go") # penn treebank tagset
def test_word_lists():
animals = TextBlob("cat dog octopus ocropus")
pluralized_words = animals.words.pluralize()
corrected_words = animals.correct()
word_ocropus = Word('ocropus')
word_ocr_spellechecked = word_ocropus.spellcheck()
word_mice = Word('mice')
word_mice_lemmatized = word_mice.lemmatize()
word_highest = Word('highest')
word_highest_lemmatized = word_highest.lemmatize()
# test word net simmilarities
king_synsets = Word("king").get_synsets(pos=NOUN)
king = Synset('king.n.01')
queen = Synset('queen.n.02')
man = Synset('man.n.01')
wife = Synset('wife.n.01')
woman = Synset('woman.n.01')
octopus = Synset('octopus.n.01')
kq_similarity = king.path_similarity(queen)
km_similarity = king.path_similarity(man)
def test_setitem(self):
wl = tb.WordList(['I', 'love', 'JavaScript'])
wl[2] = tb.Word('Python')
assert_equal(wl[2], tb.Word('Python'))
def test_slicing(self):
wl = tb.WordList(self.words)
first = wl[0]
assert_true(isinstance(first, tb.Word))
assert_equal(first, 'Beautiful')
dogs = wl[0:2]
assert_true(isinstance(dogs, tb.WordList))
assert_equal(dogs, tb.WordList(['Beautiful', 'is']))