taxonifi 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +24 -7
- data/README.rdoc +5 -6
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/assessor/row_assessor.rb +25 -18
- data/lib/export/format/base.rb +96 -1
- data/lib/export/format/obo_nomenclature.rb +71 -0
- data/lib/export/format/prolog.rb +59 -0
- data/lib/export/format/species_file.rb +303 -193
- data/lib/lumper/clump.rb +112 -0
- data/lib/lumper/lumper.rb +71 -45
- data/lib/lumper/lumps/parent_child_name_collection.rb +79 -15
- data/lib/models/author_year.rb +1 -2
- data/lib/models/base.rb +56 -51
- data/lib/models/collection.rb +16 -1
- data/lib/models/name.rb +56 -15
- data/lib/models/name_collection.rb +70 -19
- data/lib/models/ref.rb +17 -0
- data/lib/models/ref_collection.rb +2 -1
- data/lib/models/shared_class_methods.rb +29 -0
- data/lib/models/species_name.rb +14 -12
- data/lib/splitter/parser.rb +1 -2
- data/lib/splitter/tokens.rb +1 -1
- data/lib/taxonifi.rb +12 -0
- data/lib/utils/array.rb +17 -0
- data/lib/utils/hash.rb +17 -0
- data/taxonifi.gemspec +116 -0
- data/test/file_fixtures/Fossil.csv +11 -0
- data/test/file_fixtures/Lygaeoidea.csv +1 -1
- data/test/file_fixtures/names.csv +1 -0
- data/test/helper.rb +14 -0
- data/test/test_export_prolog.rb +14 -0
- data/test/test_exporter.rb +23 -0
- data/test/test_lumper_clump.rb +75 -0
- data/test/test_lumper_names.rb +67 -9
- data/test/test_lumper_parent_child_name_collection.rb +47 -3
- data/test/test_lumper_refs.rb +22 -7
- data/test/test_obo_nomenclature.rb +14 -0
- data/test/test_parser.rb +4 -2
- data/test/test_splitter_tokens.rb +9 -0
- data/test/test_taxonifi_accessor.rb +21 -15
- data/test/test_taxonifi_base.rb +25 -0
- data/test/test_taxonifi_name.rb +41 -4
- data/test/test_taxonifi_name_collection.rb +54 -17
- data/test/test_taxonifi_species_name.rb +1 -1
- metadata +34 -5
@@ -190,7 +190,7 @@ Identifier,Parent,Child,Rank,Synonyms,Vernaculars,VernacularsLanguage,Descriptio
|
|
190
190
|
1333,1331,"Drymus crassus Van Duzee, 1910",species,,,,
|
191
191
|
1334,1331,"Drymus unus (Say, 1832)",species,,,,
|
192
192
|
1339,1335,"Antillocoris minutus (Bergroth, 1895)",species,,,,
|
193
|
-
1336,1335,"Antillocoris pallidus (Uhler, 1894)",species,"
|
193
|
+
1336,1335,"Antillocoris pallidus (Uhler, 1894)",species,"Lygaeus pallidus Uhler, 1894",,,
|
194
194
|
1338,1335,"Antillocoris discretus Barber, 1952",species,,,,
|
195
195
|
1340,1335,"Antillocoris pilosulus (Stål, 1874)",species,,,,
|
196
196
|
1342,1341,"Cligenes distinctus Distant, 1893",species,,,,
|
@@ -0,0 +1 @@
|
|
1
|
+
Phylum,Class,Order,Family,Subfamily,Tribe,Genus,Subgenus,Species,Author,Year
|
data/test/helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
3
|
require 'debugger'
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/taxonifi'))
|
4
5
|
|
5
6
|
begin
|
6
7
|
Bundler.setup(:default, :development)
|
@@ -13,6 +14,7 @@ end
|
|
13
14
|
require 'test/unit'
|
14
15
|
#require 'shoulda'
|
15
16
|
|
17
|
+
|
16
18
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
19
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
18
20
|
|
@@ -36,3 +38,15 @@ def generic_csv_with_names
|
|
36
38
|
@csv = CSV.parse(@csv_string, {headers: true})
|
37
39
|
end
|
38
40
|
|
41
|
+
def names
|
42
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'file_fixtures/names.csv'))
|
43
|
+
|
44
|
+
csv = CSV.read(file, {
|
45
|
+
headers: true,
|
46
|
+
col_sep: ",",
|
47
|
+
header_converters: :downcase
|
48
|
+
} )
|
49
|
+
nc = Taxonifi::Lumper.create_name_collection(:csv => csv, :initial_id => 1)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/export/export'))
|
3
|
+
|
4
|
+
class Test_ExportProlog < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_that_prolog_export_does_stuff
|
7
|
+
e = Taxonifi::Export::Prolog.new(:nc => names, :namespace => 'YYZ')
|
8
|
+
assert foo = e.export
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
|
data/test/test_exporter.rb
CHANGED
@@ -24,9 +24,32 @@ class Test_TaxonifiExports < Test::Unit::TestCase
|
|
24
24
|
} )
|
25
25
|
|
26
26
|
nc = Taxonifi::Lumper::Lumps::ParentChildNameCollection.name_collection(csv)
|
27
|
+
nc.generate_ref_collection(1)
|
28
|
+
|
27
29
|
e = Taxonifi::Export::SpeciesFile.new(:nc => nc, :authorized_user_id => 15)
|
28
30
|
assert foo = e.export
|
29
31
|
end
|
30
32
|
|
33
|
+
def test_little_file_linkages
|
34
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'file_fixtures/Fossil.csv'))
|
35
|
+
|
36
|
+
csv = CSV.read(file, {
|
37
|
+
headers: true,
|
38
|
+
col_sep: ",",
|
39
|
+
header_converters: :downcase
|
40
|
+
} )
|
41
|
+
|
42
|
+
nc = Taxonifi::Lumper.create_name_collection(:csv => csv, :initial_id => 1)
|
43
|
+
rc = Taxonifi::Lumper.create_ref_collection(:csv => csv)
|
44
|
+
rc.uniquify_authors(1)
|
45
|
+
nc.ref_collection = rc
|
46
|
+
|
47
|
+
assert_equal "Crickets (Grylloptera: Grylloidea) in Dominican amber.", nc.ref_collection.object_from_row(0).title
|
48
|
+
assert_equal "Crickets (Grylloptera: Grylloidea) in Dominican amber.", nc.ref_collection.object_from_row(nc.collection[43].related[:link_to_ref_from_row]).title
|
49
|
+
|
50
|
+
e = Taxonifi::Export::SpeciesFile.new(:nc => nc, :authorized_user_id => 11 )
|
51
|
+
e.export
|
52
|
+
end
|
53
|
+
|
31
54
|
end
|
32
55
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lumper/clump'))
|
3
|
+
|
4
|
+
# Builder construction
|
5
|
+
|
6
|
+
class Test_TaxonifiLumperClump < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@headers = ["family", "genus", "species", "author", "year"]
|
10
|
+
@csv_string = CSV.generate() do |csv|
|
11
|
+
csv << @headers
|
12
|
+
csv << ["Fooidae", "Foo", "bar", "Smith", "1854"]
|
13
|
+
end
|
14
|
+
|
15
|
+
@csv = CSV.parse(@csv_string, {headers: true})
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_new_clump_without_params_can_be_created
|
19
|
+
assert c = Taxonifi::Lumper::Clump.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_new_clump_with_default_csv_can_be_created
|
23
|
+
assert c = Taxonifi::Lumper::Clump.new(@csv)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_that_csv_can_be_added_to_clump_that_has_no_csv
|
27
|
+
c = Taxonifi::Lumper::Clump.new
|
28
|
+
assert c.add_csv(@csv)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_that_clump_with_csv_will_not_add_csv
|
32
|
+
c = Taxonifi::Lumper::Clump.new
|
33
|
+
c.add_csv(@csv)
|
34
|
+
assert !c.add_csv(@csv)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_that_clump_with_csv_can_detach_csv
|
38
|
+
c = Taxonifi::Lumper::Clump.new
|
39
|
+
c.add_csv(@csv)
|
40
|
+
assert c.remove_csv
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_that_clump_without_csv_can_not_detach_csv
|
44
|
+
c = Taxonifi::Lumper::Clump.new
|
45
|
+
assert !c.remove_csv
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_that_name_collection_can_be_derived_from_clump
|
49
|
+
c = Taxonifi::Lumper::Clump.new
|
50
|
+
c.add_csv(@csv)
|
51
|
+
assert c.get_from_csv(:collection => :name)
|
52
|
+
assert_equal ['collection0'], c.collections.keys
|
53
|
+
assert_equal Taxonifi::Model::NameCollection, c.collections['collection0'].class
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_that_ref_collection_can_be_derived_from_clump
|
57
|
+
c = Taxonifi::Lumper::Clump.new
|
58
|
+
c.add_csv(@csv)
|
59
|
+
assert c.get_from_csv(:collection => :ref, :name => 'my_collection')
|
60
|
+
assert_equal ['my_collection'], c.collections.keys
|
61
|
+
assert_equal Taxonifi::Model::RefCollection, c.collections['my_collection'].class
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_that_existing_named_collections_are_not_overwritten
|
65
|
+
c = Taxonifi::Lumper::Clump.new
|
66
|
+
c.add_csv(@csv)
|
67
|
+
assert c.get_from_csv(:collection => :name, :name => 'my_collection')
|
68
|
+
assert !c.get_from_csv(:collection => :name, :name => 'my_collection')
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# name.ref ->
|
73
|
+
|
74
|
+
end
|
75
|
+
|
data/test/test_lumper_names.rb
CHANGED
@@ -28,34 +28,33 @@ class Test_TaxonifiLumperNames < Test::Unit::TestCase
|
|
28
28
|
def test_available_lumps
|
29
29
|
assert Taxonifi::Lumper.available_lumps( Taxonifi::Lumper::QUAD ).include?(:quadrinomial)
|
30
30
|
assert Taxonifi::Lumper.available_lumps( Taxonifi::Lumper::AUTHOR_YEAR + Taxonifi::Lumper::QUAD ).include?(:quad_author_year)
|
31
|
-
assert
|
31
|
+
assert !Taxonifi::Lumper.available_lumps( Taxonifi::Lumper::AUTHOR_YEAR + Taxonifi::Lumper::QUAD ).include?(:names)
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_create_name_collection_creates_a_name_collection
|
35
|
-
assert_equal Taxonifi::Model::NameCollection, Taxonifi::Lumper.create_name_collection(@csv).class
|
35
|
+
assert_equal Taxonifi::Model::NameCollection, Taxonifi::Lumper.create_name_collection(:csv => @csv).class
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_that_create_name_collection_raises_when_fed_non_csv
|
39
39
|
assert_raises Taxonifi::Lumper::LumperError do
|
40
|
-
Taxonifi::Lumper.create_name_collection("FOO")
|
40
|
+
Taxonifi::Lumper.create_name_collection(:csv => "FOO")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_that_create_name_collection_populates_a_name_collection
|
45
|
-
nc = Taxonifi::Lumper.create_name_collection(@csv)
|
45
|
+
nc = Taxonifi::Lumper.create_name_collection(:csv => @csv)
|
46
46
|
assert_equal 3, nc.collection.size
|
47
47
|
assert_equal ["Fooidae", "Foo", "bar"], nc.collection.collect{|n| n.name}
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_that_create_name_collection_assigns_row_number
|
51
|
-
nc = Taxonifi::Lumper.create_name_collection(@csv)
|
51
|
+
nc = Taxonifi::Lumper.create_name_collection(:csv => @csv)
|
52
52
|
assert_equal 0, nc.collection.first.row_number
|
53
53
|
assert_equal 0, nc.collection.last.row_number
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
56
|
def test_that_create_name_collection_parentifies
|
58
|
-
nc = Taxonifi::Lumper.create_name_collection(@csv)
|
57
|
+
nc = Taxonifi::Lumper.create_name_collection(:csv => @csv)
|
59
58
|
assert_equal nc.collection[0], nc.collection[1].parent
|
60
59
|
assert_equal nc.collection[1], nc.collection[2].parent
|
61
60
|
end
|
@@ -74,7 +73,7 @@ class Test_TaxonifiLumperNames < Test::Unit::TestCase
|
|
74
73
|
# 0 4 7
|
75
74
|
|
76
75
|
csv = CSV.parse(string, {headers: true})
|
77
|
-
nc = Taxonifi::Lumper.create_name_collection(csv)
|
76
|
+
nc = Taxonifi::Lumper.create_name_collection(:csv => csv)
|
78
77
|
|
79
78
|
assert_equal nc.collection[2], nc.collection[5].parent
|
80
79
|
assert_equal nc.collection[0], nc.collection[2].parent
|
@@ -98,7 +97,7 @@ class Test_TaxonifiLumperNames < Test::Unit::TestCase
|
|
98
97
|
# 3 foo
|
99
98
|
|
100
99
|
csv = CSV.parse(string, {headers: true})
|
101
|
-
nc = Taxonifi::Lumper.create_name_collection(csv)
|
100
|
+
nc = Taxonifi::Lumper.create_name_collection(:csv => csv)
|
102
101
|
assert_equal 1, nc.collection[3].author.size
|
103
102
|
assert_equal 'Smith', nc.collection[3].author.first.last_name
|
104
103
|
assert_equal 1854, nc.collection[3].year
|
@@ -113,6 +112,65 @@ class Test_TaxonifiLumperNames < Test::Unit::TestCase
|
|
113
112
|
assert_equal false, nc.collection[3].parens
|
114
113
|
end
|
115
114
|
|
115
|
+
def test_that_create_a_name_collection_handles_related_columns
|
116
|
+
string = CSV.generate() do |csv|
|
117
|
+
csv << %w{family genus species author_year foo bar Stuff}
|
118
|
+
csv << ["Fooidae", "Foo", "bar", "Smith, 1854" , nil, 1 , "one"]
|
119
|
+
end
|
120
|
+
|
121
|
+
# 0 Fooidae
|
122
|
+
# 1 Foo
|
123
|
+
# 2 bar
|
124
|
+
|
125
|
+
csv = CSV.parse(string, {headers: true})
|
126
|
+
nc = Taxonifi::Lumper.create_name_collection(:csv => csv)
|
127
|
+
assert_equal nil, nc.collection[2].related['foo']
|
128
|
+
assert_equal "1", nc.collection[2].related['bar'] # !!! everything converted to String
|
129
|
+
assert_equal 'one', nc.collection[2].related['Stuff']
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_that_create_a_name_collection_handles_varieties
|
133
|
+
string = CSV.generate() do |csv|
|
134
|
+
csv << %w{family genus species variety author_year}
|
135
|
+
csv << ["Fooidae", "Foo", "bar", "varblorf", "Smith, 1854"]
|
136
|
+
csv << ["Fooidae", "Foo", "foo", "varblorf", "(Smith, 1854)"]
|
137
|
+
csv << ["Fooidae", "Foo", "bar", "varbliff", "(Smith, 1854)"]
|
138
|
+
end
|
139
|
+
|
140
|
+
# Names added by rank
|
141
|
+
# 0 Fooidae
|
142
|
+
# 1 Foo
|
143
|
+
# 2 bar
|
144
|
+
# 3 foo
|
145
|
+
# 4 varblorf
|
146
|
+
# 5 varblorf
|
147
|
+
# 6 varbliff
|
148
|
+
|
149
|
+
csv = CSV.parse(string, {headers: true})
|
150
|
+
nc = Taxonifi::Lumper.create_name_collection(:csv => csv)
|
151
|
+
|
152
|
+
assert_equal nc.collection[1], nc.collection[2].parent
|
153
|
+
assert_equal nc.collection[1], nc.collection[3].parent
|
154
|
+
assert_equal nc.collection[2], nc.collection[4].parent
|
155
|
+
assert_equal 'variety', nc.collection[4].rank
|
156
|
+
assert_equal 'varblorf', nc.collection[5].name
|
157
|
+
assert_equal 'Smith', nc.collection[6].author.first.last_name
|
158
|
+
|
159
|
+
# assert_equal 1, nc.collection[3].author.size
|
160
|
+
|
161
|
+
# assert_equal 1854, nc.collection[3].year
|
162
|
+
|
163
|
+
# # Name only applies to the "last" name in the order.
|
164
|
+
# assert_equal nil, nc.collection[0].author
|
165
|
+
# assert_equal nil, nc.collection[1].author
|
166
|
+
# assert_equal 1, nc.collection[2].author.size
|
167
|
+
|
168
|
+
# assert_equal nil, nc.collection[0].parens
|
169
|
+
# assert_equal true, nc.collection[2].parens
|
170
|
+
# assert_equal false, nc.collection[3].parens
|
171
|
+
|
172
|
+
end
|
173
|
+
|
116
174
|
#--- reference collections
|
117
175
|
|
118
176
|
end
|
@@ -17,17 +17,17 @@ class Test_TaxonifiLumperParentChildNameCollection < Test::Unit::TestCase
|
|
17
17
|
@csv = CSV.parse(@csv_string, {headers: true})
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def create_a_collection
|
21
21
|
@nc = Taxonifi::Lumper::Lumps::ParentChildNameCollection.name_collection(@csv)
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_that_name_collection_returns_a_name_collection
|
25
|
-
|
25
|
+
create_a_collection
|
26
26
|
assert_equal Taxonifi::Model::NameCollection, @nc.class
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_that_higher_taxon_names_are_created
|
30
|
-
|
30
|
+
create_a_collection
|
31
31
|
assert_equal "Aidae", @nc.names_at_rank('family').first.name
|
32
32
|
assert_equal "family", @nc.names_at_rank('family').first.rank
|
33
33
|
assert_equal "Foo", @nc.names_at_rank('genus').first.name
|
@@ -37,5 +37,49 @@ class Test_TaxonifiLumperParentChildNameCollection < Test::Unit::TestCase
|
|
37
37
|
assert @nc.names_at_rank("subspecies").collect{|n| n.name}.include?("blorf")
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_that_synonyms_are_properly_recognized_and_set
|
41
|
+
csv_string = CSV.generate() do |csv|
|
42
|
+
csv << @headers
|
43
|
+
csv << [0, nil, 'Root','class',nil]
|
44
|
+
csv << [1, 0, 'Lygaeidae','family',nil]
|
45
|
+
csv << [2, 1, 'Lygaeus','genus', nil]
|
46
|
+
csv << [3, 1, 'Neortholomus','genus',nil]
|
47
|
+
csv << [4, 3, 'Neortholomus scolopax (Say, 1832)','species','Lygaeus scolopax Say, 1832']
|
48
|
+
csv << [5, 3, 'Neortholomus foo (Say, 1832)','species']
|
49
|
+
csv << [6, 3, 'Neortholomus bar (Say, 1832)','species']
|
50
|
+
csv << [7, 6, 'Neortholomus bar bar (Say, 1832)', nil]
|
51
|
+
csv << [8, 3, 'Neortholomus aus (Say, 1832)','species']
|
52
|
+
csv << [9, 8, 'Neortholomus aus bus (Say, 1832)', nil]
|
53
|
+
# not yet observed
|
54
|
+
# csv << [7, 3, 'Neortholomus (Neortholomus) blorf (Say, 1832)','species']
|
55
|
+
# csv << [8, 3, 'Neortholomus (Neortholomus) blorf (Say, 1832)','species']
|
56
|
+
end
|
57
|
+
csv = CSV.parse(csv_string, {headers: true})
|
58
|
+
|
59
|
+
nc = Taxonifi::Lumper::Lumps::ParentChildNameCollection.name_collection(csv)
|
60
|
+
|
61
|
+
# These are the names to instantiate when we assume nominotypical names are identical, a combination is added when names
|
62
|
+
# are used in other combinations
|
63
|
+
assert_equal ["Root", "Lygaeidae", "Lygaeus", "Neortholomus", "Neortholomus scolopax (Say, 1832)", "Neortholomus foo (Say, 1832)", "Neortholomus bar (Say, 1832)", "Neortholomus aus (Say, 1832)", "Neortholomus aus bus (Say, 1832)" ], nc.name_string_array
|
64
|
+
assert_equal 9, nc.collection.size
|
65
|
+
|
66
|
+
assert_equal 'bus Say, 1832', nc.collection.last.name_author_year_string
|
67
|
+
|
68
|
+
assert_equal 2, nc.combinations.size
|
69
|
+
|
70
|
+
# These tests a little too dependent on array order (word of warning), which is meaningless
|
71
|
+
assert_equal 'Lygaeus', nc.combinations.last.first.name
|
72
|
+
assert_equal [3, nil, 5, nil], nc.combinations.last.collect{|n| n.nil? ? nil : n.id } # ids start at 1 by default
|
73
|
+
|
74
|
+
assert_equal 'Neortholomus', nc.combinations[0].first.name
|
75
|
+
assert_equal [4, nil, 7,7], nc.combinations[0].collect{|n| n.nil? ? nil : n.id } # ids start at 1 by default
|
76
|
+
|
77
|
+
# when author/year the same ignore?!
|
78
|
+
# examine tblTaxonHIstory? ... the name *is* present but the taxon history won't be.
|
79
|
+
|
80
|
+
foo = 1
|
81
|
+
|
82
|
+
end
|
83
|
+
|
40
84
|
end
|
41
85
|
|
data/test/test_lumper_refs.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'helper'
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
2
|
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lumper/lumper'))
|
3
3
|
|
4
4
|
# Builder construction
|
@@ -33,15 +33,15 @@ class Test_TaxonifiLumperRefs < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_create_ref_collection
|
36
|
-
assert_equal Taxonifi::Model::RefCollection, Taxonifi::Lumper.create_ref_collection(@csv).class
|
36
|
+
assert_equal Taxonifi::Model::RefCollection, Taxonifi::Lumper.create_ref_collection(:csv => @csv).class
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_creates_refs
|
40
|
-
assert_equal 1, Taxonifi::Lumper.create_ref_collection(@csv).collection.size
|
40
|
+
assert_equal 1, Taxonifi::Lumper.create_ref_collection(:csv => @csv).collection.size
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_assigns_attributes_to_instantiated_refs
|
44
|
-
rc = Taxonifi::Lumper.create_ref_collection(@csv)
|
44
|
+
rc = Taxonifi::Lumper.create_ref_collection(:csv => @csv)
|
45
45
|
assert_equal ["J"], rc.collection.first.authors.first.initials
|
46
46
|
assert_equal "Smith", rc.collection.first.authors.first.last_name
|
47
47
|
assert_equal "2012", rc.collection.first.year
|
@@ -60,7 +60,7 @@ class Test_TaxonifiLumperRefs < Test::Unit::TestCase
|
|
60
60
|
csv << ["Smith J. and Barnes S.", "2012", "Bar and foo", "Journal of Foo", "2", "3", "2-3, 190", nil, "2", "4", "2(4)" ]
|
61
61
|
end
|
62
62
|
csv = CSV.parse(csv_string, {headers: true})
|
63
|
-
rc = Taxonifi::Lumper.create_ref_collection(csv)
|
63
|
+
rc = Taxonifi::Lumper.create_ref_collection(:csv => csv)
|
64
64
|
assert_equal 1, rc.collection.size
|
65
65
|
end
|
66
66
|
|
@@ -72,7 +72,7 @@ class Test_TaxonifiLumperRefs < Test::Unit::TestCase
|
|
72
72
|
csv << ["Smith J. and Bartes S.", "2012", "Bar and foo", "Journal of Foo", "2", "3", "2-3, 190", nil, "2", "4", "2(4)" ]
|
73
73
|
end
|
74
74
|
csv = CSV.parse(csv_string, {headers: true})
|
75
|
-
rc = Taxonifi::Lumper.create_ref_collection(csv)
|
75
|
+
rc = Taxonifi::Lumper.create_ref_collection(:csv => csv)
|
76
76
|
assert_equal 2, rc.collection.size
|
77
77
|
end
|
78
78
|
|
@@ -83,9 +83,24 @@ class Test_TaxonifiLumperRefs < Test::Unit::TestCase
|
|
83
83
|
csv << ["Smith J.", "2012", "Foo and bar", "Journal of Foo", "2", "3", "2-3, 190", nil, "2", "4", "2(4)" ]
|
84
84
|
end
|
85
85
|
csv = CSV.parse(csv_string, {headers: true})
|
86
|
-
rc = Taxonifi::Lumper.create_ref_collection(csv)
|
86
|
+
rc = Taxonifi::Lumper.create_ref_collection(:csv => csv)
|
87
87
|
assert_equal "Foo and bar", rc.object_from_row(1).title
|
88
88
|
end
|
89
89
|
|
90
|
+
def test_that_create_a_ref_collection_handles_related_columns
|
91
|
+
csv_string = CSV.generate() do |csv|
|
92
|
+
csv << @headers + ['foo', 'bar']
|
93
|
+
csv << ["Smith J. and Barnes S.", "2012", "Bar and foo", "Journal of Foo", "2", "3", "2-3, 190", nil, "2", "4", "2(4)", "foo value", 1 ]
|
94
|
+
csv << ["Smith J.", "2012", "Foo and bar", "Journal of Foo", "2", "3", "2-3, 190", nil, "2", "4", "2(4)", nil, "bar value" ]
|
95
|
+
end
|
96
|
+
csv = CSV.parse(csv_string, {headers: true})
|
97
|
+
rc = Taxonifi::Lumper.create_ref_collection(:csv => csv)
|
98
|
+
|
99
|
+
assert_equal "foo value", rc.collection.first.related['foo']
|
100
|
+
assert_equal nil, rc.collection.last.related['foo']
|
101
|
+
assert_equal '1', rc.collection.first.related['bar']
|
102
|
+
assert_equal 'bar value', rc.collection.last.related['bar']
|
103
|
+
end
|
104
|
+
|
90
105
|
end
|
91
106
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/export/export'))
|
3
|
+
|
4
|
+
class Test_TaxonifiExportOboNomenclature < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_that_obo_nomenlature_export_does_stuff
|
7
|
+
e = Taxonifi::Export::OboNomenclature.new(:nc => names, :namespace => 'YYZ')
|
8
|
+
assert foo = e.export
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
|
data/test/test_parser.rb
CHANGED
@@ -17,7 +17,8 @@ class Test_TaxonifiSplitterParser < Test::Unit::TestCase
|
|
17
17
|
assert_equal builder.species, builder.subspecies.parent
|
18
18
|
assert_equal "Smith", builder.names.last.author
|
19
19
|
assert_equal 1912, builder.names.last.year
|
20
|
-
assert_equal
|
20
|
+
assert_equal true, builder.names.last.parens
|
21
|
+
assert_equal "Foo (Bar) stuff things (Smith, 1912)", builder.display_name
|
21
22
|
|
22
23
|
lexer = Taxonifi::Splitter::Lexer.new("Foo stuff things Smith, 1912", :species_name)
|
23
24
|
builder = Taxonifi::Model::SpeciesName.new
|
@@ -27,7 +28,8 @@ class Test_TaxonifiSplitterParser < Test::Unit::TestCase
|
|
27
28
|
assert_equal "things", builder.subspecies.name
|
28
29
|
assert_equal "Smith", builder.names.last.author
|
29
30
|
assert_equal 1912 , builder.names.last.year
|
30
|
-
assert_equal
|
31
|
+
assert_equal false, builder.names.last.parens
|
32
|
+
assert_equal "Foo stuff things Smith, 1912", builder.display_name
|
31
33
|
end
|
32
34
|
|
33
35
|
end
|
@@ -397,6 +397,15 @@ class Test_TaxonifiSplitterTokens < Test::Unit::TestCase
|
|
397
397
|
assert_equal "1", t.pg_start
|
398
398
|
assert_equal "10", t.pg_end
|
399
399
|
end
|
400
|
+
|
401
|
+
str = '12-33. ix 14, 19'
|
402
|
+
lexer = Taxonifi::Splitter::Lexer.new(str, :pages)
|
403
|
+
assert t = lexer.pop(Taxonifi::Splitter::Tokens::Pages)
|
404
|
+
assert_equal "12", t.pg_start
|
405
|
+
assert_equal "33", t.pg_end
|
406
|
+
assert_equal "ix 14, 19", t.remainder
|
407
|
+
|
408
|
+
|
400
409
|
end
|
401
410
|
|
402
411
|
end
|
@@ -4,37 +4,44 @@ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/assessor/asse
|
|
4
4
|
class Test_TaxonifiAccessor < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@headers = ["family", "genus", "species", "author", "year"]
|
7
|
+
@headers = ["family", "genus", "subgenus", "species", "subspecies", "variety", "author", "year"]
|
8
8
|
@csv_string = CSV.generate() do |csv|
|
9
9
|
csv << @headers
|
10
|
-
csv << ["Fooidae"
|
10
|
+
csv << ["Fooidae"] # 0
|
11
|
+
csv << ["Fooidae", "Blorf"] # 1
|
12
|
+
csv << ["Fooidae", "Blorf", "Bliff"] # 2
|
13
|
+
csv << ["Fooidae", "Foo", nil, "bar", nil, nil, "Smith", "1854"] # 3
|
14
|
+
csv << ["Fooidae", "Bar", nil, "bar", "subbar", nil, "Smith", "1854"] # 4
|
15
|
+
csv << ["Fooidae", "Bar", nil, "bar", nil, "varbar", "Smith", "1854"] # 5
|
11
16
|
end
|
12
17
|
|
13
|
-
@csv = CSV.parse(@csv_string, {headers: true})
|
18
|
+
@csv = CSV.parse(@csv_string, {headers: true, header_converters: :downcase})
|
14
19
|
end
|
15
20
|
|
16
21
|
def test_first_available
|
17
|
-
assert_equal [:family, 'Fooidae'], Taxonifi::Assessor::RowAssessor.first_available(@csv
|
22
|
+
assert_equal [:family, 'Fooidae'], Taxonifi::Assessor::RowAssessor.first_available(@csv[3], [:family, :genus])
|
18
23
|
end
|
19
24
|
|
20
25
|
def test_last_available
|
21
|
-
assert_equal [:genus, '
|
26
|
+
assert_equal [:genus, 'Bar'], Taxonifi::Assessor::RowAssessor.last_available(@csv[5], [:family, :genus])
|
22
27
|
end
|
23
28
|
|
24
29
|
def test_lump_name_rank
|
25
|
-
assert_equal :
|
26
|
-
@csv
|
27
|
-
assert_equal :
|
28
|
-
@csv
|
29
|
-
assert_equal :
|
30
|
+
assert_equal :family, Taxonifi::Assessor::RowAssessor.lump_name_rank(@csv[0])
|
31
|
+
assert_equal :genus, Taxonifi::Assessor::RowAssessor.lump_name_rank(@csv[1])
|
32
|
+
assert_equal :subgenus, Taxonifi::Assessor::RowAssessor.lump_name_rank(@csv[2])
|
33
|
+
assert_equal :species, Taxonifi::Assessor::RowAssessor.lump_name_rank(@csv[3])
|
34
|
+
assert_equal :subspecies, Taxonifi::Assessor::RowAssessor.lump_name_rank(@csv[4])
|
35
|
+
assert_equal :variety, Taxonifi::Assessor::RowAssessor.lump_name_rank(@csv[5])
|
30
36
|
end
|
31
37
|
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
# DEPRECATED
|
39
|
+
# def test_lump_rank_parent
|
40
|
+
# assert_equal [nil, nil ], Taxonifi::Assessor::RowAssessor.parent_taxon_column(@csv.first)
|
41
|
+
# assert_equal ["family", "Fooidae"], Taxonifi::Assessor::RowAssessor.parent_taxon_column(@csv.first)
|
42
|
+
# end
|
35
43
|
|
36
44
|
def test_intersecting_lumps_with_data
|
37
|
-
|
38
45
|
headers = ["authors"]
|
39
46
|
csv_string = CSV.generate() do |csv|
|
40
47
|
csv << headers
|
@@ -45,7 +52,6 @@ class Test_TaxonifiAccessor < Test::Unit::TestCase
|
|
45
52
|
end
|
46
53
|
|
47
54
|
def test_lumps_with_data
|
48
|
-
|
49
55
|
headers = Taxonifi::Lumper::LUMPS[:citation_small]
|
50
56
|
csv_string = CSV.generate() do |csv|
|
51
57
|
csv << headers
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/models/base'))
|
3
|
+
|
4
|
+
class TestTaxonifiBase < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_new_base
|
7
|
+
assert b = Taxonifi::Model::Base.new()
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_that_base_has_an_id
|
11
|
+
n = Taxonifi::Model::Base.new()
|
12
|
+
assert n.respond_to?(:id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_that_base_has_a_row_number
|
16
|
+
n = Taxonifi::Model::Base.new()
|
17
|
+
assert n.respond_to?(:row_number)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_identical_by_attributes
|
21
|
+
n = Taxonifi::Model::Base.new()
|
22
|
+
assert n.identical?(n)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/test_taxonifi_name.rb
CHANGED
@@ -118,6 +118,35 @@ class TestTaxonifiName < Test::Unit::TestCase
|
|
118
118
|
@n4 = Taxonifi::Model::Name.new(:name => "boo", :rank => "Species", :author => "Frank", :year => 2020, :id => 11, :parent => @n3 )
|
119
119
|
end
|
120
120
|
|
121
|
+
def dont_test_prologify
|
122
|
+
create_a_few_names
|
123
|
+
n0 = [
|
124
|
+
"rank(#{@n0.id}, #{@n0.rank})",
|
125
|
+
"edge(#{@n0.id}, #{@n0.parent ? @no.parent.id : "_"})",
|
126
|
+
"name({@n0.id}, #{@n0.name})"
|
127
|
+
]
|
128
|
+
assert_equal n0.join("\n") , @n0.prologify
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_name_author_year_string
|
132
|
+
create_a_few_names
|
133
|
+
assert_equal 'Baridae', @n0.name_author_year_string
|
134
|
+
assert_equal 'Barinae', @n1.name_author_year_string
|
135
|
+
assert_equal 'Foo Frank, 2020', @n2.name_author_year_string
|
136
|
+
assert_equal 'Bar Frank, 2020', @n3.name_author_year_string
|
137
|
+
assert_equal 'boo Frank, 2020', @n4.name_author_year_string
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_nomenclator_name
|
141
|
+
create_a_few_names
|
142
|
+
n5 = Taxonifi::Model::Name.new(:name => "beep", :rank => "Subspecies", :author => "Frank", :year => 2020, :id => 11, :parent => @n4 )
|
143
|
+
|
144
|
+
assert_equal 'Foo', @n2.nomenclator_name
|
145
|
+
assert_equal 'Foo (Bar)', @n3.nomenclator_name
|
146
|
+
assert_equal 'Foo (Bar) boo', @n4.nomenclator_name
|
147
|
+
assert_equal 'Foo (Bar) boo beep', n5.nomenclator_name
|
148
|
+
end
|
149
|
+
|
121
150
|
def test_ancestors
|
122
151
|
create_a_few_names
|
123
152
|
assert_equal [@n0, @n1], @n2.ancestors
|
@@ -128,6 +157,7 @@ class TestTaxonifiName < Test::Unit::TestCase
|
|
128
157
|
assert_equal [2,15], @n2.ancestor_ids
|
129
158
|
end
|
130
159
|
|
160
|
+
# TODO: fix to inject valid id to confirm to SF
|
131
161
|
def test_parent_ids_sf_style
|
132
162
|
create_a_few_names
|
133
163
|
assert_equal '2-15-14g-19s-11', @n4.parent_ids_sf_style
|
@@ -141,6 +171,17 @@ class TestTaxonifiName < Test::Unit::TestCase
|
|
141
171
|
assert_equal '1920-||smith|-||jones|', n.author_year_index
|
142
172
|
end
|
143
173
|
|
174
|
+
def test_genus_group_parent
|
175
|
+
n1 = Taxonifi::Model::Name.new(name: "Fooidae", rank: "family", author: nil , year: nil) #
|
176
|
+
n2 = Taxonifi::Model::Name.new(name: "Foo", rank: "genus", author: nil , year: nil, :parent => n1) # Foo
|
177
|
+
n3 = Taxonifi::Model::Name.new(name: "Bar", rank: "subgenus", author: nil , year: nil, :parent => n2) # Foo (Bar)
|
178
|
+
n4 = Taxonifi::Model::Name.new(name: "aus", rank: "species", author: nil , year: nil, :parent => n3) # Foo (Bar) aus
|
179
|
+
n5 = Taxonifi::Model::Name.new(name: "bus", rank: "subspecies", author: 'Smith', year: 1920, :parent => n4) # Foo (Bar) aus bus
|
180
|
+
|
181
|
+
assert_equal n3, n4.genus_group_parent
|
182
|
+
assert_equal n3, n5.genus_group_parent
|
183
|
+
end
|
184
|
+
|
144
185
|
#
|
145
186
|
# ICZN Subclass
|
146
187
|
#
|
@@ -179,8 +220,4 @@ class TestTaxonifiName < Test::Unit::TestCase
|
|
179
220
|
assert n.name = "Fooina"
|
180
221
|
end
|
181
222
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
223
|
end
|