Class: Metanorma::Ogc::Converter

Inherits:
Standoc::Converter
  • Object
show all
Defined in:
lib/metanorma/ogc/converter.rb,
lib/metanorma/ogc/front.rb,
lib/metanorma/ogc/cleanup.rb,
lib/metanorma/ogc/validate.rb

Overview

A Converter implementation that generates RSD output, and a document schema encapsulation of the document for validation

Constant Summary collapse

PUBLISHER =
"./contributor[role/@type = 'publisher']/organization".freeze
OTHERIDS =
"@type = 'DOI' or @type = 'metanorma' or @type = 'ISSN' or "\
"@type = 'ISBN'".freeze
STANDARDTYPE =
%w{standard standard-with-suite abstract-specification
community-standard profile}.freeze
SEQ =

spec of permissible section sequence we skip normative references, it goes to end of list

[
  {
    msg: "Prefatory material must be followed by (clause) Scope",
    val: ["./self::clause[@type = 'scope']"],
  },
  {
    msg: "Scope must be followed by Conformance",
    val: ["./self::clause[@type = 'conformance']"],
  },
  {
    msg: "Normative References must be followed by "\
         "Terms and Definitions",
    val: ["./self::terms | .//terms"],
  },
].freeze
XML_ROOT_TAG =
"ogc-standard".freeze
XML_NAMESPACE =
"https://www.metanorma.org/ns/ogc".freeze

Instance Method Summary collapse

Instance Method Details

#add_idObject



18
19
20
# File 'lib/metanorma/ogc/cleanup.rb', line 18

def add_id
  %(id="_#{UUIDTools::UUID.random_create}")
end

#author_title_key(pubclass, title, bib) ⇒ Object



180
181
182
183
184
185
186
187
188
# File 'lib/metanorma/ogc/cleanup.rb', line 180

def author_title_key(pubclass, title, bib)
  case pubclass
  when 1, 2 then title
  when 3
    cite = ::Relaton::Render::General.new
      .render_all("<references>#{bib.to_xml}</references>")
    cite[:author]
  end
end

#bibdata_cleanup(xmldoc) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/metanorma/ogc/cleanup.rb', line 57

def bibdata_cleanup(xmldoc)
  super
  a = xmldoc.at("//bibdata/status/stage")
  a.text == "published" and a.children = "approved"
  doctype = xmldoc.at("//bibdata/ext/doctype")
  doctype.text == "technical-paper" and
    doctype.children = "white-paper"
end

#bibdata_validate(doc) ⇒ Object



19
20
21
22
# File 'lib/metanorma/ogc/validate.rb', line 19

def bibdata_validate(doc)
  stage_validate(doc)
  version_validate(doc)
end

#clause_parse(attrs, xml, node) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/metanorma/ogc/converter.rb', line 85

def clause_parse(attrs, xml, node)
  case node&.attr("heading")&.downcase || node.title.downcase
  when "submitters" then return submitters_parse(attrs, xml, node)
  when "conformance" then attrs = attrs.merge(type: "conformance")
  when "security considerations"
    attrs = attrs.merge(type: "security")
  when "executive summary"
    attrs = attrs.merge(type: "executivesummary")
  end
  super
end

#content_validate(doc) ⇒ Object



14
15
16
17
# File 'lib/metanorma/ogc/validate.rb', line 14

def content_validate(doc)
  super
  bibdata_validate(doc.root)
end

#corporate_author(node, xml) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/metanorma/ogc/front.rb', line 13

def corporate_author(node, xml)
  return unless node.attr("submitting-organizations")

  csv_split(HTMLEntities.new
    .decode(node.attr("submitting-organizations")), ";")&.each do |org|
    xml.contributor do |c|
      c.role **{ type: "author" }
      c.organization do |a|
        a.name org
      end
    end
  end
end

#default_publisherObject



80
81
82
# File 'lib/metanorma/ogc/front.rb', line 80

def default_publisher
  "Open Geospatial Consortium"
end

#default_requirement_modelObject



29
30
31
# File 'lib/metanorma/ogc/converter.rb', line 29

def default_requirement_model
  "ogc"
end

#doc_converter(node) ⇒ Object



162
163
164
# File 'lib/metanorma/ogc/converter.rb', line 162

def doc_converter(node)
  IsoDoc::Ogc::WordConvert.new(doc_extract_attributes(node))
