rley 0.3.01 → 0.3.04

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,11 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
3
  require_relative '../../../lib/rley/parser/gfg_earley_parser'
4
+ require_relative '../../../lib/rley/parser/parse_walker_factory'
4
5
 
5
- require_relative '../../../lib/rley/syntax/grammar_builder'
6
6
  require_relative '../support/grammar_helper'
7
7
  require_relative '../support/expectation_helper'
8
-
9
- require_relative '../../../lib/rley/parser/parse_walker_factory'
8
+ require_relative '../support/grammar_L0_helper'
10
9
 
11
10
  # Load the class under test
12
11
  require_relative '../../../lib/rley/parser/parse_forest_builder'
@@ -92,40 +91,35 @@ module Rley # Open this namespace to avoid module qualifier prefixes
92
91
  event2 = walker.next
93
92
  subject.receive_event(*event2)
94
93
 
95
- expect(subject.curr_parent.to_string(0)).to eq('S[?, 4]')
96
- expected_path2 = 'Phi[0, 4]/S[?, 4]'
97
- expect(path_to_s).to eq(expected_path2)
94
+ event3 = walker.next
95
+ subject.receive_event(*event3)
96
+
97
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 4]')
98
+ expected_path3 = 'Phi[0, 4]/S[0, 4]'
99
+ expect(path_to_s).to eq(expected_path3)
98
100
  end
99
101
 
100
102
  it 'should build alternative node when detecting backtrack point' do
101
- 2.times do
103
+ 3.times do
102
104
  event = walker.next
103
105
  subject.receive_event(*event)
104
106
  end
105
107
 
106
- event3 = walker.next
107
- subject.receive_event(*event3)
108
+ event4 = walker.next
109
+ subject.receive_event(*event4)
108
110
 
109
111
  expect(subject.curr_parent.to_string(0)).to eq('Alt(S => a T .)[0, 4]')
110
- expected_path3 = 'Phi[0, 4]/S[0, 4]/Alt(S => a T .)[0, 4]'
111
- expect(path_to_s).to eq(expected_path3)
112
+ expected_path4 = 'Phi[0, 4]/S[0, 4]/Alt(S => a T .)[0, 4]'
113
+ expect(path_to_s).to eq(expected_path4)
112
114
  expect(subject.curr_path[-2].refinement).to eq(:or)
113
115
  end
114
116
 
115
117
  it 'should build token node when scan edge was detected' do
116
- 3.times do
118
+ 4.times do
117
119
  event = walker.next
118
120
  subject.receive_event(*event)
119
121
  end
120
122
 
121
- event4 = walker.next
122
- subject.receive_event(*event4)
123
- expect(event4[1].to_s).to eq('S => a T . | 0')
124
- expect(subject.curr_parent.to_string(0)).to eq('T[?, 4]')
125
- expected_path4 = 'Phi[0, 4]/S[0, 4]/Alt(S => a T .)[0, 4]/T[?, 4]'
126
- expect(path_to_s).to eq(expected_path4)
127
- expect(subject.curr_parent.subnodes).to be_empty
128
-
129
123
  event5 = walker.next
130
124
  subject.receive_event(*event5)
131
125
  expect(event5[1].to_s).to eq('T. | 1')
@@ -191,12 +185,12 @@ module Rley # Open this namespace to avoid module qualifier prefixes
191
185
  event12 = walker.next
192
186
  subject.receive_event(*event12)
193
187
  expect(event12[1].to_s).to eq('S => . a T | 0')
194
- expect(subject.curr_parent.to_string(0)).to eq('Alt(S => a T .)[0, 4]')
195
- expected_path12 = 'Phi[0, 4]/S[0, 4]/Alt(S => a T .)[0, 4]'
188
+
189
+ # Alternate node is popped
190
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 4]')
191
+ expected_path12 = 'Phi[0, 4]/S[0, 4]'
196
192
  expect(path_to_s).to eq(expected_path12)
197
- expect(subject.curr_parent.subnodes.size).to eq(2) # Is this OK?
198
193
 
