$30 off During Our Annual Pro Sale. View Details »

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. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. .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
  10. Future plans Add support of words metrical feet: / —

    ictus (stressed syllable), x — nonictus (unstressed syllable) { ... 'Python': ['/', 'x'], 'TensorFlow': ['/', 'x', '/'], ... } 16