Class: Metanorma::IEEE::Converter

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

Constant Summary collapse

TERM_CLAUSE =
"//sections//terms".freeze
AMD_VALID_MOD =
[
  "'Modify' change description should start with _Change_ or _Replace_",
  "'Modify' change description for change involving figure or equation "\
  "should start with _Replace_",
  "'Modify' change description for change not involving figure or "\
  "equation should start with _Change_",
].freeze
XML_ROOT_TAG =
"ieee-standard".freeze
XML_NAMESPACE =
"https://www.metanorma.org/ns/ieee".freeze
PREFACE_CLAUSE_NAMES =
%w(abstract foreword introduction
acknowledgements participants).freeze
BIBLIO =
"//bibliography/references[@normative = 'false'][not(@hidden)] | " \
"//bibliography/clause[.//references[@normative = 'false']] | " \
"//annex//references[@normative = 'false'][not(@hidden)]".freeze
ASSETS_TO_STYLE =
"//termsource | //formula | //termnote | " \
"//p[not(ancestor::boilerplate)] | //li[not(p)] | //dt | " \
"//dd[not(p)] | //td[not(p)][not(ancestor::boilerplate)] | " \
"//th[not(p)][not(ancestor::boilerplate)] | //example".freeze
SI_UNIT =

leaving out as problematic: N J K C S T H h d B o E

"(m|cm|mm|km|μm|nm|g|kg|mgmol|cd|rad|sr|Hz|Hz|MHz|Pa|hPa|kJ|" \
"V|kV|W|MW|kW|F|μF|Ω|Wb|°C|lm|lx|Bq|Gy|Sv|kat|l|t|eV|u|Np|Bd|" \
"bit|kB|MB|Hart|nat|Sh|var)".freeze
SEQ =

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

[
  { msg: "Initial section must be (content) Abstract",
    val: ["./self::abstract"] },
  { msg: "Prefatory material must be followed by (clause) Overview",
    val: ["./self::clause[@type = 'overview']"] },
  { msg: "Normative References must be followed by "\
         "Definitions",
    val: ["./self::terms | .//terms"] },
].freeze
SECTIONS_XPATH =
"//preface/abstract | //sections/terms | .//annex | "\
"//sections/definitions | //sections/clause | "\
"//references[not(parent::clause)] | "\
"//clause[descendant::references][not(parent::clause)]".freeze

Instance Method Summary collapse

Instance Method Details

#amend_validate(xmldoc) ⇒ Object

Style manual 20.2.2



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

def amend_validate(xmldoc)
  xmldoc.xpath("//amend").each do |a|
    desc = a.at("./description")
    if desc && !desc.text.strip.empty?
      amend_validate1(a, desc.text.strip,
                      a.at("./newcontent//figure | "\
                           "./newcontent//formula"))
    else @log.add("Style", a,
                  "Editorial instruction is missing from change")
    end
  end
end

#amend_validate1(amend, description, figure_or_formula) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/metanorma/ieee/validate.rb', line 215

def amend_validate1(amend, description, figure_or_formula)
  case amend["change"]
  when "add" then /^Insert /.match?(description) or
    @log.add("Style", amend,
             "'Add' change description should start with _Insert_")
  when "delete" then /^Insert /.match?(description) or
    @log.add("Style", amend,
             "'Delete' change description should start with _Delete_")
  when "modify"
    amend_validate_modify(amend, description, figure_or_formula)
  end
end

#amend_validate_modify(amend, description, figure_or_formula) ⇒ Object



236
237
238
239
240
241
242
243
244
# File 'lib/metanorma/ieee/validate.rb', line 236

def amend_validate_modify(amend, description, figure_or_formula)
  if !/^Change |^Replace/.match?(description)
    @log.add("Style", amend, AMD_VALID_MOD[0])
  elsif /^Change /.match?(description)
    !figure_or_formula or @log.add("Style", amend, AMD_VALID_MOD[1])
  else
    figure_or_formula or @log.add("Style", amend, AMD_VALID_MOD[2])
  end
end

#asset_style(root) ⇒ Object



20
21
22
# File 'lib/metanorma/ieee/validate_style.rb', line 20

def asset_style(root)
  root.xpath(ASSETS_TO_STYLE).each { |e| style(e, extract_text(e)) }
end

#bibdata_cleanup(xmldoc) ⇒ Object



212
213
214
215
# File 'lib/metanorma/ieee/cleanup.rb', line 212

def bibdata_cleanup(xmldoc)
  super
  provenance_title(xmldoc)
end

#bibdata_validate(doc) ⇒ Object



25
26
27
28
# File 'lib/metanorma/ieee/validate.rb', line 25

def bibdata_validate(doc)
  doctype_validate(doc)
  stage_validate(doc)
end

#bibitem_validate(root) ⇒ Object



74
75
76
# File 'lib/metanorma/ieee/validate.rb', line 74

def bibitem_validate(root)
  normative_dated_refs(root)
end

#biblio_preface(ref) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 14

def biblio_preface(ref)
  if ref.at("./note[@type = 'boilerplate']")
    unwrap_boilerplate_clauses(ref, ".")
  else
    pref = @i18n.biblio_pref
    ref.at("./title").next = "<p>#{pref}</p>"
  end
end

#biblio_renumber(xmldoc) ⇒ Object



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

def biblio_renumber(xmldoc)
  i = 0
  xmldoc.xpath("//references[not(@normative = 'true')]" \
               "[not(@hidden = 'true')]").each do |r|
                 r.xpath("./bibitem[not(@hidden = 'true')]").each do |b|
                   i += 1
                   biblio_renumber1(b, i)
                 end
               end
end

#biblio_renumber1(bib, idx) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 109

