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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/docs/README.adoc +104 -2
  3. data/lib/unitsml/dimension.rb +1 -1
  4. data/lib/unitsml/fenced.rb +77 -0
  5. data/lib/unitsml/formula.rb +21 -8
  6. data/lib/unitsml/intermediate_exp_rules.rb +35 -0
  7. data/lib/unitsml/parse.rb +16 -25
  8. data/lib/unitsml/parser.rb +19 -4
  9. data/lib/unitsml/prefix.rb +10 -10
  10. data/lib/unitsml/transform.rb +31 -0
  11. data/lib/unitsml/unit.rb +29 -7
  12. data/lib/unitsml/unitsdb/dimension.rb +12 -18
  13. data/lib/unitsml/unitsdb/dimension_quantity.rb +2 -6
  14. data/lib/unitsml/unitsdb/dimensions.rb +4 -8
  15. data/lib/unitsml/unitsdb/prefix_reference.rb +23 -0
  16. data/lib/unitsml/unitsdb/prefixes.rb +19 -5
  17. data/lib/unitsml/unitsdb/quantities.rb +6 -4
  18. data/lib/unitsml/unitsdb/unit.rb +21 -0
  19. data/lib/unitsml/unitsdb/units.rb +20 -17
  20. data/lib/unitsml/unitsdb.rb +8 -4
  21. data/lib/unitsml/utility.rb +36 -44
  22. data/lib/unitsml/version.rb +1 -1
  23. data/lib/unitsml.rb +34 -16
  24. data/unitsdb/LICENSE.md +53 -0
  25. data/unitsdb/README.adoc +1071 -0
  26. data/unitsdb/RELEASE-NOTES.adoc +269 -0
  27. data/unitsdb/dimensions.yaml +1255 -602
  28. data/unitsdb/prefixes.yaml +742 -301
  29. data/unitsdb/quantities.yaml +3104 -2458
  30. data/unitsdb/scales.yaml +97 -0
  31. data/unitsdb/schemas/README.md +159 -0
  32. data/unitsdb/schemas/dimensions-schema.yaml +157 -0
  33. data/unitsdb/schemas/prefixes-schema.yaml +159 -0
  34. data/unitsdb/schemas/quantities-schema.yaml +120 -0
  35. data/unitsdb/schemas/scales-schema.yaml +109 -0
  36. data/unitsdb/schemas/unit_systems-schema.yaml +120 -0
  37. data/unitsdb/schemas/units-schema.yaml +219 -0
  38. data/unitsdb/spec/units_spec.rb +11 -10
  39. data/unitsdb/unit_systems.yaml +73 -15
  40. data/unitsdb/units.yaml +12566 -9974
  41. data/unitsdb/validate_schemas.rb +208 -0
  42. data/unitsml.gemspec +2 -1
  43. metadata +36 -8
  44. data/unitsdb/docs/README.adoc +0 -12
  45. data/unitsdb/docs/navigation.adoc +0 -7