199
- # Pop all Alternative nodes until no Alternative found, pop this last too
200
194
  event13 = walker.next
201
195
  subject.receive_event(*event13)
202
196
  expect(event13[1].to_s).to eq('.S | 0')
@@ -227,18 +221,18 @@ module Rley # Open this namespace to avoid module qualifier prefixes
227
221
  subject.receive_event(*event16)
228
222
  expect(event16[0]).to eq(:backtrack) # Backtrack event!
229
223
  expect(event16[1].to_s).to eq('S. | 0')
230
- # A new alternative node must be created
231
- expect(subject.curr_parent.to_string(0)).to eq('Alt(S => A T .)[0, 4]')
232
- expected_path16 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]'
224
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 4]')
225
+ expected_path16 = 'Phi[0, 4]/S[0, 4]'
233
226
  expect(path_to_s).to eq(expected_path16)
234
227
 
235
-
228
+ # Alternate node should be created
236
229
  event17 = walker.next
237
230
  subject.receive_event(*event17)
238
231
  expect(event17[1].to_s).to eq('S => A T . | 0')
239
- expect(subject.curr_parent.to_string(0)).to eq('T[?, 4]')
240
- expected_path17 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/T[?, 4]'
232
+ expect(subject.curr_parent.to_string(0)).to eq('Alt(S => A T .)[0, 4]')
233
+ expected_path17 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]'
241
234
  expect(path_to_s).to eq(expected_path17)
235
+ expect(subject.curr_path[-2].refinement).to eq(:or)
242
236
  end
243
237
 
244
238
  it 'should detect second time visit of an entry' do
@@ -258,39 +252,37 @@ module Rley # Open this namespace to avoid module qualifier prefixes
258
252
  event19 = walker.next
259
253
  subject.receive_event(*event19)
260
254
  expect(event19[1].to_s).to eq('S => A . T | 0')
261
- expect(subject.curr_parent.to_string(0)).to eq('A[?, 1]')
262
- expected_path19 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[?, 1]'
255
+ expect(subject.curr_parent.to_string(0)).to eq('Alt(S => A T .)[0, 4]')
256
+ expected_path19 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]'
263
257
  expect(path_to_s).to eq(expected_path19)
264
258
 
265
259
  event20 = walker.next
266
260
  subject.receive_event(*event20)
267
261
  # Next entry is an end entry...
268
262
  expect(event20[1].to_s).to eq('A. | 0')
269
- # ... with multiple antecedents => alternative nodes required
270
- expect(subject.curr_parent.to_string(0)).to eq('Alt(A => a .)[0, 1]')
271
- expected_path20 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => a .)[0, 1]'
263
+ expect(subject.curr_parent.to_string(0)).to eq('A[0, 1]')
264
+ expected_path20 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]'
272
265
  expect(path_to_s).to eq(expected_path20)
273
- expect(subject.curr_path[-2].refinement).to eq(:or)
266
+
274
267
 
275
268
  event21 = walker.next
276
269
  subject.receive_event(*event21)
277
270
  expect(event21[1].to_s).to eq('A => a . | 0')
278
271
  expect(subject.curr_parent.to_string(0)).to eq('Alt(A => a .)[0, 1]')
279
- expected_path21 = expected_path20
272
+ expected_path21 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => a .)[0, 1]'
280
273
  expect(path_to_s).to eq(expected_path21)
274
+ expect(subject.curr_path[-2].refinement).to eq(:or)
281
275
 
282
276
  event22 = walker.next
283
277
  subject.receive_event(*event22)
284
278
  expect(event22[1].to_s).to eq('A => . a | 0')
285
- expect(subject.curr_parent.to_string(0)).to eq('Alt(A => a .)[0, 1]')
279
+ expect(subject.curr_parent.to_string(0)).to eq('A[0, 1]')
286
280
  expected_path22 = expected_path20
287
281
  expect(path_to_s).to eq(expected_path22)
288
282
 
289
283
  event23 = walker.next