def biblio_renumber1(bib, idx)
  docid = bib.at("./docidentifier[@type = 'metanorma' or " \
                 "@type = 'metanorma-ordinal']")
  if /^\[?\d+\]?$/.match?(docid&.text)
    docid.children = "[B#{idx}]"
  elsif docid = bib.at("./docidentifier") || bib.at("./title[last()]") ||
      bib.at("./formattedref")
    docid.next =
      "<docidentifier type='metanorma-ordinal'>[B#{idx}]</docidentifier>"
  end
end

#bibliography_validate(root) ⇒ Object

Style manual 19.1



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

def bibliography_validate(root)
  bib = root.at("//references[@normative = 'false']") or return
  if annex = bib.at(".//ancestor::annex")
    prec = annex.xpath("./preceding-sibling::annex")
    foll = annex.xpath("./following-sibling::annex")
    valid = prec.empty? || foll.empty?
  else valid = false
  end
  valid or @log.add("Style", bib, "Bibliography must be either the first "\
                                  "or the last document annex")
end

#boilerplate_cleanup(xmldoc) ⇒ Object



9
10
11
12
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 9

def boilerplate_cleanup(xmldoc)
  f = xmldoc.at(BIBLIO) and biblio_preface(f)
  super
end

#boilerplate_file(_xmldoc) ⇒ Object



64
65
66
# File 'lib/metanorma/ieee/converter.rb', line 64

def boilerplate_file(_xmldoc)
  File.join(@libdir, "boilerplate.adoc")
end

#boilerplate_isodoc(xmldoc) ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'lib/metanorma/ieee/cleanup.rb', line 136

def boilerplate_isodoc(xmldoc)
  x = xmldoc.dup
  x.root.add_namespace(nil, self.class::XML_NAMESPACE)
  xml = Nokogiri::XML(x.to_xml)
  i = isodoc(@lang, @script, @locale)
  i.bibdata_i18n(xml.at("//xmlns:bibdata"))
  i.info(xml, nil)
  i
end

#clause_parse(attrs, xml, node) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/metanorma/ieee/converter.rb', line 35

def clause_parse(attrs, xml, node)
  case node.title
  when "Purpose" then attrs[:type] = "purpose"
  when "Overview" then attrs[:type] = "overview"
  when "Scope" then attrs[:type] = "scope"
  when "Word Usage" then attrs[:type] = "word-usage"
  when "Participants" then attrs[:type] = "participants"
  end
  super
end

#content_validate(doc) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/metanorma/ieee/validate.rb', line 13

def content_validate(doc)
  super
  bibdata_validate(doc.root)
  title_validate(doc.root)
  locality_validate(doc.root)
  bibitem_validate(doc.root)
  list_validate(doc)
  table_style(doc)
  figure_validate(doc)
  amend_validate(doc)
end

#datetypesObject



75
76
77
# File 'lib/metanorma/ieee/front.rb', line 75

def datetypes
  super + %w{feedback-ended}
end

#designator_docid(bib) ⇒ Object



54
55
56
57
58
59
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 54

def designator_docid(bib)
  n = bib.at("./docidentifier[@primary]") ||
    bib.at("./docidentifier[not(#{skip_docid})]")
  n or return "ZZZZ"
  @isodoc.docid_prefix(n["type"], n.children.to_xml)
end

#designator_or_name(bib) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 42

def designator_or_name(bib)
  case bib["type"]
  when "standard", "techreport" then designator_docid(bib)
  else
    bib1 = bib.dup
    bib1.add_namespace(nil, self.class::XML_NAMESPACE)
    n = @i.creatornames(bib1)
    n.nil? && bib["type"].nil? and n = designator_docid(bib)
    n
  end
end

#doc_converter(node) ⇒ Object



94
95
96
# File 'lib/metanorma/ieee/converter.rb', line 94

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

#doc_extract_attributes(node) ⇒ Object



74
75
76
77
78
# File 'lib/metanorma/ieee/converter.rb', line 74

def doc_extract_attributes(node)
  super.merge(hierarchicalassets:
              node.attr("hierarchical-object-numbering"),
              ulstyle: "l11", olstyle: "l16")
end

#doctype_validate(xmldoc) ⇒ Object



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

def doctype_validate(xmldoc)
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
  %w(standard recommended-practice guide whitepaper redline other)
    .include? doctype or
    @log.add("Document Attributes", nil,
             "#{doctype} is not a recognised document type")
  docsubtype = xmldoc&.at("//bibdata/ext/subdoctype")&.text or return
  %w(amendment corrigendum erratum document).include? docsubtype or
    @log.add("Document Attributes", nil,
             "#{docsubtype} is not a recognised document subtype")
end

#extract_participants(dlist) ⇒ Object



201
202
203
204
205
206
207
208
209
210
# File 'lib/metanorma/ieee/cleanup.rb', line 201

def extract_participants(dlist)
  key = ""
  map = dlist.xpath("./dt | ./dd").each_with_object({}) do |dtd, m|
    (dtd.name == "dt" and key = dtd.text.sub(/:+$/, "")) or
      m[key.strip.downcase] =
        @c.encode(@c.decode(dtd.text.strip), :hexadecimal)
  end
  map["role"] ||= "member"
  map
end

#extract_text(node) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/metanorma/ieee/validate_style.rb', line 10

def extract_text(node)
  return "" if node.nil?

  node1 = Nokogiri::XML.fragment(node.to_s)
  node1.xpath("//link | //locality | //localityStack").each(&:remove)
  ret = ""
  node1.traverse { |x| ret += x.text if x.text? }
  HTMLEntities.new.decode(ret)
end

#figure_name_style_validate(docxml) ⇒ Object

Style manual 17.2



163
164
165
166
167
168
# File 'lib/metanorma/ieee/validate.rb', line 163

def figure_name_style_validate(docxml)
  docxml.xpath("//figure/name").each do |td|
    style_regex(/^(?<num>\p{Lower}\s*)/, "figure heading should be capitalised",
                td, td.text)
  end
end

