rley 0.8.13 → 0.8.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +28 -1
  3. data/CHANGELOG.md +6 -0
  4. data/examples/NLP/engtagger.rb +1 -1
  5. data/examples/general/calc_iter1/spec/calculator_spec.rb +9 -9
  6. data/examples/general/calc_iter2/spec/calculator_spec.rb +39 -39
  7. data/examples/general/recursive_right.rb +2 -2
  8. data/lib/rley/constants.rb +1 -1
  9. data/lib/rley/gfg/grm_flow_graph.rb +0 -1
  10. data/lib/rley/parser/parse_entry_set.rb +0 -1
  11. data/lib/rley/parser/parse_walker_factory.rb +0 -1
  12. data/lib/rley/rgn/grammar_builder.rb +0 -2
  13. data/lib/rley/rgn/tokenizer.rb +6 -6
  14. data/lib/rley/syntax/base_grammar_builder.rb +0 -1
  15. data/lib/rley/syntax/grammar.rb +0 -1
  16. data/spec/rley/base/dotted_item_spec.rb +46 -46
  17. data/spec/rley/base/grm_items_builder_spec.rb +1 -1
  18. data/spec/rley/engine_spec.rb +50 -50
  19. data/spec/rley/formatter/asciitree_spec.rb +8 -8
  20. data/spec/rley/formatter/bracket_notation_spec.rb +10 -10
  21. data/spec/rley/formatter/debug_spec.rb +10 -10
  22. data/spec/rley/formatter/json_spec.rb +6 -7
  23. data/spec/rley/gfg/call_edge_spec.rb +6 -6
  24. data/spec/rley/gfg/edge_spec.rb +8 -7
  25. data/spec/rley/gfg/end_vertex_spec.rb +8 -7
  26. data/spec/rley/gfg/epsilon_edge_spec.rb +5 -4
  27. data/spec/rley/gfg/grm_flow_graph_spec.rb +33 -34
  28. data/spec/rley/gfg/item_vertex_spec.rb +34 -36
  29. data/spec/rley/gfg/non_terminal_vertex_spec.rb +12 -12
  30. data/spec/rley/gfg/return_edge_spec.rb +6 -6
  31. data/spec/rley/gfg/scan_edge_spec.rb +7 -6
  32. data/spec/rley/gfg/shortcut_edge_spec.rb +15 -15
  33. data/spec/rley/gfg/start_vertex_spec.rb +8 -8
  34. data/spec/rley/gfg/vertex_spec.rb +18 -18
  35. data/spec/rley/lexical/literal_spec.rb +5 -5
  36. data/spec/rley/lexical/token_range_spec.rb +55 -55
  37. data/spec/rley/lexical/token_spec.rb +17 -16
  38. data/spec/rley/parse_forest_visitor_spec.rb +30 -32
  39. data/spec/rley/parse_rep/ambiguous_parse_spec.rb +2 -2
  40. data/spec/rley/parse_rep/ast_builder_spec.rb +30 -30
  41. data/spec/rley/parse_rep/cst_builder_spec.rb +85 -85
  42. data/spec/rley/parse_rep/groucho_spec.rb +23 -23
  43. data/spec/rley/parse_rep/parse_forest_builder_spec.rb +42 -42
  44. data/spec/rley/parse_rep/parse_forest_factory_spec.rb +10 -12
  45. data/spec/rley/parse_rep/parse_tree_factory_spec.rb +10 -15
  46. data/spec/rley/parse_tree_visitor_spec.rb +43 -46
  47. data/spec/rley/parser/dangling_else_spec.rb +12 -12
  48. data/spec/rley/parser/error_reason_spec.rb +37 -37
  49. data/spec/rley/parser/gfg_chart_spec.rb +27 -29
  50. data/spec/rley/parser/gfg_earley_parser_spec.rb +55 -56
  51. data/spec/rley/parser/gfg_parsing_spec.rb +106 -103
  52. data/spec/rley/parser/parse_entry_set_spec.rb +63 -61
  53. data/spec/rley/parser/parse_entry_spec.rb +73 -71
  54. data/spec/rley/parser/parse_walker_factory_spec.rb +14 -15
  55. data/spec/rley/ptree/non_terminal_node_spec.rb +16 -16
  56. data/spec/rley/ptree/parse_tree_node_spec.rb +11 -11
  57. data/spec/rley/ptree/parse_tree_spec.rb +6 -8
  58. data/spec/rley/ptree/terminal_node_spec.rb +6 -6
  59. data/spec/rley/rgn/grammar_builder_spec.rb +69 -67
  60. data/spec/rley/rgn/parser_spec.rb +63 -63
  61. data/spec/rley/rgn/repetition_node_spec.rb +15 -15
  62. data/spec/rley/rgn/sequence_node_spec.rb +10 -10
  63. data/spec/rley/rgn/symbol_node_spec.rb +5 -6
  64. data/spec/rley/rgn/tokenizer_spec.rb +68 -67
  65. data/spec/rley/sppf/alternative_node_spec.rb +16 -16
  66. data/spec/rley/sppf/non_terminal_node_spec.rb +20 -20
  67. data/spec/rley/sppf/token_node_spec.rb +13 -13
  68. data/spec/rley/syntax/base_grammar_builder_spec.rb +76 -86
  69. data/spec/rley/syntax/grammar_spec.rb +40 -78
  70. data/spec/rley/syntax/grm_symbol_spec.rb +7 -7
  71. data/spec/rley/syntax/match_closest_spec.rb +8 -8
  72. data/spec/rley/syntax/non_terminal_spec.rb +25 -25
  73. data/spec/rley/syntax/production_spec.rb +33 -33
  74. data/spec/rley/syntax/symbol_seq_spec.rb +27 -27
  75. data/spec/rley/syntax/terminal_spec.rb +12 -11
  76. data/spec/support/base_tokenizer_spec.rb +9 -8
  77. metadata +2 -2