290
284
  subject.receive_event(*event23)
291
- # Next entry is an start entry...
292
285
  expect(event23[1].to_s).to eq('.A | 0')
293
- # ... with multiple antecedents => alternative nodes required
294
286
  expect(subject.curr_parent.to_string(0)).to eq('Alt(S => A T .)[0, 4]')
295
287
  expected_path23 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]'
296
288
  expect(path_to_s).to eq(expected_path23)
@@ -298,84 +290,387 @@ module Rley # Open this namespace to avoid module qualifier prefixes
298
290
  event24 = walker.next
299
291
  subject.receive_event(*event24)
300
292
  expect(event24[1].to_s).to eq('S => . A T | 0')
301
- # ... with multiple antecedents => alternative nodes required
302
- expect(subject.curr_parent.to_string(0)).to eq('Alt(S => A T .)[0, 4]')
303
- expected_path24 = expected_path23
293
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 4]')
294
+ expected_path24 = 'Phi[0, 4]/S[0, 4]'
304
295
  expect(path_to_s).to eq(expected_path24)
305
- end
306
-
307
- it 'should handle remaining events' do
308
- 24.times do
309
- event = walker.next
310
- subject.receive_event(*event)
311
- end
312
296
 
313
297
  event25 = walker.next
314
298
  subject.receive_event(*event25)
315
- expect(event25[0]).to eq(:backtrack) # Backtrack event!
316
- expect(event25[1].to_s).to eq('A. | 0')
317
- expect(subject.curr_parent.to_string(0)).to eq('Alt(A => B A .)[0, 1]')
318
- expected_path25 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]'
299
+ expect(event25[0]).to eq(:revisit) # Revisit event!
300
+ expect(event25[1].to_s).to eq('.S | 0')
301
+ expect(subject.curr_parent.to_string(0)).to eq('Phi[0, 4]')
302
+ expected_path25 = 'Phi[0, 4]'
319
303
  expect(path_to_s).to eq(expected_path25)
320
304
 
321
305
  event26 = walker.next
322
306
  subject.receive_event(*event26)
323
- expect(event26[1].to_s).to eq('A => B A . | 0')
324
- expect(subject.curr_parent.to_string(0)).to eq('A[?, 1]')
325
- expected_path26 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]/A[?, 1]'
307
+ expect(event26[0]).to eq(:revisit) # Revisit event!
308
+ expect(event26[1].to_s).to eq('.Phi | 0')
309
+ expected_path26 = ''
326
310
  expect(path_to_s).to eq(expected_path26)
311
+ end
312
+
313
+ it 'should handle remaining events' do
314
+ 26.times do
315
+ event = walker.next
316
+ subject.receive_event(*event)
317
+ end
327
318
 
328
319
  event27 = walker.next
329
320
  subject.receive_event(*event27)
330
- expect(event27[0]).to eq(:revisit) # Revisit event!
321
+ expect(event27[0]).to eq(:backtrack) # Backtrack event!
331
322
  expect(event27[1].to_s).to eq('A. | 0')
332
- expect(subject.curr_parent.to_string(0)).to eq('Alt(A => B A .)[0, 1]')
333
- expected_path27 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]'
323
+ expect(subject.curr_parent.to_string(0)).to eq('A[0, 1]')
324
+ expected_path27 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]'
334
325
  expect(path_to_s).to eq(expected_path27)
335
326
 
336
327
  event28 = walker.next
337
328
  subject.receive_event(*event28)
338
329
  expect(event28[0]).to eq(:visit)
339
- expect(event28[1].to_s).to eq('A => B . A | 0')
340
- expect(subject.curr_parent.to_string(0)).to eq('B[?, 0]')
341
- expected_path28 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]/B[?, 0]'
330
+ expect(event28[1].to_s).to eq('A => B A . | 0')
331
+ expect(subject.curr_parent.to_string(0)).to eq('Alt(A => B A .)[0, 1]')
332
+ expected_path28 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]'
342
333
  expect(path_to_s).to eq(expected_path28)
343
334
 
