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

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

#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



57
58
59
60
# File 'lib/metanorma/ogc/validate.rb', line 57

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

#clause_parse(attrs, xml, node) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/metanorma/ogc/converter.rb', line 81

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

#conformance_to_reqt(ids, reqtclass, confclass, reqtlabel, conflabel) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/metanorma/ogc/validate.rb', line 40

def conformance_to_reqt(ids, reqtclass, confclass, reqtlabel, conflabel)
  ids[confclass]&.each do |x|
    ids[reqtclass]&.any? { |r| x[:subject] == r[:id] } or
      @log.add("Requirements", x[:elem],
               "#{conflabel} #{x[:id]} has no corresponding #{reqtlabel}")
  end
end

#content_validate(doc) ⇒ Object



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

def content_validate(doc)
  super
  bibdata_validate(doc.root)
  reqt_link_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

#doc_converter(node) ⇒ Object



168
169
170
# File 'lib/metanorma/ogc/converter.rb', line 168

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

#doctype(node) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/metanorma/ogc/converter.rb', line 34

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

#example(node) ⇒ Object



134
135
136
137
138
139
140
141
142
# File 'lib/metanorma/ogc/converter.rb', line 134

def example(node)
  role = node.role || node.attr("style")
  if %w(requirements_class conformance_test conformance_class
        abstract_test).include?(role)
    node.set_attr("type", role)
    return requirement(node, "requirement")
  end
  super
end

#execsummary_validate(xmldoc) ⇒ Object



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

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



130
131
132
# File 'lib/metanorma/ogc/converter.rb', line 130

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

#html_converter(node) ⇒ Object



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

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



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

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



193
194
195
196
197
198
199
200
201
# File 'lib/metanorma/ogc/cleanup.rb', line 193

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



203
204
205
206
207
208
209
210
211
212
213
# File 'lib/metanorma/ogc/cleanup.rb', line 203

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



70
71
72
73
74
75
76
77
78
79
# File 'lib/metanorma/ogc/converter.rb', line 70

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



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

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



172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/metanorma/ogc/validate.rb', line 172

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



154
155
156
# File 'lib/metanorma/ogc/converter.rb', line 154

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


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/metanorma/ogc/validate.rb', line 20

def reqt_link_validate(docxml)
  ids = reqt_links(docxml)
  reqt_to_conformance(ids, "general", "verification", "Requirement",
                      "Conformance test")
  reqt_to_conformance(ids, "class", "conformanceclass",
                      "Requirement class", "Conformance class test")
  conformance_to_reqt(ids, "general", "verification", "Requirement",
                      "Conformance test")
  conformance_to_reqt(ids, "class", "conformanceclass",
                      "Requirement class", "Conformance class test")
end


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

def reqt_links(docxml)
  docxml.xpath("//requirement | //recommendation | //permission")
    .each_with_object({}) do |r, m|
      m[r["type"]] ||= []
      m[r["type"]] << { id: r["id"], elem: r,
                        subject: r&.at("./subject/xref/@target")&.text }
    end
end

#reqt_to_conformance(ids, reqtclass, confclass, reqtlabel, conflabel) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/metanorma/ogc/validate.rb', line 32

def reqt_to_conformance(ids, reqtclass, confclass, reqtlabel, conflabel)
  ids[reqtclass]&.each do |r|
    ids[confclass]&.any? { |x| x[:subject] == r[:id] } or
      @log.add("Requirements", r[:elem],
               "#{reqtlabel} #{r[:id]} has no corresponding #{conflabel}")
  end
end

#requirement_cleanup(xmldoc) ⇒ Object



168
169
170
171
# File 'lib/metanorma/ogc/cleanup.rb', line 168

def requirement_cleanup(xmldoc)
  requirement_type(xmldoc)
  super
end

#requirement_metadata(xmldoc) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/metanorma/ogc/cleanup.rb', line 119

def (xmldoc)
  super
  xmldoc.xpath(REQRECPER).each do |r|
    (r)
    (r)
    requirement_subparts_to_blocks(r)
  end
end

#requirement_metadata1(reqt, dlist, ins) ⇒ Object



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

