unitsdb 2.1.0 → 2.2.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/.github/workflows/release.yml +8 -1
- data/.gitignore +2 -0
- data/.gitmodules +4 -3
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +247 -53
- data/CLAUDE.md +55 -0
- data/Gemfile +5 -1
- data/README.adoc +385 -12
- data/data/dimensions.yaml +1864 -0
- data/data/prefixes.yaml +874 -0
- data/data/quantities.yaml +3715 -0
- data/data/scales.yaml +97 -0
- data/data/schemas/dimensions-schema.yaml +153 -0
- data/data/schemas/prefixes-schema.yaml +155 -0
- data/data/schemas/quantities-schema.yaml +117 -0
- data/data/schemas/scales-schema.yaml +106 -0
- data/data/schemas/unit_systems-schema.yaml +116 -0
- data/data/schemas/units-schema.yaml +215 -0
- data/data/unit_systems.yaml +78 -0
- data/data/units.yaml +14052 -0
- data/exe/unitsdb +7 -1
- data/lib/unitsdb/cli.rb +47 -13
- data/lib/unitsdb/commands/_modify.rb +41 -5
- data/lib/unitsdb/commands/base.rb +10 -32
- data/lib/unitsdb/commands/check_si/si_formatter.rb +488 -0
- data/lib/unitsdb/commands/check_si/si_matcher.rb +487 -0
- data/lib/unitsdb/commands/check_si/si_ttl_parser.rb +103 -0
- data/lib/unitsdb/commands/check_si/si_updater.rb +254 -0
- data/lib/unitsdb/commands/check_si.rb +54 -35
- data/lib/unitsdb/commands/get.rb +11 -10
- data/lib/unitsdb/commands/normalize.rb +21 -7
- data/lib/unitsdb/commands/qudt/check.rb +150 -0
- data/lib/unitsdb/commands/qudt/formatter.rb +194 -0
- data/lib/unitsdb/commands/qudt/matcher.rb +746 -0
- data/lib/unitsdb/commands/qudt/ttl_parser.rb +403 -0
- data/lib/unitsdb/commands/qudt/update.rb +126 -0
- data/lib/unitsdb/commands/qudt/updater.rb +189 -0
- data/lib/unitsdb/commands/qudt.rb +82 -0
- data/lib/unitsdb/commands/release.rb +50 -86
- data/lib/unitsdb/commands/search.rb +12 -11
- data/lib/unitsdb/commands/ucum/check.rb +139 -0
- data/lib/unitsdb/commands/ucum/formatter.rb +142 -0
- data/lib/unitsdb/commands/ucum/matcher.rb +315 -0
- data/lib/unitsdb/commands/ucum/update.rb +85 -0
- data/lib/unitsdb/commands/ucum/updater.rb +132 -0
- data/lib/unitsdb/commands/ucum/xml_parser.rb +32 -0
- data/lib/unitsdb/commands/ucum.rb +83 -0
- data/lib/unitsdb/commands/validate/identifiers.rb +3 -3
- data/lib/unitsdb/commands/validate/qudt_references.rb +111 -0
- data/lib/unitsdb/commands/validate/references.rb +37 -18
- data/lib/unitsdb/commands/validate/si_references.rb +3 -11
- data/lib/unitsdb/commands/validate/ucum_references.rb +105 -0
- data/lib/unitsdb/commands/validate.rb +67 -11
- data/lib/unitsdb/commands.rb +20 -0
- data/lib/unitsdb/database.rb +91 -52
- data/lib/unitsdb/dimension.rb +1 -4
- data/lib/unitsdb/dimension_details.rb +0 -1
- data/lib/unitsdb/dimensions.rb +1 -2
- data/lib/unitsdb/errors.rb +7 -0
- data/lib/unitsdb/prefix.rb +0 -4
- data/lib/unitsdb/prefix_reference.rb +0 -2
- data/lib/unitsdb/prefixes.rb +1 -1
- data/lib/unitsdb/quantities.rb +1 -2
- data/lib/unitsdb/quantity.rb +0 -6
- data/lib/unitsdb/qudt.rb +100 -0
- data/lib/unitsdb/root_unit_reference.rb +0 -3
- data/lib/unitsdb/scale.rb +0 -4
- data/lib/unitsdb/scale_reference.rb +0 -2
- data/lib/unitsdb/scales.rb +1 -2
- data/lib/unitsdb/si_derived_base.rb +0 -2
- data/lib/unitsdb/ucum.rb +202 -0
- data/lib/unitsdb/unit.rb +0 -10
- data/lib/unitsdb/unit_reference.rb +0 -2
- data/lib/unitsdb/unit_system.rb +1 -3
- data/lib/unitsdb/unit_system_reference.rb +0 -2
- data/lib/unitsdb/unit_systems.rb +1 -2
- data/lib/unitsdb/units.rb +1 -2
- data/lib/unitsdb/utils.rb +32 -21
- data/lib/unitsdb/version.rb +5 -1
- data/lib/unitsdb.rb +62 -14
- data/unitsdb.gemspec +6 -5
- metadata +60 -13
- data/lib/unitsdb/commands/si_formatter.rb +0 -485
- data/lib/unitsdb/commands/si_matcher.rb +0 -470
- data/lib/unitsdb/commands/si_ttl_parser.rb +0 -100
- data/lib/unitsdb/commands/si_updater.rb +0 -212
data/README.adoc
CHANGED
|
@@ -19,6 +19,11 @@ https://github.com/unitsml/unitsdb.
|
|
|
19
19
|
This repository contains the Ruby codebase for UnitsDB, which is used
|
|
20
20
|
to access and manipulate the UnitsDB content.
|
|
21
21
|
|
|
22
|
+
The UnitsDB gem ships with the UnitsDB data bundled internally. When you install
|
|
23
|
+
the gem, the YAML data files are included automatically, so you do not need to
|
|
24
|
+
obtain or configure a separate data source. The data is accessed via
|
|
25
|
+
`Unitsdb.data_dir` or the convenience method `Unitsdb.database`.
|
|
26
|
+
|
|
22
27
|
== Install
|
|
23
28
|
|
|
24
29
|
[source,sh]
|
|
@@ -26,7 +31,79 @@ to access and manipulate the UnitsDB content.
|
|
|
26
31
|
$ gem install unitsdb
|
|
27
32
|
----
|
|
28
33
|
|
|
34
|
+
The UnitsDB gem ships with the UnitsDB YAML data files bundled inside the gem.
|
|
35
|
+
Because the gem bundles immutable data, **the UnitsDB data must be released
|
|
36
|
+
(tagged) before the gem can be released with updated data**. The gem version
|
|
37
|
+
(`Unitsdb::VERSION`) and the data version (`Unitsdb::UNITS_DATA_VERSION`)
|
|
38
|
+
are independent: the gem can be patched without changing data, and the data
|
|
39
|
+
can be updated independently of the gem.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
== How the Database Works
|
|
44
|
+
|
|
45
|
+
The `Unitsdb::Database` class loads all UnitsDB YAML files and provides
|
|
46
|
+
methods for searching and querying the data.
|
|
47
|
+
|
|
48
|
+
[source,ruby]
|
|
49
|
+
----
|
|
50
|
+
require 'unitsdb'
|
|
51
|
+
|
|
52
|
+
# Access the pre-loaded bundled database (recommended)
|
|
53
|
+
db = Unitsdb.database
|
|
54
|
+
|
|
55
|
+
# Or load from a specific path
|
|
56
|
+
db = Unitsdb::Database.from_db('/path/to/data')
|
|
57
|
+
----
|
|
29
58
|
|
|
59
|
+
=== Lazy Loading and Caching
|
|
60
|
+
|
|
61
|
+
The bundled database (`Unitsdb.database`) is loaded on first access and cached
|
|
62
|
+
for subsequent calls. The path to the bundled data is available via:
|
|
63
|
+
|
|
64
|
+
[source,ruby]
|
|
65
|
+
----
|
|
66
|
+
Unitsdb.data_dir # => Path to the data/ directory inside the gem
|
|
67
|
+
----
|
|
68
|
+
|
|
69
|
+
=== Database Structure
|
|
70
|
+
|
|
71
|
+
The database contains collections for each entity type:
|
|
72
|
+
|
|
73
|
+
[source,ruby]
|
|
74
|
+
----
|
|
75
|
+
db.units # Array of Unit objects
|
|
76
|
+
db.prefixes # Array of Prefix objects
|
|
77
|
+
db.dimensions # Array of Dimension objects
|
|
78
|
+
db.quantities # Array of Quantity objects
|
|
79
|
+
db.unit_systems # Array of UnitSystem objects
|
|
80
|
+
db.scales # Array of Scale objects
|
|
81
|
+
----
|
|
82
|
+
|
|
83
|
+
=== Searching the Database
|
|
84
|
+
|
|
85
|
+
[source,ruby]
|
|
86
|
+
----
|
|
87
|
+
# Search by text (searches names, identifiers, descriptions)
|
|
88
|
+
results = db.search(text: "meter")
|
|
89
|
+
|
|
90
|
+
# Find by exact ID
|
|
91
|
+
unit = db.get_by_id(id: "NISTu1")
|
|
92
|
+
|
|
93
|
+
# Find by symbol
|
|
94
|
+
units = db.find_by_symbol("m")
|
|
95
|
+
----
|
|
96
|
+
|
|
97
|
+
=== Validation
|
|
98
|
+
|
|
99
|
+
[source,ruby]
|
|
100
|
+
----
|
|
101
|
+
# Check identifier uniqueness
|
|
102
|
+
dups = db.validate_uniqueness
|
|
103
|
+
|
|
104
|
+
# Validate all references exist
|
|
105
|
+
invalid_refs = db.validate_references
|
|
106
|
+
----
|
|
30
107
|
|
|
31
108
|
== UnitsDB version support
|
|
32
109
|
|
|
@@ -38,6 +115,24 @@ The version of the YAML files are stored in the `version` field of the `*.yaml`
|
|
|
38
115
|
files. The library checks this version when loading the database and raises an
|
|
39
116
|
error if the version is not 2.0.0.
|
|
40
117
|
|
|
118
|
+
The `unitsdb-ruby` gem version tracks the bundled data version via
|
|
119
|
+
`Unitsdb::UNITS_DATA_VERSION`. For example, `unitsdb-ruby v2.1.2` bundles
|
|
120
|
+
`unitsdb` data at `v2.0.0`. When the gem is released with an updated data
|
|
121
|
+
submodule, both the gem version and `UNITS_DATA_VERSION` are updated together.
|
|
122
|
+
|
|
123
|
+
The `data/` submodule is pinned to a specific tag in the
|
|
124
|
+
https://github.com/unitsml/unitsdb[UnitsDB repository] (e.g. `refs/tags/v2.0.0`).
|
|
125
|
+
This means:
|
|
126
|
+
|
|
127
|
+
* Every bundled version of `unitsdb-ruby` ships with a known, immutable version
|
|
128
|
+
of the UnitsDB data.
|
|
129
|
+
* A new `unitsdb-ruby` release can only be made after the upstream UnitsDB data
|
|
130
|
+
has been released (tagged) in its own repository.
|
|
131
|
+
* To release a new gem with updated data: tag the new data in
|
|
132
|
+
`unitsml/unitsdb`, update the submodule's `branch` in `.gitmodules` to point
|
|
133
|
+
to `refs/tags/new-data-tag`, update `UNITS_DATA_VERSION`, then bump the gem
|
|
134
|
+
version and release.
|
|
135
|
+
|
|
41
136
|
=== UnitsDB 2.0.0 features
|
|
42
137
|
|
|
43
138
|
==== General
|
|
@@ -101,6 +196,7 @@ Syntax:
|
|
|
101
196
|
[source,yaml]
|
|
102
197
|
----
|
|
103
198
|
schema_version: 2.0.0
|
|
199
|
+
version: 1.0.0 # Release version (in semantic format x.y.z)
|
|
104
200
|
dimensions:
|
|
105
201
|
- identifiers: [...]
|
|
106
202
|
length: {...}
|
|
@@ -224,6 +320,29 @@ Options:
|
|
|
224
320
|
|
|
225
321
|
`--database`, `-d`:: Path to UnitsDB database (required)
|
|
226
322
|
|
|
323
|
+
===== QUDT references validation
|
|
324
|
+
|
|
325
|
+
Validates that each QUDT reference is unique per entity type:
|
|
326
|
+
|
|
327
|
+
[source,sh]
|
|
328
|
+
----
|
|
329
|
+
$ unitsdb validate qudt_references --database=/path/to/unitsdb/data
|
|
330
|
+
----
|
|
331
|
+
|
|
332
|
+
This command checks that each QUDT (Quantities, Units, Dimensions and Types) URI is referenced by at most
|
|
333
|
+
one entity of each type. Multiple entities of the same type referencing the same
|
|
334
|
+
QUDT URI could cause issues with mapping and conversion processes.
|
|
335
|
+
|
|
336
|
+
The command reports:
|
|
337
|
+
|
|
338
|
+
* Any duplicate QUDT references within each entity type
|
|
339
|
+
* The entities that share the same QUDT reference
|
|
340
|
+
* Their position in the database for easy location
|
|
341
|
+
|
|
342
|
+
Options:
|
|
343
|
+
|
|
344
|
+
`--database`, `-d`:: Path to UnitsDB database (required)
|
|
345
|
+
|
|
227
346
|
=== Examples of validation commands
|
|
228
347
|
|
|
229
348
|
* Check identifiers for uniqueness:
|
|
@@ -269,7 +388,7 @@ Options:
|
|
|
269
388
|
|
|
270
389
|
`--all`, `-a`:: Process all YAML files in the repository
|
|
271
390
|
`--database`, `-d`:: Path to UnitsDB database (required)
|
|
272
|
-
`--sort`:: Sort units by: 'short' (name
|
|
391
|
+
`--sort`:: Sort units by: 'short' (name), 'nist' (ID, default), 'unitsml' (ID), or 'none'
|
|
273
392
|
|
|
274
393
|
|
|
275
394
|
==== Search
|
|
@@ -340,27 +459,27 @@ entities
|
|
|
340
459
|
[source,sh]
|
|
341
460
|
----
|
|
342
461
|
# Check all entity types and generate a report
|
|
343
|
-
$ unitsdb check_si --database=
|
|
462
|
+
$ unitsdb check_si --database=data --ttl-dir=spec/fixtures/bipm-si-ttl
|
|
344
463
|
|
|
345
464
|
# Check a specific entity type (units, quantities, or prefixes)
|
|
346
465
|
$ unitsdb check_si --entity-type=units \
|
|
347
|
-
--database=
|
|
466
|
+
--database=data \
|
|
348
467
|
--ttl-dir=spec/fixtures/bipm-si-ttl
|
|
349
468
|
|
|
350
469
|
# Check in a specific direction only
|
|
351
470
|
$ unitsdb check_si --direction=from_si \
|
|
352
|
-
--database=
|
|
471
|
+
--database=data \
|
|
353
472
|
--ttl-dir=spec/fixtures/bipm-si-ttl
|
|
354
473
|
|
|
355
474
|
# Update references and write to output directory
|
|
356
475
|
$ unitsdb check_si --output-updated-database=new_unitsdb \
|
|
357
|
-
--database=
|
|
476
|
+
--database=data \
|
|
358
477
|
--ttl-dir=spec/fixtures/bipm-si-ttl
|
|
359
478
|
|
|
360
479
|
# Include potential matches when updating references (default: false)
|
|
361
480
|
$ unitsdb check_si --include-potential-matches \
|
|
362
481
|
--output-updated-database=new_unitsdb \
|
|
363
|
-
--database=
|
|
482
|
+
--database=data \
|
|
364
483
|
--ttl-dir=spec/fixtures/bipm-si-ttl
|
|
365
484
|
----
|
|
366
485
|
|
|
@@ -383,6 +502,240 @@ with added SI references
|
|
|
383
502
|
`--include-potential-matches`, `-p`:: Include potential matches when updating
|
|
384
503
|
references (default: false)
|
|
385
504
|
|
|
505
|
+
|
|
506
|
+
==== Check references to UCUM
|
|
507
|
+
|
|
508
|
+
Performs a comprehensive check of entities in the UCUM XML file against UnitsDB
|
|
509
|
+
database entities and updates UnitsDB with UCUM references.
|
|
510
|
+
|
|
511
|
+
UCUM supports the following entity types:
|
|
512
|
+
|
|
513
|
+
* Base units
|
|
514
|
+
* Units
|
|
515
|
+
* Prefixes
|
|
516
|
+
|
|
517
|
+
UCUM provides dimensions as part of their unit definitions but not as
|
|
518
|
+
uniquely referencable entities.
|
|
519
|
+
|
|
520
|
+
This combined command checks in both directions to ensure UnitsDB supports
|
|
521
|
+
every UCUM entity:
|
|
522
|
+
|
|
523
|
+
* From UCUM to UnitsDB: Ensures every UCUM entity is referenced by at least one
|
|
524
|
+
UnitsDB entity
|
|
525
|
+
|
|
526
|
+
* From UnitsDB to UCUM: Identifies UnitsDB entities that should reference UCUM
|
|
527
|
+
entities
|
|
528
|
+
|
|
529
|
+
There are two commands:
|
|
530
|
+
|
|
531
|
+
* `ucum check`: Checks for matches between UnitsDB and UCUM entities and reports results
|
|
532
|
+
|
|
533
|
+
* `ucum update`: Updates UnitsDB entities with references to matching UCUM entities
|
|
534
|
+
|
|
535
|
+
[source,sh]
|
|
536
|
+
----
|
|
537
|
+
# Check all entity types and generate a report
|
|
538
|
+
$ unitsdb ucum check --database=data --ucum-file=spec/fixtures/ucum/ucum-essence.xml
|
|
539
|
+
|
|
540
|
+
# Check a specific entity type (units or prefixes)
|
|
541
|
+
$ unitsdb ucum check --entity-type=units \
|
|
542
|
+
--database=data \
|
|
543
|
+
--ucum-file=spec/fixtures/ucum/ucum-essence.xml
|
|
544
|
+
|
|
545
|
+
# Check in a specific direction only
|
|
546
|
+
$ unitsdb ucum check --direction=from_ucum \
|
|
547
|
+
--database=data \
|
|
548
|
+
--ucum-file=spec/fixtures/ucum/ucum-essence.xml
|
|
549
|
+
----
|
|
550
|
+
|
|
551
|
+
Options:
|
|
552
|
+
|
|
553
|
+
`--database`, `-d`:: Path to UnitsDB database (required)
|
|
554
|
+
|
|
555
|
+
`--ucum-file`, `-u`:: Path to the UCUM essence XML file (required)
|
|
556
|
+
|
|
557
|
+
`--entity-type`, `-e`:: Entity type to check (units or prefixes).
|
|
558
|
+
If not specified, all types are checked.
|
|
559
|
+
|
|
560
|
+
`--direction`, `-r`:: Direction to check: `to_ucum` (UnitsDB→UCUM), `from_ucum`
|
|
561
|
+
(UCUM→UnitsDB), or `both` (default)
|
|
562
|
+
|
|
563
|
+
`--output-updated-database`, `-o`:: Directory path to write updated YAML files
|
|
564
|
+
with added UCUM references
|
|
565
|
+
|
|
566
|
+
`--include-potential-matches`, `-p`:: Include potential matches when updating
|
|
567
|
+
references (default: false)
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
==== Update UCUM references
|
|
571
|
+
|
|
572
|
+
[source,sh]
|
|
573
|
+
----
|
|
574
|
+
# Update all entity types with UCUM references
|
|
575
|
+
$ unitsdb ucum update --database=data \
|
|
576
|
+
--ucum-file=spec/fixtures/ucum/ucum-essence.xml \
|
|
577
|
+
--output-dir=new_unitsdb
|
|
578
|
+
|
|
579
|
+
# Update a specific entity type (units or prefixes)
|
|
580
|
+
$ unitsdb ucum update --entity-type=units \
|
|
581
|
+
--database=data \
|
|
582
|
+
--ucum-file=spec/fixtures/ucum/ucum-essence.xml \
|
|
583
|
+
--output-dir=new_unitsdb
|
|
584
|
+
|
|
585
|
+
# Include potential matches when updating references (default: false)
|
|
586
|
+
$ unitsdb ucum update --include-potential-matches \
|
|
587
|
+
--database=data \
|
|
588
|
+
--ucum-file=spec/fixtures/ucum/ucum-essence.xml \
|
|
589
|
+
--output-dir=new_unitsdb
|
|
590
|
+
----
|
|
591
|
+
|
|
592
|
+
Options:
|
|
593
|
+
|
|
594
|
+
`--database`, `-d`:: Path to UnitsDB database (required)
|
|
595
|
+
|
|
596
|
+
`--ucum-file`, `-u`:: Path to the UCUM essence XML file (required)
|
|
597
|
+
|
|
598
|
+
`--entity-type`, `-e`:: Entity type to update (units or prefixes).
|
|
599
|
+
If not specified, all types are updated
|
|
600
|
+
|
|
601
|
+
`--output-dir`, `-o`:: Directory path to write updated YAML files
|
|
602
|
+
(defaults to database path)
|
|
603
|
+
|
|
604
|
+
`--include-potential-matches`, `-p`:: Include potential matches when updating
|
|
605
|
+
references (default: false)
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
==== Check references to QUDT
|
|
609
|
+
|
|
610
|
+
Performs a comprehensive check of entities in the
|
|
611
|
+
https://qudt.org/3.1.2/vocab/unit[QUDT] (Quantities, Units, Dimensions and
|
|
612
|
+
Types) vocabularies against UnitsDB database entities and updates UnitsDB with
|
|
613
|
+
QUDT references.
|
|
614
|
+
|
|
615
|
+
The support of QUDT mappings in the UnitsDB is purely informative.
|
|
616
|
+
|
|
617
|
+
QUDT supports the following entity types, and they are mapped to
|
|
618
|
+
UnitsDB as follows:
|
|
619
|
+
|
|
620
|
+
* Units: mapped to Units in UnitsDB
|
|
621
|
+
* Quantity Kinds: mapped to Quantities in UnitsDB
|
|
622
|
+
* Dimension Vectors: mapped to Dimensions in UnitsDB
|
|
623
|
+
* Systems of Units: mapped to Unit Systems in UnitsDB
|
|
624
|
+
* Prefixes: mapped to Prefixes in UnitsDB
|
|
625
|
+
* (Physical Constants: not supported in UnitsDB)
|
|
626
|
+
* (Systems of Quantity Kinds: not supported in UnitsDB)
|
|
627
|
+
|
|
628
|
+
The QUDT Vocabulary is very extensive and includes many entities that are not
|
|
629
|
+
reflected in the UnitsDB database, with the following categories:
|
|
630
|
+
|
|
631
|
+
* Many composed units in QUDT are omitted from UnitsDB for separation of
|
|
632
|
+
concerns;
|
|
633
|
+
|
|
634
|
+
* Some quantities are not included in UnitsDB for being less commonly used;
|
|
635
|
+
(e.g. "Deaths per million")
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
This combined command checks in both directions to ensure UnitsDB supports
|
|
639
|
+
every QUDT entity.
|
|
640
|
+
|
|
641
|
+
* From QUDT to UnitsDB: Ensures every QUDT entity is referenced by at least one
|
|
642
|
+
UnitsDB entity
|
|
643
|
+
|
|
644
|
+
* From UnitsDB to QUDT: Identifies UnitsDB entities that should reference QUDT
|
|
645
|
+
entities
|
|
646
|
+
|
|
647
|
+
There are two commands:
|
|
648
|
+
|
|
649
|
+
* `qudt check`: Checks for matches between UnitsDB and QUDT entities and reports results
|
|
650
|
+
|
|
651
|
+
* `qudt update`: Updates UnitsDB entities with references to matching QUDT entities
|
|
652
|
+
|
|
653
|
+
[source,sh]
|
|
654
|
+
----
|
|
655
|
+
# Check all entity types and generate a report
|
|
656
|
+
$ unitsdb qudt check --database=data
|
|
657
|
+
|
|
658
|
+
# Check a specific entity type (units, quantities, dimensions, or unit_systems)
|
|
659
|
+
$ unitsdb qudt check --entity-type=units \
|
|
660
|
+
--database=data
|
|
661
|
+
|
|
662
|
+
# Use local TTL files instead of downloading from QUDT.org
|
|
663
|
+
$ unitsdb qudt check --ttl-dir=/path/to/qudt/ttl/files \
|
|
664
|
+
--database=data
|
|
665
|
+
|
|
666
|
+
# Check in a specific direction only
|
|
667
|
+
$ unitsdb qudt check --direction=from_qudt \
|
|
668
|
+
--database=data
|
|
669
|
+
|
|
670
|
+
# Include potential matches in the output
|
|
671
|
+
$ unitsdb qudt check --include-potential-matches \
|
|
672
|
+
--database=data
|
|
673
|
+
|
|
674
|
+
# Output updated database files
|
|
675
|
+
$ unitsdb qudt check --output-dir=/path/to/output \
|
|
676
|
+
--database=data
|
|
677
|
+
----
|
|
678
|
+
|
|
679
|
+
Options:
|
|
680
|
+
|
|
681
|
+
`--database`, `-d`:: Path to UnitsDB database (required)
|
|
682
|
+
|
|
683
|
+
`--ttl-dir`, `-t`:: Path to the directory containing QUDT TTL files (optional,
|
|
684
|
+
downloads from QUDT.org if not specified)
|
|
685
|
+
|
|
686
|
+
`--entity-type`, `-e`:: Entity type to check (units, quantities, dimensions, or
|
|
687
|
+
unit_systems). If not specified, all types are checked.
|
|
688
|
+
|
|
689
|
+
`--direction`, `-r`:: Direction to check: `to_qudt` (UnitsDB→QUDT), `from_qudt`
|
|
690
|
+
(QUDT→UnitsDB), or `both` (default)
|
|
691
|
+
|
|
692
|
+
`--output-dir`, `-o`:: Directory path to write updated YAML files with added
|
|
693
|
+
QUDT references
|
|
694
|
+
|
|
695
|
+
`--include-potential-matches`, `-p`:: Include potential matches when updating
|
|
696
|
+
references (default: false)
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
==== Update QUDT references
|
|
700
|
+
|
|
701
|
+
[source,sh]
|
|
702
|
+
----
|
|
703
|
+
# Update all entity types with QUDT references
|
|
704
|
+
$ unitsdb qudt update --database=data \
|
|
705
|
+
--output-dir=new_unitsdb
|
|
706
|
+
|
|
707
|
+
# Update a specific entity type (units, quantities, dimensions, or unit_systems)
|
|
708
|
+
$ unitsdb qudt update --entity-type=units \
|
|
709
|
+
--database=data \
|
|
710
|
+
--output-dir=new_unitsdb
|
|
711
|
+
|
|
712
|
+
# Use local TTL files instead of downloading
|
|
713
|
+
$ unitsdb qudt update --ttl-dir=/path/to/qudt/ttl/files \
|
|
714
|
+
--database=data \
|
|
715
|
+
--output-dir=new_unitsdb
|
|
716
|
+
|
|
717
|
+
# Include potential matches when updating references (default: false)
|
|
718
|
+
$ unitsdb qudt update --include-potential-matches \
|
|
719
|
+
--database=data \
|
|
720
|
+
--output-dir=new_unitsdb
|
|
721
|
+
----
|
|
722
|
+
|
|
723
|
+
Options:
|
|
724
|
+
|
|
725
|
+
`--database`, `-d`:: Path to UnitsDB database (required)
|
|
726
|
+
|
|
727
|
+
`--ttl-dir`, `-t`:: Path to the directory containing QUDT TTL files (optional,
|
|
728
|
+
downloads from QUDT.org if not specified)
|
|
729
|
+
|
|
730
|
+
`--entity-type`, `-e`:: Entity type to update (units, quantities, dimensions, or
|
|
731
|
+
unit_systems). If not specified, all types are updated
|
|
732
|
+
|
|
733
|
+
`--output-dir`, `-o`:: Directory path to write updated YAML files (defaults to
|
|
734
|
+
database path)
|
|
735
|
+
|
|
736
|
+
`--include-potential-matches`, `-p`:: Include potential matches when updating
|
|
737
|
+
references (default: false)
|
|
738
|
+
|
|
386
739
|
==== Release
|
|
387
740
|
|
|
388
741
|
Creates release files for UnitsDB in unified formats:
|
|
@@ -400,6 +753,9 @@ $ unitsdb release --format=zip --database=/path/to/unitsdb/data
|
|
|
400
753
|
|
|
401
754
|
# Specify output directory
|
|
402
755
|
$ unitsdb release --output-dir=/path/to/output --database=/path/to/unitsdb/data
|
|
756
|
+
|
|
757
|
+
# Specify a version (required)
|
|
758
|
+
$ unitsdb release --version=2.1.0 --database=/path/to/unitsdb/data
|
|
403
759
|
----
|
|
404
760
|
|
|
405
761
|
This command creates release files for UnitsDB in two formats:
|
|
@@ -410,7 +766,7 @@ This command creates release files for UnitsDB in two formats:
|
|
|
410
766
|
|
|
411
767
|
The command verifies that all files have the same schema version before creating
|
|
412
768
|
the release files. The output files are named with the schema version (e.g.,
|
|
413
|
-
`unitsdb-2.
|
|
769
|
+
`unitsdb-2.1.0.yaml` and `unitsdb-2.1.0.zip`).
|
|
414
770
|
|
|
415
771
|
Options:
|
|
416
772
|
|
|
@@ -537,15 +893,15 @@ symbol-to-symbol and partial matches always classified as potential
|
|
|
537
893
|
|
|
538
894
|
=== Loading the database
|
|
539
895
|
|
|
540
|
-
The
|
|
541
|
-
|
|
896
|
+
The UnitsDB gem ships with the UnitsDB data bundled inside the gem. You can load
|
|
897
|
+
the database using the convenience method:
|
|
542
898
|
|
|
543
899
|
[source,ruby]
|
|
544
900
|
----
|
|
545
901
|
require 'unitsdb'
|
|
546
902
|
|
|
547
|
-
# Load
|
|
548
|
-
db = Unitsdb
|
|
903
|
+
# Load the bundled UnitsDB data (all entity types pre-loaded)
|
|
904
|
+
db = Unitsdb.database
|
|
549
905
|
|
|
550
906
|
# Access different collections
|
|
551
907
|
units = db.units
|
|
@@ -555,6 +911,19 @@ quantities = db.quantities
|
|
|
555
911
|
unit_systems = db.unit_systems
|
|
556
912
|
----
|
|
557
913
|
|
|
914
|
+
Alternatively, you can load from a specific path using `Database.from_db`:
|
|
915
|
+
|
|
916
|
+
[source,ruby]
|
|
917
|
+
----
|
|
918
|
+
require 'unitsdb'
|
|
919
|
+
|
|
920
|
+
# Load from the bundled data directory
|
|
921
|
+
db = Unitsdb::Database.from_db(Unitsdb.data_dir)
|
|
922
|
+
|
|
923
|
+
# Load from an external directory
|
|
924
|
+
external_db = Unitsdb::Database.from_db('/path/to/custom/unitsdb/data')
|
|
925
|
+
----
|
|
926
|
+
|
|
558
927
|
=== Database search methods
|
|
559
928
|
|
|
560
929
|
The UnitsDB Ruby gem provides several methods for searching and retrieving
|
|
@@ -715,13 +1084,17 @@ The `Quantity` class represents physical quantities that can be measured:
|
|
|
715
1084
|
|
|
716
1085
|
=== Database files
|
|
717
1086
|
|
|
718
|
-
The
|
|
1087
|
+
The UnitsDB gem bundles the following YAML files from the
|
|
1088
|
+
https://github.com/unitsml/unitsdb[UnitsDB repository]. They are included in the
|
|
1089
|
+
gem under the `data/` directory and are available immediately after installation
|
|
1090
|
+
without any additional setup.
|
|
719
1091
|
|
|
720
1092
|
* `prefixes.yaml` - Contains prefix definitions (e.g., kilo-, mega-)
|
|
721
1093
|
* `dimensions.yaml` - Contains dimension definitions (e.g., length, mass)
|
|
722
1094
|
* `units.yaml` - Contains unit definitions (e.g., meter, kilogram)
|
|
723
1095
|
* `quantities.yaml` - Contains quantity definitions (e.g., length, mass)
|
|
724
1096
|
* `unit_systems.yaml` - Contains unit system definitions (e.g., SI, Imperial)
|
|
1097
|
+
* `scales.yaml` - Contains scale definitions
|
|
725
1098
|
|
|
726
1099
|
|
|
727
1100
|
|