當前位置: 首頁>>代碼示例>>Python>>正文


Python Markov.generate_markov_text方法代碼示例

本文整理匯總了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
開發者ID:mwhooker,項目名稱:bad-love,代碼行數:16,代碼來源:bad_love.py

示例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
開發者ID:markfiend,項目名稱:markov-wiki-ircbot,代碼行數:22,代碼來源:markovtweet.py

示例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))
開發者ID:zellahenderson,項目名稱:markov2,代碼行數:9,代碼來源:generateMarkovChain.py

示例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)
開發者ID:aprikat,項目名稱:PyTextalyzer,代碼行數:7,代碼來源:main.py


注:本文中的markov.Markov.generate_markov_text方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。