Article Spinning with Spintax
Article spinning is a search engine optimization technique by which search engine optimizers post a unique version of relevant content on article directories, web 2.0 sites, or other sources for backlinks.
It is occasionally used by website authors on their own sites but usually avoided because the quality of spun content will be lower than hand written content. Spinning works by rewriting existing articles, or parts of articles, and replacing specific words, phrases, sentences, or even entire paragraphs with any number of alternate versions to provide a slightly different variation with each spin.
This process can be completely automated or rewritten manually. Your job today will be to create a program or function which interprets a string containing Spintax, the syntax by which a program would read the different options available. Below is an example string that uses Spintax:
{Hello|Hi there|Bonjour}, user! {What's up?|How are you?|Feeling alright?|I caught a fish!}
As you can see, sections of the string that are to be 'spun' are enclosed in curly braces, where individual options are split by the |
character. Here are some example sentences this could produce.
Hi there, user! What's up?
Hello, user! How are you?
Bonjour, user! Feeling alright?
Hello, user! What's up?
Hi there, user! I caught a fish!
Your Job
Your mission, should you choose to accept it, is to create a program or function which takes an input string that may or may not contain Spintax, then print 5 versions of the string, randomly selecting one of the choices from each block of options. You can make a few assumptions:
- You will not need to handle nested Spintax (
{This|is {an|one}|example}
). - The
|
,{
and}
characters will not occur anywhere else other than within a Spintax block. - You do not need to check if the 5 output sentences are distinct, as long as the code selects options using your language's random number function.
- You may assume the input ends with a newline.
Rules
Tests
1. {A|The|One} {quick|magnificent|charming|lucky|fast|super|cool} {gold|tan|yellow|white|brown|silver} {beaver|packrat|cat|lion|tiger|fox|dog|wolf} {consumed|ate|pilfered} my {pastry|strudel|cake}.
-------------------------------------------
One cool brown wolf consumed my pastry.
...(3 more here)...
The charming yellow beaver ate my cake.
-------------------------------------------
2. This sentence is valid, and happens to have no Spintax!
-------------------------------------------
This sentence is valid, and happens to have no Spintax!
...(3 more here)...
This sentence is valid, and happens to have no Spintax!
-------------------------------------------
3. {beg|get|ton|sun|bun|can|top|big}{2|3|4|5}{A|B|C|D|E|F|G}{2|3|4|5|6|7}{at|as|be|ex|hi|}{!|#|%}
-------------------------------------------
top2F2hi%
...(3 more here)...
big3E4ex#
A fourth test can be found here.
This is code-golf, so fewest number of bytes wins.
{
,|
,}
is going to be found in the input string is where there is Spintax. \$\endgroup\$