-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
315 lines (270 loc) · 5.36 KB
/
sketch.js
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// Using Context free grammer to
//complete natural language tasks that are required of
// Chinese middle school students in public school English class
//
// comments in the descript object show changes usually to greater
// generalization
// sentence expanding algorithm based on
// Daniel Shiffman
// context free grammar videos
// from his
//Session 7 of my Programming from A to Z class - Fall 2016.
//http://shiffman.net/a2z/
//
// so I will take the noun phrase out of the sentence and move it
// further down into the the has phrase and seperate by person and number
let descript = {
"S": [
//["NP","DescriP"],
["DES"]
],
"DES": [
["PossessiveDecript"],
["isDescript"],
],
"PossessiveDecript": [
// hpn is have or has person and number
// moved into a seperate expansion for body description
//["Hpn","BodyAdj","PluralBodyNoun"],
// ["Hpn","a","BodyAdj","SingBodyNoun"],
["Hpn","bodyDescript"],
["Hpn","hairDescript"],
// further moved hair into the the hair description part
//["Hpn","hairDescript","hair"],
// moved these into a seperate expansion for hair description
//["Hpn","HairAdj", "hair"],
//["Hpn","HairAdj", "HairClr","hair"],
//["Hpn","Len","HairAdj", "hair"],
//["Hpn","Len","HairAdj", "HairClr","hair"],
],
"bodyDescript": [
["BodyAdj","PluralBodyNoun"],
["a","BodyAdj","SingBodyNoun"],
],
"hairDescript":[
["HairAdj","hair"],
["HairAdj", "HairClr","hair"],
["Len","HairAdj","hair"],
["Len","HairClr","hair"],
["Len","hair"],
["Len","HairAdj","HairClr","hair"],
],
"isDescript":[
["ispn", "height"],
["ispn", "build"],
],
"build": [
["thin"],
["heavy"],
["overweight"],
["average build"]
],
"height":[
["tall"],
["short"],
["average height"],
],
"Len": [
["long"],
["short"],
],
"HairAdj":[
["curly"],
["straight"],
["wavy"],
],
"HairClr":[
["red"],
["black"],
["blond"],
["grey"],
["white"],
["brown"]
],
"BodyAdj": [
["big"],
["small"]
],
"SingBodyNoun": [
["nose"],
["mouth"],
["moustache"],
["beard"]
],
"PluralBodyNoun": [
["eyes"],
["ears"],
["hands"],
["rosy cheeks"]
],
"Hpn": [
["Dets","PersonNoun3s", "has" ],
["Detp","PersonNoun3p", "each", "have"],
["Pronoun123p", "have"],
["Pronoun3s", "has"],
["PropName","has"]
],
"ispn": [
["Dets","PersonNoun3s", "is" ],
["Detp","PersonNoun3p", "are"],
["you", "are"],
["I", "am"],
["we", "are"],
["they","are"],
["Pronoun3s","is"],
["PropName","is"]
],
"Pronoun123p": [
["I"],
["you"],
["we both"],
["they all"]
// had to quallify it here
],
"Pronoun3s":[
["he"],
["she"],
["it"],
],
"Dets": [
["this"],
["that"],
["the"]
],
"Detp": [
["these"],
["thoes"],
["the"]
],
"PersonNoun3s": [
["doctor"],
["man"],
["woman"],
["teacher"],
["boy"],
["girl"]
],
"PersonNoun3p": [
["doctors"],
["men"],
["women"],
["teachers"],
["boys"],
["girls"]
],
"PropName": [
["Greg"],
["Mary"],
["Sue"],
["Judy"],
["Kelly"],
["Robert"],
["Betty"],
["Angela"],
]
}
// var rules = {
// "S": [
// ["NP", "VP"],
// ["Interj", "NP", "VP"]
// ],
// "NP": [
// ["Det", "N"],
// ["Det", "N", "that", "VP"],
// ["Det", "Adj", "N"],
// ["PropName"]
// ],
// "VP": [
// ["Vtrans", "NP"],
// ["Vintr"]
// ],
// "Interj": [
// ["oh"],
// ["my"],
// ["wow"],
// ["darn"]
// ],
// "Det": [
// ["this"],
// ["that"],
// ["the"]
// ],
// "N": [
// ["amoeba"],
// ["dichotomy"],
// ["seagull"],
// ["trombone"],
// ["overstaffed"],
// ["corsage"]
// ],
// "Adj": [
// ["bald"],
// ["smug"],
// ["important"],
// ["tame"],
// ["overstaffed"],
// ["corsage"]
// ],
// "Vtrans": [
// ["computes"],
// ["examines"],
// ["foregrounds"],
// ],
// "Vintr": [
// ["coughs"],
// ["daydreams"],
// ["whines"],
// ],
// "PropName": [
// ["Greg"],
// ["Mj"],
// ["Cuko"],
// ["Sapa"],
// ]
// };
// var rules = {
// "S": [
// ["The", "N", "V"]
// ],
// "N": [
// ["cat"],
// ["dog"]
// ],
// "V": [
// ["meows"],
// ["barks"]
// ]
// };
function expand(start, expansion) {
if (descript[start]) {
var pick = random(descript[start]);
console.log(pick);
for (var i = 0; i < pick.length; i++) {
expand(pick[i], expansion);
}
} else {
expansion.push(start);
}
return expansion.join(" ");
}
var button;
let myp;
function setup() {
noCanvas();
myp = createP("Click generate for a randomly expanded sentence").style("color","lime");
button = createButton('generate');
button.mousePressed(cfg);
createP();
createP(); // put some space between button and link
createA('https://github.com/greggelong/cfg_description', 'link to this repo');
}
function cfg() {
var start = "S";
var expansion = [];
var result = expand(start, expansion);
console.log(result);
result+="."
// capitalize the first letter
let caps = result.charAt(0).toUpperCase() + result.slice(1);
myp.html(caps).style("color","lime");
}