glossarist 2.3.0 → 2.3.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/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +65 -0
- data/README.adoc +2 -2
- data/config.yml +1 -1
- 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 +67 -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 +29 -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 +74 -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
@@ -3,9 +3,9 @@
|
|
3
3
|
# (c) Copyright 2021 Ribose Inc.
|
4
4
|
#
|
5
5
|
|
6
|
-
require_relative "designation/abbreviation"
|
7
6
|
require_relative "designation/base"
|
8
7
|
require_relative "designation/expression"
|
8
|
+
require_relative "designation/abbreviation"
|
9
9
|
require_relative "designation/grammar_info"
|
10
10
|
require_relative "designation/symbol"
|
11
11
|
require_relative "designation/graphical_symbol"
|
@@ -21,7 +21,7 @@ module Glossarist
|
|
21
21
|
GraphicalSymbol => "graphical_symbol",
|
22
22
|
LetterSymbol => "letter_symbol",
|
23
23
|
}
|
24
|
-
|
25
|
-
|
24
|
+
.tap { |h| h.merge!(h.invert) }
|
25
|
+
.freeze
|
26
26
|
end
|
27
27
|
end
|
@@ -1,31 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Glossarist
|
4
|
-
class DetailedDefinition < Model
|
4
|
+
class DetailedDefinition < Lutaml::Model::Serializable
|
5
|
+
attribute :content, :string
|
6
|
+
attribute :sources, ConceptSource, collection: true
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
else
|
10
|
-
self.content = attributes
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [String]
|
15
|
-
attr_accessor :content
|
16
|
-
|
17
|
-
# @return [Array<ConceptSource>]
|
18
|
-
attr_reader :sources
|
19
|
-
|
20
|
-
def sources=(sources)
|
21
|
-
@sources = sources.map { |s| ConceptSource.new(s) }
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_h
|
25
|
-
{
|
26
|
-
"content" => content,
|
27
|
-
"sources" => sources&.map(&:to_h),
|
28
|
-
}.compact
|
8
|
+
yaml do
|
9
|
+
map :content, to: :content
|
10
|
+
map :sources, to: :sources
|
29
11
|
end
|
30
12
|
end
|
31
13
|
end
|
data/lib/glossarist/error.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative "error/invalid_type_error"
|
2
|
-
require_relative "error/invalid_language_code_error"
|
3
|
-
require_relative "error/parse_error"
|
4
|
-
|
5
1
|
module Glossarist
|
6
2
|
class Error < StandardError
|
7
3
|
end
|
8
4
|
end
|
5
|
+
|
6
|
+
require_relative "error/invalid_type_error"
|
7
|
+
require_relative "error/invalid_language_code_error"
|
8
|
+
require_relative "error/parse_error"
|
@@ -4,7 +4,8 @@ require "yaml"
|
|
4
4
|
|
5
5
|
module Glossarist
|
6
6
|
module GlossaryDefinition
|
7
|
-
config = YAML.load_file(File.expand_path("
|
7
|
+
config = YAML.load_file(File.expand_path("../../config.yml",
|
8
|
+
__dir__)) || {}
|
8
9
|
|
9
10
|
CONCEPT_SOURCE_STATUSES = config.dig("concept_source", "status").freeze
|
10
11
|
|
@@ -14,13 +15,15 @@ module Glossarist
|
|
14
15
|
|
15
16
|
ABBREVIATION_TYPES = config.dig("abbreviation", "type").freeze
|
16
17
|
|
17
|
-
GRAMMAR_INFO_BOOLEAN_ATTRIBUTES = config.dig("grammar_info",
|
18
|
+
GRAMMAR_INFO_BOOLEAN_ATTRIBUTES = config.dig("grammar_info",
|
19
|
+
"boolean_attribute").freeze
|
18
20
|
|
19
21
|
GRAMMAR_INFO_GENDERS = config.dig("grammar_info", "gender").freeze
|
20
22
|
|
21
23
|
GRAMMAR_INFO_NUMBERS = config.dig("grammar_info", "number").freeze
|
22
24
|
|
23
|
-
DESIGNATION_BASE_NORMATIVE_STATUSES = config.dig("designation", "base",
|
25
|
+
DESIGNATION_BASE_NORMATIVE_STATUSES = config.dig("designation", "base",
|
26
|
+
"normative_status").freeze
|
24
27
|
|
25
28
|
CONCEPT_DATE_TYPES = config.dig("concept_date", "type").freeze
|
26
29
|
|
@@ -1,75 +1,30 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# (c) Copyright 2021 Ribose Inc.
|
4
|
-
#
|
5
|
-
|
6
1
|
module Glossarist
|
7
2
|
class LocalizedConcept < Concept
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
attr_reader :language_code
|
12
|
-
|
13
|
-
# Must be one of the following:
|
14
|
-
# +notValid+, +valid+, +superseded+, +retired+.
|
15
|
-
# @todo Proper type checking.
|
16
|
-
# @note Works with strings, but soon they may be replaced with symbols.
|
17
|
-
# @return [String]
|
18
|
-
attr_accessor :entry_status
|
19
|
-
alias_method :status=, :entry_status=
|
20
|
-
|
21
|
-
# Must be one of the following:
|
22
|
-
# +preferred+, +admitted+, +deprecated+.
|
23
|
-
# @todo Proper type checking.
|
24
|
-
# @note Works with strings, but soon they may be replaced with symbols.
|
25
|
-
# @return [String]
|
26
|
-
attr_accessor :classification
|
27
|
-
|
28
|
-
# Temporary fields
|
29
|
-
# @todo Need to remove these once the isotc211-glossary is fixed
|
30
|
-
attr_accessor *%i[
|
31
|
-
review_date
|
32
|
-
review_decision_date
|
33
|
-
review_decision_event
|
34
|
-
review_type
|
35
|
-
]
|
3
|
+
attribute :classification, :string
|
4
|
+
attribute :review_type, :string
|
5
|
+
attribute :entry_status, :string
|
36
6
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
raise Glossarist::InvalidLanguageCodeError.new(code: language_code)
|
42
|
-
end
|
7
|
+
yaml do
|
8
|
+
map :classification, to: :classification
|
9
|
+
map :review_type, to: :review_type
|
43
10
|
end
|
44
11
|
|
45
|
-
|
46
|
-
hash = super
|
47
|
-
|
48
|
-
hash["data"].merge!({
|
49
|
-
"language_code" => language_code,
|
50
|
-
"entry_status" => entry_status,
|
51
|
-
"sources" => sources.empty? ? nil : sources&.map(&:to_h),
|
52
|
-
"classification" => classification,
|
53
|
-
"dates" => dates&.map(&:to_h),
|
54
|
-
"review_date" => review_date,
|
55
|
-
"review_decision_date" => review_decision_date,
|
56
|
-
"review_decision_event" => review_decision_event,
|
57
|
-
}.compact).merge!(@extension_attributes)
|
58
|
-
|
59
|
-
hash["status"] = entry_status if entry_status
|
12
|
+
alias_method :status=, :entry_status=
|
60
13
|
|
61
|
-
|
14
|
+
def language_code
|
15
|
+
data.language_code
|
62
16
|
end
|
63
17
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
18
|
+
def entry_status
|
19
|
+
data.entry_status
|
20
|
+
end
|
67
21
|
|
68
|
-
|
22
|
+
def language_code=(value)
|
23
|
+
data.language_code = value
|
69
24
|
end
|
70
25
|
|
71
|
-
|
72
|
-
|
73
|
-
|
26
|
+
def entry_status=(value)
|
27
|
+
data.entry_status = value
|
28
|
+
end
|
74
29
|
end
|
75
30
|
end
|
@@ -1,90 +1,102 @@
|
|
1
|
-
|
1
|
+
require_relative "localized_concept"
|
2
2
|
|
3
3
|
module Glossarist
|
4
|
-
class ManagedConcept < Model
|
5
|
-
include Glossarist::Utilities::Enum
|
4
|
+
class ManagedConcept < Lutaml::Model::Serializable
|
6
5
|
include Glossarist::Utilities::CommonFunctions
|
7
6
|
|
8
|
-
|
9
|
-
attr_accessor :id
|
10
|
-
alias :termid= :id=
|
11
|
-
alias :identifier= :id=
|
7
|
+
attribute :data, ManagedConceptData
|
12
8
|
|
13
|
-
|
9
|
+
attribute :related, RelatedConcept, collection: true
|
10
|
+
attribute :dates, ConceptDate, collection: true
|
11
|
+
attribute :sources, ConceptSource
|
12
|
+
attribute :date_accepted, ConceptDate
|
13
|
+
# TODO: convert to LocalizedConceptCollection when custom
|
14
|
+
# collections are implemented in lutaml-model
|
15
|
+
attribute :status, :string,
|
16
|
+
values: Glossarist::GlossaryDefinition::CONCEPT_STATUSES
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
attribute :identifier, :string
|
19
|
+
alias :id :identifier
|
20
|
+
alias :id= :identifier=
|
17
21
|
|
18
|
-
|
19
|
-
register_enum :status, Glossarist::GlossaryDefinition::CONCEPT_STATUSES
|
22
|
+
attribute :uuid, :string
|
20
23
|
|
21
|
-
|
22
|
-
|
24
|
+
yaml do
|
25
|
+
map :data, to: :data
|
26
|
+
map :id, with: { to: :identifier_to_yaml, from: :identifier_from_yaml }
|
27
|
+
map :identifier,
|
28
|
+
with: { to: :identifier_to_yaml, from: :identifier_from_yaml }
|
29
|
+
map :related, to: :related
|
30
|
+
map :dates, to: :dates
|
31
|
+
map :date_accepted,
|
32
|
+
with: { from: :date_accepted_from_yaml, to: :date_accepted_to_yaml }
|
33
|
+
map :status, to: :status
|
23
34
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# Concept group
|
28
|
-
# @return [Array<String>]
|
29
|
-
attr_reader :groups
|
30
|
-
|
31
|
-
# List of authorative sources.
|
32
|
-
# @return [Array<ConceptSource>]
|
33
|
-
attr_reader :sources
|
35
|
+
map :uuid, to: :uuid, with: { from: :uuid_from_yaml, to: :uuid_to_yaml }
|
36
|
+
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# @return [Hash<String, LocalizedConcept>]
|
39
|
-
attr_reader :localizations
|
38
|
+
def localized_concepts
|
39
|
+
data.localized_concepts
|
40
|
+
end
|
40
41
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
@localized_concept_class = Config.class_for(:localized_concept)
|
45
|
-
@uuid_namespace = Glossarist::Utilities::UUID::OID_NAMESPACE
|
42
|
+
def localized_concepts=(val)
|
43
|
+
data.localized_concepts = val
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
46
|
+
def localizations
|
47
|
+
data.localizations
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
def localization(lang)
|
51
|
+
localizations[lang]
|
52
|
+
end
|
53
|
+
alias :l10n :localization
|
53
54
|
|
54
|
-
|
55
|
+
def date_accepted_from_yaml(model, value)
|
56
|
+
model.dates ||= []
|
57
|
+
model.dates << ConceptDate.of_yaml({ "date" => value,
|
58
|
+
"type" => "accepted" })
|
59
|
+
end
|
55
60
|
|
56
|
-
|
61
|
+
def date_accepted_to_yaml(model, doc)
|
62
|
+
doc["date_accepted"] = model.date_accepted.date if model.date_accepted
|
57
63
|
end
|
58
64
|
|
59
|
-
def
|
60
|
-
|
65
|
+
def uuid_to_yaml(model, doc)
|
66
|
+
doc["id"] = model.uuid if model.uuid
|
61
67
|
end
|
62
68
|
|
63
|
-
def
|
64
|
-
|
69
|
+
def uuid_from_yaml(model, value)
|
70
|
+
model.uuid = value if value
|
65
71
|
end
|
66
72
|
|
67
|
-
def
|
68
|
-
@
|
73
|
+
def uuid
|
74
|
+
@uuid ||= Glossarist::Utilities::UUID.uuid_v5(
|
75
|
+
Glossarist::Utilities::UUID::OID_NAMESPACE,
|
76
|
+
to_yaml(except: [:uuid]),
|
77
|
+
)
|
69
78
|
end
|
70
79
|
|
71
|
-
def
|
72
|
-
|
80
|
+
def identifier_to_yaml(model, doc)
|
81
|
+
value = model.identifier || model.id
|
82
|
+
doc["id"] = value if value && !doc["id"]
|
83
|
+
end
|
73
84
|
|
74
|
-
|
85
|
+
def identifier_from_yaml(model, value)
|
86
|
+
model.identifier = value || model.identifier
|
75
87
|
end
|
76
88
|
|
77
|
-
def localized_concepts=(
|
78
|
-
return unless
|
89
|
+
def localized_concepts=(localized_concepts_collection)
|
90
|
+
return unless localized_concepts_collection
|
79
91
|
|
80
|
-
if
|
81
|
-
@localized_concepts = stringify_keys(
|
92
|
+
if localized_concepts_collection.is_a?(Hash)
|
93
|
+
@localized_concepts = stringify_keys(localized_concepts_collection)
|
82
94
|
else
|
83
|
-
|
84
|
-
lang = localized_concept_hash
|
95
|
+
localized_concepts_collection.each do |localized_concept_hash|
|
96
|
+
lang = localized_concept_hash.dig("data", "language_code").to_s
|
85
97
|
|
86
98
|
localized_concept = add_localization(
|
87
|
-
|
99
|
+
Config.class_for(:localized_concept).of_yaml(localized_concept_hash),
|
88
100
|
)
|
89
101
|
|
90
102
|
@localized_concepts[lang] = localization(lang).uuid
|
@@ -93,72 +105,22 @@ module Glossarist
|
|
93
105
|
end
|
94
106
|
end
|
95
107
|
end
|
96
|
-
|
97
|
-
def sources=(sources)
|
98
|
-
@sources = sources&.map do |source|
|
99
|
-
ConceptSource.new(source)
|
100
|
-
end || []
|
101
|
-
end
|
102
|
-
|
103
|
-
def localizations=(localizations)
|
104
|
-
return unless localizations
|
105
|
-
|
106
|
-
@localizations = {}
|
107
|
-
|
108
|
-
localizations.each do |localized_concept|
|
109
|
-
unless localized_concept.is_a?(@localized_concept_class)
|
110
|
-
localized_concept = @localized_concept_class.new(
|
111
|
-
localized_concept["data"] || localized_concept,
|
112
|
-
)
|
113
|
-
end
|
114
|
-
|
115
|
-
add_l10n(localized_concept)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def localizations_hash
|
120
|
-
@localizations.map do |key, localized_concept|
|
121
|
-
[key, localized_concept.to_h]
|
122
|
-
end.to_h
|
123
|
-
end
|
108
|
+
attr_reader :localized_concepts
|
124
109
|
|
125
110
|
# Adds concept localization.
|
126
111
|
# @param localized_concept [LocalizedConcept]
|
127
112
|
def add_localization(localized_concept)
|
128
113
|
lang = localized_concept.language_code
|
129
|
-
@localized_concepts
|
114
|
+
@localized_concepts ||= {}
|
115
|
+
@localized_concepts[lang] =
|
116
|
+
@localized_concepts[lang] || localized_concept.uuid
|
130
117
|
localizations.store(lang, localized_concept)
|
131
118
|
end
|
132
|
-
|
133
119
|
alias :add_l10n :add_localization
|
134
120
|
|
135
121
|
# Returns concept localization.
|
136
122
|
# @param lang [String] language code
|
137
123
|
# @return [LocalizedConcept]
|
138
|
-
def localization(lang)
|
139
|
-
localizations[lang]
|
140
|
-
end
|
141
|
-
|
142
|
-
alias :l10n :localization
|
143
|
-
|
144
|
-
def to_h_no_uuid
|
145
|
-
{
|
146
|
-
"data" => {
|
147
|
-
"identifier" => id,
|
148
|
-
"localized_concepts" => localized_concepts.empty? ? nil : localized_concepts,
|
149
|
-
"groups" => groups,
|
150
|
-
"sources" => sources&.map(&:to_h),
|
151
|
-
}.compact,
|
152
|
-
"related" => related&.map(&:to_h),
|
153
|
-
"date_accepted" => date_accepted&.date,
|
154
|
-
"status" => status,
|
155
|
-
}.compact
|
156
|
-
end
|
157
|
-
|
158
|
-
def to_h
|
159
|
-
to_h_no_uuid.merge("id" => uuid)
|
160
|
-
end
|
161
|
-
|
162
124
|
def default_designation
|
163
125
|
localized = localization("eng") || localizations.values.first
|
164
126
|
terms = localized&.preferred_terms&.first || localized&.terms&.first
|
@@ -167,47 +129,13 @@ module Glossarist
|
|
167
129
|
|
168
130
|
def default_definition
|
169
131
|
localized = localization("eng") || localizations.values.first
|
170
|
-
localized&.definition&.first&.content
|
132
|
+
localized&.data&.definition&.first&.content
|
171
133
|
end
|
172
134
|
|
173
135
|
def default_lang
|
174
136
|
localization("eng") || localizations.values.first
|
175
137
|
end
|
176
138
|
|
177
|
-
def date_accepted=(date)
|
178
|
-
date_hash = {
|
179
|
-
"type" => "accepted",
|
180
|
-
"date" => date,
|
181
|
-
}
|
182
|
-
|
183
|
-
@dates ||= []
|
184
|
-
@dates << ConceptDate.new(date_hash)
|
185
|
-
end
|
186
|
-
|
187
|
-
def date_accepted
|
188
|
-
return nil unless @dates
|
189
|
-
@dates.find { |date| date.accepted? }
|
190
|
-
end
|
191
|
-
|
192
|
-
def managed_concept_attributes
|
193
|
-
%i[
|
194
|
-
data
|
195
|
-
id
|
196
|
-
identifier
|
197
|
-
uuid
|
198
|
-
related
|
199
|
-
status
|
200
|
-
dates
|
201
|
-
date_accepted
|
202
|
-
dateAccepted
|
203
|
-
localized_concepts
|
204
|
-
localizedConcepts
|
205
|
-
localizations
|
206
|
-
groups
|
207
|
-
sources
|
208
|
-
].compact
|
209
|
-
end
|
210
|
-
|
211
139
|
Glossarist::GlossaryDefinition::RELATED_CONCEPT_TYPES.each do |type|
|
212
140
|
# List of related concepts of the specified type.
|
213
141
|
# @return [Array<RelatedConcept>]
|
@@ -1,36 +1,23 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Glossarist
|
4
2
|
class ManagedConceptCollection
|
5
3
|
include Enumerable
|
6
4
|
|
5
|
+
attr_accessor :managed_concepts
|
6
|
+
|
7
7
|
def initialize
|
8
|
-
@managed_concepts =
|
8
|
+
@managed_concepts = []
|
9
9
|
@managed_concepts_ids = {}
|
10
10
|
@concept_manager = ConceptManager.new
|
11
11
|
end
|
12
12
|
|
13
|
-
# @return [Array<ManagedConcept>]
|
14
|
-
def managed_concepts
|
15
|
-
@managed_concepts.values
|
16
|
-
end
|
17
|
-
|
18
|
-
def managed_concepts=(managed_concepts = [])
|
19
|
-
managed_concepts.each do |managed_concept|
|
20
|
-
store(Config.class_for(:managed_concept).new(managed_concept))
|
21
|
-
end
|
22
|
-
|
23
|
-
@managed_concepts.values
|
24
|
-
end
|
25
|
-
|
26
13
|
def to_h
|
27
14
|
{
|
28
|
-
"managed_concepts" => managed_concepts.map(&:
|
15
|
+
"managed_concepts" => managed_concepts.map(&:to_yaml_hash),
|
29
16
|
}.compact
|
30
17
|
end
|
31
18
|
|
32
19
|
def each(&block)
|
33
|
-
@managed_concepts.
|
20
|
+
@managed_concepts.each(&block)
|
34
21
|
end
|
35
22
|
|
36
23
|
# Returns concept with given ID, if it is present in collection, or +nil+
|
@@ -40,9 +27,10 @@ module Glossarist
|
|
40
27
|
# ManagedConcept ID
|
41
28
|
# @return [ManagedConcept, nil]
|
42
29
|
def fetch(id)
|
43
|
-
@managed_concepts
|
30
|
+
@managed_concepts.find do |c|
|
31
|
+
c.uuid == id || c.uuid == @managed_concepts_ids[id]
|
32
|
+
end
|
44
33
|
end
|
45
|
-
|
46
34
|
alias :[] :fetch
|
47
35
|
|
48
36
|
# If ManagedConcept with given ID is present in this collection, then
|
@@ -53,7 +41,7 @@ module Glossarist
|
|
53
41
|
# ManagedConcept ID
|
54
42
|
# @return [ManagedConcept]
|
55
43
|
def fetch_or_initialize(id)
|
56
|
-
fetch(id) or store(Config.class_for(:managed_concept).
|
44
|
+
fetch(id) or store(Config.class_for(:managed_concept).of_yaml(data: { id: id }))
|
57
45
|
end
|
58
46
|
|
59
47
|
# Adds concept to the collection. If collection contains a concept with
|
@@ -62,12 +50,15 @@ module Glossarist
|
|
62
50
|
# @param managed_concept [ManagedConcept]
|
63
51
|
# ManagedConcept about to be added
|
64
52
|
def store(managed_concept)
|
65
|
-
@managed_concepts[
|
66
|
-
@
|
53
|
+
@managed_concepts ||= []
|
54
|
+
@managed_concepts << managed_concept
|
55
|
+
if managed_concept.data.id
|
56
|
+
@managed_concepts_ids[managed_concept.data.id] =
|
57
|
+
managed_concept.uuid
|
58
|
+
end
|
67
59
|
|
68
60
|
managed_concept
|
69
61
|
end
|
70
|
-
|
71
62
|
alias :<< :store
|
72
63
|
|
73
64
|
def load_from_files(path)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Glossarist
|
2
|
+
class ManagedConceptData < Lutaml::Model::Serializable
|
3
|
+
include Glossarist::Utilities::CommonFunctions
|
4
|
+
|
5
|
+
attribute :id, :string
|
6
|
+
attribute :localized_concepts, :hash
|
7
|
+
attribute :groups, :string, collection: true
|
8
|
+
attribute :sources, ConceptSource, collection: true
|
9
|
+
attribute :localizations, :hash, collection: true, default: -> { {} }
|
10
|
+
|
11
|
+
yaml do
|
12
|
+
map %i[id identifier], to: :id,
|
13
|
+
with: { to: :id_to_yaml, from: :id_from_yaml }
|
14
|
+
map %i[localized_concepts localizedConcepts], to: :localized_concepts
|
15
|
+
map :groups, to: :groups
|
16
|
+
map :sources, to: :sources
|
17
|
+
map :localizations, to: :localizations,
|
18
|
+
with: { from: :localizations_from_yaml, to: :localizations_to_yaml }
|
19
|
+
end
|
20
|
+
|
21
|
+
def id_to_yaml(model, doc)
|
22
|
+
value = model.id || model.identifier
|
23
|
+
doc["identifier"] = value if value && !doc["identifier"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def id_from_yaml(model, value)
|
27
|
+
model.id = value unless model.id
|
28
|
+
end
|
29
|
+
|
30
|
+
def localizations_from_yaml(model, value)
|
31
|
+
model.localizations ||= {}
|
32
|
+
|
33
|
+
value.each do |localized_concept_hash|
|
34
|
+
localized_concept = Glossarist::LocalizedConcept.of_yaml(localized_concept_hash)
|
35
|
+
model.localizations[localized_concept.language_code] = localized_concept
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def localizations_to_yaml(model, doc); end
|
40
|
+
|
41
|
+
def authoritative_source
|
42
|
+
return [] unless sources
|
43
|
+
|
44
|
+
sources.select(&:authoritative?)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,18 +1,15 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Glossarist
|
4
|
-
class NonVerbRep
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# @return [Array<ConceptSource>]
|
10
|
-
attr_reader :sources
|
2
|
+
class NonVerbRep < Lutaml::Model::Serializable
|
3
|
+
attribute :image, :string
|
4
|
+
attribute :table, :string
|
5
|
+
attribute :formula, :string
|
6
|
+
attribute :sources, ConceptSource, collection: true
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
yaml do
|
9
|
+
map :image, to: :image
|
10
|
+
map :table, to: :table
|
11
|
+
map :formula, to: :formula
|
12
|
+
map :sources, to: :sources
|
16
13
|
end
|
17
14
|
end
|
18
15
|
end
|
@@ -1,31 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Glossarist
|
4
|
-
class RelatedConcept < Model
|
5
|
-
|
4
|
+
class RelatedConcept < Lutaml::Model::Serializable
|
5
|
+
attribute :content, :string
|
6
|
+
attribute :type, :string,
|
7
|
+
values: Glossarist::GlossaryDefinition::RELATED_CONCEPT_TYPES
|
8
|
+
attribute :ref, Citation
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# Reference to the related concept.
|
13
|
-
# @return [Citation]
|
14
|
-
attr_reader :ref
|
15
|
-
|
16
|
-
def ref=(ref)
|
17
|
-
@ref = Citation.new(ref)
|
10
|
+
yaml do
|
11
|
+
map :content, to: :content
|
12
|
+
map :type, to: :type
|
13
|
+
map :ref, with: { from: :ref_from_yaml, to: :ref_to_yaml }
|
18
14
|
end
|
19
15
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
16
|
+
def ref_to_yaml(model, doc)
|
17
|
+
doc["ref"] = Citation.as_yaml(model.ref)["ref"] if model.ref
|
18
|
+
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
"content" => content,
|
27
|
-
"ref" => reference,
|
28
|
-
}.compact
|
20
|
+
def ref_from_yaml(model, value)
|
21
|
+
model.ref = Citation.of_yaml(value)
|
29
22
|
end
|
30
23
|
end
|
31
24
|
end
|