#figure_name_validate(xmldoc, xrefs) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/metanorma/ieee/validate.rb', line 148

def figure_name_validate(xmldoc, xrefs)
  pref = image_name_prefix(xmldoc)
  (xmldoc.xpath("//figure") - xmldoc.xpath("//table//figure"))
    .each do |f|
      (i = f.at("./image") and !i["src"]&.start_with?("data:")) or next

      num = xrefs.anchor(f["id"], :label)
      base = File.basename(i["src"], ".*")
      base == "#{pref}_fig#{num}" or
        @log.add("Style", i,
                 "Image name #{base} is expected to be #{pref}_fig#{num}")
    end
end

#figure_validate(xmldoc) ⇒ Object

Style manual 17.1



122
123
124
125
126
127
128
# File 'lib/metanorma/ieee/validate.rb', line 122

def figure_validate(xmldoc)
  xrefs = xrefs(xmldoc)
  figure_name_validate(xmldoc, xrefs)
  figure_name_style_validate(xmldoc)
  table_figure_name_validate(xmldoc, xrefs)
  table_figure_quantity_validate(xmldoc)
end

#footnote_boilerplate_renumber(xml) ⇒ Object



17
18
19
20
21
# File 'lib/metanorma/ieee/cleanup.rb', line 17

def footnote_boilerplate_renumber(xml)
  xml.xpath("//boilerplate//fn").each_with_index do |f, i|
    f["reference"] = "_boilerplate_#{i + 1}"
  end
end

#html_converter(node) ⇒ Object



84
85
86
# File 'lib/metanorma/ieee/converter.rb', line 84

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

#html_extract_attributes(node) ⇒ Object



68
69
70
71
72
# File 'lib/metanorma/ieee/converter.rb', line 68

def html_extract_attributes(node)
  super.merge(hierarchicalassets:
              node.attr("hierarchical-object-numbering"),
              ieeedtd: node.attr("ieee-dtd"))
end

#ieee_xml_converter(node) ⇒ Object



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

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

  IsoDoc::Iso::IEEEXMLConvert.new(html_extract_attributes(node))
end

#image_name_prefix(xmldoc) ⇒ Object



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

def image_name_prefix(xmldoc)
  num = xmldoc.at("//bibdata/docnumber") or return
  yr = xmldoc.at("//bibdata/date[@type = 'published']") ||
    xmldoc.at("//bibdata/date[@type = 'issued']") ||
    xmldoc.at("//bibdata/copyright/from")
  yr = yr&.text || Date.now.year
  "#{num.text}-#{yr.sub(/-*$/, '')}"
end

#init(node) ⇒ Object



17
18
19
20
21
# File 'lib/metanorma/ieee/converter.rb', line 17

def init(node)
  super
  @document_scheme ||= "ieee-sa-2021"
  @hierarchical_assets = node.attr("hierarchical-object-numbering")
end

#initial_boilerplate(xml, isodoc) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/metanorma/ieee/cleanup.rb', line 7

def initial_boilerplate(xml, isodoc)
  intro_boilerplate(xml, isodoc)
  super if @document_scheme == "ieee-sa-2021"
  xml.at("//boilerplate") or return
  initial_note(xml)
  word_usage(xml)
  participants(xml)
  footnote_boilerplate_renumber(xml)
end

#initial_note(xml) ⇒ Object



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

def initial_note(xml)
  n = xml.at("//boilerplate//note[@id = 'boilerplate_front']")
  s = xml.at("//sections")
  (n && s) or return
  s.children.empty? and s << " "
  s.children.first.previous = n.remove
end

#intro_boilerplate(xml, isodoc) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/metanorma/ieee/cleanup.rb', line 23

def intro_boilerplate(xml, isodoc)
  intro = xml.at("//introduction/title") or return
  template = "    This introduction is not part of P{{ docnumeric }}{% if draft %}/D{{ draft }}{% endif %}, {{ full_doctitle }}\n  ADM\n  adm = isodoc.populate_template(template)\n  intro.next = \"<admonition>\#{adm}</admonition>\"\nend\n"

#list_validate(doc) ⇒ Object



87
88
89
90
# File 'lib/metanorma/ieee/validate.rb', line 87

def list_validate(doc)
  listcount_validate(doc)
  listdepth_validate(doc)
end

#listcount_validate(doc) ⇒ Object

Style manual 13.3



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/metanorma/ieee/validate.rb', line 109

def listcount_validate(doc)
  doc.xpath("//sections//clause | //annex").each do |c|
    next if c.xpath(".//ol").empty?

    ols = c.xpath(".//ol") -
      c.xpath(".//ul//ol | .//ol//ol | .//clause//ol")
    ols.size > 1 and
      style_warning(c, "More than 1 ordered list in a numbered clause",
                    nil)
  end
end

#listdepth_validate(doc) ⇒ Object

Template provision of styles



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/metanorma/ieee/validate.rb', line 93

def listdepth_validate(doc)
  doc.xpath("//ul[.//ul//ul]").each do |u|
    next unless u.ancestors("ul").empty?

    @log.add("Style", u,
             "Use ordered lists for lists more than two levels deep.")
  end
  doc.xpath("//ol[.//ol//ol//ol//ol//ol]").each do |u|
    next unless u.ancestors("ol").empty?

    @log.add("Style", u,
             "Ordered lists should not be more than five levels deep.")
  end
end

#locality_erefs_validate(root) ⇒ Object

Style manual 12.3.2



64
65
66
67
68
69
70
71
72
# File 'lib/metanorma/ieee/validate.rb', line 64

def locality_erefs_validate(root)
  root.xpath("//eref[descendant::locality]").each do |t|
    if !/[:-](\d+{4})$/.match?(t["citeas"])
      @log.add("Style", t,
               "Undated reference #{t['citeas']} should not contain "\
               "specific elements")
    end
  end
end

