stepmod-utils 0.1.0 → 0.1.5

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: d46a471013b96ac232688535ff7384c7044d166987ae53dd2e1fefd0009a73fb
4
- data.tar.gz: 39a320ba1cd3b7d05fcb34f17077d12ac036b1de3ed0db730af214f0127ceea0
3
+ metadata.gz: 46b71314210eb0f813efd1fe7862b3e5bc061133e2cfe7f32df95a77e5f4e290
4
+ data.tar.gz: c6fffa6edd1e0565127f2da4872c624bd2c501be27afabd456b50379a5904a05
5
5
  SHA512:
6
- metadata.gz: 723e010d940375916081ed59592c413219f5b0fce10df237bf6504a8be5a40c7405a8b057ec8fe692f2307fcddaecf763cb23dd1a152d1ed1a7e07087e0f49a0
7
- data.tar.gz: ada92ea7ec12cbe80509a6f9d5a45d354211b9f9aa5a5f18e5dc2e86de58569a63572d65937ccba26917931a7315c016fa4bdd8f660602d46085cb190b1cd61b
6
+ metadata.gz: 7fb0a8b89aed9d4db7c1aaa2e0d7f8881b0b5c0869019f287d6d50f472795356830d7b4f3751c163adc59db3ac5ec567516f92ebfa029fa29f85eb05b42671c4
7
+ data.tar.gz: f2b1717966c60aa636bd79e90df18c28b1a1829c7277ece5adb19180a63c01842756497b6004ff38b48350bc5b7c704117c7ecd7e12b4ad07e9755add899fdb5
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- # Specify your gem's dependencies in stepmod-utils.gemspec
4
5
  gemspec
6
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
7
 
6
8
  gem "rake", "~> 12.0"
7
9
  gem "rspec", "~> 3.0"
@@ -10,11 +10,7 @@ image:https://img.shields.io/github/commits-since/metanorma/stepmod-utils/latest
10
10
 
11
11
  == Purpose
12
12
 
13
- The stepmod-utils Ruby gem is a wrapper around the Java https://github.com/metanorma/stepmod-utils[stepmod-utils]
14
- which converts NISO STS and ISOSTS into Metanorma XML and AsciiDoc files.
15
-
16
- This gem is used to provide stepmod-utils.jar with mirrored version numbers, to allow
17
- Ruby code to easily refer to the desired stepmod-utils version as dependencies.
13
+ The stepmod-utils Ruby gem provides a number of tools to work with the STEPmod repository/
18
14
 
19
15
  == Installation
20
16
 
@@ -27,34 +23,18 @@ Or include it in your gemspec.
27
23
 
28
24
  == Usage
29
25
 
30
- [source,ruby]
26
+ [source,sh]
31
27
  ----
32
- require 'stepmod-utils'
33
- Sts2mn.convert(input: 'test/sts.xml')
34
- # => generates 'test/sts.adoc', in Metanorma AsciiDoc
35
-
36
- Sts2mn.convert(input: 'test/sts.xml', output: 'another/path/mn.xml', format: 'xml')
37
- # => generates 'another/path/mn.xml' in Metanorma XML
28
+ # Extracts from current directory
29
+ $ stepmod-extract-terms
38
30
 
39
- Sts2mn.convert(input: 'test/sts.xml', output: 'another/path/mn.adoc', format: 'adoc')
40
- # => generates 'another/path/mn.adoc' in Metanorma AsciiDoc
41
-
42
- Sts2mn.split_bibdata('test/sts.xml')
43
- # => generates 'test/sts.rxl' (Relaton XML) and 'test/mn.adoc' (Metanorma AsciiDoc)
31
+ # Extracts from specified stepmod/ or stepmod/data/ directory
32
+ $ stepmod-extract-terms {stepmod-data-directory}
44
33
  ----
45
34
 
46
- == Updating the gem
47
-
48
- Update `lib/stepmod-utils/version.rb` to the desired version of https://github.com/metanorma/stepmod-utils[stepmod-utils].
49
-
50
- Run `rake` to download the `bin/stepmod-utils.jar` file:
51
-
52
- [source,ruby]
53
- ----
54
- rm -f bin/stepmod-utils.jar
55
- rake bin/stepmod-utils.jar
56
- ----
35
+ Then these files will be created:
57
36
 
58
- Then release the gem with `rake release`.
37
+ * `031-generated-terms.adoc` all terms extracted
38
+ * `991-generated-bibliography.adoc` all bibliographic sources where the terms come from
59
39
 
