-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek9.html
243 lines (148 loc) · 6.7 KB
/
week9.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<! --
Week9
4 Nov<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title> Week 9 Context Free Grammars </title>
<link rel="stylesheet" href="week1style.css">
</head>
<!-- Top Navigation-->
<body>
<div id= "container1">
<div class="logo"> <img src="image/logo.png">
<a href="index.html">
<img src="image/logo.png">
</a>
</div>
<div class= "navbar">
<a href="index.html" id="Home">Home</a>
<a href="designFund.html" id="Projects">Design Fundamentals</a>
<a href="prgA-Z.html" id="Quotes">Programming from A-Z</a>
<a href="about.html" id="Contact">About</a>
</div>
</div>
<!-- Project Title Container 2-->
<div id= "container2">
<div class="title">
<p> Context Free Grammars</p>
</div>
<div class ="project-description">
<p> Author: Soojin Lee Date: 4, Nov, 2021 </p>
</div>
<h1>
| Context Free Grammars
</h1>
<div class="text">
<a href=https://en.wikipedia.org/wiki/Context-free_grammar/> Wikipedia</a > defines context-free grammar as (CFG) a formal grammar whose production rules are of the form
<Br>
<center>A --> α </center>
<Br> with A a single nonterminal symbol, and α a string of terminals and/or nonterminals (α can be empty). A formal grammar is "context free" if its production rules can be applied regardless of the context of a nonterminal. No matter which symbols surround it, the single nonterminal on the left hand side can always be replaced by the right hand side. This is what distinguishes it from a context-sensitive grammar.
<Br>
<br> For this week, I read these two websites to experiment on generating text with a Context Free Grammar.
<br> The two websites I used to learn more about CFG are:
<ul class="a">
<li> <a href=https://www.decontextualize.com/teaching/rwet/recursion-and-context-free-grammars/> Context-Free Grammars by Allison Parrish</a > </li>
<li> <a href=https://shiffman.net/a2z/cfg/> Context-Free Grammars by Daniel Shiffman</a ></li>
</ul>
</div>
<h1>
| Experimenting with CFG
</h1>
<h2>
What a Recipe!
</h2>
<div class="text">
Adapting <a href=https://editor.p5js.org/Soojin_lee/sketches/OacAMRXzC/> CFG example, </a > I created a program that uses CFGs to generate recipe instruction. Here are some of the texts generated using <B> What a Recipe </b> Program.
<br> <br>
Click <a href=https://editor.p5js.org/Soojin_lee/sketches/XnPy0r6qy/> here </a > to access the project.
<br> <br>
I chose to write a recipe instruciton with CFG because recipe instruction texts have orders and rules. For example, it starts with a verb such as: mix, fry, boil, cut, chop, and etcetera, followed by a food item and so on.
Below are the clauses and the terminals I created for this CFG system.
<img src="week9image/result1.png">
It was simply so hilarious and fun to read all these recipe texts. Many of the the recipe it generates are non-sensical yet still possible. With past experiences, we know that it makes no sense to cook 2ml of water until crispy. However, without this knowledge, this sentence is grammatically correct.
</div>
<h1> | Process </h1>
<div class="text">
<img src="week9image/result2.png">
<Br>
I have started with studying recipe texts. Here are some of the recipe instruction texts I collected from the <a href=https://www.pinterest.co.uk/pin/400468591836436842//> recipe website </a > to study the patterns and rules within the recipe instructions. I then created my own formula for cooking instruction based on the investigation.
</div>
<img src="week9image/recipetext.png" >
<h3> A Formula for Cooking Instruction </h3>
<div class="text">
</div>
<div class="text">
In extension of this formula, I have created clauses and terminals.
</div>
<h3>
Clauses
</h3>
<div class="text">
# clauses <Br>
S -> V NUFQ
<Br><Br>
NUFQ -> N U of F
NUFQ -> N U of QF
NUFQ -> N U of FQ #Q indicates it it not terminal
NUFQ -> N U of FPQ
<Br><Br>
FQ -> F until R
FQ -> F until RQ
<Br><Br>
QF -> SC F until R
QF -> SC F until RQ
<Br><Br>
RQ -> R M VQ <Br><Br>
VQ -> transV NUFQ <Br><Br>
FPQ -> F PP A P
</div>
<h3>
Terminals
</h3>
<div class="text">
# Start Verb <Br>
V -> Add | Bake| Barbecue | Beat | Blend | Boil | Pour | Chop | Combine | Cook | Crush | Cut | Drain | Fry | Grate | Measure | Peel | Roast | Saute | Slice | Steam | Stir-fry | Wash | Mash <Br> <Br>
# Transitional Verb <Br>
transV -> add | bake| barbecue | beat | blend | boil | pour | chop | combine | cook | crush | cut | drain | fry | grate | measure | peel | roast | saute | slice | steam | stir-fry | wash | mash
<Br><Br>
# Number <Br>
N -> 3 | 2 | 20 | 300 | 1 | 5 | 10
<Br><Br>
# Unit<Br>
U -> g | ml | cups | teaspoons | slices
<Br><Br>
# Time<Br>
T -> minute(s) | hour(s) | second(s) | overnight
<Br><Br>
# PrePosition<Br>
PP -> into | on | in | to
<Br><Br>
# More<Br>
M -> and | then | after
<Br><Br>
# a the an <Br>
A -> the | a | an
<Br><Br>
# Adjective<Br>
ADJ -> fresh | red | defrosted | spicy | delicious | ground | melted | finely grated | shredded | mini | sweet | cold | dried | rolled | precooked | smooth
<Br><Br>
# Food<Br>
F -> beef | oinions | chocolate | flour | beans | eggs | milk | garlic | chicken broth | lemons | spinach | salt | pepper | oil | carrots | cheese | tomatoes | bacons | salmon | jalapeno | zucchini | sweet potato | mushroom | cream | banana | sugar | pork | beef | chicken breast | oats | water | sauce
<Br><Br>
# Scale<Br>
SC -> small | medium | large
<Br><Br>
# Place<Br>
P -> mixing bowl | oven | container | cup | non-stick frying pan | microwave | plate | air-fryer | chopping board | mixer
<Br><Br>
# Result<Br>
R -> golden | brown | caramelized | fragrant | gone | thicken | warm | crispy | smooth
</div>
<h3>
Reflection & Evaluation
</h3>
<div class="text">
I have enjoyed working on this project. The process of was like solving a puzzle, which I love doing. I did not draw a tree branch diagram as I was creating a formula, but to make a more sophisticated text generator with more variations, the tree branch diagram would be really helpful to visualize possibilities and variations. <br><br> I am considering expanding on this to build the final project about a recipe generator bot that gives a recipe based on the food item that people already have at home. To briefly explain, people can type in the food items that are available at home and the bot will create a recipe for them using the inputs. I think it would be really interesting project to work on but I also see the potential of it being super useful for people daily about "what should I cook for dinner?".
</div>
</body>
</html>