glossarist 2.6.0 → 2.6.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_todo.yml +33 -52
- data/Gemfile +1 -1
- data/lib/glossarist/cli/export_command.rb +16 -16
- data/lib/glossarist/concept_collector.rb +40 -10
- data/lib/glossarist/concept_set.rb +0 -2
- data/lib/glossarist/gcr_package.rb +93 -21
- data/lib/glossarist/gcr_validator.rb +58 -21
- data/lib/glossarist/managed_concept.rb +0 -13
- data/lib/glossarist/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4a05468d25c9ac0d13c748454dc98d7dc031718fe98d298c3db89d6874963a7
|
|
4
|
+
data.tar.gz: 203b26205a85b9593942d7d6095dab85faa93ed1e99b9f474f20c67a77e61c5d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc177b1d927f7b309cb47fac5158c151001202ba0332b35f0eaf87a8e1e2d9eda400dd077145b10d4acc5ee968676f39dd95172a32ad16e6078ff3357c299317
|
|
7
|
+
data.tar.gz: eb60cfa90dd26008e2287cbafb35aaeb4e48bb60c120cc254fba024d945f4a6cdb41e9b51a2b8c68a30ac6e31e7e40f38243ec44437a5995126eba47f47110dd
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,48 +1,45 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on 2026-05-
|
|
3
|
+
# on 2026-05-07 13:57:54 UTC using RuboCop version 1.86.1.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
|
8
8
|
|
|
9
|
-
# Offense count: 6
|
|
10
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
11
|
-
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation.
|
|
12
|
-
Bundler/OrderedGems:
|
|
13
|
-
Exclude:
|
|
14
|
-
- 'Gemfile'
|
|
15
|
-
|
|
16
9
|
# Offense count: 1
|
|
17
10
|
Gemspec/RequiredRubyVersion:
|
|
18
11
|
Exclude:
|
|
19
12
|
- 'glossarist.gemspec'
|
|
20
13
|
|
|
21
|
-
# Offense count:
|
|
14
|
+
# Offense count: 1
|
|
22
15
|
# This cop supports safe autocorrection (--autocorrect).
|
|
23
16
|
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
|
24
17
|
# SupportedStyles: with_first_argument, with_fixed_indentation
|
|
25
18
|
Layout/ArgumentAlignment:
|
|
26
19
|
Exclude:
|
|
27
|
-
- 'lib/glossarist/cli/export_command.rb'
|
|
28
|
-
- 'lib/glossarist/gcr_package.rb'
|
|
29
20
|
- 'spec/unit/gcr_package_spec.rb'
|
|
30
21
|
|
|
31
|
-
# Offense count:
|
|
22
|
+
# Offense count: 2
|
|
32
23
|
# This cop supports safe autocorrection (--autocorrect).
|
|
33
|
-
|
|
24
|
+
# Configuration parameters: EnforcedStyleAlignWith.
|
|
25
|
+
# SupportedStylesAlignWith: either, start_of_block, start_of_line
|
|
26
|
+
Layout/BlockAlignment:
|
|
34
27
|
Exclude:
|
|
35
|
-
- 'lib/glossarist/
|
|
28
|
+
- 'lib/glossarist/gcr_validator.rb'
|
|
36
29
|
|
|
37
|
-
# Offense count:
|
|
30
|
+
# Offense count: 2
|
|
38
31
|
# This cop supports safe autocorrection (--autocorrect).
|
|
39
|
-
|
|
40
|
-
# SupportedHashRocketStyles: key, separator, table
|
|
41
|
-
# SupportedColonStyles: key, separator, table
|
|
42
|
-
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
|
43
|
-
Layout/HashAlignment:
|
|
32
|
+
Layout/BlockEndNewline:
|
|
44
33
|
Exclude:
|
|
45
|
-
- 'lib/glossarist/
|
|
34
|
+
- 'lib/glossarist/gcr_validator.rb'
|
|
35
|
+
|
|
36
|
+
# Offense count: 4
|
|
37
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
38
|
+
# Configuration parameters: Width, EnforcedStyleAlignWith, AllowedPatterns.
|
|
39
|
+
# SupportedStylesAlignWith: start_of_line, relative_to_receiver
|
|
40
|
+
Layout/IndentationWidth:
|
|
41
|
+
Exclude:
|
|
42
|
+
- 'lib/glossarist/gcr_validator.rb'
|
|
46
43
|
|
|
47
44
|
# Offense count: 214
|
|
48
45
|
# This cop supports safe autocorrection (--autocorrect).
|
|
@@ -51,14 +48,11 @@ Layout/HashAlignment:
|
|
|
51
48
|
Layout/LineLength:
|
|
52
49
|
Enabled: false
|
|
53
50
|
|
|
54
|
-
# Offense count:
|
|
51
|
+
# Offense count: 1
|
|
55
52
|
# This cop supports safe autocorrection (--autocorrect).
|
|
56
53
|
# Configuration parameters: AllowInHeredoc.
|
|
57
54
|
Layout/TrailingWhitespace:
|
|
58
55
|
Exclude:
|
|
59
|
-
- 'lib/glossarist/cli/export_command.rb'
|
|
60
|
-
- 'lib/glossarist/gcr_package.rb'
|
|
61
|
-
- 'lib/glossarist/transforms/concept_to_tbx_transform.rb'
|
|
62
56
|
- 'spec/unit/gcr_package_spec.rb'
|
|
63
57
|
|
|
64
58
|
# Offense count: 1
|
|
@@ -68,21 +62,15 @@ Lint/ConstantDefinitionInBlock:
|
|
|
68
62
|
Exclude:
|
|
69
63
|
- 'spec/unit/utilities/common_functions_spec.rb'
|
|
70
64
|
|
|
71
|
-
# Offense count:
|
|
72
|
-
Lint/DuplicateMethods:
|
|
73
|
-
Exclude:
|
|
74
|
-
- 'lib/glossarist/managed_concept.rb'
|
|
75
|
-
|
|
76
|
-
# Offense count: 2
|
|
65
|
+
# Offense count: 1
|
|
77
66
|
# This cop supports safe autocorrection (--autocorrect).
|
|
78
67
|
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
|
|
79
68
|
# NotImplementedExceptions: NotImplementedError
|
|
80
69
|
Lint/UnusedMethodArgument:
|
|
81
70
|
Exclude:
|
|
82
|
-
- 'lib/glossarist/cli/export_command.rb'
|
|
83
71
|
- 'lib/glossarist/dataset_validator.rb'
|
|
84
72
|
|
|
85
|
-
# Offense count:
|
|
73
|
+
# Offense count: 24
|
|
86
74
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
|
87
75
|
Metrics/AbcSize:
|
|
88
76
|
Exclude:
|
|
@@ -101,12 +89,6 @@ Metrics/AbcSize:
|
|
|
101
89
|
- 'lib/glossarist/utilities/uuid.rb'
|
|
102
90
|
- 'spec/unit/concept_collector_spec.rb'
|
|
103
91
|
|
|
104
|
-
# Offense count: 1
|
|
105
|
-
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
106
|
-
# AllowedMethods: refine
|
|
107
|
-
Metrics/BlockLength:
|
|
108
|
-
Max: 28
|
|
109
|
-
|
|
110
92
|
# Offense count: 19
|
|
111
93
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
112
94
|
Metrics/CyclomaticComplexity:
|
|
@@ -129,7 +111,7 @@ Metrics/CyclomaticComplexity:
|
|
|
129
111
|
Metrics/MethodLength:
|
|
130
112
|
Max: 42
|
|
131
113
|
|
|
132
|
-
# Offense count:
|
|
114
|
+
# Offense count: 3
|
|
133
115
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
|
134
116
|
Metrics/ParameterLists:
|
|
135
117
|
Max: 6
|
|
@@ -163,6 +145,17 @@ Naming/VariableNumber:
|
|
|
163
145
|
Exclude:
|
|
164
146
|
- 'spec/unit/rdf/skos_vocabulary_spec.rb'
|
|
165
147
|
|
|
148
|
+
# Offense count: 3
|
|
149
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
150
|
+
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
|
|
151
|
+
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
|
|
152
|
+
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
|
153
|
+
# FunctionalMethods: let, let!, subject, watch
|
|
154
|
+
# AllowedMethods: lambda, proc, it
|
|
155
|
+
Style/BlockDelimiters:
|
|
156
|
+
Exclude:
|
|
157
|
+
- 'lib/glossarist/gcr_validator.rb'
|
|
158
|
+
|
|
166
159
|
# Offense count: 6
|
|
167
160
|
# This cop supports safe autocorrection (--autocorrect).
|
|
168
161
|
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, Mode, AllowedMethods, AllowedPatterns.
|
|
@@ -170,12 +163,6 @@ Naming/VariableNumber:
|
|
|
170
163
|
Style/FormatStringToken:
|
|
171
164
|
EnforcedStyle: unannotated
|
|
172
165
|
|
|
173
|
-
# Offense count: 2
|
|
174
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
175
|
-
Style/MultilineIfModifier:
|
|
176
|
-
Exclude:
|
|
177
|
-
- 'lib/glossarist/gcr_package.rb'
|
|
178
|
-
|
|
179
166
|
# Offense count: 1
|
|
180
167
|
# Configuration parameters: AllowedClasses.
|
|
181
168
|
Style/OneClassPerFile:
|
|
@@ -184,12 +171,6 @@ Style/OneClassPerFile:
|
|
|
184
171
|
- 'test/**/*'
|
|
185
172
|
- 'lib/glossarist.rb'
|
|
186
173
|
|
|
187
|
-
# Offense count: 1
|
|
188
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
189
|
-
Style/RedundantAssignment:
|
|
190
|
-
Exclude:
|
|
191
|
-
- 'lib/glossarist/transforms/concept_to_tbx_transform.rb'
|
|
192
|
-
|
|
193
174
|
# Offense count: 4
|
|
194
175
|
# Configuration parameters: Max.
|
|
195
176
|
Style/SafeNavigationChainLength:
|
data/Gemfile
CHANGED
|
@@ -7,12 +7,12 @@ gemspec
|
|
|
7
7
|
gem "canon"
|
|
8
8
|
gem "lutaml-model", "~> 0.8.0"
|
|
9
9
|
gem "rake", "~> 13.0"
|
|
10
|
-
gem "tbx", "~> 0.1"
|
|
11
10
|
gem "rspec", "~> 3.0"
|
|
12
11
|
gem "rubocop"
|
|
13
12
|
gem "rubocop-performance"
|
|
14
13
|
gem "rubocop-rake"
|
|
15
14
|
gem "rubocop-rspec"
|
|
15
|
+
gem "tbx", "~> 0.1"
|
|
16
16
|
|
|
17
17
|
# Override relaton gems with lutaml-model 0.8 compatible versions.
|
|
18
18
|
# Released 2.0.0 gems have untyped lutaml-model attributes that fail with 0.8+.
|
|
@@ -5,10 +5,7 @@ module Glossarist
|
|
|
5
5
|
class ExportCommand
|
|
6
6
|
EXTENSIONS = {
|
|
7
7
|
"json" => "json",
|
|
8
|
-
|
|
9
|
-
"turtle" => "ttl",
|
|
10
|
-
"tbx" => "tbx.xml",
|
|
11
|
-
"jsonl" => "jsonl",
|
|
8
|
+
**GcrPackage::COMPILED_EXTENSIONS,
|
|
12
9
|
}.freeze
|
|
13
10
|
|
|
14
11
|
def initialize(path, options)
|
|
@@ -22,12 +19,12 @@ module Glossarist
|
|
|
22
19
|
FileUtils.mkdir_p(output_dir)
|
|
23
20
|
|
|
24
21
|
concepts = load_concepts
|
|
25
|
-
name = resolve_shortname
|
|
22
|
+
name = resolve_shortname
|
|
26
23
|
|
|
27
24
|
case format
|
|
28
25
|
when "json" then export_json(concepts, output_dir)
|
|
29
|
-
when "jsonld" then
|
|
30
|
-
when "turtle" then
|
|
26
|
+
when "jsonld" then export_jsonld(concepts, name, output_dir)
|
|
27
|
+
when "turtle" then export_turtle(concepts, name, output_dir)
|
|
31
28
|
when "tbx" then export_tbx(concepts, name, output_dir)
|
|
32
29
|
when "jsonl" then export_jsonl(concepts, name, output_dir)
|
|
33
30
|
end
|
|
@@ -55,7 +52,7 @@ module Glossarist
|
|
|
55
52
|
@options[:uri_prefix] ||= package.metadata["uri_prefix"]
|
|
56
53
|
end
|
|
57
54
|
|
|
58
|
-
def resolve_shortname
|
|
55
|
+
def resolve_shortname
|
|
59
56
|
@options[:shortname] || "glossary"
|
|
60
57
|
end
|
|
61
58
|
|
|
@@ -75,27 +72,30 @@ module Glossarist
|
|
|
75
72
|
end
|
|
76
73
|
end
|
|
77
74
|
|
|
78
|
-
def
|
|
75
|
+
def export_jsonld(concepts, name, output_dir)
|
|
79
76
|
require "glossarist/transforms/concept_to_skos_transform"
|
|
80
77
|
vocab = Transforms::ConceptToSkosTransform.transform_document(concepts,
|
|
81
78
|
transform_options)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
File.write(File.join(output_dir, "#{name}.jsonld"), vocab.to_jsonld)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def export_turtle(concepts, name, output_dir)
|
|
83
|
+
require "glossarist/transforms/concept_to_skos_transform"
|
|
84
|
+
vocab = Transforms::ConceptToSkosTransform.transform_document(concepts,
|
|
85
|
+
transform_options)
|
|
86
|
+
File.write(File.join(output_dir, "#{name}.ttl"), vocab.to_turtle)
|
|
85
87
|
end
|
|
86
88
|
|
|
87
89
|
def export_tbx(concepts, name, output_dir)
|
|
88
90
|
require "glossarist/transforms/concept_to_tbx_transform"
|
|
89
91
|
doc = Transforms::ConceptToTbxTransform.transform_document(concepts,
|
|
90
92
|
transform_options)
|
|
91
|
-
File.write(File.join(output_dir, "#{name}
|
|
92
|
-
doc.to_xml)
|
|
93
|
+
File.write(File.join(output_dir, "#{name}.tbx.xml"), doc.to_xml)
|
|
93
94
|
end
|
|
94
95
|
|
|
95
96
|
def export_jsonl(concepts, name, output_dir)
|
|
96
97
|
require "glossarist/transforms/concept_to_skos_transform"
|
|
97
|
-
File.open(File.join(output_dir, "#{name}
|
|
98
|
-
"w") do |f|
|
|
98
|
+
File.open(File.join(output_dir, "#{name}.jsonl"), "w") do |f|
|
|
99
99
|
concepts.each do |concept|
|
|
100
100
|
skos = Transforms::ConceptToSkosTransform.transform(concept,
|
|
101
101
|
transform_options)
|
|
@@ -41,13 +41,35 @@ module Glossarist
|
|
|
41
41
|
def v1_concepts?(dir)
|
|
42
42
|
concepts_dir = File.join(dir, "concepts")
|
|
43
43
|
File.directory?(concepts_dir) &&
|
|
44
|
+
!v2_flat_concepts?(dir) &&
|
|
45
|
+
!managed_concepts?(dir) &&
|
|
44
46
|
Dir.glob(File.join(concepts_dir, "*.yaml")).any? do |f|
|
|
45
47
|
V1::Concept.from_file(f)&.termid?
|
|
46
48
|
end
|
|
47
49
|
end
|
|
48
50
|
|
|
49
51
|
def v2_concepts?(dir)
|
|
50
|
-
File.directory?(File.join(dir, "geolexica-v2"))
|
|
52
|
+
File.directory?(File.join(dir, "geolexica-v2")) ||
|
|
53
|
+
v2_flat_concepts?(dir)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def v2_flat_concepts?(dir)
|
|
57
|
+
return false if managed_concepts?(dir)
|
|
58
|
+
|
|
59
|
+
concepts_dir = File.join(dir, "concepts")
|
|
60
|
+
return false unless File.directory?(concepts_dir)
|
|
61
|
+
|
|
62
|
+
Dir.glob(File.join(concepts_dir, "*.yaml")).first(5).any? do |f|
|
|
63
|
+
v2_flat_concept_file?(f)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def v2_flat_concept_file?(path)
|
|
68
|
+
raw = File.read(path, encoding: "utf-8")
|
|
69
|
+
doc = ConceptDocument.from_yamls(raw)
|
|
70
|
+
!!doc.concept&.data&.id
|
|
71
|
+
rescue StandardError
|
|
72
|
+
false
|
|
51
73
|
end
|
|
52
74
|
|
|
53
75
|
def managed_concepts?(dir)
|
|
@@ -74,24 +96,32 @@ module Glossarist
|
|
|
74
96
|
end
|
|
75
97
|
|
|
76
98
|
def collect_v2_concepts(dir)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
collect_managed_concepts(v2_dir)
|
|
99
|
+
if v2_flat_concepts?(dir)
|
|
100
|
+
collect_grouped_v2_concepts(File.join(dir, "concepts"))
|
|
80
101
|
else
|
|
81
|
-
|
|
102
|
+
v2_dir = File.join(dir, "geolexica-v2")
|
|
103
|
+
if File.directory?(File.join(v2_dir, "concepts"))
|
|
104
|
+
collect_managed_concepts(v2_dir)
|
|
105
|
+
else
|
|
106
|
+
collect_grouped_v2_concepts(v2_dir)
|
|
107
|
+
end
|
|
82
108
|
end
|
|
83
109
|
end
|
|
84
110
|
|
|
85
111
|
def each_v2_concept(dir, &block)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
each_managed_concept(v2_dir, &block)
|
|
112
|
+
if v2_flat_concepts?(dir)
|
|
113
|
+
each_grouped_v2_concepts(File.join(dir, "concepts"), &block)
|
|
89
114
|
else
|
|
90
|
-
|
|
115
|
+
v2_dir = File.join(dir, "geolexica-v2")
|
|
116
|
+
if File.directory?(File.join(v2_dir, "concepts"))
|
|
117
|
+
each_managed_concept(v2_dir, &block)
|
|
118
|
+
else
|
|
119
|
+
each_grouped_v2_concepts(v2_dir, &block)
|
|
120
|
+
end
|
|
91
121
|
end
|
|
92
122
|
end
|
|
93
123
|
|
|
94
|
-
def
|
|
124
|
+
def each_grouped_v2_concepts(v2_dir, &block)
|
|
95
125
|
collection = ManagedConceptCollection.new
|
|
96
126
|
manager = ConceptManager.new(path: v2_dir)
|
|
97
127
|
manager.load_from_files(collection: collection)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "zip"
|
|
4
4
|
require "fileutils"
|
|
5
|
+
require "pathname"
|
|
5
6
|
|
|
6
7
|
module Glossarist
|
|
7
8
|
class GcrPackage
|
|
@@ -14,12 +15,18 @@ module Glossarist
|
|
|
14
15
|
|
|
15
16
|
KNOWN_COMPILED_FORMATS = COMPILED_EXTENSIONS.keys.freeze
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
DATASET_ASSETS = [
|
|
19
|
+
{ path: "bibliography.yaml", type: :file, attr: :bibliography },
|
|
20
|
+
{ path: "images", type: :directory },
|
|
21
|
+
].freeze
|
|
22
|
+
|
|
23
|
+
attr_reader :zip_path, :metadata, :concepts, :bibliography
|
|
18
24
|
|
|
19
25
|
def initialize(zip_path)
|
|
20
26
|
@zip_path = zip_path
|
|
21
27
|
@metadata = nil
|
|
22
28
|
@concepts = []
|
|
29
|
+
@bibliography = nil
|
|
23
30
|
end
|
|
24
31
|
|
|
25
32
|
def self.create(concepts:, metadata:, output_path:, register_data: nil,
|
|
@@ -66,12 +73,43 @@ module Glossarist
|
|
|
66
73
|
end
|
|
67
74
|
end
|
|
68
75
|
|
|
76
|
+
def self.each_dataset_asset(source_dir)
|
|
77
|
+
base = Pathname.new(source_dir)
|
|
78
|
+
DATASET_ASSETS.each do |asset|
|
|
79
|
+
path = File.join(source_dir, asset[:path])
|
|
80
|
+
case asset[:type]
|
|
81
|
+
when :file
|
|
82
|
+
yield_file_asset(path, asset[:path]) { |*a| yield(*a) }
|
|
83
|
+
when :directory
|
|
84
|
+
yield_directory_assets(path, base) { |*a| yield(*a) }
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def self.yield_file_asset(path, entry_name)
|
|
90
|
+
return unless File.exist?(path)
|
|
91
|
+
|
|
92
|
+
yield entry_name, File.binread(path)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.yield_directory_assets(dir_path, base_path)
|
|
96
|
+
return unless File.directory?(dir_path)
|
|
97
|
+
|
|
98
|
+
Dir.glob(File.join(dir_path, "**", "*")).each do |file|
|
|
99
|
+
next unless File.file?(file)
|
|
100
|
+
|
|
101
|
+
relative = Pathname.new(file).relative_path_from(base_path).to_s
|
|
102
|
+
yield relative, File.binread(file)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
69
106
|
def validate
|
|
70
107
|
GcrValidator.new.validate(@zip_path)
|
|
71
108
|
end
|
|
72
109
|
|
|
73
|
-
def write(concepts, metadata, register_data,
|
|
74
|
-
|
|
110
|
+
def write(concepts, metadata, register_data, # rubocop:disable Metrics/ParameterLists
|
|
111
|
+
compiled_formats: [],
|
|
112
|
+
shortname: nil, source_dir: nil, **opts)
|
|
75
113
|
Zip::File.open(@zip_path, create: true) do |zf|
|
|
76
114
|
zf.get_output_stream("metadata.yaml") do |f|
|
|
77
115
|
f.write(metadata.to_yaml)
|
|
@@ -87,6 +125,12 @@ module Glossarist
|
|
|
87
125
|
write_concept(zf, mc)
|
|
88
126
|
end
|
|
89
127
|
|
|
128
|
+
if source_dir
|
|
129
|
+
self.class.each_dataset_asset(source_dir) do |name, content|
|
|
130
|
+
zf.get_output_stream(name) { |f| f.write(content) }
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
90
134
|
if compiled_formats.any?
|
|
91
135
|
write_compiled(zf, concepts, compiled_formats, shortname: shortname,
|
|
92
136
|
**opts)
|
|
@@ -94,29 +138,51 @@ module Glossarist
|
|
|
94
138
|
end
|
|
95
139
|
end
|
|
96
140
|
|
|
97
|
-
def write_concept(zip_file, concept)
|
|
98
|
-
termid = concept.data.id.to_s
|
|
99
|
-
doc = ConceptDocument.from_managed_concept(concept)
|
|
100
|
-
zip_file.get_output_stream("concepts/#{termid}.yaml") do |f|
|
|
101
|
-
f.write(doc.to_yamls)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
141
|
def read
|
|
106
142
|
@concepts = []
|
|
107
143
|
|
|
108
144
|
Zip::File.open(@zip_path) do |zf|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
145
|
+
read_metadata(zf)
|
|
146
|
+
read_file_assets(zf)
|
|
147
|
+
read_concepts(zf)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
112
150
|
|
|
113
|
-
|
|
114
|
-
|
|
151
|
+
def read_metadata(zip_file)
|
|
152
|
+
entry = zip_file.find_entry("metadata.yaml")
|
|
153
|
+
return unless entry
|
|
115
154
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
155
|
+
@metadata = GcrMetadata.from_yaml(entry.get_input_stream.read)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def read_file_assets(zip_file)
|
|
159
|
+
DATASET_ASSETS.each do |asset|
|
|
160
|
+
next unless asset[:type] == :file && asset[:attr]
|
|
161
|
+
|
|
162
|
+
entry = zip_file.find_entry(asset[:path])
|
|
163
|
+
next unless entry
|
|
164
|
+
|
|
165
|
+
instance_variable_set("@#{asset[:attr]}", entry.get_input_stream.read)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def read_concepts(zip_file)
|
|
170
|
+
zip_file.entries.each do |entry|
|
|
171
|
+
next unless entry.name.start_with?("concepts/") && entry.name.end_with?(".yaml")
|
|
172
|
+
|
|
173
|
+
raw = entry.get_input_stream.read
|
|
174
|
+
doc = ConceptDocument.from_yamls(raw)
|
|
175
|
+
@concepts << doc.to_managed_concept
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
private
|
|
180
|
+
|
|
181
|
+
def write_concept(zip_file, concept)
|
|
182
|
+
termid = concept.data.id.to_s
|
|
183
|
+
doc = ConceptDocument.from_managed_concept(concept)
|
|
184
|
+
zip_file.get_output_stream("concepts/#{termid}.yaml") do |f|
|
|
185
|
+
f.write(doc.to_yamls)
|
|
120
186
|
end
|
|
121
187
|
end
|
|
122
188
|
|
|
@@ -206,6 +272,7 @@ compiled_formats: [], **opts)
|
|
|
206
272
|
output_path: File.expand_path(output),
|
|
207
273
|
compiled_formats: compiled_formats,
|
|
208
274
|
shortname: shortname,
|
|
275
|
+
source_dir: dir,
|
|
209
276
|
**opts,
|
|
210
277
|
)
|
|
211
278
|
end
|
|
@@ -219,7 +286,7 @@ compiled_formats: [], **opts)
|
|
|
219
286
|
concept_count = 0
|
|
220
287
|
languages = Set.new
|
|
221
288
|
|
|
222
|
-
Zip::OutputStream.open(output_path) do |zos|
|
|
289
|
+
Zip::OutputStream.open(output_path) do |zos| # rubocop:disable Metrics/BlockLength
|
|
223
290
|
if register_data
|
|
224
291
|
zos.put_next_entry("register.yaml")
|
|
225
292
|
zos.write(register_data.to_yaml)
|
|
@@ -253,6 +320,11 @@ compiled_formats: [], **opts)
|
|
|
253
320
|
register_data: register_data, **opts)
|
|
254
321
|
zos.put_next_entry("metadata.yaml")
|
|
255
322
|
zos.write(metadata.to_yaml)
|
|
323
|
+
|
|
324
|
+
each_dataset_asset(dir) do |name, content|
|
|
325
|
+
zos.put_next_entry(name)
|
|
326
|
+
zos.write(content)
|
|
327
|
+
end
|
|
256
328
|
end
|
|
257
329
|
|
|
258
330
|
new(output_path)
|
|
@@ -13,27 +13,8 @@ module Glossarist
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
begin
|
|
16
|
-
Zip::File.open(zip_path) do |
|
|
17
|
-
|
|
18
|
-
result.add_error("Missing metadata.yaml")
|
|
19
|
-
return result
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
metadata = GcrMetadata.from_yaml(
|
|
23
|
-
zf.find_entry("metadata.yaml").get_input_stream.read,
|
|
24
|
-
)
|
|
25
|
-
validate_metadata(metadata, result)
|
|
26
|
-
|
|
27
|
-
concept_entries = zf.entries.select do |e|
|
|
28
|
-
e.name.start_with?("concepts/") && e.name.end_with?(".yaml")
|
|
29
|
-
end
|
|
30
|
-
if concept_entries.empty?
|
|
31
|
-
result.add_error("No concept files found in concepts/")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
concept_entries.each do |entry|
|
|
35
|
-
validate_concept_entry(entry, metadata, result)
|
|
36
|
-
end
|
|
16
|
+
Zip::File.open(zip_path) do |zip_file|
|
|
17
|
+
validate_zip_contents(zip_file, result)
|
|
37
18
|
end
|
|
38
19
|
rescue StandardError => e
|
|
39
20
|
result.add_error("Failed to read ZIP: #{e.message}")
|
|
@@ -44,6 +25,31 @@ module Glossarist
|
|
|
44
25
|
|
|
45
26
|
private
|
|
46
27
|
|
|
28
|
+
def validate_zip_contents(zip_file, result) # rubocop:disable Metrics/AbcSize
|
|
29
|
+
unless zip_file.find_entry("metadata.yaml")
|
|
30
|
+
result.add_error("Missing metadata.yaml")
|
|
31
|
+
return
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
metadata = GcrMetadata.from_yaml(
|
|
35
|
+
zip_file.find_entry("metadata.yaml").get_input_stream.read,
|
|
36
|
+
)
|
|
37
|
+
validate_metadata(metadata, result)
|
|
38
|
+
|
|
39
|
+
concept_entries = zip_file.entries.select do |e|
|
|
40
|
+
e.name.start_with?("concepts/") && e.name.end_with?(".yaml")
|
|
41
|
+
end
|
|
42
|
+
if concept_entries.empty?
|
|
43
|
+
result.add_error("No concept files found in concepts/")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
concept_entries.each do |entry|
|
|
47
|
+
validate_concept_entry(entry, metadata, result)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
validate_assets(zip_file, result)
|
|
51
|
+
end
|
|
52
|
+
|
|
47
53
|
def validate_metadata(metadata, result)
|
|
48
54
|
unless metadata&.concept_count
|
|
49
55
|
result.add_error("metadata.yaml missing required fields (concept_count)")
|
|
@@ -94,5 +100,36 @@ module Glossarist
|
|
|
94
100
|
result.add_warning("#{entry.name}: no concept URI (data.uri) and no concept_uri_template or uri_prefix in metadata")
|
|
95
101
|
end
|
|
96
102
|
end
|
|
103
|
+
|
|
104
|
+
def validate_assets(zip_file, result)
|
|
105
|
+
GcrPackage::DATASET_ASSETS.each do |asset|
|
|
106
|
+
case asset[:type]
|
|
107
|
+
when :file
|
|
108
|
+
validate_file_asset_entry(zip_file, asset[:path], result)
|
|
109
|
+
when :directory
|
|
110
|
+
validate_directory_asset(zip_file, asset[:path], result)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def validate_file_asset_entry(zip_file, path, result)
|
|
116
|
+
entry = zip_file.find_entry(path)
|
|
117
|
+
return unless entry
|
|
118
|
+
|
|
119
|
+
YAML.safe_load(entry.get_input_stream.read)
|
|
120
|
+
rescue Psych::SyntaxError => e
|
|
121
|
+
result.add_error("#{path}: invalid YAML at line #{e.line}: #{e.message}")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def validate_directory_asset(zip_file, dir_path, result)
|
|
125
|
+
dir_entries = zip_file.entries.select do |e|
|
|
126
|
+
e.name.start_with?("#{dir_path}/")
|
|
127
|
+
end
|
|
128
|
+
return unless dir_entries.any? && dir_entries.all? do |e|
|
|
129
|
+
e.name.end_with?("/")
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
result.add_warning("#{dir_path}/ directory is empty")
|
|
133
|
+
end
|
|
97
134
|
end
|
|
98
135
|
end
|
|
@@ -10,8 +10,6 @@ module Glossarist
|
|
|
10
10
|
attribute :dates, ConceptDate, collection: true
|
|
11
11
|
attribute :sources, ConceptSource
|
|
12
12
|
attribute :date_accepted, ConceptDate
|
|
13
|
-
# TODO: convert to LocalizedConceptCollection when custom
|
|
14
|
-
# collections are implemented in lutaml-model
|
|
15
13
|
attribute :status, :string,
|
|
16
14
|
values: Glossarist::GlossaryDefinition::CONCEPT_STATUSES
|
|
17
15
|
|
|
@@ -35,14 +33,6 @@ module Glossarist
|
|
|
35
33
|
map :uuid, to: :uuid, with: { from: :uuid_from_yaml, to: :uuid_to_yaml }
|
|
36
34
|
end
|
|
37
35
|
|
|
38
|
-
def localized_concepts
|
|
39
|
-
data.localized_concepts
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def localized_concepts=(val)
|
|
43
|
-
data.localized_concepts = val
|
|
44
|
-
end
|
|
45
|
-
|
|
46
36
|
def localizations
|
|
47
37
|
data.localizations
|
|
48
38
|
end
|
|
@@ -123,9 +113,6 @@ module Glossarist
|
|
|
123
113
|
end
|
|
124
114
|
alias :add_l10n :add_localization
|
|
125
115
|
|
|
126
|
-
# Returns concept localization.
|
|
127
|
-
# @param lang [String] language code
|
|
128
|
-
# @return [LocalizedConcept]
|
|
129
116
|
def to_jsonld
|
|
130
117
|
require "glossarist/transforms/concept_to_skos_transform"
|
|
131
118
|
Transforms::ConceptToSkosTransform.transform(self).to_jsonld
|
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.6.
|
|
4
|
+
version: 2.6.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lutaml-model
|