60
40
 
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #!/usr/bin/env ruby
4
+ # encoding: UTF-8
5
+
6
+ # resolve bin path, ignoring symlinks
7
+ require "pathname"
8
+ bin_file = Pathname.new(__FILE__).realpath
9
+
10
+ # add self to libpath
11
+ $:.unshift File.expand_path("../../lib", bin_file)
12
+
13
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
14
+ require "rubygems/specification"
15
+
16
+ class Gem::Specification
17
+ def this; self; end
18
+ end
19
+
20
+ require 'bundler/setup'
21
+ require 'stepmod/utils/stepmod_definition_converter'
22
+ require 'stepmod/utils/bibdata'
23
+ require 'stepmod/utils/concept'
24
+
25
+ ReverseAsciidoctor.config.unknown_tags = :bypass
26
+
27
+ parsed_terms = []
28
+ parsed_bibliography = []
29
+ encountered_terms = {}
30
+
31
+ stepmod_dir = ARGV.first || Dir.pwd
32
+
33
+ def log message
34
+ puts "[stepmod-utils] #{message}"
35
+ end
36
+
37
+ log "STEPmod directory set to #{stepmod_dir}. Detecting paths..."
38
+
39
+ files = %w(
40
+ resource.xml
41
+ application_protocol.xml
42
+ business_object_model.xml
43
+ module.xml
44
+ ).inject([]) do |acc, t|
45
+ acc << Dir["#{stepmod_dir}/**/#{t}"]
46
+ end.flatten.sort.uniq
47
+
48
+ files.each do |file_path|
49
+ log "Processing XML file #{file_path}"
50
+ current_document = Nokogiri::XML(File.read(file_path)).root
51
+
52
+ bibdata = nil
53
+ begin
54
+ bibdata = Stepmod::Utils::Bibdata.new(document: current_document)
55
+ rescue
56
+ log "WARNING: Unknown file #{file_path}, skipped"
57
+ next
58
+ end
59
+
60
+ if bibdata.part.to_s.empty?
61
+ log "FATAL: missing `part` attribute: #{file_path}"
62
+ end
63
+
64
+ # read definitions
65
+ current_document.xpath('//definition').each.with_index(1) do |definition, index|
66
+
67
+ term_id = definition['id']
68
+ unless term_id.nil?
69
+ if encountered_terms[term_id]
70
+ log "FATAL: Duplicated term with id: #{term_id}, #{file_path}"
71
+ end
72
+ encountered_terms[term_id] = true
73
+ end
74
+
75
+ concept = Stepmod::Utils::Concept.parse(
76
+ definition,
77
+ reference_anchor: bibdata.anchor,
78
+ # Assume that definition is located in clause 3 of the ISO document
79
+ # in order. We really don't have a good reference here.
80
+ reference_clause: "3.#{index}"
81
+ )
82
+
83
+ parsed_terms << concept
84
+ parsed_bibliography << bibdata
85
+ end
86
+
87
+ end
88
+
89
+ parsed_bibliography.uniq!
90
+
91
+ File.open('031-generated-terms.adoc', 'w') { |file|
92
+ file.puts(parsed_terms.map(&:to_mn_adoc).join("\n"))
93
+ }
94
+
95
+ log "written to: 031-generated-terms.adoc"
96
+
97
+ File.open('991-generated-bibliography.adoc', 'w') { |file|
98
+ file.puts(parsed_bibliography.map(&:to_mn_adoc).join("\n"))
99
+ }
100
+
101
+ log "written to: 991-generated-bibliography.adoc"
@@ -0,0 +1,122 @@
1
+ module Stepmod
2
+ module Utils
3
+
4
+ class Bibdata
5
+
6
+ DOCNUMBER = 10303
7
+
8
+ attr_accessor *%w(
9
+ type doctype part title_en title_fr version language pub_year pub_date
10
+ )
11
+
12
+ def initialize(document:)
13
+ return nil unless document.is_a?(Nokogiri::XML::Element)
14
+
15
+ # module, resource, application_protocol, business_object_model
16
+ @type = document.name
17
+
18
+ raise 'UnknownFileError' unless %w(module resource application_protocol business_object_model).include?(@type)
19
+
20
+ @doctype = document['status']
21
+ @part = document['part']
22
+ @title_en = document['title'] ||
23
+ document['name'].gsub('_', ' ').capitalize.gsub('2d','2D').gsub('3d','3D')
24
+ @title_fr = document['name.french']
25
+ @version = document['version']
26
+ @language = document['language']
27
+
28
+ # Some publication.year contains month...
29
+ @pub_year = document['publication.year'].split('-').first
30
+ @pub_date = document['publication.date']
31
+
32
+ # puts to_mn_adoc
33
+
34
+ return self
35
+ # <module
36
+ # name="security_classification"
37
+ # name.french="Classification des s&#233;curit&#233;s"
38
+ # part="1015"
39
+ # wg.number="1095"
40
+ # wg.number.supersedes="720"
41
+ # wg.number.arm.supersedes="1096"
42
+ # wg.number.arm="3221"
43
+ # wg.number.mim="1097"
44
+ # checklist.internal_review="2133"
45
+ # checklist.project_leader="2134"
46
+ # checklist.convener="2135"
47
+ # version="1"
48
+ # status="TS"
49
+ # language="E"
50
+ # publication.year="2004"
51
+ # publication.date="2004-12-01"
52
+ # published="y"
53
+ # rcs.date="$Date: 2009/11/02 10:59:35 $"
54
+ # rcs.revision="$Revision: 1.26 $"
55
+ # development.folder="dvlp"
56
+ # >
57
+
58
+ end
59
+
60
+ def docid
61
+ no_date = case doctype
62
+ when "IS"
63
+ "ISO #{DOCNUMBER}-#{part}"
64
+ when "WD"
65
+ "ISO/WD #{DOCNUMBER}-#{part}"
66
+ when "CD"
67
+ "ISO/CD #{DOCNUMBER}-#{part}"
68
+ when "DIS"
69
+ "ISO/DIS #{DOCNUMBER}-#{part}"
70
+ when "TS"
71
+ "ISO/TS #{DOCNUMBER}-#{part}"
72
+ when "CD-TS"
73
+ "ISO/CD TS #{DOCNUMBER}-#{part}"
74
+ else
75
+ "UNKNOWN DOCTYPE: (#{doctype})"
76
+ end
77
+
78
+ if pub_year
79
+ "#{no_date}:#{pub_year}"
80
+ else
81
+ no_date
82
+ end
83
+ end
84
+
85
+ def part_title
86
+ case part
87
+ when [200..299]
88
+ "Application protocol: #{title_en}"
89
+ when [300..399]
90
+ "Abstract test suite: #{title_en}"
91
+ when [400..499]
92
+ "Application module: #{title_en}"
93
+ when [500..599]
94
+ "Application interpreted construct: #{title_en}"
95
+ when [1000..1799]
96
+ "Application module: #{title_en}"
97
+ else
98
+ title_en
99
+ end
100
+ end
101
+
102
+ def full_title
103
+ "Industrial automation systems and integration -- Product data representation and exchange -- Part #{part}: #{part_title}"
104
+ end
105
+
106
+ def anchor
107
+ docid.gsub('/', '-').gsub(' ', '_').gsub(':', '_')
108
+ end
109
+
110
+ def to_mn_adoc
111
+ if title_en
112
+ "* [[[#{anchor},#{docid}]]], _#{full_title}_"
113
+ else
114
+ "* [[[#{anchor},#{docid}]]]"
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+ end
122
+
@@ -0,0 +1,32 @@
1
+ module Stepmod
2
+ module Utils
3
+
4
+ class Concept
5
+ attr_accessor *%w(designation definition reference_anchor reference_clause examples notes synonym converted_definition)
6
+
7
+ def initialize(options)
8
+ options.each_pair do |k, v|
9
+ send("#{k}=", v)
10
+ end
11
+ end
12
+
13
+ def self.parse(definition_xml, reference_anchor:, reference_clause:)
14
+ new(
15
+ converted_definition: Stepmod::Utils::StepmodDefinitionConverter.convert(definition_xml),
16
+ reference_anchor: reference_anchor,
17
+ reference_clause: reference_clause
18
+ )
19
+ end
20
+
21
+ def to_mn_adoc
22
+ <<~TEXT
23
+ #{converted_definition}
24
+
25
+ [.source]
26
+ <<#{reference_anchor},clause=#{reference_clause}>>
27
+ TEXT
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class ClauseRef < ReverseAsciidoctor::Converters::Base
7
+ def convert(node, _state = {})
8
+ " term:[#{normalized_ref(node['linkend'])}] "
9
+ end
10
+
11
+ private
12
+
13
+ def normalized_ref(ref)
14
+ return unless ref || ref.empty?
15
+
16
+ ref.to_s.split(':').last.squeeze(' ').strip
17
+ end
18
+ end
19
+ ReverseAsciidoctor::Converters.register :clause_ref, ClauseRef.new
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,69 @@
1
+
2
+ module Stepmod
3
+ module Utils
4
+ module Converters
5
+ class Def < ReverseAsciidoctor::Converters::Base
6
+ def convert(node, state = {})
7
+ node = node.dup
8
+ "#{additional_block(node)}#{treat_children(node, state)}"
9
+ end
10
+
11
+ private
12
+
13
+ def treat_children(node, state)
14
+ converted = node.children.each_with_object({}) do |child, res|
15
+ content = treat(child, state).strip
16
+ next if content.empty?
17
+
18
+ res[child] = content
19
+ end
20
+ previous = nil
21
+ result = ''
22
+ converted.each.with_index do |(child, content), i|
23
+ if i == 0 || !block_tag?(child, previous)
24
+ result += " #{content}"
25
+ else
26
+ result += "\n\n#{content}"
27
+ end
28
+ previous = child
29
+ end
30
+ result.strip
31
+ end
32
+
33
+ def block_tag?(child, previous)
34
+ %w[ul example note alt p].include?(child.name) ||
35
+ (child.previous && %w[ul example note alt p].include?(child.previous.name))
36
+ end
37
+
38
+ def additional_block(node)
39
+ # Treat first `p` tag as an `alt` block, metanorma/stepmod-utils#9
40
+ first_child_tag = node
41
+ .children
42
+ .find { |n| n.is_a?(Nokogiri::XML::Element) }
43
+ return unless can_transform_to_alt?(first_child_tag)
44
+
45
+ result = Stepmod::Utils::Converters::Synonym
46
+ .new
47
+ .convert(first_child_tag)
48
+ first_child_tag.remove
49
+ "#{result}\n\n"
50
+ end
51
+
52
+ # metanorma/stepmod-utils#18 when para is the only text doe snot transform it
53
+ def can_transform_to_alt?(first_child_tag)
54
+ return false unless first_child_tag&.name == 'p' &&
55
+ defined?(Stepmod::Utils::Converters::Synonym)
56
+
57
+ next_sibling = first_child_tag.next
58
+ while next_sibling
59
+ return true if !next_sibling.text.to_s.strip.empty? && %w[p text].include?(next_sibling.name)
60
+ next_sibling = next_sibling.next
61
+ end
62
+ false
63
+ end
64
+ end
65
+
66
+ ReverseAsciidoctor::Converters.register :def, Def.new
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Definition < ReverseAsciidoctor::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
+ ReverseAsciidoctor::Converters.register :definition, Definition.new
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Em < ReverseAsciidoctor::Converters::Base
7
+ def convert(node, state = {})
8
+ content = treat_children(node, state.merge(already_italic: true))
9
+ if content.strip.empty? || state[:already_italic]
10
+ content
11
+ else
12
+ "#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}"
13
+ end
14
+ end
15
+ end
16
+
17
+ ReverseAsciidoctor::Converters.register :em, Em.new
18
+ ReverseAsciidoctor::Converters.register :cite, Em.new
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Example < ReverseAsciidoctor::Converters::Base
7
+ def convert(node, state = {})
8
+ <<~TEMPLATE
9
+ [example]
10
+ ====
11
+ #{treat_children(node, state).strip}
12
+ ====
13
+ TEMPLATE
14
+ end
15
+ end
16
+ ReverseAsciidoctor::Converters.register :example, Example.new
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class ExpressRef < ReverseAsciidoctor::Converters::Base
7
+ def convert(node, _state = {})
8
+ "*#{node['linkend'].to_s.split('.').last}*"
9
+ end
10
+ end
11
+ ReverseAsciidoctor::Converters.register :express_ref, ExpressRef.new
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class ModuleRef < ReverseAsciidoctor::Converters::Base
7
+ def convert(node, _state = {})
8
+ ref = node['linkend']
9
+ # #23:
10
+ # In this case when we see this:
11
+
12
+ # <module_ref linkend="product_as_individual:3_definition">individual products</module_ref>
13
+ # We take the text value of the element and convert to this:
14
+
15
+ # term:[individual products]
16
+ if node['linkend'].split(':').length > 1
17
+ ref = node.text
18
+ end
19
+ " term:[#{normalized_ref(ref)}] "
20
+ end
21
+
22
+ private
23
+
24
+ def normalized_ref(ref)
25
+ return unless ref || ref.empty?
26
+
27
+ ref.squeeze(' ').strip
28
+ end
29
+ end
30
+ ReverseAsciidoctor::Converters.register :module_ref, ModuleRef.new
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Note < ReverseAsciidoctor::Converters::Base
7
+ def convert(node, state = {})
8
+ <<~TEMPLATE
9
+ [NOTE]
10
+ --
11
+ #{treat_children(node, state).strip}
12
+ --
13
+ TEMPLATE
14
+ end
15
+ end
16
+ ReverseAsciidoctor::Converters.register :note, Note.new
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Ol < ReverseAsciidoctor::Converters::Base
7
+ def convert(node, state = {})
8
+ id = node['id']
9
+ anchor = id ? "[[#{id}]]\n" : ""
10
+ ol_count = state.fetch(:ol_count, 0) + 1
11
+ attrs = ol_attrs(node)
12
+ res = "\n#{anchor}#{attrs}#{treat_children(node, state.merge(ol_count: ol_count))}"
13
+ res = "\n" + res if node.parent && node.parent.name == 'note'
14
+ res
15
+ end
16
+
17
+ def number_style(node)
18
+ style = case node["style"]
19
+ when "1" then "arabic"
20
+ when "A" then "upperalpha"
21
+ when "a" then "loweralpha"
22
+ when "I" then "upperroman"
23
+ when "i" then "lowerroman"
24
+ else
25
+ nil
26
+ end
27
+ end
28
+
29
+ def ol_attrs(node)
30
+ style = number_style(node)
31
+ reversed = "%reversed" if node["reversed"]
32
+ start = "start=#{node['start']}" if node["start"]
33
+ type = "type=#{node['type']}" if node["type"]
34
+ attrs = []
35
+ attrs << style if style
36
+ attrs << reversed if reversed
37
+ attrs << start if start
38
+ attrs << type if type
39
+ if attrs.empty?
40
+ ""
41
+ else
42
+ "[#{attrs.join(',')}]\n"
43
+ end
44
+ end
45
+ end
46
+
47
+ ReverseAsciidoctor::Converters.register :ol, Ol.new
48
+ ReverseAsciidoctor::Converters.register :ul, Ol.new
49
+ ReverseAsciidoctor::Converters.register :dir, Ol.new
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stepmod/utils/converters/em'
4
+
5
+ module Stepmod
6
+ module Utils
7
+ module Converters
8
+ class Stem < ReverseAsciidoctor::Converters::Base
9
+ def convert(node, state = {})
10
+ return Em.new.convert(node, state) if node.text.strip.length > 8
11
+
12
+ " stem:[#{node.text.strip}] "
13
+ end
14
+ end
15
+
16
+ ReverseAsciidoctor::Converters.register :i, Stem.new
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Synonym < ReverseAsciidoctor::Converters::Base
7
+ def convert(node, state = {})
8
+ "alt:[#{node.text.strip}]"
9
+ end
10
+ end
11
+
12
+ ReverseAsciidoctor::Converters.register :synonym, Synonym.new
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stepmod/utils/converters/synonym'
4
+
5
+ module Stepmod
6
+ module Utils
7
+ module Converters
8
+ class Term < ReverseAsciidoctor::Converters::Base
9
+ def convert(node, state = {})
10
+ first_child = node.children.find do |child|
11
+ child.name == 'text' && !child.text.to_s.strip.empty?
12
+ end
13
+ unless first_child &&
14
+ node.text.split(';').length == 2 &&
15
+ defined?(Stepmod::Utils::Converters::Synonym)
16
+ return "=== #{treat_children(node, state).strip}"
17
+ end
18
+
19
+ term_def, alt = node.text.split(';')
20
+ alt_xml = Nokogiri::XML::Text.new(alt, Nokogiri::XML::Document.new)
21
+ converted_alt = Stepmod::Utils::Converters::Synonym.new.convert(alt_xml)
22
+ "=== #{term_def}\n\n#{converted_alt}"
23
+ end
24
+ end
25
+
26
+ ReverseAsciidoctor::Converters.register :term, Term.new
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'reverse_asciidoctor'
4
+ require 'stepmod/utils/converters/clause_ref'
5
+ require 'stepmod/utils/converters/express_ref'
6
+ require 'stepmod/utils/converters/module_ref'
7
+ require 'stepmod/utils/converters/def'
8
+ require 'stepmod/utils/converters/definition'
9
+ require 'stepmod/utils/converters/em'
10
+ require 'stepmod/utils/converters/example'
11
+ require 'stepmod/utils/converters/note'
12
+ require 'stepmod/utils/converters/ol'
13
+ require 'stepmod/utils/converters/stem'
14
+ require 'stepmod/utils/converters/term'
15
+ require 'stepmod/utils/converters/synonym'
16
+
17
+ require 'reverse_asciidoctor/converters/a'
18
+ require 'reverse_asciidoctor/converters/blockquote'
19
+ require 'reverse_asciidoctor/converters/bypass'
20
+ require 'reverse_asciidoctor/converters/br'
21
+ require 'reverse_asciidoctor/converters/code'
22
+ require 'reverse_asciidoctor/converters/drop'
23
+ require 'reverse_asciidoctor/converters/head'
24
+ require 'reverse_asciidoctor/converters/hr'
25
+ require 'reverse_asciidoctor/converters/ignore'
26
+ require 'reverse_asciidoctor/converters/li'
27
+ require 'reverse_asciidoctor/converters/p'
28
+ require 'reverse_asciidoctor/converters/pass_through'
29
+ require 'reverse_asciidoctor/converters/q'
30
+ require 'reverse_asciidoctor/converters/strong'
31
+ require 'reverse_asciidoctor/converters/sup'
32
+ require 'reverse_asciidoctor/converters/sub'
33
+ require 'reverse_asciidoctor/converters/text'
34
+
35
+
36
+ module Stepmod
37
+ module Utils
38
+ class StepmodDefinitionConverter
39
+ def self.convert(input, options = {})
40
+ root = if input.is_a?(String)
41
+ then Nokogiri::XML(input).root
42
+ elsif input.is_a?(Nokogiri::XML::Document)
43
+ then input.root
44
+ elsif input.is_a?(Nokogiri::XML::Node)
45
+ then input
46
+ end
47
+
48
+ root || (return '')
49
+
50
+ ReverseAsciidoctor.config.with(options) do
51
+ result = ReverseAsciidoctor::Converters.lookup(root.name).convert(root)
52
+ ReverseAsciidoctor.cleaner.tidy(result)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
@@ -0,0 +1,302 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- $Id: resource.xml,v 1.22 2009/11/02 11:00:33 lothartklein Exp $ -->
3
+ <!DOCTYPE resource SYSTEM "../../../dtd/res_doc/resource.dtd">
4
+ <!-- Generated by mkresource.js, Eurostep Limited, http://www.eurostep.com -->
5
+ <!--
6
+ To view the resource in IExplorer, open: sys/1_scope.xml
7
+ -->
8
+ <resource
9
+ name="classification_and_set_theory"
10
+ name.french="Classification et théorie des ensembles"
11
+ part="54"
12
+ version="1"
13
+ wg.number="3212"
14
+ wg.number.supersedes="1509"
15
+ wg.number.express="3213"
16
+ wg.number.express.supersedes="1510"
17
+ checklist.internal_review="3215"
18
+ checklist.project_leader="3216"
19
+ checklist.convener="3217"
20
+ sc4.working_group="12"
21
+ status="IS"
22
+ language="E"
23
+ publication.date="2005-03-15"
24
+ publication.year="2005"
25
+ published="n"
26
+ development.folder="dvlp"
27
+ rcs.date="$Date: 2009/11/02 11:00:33 $"
28
+ rcs.revision="$Revision: 1.22 $">
29
+
30
+ <keywords>
31
+ resource, STEP, 10303, integrated resources, set theory, class, classification, specialisation, subset, superset,
32
+ union, intersection, complement power set
33
+ </keywords>
34
+ <!-- the abstract for the resource. If not provided, the XSL will use the inscope -->
35
+ <abstract>
36
+ <p>ISO 10303-54 specifies:</p>
37
+ <ul>
38
+ <li>that an object is a member of a set, and can define a finite set by enumerating all its members;</li>
39
+ <li>that the relationship between two sets is proper subset, subset, or equal;</li>
40
+ <li>that a set is result of a union, intersection, complement or powerset operation.</li>
41
+ </ul>
42
+ </abstract>
43
+ <!-- the abstract for the resource. If not provided, the XSL will use the in scope
44
+ <abstract>
45
+ <li>a specification that an object is a member of a set;</li>
46
+ <li>a specification of all the members of a finite set;</li>
47
+ <li>a specification that one set is a proper subset of, is a
48
+ subset of, or is equal to another;</li>
49
+ <li>a specification that a set is result of a union,
50
+ intersection, complement or powerset operation.</li>
51
+ </abstract>
52
+ -->
53
+ <!-- Reference to contacts detailed in stepmod/data/basic/contacts.xml -->
54
+ <contacts>
55
+ <projlead ref="ap221.projlead" />
56
+ <editor ref="ap221.projeditor" />
57
+ </contacts>
58
+
59
+ <!-- Introduction -->
60
+ <!-- The introduction should start as shown: -->
61
+ <purpose>
62
+ <p>
63
+ This part of ISO 10303 specifies an application resource for the
64
+ representation of classes or sets and classification relationships. This part of ISO 10303 also supports the
65
+ following set theory relationships:</p>
66
+ <ul>
67
+ <li>complement;</li>
68
+ <li>intersection;</li>
69
+ <li>power set;</li>
70
+ <li>proper subset;</li>
71
+ <li>same membership (that is, set equality);</li>
72
+ <li>subset;</li>
73
+ <li>union.</li>
74
+ </ul>
75
+ </purpose>
76
+
77
+ <!-- Schema Interface express-g diagrams -->
78
+ <!-- refer to p41ed2 as example -->
79
+ <schema_diag>
80
+ <express-g>
81
+ <imgfile title="Relationship between schemas in ISO 10303-54" file="schema_diagexpg1.xml" />
82
+ </express-g>
83
+ </schema_diag>
84
+
85
+ <!-- Items in scope -->
86
+ <inscope>
87
+ <li>the existence of a class or set;</li>
88
+ <li>the distinction between a class or set that is defined by abstract criteria, and a class or set that is defined
89
+ by enumerating its members;</li>
90
+
91
+
92
+ <li>the classification relationship between a class or set and a member;</li>
93
+
94
+ <li>the complete enumeration of the members for a class or set;</li>
95
+ <li> the representation of set theory relationships between classes or sets;</li>
96
+
97
+ <li>the following set theory relationships:
98
+ <ul>
99
+ <li>complement;</li>
100
+ <li>equivalence;</li>
101
+ <li>intersection;</li>
102
+ <li>power set;</li>
103
+ <li>proper subset;</li>
104
+ <li>subset;</li>
105
+ <li>union.</li>
106
+ </ul>
107
+ </li>
108
+ </inscope>
109
+
110
+ <!-- Items out of scope -->
111
+ <outscope>
112
+ <li>mappings between sets or classes;</li>
113
+ <li>relationships that are not classification or set theory relationships; </li>
114
+ <li>entities and relationships specific to continuous sets.
115
+ <note number="1">
116
+ <p>All the entities and relationships within this part of ISO 10303 are equally valid for discrete and
117
+ continuous sets.</p>
118
+ </note>
119
+ <note number="2">
120
+ <p>Entities and relationships for continuous sets can be created in anntotated EXPRESS schemas that use or
121
+ specialize entities in this part of ISO 10303, as follows:</p>
122
+ <ul>
123
+ <li><b>discrete_class_by_intension</b> and <b>continuous_set</b> can be disjoint subtypes of
124
+ <express_ref linkend="classification_and_set_theory:ir:classification_schema.class_by_intension" />;</li>
125
+ <li><b>open_set</b> and <b>closed_set</b> can be disjoint subtypes of <b>continuous_set</b>;</li>
126
+ <li><b>closure</b> can be the relationship between an <b>open_set</b> and the <b>closed_set</b> that is its
127
+ <b>boundary</b>.</li>
128
+ </ul>
129
+ </note>
130
+ </li>
131
+ </outscope>
132
+
133
+ <normrefs>
134
+ <normref.inc normref="ref10303-41" />
135
+ </normrefs>
136
+
137
+ <definition>
138
+ <term id="set">set
139
+ </term>
140
+ <synonym>class</synonym>
141
+ <def>
142
+ <p>number of things considered together</p>
143
+ <note number="1"> A set that is defined by enumerating its members is a 'class by intension'.</note>
144
+ <note number="2">A set that is defined by means of criteria that do not enumerate the members is a 'class by
145
+ extension'.</note>
146
+ </def>
147
+ </definition>
148
+ <!--
149
+ <abbreviations/>
150
+ -->
151
+
152
+ <schema name="classification_schema" version="1">
153
+ <!-- Note schema EXPRESS are in ..\resources\resource_name name_of_schema.xml -->
154
+ <introduction>The classification_schema specifies a class, and a classification relationship between a class and a
155
+ member of a class.
156
+ </introduction>
157
+ <fund_cons>
158
+ <p>For many different entity types defined within ISO 10303, an instance may stand for a class or set of things.
159
+ The fact that an instance stands for a class or set of things can be made explicit by creating a compound
160
+ instance of:</p>
161
+ <ul>
162
+ <li>the entity type class defined in this part of ISO 10303, and</li>
163
+ <li>
164
+ another entity type defined in ISO 10303. </li>
165
+ </ul>
166
+ <p>Members can be specified for an instance of the entity type class. An instance of the entity type class can be
167
+ involved in set theory relationships, such as union or intersection, with other instances of the entity type
168
+ class.</p>
169
+ <note>Instances of the entity types product, product_definition_formation and product_definition in ISO 10303-41
170
+ can be classes. In order to allow set theory relationships for these classes, an application protocol or
171
+ application module can define a subtype of:</note>
172
+ <ul>
173
+ <li>product_definition_formation (from ISO 10303-41);</li>
174
+ <li>class (from this part of ISO 10303).</li>
175
+ </ul>
176
+ <example number="1">
177
+ Pump model 'XYZ_123' is a product_definition_formation and a class. This class is a class_by_extension.
178
+ </example>
179
+
180
+ <example number="2">The set of pumps enumerated in maintenance contract '98/1234' is a class. This class is a
181
+ class_by_intension.</example>
182
+
183
+ <example number="3">The relationship between individual pump 'X/85/4567' and pump model 'XYZ_123', that indicates
184
+ the model of the pump, is a classification.</example>
185
+ <example number="4">The relationship between individual pump 'X/85/4567' and the set of pumps enumerated in
186
+ maintenance contract '98/1234', that indicates it is one of the set, is a classification. The complete set of
187
+ pumps covered by the contract can be defined by an instance of the entity type complete_membership.
188
+ </example>
189
+ <example number="5">The set of pumps that are both within maintenance contract '98/1234' and of pump model
190
+ 'XYZ_123' can be defined by the set theory relationship intersection.</example>
191
+ </fund_cons>
192
+
193
+ <!-- EXPRESS-G -->
194
+ <express-g>
195
+ <imgfile file="classification_schemaexpg2.xml" />
196
+ </express-g>
197
+ </schema>
198
+ <schema name="set_theory_schema" version="1">
199
+ <!-- Note schema EXPRESS are in ..\resources\resource_name name_of_schema.xml -->
200
+ <introduction>The set_theory_schema specifies the following relationships between classes:
201
+ <ul>
202
+ <li>complement;</li>
203
+ <li>intersection;</li>
204
+ <li>power set;</li>
205
+ <li>proper subset;</li>
206
+ <li>same membership (that is, set equality);</li>
207
+ <li>subset;</li>
208
+ <li>union.</li>
209
+ </ul>
210
+ </introduction>
211
+ <fund_cons>
212
+ <p>The set theory schema defines set theory relationship between classes or sets.</p>
213
+
214
+ <note number="1">In this part of ISO 10303, the terms class and set are synonyms.</note>
215
+
216
+ <p>In order to use this schema the entity that records the class or set shall be
217
+ <express_ref linkend="classification_and_set_theory:ir:classification_schema.class" /> or a subtype of
218
+ <express_ref linkend="classification_and_set_theory:ir:classification_schema.class" />.</p>
219
+ <example number="1">
220
+ <p>Consider the following instances of
221
+ <express_ref linkend="classification_and_set_theory:ir:classification_schema.class" />:</p>
222
+ <ul>
223
+ <li>
224
+ pump model 'XYZ_123', which is a
225
+ <express_ref
226
+ linkend="product_definition_schema:ir_express:product_definition_schema.product_definition_formation" />
227
+
228
+ and a
229
+ <express_ref linkend="classification_and_set_theory:ir:classification_schema.class" />; and </li>
230
+ <li>
231
+ the set of pumps enumerated in maintenance contract '98/1234'.
232
+ </li>
233
+ </ul>
234
+ <p>An instance of the relationship
235
+ <express_ref linkend="classification_and_set_theory:ir:set_theory_schema.subset" />
236
+
237
+ indicates that each of the set of pumps enumerated in maintenance contract '98/1234' is of pump model
238
+ 'XYZ_123'.
239
+ </p>
240
+ </example>
241
+
242
+ <example number="2">
243
+ <p>An organization has pumps of type A and type B. Some pumps handle radioactive fluids. There are the following
244
+ classes of activity:</p>
245
+ <ul>
246
+ <li>
247
+ SA - service pump type A;</li>
248
+ <li>
249
+ SB - service pump type B;</li>
250
+ <li>
251
+ DR - service equipment that has handled radioactive fluids.
252
+ </li>
253
+ </ul>
254
+ <p>For workflow management purposes, the following derived class of activity is defined:</p>
255
+ <ul>
256
+ <li>
257
+ DRS - service pump that has handled radioactive fluids.
258
+ </li>
259
+ </ul>
260
+ <p>This class is the
261
+ <express_ref linkend="classification_and_set_theory:ir:set_theory_schema.intersection" />
262
+
263
+ of class DR with the
264
+ <express_ref linkend="classification_and_set_theory:ir:set_theory_schema.union" />
265
+
266
+ of classes SA and SB.</p>
267
+ </example>
268
+ </fund_cons>
269
+
270
+ <!-- EXPRESS-G -->
271
+ <express-g>
272
+ <imgfile file="set_theory_schemaexpg2.xml" />
273
+ </express-g>
274
+ </schema>
275
+
276
+
277
+ <shortnames>
278
+ <shortname entity="class" name="CLASS" />
279
+ <shortname entity="class_by_extension" name="CLBYEX" />
280
+ <shortname entity="class_by_intension" name="CLBYIN" />
281
+ <shortname entity="classification" name="CLSSFC" />
282
+ <shortname entity="complete_membership" name="CMPMMB" />
283
+ <shortname entity="complete_membership_of_empty_set" name="CMOES" />
284
+ <shortname entity="complete_membership_of_non_empty_set" name="CMONES" />
285
+ <shortname entity="complement" name="CMPLMN" />
286
+ <shortname entity="intersection" name="INTRSC" />
287
+ <shortname entity="power_set" name="PWRST" />
288
+ <shortname entity="proper_subset" name="PRPSBS" />
289
+ <shortname entity="same_membership" name="SMMMB" />
290
+ <shortname entity="subset" name="SUBSET" />
291
+ <shortname entity="union" name="UNION" />
292
+ <shortname entity="union_of_all_members" name="UOAM" />
293
+ </shortnames>
294
+ <!--
295
+ <tech_discussion/>
296
+
297
+ <examples/>
298
+
299
+ <add_scope/>
300
+ -->
301
+ <!-- <bibliography/> -->
302
+ </resource>
@@ -6,11 +6,9 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Ribose Inc."]
7
7
  spec.email = ["open.source@ribose.com"]
