unitsdb 2.2.1 → 2.2.4

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/opal.yml +36 -0
  3. data/.gitignore +3 -0
  4. data/Gemfile +1 -0
  5. data/Rakefile +3 -1
  6. data/lib/unitsdb/cli.rb +5 -41
  7. data/lib/unitsdb/commands/_modify.rb +1 -34
  8. data/lib/unitsdb/commands/check_si/si_formatter.rb +6 -6
  9. data/lib/unitsdb/commands/check_si/si_matcher.rb +202 -292
  10. data/lib/unitsdb/commands/check_si/si_updater.rb +16 -36
  11. data/lib/unitsdb/commands/entity_presenter.rb +98 -0
  12. data/lib/unitsdb/commands/get.rb +16 -113
  13. data/lib/unitsdb/commands/qudt/formatter.rb +16 -27
  14. data/lib/unitsdb/commands/qudt/matcher.rb +18 -28
  15. data/lib/unitsdb/commands/qudt/updater.rb +8 -11
  16. data/lib/unitsdb/commands/qudt.rb +1 -34
  17. data/lib/unitsdb/commands/search.rb +33 -188
  18. data/lib/unitsdb/commands/thor.rb +41 -0
  19. data/lib/unitsdb/commands/ucum/formatter.rb +9 -18
  20. data/lib/unitsdb/commands/ucum/matcher.rb +4 -4
  21. data/lib/unitsdb/commands/ucum/updater.rb +3 -5
  22. data/lib/unitsdb/commands/ucum.rb +1 -34
  23. data/lib/unitsdb/commands/validate/qudt_references.rb +29 -70
  24. data/lib/unitsdb/commands/validate/references.rb +5 -303
  25. data/lib/unitsdb/commands/validate/si_references.rb +30 -66
  26. data/lib/unitsdb/commands/validate/ucum_references.rb +30 -64
  27. data/lib/unitsdb/commands/validate.rb +1 -36
  28. data/lib/unitsdb/commands.rb +2 -0
  29. data/lib/unitsdb/config.rb +170 -4
  30. data/lib/unitsdb/database/loader.rb +135 -0
  31. data/lib/unitsdb/database/reference_validator.rb +227 -0
  32. data/lib/unitsdb/database/uniqueness_validator.rb +80 -0
  33. data/lib/unitsdb/database.rb +127 -588
  34. data/lib/unitsdb/dimension.rb +2 -27
  35. data/lib/unitsdb/dimension_details.rb +2 -0
  36. data/lib/unitsdb/dimension_reference.rb +2 -0
  37. data/lib/unitsdb/dimensions.rb +2 -2
  38. data/lib/unitsdb/external_reference.rb +2 -0
  39. data/lib/unitsdb/identifier.rb +2 -0
  40. data/lib/unitsdb/localized_string.rb +2 -0
  41. data/lib/unitsdb/opal.rb +43 -0
  42. data/lib/unitsdb/prefix.rb +2 -13
  43. data/lib/unitsdb/prefix_reference.rb +2 -0
  44. data/lib/unitsdb/prefixes.rb +2 -2
  45. data/lib/unitsdb/quantities.rb +2 -1
  46. data/lib/unitsdb/quantity.rb +2 -2
  47. data/lib/unitsdb/quantity_reference.rb +2 -2
  48. data/lib/unitsdb/qudt.rb +5 -0
  49. data/lib/unitsdb/root_unit_reference.rb +2 -2
  50. data/lib/unitsdb/scale.rb +2 -2
  51. data/lib/unitsdb/scale_properties.rb +2 -1
  52. data/lib/unitsdb/scale_reference.rb +2 -0
  53. data/lib/unitsdb/scales.rb +2 -1
  54. data/lib/unitsdb/si_derived_base.rb +2 -1
  55. data/lib/unitsdb/symbol_presentations.rb +2 -2
  56. data/lib/unitsdb/ucum.rb +7 -0
  57. data/lib/unitsdb/unit.rb +2 -34
  58. data/lib/unitsdb/unit_reference.rb +2 -0
  59. data/lib/unitsdb/unit_system.rb +2 -2
  60. data/lib/unitsdb/unit_system_reference.rb +2 -0
  61. data/lib/unitsdb/unit_systems.rb +2 -2
  62. data/lib/unitsdb/units.rb +2 -2
  63. data/lib/unitsdb/version.rb +1 -1
  64. data/lib/unitsdb.rb +134 -27
  65. data/unitsdb.gemspec +1 -0
  66. metadata +23 -2
