stepmod-utils 0.3.14 → 0.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dbfad6cebbd4552c2b91cfd5aac3dc5a032bde8a44269b83303d8472bf86310
4
- data.tar.gz: 185a292f76f2e5b792383b8f2ca17438cb939a557f3df763ed5c9321c28b7438
3
+ metadata.gz: e8be21fe4d04046487ecb36fdebeb74f8dbbb7bda473cbb1b3451b62b15d62a0
4
+ data.tar.gz: f3005c150d30d5c8aac9b77f9221cfcfc575e0d541208152087f6ff88623375d
5
5
  SHA512:
6
- metadata.gz: a6f855167c151253c8b2278dfafe460198fe2c7789ce3cb2eba4dca20dc216546d88b68f199f48a6508574b1c28eaf476604799c99b3762662269eec743e0d5e
7
- data.tar.gz: a85e8f5a2d4607f5c001c5889c4549d2698279bb5163b3e87c79e5e28c3f0bbea7a38dd56d3440af3b43467ac2d93d7b16407d63f27c7abc61ca3fe1f5aa6551
6
+ metadata.gz: b004697a0c9eeecc570ba7e184fd7165fa991be9b0046f13305106a6cbdff123aca57299c340ce72fb95214ad878a0d0aff140af5e07308070d1c8a336c09921
7
+ data.tar.gz: 9aaa80fff000066c954b660592626a9ee0132cfca173c0d93aeb572211adf1929d79dc1f1336858725b031b287d1a9d07f9e4d79e45b8d4a4727819fbe303b9f
@@ -10,23 +10,6 @@ on:
10
10
 
11
11
  jobs:
12
12
  rake:
13
- name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
- runs-on: ${{ matrix.os }}
15
- continue-on-error: ${{ matrix.experimental }}
16
- strategy:
17
- fail-fast: false
18
- matrix:
19
- ruby: [ '3.0', '2.7', '2.6', '2.5' ]
20
- os: [ ubuntu-latest, windows-latest, macos-latest ]
21
- experimental: [ false ]
22
- steps:
23
- - uses: actions/checkout@v2
24
- with:
25
- submodules: true
26
-
27
- - uses: ruby/setup-ruby@v1
28
- with:
29
- ruby-version: ${{ matrix.ruby }}
30
- bundler-cache: true
31
-
32
- - run: bundle exec rake
13
+ uses: metanorma/ci/.github/workflows/generic-rake.yml@main
14
+ secrets:
15
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
@@ -15,32 +15,10 @@ on:
15
15
 
16
16
  jobs:
17
17
  release:
18
- runs-on: ubuntu-latest
19
- steps:
20
- - uses: actions/checkout@v2
18
+ uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
19
+ with:
20
+ next_version: ${{ github.event.inputs.next_version }}
21
+ secrets:
22
+ rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
23
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
21
24
 
22
- - uses: ruby/setup-ruby@v1
23
- with:
24
- ruby-version: '2.6'
25
- bundler-cache: true
26
-
27
- - run: gem install gem-release
28
-
29
- - run: |
30
- git config user.name github-actions
31
- git config user.email github-actions@github.com
32
-
33
- - if: github.event_name == 'workflow_dispatch' && github.event.inputs.next_version != 'skip'
34
- run: gem bump --version ${{ github.event.inputs.next_version }} --tag --push
35
-
36
- - name: publish to rubygems.org
37
- env:
38
- RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}}
39
- run: |
40
- gem install gem-release
41
- envsubst << 'EOF' > ~/.gem/credentials
42
- ---
43
- :rubygems_api_key: ${RUBYGEMS_API_KEY}
44
- EOF
45
- chmod 0600 ~/.gem/credentials
46
- gem release
data/README.adoc CHANGED
@@ -14,11 +14,6 @@ The `stepmod-utils` Ruby gem provides a number of tools to work with the STEPmod
14
14
  repository.
15
15
 
16
16
 
17
- == CVS to Git migration procedures
18
-
19
- include::migrating_from_cvs.adoc[]
20
-
21
-
22
17
  == Installation
23
18
 
24
19
  [source,ruby]
@@ -116,48 +111,15 @@ expg_image:contract_schemaexpg1.xml[]
116
111
  expg_image:contract_schemaexpg2.xml[]
117
112
  ----
118
113
 
114
+ == Git repository
119
115
 
