当前位置: 首页>>代码示例>>Python>>正文


Python BigramCollocationFinder.from_documents方法代码示例

本文整理汇总了Python中nltk.collocations.BigramCollocationFinder.from_documents方法的典型用法代码示例。如果您正苦于以下问题:Python BigramCollocationFinder.from_documents方法的具体用法?Python BigramCollocationFinder.from_documents怎么用?Python BigramCollocationFinder.from_documents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.collocations.BigramCollocationFinder的用法示例。


在下文中一共展示了BigramCollocationFinder.from_documents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: bigram_collocation_feats

# 需要导入模块: from nltk.collocations import BigramCollocationFinder [as 别名]
# 或者: from nltk.collocations.BigramCollocationFinder import from_documents [as 别名]
    def bigram_collocation_feats(self, documents, top_n=None, min_freq=3,
                                 assoc_measure=BigramAssocMeasures.pmi):
        """
        Return `top_n` bigram features (using `assoc_measure`).
        Note that this method is based on bigram collocations measures, and not
        on simple bigram frequency.

        :param documents: a list (or iterable) of tokens.
        :param top_n: number of best words/tokens to use, sorted by association
            measure.
        :param assoc_measure: bigram association measure to use as score function.
        :param min_freq: the minimum number of occurrencies of bigrams to take
            into consideration.

        :return: `top_n` ngrams scored by the given association measure.
        """
        finder = BigramCollocationFinder.from_documents(documents)
        finder.apply_freq_filter(min_freq)
        return finder.nbest(assoc_measure, top_n)
开发者ID:Weiming-Hu,项目名称:text-based-six-degree,代码行数:21,代码来源:sentiment_analyzer.py

示例2: get_top_ngrams

# 需要导入模块: from nltk.collocations import BigramCollocationFinder [as 别名]
# 或者: from nltk.collocations.BigramCollocationFinder import from_documents [as 别名]
                     for text, freq in sorted_ngrams]

    return sorted_ngrams   
    

get_top_ngrams(corpus=norm_alice, ngram_val=2,
               limit=10)
               
get_top_ngrams(corpus=norm_alice, ngram_val=3,
               limit=10)

from nltk.collocations import BigramCollocationFinder
from nltk.collocations import BigramAssocMeasures

finder = BigramCollocationFinder.from_documents([item.split() 
                                                for item 
                                                in norm_alice])
bigram_measures = BigramAssocMeasures()                                                
finder.nbest(bigram_measures.raw_freq, 10)
finder.nbest(bigram_measures.pmi, 10)   

from nltk.collocations import TrigramCollocationFinder
from nltk.collocations import TrigramAssocMeasures

finder = TrigramCollocationFinder.from_documents([item.split() 
                                                for item 
                                                in norm_alice])
trigram_measures = TrigramAssocMeasures()                                                
finder.nbest(trigram_measures.raw_freq, 10)
finder.nbest(trigram_measures.pmi, 10)  
开发者ID:000Nelson000,项目名称:text-analytics-with-python,代码行数:32,代码来源:keyphrase_extraction.py


注:本文中的nltk.collocations.BigramCollocationFinder.from_documents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。