Class: Metanorma::Ieee::Cleanup

Inherits:
Standoc::Cleanup
  • Object
show all
Defined in:
lib/metanorma/ieee/cleanup.rb,
lib/metanorma/ieee/cleanup_ref.rb,
lib/metanorma/ieee/cleanup_ref_fn.rb,
lib/metanorma/ieee/cleanup_boilerplate.rb

Constant Summary collapse

TERM_CLAUSE =
"//sections//terms".freeze
BIBLIO =
"//bibliography/references[@normative = 'false'][not(@hidden)] | " \
"//bibliography/clause[.//references[@normative = 'false']] | " \
"//annex//references[@normative = 'false'][not(@hidden)]".freeze
IEEE =
"Institute of Electrical and Electronics Engineers".freeze
AVAIL_MATCH =
<<~XPATH.freeze
  [contains(concat(',', normalize-space(translate(@type, ' ', '')), ','), ',Availability,')]
XPATH
BIBITEM_NO_AVAIL =
"//references[@normative='true']/bibitem[not(note#{AVAIL_MATCH})] | "\
        "//references[@normative='false']/bibitem[not(note#{AVAIL_MATCH})]"
.freeze
AVAIL_PUBS =
{
  ieee: IEEE,
  cispr: "International special committee on radio interference",
  etsi: "European Telecommunications Standards Institute",
  oasis: "OASIS",
  "w3c": "World Wide Web Consortium",
  "3gpp": "3rd Generation Partnership Project",
}.freeze
PARTICIPANT_BOILERPLATE_LOCATIONS =
{ "boilerplate-participants-wg": "working group",
"boilerplate-participants-bg": "balloting group",
"boilerplate-participants-sb": "standards board",
"boilerplate-participants-blank": nil }.freeze

Instance Method Summary collapse

Instance Method Details

#available_note(xmldoc, provenance_notes) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/metanorma/ieee/cleanup_ref_fn.rb', line 43

def available_note(xmldoc, provenance_notes)
  bibitems = sorted_bibitem_no_avail(xmldoc)
  iso_iec_available_note(bibitems, provenance_notes["iso-iec"], true,
                         true)
  iso_iec_available_note(bibitems, provenance_notes["iso"], true, false)
  iso_iec_available_note(bibitems, provenance_notes["iec"], false, true)
  itu_available_note(bibitems, provenance_notes["itut"], true)
  itu_available_note(bibitems, provenance_notes["itur"], false)
  nist_available_note(bibitems, provenance_notes["fips"], true)
  nist_available_note(bibitems, provenance_notes["nist"], false)
  ietf_available_note(bibitems, provenance_notes["ietf"])
  AVAIL_PUBS.each do |k, v|
    sdo_available_note(bibitems, provenance_notes[k.to_s], v)
  end
end

#bib_pubs(bib) ⇒ Object



165
166
167
168
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 165

def bib_pubs(bib)
  bib.xpath("./contributor[role/@type = 'publisher']/organization/name")
    .map(&:text)
end

#bibdata_cleanup(xmldoc) ⇒ Object



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

def bibdata_cleanup(xmldoc)
  super
  draft_id(xmldoc)
  main_title(xmldoc)
  prefixed_title(xmldoc)
  provenance_title(xmldoc)
end

#bibitem_cleanup(xmldoc) ⇒ Object



149
150
151
152
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 149

def bibitem_cleanup(xmldoc)
  super
  supply_withdrawn_notes(xmldoc)
end

#biblio_preface(ref) ⇒ Object



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

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

#biblio_renumber(xmldoc) ⇒ Object



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

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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 120

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

#biblio_reorder(xmldoc) ⇒ Object



160
161
162
163
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 160

def biblio_reorder(xmldoc)
  super
  available_note(xmldoc, @provenance_notes)
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



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

def boilerplate_file(xmldoc)
  file = "boilerplate.adoc"
  doctype = xmldoc.at("//bibdata/ext/doctype")&.text
  doctype == "whitepaper" and file = "boilerplate_wp.adoc"
  File.join(@libdir, file)
end

#boilerplate_isodoc(xmldoc) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/metanorma/ieee/cleanup.rb', line 97

def boilerplate_isodoc(xmldoc)
  x = dup_with_namespace(xmldoc.root)
  xml = Nokogiri::XML(x.to_xml)
  @isodoc ||= isodoc(@lang, @script, @locale)
  @isodoc.bibdata_i18n(xml.at("//xmlns:bibdata"))
  @isodoc.localdir = @localdir
  @isodoc.info(xml, nil)
  @isodoc
end

