stepmod-utils 0.4.14 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +4 -3
- data/exe/stepmod-annotate-all +42 -5
- 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: a5dc18c380e823b42d5e958c7c83008805c7ae44966481bd892ebe8e7119df9b
|
4
|
+
data.tar.gz: 83e1abb4edb5a8c9b585fca855024fb4cabc689a3223b858dd4b4d7c6f449897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b55e1bce8655edcc98ded98f9bd1658ecedafb15c413e123f9de6d5aecfe079f9ed929417683ad54b17e0586b55354baf4a798a94fc4a0908b825b58ca973209
|
7
|
+
data.tar.gz: 9dd2822119df10d4c6e1f66b5a49329e093c8c1a8b2bfcf05609f67660b3a5b5e0aff62fc86e8b116eb3c7da0721088d1aee91df2d9879b42da243897c10e4ba
|
@@ -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
@@ -7,6 +7,41 @@ require "fileutils"
|
|
7
7
|
require "bundler/setup"
|
8
8
|
require "optparse"
|
9
9
|
|
10
|
+
SKIP_DETACHED_SCHEMAS = %w(
|
11
|
+
assembly_constraint_schema
|
12
|
+
assembly_feature_relationship_schema
|
13
|
+
basis_schema
|
14
|
+
conditions_schema
|
15
|
+
domain_schema
|
16
|
+
equations_schema
|
17
|
+
explicit_constraint_schema
|
18
|
+
explicit_geometric_constraint_schema
|
19
|
+
fea_scalar_vector_tensor_schema
|
20
|
+
finite_element_analysis_control_and_result_schema
|
21
|
+
hierarchy_schema
|
22
|
+
iso13584_expressions_schema
|
23
|
+
ISO13584_expressions_schema
|
24
|
+
iso13584_generic_expressions_schema
|
25
|
+
ISO13584_generic_expressions_schema
|
26
|
+
mathematical_functions_schema
|
27
|
+
mesh_connectivity_schema
|
28
|
+
mesh_function_schema
|
29
|
+
mesh_topology_schema
|
30
|
+
method_definition_schema
|
31
|
+
parameterization_schema
|
32
|
+
procedural_model_schema
|
33
|
+
procedural_shape_model_schema
|
34
|
+
procedural_sketch_schema
|
35
|
+
process_property_representation_schema
|
36
|
+
process_property_schema
|
37
|
+
results_schema
|
38
|
+
sketch_schema
|
39
|
+
solid_shape_element_schema
|
40
|
+
structural_response_definition_schema
|
41
|
+
structural_response_representation_schema
|
42
|
+
variational_representation_schema
|
43
|
+
)
|
44
|
+
|
10
45
|
def log(message, indent = 0)
|
11
46
|
indent_spaces = " " * (indent * 2)
|
12
47
|
puts "[stepmod-utils] #{indent_spaces}#{message}"
|
@@ -58,17 +93,20 @@ stepmod_dir = options[:stepmod_dir]
|
|
58
93
|
raise StandardError.new("--stepmod-dir not set") unless stepmod_dir
|
59
94
|
|
60
95
|
stepmod_path = Pathname.new(stepmod_dir)
|
61
|
-
unless
|
96
|
+
unless stepmod_path.join("data").exist? && stepmod_path.join("data").directory?
|
62
97
|
raise StandardError.new("--stepmod-dir should be the root STEPmod directory and contains data/")
|
63
98
|
end
|
99
|
+
|
64
100
|
log "STEPmod data path: `#{stepmod_dir}`"
|
65
101
|
|
66
102
|
srl_output_schemas_dir = options[:srl_output_schemas_dir]
|
67
103
|
raise StandardError.new("--schemas directory for SRL schemas not set") unless srl_output_schemas_dir
|
104
|
+
|
68
105
|
log "SRL schemas output path: `#{srl_output_schemas_dir}`"
|
69
106
|
|
70
107
|
srl_output_docs_dir = options[:srl_output_docs_dir]
|
71
108
|
raise StandardError.new("--documents directory for SRL documents (generated by stepmod2mn) not set") unless srl_output_docs_dir
|
109
|
+
|
72
110
|
log "SRL documents path: `#{srl_output_docs_dir}`"
|
73
111
|
|
74
112
|
unless File.exist?(srl_output_docs_dir) && File.directory?(srl_output_docs_dir)
|
@@ -88,8 +126,9 @@ def all_express_files(stepmod_dir)
|
|
88
126
|
files << "#{stepmod_dir}/data/modules/#{item['name']}/mim.exp"
|
89
127
|
end
|
90
128
|
|
129
|
+
# Skip resource schemas
|
91
130
|
index.xpath("resources/resource").each do |item|
|
92
|
-
next if item["name"]
|
131
|
+
next if SKIP_DETACHED_SCHEMAS.include?(item["name"])
|
93
132
|
|
94
133
|
files << "#{stepmod_dir}/data/resources/#{item['name']}/#{item['name']}.exp"
|
95
134
|
end
|
@@ -126,7 +165,7 @@ def file_system_path(filepath, filename_cache)
|
|
126
165
|
filename_cache[dir][filepath.downcase]
|
127
166
|
end
|
128
167
|
|
129
|
-
MAX_THREADS = 1 #[2, Concurrent.processor_count].max * 2
|
168
|
+
MAX_THREADS = 1 # [2, Concurrent.processor_count].max * 2
|
130
169
|
MAX_QUEUE_SIZE = MAX_THREADS * 4
|
131
170
|
# https://github.com/ruby-concurrency/concurrent-ruby/blob/master/docs-source/thread_pools.md
|
132
171
|
# pool = Concurrent::ThreadPoolExecutor.new(
|
@@ -143,7 +182,6 @@ FileUtils.mkdir_p(srl_output_schemas_dir)
|
|
143
182
|
srl_output_schemas_path = Pathname.new(srl_output_schemas_dir)
|
144
183
|
srl_output_docs_path = Pathname.new(srl_output_docs_dir)
|
145
184
|
|
146
|
-
|
147
185
|
files.each do |file|
|
148
186
|
puts "#{Thread.current.object_id}: `#{file}` processing..."
|
149
187
|
|
@@ -153,7 +191,6 @@ files.each do |file|
|
|
153
191
|
).call
|
154
192
|
|
155
193
|
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
194
|
|
158
195
|
destination_path = srl_output_schemas_path.join(destination_rel_path)
|
159
196
|
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
|