From acb231a5e2955cf5704a58cda8dc6f2f69d3e1d6 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Thu, 9 Nov 2023 21:30:13 +1100 Subject: [PATCH] process series in IETF bibliographies: https://github.com/relaton/relaton-render/issues/48 --- lib/isodoc/ietf/cleanup.rb | 20 ++++-- lib/isodoc/ietf/references.rb | 127 ---------------------------------- lib/relaton/render/config.yml | 6 +- lib/relaton/render/parse.rb | 6 ++ 4 files changed, 24 insertions(+), 135 deletions(-) diff --git a/lib/isodoc/ietf/cleanup.rb b/lib/isodoc/ietf/cleanup.rb index a149336..c2a1b15 100644 --- a/lib/isodoc/ietf/cleanup.rb +++ b/lib/isodoc/ietf/cleanup.rb @@ -23,6 +23,7 @@ def cleanup(docxml) def biblio_cleanup(xmldoc) biblio_abstract_cleanup(xmldoc) biblio_date_cleanup(xmldoc) + biblio_refcontent_cleanup(xmldoc) annotation_cleanup(xmldoc) end @@ -49,6 +50,15 @@ def biblio_abstract_cleanup(xmldoc) end end + def biblio_refcontent_cleanup(xmldoc) + xmldoc.xpath("//refcontent").each do |a| + val = a.text.strip + if val.empty? then a.remove + else a.children = val + end + end + end + def reparse_abstract(abstract) a1 = Nokogiri::XML(abstract.dup.to_xml .sub("", "")).root @@ -130,10 +140,10 @@ def figure_postamble(docxml) def make_postamble(docxml) docxml.xpath("//figure").each do |f| - a = f&.at("./artwork | ./sourcecode") || next - name = f&.at("./name")&.remove - b = a&.xpath("./preceding-sibling::*")&.remove - c = a&.xpath("./following-sibling::*")&.remove + a = f.at("./artwork | ./sourcecode") || next + name = f.at("./name")&.remove + b = a.xpath("./preceding-sibling::*")&.remove + c = a.xpath("./following-sibling::*")&.remove a = a.remove name and f << name b.empty? or f << "#{to_xml(b)}" @@ -211,7 +221,7 @@ def deflist_cleanup(docxml) def dt_cleanup(docxml) docxml.xpath("//dt").each do |d| - d&.first_element_child&.name == "bookmark" and + d.first_element_child&.name == "bookmark" and d["anchor"] ||= d.first_element_child["anchor"] d.xpath(".//t").each do |t| d["anchor"] ||= t["anchor"] diff --git a/lib/isodoc/ietf/references.rb b/lib/isodoc/ietf/references.rb index 5ecf68b..dcaecd5 100644 --- a/lib/isodoc/ietf/references.rb +++ b/lib/isodoc/ietf/references.rb @@ -67,133 +67,6 @@ def bibitem_render(ref, bib) bib1.namespace = nil ref << @bibrenderer.render(bib1.to_xml, embedded: true) end - -=begin - - def nonstd_bibitem(list, bib, _ordinal, _bibliography) - uris = bib.xpath(ns("./uri")) - target = nil - uris&.each { |u| target = u.text if u["type"] == "src" } - list.reference **attr_code(target: target, - anchor: bib["id"]) do |r| - nonstd_bibitem_front(r, bib) - uris&.each do |u| - r.format nil, **attr_code(target: u.text, type: u["type"]) - end - docidentifier_render(bib, r) - end - end - - def docidentifier_render(bib, out) - docidentifiers = bib.xpath(ns("./docidentifier")) - id = render_identifier(bibitem_ref_code(bib)) - !id[:sdo].nil? && id[:sdo] != "(NO ID)" and out.refcontent id[:sdo] - docidentifiers&.each do |u| - u["type"] == "DOI" and - out.seriesInfo nil, **attr_code(value: u.text.sub(/^DOI[  ]/, ""), - name: "DOI") - %w(IETF RFC).include?(u["type"]) and docidentifier_ietf(u, out) - end - end - - def docidentifier_ietf(ident, out) - if /^RFC[  ]/.match?(ident.text) - out.seriesInfo nil, **attr_code(value: ident.text.sub(/^RFC[  ]0*/, ""), - name: "RFC") - elsif /^I-D\./.match?(ident.text) - out.seriesInfo nil, **attr_code(value: ident.text.sub(/^I-D\./, ""), - name: "Internet-Draft") - end - end - - def nonstd_bibitem_front(ref, bib) - ref.front do |f| - relaton_to_title(bib, f) - relaton_to_author(bib, f) - relaton_to_date(bib, f) - relaton_to_keyword(bib, f) - relaton_to_abstract(bib, f) - end - end - - def relaton_to_title(bib, node) - title = bib&.at(ns("./title")) || bib&.at(ns("./formattedref")) or - return - node.title do |t| - title.children.each { |n| parse(n, t) } - end - end - - def relaton_to_author(bib, node) - auths = bib.xpath(ns("./contributor[xmlns:role/@type = 'author' or " \ - "xmlns:role/@type = 'editor']")) - auths.empty? and - auths = bib.xpath(ns("./contributor[xmlns:role/@type = " \ - "'publisher']")) - auths.each do |a| - role = a.at(ns("./role[@type = 'editor']")) ? "editor" : nil - (p = a&.at(ns("./person/name")) and - relaton_person_to_author(p, role, node)) or - relaton_org_to_author(a&.at(ns("./organization")), role, node) - end - end - - def relaton_person_to_author(pers, role, node) - full = pers.at(ns("./completename"))&.text - surname = pers.at(ns("./surname"))&.text - initials = pers.xpath(ns("./initial"))&.map(&:text)&.join(" ") || - pers.xpath(ns("./forename"))&.map { |i| i.text[0] }&.join(" ") - initials = nil if initials.empty? - node.author nil, **attr_code( - fullname: full, - asciiFullname: full&.transliterate, - role: role, surname: surname, - initials: initials, - asciiSurname: full ? surname&.transliterate : nil, - asciiInitials: full ? initials&.transliterate : nil - ) - end - - def relaton_org_to_author(org, _role, node) - name = org&.at(ns("./name"))&.text - abbrev = org&.at(ns("./abbreviation"))&.text - node.author do |_a| - node.organization name, **attr_code(ascii: name&.transliterate, - abbrev: abbrev) - end - end - - def relaton_to_date(bib, node) - date = bib.at(ns("./date[@type = 'published']")) || - bib.at(ns("./date[@type = 'issued']")) || - bib.at(ns("./date[@type = 'circulated']")) - date or return - attr = date_attr(date.at(ns("./on | ./from"))&.text) or return - node.date **attr_code(attr) - end - - def relaton_to_keyword(bib, node) - bib.xpath(ns("./keyword")).each do |k| - node.keyword do |keyword| - k.children.each { |n| parse(n, keyword) } - end - end - end - - def relaton_to_abstract(bib, node) - bib.xpath(ns("./abstract")).each do |k| - node.abstract do |abstract| - if k.at(ns("./p")) - k.children.each { |n| parse(n, abstract) } - else - abstract.t do |t| - k.children.each { |n| parse(n, t) } - end - end - end - end - end -=end end end end diff --git a/lib/relaton/render/config.yml b/lib/relaton/render/config.yml index 772aeaa..a7bf8f9 100644 --- a/lib/relaton/render/config.yml +++ b/lib/relaton/render/config.yml @@ -14,12 +14,12 @@ nametemplate: # disabled the following: they should be provided in inheriting calls # etal: "{% if nonpersonal[0] %}{{ nonpersonal[0] }}{% else %}{{surname[0] | upcase}} ,_{%if given[0]%}{{given[0]}} {{middle[0]}}{%else%}{{initials[0] | join: ' '}}.{%endif%}{% endif %}, {% if nonpersonal[1] %}{{ nonpersonal[1] }}{% else %}{%if given[1]%}{{given[1]}} {{middle[1]}}{%else%}{{initials[1] | join: ' '}}.{%endif%} {{surname[1] | upcase}}{% endif %} et al." # etal_count: 5 -seriestemplate: "{% if series_formatted %}{{ series_formatted }}{%else%}{% if series_abbr %}{{series_abbr}}{% else %}{{series_title}}{% endif %} ({{series_run}}) {{series_num}}|({{series_partnumber}}){%endif%}" -journaltemplate: "{% if series_abbr %}{{series_abbr}}{% else %}{{series_title}}{% endif %} ({{series_run}}) {{ labels['volume'] }}_{{series_num}} {{ labels['part'] }}_{{series_partnumber}}" +seriestemplate: "{% if series_title and series_num %}{% else %}{% if series_formatted %}{{ series_formatted }}{% else %}{% if series_title %} {{series_title}} {{ series_run }} ,_{{ series_org }} ,_{{ series_place }} ,_{{ series_dates }} {% endif %}{% endif %}{% endif %}" +journaltemplate: "{% if series_title and series_num %}{% else %}{% if series_formatted %}{{ series_formatted }}{% else %}{% if series_title %} {{series_title}} {{ series_run }} ,_{{ series_org }} ,_{{ series_place }} ,_{{ series_dates }} {% endif %}{% endif %}{% endif %}" template: # skip standardidentifier, it is inserted in front of formattedref within metanorma # date is cleaned up into RFC XML formatting afterwards - standard: "{{ title }} {{ creatornames }} {{date}} {% for k in keywords %}{{k}}{%endfor%} {{abstract}} {% for u in uris %}{% endfor %} {%for d in doi %}{% endfor %} {% if home_standard %}{% for i in authoritative_identifier %} {% endfor %} {% else %} {{authoritative_identifier | join: ', '}} {% endif %}" + standard: "{{ title }} {{ creatornames }} {{date}} {% for k in keywords %}{{k}}{%endfor%} {{abstract}} {% for u in uris %}{% endfor %} {{ series }} {%for d in doi %}{% endfor %} {% if home_standard %}{% for i in authoritative_identifier %} {% endfor %} {% else %} {{authoritative_identifier | join: ', '}} {% endif %}" website: standard book: standard booklet: standard diff --git a/lib/relaton/render/parse.rb b/lib/relaton/render/parse.rb index e85fd89..88341bc 100644 --- a/lib/relaton/render/parse.rb +++ b/lib/relaton/render/parse.rb @@ -22,6 +22,12 @@ def creatornames_roles_allowed authorizer) end + def series_xml2hash1(series, doc) + ret = super + %w(BCP RFC I-D. Internet-Draft).include?(ret[:series_title]) and return {} + ret + end + def uris(doc) doc.link.map { |u| { content: u.content.to_s.strip, type: u.type } } end