Skip to content

Commit

Permalink
multiple subdivisions for organisations: metanorma/metanorma-ieee#150
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Feb 26, 2024
1 parent a16d7b9 commit 07f7f4c
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 110 deletions.
53 changes: 28 additions & 25 deletions lib/metanorma/standoc/biblio.rng
Original file line number Diff line number Diff line change
Expand Up @@ -338,29 +338,32 @@
</define>
<define name="organization">
<element name="organization">
<oneOrMore>
<ref name="orgname"/>
</oneOrMore>
<zeroOrMore>
<ref name="subdivision"/>
</zeroOrMore>
<optional>
<ref name="abbreviation"/>
</optional>
<zeroOrMore>
<ref name="uri"/>
</zeroOrMore>
<zeroOrMore>
<ref name="org-identifier"/>
</zeroOrMore>
<zeroOrMore>
<ref name="contact"/>
</zeroOrMore>
<optional>
<ref name="logo"/>
</optional>
<ref name="OrganizationType"/>
</element>
</define>
<define name="OrganizationType">
<oneOrMore>
<ref name="orgname"/>
</oneOrMore>
<zeroOrMore>
<ref name="subdivision"/>
</zeroOrMore>
<optional>
<ref name="abbreviation"/>
</optional>
<zeroOrMore>
<ref name="uri"/>
</zeroOrMore>
<zeroOrMore>
<ref name="org-identifier"/>
</zeroOrMore>
<zeroOrMore>
<ref name="contact"/>
</zeroOrMore>
<optional>
<ref name="logo"/>
</optional>
</define>
<define name="orgname">
<element name="name">
<choice>
Expand All @@ -371,10 +374,10 @@
</define>
<define name="subdivision">
<element name="subdivision">
<choice>
<ref name="LocalizedString"/>
<ref name="NameWithVariants"/>
</choice>
<optional>
<attribute name="type"/>
</optional>
<ref name="OrganizationType"/>
</element>
</define>
<define name="logo">
Expand Down
6 changes: 2 additions & 4 deletions lib/metanorma/standoc/cleanup_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def dl2_table_cleanup(xmldoc)

def insert_thead(table)
thead = table.at("./thead")
return thead unless thead.nil?

thead.nil? or return thead
if tname = table.at("./name")
thead = tname.add_next_sibling("<thead/>").first
return thead
Expand All @@ -35,8 +34,7 @@ def header_rows_cleanup(xmldoc)
xmldoc.xpath("//table[@headerrows]").each do |s|
thead = insert_thead(s)
(thead.xpath("./tr").size...s["headerrows"].to_i).each do
row = s.at("./tbody/tr")
row.parent = thead
s.at("./tbody/tr").parent = thead
end
thead.xpath(".//td").each { |n| n.name = "th" }
s.delete("headerrows")
Expand Down
46 changes: 39 additions & 7 deletions lib/metanorma/standoc/front_organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,48 @@ def committee_component(compname, node, out)
end
end

def organization(org, orgname, node = nil, default_org = nil)
def organization(org, orgname, node = nil, default_org = nil, attrs = {})
abbrevs = org_abbrev
n = abbrevs.invert[orgname] and orgname = n
org.name orgname
default_org and a = node&.attr("subdivision") and org.subdivision a
default_org && (a = node&.attr("subdivision")) && !attrs[:subdiv] and
subdivision(a, node&.attr("subdivision-abbr"), org)
a = attrs[:subdiv] and subdivision(a, nil, org)
abbr = org_abbrev[orgname]
default_org && b = node&.attr("subdivision-abbr") and abbr = b
abbr and org.abbreviation abbr
end

def subdivision(attr, abbr, org)
abbrs = csv_split(abbr) || []
subdivs = csv_split(attr, ";")
subdivs.size == abbrs.size or abbrs = []
subdivs.each_with_index do |s, i|
subdivision1(s, abbrs[i], org)
end
end

def subdivision1(attr, abbr, org)
m = csv_split(attr, ",").map do |s1|
t, v = s1.split(":", 2).map(&:strip)
if v.nil?
v = t
t = nil
end
{ type: t, value: v }
end
abbr and m[0][:abbr] = abbr
subdiv_build(m, org)
end

