unitsdb 2.0.1 → 2.1.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 +4 -4
- data/.rubocop_todo.yml +15 -92
- data/Gemfile +0 -1
- data/README.adoc +2 -108
- data/lib/unitsdb/cli.rb +0 -7
- data/lib/unitsdb/commands/_modify.rb +2 -2
- data/lib/unitsdb/commands/base.rb +33 -7
- data/lib/unitsdb/commands/normalize.rb +1 -1
- data/lib/unitsdb/commands/release.rb +86 -47
- data/lib/unitsdb/commands/validate/identifiers.rb +1 -3
- data/lib/unitsdb/commands/validate/references.rb +1 -3
- data/lib/unitsdb/commands/validate/si_references.rb +6 -0
- data/lib/unitsdb/commands/validate.rb +3 -3
- data/lib/unitsdb/database.rb +0 -1
- data/lib/unitsdb/dimensions.rb +0 -1
- data/lib/unitsdb/prefixes.rb +0 -1
- data/lib/unitsdb/quantities.rb +0 -1
- data/lib/unitsdb/scales.rb +0 -1
- data/lib/unitsdb/unit_systems.rb +0 -1
- data/lib/unitsdb/units.rb +0 -1
- data/lib/unitsdb/version.rb +1 -1
- data/unitsdb.gemspec +2 -0
- metadata +2 -10
- data/lib/unitsdb/commands/ucum/check.rb +0 -126
- data/lib/unitsdb/commands/ucum/formatter.rb +0 -141
- data/lib/unitsdb/commands/ucum/matcher.rb +0 -301
- data/lib/unitsdb/commands/ucum/update.rb +0 -84
- data/lib/unitsdb/commands/ucum/updater.rb +0 -98
- data/lib/unitsdb/commands/ucum/xml_parser.rb +0 -34
- data/lib/unitsdb/commands/ucum.rb +0 -43
- data/lib/unitsdb/ucum.rb +0 -198
@@ -13,7 +13,7 @@ module Unitsdb
|
|
13
13
|
def references
|
14
14
|
require_relative "validate/references"
|
15
15
|
|
16
|
-
Commands::
|
16
|
+
Commands::References.new(options).run
|
17
17
|
end
|
18
18
|
|
19
19
|
desc "identifiers", "Check for uniqueness of identifier fields"
|
@@ -23,7 +23,7 @@ module Unitsdb
|
|
23
23
|
def identifiers
|
24
24
|
require_relative "validate/identifiers"
|
25
25
|
|
26
|
-
Commands::
|
26
|
+
Commands::Identifiers.new(options).run
|
27
27
|
end
|
28
28
|
|
29
29
|
desc "si_references", "Validate that each SI digital framework reference is unique per entity type"
|
@@ -33,7 +33,7 @@ module Unitsdb
|
|
33
33
|
def si_references
|
34
34
|
require_relative "validate/si_references"
|
35
35
|
|
36
|
-
|
36
|
+
Validate::SiReferences.new(options).run
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/lib/unitsdb/database.rb
CHANGED
@@ -12,7 +12,6 @@ module Unitsdb
|
|
12
12
|
# model Config.model_for(:units)
|
13
13
|
|
14
14
|
attribute :schema_version, :string
|
15
|
-
attribute :version, :string
|
16
15
|
attribute :units, Unit, collection: true
|
17
16
|
attribute :prefixes, Prefix, collection: true
|
18
17
|
attribute :quantities, Quantity, collection: true
|
data/lib/unitsdb/dimensions.rb
CHANGED
data/lib/unitsdb/prefixes.rb
CHANGED
data/lib/unitsdb/quantities.rb
CHANGED
data/lib/unitsdb/scales.rb
CHANGED
data/lib/unitsdb/unit_systems.rb
CHANGED
data/lib/unitsdb/units.rb
CHANGED
data/lib/unitsdb/version.rb
CHANGED
data/unitsdb.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.metadata["source_code_uri"] = spec.homepage
|
20
20
|
spec.metadata["changelog_uri"] = "https://github.com/unitsml/unitsdb-ruby/releases"
|
21
21
|
|
22
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
23
|
+
|
22
24
|
# Specify which files should be added to the gem when it is released.
|
23
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
26
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unitsdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lutaml-model
|
@@ -132,13 +132,6 @@ files:
|
|
132
132
|
- lib/unitsdb/commands/si_matcher.rb
|
133
133
|
- lib/unitsdb/commands/si_ttl_parser.rb
|
134
134
|
- lib/unitsdb/commands/si_updater.rb
|
135
|
-
- lib/unitsdb/commands/ucum.rb
|
136
|
-
- lib/unitsdb/commands/ucum/check.rb
|
137
|
-
- lib/unitsdb/commands/ucum/formatter.rb
|
138
|
-
- lib/unitsdb/commands/ucum/matcher.rb
|
139
|
-
- lib/unitsdb/commands/ucum/update.rb
|
140
|
-
- lib/unitsdb/commands/ucum/updater.rb
|
141
|
-
- lib/unitsdb/commands/ucum/xml_parser.rb
|
142
135
|
- lib/unitsdb/commands/validate.rb
|
143
136
|
- lib/unitsdb/commands/validate/identifiers.rb
|
144
137
|
- lib/unitsdb/commands/validate/references.rb
|
@@ -166,7 +159,6 @@ files:
|
|
166
159
|
- lib/unitsdb/scales.rb
|
167
160
|
- lib/unitsdb/si_derived_base.rb
|
168
161
|
- lib/unitsdb/symbol_presentations.rb
|
169
|
-
- lib/unitsdb/ucum.rb
|
170
162
|
- lib/unitsdb/unit.rb
|
171
163
|
- lib/unitsdb/unit_reference.rb
|
172
164
|
- lib/unitsdb/unit_system.rb
|
@@ -1,126 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../base"
|
4
|
-
require_relative "../../database"
|
5
|
-
require_relative "../../errors"
|
6
|
-
require_relative "xml_parser"
|
7
|
-
require_relative "formatter"
|
8
|
-
require_relative "matcher"
|
9
|
-
require_relative "updater"
|
10
|
-
require "fileutils"
|
11
|
-
|
12
|
-
module Unitsdb
|
13
|
-
module Commands
|
14
|
-
module Ucum
|
15
|
-
class Check < Base
|
16
|
-
# Constants
|
17
|
-
ENTITY_TYPES = %w[units prefixes].freeze
|
18
|
-
|
19
|
-
def run
|
20
|
-
# Get options
|
21
|
-
entity_type = @options[:entity_type]&.downcase
|
22
|
-
direction = @options[:direction]&.downcase || "both"
|
23
|
-
output_dir = @options[:output_updated_database]
|
24
|
-
include_potential = @options[:include_potential_matches] || false
|
25
|
-
database_path = @options[:database]
|
26
|
-
ucum_file = @options[:ucum_file]
|
27
|
-
|
28
|
-
# Validate parameters
|
29
|
-
validate_parameters(direction, ucum_file)
|
30
|
-
|
31
|
-
# Use the path as-is without expansion
|
32
|
-
puts "Using database directory: #{database_path}"
|
33
|
-
|
34
|
-
@db = Unitsdb::Database.from_db(database_path)
|
35
|
-
|
36
|
-
puts "Using UCUM file: #{ucum_file}"
|
37
|
-
puts "Include potential matches: #{include_potential ? "Yes" : "No"}"
|
38
|
-
|
39
|
-
# Parse UCUM XML file
|
40
|
-
ucum_data = XmlParser.parse_ucum_file(ucum_file)
|
41
|
-
|
42
|
-
# Process entity types
|
43
|
-
process_entities(entity_type, ucum_data, direction, output_dir, include_potential)
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
# Process all entity types or a specific one
|
49
|
-
def process_entities(entity_type, ucum_data, direction, output_dir, include_potential)
|
50
|
-
if entity_type && ENTITY_TYPES.include?(entity_type)
|
51
|
-
process_entity_type(entity_type, ucum_data, direction, output_dir, include_potential)
|
52
|
-
else
|
53
|
-
ENTITY_TYPES.each do |type|
|
54
|
-
process_entity_type(type, ucum_data, direction, output_dir, include_potential)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Process a specific entity type
|
60
|
-
def process_entity_type(entity_type, ucum_data, direction, output_dir, include_potential = false)
|
61
|
-
puts "\n========== Processing #{entity_type.upcase} References ==========\n"
|
62
|
-
|
63
|
-
db_entities = @db.send(entity_type)
|
64
|
-
ucum_entities = XmlParser.get_entities_from_ucum(entity_type, ucum_data)
|
65
|
-
|
66
|
-
puts "Found #{ucum_entities.size} #{entity_type} in UCUM"
|
67
|
-
puts "Found #{db_entities.size} #{entity_type} in database"
|
68
|
-
|
69
|
-
check_from_ucum(entity_type, ucum_entities, db_entities, output_dir, include_potential) if %w[from_ucum
|
70
|
-
both].include?(direction)
|
71
|
-
|
72
|
-
return unless %w[to_ucum both].include?(direction)
|
73
|
-
|
74
|
-
check_to_ucum(entity_type, ucum_entities, db_entities, output_dir, include_potential)
|
75
|
-
end
|
76
|
-
|
77
|
-
# Validation helpers
|
78
|
-
def validate_parameters(direction, ucum_file)
|
79
|
-
unless %w[to_ucum from_ucum both].include?(direction)
|
80
|
-
puts "Invalid direction: #{direction}. Must be one of: to_ucum, from_ucum, both"
|
81
|
-
exit(1)
|
82
|
-
end
|
83
|
-
|
84
|
-
return if File.exist?(ucum_file)
|
85
|
-
|
86
|
-
puts "UCUM file not found: #{ucum_file}"
|
87
|
-
exit(1)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Direction handler: UCUM → UnitsDB
|
91
|
-
def check_from_ucum(entity_type, ucum_entities, db_entities, output_dir, include_potential = false)
|
92
|
-
Formatter.print_direction_header("UCUM → UnitsDB")
|
93
|
-
|
94
|
-
matches, missing_matches, unmatched_ucum = Matcher.match_ucum_to_db(entity_type, ucum_entities, db_entities)
|
95
|
-
|
96
|
-
# Print results
|
97
|
-
Formatter.display_ucum_results(entity_type, matches, missing_matches, unmatched_ucum)
|
98
|
-
|
99
|
-
# Update references if needed
|
100
|
-
return unless output_dir && !missing_matches.empty?
|
101
|
-
|
102
|
-
output_file = File.join(output_dir, "#{entity_type}.yaml")
|
103
|
-
Updater.update_references(entity_type, missing_matches, db_entities, output_file, include_potential)
|
104
|
-
puts "\nUpdated references written to #{output_file}"
|
105
|
-
end
|
106
|
-
|
107
|
-
# Direction handler: UnitsDB → UCUM
|
108
|
-
def check_to_ucum(entity_type, ucum_entities, db_entities, output_dir, include_potential = false)
|
109
|
-
Formatter.print_direction_header("UnitsDB → UCUM")
|
110
|
-
|
111
|
-
matches, missing_refs, unmatched_db = Matcher.match_db_to_ucum(entity_type, ucum_entities, db_entities)
|
112
|
-
|
113
|
-
# Print results
|
114
|
-
Formatter.display_db_results(entity_type, matches, missing_refs, unmatched_db)
|
115
|
-
|
116
|
-
# Update references if needed
|
117
|
-
return unless output_dir && !missing_refs.empty?
|
118
|
-
|
119
|
-
output_file = File.join(output_dir, "#{entity_type}.yaml")
|
120
|
-
Updater.update_references(entity_type, missing_refs, db_entities, output_file, include_potential)
|
121
|
-
puts "\nUpdated references written to #{output_file}"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Unitsdb
|
4
|
-
module Commands
|
5
|
-
module Ucum
|
6
|
-
# Formats output for UCUM matching results
|
7
|
-
module Formatter
|
8
|
-
module_function
|
9
|
-
|
10
|
-
# Print a direction header (UnitsDB → UCUM or UCUM → UnitsDB)
|
11
|
-
def print_direction_header(direction)
|
12
|
-
puts "\n=== #{direction} ===\n"
|
13
|
-
end
|
14
|
-
|
15
|
-
# Display results for UCUM → UnitsDB matching
|
16
|
-
def display_ucum_results(entity_type, matches, missing_matches, unmatched_ucum)
|
17
|
-
puts "\nResults for #{entity_type.capitalize} (UCUM → UnitsDB):"
|
18
|
-
puts " Matched: #{matches.size}"
|
19
|
-
puts " Missing matches (could be added): #{missing_matches.size}"
|
20
|
-
puts " Unmatched UCUM entities: #{unmatched_ucum.size}"
|
21
|
-
|
22
|
-
unless unmatched_ucum.empty?
|
23
|
-
puts "\nUnmatched UCUM #{entity_type}:"
|
24
|
-
unmatched_ucum.each do |entity|
|
25
|
-
case entity
|
26
|
-
when Unitsdb::UcumPrefix
|
27
|
-
puts " - #{entity.name} (#{entity.code_sensitive})"
|
28
|
-
when Unitsdb::UcumBaseUnit
|
29
|
-
puts " - #{entity.name} (#{entity.code_sensitive}, dimension: #{entity.dimension})"
|
30
|
-
when Unitsdb::UcumUnit
|
31
|
-
name = entity.name.is_a?(Array) ? entity.name.first : entity.name
|
32
|
-
puts " - #{name} (#{entity.code_sensitive}, class: #{entity.klass})"
|
33
|
-
else
|
34
|
-
puts " - Unknown entity type"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
return if missing_matches.empty?
|
40
|
-
|
41
|
-
puts "\nPotential additions (UCUM #{entity_type} that could be added to UnitsDB):"
|
42
|
-
missing_matches.each do |match|
|
43
|
-
ucum_entity = match[:ucum_entity]
|
44
|
-
db_entity = match[:db_entity]
|
45
|
-
|
46
|
-
# Get entity IDs and names
|
47
|
-
db_id = get_db_entity_id(db_entity)
|
48
|
-
db_name = get_db_entity_name(db_entity)
|
49
|
-
ucum_name = get_ucum_entity_name(ucum_entity)
|
50
|
-
ucum_code = ucum_entity.respond_to?(:code_sensitive) ? ucum_entity.code_sensitive : "unknown"
|
51
|
-
|
52
|
-
case ucum_entity
|
53
|
-
when Unitsdb::UcumPrefix
|
54
|
-
puts " - UnitsDB prefix '#{db_name}' (#{db_id}) → UCUM prefix '#{ucum_name}' (#{ucum_code})"
|
55
|
-
when Unitsdb::UcumBaseUnit
|
56
|
-
puts " - UnitsDB unit '#{db_name}' (#{db_id}) → UCUM base unit '#{ucum_name}' (#{ucum_code})"
|
57
|
-
when Unitsdb::UcumUnit
|
58
|
-
puts " - UnitsDB unit '#{db_name}' (#{db_id}) → UCUM unit '#{ucum_name}' (#{ucum_code})"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Display results for UnitsDB → UCUM matching
|
64
|
-
def display_db_results(entity_type, matches, missing_refs, unmatched_db)
|
65
|
-
puts "\nResults for #{entity_type.capitalize} (UnitsDB → UCUM):"
|
66
|
-
puts " Matched: #{matches.size}"
|
67
|
-
puts " Missing references (could be added): #{missing_refs.size}"
|
68
|
-
puts " Unmatched UnitsDB entities: #{unmatched_db.size}"
|
69
|
-
|
70
|
-
unless unmatched_db.empty?
|
71
|
-
puts "\nUnmatched UnitsDB #{entity_type}:"
|
72
|
-
unmatched_db.each do |entity|
|
73
|
-
id = get_db_entity_id(entity)
|
74
|
-
name = get_db_entity_name(entity)
|
75
|
-
puts " - #{name} (#{id})"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
return if missing_refs.empty?
|
80
|
-
|
81
|
-
puts "\nPotential references (UCUM references that could be added to UnitsDB):"
|
82
|
-
missing_refs.each do |match|
|
83
|
-
ucum_entity = match[:ucum_entity]
|
84
|
-
db_entity = match[:db_entity]
|
85
|
-
|
86
|
-
# Get entity IDs and names
|
87
|
-
db_id = get_db_entity_id(db_entity)
|
88
|
-
db_name = get_db_entity_name(db_entity)
|
89
|
-
ucum_name = get_ucum_entity_name(ucum_entity)
|
90
|
-
ucum_code = ucum_entity.respond_to?(:code_sensitive) ? ucum_entity.code_sensitive : "unknown"
|
91
|
-
|
92
|
-
case ucum_entity
|
93
|
-
when Unitsdb::UcumPrefix
|
94
|
-
puts " - UnitsDB prefix '#{db_name}' (#{db_id}) → UCUM prefix '#{ucum_name}' (#{ucum_code})"
|
95
|
-
when Unitsdb::UcumBaseUnit
|
96
|
-
puts " - UnitsDB unit '#{db_name}' (#{db_id}) → UCUM base unit '#{ucum_name}' (#{ucum_code})"
|
97
|
-
when Unitsdb::UcumUnit
|
98
|
-
puts " - UnitsDB unit '#{db_name}' (#{db_id}) → UCUM unit '#{ucum_name}' (#{ucum_code})"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Helper to get db entity id
|
104
|
-
def get_db_entity_id(entity)
|
105
|
-
if entity.respond_to?(:identifiers) && entity.identifiers && !entity.identifiers.empty?
|
106
|
-
entity.identifiers.first.id
|
107
|
-
elsif entity.respond_to?(:id)
|
108
|
-
entity.id
|
109
|
-
else
|
110
|
-
"unknown-id"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# Helper to get db entity name
|
115
|
-
def get_db_entity_name(entity)
|
116
|
-
if entity.respond_to?(:names) && entity.names && !entity.names.empty?
|
117
|
-
entity.names.first.value
|
118
|
-
elsif entity.respond_to?(:short) && entity.short
|
119
|
-
entity.short
|
120
|
-
elsif entity.respond_to?(:name)
|
121
|
-
entity.name
|
122
|
-
else
|
123
|
-
"unknown-name"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
# Helper to get ucum entity name
|
128
|
-
def get_ucum_entity_name(entity)
|
129
|
-
case entity
|
130
|
-
when Unitsdb::UcumPrefix, Unitsdb::UcumBaseUnit
|
131
|
-
entity.name
|
132
|
-
when Unitsdb::UcumUnit
|
133
|
-
entity.name.is_a?(Array) ? entity.name.first : entity.name
|
134
|
-
else
|
135
|
-
"unknown-name"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|