Add Words class for random food-related words

This commit is contained in:
Christopher C. Wells 2021-04-06 20:01:21 -07:00
parent f56fab3fd0
commit 71ba007db9
24 changed files with 547 additions and 2 deletions

View File

@ -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": {

View File

@ -58,6 +58,11 @@ return [
'endpoint' => env('AWS_ENDPOINT'),
],
'wordlists' => [
'driver' => 'local',
'root' => storage_path('wordlists'),
],
],
/*

View File

@ -0,0 +1,64 @@
<?php
namespace Database\Support;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
/**
* @method static Collection adjectives()
* @method static Collection nouns()
* @method static Collection prepositions()
* @method static Collection verbs()
*/
class Words
{
/**
* Overload by word type.
*/
public static function __callStatic($method, $parameters): ?Collection {
if (in_array($method, ['adjectives', 'nouns', 'prepositions', 'verbs'])) {
$cache_key = __METHOD__ . "::{$method}";
if (Cache::has($cache_key)) {
return Cache::get($cache_key);
}
$words = new Collection();
$storage = Storage::disk('wordlists');
foreach ($storage->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);
}
}

View File

@ -3,10 +3,12 @@
namespace Database\Factories;
use App\Models\Food;
use Illuminate\Database\Eloquent\Factories\Factory;
class FoodFactory extends Factory
{
/**
* {@inheritdoc}
*/

View File

@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Storage;
class RecipeFactory extends Factory
{
/**
* {@inheritdoc}
*/

View File

@ -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.

View File

@ -0,0 +1 @@
https://github.com/imsky/wordlists

View File

@ -0,0 +1,16 @@
bare
basic
clear
complex
complicated
convoluted
direct
easy
elaborate
fancy
hard
intricate
obvious
plain
pure
simple

View File

@ -0,0 +1,20 @@
bent
blocky
boxy
broad
chunky
compact
fat
flat
full
narrow
pointed
round
rounded
skinny
slim
solid
straight
thick
thin
wide

View File

@ -0,0 +1,19 @@
average
big
broad
flat
giant
huge
humongous
immense
large
little
long
massive
medium
miniature
short
small
tall
tiny
wide

View File

@ -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

View File

@ -0,0 +1,16 @@
blistering
burning
chill
cold
cool
freezing
frigid
frosty
hot
icy
molten
nippy
scalding
searing
sizzling
warm

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,18 @@
alligator
beef
bison
buffalo
caribou
chicken
duck
elk
goat
lamb
pheasant
pork
quail
rabbit
turkey
veal
venison
yak

View File

@ -0,0 +1,9 @@
above
across
below
in
inside
on
over
under
with

View File

@ -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

View File

@ -0,0 +1,17 @@
break
crack
crash
crush
demolish
destroy
detonate
erase
explode
melt
scratch
shatter
smash
splinter
split
squash
wreck

View File

@ -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

View File

@ -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