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