glossarist 2.3.0 → 2.3.2
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/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +65 -0
- data/README.adoc +2 -2
- data/config.yml +1 -1
- data/exe/glossarist +5 -3
- data/glossarist.gemspec +1 -0
- data/lib/glossarist/asset.rb +4 -9
- data/lib/glossarist/citation.rb +73 -41
- data/lib/glossarist/collection.rb +2 -11
- data/lib/glossarist/collections/asset_collection.rb +0 -3
- data/lib/glossarist/collections/bibliography_collection.rb +1 -1
- data/lib/glossarist/concept.rb +66 -206
- data/lib/glossarist/concept_data.rb +66 -0
- data/lib/glossarist/concept_date.rb +7 -11
- data/lib/glossarist/concept_manager.rb +19 -29
- data/lib/glossarist/concept_set.rb +6 -4
- data/lib/glossarist/concept_source.rb +15 -58
- data/lib/glossarist/config.rb +4 -4
- data/lib/glossarist/designation/abbreviation.rb +15 -16
- data/lib/glossarist/designation/base.rb +16 -15
- data/lib/glossarist/designation/expression.rb +18 -26
- data/lib/glossarist/designation/grammar_info.rb +27 -45
- data/lib/glossarist/designation/graphical_symbol.rb +12 -8
- data/lib/glossarist/designation/letter_symbol.rb +13 -11
- data/lib/glossarist/designation/symbol.rb +11 -13
- data/lib/glossarist/designation.rb +3 -3
- data/lib/glossarist/detailed_definition.rb +6 -24
- data/lib/glossarist/error.rb +4 -4
- data/lib/glossarist/glossary_definition.rb +6 -3
- data/lib/glossarist/localized_concept.rb +17 -62
- data/lib/glossarist/managed_concept.rb +73 -146
- data/lib/glossarist/managed_concept_collection.rb +15 -24
- data/lib/glossarist/managed_concept_data.rb +47 -0
- data/lib/glossarist/non_verb_rep.rb +10 -13
- data/lib/glossarist/related_concept.rb +14 -21
- data/lib/glossarist/utilities/uuid.rb +10 -5
- data/lib/glossarist/utilities.rb +0 -2
- data/lib/glossarist/version.rb +1 -1
- data/lib/glossarist.rb +10 -9
- metadata +23 -13
- data/lib/glossarist/model.rb +0 -40
- data/lib/glossarist/utilities/boolean_attributes.rb +0 -35
- data/lib/glossarist/utilities/enum/class_methods.rb +0 -99
- data/lib/glossarist/utilities/enum/enum_collection.rb +0 -45
- data/lib/glossarist/utilities/enum/instance_methods.rb +0 -55
- data/lib/glossarist/utilities/enum.rb +0 -21
- data/lib/glossarist/v1_reader.rb +0 -28
data/lib/glossarist/concept.rb
CHANGED
@@ -1,244 +1,104 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# (c) Copyright 2021 Ribose Inc.
|
4
|
-
#
|
5
|
-
|
6
1
|
module Glossarist
|
7
|
-
class Concept < Model
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
# @return [Array<DetailedDefinition>]
|
38
|
-
attr_reader :notes
|
39
|
-
|
40
|
-
# Concept examples
|
41
|
-
# @return [Array<DetailedDefinition>]
|
42
|
-
attr_reader :examples
|
43
|
-
|
44
|
-
# Contains list of extended attributes
|
45
|
-
attr_accessor :extension_attributes
|
46
|
-
|
47
|
-
attr_accessor :lineage_source
|
48
|
-
attr_accessor :lineage_source_similarity
|
49
|
-
|
50
|
-
attr_accessor :release
|
51
|
-
|
52
|
-
def initialize(*args)
|
53
|
-
@localizations = {}
|
54
|
-
@sources = Glossarist::Collections::Collection.new(klass: ConceptSource)
|
55
|
-
@related = Glossarist::Collections::Collection.new(klass: RelatedConcept)
|
56
|
-
@definition = Glossarist::Collections::Collection.new(klass: DetailedDefinition)
|
57
|
-
@notes = Glossarist::Collections::Collection.new(klass: DetailedDefinition)
|
58
|
-
@examples = Glossarist::Collections::Collection.new(klass: DetailedDefinition)
|
59
|
-
@dates = Glossarist::Collections::Collection.new(klass: ConceptDate)
|
60
|
-
|
61
|
-
@designations = Glossarist::Collections::DesignationCollection.new
|
62
|
-
@extension_attributes = {}
|
63
|
-
|
64
|
-
normalize_args(args)
|
65
|
-
|
66
|
-
super
|
67
|
-
end
|
68
|
-
|
69
|
-
def uuid
|
70
|
-
@uuid ||= Glossarist::Utilities::UUID.uuid_v5(
|
71
|
-
Glossarist::Utilities::UUID::OID_NAMESPACE,
|
72
|
-
to_h_no_uuid.to_yaml,
|
73
|
-
)
|
2
|
+
class Concept < Lutaml::Model::Serializable
|
3
|
+
attribute :data, ConceptData, default: -> { ConceptData.new }
|
4
|
+
attribute :id, :string
|
5
|
+
attribute :uuid, :string
|
6
|
+
attribute :subject, :string
|
7
|
+
attribute :non_verb_rep, :string
|
8
|
+
attribute :extension_attributes, :string
|
9
|
+
attribute :lineage_source, :string
|
10
|
+
attribute :localizations, :hash
|
11
|
+
attribute :extension_attributes, :hash
|
12
|
+
attribute :termid, :string
|
13
|
+
|
14
|
+
yaml do
|
15
|
+
map :data, to: :data
|
16
|
+
map :termid, to: :termid
|
17
|
+
map :subject, to: :subject
|
18
|
+
map %i[non_verb_rep nonVerbRep], to: :non_verb_rep
|
19
|
+
map %i[extension_attributes extensionAttributes], to: :extension_attributes
|
20
|
+
map %i[lineage_source lineageSource], to: :lineage_source
|
21
|
+
map :localizations, to: :localizations
|
22
|
+
map %i[extension_attributes extensionAttributes], to: :extension_attributes
|
23
|
+
|
24
|
+
map %i[date_accepted dateAccepted], with: { from: :date_accepted_from_yaml, to: :date_accepted_to_yaml }
|
25
|
+
map :uuid, to: :uuid, with: { to: :uuid_to_yaml, from: :uuid_from_yaml }
|
26
|
+
map :id, to: :id, with: { to: :id_to_yaml, from: :id_from_yaml }
|
27
|
+
map :identifier, to: :id, with: { to: :id_to_yaml, from: :id_from_yaml }
|
28
|
+
end
|
29
|
+
|
30
|
+
def designations
|
31
|
+
data.terms
|
74
32
|
end
|
33
|
+
alias :terms :designations
|
75
34
|
|
76
|
-
def
|
77
|
-
|
78
|
-
# so adding a temporary check until every glossary is updated using glossarist.
|
79
|
-
if !id.nil? && (id.is_a?(String) || id.is_a?(Integer))
|
80
|
-
@id = id
|
81
|
-
else
|
82
|
-
raise(Glossarist::Error, "Expect id to be a String or Integer, Got #{id.class} (#{id})")
|
83
|
-
end
|
35
|
+
def definition
|
36
|
+
data.definition
|
84
37
|
end
|
85
38
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
# List of authorative sources.
|
90
|
-
# @todo Alias +authoritative_source+ exists for legacy reasons and may be
|
91
|
-
# removed.
|
92
|
-
# @return [Array<ConceptSource>]
|
93
|
-
attr_reader :sources
|
94
|
-
|
95
|
-
# return [Array<ConceptDate>]
|
96
|
-
attr_reader :dates
|
97
|
-
|
98
|
-
def examples=(examples)
|
99
|
-
@examples.clear!
|
100
|
-
examples&.each { |example| @examples << example }
|
39
|
+
def definition=(value)
|
40
|
+
data.definition = value
|
101
41
|
end
|
102
42
|
|
103
|
-
def
|
104
|
-
|
105
|
-
notes&.each { |note| @notes << note }
|
43
|
+
def sources
|
44
|
+
data.sources
|
106
45
|
end
|
107
46
|
|
108
|
-
def
|
109
|
-
|
110
|
-
definition&.each { |definition| @definition << definition }
|
47
|
+
def examples
|
48
|
+
data.examples
|
111
49
|
end
|
112
50
|
|
113
|
-
def
|
114
|
-
|
115
|
-
designations&.each { |designation| @designations << designation }
|
51
|
+
def notes
|
52
|
+
data.notes
|
116
53
|
end
|
117
54
|
|
118
|
-
alias :terms= :designations=
|
119
|
-
|
120
55
|
def preferred_designations
|
121
|
-
|
56
|
+
data.terms.select(&:preferred?)
|
122
57
|
end
|
123
|
-
|
124
58
|
alias :preferred_terms :preferred_designations
|
125
59
|
|
126
|
-
def
|
127
|
-
|
128
|
-
dates&.each { |date| @dates << date }
|
129
|
-
end
|
130
|
-
|
131
|
-
def sources=(sources)
|
132
|
-
@sources.clear!
|
133
|
-
sources&.each { |source| @sources << source }
|
60
|
+
def date_accepted
|
61
|
+
data.date_accepted
|
134
62
|
end
|
135
63
|
|
136
64
|
def authoritative_source
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
def authoritative_source=(sources)
|
141
|
-
sources&.each do |source|
|
142
|
-
@sources << source.merge({ "type" => "authoritative" })
|
143
|
-
end
|
65
|
+
data.authoritative_source
|
144
66
|
end
|
145
67
|
|
146
|
-
def
|
147
|
-
|
148
|
-
"type" => "accepted",
|
149
|
-
"date" => date,
|
150
|
-
}
|
151
|
-
|
152
|
-
@dates ||= []
|
153
|
-
@dates << ConceptDate.new(date_hash)
|
68
|
+
def uuid_to_yaml(model, doc)
|
69
|
+
doc["id"] = model.uuid if model.uuid
|
154
70
|
end
|
155
71
|
|
156
|
-
def
|
157
|
-
|
158
|
-
@dates.find { |date| date.accepted? }
|
72
|
+
def uuid_from_yaml(model, value)
|
73
|
+
model.uuid = value
|
159
74
|
end
|
160
75
|
|
161
|
-
def
|
162
|
-
{
|
163
|
-
"data" => {
|
164
|
-
"dates" => dates&.map(&:to_h),
|
165
|
-
"definition" => definition&.map(&:to_h),
|
166
|
-
"examples" => examples&.map(&:to_h),
|
167
|
-
"id" => id,
|
168
|
-
"lineage_source_similarity" => lineage_source_similarity,
|
169
|
-
"notes" => notes&.map(&:to_h),
|
170
|
-
"release" => release,
|
171
|
-
"sources" => sources.empty? ? nil : sources&.map(&:to_h),
|
172
|
-
"terms" => (terms&.map(&:to_h) || []),
|
173
|
-
"related" => related&.map(&:to_h),
|
174
|
-
"domain" => domain,
|
175
|
-
}.compact,
|
176
|
-
|
177
|
-
"date_accepted" => date_accepted&.date,
|
178
|
-
|
179
|
-
}.compact
|
180
|
-
end
|
76
|
+
def id_to_yaml(model, doc); end
|
181
77
|
|
182
|
-
def
|
183
|
-
|
78
|
+
def id_from_yaml(model, value)
|
79
|
+
model.id = value
|
184
80
|
end
|
185
81
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
# rubocop:disable Metrics/AbcSize, Style/RescueModifier
|
191
|
-
def self.from_h(hash)
|
192
|
-
new.tap do |concept|
|
193
|
-
concept.id = hash.dig("termid") || hash.dig("id")
|
194
|
-
concept.sources = hash.dig("sources")
|
195
|
-
concept.related = hash.dig("related")
|
196
|
-
concept.definition = hash.dig("definition")
|
197
|
-
|
198
|
-
hash.values
|
199
|
-
.grep(Hash)
|
200
|
-
.map { |subhash| Config.class_for(:localized_concept).from_h(subhash) rescue nil }
|
201
|
-
.compact
|
202
|
-
|
203
|
-
concept.related = hash.dig("related") || []
|
82
|
+
def date_accepted_to_yaml(model, doc)
|
83
|
+
if model.date_accepted
|
84
|
+
doc["date_accepted"] =
|
85
|
+
model.date_accepted.date.iso8601
|
204
86
|
end
|
205
87
|
end
|
206
|
-
# rubocop:enable Metrics/AbcSize, Style/RescueModifier
|
207
88
|
|
208
|
-
|
209
|
-
|
210
|
-
def related
|
211
|
-
@related.empty? ? nil : @related
|
212
|
-
end
|
89
|
+
def date_accepted_from_yaml(model, value)
|
90
|
+
return if model.date_accepted
|
213
91
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
end
|
218
|
-
|
219
|
-
Glossarist::GlossaryDefinition::CONCEPT_DATE_TYPES.each do |type|
|
220
|
-
# Sets the ConceptDate and add it to dates list of the specified type.
|
221
|
-
define_method("date_#{type}=") do |date|
|
222
|
-
date_hash = {
|
223
|
-
"type" => type,
|
224
|
-
"date" => date,
|
225
|
-
}
|
226
|
-
@dates ||= []
|
227
|
-
@dates << ConceptDate.new(date_hash)
|
228
|
-
end
|
92
|
+
model.data.dates ||= []
|
93
|
+
model.data.dates << ConceptDate.of_yaml({ "date" => value,
|
94
|
+
"type" => "accepted" })
|
229
95
|
end
|
230
96
|
|
231
|
-
def
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
if arg["sources"]
|
238
|
-
arg.delete("authoritative_source")
|
239
|
-
arg.delete("authoritativeSource")
|
240
|
-
end
|
241
|
-
end
|
97
|
+
def uuid
|
98
|
+
@uuid ||= Glossarist::Utilities::UUID.uuid_v5(
|
99
|
+
Glossarist::Utilities::UUID::OID_NAMESPACE,
|
100
|
+
data.to_yaml,
|
101
|
+
)
|
242
102
|
end
|
243
103
|
end
|
244
104
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Glossarist
|
2
|
+
class ConceptData < Lutaml::Model::Serializable
|
3
|
+
include Glossarist::Utilities::CommonFunctions
|
4
|
+
|
5
|
+
attribute :dates, ConceptDate, collection: true
|
6
|
+
attribute :definition, DetailedDefinition, collection: true
|
7
|
+
attribute :examples, DetailedDefinition, collection: true
|
8
|
+
attribute :id, :string
|
9
|
+
attribute :lineage_source_similarity, :integer
|
10
|
+
attribute :notes, DetailedDefinition, collection: true
|
11
|
+
attribute :release, :string
|
12
|
+
attribute :sources, ConceptSource, collection: true
|
13
|
+
attribute :terms, Designation::Base, collection: true
|
14
|
+
attribute :related, RelatedConcept, collection: true
|
15
|
+
attribute :domain, :string
|
16
|
+
attribute :review_date, :date_time
|
17
|
+
attribute :review_decision_date, :date_time
|
18
|
+
attribute :review_decision_event, :string
|
19
|
+
|
20
|
+
# Concept Methods
|
21
|
+
# Language code should be exactly 3 char long.
|
22
|
+
# TODO: use min_length, max_length once added in lutaml-model
|
23
|
+
attribute :language_code, :string, pattern: /^.{3}$/
|
24
|
+
attribute :entry_status, :string
|
25
|
+
|
26
|
+
yaml do
|
27
|
+
map :dates, to: :dates
|
28
|
+
map :definition, to: :definition, render_nil: true
|
29
|
+
map :examples, to: :examples, render_nil: true
|
30
|
+
map :id, to: :id
|
31
|
+
map %i[lineage_source_similarity lineageSourceSimilarity], to: :lineage_source_similarity
|
32
|
+
map :notes, to: :notes, render_nil: true
|
33
|
+
map :release, to: :release
|
34
|
+
map :sources, to: :sources
|
35
|
+
map :terms, to: :terms,
|
36
|
+
with: { from: :terms_from_yaml, to: :terms_to_yaml }
|
37
|
+
map :related, to: :related
|
38
|
+
map :domain, to: :domain
|
39
|
+
map %i[language_code languageCode], to: :language_code
|
40
|
+
map %i[entry_status entryStatus], to: :entry_status
|
41
|
+
map %i[review_date reviewDate], to: :review_date
|
42
|
+
map %i[review_decision_date reviewDecisionDate], to: :review_decision_date
|
43
|
+
map %i[review_decision_event reviewDecisionEvent], to: :review_decision_event
|
44
|
+
end
|
45
|
+
|
46
|
+
def terms_from_yaml(model, value)
|
47
|
+
model.terms = value.map { |v| Designation::Base.of_yaml(v) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def terms_to_yaml(model, doc)
|
51
|
+
doc["terms"] = model.terms.map(&:to_yaml_hash)
|
52
|
+
end
|
53
|
+
|
54
|
+
def date_accepted
|
55
|
+
return nil unless dates
|
56
|
+
|
57
|
+
dates.find(&:accepted?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def authoritative_source
|
61
|
+
return [] unless sources
|
62
|
+
|
63
|
+
sources.select(&:authoritative?)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -1,20 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Glossarist
|
4
|
-
class ConceptDate < Model
|
5
|
-
include Glossarist::Utilities::Enum
|
6
|
-
|
4
|
+
class ConceptDate < Lutaml::Model::Serializable
|
7
5
|
# Iso8601 date
|
8
6
|
# @return [String]
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
attribute :date, :date_time
|
8
|
+
attribute :type, :string,
|
9
|
+
values: Glossarist::GlossaryDefinition::CONCEPT_DATE_TYPES
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
"type" => type,
|
17
|
-
}.compact
|
11
|
+
yaml do
|
12
|
+
map :date, to: :date
|
13
|
+
map :type, to: :type
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|
@@ -1,44 +1,35 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Glossarist
|
4
|
-
class ConceptManager
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# concepts directory path, either absolute or relative to CWD
|
12
|
-
def initialize(path: nil)
|
13
|
-
@path = path
|
2
|
+
class ConceptManager < Lutaml::Model::Serializable
|
3
|
+
attribute :path, :string
|
4
|
+
attribute :localized_concepts_path, :string
|
5
|
+
|
6
|
+
yaml do
|
7
|
+
map :path, to: :path
|
8
|
+
map %i[localized_concepts_path localizedConceptsPath], to: :localized_concepts_path
|
14
9
|
end
|
15
10
|
|
16
|
-
# Reads all concepts from files.
|
17
11
|
def load_from_files(collection: nil)
|
18
12
|
collection ||= ManagedConceptCollection.new
|
19
13
|
|
20
14
|
Dir.glob(concepts_glob) do |filename|
|
21
|
-
concept =
|
22
|
-
Glossarist::V1Reader.load_concept_from_file(filename)
|
23
|
-
else
|
24
|
-
load_concept_from_file(filename)
|
25
|
-
end
|
15
|
+
concept = load_concept_from_file(filename)
|
26
16
|
|
27
17
|
collection.store(concept)
|
28
18
|
end
|
29
19
|
end
|
30
20
|
|
31
|
-
# Writes all concepts to files.
|
32
21
|
def save_to_files(managed_concepts)
|
33
|
-
managed_concepts.
|
22
|
+
managed_concepts.each &method(:save_concept_to_file)
|
34
23
|
end
|
35
24
|
|
36
25
|
def load_concept_from_file(filename)
|
37
|
-
concept_hash = Psych.safe_load(File.read(filename),
|
26
|
+
concept_hash = Psych.safe_load(File.read(filename),
|
27
|
+
permitted_classes: [Date, Time])
|
38
28
|
concept_hash["uuid"] = concept_hash["id"] || File.basename(filename, ".*")
|
39
29
|
|
40
|
-
concept = Config.class_for(:managed_concept).
|
41
|
-
|
30
|
+
concept = Config.class_for(:managed_concept).of_yaml(concept_hash)
|
31
|
+
|
32
|
+
concept.data.localized_concepts.each_value do |id|
|
42
33
|
localized_concept = load_localized_concept(id)
|
43
34
|
concept.add_l10n(localized_concept)
|
44
35
|
end
|
@@ -55,7 +46,7 @@ module Glossarist
|
|
55
46
|
)
|
56
47
|
concept_hash["uuid"] = id
|
57
48
|
|
58
|
-
Config.class_for(:localized_concept).
|
49
|
+
Config.class_for(:localized_concept).of_yaml(concept_hash)
|
59
50
|
rescue Psych::SyntaxError => e
|
60
51
|
raise Glossarist::ParseError.new(filename: filename, line: e.line)
|
61
52
|
end
|
@@ -70,16 +61,14 @@ module Glossarist
|
|
70
61
|
Dir.mkdir(localized_concept_dir) unless Dir.exist?(localized_concept_dir)
|
71
62
|
|
72
63
|
filename = File.join(concept_dir, "#{concept.uuid}.yaml")
|
73
|
-
File.write(filename,
|
64
|
+
File.write(filename, concept.to_yaml)
|
74
65
|
|
75
66
|
concept.localized_concepts.each do |lang, uuid|
|
76
67
|
filename = File.join(localized_concept_dir, "#{uuid}.yaml")
|
77
|
-
File.write(filename,
|
68
|
+
File.write(filename, concept.localization(lang).to_yaml)
|
78
69
|
end
|
79
70
|
end
|
80
71
|
|
81
|
-
private
|
82
|
-
|
83
72
|
def concepts_glob
|
84
73
|
if v1_collection?
|
85
74
|
File.join(path, "concept-*.{yaml,yml}")
|
@@ -116,7 +105,8 @@ module Glossarist
|
|
116
105
|
end
|
117
106
|
|
118
107
|
def v1_collection?
|
119
|
-
@v1_collection ||= !Dir.glob(File.join(path,
|
108
|
+
@v1_collection ||= !Dir.glob(File.join(path,
|
109
|
+
"concept-*.{yaml,yml}")).empty?
|
120
110
|
end
|
121
111
|
end
|
122
112
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "set"
|
4
|
+
|
3
5
|
module Glossarist
|
4
6
|
class ConceptSet
|
5
7
|
# a `Glossarist::ManagedConceptCollection` object
|
@@ -40,7 +42,7 @@ module Glossarist
|
|
40
42
|
concept = concept_map[concept_name.strip.downcase]
|
41
43
|
|
42
44
|
if concept.nil?
|
43
|
-
|
45
|
+
puts " [Not Found]: #{concept_name.strip}"
|
44
46
|
else
|
45
47
|
latex_template(concept)
|
46
48
|
end
|
@@ -57,7 +59,7 @@ module Glossarist
|
|
57
59
|
|
58
60
|
def latex_template(concept)
|
59
61
|
<<~TEMPLATE
|
60
|
-
\\newglossaryentry{#{concept.default_designation.
|
62
|
+
\\newglossaryentry{#{concept.default_designation.tr('_', '-')}}
|
61
63
|
{
|
62
64
|
name={#{concept.default_designation.gsub('_', '\_')}}
|
63
65
|
description={#{normalize_definition(concept.default_definition)}}
|
@@ -66,8 +68,8 @@ module Glossarist
|
|
66
68
|
end
|
67
69
|
|
68
70
|
def normalize_definition(definition)
|
69
|
-
definition.gsub(/{{([^}]*)}}/) do |
|
70
|
-
"\\textbf{\\gls{#{Regexp.last_match[1].
|
71
|
+
definition.gsub(/{{([^}]*)}}/) do |_match|
|
72
|
+
"\\textbf{\\gls{#{Regexp.last_match[1].tr('_', '-')}}}"
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
@@ -1,62 +1,19 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Glossarist
|
4
|
-
class ConceptSource < Model
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
self.modification = rel["modification"]
|
20
|
-
end
|
21
|
-
|
22
|
-
self.origin = slice_keys(attributes, ref_param_names)
|
23
|
-
|
24
|
-
remaining_attributes = attributes.dup
|
25
|
-
ref_param_names.each { |k| remaining_attributes.delete(k) }
|
26
|
-
|
27
|
-
super(remaining_attributes)
|
28
|
-
end
|
29
|
-
|
30
|
-
def origin=(origin)
|
31
|
-
@origin = Citation.new(origin)
|
32
|
-
end
|
33
|
-
|
34
|
-
alias_method :ref=, :origin=
|
35
|
-
|
36
|
-
def to_h
|
37
|
-
origin_hash = self.origin.to_h.empty? ? nil : self.origin.to_h
|
38
|
-
|
39
|
-
{
|
40
|
-
"origin" => origin_hash,
|
41
|
-
"type" => type.to_s,
|
42
|
-
"status" => status&.to_s,
|
43
|
-
"modification" => modification,
|
44
|
-
}.compact
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def ref_param_names
|
50
|
-
%w[
|
51
|
-
ref
|
52
|
-
text
|
53
|
-
source
|
54
|
-
id
|
55
|
-
version
|
56
|
-
clause
|
57
|
-
link
|
58
|
-
original
|
59
|
-
]
|
2
|
+
class ConceptSource < Lutaml::Model::Serializable
|
3
|
+
attribute :status, :string,
|
4
|
+
values: Glossarist::GlossaryDefinition::CONCEPT_SOURCE_STATUSES
|
5
|
+
attribute :type, :string,
|
6
|
+
values: Glossarist::GlossaryDefinition::CONCEPT_SOURCE_TYPES
|
7
|
+
attribute :origin, Citation
|
8
|
+
attribute :modification, :string
|
9
|
+
|
10
|
+
yaml do
|
11
|
+
# TODO: change to `map [:ref, :origin], to: :origin
|
12
|
+
# when multiple key mapping is supported in lutaml-model
|
13
|
+
map :origin, to: :origin
|
14
|
+
map :status, to: :status
|
15
|
+
map :type, to: :type
|
16
|
+
map :modification, to: :modification
|
60
17
|
end
|
61
18
|
end
|
62
19
|
end
|
data/lib/glossarist/config.rb
CHANGED
@@ -42,19 +42,19 @@ module Glossarist
|
|
42
42
|
|
43
43
|
class << self
|
44
44
|
def class_for(name)
|
45
|
-
|
45
|
+
instance.class_for(name)
|
46
46
|
end
|
47
47
|
|
48
48
|
def extension_attributes
|
49
|
-
|
49
|
+
instance.extension_attributes
|
50
50
|
end
|
51
51
|
|
52
52
|
def register_class(class_name, klass)
|
53
|
-
|
53
|
+
instance.register_class(class_name, klass)
|
54
54
|
end
|
55
55
|
|
56
56
|
def register_extension_attributes(attributes)
|
57
|
-
|
57
|
+
instance.register_extension_attributes(attributes)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "expression"
|
4
|
-
require_relative "../utilities"
|
5
|
-
|
6
1
|
module Glossarist
|
7
2
|
module Designation
|
8
3
|
class Abbreviation < Expression
|
9
|
-
|
10
|
-
|
11
|
-
register_enum :type, Glossarist::GlossaryDefinition::ABBREVIATION_TYPES
|
4
|
+
attribute :international, :boolean
|
5
|
+
attribute :type, :string, default: -> { "abbreviation" }
|
12
6
|
|
13
|
-
|
7
|
+
Glossarist::GlossaryDefinition::ABBREVIATION_TYPES.each do |name|
|
8
|
+
attribute name.to_sym, :boolean
|
9
|
+
end
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
yaml do
|
12
|
+
map :international, to: :international
|
13
|
+
map :type, to: :type, render_default: true
|
14
|
+
Glossarist::GlossaryDefinition::ABBREVIATION_TYPES.each do |name|
|
15
|
+
map name.to_sym, to: name.to_sym
|
16
|
+
end
|
17
|
+
end
|
20
18
|
|
21
|
-
|
19
|
+
def self.of_yaml(hash, options = {})
|
20
|
+
hash["type"] = "abbreviation" unless hash["type"]
|
22
21
|
|
23
|
-
super
|
22
|
+
super
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|