8
8
 
9
- spec.summary = "stepmod-utils converts NISO STS XML into Metanorma XML."
9
+ spec.summary = "Stepmod-utils is a toolkit that works on STEPmod data."
10
10
  spec.description = <<~DESCRIPTION
11
- stepmod-utils converts NISO STS XML into Metanorma XML.
12
- This gem is a wrapper around stepmod-utils.jar available from
13
- https://github.com/metanorma/stepmod-utils, with versions matching the JAR file.
11
+ Stepmod-utils is a toolkit that works on STEPmod data.
14
12
  DESCRIPTION
15
13
 
16
14
  spec.homepage = "https://github.com/metanorma/stepmod-utils"
@@ -31,6 +29,7 @@ Gem::Specification.new do |spec|
31
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
30
  spec.require_paths = ["lib"]
33
31
 
34
- spec.add_runtime_dependency "thor", "~> 1.0"
32
+ spec.add_runtime_dependency "thor", ">= 0.20.3"
35
33
  spec.add_runtime_dependency "reverse_adoc", "~> 0.2"
34
+ spec.add_development_dependency "byebug", "~> 11.1"
36
35
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepmod-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-01 00:00:00.000000000 Z
11
+ date: 2020-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: 0.20.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: 0.20.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: reverse_adoc
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,13 +38,27 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.2'
41
- description: |
42
- stepmod-utils converts NISO STS XML into Metanorma XML.
43
- This gem is a wrapper around stepmod-utils.jar available from
44
- https://github.com/metanorma/stepmod-utils, with versions matching the JAR file.
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.1'
55
+ description: 'Stepmod-utils is a toolkit that works on STEPmod data.
56
+
57
+ '
45
58
  email:
46
59
  - open.source@ribose.com
47
- executables: []
60
+ executables:
61
+ - stepmod-extract-terms
48
62
  extensions: []
49
63
  extra_rdoc_files: []
50
64
  files:
@@ -60,8 +74,25 @@ files:
60
74
  - Rakefile
61
75
  - bin/console
62
76
  - bin/setup
77
+ - exe/stepmod-extract-terms
63
78
  - lib/stepmod/utils.rb
79
+ - lib/stepmod/utils/bibdata.rb
80
+ - lib/stepmod/utils/concept.rb
81
+ - lib/stepmod/utils/converters/clause_ref.rb
82
+ - lib/stepmod/utils/converters/def.rb
83
+ - lib/stepmod/utils/converters/definition.rb
84
+ - lib/stepmod/utils/converters/em.rb
85
+ - lib/stepmod/utils/converters/example.rb
86
+ - lib/stepmod/utils/converters/express_ref.rb
87
+ - lib/stepmod/utils/converters/module_ref.rb
88
+ - lib/stepmod/utils/converters/note.rb
89
+ - lib/stepmod/utils/converters/ol.rb
90
+ - lib/stepmod/utils/converters/stem.rb
91
+ - lib/stepmod/utils/converters/synonym.rb
92
+ - lib/stepmod/utils/converters/term.rb
93
+ - lib/stepmod/utils/stepmod_definition_converter.rb
64
94
  - lib/stepmod/utils/version.rb
95
+ - resource_example.xml
65
96
  - stepmod-utils.gemspec
66
97
  homepage: https://github.com/metanorma/stepmod-utils
67
98
  licenses:
@@ -85,5 +116,5 @@ requirements: []
85
116
  rubygems_version: 3.0.3
86
117
  signing_key:
87
118
  specification_version: 4
88
- summary: stepmod-utils converts NISO STS XML into Metanorma XML.
119
+ summary: Stepmod-utils is a toolkit that works on STEPmod data.
89
120
  test_files: []