Class: IsoDoc::Ieee::PresentationXMLConvert

Inherits:
PresentationXMLConvert
  • Object
show all
Includes:
Init
Defined in:
lib/isodoc/ieee/presentation_ref.rb,
lib/isodoc/ieee/presentation_terms.rb,
lib/isodoc/ieee/presentation_bibdata.rb,
lib/isodoc/ieee/presentation_bibitem.rb,
lib/isodoc/ieee/presentation_concepts.rb,
lib/isodoc/ieee/presentation_xml_convert.rb

Instance Method Summary collapse

Methods included from Init

#bibrenderer, #fileloc, #i18n_init, #metadata_init, #std_docid_sdo, #std_docid_semantic, #std_docid_semantic1, #std_docid_semantic_full, #xref_init

Constructor Details

#initialize(options) ⇒ PresentationXMLConvert

Returns a new instance of PresentationXMLConvert.



12
13
14
15
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 12

def initialize(options)
  @hierarchical_assets = options[:hierarchicalassets]
  super
end

Instance Method Details



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

def admitted_to_related(docxml)
  docxml.xpath(ns("//term")).each do |t|
    t.xpath(ns("./fmt-admitted/semx | ./fmt-preferred/semx"))
      .each_with_index do |a, i|
      orig = semx_orig(a)
      (i.zero? ||
       orig.at(ns("./abbreviation-type | ./graphical-symbol"))) and next
      out = t.at(ns("./fmt-related")) || t.at(ns("./definition"))
        .before("<fmt-related/>").previous
      admitted_to_related1(a, t.at(ns("./fmt-preferred/semx")), out)
      a.parent.name == "fmt-preferred" and a.remove
    end
    t.at(ns("./fmt-admitted"))&.remove
  end
end

#admitted_to_related1(adm, pref, out) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 101

def admitted_to_related1(adm, pref, out)
  out << <<~TERM
    <semx element='related' source='#{adm['source']}' type='equivalent'><fmt-preferred>#{to_xml(adm)}</p></semx></fmt-preferred>
  TERM
  out.parent.next = <<~TERM
    <term #{add_id_text}><fmt-preferred>#{to_xml(adm)}</fmt-preferred>
    <fmt-related>
      <semx element="related" source="#{pref['source']}" type="see"><fmt-preferred>#{to_xml(pref)}</fmt-preferred></semx>
    </fmt-related>
    <fmt-definition></fmt-definition></term>
  TERM
end

#affiliation_header(clause) ⇒ Object



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

def affiliation_header(clause)
  clause.xpath(ns(".//p[@type = 'officeorgrepmember']")).each do |p|
    prev = p.previous_element
    prev && prev.name == "p" &&
      prev["type"] == "officeorgrepmember" and next
    p.previous = <<~HDR
      <p type='officeorgrepmemberhdr'><em>Organization
      Represented</em><tab/><em>Name of Representative</em></p>
    HDR
  end
end

#amend1(elem) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 49

def amend1(elem)
  elem.xpath(ns("./description/p")).each do |p|
    p.children = to_xml(p.children).strip
    amend_format(p)
  end
  super
end

#amend_format(para) ⇒ Object



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

def amend_format(para)
  2.times do
    para.children.size == 1 &&
      %(em strong).include?(para.children.first.name) and
      para.children = para.elements.first.children
  end
  para.children = "<strong><em>#{to_xml(para.children)}</em></strong>"
end

#anchor_linkend(node, linkend) ⇒ Object

Style manual 19



19
20
21
22
23
24
25
26
27
# File 'lib/isodoc/ieee/presentation_ref.rb', line 19

def anchor_linkend(node, linkend)
  if node["citeas"] && i = @bibanchors[node["bibitemid"]]
    biblio_anchor_linkend(node, i)
  elsif node["citeas"] && (i = @normrefanchors[node["bibitemid"]])
    cit = normref_anchor_linkend(node, i)
    cit || super
  else super
  end
end

#anchor_linkend1(node) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# File 'lib/isodoc/ieee/presentation_ref.rb', line 131

def anchor_linkend1(node)
  linkend = @xrefs.anchor(node["target"], :xref)
  @xrefs.anchor(node["target"], :type) == "clause" &&
    @xrefs.anchor(node["target"], :level) > 1 &&
    !start_of_sentence(node) and
    linkend = strip_initial_clause(linkend)
  container = @xrefs.anchor(node["target"], :container, false)
  linkend = prefix_container(container, linkend, node, node["target"])
  capitalise_xref(node, linkend, anchor_value(node["target"]))
end

#annex1(elem) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 25

def annex1(elem)
  if @doctype == "whitepaper"
    annex1_whitepaper(elem)
  else
    super
  end
end

#annex1_whitepaper(elem) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 33

def annex1_whitepaper(elem)
  lbl = @xrefs.anchor(elem["id"], :label)
  if t = elem.at(ns("./title"))
    d = t.dup
    # TODO fmt-variant-title
    d.name = "variant-title"
    d["type"] = "sub"
    t.next = d
  end
  elem.add_first_child "<fmt-title>#{lbl}</fmt-title>"
