stepmod-utils 0.6.10.pre.alpha.1 → 0.6.11
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 +4 -4
- data/.github/workflows/release.yml +6 -0
- data/.rubocop.yml +1 -1
- data/README.adoc +67 -0
- data/exe/stepmod-convert-bibliography +97 -0
- data/lib/stepmod/utils/bibliography_converter.rb +294 -0
- data/lib/stepmod/utils/ceradoc_compat.rb +95 -0
- data/lib/stepmod/utils/change.rb +3 -109
- data/lib/stepmod/utils/change_collection.rb +3 -3
- data/lib/stepmod/utils/change_file.rb +117 -0
- data/lib/stepmod/utils/cleaner.rb +25 -5
- data/lib/stepmod/utils/converters/a.rb +15 -1
- data/lib/stepmod/utils/converters/arm.rb +1 -1
- data/lib/stepmod/utils/converters/base.rb +3 -3
- data/lib/stepmod/utils/converters/clause_ref.rb +1 -1
- data/lib/stepmod/utils/converters/comment.rb +1 -1
- data/lib/stepmod/utils/converters/dd.rb +1 -1
- data/lib/stepmod/utils/converters/def.rb +2 -2
- data/lib/stepmod/utils/converters/definition.rb +1 -1
- data/lib/stepmod/utils/converters/description.rb +1 -1
- data/lib/stepmod/utils/converters/dl.rb +1 -1
- data/lib/stepmod/utils/converters/dt.rb +1 -1
- data/lib/stepmod/utils/converters/em.rb +2 -2
- data/lib/stepmod/utils/converters/em_express_description.rb +30 -1
- data/lib/stepmod/utils/converters/eqn.rb +2 -2
- data/lib/stepmod/utils/converters/example.rb +1 -1
- data/lib/stepmod/utils/converters/express_figure.rb +1 -1
- data/lib/stepmod/utils/converters/express_g.rb +1 -1
- data/lib/stepmod/utils/converters/express_note.rb +1 -1
- data/lib/stepmod/utils/converters/express_ref.rb +1 -1
- data/lib/stepmod/utils/converters/express_ref_express_description.rb +1 -1
- data/lib/stepmod/utils/converters/ext_description.rb +1 -1
- data/lib/stepmod/utils/converters/ext_descriptions.rb +1 -1
- data/lib/stepmod/utils/converters/figure.rb +6 -5
- data/lib/stepmod/utils/converters/fund_cons.rb +1 -1
- data/lib/stepmod/utils/converters/introduction.rb +1 -1
- data/lib/stepmod/utils/converters/li.rb +3 -3
- data/lib/stepmod/utils/converters/module_ref.rb +1 -1
- data/lib/stepmod/utils/converters/module_ref_express_description.rb +1 -1
- data/lib/stepmod/utils/converters/note.rb +1 -1
- data/lib/stepmod/utils/converters/ol.rb +3 -3
- data/lib/stepmod/utils/converters/resource.rb +1 -1
- data/lib/stepmod/utils/converters/schema.rb +1 -1
- data/lib/stepmod/utils/converters/schema_diag.rb +1 -1
- data/lib/stepmod/utils/converters/stepmod_ext_description.rb +1 -1
- data/lib/stepmod/utils/converters/strong.rb +31 -9
- data/lib/stepmod/utils/converters/sub.rb +2 -2
- data/lib/stepmod/utils/converters/sup.rb +2 -2
- data/lib/stepmod/utils/converters/synonym.rb +1 -1
- data/lib/stepmod/utils/converters/table.rb +2 -2
- data/lib/stepmod/utils/converters/term.rb +1 -1
- data/lib/stepmod/utils/converters/text.rb +2 -2
- data/lib/stepmod/utils/converters/tr.rb +3 -3
- data/lib/stepmod/utils/equation_logger.rb +1 -0
- data/lib/stepmod/utils/express_bibdata.rb +3 -1
- data/lib/stepmod/utils/mapping_change.rb +17 -0
- data/lib/stepmod/utils/schema_change.rb +19 -0
- data/lib/stepmod/utils/smrl_description_converter.rb +2 -2
- data/lib/stepmod/utils/smrl_resource_converter.rb +9 -9
- data/lib/stepmod/utils/stepmod_definition_converter.rb +18 -18
- data/lib/stepmod/utils/stepmod_file_annotator.rb +15 -13
- data/lib/stepmod/utils/terms_extractor.rb +3 -3
- data/lib/stepmod/utils/version.rb +1 -1
- data/stepmod-utils.gemspec +14 -3
- metadata +75 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ddaa51a1ef62d16c439179d751c53b1226095096ddc790076745f0ddfa47d371
|
|
4
|
+
data.tar.gz: '03951e930f04c9b5525e81e48c2ab3b5e4603bd225d9c655029d4ca8b3f12fb7'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a10c72aeefe40bf8c0e327eac05f1053bd91dbf22cc74068ea95474a6e888c6967da61d485ca98cfef5d54e8207da5a90be6d628c68e4c7bfafc1ac0bd7c1ad9
|
|
7
|
+
data.tar.gz: 4b3cd54d54b8405f0d8bd5fba2c8a667f10edfc253fd2ca366d3709e8a37ab49ebffcb3a522fe332fc78019d3f91a4303dce129c13817ed00ade0cf0d0cd05a1
|
|
@@ -13,6 +13,12 @@ on:
|
|
|
13
13
|
default: 'skip'
|
|
14
14
|
repository_dispatch:
|
|
15
15
|
types: [ do-release ]
|
|
16
|
+
# The publish leg: when the release PR (head branch release/v*) merges,
|
|
17
|
+
# metanorma/ci tags the merge commit and publishes (metanorma/ci#515).
|
|
18
|
+
# Ordinary PR closes are skipped inside the reusable workflow.
|
|
19
|
+
pull_request:
|
|
20
|
+
types:
|
|
21
|
+
- closed
|
|
16
22
|
|
|
17
23
|
jobs:
|
|
18
24
|
release:
|
data/.rubocop.yml
CHANGED
data/README.adoc
CHANGED
|
@@ -30,6 +30,10 @@ Or include it in your gemspec.
|
|
|
30
30
|
This command uses Expressir to validate all EXPRESS schemas listed in the
|
|
31
31
|
`{stepmod}/repository_index.xml` file.
|
|
32
32
|
|
|
33
|
+
Validation parses each file separately so that a broken schema is reported
|
|
34
|
+
without preventing validation of the remaining files. It does not build the
|
|
35
|
+
shared repository used for concept extraction.
|
|
36
|
+
|
|
33
37
|
There is a `SHOULD_REWRITE` constant that can be switched in the code which
|
|
34
38
|
allows overwriting of the EXPRESS schemas into a pretty-printed format.
|
|
35
39
|
|
|
@@ -68,6 +72,10 @@ SCHEMA: data/resources/geometric_model_schema/geometric_model_schema.exp
|
|
|
68
72
|
This command takes the STEPmod directory and parses its XML to synthesize
|
|
69
73
|
with the target EXPRESS schemas to migrate into Annotated EXPRESS schemas.
|
|
70
74
|
|
|
75
|
+
Annotation parses each input file to determine its schema name before combining
|
|
76
|
+
it with the XML descriptions. It does not resolve references across schemas;
|
|
77
|
+
repository-wide parsing happens when extracting concepts from the annotated files.
|
|
78
|
+
|
|
71
79
|
Given the following schemas:
|
|
72
80
|
|
|
73
81
|
* Simple EXPRESS schema: `{stepmod-root-dir}/data/resources/action_schema/action_schema.exp`
|
|
@@ -119,6 +127,15 @@ $ bundle exec stepmod-annotate-all --stepmod-dir iso-10303-stepmod-wg12 --output
|
|
|
119
127
|
|
|
120
128
|
=== ISO 10303-2 concepts extraction
|
|
121
129
|
|
|
130
|
+
Concept extraction passes the complete selected set of annotated EXPRESS files to
|
|
131
|
+
`Expressir::Express::Parser.from_files` once, producing a shared repository for
|
|
132
|
+
cross-schema references as requested in
|
|
133
|
+
https://github.com/metanorma/stepmod-utils/issues/136[issue #136]. The set contains
|
|
134
|
+
existing ARM and MIM files for published, non-withdrawn modules and existing
|
|
135
|
+
schemas for published, non-withdrawn resources listed in `repository_index.xml`.
|
|
136
|
+
ISO 13584 schemas are excluded. BOMs and application protocols do not contribute
|
|
137
|
+
Clause 3 terms and are excluded from concept extraction.
|
|
138
|
+
|
|
122
139
|
[source,sh]
|
|
123
140
|
----
|
|
124
141
|
$ bundle exec stepmod-extract-concepts \
|
|
@@ -256,6 +273,56 @@ End!
|
|
|
256
273
|
[stepmod-utils] ******************************
|
|
257
274
|
----
|
|
258
275
|
|
|
276
|
+
=== Converting the STEPmod bibliography to a Relaton collection
|
|
277
|
+
|
|
278
|
+
STEPmod keeps the shared references for `normref.inc` and `bibitem.inc` in
|
|
279
|
+
`data/basic/normrefs.xml` and `data/basic/bibliography.xml`. This command
|
|
280
|
+
converts both lists into one Relaton collection, so that Metanorma can cite any
|
|
281
|
+
entry by its id.
|
|
282
|
+
|
|
283
|
+
[source,sh]
|
|
284
|
+
----
|
|
285
|
+
# from a STEPmod checkout
|
|
286
|
+
$ stepmod-convert-bibliography -s {stepmod-directory} -o stepmod-bibliography.xml
|
|
287
|
+
|
|
288
|
+
# or from the two files directly (either one can be left out)
|
|
289
|
+
$ stepmod-convert-bibliography --normrefs normrefs.xml \
|
|
290
|
+
--bibliography bibliography.xml -o stepmod-bibliography.xml
|
|
291
|
+
----
|
|
292
|
+
|
|
293
|
+
Without `-o`, the collection is written to standard output. `-t` sets the
|
|
294
|
+
collection title.
|
|
295
|
+
|
|
296
|
+
The output is a `<relaton-collection>` with one `<relation type="partOf">` per
|
|
297
|
+
entry, each holding a Relaton `<bibitem>`:
|
|
298
|
+
|
|
299
|
+
* The item id is the STEPmod id with the prefix `normref_` or `bibitem_` (for
|
|
300
|
+
example `bibitem_ref8824-1`), the anchor form that the migrated ISO 10303
|
|
301
|
+
documents use. The raw STEPmod id is kept as a `docidentifier` of type
|
|
302
|
+
`STEPmod-id`.
|
|
303
|
+
* The primary `docidentifier` is `orgname` + `stdnumber` for a normref (for
|
|
304
|
+
example `ISO 31-0`), the `stdnumber` for a bibliography entry, and
|
|
305
|
+
`report-type` + `number` for a technical report.
|
|
306
|
+
* `bibitem` and `normref` become `standard`, `bibitem.techreport` becomes
|
|
307
|
+
`techreport`, and `bibitem.book` becomes `book`.
|
|
308
|
+
* `<term>` children of a normref are not bibliographic data and are skipped.
|
|
309
|
+
* A duplicate id in one list is skipped with a warning. An unknown named
|
|
310
|
+
entity is kept as text with a warning.
|
|
311
|
+
|
|
312
|
+
From Ruby:
|
|
313
|
+
|
|
314
|
+
[source,ruby]
|
|
315
|
+
----
|
|
316
|
+
require "stepmod/utils/bibliography_converter"
|
|
317
|
+
|
|
318
|
+
converter = Stepmod::Utils::BibliographyConverter.new(
|
|
319
|
+
normrefs: "data/basic/normrefs.xml",
|
|
320
|
+
bibliography: "data/basic/bibliography.xml",
|
|
321
|
+
)
|
|
322
|
+
converter.items # => Array<Relaton::Bib::ItemData>
|
|
323
|
+
converter.to_xml # => relaton-collection XML
|
|
324
|
+
----
|
|
325
|
+
|
|
259
326
|
== Conversion of STEPmod descriptions.xml into adoc
|
|
260
327
|
|
|
261
328
|
[source,sh]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# resolve bin path, ignoring symlinks
|
|
4
|
+
require "pathname"
|
|
5
|
+
bin_file = Pathname.new(__FILE__).realpath
|
|
6
|
+
|
|
7
|
+
# add self to libpath
|
|
8
|
+
$:.unshift File.expand_path("../../lib", bin_file)
|
|
9
|
+
|
|
10
|
+
require "bundler/setup"
|
|
11
|
+
require "optparse"
|
|
12
|
+
require "stepmod/utils/bibliography_converter"
|
|
13
|
+
|
|
14
|
+
def log(message)
|
|
15
|
+
warn "[stepmod-utils] #{message}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
options = {}
|
|
19
|
+
parser = OptionParser.new do |opts|
|
|
20
|
+
opts.banner = "Usage: #{$0} [options]\n\n" \
|
|
21
|
+
"Convert STEPmod normrefs.xml and bibliography.xml into " \
|
|
22
|
+
"one Relaton collection."
|
|
23
|
+
|
|
24
|
+
opts.on("-s", "--stepmod DIR",
|
|
25
|
+
"STEPmod root; reads data/basic/normrefs.xml and " \
|
|
26
|
+
"data/basic/bibliography.xml") do |dir|
|
|
27
|
+
options[:stepmod] = dir
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
opts.on("--normrefs PATH", "Path to normrefs.xml") do |path|
|
|
31
|
+
options[:normrefs] = path
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
opts.on("--bibliography PATH", "Path to bibliography.xml") do |path|
|
|
35
|
+
options[:bibliography] = path
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
opts.on("-o", "--output PATH",
|
|
39
|
+
"Output collection XML (default: standard output)") do |path|
|
|
40
|
+
options[:output] = path
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
opts.on("-t", "--title TITLE", "Title of the collection") do |title|
|
|
44
|
+
options[:title] = title
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
|
48
|
+
puts opts
|
|
49
|
+
exit
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
begin
|
|
53
|
+
parser.parse!
|
|
54
|
+
rescue OptionParser::ParseError => e
|
|
55
|
+
warn e.message
|
|
56
|
+
warn parser
|
|
57
|
+
exit 1
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
unless ARGV.empty?
|
|
61
|
+
warn "Unexpected argument: #{ARGV.join(' ')}"
|
|
62
|
+
warn parser
|
|
63
|
+
exit 1
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
if options[:stepmod]
|
|
67
|
+
basic = File.join(options[:stepmod], "data", "basic")
|
|
68
|
+
options[:normrefs] ||= File.join(basic, "normrefs.xml")
|
|
69
|
+
options[:bibliography] ||= File.join(basic, "bibliography.xml")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
inputs = options.values_at(:normrefs, :bibliography).compact
|
|
73
|
+
if inputs.empty?
|
|
74
|
+
warn "Give --stepmod DIR, or --normrefs PATH and/or --bibliography PATH."
|
|
75
|
+
warn parser
|
|
76
|
+
exit 1
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
missing = inputs.reject { |path| File.file?(path) }
|
|
80
|
+
unless missing.empty?
|
|
81
|
+
warn "File not found: #{missing.join(', ')}"
|
|
82
|
+
exit 1
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
converter = Stepmod::Utils::BibliographyConverter.new(
|
|
86
|
+
normrefs: options[:normrefs],
|
|
87
|
+
bibliography: options[:bibliography],
|
|
88
|
+
title: options[:title],
|
|
89
|
+
)
|
|
90
|
+
xml = converter.to_xml
|
|
91
|
+
|
|
92
|
+
if options[:output]
|
|
93
|
+
File.write(options[:output], xml, encoding: "UTF-8")
|
|
94
|
+
log "#{converter.items.size} items written to #{options[:output]}"
|
|
95
|
+
else
|
|
96
|
+
$stdout.write(xml)
|
|
97
|
+
end
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
require "date"
|
|
2
|
+
require "nokogiri"
|
|
3
|
+
require "relaton/bib"
|
|
4
|
+
|
|
5
|
+
module Stepmod
|
|
6
|
+
module Utils
|
|
7
|
+
# Converts the STEPmod shared reference lists, data/basic/normrefs.xml
|
|
8
|
+
# and data/basic/bibliography.xml, into one Relaton collection, so that
|
|
9
|
+
# Metanorma can cite any entry by its id.
|
|
10
|
+
#
|
|
11
|
+
# Each entry becomes a Relaton::Bib::ItemData. Its id is the STEPmod id
|
|
12
|
+
# with the list prefix the migrated documents use ("normref_",
|
|
13
|
+
# "bibitem_"), and the raw STEPmod id is kept as a docidentifier of type
|
|
14
|
+
# "STEPmod-id".
|
|
15
|
+
class BibliographyConverter
|
|
16
|
+
COLLECTION_NS = "https://open.ribose.com/relaton-xml".freeze
|
|
17
|
+
DEFAULT_TITLE = "STEPmod bibliography".freeze
|
|
18
|
+
AUTHOR = "ISO/TC 184/SC 4".freeze
|
|
19
|
+
|
|
20
|
+
XML_ENTITIES = %w[amp lt gt quot apos].freeze
|
|
21
|
+
DASHES = /\A[\s—–-]+|[\s—–-]+\z/
|
|
22
|
+
ITEM_TYPES = {
|
|
23
|
+
"normref" => "standard",
|
|
24
|
+
"bibitem" => "standard",
|
|
25
|
+
"bibitem.techreport" => "techreport",
|
|
26
|
+
"bibitem.book" => "book",
|
|
27
|
+
}.freeze
|
|
28
|
+
|
|
29
|
+
Bib = Relaton::Bib
|
|
30
|
+
|
|
31
|
+
attr_reader :title
|
|
32
|
+
|
|
33
|
+
# @param normrefs [String, nil] path to normrefs.xml
|
|
34
|
+
# @param bibliography [String, nil] path to bibliography.xml
|
|
35
|
+
# @param title [String, nil] title of the collection
|
|
36
|
+
def initialize(normrefs: nil, bibliography: nil, title: nil)
|
|
37
|
+
@normrefs = normrefs
|
|
38
|
+
@bibliography = bibliography
|
|
39
|
+
@title = title || DEFAULT_TITLE
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @return [Array<Relaton::Bib::ItemData>]
|
|
43
|
+
def items
|
|
44
|
+
@items ||= read_list(@normrefs, "normref", "//normref") +
|
|
45
|
+
read_list(@bibliography, "bibitem",
|
|
46
|
+
"//bibitem | //bibitem.techreport | //bibitem.book")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @return [String] a relaton-collection XML document
|
|
50
|
+
def to_xml
|
|
51
|
+
doc = Nokogiri::XML::Document.new
|
|
52
|
+
doc.encoding = "UTF-8"
|
|
53
|
+
root = doc.add_child(doc.create_element("relaton-collection",
|
|
54
|
+
xmlns: COLLECTION_NS))
|
|
55
|
+
root.add_child(doc.create_element("title", title))
|
|
56
|
+
root.add_child(author_node(doc))
|
|
57
|
+
items.each do |item|
|
|
58
|
+
relation = root.add_child(doc.create_element("relation",
|
|
59
|
+
type: "partOf"))
|
|
60
|
+
relation.add_child(Nokogiri::XML(item.to_xml, &:noblanks).root)
|
|
61
|
+
end
|
|
62
|
+
doc.to_xml
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def author_node(doc)
|
|
68
|
+
contributor = doc.create_element("contributor")
|
|
69
|
+
contributor.add_child(doc.create_element("role", type: "author"))
|
|
70
|
+
org = contributor.add_child(doc.create_element("organization"))
|
|
71
|
+
org.add_child(doc.create_element("name", AUTHOR))
|
|
72
|
+
contributor
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def read_list(path, prefix, xpath)
|
|
76
|
+
return [] unless path
|
|
77
|
+
|
|
78
|
+
seen = {}
|
|
79
|
+
parse(path).xpath(xpath).filter_map do |node|
|
|
80
|
+
raw_id = node["id"]
|
|
81
|
+
id = "#{prefix}_#{sanitize_id(raw_id)}"
|
|
82
|
+
if seen[id]
|
|
83
|
+
log(path, "duplicate id #{raw_id.inspect} skipped")
|
|
84
|
+
next
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
seen[id] = true
|
|
88
|
+
build_item(node, id, raw_id)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def log(path, message)
|
|
93
|
+
warn "[stepmod-utils] #{path}: #{message}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# The DTD that declares the HTML entities is not available, so resolve
|
|
97
|
+
# them before the parse.
|
|
98
|
+
# An unknown entity would be dropped silently by the parser, so it is
|
|
99
|
+
# reported and kept as text.
|
|
100
|
+
def parse(path)
|
|
101
|
+
xml = File.read(path, encoding: "UTF-8")
|
|
102
|
+
xml = xml.gsub(/&([a-zA-Z][a-zA-Z0-9]*);/) do |match|
|
|
103
|
+
name = Regexp.last_match(1)
|
|
104
|
+
next match if XML_ENTITIES.include?(name)
|
|
105
|
+
|
|
106
|
+
resolve_entity(name) || unknown_entity(path, match)
|
|
107
|
+
end
|
|
108
|
+
Nokogiri::XML(xml, &:nonet)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def resolve_entity(name)
|
|
112
|
+
codepoint = entity_lookup[name]
|
|
113
|
+
[codepoint].pack("U") if codepoint
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def unknown_entity(path, match)
|
|
117
|
+
log(path, "unknown entity #{match} kept as text")
|
|
118
|
+
"&#{match[1..]}"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def entity_lookup
|
|
122
|
+
@entity_lookup ||= Nokogiri::HTML4::EntityLookup.new
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def sanitize_id(raw_id)
|
|
126
|
+
raw_id.to_s.gsub(/[^\w.-]+/, "_")
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def build_item(node, id, raw_id)
|
|
130
|
+
ref = node.at("./stdref") || node
|
|
131
|
+
Bib::ItemData.new(
|
|
132
|
+
id: id,
|
|
133
|
+
type: ITEM_TYPES[node.name],
|
|
134
|
+
docidentifier: docidentifiers(node, ref, raw_id),
|
|
135
|
+
title: titles(node, ref),
|
|
136
|
+
date: dates(ref),
|
|
137
|
+
contributor: contributors(node, ref),
|
|
138
|
+
place: places(node),
|
|
139
|
+
source: sources(node),
|
|
140
|
+
note: notes(node),
|
|
141
|
+
)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def docidentifiers(node, ref, raw_id)
|
|
145
|
+
primary = primary_identifier(node, ref)
|
|
146
|
+
stepmod_id = Bib::Docidentifier.new(content: raw_id,
|
|
147
|
+
type: "STEPmod-id")
|
|
148
|
+
primary ? [primary, stepmod_id] : [stepmod_id]
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# A normref stdnumber is the bare number ("31-0"). A bibliography
|
|
152
|
+
# stdnumber is already the full identifier ("ISO 286-1", "RFC 3986").
|
|
153
|
+
def primary_identifier(node, ref)
|
|
154
|
+
orgname = text(ref, "orgname")
|
|
155
|
+
number = text(ref, "stdnumber")
|
|
156
|
+
if number
|
|
157
|
+
content = node.name == "normref" ? prefixed(orgname, number) : number
|
|
158
|
+
type = docid_type(orgname)
|
|
159
|
+
elsif (number = text(node, "number"))
|
|
160
|
+
content = prefixed(text(node, "report-type"), number)
|
|
161
|
+
type = "STEPmod"
|
|
162
|
+
end
|
|
163
|
+
return unless content
|
|
164
|
+
|
|
165
|
+
Bib::Docidentifier.new(content: content, type: type, primary: true)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def prefixed(prefix, value)
|
|
169
|
+
return value if prefix.nil? || value.start_with?(prefix)
|
|
170
|
+
|
|
171
|
+
"#{prefix} #{value}"
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def docid_type(orgname)
|
|
175
|
+
case orgname
|
|
176
|
+
when /\AISO/ then "ISO"
|
|
177
|
+
when /\AIEC/ then "IEC"
|
|
178
|
+
else "STEPmod"
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# A normref subtitle continues the title ("— Part 1: ..."). A
|
|
183
|
+
# bibliography subtitle is free text, so it becomes a note instead.
|
|
184
|
+
def titles(node, ref)
|
|
185
|
+
main = strip_dashes(text(ref, "stdtitle"))
|
|
186
|
+
return [] unless main
|
|
187
|
+
|
|
188
|
+
subtitle = node.name == "normref" && strip_dashes(text(ref, "subtitle"))
|
|
189
|
+
return [title_of(main, "main")] unless subtitle
|
|
190
|
+
|
|
191
|
+
result = [title_of(join_title(main, subtitle), "main"),
|
|
192
|
+
title_of(main, "title-main")]
|
|
193
|
+
part = subtitle.start_with?("Part")
|
|
194
|
+
result << title_of(subtitle, "title-part") if part
|
|
195
|
+
result
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Some subtitles continue the sentence (", corrected and reprinted
|
|
199
|
+
# in 1995", "(OMG-UML VER 1.3)"); the others are title components.
|
|
200
|
+
def join_title(main, subtitle)
|
|
201
|
+
case subtitle
|
|
202
|
+
when /\A[,;.]/ then "#{main}#{subtitle}"
|
|
203
|
+
when /\A\(/ then "#{main} #{subtitle}"
|
|
204
|
+
else "#{main} — #{subtitle}"
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def title_of(content, type)
|
|
209
|
+
Bib::Title.new(content: content, type: type, language: "en",
|
|
210
|
+
script: "Latn")
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def strip_dashes(value)
|
|
214
|
+
stripped = value&.gsub(DASHES, "")
|
|
215
|
+
stripped unless stripped.nil? || stripped.empty?
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def notes(node)
|
|
219
|
+
return [] if node.name == "normref"
|
|
220
|
+
|
|
221
|
+
subtitle = text(node, "subtitle")
|
|
222
|
+
subtitle ? [Bib::Note.new(content: subtitle)] : []
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# STEPmod dates are "YYYY", "YYYY-MM-DD", or free text such as
|
|
226
|
+
# "January 1992". Free text is kept as the date text. A value without
|
|
227
|
+
# a year ("—", "-", "CHECK DATE") means "undated" and is dropped, and
|
|
228
|
+
# so is a future date ("To be published in 2018").
|
|
229
|
+
def dates(ref)
|
|
230
|
+
value = text(ref, "pubdate")
|
|
231
|
+
return [] unless value
|
|
232
|
+
|
|
233
|
+
if value.match?(/\A\d{4}(-\d{2}){0,2}\z/)
|
|
234
|
+
return [Bib::Date.new(type: "published", at: value)]
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
year = value[/\b(\d{4})\b/, 1]
|
|
238
|
+
return [] if year.nil? || value.match?(/to be published/i)
|
|
239
|
+
|
|
240
|
+
[Bib::Date.new(type: "published", at: year, text: value)]
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def contributors(node, ref)
|
|
244
|
+
authors = texts(node, "primary-responsibility").map do |name|
|
|
245
|
+
Bib::Contributor.new(role: [role("author")], person: person(name))
|
|
246
|
+
end
|
|
247
|
+
publishers = %w[orgname institution publisher].flat_map do |tag|
|
|
248
|
+
texts(tag == "orgname" ? ref : node, tag)
|
|
249
|
+
end
|
|
250
|
+
authors + publishers.uniq.map do |name|
|
|
251
|
+
Bib::Contributor.new(role: [role("publisher")],
|
|
252
|
+
organization: organization(name))
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def role(type)
|
|
257
|
+
Bib::Contributor::Role.new(type: type)
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def person(name)
|
|
261
|
+
Bib::Person.new(
|
|
262
|
+
name: Bib::FullName.new(
|
|
263
|
+
completename: Bib::LocalizedString.new(content: name),
|
|
264
|
+
),
|
|
265
|
+
)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def organization(name)
|
|
269
|
+
Bib::Organization.new(
|
|
270
|
+
name: [Bib::TypedLocalizedString.new(content: name)],
|
|
271
|
+
)
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def places(node)
|
|
275
|
+
texts(node, "place").map { |p| Bib::Place.new(formatted_place: p) }
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def sources(node)
|
|
279
|
+
texts(node, "ulink").map { |u| Bib::Uri.new(type: "src", content: u) }
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def text(node, tag)
|
|
283
|
+
texts(node, tag).first
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def texts(node, tag)
|
|
287
|
+
node.xpath("./#{tag}").filter_map do |el|
|
|
288
|
+
value = el.text.gsub(/\s+/, " ").strip
|
|
289
|
+
value unless value.empty?
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "nokogiri"
|
|
4
|
+
require "ceradoc"
|
|
5
|
+
require "ceradoc/html"
|
|
6
|
+
|
|
7
|
+
module Stepmod
|
|
8
|
+
module Utils
|
|
9
|
+
# coradoc 1.x string-mode compatibility over the ceradoc CoreModel
|
|
10
|
+
# engine. The coradoc → coridoc → ceradoc rename (2026-11-25)
|
|
11
|
+
# replaced the dual string/element converter API (to_coradoc +
|
|
12
|
+
# Generator.gen_adoc) with a CoreModel-only converter entry
|
|
13
|
+
# (to_ceradoc). The stepmod converter chain keeps building AsciiDoc
|
|
14
|
+
# fragments as strings; this module restores the string-mode
|
|
15
|
+
# surface on top of the ceradoc engine classes.
|
|
16
|
+
module CeradocCompat
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
# coradoc 1.x Generator.gen_adoc: flatten mixed string / CoreModel
|
|
20
|
+
# content into AsciiDoc text. CoreModel nodes serialize through
|
|
21
|
+
# the ceradoc-adoc FromCoreModel transform.
|
|
22
|
+
def gen_adoc(content)
|
|
23
|
+
case content
|
|
24
|
+
when Array then content.map { |elem| gen_adoc(elem) }.join("")
|
|
25
|
+
when String, nil then content.to_s
|
|
26
|
+
when Ceradoc::CoreModel::Base
|
|
27
|
+
require "ceradoc/asciidoc"
|
|
28
|
+
Ceradoc::AsciiDoc::Transform::FromCoreModel
|
|
29
|
+
.transform(content).to_adoc
|
|
30
|
+
else
|
|
31
|
+
content.respond_to?(:to_adoc) ? content.to_adoc : content.to_s
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Prepended to Ceradoc::Html::Converters::Base so every converter
|
|
36
|
+
# in the shared registry answers the coradoc 1.x string-mode
|
|
37
|
+
# surface. Stepmod's own to_coradoc overrides shadow these.
|
|
38
|
+
module StringMode
|
|
39
|
+
# coradoc 1.x Base#convert — the string entry the stepmod
|
|
40
|
+
# converter drive sites invoke via Converters.lookup(...).convert.
|
|
41
|
+
def convert(node, state = {})
|
|
42
|
+
Stepmod::Utils::CeradocCompat.gen_adoc(to_coradoc(node, state))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# coradoc 1.x engine entry name; ceradoc renamed it to_ceradoc
|
|
46
|
+
# (CoreModel nodes). For ceradoc-native converters this
|
|
47
|
+
# stringifies their CoreModel output; stepmod's string
|
|
48
|
+
# overrides shadow this when they define to_coradoc.
|
|
49
|
+
def to_coradoc(node, state = {})
|
|
50
|
+
Stepmod::Utils::CeradocCompat.gen_adoc(to_ceradoc(node, state))
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Engine-side name for stepmod's string converters: run the
|
|
54
|
+
# string chain and carry the fragment as literal text so
|
|
55
|
+
# ceradoc's CoreModel collectors can embed it.
|
|
56
|
+
def to_ceradoc(node, state = {})
|
|
57
|
+
result = to_coradoc(node, state)
|
|
58
|
+
if result.is_a?(String)
|
|
59
|
+
Ceradoc::CoreModel::TextElement.new(content: result)
|
|
60
|
+
else
|
|
61
|
+
result
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# coradoc 1.x string mode: children convert to joined text.
|
|
66
|
+
def treat_children(node, state)
|
|
67
|
+
node.children.map { |child| treat(child, state) }.join
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def treat(node, state)
|
|
71
|
+
Stepmod::Utils::Converters.process(node, state)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
Ceradoc::Html::Converters::Base.prepend(StringMode)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
module Stepmod
|
|
81
|
+
module Utils
|
|
82
|
+
module Converters
|
|
83
|
+
# coradoc 1.x string-mode traversal over the shared ceradoc
|
|
84
|
+
# converter registry (the old Ceradoc::Html::Converters.process).
|
|
85
|
+
def self.process(node, state)
|
|
86
|
+
node = node.to_a if defined?(Nokogiri::XML::NodeSet) &&
|
|
87
|
+
node.is_a?(Nokogiri::XML::NodeSet)
|
|
88
|
+
return node.map { |i| process(i, state) }.join if node.is_a?(Array)
|
|
89
|
+
|
|
90
|
+
lookup = Ceradoc::Html::Converters.lookup(node.name)
|
|
91
|
+
lookup.convert(node, state)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|