本文整理汇总了Python中corpus.Corpus.get_counts方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.get_counts方法的具体用法?Python Corpus.get_counts怎么用?Python Corpus.get_counts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corpus.Corpus
的用法示例。
在下文中一共展示了Corpus.get_counts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: int
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import get_counts [as 别名]
pages = int(sys.argv[1])
words = pages * 200 # Seems to be a good guess at a low average of words per page.
corpus = Corpus()
# Shuffle the number of blocks we have, so we can draw random chunks...
chunk_size = 1000
roar = numpy.arange(len(corpus))
numpy.random.shuffle(roar)
# The scoring function needs weights - create them...
letter_weight = numpy.asarray(corpus.get_counts(), dtype=numpy.float32)
letter_weight /= letter_weight.max()
letter_weight[:32] = 0.0
letter_weight[127:] = 0.0
adj_weight = numpy.asarray(corpus.get_adj(), dtype=numpy.float32)
adj_weight /= adj_weight.max()
if ' ' in corpus.get_adj_index():
loc = corpus.get_adj_index().index(' ')
adj_weight[loc,loc] = 0.0
# Random pangram, because why not?..
f = open('data/pangrams.txt')
pangrams = filter(lambda l: len(l)>=26, f.readlines())
示例2: Corpus
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import get_counts [as 别名]
import random
import numpy
from corpus import Corpus
corpus = Corpus(noisy = True)
print 'Corpus loaded, contains %i blocks' % len(corpus)
print
print 'Counts:'
counts = corpus.get_counts()
for i in xrange(128):
if counts[i]!=0:
print chr(i), ':', counts[i]
print
print 'Adjacencies:'
adj = corpus.get_adj()
adj_index = corpus.get_adj_index()
for i in xrange(32):
a, b = numpy.unravel_index(numpy.argmax(adj), adj.shape)