基于马尔可夫链的句子生成
markovip的Python项目详细描述
马尔科夫
当你给她完整的课文后,她试着用连贯的句子和你进行引人注目的对话。不,她不会抱怨你的语料库有多大。另外,不要问她是否能通过图灵测试。她可能不会再和你说话了。
我wrote a blog post如果你感兴趣的话,我会解释动机以及幕后的原因
安装
要安装markovipy,请在终端中运行此命令:
$ pip install markovipy
这是安装markovipy的首选方法,因为它总是安装最新的稳定版本。
如果您没有安装pip,这个Python installation guide可以指导您 你完成了整个过程。
用法
在项目中使用markovipy:
>>> from markovipy import MarkoviPy >>> >>> # create MarkoviPy object >>> obj = MarkoviPy("/Users/tasrahma/development/projects/markovipy/corpus/ts_eliot/Gerontion_utf8.txt", 3) >>> >>> >>> # arguments passed, is the initial corpus file and the markov chain length(defaults to 2 if nothing passed) >>> obj.generate_sentence() 'Cammel, whirled Beyond the circuit of the shuddering Bear In fractured atoms.' >>> >>> obj.generate_sentence() 'After such knowledge, what forgiveness? Think now History has many cunning passages, contrived corridors And issues, deceives with whispering ambitions, Guides us by vanities.' >>> >>> obj.generate_sentence() 'Gull against the wind, in the windy straits Of Belle Isle, or running on the Horn, White feathers in the snow, the Gulf claims, And an old man, a dull head among windy spaces.' >>> >>> obj.generate_sentence() 'Silvero With caressing hands, at Limoges Who walked all night in the field overhead; Rocks, moss, stonecrop, iron, merds.' >>> >>> obj.generate_sentence() "Gives too soon Into weak hands, what's thought can be dispensed with Till the refusal propagates a fear."
- 自由软件:GNU通用公共许可v3
- 文档:https://markovipy.readthedocs.io。
功能
- 要添加更多测试。到目前为止,已经编写了一些最低限度的测试。我们非常欢迎你的贡献。
- 创建一个带有一些漂亮按钮/ui的web界面,它会给你随机的引号。
历史记录
0.3.0(2017-05-30)
在markovipy模块中公开了Markovipy类。 API从
from markovipy.markovipy import MarkoviPy
到
from markovipy import MarkoviPy
0.2.0(2017-04-29)
- self.middle_value映射变为defaultdict
- list_to_tuple()被删除,只使用tuple()
- 已将self.words_list = get_word_list(self.filename)移动到
__init__()
0.1.1(2017-04-14)
- 在读取文件时修复了UnicodeDecodeError,而不是使用普通的open()
0.1.0(2017-04-11)
- pypi上的第一个版本。