@@ -1,34 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # NISTd1:
4
- # length:
5
- # power: 1
6
- # symbol: L
7
- # dim_symbols:
8
- # - id: "dim_L"
9
- # ascii: "L"
10
- # html: "𝖫"
11
- # mathml: "<mi mathvariant='sans-serif'>L</mi>"
12
- # latex: \ensuremath{\mathsf{L}}
13
- # unicode: "𝖫"
14
-
15
- # NISTd9:
16
- # -dimensionless: true
17
- # -plane_angle:
18
- # - dim_symbols:
19
- # - - ascii: phi
20
- # - html: "&#x1D785;"
21
- # - id: dim_phi
22
- # - latex: "\\ensuremath{\\mathsf{\\phi}}"
23
- # - mathml: "<mi mathvariant='sans-serif'>&#x3c6;</mi>"
24
- # - unicode: "\U0001D785"
25
- # - power: 1
26
- # - symbol: phi
27
-
28
3
  module Unitsdb
29
4
  class Dimension < Lutaml::Model::Serializable
30
- # model Config.model_for(:dimension)
31
-
32
5
  attribute :identifiers, Identifier, collection: true
33
6
  attribute :dimensionless, :boolean
34
7
  attribute :length, DimensionDetails
@@ -43,4 +16,6 @@ module Unitsdb
43
16
  attribute :names, LocalizedString, collection: true
44
17
  attribute :references, ExternalReference, collection: true
45
18
  end
19
+
20
+ Config.register_model(Dimension, id: :dimension)
46
21
  end
@@ -16,4 +16,6 @@ module Unitsdb
16
16
  attribute :symbol, :string
17
17
  attribute :symbols, SymbolPresentations, collection: true
18
18
  end
19
+
20
+ Config.register_model(DimensionDetails, id: :dimension_details)
19
21
  end
@@ -5,4 +5,6 @@ module Unitsdb
5
5
  attribute :id, :string
6
6
  attribute :type, :string
7
7
  end
8
+
9
+ Config.register_model(DimensionReference, id: :dimension_reference)
8
10
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Unitsdb
4
4
  class Dimensions < Lutaml::Model::Serializable
5
- # model Config.model_for(:dimensions)
6
-
7
5
  attribute :schema_version, :string
8
6
  attribute :version, :string
9
7
  attribute :dimensions, Dimension, collection: true
10
8
  end
9
+
10
+ Config.register_model(Dimensions, id: :dimensions)
11
11
  end
@@ -11,4 +11,6 @@ module Unitsdb
11
11
  attribute :type, :string, values: %w[normative informative]
12
12
  attribute :authority, :string
13
13
  end
14
+
15
+ Config.register_model(ExternalReference, id: :external_reference)
14
16
  end
@@ -5,4 +5,6 @@ module Unitsdb
5
5
  attribute :id, :string
6
6
  attribute :type, :string
7
7
  end
8
+
9
+ Config.register_model(Identifier, id: :identifier)
8
10
  end
@@ -14,4 +14,6 @@ module Unitsdb
14
14
  value&.downcase
15
15
  end
16
16
  end
