Skip to content

Commit

Permalink
Presentation XML refactor, terms: metanorma/isodoc#630
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Jan 8, 2025
1 parent 8f0713c commit 7e3d5fc
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 58 deletions.
3 changes: 3 additions & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "feature/presentation-terms"
gem "metanorma-generic", git: "https://github.com/metanorma/metanorma-generic", branch: "feature/presentation-terms"
gem "mn-requirements", git: "https://github.com/metanorma/mn-requirements", branch: "main"
27 changes: 27 additions & 0 deletions lib/isodoc/iho/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def omit_docid_prefix(prefix)

def term1(elem); end

# KILL
def termsource1(elem)
elem.parent.nil? and return
while elem&.next_element&.name == "termsource"
Expand All @@ -135,6 +136,32 @@ def termsource1(elem)
defn.elements.last << s
end

def termsource1(elem)
elem.parent.nil? and return
super
end

def termsource_label(elem, sources)
elem.at("./ancestor::xmlns:term") or return
elem.replace(l10n("[#{sources}]"))
end

def termcleanup(docxml)
collapse_term docxml
super
end

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

def collapse_term1(term)
defn = term.at(ns("./fmt-definition")) or return
source = term.at(ns("./fmt-termsource")) or return
defn.elements.last << source.children
source.remove
end

