Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gem is building

  • Loading branch information...
commit e9ce4432c0b48fff586658f498776b9bdc64e9a8 1 parent bd89354
Dmitry Mozzherin dimus authored
2  biodiversity.gemspec
View
@@ -1,4 +1,4 @@
-$:.push File.expand_path("..lib", __FILE__)
+$:.push File.expand_path("../lib", __FILE__)
require 'biodiversity/version'
10 lib/biodiversity.rb
View
@@ -1,11 +1,7 @@
-require 'rubygems'
require 'treetop'
-
-module Biodiversity
- VERSION = '3.1.2'
- LSID_RESOLVER_URL = 'http://lsid.tdwg.org/'
-end
-
+require 'json'
+require 'open-uri'
+require_relative 'biodiversity/version'
require_relative 'biodiversity/parser'
require_relative 'biodiversity/guid'
3  lib/biodiversity/guid.rb
View
@@ -1,2 +1 @@
-dir = File.dirname(__FILE__)
-require File.join(dir, *%w[guid lsid])
+require_relative 'guid/lsid'
2  lib/biodiversity/guid/lsid.rb
View
@@ -1,5 +1,3 @@
-require 'open-uri'
-
class LsidResolver
def self.resolve(lsid)
http_get_rdf(lsid)
9 lib/biodiversity/parser.rb
View
@@ -1,10 +1,7 @@
# encoding: UTF-8
-dir = File.dirname(__FILE__)
-require File.join(dir, *%w[parser scientific_name_clean])
-require File.join(dir, *%w[parser scientific_name_dirty])
-require File.join(dir, *%w[parser scientific_name_canonical])
-require 'rubygems'
-require 'json'
+require_relative 'parser/scientific_name_clean'
+require_relative 'parser/scientific_name_dirty'
+require_relative 'parser/scientific_name_canonical'
module PreProcessor
NOTES = /\s+(species\s+group|species\s+complex|group|author)\b.*$/i
7 lib/biodiversity/version.rb
View
@@ -1,4 +1,9 @@
module Biodiversity
VERSION = '3.1.2'
- LSID_RESOLVER_URL = "http://lsid.tdwg.org/"
+ LSID_RESOLVER_URL = 'http://lsid.tdwg.org/'
+
+ def self.version
+ VERSION
+ end
+
end
0  pkg/.gitignore → pkg/.gitkeep
View
File renamed without changes
9 spec/biodiversity_spec.rb
View
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Biodiversity do
+ it 'should have version' do
+ version = Biodiversity::VERSION
+ version.should =~ /^\d+\.\d+\.\d+/
+ version.should == Biodiversity.version
+ end
+end
1  spec/guid/lsid.spec.rb
View
@@ -1,4 +1,3 @@
-dir = File.dirname(__FILE__)
require_relative '../spec_helper'
describe LsidResolver do
29 spec/parser/scientific_name.spec.rb
View
@@ -1,4 +1,5 @@
# encoding: utf-8
+
#NOTE: this spec needs compiled treetop files.
require_relative '../spec_helper'
@@ -13,10 +14,10 @@
it 'should ScientificNameParser::fix_case' do
names = [
- ["QUERCUS ALBA", "Quercus alba"],
- ["QUERCUS (QUERCUS) ALBA", "Quercus (Quercus) alba"],
- ["QÜERCUS", "Qüercus"],
- ["PARDOSA MOéSTA", "Pardosa moésta"],
+ ['QUERCUS ALBA', 'Quercus alba'],
+ ['QUERCUS (QUERCUS) ALBA', 'Quercus (Quercus) alba'],
+ ['QÜERCUS', 'Qüercus'],
+ ['PARDOSA MOéSTA', 'Pardosa moésta'],
]
names.each do |name, capitalization|
ScientificNameParser::fix_case(name).should == capitalization
@@ -32,7 +33,7 @@
# it 'should generate new test_file' do
# new_test = open(File.expand_path(dir +
- # "../../spec/parser/test_data_new.txt"),'w')
+ # '../../spec/parser/test_data_new.txt'),'w')
# read_test_file do |y|
# if y[:comment]
# new_test.write y[:comment]
@@ -50,20 +51,20 @@
'"parser_version":"test_version","verbatim":"ddd sljlkj 3223452432"}}'
end
- it "should show version when the flag :show_version set to true" do
+ it 'should show version when the flag :show_version set to true' do
parse('Homo sapiens')[:scientificName][:parser_version].should_not be_nil
end
- it "should show version for not spelled names" do
+ it 'should show version for not spelled names' do
parse('not_a_name')[:scientificName][:parser_version].should_not be_nil
end
- it "should generate version for viruses" do
+ it 'should generate version for viruses' do
parse('Nile virus')[:scientificName][:parser_version].should_not be_nil
end
end
-describe "ScientificNameParser with ranked canonicals" do
+describe 'ScientificNameParser with ranked canonicals' do
before(:all) do
@parser = ScientificNameParser.new(canonical_with_rank: true)
end
@@ -99,12 +100,12 @@
end
describe ParallelParser do
- it "should find number of cpus" do
+ it 'should find number of cpus' do
pparser = ParallelParser.new
pparser.cpu_num.should > 0
end
- it "should parse several names in parallel" do
+ it 'should parse several names in parallel' do
names = []
read_test_file { |n| names << (n[:name]) if n[:name] }
names.uniq!
@@ -114,7 +115,7 @@
res.keys.size.should == names.size
end
- it "should parse several names in parallel with given num of processes" do
+ it 'should parse several names in parallel with given num of processes' do
names = []
read_test_file { |n| names << (n[:name]) if n[:name] }
names.uniq!
@@ -124,8 +125,8 @@
res.keys.size.should == names.size
end
- it "should have parsed name in native ruby format and in returned as \
- a hash with name as a key and parsed data as value" do
+ it 'should have parsed name in native ruby format and in returned as \
+ a hash with name as a key and parsed data as value' do
names = []
read_test_file { |n| names << (n[:name]) if n[:name] }
names.uniq!
22 spec/parser/scientific_name_canonical.spec.rb
View
@@ -8,11 +8,23 @@
it 'should parse names with valid name part and unparseable rest' do
[
- ['Morea ssjjlajajaj324$33 234243242','Morea', [{:uninomial=>{:string=>"Morea"}}], {0=>["uninomial", 5]}],
- ['Morea (Morea) Burt 2342343242 23424322342 23424234', 'Morea (Morea)', [{:genus=>{:string=>"Morea"}, :infragenus=>{:string=>"Morea"}}], {0=>["genus", 5], 7=>["infragenus", 12]}],
- ['Morea (Morea) burtius 2342343242 23424322342 23424234', 'Morea (Morea) burtius', [{:genus=>{:string=>"Morea"}, :infragenus=>{:string=>"Morea"}, :species=>{:string=>"burtius"}}], {0=>["genus", 5], 7=>["infragenus", 12], 14=>["species", 21]}],
- ['Moraea spathulata ( (L. f. Klatt','Moraea spathulata',[{:genus=>{:string=>"Moraea"}, :species=>{:string=>"spathulata"}}], {0=>["genus", 6], 7=>["species", 17]} ],
- ['Verpericola megasoma ""Dall" Pils.','Verpericola megasoma',[{:genus=>{:string=>"Verpericola"}, :species=>{:string=>"megasoma"}}], {0=>["genus", 11], 12=>["species", 20]}]
+ ['Morea ssjjlajajaj324$33 234243242','Morea',
+ [{:uninomial=>{:string=>"Morea"}}], {0=>["uninomial", 5]}],
+ ['Morea (Morea) Burt 2342343242 23424322342 23424234',
+ 'Morea (Morea)', [{:genus=>{:string=>"Morea"},
+ :infragenus=>{:string=>"Morea"}}],
+ {0=>["genus", 5], 7=>["infragenus", 12]}],
+ ['Morea (Morea) burtius 2342343242 23424322342 23424234',
+ 'Morea (Morea) burtius', [{:genus=>{:string=>"Morea"},
+ :infragenus=>{:string=>"Morea"},
+ :species=>{:string=>"burtius"}}],
+ {0=>["genus", 5], 7=>["infragenus", 12], 14=>["species", 21]}],
+ ['Moraea spathulata ( (L. f. Klatt','Moraea spathulata',
+ [{:genus=>{:string=>"Moraea"}, :species=>{:string=>"spathulata"}}],
+ {0=>["genus", 6], 7=>["species", 17]} ],
+ ['Verpericola megasoma ""Dall" Pils.','Verpericola megasoma',
+ [{:genus=>{:string=>"Verpericola"}, :species=>{:string=>"megasoma"}}],
+ {0=>["genus", 11], 12=>["species", 20]}]
].each do |n|
parse(n[0]).should_not be_nil
value(n[0]).should == n[1]
45 spec/parser/scientific_name_clean.spec.rb
View
@@ -19,19 +19,36 @@
it 'should parse uninomial with author and year' do
sn = 'Pseudocercospora Speg.'
parse(sn).should_not be_nil
- details(sn).should == [{:uninomial=>{:string=>"Pseudocercospora", :authorship=>"Speg.", :basionymAuthorTeam=>{:authorTeam=>"Speg.", :author=>["Speg."]}}}]
+ details(sn).should == [{:uninomial=>
+ {:string=>"Pseudocercospora",
+ :authorship=>"Speg.",
+ :basionymAuthorTeam=>
+ {:authorTeam=>"Speg.", :author=>["Speg."]}}}]
pos(sn).should == {0=>["uninomial", 16], 17=>["author_word", 22]}
sn = 'Pseudocercospora Spegazzini, 1910'
parse(sn).should_not be_nil
value(sn).should == 'Pseudocercospora Spegazzini 1910'
- details(sn).should == [{:uninomial=>{:string=>"Pseudocercospora", :authorship=>"Spegazzini, 1910", :basionymAuthorTeam=>{:authorTeam=>"Spegazzini", :author=>["Spegazzini"], :year=>"1910"}}}]
- pos(sn).should == {0=>["uninomial", 16], 17=>["author_word", 27], 29=>["year", 33]}
+ details(sn).should == [{:uninomial=>
+ {:string=>"Pseudocercospora",
+ :authorship=>"Spegazzini, 1910",
+ :basionymAuthorTeam=>
+ {:authorTeam=>"Spegazzini",
+ :author=>["Spegazzini"], :year=>"1910"}}}]
+ pos(sn).should == {0=>["uninomial", 16],
+ 17=>["author_word", 27], 29=>["year", 33]}
end
it "should parse uninomials with uninomial ranks" do
sn = "Epacridaceae trib. Archerieae Crayn & Quinn"
parse(sn).should_not be_nil
- details(sn).should == [{:uninomial=>{:string=>"Epacridaceae"}, :rank_uninomials=>"trib.", :uninomial2=>{:string=>"Archerieae", :authorship=>"Crayn & Quinn", :basionymAuthorTeam=>{:authorTeam=>"Crayn & Quinn", :author=>["Crayn", "Quinn"]}}}]
+ details(sn).should == [{:uninomial=>
+ {:string=>"Epacridaceae"},
+ :rank_uninomials=>"trib.",
+ :uninomial2=>{:string=>"Archerieae",
+ :authorship=>"Crayn & Quinn",
+ :basionymAuthorTeam=>
+ {:authorTeam=>"Crayn & Quinn",
+ :author=>["Crayn", "Quinn"]}}}]
end
it 'should parse names with a valid 2 letter genus' do
@@ -64,7 +81,9 @@
parse(sn).should_not be_nil
value(sn).should == 'Pseudocercospora dendrobii'
canonical(sn).should == 'Pseudocercospora dendrobii'
- details(sn).should == [{:genus=>{:string=>"Pseudocercospora"}, :species=>{:string=>"dendrobii"}}]
+ details(sn).should == [{:genus=>
+ {:string=>"Pseudocercospora"},
+ :species=>{:string=>"dendrobii"}}]
pos(sn).should == {0=>["genus", 16], 21=>["species", 30]}
end
@@ -75,7 +94,9 @@
sn = 'Ps. dendrobii'
parse(sn).should_not be_nil
value(sn).should == 'Ps. dendrobii'
- details(sn).should == [{:genus=>{:string=>"Ps."}, :species=>{:string=>"dendrobii"}}]
+ details(sn).should == [{:genus=>
+ {:string=>"Ps."},
+ :species=>{:string=>"dendrobii"}}]
end
@@ -86,8 +107,16 @@
sn = "Platypus bicaudatulus Schedl, 1935h"
parse(sn).should_not be_nil
value(sn).should == "Platypus bicaudatulus Schedl 1935"
- details(sn).should == [{:genus=>{:string=>"Platypus"}, :species=>{:string=>"bicaudatulus", :authorship=>"Schedl, 1935h", :basionymAuthorTeam=>{:authorTeam=>"Schedl", :author=>["Schedl"], :year=>"1935"}}}]
- pos(sn).should == {0=>["genus", 8], 9=>["species", 21], 22=>["author_word", 28], 30=>["year", 35]}
+ details(sn).should == [{:genus=>
+ {:string=>"Platypus"},
+ :species=>{:string=>"bicaudatulus",
+ :authorship=>"Schedl, 1935h",
+ :basionymAuthorTeam=>
+ {:authorTeam=>"Schedl", :author=>["Schedl"],
+ :year=>"1935"}}}]
+ pos(sn).should == {0=>["genus", 8],
+ 9=>["species", 21], 22=>["author_word", 28],
+ 30=>["year", 35]}
parse("Platypus bicaudatulus Schedl, 1935B").should_not be_nil
sn = "Platypus bicaudatulus Schedl (1935h)"
parse(sn).should_not be_nil
10 spec/spec_helper.rb
View
@@ -16,7 +16,7 @@
Treetop.load(File.expand_path(File.join(dir,
'../lib/biodiversity/parser/scientific_name_canonical')))
-PARSER_TEST_VERSION = "test_version"
+PARSER_TEST_VERSION = 'test_version'
def set_parser(parser)
@parser = parser
@@ -50,7 +50,7 @@ def json(input)
def debug(input)
res = parse(input)
- puts "<pre>"
+ puts '<pre>'
if res
puts 'success!'
puts res.inspect
@@ -58,17 +58,17 @@ def debug(input)
puts input
val = @parser.failure_reason.to_s.match(/column [0-9]*/).
to_s.gsub(/column /,'').to_i
- print ("-" * (val - 1))
+ print ('-' * (val - 1))
print "^ Computer says 'no'!\n"
puts @parser.failure_reason
puts @parser.to_yaml
end
- puts "</pre>"
+ puts '</pre>'
end
def read_test_file
f = open(File.expand_path(File.join(File.dirname(__FILE__),
- "parser/test_data.txt")))
+ 'parser/test_data.txt')))
f.each do |line|
name, jsn = line.split("|")
if line.match(/^\s*#/) == nil && name && jsn
Please sign in to comment.
Something went wrong with that request. Please try again.