本文整理汇总了Python中markov.Markov.generate_markov_text方法的典型用法代码示例。如果您正苦于以下问题:Python Markov.generate_markov_text方法的具体用法?Python Markov.generate_markov_text怎么用?Python Markov.generate_markov_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类markov.Markov
的用法示例。
在下文中一共展示了Markov.generate_markov_text方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import generate_markov_text [as 别名]
def main():
"""set-up applcation and send love"""
api = get_handle()
markov = Markov(get_corpus())
people = People(api)
love = markov.generate_markov_text(random.randrange(15, 20))
to_email = people.get_random()
print to_email
print love
if api.send_love(to_email, love):
return 0
else:
return -1
示例2: MarkovTweet
# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import generate_markov_text [as 别名]
class MarkovTweet(object):
def __init__(self, url):
"Generate the markov chain stuff first."
file_ = open(url, 'r')
self.mkov = Markov(file_)
def tweet(self, words=('', '')):
"Capitalise the first word and trim to the end of a sentence."
twit = self.mkov.generate_markov_text(50, words)
twit = twit[0].upper() + twit[1:]
while twit != '' and twit[-1] not in ';:?.,!':
twit = twit[:-1]
if twit == '':
twit = self.tweet()
else:
if twit[-1] in ';:,':
twit = twit[:-1] + '.'
return twit
示例3: open
# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import generate_markov_text [as 别名]
from markov import Markov
f = open('poems.txt')
m = Markov(f)
print(m.generate_markov_text(500))
示例4: generate_markov
# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import generate_markov_text [as 别名]
def generate_markov(textfile):
f = open(textfile)
markov_model = Markov(f)
f.close()
return markov_model.generate_markov_text(size=16)