#locality_range_validate(root) ⇒ Object

Style manual 17.2 &c



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

def locality_range_validate(root)
  root.xpath("//eref | xref").each do |e|
    e.at(".//localityStack[@connective = 'from'] | .//referenceTo") and
      @log.add("Style", e, "Cross-reference contains range, "\
                           "should be separate cross-references")
  end
end

#locality_validate(root) ⇒ Object



49
50
51
52
# File 'lib/metanorma/ieee/validate.rb', line 49

def locality_validate(root)
  locality_range_validate(root)
  locality_erefs_validate(root)
end

#metadata_committee(node, xml) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/metanorma/ieee/front.rb', line 6

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

  node.attr("balloting-group") && !node.attr("balloting-group-type") and
    node.set_attr("balloting-group-type", "individual")

  xml.editorialgroup do |a|
    committee_component("society", node, a)
    committee_component("balloting-group", node, a)
    committee_component("working-group", node, a)
    committee_component("committee", node, a)
  end
end


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/metanorma/ieee/front.rb', line 49

def (node, xml)
  publishers = node.attr("copyright-holder") || node.attr("publisher") ||
    "IEEE"
  csv_split(publishers).each do |p|
    xml.copyright do |c|
      c.from (node.attr("copyright-year") || Date.today.year)
      c.owner do |owner|
        owner.organization do |o|
          organization(
            o, p, true, node,
            !(node.attr("copyright-holder") || node.attr("publisher"))
          )
        end
      end
    end
  end
end

#metadata_ext(node, xml) ⇒ Object



92
93
94
95
# File 'lib/metanorma/ieee/front.rb', line 92

def (node, xml)
  super
  structured_id(node, xml)
end

#metadata_id(node, xml) ⇒ Object



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

def (node, xml)
  id = node.attr("docnumber") || ""
  xml.docidentifier (node.attr("docidentifier") || id), type: "IEEE"
  id = node.attr("stdid-pdf") and
    xml.docidentifier id, type: "IEEE", scope: "PDF"
  id = node.attr("stdid-print") and
    xml.docidentifier id, type: "IEEE", scope: "print"
  xml.docnumber node.attr("docnumber")
end

#metadata_other_id(node, xml) ⇒ Object



20
21
22
23
24
25
# File 'lib/metanorma/ieee/front.rb', line 20

def (node, xml)
  a = node.attr("isbn-pdf") and
    xml.docidentifier a, type: "ISBN", scope: "PDF"
  a = node.attr("isbn-print") and
    xml.docidentifier a, type: "ISBN", scope: "print"
end

#metadata_publisher(node, xml) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/metanorma/ieee/front.rb', line 37

def (node, xml)
  publishers = node.attr("publisher") || "IEEE"
  csv_split(publishers).each do |p|
    xml.contributor do |c|
      c.role type: "publisher"
      c.organization do |a|
        organization(a, p, true, node, !node.attr("publisher"))
      end
    end
  end
end

#metadata_status(node, xml) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/metanorma/ieee/front.rb', line 67

def (node, xml)
  status = node.attr("status") || node.attr("docstage") ||
    (node.attr("draft") ? "draft" : "approved")
  xml.status do |s|
    s.stage status
  end
end

#metadata_subdoctype(node, xml) ⇒ Object



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

def (node, xml)
  xml.subdoctype (node.attr("docsubtype") || "document")
  s = node.attr("trial-use") and xml.trial_use s
end

#normative_dated_refs(root) ⇒ Object

Style manual 12.3.1



79
80
81
82
83
84
85
# File 'lib/metanorma/ieee/validate.rb', line 79

def normative_dated_refs(root)
  root.xpath("//references[@normative = 'true']/bibitem").each do |b|
    b.at(".//date") or
      @log.add("Style", b,
               "Normative reference #{b&.at('./@id')&.text} is not dated.")
  end
end

#normref_cleanup(xmldoc) ⇒ Object



61
62
63
64
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 61

def normref_cleanup(xmldoc)
  super
  normref_reorder(xmldoc)
end

#normref_reorder(xmldoc) ⇒ Object



66
67
68
69
70
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 66

def normref_reorder(xmldoc)
  xmldoc.xpath("//references[@normative = 'true']").each do |r|
    biblio_reorder1(r)
  end
end

#note_cleanup(xmldoc) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/metanorma/ieee/cleanup.rb', line 87

def note_cleanup(xmldoc)
  super
  n = xmldoc.at("//preface//note[not(@type = 'boilerplate')]" \
                "[not(./ancestor::abstract)] | " \
                "//sections//note[not(@type = 'boilerplate')] | " \
                "//annex//note[not(@type = 'boilerplate')]") or
    return
  ins = n.at("./p[last()]")
  ins << "<fn reference='_boilerplate_cleanup1'>" \
         "<p>#{@i18n.note_inform_fn}</p></fn>"
end

#obligations_cleanup_norm(xml) ⇒ Object



49
50
51
52
53
54
# File 'lib/metanorma/ieee/cleanup.rb', line 49

def obligations_cleanup_norm(xml)
  super
  xml.xpath("//sections/clause").each do |r|
    r["obligation"] = "normative"
  end
end

#onlychild_clause_validate(root) ⇒ Object

Style manual 13.1



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

def onlychild_clause_validate(root)
  root.xpath(Standoc::Utils::SUBCLAUSE_XPATH).each do |c|
    next unless c.xpath("../clause").size == 1

    title = c.at("./title")
    location = c["id"] || "#{c.text[0..60]}..."
    location += ":#{title.text}" if c["id"] && !title.nil?
    @log.add("Style", nil, "#{location}: subclause is only child")
  end
end

#org_abbrevObject



84
85
86
# File 'lib/metanorma/ieee/front.rb', line 84

def org_abbrev
  { "Institute of Electrical and Electronic Engineers" => "IEEE" }
end