#designator_docid(bib) ⇒ Object



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

def designator_docid(bib)
  n = bib.at("./docidentifier[@primary = 'true']") ||
    bib.at("./docidentifier[not(#{@conv.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
53
54
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 42

def designator_or_name(bib)
  id = designator_docid(bib)
  if %w(standard techreport).include?(bib["type"]) && id != "ZZZZ" &&
      id != bib.at("./docidentifier[@type='metanorma']")&.text
    ret = id
  else
    bib1 = dup_with_namespace(bib)
    n = @i.creatornames(bib1)
    n.nil? && bib["type"].nil? and n = id
    ret = n
  end
  [ret, id]
end

#draft_id(xmldoc) ⇒ Object

IEEE Draft Std 10000-2025/D1.2 => P10000/D1.2 TODO: this needs to go to pubid-ieee



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

def draft_id(xmldoc)
  published?(xmldoc.at("//bibdata/status/stage")&.text, xmldoc) and return
  id = xmldoc.at("//bibdata/docidentifier[@type = 'IEEE']") or return
  id.text.start_with?("IEEE Draft Std ") or return
  n = id.text.sub(/^IEEE Draft Std /, "P").sub(/(\d)-(\d\d\d\d)/, "\\1")
  id.next = %(<docidentifier type="IEEE-draft">#{n}</docidentifier>)
end

#emeritus_sign(xml) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/metanorma/ieee/cleanup_boilerplate.rb', line 66

def emeritus_sign(xml)
  p = xml.at(".//p[@type = 'emeritus_sign']") or return
  ul = xml.at("//clause[@anchor = 'boilerplate-participants-sb']//ul") or
    return
  has_asterisk = ul.xpath(".//p")&.any? do |li|
    li.text.strip.end_with?("*")
  end
  if has_asterisk then ul.next = p
  else p.remove
  end
end

#empty_docid_to_title?(bibitem) ⇒ Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 170

def empty_docid_to_title?(bibitem)
    bibitem["type"] == "standard"
end

#extract_participants(dlist) ⇒ Object



122
123
124
125
126
127
128
129
130
131
# File 'lib/metanorma/ieee/cleanup_boilerplate.rb', line 122

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] = text_from_paras(dtd)
  end
  map["company"] &&= "<span class='organization'>#{map['company']}</span>"
  map["role"] ||= "member"
  map
end

#footnote_boilerplate_renumber(xml) ⇒ Object



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

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

#ietf_available_note(bibitems, note) ⇒ Object



77
78
79
80
81
82
# File 'lib/metanorma/ieee/cleanup_ref_fn.rb', line 77

def ietf_available_note(bibitems, note)
  ret = bibitems.detect do |b|
    b.at("./docidentifier[@type = 'IETF']")
  end
  insert_availability_note(ret, note)
end

#initial_boilerplate(xml, isodoc) ⇒ Object



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

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



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

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

#insert_availability_note(bib, msg) ⇒ Object



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

def insert_availability_note(bib, msg)
  bib or return
  Array(msg).each do |msg1|
    note = %(<note type="Availability"><p>#{msg1}</p></note>)
    if b = insert_availability_note_ins(bib)
      b.next = note
    end
  end
end

#insert_availability_note_ins(bib) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/metanorma/ieee/cleanup_ref_fn.rb', line 112

def insert_availability_note_ins(bib)
  if b = bib.at("./language | ./script | ./abstract | ./status")
    b.previous
  else bib.at("./contributor") || bib.at("./date") ||
    bib.at("./docnumber") || bib.at("./docidentifier") ||
    bib.at("./title")
  end
end

#intro_boilerplate(xml, isodoc) ⇒ Object



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

def intro_boilerplate(xml, isodoc)
  intro = xml.at("//introduction/title") or return
  adm = isodoc.populate_template(@i18n.introduction_disclaimer)
  intro.next = "<admonition>#{adm}</admonition>"
  add_id(intro.next)
end

#iso_iec_available_note(bibitems, note, iso, iec) ⇒ Object



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

def iso_iec_available_note(bibitems, note, iso, iec)
  ret = bibitems.detect do |b|
    pubs = bib_pubs(b)
    has_iec = pubs.include?("International Electrotechnical Commission")
    has_iso = pubs.include?("International Organization for Standardization")
    ((has_iec && iec) || (!has_iec && !iec)) &&
      ((has_iso && iso) || (!has_iso && !iso))
  end
  insert_availability_note(ret, note)
end

#itu_available_note(bibitems, note, itu_t) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/metanorma/ieee/cleanup_ref_fn.rb', line 84

def itu_available_note(bibitems, note, itu_t)
  ret = bibitems.detect do |b|
    has_itu_t = /^ITU-T/.match?(b.at("./docidentifier[@type = 'ITU']")&.text)
    bib_pubs(b).include?("International Telecommunication Union") &&
      !has_itu_t && !itu_t || (has_itu_t && itu_t)
  end
  insert_availability_note(ret, note)
end

#main_title(xmldoc) ⇒ Object



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

def main_title(xmldoc)
  t = xmldoc.at("//bibdata/title[@type = 'main']") and
    t["type"] = "title-main"
  t = xmldoc.at("//bibdata/title[@type = 'title-full']") and
    t["type"] = "main"
end

#nist_available_note(bibitems, note, fips) ⇒ Object



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

def nist_available_note(bibitems, note, fips)
  ret = bibitems.detect do |b|
    id = b.at("./docidentifier[@type = 'NIST']")
    has_fips = /\bFIPS\b/.match?(id&.text)
    id && ((has_fips && !fips) || (!has_fips && fips))
  end
  insert_availability_note(ret, note)
end

#normref_cleanup(xmldoc) ⇒ Object



63
64
65
66
67
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 63

def normref_cleanup(xmldoc)
  super
  normref_no_ordinals(xmldoc)
  normref_reorder(xmldoc)
end

#normref_no_ordinals(xmldoc) ⇒ Object



69
70
71
72
73
74
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 69

def normref_no_ordinals(xmldoc)
  xmldoc.xpath("//references[@normative = 'true']/bibitem/" \
              "docidentifier[@type = 'metanorma']").each do |d|
    /^\[?\d+\]?$/.match?(d.text) and d.remove
  end
end

#normref_reorder(xmldoc) ⇒ Object



76
77
78
79
80
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 76

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

#note_cleanup(xmldoc) ⇒ Object



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

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

#obligations_cleanup_norm(xml) ⇒ Object



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

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

#other_footnote_renumber1(fnote, idx, seen) ⇒ Object



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

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

#overview_children_cleanup(xml) ⇒ Object



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

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



21
22
23
24
# File 'lib/metanorma/ieee/cleanup.rb', line 21

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

#overview_once_cleanup(xml) ⇒ Object



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

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



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

def participants(xml)
  @document_scheme == "ieee-sa-2021" or return
  PARTICIPANT_BOILERPLATE_LOCATIONS.each do |k, v|
    populate_participants(xml, k.to_s, v)
  end
  emeritus_sign(xml)
  xml.at("//sections//clause[@type = 'participants']")&.remove
end

#participants_dl_to_ul(clause) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/metanorma/ieee/cleanup_boilerplate.rb', line 97

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

#populate_participants(xml, target, subtitle) ⇒ Object



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

def populate_participants(xml, target, subtitle)
  t = xml.at("//clause[@anchor = '#{target}']/membership") or return
  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



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

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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/metanorma/ieee/cleanup_boilerplate.rb', line 106

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

#prefixed_title(xmldoc) ⇒ Object



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

def prefixed_title(xmldoc)
  t, stage, trial = prefixed_title_prep(xmldoc)
  %w(main title-abbrev).reverse_each do |type|
    xmldoc.at("//bibdata/title[@type = '#{type}']") and next
    p = prefixed_title1(stage, trial, type)
    t.previous = <<~XML
      <title type='#{type}' language='en'>#{p}#{to_xml(t.children)}</title>
    XML
  end
end

#prefixed_title1(stage, trial, type) ⇒ Object



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

def prefixed_title1(stage, trial, type)
  m = []
  m << (stage == "draft" ? "Draft" : "IEEE")
  trial and m << "Trial-Use"
  doctype = @doctype.split(/[- ]/).map(&:capitalize).join(" ")
  type == "title-abbrev" && a = @i18n.get["doctype_abbrev"][@doctype] and
    doctype = a
  m << doctype
  m << "for"
  "#{m.join(' ')} "
end

#prefixed_title_prep(xmldoc) ⇒ Object



150
151
152
153
154
155
# File 'lib/metanorma/ieee/cleanup.rb', line 150

def prefixed_title_prep(xmldoc)
  t = xmldoc.at("//bibdata/title[@type = 'title-main']")
  stage = xmldoc.at("//status/stage")&.text
  trial = xmldoc.at("//bibdata/ext/trial-use[text() = 'true']")
  [t, stage, trial]
end

#provenance_title(xmldoc) ⇒ Object



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

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[@type = 'title-main']")
  t = provenance_title1(u, m)
  ins.next = "<title type='provenance' language='en'>#{t}</title>"
end

#provenance_title1(updates, merges) ⇒ Object



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

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

#published?(stage, _xmldoc) ⇒ Boolean

Returns:

  • (Boolean)


186
187
188
# File 'lib/metanorma/ieee/cleanup.rb', line 186

def published?(stage, _xmldoc)
  %w(approved superseded withdrawn).include?(stage&.downcase)
end

#quotesource_cleanup(xmldoc) ⇒ Object

end of citeas generation



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

def quotesource_cleanup(xmldoc)
  super
  trademark_ieee_erefs(xmldoc)
end

#sdo_available_note(bibitems, note, publisher) ⇒ Object



59
60
61
62
63
64
# File 'lib/metanorma/ieee/cleanup_ref_fn.rb', line 59

def sdo_available_note(bibitems, note, publisher)
  ret = bibitems.detect do |b|
    bib_pubs(b).include?(publisher)
  end
  insert_availability_note(ret, note)
end

#section_names_refs_cleanup(xml) ⇒ Object



144
145
146
147
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 144

def section_names_refs_cleanup(xml)
  @doctype == "whitepaper" or return super
  replace_title(xml, "//bibliography/references", @i18n&.references, true)
end

#sections_cleanup(xml) ⇒ Object



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

def sections_cleanup(xml)
  super
  overview_cleanup(xml)
end

#select_docid(ref, type = nil) ⇒ Object



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

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

#sort_biblio(bib) ⇒ Object



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

def sort_biblio(bib)
  @i = IsoDoc::Ieee::PresentationXMLConvert
    .new({ lang: @lang, script: @script, locale: @locale })
  @i.i18n_init(@lang, @script, @locale)
  sort_keys = bib.each_with_object({}) do |b, m|
    m[b["id"]] = sort_biblio_key(b)
  end
  bib.sort { |a, b| sort_keys[a["id"]] <=> sort_keys[b["id"]] }
end

#sort_biblio_key(bib) ⇒ Object

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



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

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

#sorted_bibitem_no_avail(xmldoc) ⇒ Object



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

def sorted_bibitem_no_avail(xmldoc)
  # Get normative references first, maintaining their order
  normative_bibitems = xmldoc.xpath("//references[@normative='true']/" \
    "bibitem[not(note#{AVAIL_MATCH})]")
  # Get non-normative references second, maintaining their order
  non_normative_bibitems = xmldoc.xpath("//references[@normative='false']/" \
    "bibitem[not(note#{AVAIL_MATCH})]")
  # Return concatenated array with normative first
  normative_bibitems.to_a + non_normative_bibitems.to_a
end

#supply_withdrawn_notes(xmldoc) ⇒ Object



154
155
156
157
158
# File 'lib/metanorma/ieee/cleanup_ref.rb', line 154

def supply_withdrawn_notes(xmldoc)
  f = File.join(File.dirname(__FILE__), "ieee-footnotes.yaml")
  @provenance_notes = YAML.safe_load(File.read(f))
  withdrawn_note(xmldoc, @provenance_notes)
end

#table_footnote_renumber1(fnote, idx, seen) ⇒ Object



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

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

#term_defs_boilerplate_cont(src, term, isodoc) ⇒ Object



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

def term_defs_boilerplate_cont(src, term, isodoc); end

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



86
87
88
89
# File 'lib/metanorma/ieee/cleanup.rb', line 86

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

#termlookup_cleanup(xmldoc) ⇒ Object



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

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

#text_from_paras(node) ⇒ Object



107
108
109
110
# File 'lib/metanorma/ieee/cleanup.rb', line 107

def text_from_paras(node)
  r = node.at("./p") and node = r
  node.children.to_xml.strip
end

#tm_id_extract(relations) ⇒ Object



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

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



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

def trademark_ieee_erefs(xmldoc)
  ieee = xmldoc.xpath("//references/bibitem")
    .each_with_object({}) do |b, m|
    bib_pubs(b).include?(IEEE) and
      m[b["anchor"]] = 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



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

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

#withdrawn_note(xmldoc, provenance_notes) ⇒ Object



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

def withdrawn_note(xmldoc, provenance_notes)
  sorted_bibitem_no_avail(xmldoc).each do |b|
    bib_pubs(b).include?(IEEE) or next
    b.at("./status/stage")&.text == "withdrawn" or next
    docid = b.at("./docidentifier[@type = 'IEEE'][not(@scope)]")
    note = provenance_notes["ieee-withdrawn"].sub("%", docid.text)
    insert_availability_note(b, note)
  end
end

#word_usage(xml) ⇒ Object



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

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