Add an advanced text generator based on markov chains.#254
Add an advanced text generator based on markov chains.#254fzaninotto merged 8 commits intofzaninotto:masterfrom TimWolla:advancedTextProvider
Conversation
The advanced text generator's text()-generator is compatible to Lorem's one and can be used as a drop in replacement.
src/Faker/Provider/Text.php
Outdated
There was a problem hiding this comment.
Since this provider contains English text, it should probably be under the en_US locale. So I think you should commit one class with no locale and a basic text (see for instance the base Person generator), and another one, more complete with the en_US locale.
The non-locale Text provider can even be abstract, to force a proper text.
There was a problem hiding this comment.
Okay, I'll change it.
There was a problem hiding this comment.
After thinking about it, putting lorem ipsum text in this class brings confusion with the text class. That's why you should leave the $baseText empty and make the class abstract, to be instanciated in locales.
|
I absolutely love that contribution. I think it adds great value to Faker. Thanks a lot! |
|
I've been wanting something like that for a while now so I really appreciate this too. |
|
@fzaninotto The updates are now added to this pull request. |
src/Faker/Provider/Text.php
Outdated
There was a problem hiding this comment.
To simplify, I suggest to remove the ability to generate character-based markov text. It only produces legible text with 4+ characters, and by that time it's almost equivalent to a word-based markov chain.
|
@fzaninotto Everything should be fine now. |
src/Faker/Provider/Text.php
Outdated
There was a problem hiding this comment.
I think I see a potential bug when switching locales.
$faker = Faker\Factory::create('fr_FR');
$faker->realText(100); // generates static $table cache for French locale
$faker = Faker\Factory::create('en_EN');
$faker->realText(100); // uses static $table cache for French locale, generates French textThat probably means that $tables should not be static, and therefore realText shouldn't be static either.
There was a problem hiding this comment.
also, $tables is a pretty generic name. I suggest $consecutiveWords.
|
@fzaninotto Done. |
|
Awesome. I'll merge it right away. Thanks a lot for your patch! |
|
oops, sorry can't merge: tests fail. |
Funny, they did work on my development box though they shouldn't. Anyway: Fix gone out just now. Even more funny: Hiphop worked. |
Add an advanced text generator based on markov chains.
The advanced text generator's text()-generator is compatible to
Lorem's one and can be used as a drop in replacement.
see #109
Examples (The number is the maximum amount of characters, the line breaks are here for better formatting and not generated):