本文整理汇总了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."
示例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
示例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()