Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Buzzword poem generator in Python

Delimitry
February 13, 2018

Buzzword poem generator in Python

The presentation from SPbPython community / PiterPy meetup
about the tool in pure Python for generation of the poems from the buzzwords.

Delimitry

February 13, 2018
Tweet

More Decks by Delimitry

Other Decks in Programming

Transcript

  1. Buzzword poem
    generator in Python
    Dmitry Alimov
    2018

    View full-size slide

  2. Inspired by this tweet
    2

    View full-size slide

  3. Plan
    1) Prepare list of buzzwords
    2) Prepare rhymes
    3) Generate base from given number of syllables in lines and number of lines
    4) Find list of rhymes for generated base
    5) Fill poem base with buzzwords from given rhyme scheme and base
    3

    View full-size slide

  4. Algorithm
    1) Knowing the total number of syllables in each line — generate all combinations
    of sums (compositions) from all available number of syllables.
    Compositions of 3:
    1 + 1 + 1
    1 + 2
    2 + 1
    3
    NB: Each positive integer n has 2 ** (n - 1) distinct compositions.
    4

    View full-size slide

  5. Algorithm
    2) Knowing the number of syllables in each line, generate the base (I call it so) for
    future poem from random compositions for each number of syllables.
    E.g. for number of syllables in lines [4, 4], poem base is:
    1, 2, 1
    1, 3
    5

    View full-size slide

  6. Algorithm
    3) After generating of poem base and known rhyme scheme — find rhymes.
    For poem base:
    1, 2, 1
    1, 3
    and rhyme scheme AA (i.e. first and second lines rhyme with each other).
    To prepare rhymes get only last values (here 1, 3), because only the last words
    form a rhyme.
    I.e. for the poem above find rhymes for words with number of syllables 1, 3.
    Storm and Ter-ra-form are fit.
    6

    View full-size slide

  7. Algorithm
    4) Fill the poem base with buzzwords. Insert the rhymes found in previous step.
    1, 2, Storm
    1, Ter-ra-form
    Fill the remaining values with not used buzzwords:
    Go Sca-la Storm
    Vault Ter-ra-form
    7

    View full-size slide

  8. Examples
    ./buzzword_poem_generator.py -r ABAB -s 7 7 7 7 -m 3
    Kinesis Flink Hadoop Swarm
    Impala Splunk Riak Raft
    Couchbase Go HBase Storm
    Zookeeper Sqoop Nomad Rust
    8

    View full-size slide

  9. Examples
    ./buzzword_poem_generator.py -r AABB -s 7 7 7 7
    Riak Swarm Storm Flink Travis
    HBase Splunk Go Raft Redis
    Keras Nomad Spark Sqoop
    Logstash Hive Vault Rust Hadoop
    9

    View full-size slide

  10. Examples
    ./buzzword_poem_generator.py -r ABABA -s 7 7 7 7 7
    Splunk Swarm Hazelcast Flink Rust
    Chef Hive Couchbase Vault Sqoop
    Storm Go Cassandra Spark Raft
    Lambda Terraform Hadoop
    Erlang Celery React
    10

    View full-size slide

  11. Github project
    12

    View full-size slide

  12. .travis.yml
    language: python
    python:
    - "2.7"
    - "3.5"
    - "3.6"
    install:
    - pip install coveralls
    script:
    - coverage run --source=buzzword_poem_generator tests.py
    after_success:
    - coveralls
    13

    View full-size slide

  13. Travis CI integration
    14

    View full-size slide

  14. Coveralls integration for tests coverage
    15

    View full-size slide

  15. Future plans
    Add support of words metrical feet:
    / — ictus (stressed syllable), x — nonictus (unstressed syllable)
    {
    ...
    'Python': ['/', 'x'],
    'TensorFlow': ['/', 'x', '/'],
    ...
    }
    16

    View full-size slide

  16. Questions
    https://t.me/spbpython
    https://t.me/piterpy_meetup
    17

    View full-size slide

  17. Links
    https://twitter.com/lenadroid/status/957054198872293378
    http://delimitry.blogspot.com/2018/02/buzzword-poem-generator.html
    http://delimitry.blogspot.com/2018/02/buzzword-poem-generator-algorithm.html
    https://github.com/delimitry/buzzword_poem_generator
    18

    View full-size slide