end

#annex_delim(_elem) ⇒ Object



45
46
47
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 45

def annex_delim(_elem)
  "<br/>"
end

#asciimath_dup(node) ⇒ Object



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

def asciimath_dup(node)
  @suppressasciimathdup and return
  super
  node.parent.at(ns("./latexmath")) and return
  math = node.to_xml.gsub(/ xmlns=["'][^"']+["']/, "")
    .gsub(%r{<[^:/]+:}, "<").gsub(%r{</[^:/]+:}, "</")
  ret = Plurimath::Math.parse(math, "mathml").to_latex
  ret = HTMLEntities.new.encode(ret, :basic)
  node.next = "<latexmath>#{ret}</latexmath>"
rescue StandardError => e
  warn "Failure to convert MathML to LaTeX\n#{node.parent.to_xml}\n#{e}"
end

#author_date(xml, renderings) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 30

def author_date(xml, renderings)
  author_date?(xml) or return
  cit = renderings[xml["id"]][:citation]
  xml << "<docidentifier type='metanorma'>#{cit}</docidentifier>"
  xml.at(ns("./biblio-tag"))&.remove
  xml << "<biblio-tag>#{cit}, </biblio-tag>"
end

#author_date?(xml) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 38

def author_date?(xml)
  ret = !xml["type"]
  ret ||= %w(standard techreport website webresource)
    .include?(xml["type"])
  ret ||= xml.at(".//ancestor::xmlns:references[@normative = 'false']")
  ret ||= xml.at(ns("./docidentifier[@type = 'metanorma']"))
  ret and return false
  true
end

#availability_note(bib) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 78

def availability_note(bib)
  notes = bib.xpath(ns("./note[@type = 'Availability']"))
  notes.map do |note|
    id = UUIDTools::UUID.random_create.to_s
    @new_ids[id] = nil
    "<fn id='#{id}' reference='#{id}'><p>#{note.content}</p></fn>"
  end.join
end

#bibdata_dates(bib) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 9

def bibdata_dates(bib)
  bib.xpath(ns("./date")).each do |d|
    d.next = d.dup
    d.next["format"] = "ddMMMyyyy"
    d.next.xpath(ns("./from | ./to | ./on")).each do |x|
      x.children = ddMMMyyyy(x.text)
    end
  end
end

#bibdata_i18n(bib) ⇒ Object



4
5
6
7
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 4

def bibdata_i18n(bib)
  super
  bibdata_dates(bib)
end

#biblio_anchor_linkend(node, bib) ⇒ Object



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

def biblio_anchor_linkend(node, bib)
  if %w(techreport standard).include?(bib[:type])
    if !node.children.empty?
      to_xml(node.children).strip
    elsif node["citeas"] == bib[:ord] then node["citeas"]
    else [node["citeas"], bib[:ord]].compact.join(" ")
    end
  else biblio_anchor_linkend_nonstd(node, bib)
  end
end

#biblio_anchor_linkend_nonstd(node, bib) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/isodoc/ieee/presentation_ref.rb', line 49

def biblio_anchor_linkend_nonstd(node, bib)
  node["style"] == "no-biblio-tag" or tag = node["citeas"]
  if !node.children.empty?
    "#{to_xml(node.children)} #{tag}".strip
  elsif node["style"] == "title" && bib[:title]
    "#{bib[:title]} #{tag}".strip
  elsif bib[:author] # default, also if node["style"] == "title"
    "#{bib[:author]} #{tag}".strip
  else tag.strip
  end
end

#biblio_ids_titles(xmldoc, normative) ⇒ Object



61
62
63
64
65
66
# File 'lib/isodoc/ieee/presentation_ref.rb', line 61

def biblio_ids_titles(xmldoc, normative)
  xmldoc.xpath(ns("//references[@normative = '#{normative}']/bibitem"))
    .each_with_object({}) do |b, acc|
    biblio_ids_titles1(b, acc)
  end
end

#biblio_ids_titles1(bib, acc) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/isodoc/ieee/presentation_ref.rb', line 68

def biblio_ids_titles1(bib, acc)
  acc[bib["id"]] =
    { docid: pref_ref_code(bib), type: bib["type"],
      title: bib.at(ns("./title")) || bib.at(ns("./formattedref")),
      author: @author[bib["id"]] || (bib.at(ns("./title")) ||
             bib.at(ns("./formattedref"))),
      ord: bib.at(ns("./docidentifier[@type = 'metanorma' or " \
                   "@type = 'metanorma-ordinal']")) }
  %i(title author ord).each do |k|
    acc[bib["id"]][k].is_a?(Nokogiri::XML::Node) and
      acc[bib["id"]][k] = acc[bib["id"]][k].text
  end
end

#bibliography_bibitem_number1(bibitem, idx, normative) ⇒ Object



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

def bibliography_bibitem_number1(bibitem, idx, normative)
  bibitem.xpath(ns(".//docidentifier[@type = 'metanorma' or " \
                   "@type = 'metanorma-ordinal']")).each do |mn|
    /^\[?B?\d\]?$/.match?(mn&.text) and mn.remove
  end
  unless bibliography_bibitem_number_skip(bibitem) || normative
    idx += 1
    docidentifier_insert_pt(bibitem).next =
      "<docidentifier type='metanorma-ordinal'>[B#{idx}]</docidentifier>"
  end
  idx
