inci_score 4.5.1 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8d0453d792d9a6f5e628d13720a927c15ee14ba8441faf588736b22ab8bf618
4
- data.tar.gz: d354ebb76fa432acc592da8e152e6a9712022c394cce7e8f951e6ebc9f94b93a
3
+ metadata.gz: 7c1ec290c92d1fb34798dbd04ec8f93a6ad1db12fd124ff2f7d0c4a50c108aa7
4
+ data.tar.gz: dad169f8a2486aeeac3a22df47097235d965b9435350d4800d662c9022f0a36c
5
5
  SHA512:
6
- metadata.gz: dcfc4fcafe3b51ed9917937c36055c4043591b499250eae36be97cf4b58d101d0440bc12a57a2fe8e22c5fb4189ed20969cd6f0ab7f58cfa9028fa2ea681fda6
7
- data.tar.gz: a34557698ffc1449c4ae4d4bb031465566506e92186c7a6e482ff655453566581d3645f8e78894d5afec6a3feb6066d887d30063356b6d3a91b408204a1a6ed4
6
+ metadata.gz: 34394e8b825952f6ff98696ba899592f23a0acd8e3b95331c1d645903ac9795569dc6e115ff1dca5df0ae4aee551b54aae0e32b91faa302b4338b4e37769d797
7
+ data.tar.gz: 1b932c8c80adfc5b0989383a7c31c7b78432890dd3b86c54c887b1d3146f6629332cb7abd16e50b70343113bf3beb76233f4cd0d77fd684e26e7377ca0a8ee7f
data/README.md CHANGED
@@ -80,7 +80,7 @@ You can collect INCI data by using the available CLI interface:
80
80
  inci_score --src="ingredients: aqua, dimethicone, pej-10, noent"
81
81
 
82
82
  TOTAL SCORE:
83
- 47.18
83
+ 53.22
84
84
  PRECISION:
85
85
  75.0
86
86
  COMPONENTS:
data/config/catalog.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  aqua: 0
3
3
  water: 0
4
+ aroma: 2
4
5
  parfum: 3
5
6
  fragrance: 3
6
7
  phosphatidylcholine: 1
@@ -1580,6 +1581,7 @@ fagus sylvatica: 0
1580
1581
  farnesol: 2
1581
1582
  farnesyl acetate: 0
1582
1583
  fast green fcf: 4
1584
+ fava tonka: 1
1583
1585
  fermented vegetable extract: 0
1584
1586
  ferric chloride: 0
1585
1587
  ferula assa foetida: 0
@@ -3370,6 +3372,7 @@ pentasodium aminotrimethylene phosphonate: 3
3370
3372
  pentasodium pentetate: 3
3371
3373
  pentasodium triphosphate: 2
3372
3374
  pentetic acid: 3
3375
+ pentylene glycol: 2
3373
3376
  perfluorodecalin: 3
3374
3377
  perfluoropolymethylisopropyl ether: 3
3375
3378
  perfluorotetralin: 3
@@ -4019,6 +4022,7 @@ prunus avium: 0
4019
4022
  prunus cerasus: 0
4020
4023
  prunus domestica: 0
4021
4024
  prunus dulcis: 0
4025
+ prunus amygdalus dulcis (sweet almond) oil: 0
4022
4026
  prunus persica: 0
4023
4027
  prunus serotina: 0
4024
4028
  prunus spinosa: 0
@@ -4831,6 +4835,8 @@ thymus extract: 4
4831
4835
  thymus hydrolysate: 4
4832
4836
  thymus serpyllum: 0
4833
4837
  thymus vulgaris: 0
4838
+ thymus vulgaris leaf oil: 0
4839
+ thymus vulgaris leaf water: 0
4834
4840
  tilia americana: 0
4835
4841
  tilia cordata: 0
4836
4842
  tilia vulgaris: 0
@@ -4908,6 +4914,7 @@ tripeptide-29: 1
4908
4914
  triphenyl trimethicone: 4
4909
4915
  tripotassium edta: 4
4910
4916
  trisodium edta: 4
4917
+ trisodium ethylenediamine disuccinate: 2
4911
4918
  trisodium hedta: 4
4912
4919
  trisodium lauroampho pg-acetate phosphate chloride: 3
4913
4920
  trisodium methylglycinediacetate: 1
@@ -5,7 +5,6 @@ require 'yaml'
5
5
  module InciScore
6
6
  module Config
7
7
  CATALOG = YAML::load_file(File::expand_path('../../../config/catalog.yml', __FILE__)).freeze
8
- CIR = File.readlines(File::expand_path('../../../config/cir', __FILE__)).freeze
9
8
  HAZARDS = YAML::load_file(File::expand_path('../../../config/hazards.yml', __FILE__)).freeze
10
9
  end
11
10
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module InciScore
4
4
  class Ingredient
