stepmod-utils 0.3.23 → 0.3.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test-concept-generation.yml +38 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +3 -0
- data/exe/stepmod-annotate-all +27 -14
- data/exe/stepmod-extract-changes +57 -0
- data/exe/stepmod-extract-concepts +165 -0
- data/lib/stepmod/utils/change.rb +74 -0
- data/lib/stepmod/utils/change_collection.rb +50 -0
- data/lib/stepmod/utils/change_edition.rb +60 -0
- data/lib/stepmod/utils/change_edition_collection.rb +38 -0
- data/lib/stepmod/utils/changes_extractor.rb +194 -0
- data/lib/stepmod/utils/concept.rb +40 -10
- data/lib/stepmod/utils/converters/description.rb +22 -0
- data/lib/stepmod/utils/express_bibdata.rb +111 -0
- data/lib/stepmod/utils/smrl_description_converter.rb +1 -0
- data/lib/stepmod/utils/stepmod_file_annotator.rb +215 -14
- data/lib/stepmod/utils/term.rb +18 -5
- data/lib/stepmod/utils/terms_extractor.rb +253 -292
- data/lib/stepmod/utils/version.rb +1 -1
- data/stepmod-utils.gemspec +2 -1
- metadata +31 -11
- data/exe/stepmod-build-resource-docs-cache +0 -20
- data/exe/stepmod-extract-terms +0 -237
- data/exe/stepmod-find-express-files +0 -24
@@ -0,0 +1,194 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "stepmod/utils/change_collection"
|
3
|
+
require "stepmod/utils/smrl_description_converter"
|
4
|
+
|
5
|
+
module Stepmod
|
6
|
+
module Utils
|
7
|
+
class ChangesExtractor
|
8
|
+
MODULE_TYPES = %w[arm mim arm_longform mim_longform].freeze
|
9
|
+
|
10
|
+
attr_accessor :stepmod_dir
|
11
|
+
|
12
|
+
def self.call(stepmod_dir:, stdout: $stdout)
|
13
|
+
new(stepmod_dir: stepmod_dir, stdout: stdout).call
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(stepmod_dir:, stdout: $stdout)
|
17
|
+
@stdout = stdout
|
18
|
+
@stepmod_dir = stepmod_dir
|
19
|
+
@collection = Stepmod::Utils::ChangeCollection.new(
|
20
|
+
stepmod_dir: stepmod_dir,
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def call
|
25
|
+
all_resource_changes_files.each do |resource_change_file|
|
26
|
+
xml_changes = Nokogiri::XML(File.read(resource_change_file)).root
|
27
|
+
add_resource_changes_to_collection(xml_changes, @collection)
|
28
|
+
end
|
29
|
+
|
30
|
+
all_modules_changes_files.each do |module_change_file|
|
31
|
+
xml_changes = Nokogiri::XML(File.read(module_change_file)).root
|
32
|
+
schema_name = Pathname.new(module_change_file).parent.basename.to_s
|
33
|
+
add_module_changes_to_collection(xml_changes, @collection, schema_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
@collection
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# rubocop:disable Metrics/MethodLength
|
42
|
+
def add_resource_changes_to_collection(xml_data, collection)
|
43
|
+
xml_data.xpath("//changes").each do |changes_node|
|
44
|
+
changes_node.xpath("change_edition").each do |change_edition_node|
|
45
|
+
options = {
|
46
|
+
version: change_edition_node.attr("version"),
|
47
|
+
description: Stepmod::Utils::SmrlDescriptionConverter.convert(
|
48
|
+
change_edition_node.at("description"),
|
49
|
+
),
|
50
|
+
}
|
51
|
+
|
52
|
+
add_resource_changes(
|
53
|
+
collection,
|
54
|
+
change_edition_node,
|
55
|
+
options,
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_module_changes_to_collection(xml_data, collection, schema_name)
|
62
|
+
xml_data.xpath("//changes").each do |changes_node|
|
63
|
+
changes_node.xpath("change").each do |change_node|
|
64
|
+
options = {
|
65
|
+
schema_name: schema_name,
|
66
|
+
version: change_node.attr("version"),
|
67
|
+
description: converted_description(change_node.at("description")),
|
68
|
+
}
|
69
|
+
|
70
|
+
MODULE_TYPES.each do |type|
|
71
|
+
add_module_changes(
|
72
|
+
collection,
|
73
|
+
change_node,
|
74
|
+
options,
|
75
|
+
type,
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_resource_changes(collection, change_node, options)
|
83
|
+
change_node.xpath("schema.changes").each do |changes|
|
84
|
+
schema_name = correct_schema_name(changes.attr("schema_name"))
|
85
|
+
change = collection.fetch_or_initialize(schema_name, "schema")
|
86
|
+
|
87
|
+
change_edition = extract_change_edition(changes, options)
|
88
|
+
change.add_change_edition(change_edition)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def add_module_changes(collection, change_node, options, type)
|
93
|
+
options[:type] = type
|
94
|
+
# assuming there will only be one change related to a type in the
|
95
|
+
# same version.
|
96
|
+
changes = change_node.xpath("#{type}.changes").first
|
97
|
+
schema_name = options[:schema_name]
|
98
|
+
change = collection.fetch_or_initialize(schema_name, type)
|
99
|
+
|
100
|
+
change_edition = extract_change_edition(changes, options)
|
101
|
+
change.add_change_edition(change_edition)
|
102
|
+
|
103
|
+
if type == "arm"
|
104
|
+
add_mapping_changes(collection, change_node, options)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_mapping_changes(collection, change_node, options)
|
109
|
+
change_edition = collection
|
110
|
+
.fetch_or_initialize(options[:schema_name], "arm")
|
111
|
+
.change_editions
|
112
|
+
.fetch_or_initialize(options[:version])
|
113
|
+
|
114
|
+
change_edition.mapping = extract_mapping_changes(change_node)
|
115
|
+
end
|
116
|
+
|
117
|
+
def extract_mapping_changes(change_node)
|
118
|
+
mappings = []
|
119
|
+
|
120
|
+
change_node.xpath("mapping.changes").each do |changes|
|
121
|
+
changes.xpath("mapping.change").each do |change|
|
122
|
+
mappings << { "change" => change.text }
|
123
|
+
end
|
124
|
+
|
125
|
+
changes.xpath("description").each do |change|
|
126
|
+
mappings << { "description" => change.text }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
mappings
|
131
|
+
end
|
132
|
+
|
133
|
+
def extract_change_edition(schema_changes, options)
|
134
|
+
type = options[:type] || "schema"
|
135
|
+
addition_nodes = schema_changes&.xpath("#{type}.additions") || []
|
136
|
+
modification_nodes = schema_changes&.xpath("#{type}.modifications") || []
|
137
|
+
deletion_nodes = schema_changes&.xpath("#{type}.deletions") || []
|
138
|
+
|
139
|
+
{
|
140
|
+
version: options[:version],
|
141
|
+
description: options[:description],
|
142
|
+
additions: extract_modified_objects(addition_nodes),
|
143
|
+
modifications: extract_modified_objects(modification_nodes),
|
144
|
+
deletions: extract_modified_objects(deletion_nodes),
|
145
|
+
}
|
146
|
+
end
|
147
|
+
# rubocop:enable Metrics/MethodLength
|
148
|
+
|
149
|
+
def extract_modified_objects(nodes)
|
150
|
+
nodes.map do |node|
|
151
|
+
node.xpath("modified.object").map do |object|
|
152
|
+
{
|
153
|
+
type: object.attr("type"),
|
154
|
+
name: object.attr("name"),
|
155
|
+
description: converted_description(object.at("description")),
|
156
|
+
interfaced_items: object.attr("interfaced.items"),
|
157
|
+
}.compact
|
158
|
+
end
|
159
|
+
end.flatten
|
160
|
+
end
|
161
|
+
|
162
|
+
def converted_description(description)
|
163
|
+
return if description.to_s.empty?
|
164
|
+
|
165
|
+
Stepmod::Utils::SmrlDescriptionConverter.convert(description)
|
166
|
+
end
|
167
|
+
|
168
|
+
def all_resource_changes_files
|
169
|
+
Dir.glob(
|
170
|
+
File.join(stepmod_dir, "data", "resource_docs", "*", "resource.xml"),
|
171
|
+
)
|
172
|
+
end
|
173
|
+
|
174
|
+
def all_modules_changes_files
|
175
|
+
Dir.glob(
|
176
|
+
File.join(stepmod_dir, "data", "modules", "*", "module.xml"),
|
177
|
+
)
|
178
|
+
end
|
179
|
+
|
180
|
+
# rubocop:disable Layout/LineLength
|
181
|
+
def correct_schema_name(schema_name)
|
182
|
+
schema_name_corrector = {
|
183
|
+
"material_property_definition" => "material_property_definition_schema",
|
184
|
+
"qualified_measure" => "qualified_measure_schema",
|
185
|
+
"material_property_representation" => "material_property_representation_schema",
|
186
|
+
"annotated_3d_model_data_quality_criteria" => "annotated_3d_model_data_quality_criteria_schema",
|
187
|
+
}
|
188
|
+
|
189
|
+
schema_name_corrector[schema_name] || schema_name
|
190
|
+
end
|
191
|
+
# rubocop:enable Layout/LineLength
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -8,6 +8,10 @@ module Stepmod
|
|
8
8
|
reference_anchor
|
9
9
|
converted_definition
|
10
10
|
file_path
|
11
|
+
schema
|
12
|
+
part
|
13
|
+
domain
|
14
|
+
document
|
11
15
|
)
|
12
16
|
|
13
17
|
# TODO: converted_definition is not supposed to be an attribute, it is
|
@@ -40,8 +44,8 @@ module Stepmod
|
|
40
44
|
# TODO: `designations:` should include the `alt:[...]` terms here,
|
41
45
|
# they are now only included in definition_xml_converted_definition.
|
42
46
|
new(
|
43
|
-
designations:
|
44
|
-
definition: definition,
|
47
|
+
designations: designation,
|
48
|
+
definition: [definition],
|
45
49
|
converted_definition: converted_definition,
|
46
50
|
id: "#{reference_anchor}.#{reference_clause}",
|
47
51
|
reference_anchor: reference_anchor,
|
@@ -65,11 +69,16 @@ module Stepmod
|
|
65
69
|
definition_xml.xpath(".//term").first
|
66
70
|
)
|
67
71
|
|
68
|
-
{
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
72
|
+
# [4..-1] because we want to skip the initial `=== {title}`
|
73
|
+
designations = [
|
74
|
+
{ "designation" => term[4..-1], "type" => "expression", "normative_status" => "preferred" },
|
75
|
+
]
|
76
|
+
|
77
|
+
alts.each do |alt|
|
78
|
+
designations << { "designation" => alt, "type" => "expression" }
|
79
|
+
end
|
80
|
+
|
81
|
+
designations
|
73
82
|
end
|
74
83
|
|
75
84
|
def definition_xml_definition(definition_xml, reference_anchor)
|
@@ -95,12 +104,24 @@ module Stepmod
|
|
95
104
|
end
|
96
105
|
|
97
106
|
def definition_xml_converted_definition(designation, definition)
|
98
|
-
|
99
|
-
|
107
|
+
accepted_designation = designation.select do |des|
|
108
|
+
des["normative_status"] == "preferred"
|
109
|
+
end
|
110
|
+
|
111
|
+
alt_designations = designation.reject do |des|
|
112
|
+
des["normative_status"] == "preferred"
|
113
|
+
end
|
114
|
+
|
115
|
+
if alt_designations.length.positive?
|
116
|
+
alt_designations_text = alt_designations.map do |d|
|
117
|
+
d["designation"].strip
|
118
|
+
end.join(",")
|
119
|
+
|
120
|
+
alt_notation = "alt:[#{alt_designations_text}]"
|
100
121
|
end
|
101
122
|
|
102
123
|
result = <<~TEXT
|
103
|
-
=== #{designation
|
124
|
+
=== #{accepted_designation.map { |d| d['designation'].strip }.join(',')}
|
104
125
|
TEXT
|
105
126
|
|
106
127
|
if alt_notation
|
@@ -117,6 +138,15 @@ module Stepmod
|
|
117
138
|
end
|
118
139
|
end
|
119
140
|
|
141
|
+
def to_h
|
142
|
+
super.merge({
|
143
|
+
"domain" => domain,
|
144
|
+
"part" => part,
|
145
|
+
"schema" => schema,
|
146
|
+
"document" => document,
|
147
|
+
}.compact)
|
148
|
+
end
|
149
|
+
|
120
150
|
def to_mn_adoc
|
121
151
|
<<~TEXT
|
122
152
|
// STEPmod path:#{file_path.empty? ? '' : " #{file_path}"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stepmod
|
4
|
+
module Utils
|
5
|
+
module Converters
|
6
|
+
class Description < ReverseAdoc::Converters::Base
|
7
|
+
def convert(node, state = {})
|
8
|
+
treat_children(node, state)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def treat_children(node, state)
|
14
|
+
res = node.children.map { |child| treat(child, state) }
|
15
|
+
res.map(&:strip).reject(&:empty?).join("\n\n")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ReverseAdoc::Converters.register :description, Description.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Stepmod
|
2
|
+
module Utils
|
3
|
+
class ExpressBibdata
|
4
|
+
DOCNUMBER = 10303
|
5
|
+
|
6
|
+
attr_accessor *%w(
|
7
|
+
type doctype part title_en version pub_year pubid published_info number
|
8
|
+
)
|
9
|
+
|
10
|
+
def initialize(schema:)
|
11
|
+
# module, resource, application_protocol, business_object_model
|
12
|
+
# @type = document.name
|
13
|
+
|
14
|
+
# raise "UnknownFileError" unless %w(module resource
|
15
|
+
# application_protocol business_object_model).include?(@type)
|
16
|
+
|
17
|
+
@published_info = schema.find("__published_in")&.remarks&.first
|
18
|
+
@number = schema.find("__identifier")&.remarks&.first&.split("N")&.last
|
19
|
+
@schema = schema
|
20
|
+
|
21
|
+
if !published_info.nil?
|
22
|
+
@pubid = Pubid::Iso::Identifier.parse(published_info)
|
23
|
+
|
24
|
+
@part = pubid.part
|
25
|
+
@version = pubid.edition
|
26
|
+
@pub_year = pubid.year
|
27
|
+
elsif !schema.version.nil?
|
28
|
+
@part = schema.version.items.find { |i| i.name == "part" }.value
|
29
|
+
@version = schema.version.items.find { |i| i.name == "part" }.value
|
30
|
+
@pub_year = schema.version.items.find { |i| i.name == "part" }.value
|
31
|
+
else
|
32
|
+
raise "PublishedInfoNotFound"
|
33
|
+
end
|
34
|
+
|
35
|
+
@doctype = schema.find("__status")&.remarks&.first
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def title_en
|
40
|
+
@title_en ||= @schema.find("__title")
|
41
|
+
.remarks
|
42
|
+
.first
|
43
|
+
.gsub("_", " ")
|
44
|
+
.capitalize
|
45
|
+
.gsub("2d", "2D")
|
46
|
+
.gsub("3d", "3D")
|
47
|
+
end
|
48
|
+
|
49
|
+
def docid
|
50
|
+
no_date = case doctype
|
51
|
+
when "IS"
|
52
|
+
"ISO #{DOCNUMBER}-#{part}"
|
53
|
+
when "WD"
|
54
|
+
"ISO/WD #{DOCNUMBER}-#{part}"
|
55
|
+
when "CD"
|
56
|
+
"ISO/CD #{DOCNUMBER}-#{part}"
|
57
|
+
when "DIS"
|
58
|
+
"ISO/DIS #{DOCNUMBER}-#{part}"
|
59
|
+
when "FDIS"
|
60
|
+
"ISO/FDIS #{DOCNUMBER}-#{part}"
|
61
|
+
when "TS"
|
62
|
+
"ISO/TS #{DOCNUMBER}-#{part}"
|
63
|
+
when "CD-TS"
|
64
|
+
"ISO/CD TS #{DOCNUMBER}-#{part}"
|
65
|
+
else
|
66
|
+
"UNKNOWN DOCTYPE: (#{doctype})"
|
67
|
+
end
|
68
|
+
|
69
|
+
if pub_year
|
70
|
+
"#{no_date}:#{pub_year}"
|
71
|
+
else
|
72
|
+
no_date
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def part_title
|
77
|
+
case part
|
78
|
+
when [200..299]
|
79
|
+
"Application protocol: #{title_en}"
|
80
|
+
when [300..399]
|
81
|
+
"Abstract test suite: #{title_en}"
|
82
|
+
when [400..499]
|
83
|
+
"Application module: #{title_en}"
|
84
|
+
when [500..599]
|
85
|
+
"Application interpreted construct: #{title_en}"
|
86
|
+
when [1000..1799]
|
87
|
+
"Application module: #{title_en}"
|
88
|
+
else
|
89
|
+
title_en
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def full_title
|
94
|
+
"Industrial automation systems and integration -- Product data" \
|
95
|
+
" representation and exchange -- Part #{part}: #{part_title}"
|
96
|
+
end
|
97
|
+
|
98
|
+
def anchor
|
99
|
+
docid.gsub("/", "-").gsub(" ", "_").gsub(":", "_")
|
100
|
+
end
|
101
|
+
|
102
|
+
def to_mn_adoc
|
103
|
+
if title_en
|
104
|
+
"* [[[#{anchor},#{docid}]]], _#{full_title}_"
|
105
|
+
else
|
106
|
+
"* [[[#{anchor},#{docid}]]]"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -6,6 +6,7 @@ require "stepmod/utils/converters/blockquote"
|
|
6
6
|
require "stepmod/utils/converters/br"
|
7
7
|
require "stepmod/utils/converters/bypass"
|
8
8
|
require "stepmod/utils/converters/code"
|
9
|
+
require "stepmod/utils/converters/description"
|
9
10
|
require "stepmod/utils/converters/drop"
|
10
11
|
require "stepmod/utils/converters/em_express_description"
|
11
12
|
require "stepmod/utils/converters/example"
|