17
+
18
+ Config.register_model(LocalizedString, id: :localized_string)
17
19
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Opal entry point for unitsdb.
4
+ #
5
+ # Under MRI, lib/unitsdb.rb uses autoload for lazy loading. Under Opal,
6
+ # autoload does not lazy-execute, so a single eager-require file lists
7
+ # every entry point the consumer (unitsml-ruby, plurimath-js) needs.
8
+ # Consumers add `-r unitsdb/opal` to their Opal compile command.
9
+
10
+ require "lutaml/model"
11
+ require "unitsdb"
12
+ require "unitsdb/config"
13
+ require "unitsdb/identifier"
14
+ require "unitsdb/localized_string"
15
+ require "unitsdb/symbol_presentations"
16
+ require "unitsdb/scale_properties"
17
+ require "unitsdb/unit_reference"
18
+ require "unitsdb/prefix_reference"
19
+ require "unitsdb/quantity_reference"
20
+ require "unitsdb/dimension_reference"
21
+ require "unitsdb/unit_system_reference"
22
+ require "unitsdb/scale_reference"
23
+ require "unitsdb/external_reference"
24
+ require "unitsdb/root_unit_reference"
25
+ require "unitsdb/si_derived_base"
26
+ require "unitsdb/dimension_details"
27
+ require "unitsdb/dimension"
28
+ require "unitsdb/prefix"
29
+ require "unitsdb/unit_system"
30
+ require "unitsdb/quantity"
31
+ require "unitsdb/scale"
32
+ require "unitsdb/unit"
33
+ require "unitsdb/dimensions"
34
+ require "unitsdb/prefixes"
35
+ require "unitsdb/quantities"
36
+ require "unitsdb/scales"
37
+ require "unitsdb/unit_systems"
38
+ require "unitsdb/units"
39
+ require "unitsdb/database"
40
+ require "unitsdb/qudt"
41
+ require "unitsdb/ucum"
42
+ require "unitsdb/errors"
43
+ require "unitsdb/utils"
@@ -1,20 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # ---
4
- # NISTp10_30:
5
- # name: quetta
6
- # symbol:
7
- # ascii: Q
8
- # html: Q
9
- # latex: Q
10
- # unicode: Q
11
- # base: 10
12
- # power: 30
13
-
14
3
  module Unitsdb
15
4
  class Prefix < Lutaml::Model::Serializable
16
- # model Config.model_for(:prefix)
17
-
18
5
  attribute :identifiers, Identifier, collection: true
19
6
  attribute :names, LocalizedString, collection: true
20
7
  attribute :short, :string
@@ -23,4 +10,6 @@ module Unitsdb
23
10
  attribute :power, :integer
24
11
  attribute :references, ExternalReference, collection: true
25
12
  end
13
+
14
+ Config.register_model(Prefix, id: :prefix)
26
15
  end
@@ -5,4 +5,6 @@ module Unitsdb
5
5
  attribute :id, :string
6
6
  attribute :type, :string
7
7
  end
8
+
9
+ Config.register_model(PrefixReference, id: :prefix_reference)
8
10
  end
@@ -13,10 +13,10 @@
13
13
 
14
14
  module Unitsdb
15
15
  class Prefixes < Lutaml::Model::Serializable
16
- # model Config.model_for(:prefixes)
17
-
18
16
  attribute :schema_version, :string
19
17
  attribute :version, :string
20
18
  attribute :prefixes, Prefix, collection: true
21
19
  end
20
+
21
+ Config.register_model(Prefixes, id: :prefixes)
22
22
  end
@@ -2,9 +2,10 @@
2
2
 
3
3
  module Unitsdb
4
4
  class Quantities < Lutaml::Model::Serializable
5
- # model Config.model_for(:quantities)
6
5
  attribute :schema_version, :string
7
6
  attribute :version, :string
8
7
  attribute :quantities, Quantity, collection: true
9
8
  end
9
+
10
+ Config.register_model(Quantities, id: :quantities)
10
11
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module Unitsdb
4
4
  class Quantity < Lutaml::Model::Serializable
5
- # model Config.model_for(:quantity)
6
-
7
5
  attribute :identifiers, Identifier, collection: true
8
6
  attribute :quantity_type, :string
9
7
  attribute :names, LocalizedString, collection: true