end

#doctype(node) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/metanorma/ogc/converter.rb', line 38

def doctype(node)
  d = super
  d1 = ::IsoDoc::Ogc::DOCTYPE_ABBR.invert[d] and d = d1
  unless %w{abstract-specification-topic best-practice other policy
            change-request-supporting-document community-practice
            community-standard discussion-paper engineering-report
            reference-model release-notes standard user-guide white-paper
            technical-paper test-suite}.include? d
    @warned_doctype or
      @log.add("Document Attributes", nil,
               "'#{d}' is not a legal document type: reverting to 'standard'")
    @warned_doctype = true
    d = "standard"
  end
  d
end

#execsummary_validate(xmldoc) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/metanorma/ogc/validate.rb', line 60

def execsummary_validate(xmldoc)
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
  sect = xmldoc&.at("//clause[@type = 'executivesummary']")
  doctype == "engineering-report" && sect.nil? and
    @log.add("Style", nil,
             "Executive Summary required for Engineering Reports!")
  doctype != "engineering-report" && !sect.nil? and
    @log.add("Style", nil,
             "Executive Summary only allowed for Engineering Reports!")
end

#externalid(node) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/metanorma/ogc/front.rb', line 100

def externalid(node)
  return node.attr("external-id") if node.attr("external-id")

  d = doctype(node)
  a = node.attr("abbrev")
  return unless d && a

  url = "http://www.opengis.net/doc/#{IsoDoc::Ogc::DOCTYPE_ABBR[d]}/#{a}"
  v = (node.attr("edition") || node.attr("version")) and url += "/#{v}"
  url
end

#externalurl(node) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/metanorma/ogc/front.rb', line 123

def externalurl(node)
  if doctype(node) == "engineering-report"
    "http://www.opengis.net/doc/PER/t14-#{node.attr('referenceurlid')}"
  else
    node.attr("referenceurlid")
  end
end

#highlight_parse(text, xml) ⇒ Object



134
135
136
# File 'lib/metanorma/ogc/converter.rb', line 134

def highlight_parse(text, xml)
  xml.hi { |s| s << text }
end

#html_converter(node) ⇒ Object



152
153
154
# File 'lib/metanorma/ogc/converter.rb', line 152

def html_converter(node)
  IsoDoc::Ogc::HtmlConvert.new(html_extract_attributes(node))
end

#init_toc(node) ⇒ Object



19
20
21
22
23
24
# File 'lib/metanorma/ogc/converter.rb', line 19

def init_toc(node)
  super
  @tocfigures = true
  @toctables = true
  @tocrecommendations = true
end

#insert_execsummary(xml, sect) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/metanorma/ogc/cleanup.rb', line 22

def insert_execsummary(xml, sect)
  summ = xml&.at("//clause[@type = 'executivesummary']")&.remove or
    return
  preface = sect.at("//preface") ||
    sect.add_previous_sibling("<preface/>").first
  preface.add_child summ
end

#insert_security(xml, sect) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/metanorma/ogc/cleanup.rb', line 30

def insert_security(xml, sect)
  description = "document"
  description = "standard" if %w(standard community-standard)
    .include?(sect&.at("//bibdata/ext/doctype")&.text)
  preface = sect.at("//preface") ||
    sect.add_previous_sibling("<preface/>").first
  sect = xml&.at("//clause[@type = 'security']")&.remove ||
    "<clause type='security' #{add_id}>"\
    "<title>Security considerations</title>"\
    "<p>#{@i18n.security_empty.sub(/%/, description)}</p></clause>"
  preface.add_child sect
end

#insert_submitters(xml, sect) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/metanorma/ogc/cleanup.rb', line 43

def insert_submitters(xml, sect)
  if xml.at("//submitters")
    preface = sect.at("//preface") ||
      sect.add_previous_sibling("<preface/>").first
    submitters = xml.at("//submitters").remove
    submitters.xpath(".//table").each do |t|
      t["unnumbered"] = true
    end
    preface.add_child submitters.remove
  end
end

#make_preface(xml, sect) ⇒ Object



11
12
13
14
15
16
# File 'lib/metanorma/ogc/cleanup.rb', line 11

def make_preface(xml, sect)
  super
  insert_execsummary(xml, sect)
  insert_security(xml, sect)
  insert_submitters(xml, sect)
