1 | <?php declare(strict_types = 1); |
||
8 | class RandomEnglishGenerator |
||
9 | { |
||
10 | |||
11 | private const POSSIBLE_WORD_TYPES = [ |
||
12 | 'noun', |
||
13 | 'countable_noun', |
||
14 | |||
15 | 'adjective', |
||
16 | 'preposition', |
||
17 | 'conjunction', |
||
18 | 'contraction', |
||
19 | 'control_verb', |
||
20 | |||
21 | 'sequence_adverb', |
||
22 | 'frequency_adverb', |
||
23 | |||
24 | // pluralize and ing these? |
||
25 | 'intransitive_verb', |
||
26 | 'irregular_verb', |
||
27 | 'transitive_verb', |
||
28 | 'verb', |
||
29 | 'adverb', |
||
30 | |||
31 | 'intransitive_verb_ing', |
||
32 | 'irregular_verb_ing', |
||
33 | 'transitive_verb_ing', |
||
34 | 'verb_ing', |
||
35 | |||
36 | |||
37 | // positions |
||
38 | 'locative', |
||
39 | |||
40 | 'plural_noun', |
||
41 | |||
42 | |||
43 | // names |
||
44 | 'mens_name', |
||
45 | 'womens_name', |
||
46 | 'country', |
||
47 | 'colour', |
||
48 | ]; |
||
49 | |||
50 | private const POSSIBLE_FAKER_TYPES=[ |
||
51 | 'address', |
||
52 | 'name', |
||
53 | 'randomDigit', |
||
54 | 'randomLetter', |
||
55 | 'randomNumber', |
||
56 | 'title', |
||
57 | 'titleMale', |
||
58 | 'titleFemale', |
||
59 | 'firstNameMale', |
||
60 | 'firstNameFemale', |
||
61 | 'lastName', |
||
62 | |||
63 | 'catchPhrase', |
||
64 | 'bs', |
||
65 | 'company', |
||
66 | 'companySuffix', |
||
67 | 'jobTitle', |
||
68 | |||
69 | 'realText', |
||
70 | |||
71 | 'dayOfWeek', |
||
72 | 'monthName', |
||
73 | |||
74 | ]; |
||
75 | |||
76 | /** @var string configuration file for sentences */ |
||
77 | private $config = ''; |
||
78 | |||
79 | public function __construct() |
||
84 | |||
85 | |||
86 | /** @param string $newConfig configuration file of how sentence structures */ |
||
87 | public function setConfig(string $newConfig): void |
||
91 | |||
92 | |||
93 | /** |
||
94 | * Generate a random sentence |
||
95 | * |
||
96 | * @param bool $titleCase true to generate a title, false (default) to generate a sentence |
||
97 | * @return string a random sentence |
||
98 | */ |
||
99 | public function sentence(bool $titleCase = false): string |
||
122 | |||
123 | |||
124 | /** |
||
125 | * Generate a random title |
||
126 | * |
||
127 | * @return string a random sentence, all in caps, no trailing full stop |
||
128 | */ |
||
129 | public function title(): string |
||
133 | |||
134 | |||
135 | /** |
||
136 | * @param int $maxSentences The maximum number of sentences |
||
137 | * @return string a paragraph of random sentences |
||
138 | */ |
||
139 | public function paragraph(int $maxSentences = 10): string |
||
150 | |||
151 | |||
152 | /** @return string a plural noun */ |
||
153 | public function pluralNoun(): string |
||
159 | |||
160 | |||
161 | /** @return string the ing version of a verb, e.g. run -> running */ |
||
162 | public function verbing(): string |
||
170 | |||
171 | |||
172 | /** |
||
173 | * @param string $wordType The word type, e.g. 'noun' or 'verb' |
||
174 | * @return bool true if this is a plural noun |
||
175 | */ |
||
176 | public function pluralNounCheck(string &$wordType, string &$possiblyRandomWord): bool |
||
186 | |||
187 | |||
188 | /** @return bool true if this is a verb with ing */ |
||
189 | public function ingVerbCheck(string &$wordType, string &$possiblyRandomWord): bool |
||
199 | |||
200 | |||
201 | public function augmentIfPluralNoun(bool $pluralNoun, string &$randomWord): void |
||
209 | |||
210 | |||
211 | public function augmentIfIngVerb(bool $ing, string &$randomWord): void |
||
219 | |||
220 | |||
221 | public function augmentSentenceTitleCase(bool $titleCase, string &$result): void |
||
230 | |||
231 | |||
232 | /** |
||
233 | * Convert an array of strings into a sentence |
||
234 | * 1) Capitalize first letter |
||
235 | * 2) Glue words together with a space |
||
236 | * 3) Add a full stop |
||
237 | * 4) Deal with diferent sentence endings such as ! or ? |
||
238 | * |
||
239 | * @param array<string> $sentenceArray a sentence whose words are in an array of strings |
||
240 | * @return string a sentence |
||
241 | */ |
||
242 | public function makeArrayIntoSentence(array $sentenceArray): string |
||
252 | |||
253 | |||
254 | /** |
||
255 | * If a sentence ended with a question or exclamation mark prior to having a full stop appended, deal with it |
||
256 | * |
||
257 | * @param string $result The sentence, by reference, prior to being fixed |
||
258 | */ |
||
259 | public function fixEndOfSentence(string &$result): void |
||
265 | |||
266 | |||
267 | /** |
||
268 | * @param string $wordType the type of word, e.g. noun, verb |
||
269 | * @return string a random word for the given word type |
||
270 | */ |
||
271 | private function getRandomWord(string $wordType): string |
||
279 | |||
280 | |||
281 | /** @return string the above string as is, or a possibly randomized version, e.g. a random noun */ |
||
282 | private function getWordOrRandomWord(string $possiblyRandomWord): string |
||
326 | |||
327 | |||
328 | /** |
||
329 | * @param string $wordType noun, verb, adjective etc |
||
330 | * @param bool $pluralizeNoun if true pluralize a noun |
||
331 | * @param bool $makeVerbIng if true make a verb an ing verb, e.g. run -> running |
||
332 | */ |
||
333 | private function chooseRandomWord( |
||
357 | } |
||
358 |