本文整理汇总了Python中corpus.Corpus.get_adj_index方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.get_adj_index方法的具体用法?Python Corpus.get_adj_index怎么用?Python Corpus.get_adj_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corpus.Corpus
的用法示例。
在下文中一共展示了Corpus.get_adj_index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import get_adj_index [as 别名]
# 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())
f.close()
print 'A pangram:'
print
print numpy.random.choice(pangrams)
print
示例2: xrange
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import get_adj_index [as 别名]
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)
print 'Pair %i: %s%s (With %i)'%(i+1, adj_index[a], adj_index[b], adj[a,b])
adj[a,b] = 0
print
print 'Random block:'
i = random.randrange(len(corpus))
block = corpus[i]