本文整理汇总了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)
示例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)