120
- == CVS revision detection
121
-
122
- If the STEPmod repository is a CVS repository, it will display the
123
- working and repository revisions as comments.
124
-
125
- WARNING: CVS revision detection can be *slow*! Be patient.
126
-
127
- Sample output:
128
-
129
- [source,sh]
130
- ----
131
- [stepmod-utils] INFO: STEPmod directory set to ../x/stepmod/.
132
- [stepmod-utils] INFO: STEPmod directory is a CVS repository and will detect revisions.
133
- [stepmod-utils] INFO: [CVS] Detecting file revisions can be slow, please be patient!
134
- [stepmod-utils] INFO: Detecting paths...
135
- [stepmod-utils] INFO: Processing XML file data/business_object_models/managed_model_based_3d_engineering/business_object_model.xml
136
- [stepmod-utils] INFO: Detecting CVS revision...
137
- [stepmod-utils] INFO: CVS working rev (1.148), repo rev (1.148)
138
- [stepmod-utils] INFO: Completed processing XML file data/business_object_models/managed_model_based_3d_engineering/business_object_model.xml
139
- [stepmod-utils] INFO: Processing XML file data/business_object_models/managed_model_based_3d_engineering_domain/business_object_model.xml
140
- [stepmod-utils] INFO: Detecting CVS revision...
141
- [stepmod-utils] INFO: CVS working rev (1.31), repo rev (1.31)
142
- [stepmod-utils] INFO: Completed processing XML file data/business_object_models/managed_model_based_3d_engineering_domain/business_object_model.xml
143
- ...
144
- stepmod/data/business_object_models/managed_model_based_3d_engineering_domain/business_object_model.xml
145
- [stepmod-utils] INFO: written to: 031-generated-terms.adoc
146
- [stepmod-utils] INFO: written to: 991-generated-bibliography.adoc
147
- ----
148
-
149
-
150
- == Non-CVS repository
151
-
152
- If the STEPmod repository is not a CVS repository, or if the `cvs` executable
153
- cannot be found, term extract will still work.
116
+ If the STEPmod repository is a Git repository, term extract will work.
154
117
 
155
118
  Sample output:
156
119
 
157
120
  [source,sh]
158
121
  ----
159
122
  [stepmod-utils] INFO: STEPmod directory set to ../iso-10303-stepmod.
160
- [stepmod-utils] INFO: STEPmod directory is not a CVS repository, skipping revision detection.
161
123
  [stepmod-utils] INFO: Detecting paths...
162
124
  [stepmod-utils] INFO: Processing XML file data/application_protocols/boundary_representation_for_iso_14306_open_jt/application_protocol.xml
163
125
  [stepmod-utils] INFO: skipped ISO/CD 10303-243 as it is not IS, DIS or TS
@@ -27,15 +27,20 @@ files.each_slice(MAX_QUEUE_SIZE) do |batch|
27
27
  batch.each do |file|
28
28
  pool.post do
29
29
  puts("#{Thread.current.object_id}: Queued processing #{file}")
30
- annotated = Stepmod::Utils::StepmodFileAnnotator.new(express_file: file,
31
- resource_docs_cache_file: resource_docs_cache_file, stepmod_dir: stepmod_dir).call
32
- File.open(
33
- File.join(File.dirname(file),
34
- "#{File.basename(file, '.exp')}_annotated.exp"), "w"
35
- ) do |file|
30
+ annotated = Stepmod::Utils::StepmodFileAnnotator.new(
31
+ express_file: file,
32
+ resource_docs_cache_file: resource_docs_cache_file,
33
+ stepmod_dir: stepmod_dir
34
+ ).call
35
+
36
+ annotated_file_name = "#{File.basename(file, '.exp')}_annotated.exp"
37
+ annotated_file_path = File.join(File.dirname(file), annotated_file_name)
38
+
39
+ File.open(annotated_file_path, "w") do |file|
36
40
  file.puts(annotated)
37
41
  end
38
- puts("#{Thread.current.object_id}: Done processing #{file}")
42
+
43
+ puts("#{Thread.current.object_id}: Done processing #{File.basename(file)} => #{annotated_file_path}.")
39
44
  end
40
45
  end
41
46
  pool.shutdown
@@ -20,14 +20,17 @@ end
20
20
 
21
21
  require "bundler/setup"
22
22
  require "stepmod/utils/terms_extractor"
23
-
24
23
  require 'optparse'
25
24
 
25
+ def log(message)
26
+ puts "[stepmod-utils] #{message}"
27
+ end
28
+
26
29
  options = {}
27
30
  OptionParser.new do |opts|
28
31
  opts.banner = "Usage: #{$0} [options]"
29
32
 
30
- opts.on("-p", "--path STEPMOD_DATA_PATH", String, "Path to STEPmod CVS data directory") do |path|
33
+ opts.on("-p", "--path STEPMOD_DATA_PATH", String, "Path to STEPmod data directory") do |path|
31
34
  options[:stepmod_dir] = path
32
35
  end
33
36
 
@@ -103,32 +106,29 @@ def replace_images(content)
103
106
  content
104
107
  end
105
108
 
