dimus-biodiversity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.rdoc +0 -0
- data/Rakefile +24 -0
- data/bin/nnparse +28 -0
- data/lib/biodiversity.rb +9 -0
- data/lib/biodiversity/parser.rb +2 -0
- data/lib/biodiversity/parser/scientific_name.rb +3403 -0
- data/lib/biodiversity/parser/scientific_name.treetop +507 -0
- data/spec/parser/scientific_name.spec.rb +244 -0
- metadata +76 -0
@@ -0,0 +1,507 @@
|
|
1
|
+
grammar ScientificName
|
2
|
+
|
3
|
+
rule composite_scientific_name
|
4
|
+
a:scientific_name space hybrid_separator space b:scientific_name space {
|
5
|
+
def value
|
6
|
+
a.value + " × " + b.value
|
7
|
+
end
|
8
|
+
def canonical
|
9
|
+
a.canonical + " × " + b.canonical
|
10
|
+
end
|
11
|
+
def details
|
12
|
+
{:hybrid => {:scientific_name1 => a.details, :scientific_name2 => b.details}}
|
13
|
+
end
|
14
|
+
}
|
15
|
+
/
|
16
|
+
a:scientific_name space hybrid_separator space [\?]? {
|
17
|
+
def value
|
18
|
+
a.value + " × ?"
|
19
|
+
end
|
20
|
+
|
21
|
+
def canonical
|
22
|
+
a.canonical
|
23
|
+
end
|
24
|
+
|
25
|
+
def details
|
26
|
+
{:hybrid => {:scientific_name1 => a.details, :scientific_name2 => "?"}}
|
27
|
+
end
|
28
|
+
}
|
29
|
+
/
|
30
|
+
scientific_name
|
31
|
+
end
|
32
|
+
|
33
|
+
rule scientific_name
|
34
|
+
space a:name_part space b:authors_part space c:status_part space {
|
35
|
+
def value
|
36
|
+
a.value + " " + b.value + " " + c.value
|
37
|
+
end
|
38
|
+
def canonical
|
39
|
+
a.canonical
|
40
|
+
end
|
41
|
+
def details
|
42
|
+
a.details.merge(b.details).merge(c.details)
|
43
|
+
end
|
44
|
+
}
|
45
|
+
/
|
46
|
+
space a:name_part space b:authors_part space {
|
47
|
+
def value
|
48
|
+
a.value + " " + b.value
|
49
|
+
end
|
50
|
+
def canonical
|
51
|
+
a.canonical
|
52
|
+
end
|
53
|
+
def details
|
54
|
+
a.details.merge(b.details)
|
55
|
+
end
|
56
|
+
}
|
57
|
+
/
|
58
|
+
space a:name_part space b:year space {
|
59
|
+
def value
|
60
|
+
a.value + " " + b.value
|
61
|
+
end
|
62
|
+
|
63
|
+
def canonical
|
64
|
+
a.canonical
|
65
|
+
end
|
66
|
+
|
67
|
+
def details
|
68
|
+
a.details.merge(b.details).merge({:is_valid => false})
|
69
|
+
end
|
70
|
+
}
|
71
|
+
/
|
72
|
+
name_part
|
73
|
+
end
|
74
|
+
|
75
|
+
rule status_part
|
76
|
+
a:status_word space b:status_part {
|
77
|
+
def value
|
78
|
+
a.value + " " + b.value
|
79
|
+
end
|
80
|
+
def details
|
81
|
+
{:status => value}
|
82
|
+
end
|
83
|
+
}
|
84
|
+
/
|
85
|
+
status_word
|
86
|
+
end
|
87
|
+
|
88
|
+
rule status_word
|
89
|
+
latin_word [\.] {
|
90
|
+
def value
|
91
|
+
text_value.strip
|
92
|
+
end
|
93
|
+
def details
|
94
|
+
{:status => value}
|
95
|
+
end
|
96
|
+
}
|
97
|
+
/
|
98
|
+
latin_word
|
99
|
+
end
|
100
|
+
|
101
|
+
rule authors_part
|
102
|
+
a:original_authors_revised_name space b:authors_revised_name {
|
103
|
+
def value
|
104
|
+
a.value + " " + b.value
|
105
|
+
end
|
106
|
+
|
107
|
+
def details
|
108
|
+
a.details.merge(b.details)
|
109
|
+
end
|
110
|
+
}
|
111
|
+
/
|
112
|
+
a:simple_authors_part space "ex" space b:simple_authors_part {
|
113
|
+
def value
|
114
|
+
a.value + " ex " + b.value
|
115
|
+
end
|
116
|
+
|
117
|
+
def details
|
118
|
+
{:revised_name_authors => {:revised_authors => a.details[:authors], :authors => b.details[:authors]}}
|
119
|
+
end
|
120
|
+
}
|
121
|
+
/
|
122
|
+
a:original_authors_revised_name space b:authors_names_full {
|
123
|
+
def value
|
124
|
+
a.value + " " + b.value
|
125
|
+
end
|
126
|
+
def details
|
127
|
+
a.details.merge(b.details)
|
128
|
+
end
|
129
|
+
}
|
130
|
+
/
|
131
|
+
authors_revised_name
|
132
|
+
/
|
133
|
+
original_authors_revised_name
|
134
|
+
/
|
135
|
+
simple_authors_part
|
136
|
+
end
|
137
|
+
|
138
|
+
rule simple_authors_part
|
139
|
+
a:original_authors_names_full space b:authors_names_full {
|
140
|
+
def value
|
141
|
+
a.value + " " + b.value
|
142
|
+
end
|
143
|
+
def details
|
144
|
+
a.details.merge(b.details)
|
145
|
+
end
|
146
|
+
}
|
147
|
+
/
|
148
|
+
original_authors_names_full
|
149
|
+
/
|
150
|
+
authors_names_full
|
151
|
+
end
|
152
|
+
|
153
|
+
rule original_authors_names_full
|
154
|
+
"(" space a:authors_names_full space ")" {
|
155
|
+
def value
|
156
|
+
"(" + a.value + ")"
|
157
|
+
end
|
158
|
+
def details
|
159
|
+
{:orig_authors => a.details[:authors]}
|
160
|
+
end
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
rule original_authors_revised_name
|
165
|
+
"(" space a:authors_revised_name space ")" {
|
166
|
+
def value
|
167
|
+
"(" + a.value + ")"
|
168
|
+
end
|
169
|
+
|
170
|
+
def details
|
171
|
+
{:original_revised_name_authors => a.details[:revised_name_authors]}
|
172
|
+
end
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
176
|
+
rule authors_revised_name
|
177
|
+
a:authors_names_full space "ex" space b:authors_names_full {
|
178
|
+
def value
|
179
|
+
a.value + " ex " + b.value
|
180
|
+
end
|
181
|
+
def details
|
182
|
+
{:revised_name_authors =>{:revised_authors => a.details[:authors], :authors => b.details[:authors]}}
|
183
|
+
end
|
184
|
+
}
|
185
|
+
end
|
186
|
+
|
187
|
+
rule authors_names_full
|
188
|
+
a:authors_names space [,]? space b:year {
|
189
|
+
def value
|
190
|
+
a.value + " " + b.value
|
191
|
+
end
|
192
|
+
def details
|
193
|
+
{:authors => {:names => a.details[:authors][:names]}.merge(b.details)}
|
194
|
+
end
|
195
|
+
}
|
196
|
+
/
|
197
|
+
authors_names
|
198
|
+
end
|
199
|
+
|
200
|
+
rule authors_names
|
201
|
+
a:author_name space sep:author_name_separator space b:authors_names {
|
202
|
+
def value
|
203
|
+
sep.apply(a,b)
|
204
|
+
end
|
205
|
+
|
206
|
+
def details
|
207
|
+
sep.details(a,b)
|
208
|
+
end
|
209
|
+
}
|
210
|
+
/
|
211
|
+
author_name
|
212
|
+
end
|
213
|
+
|
214
|
+
rule author_name_separator
|
215
|
+
("&"/",") {
|
216
|
+
def apply(a,b)
|
217
|
+
a.value + " " + text_value + " " + b.value
|
218
|
+
end
|
219
|
+
|
220
|
+
def details(a,b)
|
221
|
+
{:authors => {:names => a.details[:authors][:names] + b.details[:authors][:names]}}
|
222
|
+
end
|
223
|
+
}
|
224
|
+
end
|
225
|
+
|
226
|
+
rule author_name
|
227
|
+
space a:author_word space b:author_name space {
|
228
|
+
def value
|
229
|
+
a.value + " " + b.value
|
230
|
+
end
|
231
|
+
|
232
|
+
def details
|
233
|
+
{:authors => {:names => [value]}}
|
234
|
+
end
|
235
|
+
}
|
236
|
+
/
|
237
|
+
author_word
|
238
|
+
end
|
239
|
+
|
240
|
+
rule author_word
|
241
|
+
"A S. Xu"
|
242
|
+
/
|
243
|
+
("anon."/"f."/"bis"/"arg."/"da"/"der"/"den"/"de"/"du"/"la"/"ter"/"van"/"et al.\{\?\}"/"et al.") {
|
244
|
+
def value
|
245
|
+
text_value.strip
|
246
|
+
end
|
247
|
+
def details
|
248
|
+
{:authors => {:names => [value]}}
|
249
|
+
end
|
250
|
+
}
|
251
|
+
/
|
252
|
+
("Å"/"Ö"/"Á"/"Ø"/"Ô"/"Š"/"Ś"/"Č"/"Ķ"/"Ł"/"É"/"Ž"/[A-Z]) [^0-9()\s&,]+ {
|
253
|
+
def value
|
254
|
+
text_value.gsub(/\s+/, " ").strip
|
255
|
+
end
|
256
|
+
def details
|
257
|
+
{:authors => {:names => [value]}}
|
258
|
+
end
|
259
|
+
}
|
260
|
+
end
|
261
|
+
|
262
|
+
rule name_part
|
263
|
+
space a:species_name space b:selector space_hard c:editorials_full {
|
264
|
+
def value
|
265
|
+
a.value + " " + b.value + " " + c.value
|
266
|
+
end
|
267
|
+
def canonical
|
268
|
+
a.canonical
|
269
|
+
end
|
270
|
+
def details
|
271
|
+
a.details.merge(b.details).merge(c.details)
|
272
|
+
end
|
273
|
+
}
|
274
|
+
/
|
275
|
+
space a:species_name space b:subspecies_names {
|
276
|
+
def value
|
277
|
+
a.value + b.value
|
278
|
+
end
|
279
|
+
def canonical
|
280
|
+
a.canonical + b.canonical
|
281
|
+
end
|
282
|
+
|
283
|
+
def details
|
284
|
+
a.details.merge(b.details)
|
285
|
+
end
|
286
|
+
}
|
287
|
+
/
|
288
|
+
space a:species_name space b:latin_word {
|
289
|
+
def value
|
290
|
+
a.value + " " + b.value
|
291
|
+
end
|
292
|
+
|
293
|
+
def canonical
|
294
|
+
value
|
295
|
+
end
|
296
|
+
|
297
|
+
def details
|
298
|
+
a.details.merge({:subspecies => {:type => "n/a", :value =>b.value}})
|
299
|
+
end
|
300
|
+
}
|
301
|
+
/
|
302
|
+
species_name
|
303
|
+
/
|
304
|
+
cap_latin_word
|
305
|
+
end
|
306
|
+
|
307
|
+
rule subspecies_names
|
308
|
+
a:subspecies_name space b:subspecies_names {
|
309
|
+
def value
|
310
|
+
a.value + b.value
|
311
|
+
end
|
312
|
+
|
313
|
+
def canonical
|
314
|
+
a.canonical + b.canonical
|
315
|
+
end
|
316
|
+
|
317
|
+
def details
|
318
|
+
c = a.details[:subspecies] + b.details_subspecies
|
319
|
+
a.details.merge({:subspecies => c, :is_valid => false})
|
320
|
+
end
|
321
|
+
}
|
322
|
+
/
|
323
|
+
subspecies_name
|
324
|
+
end
|
325
|
+
|
326
|
+
rule subspecies_name
|
327
|
+
sel:selector space_hard a:latin_word {
|
328
|
+
def value
|
329
|
+
sel.apply(a)
|
330
|
+
end
|
331
|
+
def canonical
|
332
|
+
sel.canonical(a)
|
333
|
+
end
|
334
|
+
def details
|
335
|
+
sel.details(a)
|
336
|
+
end
|
337
|
+
def details_subspecies
|
338
|
+
details[:subspecies]
|
339
|
+
end
|
340
|
+
}
|
341
|
+
end
|
342
|
+
|
343
|
+
rule editorials_full
|
344
|
+
"(" space a:editorials space ")" {
|
345
|
+
def value
|
346
|
+
"(" + a.value + ")"
|
347
|
+
end
|
348
|
+
def details
|
349
|
+
{:editorial_markup => value, :is_valid => false}
|
350
|
+
end
|
351
|
+
}
|
352
|
+
end
|
353
|
+
|
354
|
+
rule editorials
|
355
|
+
space a:selector space [&]? space b:editorials {
|
356
|
+
def value
|
357
|
+
a.value + b.value
|
358
|
+
end
|
359
|
+
}
|
360
|
+
/
|
361
|
+
selector
|
362
|
+
end
|
363
|
+
|
364
|
+
rule selector
|
365
|
+
("f.sp."/"f."/"B"/"ssp."/"mut."/"pseudovar."/"sect."/"ser."/"var."/"subvar."/ "[var.]" /"subsp."/"subf."/"race"/"α"
|
366
|
+
/"ββ"/"β"/"γ"/"δ"/"ε"/"φ"/"θ"/"μ"/"a."/"b."/"c."/"d."/"e."/"g."/"k."/"****"/"**"/"*")
|
367
|
+
{
|
368
|
+
def value
|
369
|
+
text_value.strip
|
370
|
+
end
|
371
|
+
def apply(a)
|
372
|
+
" " + text_value + " " + a.value
|
373
|
+
end
|
374
|
+
def canonical(a)
|
375
|
+
" " + a.value
|
376
|
+
end
|
377
|
+
def details(a = nil)
|
378
|
+
{:subspecies => [{:type => text_value, :value => (a.value rescue nil)}]}
|
379
|
+
end
|
380
|
+
}
|
381
|
+
end
|
382
|
+
|
383
|
+
rule species_name
|
384
|
+
hybrid_separator space_hard a:cap_latin_word space_hard b:latin_word {
|
385
|
+
def value
|
386
|
+
"× " + a.value + " " + b.value
|
387
|
+
end
|
388
|
+
def canonical
|
389
|
+
a.value + " " + b.value
|
390
|
+
end
|
391
|
+
def details
|
392
|
+
{:genus => a.value, :species => b.value, :cross => 'before'}
|
393
|
+
end
|
394
|
+
}
|
395
|
+
/
|
396
|
+
hybrid_separator space_hard a:cap_latin_word {
|
397
|
+
def value
|
398
|
+
"× " + a.value
|
399
|
+
end
|
400
|
+
def canonical
|
401
|
+
a.value
|
402
|
+
end
|
403
|
+
def details
|
404
|
+
{:uninomial => a.value, :cross => 'before'}
|
405
|
+
end
|
406
|
+
}
|
407
|
+
/
|
408
|
+
a:cap_latin_word space_hard hybrid_separator space_hard b:latin_word {
|
409
|
+
def value
|
410
|
+
a.value + " × " + b.value
|
411
|
+
end
|
412
|
+
def canonical
|
413
|
+
a.value + " " + b.value
|
414
|
+
end
|
415
|
+
def details
|
416
|
+
{:genus => a.value, :species => b.value, :cross => 'inside'}
|
417
|
+
end
|
418
|
+
}
|
419
|
+
/
|
420
|
+
a:cap_latin_word space_hard b:subgenus space_hard c:latin_word {
|
421
|
+
def value
|
422
|
+
a.value + " " + b.value + " " + c.value
|
423
|
+
end
|
424
|
+
def canonical
|
425
|
+
a.value + " " + c.value
|
426
|
+
end
|
427
|
+
def details
|
428
|
+
{:genus => a.value, :subgenus => b.details, :species => c.value}
|
429
|
+
end
|
430
|
+
}
|
431
|
+
/
|
432
|
+
a:cap_latin_word space_hard b:latin_word {
|
433
|
+
def value
|
434
|
+
a.value + " " + b.value
|
435
|
+
end
|
436
|
+
def canonical
|
437
|
+
value
|
438
|
+
end
|
439
|
+
|
440
|
+
def details
|
441
|
+
{:genus => a.value, :species => b.value}
|
442
|
+
end
|
443
|
+
}
|
444
|
+
end
|
445
|
+
|
446
|
+
rule subgenus
|
447
|
+
"(" space a:cap_latin_word space ")" {
|
448
|
+
def value
|
449
|
+
"(" + a.value + ")"
|
450
|
+
end
|
451
|
+
def details
|
452
|
+
a.value
|
453
|
+
end
|
454
|
+
}
|
455
|
+
end
|
456
|
+
|
457
|
+
rule latin_word
|
458
|
+
[a-zë] [a-z\-ëüäöï]+ {
|
459
|
+
def value
|
460
|
+
text_value.strip
|
461
|
+
end
|
462
|
+
}
|
463
|
+
end
|
464
|
+
|
465
|
+
rule cap_latin_word
|
466
|
+
[A-Z] [a-zë] [a-z\-ëüäöï]+ {
|
467
|
+
def value
|
468
|
+
text_value.strip
|
469
|
+
end
|
470
|
+
|
471
|
+
def canonical
|
472
|
+
text_value.strip
|
473
|
+
end
|
474
|
+
|
475
|
+
def details
|
476
|
+
{:name_type => "Uninomial", :uninomial => value}
|
477
|
+
end
|
478
|
+
}
|
479
|
+
end
|
480
|
+
|
481
|
+
rule hybrid_separator
|
482
|
+
("x"/"X"/"×") {
|
483
|
+
def value
|
484
|
+
"x"
|
485
|
+
end
|
486
|
+
}
|
487
|
+
end
|
488
|
+
|
489
|
+
rule year
|
490
|
+
[0-9\?]+ {
|
491
|
+
def value
|
492
|
+
text_value.strip
|
493
|
+
end
|
494
|
+
def details
|
495
|
+
{:year => value}
|
496
|
+
end
|
497
|
+
}
|
498
|
+
end
|
499
|
+
|
500
|
+
rule space
|
501
|
+
[\s]*
|
502
|
+
end
|
503
|
+
|
504
|
+
rule space_hard
|
505
|
+
[\s]+
|
506
|
+
end
|
507
|
+
end
|