def subdiv_build(list, org)
list.empty? and return
org.subdivision **attr_code(type: list[0][:type]) do |s|
s.name { |n| n << list[0][:value] }
subdiv_build(list[1..-1], s)
a = list[0][:abbr] and s.abbreviation { |n| n << a }
end
end

def org_address(org, xml)
p = org[:address] and xml.address do |ad|
ad.formattedAddress do |f|
Expand All @@ -43,9 +75,8 @@ def person_organization(node, suffix, xml)
xml.name node.attr("affiliation#{suffix}")
abbr = node.attr("affiliation_abbrev#{suffix}") and
xml.abbreviation abbr
csv_split(node.attr("affiliation_subdiv#{suffix}"))&.each do |s|
xml.subdivision s
end
a = node.attr("affiliation_subdiv#{suffix}") and
subdivision(a, nil, xml)
person_address(node, suffix, xml)
person_org_logo(node, suffix, xml)
end
Expand Down Expand Up @@ -108,7 +139,7 @@ def org_contributor_role(xml, org)
end

def org_organization(node, xml, org)
organization(xml, org[:name], node, !node.attr("publisher"))
organization(xml, org[:name], node, !node.attr("publisher"), org)
org_address(org, xml)
org_logo(xml, org[:logo])
end
Expand Down Expand Up @@ -150,6 +181,7 @@ def org_attrs_complex_parse(node, opts, source)
def extract_org_attrs_complex(node, opts, source, suffix)
{ name: node.attr(source + suffix),
role: opts[:role], desc: opts[:desc],
subdiv: node.attr("#{source}_subdivision#{suffix}"),
logo: node.attr("#{source}_logo#{suffix}") }.compact
.merge(extract_org_attrs_address(node, opts, suffix))
end
Expand Down
195 changes: 121 additions & 74 deletions spec/metanorma/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@
<organization>
<name>Slate Rock and Gravel Company</name>
<abbreviation>SRG</abbreviation>
<subdivision>Hermeneutics Unit</subdivision>
<subdivision>Exegetical Subunit</subdivision>
<subdivision><name>Hermeneutics Unit</name></subdivision>
<subdivision><name>Exegetical Subunit</name></subdivision>
<address>
<formattedAddress>
6 Rubble Way, Bedrock
Expand Down Expand Up @@ -397,8 +397,8 @@
<organization>
<name>Rockhead and Quarry Cave Construction Company</name>
<abbreviation>RQCCC</abbreviation>
<subdivision>Hermeneutics Unit</subdivision>
<subdivision>Exegetical Subunit</subdivision>
<subdivision><name>Hermeneutics Unit</name></subdivision>
<subdivision><name>Exegetical Subunit</name></subdivision>
<address>
<formattedAddress>6A Rubble Way, <br/>Bedrock</formattedAddress>
</address>
Expand Down Expand Up @@ -1114,87 +1114,134 @@
:tc-docnumber: 2000
:language: el
:script: Grek
:subdivision: Subdivision
:subdivision-abbr: SD
:subdivision: Subdivision, committee: TC 3; "institute: My Curious Corporation, inc", committee: TC 7
:subdivision-abbr: SD, MCC
:doctype: This is a DocType
:pub-address: 1 Infinity Loop + \\
California
:pub-phone: 3333333
:pub-fax: 4444444
:pub-email: x@example.com
:pub-uri: http://www.example.com
:sponsor: IEC
:sponsor_subdivision: technical committee: TC 9, subcommittee: SC 7, working group: WG 88
INPUT
output = <<~OUTPUT
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="semantic" version="#{Metanorma::Standoc::VERSION}">
<bibdata type='standard'>
<title language='en' format='text/plain'>Document title</title>
<docidentifier>OVERRIDE-DOCIDENTIFIER</docidentifier>
<docnumber>1000</docnumber>
<date type='published'>
<on>1000-01</on>
</date>
<contributor>
<role type='author'/>
<organization>
<name>International Standards Organization</name>
<subdivision>Subdivision</subdivision>
<abbreviation>SD</abbreviation>
<address>
<formattedAddress>1 Infinity Loop <br/>California</formattedAddress>
</address>
<phone>3333333</phone>
<phone type='fax'>4444444</phone>
<email>x@example.com</email>
<uri>http://www.example.com</uri>
</organization>
</contributor>
<contributor>
<role type='publisher'/>
<organization>
<name>International Standards Organization</name>
<subdivision>Subdivision</subdivision>
<abbreviation>SD</abbreviation>
<address>
<formattedAddress>1 Infinity Loop <br/>California</formattedAddress>
</address>
<phone>3333333</phone>
<phone type='fax'>4444444</phone>
<email>x@example.com</email>
<uri>http://www.example.com</uri>
</organization>
</contributor>
<version>
<revision-date>2000-01</revision-date>
</version>
<language>el</language>
<script>Grek</script>
<status>
<stage>published</stage>
</status>
<copyright>
<from>#{Time.now.year}</from>
<owner>
<organization>
<name>International Standards Organization</name>
<subdivision>Subdivision</subdivision>
<abbreviation>SD</abbreviation>
<address>
<formattedAddress>1 Infinity Loop <br/>California</formattedAddress>
</address>
<phone>3333333</phone>
<phone type='fax'>4444444</phone>
<email>x@example.com</email>
<uri>http://www.example.com</uri>
</organization>
</owner>
</copyright>
<ext>
<doctype>this-is-a-doctype</doctype>
</ext>
</bibdata>
<sections> </sections>
</standard-document>
<bibdata type="standard">
<title language="en" format="text/plain">Document title</title>
<docidentifier>OVERRIDE-DOCIDENTIFIER</docidentifier>
<docnumber>1000</docnumber>
<date type="published">
<on>1000-01</on>
</date>
<contributor>
<role type="author"/>
<organization>
<name>International Standards Organization</name>
<subdivision>
<name>Subdivision</name>
<subdivision type="committee">
<name>TC 3</name>
</subdivision>
</subdivision>
<subdivision type="institute">
<name>My Curious Corporation, inc</name>
<subdivision type="committee">
<name>TC 7</name>
</subdivision>
</subdivision>
<address>
<formattedAddress>1 Infinity Loop<br/>California</formattedAddress>
</address>
<phone>3333333</phone>
<phone type="fax">4444444</phone>
<email>x@example.com</email>
<uri>http://www.example.com</uri>
</organization>
</contributor>
<contributor>
<role type="publisher"/>
<organization>
<name>International Standards Organization</name>
<subdivision>
<name>Subdivision</name>
<subdivision type="committee">
<name>TC 3</name>
</subdivision>
</subdivision>
<subdivision type="institute">
<name>My Curious Corporation, inc</name>
<subdivision type="committee">
<name>TC 7</name>
</subdivision>
</subdivision>
<address>
<formattedAddress>1 Infinity Loop<br/>California</formattedAddress>
</address>
<phone>3333333</phone>
<phone type="fax">4444444</phone>
<email>x@example.com</email>
<uri>http://www.example.com</uri>
</organization>
</contributor>
<contributor>
<role type="enabler"/>
<organization>
<name>IEC</name>
<subdivision type="technical committee">
<name>TC 9</name>
<subdivision type="subcommittee">
<name>SC 7</name>
<subdivision type="working group">
<name>WG 88</name>
</subdivision>
</subdivision>
</subdivision>
</organization>
</contributor>
<version>
<revision-date>2000-01</revision-date>
</version>
<language>el</language>
<script>Grek</script>
<status>
<stage>published</stage>
</status>
<copyright>
<from>#{Time.now.year}</from>
<owner>
<organization>
<name>International Standards Organization</name>
<subdivision>
<name>Subdivision</name>
<subdivision type="committee">
<name>TC 3</name>
</subdivision>
</subdivision>
<subdivision type="institute">
<name>My Curious Corporation, inc</name>
<subdivision type="committee">
<name>TC 7</name>
</subdivision>
</subdivision>
<address>
<formattedAddress>1 Infinity Loop<br/>California</formattedAddress>
</address>
<phone>3333333</phone>
<phone type="fax">4444444</phone>
<email>x@example.com</email>
<uri>http://www.example.com</uri>
</organization>
</owner>
</copyright>
<ext>
<doctype>this-is-a-doctype</doctype>
</ext>
</bibdata>
<sections/>
</standard-document>
OUTPUT
xml = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS))
xml.at("//xmlns:metanorma-extension")&.remove
Expand Down

0 comments on commit 07f7f4c

Please sign in to comment.