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


Python metrics.BigramAssocMeasures方法代碼示例

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


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

示例1: collocations

# 需要導入模塊: from nltk import metrics [as 別名]
# 或者: from nltk.metrics import BigramAssocMeasures [as 別名]
def collocations(self, num=20, window_size=2):
        """
        Print collocations derived from the text, ignoring stopwords.

        :seealso: find_collocations
        :param num: The maximum number of collocations to print.
        :type num: int
        :param window_size: The number of tokens spanned by a collocation (default=2)
        :type window_size: int
        """
        if not ('_collocations' in self.__dict__ and self._num == num and self._window_size == window_size):
            self._num = num
            self._window_size = window_size

            #print("Building collocations list")
            from nltk.corpus import stopwords
            ignored_words = stopwords.words('english')
            finder = BigramCollocationFinder.from_words(self.tokens, window_size)
            finder.apply_freq_filter(2)
            finder.apply_word_filter(lambda w: len(w) < 3 or w.lower() in ignored_words)
            bigram_measures = BigramAssocMeasures()
            self._collocations = finder.nbest(bigram_measures.likelihood_ratio, num)
        colloc_strings = [w1+' '+w2 for w1, w2 in self._collocations]
        print(tokenwrap(colloc_strings, separator="; ")) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:26,代碼來源:text.py


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