Fabulist Introduction

class: center, middle # Introduction to Fabulist > Random strings that make *sense*. https://github.com/mar10/fabulist/ <p> <small>(Hit <kbd>H</kbd>-key for help.)</small> </p> .footnote[ [Fabulist](https://github.com/mar10/fabulist/) © 2017 Martin Wendt] --- class: center, middle, inverse # Fabulist - what and why? --- class:left # What is Fabulist? Fabulist is an open source library written in Python that can -- 1. Generate random sentences based on custom patterns. -- 2. Generate random names. -- 3. Generate blind text (*lorem ipsum* et al). --- # Why? Use Fabulist to -- * Display mock data that is apposite to a given context. -- * Create test data that makes sense (sort of). -- * Create texts that are more fun to read than<br> *"asdf asdf"* or *"lorem ipsum dolor sit amet"*. --- class: center, middle, inverse ## Examples --- ## Example Generate quotes from a template string: ```python from fabulist import Fabulist fab = Fabulist() print fab.get_quote("$(Verb) $(noun)") ``` may produce something like -- ```bash Order boyfriend ``` --- ## Example Generate a sequence of unique random strings using a generator: ```python template = "$(Noun) $(verb:s) $(adv:#negative)" for q in fab.generate_quotes(template, count=1000, dedupe=True): print(q) ``` may produce something like -- ```bash Pension succeeds fiercely Philosophy approaches outrageously Delay integrates incorrectly Problem implicates unwillingly Relative surveys outrageously Agreement absorbs hatefully Environment falls unfavorably Anybody squeezes hopelessly Hyena tosses obnoxiously Light values kookily Personality horrifies ridiculously ... ``` --- ## Example Pass multiple template strings to mix more variants: ```python from fabulist import Fabulist fab = Fabulist() templates = [ "$(Verb) $(noun)", "Provide $(adj:#positive) $(noun:plural)", ] for q in fab.generate_quotes(templates, count=5): print(q) ``` may produce something like -- ```bash Provide favorite locks Tremble ice Provide superior noses Provide enormous economies Open crazy ``` --- ## Example: Person Names ```python >>> from fabulist import Fabulist >>> fab = Fabulist() >>> fab.get_name() 'Isaac Skinner' >>> fab.get_name("#f") 'Lisa Hart' >>> fab.get_name("#f:mr") 'Mrs. Pippa Walker' >>> fab.get_name("mr:middle:#m") 'Mr. Frank N. Glover' ``` -- Names can also be embeded in templates ```py template = ("My name is $(name:mr:middle)") for q in fab.generate_quotes(template, count=3): print(q) ``` ```bash My name is Mr. Paul M. Mathis My name is Mr. Carl Howard My name is Mrs. Felicity S. Lyman ``` --- ## Example: Passwords The 'num' word type generates random numbers within a given range and zero-padded.<br> The 'pick' word type allows to inject words or characters from a list of options. ```python template = r"$(Adj)-$(Noun)-$(num:1,9999,4)$(pick:\:#\,$%?!)" for q in fab.generate_quotes(template, count=3): print(q) ``` may produce something like -- ```bash Frugal-Work-8811: Woozy-Satisfaction-3112# Grand-Tap-6928! ``` --- ## Example: Mix With Python 'format()' Syntax Mix fabulist templates with standard Python formatting ```python import random template = "$(adj)-$(noun:#animal)-{idx:04d}" for q in fab.generate_quotes(template, count=3): q = q.format(idx=random.randint(0, 9999)) print(q) ``` may produce something like -- ```bash woozy-reindeer-5638 svelte-caribou-7290 cultivated-ant-7906 ``` --- ## Example: Fortune Cookies ```python from fabulist import Fabulist fab = Fabulist() templates = [ "$(Verb:ing) is better than $(verb:ing).", "$(Noun:an) a day keeps the $(noun:plural) away.", "If you want to $(verb) $(adv), $(verb) $(adv)!", 'Confucius says: "The one who wants to $(verb) must $(verb) $(adv) the $(noun)!"', ] for q in fab.generate_quotes(templates, count=5): print(q) ``` may produce something like -- ```bash A statement a day keeps the airports away. Praying is better than inspecting. Confucius says: "The one who wants to sterilize must inform miserably the possibility!" If you want to blur orderly, stride poorly! Confucius says: "The one who wants to vanish must swear terribly the punch!" ``` --- ## Example: Back-References A generated term may be re-used in a sentence. Use the `=NUM` macro to assign an entry to a variable and use `@NUM` to reference it in the same template: ```python >>>fab.get_quote("One $(noun:=1) is good, but two $(@1:plural) are better.") 'One salad is good, but two salads are better.' ``` --- class: center, middle, inverse ## Blind Text --- ## Blind Text Fabulist talks *Lorem Ipsum* in multiple dialects: ```python from fabulist import Fabulist fab = Fabulist() q = fab.get_lorem_paragraph(dialect="pulp", entropy=1) print(q) ``` may produce something like -- ``` Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. ``` --- class: center, middle, inverse ## What Next? --- # Install ```bash $ pip install fabulist ``` and [Read the docs...](http://fabulist.readthedocs.io/en/latest/) ### Credits This slides are made with [remark](https://github.com/gnab/remark).