end

#bibrender_relaton(xml, renderings) ⇒ Object



11
12
13
14
15
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 11

def bibrender_relaton(xml, renderings)
  bibrender_relaton1(xml, renderings)
  author_date(xml, renderings)
  @author[xml["id"]] = renderings[xml["id"]][:author]
end

#bibrender_relaton1(xml, renderings) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 17

def bibrender_relaton1(xml, renderings)
  f = renderings[xml["id"]][:formattedref] or return
  fn = availability_note(xml)
  f = "<formattedref>#{f}#{fn}</formattedref>"
  if x = xml.at(ns("./formattedref"))
    x.replace(f)
  elsif xml.children.empty?
    xml << f
  else
    xml.children.first.previous = f
  end
end

#block_delimObject



17
18
19
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 17

def block_delim
  "&#x2014;"
end

#boilerplate(docxml) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 31

def boilerplate(docxml)
  docxml.xpath(ns("//clause[@id = 'boilerplate-participants']/" \
                  "clause/title")).each(&:remove)
  docxml.xpath(ns("//clause[@id = 'boilerplate-participants']/clause"))
    .each do |clause|
    participants(clause)
  end
end

#bracket_if_num(num) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 92

def bracket_if_num(num)
  num.nil? and return nil
  ret = num.dup
  ret.xpath(ns(".//fn")).each(&:remove)
  ret = ret.text.strip.sub(/^\[/, "").sub(/\]$/, "")
  /^B?\d+$/.match?(ret) and return "[#{ret}]"
  ret
end

#citestyleObject



82
83
84
# File 'lib/isodoc/ieee/presentation_ref.rb', line 82

def citestyle
  "author-date"
end

#cleanup(docxml) ⇒ Object



179
180
181
182
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 179

def cleanup(docxml)
  termsource_brackets(docxml)
  super
end

#collapse_term(docxml) ⇒ Object



87
88
89
# File 'lib/isodoc/ieee/presentation_terms.rb', line 87

def collapse_term(docxml)
  docxml.xpath(ns("//term")).each { |t| collapse_term1(t) }
end

#collapse_term1(term) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/isodoc/ieee/presentation_terms.rb', line 91

def collapse_term1(term)
  ret = collapse_term_template(
    pref: term.at(ns("./fmt-preferred"))&.remove,
    def: term.at(ns("./fmt-definition")),
    rels: term.at(ns("./fmt-related"))&.remove,
    source: term.at(ns("./fmt-termsource"))&.remove,
    fns: term.xpath(ns("./fn")).map(&:remove),
  )
  term.at(ns("./fmt-admitted"))&.remove
  ins = term.at(ns("./fmt-definition")) and
    ins.children = ret
end

#collapse_term_pref(opt) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/isodoc/ieee/presentation_terms.rb', line 146

def collapse_term_pref(opt)
  p = opt[:pref]
  p.text.strip.empty? and return "**TERM NOT FOUND**"
  wrap_termsource_in_parens(p.xpath(ns(".//semx[@element = 'source']")))
  p.xpath(ns(".//fmt-termsource")).each { |x| x.replace(x.children) }
  to_xml(p.children).strip
end


104
105
106
107
108
109
110
111
112
# File 'lib/isodoc/ieee/presentation_terms.rb', line 104

def collapse_term_related(rels)
  rels or return
  collapse_term_related1(rels)
  ret = rels.xpath(ns("./p")).map do |x|
    to_xml(x.children).strip
  end.join(". ")
  ret += "." unless ret.empty?
  ret
end

#collapse_term_related1(rels) ⇒ Object



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

def collapse_term_related1(rels)
  rels.xpath(ns("./p")).each do |p|
    orig = p.at(ns(".//semx[@element = 'related']"))
    p.add_first_child "<em>#{@i18n.relatedterms[orig['type']]}:</em> "
    p.xpath(ns(".//semx[@element = 'related']")).each do |r|
      r.at(ns("./fmt-preferred")) or
        r.add_first_child "**RELATED TERM NOT FOUND**"
    end
  end
end

#collapse_term_template(opt) ⇒ Object



125
126
127
128
129
130
131
132
133
134
# File 'lib/isodoc/ieee/presentation_terms.rb', line 125

def collapse_term_template(opt)
  defn, multiblock = collapse_unwrap_definition(opt[:def])
  t = collapse_term_pref(opt)
  tail = collapse_term_template_tail(opt)
  if multiblock
    tail = tail.strip.empty? ? "" : "<p>#{tail}</p>"
    "<p>#{t}:</p> #{defn}#{tail}"
  else "<p>#{t}: #{defn} #{tail}</p>"
  end
end

#collapse_term_template_tail(opt) ⇒ Object



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

