From 71ba007db9ecc950e84e9230319e6be788644b40 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Tue, 6 Apr 2021 20:01:21 -0700 Subject: [PATCH] Add Words class for random food-related words --- composer.json | 5 +- config/filesystems.php | 5 + database/Support/Words.php | 64 +++++++++++++ database/factories/FoodFactory.php | 2 + database/factories/RecipeFactory.php | 1 + storage/wordlists/LICENSE.txt | 21 +++++ storage/wordlists/SOURCE.txt | 1 + storage/wordlists/adjectives/complexity.txt | 16 ++++ storage/wordlists/adjectives/shape.txt | 20 ++++ storage/wordlists/adjectives/size.txt | 19 ++++ storage/wordlists/adjectives/taste.txt | 21 +++++ storage/wordlists/adjectives/temperature.txt | 16 ++++ storage/wordlists/nouns/cheese.txt | 29 ++++++ storage/wordlists/nouns/condiments.txt | 22 +++++ storage/wordlists/nouns/fast_food.txt | 21 +++++ storage/wordlists/nouns/fish.txt | 34 +++++++ storage/wordlists/nouns/food.txt | 98 ++++++++++++++++++++ storage/wordlists/nouns/fruit.txt | 31 +++++++ storage/wordlists/nouns/meat.txt | 18 ++++ storage/wordlists/prepositions/common.txt | 9 ++ storage/wordlists/verbs/cooking.txt | 24 +++++ storage/wordlists/verbs/destruction.txt | 17 ++++ storage/wordlists/verbs/manipulation.txt | 33 +++++++ storage/wordlists/verbs/quantity.txt | 22 +++++ 24 files changed, 547 insertions(+), 2 deletions(-) create mode 100644 database/Support/Words.php create mode 100644 storage/wordlists/LICENSE.txt create mode 100644 storage/wordlists/SOURCE.txt create mode 100644 storage/wordlists/adjectives/complexity.txt create mode 100644 storage/wordlists/adjectives/shape.txt create mode 100644 storage/wordlists/adjectives/size.txt create mode 100644 storage/wordlists/adjectives/taste.txt create mode 100644 storage/wordlists/adjectives/temperature.txt create mode 100644 storage/wordlists/nouns/cheese.txt create mode 100644 storage/wordlists/nouns/condiments.txt create mode 100644 storage/wordlists/nouns/fast_food.txt create mode 100644 storage/wordlists/nouns/fish.txt create mode 100644 storage/wordlists/nouns/food.txt create mode 100644 storage/wordlists/nouns/fruit.txt create mode 100644 storage/wordlists/nouns/meat.txt create mode 100644 storage/wordlists/prepositions/common.txt create mode 100644 storage/wordlists/verbs/cooking.txt create mode 100644 storage/wordlists/verbs/destruction.txt create mode 100644 storage/wordlists/verbs/manipulation.txt create mode 100644 storage/wordlists/verbs/quantity.txt diff --git a/composer.json b/composer.json index 252a306..c157a12 100644 --- a/composer.json +++ b/composer.json @@ -54,8 +54,9 @@ "autoload": { "psr-4": { "App\\": "app/", - "Database\\Factories\\": "database/factories/", - "Database\\Seeders\\": "database/seeders/" + "Database\\Factories\\": "database/Factories/", + "Database\\Seeders\\": "database/Seeders/", + "Database\\Support\\": "database/Support/" } }, "autoload-dev": { diff --git a/config/filesystems.php b/config/filesystems.php index f7bdc6e..1754610 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -58,6 +58,11 @@ return [ 'endpoint' => env('AWS_ENDPOINT'), ], + 'wordlists' => [ + 'driver' => 'local', + 'root' => storage_path('wordlists'), + ], + ], /* diff --git a/database/Support/Words.php b/database/Support/Words.php new file mode 100644 index 0000000..f3d0ff8 --- /dev/null +++ b/database/Support/Words.php @@ -0,0 +1,64 @@ +files($method) as $file) { + $contents = array_filter(explode("\n", $storage->get($file))); + $words->push(...$contents); + } + + Cache::put($cache_key, $words, 60 * 5); + return $words; + } + throw new \BadMethodCallException(); + } + + /** + * Create a random string of words in the provided format. + * + * Supported format keys: + * - a: adjective, + * - n: noun, + * - p: preposition, and + * - v: verb. + */ + public static function randomWords(string $format = 'an'): string { + $name = []; + foreach (str_split($format) as $type) { + $name[] = match ($type) { + 'a' => self::adjectives()->random(), + 'n' => self::nouns()->random(), + 'p' => self::prepositions()->random(), + 'v' => self::verbs()->random(), + default => NULL + }; + } + return implode(' ', $name); + } + +} diff --git a/database/factories/FoodFactory.php b/database/factories/FoodFactory.php index 8ccac38..2879e8c 100644 --- a/database/factories/FoodFactory.php +++ b/database/factories/FoodFactory.php @@ -3,10 +3,12 @@ namespace Database\Factories; use App\Models\Food; + use Illuminate\Database\Eloquent\Factories\Factory; class FoodFactory extends Factory { + /** * {@inheritdoc} */ diff --git a/database/factories/RecipeFactory.php b/database/factories/RecipeFactory.php index fe1d56b..9e7235b 100644 --- a/database/factories/RecipeFactory.php +++ b/database/factories/RecipeFactory.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Storage; class RecipeFactory extends Factory { + /** * {@inheritdoc} */ diff --git a/storage/wordlists/LICENSE.txt b/storage/wordlists/LICENSE.txt new file mode 100644 index 0000000..44011c9 --- /dev/null +++ b/storage/wordlists/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017-2019 Ivan Malopinsky + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/storage/wordlists/SOURCE.txt b/storage/wordlists/SOURCE.txt new file mode 100644 index 0000000..e70fe66 --- /dev/null +++ b/storage/wordlists/SOURCE.txt @@ -0,0 +1 @@ +https://github.com/imsky/wordlists diff --git a/storage/wordlists/adjectives/complexity.txt b/storage/wordlists/adjectives/complexity.txt new file mode 100644 index 0000000..4c464dd --- /dev/null +++ b/storage/wordlists/adjectives/complexity.txt @@ -0,0 +1,16 @@ +bare +basic +clear +complex +complicated +convoluted +direct +easy +elaborate +fancy +hard +intricate +obvious +plain +pure +simple diff --git a/storage/wordlists/adjectives/shape.txt b/storage/wordlists/adjectives/shape.txt new file mode 100644 index 0000000..46e8971 --- /dev/null +++ b/storage/wordlists/adjectives/shape.txt @@ -0,0 +1,20 @@ +bent +blocky +boxy +broad +chunky +compact +fat +flat +full +narrow +pointed +round +rounded +skinny +slim +solid +straight +thick +thin +wide diff --git a/storage/wordlists/adjectives/size.txt b/storage/wordlists/adjectives/size.txt new file mode 100644 index 0000000..7d69050 --- /dev/null +++ b/storage/wordlists/adjectives/size.txt @@ -0,0 +1,19 @@ +average +big +broad +flat +giant +huge +humongous +immense +large +little +long +massive +medium +miniature +short +small +tall +tiny +wide diff --git a/storage/wordlists/adjectives/taste.txt b/storage/wordlists/adjectives/taste.txt new file mode 100644 index 0000000..ea69c11 --- /dev/null +++ b/storage/wordlists/adjectives/taste.txt @@ -0,0 +1,21 @@ +bitter +chalky +chewy +creamy +crispy +crunchy +dry +greasy +gritty +mild +moist +oily +plain +salty +savory +sour +spicy +sweet +tangy +tart +zesty diff --git a/storage/wordlists/adjectives/temperature.txt b/storage/wordlists/adjectives/temperature.txt new file mode 100644 index 0000000..89a5da8 --- /dev/null +++ b/storage/wordlists/adjectives/temperature.txt @@ -0,0 +1,16 @@ +blistering +burning +chill +cold +cool +freezing +frigid +frosty +hot +icy +molten +nippy +scalding +searing +sizzling +warm diff --git a/storage/wordlists/nouns/cheese.txt b/storage/wordlists/nouns/cheese.txt new file mode 100644 index 0000000..09eabe6 --- /dev/null +++ b/storage/wordlists/nouns/cheese.txt @@ -0,0 +1,29 @@ +asadero +asiago +blue +brick +brie +burrata +butterkase +camembert +cheddar +colby +cotija +edam +emmentaler +feta +fontina +gorgonzola +gouda +havarti +kasseri +limburger +mascarpone +mozzarella +muenster +parmesan +pepato +provolone +ricotta +romano +swiss diff --git a/storage/wordlists/nouns/condiments.txt b/storage/wordlists/nouns/condiments.txt new file mode 100644 index 0000000..f4e893e --- /dev/null +++ b/storage/wordlists/nouns/condiments.txt @@ -0,0 +1,22 @@ +butter +chili +chives +chutney +garlic +honey +horseradish +ketchup +margarine +mayonnaise +miso +mustard +oil +onion +pesto +relish +remoulade +salsa +sauerkraut +sriracha +vinegar +wasabi diff --git a/storage/wordlists/nouns/fast_food.txt b/storage/wordlists/nouns/fast_food.txt new file mode 100644 index 0000000..a0a864e --- /dev/null +++ b/storage/wordlists/nouns/fast_food.txt @@ -0,0 +1,21 @@ +BLT +bagel +burger +burrito +cheeseburger +clubhouse +frank +hamburger +hoagie +melt +muffin +panini +philly +pita +pretzel +reuben +sandwich +slider +sub +taco +wrap diff --git a/storage/wordlists/nouns/fish.txt b/storage/wordlists/nouns/fish.txt new file mode 100644 index 0000000..c9c2725 --- /dev/null +++ b/storage/wordlists/nouns/fish.txt @@ -0,0 +1,34 @@ +amberjack +anchovy +angler +ayu +barbel +barracuda +bass +betta +blowfish +bocaccio +burbot +carp +cobbler +cod +eel +flounder +grouper +haddock +halibut +herring +mackerel +marlin +mullet +perch +pollock +salmon +sardine +scallop +shark +snapper +sole +tilapia +trout +tuna diff --git a/storage/wordlists/nouns/food.txt b/storage/wordlists/nouns/food.txt new file mode 100644 index 0000000..1df2e8e --- /dev/null +++ b/storage/wordlists/nouns/food.txt @@ -0,0 +1,98 @@ +aroma +bagel +batter +beans +beer +biscuit +bread +broth +burger +butter +cake +candy +caramel +caviar +cheese +chili +chocolate +cider +cobbler +cocoa +coffee +cookie +cream +croissant +crumble +cuisine +curd +dessert +dish +drink +eggs +entree +filet +fish +flour +foie gras +food +glaze +grill +hamburger +ice +juice +ketchup +kitchen +lard +liquor +margarine +marinade +mayo +mayonnaise +meat +milk +mousse +muffin +mushroom +noodle +nut +oil +olive +omelette +pan +pasta +paste +pastry +pie +pizza +plate +pot +poutine +pudding +raclette +recipe +rice +salad +salsa +sandwich +sauce +seasoning +skillet +soda +soup +soy +spice +steak +stew +syrup +tartar +taste +tea +toast +vinegar +waffle +water +wheat +wine +wok +yeast +yogurt diff --git a/storage/wordlists/nouns/fruit.txt b/storage/wordlists/nouns/fruit.txt new file mode 100644 index 0000000..bc4f2e3 --- /dev/null +++ b/storage/wordlists/nouns/fruit.txt @@ -0,0 +1,31 @@ +apple +apricot +avocado +banana +berry +cantaloupe +cherry +citron +citrus +coconut +date +fig +grape +guava +kiwi +lemon +lime +mango +melon +mulberry +nectarine +orange +papaya +peach +pear +pineapple +plum +prune +raisin +raspberry +tangerine diff --git a/storage/wordlists/nouns/meat.txt b/storage/wordlists/nouns/meat.txt new file mode 100644 index 0000000..cce2bd1 --- /dev/null +++ b/storage/wordlists/nouns/meat.txt @@ -0,0 +1,18 @@ +alligator +beef +bison +buffalo +caribou +chicken +duck +elk +goat +lamb +pheasant +pork +quail +rabbit +turkey +veal +venison +yak diff --git a/storage/wordlists/prepositions/common.txt b/storage/wordlists/prepositions/common.txt new file mode 100644 index 0000000..34256d2 --- /dev/null +++ b/storage/wordlists/prepositions/common.txt @@ -0,0 +1,9 @@ +above +across +below +in +inside +on +over +under +with diff --git a/storage/wordlists/verbs/cooking.txt b/storage/wordlists/verbs/cooking.txt new file mode 100644 index 0000000..48f992d --- /dev/null +++ b/storage/wordlists/verbs/cooking.txt @@ -0,0 +1,24 @@ +bake +barbecue +boil +braise +broil +burn +chop +dip +fry +grill +heat +melt +microwave +poach +roast +saute +scramble +sear +simmer +slice +steam +stir +thaw +toast diff --git a/storage/wordlists/verbs/destruction.txt b/storage/wordlists/verbs/destruction.txt new file mode 100644 index 0000000..612f9a9 --- /dev/null +++ b/storage/wordlists/verbs/destruction.txt @@ -0,0 +1,17 @@ +break +crack +crash +crush +demolish +destroy +detonate +erase +explode +melt +scratch +shatter +smash +splinter +split +squash +wreck diff --git a/storage/wordlists/verbs/manipulation.txt b/storage/wordlists/verbs/manipulation.txt new file mode 100644 index 0000000..d66f054 --- /dev/null +++ b/storage/wordlists/verbs/manipulation.txt @@ -0,0 +1,33 @@ +add +change +combine +connect +copy +create +delete +edit +file +lengthen +lower +merge +modify +order +organize +place +put +raise +replace +separate +shorten +sort +split +swap +throw +trash +tweak +widen +turn +extend +shrink +stretch +compress diff --git a/storage/wordlists/verbs/quantity.txt b/storage/wordlists/verbs/quantity.txt new file mode 100644 index 0000000..b66c87b --- /dev/null +++ b/storage/wordlists/verbs/quantity.txt @@ -0,0 +1,22 @@ +abridge +accrue +add +augment +boost +condense +decrease +deflate +diminish +extend +grow +increase +lessen +magnify +maximize +multiply +raise +reduce +remove +shorten +shrink +subtract