@@ -0,0 +1,109 @@
1
+ # yaml-language-server: $schema=http://json-schema.org/draft-06/schema
2
+ ---
3
+ $schema: "http://json-schema.org/draft-06/schema#"
4
+ $id: "https://unitsml.org/schemas/scales-schema.yaml"
5
+ title: "Scales Database Schema"
6
+ description: "Schema for scales.yaml - defines measurement scales with their mathematical properties"
7
+
8
+ type: object
9
+ required: ["schema_version", "scales"]
10
+ properties:
11
+ schema_version:
12
+ type: string
13
+ pattern: "^\\d+\\.\\d+\\.\\d+$"
14
+ description: "Semantic version of the schema"
15
+ scales:
16
+ type: array
17
+ description: "Array of scale definitions"
18
+ items:
19
+ $ref: "#/definitions/Scale"
20
+
21
+ definitions:
22
+ Scale:
23
+ type: object
24
+ required: ["identifiers", "names", "properties"]
25
+ properties:
26
+ identifiers:
27
+ type: array
28
+ description: "External identifiers for this scale"
29
+ items:
30
+ $ref: "#/definitions/Identifier"
31
+ names:
32
+ type: array
33
+ description: "Multilingual names for this scale"
34
+ items:
35
+ $ref: "#/definitions/Name"
36
+ properties:
37
+ $ref: "#/definitions/ScaleProperties"
38
+ description: "Mathematical properties of the scale"
39
+ references:
40
+ type: array
41
+ description: "External references and citations"
42
+ items:
43
+ $ref: "#/definitions/Reference"
44
+
45
+ Identifier:
46
+ type: object
47
+ required: ["type", "id"]
48
+ properties:
49
+ type:
50
+ type: string
51
+ description: "Type of identifier system"
52
+ id:
53
+ type: string
54
+ description: "Identifier value within the system"
55
+
56
+ Name:
57
+ type: object
58
+ required: ["value", "lang"]
59
+ properties:
60
+ value:
61
+ type: string
62
+ description: "Name in the specified language"
63
+ lang:
64
+ type: string
65
+ pattern: "^[a-z]{2}(-[A-Z]{2})?$"
66
+ description: "Language code (ISO 639-1, optionally with ISO 3166-1 country)"
67
+
68
+ ScaleProperties:
69
+ type: object
70
+ required: ["continuous", "ordered", "logarithmic", "interval", "ratio"]
71
+ properties:
72
+ continuous:
73
+ type: boolean
74
+ description: "Whether the scale is continuous"
75
+ ordered:
76
+ type: boolean
77
+ description: "Whether the scale has an ordering"
78
+ logarithmic:
79
+ type: boolean
80
+ description: "Whether the scale is logarithmic"
81
+ interval:
82
+ type: boolean
83
+ description: "Whether the scale has meaningful intervals"
84
+ ratio:
85
+ type: boolean
86
+ description: "Whether the scale has a meaningful zero point"
87
+
88
+ Reference:
89
+ type: object
90
+ required: ["type"]
91
+ properties:
92
+ type:
93
+ type: string
94
+ description: "Type of reference"
95
+ authority:
96
+ type: string
97
+ description: "Authoritative body or organization"
98
+ uri:
99
+ type: string
100
+ format: "uri"
101
+ description: "URI to the reference"
102
+ title:
103
+ type: string
104
+ description: "Title of the reference"
105
+ year:
106
+ type: integer
107
+ minimum: 1000
108
+ maximum: 9999
109
+ description: "Publication year"
@@ -0,0 +1,120 @@
1
+ # yaml-language-server: $schema=http://json-schema.org/draft-06/schema
2
+ ---
3
+ $schema: "http://json-schema.org/draft-06/schema#"
4
+ $id: "https://unitsml.org/schemas/unit_systems-schema.yaml"
5
+ title: "Unit Systems Database Schema"
6
+ description: "Schema for unit_systems.yaml - defines systems of measurement units"
7
+
8
+ type: object
9
+ required: ["schema_version", "unit_systems"]
10
+ properties:
11
+ schema_version:
12
+ type: string
13
+ pattern: "^\\d+\\.\\d+\\.\\d+$"
14
+ description: "Semantic version of the schema"
15
+ unit_systems:
16
+ type: array
17
+ description: "Array of unit system definitions"
18
+ items:
19
+ $ref: "#/definitions/UnitSystem"
20
+
21
+ definitions:
22
+ UnitSystem:
23
+ type: object
24
+ required: ["identifiers", "names"]
25
+ properties:
26
+ identifiers:
27
+ type: array
28
+ description: "External identifiers for this unit system"
29
+ items:
30
+ $ref: "#/definitions/Identifier"
31
+ names:
32
+ type: array
33
+ description: "Multilingual names for this unit system"
34
+ items:
35
+ $ref: "#/definitions/Name"
36
+ base_units:
37
+ type: array
38
+ description: "Base units that define this system"
39
+ items:
40
+ $ref: "#/definitions/BaseUnitReference"
41
+ references:
42
+ type: array
43
+ description: "External references and citations"
44
+ items:
45
+ $ref: "#/definitions/Reference"
46
+
47
+ Identifier:
48
+ type: object
49
+ required: ["type", "id"]
50
+ properties:
51
+ type:
52
+ type: string
53
+ enum: ["nist", "unitsml", "si-digital-framework"]
54
+ description: "Type of identifier system"
55
+ id:
56
+ type: string
57
+ description: "Identifier value within the system"
58
+
59
+ Name:
60
+ type: object
61
+ required: ["value", "lang"]
62
+ properties:
63
+ value:
64
+ type: string
65
+ description: "Name in the specified language"
66
+ lang:
67
+ type: string
68
+ pattern: "^[a-z]{2}(-[A-Z]{2})?$"
69
+ description: "Language code (ISO 639-1, optionally with ISO 3166-1 country)"
70
+
71
+ BaseUnitReference:
72
+ type: object
73
+ required: ["type", "id", "quantity_reference"]
74
+ properties:
75
+ type:
76
+ type: string
77
+ const: "unit"
78
+ description: "Reference type indicator"
79
+ id:
80
+ type: string
81
+ description: "Unit identifier"
82
+ quantity_reference:
83
+ $ref: "#/definitions/QuantityReference"
84
+ description: "Physical quantity this base unit measures"
85
+
86
+ QuantityReference:
87
+ type: object
88
+ required: ["type", "id"]
89
+ properties:
90
+ type:
91
+ type: string
92
+ const: "quantity"
93
+ description: "Reference type indicator"
94
+ id:
95
+ type: string
96
+ description: "Quantity identifier"
97
+
98
+ Reference:
99
+ type: object
100
+ required: ["type"]
101
+ properties:
102
+ type:
103
+ type: string
104
+ enum: ["standard", "specification", "publication", "website"]
105
+ description: "Type of reference"
106
+ authority:
107
+ type: string
108
+ description: "Authoritative body or organization"
109
+ uri:
110
+ type: string
111
+ format: "uri"
112
+ description: "URI to the reference"
113
+ title:
114
+ type: string
115
+ description: "Title of the reference"
116
+ year:
117
+ type: integer
118
+ minimum: 1000
119
+ maximum: 9999
120
+ description: "Publication year"
@@ -0,0 +1,219 @@
1
+ # yaml-language-server: $schema=http://json-schema.org/draft-06/schema
2
+ ---
3
+ $schema: "http://json-schema.org/draft-06/schema#"
4
+ $id: "https://unitsml.org/schemas/units-schema.yaml"
5
+ title: "Units Database Schema"
6
+ description: "Schema for units.yaml - defines measurement units with their properties, symbols, and relationships"
7
+
8
+ type: object
9
+ required: ["schema_version", "units"]
10
+ properties:
11
+ schema_version:
12
+ type: string
13
+ pattern: "^\\d+\\.\\d+\\.\\d+$"
14
+ description: "Semantic version of the schema"
15
+ units:
16
+ type: array
17
+ description: "Array of unit definitions"
18
+ items:
19
+ $ref: "#/definitions/Unit"
20
+
21
+ definitions:
22
+ Unit:
23
+ type: object
24
+ required: ["identifiers", "names", "scale_reference", "unit_system_reference", "root", "short", "symbols"]
25
+ properties:
26
+ identifiers:
27
+ type: array
28
+ description: "External identifiers for this unit"
29
+ items:
30
+ $ref: "#/definitions/Identifier"
31
+ names:
32
+ type: array
33
+ description: "Multilingual names for this unit"
34
+ items:
35
+ $ref: "#/definitions/Name"
36
+ scale_reference:
37
+ $ref: "#/definitions/ScaleReference"
38
+ description: "Reference to the measurement scale"
39
+ unit_system_reference:
40
+ type: array
41
+ description: "Reference to the unit system"
42
+ items:
43
+ $ref: "#/definitions/UnitSystemReference"
44
+ minimum: 1
45
+ root:
46
+ type: boolean
47
+ description: "Whether this unit is a root unit in its system"
48
+ root_units:
49
+ type: array
50
+ description: "Root units that compose this unit"
51
+ items:
52
+ $ref: "#/definitions/RootUnit"
53
+ short:
54
+ type: string
55
+ description: "Short description or definition"
56
+ symbols:
57
+ type: array
58
+ description: "Mathematical and textual representations"
59
+ items:
60
+ $ref: "#/definitions/Symbol"
61
+ quantity_reference:
62
+ $ref: "#/definitions/QuantityReference"
63
+ description: "Reference to the physical quantity (optional)"
64
+ references:
65
+ type: array
66
+ description: "External references and citations"
67
+ items:
68
+ $ref: "#/definitions/Reference"
69
+
70
+ Identifier:
71
+ type: object
72
+ required: ["type", "id"]
73
+ properties:
74
+ type:
75
+ type: string
76
+ enum: ["nist", "unitsml", "ucum", "si-digital-framework"]
77
+ description: "Type of identifier system"
78
+ id:
79
+ type: string
80
+ description: "Identifier value within the system"
81
+
82
+ Name:
83
+ type: object
84
+ required: ["value", "lang"]
85
+ properties:
86
+ value:
87
+ type: string
88
+ description: "Name in the specified language"
89
+ lang:
90
+ type: string
91
+ pattern: "^[a-z]{2}(-[A-Z]{2})?$"
92
+ description: "Language code (ISO 639-1, optionally with ISO 3166-1 country)"
93
+
94
+ ScaleReference:
95
+ type: object
96
+ required: ["type", "id"]
97
+ properties:
98
+ type:
99
+ type: string
100
+ description: "Reference type indicator"
101
+ enum: ["unitsml"]
102
+ id:
103
+ type: string
104
+ description: "Scale identifier"
105
+
106
+ UnitSystemReference:
107
+ type: object
108
+ required: ["type", "id"]
109
+ properties:
110
+ type:
111
+ type: string
112
+ description: "Reference type indicator"
113
+ enum: ["unitsml", "ucum", "nist"]
114
+ id:
115
+ type: string
116
+ description: "Unit system identifier"
117
+
118
+ QuantityReference:
119
+ type: object
120
+ required: ["type", "id"]
121
+ properties:
122
+ type:
123
+ type: string
124
+ description: "Reference type indicator"
125
+ enum: ["unitsml", "ucum", "nist"]
126
+ id:
127
+ type: string
128
+ description: "Quantity identifier"
129
+
130
+ RootUnit:
131
+ type: object
132
+ required: ["power", "unit_reference"]
133
+ properties:
134
+ power:
135
+ type: integer
136
+ description: "Exponent for this unit in the composition"
137
+ unit_reference:
138
+ $ref: "#/definitions/UnitReference"
139
+ description: "Reference to the base unit"
140
+
141
+ UnitReference:
142
+ type: object
143
+ required: ["type", "id"]
144
+ properties:
145
+ type:
146
+ type: string
147
+ description: "Reference type indicator"
148
+ id:
149
+ type: string
150
+ description: "Unit identifier"
151
+ prefix_reference:
152
+ $ref: "#/definitions/PrefixReference"
153
+ description: "Optional prefix applied to the unit"
154
+
155
+ PrefixReference:
156
+ type: object
157
+ required: ["type", "id"]
158
+ properties:
159
+ type:
160
+ type: string
161
+ description: "Reference type indicator"
162
+ id:
163
+ type: string
164
+ description: "Prefix identifier"
165
+
166
+ # - latex: "\\ensuremath{\\mathrm{m}}"
167
+ # unicode: m
168
+ # ascii: m
169
+ # html: m
170
+ # id: m
171
+ # mathml: "<mi mathvariant='normal'>m</mi>"
172
+
173
+ Symbol:
174
+ type: object
175
+ required: ["latex", "unicode", "ascii", "html", "id", "mathml"]
176
+ description: "Mathematical and textual representations of the unit"
177
+ properties:
178
+ latex:
179
+ type: string
180
+ description: "LaTeX representation"
181
+ unicode:
182
+ type: string
183
+ description: "Unicode representation"
184
+ ascii:
185
+ type: string
186
+ description: "ASCII representation"
187
+ html:
188
+ type: string
189
+ description: "HTML representation"
190
+ id:
191
+ type: string
192
+ description: "Symbol identifier"
193
+ mathml:
194
+ type: string
195
+ description: "MathML representation"
196
+
197
+ Reference:
198
+ type: object
199
+ required: ["type"]
200
+ properties:
201
+ type:
202
+ type: string
203
+ enum: ["normative", "informative"]
204
+ description: "Type of reference"
205
+ authority:
206
+ type: string
207
+ description: "Authoritative body or organization"
208
+ uri:
209
+ type: string
210
+ format: "uri"
211
+ description: "URI to the reference"
212
+ title:
213
+ type: string
214
+ description: "Title of the reference"
215
+ year:
216
+ type: integer
217
+ minimum: 1000
218
+ maximum: 9999
219
+ description: "Publication year"
@@ -1,17 +1,18 @@
1
- require 'yaml'
2
- require 'rspec'
3
- require 'plurimath'
1
+ # frozen_string_literal: true
4
2
 