344
335
  event29 = walker.next
345
336
  subject.receive_event(*event29)
346
- expect(event29[0]).to eq(:visit)
347
- expect(event29[1].to_s).to eq('B. | 0')
348
- expect(subject.curr_parent.to_string(0)).to eq('B[0, 0]')
349
- expected_path29 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]/B[0, 0]'
337
+ expect(event29[0]).to eq(:revisit) # Revisit event!
338
+ expect(event29[1].to_s).to eq('A. | 0')
339
+ expect(subject.curr_parent.to_string(0)).to eq('Alt(A => B A .)[0, 1]')
340
+ expected_path29 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]'
350
341
  expect(path_to_s).to eq(expected_path29)
351
342
 
352
343
  event30 = walker.next
353
344
  subject.receive_event(*event30)
354
345
  expect(event30[0]).to eq(:visit)
355
- # Empty production!
356
- expect(event30[1].to_s).to eq('B => . | 0')
357
- expect(subject.curr_parent.to_string(0)).to eq('B[0, 0]')
358
- expected_path30 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]/B[0, 0]'
346
+ expect(event30[1].to_s).to eq('A => B . A | 0')
347
+ expect(subject.curr_parent.to_string(0)).to eq('Alt(A => B A .)[0, 1]')
348
+ expected_path30 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]'
359
349
  expect(path_to_s).to eq(expected_path30)
360
-
350
+
361
351
  event31 = walker.next
362
352
  subject.receive_event(*event31)
363
353
  expect(event31[0]).to eq(:visit)
364
- expect(event31[1].to_s).to eq('.B | 0')
365
- expect(subject.curr_parent.to_string(0)).to eq('Alt(A => B A .)[0, 1]')
366
- expected_path31 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]'
354
+ expect(event31[1].to_s).to eq('B. | 0')
355
+ expect(subject.curr_parent.to_string(0)).to eq('B[0, 0]')
356
+ expected_path31 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]/B[0, 0]'
367
357
  expect(path_to_s).to eq(expected_path31)
368
358
 
369
359
  event32 = walker.next
370
360
  subject.receive_event(*event32)
371
361
  expect(event32[0]).to eq(:visit)
372
- expect(event32[1].to_s).to eq('A => . B A | 0')
362
+ # Empty production!
363
+ expect(event32[1].to_s).to eq('B => . | 0')
364
+ expect(subject.curr_parent.to_string(0)).to eq('B[0, 0]')
365
+ expected_path30 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]/B[0, 0]'
366
+ expect(path_to_s).to eq(expected_path30)
367
+
368
+ event33 = walker.next
369
+ subject.receive_event(*event33)
370
+ expect(event33[0]).to eq(:visit)
371
+ expect(event33[1].to_s).to eq('.B | 0')
373
372
  expect(subject.curr_parent.to_string(0)).to eq('Alt(A => B A .)[0, 1]')
374
- expected_path32 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]'
375
- expect(path_to_s).to eq(expected_path32)
376
- end
373
+ expected_path33 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/Alt(A => B A .)[0, 1]'
374
+ expect(path_to_s).to eq(expected_path33)
375
+
376
+ event34 = walker.next
377
+ subject.receive_event(*event34)
378
+ expect(event34[0]).to eq(:visit)
379
+ expect(event34[1].to_s).to eq('A => . B A | 0')
380
+ expect(subject.curr_parent.to_string(0)).to eq('A[0, 1]')
381
+ expected_path34 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]'
382
+ expect(path_to_s).to eq(expected_path34)
383
+
384
+ event35 = walker.next
385
+ subject.receive_event(*event35)
386
+ expect(event35[0]).to eq(:revisit)
387
+ expect(event35[1].to_s).to eq('.A | 0')
388
+ expect(subject.curr_parent.to_string(0)).to eq('Alt(S => A T .)[0, 4]')
389
+ expected_path35 = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]'
390
+ expect(path_to_s).to eq(expected_path35)
391
+
392
+ event36 = walker.next
393
+ subject.receive_event(*event36)
394
+ expect(event36[0]).to eq(:revisit)
395
+ expect(event36[1].to_s).to eq('.S | 0')
396
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 4]')
397
+ expected_path36 = 'Phi[0, 4]/S[0, 4]'
398
+ expect(path_to_s).to eq(expected_path36)
399
+
400
+ event37 = walker.next
401
+ subject.receive_event(*event37)
402
+ expect(event37[0]).to eq(:revisit)
403
+ expect(event37[1].to_s).to eq('.Phi | 0')
404
+ expect(subject.curr_parent.to_string(0)).to eq('Phi[0, 4]')
405
+ expected_path37 = 'Phi[0, 4]'
406
+ expect(path_to_s).to eq(expected_path37)
407
+ end
377
408
  end # context
