根据真实英语单词使用的模式生成合成词。

fictionar的Python项目详细描述


https://travis-ci.com/judy2k/fictionary.svg?branch=masterhttps://coveralls.io/repos/github/judy2k/fictionary/badge.svg?branch=masterhttps://img.shields.io/badge/code%20style-black-000000.svg

根据真实英语单词使用的模式生成合成词。

使用虚构的

安装时使用:

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个现成的型号:

ModelDescription
allIncludes all words is both british and american wordlists.
americanIncludes English words, using American spelling.
britishIncludes English words, using British spelling.

一旦小说作者理解了 英语,它可以用这些规则来产生新的,无意义的词 看起来像英语单词,但不是。马尔可夫链很容易 意外生成一个真正的英语单词,我们必须检查每个生成的单词 对照字典来确定它不是。

释放

这些是我的笔记,很明显:

  • 检查自述文件
  • bumpversion
  • python setup.py sdist bdist\u控制盘
  • 捆绳上传距离/*.*

待办事项

以下是本项目的待办事项:

允许有效单词
添加一个标志以关闭“实词”验证。
单词生成回滚
拒绝太长或太短的单词是相当昂贵的。我可以 重构此项以回滚和重新生成选项,直到有效的“word”为 达到。或者我可以找到更好的方法来打发时间。
优化长单词
遇到最大长度时立即使字生成器跳出。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java是否可以创建一个正则表达式来查找与模式不匹配的字符串?   使用“debugUnreturnedConnectionStackTraces”进行java调试连接丢失   java如何在openLDAP中禁用/启用用户帐户?   java无法从jsoup api获取某些类   java无法从APK提取XML文件   如何在linux命令行中替换多个文件中的字符串   java学生班。如何根据单位输入打印成绩?   java有没有办法将Struts配置为绑定null而不是空字符串?   python使用OpenCV[Java]检测简单几何形状   java文件。isFile()和文件。isDirectory()返回false   java Fetch有条件地加入hibernate,还是将实体设计更改为子实体上的条件Fetch?   java lombok@Data generated setter是否对成员对象(如映射)执行深度复制?   java如何使JLabel从下一行开始   java Gradle依赖解决了配置文件的问题