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


Python Markov.sentence方法代碼示例

本文整理匯總了Python中markov.Markov.sentence方法的典型用法代碼示例。如果您正苦於以下問題:Python Markov.sentence方法的具體用法?Python Markov.sentence怎麽用?Python Markov.sentence使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在markov.Markov的用法示例。


在下文中一共展示了Markov.sentence方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from markov import Markov [as 別名]
# 或者: from markov.Markov import sentence [as 別名]
def main():
    twitter = Twython(KEY, access_token=TOKEN)
    try:
        tweets = twitter.get_user_timeline(screen_name=raw_input("twitter username: "), count=200)
    except:
        print "User does not exist."
        return
    try:
        count = int(raw_input("number of tweets to generate: "))
        text = ""
        for tw in tweets:
            text += re.sub("https?:\/\/([^\s]+)", "", tw['text']) + ". "
        mk = Markov(text)
        sentences = ""
        for i in range(0, count):
            print mk.sentence()

    except:
        print "Please enter a valid number."
開發者ID:tylerbonnell,項目名稱:Markov,代碼行數:21,代碼來源:lazy_tweeter.py

示例2: main

# 需要導入模塊: from markov import Markov [as 別名]
# 或者: from markov.Markov import sentence [as 別名]
def main():
    r = praw.Reddit(user_agent="Markov Comment Generator by /u/officialdovahkiin")
    name = raw_input("reddit username: ")
    user = r.get_redditor(name)
    if (valid_redditor(user)):
        try:
            comment_amount = int(raw_input("number of comments to consider: "))
            sentence_amount = int(raw_input("number of sentences to generate: "))
            comments = user.get_comments(limit=(None if comment_amount <= 0 else comment_amount))
            text = ""
            for c in comments:
                text += format_comment(c.body) + ". "
            mk = Markov(text)
            sentences = ""
            for i in range(0, sentence_amount):
                sentences += mk.sentence() + ". "
            print sentences
        except:
            print "Please enter a valid number"
    else:
        print "No comments found for /u/" + name
開發者ID:tylerbonnell,項目名稱:Markov,代碼行數:23,代碼來源:reddit_comment.py

示例3: main

# 需要導入模塊: from markov import Markov [as 別名]
# 或者: from markov.Markov import sentence [as 別名]
def main():
    f = open('sherlock.txt', 'r')
    mk = Markov(f.read())
    for i in range(0, 3):
        print mk.sentence()
開發者ID:tylerbonnell,項目名稱:Markov,代碼行數:7,代碼來源:main.py


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