当前位置: 首页>>代码示例>>Python>>正文


Python Markov.scan方法代码示例

本文整理汇总了Python中markov.Markov.scan方法的典型用法代码示例。如果您正苦于以下问题:Python Markov.scan方法的具体用法?Python Markov.scan怎么用?Python Markov.scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在markov.Markov的用法示例。


在下文中一共展示了Markov.scan方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_count

# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import scan [as 别名]
    def test_count(self):
        m = Markov(2)
        m.scan(['a', 'b', 'b', 'b', 'c'])
        self.assertEquals(m.chains['a']['count'], 1)
        self.assertEquals(m.chains['b']['count'], 3)

        self.assertEquals(m.chains['a']['next']['b']['count'], 1)
        self.assertEquals(m.chains['b']['next']['b']['count'], 2)
        self.assertEquals(m.chains['b']['next']['c']['count'], 1)
开发者ID:thegreatape,项目名称:mockingbard,代码行数:11,代码来源:tests.py

示例2: test_probabilities

# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import scan [as 别名]
    def test_probabilities(self):
        m = Markov(2)
        m.scan(['bacon', 'fish', 'bacon', 'lung',
                'bacon', 'lung', 'bacon', 'lung',  '.'])
        result = m.compute_probabilities(3)
        self.assertEquals(len(result), 3)

        # least likely to most
        self.assertEquals(result[0]['word'], 'fish')
        self.assertEquals(result[0]['chance'], 1.0/8.0 * (1.0 / 0.5))
        self.assertEquals(result[1]['word'], 'lung')
        self.assertEquals(result[1]['chance'], 3.0/8.0 * (1.0 / 0.5))
        self.assertEquals(result[2]['word'], 'bacon')
        self.assertEquals(result[2]['chance'], 0.5 * (1.0 / 0.5))
开发者ID:thegreatape,项目名称:mockingbard,代码行数:16,代码来源:tests.py

示例3: TestParsing

# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import scan [as 别名]
class TestParsing(unittest.TestCase):
    def setUp(self):
        self.markov = Markov()

    def test_basic_tokenize(self):
        result = self.markov.tokenize("grraaaaa brainss monkeybutter")
        self.assertEquals(result, ["grraaaaa", "brainss", "monkeybutter"])

    def test_basic_scan(self):
        self.markov.scan(['a', 'b', 'c', 'd', 'e'])
        self.assertTrue('a' in self.markov.chains)
        self.assertTrue('b' in self.markov.chains)
        self.assertTrue('c' in self.markov.chains)

        self.assertTrue('b' in self.markov.chains['a']['next'])
        self.assertTrue('c' in self.markov.chains['a']['next']['b']['next'])
        self.assertTrue('d' in self.markov.chains['b']['next']['c']['next'])

    def test_count(self):
        m = Markov(2)
        m.scan(['a', 'b', 'b', 'b', 'c'])
        self.assertEquals(m.chains['a']['count'], 1)
        self.assertEquals(m.chains['b']['count'], 3)

        self.assertEquals(m.chains['a']['next']['b']['count'], 1)
        self.assertEquals(m.chains['b']['next']['b']['count'], 2)
        self.assertEquals(m.chains['b']['next']['c']['count'], 1)

    def test_probabilities(self):
        m = Markov(2)
        m.scan(['bacon', 'fish', 'bacon', 'lung',
                'bacon', 'lung', 'bacon', 'lung',  '.'])
        result = m.compute_probabilities(3)
        self.assertEquals(len(result), 3)

        # least likely to most
        self.assertEquals(result[0]['word'], 'fish')
        self.assertEquals(result[0]['chance'], 1.0/8.0 * (1.0 / 0.5))
        self.assertEquals(result[1]['word'], 'lung')
        self.assertEquals(result[1]['chance'], 3.0/8.0 * (1.0 / 0.5))
        self.assertEquals(result[2]['word'], 'bacon')
        self.assertEquals(result[2]['chance'], 0.5 * (1.0 / 0.5))
开发者ID:thegreatape,项目名称:mockingbard,代码行数:44,代码来源:tests.py


注:本文中的markov.Markov.scan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。