@@ -19,6 +19,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
19
19
  include GrammarBExprHelper # Mix-in for basic arithmetic language
20
20
  include GrammarArrIntHelper # Mix-in for array of integers language
21
21
 
22
+ subject(:a_builder) { described_class.new(sample_tokens) }
23
+
22
24
  let(:sample_grammar) do
23
25
  builder = grammar_expr_builder
24
26
  builder.grammar
@@ -28,8 +30,6 @@ module Rley # Open this namespace to avoid module qualifier prefixes
28
30
  expr_tokenizer('2 + 3 * 4')
29
31
  end
30
32
 
31
- subject { CSTBuilder.new(sample_tokens) }
32
-
33
33
  def init_walker(theParser, theTokens)
34
34
  result = theParser.parse(theTokens)
35
35
  factory = Parser::ParseWalkerFactory.new
@@ -41,7 +41,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
41
41
  def skip_events(count)
42
42
  count.times do
43
43
  event = @walker.next
44
- subject.receive_event(*event)
44
+ a_builder.receive_event(*event)
45
45
  end
46
46
  end
47
47
 
@@ -54,27 +54,27 @@ module Rley # Open this namespace to avoid module qualifier prefixes
54
54
  end
55
55
 
56
56
  context 'Initialization:' do
57
- it 'should be created with a sequence of tokens' do
58
- expect { CSTBuilder.new(sample_tokens) }.not_to raise_error
57
+ it 'is created with a sequence of tokens' do
58
+ expect { described_class.new(sample_tokens) }.not_to raise_error
59
59
  end
60
60
 
61
- it 'should know the input tokens' do
62
- expect(subject.tokens).to eq(sample_tokens)
61
+ it 'knows the input tokens' do
62
+ expect(a_builder.tokens).to eq(sample_tokens)
63
63
  end
64
64
 
65
- it "shouldn't know the result yet" do
66
- expect(subject.result).to be_nil
65
+ it "doesn't know the result yet" do
66
+ expect(a_builder.result).to be_nil
67
67
  end
68
68
 
69
- it 'should have an empty stack' do
70
- expect(subject.send(:stack)).to be_empty
69
+ it 'has an empty stack' do
70
+ expect(a_builder.send(:stack)).to be_empty
71
71
  end
72
72
  end # context
73
73
 
74
74
 
75
75
 
76
76
  context 'Parse tree construction (no null symbol):' do
77
- before(:each) do
77
+ before do
78
78
  parser = Parser::GFGEarleyParser.new(sample_grammar)