def collapse_term_template_tail(opt)
  if opt[:source]
    # For this context, we need to use the old string-based approach
    # since the source element has been removed from its parent
    src = "<span class='fmt-termsource-delim'>(</span>#{to_xml(opt[:source].children).strip}<span class='fmt-termsource-delim'>)</span>"
  end
  opt[:fns].empty? or fn = opt[:fns].map { |f| to_xml(f) }.join
  "#{collapse_term_related(opt[:rels])} #{src}#{fn}".strip
end

#collapse_unwrap_definition(defn) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/isodoc/ieee/presentation_terms.rb', line 154

def collapse_unwrap_definition(defn)
  defn.nil? and return nil, nil
  s = defn.xpath(ns(".//fmt-termsource"))
  p = defn.at(ns(".//p"))
  !s.empty? && p and p << s.map(&:remove).map(&:children)
    .map { |x| to_xml(x) }.join
  # fmt-definition/semx/p
  elems = defn.at(ns("./semx")) || defn
  multiblock = elems.at(ns("./table | ./formula | ./dl | ./ol | ./ul")) ||
    elems.xpath(ns("./p")).size > 1
  [defn.elements, multiblock]
end

#concept1(node) ⇒ Object



162
163
164
165
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 162

def concept1(node)
  concept_render(node, ital: "false", ref: "false", bold: "false",
                       linkref: "false", linkmention: "false")
end

#conversions(docxml) ⇒ Object

before processing, move license termnotes to fn at end of term, so they aren’t numbered as termnotes



171
172
173
174
175
176
177
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 171

def conversions(docxml)
  docxml.xpath(ns("//termnote[@type='license']"))
    .each_with_index do |n, i|
    license_termnote(n, i)
  end
  super
end

#creatornames(bib) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 48

def creatornames(bib)
  ::Relaton::Render::Ieee::General
    .new(language: @lang, i18nhash: @i18n.get,
         # template: { (bib["type"] || "misc").to_sym =>
         # "{{ creatornames }}" },
         template: "{{ creatornames }}",
         extenttemplate: { (bib["type"] || "misc").to_sym => "{{page}}" },
         sizetemplate: { (bib["type"] || "misc").to_sym => "{{data}}" })
    .render1(RelatonBib::XMLParser.from_xml(bib.to_xml))
end

#ddMMMyyyy(isodate) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 19

def ddMMMyyyy(isodate)
  isodate.nil? and return nil
  arr = isodate.split("-")
  if arr.size == 1 && (/^\d+$/.match isodate)
    Date.new(*arr.map(&:to_i)).strftime("%Y")
  elsif arr.size == 2
    Date.new(*arr.map(&:to_i)).strftime("%b %Y")
  else
    Date.parse(isodate).strftime("%d %b %Y")
  end
end

#deprecates(desgn) ⇒ Object



4
5
6
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 4

def deprecates(desgn)
  desgn.remove
end

#designation_boldface(desgn) ⇒ Object



8
9
10
11
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 8

def designation_boldface(desgn)
  name = desgn.at(ns("./expression/name | ./letter-symbol/name")) or return
  name.children = "<strong>#{name.children}</strong>"
end

#designation_field(desgn, name, orig) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 132

def designation_field(desgn, name, orig)
  if desgn["element"] == "preferred"
    f = orig.parent.xpath(ns("./domain | ./subject"))
      .map { |u| to_xml(semx_fmt_dup(u)) }.join(", ")
    f.empty? or
      name << "<span class='fmt-designation-field'>, &#x3c;#{f}&#x3e;</span>"
  end
  super
end

#docidentifier_insert_pt(bibitem) ⇒ Object



72
73
74
75
76
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 72

def docidentifier_insert_pt(bibitem)
  bibitem.at(ns(".//docidentifier"))&.previous ||
    bibitem.at(ns(".//title")) ||
    bibitem.at(ns(".//formattedref"))
end

#document_footnotes(docxml) ⇒ Object



184
185
186
187
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 184

def document_footnotes(docxml)
  first_biblio_eref_fn(docxml)
  super
end

#eref_localities1(opt) ⇒ Object



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

def eref_localities1(opt)
  opt[:type] == "anchor" and return nil
  opt[:type].downcase!
  opt[:lang] == "zh" and return l10n(eref_localities1_zh(opt))
  ret = ""
  opt[:node]["droploc"] != "true" &&
    !subclause?(opt[:target], opt[:type], opt[:from]) and
    ret = eref_locality_populate(opt[:type], opt[:node], opt[:number])
  ret += " #{opt[:from]}" if opt[:from]
  ret += "&#x2013;#{opt[:upto]}" if opt[:upto]
  ret += ")" if opt[:type] == "list"
  l10n(ret)
end

#eref_localities_conflated(refs, target, node) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/isodoc/ieee/presentation_ref.rb', line 90

def eref_localities_conflated(refs, target, node)
  droploc = node["droploc"]
  node["droploc"] = true
  ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
                                                      node))
  node["droploc"] = droploc
  p = prefix_clause(target, refs.first.at(ns("./locality")))
  eref_localities1({ target: target, number: "pl",
                     type: p,
                     from: l10n(ret[1..-1].join), node: node,
                     lang: @lang })