5
- describe 'MathML in UnitsDB' do
6
- unitsdb = YAML.load_file('units.yaml')
3
+ require "yaml"
4
+ require "rspec"
5
+ require "plurimath/math"
6
+
7
+ describe "Validate MathML in UnitsDB" do
8
+ unitsdb = YAML.load_file(File.join(__dir__, "../units.yaml"))
7
9
 
8
10
  unitsdb.each do |unit, unit_data|
9
11
  context "when parsing MathML for #{unit}" do
10
-
11
- it 'parses successfully' do
12
- unit_symbols = unit_data.dig("unit_symbols").flatten.compact
13
- unit_symbols.each do |symbols_hash|
14
- expect { Plurimath::Math.parse(symbols_hash.dig("mathml"), :mathml) }.not_to raise_error
12
+ it "parses successfully" do
13
+ symbols = unit_data["symbols"].flatten.compact
14
+ symbols.each do |symbols_hash|
15
+ expect { Plurimath::Math.parse(symbols_hash["mathml"], :mathml) }.not_to raise_error
15
16
  end
16
17
  end
17
18
  end
@@ -1,16 +1,74 @@
1
+ # yaml-language-server: $schema=schemas/unit_systems-schema.yaml
1
2
  ---
2
- - id: SI_base
3
- name: SI
4
- acceptable: true
5
- - id: SI_derived_special
6
- name: SI
7
- acceptable: true
8
- - id: SI_derived_non-special
9
- name: SI
10
- acceptable: true
11
- - id: non-SI_acceptable
12
- name: non-SI
13
- acceptable: true
14
- - id: non-SI_not_acceptable
15
- name: non-SI
16
- acceptable: false
3
+ schema_version: 2.0.0
4
+ unit_systems:
5
+ - acceptable: true
6
+ identifiers:
7
+ - type: nist
8
+ id: SI_base
9
+ - type: unitsml
10
+ id: us:si-base
11
+ names:
12
+ - value: SI base units
13
+ lang: en
14
+ short: si-base
15
+ - acceptable: true
16
+ identifiers:
17
+ - type: nist
18
+ id: SI_compatible
19
+ - type: unitsml
20
+ id: us:si-compatible
21
+ names:
22
+ - value: Units compatible with SI
23
+ lang: en
24
+ short: si-compatible
25
+ - acceptable: true
26
+ identifiers:
27
+ - type: nist
28
+ id: SI_derived_non-special
29
+ - type: unitsml
30
+ id: us:si-derived-nonspecial
31
+ names:
32
+ - value: SI-derived units non-special
33
+ lang: en
34
+ short: si-derived-nonspecial
35
+ - acceptable: true
36
+ identifiers:
37
+ - type: nist
38
+ id: SI_derived_special
39
+ - type: unitsml
40
+ id: us:si-derived-special
41
+ names:
42
+ - value: SI-derived units special
43
+ lang: en
44
+ short: si-derived-special
45
+ - acceptable: true
46
+ identifiers:
47
+ - type: nist
48
+ id: non-SI_acceptable
49
+ - type: unitsml
50
+ id: us:nonsi-acceptable
51
+ names:
52
+ - value: non-SI but acceptable
53
+ lang: en
54
+ short: nonsi-acceptable
55
+ - acceptable: true
56
+ identifiers:
57
+ - type: nist
58
+ id: non-SI_nist_acceptable
59
+ - type: unitsml
60
+ id: us:nonsi-nist-acceptable
61
+ names:
62
+ - value: non-SI but acceptable by NIST SP 811
63
+ lang: en
64
+ short: nonsi-nist-acceptable
65
+ - acceptable: false
66
+ identifiers:
67
+ - type: nist
68
+ id: non-SI_not_acceptable
69
+ - type: unitsml
70
+ id: us:nonsi-unacceptable
71
+ names:
72
+ - value: non-SI and not acceptable
73
+ lang: en
74
+ short: nonsi-unacceptable