Skip to content

Commit

Permalink
Merge pull request #197 from metanorma/features/series_biblio
Browse files Browse the repository at this point in the history
process series in IETF bibliographies: https://github.com/relaton/rel…
  • Loading branch information
opoudjis authored Nov 18, 2023
2 parents 6eb80bf + acb231a commit 3dd7027
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 135 deletions.
20 changes: 15 additions & 5 deletions lib/isodoc/ietf/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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("<abstract>", "<abstract xmlns='http://www.example.com'>")).root
Expand Down Expand Up @@ -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 << "<preamble>#{to_xml(b)}</preamble>"
Expand Down Expand Up @@ -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"]
Expand Down
127 changes: 0 additions & 127 deletions lib/isodoc/ietf/references.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions lib/relaton/render/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %} <em>et al.</em>"
# 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: "<em>{% if series_abbr %}{{series_abbr}}{% else %}{{series_title}}{% endif %}</em> ({{series_run}}) {{ labels['volume'] }}_{{series_num}} {{ labels['part'] }}_{{series_partnumber}}"
seriestemplate: "{% if series_title and series_num %}<seriesInfo_name='{{ series_title }}'_value='{{series_num}}'/>{% else %}{% if series_formatted %}<refcontent>{{ series_formatted }}</refcontent>{% else %}{% if series_title %}<refcontent> {{series_title}} {{ series_run }} ,_{{ series_org }} ,_{{ series_place }} ,_{{ series_dates }} </refcontent>{% endif %}{% endif %}{% endif %}"
journaltemplate: "{% if series_title and series_num %}<seriesInfo_name='{{ series_title }}'_value='{{series_num}}'/>{% else %}{% if series_formatted %}<refcontent>{{ series_formatted }}</refcontent>{% else %}{% if series_title %}<refcontent> {{series_title}} {{ series_run }} ,_{{ series_org }} ,_{{ series_place }} ,_{{ series_dates }} </refcontent>{% 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: "<front><title>{{ title }}</title> {{ creatornames }} <date_cleanme='true'>{{date}}</date> {% for k in keywords %}<keyword>{{k}}</keyword>{%endfor%} <abstract_cleanme='true'>{{abstract}}</abstract> </front> {% for u in uris %}<format_target='{{u.content}}'_type='{%if u.type%}{{u.type}}{%else%}HTML{%endif%}'/>{% endfor %} {%for d in doi %}<seriesInfo_value='{{ d | replace: ' ', ' ' | remove_first: 'DOI' | strip }}'_name='DOI'/>{% endfor %} {% if home_standard %}{% for i in authoritative_identifier %} <seriesInfo_value='{{ i | replace: ' ', ' ' | strip | split: ' ' | last | remove_first: 'I-D.'}}'_name='{%if i contains 'I-D.'%}Internet-Draft{% else %}{{ i | replace: ' ', ' ' | strip | split: ' ' | slice: -2 }}{%endif%}'/> {% endfor %} {% else %} <refcontent>{{authoritative_identifier | join: ', '}}</refcontent> {% endif %}"
standard: "<front><title>{{ title }}</title> {{ creatornames }} <date_cleanme='true'>{{date}}</date> {% for k in keywords %}<keyword>{{k}}</keyword>{%endfor%} <abstract_cleanme='true'>{{abstract}}</abstract> </front> {% for u in uris %}<format_target='{{u.content}}'_type='{%if u.type%}{{u.type}}{%else%}HTML{%endif%}'/>{% endfor %} {{ series }} {%for d in doi %}<seriesInfo_value='{{ d | replace: ' ', ' ' | remove_first: 'DOI' | strip }}'_name='DOI'/>{% endfor %} {% if home_standard %}{% for i in authoritative_identifier %} <seriesInfo_value='{{ i | replace: ' ', ' ' | strip | split: ' ' | last | remove_first: 'I-D.'}}'_name='{%if i contains 'I-D.'%}Internet-Draft{% else %}{{ i | replace: ' ', ' ' | strip | split: ' ' | slice: -2 }}{%endif%}'/> {% endfor %} {% else %} <refcontent>{{authoritative_identifier | join: ', '}}</refcontent> {% endif %}"
website: standard
book: standard
booklet: standard
Expand Down
6 changes: 6 additions & 0 deletions lib/relaton/render/parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3dd7027

Please sign in to comment.