metanorma-plugin-glossarist 0.3.1 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 035bbab9dbca5a50d31568ac38270873b5d0adba5bc7be42f69f5cfc90930e2b
4
- data.tar.gz: 226a954bac71bd41894a46692f7610b9b7d04f3d44444494acb4d73e6fbfb053
3
+ metadata.gz: 55d315bc6cddf69dfc612fa0f19f6b7fb2161333f765a525befffb6e83000185
4
+ data.tar.gz: db3d207cb5be69640cd4e137c79853ee5d008537743f6d24763ae687f464923c
5
5
  SHA512:
6
- metadata.gz: 0353502cfb820476dca14b27c428475feb7ac33a6badaf0d84517540c7b5466f410eb2b1025f26eca5f9dc0e1cf5d90c170e7222cd90a72fad0db258267c8d95
7
- data.tar.gz: 1fefdf7694567c819f7789f96494e8dd4fbc54ddfeea801686924c524ed064ddf263dadd497b84c60deb763341b347d0c4bc87c64fb845a6cb2ab02eafcc70d2
6
+ metadata.gz: 164ee3cb6feb6b609cc4bb28541f539e9fd2c7354a05dded59863b9d81405ae0f42bc68a618f5b5fecb02b503bf628a6101c9ab0a3ffae0c54c502ecd0db9e63
7
+ data.tar.gz: b014dcaa771d6e67dac030f6ffaf0b662cfc9e5f2471ec8a482c38006ff2dcdd321c568a3c8f3fa3026170dd19c497dcbff0c21c8e25c7f19fd373e5af463792
data/.gitignore CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
- Gemfile.lock
13
12
 
14
13
  .rubocop-https--*
15
14
  *.log.txt
15
+ Gemfile.lock
data/Gemfile CHANGED
@@ -3,7 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
  git_source(:github) { |repo| "https://github.com/#{repo}" }
5
5
 
6
- gem "glossarist"
7
6
  gem "metanorma", github: "metanorma/metanorma", branch: "main"
8
7
  gem "metanorma-plugin-lutaml", github: "metanorma/metanorma-plugin-lutaml",
9
8
  branch: "main"
data/README.adoc CHANGED
@@ -271,7 +271,7 @@ Multiple filters can be applied by separating them with a semicolon `;`.
271
271
  ====
272
272
  [source,adoc]
273
273
  ------
274
- [glossarist,dataset,filter='group=foo;sort_by=term',concepts]
274
+ [glossarist,dataset,filter='domain=foo;sort_by=term',concepts]
275
275
  ----
276
276
  ...
277
277
  ----
@@ -287,7 +287,7 @@ which concepts are loaded into the block.
287
287
  `sort_by=<field name>`::: Sorts the dataset in ascending order of the given
288
288
  field values. The field `term` is a special case, where it sorts according to
289
289
  the `default_designation` of the term. Nested attribute paths are supported
290
- using dot notation (e.g., `data.id`) and bracket notation for hash/array access
290
+ using dot notation (e.g., `data.identifier`) and bracket notation for hash/array access
291
291
  (e.g., `data.localizations['eng'].data.terms[0].designation`).
292
292
  Nested path sorts use natural ordering so that version-like identifiers
293
293
  (e.g., `3.1.1.10`) sort correctly after `3.1.1.2`. Concepts missing the
@@ -299,7 +299,7 @@ specified path are sorted last.
299
299
  default term (which is the first English designation, at `data.localizations['eng'].data.terms[0].designation`).
300
300
 
301
301
  [example]
302
- `sort_by=data.id` will sort concepts by their identifier.
302
+ `sort_by=data.identifier` will sort concepts by their identifier.
303
303
 
304
304
  [example]
305
305
  `sort_by=data.localizations['eng'].data.terms[0].designation` will sort concepts
@@ -311,11 +311,18 @@ alphabetically by the English designation.
311
311
  [example]
312
312
  `lang=ara` loads all localized concepts of Arabic for all concepts.
313
313
 
