unitsml 0.4.6 → 0.5.1
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/docs/README.adoc +104 -2
- data/lib/unitsml/dimension.rb +1 -1
- data/lib/unitsml/fenced.rb +77 -0
- data/lib/unitsml/formula.rb +21 -8
- data/lib/unitsml/intermediate_exp_rules.rb +35 -0
- data/lib/unitsml/parse.rb +16 -25
- data/lib/unitsml/parser.rb +19 -4
- data/lib/unitsml/prefix.rb +10 -10
- data/lib/unitsml/transform.rb +31 -0
- data/lib/unitsml/unit.rb +29 -7
- data/lib/unitsml/unitsdb/dimension.rb +12 -18
- data/lib/unitsml/unitsdb/dimension_quantity.rb +2 -6
- data/lib/unitsml/unitsdb/dimensions.rb +4 -8
- data/lib/unitsml/unitsdb/prefix_reference.rb +23 -0
- data/lib/unitsml/unitsdb/prefixes.rb +19 -5
- data/lib/unitsml/unitsdb/quantities.rb +6 -4
- data/lib/unitsml/unitsdb/unit.rb +21 -0
- data/lib/unitsml/unitsdb/units.rb +20 -17
- data/lib/unitsml/unitsdb.rb +8 -4
- data/lib/unitsml/utility.rb +36 -44
- data/lib/unitsml/version.rb +1 -1
- data/lib/unitsml.rb +34 -16
- data/unitsdb/LICENSE.md +53 -0
- data/unitsdb/README.adoc +1071 -0
- data/unitsdb/RELEASE-NOTES.adoc +269 -0
- data/unitsdb/dimensions.yaml +1255 -602
- data/unitsdb/prefixes.yaml +742 -301
- data/unitsdb/quantities.yaml +3104 -2458
- data/unitsdb/scales.yaml +97 -0
- data/unitsdb/schemas/README.md +159 -0
- data/unitsdb/schemas/dimensions-schema.yaml +157 -0
- data/unitsdb/schemas/prefixes-schema.yaml +159 -0
- data/unitsdb/schemas/quantities-schema.yaml +120 -0
- data/unitsdb/schemas/scales-schema.yaml +109 -0
- data/unitsdb/schemas/unit_systems-schema.yaml +120 -0
- data/unitsdb/schemas/units-schema.yaml +219 -0
- data/unitsdb/spec/units_spec.rb +11 -10
- data/unitsdb/unit_systems.yaml +73 -15
- data/unitsdb/units.yaml +12566 -9974
- data/unitsdb/validate_schemas.rb +208 -0
- data/unitsml.gemspec +2 -1
- metadata +36 -8
- data/unitsdb/docs/README.adoc +0 -12
- data/unitsdb/docs/navigation.adoc +0 -7
@@ -0,0 +1,208 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'json-schema'
|
5
|
+
require 'json'
|
6
|
+
require 'pathname'
|
7
|
+
|
8
|
+
class SchemaValidator
|
9
|
+
def initialize
|
10
|
+
@schemas_dir = Pathname.new('schemas')
|
11
|
+
@errors_found = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate_all
|
15
|
+
puts "UnitsDB Schema Validation"
|
16
|
+
puts "=" * 50
|
17
|
+
|
18
|
+
# Define the mapping of YAML files to their schemas
|
19
|
+
file_schema_map = {
|
20
|
+
'units.yaml' => 'units-schema.yaml',
|
21
|
+
'quantities.yaml' => 'quantities-schema.yaml',
|
22
|
+
'scales.yaml' => 'scales-schema.yaml',
|
23
|
+
'prefixes.yaml' => 'prefixes-schema.yaml',
|
24
|
+
'unit_systems.yaml' => 'unit_systems-schema.yaml',
|
25
|
+
'dimensions.yaml' => 'dimensions-schema.yaml'
|
26
|
+
}
|
27
|
+
|
28
|
+
file_schema_map.each do |yaml_file, schema_file|
|
29
|
+
validate_file(yaml_file, schema_file)
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "\n" + "=" * 50
|
33
|
+
if @errors_found
|
34
|
+
puts "❌ Validation completed with errors"
|
35
|
+
exit 1
|
36
|
+
else
|
37
|
+
puts "✅ All files passed validation"
|
38
|
+
exit 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def validate_file(yaml_file, schema_file)
|
45
|
+
puts "\nValidating #{yaml_file}..."
|
46
|
+
|
47
|
+
# Check if files exist
|
48
|
+
unless File.exist?(yaml_file)
|
49
|
+
puts "❌ YAML file not found: #{yaml_file}"
|
50
|
+
@errors_found = true
|
51
|
+
return
|
52
|
+
end
|
53
|
+
|
54
|
+
schema_path = @schemas_dir / schema_file
|
55
|
+
unless File.exist?(schema_path)
|
56
|
+
puts "❌ Schema file not found: #{schema_path}"
|
57
|
+
@errors_found = true
|
58
|
+
return
|
59
|
+
end
|
60
|
+
|
61
|
+
begin
|
62
|
+
# Load YAML data
|
63
|
+
yaml_data = YAML.load_file(yaml_file)
|
64
|
+
|
65
|
+
# Load schema (YAML schemas need to be converted to JSON for json-schema gem)
|
66
|
+
schema_yaml = YAML.load_file(schema_path)
|
67
|
+
schema_json = JSON.parse(schema_yaml.to_json)
|
68
|
+
|
69
|
+
# Validate
|
70
|
+
errors = JSON::Validator.fully_validate(schema_json, yaml_data,
|
71
|
+
errors_as_objects: true,
|
72
|
+
validate_schema: true)
|
73
|
+
|
74
|
+
if errors.empty?
|
75
|
+
puts "✅ #{yaml_file} - Valid"
|
76
|
+
else
|
77
|
+
puts "❌ #{yaml_file} - #{errors.length} error(s) found:"
|
78
|
+
@errors_found = true
|
79
|
+
|
80
|
+
errors.each_with_index do |error, index|
|
81
|
+
puts "\n Error #{index + 1}:"
|
82
|
+
puts " Path: #{error[:fragment] || 'root'}"
|
83
|
+
puts " Message: #{error[:message]}"
|
84
|
+
|
85
|
+
# Try to provide more context about the location
|
86
|
+
if error[:fragment] && !error[:fragment].empty?
|
87
|
+
path_parts = error[:fragment].split('/')
|
88
|
+
puts " Location: #{describe_path(path_parts, yaml_data)}"
|
89
|
+
end
|
90
|
+
|
91
|
+
# Show the failing value if available
|
92
|
+
if error[:failed_attribute] && error[:failed_attribute] != 'schema'
|
93
|
+
puts " Failed validation: #{error[:failed_attribute]}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
rescue YAML::SyntaxError => e
|
99
|
+
puts "❌ YAML syntax error in #{yaml_file}:"
|
100
|
+
puts " Line #{e.line}: #{e.problem}"
|
101
|
+
@errors_found = true
|
102
|
+
rescue JSON::Schema::ValidationError => e
|
103
|
+
puts "❌ Schema validation error: #{e.message}"
|
104
|
+
@errors_found = true
|
105
|
+
rescue StandardError => e
|
106
|
+
puts "❌ Unexpected error validating #{yaml_file}: #{e.message}"
|
107
|
+
puts " #{e.class}: #{e.backtrace.first}"
|
108
|
+
@errors_found = true
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def describe_path(path_parts, data)
|
113
|
+
current = data
|
114
|
+
description_parts = []
|
115
|
+
|
116
|
+
path_parts.each do |part|
|
117
|
+
next if part.empty? || part == '#'
|
118
|
+
|
119
|
+
if part =~ /^\d+$/
|
120
|
+
# Array index
|
121
|
+
index = part.to_i
|
122
|
+
if current.is_a?(Array) && current[index]
|
123
|
+
description_parts << "item #{index}"
|
124
|
+
current = current[index]
|
125
|
+
else
|
126
|
+
description_parts << "index #{index} (out of bounds)"
|
127
|
+
break
|
128
|
+
end
|
129
|
+
else
|
130
|
+
# Object property
|
131
|
+
if current.is_a?(Hash) && current.key?(part)
|
132
|
+
description_parts << "property '#{part}'"
|
133
|
+
current = current[part]
|
134
|
+
else
|
135
|
+
description_parts << "missing property '#{part}'"
|
136
|
+
break
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
description_parts.join(' -> ')
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Additional helper methods for detailed error reporting
|
146
|
+
class SchemaValidator
|
147
|
+
def self.check_dependencies
|
148
|
+
begin
|
149
|
+
require 'json-schema'
|
150
|
+
rescue LoadError
|
151
|
+
puts "❌ Missing required gem: json-schema"
|
152
|
+
puts " Install with: gem install json-schema"
|
153
|
+
exit 1
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.run_with_options
|
158
|
+
check_dependencies
|
159
|
+
|
160
|
+
if ARGV.include?('--help') || ARGV.include?('-h')
|
161
|
+
show_help
|
162
|
+
exit 0
|
163
|
+
end
|
164
|
+
|
165
|
+
validator = new
|
166
|
+
|
167
|
+
if ARGV.include?('--verbose') || ARGV.include?('-v')
|
168
|
+
puts "Ruby version: #{RUBY_VERSION}"
|
169
|
+
puts "JSON Schema gem version: #{JSON::Schema::VERSION}"
|
170
|
+
puts "Working directory: #{Dir.pwd}"
|
171
|
+
puts ""
|
172
|
+
end
|
173
|
+
|
174
|
+
validator.validate_all
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.show_help
|
178
|
+
puts <<~HELP
|
179
|
+
UnitsDB Schema Validator
|
180
|
+
|
181
|
+
Usage: ruby validate_schemas.rb [options]
|
182
|
+
|
183
|
+
Options:
|
184
|
+
-h, --help Show this help message
|
185
|
+
-v, --verbose Show additional information
|
186
|
+
|
187
|
+
This script validates all YAML files in the UnitsDB repository
|
188
|
+
against their corresponding JSON schemas in the schemas/ directory.
|
189
|
+
|
190
|
+
Files validated:
|
191
|
+
- units.yaml
|
192
|
+
- quantities.yaml
|
193
|
+
- scales.yaml
|
194
|
+
- prefixes.yaml
|
195
|
+
- unit_systems.yaml
|
196
|
+
- dimensions.yaml
|
197
|
+
|
198
|
+
Exit codes:
|
199
|
+
0 - All files passed validation
|
200
|
+
1 - Validation errors found or script error
|
201
|
+
HELP
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# Run the validator if this script is executed directly
|
206
|
+
if __FILE__ == $0
|
207
|
+
SchemaValidator.run_with_options
|
208
|
+
end
|
data/unitsml.gemspec
CHANGED
@@ -30,5 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_dependency 'htmlentities'
|
31
31
|
spec.add_dependency 'mml'
|
32
32
|
spec.add_dependency 'parslet'
|
33
|
-
spec.add_dependency 'unitsdb'
|
33
|
+
spec.add_dependency 'unitsdb', '~> 2.0'
|
34
|
+
spec.add_dependency 'lutaml-model', '~> 0.7.6'
|
34
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unitsml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
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-
|
11
|
+
date: 2025-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -56,16 +56,30 @@ dependencies:
|
|
56
56
|
name: unitsdb
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '2.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: lutaml-model
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.7.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.7.6
|
69
83
|
description: Library to work with UnitsML in Ruby
|
70
84
|
email:
|
71
85
|
- open.source@ribose.com
|
@@ -93,7 +107,9 @@ files:
|
|
93
107
|
- lib/unitsml/error.rb
|
94
108
|
- lib/unitsml/errors/plurimath_load_error.rb
|
95
109
|
- lib/unitsml/extender.rb
|
110
|
+
- lib/unitsml/fenced.rb
|
96
111
|
- lib/unitsml/formula.rb
|
112
|
+
- lib/unitsml/intermediate_exp_rules.rb
|
97
113
|
- lib/unitsml/model/dimension.rb
|
98
114
|
- lib/unitsml/model/dimension_quantities/amount_of_substance.rb
|
99
115
|
- lib/unitsml/model/dimension_quantities/electric_current.rb
|
@@ -125,19 +141,31 @@ files:
|
|
125
141
|
- lib/unitsml/unitsdb/dimension.rb
|
126
142
|
- lib/unitsml/unitsdb/dimension_quantity.rb
|
127
143
|
- lib/unitsml/unitsdb/dimensions.rb
|
144
|
+
- lib/unitsml/unitsdb/prefix_reference.rb
|
128
145
|
- lib/unitsml/unitsdb/prefixes.rb
|
129
146
|
- lib/unitsml/unitsdb/quantities.rb
|
147
|
+
- lib/unitsml/unitsdb/unit.rb
|
130
148
|
- lib/unitsml/unitsdb/units.rb
|
131
149
|
- lib/unitsml/utility.rb
|
132
150
|
- lib/unitsml/version.rb
|
151
|
+
- unitsdb/LICENSE.md
|
152
|
+
- unitsdb/README.adoc
|
153
|
+
- unitsdb/RELEASE-NOTES.adoc
|
133
154
|
- unitsdb/dimensions.yaml
|
134
|
-
- unitsdb/docs/README.adoc
|
135
|
-
- unitsdb/docs/navigation.adoc
|
136
155
|
- unitsdb/prefixes.yaml
|
137
156
|
- unitsdb/quantities.yaml
|
157
|
+
- unitsdb/scales.yaml
|
158
|
+
- unitsdb/schemas/README.md
|
159
|
+
- unitsdb/schemas/dimensions-schema.yaml
|
160
|
+
- unitsdb/schemas/prefixes-schema.yaml
|
161
|
+
- unitsdb/schemas/quantities-schema.yaml
|
162
|
+
- unitsdb/schemas/scales-schema.yaml
|
163
|
+
- unitsdb/schemas/unit_systems-schema.yaml
|
164
|
+
- unitsdb/schemas/units-schema.yaml
|
138
165
|
- unitsdb/spec/units_spec.rb
|
139
166
|
- unitsdb/unit_systems.yaml
|
140
167
|
- unitsdb/units.yaml
|
168
|
+
- unitsdb/validate_schemas.rb
|
141
169
|
- unitsml.gemspec
|
142
170
|
homepage: https://github.com/unitsml/unitsml-ruby
|
143
171
|
licenses:
|
data/unitsdb/docs/README.adoc
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
= UnitsDB
|
2
|
-
|
3
|
-
This data repository is used in conjunction with UnitsML.
|
4
|
-
|
5
|
-
Sources include:
|
6
|
-
|
7
|
-
* https://www.bipm.org/en/publications/si-brochure/[BIPM SI Brochure]
|
8
|
-
* https://www.nist.gov/pml/special-publication-811[NIST SP 811]
|
9
|
-
* ISO 80000 series
|
10
|
-
* (in some cases, "Encyclopaedia of Scientific Units, Weights and Measures, Their SI Equivalences and Origins" by François Cardarelli, is consulted)
|
11
|
-
|
12
|
-
NOTE: Conversion factors here are not updated with the revised SI.
|