glossarist 2.14.9.pre.alpha.1 → 2.14.9
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/README.adoc +65 -0
- data/glossarist.gemspec +1 -0
- data/lib/glossarist/collections/localization_collection.rb +7 -1
- data/lib/glossarist/concept_ref.rb +5 -3
- data/lib/glossarist/dataset_register.rb +25 -1
- data/lib/glossarist/glossary_store.rb +67 -24
- data/lib/glossarist/managed_concept_collection.rb +31 -1
- data/lib/glossarist/schema_migration/v0_to_v1.rb +8 -1
- data/lib/glossarist/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5998b563be6ba537552a419b8fd199a5cda32f2337ccda0deee2c09b3db248e7
|
|
4
|
+
data.tar.gz: bcc888fd4972c5f3253c8daa31d5b897199afdb35eec6ead02b4c1610bc34778
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 659e5bc82dd9d60f8ec31b0214f49ef581edaf4f32ca329622f926c39f7e5bb0f4f0594143cb953a5b10cf5ccac65536e36cc7508fa0f4afccff0508f0fe5aee
|
|
7
|
+
data.tar.gz: 4a5146720fe468eeff50f825d6460b7bbbd666cc62b657ea95d022678b7c1cbe85487b8a193eed99527ab7f9e1a63f92825967ff5aba91d6ad4358576011b72c
|
data/README.adoc
CHANGED
|
@@ -29,6 +29,71 @@ Or install it yourself as:
|
|
|
29
29
|
gem install glossarist
|
|
30
30
|
----
|
|
31
31
|
|
|
32
|
+
== Configuration
|
|
33
|
+
|
|
34
|
+
=== glossarist.yaml
|
|
35
|
+
|
|
36
|
+
A dataset can carry attributes that are not part of the Glossarist model, such
|
|
37
|
+
as the part and document of an ISO 10303 term. List them under
|
|
38
|
+
`extension_attributes` in a `glossarist.yaml` file:
|
|
39
|
+
|
|
40
|
+
[,yaml]
|
|
41
|
+
----
|
|
42
|
+
extension_attributes:
|
|
43
|
+
- part
|
|
44
|
+
- document
|
|
45
|
+
----
|
|
46
|
+
|
|
47
|
+
When a localized concept file has one of these keys at its top level, the
|
|
48
|
+
value is kept under `extension_attributes` and written back there on save.
|
|
49
|
+
Other unknown keys are dropped.
|
|
50
|
+
|
|
51
|
+
[,ruby]
|
|
52
|
+
----
|
|
53
|
+
concept = Glossarist::LocalizedConcept.from_yaml(<<~YAML)
|
|
54
|
+
data:
|
|
55
|
+
language_code: eng
|
|
56
|
+
part: 2
|
|
57
|
+
YAML
|
|
58
|
+
|
|
59
|
+
concept.extension_attributes # => {"part" => 2}
|
|
60
|
+
----
|
|
61
|
+
|
|
62
|
+
The gem reads `glossarist.yaml` from the current working directory once, the
|
|
63
|
+
first time the configuration is used. Run your script from the directory that
|
|
64
|
+
holds the file, or register the attributes in code as shown below.
|
|
65
|
+
|
|
66
|
+
=== Glossarist.configure
|
|
67
|
+
|
|
68
|
+
The same settings can be made in code:
|
|
69
|
+
|
|
70
|
+
[,ruby]
|
|
71
|
+
----
|
|
72
|
+
Glossarist.configure do |config|
|
|
73
|
+
# Replaces the list read from glossarist.yaml
|
|
74
|
+
config.register_extension_attributes(["part", "document"])
|
|
75
|
+
|
|
76
|
+
# Use your own subclasses of Glossarist::ManagedConcept and
|
|
77
|
+
# Glossarist::LocalizedConcept
|
|
78
|
+
config.register_class(:managed_concept, MyManagedConcept)
|
|
79
|
+
config.register_class(:localized_concept, MyLocalizedConcept)
|
|
80
|
+
end
|
|
81
|
+
----
|
|
82
|
+
|
|
83
|
+
The registered classes are used for the concepts that
|
|
84
|
+
`ManagedConceptCollection#load_from_files` loads, and for new concepts made by
|
|
85
|
+
`ManagedConceptCollection#fetch_or_initialize` and by
|
|
86
|
+
`ManagedConcept#localized_concepts=` given a list of localized concept hashes.
|
|
87
|
+
|
|
88
|
+
The `generate_latex` command takes the same list with `--extra-attributes`.
|
|
89
|
+
|
|
90
|
+
=== config.yml
|
|
91
|
+
|
|
92
|
+
The allowed values of the model's enumerations, such as concept statuses,
|
|
93
|
+
abbreviation types and relationship types, come from `config.yml` in the gem's
|
|
94
|
+
root directory. The gem always reads its own copy, so a project cannot override
|
|
95
|
+
these values with a file of its own.
|
|
96
|
+
|
|
32
97
|
== Usage
|
|
33
98
|
|
|
34
99
|
=== Reading a Glossarist model V2 from files
|
data/glossarist.gemspec
CHANGED
|
@@ -45,6 +45,7 @@ Gem::Specification.new do |spec|
|
|
|
45
45
|
# std_meta); 0.5.x is not supported.
|
|
46
46
|
spec.add_dependency "sts", "~> 0.6"
|
|
47
47
|
spec.add_dependency "table_tennis", "~> 0.0"
|
|
48
|
+
spec.add_dependency "yeptris", "~> 0.6.59"
|
|
48
49
|
spec.add_dependency "tbx", "~> 0.1"
|
|
49
50
|
spec.add_dependency "thor"
|
|
50
51
|
end
|
|
@@ -15,7 +15,13 @@ module Glossarist
|
|
|
15
15
|
|
|
16
16
|
def store(lang_code, localized_concept)
|
|
17
17
|
localized_concept.language_code ||= lang_code.to_s
|
|
18
|
-
|
|
18
|
+
# One localization per language: storing the same language again
|
|
19
|
+
# replaces it, so a concept attached twice is not duplicated.
|
|
20
|
+
position = to_a.index do |l10n|
|
|
21
|
+
l10n.language_code == localized_concept.language_code
|
|
22
|
+
end
|
|
23
|
+
position ? collection[position] = localized_concept : push(localized_concept)
|
|
24
|
+
build_index_caches!
|
|
19
25
|
localized_concept
|
|
20
26
|
end
|
|
21
27
|
|
|
@@ -4,10 +4,10 @@ module Glossarist
|
|
|
4
4
|
# A typed reference to another concept, used inside n-ary relation
|
|
5
5
|
# members and other internal pointer shapes.
|
|
6
6
|
#
|
|
7
|
-
# The base ConceptRef carries `source`, `id`, `text`, `external`,
|
|
8
|
-
# `ellipsis`. The richer `ConceptReference` (in
|
|
7
|
+
# The base ConceptRef carries `source`, `id`, `version`, `text`, `external`,
|
|
8
|
+
# and `ellipsis`. The richer `ConceptReference` (in
|
|
9
9
|
# `glossarist/concept_reference.rb`) extends this with `term`, `urn`,
|
|
10
|
-
# `
|
|
10
|
+
# `ref_type` for use in cross-vocabulary references and
|
|
11
11
|
# relevance contexts.
|
|
12
12
|
#
|
|
13
13
|
# A ConceptRef is identified by `source:id` for external references
|
|
@@ -30,6 +30,7 @@ module Glossarist
|
|
|
30
30
|
class ConceptRef < Lutaml::Model::Serializable
|
|
31
31
|
attribute :source, :string
|
|
32
32
|
attribute :id, :string
|
|
33
|
+
attribute :version, :string
|
|
33
34
|
attribute :text, :string
|
|
34
35
|
attribute :external, :boolean, default: -> { false }
|
|
35
36
|
attribute :ellipsis, :boolean, default: -> { false }
|
|
@@ -37,6 +38,7 @@ module Glossarist
|
|
|
37
38
|
key_value do
|
|
38
39
|
map :source, to: :source
|
|
39
40
|
map :id, to: :id
|
|
41
|
+
map :version, to: :version
|
|
40
42
|
map :text, to: :text
|
|
41
43
|
map :external, to: :external
|
|
42
44
|
map :ellipsis, to: :ellipsis
|
|
@@ -41,11 +41,35 @@ module Glossarist
|
|
|
41
41
|
map "languageOrder", to: :language_order
|
|
42
42
|
map "ordering", to: :ordering
|
|
43
43
|
map "sections", to: :sections
|
|
44
|
-
map "description", to: :description
|
|
44
|
+
map "description", to: :description,
|
|
45
|
+
with: { from: :description_from_yaml,
|
|
46
|
+
to: :description_to_yaml }
|
|
45
47
|
map "about", to: :about
|
|
46
48
|
map "logo", to: :logo
|
|
47
49
|
end
|
|
48
50
|
|
|
51
|
+
# A register's description is a localized hash ({ "eng" => "..." }) or,
|
|
52
|
+
# in some datasets, a plain string. Keep whichever form was written.
|
|
53
|
+
# The :hash attribute cannot cast a string, so a string is stored as is.
|
|
54
|
+
# The :hash attribute cannot cast a string, so a plain-text description
|
|
55
|
+
# is stored as it is.
|
|
56
|
+
def description=(value)
|
|
57
|
+
if value.is_a?(String)
|
|
58
|
+
instance_variable_set(:@description, value)
|
|
59
|
+
else
|
|
60
|
+
super
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def description_from_yaml(model, value)
|
|
65
|
+
model.description = value
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def description_to_yaml(model, doc)
|
|
69
|
+
value = model.description
|
|
70
|
+
doc["description"] = value unless value.nil? || value.empty?
|
|
71
|
+
end
|
|
72
|
+
|
|
49
73
|
def section_by_id(target_id)
|
|
50
74
|
sections&.each do |section|
|
|
51
75
|
return section if section.id == target_id
|
|
@@ -348,17 +348,30 @@ module Glossarist
|
|
|
348
348
|
end
|
|
349
349
|
end
|
|
350
350
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
351
|
+
# Directory holding the split concept/ + localized_concept/ layout:
|
|
352
|
+
# the dataset root, or its concepts/ directory (the layout
|
|
353
|
+
# glossarist-data-iev uses). nil when the dataset is not split.
|
|
354
|
+
def split_layout_root(path)
|
|
355
|
+
concepts = File.join(path, "concepts")
|
|
356
|
+
if File.directory?(concepts)
|
|
357
|
+
return split_concept_files?(concepts) ? concepts : nil
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
path if split_concept_files?(path)
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
def split_concept_files?(dir)
|
|
364
|
+
Dir.glob(File.join(dir, "concept", "*.yaml")).any?
|
|
365
|
+
end
|
|
355
366
|
|
|
356
|
-
|
|
367
|
+
def legacy_managed_layout?(path)
|
|
368
|
+
!split_layout_root(path).nil?
|
|
357
369
|
end
|
|
358
370
|
|
|
359
371
|
def load_legacy_managed(path)
|
|
360
|
-
|
|
361
|
-
|
|
372
|
+
root = split_layout_root(path)
|
|
373
|
+
concept_dir = File.join(root, "concept")
|
|
374
|
+
lc_dir = find_localized_concepts_dir(root)
|
|
362
375
|
lc_index = build_lc_index(lc_dir) if lc_dir
|
|
363
376
|
|
|
364
377
|
@v1_concepts = []
|
|
@@ -379,6 +392,32 @@ module Glossarist
|
|
|
379
392
|
rescue Encoding::InvalidByteSequenceError => e
|
|
380
393
|
raise Errors::LoadError.new(path: f, reason: e.message)
|
|
381
394
|
end
|
|
395
|
+
load_grouped_beside_split(root) if File.basename(root) == "concepts"
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
# Grouped concepts/*.yaml files next to the split directories. A
|
|
399
|
+
# grouped file for an id the split layout already provides is a
|
|
400
|
+
# duplicate: the split files win and the file is reported, not
|
|
401
|
+
# loaded. Any other grouped file is loaded as usual.
|
|
402
|
+
def load_grouped_beside_split(root)
|
|
403
|
+
known = @v1_concepts.to_set { |mc| mc.data.id.to_s }
|
|
404
|
+
duplicates = []
|
|
405
|
+
Dir.glob(File.join(root, "*.yaml")).each do |f|
|
|
406
|
+
mc = read_grouped_concept(f)
|
|
407
|
+
next unless mc
|
|
408
|
+
|
|
409
|
+
if known.include?(mc.data.id.to_s)
|
|
410
|
+
duplicates << File.basename(f)
|
|
411
|
+
else
|
|
412
|
+
known << mc.data.id.to_s
|
|
413
|
+
@v1_concepts << mc
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
return if duplicates.empty?
|
|
417
|
+
|
|
418
|
+
warn "glossarist: ignored #{duplicates.length} grouped file(s) " \
|
|
419
|
+
"duplicating concept/ + localized_concept/ entries: " \
|
|
420
|
+
"#{duplicates.join(', ')}"
|
|
382
421
|
end
|
|
383
422
|
|
|
384
423
|
def load_legacy_localizations(managed_concept, lc_index, version = "3")
|
|
@@ -440,26 +479,30 @@ module Glossarist
|
|
|
440
479
|
end
|
|
441
480
|
|
|
442
481
|
def load_grouped_at_root(path)
|
|
443
|
-
@v1_concepts =
|
|
444
|
-
|
|
445
|
-
raw = File.read(f, encoding: "utf-8")
|
|
446
|
-
version = detect_version(raw)
|
|
447
|
-
doc_class = ConceptDocument.for_version(version)
|
|
448
|
-
doc = doc_class.from_yamls(raw)
|
|
449
|
-
mc = doc.concept
|
|
450
|
-
next unless mc&.data&.id
|
|
451
|
-
|
|
452
|
-
Array(doc.localizations).each { |l10n| mc.add_localization(l10n) }
|
|
453
|
-
@v1_concepts << mc
|
|
454
|
-
rescue Psych::SyntaxError => e
|
|
455
|
-
raise Errors::ParseError.new(filename: f, line: e.line)
|
|
456
|
-
rescue Lutaml::Model::InvalidFormatError => e
|
|
457
|
-
raise Errors::ParseError.new(filename: f, message: e.message)
|
|
458
|
-
rescue Encoding::InvalidByteSequenceError => e
|
|
459
|
-
raise Errors::LoadError.new(path: f, reason: e.message)
|
|
482
|
+
@v1_concepts = Dir.glob(File.join(path, "*.yaml")).filter_map do |f|
|
|
483
|
+
read_grouped_concept(f)
|
|
460
484
|
end
|
|
461
485
|
end
|
|
462
486
|
|
|
487
|
+
# Parses one grouped (multi-document) concept file into a
|
|
488
|
+
# ManagedConcept with its localizations; nil when it has no id.
|
|
489
|
+
def read_grouped_concept(file)
|
|
490
|
+
raw = File.read(file, encoding: "utf-8")
|
|
491
|
+
doc_class = ConceptDocument.for_version(detect_version(raw))
|
|
492
|
+
doc = doc_class.from_yamls(raw)
|
|
493
|
+
mc = doc.concept
|
|
494
|
+
return unless mc&.data&.id
|
|
495
|
+
|
|
496
|
+
Array(doc.localizations).each { |l10n| mc.add_localization(l10n) }
|
|
497
|
+
mc
|
|
498
|
+
rescue Psych::SyntaxError => e
|
|
499
|
+
raise Errors::ParseError.new(filename: file, line: e.line)
|
|
500
|
+
rescue Lutaml::Model::InvalidFormatError => e
|
|
501
|
+
raise Errors::ParseError.new(filename: file, message: e.message)
|
|
502
|
+
rescue Encoding::InvalidByteSequenceError => e
|
|
503
|
+
raise Errors::LoadError.new(path: file, reason: e.message)
|
|
504
|
+
end
|
|
505
|
+
|
|
463
506
|
def detect_version(raw)
|
|
464
507
|
if (m = raw.match(/^schema_version:\s*['"]?v?(\d)/))
|
|
465
508
|
m[1]
|
|
@@ -76,7 +76,7 @@ module Glossarist
|
|
|
76
76
|
def load_from_files(path)
|
|
77
77
|
store = GlossaryStore.new
|
|
78
78
|
store.load(path)
|
|
79
|
-
store.concepts.each { |mc| store(mc) }
|
|
79
|
+
store.concepts.each { |mc| store(as_registered(mc)) }
|
|
80
80
|
@localized_concepts_path = store.localized_concepts_dir_name || "localized_concept"
|
|
81
81
|
end
|
|
82
82
|
|
|
@@ -116,6 +116,36 @@ module Glossarist
|
|
|
116
116
|
|
|
117
117
|
private
|
|
118
118
|
|
|
119
|
+
# GlossaryStore picks V2/V3 classes by schema version. A class
|
|
120
|
+
# registered through Config takes their place, as it did before.
|
|
121
|
+
def as_registered(concept)
|
|
122
|
+
klass = Config.class_for(:managed_concept)
|
|
123
|
+
registered = concept.is_a?(klass) ? concept : copy_into(klass, concept)
|
|
124
|
+
registered.data.localizations = Collections::LocalizationCollection.new(
|
|
125
|
+
concept.localizations.values.map { |l10n| as_registered_l10n(l10n) },
|
|
126
|
+
)
|
|
127
|
+
registered
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def as_registered_l10n(localized_concept)
|
|
131
|
+
klass = Config.class_for(:localized_concept)
|
|
132
|
+
return localized_concept if localized_concept.is_a?(klass)
|
|
133
|
+
|
|
134
|
+
copy_into(klass, localized_concept)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Values move across as they are, so nested V2/V3 data keeps its type;
|
|
138
|
+
# the registered class cannot re-parse V2 YAML itself.
|
|
139
|
+
def copy_into(klass, source)
|
|
140
|
+
klass.new.tap do |target|
|
|
141
|
+
klass.attributes.each_key do |name|
|
|
142
|
+
next unless source.respond_to?(name)
|
|
143
|
+
|
|
144
|
+
target.public_send(:"#{name}=", source.public_send(name))
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
119
149
|
def file_key(concept)
|
|
120
150
|
@file_key ? @file_key.call(concept) : concept.uuid
|
|
121
151
|
end
|
|
@@ -82,9 +82,10 @@ module Glossarist
|
|
|
82
82
|
next unless s.is_a?(Hash)
|
|
83
83
|
|
|
84
84
|
origin = {}
|
|
85
|
-
origin["ref"] = s["ref"] if s["ref"]
|
|
85
|
+
origin["ref"] = structured_ref(s["ref"]) if s["ref"]
|
|
86
86
|
origin["clause"] = s["clause"] if s["clause"]
|
|
87
87
|
origin["link"] = s["link"] if s["link"]
|
|
88
|
+
origin["original"] = s["original"] if s["original"]
|
|
88
89
|
|
|
89
90
|
entry = { "type" => "authoritative", "origin" => origin }
|
|
90
91
|
if s["relationship"]
|
|
@@ -100,6 +101,12 @@ module Glossarist
|
|
|
100
101
|
l10n_block["sources"] = sources if sources.any?
|
|
101
102
|
end
|
|
102
103
|
|
|
104
|
+
# A plain-text ref names the document only; the structured form
|
|
105
|
+
# carries that title as the ref's source.
|
|
106
|
+
def structured_ref(ref)
|
|
107
|
+
ref.is_a?(String) ? { "source" => ref } : ref
|
|
108
|
+
end
|
|
109
|
+
|
|
103
110
|
def migrate_dates(l10n_block)
|
|
104
111
|
return if l10n_block.key?("dates")
|
|
105
112
|
|
data/lib/glossarist/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: glossarist
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.14.9
|
|
4
|
+
version: 2.14.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lutaml-model
|
|
@@ -136,6 +136,20 @@ dependencies:
|
|
|
136
136
|
- - "~>"
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
138
|
version: '0.0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: yeptris
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - "~>"
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: 0.6.59
|
|
146
|
+
type: :runtime
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - "~>"
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: 0.6.59
|
|
139
153
|
- !ruby/object:Gem::Dependency
|
|
140
154
|
name: tbx
|
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|