stepmod-utils 0.3.15 → 0.3.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0fb38c39db845a0b6ff3358d7dea3b0b5f687c50109ee6318438a7787453e5e
4
- data.tar.gz: 7ac3bdf768eeac0805f19fd41703632ed12460c4216b98c5a4b689dc99491033
3
+ metadata.gz: 7d666c11f9282db59fefb04c07c40a88f6167cd214d316f2b1a14ae7117ce898
4
+ data.tar.gz: fe07f66170d74a97a95003b0f5e3594c5f2bbeaa3d431b716ce52f01d13d418d
5
5
  SHA512:
6
- metadata.gz: 799b824cd2eec2efe7d3c5a7972ac21ead6af9b493e13e7ec78a3cfb6417e3576835e5aead8ac07ca264ae3513758cb212259d7ed0e0cb9713acb025393c26e6
7
- data.tar.gz: 2b95f4f76fb19b09695d6cceddce5d854a4843bdfab62d645363b9fa379ad8616c8e1c361802264703c00684b9a3f7242c0aa22b6448ec8cc2e555cea85e797e
6
+ metadata.gz: 7b2fea45d8a30e633e393afac572894481d7de3bf5a33cd19043b6b55cb5b2c948666eb705b4cc9e69a12fe7b43217ca80f8f9a47d7aab4507b1b00c4136476e
7
+ data.tar.gz: 8e5334b99ece0ad5bff37d8ffd7cd70c64fd4998c3e0f4da58825802420f8537493a7858a6158b00ffcfdb3907a532e44067ab4ba07f7cc8f6091b5bb7912517
@@ -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
@@ -30,7 +30,7 @@ options = {}
30
30
  OptionParser.new do |opts|
31
31
  opts.banner = "Usage: #{$0} [options]"
32
32
 
33
- 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|
34
34
  options[:stepmod_dir] = path
35
35
  end
36
36
 
@@ -106,28 +106,29 @@ def replace_images(content)
106
106
  content
107
107
  end
108
108
 
109
- part_concepts.each do |(bibdata, current_part_concepts)|
110
- current_part_concepts = current_part_concepts.to_a.map do |n|
111
- n.localizations["en"]
112
- end
113
- fn = "03x-stepmod-#{bibdata.part}.adoc"
114
- File.open(fn, "w") do |file|
115
- file.puts("== #{part_to_title(bibdata)}\n\n")
116
- file.puts(replace_images(current_part_concepts.map(&:to_mn_adoc).join("\n")))
117
- end
118
- log "INFO: written to: #{fn}"
119
- end
120
-
121
- File.open("03x-stepmod.adoc", "w") do |file|
122
- part_concepts.sort_by do |(bibdata, current_part_concepts)|
123
- bibdata.part.to_i
124
- end.each do |(bibdata, current_part_concepts)|
125
- fn = "03x-stepmod-#{bibdata.part}.adoc"
126
- file.puts("\ninclude::#{fn}[]\n")
127
- end
128
- end
129
-
130
- 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"
131
132
 
132
133
  part_resources.each do |(bibdata, current_part_resources)|
133
134
  current_part_resources = current_part_resources.to_a.map do |n|
@@ -194,17 +195,18 @@ end
194
195
 
195
196
  log "INFO: written summary file to: 05x-stepmod-entities-modules.adoc"
196
197
 
197
- File.open("031-stepmod-general.adoc", "w") do |file|
198
- file.puts(
199
- replace_images(
200
- general_concepts.to_a.map do |n|
201
- n.localizations["en"]
202
- end.map(&:to_mn_adoc).join("\n")
203
- )
204
- )
205
- end
206
-
207
- 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"
208
210
 
209
211
  File.open("041-stepmod-entities-resources.adoc", "w") do |file|