#other_footnote_renumber1(fnote, idx, seen) ⇒ Object



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

def other_footnote_renumber1(fnote, idx, seen)
  fnote["table"] and return [idx, seen]
  content = footnote_content(fnote)
  idx += 1
  if seen[content]
    fnote.children = "<p>See Footnote #{seen[content]}.</p>"
  else seen[content] = idx
  end
  fnote["reference"] = idx.to_s
  [idx, seen]
end

#outputs(node, ret) ⇒ Object



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

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")
  node.attr("no-pdf") or
    pdf_converter(node)&.convert("#{@filename}.presentation.xml",
                                 nil, false, "#{@filename}.pdf")
end

#overview_children_cleanup(xml) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/metanorma/ieee/cleanup.rb', line 66

def overview_children_cleanup(xml)
  %w(scope purpose word-usage).each do |x|
    (xml.xpath("//clause[@type = '#{x}']") -
      xml.xpath("//sections/clause[@type = 'overview']" \
                "//clause[@type = '#{x}']"))
      .each { |c| c.delete("type") }
  end
end

#overview_cleanup(xml) ⇒ Object



61
62
63
64
# File 'lib/metanorma/ieee/cleanup.rb', line 61

def overview_cleanup(xml)
  overview_once_cleanup(xml)
  overview_children_cleanup(xml)
end

#overview_once_cleanup(xml) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/metanorma/ieee/cleanup.rb', line 75

def overview_once_cleanup(xml)
  found = false
  xml.xpath("//sections//clause[@type = 'overview']").each do |c|
    found and c.delete("type")
    found = true if c.parent.name == "sections"
  end
  xml.xpath("//annex//clause[@type = 'overview'] | " \
            "//preface//clause[@type = 'overview']").each do |c|
    c.delete("type")
  end
end

#participants(xml) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/metanorma/ieee/cleanup.rb', line 146

def participants(xml)
  @document_scheme == "ieee-sa-2021" or return
  { "boilerplate-participants-wg": "working group",
    "boilerplate-participants-bg": "balloting group",
    "boilerplate-participants-sb": "standards board" }.each do |k, v|
      populate_participants(xml, k.to_s, v)
    end
  p = xml.at(".//p[@type = 'emeritus_sign']")
  ul = xml.at("//clause[@id = 'boilerplate-participants-sb']//ul")
  p && ul and ul.next = p
  xml.at("//sections//clause[@type = 'participants']")&.remove
end

#participants_dl_to_ul(clause) ⇒ Object



178
179
180
181
182
183
184
185
# File 'lib/metanorma/ieee/cleanup.rb', line 178

def participants_dl_to_ul(clause)
  clause.xpath(".//dl").each do |dl|
    dl.ancestors("dl, ul, ol").empty? or next
    dl.name = "ul"
    dl.xpath("./dt").each(&:remove)
    dl.xpath("./dd").each { |li| li.name = "li" }
  end
end

#pdf_converter(node) ⇒ Object



88
89
90
91
92
# File 'lib/metanorma/ieee/converter.rb', line 88

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

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

#populate_participants(xml, target, subtitle) ⇒ Object



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

def populate_participants(xml, target, subtitle)
  t = xml.at("//clause[@id = '#{target}']/membership")
  s = xml.xpath("//clause[@type = 'participants']/clause").detect do |x|
    n = x.at("./title") and n.text.strip.downcase == subtitle
  end
  t.replace(populate_participants1(s || t))
end

#populate_participants1(clause) ⇒ Object



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

def populate_participants1(clause)
  participants_dl_to_ul(clause)
  clause.xpath(".//ul | .//ol").each do |ul|
    ul.name = "ul"
    ul.xpath("./li").each { |li| populate_participants2(li) }
    ul.xpath(".//p[normalize-space() = '']").each(&:remove)
  end
  clause.at("./title")&.remove
  clause.children.to_xml
end

#populate_participants2(list) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/metanorma/ieee/cleanup.rb', line 187

def populate_participants2(list)
  curr = list
  p = curr.at("./p") and curr = p
  if dl = curr.at("./dl")
    ret = extract_participants(dl)
    dl.children = ret.keys.map do |k|
      "<dt>#{k}</dt><dd><p>#{ret[k]}</p></dd>"
    end.join
  else
    list.children = "<dl><dt>name</dt><dd><p>#{curr.children.to_xml}" \
                    "</p></dd><dt>role</dt><dd><p>member</p></dd></dl>"
  end
end

#preposition?(word) ⇒ Boolean

Returns:

  • (Boolean)


152
153
154
155
156
157
158
159
160
# File 'lib/metanorma/ieee/validate_style.rb', line 152

def preposition?(word)
  %w(aboard about above across after against along amid among anti around
     as at before behind below beneath beside besides between beyond but
     by concerning considering despite down during except excepting
     excluding following for from in inside into like minus near of off
     on onto opposite outside over past per plus regarding round save
     since than through to toward towards under underneath unlike until
     up upon versus via with within without a an the).include?(word)
end

#presentation_xml_converter(node) ⇒ Object



80
81
82
# File 'lib/metanorma/ieee/converter.rb', line 80

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

#provenance_title(xmldoc) ⇒ Object



217
218
219
220
221
222
223
224
225
# File 'lib/metanorma/ieee/cleanup.rb', line 217

def provenance_title(xmldoc)
  u = xmldoc.xpath("//bibdata/relation[@type = 'updates']")
  m = xmldoc.xpath("//bibdata/relation[@type = 'merges']")
  u.empty? and m.empty? and return
  ins = xmldoc.at("//bibdata/title")
  t = provenance_title1(u, m)
  ins.next = "<title type='provenance' language='en' " \
             "format='application/xml'>#{t}</title>"
end

#provenance_title1(updates, merges) ⇒ Object



227
228
229
230
231
232
233
234
235
# File 'lib/metanorma/ieee/cleanup.rb', line 227