end

#eref_locality_populate(type, node, number) ⇒ Object



148
149
150
151
# File 'lib/isodoc/ieee/presentation_ref.rb', line 148

def eref_locality_populate(type, node, number)
  type == "page" and return ""
  super
end

#example1(elem) ⇒ Object



162
163
164
165
166
167
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 162

def example1(elem)
  super
  n = elem.at(ns("./fmt-name")) or return
  n << l10n("<span class='fmt-caption-delim'>:</span>")
  n.children.wrap("<em></em>")
end

#expand_citeas(text) ⇒ Object



86
87
88
# File 'lib/isodoc/ieee/presentation_ref.rb', line 86

def expand_citeas(text)
  std_docid_semantic(super)
end

#first_biblio_eref_fn(docxml) ⇒ Object



153
154
155
156
157
158
159
160
161
# File 'lib/isodoc/ieee/presentation_ref.rb', line 153

def first_biblio_eref_fn(docxml)
  @bibanchors ||= biblio_ids_titles(docxml)
  docxml.xpath("//*[@citeas]").each do |node|
    @bibanchors[node["bibitemid"]] or next
    node.children.empty? or next
    insert_biblio_footnote(node, docxml)
    break
  end
end

#inline(docxml) ⇒ Object



12
13
14
15
16
# File 'lib/isodoc/ieee/presentation_ref.rb', line 12

def inline(docxml)
  @bibanchors ||= biblio_ids_titles(docxml, false)
  @normrefanchors ||= biblio_ids_titles(docxml, true)
  super
end

temporarily insert related/@type to fmt-related/semx, for sorting



23
24
25
26
27
28
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 23

def insert_related_type(docxml)
  docxml.xpath(ns("//fmt-related/semx")).each do |r|
    orig = semx_orig(r)
    r["type"] = orig["type"]
  end
end

#license_termnote(elem, idx) ⇒ Object



194
195
196
197
198
# File 'lib/isodoc/ieee/presentation_terms.rb', line 194

def license_termnote(elem, idx)
  elem.name = "fn"
  elem["reference"] = "_termnote_license_#{idx}"
  elem.parent << elem
end

#merge_second_preferred(term) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 142

def merge_second_preferred(term)
  term.name == "fmt-admitted" and return
  pref =
    term.parent.at(ns("./preferred[not(abbreviation-type)][expression/name]"))
  x = term.parent.xpath(ns("./preferred[expression/name][abbreviation-type] | " \
                    "./admitted[expression/name][abbreviation-type]"))
  (pref && !x.empty?) or return
  fmt_pref = term.parent.at(ns(".//semx[@source = '#{pref['id']}']"))
  fdf = fmt_pref.at(ns(".//span[@class = 'fmt-designation-field']"))&.text
  out = to_xml(fmt_pref)
  tail = x.map do |p|
    ret = term.parent.at(ns(".//semx[@source = '#{p['id']}']")).remove
    fdf1 = ret.at(ns(".//span[@class = 'fmt-designation-field']"))
    fdf1 && (fdf1&.text == fdf) and fdf1.remove # repetition of domain suppressed
    to_xml(ret).strip
  end.join(", ")
  out += " (#{tail})"
  term.children = out
end

#middle_title(docxml) ⇒ Object



128
129
130
131
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 128

def middle_title(docxml)
  s = middle_title_insert(docxml) or return
  s.previous = middle_title_body
end

#middle_title_bodyObject



133
134
135
136
137
138
139
140
141
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 133

def middle_title_body
  ret = "<p class='zzSTDTitle1'>#{@meta.get[:full_doctitle]}"
  @meta.get[:amd] || @meta.get[:corr] and ret += "<br/>"
  @meta.get[:amd] and ret += "Amendment #{@meta.get[:amd]}"
  @meta.get[:amd] && @meta.get[:corr] and ret += " "
  @meta.get[:corr] and ret += "Corrigenda #{@meta.get[:corr]}"
  ret += "</p>"
  ret
end

#middle_title_insert(docxml) ⇒ Object



143
144
145
146
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 143

def middle_title_insert(docxml)
  s = docxml.at(ns("//sections")) or return
  s.children.first
end

#move_abstract(doc) ⇒ Object



153
154
155
156
157
158
159
160
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 153

def move_abstract(doc)
  doc.at(ns("//bibdata/ext/doctype"))&.text == "whitepaper" or return
  source = doc.at(ns("//preface/abstract")) or return
  dest = doc.at(ns("//sections")) ||
    doc.at(ns("//preface")).after("<sections> </sections>").next_element
  dest.children.empty? and dest.children = " "
  dest.children.first.next = source
end

#multidef(_elem, defn, fmt_defn) ⇒ Object



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

def multidef(_elem, defn, fmt_defn)
  ctr = IsoDoc::XrefGen::Counter.new("@")
  coll = defn.each_with_object([]) do |d, m|
    ctr.increment(d)
    ret = semx_fmt_dup(d)
    ret.at(ns("./verbal-definition | ./non-verbal-definition")).elements
      .first.add_first_child("<strong>(#{ctr.print})</strong>&#xa0;")
    m << ret
  end
  fmt_defn << coll.map { |c| to_xml(c) }.join(" ")