def requirement_metadata1(reqt, dlist, ins)
  ins1 = super
  dlist.xpath("./dt").each do |e|
    tag = e&.text&.gsub(/ /, "-")&.downcase
    next unless .include? tag

    ins1.next = requirement_metadata1_component(e, tag)
    ins1 = ins1.next
  end
end

#requirement_metadata1_component(term, tag) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/metanorma/ogc/cleanup.rb', line 104

def requirement_metadata1_component(term, tag)
  val = term.at("./following::dd")
  val.name = tag
  val.xpath("./dl").each do |d|
    requirement_metadata1(val, d, d)
    d.remove
  end
  if %w(requirement permission
        recommendation).include?(term.text) && !val.text.empty?
    val["label"] = val.text.strip
    val.children.remove
  end
  val
end

#requirement_metadata_component_tagsObject



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

def 
  %w(test-purpose test-method test-method-type conditions part description
     reference step requirement permission recommendation)
end

#requirement_metadata_to_component(reqt) ⇒ Object



128
129
130
131
132
133
134
135
# File 'lib/metanorma/ogc/cleanup.rb', line 128

def (reqt)
  reqt.xpath(".//test-method | .//test-purpose | .//conditions | "\
             ".//part | .//test-method-type | .//step | .//reference")
    .each do |c|
    c["class"] = c.name
    c.name = "component"
  end
end

#requirement_metadata_to_requirement(reqt) ⇒ Object



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

def (reqt)
  reqt.xpath("./requirement | ./permission | ./recommendation")
    .each do |c|
    c["id"] = Metanorma::Utils::anchor_or_uuid
  end
end

#requirement_subparts_to_blocks(reqt) ⇒ Object



144
145
146
147
148
149
150
151
# File 'lib/metanorma/ogc/cleanup.rb', line 144

def requirement_subparts_to_blocks(reqt)
  reqt.xpath(".//component | .//description").each do |c|
    next if %w(p ol ul dl table component description)
      .include?(c&.elements&.first&.name)

    c.children = "<p>#{c.children.to_xml}</p>"
  end
end

#requirement_type(xmldoc) ⇒ Object



173
174
175
176
177
178
179
# File 'lib/metanorma/ogc/cleanup.rb', line 173

def requirement_type(xmldoc)
  xmldoc.xpath(REQRECPER).each do |r|
    next unless r["type"]

    requirement_type1(r)
  end
end

#requirement_type1(reqt) ⇒ Object



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

def requirement_type1(reqt)
  reqt["type"] = case reqt["type"]
                 when "requirement", "recommendation", "permission"
                   "general"
                 when "requirements_class" then "class"
                 when "conformance_test" then "verification"
                 when "conformance_class" then "conformanceclass"
                 when "abstract_test" then "abstracttest"
                 else reqt["type"]
                 end
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



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

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



215
216
217
218
# File 'lib/metanorma/ogc/cleanup.rb', line 215

def sections_order_cleanup(xml)
  super
  sort_annexes(xml)
end

#sections_sequence_validate(root) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/metanorma/ogc/validate.rb', line 149

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



51
52
53
54
55
56
57
# File 'lib/metanorma/ogc/converter.rb', line 51

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



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

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



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

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



144
145
146
147
148
149
150
151
152
# File 'lib/metanorma/ogc/converter.rb', line 144

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



220
221
222
223
224
225
226
227
228
# File 'lib/metanorma/ogc/cleanup.rb', line 220

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

#stage_type_validate(stage, doctype) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/metanorma/ogc/validate.rb', line 71

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



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

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



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

def style(_node, _text)
  nil
end

#submitters_parse(attrs, xml, node) ⇒ Object



93
94
95
96
97
98
# File 'lib/metanorma/ogc/converter.rb', line 93

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



112
113
114
115
# File 'lib/metanorma/ogc/converter.rb', line 112

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

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



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

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



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

def termdef_cleanup(xmldoc)
  super
  termdef_subclause_cleanup(xmldoc)
end

#termdef_subclause_cleanup(xmldoc) ⇒ Object

skip annex/terms/terms, which is empty node



159
160
161
162
163
164
165
166
# File 'lib/metanorma/ogc/cleanup.rb', line 159

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



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/metanorma/ogc/converter.rb', line 117

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_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



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

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