@@ -12,4 +10,6 @@ module Unitsdb
12
10
  attribute :dimension_reference, DimensionReference
13
11
  attribute :references, ExternalReference, collection: true
14
12
  end
13
+
14
+ Config.register_model(Quantity, id: :quantity)
15
15
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Unitsdb
4
4
  class QuantityReference < Identifier
5
- # model Config.model_for(:quantity_reference)
6
-
7
5
  attribute :id, :string
8
6
  attribute :type, :string
9
7
  end
8
+
9
+ Config.register_model(QuantityReference, id: :quantity_reference)
10
10
  end
data/lib/unitsdb/qudt.rb CHANGED
@@ -18,6 +18,7 @@ module Unitsdb
18
18
  "qudt:unit:#{uri}"
19
19
  end
20
20
  end
21
+ Config.register_model(QudtUnit, id: :qudt_unit)
21
22
 
22
23
  # QUDT QuantityKind from quantitykinds vocabulary
23
24
  # Example: http://qudt.org/vocab/quantitykind/Length
@@ -33,6 +34,7 @@ module Unitsdb
33
34
  "qudt:quantitykind:#{uri}"
34
35
  end
35
36
  end
37
+ Config.register_model(QudtQuantityKind, id: :qudt_quantity_kind)
36
38
 
37
39
  # QUDT DimensionVector from dimensionvectors vocabulary
38
40
  # Example: http://qudt.org/vocab/dimensionvector/A0E0L1I0M0H0T0D0
@@ -52,6 +54,7 @@ module Unitsdb
52
54
  "qudt:dimensionvector:#{uri}"
53
55
  end
54
56
  end
57
+ Config.register_model(QudtDimensionVector, id: :qudt_dimension_vector)
55
58
 
56
59
  # QUDT SystemOfUnits from sou vocabulary
57
60
  # Example: http://qudt.org/vocab/sou/SI
@@ -65,6 +68,7 @@ module Unitsdb
65
68
  "qudt:sou:#{uri}"
66
69
  end
67
70
  end
71
+ Config.register_model(QudtSystemOfUnits, id: :qudt_system_of_units)
68
72
 
69
73
  # QUDT Prefix from prefixes vocabulary
70
74
  # Example: http://qudt.org/vocab/prefix/Kilo
@@ -83,6 +87,7 @@ module Unitsdb
83
87
  "qudt:prefix:#{uri}"
84
88
  end
85
89
  end
90
+ Config.register_model(QudtPrefix, id: :qudt_prefix)
86
91
 
87
92
  # Container for all QUDT vocabularies
88
93
  class QudtVocabularies
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Unitsdb
4
4
  class RootUnitReference < Lutaml::Model::Serializable
5
- # model Config.model_for(:root_unit)
6
-
7
5
  attribute :power, :integer
8
6
  attribute :unit_reference, UnitReference
9
7
  attribute :prefix_reference, PrefixReference
10
8
  end
9
+
10
+ Config.register_model(RootUnitReference, id: :root_unit_reference)
11
11
  end
data/lib/unitsdb/scale.rb CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  module Unitsdb
4
4
  class Scale < Lutaml::Model::Serializable
5
- # model Config.model_for(:quantity)
6
-
7
5
  attribute :identifiers, Identifier, collection: true
8
6
  attribute :names, LocalizedString, collection: true
9
7
  attribute :description, LocalizedString, collection: true
10
8
  attribute :short, :string
11
9
  attribute :properties, ScaleProperties
12
10
  end
11
+
12
+ Config.register_model(Scale, id: :scale)
13
13
  end
@@ -2,11 +2,12 @@
2
2
 
3
3
  module Unitsdb
4
4
  class ScaleProperties < Lutaml::Model::Serializable
5
- # model Config.model_for(:quantity)
6
5
  attribute :continuous, :boolean
7
6
  attribute :ordered, :boolean
8
7
  attribute :logarithmic, :boolean
9
8
  attribute :interval, :boolean
10
9
  attribute :ratio, :boolean
11
10
  end