end

#normref_anchor_linkend(node, bib) ⇒ Object

force Author-Date referencing on non-standards in norm ref



30
31
32
33
34
35
36
# File 'lib/isodoc/ieee/presentation_ref.rb', line 30

def normref_anchor_linkend(node, bib)
   @ref_renderings or return nil
  %w(techreport standard).include?(bib[:type]) and return nil
  cit = @ref_renderings[node["bibitemid"]][:citation]&.strip
  cit.empty? and cit = nil
  cit
end

#note_delim(_elem) ⇒ Object



21
22
23
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 21

def note_delim(_elem)
  "&#x2014;"
end

#ol(docxml) ⇒ Object



84
85
86
87
88
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 84

def ol(docxml)
  ol_numbering(docxml)
  @xrefs.list_anchor_names(docxml.xpath(ns(@xrefs.sections_xpath)))
  docxml.xpath(ns("//ol/li")).each { |f| ol_label(f) }
end

#ol_depth_rotate(node, idx) ⇒ Object

overrides IsoDoc

XrefGen::OlTypeProvider: we trigger



111
112
113
114
115
116
117
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 111

def ol_depth_rotate(node, idx)
  depth = node.ancestors("ol").size + idx
  type = :alphabet
  type = :arabic if [2, 5, 8].include? depth
  type = :roman if [3, 6, 9].include? depth
  type
end

#ol_numbering(docxml) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 90

def ol_numbering(docxml)
  p = "//clause | //annex | //foreword | //acknowledgements | " \
      "//introduction | //preface/abstract | //appendix | //terms | " \
      "//term | //definitions | //references | //colophon"
  docxml.xpath(ns(p)).each do |c|
    (c.xpath(ns(".//ol")) -
    c.xpath(ns("./clause//ol | ./appendix//ol | ./term//ol | " \
               "./terms//ol | ./definitions//ol | " \
               "/references//ol | ./colophon//ol")))
      .each_with_index do |o, i|
      ol_numbering1(o, i)
    end
  end
end

#ol_numbering1(elem, idx) ⇒ Object



105
106
107
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 105

def ol_numbering1(elem, idx)
  elem["type"] = ol_depth_rotate(elem, idx).to_s
end

#omit_docid_prefix(prefix) ⇒ Object



87
88
89
90
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 87

def omit_docid_prefix(prefix)
  prefix == "DOI" and return true
  super
end

#participant_member_para(map, name, _idx) ⇒ Object



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

def participant_member_para(map, name, _idx)
  if map["company"] && (map["name"] || map["surname"])
    pers = map["name"] || "#{map['given']} #{map['surname']}"
    "<p type='officeorgrepmember'>#{name}<tab/>#{pers}</p>"
  elsif map["company"] then "<p type='officeorgmember'>#{name}</p>"
  else "<p type='officemember'>#{name}</p>"
  end
end

#participant_name(map) ⇒ Object



100
101
102
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 100

def participant_name(map)
  map["company"] || map["name"] || "#{map['given']} #{map['surname']}"
end

#participant_officeholder_para(map, name, idx) ⇒ Object



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

def participant_officeholder_para(map, name, idx)
  name = "<strong>#{name}</strong>" if idx.zero?
  br = map["role"].size > 30 ? "<br/>" : ""
  "<p type='officeholder' align='center'>#{name}, #{br}" \
    "<em><span class='au_role'>#{map['role']}</span></em></p>"
end

#participant_para(map, idx) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 75

def participant_para(map, idx)
  name = participant_name(map)
  if map["role"]&.casecmp("member")&.zero?
    participant_member_para(map, name, idx)
  else
    participant_officeholder_para(map, name, idx)
  end
end

#participants(clause) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 40

def participants(clause)
  clause.xpath(ns(".//ul")).each_with_index do |ulist, idx|
    ulist.xpath(ns("./li")).each { |list| participants1(list, idx) }
    ulist.replace(ulist.children)
  end
  affiliation_header(clause)
end

#participants1(list, idx) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 60

def participants1(list, idx)
  key = ""
  map = list.xpath(ns(".//dt | .//dd")).each_with_object({}) do |dtd, m|
    (dtd.name == "dt" and key = dtd.text) or
      m[key] = text_from_paras(dtd)
        .gsub(/\*/, "<span class='cite_fn'>*</span>")
  end
  list.replace(participant_para(map, idx))
end

#preface_rearrange(doc) ⇒ Object



148
149
150
151
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 148

def preface_rearrange(doc)
  move_abstract(doc)
  super
end

#prefix_clause(target, loc) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/isodoc/ieee/presentation_ref.rb', line 103

def prefix_clause(target, loc)
  loc["type"] == "clause" or return loc["type"]
  if subclause?(target, loc["type"],
                loc&.at(ns("./referenceFrom"))&.text)
    ""
  else "clause"
  end
end

#references_render(docxml) ⇒ Object



6
7
8
9
# File 'lib/isodoc/ieee/presentation_bibitem.rb', line 6

