How best to handle the result issued by wordai?

Want to make the site unique text by using the wordai service. To do this, they have API function https://wordai.com/api.phpissuing the result in this form

{Here is|Here's} {an example|a good example|an illustration}


ie what can you say multiple choice is given in parentheses. And there are structures {{word, word} , {word, word, word, word}}, just a word {word, word}. Maybe you have ideas to make this a random text?
July 2nd 19 at 13:28
1 answer
July 2nd 19 at 13:30
If I'm not mistaken, the parameter returnspin is responsible for what in the result you should get: have a unique article or a unique template for you.

But if you want to handle such patterns, then there's nothing complicated, just search for all pairs of curly braces, and choose a random option if within this option, there are a couple brackets and handle it and so until then, until there is clean text.
returnspin gives only one result for some reason. Don't quite understand how you can handle parentheses in parentheses. If there was only single brackets, and there, Yes, count them, content to make the arrays, choose randomly from each array and insert into the right place, but nested parentheses how to handle? - Verda_Reynol commented on July 2nd 19 at 13:33
To introduce two-dimensional arrays is not desirable - Verda_Reynol commented on July 2nd 19 at 13:36
In the same way. I can throw you my realization of this task in Delphi, if you can figure out. Sorry, but to translate to PHP I will not. - vincenza.Satterfield commented on July 2nd 19 at 13:39
Of course, throw :) thanks - Verda_Reynol commented on July 2nd 19 at 13:42
Well look, the easiest option that comes to mind:
1. Go cycle through the text until you get to {
2. Transfer this position to another function that is looking for a couple that open parenthesis
3. When she finds a couple, then splits to an array of variants (in a similar way, passing places nested parentheses)
4. Selects one of variantov and replaces the text
5. Return to the first function, which continues the search from the same position where he finished only changed the text and operate on the same principle

Ie if we have a text
{{word, word} , {word, word, word, word}}, just a word {word, word}

After the first finding { will be approximately the following:
{word, word}, a word {word, word}

Then the script again immediately finds an open parenthesis and again selects the desired option remains:
the word is just a word {word, word}

Oh, and then clear. You would show your first draft of the code would be easier to show what to change/add necessary - vincenza.Satterfield commented on July 2nd 19 at 13:45
Of course, throw :) thanks

Unfortunately a simple version I wrote in Delphi I have left, I once made a more powerful algorithm in C++ to build the tree of options. I'm afraid in your case it will not help you. - vincenza.Satterfield commented on July 2nd 19 at 13:48
Thank you for this! - Verda_Reynol commented on July 2nd 19 at 13:51

Find more questions by tags PHP