本文整理匯總了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)