-
Notifications
You must be signed in to change notification settings - Fork 9
Program structure
In this section, we discuss the many parts of this software.
-
data/powerpoint/template.pptx
: This Powerpoint file contains the powerpoint presentation to start from. The interesting part of this file is when opening the model view, as you can edit the slide templates and their placeholders. -
slide_templates.py
: This Python module is responsible for filling in thetemplate.pptx
with values. There are also functions present which you can give as arguments functions that generates content when given apresentation_context
dictionary. It will then generate the content, and if certain conditions (e.g. originality) are satisfied, it will create and add a slide to the presentation.
-
PresentationSchema: This class controls the parameters of the powerpoint generator. It contains information about which slide generators to use, which slide topic generator and a dictionary
max_allowed_tags
that contains information about how many times slide generators with certain tags are allowed to generate in one presentation. We might add different presentation schemas for different types of presentation generators in the future. The PresentationSchema class can be found inpresentation_schema.py
. -
SlideGenerator: This class contains information about how to generate a particular type of slide. It holds a generating function for this purpose, as well as meta-data. For example, it contains a
weight_function
to calculate the chance of being used for a certain slide number, a name and tags for the generator, the allowed number of elements that have already been used in the presentation and the number of retries the slide generator is allowed to make in case it fails to generate a slide. The SlideGenerator class can be found inpresentation_schema.py
. -
SlideTopicGenerator: This is type of class that has a
generate_seed(slide_nr)
function, which generates a seed for the given slide number, which tends to be based on the topic of the presentation (as entered by the user). This slideseed
will then be given to a Slide Generator as an inspiration point for the content of the slide. There are several types of topic generators, such as a slide topic generator that just returns the presentation topic, one that gives synonyms and one that makes little side tracks using related concepts onConceptNet
-
presentation_context
: This is an object that is created by the Presentation Schema, containing information about the topic and presenter of the presentation, the used content and theseed
for the current slide
We wrote our own custom templated text generation language to easily generate texts. They're mostly based on Python's str.format
and Tracery, but come with some extra functionalities (see also language_util
)
The template files themselves are stored in /data/text-templates/*
On construction, this object is given the name of a file that contains a text template on a new line, usually in a .txt
file. Similar to the build-in str.format
function, these text templates can contain named variables between curly brackets {variable_name}
. Usually, the presentation_context
dictionary is used as an argument. This means that in these text generators {seed}
will be the variable containing the slide topic seed. This dictionary can also be extended before generating the text, such that more, custom variables are also possible.
A difference is that our custom language also provides some functions that can be easily called within the template. If a function returns None, or the variable is not present in the given dictionary, the text generator will keep retrying to generate until no templates are left. An example of such a function is {seed.plural.title}
, which will pluralise the seed, and then apply title casing.
Listed below are some possible functions in our text generation language. The up-to-date list of function can be found in text_generator.py
.
Function | Description |
---|---|
title |
Converts the string to title casing |
lower |
Converts the string to lower casing |
upper |
Converts the string to upper casing |
dashes |
Replaces the spaces of the string with dashes |
a |
Adds the "a" article, or "an" if the word starts with a vowel (except u) |
ing |
Converts a verb to the present participle |
plural |
Converts a noun to plural |
singular |
Converts a noun to singular |
synonym |
Converts the noun to a random synonym |
2_to_1_pronouns |
Changes 2nd person pronouns to 1st person pronouns in a sentence (e.g. you->my) |
wikihow_action |
Retrieves a random action based on the string using Wikihow |
get_last_noun_and_article |
Extracts the last noun from a sentence |
conceptnet_location |
Retrieves a location related to the string using Conceptnet |
is_noun |
Checks if the string can be a noun |
is_verb |
Checks if the string can be a verb |
Allows the same things TemplatedTextGenerator
does, but using a Tracery grammar. This means that the file is saved as a JSON file, and that local variables can be declared, for easily creating a large possibility space of possible texts.
-
random_util
: This module helps with dealing better with randomness. It has a function to deal with picking from a list with weighted elements, as well aschoice_optional(list)
, which is likerandom.choice
, except it returns None if the list is empty -
generator_util
: This module provides lots of utilities for creating generators. Since some content generators return (image or textual) lists, there are functions for converting them to normal single output generators. There are also methods for converting methods that only take a stringseed
as input to one that takes apresentation_context
, namelycreate_seeded_generator(generator)
. There are also more exotic generators such as weighted generators and walking generators. -
language_util
: Contains many language functionalities, such as converting to singular/plural, changing tense, checking part of speech, getting synonyms etc. -
scraper_util
: Provides some common functionalities for the page scrapers. -
os_util
: Contains some methods dealing with the operating system, such as saving and checking files. -
cache_util
: Contains a hashable dictionary class, which is necessary for caching certain functions.
There are a lot of different services providing content to our generator. Usually, the content scrapers below are used in run.py
to craft a real concent generator used in the slides generators.
-
chart.py
: Generates random powerpoint charts using text templates and random math functions. -
conceptnet.py
: Explores the graph of related concepts to certain seeds -
goodreads.py
: Used for retrieving quotes related to a seed -
google_images.py
: Used for retrieving relevant images for certain seeds (e.g. as background image) -
inspirobot.py
: Used for retrieving nonsensical quote images -
reddit.py
: Used for scraping reddit images, as there are many interesting subreddits to scrape images from. -
shitpostbot.py
: Used for retrieving "interesting"/weird images -
wikihow.py
: Used for finding related actions to a certain seed.
Sometimes, certain content providers return a default image when no image is found for that url (usually when an image got deleted). These types of images are stored in our repository in data/images/prohibited/*
. This folder gets automatically scanned, and all images in the generated presentation are compared to images from this folder, to ensure that none gets added to the final presentation.