end

#makexml(node) ⇒ Object



33
34
35
36
# File 'lib/metanorma/ogc/converter.rb', line 33

def makexml(node)
  @draft = node.attributes.has_key?("draft")
  super
end

#metadata_author(node, xml) ⇒ Object



8
9
10
11
# File 'lib/metanorma/ogc/front.rb', line 8

def (node, xml)
  corporate_author(node, xml)
  personal_author(node, xml)
end

#metadata_committee(node, xml) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/metanorma/ogc/front.rb', line 84

def (node, xml)
  return unless node.attr("committee")

  xml.editorialgroup do |a|
    a.committee(node.attr("committee") || "technical")
    node.attr("subcommittee") and
      a.subcommittee(node.attr("subcommittee"),
                     **attr_code(type: node.attr("subcommittee-type"),
                                 number: node.attr("subcommittee-number")))
    (node.attr("workgroup") || node.attr("workinggroup")) and
      a.workgroup(node.attr("workgroup") || node.attr("workinggroup"),
                  **attr_code(type: node.attr("workgroup-type"),
                              number: node.attr("workgroup-number")))
  end
end


137
138
139
140
141
# File 'lib/metanorma/ogc/front.rb', line 137

def (node, xml)
  node.attr("copyrightyear") and
    node.set_attr("copyright-year", node.attr("copyrightyear"))
  super
end

#metadata_date(node, xml) ⇒ Object



143
144
145
146
147
148
# File 'lib/metanorma/ogc/front.rb', line 143

def (node, xml)
  super
  ogc_date(node, xml, "submissiondate", "received")
  ogc_date(node, xml, "publicationdate", "published")
  ogc_date(node, xml, "approvaldate", "issued")
end

#metadata_ext(node, xml) ⇒ Object



196
197
198
199
200
# File 'lib/metanorma/ogc/front.rb', line 196