def provenance_title1(updates, merges)
  ret = ""
  u = @isodoc.i18n.boolean_conj(tm_id_extract(updates), "and")
  m = @isodoc.i18n.boolean_conj(tm_id_extract(merges), "and")
  u.empty? or ret += "Revision of #{u}"
  !u.empty? && !m.empty? and ret += "<br/>"
  m.empty? or ret += "Incorporates #{m}"
  ret
end

#quotesource_cleanup(xmldoc) ⇒ Object

end of citeas generation



73
74
75
76
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 73

def quotesource_cleanup(xmldoc)
  super
  trademark_ieee_erefs(xmldoc)
end

#relaton_relationsObject



88
89
90
# File 'lib/metanorma/ieee/front.rb', line 88

def relaton_relations
  super + %w(merges updates)
end

#section_validate(doc) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/metanorma/ieee/validate_section.rb', line 4

def section_validate(doc)
  doctype = doc&.at("//bibdata/ext/doctype")&.text
  unless %w(amendment technical-corrigendum).include? doctype
    sections_presence_validate(doc.root)
    sections_sequence_validate(doc.root)
  end
  subclause_validate(doc.root)
  onlychild_clause_validate(doc.root)
  super
end

#sections_cleanup(xml) ⇒ Object



56
57
58
59
# File 'lib/metanorma/ieee/cleanup.rb', line 56

def sections_cleanup(xml)
  super
  overview_cleanup(xml)
end

#sections_presence_validate(root) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/metanorma/ieee/validate_section.rb', line 15

def sections_presence_validate(root)
  root.at("//sections/clause[@type = 'overview']") or
    @log.add("Style", nil, "Overview clause missing")
  root.at("//sections/clause[@type = 'overview']/clause[@type = 'scope']") or
    @log.add("Style", nil, "Scope subclause missing")
  root.at("//sections/clause[@type = 'overview']/clause[@type = 'word-usage']") or
    @log.add("Style", nil, "Word Usage subclause missing")
  root.at("//references[@normative = 'true']") or
    @log.add("Style", nil, "Normative references missing")
  root.at("//terms") or
    @log.add("Style", nil, "Definitions missing")
end

#sections_sequence_validate(root) ⇒ Object



57
58
59
60
61
62
# File 'lib/metanorma/ieee/validate_section.rb', line 57

def sections_sequence_validate(root)
  names, n = sections_sequence_validate_start(root)
  names, n = sections_sequence_validate_body(names, n)
  sections_sequence_validate_end(names, n)
  bibliography_validate(root)
end

#sections_sequence_validate_body(names, elem) ⇒ Object



75
76
77
# File 'lib/metanorma/ieee/validate_section.rb', line 75

def sections_sequence_validate_body(names, elem)
  [names, elem]
end

#sections_sequence_validate_end(names, elem) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/metanorma/ieee/validate_section.rb', line 79

def sections_sequence_validate_end(names, elem)
  while elem&.name == "annex"
    elem = names.shift
    if elem.nil?
      @log.add("Style", nil, "Document must include (references) "\
                             "Normative References")
    end
  end
  elem&.at("./self::references[@normative = 'true']") ||
    @log.add("Style", nil, "Document must include (references) "\
                           "Normative References")
end

#sections_sequence_validate_start(root) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/metanorma/ieee/validate_section.rb', line 64

def sections_sequence_validate_start(root)
  names = root.xpath(SECTIONS_XPATH)
  names = seqcheck(names, SEQ[0][:msg], SEQ[0][:val])
  n = names[0]
  names = seqcheck(names, SEQ[1][:msg], SEQ[1][:val])
  names = seqcheck(names, SEQ[2][:msg], SEQ[2][:val])
  n = names.shift
  n = names.shift if n&.at("./self::definitions")
  [names, n]
end

#sectiontype_streamline(ret) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/metanorma/ieee/converter.rb', line 26

def sectiontype_streamline(ret)
  case ret
  when "definitions", "definitions, acronyms and abbreviations"
    "terms and definitions"
  when "acronyms and abbreviations" then "symbols and abbreviated terms"
  else super
  end
end

#select_docid(ref, type = nil) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 121

def select_docid(ref, type = nil)
  ret = super
  if %w(standard techreport).include?(ref["type"]) then ret
  else
    ref.at("./docidentifier[@type = 'metanorma-ordinal']") || ret
  end
end

#seqcheck(names, msg, accepted) ⇒ Object



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

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

#sort_biblio(bib) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 23

def sort_biblio(bib)
  @c = HTMLEntities.new
  @i = IsoDoc::IEEE::PresentationXMLConvert
    .new({ lang: @lang, script: @script, locale: @locale })
  @i.i18n_init(@lang, @script, @locale)
  bib.sort do |a, b|
    sort_biblio_key(a) <=> sort_biblio_key(b)
  end
end

#sort_biblio_key(bib) ⇒ Object

Alphabetic by rendering: author surname or designation, followed by title



34
35
36
37
38
39
40
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 34

def sort_biblio_key(bib)
  name = designator_or_name(bib)
  title = bib.at("./title[@type = 'main']")&.text ||
    bib.at("./title")&.text || bib.at("./formattedref")&.text
  title.gsub!(/[[:punct:]]/, "")
  @c.decode("#{name} #{title}").strip.downcase
end

#stage_validate(xmldoc) ⇒ Object



42
43
44
45
46
47
# File 'lib/metanorma/ieee/validate.rb', line 42

def stage_validate(xmldoc)
  stage = xmldoc&.at("//bibdata/status/stage")&.text
  %w(draft approved superseded withdrawn).include? stage or
    @log.add("Document Attributes", nil,
             "#{stage} is not a recognised stage")
end

#strict_capitalize_phrase(str) ⇒ Object



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