def references_render(docxml)
  @author = {}
  super
end


13
14
15
16
17
18
19
20
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 13

def related(docxml)
  insert_related_type(docxml)
  admitted_to_related docxml
  term_reorder(docxml)
  docxml.xpath(ns("//term[fmt-related/semx]")).each do |f|
    related_term(f)
  end
end


30
31
32
33
34
35
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 30

def related_term(term)
  r = term.at(ns("./fmt-related"))
  r.xpath(ns(".//xref | .//eref | .//termref")).each(&:remove)
  coll = sort_related(r.xpath(ns("./semx")))
  r.children = term_related_collapse(coll)
end

#section(docxml) ⇒ Object



66
67
68
69
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 66

def section(docxml)
  boilerplate(docxml)
  super
end


68
69
70
71
72
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 68

def sort_related(coll)
  coll.sort do |a, b|
    sort_related_key(a) <=> sort_related_key(b)
  end
end


74
75
76
77
78
79
80
81
82
83
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 74

def sort_related_key(related)
  type = case related["type"]
         when "contrast" then 1
         when "equivalent" then 2
         when "see" then 3
         when "seealso" then 4
         else "5-#{related['type']}"
         end
  "#{type} :: #{sort_terms_key(related)}"
end

#sort_terms(terms) ⇒ Object



126
127
128
129
130
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 126

def sort_terms(terms)
  terms.sort do |a, b|
    sort_terms_key(a) <=> sort_terms_key(b)
  end
end

#sort_terms_key(term) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 51

def sort_terms_key(term)
  d = term.at(ns("./preferred/expression/name | " \
                 "./preferred/letter-symbol/name | " \
                 "./preferred/graphical-symbol/figure/name | " \
                 "./preferred/graphical-symbol/figure/@id | " \
                 "./preferred | ./fmt-preferred//semx"))
  f = term.at(ns("./field-of-application")) || term.at(ns("./domain"))
  @c.decode("#{sort_terms_key1(d)} :: #{sort_terms_key1(f)}")
end

#sort_terms_key1(elem) ⇒ Object



61
62
63
64
65
66
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 61

def sort_terms_key1(elem)
  elem.nil? and return "zzzz"
  dup = elem.dup
  dup.xpath(ns(".//asciimath | .//latexmath")).each(&:remove)
  dup.text&.strip&.downcase || "zzzz"
end

#strip_initial_clause(linkend) ⇒ Object



142
143
144
145
146
# File 'lib/isodoc/ieee/presentation_ref.rb', line 142

def strip_initial_clause(linkend)
  x = Nokogiri::XML("<a>#{linkend}</a>")
  x.at(".//span[@class = 'fmt-element-name']")&.remove
  to_xml(x.elements.first.children).strip
end

#subclause?(target, type, from) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
115
# File 'lib/isodoc/ieee/presentation_ref.rb', line 112

def subclause?(target, type, from)
  (from&.include?(".") && type == "clause") ||
    target&.gsub(/<[^<>]+>/, "")&.match?(/^IEV$|^IEC 60050-/)
end

#term(docxml) ⇒ Object



192
# File 'lib/isodoc/ieee/presentation_terms.rb', line 192

def term(docxml); end


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 37

def term_related_collapse(coll)
  ret = [[coll[0]]]
  coll[1..-1].each do |r|
    if ret[-1][0]["type"] != r["type"]
      ret << [r] and next
    end

    ret[-1] << r
  end
  ret.map do |x|
    x.map { |y| to_xml(y) }.join("; ")
  end.map { |x| "<p>#{x}</p>" }.join("\n")
end

#term_reorder(xmldoc) ⇒ Object



114
115
116
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 114

def term_reorder(xmldoc)
  xmldoc.xpath(ns("//terms")).each { |t| term_reorder1(t) }
end

#term_reorder1(terms) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/isodoc/ieee/presentation_concepts.rb', line 118

def term_reorder1(terms)
  ins = terms.at(ns("./term"))&.previous_element or return
  coll = terms.xpath(ns("./term"))
  ret = sort_terms(coll)
  coll.each(&:remove)
  ret.reverse_each { |t| ins.next = t }
end

#termcleanup(docxml) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/isodoc/ieee/presentation_terms.rb', line 71

def termcleanup(docxml)
  collapse_term docxml
  # temp attribute from insert_related_type
  docxml.xpath(ns("//term//semx[@type]")).each do |x|
    x.delete("type")
  end
  super
end

#termcontainers(docxml) ⇒ Object



80
81
82
83
84
85
# File 'lib/isodoc/ieee/presentation_terms.rb', line 80

def termcontainers(docxml)
  super
  docxml.xpath(ns("//term[not(./fmt-definition)]")).each do |t|
    t << "<fmt-definition #{add_id_text}></fmt-definition>"
  end
end

#termdomain(elem, domain) ⇒ Object

domain is rendered in designation_field instead



180
# File 'lib/isodoc/ieee/presentation_terms.rb', line 180

def termdomain(elem, domain); end

#termnote1(elem) ⇒ Object