11
+
12
+ Config.register_model(ScaleProperties, id: :scale_properties)
12
13
  end
@@ -5,4 +5,6 @@ module Unitsdb
5
5
  attribute :id, :string
6
6
  attribute :type, :string
7
7
  end
8
+
9
+ Config.register_model(ScaleReference, id: :scale_reference)
8
10
  end
@@ -2,9 +2,10 @@
2
2
 
3
3
  module Unitsdb
4
4
  class Scales < Lutaml::Model::Serializable
5
- # model Config.model_for(:Scale)
6
5
  attribute :schema_version, :string
7
6
  attribute :version, :string
8
7
  attribute :scales, Scale, collection: true
9
8
  end
9
+
10
+ Config.register_model(Scales, id: :scales)
10
11
  end
@@ -12,6 +12,7 @@
12
12
 
13
13
  module Unitsdb
14
14
  class SiDerivedBase < RootUnitReference
15
- # model Config.model_for(:si_derived_base)
16
15
  end
16
+
17
+ Config.register_model(SiDerivedBase, id: :si_derived_base)
17
18
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module Unitsdb
4
4
  class SymbolPresentations < Lutaml::Model::Serializable
5
- # model Config.model_for(:symbol_presentations)
6
-
7
5
  attribute :id, :string
8
6
  attribute :ascii, :string
9
7
  attribute :html, :string
@@ -11,4 +9,6 @@ module Unitsdb
11
9
  attribute :mathml, :string
12
10
  attribute :unicode, :string
13
11
  end
12
+
13
+ Config.register_model(SymbolPresentations, id: :symbol_presentations)
14
14
  end
data/lib/unitsdb/ucum.rb CHANGED
@@ -28,6 +28,7 @@ module Unitsdb
28
28
  "ucum:base-unit:code:#{code_sensitive}"
29
29
  end
30
30
  end
31
+ Config.register_model(UcumBaseUnit, id: :ucum_base_unit)
31
32
 
32
33
  # <prefix Code="Y" CODE="YA">
33
34
  # <name>yotta</name>
@@ -46,6 +47,7 @@ module Unitsdb
46
47
  map_content to: :content
47
48
  end
48
49
  end
50
+ Config.register_model(UcumPrefixValue, id: :ucum_prefix_value)
49
51
 
50
52
  class UcumPrefix < Lutaml::Model::Serializable
51
53
  attribute :code_sensitive, :string
@@ -67,6 +69,7 @@ module Unitsdb
67
69
  "ucum:prefix:code:#{code_sensitive}"
68
70
  end
69
71
  end
72
+ Config.register_model(UcumPrefix, id: :ucum_prefix)
70
73
 
71
74
  # <unit Code="10*" CODE="10*" isMetric="no" class="dimless">
72
75
  # <name>the number ten for arbitrary powers</name>
@@ -114,6 +117,7 @@ module Unitsdb
114
117
  map_attribute "Unit", to: :unit_sensitive
115
118
  end
116
119
  end
120
+ Config.register_model(UcumUnitValueFunction, id: :ucum_unit_value_function)
117
121
 
118
122
  class UcumUnitValue < Lutaml::Model::Serializable
119
123
  attribute :unit_sensitive, :string
@@ -131,6 +135,7 @@ module Unitsdb
131
135
  map_content to: :content
132
136
  end
133
137
  end
138
+ Config.register_model(UcumUnitValue, id: :ucum_unit_value)
134
139
 
135
140
  class UcumUnit < Lutaml::Model::Serializable
136
141
  attribute :code_sensitive, :string
@@ -165,6 +170,7 @@ module Unitsdb
165
170
  "ucum:unit:#{k}:code:#{code_sensitive}"
166
171
  end
167
172
  end
173
+ Config.register_model(UcumUnit, id: :ucum_unit)
168
174
 
169
175
  class UcumNamespace < Lutaml::Xml::Namespace
170
176
  uri "http://unitsofmeasure.org/ucum-essence"