79
79
  init_walker(parser, sample_tokens)
80
80
  end
@@ -120,196 +120,196 @@ module Rley # Open this namespace to avoid module qualifier prefixes
120
120
  # Event: visit P => . S | 0 0
121
121
  # Event: visit .P | 0 0
122
122
 
123
- it 'should react to a first end event' do
123
+ it 'reacts to a first end event' do
124
124
  event = @walker.next
125
- expect { subject.receive_event(*event) }.not_to raise_error
126
- stack = get_stack(subject)
125
+ expect { a_builder.receive_event(*event) }.not_to raise_error
126
+ stack = get_stack(a_builder)
127
127
  expect(stack.size).to eq(1)
128
128
  expect(stack.last.range).to eq(create_range(0, 5))
129
129
  expect(stack.last.children).to be_nil
130
130
  end
131
131
 
132
- it 'should react to a first exit event' do
132
+ it 'reacts to a first exit event' do
133
133
  skip_events(1)
134
134
  event = @walker.next
135
- expect { subject.receive_event(*event) }.not_to raise_error
136
- stack = get_stack(subject)
135
+ expect { a_builder.receive_event(*event) }.not_to raise_error
136
+ stack = get_stack(a_builder)
137
137
  expect(stack.size).to eq(1)
138
138
  end
139
139
 
140
- it 'should react to a second end event' do
140
+ it 'reacts to a second end event' do
141
141
  skip_events(2)
142
142
  event = @walker.next
143
- expect { subject.receive_event(*event) }.not_to raise_error
144
- stack = get_stack(subject)
143
+ expect { a_builder.receive_event(*event) }.not_to raise_error
144
+ stack = get_stack(a_builder)
145
145
  expect(stack.size).to eq(2)
146
146
  expect(stack.last.range).to eq(create_range(0, 5))
147
147
  expect(stack.last.children).to be_nil
148
148
  end
149
149
 
150
- it 'should react to a second exit event' do
150
+ it 'reacts to a second exit event' do
151
151
  skip_events(3)
152
152
  event = @walker.next
153
- expect { subject.receive_event(*event) }.not_to raise_error
154
- stack = get_stack(subject)
153
+ expect { a_builder.receive_event(*event) }.not_to raise_error
154
+ stack = get_stack(a_builder)
155
155
  expect(stack.size).to eq(2)
156
156
  expect(stack.last.children.size).to eq(3)
157
157
  end
158
158
 
159
- it 'should react to an exit event that creates a terminal node' do
159
+ it 'reacts to an exit event that creates a terminal node' do
160
160
  skip_events(7)
161
161
  event = @walker.next
162
- expect { subject.receive_event(*event) }.not_to raise_error
163
- stack = get_stack(subject)
162
+ expect { a_builder.receive_event(*event) }.not_to raise_error
163
+ stack = get_stack(a_builder)
164
164
  expect(stack.size).to eq(4)
165
165
  expect(stack.last.children.size).to eq(1)
166
166
  child = stack.last.children[-1]
167
- expect(child).to be_kind_of(PTree::TerminalNode)
167
+ expect(child).to be_a(PTree::TerminalNode)
168
168
  expect(child.to_s).to eq("integer[4, 5]: '4'")
169
169
  end
170
170
 
171
171
 
172
- it 'should react to a first entry event' do
172
+ it 'reacts to a first entry event' do
173
173
  skip_events(8)
174
174
  event = @walker.next
175
- expect { subject.receive_event(*event) }.not_to raise_error
176
- stack = get_stack(subject)
175
+ expect { a_builder.receive_event(*event) }.not_to raise_error
176
+ stack = get_stack(a_builder)
177
177
  expect(stack.size).to eq(3) # Element popped
178
178
  expect(stack.last.children.size).to eq(3)
179
179
  child = stack.last.children[-1]
180
- expect(child).to be_kind_of(PTree::NonTerminalNode)
180
+ expect(child).to be_a(PTree::NonTerminalNode)
181
181
  expect(child.to_s).to eq('T[4, 5]')
182
182
  end
183
183
 
184
- it 'should react to a first start event' do
184
+ it 'reacts to a first start event' do
185
185
  skip_events(9)
186
186
  event = @walker.next
