Skip to content

A number joke generator! (number joke: a sequence of numbers that mimics the structure of a "normal" joke)

License

Notifications You must be signed in to change notification settings

JSimple/number_jokes

Repository files navigation

to see my numberjoke generator go to: http://jsimple.pythonanywhere.com/

What is a Number Joke?

A number joke is an ordered sequence of numbers, the progression of which mimics the structure of a joke. For example:

a natural language joke
"When I was a kid my parents moved a lot, but I always found them"
–Rodney Dangerfield

a number joke
"3, 6, 9, 12, ... -9977, -49942, -149859"
–This module

It may not look like it but both of these jokes follow a similar structure:

  • a setup that establishes an expected rule through which you're interpreting the joke. followed by...
  • a Punchline that violates this rule, thereby making you realize that a different, less obvious, rule was at play the whole time.

In a natural language joke these rules are symantic or syntactic. In a number joke the rules are mathematical and can often be represented as functions. Take our examples:

natural language joke

  • setup: "When I was a kid my parents moved a lot,"
  • the implied rule: The word "move" in this joke means something like "changing homes as a family."
  • punchline: "but I always found them."
  • the actual rule: The word "move" in this joke actually means to literally just move around in space.

number joke

  • setup: "3, 6, 9, 12"
  • the implied rule: Joke(n) = 3 + 3n
  • punchline: "-9977, -49942, -149859"
  • the actual rule: Joke(n) = 3 + 2501n - 4579.667(n ** 2) + 2498(n ** 3) - 416.333(n ** 4)
    (yes the setup of "3, 6, 9, 12" does indeed follow this complicated rule )

Why should you care about number jokes?

The short answer is that you shouldn't.

The long answer is that for millenia psychologists, philosophers, and humorists have been trying to come up with theories of what makes something funny. All these theories have been notoriously hard to prove experimentally. Some of them even seem to be unfalsifiable.

But now with number jokes we have a way to mathematically model a theory of humor. The theory that number jokes are based on is the script-based semantic theory of humor. (Victor Raskin: Semantic Mechanisms of Humor, 1985) Creating an abstract mathematical model of a theory is the first step in establishing rigorous scientific proof of the theory. We can use mathematical models to make predictions and test them in real life experiments. As we generate number jokes, control for various parameters, and see which one people find funny - we may be able to establish proof for how humor itself works.

This is a joke, right?

Yes.

How does the number_jokes module work?

What's it for?

This module is designed to be used as a number joke generation API for the official number jokes website In future itterations, I plan to expand this module for general use.

What's it do?

number_jokes is a module that generates number jokes. Jokes generated by this module are made up of "joke parts." A joke part is a setup, a punchline, or a kicker (these are just aditional punchlines at the end of a joke that use the puncline preceeding them as their own setup). Joke parts are instantiated as a class. This module currently includes one type of joke part class, PolynomialJokePart. This class can serve as a setup, punchline, or kicker for a specific kind of number joke generation algorithm, called the Polynomial Gardenpath Algorythm. (More on this algorithm later.) This is the algorithm used by the number joke generation class called PolynomialGardenpath.

Here is a quick tutorial on how to generate number jokes using the PolynomialGardenpath class:

Create an instance of the class:

my_joke = PolynomialGardenpath()

Next, the quickest way to generate a joke is:

my_joke.gen_joke()

The content of the joke will be stored as a list of JokeParts in the my_joke's joke_parts attribute.

gen_joke has a couple of parameters that we can play around with if we want more control over the kind of joke we get. The most important parameter is the first one, jp_degree_and_length. This is a list of tuples that represent information about each of the joke parts we want to have in our joke. Each tuple in jp_degree_and_length consists of two values. The first represents the joke part's polynomial degree, and the second represents the joke part's length (i.e. how many numbers will be in the joke part).

for example, let's say we want to generate a number joke with the following structure:

  • a setup that follows a 1st degree polynomial rule and is 4 numbers long
  • a punchline that follows a 4th degree polynomial rule and is 3 numbers long
  • a kicker that follows a 7th degree polynomial rule and is 2 numbers long
  • another kicker (we can have as many as we want!) that follows a 10th degree polynomial rule and is 3 numbers long

This is what we'd input into the gen_joke method:

my_joke.gen_joke([
                (1,4), 
                (4,3),
                (7,2), 
                (10,3)
                ])

at any point in time we may add additional joke parts to our joke in a similar fashion using the add_gen_joke_parts method.

Let's say we want to add two more kickers, one that follows an 11th degree polynomial rule and has one number, and another that follows an 13th degree polynomial rule and has 5 numbers. This is how we'd do it:

my_joke.add_gen_joke_parts([ (11, 1), (13, 5)])

Now let's say we want to add one final kicker to our joke. But this time we don't want to leave the numbers in our joke part up to the semi-random algorithm. We actually want to specify that this joke part will be: 3, 2, 1. For this we can use the add_joke_part_w_points method like so:

my_joke.add_joke_part_w_points([3, 2, 1])

Now you know all the basic functionality for polynimial gardenpath generation! If you wante to get even further into the nitty-gritty, feel free to explore the module's docstrings.

Happy number joke generation!

About

A number joke generator! (number joke: a sequence of numbers that mimics the structure of a "normal" joke)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages