cosing 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cosing.gemspec +17 -2
- data/data/annex.II.csv +714 -714
- data/data/annex.III.csv +1178 -1178
- data/data/annex.IV.csv +14 -14
- data/data/annex.V.csv +66 -66
- data/data/annex.VI.csv +72 -72
- data/lib/cosing/annex/base.rb +6 -8
- data/lib/cosing/annex/ii.rb +18 -0
- data/lib/cosing/annex/iii.rb +25 -0
- data/lib/cosing/annex/iv.rb +19 -0
- data/lib/cosing/annex/rule.rb +2 -0
- data/lib/cosing/annex/sccs_opinion.rb +2 -0
- data/lib/cosing/annex/v.rb +25 -0
- data/lib/cosing/annex/vi.rb +25 -0
- data/lib/cosing/annex.rb +15 -123
- data/lib/cosing/database.rb +50 -44
- data/lib/cosing/parser.rb +15 -0
- data/lib/cosing/patterns.rb +7 -0
- data/lib/cosing/version.rb +1 -2
- data/lib/cosing.rb +6 -7
- metadata +5 -7
- data/.rspec +0 -3
- data/.rubocop.yml +0 -9
- data/CHANGELOG.md +0 -13
- data/Rakefile +0 -14
data/lib/cosing/annex/iii.rb
CHANGED
@@ -10,6 +10,31 @@ module Cosing
|
|
10
10
|
attribute :other_restrictions, Types::String
|
11
11
|
attribute :product_type, Types::String
|
12
12
|
end
|
13
|
+
|
14
|
+
def self.load
|
15
|
+
new.tap do |annex|
|
16
|
+
Annex.parse("data/annex.III.csv") do |row|
|
17
|
+
common_ingredients = Cosing::Parser.transform_array!(
|
18
|
+
row,
|
19
|
+
key: :common_ingredients,
|
20
|
+
split: ";"
|
21
|
+
)
|
22
|
+
identified_ingredients = Cosing::Parser.transform_array!(
|
23
|
+
row,
|
24
|
+
key: :identified_ingredients,
|
25
|
+
split: ";"
|
26
|
+
)
|
27
|
+
|
28
|
+
annex.add_rule(
|
29
|
+
row.merge(
|
30
|
+
common_ingredients: common_ingredients.compact,
|
31
|
+
identified_ingredients: identified_ingredients.compact,
|
32
|
+
other_restrictions: row[:other]
|
33
|
+
)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
13
38
|
end
|
14
39
|
end
|
15
40
|
end
|
data/lib/cosing/annex/iv.rb
CHANGED
@@ -11,6 +11,25 @@ module Cosing
|
|
11
11
|
attribute :product_type, Types::String
|
12
12
|
attribute :wording_of_conditions, Types::String
|
13
13
|
end
|
14
|
+
|
15
|
+
def self.load
|
16
|
+
new.tap do |annex|
|
17
|
+
Annex.parse("data/annex.IV.csv") do |row|
|
18
|
+
ingredients = Cosing::Parser.transform_array!(
|
19
|
+
row,
|
20
|
+
key: :identified_ingredients,
|
21
|
+
split: ";"
|
22
|
+
)
|
23
|
+
|
24
|
+
annex.add_rule(
|
25
|
+
row.merge(
|
26
|
+
identified_ingredients: ingredients.compact,
|
27
|
+
other_restrictions: row[:other]
|
28
|
+
)
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
14
33
|
end
|
15
34
|
end
|
16
35
|
end
|
data/lib/cosing/annex/rule.rb
CHANGED
data/lib/cosing/annex/v.rb
CHANGED
@@ -10,6 +10,31 @@ module Cosing
|
|
10
10
|
attribute :product_type, Types::String
|
11
11
|
attribute :wording_of_conditions, Types::String
|
12
12
|
end
|
13
|
+
|
14
|
+
def self.load
|
15
|
+
new.tap do |annex|
|
16
|
+
Annex.parse("data/annex.V.csv") do |row|
|
17
|
+
common_ingredients = Cosing::Parser.transform_array!(
|
18
|
+
row,
|
19
|
+
key: :common_ingredients,
|
20
|
+
split: ";"
|
21
|
+
)
|
22
|
+
identified_ingredients = Cosing::Parser.transform_array!(
|
23
|
+
row,
|
24
|
+
key: :identified_ingredients,
|
25
|
+
split: ";"
|
26
|
+
)
|
27
|
+
|
28
|
+
annex.add_rule(
|
29
|
+
row.merge(
|
30
|
+
common_ingredients: common_ingredients.compact,
|
31
|
+
identified_ingredients: identified_ingredients.compact,
|
32
|
+
other_restrictions: row[:other]
|
33
|
+
)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
13
38
|
end
|
14
39
|
end
|
15
40
|
end
|
data/lib/cosing/annex/vi.rb
CHANGED
@@ -11,6 +11,31 @@ module Cosing
|
|
11
11
|
attribute :product_type, Types::String
|
12
12
|
attribute :wording_of_conditions, Types::String
|
13
13
|
end
|
14
|
+
|
15
|
+
def self.load
|
16
|
+
new.tap do |annex|
|
17
|
+
Annex.parse("data/annex.VI.csv") do |row|
|
18
|
+
common_ingredients = Cosing::Parser.transform_array!(
|
19
|
+
row,
|
20
|
+
key: :common_ingredients,
|
21
|
+
split: ";"
|
22
|
+
)
|
23
|
+
identified_ingredients = Cosing::Parser.transform_array!(
|
24
|
+
row,
|
25
|
+
key: :identified_ingredients,
|
26
|
+
split: ";"
|
27
|
+
)
|
28
|
+
|
29
|
+
annex.add_rule(
|
30
|
+
row.merge(
|
31
|
+
common_ingredients: common_ingredients.compact,
|
32
|
+
identified_ingredients: identified_ingredients.compact,
|
33
|
+
other_restrictions: row[:other]
|
34
|
+
)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
14
39
|
end
|
15
40
|
end
|
16
41
|
end
|
data/lib/cosing/annex.rb
CHANGED
@@ -33,133 +33,25 @@ module Cosing
|
|
33
33
|
yield row.merge(
|
34
34
|
cas_numbers: cas_numbers.compact,
|
35
35
|
ec_numbers: ec_numbers.compact,
|
36
|
-
sccs_opinions: sccs_opinions.compact
|
36
|
+
sccs_opinions: sccs_opinions.compact
|
37
37
|
)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def load
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
row.merge(
|
52
|
-
identified_ingredients: identified_ingredients.compact
|
53
|
-
)
|
54
|
-
)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
annex_iii = Annex::III.new.tap do |annex|
|
59
|
-
parse("data/annex.III.csv") do |row|
|
60
|
-
common_ingredients = transform_array!(
|
61
|
-
row,
|
62
|
-
key: :common_ingredients,
|
63
|
-
split: ";"
|
64
|
-
)
|
65
|
-
identified_ingredients = transform_array!(
|
66
|
-
row,
|
67
|
-
key: :identified_ingredients,
|
68
|
-
split: ";"
|
69
|
-
)
|
70
|
-
|
71
|
-
annex.add_rule(
|
72
|
-
row.merge(
|
73
|
-
common_ingredients: common_ingredients.compact,
|
74
|
-
identified_ingredients: identified_ingredients.compact,
|
75
|
-
other_restrictions: row[:other]
|
76
|
-
)
|
77
|
-
)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
annex_iv = Annex::IV.new.tap do |annex|
|
82
|
-
parse("data/annex.IV.csv") do |row|
|
83
|
-
identified_ingredients = transform_array!(
|
84
|
-
row,
|
85
|
-
key: :identified_ingredients,
|
86
|
-
split: ";"
|
87
|
-
)
|
88
|
-
|
89
|
-
annex.add_rule(
|
90
|
-
row.merge(
|
91
|
-
identified_ingredients: identified_ingredients.compact,
|
92
|
-
other_restrictions: row[:other]
|
93
|
-
)
|
94
|
-
)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
annex_v = Annex::V.new.tap do |annex|
|
99
|
-
parse("data/annex.V.csv") do |row|
|
100
|
-
common_ingredients = transform_array!(
|
101
|
-
row,
|
102
|
-
key: :common_ingredients,
|
103
|
-
split: ";"
|
104
|
-
)
|
105
|
-
identified_ingredients = transform_array!(
|
106
|
-
row,
|
107
|
-
key: :identified_ingredients,
|
108
|
-
split: ";"
|
109
|
-
)
|
110
|
-
|
111
|
-
annex.add_rule(
|
112
|
-
row.merge(
|
113
|
-
common_ingredients: common_ingredients.compact,
|
114
|
-
identified_ingredients: identified_ingredients.compact,
|
115
|
-
other_restrictions: row[:other]
|
116
|
-
)
|
117
|
-
)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
annex_vi = Annex::VI.new.tap do |annex|
|
122
|
-
parse("data/annex.VI.csv") do |row|
|
123
|
-
common_ingredients = transform_array!(
|
124
|
-
row,
|
125
|
-
key: :common_ingredients,
|
126
|
-
split: ";"
|
127
|
-
)
|
128
|
-
identified_ingredients = transform_array!(
|
129
|
-
row,
|
130
|
-
key: :identified_ingredients,
|
131
|
-
split: ";"
|
132
|
-
)
|
133
|
-
|
134
|
-
annex.add_rule(
|
135
|
-
row.merge(
|
136
|
-
common_ingredients: common_ingredients.compact,
|
137
|
-
identified_ingredients: identified_ingredients.compact,
|
138
|
-
other_restrictions: row[:other]
|
139
|
-
)
|
140
|
-
)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
{
|
145
|
-
ii: annex_ii,
|
146
|
-
iii: annex_iii,
|
147
|
-
iv: annex_iv,
|
148
|
-
v: annex_v,
|
149
|
-
vi: annex_vi
|
150
|
-
}
|
151
|
-
end
|
152
|
-
|
153
|
-
def transform_array!(params, key:, split:)
|
154
|
-
params
|
155
|
-
.delete(key)
|
156
|
-
.split(split)
|
157
|
-
.map(&:strip)
|
158
|
-
.reject { |n| n == "-" }
|
42
|
+
ii, iii, iv, v, vi = [
|
43
|
+
Annex::II,
|
44
|
+
Annex::III,
|
45
|
+
Annex::IV,
|
46
|
+
Annex::V,
|
47
|
+
Annex::VI
|
48
|
+
].map(&:load)
|
49
|
+
|
50
|
+
{ ii:, iii:, iv:, v:, vi: }
|
159
51
|
end
|
160
52
|
|
161
53
|
def build_sccs_opinions(row)
|
162
|
-
transform_array!(
|
54
|
+
Cosing::Parser.transform_array!(
|
163
55
|
row,
|
164
56
|
key: :sccs_opinions,
|
165
57
|
split: ";"
|
@@ -174,23 +66,23 @@ module Cosing
|
|
174
66
|
end
|
175
67
|
|
176
68
|
def build_cas_numbers(row)
|
177
|
-
transform_array!(
|
69
|
+
Cosing::Parser.transform_array!(
|
178
70
|
row,
|
179
71
|
key: :cas_number,
|
180
72
|
split: "/"
|
181
73
|
).map do |cas_number|
|
182
|
-
match = cas_number.match(
|
74
|
+
match = cas_number.match(Patterns::CAS_NUMBER)
|
183
75
|
match[:cas_number] if match
|
184
76
|
end
|
185
77
|
end
|
186
78
|
|
187
79
|
def build_ec_numbers(row)
|
188
|
-
transform_array!(
|
80
|
+
Cosing::Parser.transform_array!(
|
189
81
|
row,
|
190
82
|
key: :ec_number,
|
191
83
|
split: "/"
|
192
84
|
).map do |ec_number|
|
193
|
-
match = ec_number.match(
|
85
|
+
match = ec_number.match(Patterns::EC_NUMBER)
|
194
86
|
match[:ec_number] if match
|
195
87
|
end
|
196
88
|
end
|
data/lib/cosing/database.rb
CHANGED
@@ -4,80 +4,86 @@ module Cosing
|
|
4
4
|
class Database
|
5
5
|
attr_reader :annexes, :ingredients
|
6
6
|
|
7
|
+
ANNOTATION_PATTERN = %r{([IVX]+)/([IVX]*/)?([\dabcd,]+)}
|
8
|
+
|
7
9
|
def initialize(annexes)
|
8
10
|
@annexes = annexes
|
9
11
|
@ingredients = {}
|
10
12
|
end
|
11
13
|
|
12
14
|
def add_ingredient(params)
|
13
|
-
restrictions =
|
14
|
-
|
15
|
+
restrictions = Parser
|
16
|
+
.transform_array!(params, key: :restriction, split: "\n")
|
17
|
+
regulations = extract_regulations(restrictions).compact
|
18
|
+
cas_numbers = extract_cas_numbers(params).compact
|
19
|
+
einecs_numbers = extract_einecs_numbers(params).compact
|
20
|
+
functions = Parser
|
21
|
+
.transform_array!(params, key: :functions, split: ",")
|
22
|
+
.compact
|
15
23
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
24
|
+
@ingredients[params[:reference_number]] = Ingredient.new(
|
25
|
+
functions:,
|
26
|
+
restrictions:,
|
27
|
+
regulations:,
|
28
|
+
cas_numbers:,
|
29
|
+
einecs_numbers:,
|
30
|
+
**params
|
31
|
+
)
|
32
|
+
end
|
20
33
|
|
21
|
-
|
22
|
-
|
34
|
+
def save(filepath, pretty: false)
|
35
|
+
output = if pretty
|
36
|
+
JSON.pretty_generate(@ingredients.to_h)
|
37
|
+
else
|
38
|
+
JSON.dump(@ingredients.to_h)
|
39
|
+
end
|
23
40
|
|
24
|
-
|
25
|
-
|
26
|
-
@annexes[numeral.downcase.to_sym].lookup(number)
|
27
|
-
end
|
28
|
-
end
|
41
|
+
File.write(filepath, output)
|
42
|
+
end
|
29
43
|
|
30
|
-
|
31
|
-
end
|
44
|
+
private
|
32
45
|
|
33
|
-
|
46
|
+
def extract_cas_numbers(params)
|
47
|
+
Parser.transform_array!(
|
34
48
|
params,
|
35
49
|
key: :cas_number,
|
36
50
|
split: "/"
|
37
51
|
).map do |cas_number|
|
38
|
-
match = cas_number.match(
|
52
|
+
match = cas_number.match(Patterns::CAS_NUMBER)
|
39
53
|
match[:cas_number] if match
|
40
54
|
end
|
55
|
+
end
|
41
56
|
|
42
|
-
|
43
|
-
|
44
|
-
einecs_numbers = transform_array!(
|
57
|
+
def extract_einecs_numbers(params)
|
58
|
+
Parser.transform_array!(
|
45
59
|
params,
|
46
60
|
key: :einecs_number,
|
47
61
|
split: "/"
|
48
62
|
).map do |einecs_number|
|
49
|
-
match = einecs_number.match(
|
63
|
+
match = einecs_number.match(Patterns::EINECS_NUMBER)
|
50
64
|
match[:einecs_number] if match
|
51
65
|
end
|
52
|
-
|
53
|
-
@ingredients[params[:reference_number]] = Ingredient.new(
|
54
|
-
functions:,
|
55
|
-
restrictions: restrictions.compact,
|
56
|
-
regulations: regulations.compact,
|
57
|
-
cas_numbers: cas_numbers.compact,
|
58
|
-
einecs_numbers: einecs_numbers.compact,
|
59
|
-
**params
|
60
|
-
)
|
61
66
|
end
|
62
67
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
68
|
+
def extract_regulations(restrictions)
|
69
|
+
restrictions
|
70
|
+
.flat_map do |restriction|
|
71
|
+
matches = restriction.scan(ANNOTATION_PATTERN)
|
72
|
+
next if matches.none?
|
69
73
|
|
70
|
-
|
74
|
+
extract_hits(matches).compact
|
75
|
+
end
|
71
76
|
end
|
72
77
|
|
73
|
-
|
78
|
+
def extract_hits(matches)
|
79
|
+
matches.flat_map do |match|
|
80
|
+
numeral, _, reference_number = match
|
74
81
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
.reject { |n| n == "-" }
|
82
|
+
reference_number.split(",").flat_map do |number|
|
83
|
+
# debugger if number == "41" && numeral == "VI"
|
84
|
+
@annexes[numeral.downcase.to_sym].lookup(number)
|
85
|
+
end
|
86
|
+
end
|
81
87
|
end
|
82
88
|
end
|
83
89
|
end
|
data/lib/cosing/version.rb
CHANGED
data/lib/cosing.rb
CHANGED
@@ -7,6 +7,8 @@ require "dry/types"
|
|
7
7
|
require "dry/struct"
|
8
8
|
require_relative "cosing/version"
|
9
9
|
require_relative "cosing/types"
|
10
|
+
require_relative "cosing/parser"
|
11
|
+
require_relative "cosing/patterns"
|
10
12
|
require_relative "cosing/ingredient"
|
11
13
|
require_relative "cosing/annex"
|
12
14
|
require_relative "cosing/database"
|
@@ -30,13 +32,10 @@ module Cosing
|
|
30
32
|
liberal_parsing: true,
|
31
33
|
header_converters: :symbol
|
32
34
|
) do |row|
|
33
|
-
row
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
.transform_values(&:strip)
|
38
|
-
|
39
|
-
database.add_ingredient(row)
|
35
|
+
row
|
36
|
+
.to_h
|
37
|
+
.transform_values! { |value| value.to_s.strip }
|
38
|
+
.then { |row| database.add_ingredient(row) }
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cosing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nolan J Tait
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: csv
|
@@ -59,12 +59,8 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".rspec"
|
63
|
-
- ".rubocop.yml"
|
64
|
-
- CHANGELOG.md
|
65
62
|
- LICENSE.txt
|
66
63
|
- README.md
|
67
|
-
- Rakefile
|
68
64
|
- cosing.gemspec
|
69
65
|
- data/annex.II.csv
|
70
66
|
- data/annex.III.csv
|
@@ -84,6 +80,8 @@ files:
|
|
84
80
|
- lib/cosing/annex/vi.rb
|
85
81
|
- lib/cosing/database.rb
|
86
82
|
- lib/cosing/ingredient.rb
|
83
|
+
- lib/cosing/parser.rb
|
84
|
+
- lib/cosing/patterns.rb
|
87
85
|
- lib/cosing/types.rb
|
88
86
|
- lib/cosing/version.rb
|
89
87
|
homepage: https://github.com/inhouse-work/cosing
|
@@ -109,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
107
|
- !ruby/object:Gem::Version
|
110
108
|
version: '0'
|
111
109
|
requirements: []
|
112
|
-
rubygems_version: 3.5.
|
110
|
+
rubygems_version: 3.5.7
|
113
111
|
signing_key:
|
114
112
|
specification_version: 4
|
115
113
|
summary: COSING database
|
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/CHANGELOG.md
DELETED
data/Rakefile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "bundler/gem_tasks"
|
4
|
-
require "rspec/core/rake_task"
|
5
|
-
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
7
|
-
|
8
|
-
task default: :spec
|
9
|
-
|
10
|
-
desc "Output the cosing database into a json format"
|
11
|
-
task :export do
|
12
|
-
database = Cosing.load
|
13
|
-
database.save
|
14
|
-
end
|