182
183
184
185
# File 'lib/isodoc/ieee/presentation_terms.rb', line 182

def termnote1(elem)
  lbl = termnote_label(elem)
  prefix_name(elem, { label: block_delim }, lower2cap(lbl), "name")
end

#termnote_label(elem) ⇒ Object



187
188
189
190
# File 'lib/isodoc/ieee/presentation_terms.rb', line 187

def termnote_label(elem)
  lbl = l10n(@xrefs.anchor(elem["id"], :label)&.strip || "???")
  l10n lbl
end

#termsource_adapt(status) ⇒ Object



173
174
175
176
177
# File 'lib/isodoc/ieee/presentation_terms.rb', line 173

def termsource_adapt(status)
  case status
  when "adapted" then @i18n.adapted_from
  end
end

#termsource_brackets(docxml) ⇒ Object



200
201
202
203
204
205
206
207
208
209
# File 'lib/isodoc/ieee/presentation_terms.rb', line 200

def termsource_brackets(docxml)
  docxml.xpath(ns("//term//semx[@element = 'source']")).each do |s|
    text = termsource_text_content(s)
    text&.include?("(") && text.include?(")") or next
    prevbr = s.at("./preceding-sibling::xmlns:span[@class='fmt-termsource-delim']")
    nextbr = s.at("./following-sibling::xmlns:span[@class='fmt-termsource-delim']")
    prevbr.children = "["
    nextbr.children = "]"
  end
end

#termsource_label(elem, sources) ⇒ Object



167
168
169
170
171
# File 'lib/isodoc/ieee/presentation_terms.rb', line 167

def termsource_label(elem, sources)
  adapt = termsource_adapt(elem["status"]) and
    sources = "#{adapt}#{sources}"
  elem.replace(l10n(sources))
end

#termsource_text_content(span) ⇒ Object



211
212
213
214
# File 'lib/isodoc/ieee/presentation_terms.rb', line 211

def termsource_text_content(span)
  span.dup.xpath(ns(".//localityStack | .//locality")).each(&:remove)
    .text
end

#text_from_paras(node) ⇒ Object



70
71
72
73
# File 'lib/isodoc/ieee/presentation_bibdata.rb', line 70

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

#ul_label_list(_elem) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 119

def ul_label_list(_elem)
  if @doctype == "whitepaper" ||
      %w(icap industry-connection-report).include?(@subdoctype)
    %w(&#x25aa; &#x2014;)
  else
    %w(&#x2014;)
  end
end

#unwrap_definition(_elem, fmt_defn) ⇒ Object



28
29
30
31
32
# File 'lib/isodoc/ieee/presentation_terms.rb', line 28

def unwrap_definition(_elem, fmt_defn)
  fmt_defn.xpath(ns(".//semx[@element = 'definition']")).each do |d|
    unwrap_definition1(d)
  end
end

#unwrap_definition1(d) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/isodoc/ieee/presentation_terms.rb', line 51

def unwrap_definition1(d)
  %w(verbal-definition non-verbal-representation).each do |e|
    v = d.at(ns("./#{e}")) or next
    if v.elements.all? { |n| %w(source p).include?(n.name) }
      p = v.xpath(ns("./p"))
      s = v.xpath(ns("./source"))
      s = wrap_termsource_in_parens(s) unless s.empty?
      v.children =
        "#{p.map(&:children).map do |x|
          to_xml(x)
        end.join("\n")}#{s.map do |x|
                         to_xml(x)
                       end.join}"
    else
      wrap_termsource_in_parens(v.xpath(ns("./source")))
    end
    v.replace(v.children)
  end
end

#unwrap_multidef(coll) ⇒ Object



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

def unwrap_multidef(coll)
  if coll.all? do |c|
    c.elements.size == 1 && c.elements.first.name == "p"
  end
    ret = coll.map do |c|
      c.children = c.elements.first.children
    end
    return "<p>#{ret.map { |x| to_xml(x) }.join}</p>"
  end
  coll.map { |c| to_xml(c.children) }.join(" ")
end

#wrap_termsource_in_parens(xpath) ⇒ Object



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

def wrap_termsource_in_parens(xpath)
  xpath.empty? and return xpath
  opening_paren = Nokogiri::XML::Node.new("span", xpath[0].document)
  opening_paren["class"] = "fmt-termsource-delim"
  opening_paren.content = "("
  xpath[0].add_previous_sibling(opening_paren)
  closing_paren = Nokogiri::XML::Node.new("span", xpath[-1].document)
  closing_paren["class"] = "fmt-termsource-delim"
  closing_paren.content = ")"
  xpath[-1].add_next_sibling(closing_paren)
  # Return expanded nodeset including parentheses
  parent = xpath[0].parent
  start_index = parent.children.index(opening_paren)
  end_index = parent.children.index(closing_paren)
  parent.children[start_index..end_index]
end

#xref_empty?(node) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
# File 'lib/isodoc/ieee/presentation_ref.rb', line 4

def xref_empty?(node)
  if node["citeas"] &&
      @bibanchors[node["bibitemid"]] && !node.children.empty?
    true
  else super
  end
end