187
- expect { subject.receive_event(*event) }.not_to raise_error
188
- stack = get_stack(subject)
187
+ expect { a_builder.receive_event(*event) }.not_to raise_error
188
+ stack = get_stack(a_builder)
189
189
  expect(stack.size).to eq(3)
190
190
  end
191
191
 
192
- it 'should react to an middle event that creates a terminal node' do
192
+ it 'reacts to an middle event that creates a terminal node (i)' do
193
193
  skip_events(10)
194
194
  event = @walker.next
195
- expect { subject.receive_event(*event) }.not_to raise_error
196
- stack = get_stack(subject)
195
+ expect { a_builder.receive_event(*event) }.not_to raise_error
196
+ stack = get_stack(a_builder)
197
197
  expect(stack.size).to eq(3)
198
198
  expect(stack.last.children.size).to eq(3)
199
199
  child = stack.last.children[1]
200
- expect(child).to be_kind_of(PTree::TerminalNode)
200
+ expect(child).to be_a(PTree::TerminalNode)
201
201
  expect(child.to_s).to eq("*[3, 4]: '*'")
202
202
  end
203
203
 
204
- it 'should react to an exit event that creates a terminal node' do
204
+ it 'reacts to an exit event that creates a terminal node (ii)' do
205
205
  skip_events(15)
206
206
  event = @walker.next
207
- expect { subject.receive_event(*event) }.not_to raise_error
208
- stack = get_stack(subject)
207
+ expect { a_builder.receive_event(*event) }.not_to raise_error
208
+ stack = get_stack(a_builder)
209
209
  expect(stack.size).to eq(5)
210
210
  expect(stack.last.children.size).to eq(1)
211
211
  child = stack.last.children[-1]
212
- expect(child).to be_kind_of(PTree::TerminalNode)
212
+ expect(child).to be_a(PTree::TerminalNode)
213
213
  expect(child.to_s).to eq("integer[2, 3]: '3'")
214
214
  end
215
215
 
216
- it 'should ignore to a revisit event' do
216
+ it 'ignores to a revisit event' do
217
217
  skip_events(21)
218
218
  event = @walker.next
219
- expect { subject.receive_event(*event) }.not_to raise_error
220
- stack = get_stack(subject)
219
+ expect { a_builder.receive_event(*event) }.not_to raise_error
220
+ stack = get_stack(a_builder)
221
221
  expect(stack.size).to eq(2)
222
222
  expect(stack.last.children.size).to eq(3)
223
223
  child = stack.last.children[-1]
224
- expect(child).to be_kind_of(PTree::NonTerminalNode)
224
+ expect(child).to be_a(PTree::NonTerminalNode)
225
225
  expect(child.to_s).to eq('M[2, 5]')
226
226
  end
227
227
 
228
- it 'should react to a 2nd middle event that creates a terminal node' do
228
+ it 'reacts to a 2nd middle event that creates a terminal node' do
229
229
  skip_events(22)
230
230
  event = @walker.next
231
- expect { subject.receive_event(*event) }.not_to raise_error
232
- stack = get_stack(subject)
231
+ expect { a_builder.receive_event(*event) }.not_to raise_error
232
+ stack = get_stack(a_builder)
233
233
  expect(stack.size).to eq(2)
234
234
  expect(stack.last.children.size).to eq(3)
235
235
  child = stack.last.children[1]
236
- expect(child).to be_kind_of(PTree::TerminalNode)
236
+ expect(child).to be_a(PTree::TerminalNode)
237
237
  expect(child.to_s).to eq("+[1, 2]: '+'")
238
238
  end
239
239
 
240
- it 'should react to a exit event that creates a terminal node' do
240
+ it 'reacts to a exit event that creates a terminal node' do
241
241
  skip_events(29)
242
242
  event = @walker.next
243
- expect { subject.receive_event(*event) }.not_to raise_error
244
- stack = get_stack(subject)
243
+ expect { a_builder.receive_event(*event) }.not_to raise_error
244
+ stack = get_stack(a_builder)
245
245
  expect(stack.size).to eq(5)
246
246
  expect(stack.last.children.size).to eq(1)
247
247
  child = stack.last.children[-1]
