本文整理汇总了Python中corpus.Corpus.get_words方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.get_words方法的具体用法?Python Corpus.get_words怎么用?Python Corpus.get_words使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corpus.Corpus
的用法示例。
在下文中一共展示了Corpus.get_words方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCorpusSet
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import get_words [as 别名]
class TestCorpusSet(unittest.TestCase):
def setUp(self):
self.negative = StringIO(u'I hated that so much')
self.negative_corpus = Corpus(self.negative, 'negative')
self.positive = StringIO(u'loved movie!! loved')
self.positive_corpus = Corpus(self.positive, 'positive')
def test_trivial(self):
"""consumes multiple files and turns it into sparse vectors"""
self.assertEqual('negative', self.negative_corpus.sentiment)
def test_tokenize1(self):
"""downcases all the word tokens"""
self.assertListEqual(['quick', 'brown', 'fox'], Corpus.tokenize('Quick Brown Fox'))
def test_tokenize2(self):
"""ignores all stop symbols"""
self.assertListEqual(['hello'], Corpus.tokenize('"\'hello!?!?!.\'" '))
def test_tokenize3(self):
"""ignores the unicode space"""
self.assertListEqual(['hello', 'bob'], Corpus.tokenize(u'hello\u00A0bob'))
def test_positive(self):
"""consumes a positive training set"""
self.assertEqual('positive', self.positive_corpus.sentiment)
def test_words(self):
"""consumes a positive training set and unique set of words"""
self.assertEqual({'loved', 'movie'}, self.positive_corpus.get_words())
def test_sentiment_code_1(self):
"""defines a sentiment_code of 1 for positive"""
self.assertEqual(1, Corpus(StringIO(u''), 'positive').sentiment_code)
def test_sentiment_code_minus1(self):
"""defines a sentiment_code of 1 for positive"""
self.assertEqual(-1, Corpus(StringIO(u''), 'negative').sentiment_code)