stepmod-utils 0.4.14 → 0.5.0
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/.github/workflows/release.yml +4 -3
- data/exe/stepmod-annotate-all +5 -4
- data/exe/stepmod-convert-express-description +4 -6
- data/exe/stepmod-convert-express-resource +4 -6
- data/exe/stepmod-extract-concepts +5 -4
- data/exe/stepmod-srl-migrate +21 -22
- data/exe/stepmod-validate-express +13 -15
- data/lib/stepmod/utils/change.rb +33 -5
- data/lib/stepmod/utils/change_collection.rb +1 -1
- data/lib/stepmod/utils/changes_extractor.rb +23 -3
- data/lib/stepmod/utils/concept.rb +12 -10
- data/lib/stepmod/utils/converters/blockquote.rb +0 -2
- data/lib/stepmod/utils/converters/def.rb +4 -4
- data/lib/stepmod/utils/converters/dt.rb +1 -1
- data/lib/stepmod/utils/converters/em_express_description.rb +8 -7
- data/lib/stepmod/utils/converters/eqn.rb +8 -6
- data/lib/stepmod/utils/converters/express_figure.rb +1 -1
- data/lib/stepmod/utils/converters/express_g.rb +1 -1
- data/lib/stepmod/utils/converters/express_table.rb +1 -1
- data/lib/stepmod/utils/converters/ext_description.rb +2 -1
- data/lib/stepmod/utils/converters/figure.rb +5 -5
- data/lib/stepmod/utils/converters/module_ref.rb +3 -5
- data/lib/stepmod/utils/converters/module_ref_express_description.rb +3 -7
- data/lib/stepmod/utils/converters/ol.rb +7 -7
- data/lib/stepmod/utils/converters/stepmod_ext_description.rb +3 -3
- data/lib/stepmod/utils/converters/strong.rb +12 -11
- data/lib/stepmod/utils/converters/term.rb +0 -1
- data/lib/stepmod/utils/express_bibdata.rb +6 -2
- data/lib/stepmod/utils/html_to_asciimath.rb +80 -80
- data/lib/stepmod/utils/parsers/mapping_table_parser.rb +31 -0
- data/lib/stepmod/utils/parsers/models/a.rb +40 -0
- data/lib/stepmod/utils/parsers/models/aa.rb +53 -0
- data/lib/stepmod/utils/parsers/models/ae.rb +54 -0
- data/lib/stepmod/utils/parsers/models/aimelt.rb +21 -0
- data/lib/stepmod/utils/parsers/models/alt.rb +19 -0
- data/lib/stepmod/utils/parsers/models/alt_map.rb +46 -0
- data/lib/stepmod/utils/parsers/models/alt_scmap.rb +34 -0
- data/lib/stepmod/utils/parsers/models/b.rb +58 -0
- data/lib/stepmod/utils/parsers/models/bigeqn.rb +55 -0
- data/lib/stepmod/utils/parsers/models/bold.rb +52 -0
- data/lib/stepmod/utils/parsers/models/bom_ref.rb +21 -0
- data/lib/stepmod/utils/parsers/models/constraint.rb +19 -0
- data/lib/stepmod/utils/parsers/models/dd.rb +86 -0
- data/lib/stepmod/utils/parsers/models/description.rb +86 -0
- data/lib/stepmod/utils/parsers/models/dl.rb +24 -0
- data/lib/stepmod/utils/parsers/models/dt.rb +86 -0
- data/lib/stepmod/utils/parsers/models/eqn.rb +57 -0
- data/lib/stepmod/utils/parsers/models/example.rb +84 -0
- data/lib/stepmod/utils/parsers/models/express_extref.rb +21 -0
- data/lib/stepmod/utils/parsers/models/express_ref.rb +21 -0
- data/lib/stepmod/utils/parsers/models/figure.rb +30 -0
- data/lib/stepmod/utils/parsers/models/i.rb +52 -0
- data/lib/stepmod/utils/parsers/models/img.rb +25 -0
- data/lib/stepmod/utils/parsers/models/imgarea.rb +23 -0
- data/lib/stepmod/utils/parsers/models/li.rb +86 -0
- data/lib/stepmod/utils/parsers/models/mapping_table.rb +26 -0
- data/lib/stepmod/utils/parsers/models/module_ref.rb +21 -0
- data/lib/stepmod/utils/parsers/models/note.rb +84 -0
- data/lib/stepmod/utils/parsers/models/ol.rb +25 -0
- data/lib/stepmod/utils/parsers/models/p.rb +56 -0
- data/lib/stepmod/utils/parsers/models/refpath.rb +23 -0
- data/lib/stepmod/utils/parsers/models/refpath_extend.rb +23 -0
- data/lib/stepmod/utils/parsers/models/rules.rb +19 -0
- data/lib/stepmod/utils/parsers/models/sc.rb +36 -0
- data/lib/stepmod/utils/parsers/models/screen.rb +55 -0
- data/lib/stepmod/utils/parsers/models/source.rb +21 -0
- data/lib/stepmod/utils/parsers/models/sub.rb +52 -0
- data/lib/stepmod/utils/parsers/models/sup.rb +52 -0
- data/lib/stepmod/utils/parsers/models/table.rb +29 -0
- data/lib/stepmod/utils/parsers/models/td.rb +98 -0
- data/lib/stepmod/utils/parsers/models/th.rb +98 -0
- data/lib/stepmod/utils/parsers/models/title.rb +53 -0
- data/lib/stepmod/utils/parsers/models/tr.rb +26 -0
- data/lib/stepmod/utils/parsers/models/tt.rb +68 -0
- data/lib/stepmod/utils/parsers/models/ul.rb +21 -0
- data/lib/stepmod/utils/parsers/models.rb +0 -0
- data/lib/stepmod/utils/parsers/types/string_without_indent.rb +17 -0
- data/lib/stepmod/utils/parsers.rb +4 -0
- data/lib/stepmod/utils/smrl_description_converter.rb +2 -1
- data/lib/stepmod/utils/smrl_resource_converter.rb +2 -1
- data/lib/stepmod/utils/stepmod_file_annotator.rb +14 -7
- data/lib/stepmod/utils/term.rb +1 -1
- data/lib/stepmod/utils/terms_extractor.rb +33 -31
- data/lib/stepmod/utils/version.rb +1 -1
- data/stepmod-utils.gemspec +4 -3
- metadata +76 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 18bfb358046e62d1504ff514004e1c01213a5cd3a86c53985dabcf5ede14e56c
|
|
4
|
+
data.tar.gz: 37bf06f7198d4066bbabba3038ab4107dd4ac16dc65add33d0cd267b26fd2bdd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 767a9ba90526a414738cbc5bafe61b0e80da0f5b7ed9a714aa10442f87ca200303bd565ad718b0e5c2f5255311d174400fa00be6932f2b291c0b1ee55ed597b8
|
|
7
|
+
data.tar.gz: a73c95f1f931e1023f44bf308888a38cb1f1f7bc570e7fe910131e50e843b6c2d0384bb863f33fe35456ffdd39512ca85bb0e85f13cb62c7b663dc7178d78e39
|
|
@@ -7,11 +7,12 @@ on:
|
|
|
7
7
|
inputs:
|
|
8
8
|
next_version:
|
|
9
9
|
description: |
|
|
10
|
-
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
|
|
10
|
+
Next release version. Possible values: x.y.z, major, minor, patch (or pre|rc|etc).
|
|
11
|
+
Also, you can pass 'skip' to skip 'git tag' and do 'gem push' for the current version
|
|
11
12
|
required: true
|
|
12
13
|
default: 'skip'
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
repository_dispatch:
|
|
15
|
+
types: [ do-release ]
|
|
15
16
|
|
|
16
17
|
jobs:
|
|
17
18
|
release:
|
data/exe/stepmod-annotate-all
CHANGED
|
@@ -58,17 +58,20 @@ stepmod_dir = options[:stepmod_dir]
|
|
|
58
58
|
raise StandardError.new("--stepmod-dir not set") unless stepmod_dir
|
|
59
59
|
|
|
60
60
|
stepmod_path = Pathname.new(stepmod_dir)
|
|
61
|
-
unless
|
|
61
|
+
unless stepmod_path.join("data").exist? && stepmod_path.join("data").directory?
|
|
62
62
|
raise StandardError.new("--stepmod-dir should be the root STEPmod directory and contains data/")
|
|
63
63
|
end
|
|
64
|
+
|
|
64
65
|
log "STEPmod data path: `#{stepmod_dir}`"
|
|
65
66
|
|
|
66
67
|
srl_output_schemas_dir = options[:srl_output_schemas_dir]
|
|
67
68
|
raise StandardError.new("--schemas directory for SRL schemas not set") unless srl_output_schemas_dir
|
|
69
|
+
|
|
68
70
|
log "SRL schemas output path: `#{srl_output_schemas_dir}`"
|
|
69
71
|
|
|
70
72
|
srl_output_docs_dir = options[:srl_output_docs_dir]
|
|
71
73
|
raise StandardError.new("--documents directory for SRL documents (generated by stepmod2mn) not set") unless srl_output_docs_dir
|
|
74
|
+
|
|
72
75
|
log "SRL documents path: `#{srl_output_docs_dir}`"
|
|
73
76
|
|
|
74
77
|
unless File.exist?(srl_output_docs_dir) && File.directory?(srl_output_docs_dir)
|
|
@@ -126,7 +129,7 @@ def file_system_path(filepath, filename_cache)
|
|
|
126
129
|
filename_cache[dir][filepath.downcase]
|
|
127
130
|
end
|
|
128
131
|
|
|
129
|
-
MAX_THREADS = 1 #[2, Concurrent.processor_count].max * 2
|
|
132
|
+
MAX_THREADS = 1 # [2, Concurrent.processor_count].max * 2
|
|
130
133
|
MAX_QUEUE_SIZE = MAX_THREADS * 4
|
|
131
134
|
# https://github.com/ruby-concurrency/concurrent-ruby/blob/master/docs-source/thread_pools.md
|
|
132
135
|
# pool = Concurrent::ThreadPoolExecutor.new(
|
|
@@ -143,7 +146,6 @@ FileUtils.mkdir_p(srl_output_schemas_dir)
|
|
|
143
146
|
srl_output_schemas_path = Pathname.new(srl_output_schemas_dir)
|
|
144
147
|
srl_output_docs_path = Pathname.new(srl_output_docs_dir)
|
|
145
148
|
|
|
146
|
-
|
|
147
149
|
files.each do |file|
|
|
148
150
|
puts "#{Thread.current.object_id}: `#{file}` processing..."
|
|
149
151
|
|
|
@@ -153,7 +155,6 @@ files.each do |file|
|
|
|
153
155
|
).call
|
|
154
156
|
|
|
155
157
|
destination_rel_path = Pathname.new(file).dirname.relative_path_from(stepmod_path.join("data"))
|
|
156
|
-
directory_type = destination_rel_path.each_filename.to_a.first
|
|
157
158
|
|
|
158
159
|
destination_path = srl_output_schemas_path.join(destination_rel_path)
|
|
159
160
|
FileUtils.mkdir_p(destination_path)
|
|
@@ -17,10 +17,8 @@ input_content = ARGF.read
|
|
|
17
17
|
|
|
18
18
|
result = Stepmod::Utils::SmrlDescriptionConverter.convert(input_content, {})
|
|
19
19
|
result.split("\n").each do |line|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
exit(74)
|
|
25
|
-
end
|
|
20
|
+
$stdout.puts(line)
|
|
21
|
+
$stdout.flush
|
|
22
|
+
rescue Errno::EPIPE
|
|
23
|
+
exit(74)
|
|
26
24
|
end
|
|
@@ -17,10 +17,8 @@ input_content = ARGF.read
|
|
|
17
17
|
|
|
18
18
|
result = Stepmod::Utils::SmrlResourceConverter.convert(input_content, {})
|
|
19
19
|
result.split("\n").each do |line|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
exit(74)
|
|
25
|
-
end
|
|
20
|
+
$stdout.puts(line)
|
|
21
|
+
$stdout.flush
|
|
22
|
+
rescue Errno::EPIPE
|
|
23
|
+
exit(74)
|
|
26
24
|
end
|
|
@@ -77,7 +77,8 @@ else
|
|
|
77
77
|
)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
default_output_dir = File.join(File.expand_path("..", stepmod_dir),
|
|
80
|
+
default_output_dir = File.join(File.expand_path("..", stepmod_dir),
|
|
81
|
+
"output_yaml")
|
|
81
82
|
output_dir = options[:output_dir] || default_output_dir
|
|
82
83
|
unless File.directory?(output_dir)
|
|
83
84
|
FileUtils.mkdir_p(output_dir)
|
|
@@ -164,7 +165,7 @@ end
|
|
|
164
165
|
yaml_outputs = {
|
|
165
166
|
clause_4_sections: {},
|
|
166
167
|
clause_5_sections: {},
|
|
167
|
-
bibliographies: {}
|
|
168
|
+
bibliographies: {},
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
part_resources.each do |(_bibdata, current_part_resources)|
|
|
@@ -204,9 +205,9 @@ extract_bibliographies(resource_concepts, yaml_outputs[:bibliographies])
|
|
|
204
205
|
{
|
|
205
206
|
clause_4_sections: "resource_sections.yaml",
|
|
206
207
|
clause_5_sections: "module_sections.yaml",
|
|
207
|
-
bibliographies: "bib.yaml"
|
|
208
|
+
bibliographies: "bib.yaml",
|
|
208
209
|
}.each_pair do |var, filename|
|
|
209
210
|
path = File.join(output_dir, filename)
|
|
210
211
|
File.write(path, yaml_outputs[var].values.to_yaml)
|
|
211
|
-
log "INFO: #{var
|
|
212
|
+
log "INFO: #{var} written to #{path}."
|
|
212
213
|
end
|
data/exe/stepmod-srl-migrate
CHANGED
|
@@ -15,7 +15,7 @@ require "optparse"
|
|
|
15
15
|
|
|
16
16
|
def log(message, indent = 0)
|
|
17
17
|
indent_spaces = " " * (indent * 2)
|
|
18
|
-
puts "[stepmod-utils] #{message}"
|
|
18
|
+
puts "[stepmod-utils] #{indent_spaces}#{message}"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def copy_files_to_schemas(path, stepmod_path, srl_output_schemas_dir)
|
|
@@ -34,13 +34,12 @@ def copy_files_to_schemas(path, stepmod_path, srl_output_schemas_dir)
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def copy_files_to_document(path, stepmod_path, srl_output_docs_dir)
|
|
37
|
-
base_path = path.dirname.relative_path_from(File.join(stepmod_path, "data"))
|
|
38
37
|
file_name = path.basename
|
|
39
|
-
module_xml_path = path.dirname.join(
|
|
38
|
+
module_xml_path = path.dirname.join("module.xml")
|
|
40
39
|
# puts "module_xml_path #{module_xml_path}"
|
|
41
40
|
module_xml = Nokogiri::XML(IO.read(module_xml_path)).root
|
|
42
41
|
|
|
43
|
-
part_number = module_xml.xpath(
|
|
42
|
+
part_number = module_xml.xpath("//module").first.attr("part")
|
|
44
43
|
# module_name = module_xml.xpath('//module').first.attr('name')
|
|
45
44
|
|
|
46
45
|
new_dir = File.join(srl_output_docs_dir, "iso-10303-#{part_number}")
|
|
@@ -99,19 +98,19 @@ OptionParser.new do |opts|
|
|
|
99
98
|
end.parse!
|
|
100
99
|
|
|
101
100
|
def download_stepmod2mn(path)
|
|
102
|
-
if path
|
|
101
|
+
if path&.exist?
|
|
103
102
|
puts "Specified `stepmod2mn.jar` found, skipping download."
|
|
104
103
|
return path
|
|
105
104
|
end
|
|
106
105
|
|
|
107
106
|
puts "Specified `stepmod2mn.jar` not found, downloading from GitHub."
|
|
108
107
|
|
|
109
|
-
require
|
|
108
|
+
require "octokit"
|
|
110
109
|
require "down"
|
|
111
110
|
require "fileutils"
|
|
112
111
|
|
|
113
112
|
client = Octokit::Client.new
|
|
114
|
-
download_url = client.latest_release(
|
|
113
|
+
download_url = client.latest_release("metanorma/stepmod2mn").assets.first.browser_download_url
|
|
115
114
|
|
|
116
115
|
filename = Pathname.new(download_url).basename.to_s
|
|
117
116
|
|
|
@@ -147,7 +146,7 @@ end
|
|
|
147
146
|
|
|
148
147
|
stepmod_path = Pathname.new(stepmod_dir)
|
|
149
148
|
unless stepmod_path.exist? && stepmod_path.directory? &&
|
|
150
|
-
|
|
149
|
+
stepmod_path.join("data").exist? && stepmod_path.join("data").directory?
|
|
151
150
|
puts "Specified STEPmod directory not found, not a directory, or does not contain `data/`. Aborting."
|
|
152
151
|
exit 1
|
|
153
152
|
end
|
|
@@ -167,32 +166,32 @@ unless File.directory?(srl_output_docs_dir)
|
|
|
167
166
|
end
|
|
168
167
|
log "SRL output documents directory path: `#{srl_output_docs_dir}`"
|
|
169
168
|
|
|
170
|
-
log("*"*30)
|
|
169
|
+
log("*" * 30)
|
|
171
170
|
log("[SRL MIGRATION] Migration starts!")
|
|
172
171
|
|
|
173
|
-
log("*"*30)
|
|
172
|
+
log("*" * 30)
|
|
174
173
|
log("[SRL MIGRATION: stepmod2mn.jar] START SVG generation.")
|
|
175
|
-
log("*"*30)
|
|
174
|
+
log("*" * 30)
|
|
176
175
|
system "java -Xss5m -jar #{stepmod2mn_path} #{stepmod_dir} --output-documents #{srl_output_docs_dir} --output-schemas #{srl_output_schemas_dir} --svg"
|
|
177
176
|
|
|
178
|
-
log("*"*30)
|
|
177
|
+
log("*" * 30)
|
|
179
178
|
log("[SRL MIGRATION: stepmod2mn.jar] COMPLETE SVG generation.")
|
|
180
179
|
|
|
181
|
-
log("*"*30)
|
|
180
|
+
log("*" * 30)
|
|
182
181
|
log("[SRL MIGRATION: stepmod2mn.jar] START document migration and SVG generation.")
|
|
183
|
-
log("*"*30)
|
|
182
|
+
log("*" * 30)
|
|
184
183
|
system "java -Xss5m -jar #{stepmod2mn_path} #{stepmod_dir} --output-documents #{srl_output_docs_dir} --output-schemas #{srl_output_schemas_dir}"
|
|
185
|
-
log("*"*30)
|
|
184
|
+
log("*" * 30)
|
|
186
185
|
log("[SRL MIGRATION: stepmod2mn.jar] COMPLETE document migration and SVG generation.")
|
|
187
186
|
|
|
188
|
-
log("*"*30)
|
|
187
|
+
log("*" * 30)
|
|
189
188
|
log("[SRL MIGRATION: stepmod-utils] START Annotated EXPRESS generation.")
|
|
190
|
-
log("*"*30)
|
|
189
|
+
log("*" * 30)
|
|
191
190
|
system "stepmod-annotate-all --stepmod-dir #{stepmod_dir} --documents #{srl_output_docs_dir} --schemas #{srl_output_schemas_dir}"
|
|
192
|
-
log("*"*30)
|
|
191
|
+
log("*" * 30)
|
|
193
192
|
log("[SRL MIGRATION: stepmod-utils] COMPLETE Annotated EXPRESS generation.")
|
|
194
193
|
|
|
195
|
-
log("*"*30)
|
|
194
|
+
log("*" * 30)
|
|
196
195
|
log("[SRL MIGRATION: stepmod-utils] START EXPRESS change YAML extraction.")
|
|
197
196
|
system "stepmod-extract-changes -p #{stepmod_dir}"
|
|
198
197
|
|
|
@@ -208,10 +207,10 @@ Dir.glob("#{stepmod_dir}/data/**/changes.yaml").each do |filepath|
|
|
|
208
207
|
copy_files_to_document(path, stepmod_dir, srl_output_docs_dir)
|
|
209
208
|
end
|
|
210
209
|
|
|
211
|
-
log("*"*30)
|
|
210
|
+
log("*" * 30)
|
|
212
211
|
log("[SRL MIGRATION: stepmod-utils] COMPLETE EXPRESS change YAML extraction.")
|
|
213
212
|
|
|
214
|
-
log("*"*30)
|
|
213
|
+
log("*" * 30)
|
|
215
214
|
log("[SRL MIGRATION] Migration complete!")
|
|
216
215
|
|
|
217
|
-
log("*"*30)
|
|
216
|
+
log("*" * 30)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
3
|
+
require "nokogiri"
|
|
4
|
+
require "expressir"
|
|
5
|
+
require "expressir/express/parser"
|
|
6
|
+
require "expressir/express/formatter"
|
|
7
7
|
|
|
8
8
|
stepmod_dir = ARGV.pop || "iso-10303-stepmod-wg12"
|
|
9
9
|
stepmod_path = Pathname.new(stepmod_dir)
|
|
@@ -38,7 +38,7 @@ end
|
|
|
38
38
|
|
|
39
39
|
def parse_express_schema(path)
|
|
40
40
|
Expressir::Express::Parser.from_file(path)
|
|
41
|
-
rescue
|
|
41
|
+
rescue StandardError
|
|
42
42
|
puts "ERROR: Broken schema detected in #{path}!"
|
|
43
43
|
nil
|
|
44
44
|
end
|
|
@@ -54,7 +54,7 @@ puts REPO_INDEX_XML
|
|
|
54
54
|
puts
|
|
55
55
|
puts "NOTE: SHOULD_REWRITE mode is turned #{SHOULD_REWRITE ? 'ON' : 'OFF'}"
|
|
56
56
|
|
|
57
|
-
all_express_files(stepmod_dir).each_with_index do |exp_file,
|
|
57
|
+
all_express_files(stepmod_dir).each_with_index do |exp_file, _i|
|
|
58
58
|
# puts "i #{i}"
|
|
59
59
|
# next if i > 10
|
|
60
60
|
|
|
@@ -62,7 +62,6 @@ all_express_files(stepmod_dir).each_with_index do |exp_file, i|
|
|
|
62
62
|
exp_path = Pathname.new(exp_file)
|
|
63
63
|
repo = parse_express_schema(exp_file)
|
|
64
64
|
|
|
65
|
-
|
|
66
65
|
schemas_status[exp_path.to_s] = repo ? true : false
|
|
67
66
|
|
|
68
67
|
if repo.nil?
|
|
@@ -77,28 +76,27 @@ all_express_files(stepmod_dir).each_with_index do |exp_file, i|
|
|
|
77
76
|
formatted_schema = format_express_schema(repo)
|
|
78
77
|
# experimental_path = exp_path.dirname.join(exp_path.basename('.exp').to_s+".x.exp")
|
|
79
78
|
|
|
80
|
-
puts "rewriting : #{exp_path
|
|
79
|
+
puts "rewriting : #{exp_path}"
|
|
81
80
|
exp_path.truncate(0)
|
|
82
81
|
exp_path.write(formatted_schema)
|
|
83
82
|
end
|
|
84
|
-
|
|
85
83
|
end
|
|
86
84
|
|
|
87
|
-
puts "*"*30
|
|
85
|
+
puts "*" * 30
|
|
88
86
|
|
|
89
|
-
if schemas_status.
|
|
87
|
+
if schemas_status.value?(false)
|
|
90
88
|
puts "The following schemas failed validation:"
|
|
91
|
-
schemas_status.select do |
|
|
89
|
+
schemas_status.select do |_path, status|
|
|
92
90
|
status == false
|
|
93
|
-
end.each_pair do |path,
|
|
91
|
+
end.each_pair do |path, _status|
|
|
94
92
|
puts "SCHEMA: #{path}"
|
|
95
93
|
end
|
|
96
|
-
puts "*"*30
|
|
94
|
+
puts "*" * 30
|
|
97
95
|
|
|
98
96
|
exit 1
|
|
99
97
|
end
|
|
100
98
|
|
|
101
99
|
puts "All schemas passed validation."
|
|
102
|
-
puts "*"*30
|
|
100
|
+
puts "*" * 30
|
|
103
101
|
|
|
104
102
|
exit 0
|
data/lib/stepmod/utils/change.rb
CHANGED
|
@@ -5,7 +5,7 @@ require "stepmod/utils/change_edition_collection"
|
|
|
5
5
|
module Stepmod
|
|
6
6
|
module Utils
|
|
7
7
|
class Change
|
|
8
|
-
attr_accessor :schema_name
|
|
8
|
+
attr_accessor :schema_name, :mapping_table
|
|
9
9
|
attr_reader :change_editions
|
|
10
10
|
|
|
11
11
|
MODULE_TYPES = {
|
|
@@ -14,12 +14,19 @@ module Stepmod
|
|
|
14
14
|
arm_longform: "arm_lf",
|
|
15
15
|
mim_longform: "mim_lf",
|
|
16
16
|
mapping: "mapping",
|
|
17
|
-
changes: "",
|
|
17
|
+
changes: "changes",
|
|
18
|
+
mapping_table: "mapping",
|
|
18
19
|
}.freeze
|
|
19
20
|
|
|
21
|
+
TYPES_WITHOUT_EXTENSION = %w[
|
|
22
|
+
changes
|
|
23
|
+
mapping_table
|
|
24
|
+
].freeze
|
|
25
|
+
|
|
20
26
|
def initialize(stepmod_dir:, schema_name:, type:)
|
|
21
27
|
@stepmod_dir = stepmod_dir
|
|
22
28
|
@change_editions = Stepmod::Utils::ChangeEditionCollection.new
|
|
29
|
+
@mapping_table = {}
|
|
23
30
|
@schema_name = schema_name
|
|
24
31
|
@type = type
|
|
25
32
|
end
|
|
@@ -42,10 +49,14 @@ module Stepmod
|
|
|
42
49
|
alias_method :[], :fetch_change_edition
|
|
43
50
|
|
|
44
51
|
def save_to_file
|
|
45
|
-
change_hash =
|
|
52
|
+
change_hash = if @type == "mapping_table"
|
|
53
|
+
@mapping_table
|
|
54
|
+
else
|
|
55
|
+
to_h
|
|
56
|
+
end
|
|
46
57
|
return if change_hash.empty?
|
|
47
58
|
|
|
48
|
-
File.write(filepath(@type), Psych.dump(change_hash))
|
|
59
|
+
File.write(filepath(@type), Psych.dump(stringify_keys(change_hash)))
|
|
49
60
|
end
|
|
50
61
|
|
|
51
62
|
def to_h
|
|
@@ -72,7 +83,7 @@ module Stepmod
|
|
|
72
83
|
end
|
|
73
84
|
|
|
74
85
|
def filename(type)
|
|
75
|
-
return "
|
|
86
|
+
return "#{MODULE_TYPES[type.to_sym]}.yaml" if TYPES_WITHOUT_EXTENSION.include?(type.to_s)
|
|
76
87
|
|
|
77
88
|
"#{MODULE_TYPES[type.to_sym] || schema_name}.changes.yaml"
|
|
78
89
|
end
|
|
@@ -84,6 +95,23 @@ module Stepmod
|
|
|
84
95
|
"modules"
|
|
85
96
|
end
|
|
86
97
|
end
|
|
98
|
+
|
|
99
|
+
# Hash#transform_keys is not available in Ruby 2.4
|
|
100
|
+
# so we have to do this ourselves :(
|
|
101
|
+
# symbolize hash keys
|
|
102
|
+
def stringify_keys(hash)
|
|
103
|
+
result = {}
|
|
104
|
+
hash.each_pair do |key, value|
|
|
105
|
+
result[key.to_s] = if value.is_a?(Hash)
|
|
106
|
+
stringify_keys(value)
|
|
107
|
+
elsif value.is_a?(Array)
|
|
108
|
+
value.map { |v| stringify_keys(v) }
|
|
109
|
+
else
|
|
110
|
+
value
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
result
|
|
114
|
+
end
|
|
87
115
|
end
|
|
88
116
|
end
|
|
89
117
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "nokogiri"
|
|
2
2
|
require "stepmod/utils/change_collection"
|
|
3
3
|
require "stepmod/utils/smrl_description_converter"
|
|
4
|
+
require_relative "parsers"
|
|
4
5
|
|
|
5
6
|
module Stepmod
|
|
6
7
|
module Utils
|
|
@@ -30,7 +31,11 @@ module Stepmod
|
|
|
30
31
|
all_modules_changes_files.each do |module_change_file|
|
|
31
32
|
xml_changes = Nokogiri::XML(File.read(module_change_file)).root
|
|
32
33
|
schema_name = Pathname.new(module_change_file).parent.basename.to_s
|
|
33
|
-
add_module_changes_to_collection(xml_changes, @collection,
|
|
34
|
+
add_module_changes_to_collection(xml_changes, @collection,
|
|
35
|
+
schema_name)
|
|
36
|
+
|
|
37
|
+
add_mapping_table_changes_to_collection(xml_changes, schema_name,
|
|
38
|
+
@collection)
|
|
34
39
|
end
|
|
35
40
|
|
|
36
41
|
@collection
|
|
@@ -38,6 +43,17 @@ module Stepmod
|
|
|
38
43
|
|
|
39
44
|
private
|
|
40
45
|
|
|
46
|
+
def add_mapping_table_changes_to_collection(xml_data, schema_name,
|
|
47
|
+
collection)
|
|
48
|
+
mapping_table = xml_data.at_xpath("//mapping_table")
|
|
49
|
+
return unless mapping_table
|
|
50
|
+
|
|
51
|
+
shale_object = Stepmod::Utils::Parsers::MappingTableParser.parse(mapping_table)
|
|
52
|
+
|
|
53
|
+
change = collection.fetch_or_initialize(schema_name, "mapping_table")
|
|
54
|
+
change.mapping_table = shale_object.to_hash
|
|
55
|
+
end
|
|
56
|
+
|
|
41
57
|
# rubocop:disable Metrics/MethodLength
|
|
42
58
|
def add_resource_changes_to_collection(xml_data, collection)
|
|
43
59
|
xml_data.xpath("//changes").each do |changes_node|
|
|
@@ -135,17 +151,21 @@ module Stepmod
|
|
|
135
151
|
|
|
136
152
|
change_node.xpath("mapping.changes").each do |changes|
|
|
137
153
|
changes.xpath("mapping.change").each do |change|
|
|
138
|
-
mappings << { "change" => change.text }
|
|
154
|
+
mappings << { "change" => clean_string(change.text.strip) }
|
|
139
155
|
end
|
|
140
156
|
|
|
141
157
|
changes.xpath("description").each do |change|
|
|
142
|
-
mappings << { "description" => change.text }
|
|
158
|
+
mappings << { "description" => clean_string(change.text.strip) }
|
|
143
159
|
end
|
|
144
160
|
end
|
|
145
161
|
|
|
146
162
|
mappings
|
|
147
163
|
end
|
|
148
164
|
|
|
165
|
+
def clean_string(string)
|
|
166
|
+
string.gsub(/[\n\t]/, " ").squeeze(" ")
|
|
167
|
+
end
|
|
168
|
+
|
|
149
169
|
def extract_change_edition(schema_changes, options)
|
|
150
170
|
type = options[:type] || "schema"
|
|
151
171
|
node_type = type.gsub("_longform", "")
|
|
@@ -17,7 +17,8 @@ module Stepmod
|
|
|
17
17
|
# TODO: converted_definition is not supposed to be an attribute, it is
|
|
18
18
|
# supposed to be a method!
|
|
19
19
|
class << self
|
|
20
|
-
def parse(definition_xml, reference_anchor:, reference_clause:,
|
|
20
|
+
def parse(definition_xml, reference_anchor:, reference_clause:,
|
|
21
|
+
file_path:, language_code: "eng")
|
|
21
22
|
converted_definition = Stepmod::Utils::StepmodDefinitionConverter.convert(
|
|
22
23
|
definition_xml,
|
|
23
24
|
{
|
|
@@ -64,14 +65,15 @@ module Stepmod
|
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
term = Stepmod::Utils::Converters::Term
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
.new
|
|
69
|
+
.convert(
|
|
70
|
+
definition_xml.xpath(".//term").first,
|
|
71
|
+
)
|
|
71
72
|
|
|
72
73
|
# [4..-1] because we want to skip the initial `=== {title}`
|
|
73
74
|
designations = [
|
|
74
|
-
{ "designation" => term[4..-1], "type" => "expression",
|
|
75
|
+
{ "designation" => term[4..-1], "type" => "expression",
|
|
76
|
+
"normative_status" => "preferred" },
|
|
75
77
|
]
|
|
76
78
|
|
|
77
79
|
alts.each do |alt|
|
|
@@ -84,10 +86,10 @@ module Stepmod
|
|
|
84
86
|
def definition_xml_definition(definition_xml, reference_anchor)
|
|
85
87
|
# We reject the <p> that was considered an alternative term (length<=20)
|
|
86
88
|
text_nodes = definition_xml
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
.xpath(".//def")
|
|
90
|
+
.first
|
|
91
|
+
.children
|
|
92
|
+
.reject { |n| n.name == "p" && n.text.length <= 20 }
|
|
91
93
|
|
|
92
94
|
wrapper = "<def>#{text_nodes.map(&:to_s).join}</def>"
|
|
93
95
|
|
|
@@ -6,12 +6,10 @@ module Stepmod
|
|
|
6
6
|
class Blockquote < Stepmod::Utils::Converters::Base
|
|
7
7
|
def convert(node, state = {})
|
|
8
8
|
id = node["id"]
|
|
9
|
-
anchor = id ? "[[#{id}]]\n" : ""
|
|
10
9
|
cite = node["cite"]
|
|
11
10
|
attrs = cite ? "[quote, #{cite}]\n" : ""
|
|
12
11
|
content = treat_children(node, state).strip
|
|
13
12
|
content = ReverseAdoc.cleaner.remove_newlines(content)
|
|
14
|
-
# "\n\n> " << content.lines.to_a.join('> ') << "\n\n"
|
|
15
13
|
"\n\n#{attrs}____\n" << content.lines.to_a.join("") << "\n____\n\n"
|
|
16
14
|
end
|
|
17
15
|
end
|
|
@@ -50,13 +50,13 @@ module Stepmod
|
|
|
50
50
|
def additional_block(node)
|
|
51
51
|
# Treat first `p` tag as an `alt` block, metanorma/stepmod-utils#9
|
|
52
52
|
first_child_tag = node
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
.children
|
|
54
|
+
.find { |n| n.is_a?(Nokogiri::XML::Element) }
|
|
55
55
|
return unless can_transform_to_alt?(first_child_tag)
|
|
56
56
|
|
|
57
57
|
result = Stepmod::Utils::Converters::Synonym
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
.new
|
|
59
|
+
.convert(first_child_tag)
|
|
60
60
|
|
|
61
61
|
first_child_tag.remove
|
|
62
62
|
"#{result}\n\n"
|
|
@@ -13,18 +13,19 @@ module Stepmod
|
|
|
13
13
|
def italic_converted(node, state)
|
|
14
14
|
cloned_node = node.clone
|
|
15
15
|
equations = extract_equations(cloned_node)
|
|
16
|
-
content = treat_children(cloned_node,
|
|
16
|
+
content = treat_children(cloned_node,
|
|
17
|
+
state.merge(already_italic: true))
|
|
17
18
|
equation_content = equations.map do |equation|
|
|
18
19
|
treat(equation, state.merge(equation: true, already_italic: true))
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
content = if state[:equation] && state[:convert_bold_and_italics]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
"ii(#{content.strip})"
|
|
24
|
+
elsif content.strip.empty? || state[:already_italic] || state[:equation]
|
|
25
|
+
content
|
|
26
|
+
else
|
|
27
|
+
"#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}"
|
|
28
|
+
end
|
|
28
29
|
|
|
29
30
|
[content, equation_content].compact.join("")
|
|
30
31
|
end
|
|
@@ -26,8 +26,8 @@ module Stepmod
|
|
|
26
26
|
|
|
27
27
|
def definition_node?(node)
|
|
28
28
|
first_strong_node = node
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
.children
|
|
30
|
+
.find do |n|
|
|
31
31
|
return false if !n.text? && n.name != "b"
|
|
32
32
|
|
|
33
33
|
n.name == "b"
|
|
@@ -39,8 +39,8 @@ module Stepmod
|
|
|
39
39
|
|
|
40
40
|
def definition_converted(cloned_node, state)
|
|
41
41
|
first_strong_node = cloned_node
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
.children
|
|
43
|
+
.find do |n|
|
|
44
44
|
return false if !n.text? && n.name != "b"
|
|
45
45
|
|
|
46
46
|
n.name == "b"
|
|
@@ -56,7 +56,8 @@ module Stepmod
|
|
|
56
56
|
|
|
57
57
|
def stem_converted(cloned_node, state)
|
|
58
58
|
remove_tags_not_in_context(cloned_node) unless state[:convert_bold_and_italics]
|
|
59
|
-
internal_content = treat_children(cloned_node,
|
|
59
|
+
internal_content = treat_children(cloned_node,
|
|
60
|
+
state.merge(equation: true))
|
|
60
61
|
content = Stepmod::Utils::HtmlToAsciimath.new.call(internal_content)
|
|
61
62
|
res = <<~TEMPLATE
|
|
62
63
|
#{source_type_comment(cloned_node)}
|
|
@@ -107,7 +108,8 @@ module Stepmod
|
|
|
107
108
|
end
|
|
108
109
|
|
|
109
110
|
def log_equation(node, state, equation_converted)
|
|
110
|
-
equation_converted_with_bold_and_italics = stem_converted(node.clone,
|
|
111
|
+
equation_converted_with_bold_and_italics = stem_converted(node.clone,
|
|
112
|
+
state.merge(convert_bold_and_italics: true))
|
|
111
113
|
|
|
112
114
|
return if equation_converted_with_bold_and_italics == equation_converted
|
|
113
115
|
|