當前位置: 首頁>>代碼示例>>Python>>正文


Python BigramAssocMeasures.pmi方法代碼示例

本文整理匯總了Python中nltk.metrics.BigramAssocMeasures.pmi方法的典型用法代碼示例。如果您正苦於以下問題:Python BigramAssocMeasures.pmi方法的具體用法?Python BigramAssocMeasures.pmi怎麽用?Python BigramAssocMeasures.pmi使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nltk.metrics.BigramAssocMeasures的用法示例。


在下文中一共展示了BigramAssocMeasures.pmi方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_bigram2

# 需要導入模塊: from nltk.metrics import BigramAssocMeasures [as 別名]
# 或者: from nltk.metrics.BigramAssocMeasures import pmi [as 別名]
def test_bigram2(self):
        sent = 'this this is is a a test test'.split()

        b = BigramCollocationFinder.from_words(sent)

        #python 2.6 does not have assertItemsEqual or assertListEqual
        self.assertEqual(
            sorted(b.ngram_fd.items()),
            sorted([(('a', 'a'), 1), (('a', 'test'), 1), (('is', 'a'), 1), (('is', 'is'), 1), (('test', 'test'), 1), (('this', 'is'), 1), (('this', 'this'), 1)])
        )
        self.assertEqual(
            sorted(b.word_fd.items()),
            sorted([('a', 2), ('is', 2), ('test', 2), ('this', 2)])
        )
        self.assertTrue(len(sent) == sum(b.word_fd.values()) == sum(b.ngram_fd.values()) + 1)
        self.assertTrue(close_enough(
            sorted(b.score_ngrams(BigramAssocMeasures.pmi)),
            sorted([(('a', 'a'), 1.0), (('a', 'test'), 1.0), (('is', 'a'), 1.0), (('is', 'is'), 1.0), (('test', 'test'), 1.0), (('this', 'is'), 1.0), (('this', 'this'), 1.0)])
        )) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:21,代碼來源:test_collocations.py

示例2: test_bigram3

# 需要導入模塊: from nltk.metrics import BigramAssocMeasures [as 別名]
# 或者: from nltk.metrics.BigramAssocMeasures import pmi [as 別名]
def test_bigram3(self):
        sent = 'this this is is a a test test'.split()

        b = BigramCollocationFinder.from_words(sent, window_size=3)
        self.assertEqual(
            sorted(b.ngram_fd.items()),
            sorted([(('a', 'test'), 3), (('is', 'a'), 3), (('this', 'is'), 3), (('a', 'a'), 1), (('is', 'is'), 1), (('test', 'test'), 1), (('this', 'this'), 1)])
        )
        self.assertEqual(
            sorted(b.word_fd.items()),
            sorted([('a', 2), ('is', 2), ('test', 2), ('this', 2)])
        )
        self.assertTrue(len(sent) == sum(b.word_fd.values()) == (sum(b.ngram_fd.values()) + 2 + 1) / 2.0)
        self.assertTrue(close_enough(
            sorted(b.score_ngrams(BigramAssocMeasures.pmi)),
            sorted([(('a', 'test'), 1.584962500721156), (('is', 'a'), 1.584962500721156), (('this', 'is'), 1.584962500721156), (('a', 'a'), 0.0), (('is', 'is'), 0.0), (('test', 'test'), 0.0), (('this', 'this'), 0.0)])
        )) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:19,代碼來源:test_collocations.py

示例3: test_bigram5

# 需要導入模塊: from nltk.metrics import BigramAssocMeasures [as 別名]
# 或者: from nltk.metrics.BigramAssocMeasures import pmi [as 別名]
def test_bigram5(self):
        sent = 'this this is is a a test test'.split()

        b = BigramCollocationFinder.from_words(sent, window_size=5)
        self.assertEqual(
            sorted(b.ngram_fd.items()),
            sorted([(('a', 'test'), 4), (('is', 'a'), 4), (('this', 'is'), 4), (('is', 'test'), 3), (('this', 'a'), 3), (('a', 'a'), 1), (('is', 'is'), 1), (('test', 'test'), 1), (('this', 'this'), 1)])
        )
        self.assertEqual(
            sorted(b.word_fd.items()),
            sorted([('a', 2), ('is', 2), ('test', 2), ('this', 2)])
        )
        self.assertTrue(len(sent) == sum(b.word_fd.values()) == (sum(b.ngram_fd.values()) + 4 + 3 + 2 + 1) / 4.0)
        self.assertTrue(close_enough(
            sorted(b.score_ngrams(BigramAssocMeasures.pmi)),
            sorted([(('a', 'test'), 1.0), (('is', 'a'), 1.0), (('this', 'is'), 1.0), (('is', 'test'), 0.5849625007211562), (('this', 'a'), 0.5849625007211562), (('a', 'a'), -1.0), (('is', 'is'), -1.0), (('test', 'test'), -1.0), (('this', 'this'), -1.0)])
        )) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:19,代碼來源:test_collocations.py


注:本文中的nltk.metrics.BigramAssocMeasures.pmi方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。