stepmod-utils 0.3.5 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/.github/workflows/release.yml +4 -3
- data/.rubocop.yml +1 -1
- data/Gemfile +3 -3
- data/Rakefile +1 -1
- data/exe/stepmod-annotate-all +17 -11
- data/exe/stepmod-build-resource-docs-cache +8 -7
- data/exe/stepmod-convert-express-description +6 -4
- data/exe/stepmod-convert-express-resource +6 -4
- data/exe/stepmod-extract-terms +38 -25
- data/exe/stepmod-find-express-files +8 -7
- data/lib/stepmod/utils/bibdata.rb +31 -35
- data/lib/stepmod/utils/cleaner.rb +3 -3
- data/lib/stepmod/utils/concept.rb +30 -35
- data/lib/stepmod/utils/converters/a.rb +7 -10
- data/lib/stepmod/utils/converters/blockquote.rb +4 -4
- data/lib/stepmod/utils/converters/br.rb +1 -1
- data/lib/stepmod/utils/converters/bypass.rb +33 -33
- data/lib/stepmod/utils/converters/clause_ref.rb +3 -3
- data/lib/stepmod/utils/converters/code.rb +1 -1
- data/lib/stepmod/utils/converters/comment.rb +5 -3
- data/lib/stepmod/utils/converters/dd.rb +2 -2
- data/lib/stepmod/utils/converters/def.rb +19 -19
- data/lib/stepmod/utils/converters/drop.rb +2 -2
- data/lib/stepmod/utils/converters/dt.rb +2 -2
- data/lib/stepmod/utils/converters/em.rb +1 -1
- data/lib/stepmod/utils/converters/em_express_description.rb +1 -1
- data/lib/stepmod/utils/converters/eqn.rb +28 -26
- data/lib/stepmod/utils/converters/example.rb +5 -6
- data/lib/stepmod/utils/converters/express_g.rb +10 -9
- data/lib/stepmod/utils/converters/express_ref.rb +2 -2
- data/lib/stepmod/utils/converters/express_ref_express_description.rb +3 -2
- data/lib/stepmod/utils/converters/ext_description.rb +1 -1
- data/lib/stepmod/utils/converters/figure.rb +3 -3
- data/lib/stepmod/utils/converters/fund_cons.rb +1 -1
- data/lib/stepmod/utils/converters/head.rb +3 -2
- data/lib/stepmod/utils/converters/hr.rb +2 -2
- data/lib/stepmod/utils/converters/ignore.rb +3 -3
- data/lib/stepmod/utils/converters/introduction.rb +1 -1
- data/lib/stepmod/utils/converters/module_ref.rb +6 -6
- data/lib/stepmod/utils/converters/note.rb +5 -6
- data/lib/stepmod/utils/converters/ol.rb +5 -5
- data/lib/stepmod/utils/converters/p.rb +2 -2
- data/lib/stepmod/utils/converters/pass_through.rb +2 -2
- data/lib/stepmod/utils/converters/q.rb +1 -1
- data/lib/stepmod/utils/converters/schema.rb +1 -1
- data/lib/stepmod/utils/converters/stem.rb +1 -1
- data/lib/stepmod/utils/converters/stepmod_ext_description.rb +5 -4
- data/lib/stepmod/utils/converters/strong.rb +5 -4
- 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 +2 -2
- data/lib/stepmod/utils/converters/table.rb +7 -9
- data/lib/stepmod/utils/converters/term.rb +18 -9
- data/lib/stepmod/utils/converters/text.rb +11 -13
- data/lib/stepmod/utils/converters/uof.rb +3 -4
- data/lib/stepmod/utils/html_to_asciimath.rb +91 -90
- data/lib/stepmod/utils/smrl_description_converter.rb +34 -33
- data/lib/stepmod/utils/smrl_resource_converter.rb +50 -49
- data/lib/stepmod/utils/stepmod_definition_converter.rb +39 -38
- data/lib/stepmod/utils/stepmod_file_annotator.rb +26 -19
- data/lib/stepmod/utils/terms_extractor.rb +138 -86
- data/lib/stepmod/utils/version.rb +1 -1
- data/stepmod-utils.gemspec +11 -5
- metadata +71 -15
@@ -1,43 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
3
|
+
require "reverse_adoc"
|
4
|
+
require "stepmod/utils/converters/a"
|
5
|
+
require "stepmod/utils/converters/blockquote"
|
6
|
+
require "stepmod/utils/converters/br"
|
7
|
+
require "stepmod/utils/converters/bypass"
|
8
|
+
require "stepmod/utils/converters/code"
|
9
|
+
require "stepmod/utils/converters/drop"
|
10
|
+
require "stepmod/utils/converters/em_express_description"
|
11
|
+
require "stepmod/utils/converters/example"
|
12
|
+
require "stepmod/utils/converters/express_ref_express_description"
|
13
|
+
require "stepmod/utils/converters/ext_description"
|
14
|
+
require "stepmod/utils/converters/ext_descriptions"
|
15
|
+
require "stepmod/utils/converters/head"
|
16
|
+
require "stepmod/utils/converters/hr"
|
17
|
+
require "stepmod/utils/converters/ignore"
|
18
|
+
require "stepmod/utils/converters/note"
|
19
|
+
require "stepmod/utils/converters/p"
|
20
|
+
require "stepmod/utils/converters/pass_through"
|
21
|
+
require "stepmod/utils/converters/q"
|
22
|
+
require "stepmod/utils/converters/strong"
|
23
|
+
require "stepmod/utils/converters/sub"
|
24
|
+
require "stepmod/utils/converters/sup"
|
25
|
+
require "stepmod/utils/converters/text"
|
26
|
+
require "stepmod/utils/cleaner"
|
27
27
|
|
28
28
|
module Stepmod
|
29
29
|
module Utils
|
30
30
|
class SmrlDescriptionConverter
|
31
31
|
def self.convert(input, options = {})
|
32
|
-
root =
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
root = case input
|
33
|
+
when String
|
34
|
+
Nokogiri::XML(input).root
|
35
|
+
when Nokogiri::XML::Document
|
36
|
+
input.root
|
37
|
+
when Nokogiri::XML::Node
|
38
|
+
input
|
39
|
+
end
|
39
40
|
|
40
|
-
root || (return
|
41
|
+
root || (return "")
|
41
42
|
|
42
43
|
ReverseAdoc.config.with(options) do
|
43
44
|
result = ReverseAdoc::Converters.lookup(root.name).convert(root)
|
@@ -46,4 +47,4 @@ module Stepmod
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
49
|
-
end
|
50
|
+
end
|
@@ -1,61 +1,62 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
3
|
+
require "reverse_adoc"
|
4
|
+
require "reverse_adoc/converters/bypass"
|
5
|
+
require "reverse_adoc/converters/pass_through"
|
6
|
+
require "stepmod/utils/converters/a"
|
7
|
+
require "stepmod/utils/converters/blockquote"
|
8
|
+
require "stepmod/utils/converters/br"
|
9
|
+
require "stepmod/utils/converters/bypass"
|
10
|
+
require "stepmod/utils/converters/code"
|
11
|
+
require "stepmod/utils/converters/comment"
|
12
|
+
require "stepmod/utils/converters/dd"
|
13
|
+
require "stepmod/utils/converters/dl"
|
14
|
+
require "stepmod/utils/converters/dt"
|
15
|
+
require "stepmod/utils/converters/drop"
|
16
|
+
require "stepmod/utils/converters/example"
|
17
|
+
require "stepmod/utils/converters/express_g"
|
18
|
+
require "stepmod/utils/converters/fund_cons"
|
19
|
+
require "stepmod/utils/converters/eqn"
|
20
|
+
require "stepmod/utils/converters/head"
|
21
|
+
require "stepmod/utils/converters/hr"
|
22
|
+
require "stepmod/utils/converters/ignore"
|
23
|
+
require "stepmod/utils/converters/introduction"
|
24
|
+
require "stepmod/utils/converters/note"
|
25
|
+
require "stepmod/utils/converters/ol"
|
26
|
+
require "stepmod/utils/converters/p"
|
27
|
+
require "stepmod/utils/converters/pass_through"
|
28
|
+
require "stepmod/utils/converters/q"
|
29
|
+
require "stepmod/utils/converters/resource"
|
30
|
+
require "stepmod/utils/converters/schema_diag"
|
31
|
+
require "stepmod/utils/converters/schema"
|
32
|
+
require "stepmod/utils/converters/strong"
|
33
|
+
require "stepmod/utils/converters/sub"
|
34
|
+
require "stepmod/utils/converters/sup"
|
35
|
+
require "stepmod/utils/converters/table"
|
36
|
+
require "stepmod/utils/converters/text"
|
37
|
+
require "stepmod/utils/cleaner"
|
38
38
|
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require
|
39
|
+
require "reverse_adoc/converters/figure"
|
40
|
+
require "reverse_adoc/converters/img"
|
41
|
+
require "reverse_adoc/converters/li"
|
42
|
+
require "reverse_adoc/converters/tr"
|
43
|
+
require "reverse_adoc/converters/td"
|
44
|
+
require "reverse_adoc/converters/th"
|
45
45
|
|
46
46
|
module Stepmod
|
47
47
|
module Utils
|
48
48
|
class SmrlResourceConverter
|
49
49
|
def self.convert(input, options = {})
|
50
|
-
root =
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
root = case input
|
51
|
+
when String
|
52
|
+
Nokogiri::XML(input).root
|
53
|
+
when Nokogiri::XML::Document
|
54
|
+
input.root
|
55
|
+
when Nokogiri::XML::Node
|
56
|
+
input
|
57
|
+
end
|
57
58
|
|
58
|
-
root || (return
|
59
|
+
root || (return "")
|
59
60
|
|
60
61
|
ReverseAdoc.config.with(options) do
|
61
62
|
result = ReverseAdoc::Converters.lookup(root.name).convert(root)
|
@@ -1,41 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
|
21
|
-
require 'reverse_adoc/converters/a'
|
22
|
-
require 'reverse_adoc/converters/blockquote'
|
23
|
-
require 'reverse_adoc/converters/bypass'
|
24
|
-
require 'reverse_adoc/converters/br'
|
25
|
-
require 'reverse_adoc/converters/code'
|
26
|
-
require 'reverse_adoc/converters/drop'
|
27
|
-
require 'reverse_adoc/converters/head'
|
28
|
-
require 'reverse_adoc/converters/hr'
|
29
|
-
require 'reverse_adoc/converters/ignore'
|
30
|
-
require 'reverse_adoc/converters/li'
|
31
|
-
require 'reverse_adoc/converters/p'
|
32
|
-
require 'reverse_adoc/converters/pass_through'
|
33
|
-
require 'reverse_adoc/converters/q'
|
34
|
-
require 'reverse_adoc/converters/strong'
|
35
|
-
require 'reverse_adoc/converters/sup'
|
36
|
-
require 'reverse_adoc/converters/sub'
|
37
|
-
require 'reverse_adoc/converters/text'
|
3
|
+
require "reverse_adoc"
|
4
|
+
require "stepmod/utils/converters/arm"
|
5
|
+
require "stepmod/utils/converters/clause_ref"
|
6
|
+
require "stepmod/utils/converters/express_ref"
|
7
|
+
require "stepmod/utils/converters/module_ref"
|
8
|
+
require "stepmod/utils/converters/def"
|
9
|
+
require "stepmod/utils/converters/definition"
|
10
|
+
require "stepmod/utils/converters/em"
|
11
|
+
require "stepmod/utils/converters/example"
|
12
|
+
require "stepmod/utils/converters/note"
|
13
|
+
require "stepmod/utils/converters/ol"
|
14
|
+
require "stepmod/utils/converters/stem"
|
15
|
+
require "stepmod/utils/converters/stepmod_ext_description"
|
16
|
+
require "stepmod/utils/converters/term"
|
17
|
+
require "stepmod/utils/converters/synonym"
|
18
|
+
require "stepmod/utils/converters/uof"
|
19
|
+
require "stepmod/utils/converters/figure"
|
38
20
|
|
21
|
+
require "reverse_adoc/converters/a"
|
22
|
+
require "reverse_adoc/converters/blockquote"
|
23
|
+
require "reverse_adoc/converters/bypass"
|
24
|
+
require "reverse_adoc/converters/br"
|
25
|
+
require "reverse_adoc/converters/code"
|
26
|
+
require "reverse_adoc/converters/drop"
|
27
|
+
require "reverse_adoc/converters/head"
|
28
|
+
require "reverse_adoc/converters/hr"
|
29
|
+
require "reverse_adoc/converters/ignore"
|
30
|
+
require "reverse_adoc/converters/li"
|
31
|
+
require "reverse_adoc/converters/p"
|
32
|
+
require "reverse_adoc/converters/pass_through"
|
33
|
+
require "reverse_adoc/converters/q"
|
34
|
+
require "reverse_adoc/converters/strong"
|
35
|
+
require "reverse_adoc/converters/sup"
|
36
|
+
require "reverse_adoc/converters/sub"
|
37
|
+
require "reverse_adoc/converters/text"
|
39
38
|
|
40
39
|
module Stepmod
|
41
40
|
module Utils
|
@@ -50,11 +49,13 @@ module Stepmod
|
|
50
49
|
input
|
51
50
|
end
|
52
51
|
|
53
|
-
return
|
52
|
+
return "" unless root
|
54
53
|
|
55
54
|
ReverseAdoc.config.with(options) do
|
56
|
-
result = ReverseAdoc::Converters.lookup(root.name).convert(root,
|
57
|
-
|
55
|
+
result = ReverseAdoc::Converters.lookup(root.name).convert(root,
|
56
|
+
options)
|
57
|
+
return "" unless result
|
58
|
+
|
58
59
|
ReverseAdoc.cleaner.tidy(result.dup)
|
59
60
|
end
|
60
61
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "json"
|
2
|
+
require "stepmod/utils/smrl_description_converter"
|
3
|
+
require "stepmod/utils/smrl_resource_converter"
|
4
4
|
|
5
5
|
module Stepmod
|
6
6
|
module Utils
|
@@ -17,35 +17,41 @@ module Stepmod
|
|
17
17
|
|
18
18
|
def call
|
19
19
|
match = File.basename(express_file).match('^(arm|mim|bom)\.exp$')
|
20
|
-
descriptions_base = match ? "#{match.captures[0]}_descriptions.xml" :
|
21
|
-
descriptions_file = File.join(File.dirname(express_file),
|
20
|
+
descriptions_base = match ? "#{match.captures[0]}_descriptions.xml" : "descriptions.xml"
|
21
|
+
descriptions_file = File.join(File.dirname(express_file),
|
22
|
+
descriptions_base)
|
22
23
|
output_express = File.read(express_file)
|
23
24
|
resource_docs_cache = JSON.parse(File.read(resource_docs_cache_file))
|
24
25
|
|
25
26
|
if File.exists?(descriptions_file)
|
26
27
|
descriptions = Nokogiri::XML(File.read(descriptions_file)).root
|
27
28
|
added_resource_descriptions = {}
|
28
|
-
descriptions.xpath(
|
29
|
+
descriptions.xpath("ext_description").each do |description|
|
29
30
|
# Add base resource from linked path if exists, eg "language_schema.language.wr:WR1" -> "language_schema"
|
30
|
-
base_linked = description[
|
31
|
+
base_linked = description["linkend"].to_s.split(".").first
|
31
32
|
if added_resource_descriptions[base_linked].nil?
|
32
|
-
base_reource_doc_dir = resource_docs_cache[description[
|
33
|
+
base_reource_doc_dir = resource_docs_cache[description["linkend"].to_s.split(".").first]
|
33
34
|
if base_reource_doc_dir
|
34
|
-
output_express << convert_from_resource_file(
|
35
|
+
output_express << convert_from_resource_file(
|
36
|
+
base_reource_doc_dir, stepmod_dir, base_linked, descriptions_file
|
37
|
+
)
|
35
38
|
end
|
36
39
|
added_resource_descriptions[base_linked] = true
|
37
40
|
end
|
38
|
-
resource_docs_dir = resource_docs_cache[description[
|
41
|
+
resource_docs_dir = resource_docs_cache[description["linkend"]]
|
39
42
|
# Convert content description
|
40
43
|
# when a schema description is available from resource.xml and also descriptions.xml, the description from resource.xml is only used.
|
41
44
|
# https://github.com/metanorma/annotated-express/issues/32#issuecomment-792609078
|
42
45
|
if description.text.strip.length.positive? && resource_docs_dir.nil?
|
43
|
-
output_express << convert_from_description_text(
|
46
|
+
output_express << convert_from_description_text(
|
47
|
+
descriptions_file, description
|
48
|
+
)
|
44
49
|
end
|
45
50
|
# Add converted description from exact linked path
|
46
|
-
if resource_docs_dir && added_resource_descriptions[description[
|
47
|
-
output_express << convert_from_resource_file(resource_docs_dir,
|
48
|
-
|
51
|
+
if resource_docs_dir && added_resource_descriptions[description["linkend"]].nil?
|
52
|
+
output_express << convert_from_resource_file(resource_docs_dir,
|
53
|
+
stepmod_dir, description["linkend"], descriptions_file)
|
54
|
+
added_resource_descriptions[description["linkend"]] = true
|
49
55
|
end
|
50
56
|
end
|
51
57
|
end
|
@@ -57,20 +63,21 @@ module Stepmod
|
|
57
63
|
|
58
64
|
def convert_from_description_text(descriptions_file, description)
|
59
65
|
Dir.chdir(File.dirname(descriptions_file)) do
|
60
|
-
wrapper = "<ext_descriptions>#{description
|
61
|
-
"\n
|
66
|
+
wrapper = "<ext_descriptions>#{description}</ext_descriptions>"
|
67
|
+
"\n#{Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper)}"
|
62
68
|
end
|
63
69
|
end
|
64
70
|
|
65
71
|
def convert_from_resource_file(resource_docs_dir, stepmod_dir, linked, descriptions_file)
|
66
|
-
resource_docs_file = File.join(stepmod_dir,
|
72
|
+
resource_docs_file = File.join(stepmod_dir, "data/resource_docs",
|
73
|
+
resource_docs_dir, "resource.xml")
|
67
74
|
puts(resource_docs_file)
|
68
75
|
resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
|
69
76
|
schema = resource_docs.xpath("schema[@name='#{linked}']")
|
70
77
|
|
71
78
|
Dir.chdir(File.dirname(descriptions_file)) do
|
72
|
-
wrapper = "<resource>#{schema
|
73
|
-
"\n
|
79
|
+
wrapper = "<resource>#{schema}</resource>"
|
80
|
+
"\n#{Stepmod::Utils::SmrlResourceConverter.convert(wrapper)}"
|
74
81
|
end
|
75
82
|
end
|
76
83
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "stepmod/utils/stepmod_definition_converter"
|
2
|
+
require "stepmod/utils/bibdata"
|
3
|
+
require "stepmod/utils/concept"
|
4
|
+
require "glossarist"
|
5
|
+
require "securerandom"
|
4
6
|
|
5
7
|
ReverseAdoc.config.unknown_tags = :bypass
|
6
8
|
|
@@ -8,21 +10,22 @@ module Stepmod
|
|
8
10
|
module Utils
|
9
11
|
class TermsExtractor
|
10
12
|
# TODO: we may want a command line option to override this in the future
|
11
|
-
ACCEPTED_STAGES = %w(IS DIS FDIS TS)
|
13
|
+
ACCEPTED_STAGES = %w(IS DIS FDIS TS).freeze
|
14
|
+
WITHDRAWN_STATUS = "withdrawn".freeze
|
12
15
|
|
13
16
|
attr_reader :stepmod_path,
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def self.call(stepmod_dir, stdout =
|
17
|
+
:stepmod_dir,
|
18
|
+
:general_concepts,
|
19
|
+
:resource_concepts,
|
20
|
+
:parsed_bibliography,
|
21
|
+
:encountered_terms,
|
22
|
+
:cvs_mode,
|
23
|
+
:part_concepts,
|
24
|
+
:part_resources,
|
25
|
+
:part_modules,
|
26
|
+
:stdout
|
27
|
+
|
28
|
+
def self.call(stepmod_dir, stdout = $stdout)
|
26
29
|
new(stepmod_dir, stdout).call
|
27
30
|
end
|
28
31
|
|
@@ -30,8 +33,8 @@ module Stepmod
|
|
30
33
|
@stdout = stdout
|
31
34
|
@stepmod_dir = stepmod_dir
|
32
35
|
@stepmod_path = Pathname.new(stepmod_dir).realpath
|
33
|
-
@general_concepts =
|
34
|
-
@resource_concepts =
|
36
|
+
@general_concepts = Glossarist::Collection.new
|
37
|
+
@resource_concepts = Glossarist::Collection.new
|
35
38
|
@parsed_bibliography = []
|
36
39
|
@part_concepts = []
|
37
40
|
@part_resources = []
|
@@ -39,13 +42,13 @@ module Stepmod
|
|
39
42
|
@encountered_terms = {}
|
40
43
|
end
|
41
44
|
|
42
|
-
def log
|
45
|
+
def log(message)
|
43
46
|
stdout.puts "[stepmod-utils] #{message}"
|
44
47
|
end
|
45
48
|
|
46
49
|
def term_special_category(bibdata)
|
47
50
|
case bibdata.part.to_i
|
48
|
-
when 41,42,43,44,45,46,47,51
|
51
|
+
when 41, 42, 43, 44, 45, 46, 47, 51
|
49
52
|
true
|
50
53
|
when [56..112]
|
51
54
|
true
|
@@ -56,47 +59,58 @@ module Stepmod
|
|
56
59
|
|
57
60
|
def call
|
58
61
|
# If we are using the stepmod CVS repository, provide the revision number per file
|
59
|
-
@cvs_mode = if Dir.exists?(stepmod_path.join(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
@cvs_mode = if Dir.exists?(stepmod_path.join("CVS"))
|
63
|
+
require "ptools"
|
64
|
+
# ptools provides File.which
|
65
|
+
File.which("cvs")
|
66
|
+
end
|
64
67
|
|
65
68
|
log "INFO: STEPmod directory set to #{stepmod_dir}."
|
66
69
|
|
67
70
|
if cvs_mode
|
68
|
-
log "INFO: STEPmod directory is a
|
69
|
-
|
71
|
+
log "INFO: STEPmod directory is a \
|
72
|
+
CVS repository and will detect revisions."
|
73
|
+
log "INFO: [CVS] Detecting file revisions can be slow, \
|
74
|
+
please be patient!"
|
70
75
|
else
|
71
|
-
log "INFO: STEPmod directory is not a CVS repository,
|
76
|
+
log "INFO: STEPmod directory is not a CVS repository, \
|
77
|
+
skipping revision detection."
|
72
78
|
end
|
73
79
|
|
74
80
|
log "INFO: Detecting paths..."
|
75
81
|
|
76
|
-
repo_index = Nokogiri::XML(File.read(stepmod_path.join(
|
82
|
+
repo_index = Nokogiri::XML(File.read(stepmod_path.join("repository_index.xml"))).root
|
77
83
|
|
78
84
|
files = []
|
79
85
|
|
80
86
|
# add module paths
|
81
|
-
repo_index.xpath(
|
87
|
+
repo_index.xpath("//module").each do |x|
|
88
|
+
next if x['status'] == WITHDRAWN_STATUS
|
89
|
+
|
82
90
|
path = Pathname.new("#{stepmod_dir}/modules/#{x['name']}/module.xml")
|
83
91
|
files << path if File.exists? path
|
84
92
|
end
|
85
93
|
|
86
94
|
# add resource_docs paths
|
87
|
-
repo_index.xpath(
|
95
|
+
repo_index.xpath("//resource_doc").each do |x|
|
96
|
+
next if x['status'] == WITHDRAWN_STATUS
|
97
|
+
|
88
98
|
path = Pathname.new("#{stepmod_dir}/resource_docs/#{x['name']}/resource.xml")
|
89
99
|
files << path if File.exists? path
|
90
100
|
end
|
91
101
|
|
92
102
|
# add business_object_models paths
|
93
|
-
repo_index.xpath(
|
103
|
+
repo_index.xpath("//business_object_model").each do |x|
|
104
|
+
next if x['status'] == WITHDRAWN_STATUS
|
105
|
+
|
94
106
|
path = Pathname.new("#{stepmod_dir}/business_object_models/#{x['name']}/business_object_model.xml")
|
95
107
|
files << path if File.exists? path
|
96
108
|
end
|
97
109
|
|
98
110
|
# add application_protocols paths
|
99
|
-
repo_index.xpath(
|
111
|
+
repo_index.xpath("//application_protocol").each do |x|
|
112
|
+
next if x['status'] == WITHDRAWN_STATUS
|
113
|
+
|
100
114
|
path = Pathname.new("#{stepmod_dir}/application_protocols/#{x['name']}/application_protocol.xml")
|
101
115
|
files << path if File.exists? path
|
102
116
|
end
|
@@ -110,7 +124,7 @@ module Stepmod
|
|
110
124
|
parsed_bibliography,
|
111
125
|
part_concepts,
|
112
126
|
part_resources,
|
113
|
-
part_modules
|
127
|
+
part_modules,
|
114
128
|
]
|
115
129
|
end
|
116
130
|
|
@@ -128,13 +142,14 @@ module Stepmod
|
|
128
142
|
bibdata = nil
|
129
143
|
begin
|
130
144
|
bibdata = Stepmod::Utils::Bibdata.new(document: current_document)
|
131
|
-
rescue
|
145
|
+
rescue StandardError
|
132
146
|
log "WARNING: Unknown file #{fpath}, skipped"
|
133
147
|
next
|
134
148
|
end
|
135
149
|
|
136
150
|
unless ACCEPTED_STAGES.include? bibdata.doctype
|
137
|
-
log "INFO: skipped #{bibdata.docid} as it is not
|
151
|
+
log "INFO: skipped #{bibdata.docid} as it is not \
|
152
|
+
one of (#{ACCEPTED_STAGES.join(', ')})."
|
138
153
|
next
|
139
154
|
end
|
140
155
|
|
@@ -153,9 +168,12 @@ module Stepmod
|
|
153
168
|
status = `cvs status #{fpath}`
|
154
169
|
|
155
170
|
unless status.empty?
|
156
|
-
working_rev = status.split(/\n/).grep(/Working revision:/)
|
157
|
-
|
158
|
-
|
171
|
+
working_rev = status.split(/\n/).grep(/Working revision:/)
|
172
|
+
.first.match(/revision:\s+(.+)$/)[1]
|
173
|
+
repo_rev = status.split(/\n/).grep(/Repository revision:/)
|
174
|
+
.first.match(/revision:\t(.+)\t/)[1]
|
175
|
+
log "INFO: CVS working rev (#{working_rev}), \
|
176
|
+
repo rev (#{repo_rev})"
|
159
177
|
revision_string = "\n// CVS working rev: (#{working_rev}), repo rev (#{repo_rev})\n" +
|
160
178
|
"// CVS: revision #{working_rev == repo_rev ? 'up to date' : 'differs'}"
|
161
179
|
end
|
@@ -163,11 +181,11 @@ module Stepmod
|
|
163
181
|
end
|
164
182
|
|
165
183
|
# read definitions
|
166
|
-
current_part_concepts =
|
184
|
+
current_part_concepts = Glossarist::Collection.new
|
167
185
|
definition_index = 0
|
168
|
-
current_document.xpath(
|
186
|
+
current_document.xpath("//definition").each do |definition|
|
169
187
|
definition_index += 1
|
170
|
-
term_id = definition[
|
188
|
+
term_id = definition["id"]
|
171
189
|
unless term_id.nil?
|
172
190
|
if encountered_terms[term_id]
|
173
191
|
log "FATAL: Duplicated term with id: #{term_id}, #{fpath}"
|
@@ -183,22 +201,22 @@ module Stepmod
|
|
183
201
|
definition,
|
184
202
|
reference_anchor: bibdata.anchor,
|
185
203
|
reference_clause: ref_clause,
|
186
|
-
file_path: fpath + revision_string
|
204
|
+
file_path: fpath + revision_string,
|
187
205
|
)
|
188
206
|
next unless concept
|
189
207
|
|
190
|
-
|
191
|
-
# log "INFO: this part is generic"
|
192
|
-
general_concepts << concept
|
193
|
-
else
|
208
|
+
if term_special_category(bibdata)
|
194
209
|
# log "INFO: this part is special"
|
195
|
-
current_part_concepts
|
210
|
+
find_or_initialize_concept(current_part_concepts, concept)
|
211
|
+
else
|
212
|
+
# log "INFO: this part is generic"
|
213
|
+
find_or_initialize_concept(general_concepts, concept)
|
196
214
|
end
|
197
215
|
|
198
216
|
parsed_bibliography << bibdata
|
199
217
|
end
|
200
218
|
|
201
|
-
current_part_resources =
|
219
|
+
current_part_resources = Glossarist::Collection.new
|
202
220
|
current_part_modules_arm = {}
|
203
221
|
current_part_modules_mim = {}
|
204
222
|
|
@@ -207,10 +225,12 @@ module Stepmod
|
|
207
225
|
when /resource.xml$/
|
208
226
|
log "INFO: Processing resource.xml for #{file_path}"
|
209
227
|
# Assumption: every schema is only linked by a single resource_docs document.
|
210
|
-
current_document.xpath(
|
211
|
-
schema_name = schema_node[
|
228
|
+
current_document.xpath("//schema").each do |schema_node|
|
229
|
+
schema_name = schema_node["name"]
|
212
230
|
if parsed_schema_names[schema_name]
|
213
|
-
log "ERROR: We have encountered this schema before:
|
231
|
+
log "ERROR: We have encountered this schema before: \
|
232
|
+
#{schema_name} from path \
|
233
|
+
#{parsed_schema_names[schema_name]}, now at #{file_path}"
|
214
234
|
next
|
215
235
|
else
|
216
236
|
parsed_schema_names[schema_name] = file_path
|
@@ -219,24 +239,24 @@ module Stepmod
|
|
219
239
|
Dir["#{stepmod_path}/resources/#{schema_name}/descriptions.xml"].each do |description_xml_path|
|
220
240
|
log "INFO: Processing resources schema #{description_xml_path}"
|
221
241
|
description_document = Nokogiri::XML(File.read(description_xml_path)).root
|
222
|
-
description_document.xpath(
|
223
|
-
|
242
|
+
description_document.xpath("//ext_description").each do |ext_description|
|
224
243
|
# log "INFO: Processing linkend[#{ext_description['linkend']}]"
|
225
244
|
|
226
245
|
concept = Stepmod::Utils::Concept.parse(
|
227
246
|
ext_description,
|
228
247
|
reference_anchor: bibdata.anchor,
|
229
248
|
reference_clause: nil,
|
230
|
-
file_path: Pathname.new(description_xml_path)
|
249
|
+
file_path: Pathname.new(description_xml_path)
|
250
|
+
.relative_path_from(stepmod_path),
|
231
251
|
)
|
232
252
|
next unless concept
|
233
253
|
|
234
|
-
|
235
|
-
# log "INFO: this part is generic"
|
236
|
-
resource_concepts << concept
|
237
|
-
else
|
254
|
+
if term_special_category(bibdata)
|
238
255
|
# log "INFO: this part is special"
|
239
|
-
current_part_resources
|
256
|
+
find_or_initialize_concept(current_part_resources, concept)
|
257
|
+
else
|
258
|
+
# log "INFO: this part is generic"
|
259
|
+
find_or_initialize_concept(resource_concepts, concept)
|
240
260
|
end
|
241
261
|
|
242
262
|
parsed_bibliography << bibdata
|
@@ -248,9 +268,11 @@ module Stepmod
|
|
248
268
|
log "INFO: Processing module.xml for #{file_path}"
|
249
269
|
# Assumption: every schema is only linked by a single module document.
|
250
270
|
# puts current_document.xpath('//module').length
|
251
|
-
schema_name = current_document.xpath(
|
271
|
+
schema_name = current_document.xpath("//module").first["name"]
|
252
272
|
if parsed_schema_names[schema_name]
|
253
|
-
log "ERROR: We have encountered this schema before:
|
273
|
+
log "ERROR: We have encountered this schema before: \
|
274
|
+
#{schema_name} from path #{parsed_schema_names[schema_name]}, \
|
275
|
+
now at #{file_path}"
|
254
276
|
next
|
255
277
|
else
|
256
278
|
parsed_schema_names[schema_name] = file_path
|
@@ -260,20 +282,25 @@ module Stepmod
|
|
260
282
|
log "INFO: Processing modules schema #{description_xml_path}"
|
261
283
|
|
262
284
|
if File.exists?(description_xml_path)
|
263
|
-
description_document = Nokogiri::XML(
|
264
|
-
|
265
|
-
|
266
|
-
|
285
|
+
description_document = Nokogiri::XML(
|
286
|
+
File.read(description_xml_path),
|
287
|
+
)
|
288
|
+
.root
|
289
|
+
description_document.xpath("//ext_description").each do |ext_description|
|
290
|
+
linkend_schema = ext_description["linkend"].split(".").first
|
267
291
|
concept = Stepmod::Utils::Concept.parse(
|
268
292
|
ext_description,
|
269
293
|
reference_anchor: bibdata.anchor,
|
270
294
|
reference_clause: nil,
|
271
|
-
file_path: Pathname.new(description_xml_path)
|
295
|
+
file_path: Pathname.new(description_xml_path)
|
296
|
+
.relative_path_from(stepmod_path),
|
272
297
|
)
|
273
298
|
next unless concept
|
274
299
|
|
275
|
-
current_part_modules_arm[linkend_schema] ||=
|
276
|
-
|
300
|
+
current_part_modules_arm[linkend_schema] ||= Glossarist::Collection.new
|
301
|
+
find_or_initialize_concept(
|
302
|
+
current_part_modules_arm[linkend_schema], concept
|
303
|
+
)
|
277
304
|
# puts part_modules_arm.inspect
|
278
305
|
parsed_bibliography << bibdata
|
279
306
|
end
|
@@ -283,21 +310,28 @@ module Stepmod
|
|
283
310
|
log "INFO: Processing modules schema #{description_xml_path}"
|
284
311
|
|
285
312
|
if File.exists?(description_xml_path)
|
286
|
-
description_document = Nokogiri::XML(
|
287
|
-
|
288
|
-
|
289
|
-
|
313
|
+
description_document = Nokogiri::XML(
|
314
|
+
File.read(description_xml_path),
|
315
|
+
)
|
316
|
+
.root
|
317
|
+
description_document.xpath("//ext_description").each do |ext_description|
|
318
|
+
linkend_schema = ext_description["linkend"].split(".").first
|
290
319
|
|
291
320
|
concept = Stepmod::Utils::Concept.parse(
|
292
321
|
ext_description,
|
293
322
|
reference_anchor: bibdata.anchor,
|
294
323
|
reference_clause: nil,
|
295
|
-
file_path: Pathname
|
324
|
+
file_path: Pathname
|
325
|
+
.new(description_xml_path)
|
326
|
+
.relative_path_from(stepmod_path),
|
296
327
|
)
|
297
328
|
next unless concept
|
298
329
|
|
299
|
-
current_part_modules_mim[linkend_schema] ||=
|
300
|
-
|
330
|
+
current_part_modules_mim[linkend_schema] ||=
|
331
|
+
Glossarist::Collection.new
|
332
|
+
find_or_initialize_concept(
|
333
|
+
current_part_modules_mim[linkend_schema], concept
|
334
|
+
)
|
301
335
|
|
302
336
|
parsed_bibliography << bibdata
|
303
337
|
end
|
@@ -306,21 +340,39 @@ module Stepmod
|
|
306
340
|
end
|
307
341
|
|
308
342
|
log "INFO: Completed processing XML file #{fpath}"
|
309
|
-
if current_part_concepts.empty?
|
310
|
-
log "INFO: Skipping #{fpath} (#{bibdata.docid})
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
343
|
+
if current_part_concepts.to_a.empty?
|
344
|
+
log "INFO: Skipping #{fpath} (#{bibdata.docid}) \
|
345
|
+
because it contains no concepts."
|
346
|
+
elsif current_part_concepts.to_a.length < 3
|
347
|
+
log "INFO: Skipping #{fpath} (#{bibdata.docid}) \
|
348
|
+
because it only has #{current_part_concepts.to_a.length} terms."
|
349
|
+
|
350
|
+
current_part_concepts.to_a.each do |x|
|
351
|
+
general_concepts.store(x)
|
316
352
|
end
|
317
353
|
else
|
318
|
-
|
354
|
+
unless current_part_concepts.to_a.empty?
|
355
|
+
part_concepts << [bibdata,
|
356
|
+
current_part_concepts]
|
357
|
+
end
|
358
|
+
end
|
359
|
+
unless current_part_resources.to_a.empty?
|
360
|
+
part_resources << [bibdata,
|
361
|
+
current_part_resources]
|
362
|
+
end
|
363
|
+
if (current_part_modules_arm.to_a.size +
|
364
|
+
current_part_modules_mim.to_a.size).positive?
|
365
|
+
part_modules << [bibdata, current_part_modules_arm,
|
366
|
+
current_part_modules_mim]
|
319
367
|
end
|
320
|
-
part_resources << [bibdata, current_part_resources] unless current_part_resources.empty?
|
321
|
-
part_modules << [bibdata, current_part_modules_arm, current_part_modules_mim] if current_part_modules_arm.size + current_part_modules_mim.size > 0
|
322
368
|
end
|
323
369
|
end
|
370
|
+
|
371
|
+
def find_or_initialize_concept(collection, localized_concept)
|
372
|
+
concept = collection
|
373
|
+
.store(Glossarist::Concept.new(id: SecureRandom.uuid))
|
374
|
+
concept.add_l10n(localized_concept)
|
375
|
+
end
|
324
376
|
end
|
325
377
|
end
|
326
378
|
end
|