def strict_capitalize_phrase(str)
  ret = str.split(/[ -]/).map do |w|
    letters = w.chars
    letters.first.upcase! unless /^[ -]/.match?(w)
    letters.join
  end.join(" ")
  ret = "Trial-Use" if ret == "Trial Use"
  ret
end

#structured_id(node, xml) ⇒ Object



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

def structured_id(node, xml)
  return unless node.attr("docnumber")

  xml.structuredidentifier do |i|
    i.docnumber node.attr("docnumber")
    i.agency "IEEE"
    i.class_ doctype(node)
    a = node.attr("edition") and i.edition a
    a = node.attr("draft") and i.version a
    a = node.attr("amendment-number") and i.amendment a
    a = node.attr("corrigendum-number") and i.corrigendum a
    a = node.attr("copyright-year") and i.year a
  end
end

#style(node, text) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/metanorma/ieee/validate_style.rb', line 36

def style(node, text)
  return if @novalid

  style_number(node, text)
  style_percent(node, text)
  style_units(node, text)
end

#style_number(node, text) ⇒ Object

Style manual 14.2



45
46
47
48
49
50
# File 'lib/metanorma/ieee/validate_style.rb', line 45

def style_number(node, text)
  style_regex(/\b(?<num>[0-9]+,[0-9]+)/i,
              "possible decimal comma", node, text)
  style_regex(/(?:^|\s)(?<num>[\u2212-]?\.[0-9]+)/i,
              "decimal without initial zero", node, text)
end

#style_percent(node, text) ⇒ Object

Style manual 14.2



53
54
55
56
# File 'lib/metanorma/ieee/validate_style.rb', line 53

def style_percent(node, text)
  style_regex(/\b(?<num>[0-9.]+%)/,
              "no space before percent sign", node, text)
end

#style_regex(regex, warning, node, text) ⇒ Object



24
25
26
# File 'lib/metanorma/ieee/validate_style.rb', line 24

def style_regex(regex, warning, node, text)
  (m = regex.match(text)) && style_warning(node, warning, m[:num])
end

#style_units(node, text) ⇒ Object

Style manual 14.2



64
65
66
67
68
69
# File 'lib/metanorma/ieee/validate_style.rb', line 64