378
409
 
410
+ context 'Natural language processing' do
411
+ include GrammarL0Helper
412
+
413
+ let(:grammar_L0) do
414
+ builder = grammar_L0_builder
415
+ builder.grammar
416
+ end
417
+
418
+ let(:sentence_tokens) do
419
+ sentence = 'I prefer a morning flight'
420
+ tokenizer_L0(sentence, grammar_L0)
421
+ end
422
+
423
+ let(:sentence_result) do
424
+ parser = Parser::GFGEarleyParser.new(grammar_L0)
425
+ parser.parse(sentence_tokens)
426
+ end
427
+
428
+ let(:walker) do
429
+ factory = ParseWalkerFactory.new
430
+ accept_entry = sentence_result.accepting_entry
431
+ accept_index = sentence_result.chart.last_index
432
+ factory.build_walker(accept_entry, accept_index)
433
+ end
434
+
435
+ subject { ParseForestBuilder.new(sentence_tokens) }
436
+
437
+ it 'should handle walker events' do
438
+ event1 = walker.next
439
+ subject.receive_event(*event1)
440
+ expect(event1[0]).to eq(:visit)
441
+ expect(event1[1].to_s).to eq('S. | 0')
442
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 5]')
443
+ expected_path1 = 'S[0, 5]'
444
+ expect(path_to_s).to eq(expected_path1)
445
+
446
+ event2 = walker.next
447
+ subject.receive_event(*event2)
448
+ expect(event2[0]).to eq(:visit)
449
+ expect(event2[1].to_s).to eq('S => NP VP . | 0')
450
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 5]')
451
+ expected_path2 = expected_path1
452
+ expect(path_to_s).to eq(expected_path2)
453
+
454
+ event3 = walker.next
455
+ subject.receive_event(*event3)
456
+ expect(event3[0]).to eq(:visit)
457
+ expect(event3[1].to_s).to eq('VP. | 1')
458
+ expect(subject.curr_parent.to_string(0)).to eq('VP[1, 5]')
459
+ expected_path3 = 'S[0, 5]/VP[1, 5]'
460
+ expect(path_to_s).to eq(expected_path3)
461
+
462
+ event4 = walker.next
463
+ subject.receive_event(*event4)
464
+ expect(event4[0]).to eq(:visit)
465
+ expect(event4[1].to_s).to eq('VP => Verb NP . | 1')
466
+ expect(subject.curr_parent.to_string(0)).to eq('VP[1, 5]')
467
+ expected_path4 = 'S[0, 5]/VP[1, 5]'
468
+ expect(path_to_s).to eq(expected_path4)
469
+
470
+ event5 = walker.next
471
+ subject.receive_event(*event5)
472
+ expect(event5[0]).to eq(:visit)
473
+ expect(event5[1].to_s).to eq('NP. | 2')
474
+ expect(subject.curr_parent.to_string(0)).to eq('NP[2, 5]')
475
+ expected_path5 = 'S[0, 5]/VP[1, 5]/NP[2, 5]'
476
+ expect(path_to_s).to eq(expected_path5)
477
+
478
+ event6 = walker.next
479
+ subject.receive_event(*event6)
480
+ expect(event6[0]).to eq(:visit)
481
+ expect(event6[1].to_s).to eq('NP => Determiner Nominal . | 2')
482
+ expect(subject.curr_parent.to_string(0)).to eq('NP[2, 5]')
483
+ expected_path6 = 'S[0, 5]/VP[1, 5]/NP[2, 5]'
484
+ expect(path_to_s).to eq(expected_path6)
485
+
486
+ event7 = walker.next
487
+ subject.receive_event(*event7)
488
+ expect(event7[0]).to eq(:visit)
489
+ expect(event7[1].to_s).to eq('Nominal. | 3')
490
+ expect(subject.curr_parent.to_string(0)).to eq('Nominal[3, 5]')
491
+ expected_path7 = 'S[0, 5]/VP[1, 5]/NP[2, 5]/Nominal[3, 5]'
492
+ expect(path_to_s).to eq(expected_path7)
493
+
494
+ event8 = walker.next
495
+ subject.receive_event(*event8)
496
+ expect(event8[0]).to eq(:visit)
497
+ expect(event8[1].to_s).to eq('Nominal => Nominal Noun . | 3')
498
+ expect(subject.curr_parent.to_string(0)).to eq('Nominal[3, 5]')
499
+ expected_path8 = 'S[0, 5]/VP[1, 5]/NP[2, 5]/Nominal[3, 5]'
500
+ expect(path_to_s).to eq(expected_path8)
501
+ expect(subject.curr_parent.subnodes.size).to eq(1)
502
+ token_event8 = 'Noun[4, 5]'
503
+ expect(subject.curr_parent.subnodes.first.to_string(0)).to eq(token_event8)
504
+
505
+ event9 = walker.next
506
+ subject.receive_event(*event9)
507
+ expect(event9[0]).to eq(:visit)
508
+ expect(event9[1].to_s).to eq('Nominal => Nominal . Noun | 3')
509
+ expect(subject.curr_parent.to_string(0)).to eq('Nominal[3, 5]')
510
+ expected_path9 = 'S[0, 5]/VP[1, 5]/NP[2, 5]/Nominal[3, 5]'
511
+ expect(path_to_s).to eq(expected_path9)
512
+
513
+ event10 = walker.next
514
+ subject.receive_event(*event10)
515
+ expect(event10[0]).to eq(:visit)
516
+ expect(event10[1].to_s).to eq('Nominal. | 3')
517
+ expect(subject.curr_parent.to_string(0)).to eq('Nominal[3, 4]')
518
+ expected_path10 = 'S[0, 5]/VP[1, 5]/NP[2, 5]/Nominal[3, 5]/Nominal[3, 4]'
519
+ expect(path_to_s).to eq(expected_path10)
520
+
521
+ event11 = walker.next
522
+ subject.receive_event(*event11)
523
+ expect(event11[0]).to eq(:visit)
524
+ expect(event11[1].to_s).to eq('Nominal => Noun . | 3')
525
+ expect(subject.curr_parent.to_string(0)).to eq('Nominal[3, 4]')
526
+ expected_path11 = 'S[0, 5]/VP[1, 5]/NP[2, 5]/Nominal[3, 5]/Nominal[3, 4]'
527
+ expect(path_to_s).to eq(expected_path11)
528
+ expect(subject.curr_parent.subnodes.size).to eq(1)
529
+ token_event11 = 'Noun[3, 4]'
530
+ expect(subject.curr_parent.subnodes.first.to_string(0)).to eq(token_event11)
531
+
532
+ event12 = walker.next
533
+ subject.receive_event(*event12)
534
+ expect(event12[0]).to eq(:visit)
535
+ expect(event12[1].to_s).to eq('Nominal => . Noun | 3')
536
+ expect(subject.curr_parent.to_string(0)).to eq('Nominal[3, 4]')
537
+ expected_path12 = 'S[0, 5]/VP[1, 5]/NP[2, 5]/Nominal[3, 5]/Nominal[3, 4]'
538
+ expect(path_to_s).to eq(expected_path12)
539
+
540
+ event13 = walker.next
541
+ subject.receive_event(*event13)
542
+ expect(event13[0]).to eq(:visit)
543
+ expect(event13[1].to_s).to eq('.Nominal | 3')
544
+ expect(subject.curr_parent.to_string(0)).to eq('Nominal[3, 5]')
545
+ expected_path13 = 'S[0, 5]/VP[1, 5]/NP[2, 5]/Nominal[3, 5]'
546
+ expect(path_to_s).to eq(expected_path13)
547
+
548
+ event14 = walker.next
549
+ subject.receive_event(*event14)
550
+ expect(event14[0]).to eq(:visit)
551
+ expect(event14[1].to_s).to eq('Nominal => . Nominal Noun | 3')
552
+ expect(subject.curr_parent.to_string(0)).to eq('Nominal[3, 5]')
553
+ expected_path14 = 'S[0, 5]/VP[1, 5]/NP[2, 5]/Nominal[3, 5]'
554
+ expect(path_to_s).to eq(expected_path14)
555
+
556
+ event15 = walker.next
557
+ subject.receive_event(*event15)
558
+ expect(event15[0]).to eq(:revisit)
559
+ expect(event15[1].to_s).to eq('.Nominal | 3')
560
+ expect(subject.curr_parent.to_string(0)).to eq('NP[2, 5]')
561
+ expected_path15 = 'S[0, 5]/VP[1, 5]/NP[2, 5]'
562
+ expect(path_to_s).to eq(expected_path15)
563
+
564
+ event16 = walker.next
565
+ subject.receive_event(*event16)
566
+ expect(event16[0]).to eq(:visit)
567
+ expect(event16[1].to_s).to eq('NP => Determiner . Nominal | 2')
568
+ expect(subject.curr_parent.to_string(0)).to eq('NP[2, 5]')
569
+ expected_path16 = 'S[0, 5]/VP[1, 5]/NP[2, 5]'
570
+ expect(path_to_s).to eq(expected_path16)
571
+ token_event16 = 'Determiner[2, 3]'
572
+ expect(subject.curr_parent.subnodes.first.to_string(0)).to eq(token_event16)
573
+
574
+ event17 = walker.next
575
+ subject.receive_event(*event17)
576
+ expect(event17[0]).to eq(:visit)
577
+ expect(event17[1].to_s).to eq('NP => . Determiner Nominal | 2')
578
+ expect(subject.curr_parent.to_string(0)).to eq('NP[2, 5]')
579
+ expected_path17 = 'S[0, 5]/VP[1, 5]/NP[2, 5]'
580
+ expect(path_to_s).to eq(expected_path17)
581
+
582
+ event18 = walker.next
583
+ subject.receive_event(*event18)
584
+ expect(event18[0]).to eq(:visit)
585
+ expect(event18[1].to_s).to eq('.NP | 2')
586
+ expect(subject.curr_parent.to_string(0)).to eq('VP[1, 5]')
587
+ expected_path18 = 'S[0, 5]/VP[1, 5]'
588
+ expect(path_to_s).to eq(expected_path18)
589
+
590
+ event19 = walker.next
591
+ subject.receive_event(*event19)
592
+ expect(event19[0]).to eq(:visit)
593
+ expect(event19[1].to_s).to eq('VP => Verb . NP | 1')
594
+ expect(subject.curr_parent.to_string(0)).to eq('VP[1, 5]')
595
+ expected_path19 = 'S[0, 5]/VP[1, 5]'
596
+ expect(path_to_s).to eq(expected_path19)
597
+ token_event19 = 'Verb[1, 2]'
598
+ expect(subject.curr_parent.subnodes.first.to_string(0)).to eq(token_event19)
599
+
600
+ event20 = walker.next
601
+ subject.receive_event(*event20)
602
+ expect(event20[0]).to eq(:visit)
603
+ expect(event20[1].to_s).to eq('VP => . Verb NP | 1')
604
+ expect(subject.curr_parent.to_string(0)).to eq('VP[1, 5]')
605
+ expected_path20 = 'S[0, 5]/VP[1, 5]'
606
+ expect(path_to_s).to eq(expected_path20)
607
+
608
+ event21 = walker.next
609
+ subject.receive_event(*event21)
610
+ expect(event21[0]).to eq(:visit)
611
+ expect(event21[1].to_s).to eq('.VP | 1')
612
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 5]')
613
+ expected_path21 = 'S[0, 5]'
614
+ expect(path_to_s).to eq(expected_path21)
615
+
616
+ event22 = walker.next
617
+ subject.receive_event(*event22)
618
+ expect(event22[0]).to eq(:visit)
619
+ expect(event22[1].to_s).to eq('S => NP . VP | 0')
620
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 5]')
621
+ expected_path22 = 'S[0, 5]'
622
+ expect(path_to_s).to eq(expected_path22)
623
+
624
+ event23 = walker.next
625
+ subject.receive_event(*event23)
626
+ expect(event23[0]).to eq(:visit)
627
+ expect(event23[1].to_s).to eq('NP. | 0')
628
+ expect(subject.curr_parent.to_string(0)).to eq('NP[0, 1]')
629
+ expected_path23 = 'S[0, 5]/NP[0, 1]'
630
+ expect(path_to_s).to eq(expected_path23)
631
+
632
+ event24 = walker.next
633
+ subject.receive_event(*event24)
634
+ expect(event24[0]).to eq(:visit)
635
+ expect(event24[1].to_s).to eq('NP => Pronoun . | 0')
636
+ expect(subject.curr_parent.to_string(0)).to eq('NP[0, 1]')
637
+ expected_path24 = 'S[0, 5]/NP[0, 1]'
638
+ expect(path_to_s).to eq(expected_path24)
639
+ token_event24 = 'Pronoun[0, 1]'
640
+ expect(subject.curr_parent.subnodes.first.to_string(0)).to eq(token_event24)
641
+
642
+ event25 = walker.next
643
+ subject.receive_event(*event25)
644
+ expect(event25[0]).to eq(:visit)
645
+ expect(event25[1].to_s).to eq('NP => . Pronoun | 0')
646
+ expect(subject.curr_parent.to_string(0)).to eq('NP[0, 1]')
647
+ expected_path25 = 'S[0, 5]/NP[0, 1]'
648
+ expect(path_to_s).to eq(expected_path25)
649
+
650
+ event26 = walker.next
651
+ subject.receive_event(*event26)
652
+ expect(event26[0]).to eq(:visit)
653
+ expect(event26[1].to_s).to eq('.NP | 0')
654
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 5]')
655
+ expected_path26 = 'S[0, 5]'
656
+ expect(path_to_s).to eq(expected_path26)
657
+
658
+ event27 = walker.next
659
+ subject.receive_event(*event27)
660
+ expect(event27[0]).to eq(:visit)
661
+ expect(event27[1].to_s).to eq('S => . NP VP | 0')
662
+ expect(subject.curr_parent.to_string(0)).to eq('S[0, 5]')
663
+ expected_path27 = 'S[0, 5]'
664
+ expect(path_to_s).to eq(expected_path27)
665
+
666
+ event28 = walker.next
667
+ subject.receive_event(*event28)
668
+ expect(event28[0]).to eq(:visit)
669
+ expect(event28[1].to_s).to eq('.S | 0')
670
+ expected_path28 = ''
671
+ expect(path_to_s).to eq(expected_path28)
672
+ end
673
+ end # context
379
674
  end # describe
380
675
  end # module
381
676
  end # module
@@ -69,7 +69,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
69
69
  expect(forest).to be_kind_of(SPPF::ParseForest)
70
70
  =begin
71
71
  require 'yaml'
72
- require_relative '../sppf/forest_representation'
72
+ require_relative '../../../exp/lab/forest_representation'
73
73
  File.open("forest.yml", "w") { |f| YAML.dump(forest, f) }
74
74
  pen = ForestRepresentation.new
75
75
  pen.generate_graph(forest, File.open("forest.dot", "w"))