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


Python Markov.generate方法代碼示例

本文整理匯總了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)
開發者ID:ekatek,項目名稱:nanowrinet,代碼行數:12,代碼來源:lambda_function.py

示例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)
開發者ID:gthomas,項目名稱:python-markov,代碼行數:42,代碼來源:tests.py

示例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
開發者ID:riordan,項目名稱:ponyinthere,代碼行數:15,代碼來源:tweetslice.py

示例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)
開發者ID:vfulco,項目名稱:python-markov,代碼行數:72,代碼來源:tests.py

示例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
開發者ID:jordanribera,項目名稱:song-serpent,代碼行數:7,代碼來源:song-serpent.py


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