248
- expect(child).to be_kind_of(PTree::TerminalNode)
248
+ expect(child).to be_a(PTree::TerminalNode)
249
249
  expect(child.to_s).to eq("integer[0, 1]: '2'")
250
250
  end
251
251
 
252
252
 
253
- it 'should react to entry event 31' do
253
+ it 'reacts to entry event 31' do
254
254
  skip_events(30)
255
255
  event = @walker.next
256
- expect { subject.receive_event(*event) }.not_to raise_error
257
- stack = get_stack(subject)
256
+ expect { a_builder.receive_event(*event) }.not_to raise_error
257
+ stack = get_stack(a_builder)
258
258
  expect(stack.size).to eq(4)
259
259
  expect(stack.last.children.size).to eq(1)
260
260
  child = stack.last.children[-1]
261
- expect(child).to be_kind_of(PTree::NonTerminalNode)
261
+ expect(child).to be_a(PTree::NonTerminalNode)
262
262
  expect(child.to_s).to eq('T[0, 1]')
263
263
  end
264
264
 
265
- it 'should react to entry event 33' do
265
+ it 'reacts to entry event 33' do
266
266
  skip_events(32)
267
267
  event = @walker.next
268
- expect { subject.receive_event(*event) }.not_to raise_error
269
- stack = get_stack(subject)
268
+ expect { a_builder.receive_event(*event) }.not_to raise_error
269
+ stack = get_stack(a_builder)
270
270
  expect(stack.size).to eq(3)
271
271
  expect(stack.last.children.size).to eq(1)
272
272
  child = stack.last.children[-1]
273
- expect(child).to be_kind_of(PTree::NonTerminalNode)
273
+ expect(child).to be_a(PTree::NonTerminalNode)
274
274
  expect(child.to_s).to eq('M[0, 1]')
275
275
  end
276
276
 
277
- it 'should react to entry event 35' do
277
+ it 'reacts to entry event 35' do
278
278
  skip_events(34)
279
279
  event = @walker.next
280
- expect { subject.receive_event(*event) }.not_to raise_error
281
- stack = get_stack(subject)
280
+ expect { a_builder.receive_event(*event) }.not_to raise_error
281
+ stack = get_stack(a_builder)
282
282
  expect(stack.size).to eq(2)
283
283
  expect(stack.last.children.size).to eq(3)
284
284
  child = stack.last.children[0]
285
- expect(child).to be_kind_of(PTree::NonTerminalNode)
285
+ expect(child).to be_a(PTree::NonTerminalNode)
286
286
  expect(child.to_s).to eq('S[0, 1]')
287
287
  end
288
288
 
289
- it 'should react to entry event 37' do
289
+ it 'reacts to entry event 37' do
290
290
  skip_events(36)
291
291
  event = @walker.next
292
- expect { subject.receive_event(*event) }.not_to raise_error
293
- stack = get_stack(subject)
292
+ expect { a_builder.receive_event(*event) }.not_to raise_error
293
+ stack = get_stack(a_builder)
294
294
  expect(stack.size).to eq(1)
295
295
  expect(stack.last.children.size).to eq(1)
296
296
  child = stack.last.children[0]
297
- expect(child).to be_kind_of(PTree::NonTerminalNode)
297
+ expect(child).to be_a(PTree::NonTerminalNode)
298
298
  expect(child.to_s).to eq('S[0, 5]')
299
299
  end
300
300
 
301
- it 'should react to entry event that creates the tree' do
301
+ it 'reacts to entry event that creates the tree' do
302
302
  skip_events(38)
303
303
  event = @walker.next
304
- expect { subject.receive_event(*event) }.not_to raise_error
305
- stack = get_stack(subject)
304
+ expect { a_builder.receive_event(*event) }.not_to raise_error
305
+ stack = get_stack(a_builder)
306
306
  expect(stack).to be_empty
307
- expect(subject.result).to be_kind_of(PTree::ParseTree)
307
+ expect(a_builder.result).to be_a(PTree::ParseTree)
308
308
 
309
309
  # Lightweight sanity check