@@ -199,4 +205,5 @@ module Unitsdb
199
205
 
200
206
  # No adapter registration needed
201
207
  end
208
+ Config.register_model(UcumFile, id: :ucum_file)
202
209
  end
data/lib/unitsdb/unit.rb CHANGED
@@ -1,41 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # "NISTu10":
4
- # dimension_url: "#NISTd9"
5
- # short: steradian
6
- # root: true
7
- # unit_system:
8
- # type: "SI_derived_special"
9
- # name: "SI"
10
- # names:
11
- # - "steradian"
12
- # unit_symbols:
13
- # - id: "sr"
14
- # ascii: "sr"
15
- # html: "sr"
16
- # mathml: "<mi mathvariant='normal'>sr</mi>"
17
- # latex: \ensuremath{\mathrm{sr}}
18
- # unicode: "sr"
19
- # root_units:
20
- # enumerated_root_units:
21
- # - unit: "steradian"
22
- # power_denominator: 1
23
- # power: 1
24
- # quantity_reference:
25
- # - name: "solid angle"
26
- # url: "#NISTq11"
27
- # si_derived_bases:
28
- # - id: NISTu1
29
- # prefix:
30
- # power: 1
31
- # - id: NISTu1
32
- # prefix:
33
- # power: -1
34
-
35
3
  module Unitsdb
36
4
  class Unit < Lutaml::Model::Serializable
37
- # model Config.model_for(:unit)
38
-
39
5
  attribute :identifiers, Identifier, collection: true
40
6
  attribute :short, :string
41
7
  attribute :root, :boolean
@@ -50,4 +16,6 @@ module Unitsdb
50
16
  attribute :references, ExternalReference, collection: true
51
17
  attribute :scale_reference, ScaleReference
52
18
  end
19
+
20
+ Config.register_model(Unit, id: :unit)
53
21
  end
@@ -5,4 +5,6 @@ module Unitsdb
5
5
  attribute :id, :string
6
6
  attribute :type, :string
7
7
  end
8
+
9
+ Config.register_model(UnitReference, id: :unit_reference)
8
10
  end
@@ -2,12 +2,12 @@
2
2
 
3
3
  module Unitsdb
4
4
  class UnitSystem < Lutaml::Model::Serializable
5
- # model Config.model_for(:unit_system)
6
-
7
5
  attribute :identifiers, Identifier, collection: true
8
6
  attribute :names, LocalizedString, collection: true
9
7
  attribute :short, :string
10
8
  attribute :acceptable, :boolean
11
9
  attribute :references, ExternalReference, collection: true
12
10
  end
11
+
12
+ Config.register_model(UnitSystem, id: :unit_system)
13
13
  end
@@ -5,4 +5,6 @@ module Unitsdb
5
5
  attribute :id, :string
6
6
  attribute :type, :string
7
7
  end
8
+
9
+ Config.register_model(UnitSystemReference, id: :unit_system_reference)
8
10
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Unitsdb
4
4
  class UnitSystems < Lutaml::Model::Serializable
5
- # model Config.model_for(:unit_systems)
6
-
7
5
  attribute :schema_version, :string
8
6
  attribute :version, :string
9
7
  attribute :unit_systems, UnitSystem, collection: true
10
8
  end
9
+
10
+ Config.register_model(UnitSystems, id: :unit_systems)
11
11
  end
data/lib/unitsdb/units.rb CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Unitsdb
4
4
  class Units < Lutaml::Model::Serializable
5
- # model Config.model_for(:units)
6
-
7
5
  attribute :schema_version, :string
8
6
  attribute :version, :string
9
7
  attribute :units, Unit, collection: true
10
8
  end
9
+
10
+ Config.register_model(Units, id: :units)
11
11
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Unitsdb
4
- VERSION = "2.2.1"
4
+ VERSION = "2.2.4"
5
5
 
6
6
  # The version of the bundled UnitsDB data (from the data/ submodule).
7
7
  # This version corresponds to a tag/commit in https://github.com/unitsml/unitsdb.