5
- SLASH = '/'
6
5
  SLASH_RULE = /(?<!ate)\//.freeze
7
6
  PARENTHESIS = %w[( ) [ ]].freeze
8
7
  PARENTHESIS_RULE = /(\(.+\)|\[.+\])/.freeze
@@ -11,24 +10,23 @@ module InciScore
11
10
 
12
11
  def initialize(raw)
13
12
  @raw = raw.to_s
14
- @values = fetch_values
13
+ @values = fetch_values.uniq
15
14
  freeze
16
15
  end
17
16
 
18
- def to_s
19
- values.join(SLASH)
20
- end
21
-
22
17
  private
23
18
 
24
19
  def fetch_values
25
- if parenthesis?
26
- parenthesis = PARENTHESIS.join
27
- parenthesis_values = raw.match(PARENTHESIS_RULE).captures.map { |c| c.delete(parenthesis) }
28
- deparenthesized = raw.sub(PARENTHESIS_RULE, '').sub(/\s+/, ' ').strip
29
- [deparenthesized].concat(parenthesis_values)
30
- else
31
- raw.split(SLASH_RULE).map(&:strip)
20
+ [raw].tap do |vals|
21
+ if parenthesis?
22
+ parenthesis = PARENTHESIS.join
23
+ parenthesis_values = raw.match(PARENTHESIS_RULE).captures.map { |c| c.delete(parenthesis) }
24
+ deparenthesized = raw.sub(PARENTHESIS_RULE, '').sub(/\s{2,}/, ' ').strip
25
+ vals << deparenthesized
26
+ vals.concat(parenthesis_values)
27
+ else
28
+ vals.concat(raw.split(SLASH_RULE).map(&:strip))
29
+ end
32
30
  end
33
31
  end
34
32
 
@@ -7,7 +7,11 @@ module InciScore
7
7
  module Rules
8
8
  TOLERANCE = 3
9
9
 
10
- Component = Struct.new(:name, :hazard)
10
+ Component = Struct.new(:name, :hazard) do
11
+ def to_s
12
+ "#{name} (#{hazard})"
13
+ end
14
+ end
11
15
 
12
16
  Key = ->(src) do
13
17
  score = Config::CATALOG[src]
@@ -24,24 +28,31 @@ module InciScore
24
28
  extend self
25
29
 
26
30
  Result = Struct.new(:name, :distance, :score) do
27
- def tolerable?(size)
28
- distance < TOLERANCE && distance <= (size-1)
31
+ def tolerable?(size, tolerance)
32
+ distance < tolerance && distance <= (size-1)
29
33
  end
30
34
  end
31
35
 
32
36
  def call(src)
33
37
  return if src.empty?
34
38
  size = src.size
39
+ t = tolerance(size)
35
40
  farthest = Result.new(nil, size)
36
41
  initial = src[0]
37
42
  result = Config::CATALOG.reduce(farthest) do |nearest, (name, score)|
38
43
  next nearest unless name.start_with?(initial)
39
- next nearest if name.size > (size + TOLERANCE)
44
+ next nearest if name.size > (size + t)
40
45
  d = src.distance(name)
41
46
  nearest = Result.new(name, d, score) if d < nearest.distance
42
47
  nearest
43
48
  end
44
- Component.new(result.name, result.score) if result.tolerable?(size)
49
+ Component.new(result.name, result.score) if result.tolerable?(size, t)
50
+ end
51
+
52
+ private
53
+
54
+ def tolerance(size)
55
+ Math.log(size, 1.8).round
45
56
  end
46
57
  end
47
58
 
@@ -53,7 +64,7 @@ module InciScore
53
64
  def call(src)
54
65
  return if src.size < TOLERANCE
55
66
  digits = src[0, MIN_MEANINGFUL]
56
- pairs = Config::CATALOG.detect { |name, _| name.start_with?(digits) }.to_a.first
67
+ pairs = Config::CATALOG.detect { |name, _| name.start_with?(digits) }
57
68
  Component.new(*pairs) if pairs
58
69
  end
59
70
  end
@@ -41,7 +41,7 @@ PRECISION:
41
41
  return '' if components.empty?
42
42
  %Q{
43
43
  COMPONENTS:
44
- \t#{components.map { |c| "#{c.name} (#{c.hazard})" }.join(', ')}}
44
+ \t#{components.map(&:to_s).join(', ')}}
45
45
  end
46
46
 
47
47
  def unrecognized_str
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InciScore
4
- VERSION = '4.5.1'
4
+ VERSION = '4.6.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inci_score
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.1
4
+ version: 4.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob
@@ -106,7 +106,6 @@ files:
106
106
  - README.md
107
107
  - bin/inci_score
108
108
  - config/catalog.yml
109
- - config/cir
110
109
  - config/hazards.yml
111
110
  - ext/levenshtein.c
112
111
  - lib/inci_score.rb