310
- expect(subject.result.root.to_s).to eq('P[0, 5]')
311
- expect(subject.result.root.subnodes.size).to eq(1)
312
- child_node = subject.result.root.subnodes[0]
310
+ expect(a_builder.result.root.to_s).to eq('P[0, 5]')
311
+ expect(a_builder.result.root.subnodes.size).to eq(1)
312
+ child_node = a_builder.result.root.subnodes[0]
313
313
  expect(child_node.to_s).to eq('S[0, 5]')
314
314
  expect(child_node.subnodes.size).to eq(3)
315
315
  first_grandchild = child_node.subnodes[0]
@@ -335,14 +335,14 @@ module Rley # Open this namespace to avoid module qualifier prefixes
335
335
  builder.grammar
336
336
  end
337
337
 
338
- before(:each) do
338
+ before do
339
339
  @parser = Parser::GFGEarleyParser.new(array_grammar)
340
340
  end
341
341
 
342
342
  # The visit events were generated with the following snippets:
343
343
  # 13.times do
344
344
  # event = @walker.next
345
- # subject.receive_event(*event)
345
+ # a_builder.receive_event(*event)
346
346
  # end
347
347
  # The events are:
348
348
  # Event: visit P. | 0 2
@@ -358,9 +358,9 @@ module Rley # Open this namespace to avoid module qualifier prefixes
358
358
  # Event: visit .arr | 0 0
359
359
  # Event: visit P => . arr | 0 0
360
360
  # Event: visit .P | 0 0
361
- it 'should build a tree for an empty array' do
361
+ it 'builds a tree for an empty array' do
362
362
  empty_arr_tokens = arr_int_tokenizer('[ ]')
363
- @instance = CSTBuilder.new(empty_arr_tokens)
363
+ @instance = described_class.new(empty_arr_tokens)
364
364
  init_walker(@parser, empty_arr_tokens)
365
365
  stack = get_stack(@instance)
366
366
 
@@ -400,7 +400,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
400
400
  # stack: [arr[0, 2], P[0, 2]]
401
401
  expect(stack.last.range).to eq(create_range(0, 2))
402
402
  sequence = stack.last.children[1]
403
- expect(sequence).to be_kind_of(PTree::NonTerminalNode)
403
+ expect(sequence).to be_a(PTree::NonTerminalNode)
404
404
  expect(sequence.subnodes).to be_empty
405
405
  expect(sequence.to_s).to eq('sequence[1, 1]')
406
406
 
@@ -411,7 +411,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
411
411
  expect(stack.size).to eq(2)
412
412
  expect(stack.last.range).to eq(create_range(0, 2))
413
413
  sequence = stack.last.children[0]
414
- expect(sequence).to be_kind_of(PTree::TerminalNode)
414
+ expect(sequence).to be_a(PTree::TerminalNode)
415
415
  expect(sequence.to_s).to eq("[[0, 1]: '['")
416
416
 
417
417
  next_event('visit arr => . [ sequence ] | 0 0')
@@ -419,7 +419,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
419
419
  # stack: [P[0, 2]]
420
420
  expect(stack.last.range).to eq(create_range(0, 2))
421
421
  expect(stack.last.children.size).to eq(1)
422
- expect(stack.last.children[0]).to be_kind_of(PTree::NonTerminalNode)
422
+ expect(stack.last.children[0]).to be_a(PTree::NonTerminalNode)
423
423
  expect(stack.last.children[0].to_s).to eq('arr[0, 2]')
424
424
 
425
425
  next_event('visit .arr | 0 0')
@@ -50,6 +50,16 @@ module Rley # Open this namespace to avoid module qualifier prefixes
50
50
  }
51
51
  end
52
52
 
53
+ let(:sentence_tokens) do
54
+ sentence = 'I shot an elephant in my pajamas'
55
+ tokenizer(sentence, sample_grammar)
56
+ end
57
+
58
+ let(:sentence_result) do
59
+ parser = Parser::GFGEarleyParser.new(sample_grammar)
60
+ parser.parse(sentence_tokens)
61
+ end
62
+
53
63
  # Highly simplified tokenizer implementation.
54
64
  def tokenizer(aText, aGrammar)
55
65
  pos = Rley::Lexical::Position.new(1, 2) # Dummy position
@@ -62,19 +72,9 @@ module Rley # Open this namespace to avoid module qualifier prefixes
62
72
  end
63
73
  end
64
74
 
