metanorma-plugin-glossarist 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f950715c1c6a808aa2b24e8cb855ef674799465bd7a57b1f04ac73d1e899a91
4
- data.tar.gz: 4fb0bdfc76982a98749a03f8f89600cff06073fbe5a555d6ef2004d1fffda0b8
3
+ metadata.gz: daa2bea1e77bfd5f4bf2ec230949e1b553f977df76078f98cad24d24b471cd2c
4
+ data.tar.gz: 4f2387682fcca5c77a82a377ce7f739632adfa92656c289a69cd6b5e7e947724
5
5
  SHA512:
6
- metadata.gz: 02f4df920b7fb3b3b67f647764b49bbfa4f276bb6aa8c8c803c3f55227d257d4cd5bcd1b77a88996ce6d96d1d453626bf2ab088e75c8629520b8976ff7fecf9d
7
- data.tar.gz: 5c1a118c591f17783f7f54f9c66c316c3dd60b9034b8a23b904c22335a338a61d526c73d68d0f16a1c43c7d0520ac5469f32fc5da049004141cc42241769d968
6
+ metadata.gz: 2106de661a748c6f9026889236f3e6b53bc5cb1cbbad24ef0870210173f09ae0ba730afe2469bb7d55b57845ee5693efdee68c14efec608ae3c45961bcaac27b
7
+ data.tar.gz: c1280bae939146a0bda8c7c1904c9187dd1e922e9087cc14b5b1cd7b5a7fe43bc8b47fb5e87a921b1637f635a023de83824bc0896339b760efdc5fa4ed10c293
data/Gemfile CHANGED
@@ -4,6 +4,11 @@ Encoding.default_internal = Encoding::UTF_8
4
4
  source "https://rubygems.org"
5
5
  git_source(:github) { |repo| "https://github.com/#{repo}" }
6
6
 
7
+ gem "metanorma-standoc"
8
+ gem "pry"
9
+ gem "rake", "~> 12.0"
10
+ gem "rspec", "~> 3.0"
11
+
7
12
  gemspec
8
13
 
9
14
  eval_gemfile("Gemfile.devel") rescue nil
data/README.md CHANGED
@@ -138,6 +138,194 @@ The term bar is used as metasyntactic variables and placeholder names in compute
138
138
  The term foo is used as metasyntactic variables and placeholder names in computer programming
