glossarist 2.14.16 → 2.14.17

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.
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Editorial proposals (FERIN register procedure, glossarist-server#45):
4
+ # a proposal is a payload of concept changes against a dataset repository
5
+ # (the git SSOT). Bridges turn a payload into a proposal branch — locally
6
+ # via GitBridge or as a GitHub pull request via GithubBridge.
7
+ module Glossarist
8
+ module Proposals
9
+ autoload :Change, "glossarist/proposals/change"
10
+ autoload :Payload, "glossarist/proposals/payload"
11
+ autoload :GitBridge, "glossarist/proposals/git_bridge"
12
+ autoload :GithubBridge, "glossarist/proposals/github_bridge"
13
+ autoload :PrDescription, "glossarist/proposals/pr_description"
14
+ end
15
+ end
@@ -15,7 +15,7 @@ module Glossarist
15
15
  attribute :repository, :string
16
16
  attribute :license, :string
17
17
  attribute :tags, :string, collection: true
18
- attribute :translations, :hash, default: -> {}
18
+ attribute :translations, :hash, default: -> { {} }
19
19
 
20
20
  # Identity and lifecycle fields. These MUST round-trip through GCR
21
21
  # packaging so consumers (concept-browser's lineage-series renderer,
@@ -61,6 +61,12 @@ module Glossarist
61
61
  map "source_repo", to: :source_repo
62
62
  end
63
63
 
64
+ # lutaml-model#1272 hardening for the plain-Hash defaults — see
65
+ # DefaultMaterialization. Prepended (not included) so they wrap the
66
+ # generated accessors for `attribute :subregisters`/`:translations`.
67
+ prepend DefaultMaterialization::SubregistersDefault
68
+ prepend DefaultMaterialization::TranslationsDefault
69
+
64
70
  def self.from_file(path)
65
71
  return nil unless File.exist?(path)
66
72
 
@@ -0,0 +1,428 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tmpdir"
4
+ require "unitsdb"
5
+
6
+ module Glossarist
7
+ module Units
8
+ # Converts unitsdb data (https://github.com/unitsml/unitsdb, parsed
9
+ # via the unitsdb gem) into glossarist dataset content.
10
+ #
11
+ # The source may be a unitsdb data directory (containing units.yaml,
12
+ # quantities.yaml, prefixes.yaml, dimensions.yaml, unit_systems.yaml),
13
+ # a ZIP archive of such a directory, or nil — meaning the data bundled
14
+ # inside the unitsdb gem.
15
+ #
16
+ # #ingest produces {Unit}, {QuantityKind} and {UnitPrefix} model
17
+ # instances (+#units+, +#quantity_kinds+, +#unit_prefixes+) and
18
+ # {Glossarist::ManagedConcept} dataset entries (+#concepts+);
19
+ # #write_to persists the entries as a {Glossarist::GlossaryStore}
20
+ # dataset directory or .gcr package.
21
+ #
22
+ # Dataset entry conventions follow the deployed units tenant
23
+ # (glossarist-units-tenant):
24
+ #
25
+ # * concept identifier (data.id) = unitsdb short ("ampere");
26
+ # * the first unitsdb name per language is the preferred expression,
27
+ # remaining names become admitted expressions, and the canonical
28
+ # symbol becomes a symbol designation;
29
+ # * normative unitsdb references become authoritative concept
30
+ # sources, mirrored into every localization;
31
+ # * QUDT / SI Digital Framework references become exact_match
32
+ # relations and UCUM references close_match relations;
33
+ # * unit -> quantity kind links become "references" relations on
34
+ # the unit (the one direction the dataset carries; the inverse
35
+ # stays on QuantityKind#units);
36
+ # * units carry their unit systems as domains, quantities their
37
+ # quantity type ("base"/"derived"), prefixes a "prefix" domain;
38
+ # * concept status and entry status are "valid".
39
+ class Ingestor
40
+ DEFAULT_LANG_MAP = { "en" => "eng", "fr" => "fra" }.freeze
41
+
42
+ EXACT_MATCH_AUTHORITIES = %w[qudt si-digital-framework].freeze
43
+ NOTATION_AUTHORITIES = %w[ucum].freeze
44
+
45
+ PREFIX_DOMAIN = "prefix"
46
+
47
+ attr_reader :units, :quantity_kinds, :unit_prefixes
48
+
49
+ # @param source [String, nil] unitsdb data directory, ZIP archive
50
+ # path, or nil for the data bundled in the unitsdb gem
51
+ # @param lang_map [Hash] unitsdb 2-letter language codes mapped to
52
+ # ISO 639-3 codes; unmapped codes pass through unchanged
53
+ def initialize(source = nil, lang_map: DEFAULT_LANG_MAP)
54
+ @source = source
55
+ @lang_map = lang_map
56
+ end
57
+
58
+ def ingest
59
+ @database = load_database
60
+ build_models
61
+ build_concepts
62
+ self
63
+ end
64
+
65
+ def concepts
66
+ @concepts ||= []
67
+ end
68
+
69
+ def each_concept(&)
70
+ concepts.each(&)
71
+ end
72
+
73
+ # @param path [String] output dataset directory or .gcr path
74
+ # @param shortname [String, nil] required for .gcr output
75
+ # @param version [String, nil] required for .gcr output
76
+ def write_to(path, shortname: nil, version: nil)
77
+ if path.end_with?(".gcr")
78
+ write_gcr(path, shortname, version)
79
+ else
80
+ write_dataset(path)
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def load_database
87
+ if @source.nil?
88
+ Unitsdb::Database.from_db(bundled_data_dir)
89
+ elsif File.directory?(@source)
90
+ Unitsdb::Database.from_db(@source)
91
+ elsif File.file?(@source) && @source.end_with?(".zip")
92
+ database_from_zip
93
+ else
94
+ raise ArgumentError,
95
+ "unitsdb source not found " \
96
+ "(expected a data directory or .zip archive): #{@source}"
97
+ end
98
+ end
99
+
100
+ def bundled_data_dir
101
+ File.join(Gem::Specification.find_by_name("unitsdb").gem_dir, "data")
102
+ rescue Gem::LoadError
103
+ raise ArgumentError, "the unitsdb gem is not available"
104
+ end
105
+
106
+ def database_from_zip
107
+ Dir.mktmpdir("glossarist-unitsdb") do |dir|
108
+ extract_zip(dir)
109
+ Unitsdb::Database.from_db(database_dir_within(dir))
110
+ end
111
+ end
112
+
113
+ # rubyzip 3 does its own zip-slip guard: entries whose archive path
114
+ # escapes the destination directory are skipped with a warning.
115
+ def extract_zip(dir)
116
+ require "zip"
117
+ Zip::File.open(@source) do |zip|
118
+ zip.each do |entry|
119
+ next unless entry.file?
120
+
121
+ entry.extract(destination_directory: dir,
122
+ create_parent_directories: true)
123
+ end
124
+ end
125
+ end
126
+
127
+ def database_dir_within(dir)
128
+ files = Unitsdb::Database::Loader::REQUIRED_DATABASE_FILES.values
129
+ return dir if files.all? { |name| File.exist?(File.join(dir, name)) }
130
+
131
+ child = Dir.children(dir).find do |name|
132
+ path = File.join(dir, name)
133
+ File.directory?(path) &&
134
+ files.all? { |file| File.exist?(File.join(path, file)) }
135
+ end
136
+ return File.join(dir, child) if child
137
+
138
+ raise ArgumentError,
139
+ "no unitsdb database (#{files.join(', ')}) in #{@source}"
140
+ end
141
+
142
+ # ── model building ──
143
+
144
+ def build_models
145
+ @quantity_short_by_nist = index_shorts_by_nist(@database.quantities)
146
+ @dimension_id_by_nist = index_unitsml_by_nist(@database.dimensions)
147
+ @raw_units_by_short = {}
148
+ @units = @database.units.map do |raw|
149
+ @raw_units_by_short[raw.short] = raw
150
+ build_unit(raw)
151
+ end
152
+ @quantity_kinds = @database.quantities.map { |raw| build_quantity_kind(raw) }
153
+ @unit_prefixes = @database.prefixes.map { |raw| build_unit_prefix(raw) }
154
+ link_quantities_to_units
155
+ end
156
+
157
+ def index_shorts_by_nist(entities)
158
+ entities.each_with_object({}) do |entity, hash|
159
+ nist = identifier_of(entity, "nist")
160
+ hash[nist] = entity.short if nist && entity.short
161
+ end
162
+ end
163
+
164
+ def index_unitsml_by_nist(entities)
165
+ entities.each_with_object({}) do |entity, hash|
166
+ nist = identifier_of(entity, "nist")
167
+ unitsml = identifier_of(entity, "unitsml")
168
+ hash[nist] = unitsml if nist && unitsml
169
+ end
170
+ end
171
+
172
+ def identifier_of(entity, type)
173
+ Array(entity.identifiers).find { |id| id.type == type }&.id
174
+ end
175
+
176
+ def build_unit(raw)
177
+ Unit.new(
178
+ id: identifier_of(raw, "unitsml") || raw.short,
179
+ short: raw.short,
180
+ name: primary_names(raw.names),
181
+ alt_names: alternate_names(raw.names),
182
+ symbol: Array(raw.symbols).first&.unicode,
183
+ notations: notations_of(raw),
184
+ exact_matches: matches_of(raw),
185
+ systems: Array(raw.unit_system_reference).map(&:id),
186
+ quantity_kinds: Array(raw.quantity_references).map do |ref|
187
+ ConceptRef.new(id: @quantity_short_by_nist.fetch(ref.id, ref.id))
188
+ end,
189
+ dimension: dimension_of(raw),
190
+ root: raw.root,
191
+ references: authoritative_sources(raw),
192
+ )
193
+ end
194
+
195
+ def build_quantity_kind(raw)
196
+ QuantityKind.new(
197
+ id: identifier_of(raw, "unitsml") || raw.short,
198
+ short: raw.short,
199
+ name: primary_names(raw.names),
200
+ alt_names: alternate_names(raw.names),
201
+ notations: notations_of(raw),
202
+ exact_matches: matches_of(raw),
203
+ quantity_type: raw.quantity_type,
204
+ dimension: dimension_of(raw),
205
+ references: authoritative_sources(raw),
206
+ )
207
+ end
208
+
209
+ def build_unit_prefix(raw)
210
+ UnitPrefix.new(
211
+ id: identifier_of(raw, "unitsml") || raw.short,
212
+ short: raw.short,
213
+ name: primary_names(raw.names),
214
+ alt_names: alternate_names(raw.names),
215
+ symbol: Array(raw.symbols).first&.unicode,
216
+ notations: notations_of(raw),
217
+ base: raw.base,
218
+ power: raw.power,
219
+ references: authoritative_sources(raw),
220
+ )
221
+ end
222
+
223
+ # Inverse of Unit#quantity_kinds: every quantity kind gets the
224
+ # units that measure it (concept-model QuantityKind#units).
225
+ def link_quantities_to_units
226
+ kinds_by_short = @quantity_kinds.each_with_object({}) do |kind, hash|
227
+ hash[kind.short] = kind if kind.short
228
+ end
229
+
230
+ @units.each do |unit|
231
+ Array(unit.quantity_kinds).each do |ref|
232
+ kind = kinds_by_short[ref.id]
233
+ kind&.units = Array(kind&.units) + [ConceptRef.new(id: unit.short)]
234
+ end
235
+ end
236
+ end
237
+
238
+ # ── shared field builders ──
239
+
240
+ # Ordered { lang => [names] } — the first name per language is the
241
+ # primary designation, the rest are alternates.
242
+ def names_by_lang(names)
243
+ Array(names).each_with_object({}) do |name, hash|
244
+ lang = @lang_map.fetch(name.lang, name.lang)
245
+ (hash[lang] ||= []) << name.value
246
+ end
247
+ end
248
+
249
+ def primary_names(names)
250
+ names_by_lang(names).transform_values(&:first)
251
+ end
252
+
253
+ def alternate_names(names)
254
+ alts = names_by_lang(names)
255
+ .transform_values { |list| list.drop(1) }
256
+ .delete_if { |_lang, list| list.empty? }
257
+ alts.empty? ? nil : alts
258
+ end
259
+
260
+ def notations_of(raw)
261
+ Array(raw.identifiers).map(&:id) +
262
+ external_refs(raw, *NOTATION_AUTHORITIES).map(&:uri)
263
+ end
264
+
265
+ def matches_of(raw)
266
+ external_refs(raw, *EXACT_MATCH_AUTHORITIES).map(&:uri)
267
+ end
268
+
269
+ def external_refs(raw, *authorities)
270
+ Array(raw.references)
271
+ .select { |ref| authorities.include?(ref.authority) }
272
+ end
273
+
274
+ def dimension_of(raw)
275
+ ref = raw.dimension_reference
276
+ ref && @dimension_id_by_nist.fetch(ref.id, ref.id)
277
+ end
278
+
279
+ # Normative unitsdb references become authoritative glossarist
280
+ # concept sources; informative ones surface as exact/close matches
281
+ # and notations instead (the glossarist source-type enum has no
282
+ # "informative").
283
+ def authoritative_sources(raw)
284
+ Array(raw.references)
285
+ .select { |ref| ref.type == "normative" }
286
+ .map { |ref| source_of(ref) }
287
+ end
288
+
289
+ def source_of(ref)
290
+ ConceptSource.new(
291
+ type: "authoritative",
292
+ origin: Citation.new(
293
+ ref: Citation::Ref.new(source: ref.authority, id: ref.uri),
294
+ ),
295
+ )
296
+ end
297
+
298
+ # ── concept building ──
299
+
300
+ def build_concepts
301
+ @concepts = []
302
+ @units.each { |unit| @concepts << unit_concept(unit) }
303
+ @quantity_kinds.each { |kind| @concepts << quantity_concept(kind) }
304
+ @unit_prefixes.each { |prefix| @concepts << prefix_concept(prefix) }
305
+ end
306
+
307
+ def unit_concept(unit)
308
+ concept = base_concept(unit)
309
+ concept.data.domains = Array(unit.systems).map do |system|
310
+ ConceptReference.domain(system)
311
+ end
312
+ concept.related = unit_related(unit, @raw_units_by_short[unit.short])
313
+ concept
314
+ end
315
+
316
+ def quantity_concept(kind)
317
+ concept = base_concept(kind)
318
+ concept.data.domains = [kind.quantity_type].compact.map do |type|
319
+ ConceptReference.domain(type)
320
+ end
321
+ concept
322
+ end
323
+
324
+ def prefix_concept(prefix)
325
+ concept = base_concept(prefix)
326
+ concept.data.domains = [ConceptReference.domain(PREFIX_DOMAIN)]
327
+ concept
328
+ end
329
+
330
+ def base_concept(model)
331
+ concept = ManagedConcept.new(data: { id: model.short })
332
+ concept.status = "valid"
333
+ concept.sources = model.references
334
+ add_localizations(concept, model)
335
+ concept
336
+ end
337
+
338
+ def add_localizations(concept, model)
339
+ langs = (model.name || {}).keys + (model.alt_names || {}).keys
340
+ langs.uniq.each { |lang| concept.add_l10n(localized_concept(model, lang)) }
341
+ end
342
+
343
+ # Built via of_yaml (the TermMapper pattern): attribute-assignment
344
+ # on a default-initialized ConceptData is skipped by lutaml's
345
+ # defaults-tracking serialization.
346
+ def localized_concept(model, lang)
347
+ LocalizedConcept.of_yaml(
348
+ "data" => {
349
+ "language_code" => lang,
350
+ "entry_status" => "valid",
351
+ "terms" => designation_hashes(model, lang),
352
+ "sources" => Array(model.references).map(&:to_hash),
353
+ },
354
+ )
355
+ end
356
+
357
+ def designation_hashes(model, lang)
358
+ terms = []
359
+ if (preferred = (model.name || {})[lang])
360
+ terms << designation_hash("expression", preferred, "preferred")
361
+ end
362
+ Array((model.alt_names || {})[lang]).each do |value|
363
+ terms << designation_hash("expression", value, "admitted")
364
+ end
365
+ terms << designation_hash("symbol", model.symbol, "preferred") if model.symbol
366
+ terms
367
+ end
368
+
369
+ def designation_hash(type, designation, normative_status)
370
+ { "type" => type, "designation" => designation,
371
+ "normative_status" => normative_status }
372
+ end
373
+
374
+ def unit_related(unit, raw)
375
+ quantity_edges(unit) +
376
+ match_edges(raw, "exact_match", EXACT_MATCH_AUTHORITIES) +
377
+ match_edges(raw, "close_match", NOTATION_AUTHORITIES)
378
+ end
379
+
380
+ def quantity_edges(unit)
381
+ Array(unit.quantity_kinds).map do |ref|
382
+ RelatedConcept.new(
383
+ type: "references", ref: ConceptRef.new(id: ref.id),
384
+ )
385
+ end
386
+ end
387
+
388
+ def match_edges(raw, type, authorities)
389
+ external_refs(raw, *authorities).map do |ref|
390
+ RelatedConcept.new(
391
+ type: type,
392
+ ref: ConceptRef.new(source: ref.authority, id: ref.uri),
393
+ )
394
+ end
395
+ end
396
+
397
+ # ── output ──
398
+
399
+ def write_dataset(path)
400
+ FileUtils.mkdir_p(path)
401
+ store = GlossaryStore.new
402
+ concepts.each { |concept| store.add_concept(concept) }
403
+ store.save_directory(path)
404
+ end
405
+
406
+ def write_gcr(path, shortname, version)
407
+ unless shortname && version
408
+ raise ArgumentError, "shortname and version are required for GCR output"
409
+ end
410
+
411
+ Dir.mktmpdir("glossarist-units-import") do |dir|
412
+ write_dataset(dir)
413
+ GC.start
414
+ tmp_gcr = "#{path}.tmp.#{Process.pid}"
415
+ begin
416
+ GcrPackage.create_from_directory(
417
+ dir, output: tmp_gcr, shortname: shortname, version: version
418
+ )
419
+ FileUtils.rm_f(path)
420
+ FileUtils.mv(tmp_gcr, path)
421
+ ensure
422
+ FileUtils.rm_f(tmp_gcr)
423
+ end
424
+ end
425
+ end
426
+ end
427
+ end
428
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module Units
5
+ # A kind of physical quantity (ISQ, ISO 80000) as dataset content.
6
+ #
7
+ # Aligned with concept-model models/units/QuantityKind.lutaml
8
+ # (concept-model#104): +dimension+ carries the ISQ dimension reference
9
+ # (as a unitsdb dimension reference id), +quantity_type+ is
10
+ # "base"/"derived", +broader+ references superordinate quantity kinds
11
+ # (skos:broader semantics; unitsdb states no quantity hierarchy, so
12
+ # unitsdb ingest leaves it empty), +units+ references the units that
13
+ # measure this quantity (the inverse of Unit#quantity_kinds).
14
+ # +short+ and +alt_names+ are glossarist-side additions: the dataset
15
+ # concept identifier convention and the remaining names per language
16
+ # (tenant prefLabel/altLabel split; +name+ holds the first unitsdb
17
+ # name per language). Localized names use the glossarist
18
+ # LocalizedString hash convention ({ "eng" => "length" }).
19
+ class QuantityKind < Lutaml::Model::Serializable
20
+ attribute :id, :string
21
+ attribute :short, :string
22
+ attribute :name, :hash
23
+ attribute :alt_names, :hash
24
+ attribute :symbol, :string
25
+ attribute :notations, :string, collection: true
26
+ attribute :exact_matches, :string, collection: true
27
+ attribute :quantity_type, :string
28
+ attribute :dimension, :string
29
+ attribute :units, Glossarist::ConceptRef, collection: true
30
+ attribute :broader, Glossarist::ConceptRef, collection: true
31
+ attribute :references, Glossarist::ConceptSource, collection: true
32
+
33
+ key_value do
34
+ map :id, to: :id
35
+ map :short, to: :short
36
+ map :name, to: :name
37
+ map %i[alt_names altNames], to: :alt_names
38
+ map :symbol, to: :symbol
39
+ map :notations, to: :notations
40
+ map %i[exact_matches exactMatches], to: :exact_matches
41
+ map %i[quantity_type quantityType], to: :quantity_type
42
+ map :dimension, to: :dimension
43
+ map :units, to: :units
44
+ map :broader, to: :broader
45
+ map :references, to: :references
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module Units
5
+ # A unit of measurement as dataset content.
6
+ #
7
+ # Aligned with concept-model models/units/Unit.lutaml (concept-model#104):
8
+ # +id+ is the UnitsML code (unitsdb identifiers[type=unitsml], e.g.
9
+ # "u:ampere"), +notations+ carry the remaining external scheme codes
10
+ # (NIST id, UCUM), +exact_matches+ hold the IRI counterparts (QUDT, SI
11
+ # Digital Framework), +quantity_kinds+ reference the quantity kinds this
12
+ # unit measures.
13
+ #
14
+ # Two pragmatic glossarist-side additions beyond the concept-model
15
+ # field set: +short+ (the unitsdb short name — the dataset concept
16
+ # identifier convention), +systems+ (unitsdb unit_system_reference
17
+ # ids, deferred by concept-model as an orthogonal classification
18
+ # dimension but required here because the dataset entry convention
19
+ # maps unit systems to concept domains/groups), and +alt_names+
20
+ # (remaining names per language — the tenant prefLabel/altLabel
21
+ # split; +name+ holds the first unitsdb name per language).
22
+ # Localized names use the glossarist LocalizedString hash convention
23
+ # ({ "eng" => "ampere" }). +prefixes+ carries the
24
+ # UnitsML codes of prefixes applicable to this unit; unitsdb ingest
25
+ # leaves it empty (unitsdb states applicability only implicitly).
26
+ class Unit < Lutaml::Model::Serializable
27
+ attribute :id, :string
28
+ attribute :short, :string
29
+ attribute :name, :hash
30
+ attribute :alt_names, :hash
31
+ attribute :symbol, :string
32
+ attribute :notations, :string, collection: true
33
+ attribute :exact_matches, :string, collection: true
34
+ attribute :systems, :string, collection: true
35
+ attribute :quantity_kinds, Glossarist::ConceptRef, collection: true
36
+ attribute :prefixes, :string, collection: true
37
+ attribute :dimension, :string
38
+ attribute :root, :boolean
39
+ attribute :references, Glossarist::ConceptSource, collection: true
40
+
41
+ key_value do
42
+ map :id, to: :id
43
+ map :short, to: :short
44
+ map :name, to: :name
45
+ map %i[alt_names altNames], to: :alt_names
46
+ map :symbol, to: :symbol
47
+ map :notations, to: :notations
48
+ map %i[exact_matches exactMatches], to: :exact_matches
49
+ map :systems, to: :systems
50
+ map %i[quantity_kinds quantityKinds], to: :quantity_kinds
51
+ map :prefixes, to: :prefixes
52
+ map :dimension, to: :dimension
53
+ map :root, to: :root
54
+ map :references, to: :references
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module Units
5
+ # A unit prefix — a multiplier prepended to a unit to form multiples
6
+ # and submultiples (SI Brochure chapter 3; binary prefixes per
7
+ # IEC 80000-13).
8
+ #
9
+ # Aligned with concept-model models/units/UnitPrefix.lutaml
10
+ # (concept-model#104): +base+ (10 decimal, 2 binary) and +power+ give
11
+ # the multiplier base**power, which is derived, never stored. The
12
+ # class is named UnitPrefix (not Prefix) after the concept-model
13
+ # rename — gloss:Prefix is the designation-type class.
14
+ # +short+ and +alt_names+ are glossarist-side additions: the dataset
15
+ # concept identifier convention and the remaining names per language.
16
+ # Localized names use the glossarist LocalizedString hash convention
17
+ # ({ "eng" => "kilo" }).
18
+ class UnitPrefix < Lutaml::Model::Serializable
19
+ attribute :id, :string
20
+ attribute :short, :string
21
+ attribute :name, :hash
22
+ attribute :alt_names, :hash
23
+ attribute :symbol, :string
24
+ attribute :notations, :string, collection: true
25
+ attribute :base, :integer
26
+ attribute :power, :integer
27
+ attribute :references, Glossarist::ConceptSource, collection: true
28
+
29
+ key_value do
30
+ map :id, to: :id
31
+ map :short, to: :short
32
+ map :name, to: :name
33
+ map %i[alt_names altNames], to: :alt_names
34
+ map :symbol, to: :symbol
35
+ map :notations, to: :notations
36
+ map :base, to: :base
37
+ map :power, to: :power
38
+ map :references, to: :references
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ # Units/quantities ingest helpers (roadmap 2.5 P3, glossarist/glossarist-server#32).
5
+ #
6
+ # Gives unitsdb-sourced unit/quantity/prefix data first-class glossarist
7
+ # dataset content: {Units::Ingestor} converts a unitsdb data directory
8
+ # (https://github.com/unitsml/unitsdb, parsed via the unitsdb gem) into
9
+ # {Glossarist::ManagedConcept} entries a {Glossarist::GlossaryStore} can
10
+ # ingest like any other dataset.
11
+ #
12
+ # The models mirror the concept-model units module
13
+ # (concept-model#104, models/units/*.lutaml) scoped to the fields the
14
+ # ingest needs; field-level alignment notes live on each model class.
15
+ module Units
16
+ autoload :Unit, "glossarist/units/unit"
17
+ autoload :QuantityKind, "glossarist/units/quantity_kind"
18
+ autoload :UnitPrefix, "glossarist/units/unit_prefix"
19
+ autoload :Ingestor, "glossarist/units/ingestor"
20
+ end
21
+ end
@@ -9,6 +9,9 @@ module Glossarist
9
9
  attribute :term, :string
10
10
  attribute :groups, :string, collection: true
11
11
  attribute :references, :hash, collection: true
12
+ # Plain-Hash default; not exposed to lutaml-model#1272 silent
13
+ # serialization loss because every assignment goes through the
14
+ # `lang_blocks_from` handler's writer (see DefaultMaterialization).
12
15
  attribute :language_blocks, :hash, default: -> { {} }
13
16
 
14
17
  key_value do
@@ -3,6 +3,9 @@
3
3
  module Glossarist
4
4
  module V1
5
5
  class CrossReferences < Lutaml::Model::Serializable
6
+ # Plain-Hash defaults; not exposed to lutaml-model#1272 silent
7
+ # serialization loss because every assignment goes through the
8
+ # `xref_from_yaml` handler's writers (see DefaultMaterialization).
6
9
  attribute :ref_prefix_map, :hash, default: -> { {} }
7
10
  attribute :urn_standard_map, :hash, default: -> { {} }
8
11
 
@@ -4,6 +4,11 @@ module Glossarist
4
4
  module V2
5
5
  class LocalizedConcept < Glossarist::LocalizedConcept
6
6
  attribute :data, V2::ConceptData, default: -> { V2::ConceptData.new }
7
+
8
+ # lutaml-model#1272 hardening — the `attribute :data` re-declaration
9
+ # above regenerates the accessor, shadowing the parent's; re-apply.
10
+ # See DefaultMaterialization.
11
+ prepend DefaultMaterialization
7
12
  end
8
13
  end
9
14
  end
@@ -18,6 +18,11 @@ module Glossarist
18
18
  with: { from: :uuid_from_yaml, to: :uuid_to_yaml }
19
19
  map :sources, to: :sources
20
20
  end
21
+
22
+ # lutaml-model#1272 hardening — the `attribute :data` re-declaration
23
+ # above regenerates the accessor, shadowing the parent's; re-apply.
24
+ # See DefaultMaterialization.
25
+ prepend DefaultMaterialization
21
26
  end
22
27
  end
23
28
  end