biodiversity19 0.5.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,475 @@
1
+ # encoding: UTF-8
2
+ module ScientificNameCanonical
3
+ include Treetop::Runtime
4
+
5
+ def root
6
+ @root || :root
7
+ end
8
+
9
+ include ScientificNameClean
10
+
11
+ include ScientificNameDirty
12
+
13
+ module Root0
14
+ def hybrid
15
+ false
16
+ end
17
+
18
+ def details
19
+ [super]
20
+ end
21
+ end
22
+
23
+ module Root1
24
+ def hybrid
25
+ false
26
+ end
27
+
28
+ def details
29
+ [super]
30
+ end
31
+ end
32
+
33
+ def _nt_root
34
+ start_index = index
35
+ if node_cache[:root].has_key?(index)
36
+ cached = node_cache[:root][index]
37
+ if cached
38
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
39
+ @index = cached.interval.end
40
+ end
41
+ return cached
42
+ end
43
+
44
+ i0 = index
45
+ r1 = _nt_multinomial_with_garbage
46
+ r1.extend(Root0)
47
+ if r1
48
+ r0 = r1
49
+ else
50
+ r2 = _nt_uninomial_with_garbage
51
+ r2.extend(Root1)
52
+ if r2
53
+ r0 = r2
54
+ else
55
+ @index = i0
56
+ r0 = nil
57
+ end
58
+ end
59
+
60
+ node_cache[:root][start_index] = r0
61
+
62
+ r0
63
+ end
64
+
65
+ module MultinomialWithGarbage0
66
+ def a
67
+ elements[0]
68
+ end
69
+
70
+ def space1
71
+ elements[1]
72
+ end
73
+
74
+ def b
75
+ elements[2]
76
+ end
77
+
78
+ def space2
79
+ elements[3]
80
+ end
81
+
82
+ def c
83
+ elements[4]
84
+ end
85
+
86
+ def garbage
87
+ elements[5]
88
+ end
89
+ end
90
+
91
+ module MultinomialWithGarbage1
92
+ def value
93
+ a.value + " " + b.value + " " + c.value
94
+ end
95
+
96
+ def canonical
97
+ a.canonical + " " + b.canonical + " " + c.canonical
98
+ end
99
+
100
+ def pos
101
+ a.pos.merge(b.pos).merge(c.pos)
102
+ end
103
+
104
+ def details
105
+ a.details.merge(b.details).merge(c.details)
106
+ end
107
+ end
108
+
109
+ module MultinomialWithGarbage2
110
+ def a
111
+ elements[0]
112
+ end
113
+
114
+ def space
115
+ elements[1]
116
+ end
117
+
118
+ def b
119
+ elements[2]
120
+ end
121
+
122
+ def garbage
123
+ elements[3]
124
+ end
125
+ end
126
+
127
+ module MultinomialWithGarbage3
128
+ def value
129
+ a.value + " " + b.value
130
+ end
131
+
132
+ def canonical
133
+ a.canonical + " " + b.canonical
134
+ end
135
+
136
+ def pos
137
+ a.pos.merge(b.pos)
138
+ end
139
+
140
+ def details
141
+ a.details.merge(b.details)
142
+ end
143
+ end
144
+
145
+ module MultinomialWithGarbage4
146
+ def a
147
+ elements[0]
148
+ end
149
+
150
+ def space
151
+ elements[1]
152
+ end
153
+
154
+ def b
155
+ elements[2]
156
+ end
157
+
158
+ def garbage
159
+ elements[3]
160
+ end
161
+ end
162
+
163
+ module MultinomialWithGarbage5
164
+ def value
165
+ a.value + " " + b.value
166
+ end
167
+
168
+ def canonical
169
+ a.canonical + " " + b.canonical
170
+ end
171
+
172
+ def pos
173
+ a.pos.merge(b.pos)
174
+ end
175
+
176
+ def details
177
+ a.details.merge(b.details)
178
+ end
179
+ end
180
+
181
+ def _nt_multinomial_with_garbage
182
+ start_index = index
183
+ if node_cache[:multinomial_with_garbage].has_key?(index)
184
+ cached = node_cache[:multinomial_with_garbage][index]
185
+ if cached
186
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
187
+ @index = cached.interval.end
188
+ end
189
+ return cached
190
+ end
191
+
192
+ i0 = index
193
+ i1, s1 = index, []
194
+ r2 = _nt_genus
195
+ s1 << r2
196
+ if r2
197
+ r3 = _nt_space
198
+ s1 << r3
199
+ if r3
200
+ r4 = _nt_infragenus
201
+ s1 << r4
202
+ if r4
203
+ r5 = _nt_space
204
+ s1 << r5
205
+ if r5
206
+ r6 = _nt_species
207
+ s1 << r6
208
+ if r6
209
+ r7 = _nt_garbage
210
+ s1 << r7
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
216
+ if s1.last
217
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
218
+ r1.extend(MultinomialWithGarbage0)
219
+ r1.extend(MultinomialWithGarbage1)
220
+ else
221
+ @index = i1
222
+ r1 = nil
223
+ end
224
+ if r1
225
+ r0 = r1
226
+ else
227
+ i8, s8 = index, []
228
+ r9 = _nt_genus
229
+ s8 << r9
230
+ if r9
231
+ r10 = _nt_space
232
+ s8 << r10
233
+ if r10
234
+ r11 = _nt_infragenus
235
+ s8 << r11
236
+ if r11
237
+ r12 = _nt_garbage
238
+ s8 << r12
239
+ end
240
+ end
241
+ end
242
+ if s8.last
243
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
244
+ r8.extend(MultinomialWithGarbage2)
245
+ r8.extend(MultinomialWithGarbage3)
246
+ else
247
+ @index = i8
248
+ r8 = nil
249
+ end
250
+ if r8
251
+ r0 = r8
252
+ else
253
+ i13, s13 = index, []
254
+ r14 = _nt_genus
255
+ s13 << r14
256
+ if r14
257
+ r15 = _nt_space
258
+ s13 << r15
259
+ if r15
260
+ r16 = _nt_species
261
+ s13 << r16
262
+ if r16
263
+ r17 = _nt_garbage
264
+ s13 << r17
265
+ end
266
+ end
267
+ end
268
+ if s13.last
269
+ r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
270
+ r13.extend(MultinomialWithGarbage4)
271
+ r13.extend(MultinomialWithGarbage5)
272
+ else
273
+ @index = i13
274
+ r13 = nil
275
+ end
276
+ if r13
277
+ r0 = r13
278
+ else
279
+ @index = i0
280
+ r0 = nil
281
+ end
282
+ end
283
+ end
284
+
285
+ node_cache[:multinomial_with_garbage][start_index] = r0
286
+
287
+ r0
288
+ end
289
+
290
+ module UninomialWithGarbage0
291
+ def a
292
+ elements[0]
293
+ end
294
+
295
+ def b
296
+ elements[1]
297
+ end
298
+ end
299
+
300
+ module UninomialWithGarbage1
301
+ def value
302
+ a.value
303
+ end
304
+
305
+ def canonical
306
+ a.canonical
307
+ end
308
+
309
+ def pos
310
+ a.pos
311
+ end
312
+
313
+ def details
314
+ {:uninomial => a.details[:uninomial]}
315
+ end
316
+ end
317
+
318
+ def _nt_uninomial_with_garbage
319
+ start_index = index
320
+ if node_cache[:uninomial_with_garbage].has_key?(index)
321
+ cached = node_cache[:uninomial_with_garbage][index]
322
+ if cached
323
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
324
+ @index = cached.interval.end
325
+ end
326
+ return cached
327
+ end
328
+
329
+ i0, s0 = index, []
330
+ r1 = _nt_uninomial_string
331
+ s0 << r1
332
+ if r1
333
+ r2 = _nt_garbage
334
+ s0 << r2
335
+ end
336
+ if s0.last
337
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
338
+ r0.extend(UninomialWithGarbage0)
339
+ r0.extend(UninomialWithGarbage1)
340
+ else
341
+ @index = i0
342
+ r0 = nil
343
+ end
344
+
345
+ node_cache[:uninomial_with_garbage][start_index] = r0
346
+
347
+ r0
348
+ end
349
+
350
+ module Garbage0
351
+ def space1
352
+ elements[0]
353
+ end
354
+
355
+ def space2
356
+ elements[2]
357
+ end
358
+
359
+ end
360
+
361
+ module Garbage1
362
+ def space_hard
363
+ elements[0]
364
+ end
365
+
366
+ end
367
+
368
+ def _nt_garbage
369
+ start_index = index
370
+ if node_cache[:garbage].has_key?(index)
371
+ cached = node_cache[:garbage][index]
372
+ if cached
373
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
374
+ @index = cached.interval.end
375
+ end
376
+ return cached
377
+ end
378
+
379
+ i0 = index
380
+ i1, s1 = index, []
381
+ r2 = _nt_space
382
+ s1 << r2
383
+ if r2
384
+ if has_terminal?('\G["\',.]', true, index)
385
+ r3 = true
386
+ @index += 1
387
+ else
388
+ r3 = nil
389
+ end
390
+ s1 << r3
391
+ if r3
392
+ r4 = _nt_space
393
+ s1 << r4
394
+ if r4
395
+ s5, i5 = [], index
396
+ loop do
397
+ if has_terminal?('\G[^щ]', true, index)
398
+ r6 = true
399
+ @index += 1
400
+ else
401
+ r6 = nil
402
+ end
403
+ if r6
404
+ s5 << r6
405
+ else
406
+ break
407
+ end
408
+ end
409
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
410
+ s1 << r5
411
+ end
412
+ end
413
+ end
414
+ if s1.last
415
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
416
+ r1.extend(Garbage0)
417
+ else
418
+ @index = i1
419
+ r1 = nil
420
+ end
421
+ if r1
422
+ r0 = r1
423
+ else
424
+ i7, s7 = index, []
425
+ r8 = _nt_space_hard
426
+ s7 << r8
427
+ if r8
428
+ s9, i9 = [], index
429
+ loop do
430
+ if has_terminal?('\G[^ш]', true, index)
431
+ r10 = true
432
+ @index += 1
433
+ else
434
+ r10 = nil
435
+ end
436
+ if r10
437
+ s9 << r10
438
+ else
439
+ break
440
+ end
441
+ end
442
+ if s9.empty?
443
+ @index = i9
444
+ r9 = nil
445
+ else
446
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
447
+ end
448
+ s7 << r9
449
+ end
450
+ if s7.last
451
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
452
+ r7.extend(Garbage1)
453
+ else
454
+ @index = i7
455
+ r7 = nil
456
+ end
457
+ if r7
458
+ r0 = r7
459
+ else
460
+ @index = i0
461
+ r0 = nil
462
+ end
463
+ end
464
+
465
+ node_cache[:garbage][start_index] = r0
466
+
467
+ r0
468
+ end
469
+
470
+ end
471
+
472
+ class ScientificNameCanonicalParser < Treetop::Runtime::CompiledParser
473
+ include ScientificNameCanonical
474
+ end
475
+
@@ -0,0 +1,111 @@
1
+ # encoding: UTF-8
2
+ grammar ScientificNameCanonical
3
+ include ScientificNameClean
4
+ include ScientificNameDirty
5
+
6
+ rule root
7
+ multinomial_with_garbage {
8
+ def hybrid
9
+ false
10
+ end
11
+
12
+ def details
13
+ [super]
14
+ end
15
+ }
16
+ /
17
+ uninomial_with_garbage {
18
+ def hybrid
19
+ false
20
+ end
21
+
22
+ def details
23
+ [super]
24
+ end
25
+ }
26
+ end
27
+
28
+ rule multinomial_with_garbage
29
+
30
+ a:genus space b:infragenus space c:species garbage {
31
+ def value
32
+ a.value + " " + b.value + " " + c.value
33
+ end
34
+
35
+ def canonical
36
+ a.canonical + " " + b.canonical + " " + c.canonical
37
+ end
38
+
39
+ def pos
40
+ a.pos.merge(b.pos).merge(c.pos)
41
+ end
42
+
43
+ def details
44
+ a.details.merge(b.details).merge(c.details)
45
+ end
46
+ }
47
+ /
48
+ a:genus space b:infragenus garbage {
49
+ def value
50
+ a.value + " " + b.value
51
+ end
52
+
53
+ def canonical
54
+ a.canonical + " " + b.canonical
55
+ end
56
+
57
+ def pos
58
+ a.pos.merge(b.pos)
59
+ end
60
+
61
+ def details
62
+ a.details.merge(b.details)
63
+ end
64
+ }
65
+ /
66
+ a:genus space b:species garbage {
67
+ def value
68
+ a.value + " " + b.value
69
+ end
70
+
71
+ def canonical
72
+ a.canonical + " " + b.canonical
73
+ end
74
+
75
+ def pos
76
+ a.pos.merge(b.pos)
77
+ end
78
+
79
+ def details
80
+ a.details.merge(b.details)
81
+ end
82
+ }
83
+ end
84
+
85
+ rule uninomial_with_garbage
86
+ a:uninomial_string b:garbage {
87
+ def value
88
+ a.value
89
+ end
90
+
91
+ def canonical
92
+ a.canonical
93
+ end
94
+
95
+ def pos
96
+ a.pos
97
+ end
98
+
99
+ def details
100
+ {:uninomial => a.details[:uninomial]}
101
+ end
102
+ }
103
+ end
104
+
105
+ rule garbage
106
+ space (["',.]) space [^щ]*
107
+ /
108
+ space_hard [^ш]+
109
+ end
110
+
111
+ end