A customizable bullshit generator based on Seb Pearce's 'New-Age Bullshit Generator'
Project description
nabg (New-Age Bullshit Generator)
What is it?
nabg lets you generate randomized sentences using pre-defined sentence patterns and a vocabulary. The default vocabulary and sentences are based on Seb Pearce's "New Age Bullshit Generator". You can also provide your own sentence patterns and word lists to generate customized bullshit.
Installing nabg
nabg is available on PyPI:
pip install nabg
Usage
Generating New-Age Bullshit
nabg comes with Seb Pearce's "New-Age Bullshit Generator". To generate new-age bullshit, in python you can do:
import nabg
# Generate new-age bullshit
nabg.ionize()
# List the available topics
nabg.list_topics()
# Generate 5 bullshit sentences with topic history
nabg.ionize(5, "history")
Or, you can use the CLI:
# Generate new-age bullshit
$ nabg
# List the available topics
$ nabg --list-topics
# Generate 5 bullshit sentences with topic history
$ nabg -n 5 -t history
Generating Custom Bullshit
nabg also lets you use your own sentence patterns and vocabulary to generate sentences.
from nabg import BullshitGenerator
# ---------------------------------------------------------------------------- #
# Custom sentence patterns. A dictionary with a list of patterns for each #
# topic. All instances of ${vocabType} will be replaced with a randomly picked #
# word of type "vocabType" from the vocabulary. #
# ---------------------------------------------------------------------------- #
patterns = {
"topic1": [
"This is a ${adj} sentence.",
"This is a ${adjPrefix}${adj} sentence."
],
"topic2": [
"We can no longer afford to live with ${nMassBad}.",
"Without ${nMass}, one cannot ${viPerson}.",
],
}
# ---------------------------------------------------------------------------- #
# Custom vocabulary. A dictionary with a list of buzzwords for each type. #
# Each type used in a sentence pattern must have at least one word in the #
# vocabulary. #
# ---------------------------------------------------------------------------- #
vocabulary = {
"adj": [
"fantastic",
"stupid",
"amazing",
],
"adjPrefix": [
"ultra-",
"semi-",
],
"nMass": [
"knowledge",
"truth",
],
"nMassBad": [
"pain",
"suffering",
],
"viPerson": [
"exist",
"believe",
],
}
# Create a bullshit generator object
bullshit_generator = BullshitGenerator(patterns, vocabulary)
# Generate custom bullshit
bullshit_generator.ionize(5, "topic1")
BullshitGenerator
ensures that sentence patterns aren't repeated on multiple calls to BullshitGenerator.ionize()
. If there are no unused sentence patterns remaining in the pool for the requested topic, another topic is chosen at random. This behavior can be customised by calling any of the three methods below:
# The three methods below can be used to set BullshitGenerator's behavior
# when no more unused patterns are available for the requested topic.
# Pick a different topic at random. This is the default behavior.
bullshit_generator.use_random_topic_when_out_of_patterns()
# Reset the pool. This would cause previously used patterns to repeat.
bullshit_generator.reset_pool_when_out_of_patterns()
# Raise a NoPatternsAvailableError.
bullshit_generator.raise_error_when_out_of_patterns()
When all sentence patterns across all topics have been used up, the pool is reset. This behavior can be customised by calling any of the two methods below:
# The two methods below can be used to set BullshitGenerator's behavior
# when all patterns across topics have been used up.
# Automatically reset the pool. This is the default behavior.
bullshit_generator.enable_auto_reset()
# Raise a NoPatternsAvailableError.
bullshit_generator.disable_auto_reset()
You can reset the pool manually at any time by calling:
bullshit_generator.reset_sentence_patterns()
Note: Successive calls to nabg.ionize()
are not guaranteed to have distinct sentence patterns across calls (or in other words, the pool is reset after each call to nabg.ionize()
). However, the sentence patterns and vocabulary for the default new-age bullshit generator can be used to create your own instance of BullshitGenerator
to customize this behaviour:
from nabg import BullshitGenerator, patterns, vocabulary
# Create a BullshitGenerator object using Seb Pearce's pattern and vocabulary set
bullshit_generator = BullshitGenerator(patterns, vocabulary)
# The calls below are guaranteed to use different sentence patterns
print(bullshit_generator.ionize(3))
print(bullshit_generator.ionize(5))
print(bullshit_generator.ionize(2))
# Reset the pool
bullshit_generator.reset_sentence_patterns()
# The below call might use the same sentence pattern as one of the above calls as the pool has been reset
print(bullshit_generator.ionize())
Developing nabg
- Clone the repository.
git clone https://github.com/naveen-u/nabg.git
- Create and activate a virtual environment:
virtualenv venv
source venv/bin/activate
- To install nabg, along with along with the tools you need to develop and run tests, run the following in your virtualenv: :
pip3 install -e .[dev]
References
Authors
- Naveen Unnikrishnan - Initial work - naveen-u
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.