139
139
  ```
140
140
 
141
+ The full concept model (a concept can have multiple localized concepts) is available through the block as follows:
142
+
143
+ ```ruby
144
+ {
145
+ # UUIDs for localized concept mappings
146
+ "localized_concepts" => {
147
+ "eng" => "<uuid>", # English concept UUID
148
+ "fre" => "<uuid>" # French concept UUID
149
+ },
150
+
151
+ # Main concept term
152
+ "term" => "<string>",
153
+
154
+ # Language-specific content (structure repeated for each language code)
155
+ "<language_code>" => {
156
+ "dates" => [], # Array of relevant dates
157
+ "definition" => [ # Array of definition objects
158
+ {
159
+ "content" => "<string>" # Definition text
160
+ }
161
+ ],
162
+ "examples" => [], # Array of example objects
163
+ "id" => "<string>", # Concept ID
164
+
165
+ "notes" => [ # Array of note objects
166
+ {
167
+ "content" => "<string>" # Note text
168
+ }
169
+ ],
170
+
171
+ "sources" => [ # Array of source objects
172
+ {
173
+ "origin" => {
174
+ "ref" => "<string>" # Reference citation
175
+ },
176
+ "type" => "<string>", # Source type (e.g. "lineage")
177
+ "status" => "<string>" # Status (e.g. "identical")
178
+ }
179
+ ],
180
+
181
+ "terms" => [ # Array of term objects
182
+ {
183
+ "type" => "<string>", # Term type (e.g. "expression")
184
+ "normative_status" => "<string>", # Status (e.g. "preferred")
185
+ "designation" => "<string>", # Term text
186
+ "grammar_info" => [ # Array of grammar objects
187
+ {
188
+ "preposition" => boolean,
189
+ "participle" => boolean,
190
+ "adj" => boolean,
191
+ "verb" => boolean,
192
+ "adverb" => boolean,
193
+ "noun" => boolean,
194
+ "gender" => ["<string>"], # Array of grammatical genders
195
+ "number" => ["<string>"] # Array of grammatical numbers
196
+ }
197
+ ]
198
+ }
199
+ ],
200
+
201
+ "language_code" => "<string>" # ISO language code
202
+ }
203
+ }
204
+ ```
205
+
206
+ The language codes used are ISO 639-* 3-character codes, as described in the
207
+ [Glossarist Concept model](https://github.com/glossarist/concept-model).
208
+
209
+ An example of the full model (from ISO/IEC 2382:2015):
210
+
211
+ ```ruby
212
+ {
213
+ "localized_concepts" => {
214
+ "eng" => "01134f51-b88c-5214-8909-5d271ea619cf",
215
+ "fre" => "f290a3af-f1b3-527a-9045-a2dfcc0caf5a"
216
+ },
217
+ "term" => "concept description",
218
+ "eng" => {
219
+ "dates" => [],
220
+ "definition" => [
221
+ {
222
+ "content" => "data structure describing the class of all known instances of a concept"
223
+ }
224
+ ],
225
+ "examples" => [],
226
+ "id" => "2122978",
227
+ "notes" => [
228
+ {
229
+ "content" => "concept description: term and definition standardized by ISO/IEC [ISO/IEC 2382-31:1997]."
230
+ },
231
+ {
232
+ "content" => "31.02.02 (2382)"
233
+ }
234
+ ],
235
+ "sources" => [
236
+ {
237
+ "origin" => {
238
+ "ref" => "ISO/IEC 2382-31:1997"
239
+ },
240
+ "type" => "lineage",
241
+ "status" => "identical"
242
+ },
243
+ {
244
+ "origin" => {
245
+ "ref" => "Ranger, Natalie * 2006 * Bureau de la traduction / Translation Bureau * Services linguistiques / Linguistic Services * Bur. dir. Centre de traduction et de terminologie / Dir's Office Translation and Terminology Centre * Div. Citoyenneté et Protection civile / Citizen. & Emergency preparedness Div. * Normalisation terminologique / Terminology Standardization"
246
+ },
247
+ "type" => "lineage",
248
+ "status" => "identical"
249
+ }
250
+ ],
251
+ "terms" => [
252
+ {
253
+ "type" => "expression",
254
+ "normative_status" => "preferred",
255
+ "designation" => "concept description",
256
+ "grammar_info" => [
257
+ {
258
+ "preposition" => false,
259
+ "participle" => false,
260
+ "adj" => false,
261
+ "verb" => false,
262
+ "adverb" => false,
263
+ "noun" => false,
264
+ "gender" => [],
265
+ "number" => ["singular"]
266
+ }
267
+ ]
268
+ }
269
+ ],
270
+ "language_code" => "eng"
271
+ },
272
+ "fre" => {
273
+ "dates" => [],
274
+ "definition" => [
275
+ {
276
+ "content" => "structure de données qui décrit la classe des instances connues d'un concept"
277
+ }
278
+ ],
279
+ "examples" => [],
280
+ "id" => "2122978",
281
+ "notes" => [
282
+ {
283
+ "content" => "description de concept : terme et définition normalisés par l'ISO/CEI [ISO/IEC 2382-31:1997]."
284
+ },
285
+ {
286
+ "content" => "31.02.02 (2382)"
287
+ }
288
+ ],
289
+ "sources" => [
290
+ {
291
+ "origin" => {
292
+ "ref" => "ISO/IEC 2382-31:1997"
293
+ },
294
+ "type" => "lineage",
295
+ "status" => "identical"
296
+ },
297
+ {
298
+ "origin" => {
299
+ "ref" => "Ranger, Natalie * 2006 * Bureau de la traduction / Translation Bureau * Services linguistiques / Linguistic Services * Bur. dir. Centre de traduction et de terminologie / Dir's Office Translation and Terminology Centre * Div. Citoyenneté et Protection civile / Citizen. & Emergency preparedness Div. * Normalisation terminologique / Terminology Standardization"
300
+ },
301
+ "type" => "lineage",
302
+ "status" => "identical"
303
+ }
304
+ ],
305
+ "terms" => [
306
+ {
307
+ "type" => "expression",
308
+ "normative_status" => "preferred",
309
+ "designation" => "description de concept",
310
+ "grammar_info" => [
311
+ {
312
+ "preposition" => false,
313
+ "participle" => false,
314
+ "adj" => false,
315
+ "verb" => false,
316
+ "adverb" => false,
317
+ "noun" => false,
318
+ "gender" => ["f"],
319
+ "number" => ["singular"]
320
+ }
321
+ ]
322
+ }
323
+ ],
324
+ "language_code" => "fre"
325
+ }
326
+ }
327
+ ```
328
+
141
329
  ### Rendering a single term from loaded dataset
142
330
 
143
331
  This can be used to render a single concept from the loaded dataset. See [Loading Dataset](#loading-dataset) to load a dataset.
@@ -8,24 +8,20 @@ module Liquid
8
8
  # rubocop:disable Lint/MissingSuper
9
9
  def initialize(managed_concept_collection, filters = {})
10
10
  @concepts_collection = managed_concept_collection
11
- @concepts_map = {}
12
-
13
- filtered_concepts(@concepts_collection, filters).each do |concept|
14
- @concepts_map[concept["term"]] = concept
15
- end
11
+ @concepts = filtered_concepts(@concepts_collection, filters)
16
12
  end
17
13
  # rubocop:enable Lint/MissingSuper
18
14
 
19
15
  def concepts
20
- @concepts_map
16
+ @concepts
21
17
  end
22
18
 
23
19
  def [](concept_name)
24
- @concepts_map[concept_name]
20
+ @concepts.find { |c| c["term"] == concept_name }
25
21
  end
26
22
 
27
23
  def each(&block)
28
- @concepts_map.values.each(&block)
24
+ @concepts.each(&block)
29
25
  end
30
26
 
31
27
  private
@@ -60,7 +60,9 @@ module Metanorma
60
60
  super
61
61
  @config = config
62
62
  @datasets = {}
63
+ @title_depth = { value: 2 }
63
64
  @rendered_bibliographies = {}
65
+ @seen_glossarist = []
64
66
  end
65
67
 
66
68
  def process(document, reader)
@@ -73,10 +75,19 @@ module Metanorma
73
75
  @config[:file_system] = file_system
74
76
 
75
77
  processed_doc = prepare_document(document, input_lines)
78
+ log(document, processed_doc.to_s) unless @seen_glossarist.empty?
76
79
  Asciidoctor::PreprocessorReader.new(document,
77
80
  processed_doc.to_s.split("\n"))
78
81
  end
79
82
 
83
+ protected
84
+
85
+ def log(doc, text)
86
+ File.open("#{doc.attr('docfile')}.glossarist.log.txt", "w:UTF-8") do |f|
87
+ f.write(text)
88
+ end
89
+ end
90
+
80
91
  private
81
92
 
82
93
  def prepare_document(document, input_lines, end_mark = nil)
@@ -109,11 +120,13 @@ module Metanorma
109
120
  elsif match = current_line.match(GLOSSARIST_BLOCK_REGEX)
110
121
  process_glossarist_block(document, liquid_doc, input_lines, match)
111
122
  else
123
+ @title_depth[:value] = current_line.sub(/ .*$/, "").size if /^==+ \S/.match?(current_line)
112
124
  liquid_doc.add_content(current_line)
113
125
  end
114
126
  end
115
127
 
116
128
  def process_dataset_tag(document, input_lines, liquid_doc, match)
129
+ @seen_glossarist << "x"
117
130
  context_names = prepare_dataset_contexts(document, match[1])
118
131
 
119
132
  dataset_section = <<~TEMPLATE
@@ -129,6 +142,7 @@ module Metanorma
129
142
  end
130
143
 
131
144
  def process_glossarist_block(document, liquid_doc, input_lines, match)
145
+ @seen_glossarist << "x"
132
146
  end_mark = input_lines.next
133
147
  path = relative_file_path(document, match[1])
134
148
 
@@ -160,6 +174,7 @@ module Metanorma
160
174
  end
161
175
 
162
176
  def process_render_tag(liquid_doc, match)
177
+ @seen_glossarist << "x"
163
178
  context_name, concept_name = match[1].split(",")
164
179
 
165
180
  liquid_doc.add_content(
@@ -168,6 +183,7 @@ module Metanorma
168
183
  end
169
184
 
170
185
  def process_import_tag(liquid_doc, match)
186
+ @seen_glossarist << "x"
171
187
  context_name = match[1].strip
172
188
  dataset = @datasets[context_name.strip]
173
189
 
@@ -179,17 +195,19 @@ module Metanorma
179
195
  end
180
196
 
181
197
  def process_bibliography(liquid_doc, match)
198
+ @seen_glossarist << "x"
182
199
  dataset_name = match[1].strip
183
200
  dataset = @datasets[dataset_name]
184
201
 
185
202
  liquid_doc.add_content(
186
- dataset.concepts.map do |_concept_name, concept|
203
+ dataset.concepts.map do |concept|
187
204
  concept_bibliography(concept)
188
205
  end.compact.sort.join("\n"),
189
206
  )
190
207
  end
191
208
 
192
209
  def process_bibliography_entry(liquid_doc, match)
210
+ @seen_glossarist << "x"
193
211
  dataset_name, concept_name = match[1].split(",").map(&:strip)
194
212
  concept = @datasets[dataset_name][concept_name]
195
213
 
@@ -202,7 +220,7 @@ module Metanorma
202
220
  bibliography = concept["eng"]["sources"].map do |source|
203
221
  ref = source["origin"]["ref"]
204
222
 
205
- next if @rendered_bibliographies[ref]
223
+ next if @rendered_bibliographies[ref] || ref.nil? || ref.empty?
206
224
 
207
225
  @rendered_bibliographies[ref] = ref.gsub(/[ \/:]/, "_")
208
226
  "* [[[#{@rendered_bibliographies[ref]},#{ref}]]]"
@@ -237,7 +255,7 @@ module Metanorma
237
255
 
238
256
  def concept_template(dataset_name, concept_name)
239
257
  <<~CONCEPT_TEMPLATE
240
- ==== {{ #{dataset_name}['#{concept_name}'].term }}
258
+ #{"=" * (@title_depth[:value] + 1)} {{ #{dataset_name}['#{concept_name}'].term }}
241
259
  #{alt_terms(dataset_name, concept_name)}
242
260
 
243
261
  {{ #{dataset_name}['#{concept_name}']['eng'].definition[0].content }}
@@ -289,6 +307,7 @@ module Metanorma
289
307
  def sources(dataset_name, concept_name)
290
308
  <<~SOURCES
291
309
  {% for source in #{dataset_name}['#{concept_name}']['eng'].sources %}
310
+ {%- if source.origin.ref == nil or source.origin.ref == '' %}{% continue %}{% endif %}
292
311
  [.source]
293
312
  <<{{ source.origin.ref | replace: ' ', '_' | replace: '/', '_' | replace: ':', '_' }},{{ source.origin.clause }}>>
294
313
 
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Glossarist
4
- VERSION = "0.2.1".freeze
4
+ VERSION = "0.2.3".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -24,10 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ["lib"]
25
25
 
26
26
  spec.add_dependency "asciidoctor", "~> 2.0.0"
27
- spec.add_dependency "glossarist", "~> 2.0.1"
27
+ spec.add_dependency "glossarist", "~> 2.0"
28
28
  spec.add_dependency "liquid", "~> 5"
29
-
30
- spec.add_development_dependency "pry"
31
- spec.add_development_dependency "rake", "~> 12.0"
32
- spec.add_development_dependency "rspec", "~> 3.0"
33
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-plugin-glossarist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-30 00:00:00.000000000 Z
11
+ date: 2024-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.1
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.1
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: liquid
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,48 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5'
55
- - !ruby/object:Gem::Dependency
56
- name: pry
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '12.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '12.0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '3.0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '3.0'
97
55
  description: Metanorma plugin for glossarist
98
56
  email:
99
57
  - open.source@ribose.com