106
- def log(message)
107
- puts "[stepmod-utils] #{message}"
108
- end
109
-
110
- part_concepts.each do |(bibdata, current_part_concepts)|
111
- current_part_concepts = current_part_concepts.to_a.map do |n|
112
- n.localizations["en"]
113
- end
114
- fn = "03x-stepmod-#{bibdata.part}.adoc"
115
- File.open(fn, "w") do |file|
116
- file.puts("== #{part_to_title(bibdata)}\n\n")
117
- file.puts(replace_images(current_part_concepts.map(&:to_mn_adoc).join("\n")))
118
- end
119
- log "INFO: written to: #{fn}"
120
- end
121
-
122
- File.open("03x-stepmod.adoc", "w") do |file|
123
- part_concepts.sort_by do |(bibdata, current_part_concepts)|
124
- bibdata.part.to_i
125
- end.each do |(bibdata, current_part_concepts)|
126
- fn = "03x-stepmod-#{bibdata.part}.adoc"
127
- file.puts("\ninclude::#{fn}[]\n")
128
- end
129
- end
130
-
131
- log "INFO: written summary file to: 03x-stepmod.adoc"
109
+ ## Skip all Clause 3 terms
110
+ # part_concepts.each do |(bibdata, current_part_concepts)|
111
+ # current_part_concepts = current_part_concepts.to_a.map do |n|
112
+ # n.localizations["en"]
113
+ # end
114
+ # fn = "03x-stepmod-#{bibdata.part}.adoc"
115
+ # File.open(fn, "w") do |file|
116
+ # file.puts("== #{part_to_title(bibdata)}\n\n")
117
+ # file.puts(replace_images(current_part_concepts.map(&:to_mn_adoc).join("\n")))
118
+ # end
119
+ # log "INFO: written to: #{fn}"
120
+ # end
121
+
122
+ # File.open("03x-stepmod.adoc", "w") do |file|
123
+ # part_concepts.sort_by do |(bibdata, current_part_concepts)|
124
+ # bibdata.part.to_i
125
+ # end.each do |(bibdata, current_part_concepts)|
126
+ # fn = "03x-stepmod-#{bibdata.part}.adoc"
127
+ # file.puts("\ninclude::#{fn}[]\n")
128
+ # end
129
+ # end
130
+
131
+ # log "INFO: written summary file to: 03x-stepmod.adoc"
132
132
 
133
133
  part_resources.each do |(bibdata, current_part_resources)|
134
134
  current_part_resources = current_part_resources.to_a.map do |n|
@@ -195,17 +195,18 @@ end
195
195
 
196
196
  log "INFO: written summary file to: 05x-stepmod-entities-modules.adoc"
197
197
 
198
- File.open("031-stepmod-general.adoc", "w") do |file|
199
- file.puts(
200
- replace_images(
201
- general_concepts.to_a.map do |n|
202
- n.localizations["en"]
203
- end.map(&:to_mn_adoc).join("\n")
204
- )
205
- )
206
- end
207
-
208
- log "INFO: written to: 031-stepmod-general.adoc"
198
+ ## Skipping all Clause 3 terms
199
+ # File.open("031-stepmod-general.adoc", "w") do |file|
200
+ # file.puts(
201
+ # replace_images(
202
+ # general_concepts.to_a.map do |n|
203
+ # n.localizations["en"]
204
+ # end.map(&:to_mn_adoc).join("\n")
205
+ # )
206
+ # )
207
+ # end
208
+
209
+ # log "INFO: written to: 031-stepmod-general.adoc"
209
210
 
210
211
  File.open("041-stepmod-entities-resources.adoc", "w") do |file|