65
- let(:sentence_tokens) do
66
- sentence = 'I shot an elephant in my pajamas'
67
- tokenizer(sentence, sample_grammar)
68
- end
69
-
70
- let(:sentence_result) do
71
- parser = Parser::GFGEarleyParser.new(sample_grammar)
72
- parser.parse(sentence_tokens)
73
- end
74
-
75
75
  # Emit a text representation of the current path.
76
76
  def path_to_s
77
- text_parts = subject.curr_path.map do |path_element|
77
+ text_parts = a_builder.curr_path.map do |path_element|
78
78
  path_element.to_string(0)
79
79
  end
80
80
  text_parts.join('/')
@@ -82,13 +82,13 @@ module Rley # Open this namespace to avoid module qualifier prefixes
82
82
 
83
83
  def next_event(eventType, anEntryText)
84
84
  event = @walker.next
85
- subject.receive_event(*event)
85
+ a_builder.receive_event(*event)
86
86
  expect(event[0]).to eq(eventType)
87
87
  expect(event[1].to_s).to eq(anEntryText)
88
88
  end
89
89
 
90
90
  def expected_curr_parent(anExpectation)
91
- expect(subject.curr_parent.to_string(0)).to eq(anExpectation)
91
+ expect(a_builder.curr_parent.to_string(0)).to eq(anExpectation)
92
92
  end
93
93
 
94
94
  def expected_curr_path(anExpectation)
@@ -96,16 +96,16 @@ module Rley # Open this namespace to avoid module qualifier prefixes
96
96
  end
97
97
 
98
98
  def expected_first_child(anExpectation)
99
- child = subject.curr_parent.subnodes.first
99
+ child = a_builder.curr_parent.subnodes.first
100
100
  expect(child.to_string(0)).to eq(anExpectation)
101
101
  end
102
102
 
103
103
  def root_children
104
- subject.result.root.subnodes
104
+ a_builder.result.root.subnodes
105
105
  end
106
106
 
107
107
 
108
- before(:each) do
108
+ before do
109
109
  factory = Parser::ParseWalkerFactory.new
110
110
  accept_entry = sentence_result.accepting_entry
111
111
  accept_index = sentence_result.chart.last_index
@@ -113,12 +113,12 @@ module Rley # Open this namespace to avoid module qualifier prefixes
113
113
  end
114
114
 
115
115
  context 'Parse ambiguous sentence' do
116
- subject { ParseForestBuilder.new(sentence_tokens) }
116
+ subject(:a_builder) { ParseForestBuilder.new(sentence_tokens) }
117
117
 
118
- it 'should build a parse forest with a correct root node' do
118
+ it 'builds a parse forest with a correct root node' do
119
119
  next_event(:visit, 'S. | 0') # Event 1
120
120
  expected_curr_path('S[0, 7]')
121
- # Root node should have no child
121
+ # Root node has no child
122
122
  expect(root_children.size).to be_zero
123
123
 
124
124
  next_event(:visit, 'S => NP VP . | 0') # Event 2
@@ -126,24 +126,24 @@ module Rley # Open this namespace to avoid module qualifier prefixes
126
126
 
127
127
  next_event(:visit, 'VP. | 1') # Event 3
128
128
  expected_curr_path('S[0, 7]/VP[1, 7]')
129
- # Root node should have one child
129
+ # Root node has one child
130
130
  expect(root_children.size).to eq(1)
131
131
  expect(root_children.first.to_string(0)).to eq('VP[1, 7]')
132
132
 
133
133
  25.times do
134
134
  event = @walker.next
135
- subject.receive_event(*event)
135
+ a_builder.receive_event(*event)
136
136
  end
137
137
 
138
138
  next_event(:visit, 'NP. | 0') # Event 29
139
139
  expected_curr_path('S[0, 7]/NP[0, 1]')
140
- # Root node should have two children
140
+ # Root node has two children
141
141
  expect(root_children.size).to eq(2)
142
142
  expect(root_children.first.to_string(0)).to eq('NP[0, 1]')
143
143
 
144
144
  18.times do
145
145
  event = @walker.next
146
- subject.receive_event(*event)
146
+ a_builder.receive_event(*event)
147
147
  end
148
148
 
149
149
  next_event(:revisit, 'NP. | 0') # Event 48