def style_units(node, text)
  style_regex(/(\b|^)(?<num>[0-9][0-9.]*#{SI_UNIT})\b/o,
              "no space between number and SI unit", node, text)
  style_regex(/(\b|^)(?<num>[0-9.]+\s*\u00b1\s*[0-9.]+\s*#{SI_UNIT})\b/o,
              "unit is needed on both value and tolerance", node, text)
end

#style_warning(node, msg, text = nil) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/metanorma/ieee/validate_style.rb', line 28

def style_warning(node, msg, text = nil)
  return if @novalid

  w = msg
  w += ": #{text}" if text
  @log.add("Style", node, w)
end

#subclause_validate(root) ⇒ Object

Style manual 13.1



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

def subclause_validate(root)
  root.xpath("//clause/clause/clause/clause/clause/clause")
    .each do |c|
    style_warning(c, "Exceeds the maximum clause depth of 5", nil)
  end
end

#table_extract_columns(table) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/metanorma/ieee/validate_style.rb', line 101

def table_extract_columns(table)
  ret = table.xpath(".//tr").each_with_object([]) do |tr, m|
    tr.xpath("./td | ./th").each_with_index do |d, i|
      m[i] ||= []
      m[i] << d.text
    end
  end
  ret.map { |x| x.is_a?(Array) ? x : [] }
end

#table_figure_name_validate(xmldoc, xrefs) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/metanorma/ieee/validate.rb', line 170

def table_figure_name_validate(xmldoc, xrefs)
  xmldoc.xpath("//table[.//figure]").each do |t|
    xmldoc.xpath(".//figure").each do |f|
      (i = f.at("./image") and !i["src"]&.start_with?("data:")) or next

      num = tablefigurenumber(t, f, xrefs)
      base = File.basename(i["src"])
      base == num or
        @log.add("Style", i,
                 "Image name #{base} is expected to be #{num}")
    end
  end
end

#table_figure_quantity_validate(xmldoc) ⇒ Object



193
194
195
196
197
198
199
# File 'lib/metanorma/ieee/validate.rb', line 193

def table_figure_quantity_validate(xmldoc)
  xmldoc.xpath("//td[.//image] | //th[.//image]").each do |d|
    d.xpath(".//image").size > 1 and
      @log.add("Style", d,
               "More than one image in the table cell")
  end
end

#table_footnote_renumber1(fnote, idx, seen) ⇒ Object



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

def table_footnote_renumber1(fnote, idx, seen)
  content = footnote_content(fnote)
  idx += 1
  if seen[content]
    fnote.children = "<p>See Footnote #{seen[content]}.</p>"
  else seen[content] = idx
  end
  fnote["reference"] = (idx - 1 + "a".ord).chr
  fnote["table"] = true
  [idx, seen]
end

#table_style(docxml) ⇒ Object

Style manual 16.2, 16.3.2



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

def table_style(docxml)
  docxml.xpath("//td").each do |td|
    style_regex(/^(?<num>[\u2212-]?[0-9]{5,}[.0-9]*|-?[0-9]+\.[0-9]{5,})$/,
                "number in table not broken up in threes", td, td.text)
  end
  docxml.xpath("//table").each { |t| table_style_columns(t) }
  docxml.xpath("//table/name | //th").each do |td|
    style_regex(/^(?<num>\p{Lower}\S*)/, "table heading should be capitalised",
                td, td.text)
  end
end

#table_style_columns(table) ⇒ Object

deliberately doing naive, ignoring rowspan



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

def table_style_columns(table)
  table_extract_columns(table).each do |col|
    col.any? do |x|
      /^[0-9. ]+$/.match?(x) &&
        (/\d{3} \d/.match?(x) || /\d \d{3}/.match?(x))
    end or next

    col.each do |x|
      /^[0-9. ]+$/.match?(x) && /\d{4}/.match?(x) and
        @log.add("Style", table,
                 "#{x} is a 4-digit number in a table column with " \
                 "numbers broken up in threes")
    end
  end
end

#tablefigurenumber(table, figure, xrefs) ⇒ Object



184
185
186
187
188
189
190
191
# File 'lib/metanorma/ieee/validate.rb', line 184

def tablefigurenumber(table, figure, xrefs)
  tab = xrefs.anchor(table["id"], :label)
  td = figure.at("./ancestor::td | ./ancestor::th")
  cols = td.xpath("./preceding-sibling::td | ./preceding-sibling::td")
  rows = td.parent.xpath("./preceding::tr") &
    td.at("./ancestor::table").xpath(".//tr")
  "Tab#{tab}Row#{rows.size + 1}Col#{cols.size + 1}"
end

#term_defs_boilerplate_cont(src, term, isodoc) ⇒ Object



130
# File 'lib/metanorma/ieee/cleanup.rb', line 130

def term_defs_boilerplate_cont(src, term, isodoc); end

#termdef_boilerplate_insert(xmldoc, isodoc, once = false) ⇒ Object



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

def termdef_boilerplate_insert(xmldoc, isodoc, once = false)
  once = true
  super
end

#termlookup_cleanup(xmldoc) ⇒ Object



132
133
134
# File 'lib/metanorma/ieee/cleanup.rb', line 132

def termlookup_cleanup(xmldoc)
  Metanorma::IEEE::TermLookupCleanup.new(xmldoc, @log).call
end

#termsource_attrs(node, matched) ⇒ Object



46
47
48
49
50
# File 'lib/metanorma/ieee/converter.rb', line 46

def termsource_attrs(node, matched)
  ret = super
  node.option? "adapted" and ret[:status] = "adapted"
  ret
end

#title_validate(xml) ⇒ Object



111
112
113
114
# File 'lib/metanorma/ieee/validate_style.rb', line 111

def title_validate(xml)
  title_validate_type(xml)
  title_validate_capitalisation(xml)
end

#title_validate_capitalisation(xml) ⇒ Object

Style Manual 11.3



141
142
143
144
145
146
147
148
149
150
# File 'lib/metanorma/ieee/validate_style.rb', line 141

def title_validate_capitalisation(xml)
  title = xml.at("//bibdata/title") or return
  found = false
  title.text.split(/[ -]/).each do |w|
    /^[[:upper:]]/.match?(w) or preposition?(w) or
      found = true
  end
  found and @log.add("Style", title,
                     "Title contains uncapitalised word other than preposition")
end

#title_validate_type(xml) ⇒ Object

Style Manual 11.3



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

def title_validate_type(xml)
  title = xml.at("//bibdata/title") or return
  draft = xml.at("//bibdata//draft")
  type = xml.at("//bibdata/ext/doctype")
  trial = xml.at("//bibdata/ext/trial-use[text() = 'true']")
  target = draft ? "Draft " : ""
  target += trial ? "Trial-Use " : ""
  target += type ? "#{strict_capitalize_phrase(type.text)} " : ""
  /^#{target}/.match?(title.text) or
    @log.add("Style", title,
             "Expected title to start as: #{target}")
end

#tm_id_extract(relations) ⇒ Object



237
238
239
240
241
242
243
# File 'lib/metanorma/ieee/cleanup.rb', line 237

def tm_id_extract(relations)
  relations.map do |u|
    u.at("./bibitem/docidentifier[@scope = 'trademark']") ||
      u.at("./bibitem/docidentifier[@primary = 'true']") ||
      u.at("./bibitem/docidentifier")
  end.map(&:text)
end

#trademark_ieee_erefs(xmldoc) ⇒ Object

Style manual 12.3.5



79
80
81
82
83
84
85
86
87
88
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 79

def trademark_ieee_erefs(xmldoc)
  ieee = xmldoc.xpath("//references/bibitem")
    .each_with_object({}) do |b, m|
    n = b.at("./contributor[role/@type = 'publisher']/organization/name")
    n&.text == "Institute of Electrical and Electronics Engineers" and
      m[b["id"]] = b.at("./docidentifier[@scope = 'trademark']")&.text
  end
  trademark_ieee_erefs1(xmldoc, "//preface//eref", ieee)
  trademark_ieee_erefs1(xmldoc, "//sections//eref | //annex//eref", ieee)
end

#trademark_ieee_erefs1(xmldoc, path, ieee) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 90

def trademark_ieee_erefs1(xmldoc, path, ieee)
  xmldoc.xpath(path).each_with_object({}) do |e, m|
    ieee[e["bibitemid"]] or next
    m[e["bibitemid"]] or e["citeas"] = ieee[e["bibitemid"]]
    m[e["bibitemid"]] = true
  end
end

#validate(doc) ⇒ Object



7
8
9
10
11
# File 'lib/metanorma/ieee/validate.rb', line 7

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

#word_usage(xml) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/metanorma/ieee/cleanup.rb', line 40

def word_usage(xml)
  @document_scheme == "ieee-sa-2021" or return
  n = xml.at("//boilerplate//clause[@id = 'boilerplate_word_usage']")
    &.remove
  s = xml.at("//clause[@type = 'overview']")
  (n && s) or return
  s << n
end

#xrefs(xmldoc) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/metanorma/ieee/validate.rb', line 130

def xrefs(xmldoc)
  klass = IsoDoc::IEEE::HtmlConvert.new(language: @lang, script: @script)
  xrefs = IsoDoc::IEEE::Xref
    .new(@lang, @script, klass, IsoDoc::IEEE::I18n.new(@lang, @script),
         { hierarchicalassets: @hierarchical_assets })
  xrefs.parse(Nokogiri::XML(xmldoc.to_xml))
  xrefs
end