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