314
- `group=<group name>`::: Loads concepts that belong to the specified group. Group is a dataset-specific
315
- field that can be used to categorize concepts.
314
+ `domain=<domain name>`::: Loads concepts that belong to the specified domain.
315
+ Domains are `ConceptReference` objects (with `concept_id` and `ref_type: "domain"`)
316
+ that categorize concepts into subject areas.
316
317
  +
317
318
  [example]
318
- `group=foo` will only load concepts that have a group named `foo`.
319
+ `domain=foo` will only load concepts that have a domain with `concept_id` "foo".
320
+
321
+ `group=<group name>`::: Legacy alias for `domain`. Loads concepts that belong to
322
+ the specified domain. Provided for backward compatibility with existing documents.
323
+ +
324
+ [example]
325
+ `group=foo` will only load concepts that have a domain with `concept_id` "foo".
319
326
 
320
327
  Field filters:: These filters are applied to individual fields of the concepts
321
328
  and affect which concepts are included in the block based on the values of those
@@ -724,14 +731,14 @@ System for identifying position in the real world
724
731
  ====
725
732
 
726
733
  [example]
727
- .Applying sorting and filtering by group
734
+ .Applying sorting and filtering by domain
728
735
  ====
729
- Using the same dataset as above, but with sorting and filtering by the "terminology" group:
736
+ Using the same dataset as above, but with sorting and filtering by the "terminology" domain:
730
737
 
731
738
  [source,asciidoc]
732
739
  ------
733
740
  === Terms and definitions
734
- [glossarist, /path/to/glossarist-dataset, filter='group=terminology;sort_by=term', dataset]
741
+ [glossarist, /path/to/glossarist-dataset, filter='domain=terminology;sort_by=term', dataset]
735
742
  ----
736
743
  {%- for concept in dataset -%}
737
744
  ==== {{ concept.data.localizations['eng'].data.terms[0].designation }}
@@ -761,7 +768,7 @@ Using the same dataset, but filtering for terms related to addressing:
761
768
  [source,asciidoc]
762
769
  ------
763
770
  === Terms and definitions
764
- [glossarist, /path/to/glossarist-dataset, filter='group=addressing', dataset]
771
+ [glossarist, /path/to/glossarist-dataset, filter='domain=addressing', dataset]
765
772
  ----
766
773
  {%- for concept in dataset -%}
767
774
  ==== {{ concept.data.localizations['eng'].data.terms[0].designation }}
@@ -4,7 +4,8 @@ module Metanorma
4
4
  module Plugin
5
5
  module Glossarist
6
6
  class ConceptFilter
7
- COLLECTION_FILTERS = %w[lang group sort_by].freeze
7
+ COLLECTION_FILTERS = %w[lang domain group sort_by].freeze
8
+ SORT_LAST = ["￿"].freeze
8
9
 
9
10
  def initialize(filters)
10
11
  @filters = filters || {}
@@ -13,7 +14,9 @@ module Metanorma
13
14
  def apply(collection)
14
15
  result = collection
15
16
  result = filter_by_lang(result) if @filters.key?("lang")
16
- result = filter_by_group(result) if @filters.key?("group")
17
+ if @filters.key?("domain") || @filters.key?("group")
18
+ result = filter_by_domain(result)
19
+ end
17
20
  result = filter_by_field(result) if field_filter?
18
21
  result = sort(result) if @filters.key?("sort_by")
19
22
  result
@@ -34,9 +37,11 @@ module Metanorma
34
37
  collection.reject { |c| c.localization(lang).nil? }
35
38
  end
36
39
 
37
- def filter_by_group(collection)
38
- group = @filters["group"]
39
- collection.select { |c| c.data.groups&.include?(group) }
40
+ def filter_by_domain(collection)
41
+ domain = @filters["domain"] || @filters["group"]
42
+ collection.select do |c|
43
+ c.data.domains&.any? { |d| d.concept_id == domain }
44
+ end
40
45
  end
41
46
 
42
47
  def sort(collection)
@@ -58,10 +63,9 @@ module Metanorma
58
63
  value.nil? ? SORT_LAST : natural_sort_key(value.to_s)