210
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(exp_annotated_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(exp_annotated_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(exp_annotated_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,150 @@ 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
+ def combine_paragraphs(full_paragraph, next_paragraph)
401
+ # If full_paragraph already contains a period, extract that.
402
+ if m = full_paragraph.match(/\A(?<inner_first>[^\n]*?\.)\s/)
403
+ # puts "CONDITION 1"
404
+ if m[:inner_first]
405
+ return m[:inner_first]
406
+ else
407
+ return full_paragraph
408
+ end
409
+ end
410
+
411
+ # If full_paragraph ends with a period, this is the last.
412
+ if full_paragraph =~ /\.\s*\Z/
413
+ # puts "CONDITION 2"
414
+ return full_paragraph
415
+ end
416
+
417
+ # If next_paragraph is a list
418
+ if next_paragraph.match(/\A\*/)
419
+ # puts "CONDITION 3"
420
+ return full_paragraph + "\n\n" + next_paragraph
421
+ end
422
+
423
+ # If next_paragraph is a continuation of a list
424
+ if next_paragraph.match(/\Awhich/) || next_paragraph.match(/\Athat/)
425
+ # puts "CONDITION 4"
426
+ return full_paragraph + "\n\n" + next_paragraph
427
+ end
428
+
429
+ # puts "CONDITION 5"
430
+ full_paragraph
431
+ end
432
+
433
+ def trim_definition(definition)
434
+ # Unless the first paragraph ends with "between" and is followed by a
435
+ # list, don't split
436
+ paragraphs = definition.split("\n\n")
437
+
438
+ # puts paragraphs.inspect
439
+
440
+ first_paragraph = paragraphs.first
441
+
442
+ if paragraphs.length > 1
443
+ combined = paragraphs[1..-1].inject(first_paragraph) do |acc, p|
444
+ combine_paragraphs(acc, p)
445
+ end
446
+ else
447
+ combined = combine_paragraphs(first_paragraph, "")
448
+ end
449
+
450
+ # puts "combined--------- #{combined}"
451
+
452
+ # Remove comments until end of line
453
+ combined = combined + "\n"
454
+ combined.gsub!(/\n\/\/.*?\n/, "\n")
455
+ combined.strip!
456
+
457
+ combined
458
+ # # TODO: If the definition contains a list immediately after the first paragraph, don't split
459
+ # return definition if definition =~ /\n\* /
460
+
461
+ # unless (
462
+ # first_paragraph =~ /between:?\s*\Z/ ||
463
+ # first_paragraph =~ /include:?\s*\Z/ ||
464
+ # first_paragraph =~ /of:?\s*\Z/ ||
465
+ # first_paragraph =~ /[:;]\s*\Z/
466
+ # ) &&
467
+ # definition =~ /\n\n\*/
468
+
469
+ # # Only taking the first paragraph of the definition
470
+ # first_paragraph
471
+ # end
472
+ end
473
+
474
+
475
+ # rubocop:disable Layout/LineLength
476
+ def generate_entity_definition(entity, domain, old_definition)
477
+ return "" if entity.nil?
478
+
479
+ entity_text = if entity.subtype_of.size.zero?
480
+ "entity data type that represents " +
481
+ entity.id.indefinite_article + " **#{entity.id}** entity"
482
+ else
483
+ "entity data type that is a type of "+
484
+ "**#{entity.subtype_of.map(&:id).join('** and **')}** that represents " +
485
+ entity.id.indefinite_article + " **#{entity.id}** entity"
486
+ end
487
+
488
+ definition = <<~DEFINITION
489
+ === #{entity.id}
490
+ domain:[#{domain}]
491
+
492
+ #{entity_text}
493
+
494
+ DEFINITION
495
+
496
+ unless old_definition.nil? || old_definition.blank?
497
+ old_definition = trim_definition(old_definition)
498
+
499
+ definition << <<~OLD_DEFINITION
500
+ [NOTE]
501
+ --
502
+ #{old_definition.strip}
503
+ --
504
+ OLD_DEFINITION
505
+ end
506
+
507
+ # We no longer add Notes and Examples to the extracted terms
508
+ # definition + format_remark_items(entity.remark_items)
509
+
510
+ definition
511
+ end
512
+
513
+ def format_remark_items(remark_items)
514
+ notes = remark_items.detect { |i| i.id == "__note" }&.remarks
515
+ examples = remark_items.detect { |i| i.id == "__example" }&.remarks
516
+
517
+ formatted_notes = format_remarks(notes, "NOTE", "--")
518
+ formatted_examples = format_remarks(examples, "example", "====")
519
+
520
+ formatted_notes + formatted_examples
521
+ end
522
+ # rubocop:enable Layout/LineLength
523
+
524
+ def format_remarks(remarks, remark_item_name, remark_item_symbol)
525
+ return "" if remarks.nil?
526
+
527
+ remarks.map do |remark|
528
+ <<~REMARK
529
+
530
+ [#{remark_item_name}]
531
+ #{remark_item_symbol}
532
+ #{remark}
533
+ #{remark_item_symbol}
534
+ REMARK
535
+ end.join
536
+ end
378
537
  end
379
538
  end
380
539
  end
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.3.15".freeze
3
+ VERSION = "0.3.18".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.15
4
+ version: 0.3.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2022-09-08 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
@@ -236,7 +268,7 @@ 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
271
+ rubygems_version: 3.1.6
240
272
  signing_key:
241
273
  specification_version: 4
242
274
  summary: Stepmod-utils is a toolkit that works on STEPmod data.