当前位置: 首页>>代码示例>>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;未经允许,请勿转载。