59
64
  end
60
65
 
61
- SORT_LAST = ["￿"].freeze
62
-
63
66
  def natural_sort_key(str)
64
- str.scan(/(\d+)|(\D+)/).map { |num, txt| num ? num.to_i : txt.downcase }
67
+ str.scan(/(\d+)|(\D+)/)
68
+ .map { |num, txt| num ? num.to_i : txt.downcase }
65
69
  end
66
70
 
67
71
  def filter_by_field(collection)
@@ -9,94 +9,18 @@ module Metanorma
9
9
  end
10
10
 
11
11
  def to_h
12
- { "data" => concept_data_hash }
12
+ data = @concept.data.to_hash
13
+ data["localizations"] = localizations_hash unless @concept.localizations.empty?
14
+ { "data" => data.compact }
13
15
  end
14
16
 
15
17
  private
16
18
 
17
- def concept_data_hash
18
- {
19
- "id" => @concept.data.id,
20
- "identifier" => @concept.data.id,
21
- "localized_concepts" => @concept.data.localized_concepts,
22
- "groups" => @concept.data.groups.to_a,
23
- "localizations" => localizations_hash,
24
- "sources" => sources_to_h(@concept.data.sources),
25
- }.compact
26
- end
27
-
28
19
  def localizations_hash
29
20
  @concept.localizations.to_h do |l10n|
30
- [l10n.language_code, localized_concept_hash(l10n)]
31
- end
32
- end
33
-
34
- def localized_concept_hash(l10n)
35
- {
36
- "data" => localized_concept_data_hash(l10n),
37
- "classification" => l10n.classification,
38
- "review_type" => l10n.review_type,
39
- }.compact
40
- end
41
-
42
- def localized_concept_data_hash(l10n)
43
- {
44
- "terms" => l10n.terms.map { |t| designation_to_h(t) },
45
- "definition" => definitions_to_h(l10n.definition),
46
- "examples" => definitions_to_h(l10n.examples),
47
- "notes" => definitions_to_h(l10n.notes),
48
- "sources" => sources_to_h(l10n.sources),
49
- "language_code" => l10n.language_code,
50
- "entry_status" => l10n.entry_status,
51
- }.compact
52
- end
53
-
54
- def designation_to_h(designation)
55
- {
56
- "type" => designation.type,
57
- "designation" => designation.designation,
58
- "normative_status" => designation.normative_status,
59
- "geographical_area" => designation.geographical_area,
60
- }.compact
61
- end
62
-
63
- def definitions_to_h(definitions)
64
- definitions.map do |d|
65
- { "content" => d.content,
66
- "sources" => sources_to_h(d.sources) }.compact
21
+ [l10n.language_code, l10n.to_hash]
67
22
  end
68
23
  end
69
-
70
- def sources_to_h(sources)
71
- return [] unless sources
72
-
73
- sources.map do |source|
74
- {
75
- "type" => source.type,
76
- "origin" => citation_to_h(source.origin),
77
- "modification" => source.modification,
78
- }.compact
79
- end
80
- end
81
-
82
- def citation_to_h(citation)
83
- return nil unless citation
84
-
85
- hash = {}
86
- hash["text"] = citation.text if citation.text && !citation.text.empty?
87
- hash["ref"] = citation.text if citation.text && !citation.text.empty?
88
-
89
- if citation.locality
90
- hash["locality"] = {
91
- "type" => citation.locality.type,
92
- "reference_from" => citation.locality.reference_from,
93
- }
94
- hash["clause"] = citation.locality.reference_from
95
- end
96
-
97
- hash["link"] = citation.link if citation.link
98
- hash
99
- end
100
24
  end
101
25
  end
102
26
  end
@@ -3,7 +3,7 @@
3
3
  module Metanorma
4
4
  module Plugin
5
5
  module Glossarist
6
- VERSION = "0.3.1"
6
+ VERSION = "0.3.2"
7
7
  end
8
8
  end
9
9
  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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-05-12 00:00:00.000000000 Z
11
+ date: 2026-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor