![]() |
|
twLoremIpsumPlugin - 0.5.0False data generator with more-or-less normal distribution of letters |
|
False data generator with more-or-less normal distribution of letters
When it is necessary to generate test data for performance testing, or if you need to generate data for presentation purposes this plugin can be helpful.
symfony plugin:install twLoremIpsumPlugin -s beta
By default plugin uses own library of words and sentences fragments saved in json format. This files are:
sentences_data.json - Standard Lorem Ipsum and other Latin frazes.
words_data.json - Sets of Latin words
This dictionary files are not to big and if for generation purposes bigger sets of data is needed - Special task to generate this kind of files is added to dis plugin.
For example with plugin you have files based of polish translattion of Homer Iliada book:
pl_homer_sentences_data.json
pl_homer_words_data.json
symfony loremipsum:sentences-generator [--nonumeric[="..."]] source output
* Where optional --nonumeric gives information about possibility of numbers inside of sentences like:
There is 2 tree's in this garden.
symfony loremipsum:words-generator [--nonumeric[="..."]] [--regex[="..."]] source output
* Where optional --nonumeric gives information about possibility to use numbers as word in dictionary and optional --regex to add own filter for words
The fastes way is to put dictionary files to data folder of twLoremIpsumPlugin.
$loremipsum = new twLoremIpsum();
$loremipsum->setSentencesSourceFile('my_sentences_data.json')
$loremipsum = new twLoremIpsum();
$loremipsum->setWordsSourceFile('my_sentences_data.json')
$mytlds = array('com', 'net', 'gov', 'com.pl', 'pl', 'org');
$loremipsum = new twLoremIpsum();
$loremipsum->setTlds($mytlds)
Best way to explain usability of this plugin is lots of examples. Plugin can be useful in task's and in modules.
For Generating paragraphs we have 2 methods
generateParagraph($length = 10) - Where $length is mixed number of sentences
- Number of sentences in paragraph: if int or number of sentences to randomly select if array($min, $max)
- Returns string with paragraph
generateParagraphs($num, $length = 10) - Where $num is number of paragraphs to genearte and $length is mixed number of sentences in paragraphs
- Number of sentences in paragraph: if int or number of sentences to randomly select if array($min, $max)
- Returns array with paragraphs
If we need to generate paragraph by with sentences betwean 3 to 10
$loremipsum = new twLoremIpsum();
$sentence = $loremipsum->generateParagraph(array(3, 10));
If we need to generate 10 paragraphs by default with sentences betwean 4 to 9 per paragraph
$loremipsum = new twLoremIpsum();
$sentences = $loremipsum->generateParagraphs(10, array(4, 9);
For Generating sentences we have 2 methods
generateSentence($length = array(1, 3)) - Where $length is mixed number of sentences fragments seperated by ,
- Number of sub sentences in sentence: if int or number of sub sentences in sentence to randomly select if array($min, $max)
- Returns string with sentence
generateSentences($num, $length = array(1, 3)) - Where $num is number of sentences to genearte and $length is mixed number of sentences fragments seperated by ,
- Number of sub sentences in sentence: if int or number of sub sentences in sentence to randomly select if array($min, $max)
- Returns array with sentences
If we need to generate sentence with 1 to 5 sentences fragments
$loremipsum = new twLoremIpsum();
$sentence = $loremipsum->generateSentence(array(1, 5));
If we need to generate 20 sentences with 2 to 4 sentences fragments
$loremipsum = new twLoremIpsum();
$sentences = $loremipsum->generateSentences(20, array(2, 4));
For Generating words we have 4 methods
generateUniqueWord($length = 10, $namespace = 'default') - Where $length is mixed number of chars in word and $namespace is use for contener with used words to preserve uniq generation
- Number of letters in word: if int or number of letters in word to randomly select if array($min, $max)
- There is allways limit of unique words. If this limit will be reached Exception will be generated
- Returns string with word
generateUniqueWords($num, $length = 10, $namespace = 'default') - Where $num is number of words to genearte and $length is mixed number of chars in word and $namespace is use for contener with used words to preserve uniq generation
- Number of letters in word: if int or number of letters in word to randomly select if array($min, $max)
- There is allways limit of unique words. If this limit will be reached Exception will be generated
- Returns array with words
generateWord($length = 10) - Works almoust the same like generateUniqueWord but not checking if word was used
generateWords($num, $length = 10) - Works almoust the same like generateUniqueWords but not checking if word was used
We need to generate 200 unique users with names betwean 5 to 20 letters in namespace users
$loremipsum = new twLoremIpsum();
$users = $loremipsum->generateUniqueWords(200, array(5, 20), 'users');
For Generating random unique strings we have 2 methods
generateUniqueString($length = 0, $namespace = 'default') - Where $length is mixed number of chars in string and $namespace is use for contener with used strings to preserve uniq generation
- Number of chars in string: if int or range of length to randomly select if array($min, $max)
- There is allways limit of unique string based on length. But if string have more then 8 chars then is hard to generate Exception for limit reached
- Returns string
generateUniqueStrings($num, $length = 0, $namespace = 'default') - Where $num is number of strings to genearte and $length is mixed number of chars in string and $namespace is use for contener with used strings to preserve uniq generation
- Number of chars in string: if int or range of length to randomly select if array($min, $max)
- There is allways limit of unique string based on length. But if string have more then 8 chars then is hard to generate Exception for limit reached
- Returns array of strings
Generating 1000 unique strings with string lenght changes from 5 to 10
$loremipsum = new twLoremIpsum();
$this->mystring = $loremipsum->generateUniqueStrings(1000, array(5, 10));
For Generating random emails we have 2 methods
generateRandomEmail()
generateUniqueEmail($namespace = 'default')