根据真实英语单词使用的模式生成合成词。
fictionar的Python项目详细描述
根据真实英语单词使用的模式生成合成词。
使用虚构的
安装时使用:
pip install --upgrade fictionary
通过运行virtualary-h:
usage: fictionary [-h] [-v] [-c COUNT] [-m LENGTH] [-x LENGTH] [-d {all,american,british}] A made-up word factory, following standard English word rules. optional arguments: -h, --help show this help message and exit -v, --verbose Be verbose. -c COUNT, --count COUNT The number of words to create. -m LENGTH, --min-length LENGTH Only make_model words of LENGTH chars or longer. -x LENGTH, --max-length LENGTH Only make_model words of LENGTH chars or shorter. -d {all,american,british}, --dictionary {all,american,british} The dictionary rules to follow: american, british, or all
运行起来有点像这样:
$ fictionary nivenver $ fictionary -c 4 cest colped burpen flumat
库使用
您还可以将其用作库:
>>> import fictionary
>>> fictionary.word() 'regagreagised'
如果您想创建自己的模型:
# Create a model and add a couple of words to it:m=fictionary.Model()m.feed('table')m.feed('babel')# Now we can generate words!# (This model is capable of only 2 fictional words)print(m.random_word(5,5))# tabelprint(m.random_word(5,5))# bable# If you're building a model with *lots* of words, generating the model# can be slow, so you can save the generated model to a json file:withopen('my-fictionary-dict.json','w',encoding='utf-8')asfp:m.write(fp)# And then later you'll want to read it in with this:# (You still need to supply a list of 'real' words, for collision detection)new_model=fictionary.Model(words=['table','babel'])withopen('my-fictionary-dict.json','r',encoding='utf-8')asfp:new_model.read(fp)print(m.random_word(5,5))# bable
为什么???
为什么不呢?它特别有利于产生令人难忘但又合理的 长度密码,虽然我不确定这些密码有多安全 假设它们遵循定义良好的模式。总有一天我会坐下来 解决它。
工作原理
当它运行时,虚构的加载一个数据结构 称为马尔可夫链,它表示 字典中的单词(例如,最常见的第一个字母是“s”)。最常见的字母 单词开头的“s”是“t”等)。提供虚构的 有3个现成的型号:
Model | Description |
---|---|
all | Includes all words is both british and american wordlists. |
american | Includes English words, using American spelling. |
british | Includes English words, using British spelling. |
一旦小说作者理解了 英语,它可以用这些规则来产生新的,无意义的词 看起来像英语单词,但不是。马尔可夫链很容易 意外生成一个真正的英语单词,我们必须检查每个生成的单词 对照字典来确定它不是。
释放
这些是我的笔记,很明显:
- 检查自述文件
- bumpversion
- python setup.py sdist bdist\u控制盘
- 捆绳上传距离/*.*
待办事项
以下是本项目的待办事项:
- 允许有效单词
- 添加一个标志以关闭“实词”验证。
- 单词生成回滚
- 拒绝太长或太短的单词是相当昂贵的。我可以 重构此项以回滚和重新生成选项,直到有效的“word”为 达到。或者我可以找到更好的方法来打发时间。
- 优化长单词
- 遇到最大长度时立即使字生成器跳出。