def (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
end

#metadata_id(node, xml) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'lib/metanorma/ogc/front.rb', line 112

def (node, xml)
  e = externalid(node) and xml.docidentifier e, **{ type: "ogc-external" }
  node.attr("referenceurlid") and
    xml.docidentifier externalurl(node), **{ type: "ogc-external" }
  docnumber = node.attr("docnumber") || node.attr("docreference")
  if docnumber
    xml.docidentifier docnumber, **{ type: "ogc-internal" }
    xml.docnumber docnumber
  end
end

#metadata_source(node, xml) ⇒ Object



131
132
133
134
135
# File 'lib/metanorma/ogc/front.rb', line 131

def (node, xml)
  super
  node.attr("previous-uri") && xml.uri(node.attr("previous-uri"),
                                       type: "previous")
end

#metadata_subdoctype(node, xml) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/metanorma/ogc/front.rb', line 164

def (node, xml)
  s = node.attr("docsubtype")
  s1 = ::IsoDoc::Ogc::DOCSUBTYPE_ABBR.invert[s] and s = s1
  case doctype(node)
  when "standard"
    unless %w{conceptual-model conceptual-model-and-encoding
              conceptual-model-and-implementation encoding extension
              implementation profile profile-with-extension}.include? s
      @log.add("Document Attributes", nil,
               "'#{s}' is not a permitted subtype of Standard: "\
               "reverting to 'implementation'")
      s = "implementation"
    end
  when "best-practice"
    unless %w{general encoding extension profile
              profile-with-extension}.include? s
      @log.add("Document Attributes", nil,
               "'#{s}' is not a permitted subtype of Standard: "\
               "reverting to 'implementation'")
      s = "general"
    end
  end
  s and xml.subdoctype s
end

#metadata_version(node, xml) ⇒ Object



158
159
160
161
162
# File 'lib/metanorma/ogc/front.rb', line 158

def (node, xml)
  node.attr("version") and
    node.set_attr("edition", node.attr("version"), false)
  super
end

#normref_cleanup(xmldoc) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/metanorma/ogc/cleanup.rb', line 103

def normref_cleanup(xmldoc)
  r1 = xmldoc.at("//references[title[translate(text(), 'R', 'r') = "\
                 "'Normative references']]")
  r2 = xmldoc.at("//references[title[text() = 'References']]")
  if r1 && r2
    r2["normative"] = false
  end
  super
end

#obligations_cleanup_inherit(xml) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/metanorma/ogc/cleanup.rb', line 113

def obligations_cleanup_inherit(xml)
  xml.xpath("//annex").each do |r|
    r["obligation"] = "informative" unless r["obligation"]
  end
  xml.xpath("//clause[not(ancestor::boilerplate)]").each do |r|
    r["obligation"] = "normative" unless r["obligation"]
  end
  xml.xpath(::Metanorma::Standoc::Utils::SUBCLAUSE_XPATH).each do |r|
    o = r&.at("./ancestor::*/@obligation")&.text and r["obligation"] = o
  end
end

#ogc_date(node, xml, ogcname, metanormaname) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/metanorma/ogc/front.rb', line 150

def ogc_date(node, xml, ogcname, metanormaname)
  if node.attr(ogcname)
    xml.date **{ type: metanormaname } do |d|
      d.on node.attr(ogcname)
    end
  end
end

#ogc_editor(node, xml) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/metanorma/ogc/front.rb', line 51

def ogc_editor(node, xml)
  return unless node.attr("editor")

  xml.contributor do |c|
    c.role **{ type: "editor" }
    c.person do |p|
      p.name do |n|
        n.completename node.attr("editor")
      end
    end
  end
end

#outputs(node, ret) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/metanorma/ogc/converter.rb', line 74

def outputs(node, ret)
  File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
  presentation_xml_converter(node).convert("#{@filename}.xml")
  html_converter(node).convert("#{@filename}.presentation.xml", nil,
                               false, "#{@filename}.html")
  doc_converter(node).convert("#{@filename}.presentation.xml", nil,
                              false, "#{@filename}.doc")
  pdf_converter(node)&.convert("#{@filename}.presentation.xml", nil,
                               false, "#{@filename}.pdf")
end

#pdf_converter(node) ⇒ Object



156
157
158
159
160
# File 'lib/metanorma/ogc/converter.rb', line 156

def pdf_converter(node)
  return nil if node.attr("no-pdf")

  IsoDoc::Ogc::PdfConvert.new(pdf_extract_attributes(node))
end

#personal_author(node, xml) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/metanorma/ogc/front.rb', line 27

def personal_author(node, xml)
  ogc_editor(node, xml)
  if node.attr("fullname") || node.attr("surname")
    personal_author1(node, xml, "")
  end
  i = 2
  while node.attr("fullname_#{i}") || node.attr("surname_#{i}")
    personal_author1(node, xml, "_#{i}")
    i += 1
  end
end

#personal_author1(node, xml, suffix) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/metanorma/ogc/front.rb', line 64

def personal_author1(node, xml, suffix)
  xml.contributor do |c|
    personal_role(node, c, suffix)
    c.person do |p|
      p.name do |n|
        if node.attr("fullname#{suffix}")
          n.completename node.attr("fullname#{suffix}")
        else
          n.forename node.attr("givenname#{suffix}")
          n.surname node.attr("surname#{suffix}")
        end
      end
    end
  end
end

#personal_role(node, contrib, suffix) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/metanorma/ogc/front.rb', line 39

def personal_role(node, contrib, suffix)
  type = node.attr("role#{suffix}")&.downcase || "editor"
  if type == "contributor"
    contrib.role **{ type: "author" } do |r|
      r.description do |d|
        d << type
      end
    end
  else contrib.role **{ type: type }
  end
end

#preface_sequence_validate(root) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/metanorma/ogc/validate.rb', line 134

def preface_sequence_validate(root)
  root.at("//preface/abstract") or @log.add("Style", nil,
                                            "Abstract is missing!")
  root.at("//bibdata/keyword | //bibdata/ext/keyword") or
    @log.add("Style", nil, "Keywords are missing!")
  root.at("//foreword") or @log.add("Style", nil,
                                    "Preface is missing!")
  root.at("//bibdata/contributor[role/@type = 'author']/organization/"\
          "name") or
    @log.add("Style", nil, "Submitting Organizations is missing!")
  root.at("//submitters") or @log.add("Style", nil,
                                      "Submitters is missing!")
end

#presentation_xml_converter(node) ⇒ Object



148
149
150
# File 'lib/metanorma/ogc/converter.rb', line 148

def presentation_xml_converter(node)
  IsoDoc::Ogc::PresentationXMLConvert.new(html_extract_attributes(node))
end

#pub_class(bib) ⇒ Object



151
152
153
154
155
156
157
158
# File 'lib/metanorma/ogc/cleanup.rb', line 151

def pub_class(bib)
  return 1 if bib.at("#{PUBLISHER}[abbreviation = 'OGC']")
  return 1 if bib.at("#{PUBLISHER}[name = 'Open Geospatial "\
                     "Consortium']")
  return 2 if bib.at("./docidentifier[@type][not(#{OTHERIDS})]")

  3
end

#section_names_terms_cleanup(xml) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/metanorma/ogc/cleanup.rb', line 66

def section_names_terms_cleanup(xml)
  replace_title(xml, "//definitions[@type = 'symbols']", @i18n&.symbols)
  replace_title(xml, "//definitions[@type = 'abbreviated_terms']",
                @i18n&.abbrev)
  replace_title(xml, "//definitions[not(@type)]", @i18n&.symbolsabbrev)
  replace_title(xml, "//sections//terms#{SYMnoABBR} | "\
                     "//sections//clause[.//terms]#{SYMnoABBR}",
                @i18n&.termsdefsymbols, true)
  replace_title(xml, "//sections//terms#{ABBRnoSYM} | "\
                     "//sections//clause[.//terms]#{ABBRnoSYM}",
                @i18n&.termsdefabbrev, true)
  replace_title(xml, "//sections//terms#{SYMABBR} | "\
                     "//sections//clause[.//terms]#{SYMABBR}",
                @i18n&.termsdefsymbolsabbrev, true)
  replace_title(xml, "//sections//terms#{NO_SYMABBR} | "\
                     "//sections//clause[.//terms]#{NO_SYMABBR}",
                @i18n&.termsdefsymbolsabbrev, true)
  replace_title(xml, "//sections//terms[not(.//definitions)] | "\
                     "//sections//clause[.//terms][not(.//definitions)]",
                @i18n&.termsdef, true)
end

#section_validate(doc) ⇒ Object



71
72
73
74
75
76
# File 'lib/metanorma/ogc/validate.rb', line 71

def section_validate(doc)
  preface_sequence_validate(doc.root)
  execsummary_validate(doc.root)
  sections_sequence_validate(doc.root)
  super
end

#sections_cleanup(xml) ⇒ Object



4
5
6
7
8
9
# File 'lib/metanorma/ogc/cleanup.rb', line 4

def sections_cleanup(xml)
  super
  xml.xpath("//*[@inline-header]").each do |h|
    h.delete("inline-header")
  end
end

#sections_order_cleanup(xml) ⇒ Object



125
126
127
128
# File 'lib/metanorma/ogc/cleanup.rb', line 125

def sections_order_cleanup(xml)
  super
  sort_annexes(xml)
end

#sections_sequence_validate(root) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/metanorma/ogc/validate.rb', line 111

def sections_sequence_validate(root)
  return unless STANDARDTYPE.include?(
    root&.at("//bibdata/ext/doctype")&.text,
  )

  names = root.xpath("//sections/* | //bibliography/*")
  names = seqcheck(names, SEQ[0][:msg], SEQ[0][:val])
  names = seqcheck(names, SEQ[1][:msg], SEQ[1][:val])
  names = seqcheck(names, SEQ[2][:msg], SEQ[2][:val])
  n = names.shift
  if n&.at("./self::definitions")
    n = names.shift
  end
  if n.nil? || n.name != "clause"
    @log.add("Style", nil,
             "Document must contain at least one clause")
    return
  end
  root.at("//references | //clause[descendant::references]"\
          "[not(parent::clause)]") or
    @log.add("Style", nil, "Normative References are mandatory")
end

#sectiontype(node, level = true) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/metanorma/ogc/converter.rb', line 55

def sectiontype(node, level = true)
  ret = sectiontype_streamline(sectiontype1(node))
  return ret if ret == "terms and definitions" &&
    node.attr("style") == "appendix" && node.level == 1

  super
end

#sectiontype_streamline(ret) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/metanorma/ogc/converter.rb', line 63

def sectiontype_streamline(ret)
  case ret
  when "preface" then "foreword"
  when "foreword", "introduction" then "donotrecognise-foreword"
  when "references" then "normative references"
  when "glossary" then "terms and definitions"
  else
    super
  end
end

#seqcheck(names, msg, accepted) ⇒ Object



100
101
102
103
104
105
106
107
108
109
# File 'lib/metanorma/ogc/validate.rb', line 100

def seqcheck(names, msg, accepted)
  n = names.shift
  return [] if n.nil?

  test = accepted.map { |a| n.at(a) }
  if test.all?(&:nil?)
    @log.add("Style", nil, msg)
  end
  names
end

#set_obligation(attrs, node) ⇒ Object



138
139
140
141
142
143
144
145
146
# File 'lib/metanorma/ogc/converter.rb', line 138

def set_obligation(attrs, node)
  if node.attr("style") == "appendix" && node.level == 1
    attrs[:obligation] = if node.attributes.has_key?("obligation")
                           node.attr("obligation")
                         else "informative"
                         end
  else super
  end
end

#sort_annexes(xml) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/metanorma/ogc/cleanup.rb', line 130

def sort_annexes(xml)
  last = xml.at("//annex[last()]") or return
  last.next = "<sentinel/>" and last = last.next_element
  gl = xml.at("//annex[.//term]") and last.previous = gl.remove
  rev = xml.at("//annex[title[normalize-space(.) = 'Revision history']]") ||
    xml.at("//annex[title[normalize-space(.) = 'Revision History']]") and
    last.previous = rev.remove
  last.remove
end

#sort_biblio(bib) ⇒ Object



140
141
142
143
144
# File 'lib/metanorma/ogc/cleanup.rb', line 140

def sort_biblio(bib)
  bib.sort do |a, b|
    sort_biblio_key(a) <=> sort_biblio_key(b)
  end
end

#sort_biblio_ids_key(bib) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
# File 'lib/metanorma/ogc/cleanup.rb', line 196

def sort_biblio_ids_key(bib)
  id = bib.at("./docidentifier[@primary]") ||
    bib.at("./docidentifier[not(#{OTHERIDS})]")
  metaid = bib.at("./docidentifier[@type = 'metanorma']")&.text
  /\d-(?<partid>\d+)/ =~ id&.text
  { id: id&.text,
    num: bib.at("./docnumber")&.text,
    abbrid: /^\[\d+\]$/.match?(metaid) ? metaid : nil,
    partid: partid&.to_i || 0,
    type: id ? id["type"] : nil }
end

#sort_biblio_key(bib) ⇒ Object

sort by: doc class (OGC, other standard (not DOI &c), other then standard class (docid class other than DOI &c) then if OGC, doc title else if other, authors then docnumber if present, numeric sort

else alphanumeric metanorma id (abbreviation)

then doc part number if present, numeric sort then doc id (not DOI &c) then title



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/metanorma/ogc/cleanup.rb', line 168

def sort_biblio_key(bib)
  pubclass = pub_class(bib)
  ids = sort_biblio_ids_key(bib)
  title = title_key(bib)
  sortkey3 = author_title_key(pubclass, title, bib)
  num = if ids[:num].nil? then ids[:abbrid]
        else sprintf("%09d", ids[:num].to_i)
        end
  "#{pubclass} :: #{ids[:type]} :: #{sortkey3} :: #{num} :: "\
    "#{sprintf('%09d', ids[:partid])} :: #{ids[:id]} :: #{title}"
end

#stage_type_validate(stage, doctype) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/metanorma/ogc/validate.rb', line 33

def stage_type_validate(stage, doctype)
  err = case doctype
        when "standard", "abstract-specification-topic"
          %w(draft work-item-draft).include?(stage)
        when "community-standard"
          %w(draft swg-draft).include?(stage)
        else %w(swg-draft oab-review public-rfc tc-vote
                work-item-draft deprecated rescinded).include?(stage)
        end
  err and @log.add("Document Attributes", nil,
                   "#{stage} is not an allowed status for #{doctype}")
end

#stage_validate(xmldoc) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/metanorma/ogc/validate.rb', line 24

def stage_validate(xmldoc)
  stage = xmldoc&.at("//bibdata/status/stage")&.text
  %w(draft swg-draft oab-review public-rfc tc-vote work-item-draft
     approved deprecated retired rescinded).include? stage or
    @log.add("Document Attributes", nil,
             "#{stage} is not a recognised status")
  stage_type_validate(stage, xmldoc&.at("//bibdata/ext/doctype")&.text)
end

#style(_node, _text) ⇒ Object



104
105
106
# File 'lib/metanorma/ogc/converter.rb', line 104

def style(_node, _text)
  nil
end

#submitters_parse(attrs, xml, node) ⇒ Object



97
98
99
100
101
102
# File 'lib/metanorma/ogc/converter.rb', line 97

def submitters_parse(attrs, xml, node)
  xml.submitters **attr_code(attrs) do |xml_section|
    xml_section.title @i18n.submitters
    xml_section << node.content
  end
end

#table_cell(node, xml_tr, tblsec) ⇒ Object



116
117
118
119
# File 'lib/metanorma/ogc/converter.rb', line 116

def table_cell(node, xml_tr, tblsec)
  node.set_attr("valign", "middle")
  super
end

#term_def_parse(attrs, xml, node, _toplevel) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/metanorma/ogc/converter.rb', line 108

def term_def_parse(attrs, xml, node, _toplevel)
  if node.attr("style") == "appendix" && node.level == 1
    terms_annex_parse(attrs, xml, node)
  else
    super
  end
end

#termdef_boilerplate_cleanup(xmldoc) ⇒ Object



55
# File 'lib/metanorma/ogc/cleanup.rb', line 55

def termdef_boilerplate_cleanup(xmldoc); end

#termdef_cleanup(xmldoc) ⇒ Object



88
89
90
91
# File 'lib/metanorma/ogc/cleanup.rb', line 88

def termdef_cleanup(xmldoc)
  super
  termdef_subclause_cleanup(xmldoc)
end

#termdef_subclause_cleanup(xmldoc) ⇒ Object

skip annex/terms/terms, which is empty node



94
95
96
97
98
99
100
101
# File 'lib/metanorma/ogc/cleanup.rb', line 94

def termdef_subclause_cleanup(xmldoc)
  xmldoc.xpath("//annex//clause[terms]").each do |t|
    next unless t.xpath("./clause | ./terms | ./definitions").size == 1

    t.children.each { |n| n.parent = t.parent }
    t.remove
  end
end

#terms_annex_parse(attrs, xml, node) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/metanorma/ogc/converter.rb', line 121

def terms_annex_parse(attrs, xml, node)
  attrs1 = attrs.merge(id: "_#{UUIDTools::UUID.random_create}")
  xml.annex **attr_code(attrs1) do |xml_section|
    xml_section.title { |name| name << node.title }
    xml_section.terms **attr_code(attrs) do |terms|
      (s = node.attr("source")) && s.split(",").each do |s1|
        terms.termdocsource(nil, **attr_code(bibitemid: s1))
      end
      terms << node.content
    end
  end
end

#title(node, xml) ⇒ Object



189
190
191
192
193
194
# File 'lib/metanorma/ogc/front.rb', line 189

def title(node, xml)
  super
  at = { format: "text/plain", type: "abbrev" }
  a = node.attr("abbrev") and
    xml.title a, **attr_code(at)
end

#title_key(bib) ⇒ Object



190
191
192
193
194
# File 'lib/metanorma/ogc/cleanup.rb', line 190

def title_key(bib)
  title = bib.at("./title[@type = 'main']") ||
    bib.at("./title") || bib.at("./formattedref")
  title&.text&.sub!(/^(OGC|Open Geospatial Consortium)\b/, "")
end

#title_validate(_root) ⇒ Object



10
11
12
# File 'lib/metanorma/ogc/validate.rb', line 10

def title_validate(_root)
  nil
end

#toc(value) ⇒ Object

ignore, we generate ToC outside of asciidoctor



27
# File 'lib/metanorma/ogc/converter.rb', line 27

def toc(value); end

#validate(doc) ⇒ Object



4
5
6
7
8
# File 'lib/metanorma/ogc/validate.rb', line 4

def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  File.join(File.dirname(__FILE__), "ogc.rng"))
end

#version_validate(xmldoc) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/metanorma/ogc/validate.rb', line 46

def version_validate(xmldoc)
  version = xmldoc&.at("//bibdata/edition")&.text
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
  if %w(engineering-report discussion-paper).include? doctype
    version.nil? or
      @log.add("Document Attributes", nil,
               "Version not permitted for #{doctype}")
  else
    version.nil? and
      @log.add("Document Attributes", nil,
               "Version required for #{doctype}")
  end
end