211
212
  file.puts(
@@ -23,15 +23,6 @@ module Stepmod
23
23
 
24
24
  return nil if converted_definition.nil? || converted_definition.strip.empty?
25
25
 
26
- if definition_xml.name == "ext_description"
27
- converted_definition = <<~TEXT
28
- #{converted_definition}
29
-
30
- NOTE: This term is incompletely defined in this document.
31
- Reference <<#{reference_anchor}>> for the complete definition.
32
- TEXT
33
- end
34
-
35
26
  # https://github.com/metanorma/stepmod-utils/issues/86
36
27
 
37
28
  # TODO: This portion DOES NOT HANDLE the <synonym> element. WTF??
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class ExpressExample < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ <<~TEMPLATE
9
+ (*"#{state[:schema_and_entity]}.__example"
10
+ #{treat_children(node, state).strip}
11
+ *)
12
+ TEMPLATE
13
+ end
14
+ end
15
+
16
+ ReverseAdoc::Converters.register :express_example, ExpressExample.new
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class ExpressNote < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ <<~TEMPLATE
9
+ (*"#{state[:schema_and_entity]}.__note"
10
+ #{treat_children(node, state).strip}
11
+ *)
12
+ TEMPLATE
13
+ end
14
+ end
15
+
16
+ ReverseAdoc::Converters.register :express_note, ExpressNote.new
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Stepmod
2
+ module Utils
3
+ module Converters
4
+ class ModuleRefExpressDescription < ReverseAdoc::Converters::Base
5
+ def convert(node, _state = {})
6
+ parts = node["linkend"].to_s.split(":").last.split(".")
7
+ "<<express:#{parts.join('.').strip},#{parts.last.strip}>>"
8
+ end
9
+ end
10
+ ReverseAdoc::Converters.register :module_ref,
11
+ ModuleRefExpressDescription.new
12
+ end
13
+ end
14
+ end
@@ -43,18 +43,17 @@ module Stepmod
43
43
 
44
44
  domain = case linkend.first
45
45
  when /_mim$/, /_arm$/
46
- "ISO 10303 application module"
46
+ "application module"
47
47
  # when /_schema$/
48
48
  else
49
- "ISO 10303 resource"
49
+ "resource"
50
50
  end
51
51
 
52
52
  <<~TEMPLATE
53
53
  === #{linkend.last}
54
+ #{domain ? "domain:[#{domain}: #{linkend.first}]" : ''}
54
55
 
55
- #{domain ? "domain:[#{domain}]" : ''}
56
-
57
- #{child_text}
56
+ #{child_text.strip}
58
57
  TEMPLATE
59
58
  end
60
59
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "stepmod/utils/converters/synonym"
4
+ require "stepmod/utils/term"
5
+ require "glossarist"
4
6
 
5
7
  module Stepmod
6
8
  module Utils
@@ -22,22 +24,20 @@ module Stepmod
22
24
  unless first_child &&
23
25
  node.text.split(";").length == 2 &&
24
26
  defined?(Stepmod::Utils::Converters::Synonym)
25
- return "=== #{treat_acronym(treat_children(node, state).strip)}"
27
+
28
+ return Stepmod::Utils::Term.from_h(
29
+ "definition" => treat_children(node, state).strip,
30
+ ).to_mn_adoc
26
31
  end
27
32
 
28
33
  term_def, alt = node.text.split(";")
29
34
  alt_xml = Nokogiri::XML::Text.new(alt, Nokogiri::XML::Document.new)
30
35
  converted_alt = Stepmod::Utils::Converters::Synonym.new.convert(alt_xml)
31
- "=== #{treat_acronym(term_def)}\n\n#{converted_alt}"
32
- end
33
-
34
- private
35
-
36
- def treat_acronym(term_def)
37
- return term_def.strip if term_def !~ /.+\(.+?\)$/
38
36
 
39
- _, term_text, term_acronym = term_def.match(/(.+?)(\(.+\))$/).to_a
40
- "#{term_text.strip}\nalt:[#{term_acronym.gsub(/\(|\)/, '')}]"
37
+ Stepmod::Utils::Term.from_h(
38
+ "definition" => term_def,
39
+ "synonyms" => [converted_alt],
40
+ ).to_mn_adoc
41
41
  end
42
42
  end
43
43
 
@@ -41,7 +41,7 @@ module Stepmod
41
41
  root || (return "")
42
42
 
43
43
  ReverseAdoc.config.with(options) do
44
- result = ReverseAdoc::Converters.lookup(root.name).convert(root)
44
+ result = ReverseAdoc::Converters.lookup(root.name).convert(root, options)
45
45
  Stepmod::Utils::Cleaner.new.tidy(result)
46
46
  end
47
47
  end
@@ -59,7 +59,8 @@ module Stepmod
59
59
  root || (return "")
60
60
 
61
61
  ReverseAdoc.config.with(options) do
62
- result = ReverseAdoc::Converters.lookup(root.name).convert(root)
62
+ result = ReverseAdoc::Converters.lookup(root.name).convert(root, options)
63
+
63
64
  Stepmod::Utils::Cleaner.new.tidy(result)
64
65
  end
65
66
  end
@@ -1,6 +1,8 @@
1
1
  require "json"
2
2
  require "stepmod/utils/smrl_description_converter"
3
3
  require "stepmod/utils/smrl_resource_converter"
4
+ require "stepmod/utils/converters/express_note"
5
+ require "stepmod/utils/converters/express_example"
4
6
 
5
7
  module Stepmod
6
8
  module Utils
@@ -64,7 +66,27 @@ module Stepmod
64
66
  def convert_from_description_text(descriptions_file, description)
65
67
  Dir.chdir(File.dirname(descriptions_file)) do
66
68
  wrapper = "<ext_descriptions>#{description}</ext_descriptions>"
67
- "\n#{Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper)}"
69
+ notes = description.xpath("note")
70
+ examples = description.xpath("example")
71
+
72
+ converted_description = <<~DESCRIPTION
73
+
74
+ #{Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper, no_notes_examples: true)}
75
+ DESCRIPTION
76
+
77
+ converted_examples = examples.map do |example|
78
+ Stepmod::Utils::Converters::ExpressExample
79
+ .new
80
+ .convert(example, schema_and_entity: description["linkend"])
81
+ end.join
82
+
83
+ converted_notes = notes.map do |note|
84
+ Stepmod::Utils::Converters::ExpressNote
85
+ .new
86
+ .convert(note, schema_and_entity: description["linkend"])
87
+ end.join
88
+
89
+ "#{converted_description}#{converted_examples}#{converted_notes}"
68
90
  end
69
91
  end
70
92
 
@@ -77,7 +99,7 @@ module Stepmod
77
99
 
78
100
  Dir.chdir(File.dirname(descriptions_file)) do
79
101
  wrapper = "<resource>#{schema}</resource>"
80
- "\n#{Stepmod::Utils::SmrlResourceConverter.convert(wrapper)}"
102
+ "\n#{Stepmod::Utils::SmrlResourceConverter.convert(wrapper, no_notes_examples: true)}"
81
103
  end
82
104
  end
83
105
  end
@@ -0,0 +1,38 @@
1
+ require "glossarist"
2
+
3
+ module Stepmod
4
+ module Utils
5
+ class Term < Glossarist::LocalizedConcept
6
+ # Term acronym
7
+ attr_accessor :acronym
8
+
9
+ def to_mn_adoc
10
+ mn_adoc = ["=== #{definition}"]
11
+ mn_adoc << "\nalt:[#{acronym}]" if acronym
12
+ mn_adoc << "\n\n#{designations.join(", ")}" if designations&.any?
13
+
14
+ mn_adoc.join
15
+ end
16
+
17
+ class << self
18
+ def from_h(hash)
19
+ _, definition, acronym = treat_acronym(hash["definition"])
20
+
21
+ hash["definition"] = definition
22
+ hash["acronym"] = acronym.gsub(/\(|\)/, "") if acronym
23
+ hash["designations"] = hash["synonyms"]
24
+
25
+ super(hash.reject { |k, _| k == "synonyms" })
26
+ end
27
+
28
+ private
29
+
30
+ def treat_acronym(term_def)
31
+ return [nil, term_def.strip, nil] unless term_def.match?(/.+\(.+?\)$/)
32
+
33
+ term_def.match(/(.+?)(\(.+\))$/).to_a
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -3,6 +3,9 @@ require "stepmod/utils/bibdata"
3
3
  require "stepmod/utils/concept"
4
4
  require "glossarist"
5
5
  require "securerandom"
6
+ require "expressir"
7
+ require "expressir/express/parser"
8
+ require "indefinite_article"
6
9
 
7
10
  ReverseAdoc.config.unknown_tags = :bypass
8
11
 
@@ -20,7 +23,6 @@ module Stepmod
20
23
  :resource_concepts,
21
24
  :parsed_bibliography,
22
25
  :encountered_terms,
23
- :cvs_mode,
24
26
  :part_concepts,
25
27
  :part_resources,
26
28
  :part_modules,
@@ -60,25 +62,7 @@ module Stepmod
60
62
  end
61
63
 
62
64
  def call
63
- # If we are using the stepmod CVS repository, provide the revision number per file
64
- @cvs_mode = if Dir.exists?(stepmod_path.join("CVS"))
65
- require "ptools"
66
- # ptools provides File.which
67
- File.which("cvs")
68
- end
69
-
70
65
  log "INFO: STEPmod directory set to #{stepmod_dir}."
71
-
72
- if cvs_mode
73
- log "INFO: STEPmod directory is a \
74
- CVS repository and will detect revisions."
75
- log "INFO: [CVS] Detecting file revisions can be slow, \
76
- please be patient!"
77
- else
78
- log "INFO: STEPmod directory is not a CVS repository, \
79
- skipping revision detection."
80
- end
81
-
82
66
  log "INFO: Detecting paths..."
83
67
 
84
68
  repo_index = Nokogiri::XML(File.read(@index_path)).root
@@ -161,24 +145,15 @@ module Stepmod
161
145
  next
162
146
  end
163
147
 
164
- revision_string = "\n// CVS: revision not detected"
165
- if cvs_mode
166
- # Run `cvs status` to find out version
167
-
168
- log "INFO: Detecting CVS revision..."
169
- Dir.chdir(stepmod_path) do
170
- status = `cvs status #{fpath}`
171
-
172
- unless status.empty?
173
- working_rev = status.split(/\n/).grep(/Working revision:/)
174
- .first.match(/revision:\s+(.+)$/)[1]
175
- repo_rev = status.split(/\n/).grep(/Repository revision:/)
176
- .first.match(/revision:\t(.+)\t/)[1]
177
- log "INFO: CVS working rev (#{working_rev}), \
178
- repo rev (#{repo_rev})"
179
- revision_string = "\n// CVS working rev: (#{working_rev}), repo rev (#{repo_rev})\n" +
180
- "// CVS: revision #{working_rev == repo_rev ? 'up to date' : 'differs'}"
181
- end
148
+ revision_string = ""
149
+
150
+ # Run `cvs status` to find out version
151
+ log "INFO: Detecting Git SHA..."
152
+ Dir.chdir(stepmod_path) do
153
+ git_sha = `git rev-parse HEAD`
154
+
155
+ unless git_sha.empty?
156
+ revision_string = "\n// Git: SHA #{git_sha}"
182
157
  end
183
158
  end
184
159
 
@@ -226,7 +201,7 @@ module Stepmod
226
201
  case file_path.to_s
227
202
  when /resource.xml$/
228
203
  log "INFO: Processing resource.xml for #{file_path}"
229
- # Assumption: every schema is only linked by a single resource_docs document.
204
+
230
205
  current_document.xpath("//schema").each do |schema_node|
231
206
  schema_name = schema_node["name"]
232
207
  if parsed_schema_names[schema_name]
@@ -238,19 +213,36 @@ module Stepmod
238
213
  parsed_schema_names[schema_name] = file_path
239
214
  end
240
215
 
241
- Dir["#{stepmod_path}/resources/#{schema_name}/descriptions.xml"].each do |description_xml_path|
242
- log "INFO: Processing resources schema #{description_xml_path}"
243
- description_document = Nokogiri::XML(File.read(description_xml_path)).root
244
- description_document.xpath("//ext_description").each do |ext_description|
245
- # log "INFO: Processing linkend[#{ext_description['linkend']}]"
246
-
247
- concept = Stepmod::Utils::Concept.parse(
248
- ext_description,
249
- reference_anchor: bibdata.anchor,
250
- reference_clause: nil,
251
- file_path: Pathname.new(description_xml_path)
216
+ exp_annotated_path =
217
+ "#{stepmod_path}/resources/#{schema_name}/#{schema_name}_annotated.exp"
218
+
219
+ log "INFO: Processing resources schema #{exp_annotated_path}"
220
+
221
+ if File.exists?(exp_annotated_path)
222
+ repo = Expressir::Express::Parser.from_file(exp_annotated_path)
223
+ schema = repo.schemas.first
224
+
225
+ schema.entities.each do |entity|
226
+ old_definition = entity.remarks.first
227
+
228
+ domain = "resource: #{schema.id}"
229
+ entity_definition = generate_entity_definition(entity, domain, old_definition)
230
+
231
+ reference_anchor = bibdata.anchor
232
+ reference_clause = nil
233
+
234
+ concept = Stepmod::Utils::Concept.new(
235
+ designations: [entity.id],
236
+ definition: old_definition,
237
+ converted_definition: entity_definition,
238
+ id: "#{reference_anchor}.#{reference_clause}",
239
+ reference_anchor: reference_anchor,
240
+ reference_clause: reference_clause,
241
+ file_path: Pathname.new(file_path)
252
242
  .relative_path_from(stepmod_path),
243
+ language_code: "en",
253
244
  )
245
+
254
246
  next unless concept
255
247
 
256
248
  if term_special_category(bibdata)
@@ -280,62 +272,89 @@ module Stepmod
280
272
  parsed_schema_names[schema_name] = file_path
281
273
  end
282
274
 
283
- description_xml_path = "#{stepmod_path}/modules/#{schema_name}/arm_descriptions.xml"
284
- log "INFO: Processing modules schema #{description_xml_path}"
285
-
286
- if File.exists?(description_xml_path)
287
- description_document = Nokogiri::XML(
288
- File.read(description_xml_path),
289
- )
290
- .root
291
- description_document.xpath("//ext_description").each do |ext_description|
292
- linkend_schema = ext_description["linkend"].split(".").first
293
- concept = Stepmod::Utils::Concept.parse(
294
- ext_description,
295
- reference_anchor: bibdata.anchor,
296
- reference_clause: nil,
297
- file_path: Pathname.new(description_xml_path)
298
- .relative_path_from(stepmod_path),
299
- )
300
- next unless concept
301
-
302
- current_part_modules_arm[linkend_schema] ||= Glossarist::Collection.new
303
- find_or_initialize_concept(
304
- current_part_modules_arm[linkend_schema], concept
305
- )
306
- # puts part_modules_arm.inspect
307
- parsed_bibliography << bibdata
275
+ exp_annotated_path =
276
+ "#{stepmod_path}/modules/#{schema_name}/arm_annotated.exp"
277
+
278
+ log "INFO: Processing modules schema #{exp_annotated_path}"
279
+
280
+ if File.exists?(exp_annotated_path)
281
+ repo = Expressir::Express::Parser.from_file(exp_annotated_path)
282
+
283
+ repo.schemas.each do |schema|
284
+ schema.entities.each do |entity|
285
+ old_definition = entity.remarks.first
286
+
287
+ domain = "application module: #{schema.id}"
288
+ entity_definition = generate_entity_definition(entity, domain, old_definition)
289
+
290
+ reference_anchor = bibdata.anchor
291
+ reference_clause = nil
292
+
293
+ concept = Stepmod::Utils::Concept.new(
294
+ designations: [entity.id],
295
+ definition: old_definition,
296
+ converted_definition: entity_definition,
297
+ id: "#{reference_anchor}.#{reference_clause}",
298
+ reference_anchor: reference_anchor,
299
+ reference_clause: reference_clause,
300
+ file_path: Pathname.new(file_path)
301
+ .relative_path_from(stepmod_path),
302
+ language_code: "en",
303
+ )
304
+
305
+ next unless concept
306
+
307
+ current_part_modules_arm[schema.id] ||=
308
+ Glossarist::Collection.new
309
+ find_or_initialize_concept(
310
+ current_part_modules_arm[schema.id], concept
311
+ )
312
+
313
+ # puts part_modules_arm.inspect
314
+ parsed_bibliography << bibdata
315
+ end
308
316
  end
309
317
  end
310
318
 
311
- description_xml_path = "#{stepmod_path}/modules/#{schema_name}/mim_descriptions.xml"
312
- log "INFO: Processing modules schema #{description_xml_path}"
313
-
314
- if File.exists?(description_xml_path)
315
- description_document = Nokogiri::XML(
316
- File.read(description_xml_path),
317
- )
318
- .root
319
- description_document.xpath("//ext_description").each do |ext_description|
320
- linkend_schema = ext_description["linkend"].split(".").first
321
-
322
- concept = Stepmod::Utils::Concept.parse(
323
- ext_description,
324
- reference_anchor: bibdata.anchor,
325
- reference_clause: nil,
326
- file_path: Pathname
327
- .new(description_xml_path)
328
- .relative_path_from(stepmod_path),
329
- )
330
- next unless concept
331
-
332
- current_part_modules_mim[linkend_schema] ||=
333
- Glossarist::Collection.new
334
- find_or_initialize_concept(
335
- current_part_modules_mim[linkend_schema], concept
336
- )
337
-
338
- parsed_bibliography << bibdata
319
+ mim_exp_annotated_path = "#{stepmod_path}/modules/#{schema_name}/mim_annotated.exp"
320
+
321
+ log "INFO: Processing modules schema #{mim_exp_annotated_path}"
322
+
323
+ if File.exists?(mim_exp_annotated_path)
324
+ repo = Expressir::Express::Parser.from_file(mim_exp_annotated_path)
325
+
326
+ repo.schemas.each do |schema|
327
+ schema.entities.each do |entity|
328
+ old_definition = entity.remarks.first
329
+
330
+ domain = "application module: #{schema.id}"
331
+ definition = generate_entity_definition(entity, domain, old_definition)
332
+
333
+ reference_anchor = bibdata.anchor
334
+ reference_clause = nil
335
+
336
+ concept = Stepmod::Utils::Concept.new(
337
+ designations: [entity.id],
338
+ definition: old_definition,
339
+ converted_definition: definition,
340
+ id: "#{reference_anchor}.#{reference_clause}",
341
+ reference_anchor: reference_anchor,
342
+ reference_clause: reference_clause,
343
+ file_path: Pathname.new(file_path)
344
+ .relative_path_from(stepmod_path),
345
+ language_code: "en",
346
+ )
347
+
348
+ next unless concept
349
+
350
+ current_part_modules_mim[schema.id] ||=
351
+ Glossarist::Collection.new
352
+ find_or_initialize_concept(
353
+ current_part_modules_mim[schema.id], concept
354
+ )
355
+
356
+ parsed_bibliography << bibdata
357
+ end
339
358
  end
340
359
  end
341
360
 
@@ -371,10 +390,73 @@ module Stepmod
371
390
  end
372
391
 
373
392
  def find_or_initialize_concept(collection, localized_concept)
393
+ concept_id = SecureRandom.uuid
394
+
374
395
  concept = collection
375
- .store(Glossarist::Concept.new(id: SecureRandom.uuid))
396
+ .store(Glossarist::Concept.new(id: concept_id))
376
397
  concept.add_l10n(localized_concept)
377
398
  end
399
+
400
+ # rubocop:disable Layout/LineLength
401
+ def generate_entity_definition(entity, domain, old_definition)
402
+ return "" if entity.nil?
403
+
404
+ entity_text = if entity.subtype_of.size.zero?
405
+ "entity data type that represents " +
406
+ entity.id.indefinite_article + " **#{entity.id}** entity"
407
+ else
408
+ "entity data type that is a type of "+
409
+ "**#{entity.subtype_of.map(&:id).join('** and **')}** that represents " +
410
+ entity.id.indefinite_article + " **#{entity.id}** entity"
411
+ end
412
+
413
+ definition = <<~DEFINITION
414
+ === #{entity.id}
415
+ domain:[#{domain}]
416
+
417
+ #{entity_text}
418
+
419
+ DEFINITION
420
+
421
+ unless old_definition.nil? || old_definition.blank?
422
+ definition << <<~OLD_DEFINITION
423
+ [NOTE]
424
+ --
425
+ #{old_definition&.strip}
426
+ --
427
+ OLD_DEFINITION
428
+ end
429
+
430
+ # We no longer add Notes and Examples to the extracted terms
431
+ # definition + format_remark_items(entity.remark_items)
432
+
433
+ definition
434
+ end
435
+
436
+ def format_remark_items(remark_items)
437
+ notes = remark_items.detect { |i| i.id == "__note" }&.remarks
438
+ examples = remark_items.detect { |i| i.id == "__example" }&.remarks
439
+
440
+ formatted_notes = format_remarks(notes, "NOTE", "--")
441
+ formatted_examples = format_remarks(examples, "example", "====")
442
+
443
+ formatted_notes + formatted_examples
444
+ end
445
+ # rubocop:enable Layout/LineLength
446
+
447
+ def format_remarks(remarks, remark_item_name, remark_item_symbol)
448
+ return "" if remarks.nil?
449
+
450
+ remarks.map do |remark|
451
+ <<~REMARK
452
+
453
+ [#{remark_item_name}]
454
+ #{remark_item_symbol}
455
+ #{remark}
456
+ #{remark_item_symbol}
457
+ REMARK
458
+ end.join
459
+ end
378
460
  end
379
461
  end
380
462
  end
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.3.14".freeze
3
+ VERSION = "0.3.17".freeze
4
4
  end
5
5
  end
@@ -32,7 +32,9 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ["lib"]
33
33
 
34
34
  spec.add_runtime_dependency "concurrent-ruby"
35
+ spec.add_runtime_dependency "expressir"
35
36
  spec.add_runtime_dependency "glossarist", "~> 0.1.0"
37
+ spec.add_runtime_dependency "indefinite_article"
36
38
  spec.add_runtime_dependency "ptools"
37
39
  spec.add_runtime_dependency "reverse_adoc", ">= 0.3.5"
38
40
  spec.add_runtime_dependency "thor", ">= 0.20.3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepmod-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2022-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: expressir
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: glossarist
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: 0.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: indefinite_article
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: ptools
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +206,9 @@ files:
178
206
  - lib/stepmod/utils/converters/em_express_description.rb
179
207
  - lib/stepmod/utils/converters/eqn.rb
180
208
  - lib/stepmod/utils/converters/example.rb
209
+ - lib/stepmod/utils/converters/express_example.rb
181
210
  - lib/stepmod/utils/converters/express_g.rb
211
+ - lib/stepmod/utils/converters/express_note.rb
182
212
  - lib/stepmod/utils/converters/express_ref.rb
183
213
  - lib/stepmod/utils/converters/express_ref_express_description.rb
184
214
  - lib/stepmod/utils/converters/ext_description.rb
@@ -190,6 +220,7 @@ files:
190
220
  - lib/stepmod/utils/converters/ignore.rb
191
221
  - lib/stepmod/utils/converters/introduction.rb
192
222
  - lib/stepmod/utils/converters/module_ref.rb
223
+ - lib/stepmod/utils/converters/module_ref_express_description.rb
193
224
  - lib/stepmod/utils/converters/note.rb
194
225
  - lib/stepmod/utils/converters/ol.rb
195
226
  - lib/stepmod/utils/converters/p.rb
@@ -213,6 +244,7 @@ files:
213
244
  - lib/stepmod/utils/smrl_resource_converter.rb
214
245
  - lib/stepmod/utils/stepmod_definition_converter.rb
215
246
  - lib/stepmod/utils/stepmod_file_annotator.rb
247
+ - lib/stepmod/utils/term.rb
216
248
  - lib/stepmod/utils/terms_extractor.rb
217
249
  - lib/stepmod/utils/version.rb
218
250
  - resource_example.xml
@@ -221,7 +253,7 @@ homepage: https://github.com/metanorma/stepmod-utils
221
253
  licenses:
222
254
  - BSD-2-Clause
223
255
  metadata: {}
224
- post_install_message:
256
+ post_install_message:
225
257
  rdoc_options: []
226
258
  require_paths:
227
259
  - lib
@@ -236,8 +268,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
268
  - !ruby/object:Gem::Version
237
269
  version: '0'
238
270
  requirements: []
239
- rubygems_version: 3.0.3.1
240
- signing_key:
271
+ rubygems_version: 3.3.7
272
+ signing_key:
241
273
  specification_version: 4
242
274
  summary: Stepmod-utils is a toolkit that works on STEPmod data.
243
275
  test_files: []