-
Notifications
You must be signed in to change notification settings - Fork 655
/
scratch.js
373 lines (326 loc) · 13.2 KB
/
scratch.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/* eslint-disable no-console, no-unused-vars */
import nlp from './src/three.js'
import plg from './plugins/dates/src/plugin.js'
nlp.plugin(plg)
// nlp.verbose('tagger')
const text = 'to the window'
// Throws an error, capturing group at beginning, replacing with an empty string
const doc1 = nlp(text)
doc1.match('[to] the window', 0).replaceWith('by')
doc1.debug()
doc1.match('[by]', 0).debug().replaceWith('')
// Works, capturing group at beginning, replacing with a non-empty string
const doc2 = nlp(text)
doc2.match('[to] the window', 0).replaceWith('near')
doc2.match('[near]', 0).replaceWith('by')
console.log('doc2', doc2.text())
// Works, capture group at end, replacing with an empty string
const doc3 = nlp(text)
doc3.match('to the [window]', 0).replaceWith('wall')
doc3.match('[wall]', 0).replaceWith('')
console.log('doc3', doc3.text())
// const doc = nlp('one match match after')
// doc.match('one .* after').debug() // works
// doc.match('[one match+ after]', 0).debug() //bad
// -bury
// -ford
// -ton
// -shire
// Dundas Harbour
// hants county
// console.log(nlp(`IEEE / WIC`).debug().docs[0][0])
// const prependingText = 'the patient will need an '
// let doc = nlp('ECG')
// doc.prepend(prependingText)
// doc.debug('freeze')
// nlp('i play dr who').debug()
// let doc = nlp(`john jacob and john.foobar`)
// let m = doc.split('.')
// let res = m.joinIf('john', '.')
// res.debug()
// let doc = nlp('one foo two foo')
// let m = doc.terms()
// m = m.join()
// m.debug()
// let doc = nlp('one two three four')
// let a = doc.match('one .')
// let b = doc.match('. three')
// a.difference(b).debug()
// let doc = nlp('one two three four five. one three four')
// doc.before('three four').debug()
// doc.debug()
// let doc = nlp('one foo two foo')
// let m = doc.terms()
// m = m.join().debug()
// let doc = nlp("one two John Carreyrou three four Roger Moore")
// let m = doc.terms()
// let people = doc.people()
// m = m.joinIf(people)
// return m.out('array')
let arr = [
// 'I left the window open for fresh air.',
// 'Iran also stands accused of aiding terrorism ',
// 'the belief that bees got a sweet substance ',
// 'You have all devoted considerable time',
// 'He befriend a stray dog',
// noun|verb|adjective:
// 'average',
// 'welcome',
// 'light',
// 'forward',
// 'square',
// 'welcome',
// 'mean',
// 'right',
// adjectives
// 'even',
// 'was very holy',
// verbs
// `The couple wed in a traditional church`,
// `Fish surface to breathe in oxygen`,
// `The NGO sponsors educational programs`,
// `The bakery smells like freshly baked bread.`,
// `Don't let one mistake ruin your day.`,
// `The hammer pounds the nail`,
// `He is trying to perfect his piano skills.`,
// `They will fast before`,
// `They forgot to bill me`,
// `The news is broadcast at 6 p.m.`,
// `She is determined to attain her fitness goals.`,
// `The seal barks to communicate with others.`,
// `He always tries to best his personal records.`,
// `Please bill me for the dinner tonight.`,
// `The plumber will bill you for the repairs.`,
// `They forgot to bill me for the subscription.`,
// `I will bill you for the work done.`,
// `The bomb exploded, causing widespread damage.`,
// `How much does this shirt cost?`,
// 'of'
// 'A slice of heaven',
// `Please dispose of your trash properly.`,
// `They are planning to dispose of the company's assets.`,
// `I dream of becoming a doctor one day.`,
// `They dream of owning their own business.`,
// `The hammer pounds the nail into the wood.`,
// `I couldn't help but sob when I heard the sad news.`,
// `The old man stoops to pet the cat.`,
// `The teacher welcomes questions from students.`,
// 'advertising'
// 'gets compounded',
// 'always gets flirted with',
// 'reports stated',
// nouns
// `She manages the company's social media accounts.`,//account/noun
// `The company invested a lot of money in advertising.`,//advertising/noun
// 'The lower the reins, the stronger the action',
// 'Ideas are welcome',
// 'days the average American receives each Year',
// 'and its sprawling metropolis.',
// 'She shoved her hand under my mouth',
// `I watch a lot of cooking channels on YouTube.`,//channel/noun
// `The police arrested the criminal yesterday.`,//criminal/noun
// `Can you provide more details about the project?`,//detail/noun
// `I love the attention to detail in this design.`,//detail/noun
// `The company received funding for its new project.`,//funding/noun
// `I love playing video games with my friends.`,//game/noun
// `The giant towered over the city, casting a long shadow.`,//giant/noun
// `They paid off their student loans after graduation.`,//loan/noun
// `My sister is a minor and still goes to high school.`,//minor/noun
// %Adj|Noun% %Noun|Verb%
// `He turned off the television screen before leaving.`,//screen/noun
// `She is a senior studying computer science.`,//senior/noun
// `She is seeking emotional support after the loss.`,//support/noun
// `The suspect denied any involvement in the crime.`,//suspect/noun
// 'Dance like a stripper',
// 'and bickering occurred ',
// `I enjoy taking long walks in the park.`,//walk/noun
// `There was a warning about heavy rain.`,//warning/noun
// `She ordered a plate of buffalo wings at the restaurant.`,//wing/noun
// 'The boat floats on the water.',
// 'I caught a cold and have a runny nose.',
// adjectives
// `He is always accommodating to his guests.`,//accommodating/adjective
// `The company offers advanced training programs for employees.`,//advanced/adjective
// `The comedian's jokes were incredibly amusing and had everyone in stitches.`,//amusing/adjective
// `Learning a new language can be challenging.`,//challenging/adjective
// `The book's characters are compelling and relatable.`,//compelling/adjective
// `The artist's work is visually compelling and unique.`,//compelling/adjective
// `The toilets are overflowing.`, //confusing/adjective
// `The toilet is overflowing.`, //confusing/adjective
// `The instructions for this game are confusing.`, //confusing/adjective
// `The road signs in this town are confusing.`, //confusing/adjective
// `I find the English language confusing sometimes.`, //confusing/adjective
// `The food at the restaurant was disappointing, it lacked flavor.`, //disappointing/adjective
// `He always plays fair in sports.`, //fair/adjective
// `The restaurant gave us free dessert after the meal.`, //free/adjective
`The holy book is sacred to believers.`, //holy/adjective
`The holy man blessed the crowd with peace.`, //holy/adjective
`The holy site is a place of worship.`, //holy/adjective
`The holy water is used for baptisms.`, //holy/adjective
`The puppy looked innocent with its big, round eyes.`, //innocent/adjective
`His speeches are always inspiring and motivate me.`, //inspiring/adjective
`The sunset over the ocean was truly inspiring.`, //inspiring/adjective
`The art exhibition was filled with inspiring works.`, //inspiring/adjective
`The internet provides instant access to information.`, //instant/adjective
`The driver checked his left mirror before turning.`, //left/adjective
`My left shoe is missing!`, //left/adjective
`She has long, blonde hair.`, //long/adjective
`The rainforest is home to many lush plants.`, //lush/adjective
`She walked through the lush green meadow.`, //lush/adjective
`The kids were being mean to each other.`, //mean/adjective
`He has a medium build and is quite strong.`, //medium/adjective
`It is important to have strong moral values.`, //moral/adjective
`The movie explores complex moral dilemmas.`, //moral/adjective
`Her waist looked narrow in the dress.`, //narrow/adjective
`His comments about her appearance were offensive.`, //offensive/adjective
`The movie contains offensive language and violence.`, //offensive/adjective
`She found his behavior towards her offensive.`, //offensive/adjective
`He was given an official warning for breaking the rules.`, //official/adjective
`I left the window open for fresh air.`, //open/adjective
`He looks pale because he is sick.`, //pale/adjective
`Her pale blue eyes sparkled with excitement.`, //pale/adjective
`The princess wore a pointy hat to the party.`, //pointy/adjective
`The mountain peak had a pointy shape.`, //pointy/adjective
`The witch's nose was long and pointy.`, //pointy/adjective
`The pencil has a pointy tip.`, //pointy/adjective
`The hotel room was pricy but luxurious.`, //pricy/adjective
`Eating at that restaurant can be pricy.`, //pricy/adjective
`This brand of shoes is known to be pricy.`, //pricy/adjective
`The new restaurant in town has promising reviews.`, //promising/adjective
`I don't tolerate racist comments.`, //racist/adjective
`She was accused of making racist remarks.`, //racist/adjective
`We need to address the issue of racist behavior.`, //racist/adjective
`He was criticized for his racist beliefs.`, //racist/adjective
`The seasoned chef prepared a delicious meal.`, //seasoned/adjective
`She is a seasoned traveler and knows the best places to visit.`, //seasoned/adjective
`The seasoned politician delivered a powerful speech.`, //seasoned/adjective
`He is a seasoned player and always performs well.`, //seasoned/adjective
`I find it shocking that people still believe that.`, //shocking/adjective
`The price of the stock has been stable for months.`, //stable/adjective
`He keeps his emotions stable in stressful situations.`, //stable/adjective
`The bridge is built on stable foundations.`, //stable/adjective
`The bride looked stunning in her white dress.`, //stunning/adjective
`The super cute puppy is playing in the park.`, //super/adjective
`It was surprising to see her there.`, //surprising/adjective
`Her sudden arrival was surprising to everyone.`, //surprising/adjective
`He became testy after waiting in line for hours.`, //testy/adjective
`Her testy remark upset everyone at the meeting.`, //testy/adjective
`The testy customer complained about the slow service.`, //testy/adjective
`She had a testy response to his question.`, //testy/adjective
`Working a full day can be tiring.`, //tiring/adjective
`The problem is trifling and can be easily solved.`, //trifling/adjective
`Don't waste your time on trifling matters.`, //trifling/adjective
`She dismissed his trifling comment with a wave of her hand.`, //trifling/adjective
`I'm tired of dealing with trifling people.`, //trifling/adjective
`The ground was wet after the rain.`, //wet/adjective
// 'he tries to improve her English',
// 'he learns to play tennis',
'he learns to code',
'he tried to code',
'he travelled around the world',
'he thought about toronto',
// 'gets paid',
// 'gets drunk',
// 'becoming involved',
// 'becoming entangled',
'(The cat) jumped onto the counter. [It] knocked over a glass.',
'The waiter emptied the water ',
"can't help but fork",
// 'poviding care',
'We take walks in the park.',
'the tree will grow',
'They listen to music on their way to work.',
// `find just one law abiding citizen`,
// 'sensationally',
// 'catch',
// 'teach',
// 'buy',
// 'break',
// 'sink',
// 'know',
// 'run',
// 'swim',
// 'sea of japan',
// 'adriadic sea',
// 'more broken promises',
// 'cheerful',
// 'secure',
// 'we will convert',
// 'matchmaking',
// "would be amusing",
// "would be outstanding",
// 'please do not speak',
// 'is a tough read',
// 'spot on',
// 'up to date',
// 'sleepier',
// 'guiltier',
// 'clean',
// 'drunk',
// 'hearty',
// 'holy',
// 'leery',
// 'solitary',
// 'cynically',
// 'hairy',
// 'richest',
// 'jet',
// "sittin",
// "ridin",
// "jus",
// "allergic",
// "listed",
// "quo",
// "triple",
// "foremost",
// "friends",
// "guys",
// "playin",
// "waitin",
// "gettin",
// "comin",
// "livin",
// "sayin",
// "doin",
// "lovin",
// "tone",
// "shore",
// "i drive to the cottage",
// "He will study biology in college.",
// "drive",
// "vie",
// "convoluted",
// "rooted",
// "trumpeted",
// "wad",
// "sub",
// 'overtime',
// "small fragment",
// 'manufacturing',
// 'stream',
// 'cave',
// 'what companies are doing is',
]
// let doc = nlp(arr[0]).debug()
// console.log(doc.people().debug().json())
// let p = doc.pronouns().debug().refersTo().debug()
// console.log(nlp('colored').debug().verbs().conjugate())
// doc.match('{sway/verb}').debug()
// console.log(doc.verbs().toPresentTense().text())
// console.log(doc.verbs().conjugate())
// doc.verbs().toPastParticiple()
// console.log(nlp('wore').verbs().conjugate())
// doc.verbs().debug()
// console.log(doc.text())
// console.log(doc.compute('root').text('root'))
// console.log(doc.json({ root: true })[0])
// let doc = nlp('she ran to the sea to see what he could see')
// doc.sentences().subjects().debug()
// let m = doc.match('[<date>#Value] [<month>#Month]')
// m.debug()
// m.groups().date.debug()
// m.groups().month.debug()
// console.log(nlp.parseMatch('[<month>#Month] [<date>#Value] [<year>#Year]?'))
// console.log(nlp.parseMatch('[<month>#Month] [<date>#Value] [<year>#Year?]'))
// let m = doc.match('[<month>#Month] [<date>#Value] [<year>#Year]?')
// console.log(m.groups())