def clausedelim
""
end
Expand Down
26 changes: 22 additions & 4 deletions spec/isodoc/html_convert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<clause id="H" obligation="normative"><title>Terms, definitions, symbols and abbreviated terms</title><terms id="I" obligation="normative">
<title>Normal Terms</title>
<term id="J">
<preferred>Term2</preferred>
<preferred><expression><name>Term2</name></expression></preferred>
</term>
</terms>
<definitions id="K">
Expand Down Expand Up @@ -270,7 +270,14 @@
<semx element="autonum" source="I">1</semx>
</fmt-xref-label>
<term id="J">
<preferred>Term2</preferred>
<preferred id="_"><expression><name>Term2</name></expression></preferred>
<fmt-preferred>
<p>
<semx element="preferred" source="_">
<strong>Term2</strong>
</semx>
</p>
</fmt-preferred>
</term>
</terms>
<definitions id="K">
Expand Down Expand Up @@ -496,7 +503,7 @@
<clause id="H" obligation="normative"><title>Terms, definitions, symbols and abbreviated terms</title><terms id="I" obligation="normative">
<title>Normal Terms</title>
<term id="J">
<preferred>Term2</preferred>
<preferred><expression><name>Term2</name></expression></preferred>
</term>
</terms>
<definitions id="K">
Expand Down Expand Up @@ -646,7 +653,18 @@
<semx element="autonum" source="I">1</semx>
</fmt-xref-label>
<term id="J">
<preferred>Term2</preferred>
<preferred id="_">
<expression>
<name>Term2</name>
</expression>
</preferred>
<fmt-preferred>
<p>
<semx element="preferred" source="_">
<strong>Term2</strong>
</semx>
</p>
</fmt-preferred>
</term>
</terms>
<definitions id="K">
Expand Down
227 changes: 173 additions & 54 deletions spec/isodoc/terms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,80 @@
</fmt-xref-label>
<p>For the purposes of this document, the following terms and definitions apply.</p>
<term id="paddy1">
<preferred>
<strong>paddy</strong>
, &lt;in agriculture, dated&gt;
</preferred>
<domain hidden="true">rice</domain>
<definition>
<p id="_">
&lt;
<domain>rice</domain>
&gt; rice retaining its husk after threshing [
<preferred id="_">
<expression>
<name>paddy</name>
</expression>
<field-of-application id="_">in agriculture</field-of-application>
<usage-info id="_">dated</usage-info>
<termsource status="modified" original-id="_">
<origin bibitemid="ISO7301" type="inline" citeas="ISO 7301:2011">
<locality type="clause">
<referenceFrom>3.1</referenceFrom>
</locality>
ISO 7301:2011, Clause 3.1
</origin>
, modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here] [
<origin citeas="">
<termref base="IEV" target="xyz">t1</termref>
</origin>
— comment ;
<origin citeas="">
<termref base="IEV" target="xyz"/>
</origin>
, modified — with adjustments]
<modification>
<p original-id="_">The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here</p>
</modification>
</termsource>
</preferred>
<fmt-preferred>
<p>
<semx element="preferred" source="_">
<strong>paddy</strong>
<span class="fmt-designation-field">
, &lt;
<semx element="field-of-application" source="_">in agriculture</semx>
,
<semx element="usage-info" source="_">dated</semx>
&gt;
</span>
</semx>
</p>
<fmt-termsource>
[
<semx element="termsource" source="_">
<origin bibitemid="ISO7301" type="inline" citeas="ISO 7301:2011">
<locality type="clause">
<referenceFrom>3.1</referenceFrom>
</locality>
ISO 7301:2011, Clause 3.1
</origin>
, modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
</semx>
]
</fmt-termsource>
</fmt-preferred>
<domain id="_">rice</domain>
<definition id="_">
<verbal-definition>
<p original-id="_">rice retaining its husk after threshing</p>
</verbal-definition>
</definition>
<fmt-definition>
<semx element="definition" source="_">
<p id="_">
&lt;
<semx element="domain" source="_">rice</semx>
&gt; rice retaining its husk after threshing
</p>
[
<semx element="termsource" source="_">
<origin citeas="">
<termref base="IEV" target="xyz">t1</termref>
</origin>
— comment
</semx>
;
<semx element="termsource" source="_">
<origin citeas="">
<termref base="IEV" target="xyz"/>
</origin>
, modified — with adjustments
</semx>
]
</semx>
</fmt-definition>
<termexample id="_" keep-with-next="true" keep-lines-together="true" autonum="1">
<fmt-name>
<span class="fmt-caption-label">
Expand Down Expand Up @@ -179,32 +226,99 @@
<li>A</li>
</ul>
</termexample>
<termsource status="identical" id="_">
<origin citeas="">
<termref base="IEV" target="xyz">t1</termref>
</origin>
<modification>
<p original-id="_">comment</p>
</modification>
</termsource>
<termsource status="modified" id="_">
<origin citeas="">
<termref base="IEV" target="xyz"/>
</origin>
<modification>
<p original-id="_">with adjustments</p>
</modification>
</termsource>
</term>
<term id="paddy">
<preferred>
<strong>paddy</strong>
<preferred id="_">
<expression>
<name>paddy</name>
</expression>
</preferred>
<admitted>paddy rice, &lt;in agriculture&gt;</admitted>
<admitted>rough rice</admitted>
<deprecates>DEPRECATED: cargo rice</deprecates>
<definition>
<p id="_">
rice retaining its husk after threshing [
<origin bibitemid="ISO7301" type="inline" droploc="true" citeas="ISO 7301:2011">
<locality type="clause">
<referenceFrom>3.1</referenceFrom>
</locality>
ISO 7301:2011, 3.1
</origin>
<origin bibitemid="ISO7301" type="inline" case="lowercase" citeas="ISO 7301:2011">
<locality type="clause">
<referenceFrom>3.1</referenceFrom>
</locality>
ISO 7301:2011, clause 3.1
</origin>
]
<fmt-preferred>
<p>
<semx element="preferred" source="_">
<strong>paddy</strong>
</semx>
</p>
</fmt-preferred>
<admitted id="_">
<letter-symbol>
<name>paddy rice</name>
</letter-symbol>
<field-of-application id="_">in agriculture</field-of-application>
</admitted>
<admitted id="_">
<expression>
<name>rough rice</name>
</expression>
</admitted>
<fmt-admitted>
<p>
<semx element="admitted" source="_">
paddy rice
<span class="fmt-designation-field">
, &lt;
<semx element="field-of-application" source="_">in agriculture</semx>
&gt;
</span>
</semx>
</p>
<p>
<semx element="admitted" source="_">rough rice</semx>
</p>
</fmt-admitted>
<deprecates id="_">
<expression>
<name>cargo rice</name>
</expression>
</deprecates>
<fmt-deprecates>
<p>
DEPRECATED:
<semx element="deprecates" source="_">cargo rice</semx>
</p>
</fmt-deprecates>
<definition id="_">
<verbal-definition>
<p original-id="_">rice retaining its husk after threshing</p>
</verbal-definition>
</definition>
<fmt-definition>
<semx element="definition" source="_">
<p id="_">rice retaining its husk after threshing</p>
[
<semx element="termsource" source="_">
<origin bibitemid="ISO7301" type="inline" droploc="true" citeas="ISO 7301:2011">
<locality type="clause">
<referenceFrom>3.1</referenceFrom>
</locality>
ISO 7301:2011, 3.1
</origin>
<origin bibitemid="ISO7301" type="inline" case="lowercase" citeas="ISO 7301:2011">
<locality type="clause">
<referenceFrom>3.1</referenceFrom>
</locality>
ISO 7301:2011, clause 3.1
</origin>
</semx>
]
</semx>
</fmt-definition>
<termexample id="_" autonum="">
<fmt-name>
<span class="fmt-caption-label">
Expand Down Expand Up @@ -283,14 +397,26 @@
</ul>
<p id="_">The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.</p>
</termnote>
<termsource status="identical" id="_">
<origin bibitemid="ISO7301" type="inline" droploc="true" citeas="ISO 7301:2011">
<locality type="clause">
<referenceFrom>3.1</referenceFrom>
</locality>
</origin>
<origin bibitemid="ISO7301" type="inline" case="lowercase" citeas="ISO 7301:2011">
<locality type="clause">
<referenceFrom>3.1</referenceFrom>
</locality>
</origin>
</termsource>
</term>
</terms>
</sections>
</iso-standard>
PRESXML
html = <<~"OUTPUT"
#{HTML_HDR}
<br/>
<br/>
<div id="_" class="TOC">
<h1 class="IntroTitle">Contents</h1>
</div>
Expand All @@ -302,16 +428,9 @@
<b>paddy</b>
, &lt;in agriculture, dated&gt;
</p>
<p id="_">&lt;rice&gt; rice retaining its husk after threshing [ISO 7301:2011, Clause 3.1, modified
The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here] [t1
comment
;
Termbase IEV, term ID xyz, modified
with adjustments]</p>
<p>[ISO 7301:2011, Clause 3.1, modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here]</p>
<p id="_">&lt;rice&gt; rice retaining its husk after threshing</p>
[t1 — comment; Termbase IEV, term ID xyz, modified — with adjustments]
<div id="_" class="example" style="page-break-after: avoid;page-break-inside: avoid;">
<p class="example-title">EXAMPLE 1</p>
<p id="_">Foreign seeds, husks, bran, sand, dust.</p>
Expand All @@ -336,8 +455,8 @@
<p class="AltTerms" style="text-align:left;">paddy rice, &lt;in agriculture&gt;</p>
<p class="AltTerms" style="text-align:left;">rough rice</p>
<p class="DeprecatedTerms" style="text-align:left;">DEPRECATED: cargo rice</p>
<p id="_">rice retaining its husk after threshing [ISO 7301:2011, 3.1
ISO 7301:2011, clause 3.1]</p>
<p id="_">rice retaining its husk after threshing</p>
[ISO 7301:2011, 3.1ISO 7301:2011, clause 3.1]
<div id="_" class="example">
<p class="example-title">EXAMPLE</p>
<div class="ul_wrap">
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def metadata(xml)

def strip_guid(xml)
xml.gsub(%r{ id="_[^"]+"}, ' id="_"')
.gsub(%r{ original-id="_[^"]+"}, ' original-id="_"')
.gsub(%r{ source="_[^"]+"}, ' source="_"')
.gsub(%r{ target="_[^"]+"}, ' target="_"')
.gsub(%r{<fetched>[^<]+</fetched>}, "<fetched/>")
Expand Down

0 comments on commit 7e3d5fc

Please sign in to comment.