本文整理汇总了Python中markov.Markov.generate方法的典型用法代码示例。如果您正苦于以下问题:Python Markov.generate方法的具体用法?Python Markov.generate怎么用?Python Markov.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类markov.Markov
的用法示例。
在下文中一共展示了Markov.generate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lambda_handler
# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import generate [as 别名]
def lambda_handler(event, context):
"""Entrypoint for AWS Lambda. Event contains the payload from the AWS Lambda
call."""
user_text = event['userText']
mixin = event['mixin']
length = int(event['length'])
full_text = user_text + load_mixin(mixin)
markover = Markov(full_text)
return markover.generate(length)
示例2: TestMarkovClass
# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import generate [as 别名]
class TestMarkovClass(unittest.TestCase):
"""
Test that the Markov wrapper class behaves as expected
"""
def setUp(self):
self.markov = Markov(prefix="testclass",db=11)
def test_add_line_to_index(self):
line = ['i','ate','a','peach']
line1 = ['i','ate','one','peach']
line2 = ['i','ate','a', 'sandwich']
self.markov.add_line_to_index(line)
self.markov.add_line_to_index(line1)
self.markov.add_line_to_index(line2)
self.assertEqual(self.markov.client.zscore("testclass:i:ate", "a"), 2.0)
self.assertEqual(self.markov.client.zscore("testclass:ate:a", "peach"), 1.0)
def test_score_for_line(self):
self.test_add_line_to_index()
line = ['i','ate','a','peach']
self.assertEqual(self.markov.score_for_line(line), 100)
def test_generate(self):
self.test_add_line_to_index()
generated = self.markov.generate(max_words=3)
assert len(generated) >= 2
assert len(generated) <= 3
generated = self.markov.generate(seed=['ate','one'], max_words=3)
assert 'peach' in generated
assert 'sandwich' not in generated
def tearDown(self):
"""
clean up our redis keys
"""
keys = self.markov.client.keys(self.markov.prefix+"*")
for key in keys:
self.markov.client.delete(key)
示例3: newTweet
# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import generate [as 别名]
def newTweet():
tweet_data = Markov(prefix="tweets")
tweetline = tweet_data.generate()
tweet = ""
for word in tweetline:
tweet += word + " "
tweet = tweet.rstrip()
if len(tweet)>140:
return newTweet()
else:
return tweet
示例4: TestMarkovClass
# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import generate [as 别名]
class TestMarkovClass(unittest.TestCase):
"""
Test that the Markov wrapper class behaves as expected
"""
def setUp(self):
self.markov = Markov(prefix="testclass", db=11)
def test_add_line_to_index(self):
line = ['i','ate','a','peach']
line1 = ['i','ate','one','peach']
line2 = ['i','ate','a', 'sandwich']
self.markov.add_line_to_index(line)
self.markov.add_line_to_index(line1)
self.markov.add_line_to_index(line2)
self.assertEqual(self.markov.client.zscore("testclass:i:ate", "a"), 2.0)
self.assertEqual(self.markov.client.zscore("testclass:ate:a", "peach"), 1.0)
def test_score_for_line(self):
self.test_add_line_to_index()
line = ['i','ate','a','peach']
self.assertEqual(self.markov.score_for_line(line), 100)
def test_generate(self):
self.test_add_line_to_index()
generated = self.markov.generate(max_words=3)
assert len(generated) >= 2
assert len(generated) <= 3
generated = self.markov.generate(seed=['ate','one'], max_words=3)
assert 'peach' in generated
assert 'sandwich' not in generated
def test_flush(self):
m1 = Markov(prefix="one", db=5)
m2 = Markov(prefix="two", db=5)
line = ['i','ate','a','peach']
line1 = ['i','ate','one','peach']
line2 = ['i','ate','a', 'sandwich']
m1.add_line_to_index(line)
m1.add_line_to_index(line1)
m1.add_line_to_index(line2)
important_line = ['we', 'all', 'have', 'phones']
m2.add_line_to_index(important_line)
r = redis.Redis(db=5)
assert len(r.keys("one:*")) == 6
assert len(r.keys("two:*")) == 3
m1.flush(prefix="one")
assert len(r.keys("one:*")) == 0
assert len(r.keys("two:*")) == 3
m2.flush(prefix="two")
assert len(r.keys("one:*")) == 0
assert len(r.keys("two:*")) == 0
def tearDown(self):
"""
clean up our redis keys
"""
keys = self.markov.client.keys(self.markov.prefix+"*")
for key in keys:
self.markov.client.delete(key)
示例5: make_tweet
# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import generate [as 别名]
def make_tweet(target):
target_data = Markov(target)
output_tweet = target_data.generate(max_words=10)
return output_tweet