Generate made-up words following the patterns used by real English words.
Project description
Generate made-up words following the patterns used by real English words.
Using Fictionary
Install with:
pip install --upgrade fictionary
You can learn how to use fictionary as a command-line tool by running fictionary -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
Running it looks a little like this:
$ fictionary nivenver $ fictionary -c 4 cest colped burpen flumat
Library Usage
And you can also use it as a library:
>>> import fictionary
>>> fictionary.word() 'regagreagised'
And if you want to create your own models:
# 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)) # tabel
print(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:
with open('my-fictionary-dict.json', 'w', encoding='utf-8') as fp:
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'])
with open('my-fictionary-dict.json', 'r', encoding='utf-8') as fp:
new_model.read(fp)
print(m.random_word(5, 5)) # bable
Why???
Why not? It is particularly good for generating memorable yet reasonable length passwords, although I’m not sure how secure those passwords would be given that they follow well-defined patterns. One day I might sit down and work it out.
How it Works
When it runs, fictionary loads a data structure called a Markov chain, which represents the patterns of letters found in the words in the dictionary (e.g. The most common first-letter is ‘s’. The most common letter following ‘s’ at the start of a word is ‘t’ etc.). Fictionary is supplied with 3 models out of the box:
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. |
Once fictionary understands the patterns of letters used in words in the English language, it can use these rules to generate new, nonsense words that look like English words, but aren’t. It’s so easy for the Markov chain to accidentally generate a real English word that we have to check each generated word against a dictionary to make sure it isn’t.
Releasing
These are notes for me, as is probably obvious:
Check the README
bumpversion
python setup.py sdist bdist_wheel
twine upload dist/*.*
To Do
The following is my to-do list for this project:
- Allow Valid Words
Add a flag to turn off ‘real-word’ validation.
- Word Generation Rollback
Rejecting words that are too long or short is reasonably expensive. I may refactor this to rollback and remake choices until a valid ‘word’ is reached. Or I may find something better to do with my time.
- Optimize Long Words
Make word-generator bail out as soon as max-length is encountered.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fictionary-0.1.0.tar.gz
.
File metadata
- Download URL: fictionary-0.1.0.tar.gz
- Upload date:
- Size: 891.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c60e1af7eee6b003d28701adcfe94b8ba951e9f1a9ed4b355b4d907013839d54 |
|
MD5 | 882955212098fe25a0bfa00ed3f6d043 |
|
BLAKE2b-256 | 3151ed265088445955fafff3be379d05697bf410c02aaa818d1b7395b9c790f1 |
File details
Details for the file fictionary-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: fictionary-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 426.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd7e43d8fb4ed83faf8813a7559ff491e176872c3c0aa55d5bb9f269ff49a7f9 |
|
MD5 | d829462ce01cfb27fb0536adb633cc65 |
|
BLAKE2b-256 | 6ac08e2a9bf8c7d7bba75c3642a65d27d204b102cb06eee876629f5c56f19933 |