diff --git a/Gemfile.devel b/Gemfile.devel new file mode 100644 index 0000000..60e80c0 --- /dev/null +++ b/Gemfile.devel @@ -0,0 +1,3 @@ +gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "feature/presentation-terms" +gem "metanorma-standoc", git: "https://github.com/metanorma/metanorma-standoc", branch: "fix/remove-asciimath2unitsml" +gem "mn-requirements", git: "https://github.com/metanorma/mn-requirements", branch: "main" diff --git a/lib/isodoc/ieee/presentation_terms.rb b/lib/isodoc/ieee/presentation_terms.rb index 734eca1..c9b0290 100644 --- a/lib/isodoc/ieee/presentation_terms.rb +++ b/lib/isodoc/ieee/presentation_terms.rb @@ -1,78 +1,172 @@ module IsoDoc module Ieee class PresentationXMLConvert < IsoDoc::PresentationXMLConvert - def multidef(elem) - # require "debug"; binding.b - number_multidef(elem) - collapse_multidef(elem) + 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("(#{ctr.print}) ") + m << ret + end + #require "debug"; binding.b + fmt_defn << coll.map { |c| to_xml(c) }.join(" ") + #coll.each { |x| unwrap_definition1(x) } + #fmt_defn << unwrap_multidef(coll) end - def number_multidef(elem) - c = IsoDoc::XrefGen::Counter.new("@") - elem.xpath(ns("./definition")).each do |d| - c.increment(d) - d.elements.first.add_first_child "(#{c.print}) " + 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 "
#{ret.map { |x| to_xml(x) }.join}
" end + coll.map { |c| to_xml(c.children) }.join(" ") end - def collapse_multidef(elem) - ins = elem.at(ns("./definition")).previous_element - coll = elem.xpath(ns("./definition")) - coll.each(&:remove) - ins.next = "#{ret.join}
" + to + + def unwrap_definition(_elem, fmt_defn) + fmt_defn.xpath(ns(".//semx[@element = 'definition']")).each do |d| + %w(verbal-definition non-verbal-representation).each do |e| + v = d&.at(ns("./#{e}")) + v&.replace(v.children) end - coll.map { |c| to_xml(c.children) }.join end + en + +=end + +def designation(docxml) + super +end + +def deprecates(desgn) + desgn.remove +end + + def designation_boldface(desgn) + #desgn["element"] == "preferred" or return + name = desgn.at(ns("./expression/name | ./letter-symbol/name")) or return + name.children = "#{name.children}" + end def unwrap_definition(docxml) docxml.xpath(ns(".//definition/verbal-definition")).each do |v| v.elements.all? { |e| %w(termsource p).include?(e.name) } or next p = v.xpath(ns("./p")) s = v.xpath(ns('./termsource')) - s.empty? or - s = " (#{s.map { |x| to_xml(x) }.join("\n")})" + s.empty? or s = " (#{s.map { |x| to_xml(x) }.join("\n")})" v.children = "#{p.map(&:children).map { |x| to_xml(x) }.join("\n")}#{s}
" end super end + def unwrap_definition(_elem, fmt_defn) + fmt_defn.xpath(ns(".//semx[@element = 'definition']")).each do |d| + unwrap_definition1(d) + end + end + + def unwrap_definition1(d) + %w(verbal-definition non-verbal-representation).each do |e| + v = d.at(ns("./#{e}")) or next + if v.elements.all? { |e| %w(termsource p).include?(e.name) } + p = v.xpath(ns("./p")) + s = v.xpath(ns('./termsource')) + s.empty? or s = " (#{s.map { |x| to_xml(x) }.join()})" + v.children = + "#{p.map(&:children).map { |x| to_xml(x) }.join("\n")}#{s}" + else + s = v.xpath(ns('./termsource')) + unless s.empty? + s[0].previous = " (" + s[-1].next = ")" + end + end + v.replace(v.children) + end + end + + def related_designation1(desgn) + super + end + def related(docxml) - docxml.xpath(ns("//term[related]")).each { |f| related_term(f) } + insert_related_type(docxml) + admitted_to_related docxml + term_reorder(docxml) + docxml.xpath(ns("//term[fmt-related/semx]")).each { |f| related_term(f) } + end + + # temporarily insert related/@type to fmt-related/semx, for sorting + def insert_related_type(docxml) + docxml.xpath(ns("//fmt-related/semx")).each do |r| + orig = semx_orig(r) + r["type"] = orig["type"] + end end def related_term(term) - coll = term_related_reorder(term.xpath(ns("./related"))) - term_related_collapse(coll) + #require "debug"; binding.b + #coll = term_related_reorder(term.xpath(ns("./fmt-related/semx"))) + 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 def term_related_collapse(coll) prev = 0 + coll[0].wrap("") coll[1..-1].each_with_index do |r, i| if coll[prev]["type"] != r["type"] - prev = i and next + prev = i + r.wrap("") + next end - coll[prev].at(ns("./preferred")) << "; #{to_xml(r.at(ns('./preferred')) - .children)}" + #coll[prev].at(ns("./preferred")) << "; #{to_xml(r.at(ns('./preferred')) + #.children)}" + coll[prev] << "; #{to_xml(r)}" r.remove end end + def term_related_collapse(coll) + prev = 0 + ret = [[coll[0]]] + coll[1..-1].each do |r| + if ret[-1][0]["type"] != r["type"] + ret << [r] + next + end + ret[-1] << r + end + ret.map { |x| x.map { |y| to_xml(y) }.join("; ") }.map { |x| "#{x}
" }.join("\n") + end + 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")) + "./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 @@ -84,6 +178,7 @@ def sort_terms_key1(elem) dup.text&.strip&.downcase || "zzzz" end + #KILL def term_related_reorder(coll) ins = coll.first.previous_element ret = sort_related(coll) @@ -109,24 +204,28 @@ def sort_related_key(related) "#{type} :: #{sort_terms_key(related)}" end - def terms(docxml) - admitted_to_related docxml - super + def termcleanup(docxml) collapse_term docxml + docxml.xpath(ns("//term//semx[@type]")).each { |x| x.delete("type") } # temp attribute from insert_related_type + super end def admitted_to_related(docxml) docxml.xpath(ns("//term")).each do |t| - t.xpath(ns("./admitted | ./preferred")).each_with_index do |a, i| + t.xpath(ns("./fmt-admitted/semx | ./fmt-preferred/semx")).each_with_index do |a, i| + orig = semx_orig(a) (i.zero? || - a.at(ns("./abbreviation-type | ./graphical-symbol"))) and next - admitted_to_related1(a, t.at(ns("./preferred"))) + orig.at(ns("./abbreviation-type | ./graphical-symbol"))) and next + out = t.at(ns("./fmt-related")) || t.at(ns("./definition")).before("#{label}: " \ + "#{to_xml(p)}
")) + else + node.children = (l10n("#{label}: " \ + "**RELATED TERM NOT FOUND**
")) + end + end + def term_reorder(xmldoc) xmldoc.xpath(ns("//terms")).each { |t| term_reorder1(t) } end @@ -155,19 +281,35 @@ def sort_terms(terms) end end + def termcontainers(docxml) + super + docxml.xpath(ns("//term[not(./fmt-definition)]")).each do |t| + t << "#{tail}
" + <<~TERM +#{t}:
#{defn}#{tail} + TERM + else <<~TERM -#{t}: #{defn} #{collapse_term_related(opt[:rels])} #{src}
+#{t}: #{defn} #{tail}
TERM + end + end + + def collapse_term_pref(opt) + p = opt[:pref] + p.text.strip.empty? and return "**TERM NOT FOUND**" + s = p.xpath(ns(".//semx[@element = 'termsource']")) + unless s.empty? + s[0].previous = " (" + s[-1].next = ")" + end + p.xpath(ns(".//fmt-termsource")).each { |x| x.replace(x.children) } + to_xml(p.children).strip + end def collapse_unwrap_definition(defn) - defn.nil? and return nil - s = defn.remove.xpath(ns("./termsource")) - p = defn.at(ns("./p")) + #require "debug"; binding.b + 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 - if defn.elements.size == 1 && defn.elements.first.name == "p" - defn.elements.first.children - else defn.elements - end + # 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 - def termsource1(elem) + # KILL + def termsource1xx(elem) while elem&.next_element&.name == "termsource" elem << "; #{to_xml(elem.next_element.remove.children)}" end @@ -210,6 +394,12 @@ def termsource1(elem) elem.children = l10n("#{adapt}#{to_xml(elem.children).strip}") end + def termsource_label(elem, sources) + adapt = termsource_adapt(elem["status"]) and + sources = "#{adapt}#{sources}" + elem.replace(l10n(sources)) + end + def termsource_adapt(status) case status when "adapted" then @i18n.adapted_from @@ -217,17 +407,17 @@ def termsource_adapt(status) end # domain is rendered in designation_field instead - def termdomain(elem) - d = elem.at(ns(".//domain")) or return - d["hidden"] = "true" + def termdomain(elem, domain) + #d = elem.at(ns(".//domain")) or return + #d["hidden"] = "true" end - # TODO wrap domain not in- Term2 - : -
-
+
??? for ???
-For the purposes of this document, the following terms and definitions apply.
-
- paddy
- , <rice>, <in agriculture, dated>: rice retaining its husk after threshing (
-
Foreign seeds, husks, bran, sand, dust.
-
- paddy
- : rice retaining its husk after threshing
- Syn:
- paddy rice
- , <in agriculture>;
- rough rice
- . (
-
The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.
-The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.
-- paddy rice - , <in agriculture>: - See: - paddy - . -
-- rough rice - : - See: - paddy - . -
-??? for ???
+For the purposes of this document, the following terms and definitions apply.
+The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+rice retaining its husk after threshing
+
+
Foreign seeds, husks, bran, sand, dust.
+with adjustments
+rice retaining its husk after threshing
+
+
The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.
+The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.
+
+
+
paddy - , <rice>, <in agriculture, dated>: rice retaining its husk after threshing ( + , <rice>, <in agriculture, dated> ( ISO 7301 : 2011 - , 3.1, modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here) + , 3.1, modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here): rice retaining its husk after threshing (adapted from t1, adapted; Termbase IEV, term ID xyz, adapted — with adjustments)
@@ -357,14 +501,6 @@
adapted from t1, adapted - - - - ; - Termbase IEV, term ID xyz, adapted - — - with adjustments
paddy @@ -380,7 +516,6 @@ 2011 , 3.1)
-DEPRECATED: cargo rice
Example @@ -464,12 +599,12 @@
paddy - , <rice>, <in agriculture, dated>: rice retaining its husk after threshing ( + , <rice>, <in agriculture, dated> ( ISO 7301 : 2011 - , 3.1, modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here) + , 3.1, modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here): rice retaining its husk after threshing (adapted from t1, adapted; Termbase IEV, term ID xyz, adapted — with adjustments)
@@ -494,14 +629,6 @@
adapted from t1, adapted - - - - ; - Termbase IEV, term ID xyz, adapted - — - with adjustments
paddy @@ -517,7 +644,6 @@ 2011 , 3.1)
-DEPRECATED: cargo rice
Example
@@ -634,7 +760,7 @@
INPUT
output = <<~OUTPUT
-
- prozac - : -
+
+
-
-
+
- Xanax - : -
+
+
For the purposes of this document, the following terms and definitions apply.
- paddy
- , <rice>: rice retaining its husk after threshing, mark 2 rice retaining its husk after threshing, mark 3 (
- rice retaining its husk after threshing, mark 2 rice retaining its husk after threshing, mark 3 The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+
For the purposes of this document, the following terms and definitions apply.
- paddy
- , <rice>:
- (A)
- rice retaining its
-
+ rice retaining its
+
rice retaining its husk after threshing, mark 2
+The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+
+
with adjustments
+For the purposes of this document, the following terms and definitions apply.
- paddy
- , <rice>:
- (A)
- rice retaining its husk after threshing
- (B)
- rice retaining its husk after threshing, mark 2 (
-
rice retaining its husk after threshing
+rice retaining its husk after threshing, mark 2
+
+
Foreign seeds, husks, bran, sand, dust.
with adjustments
+- A - , <rice>: rice retaining its husk after threshing - Syn: - B - . -
+rice retaining its husk after threshing
+
+
- B - : - See: - A - . -
+
+
- C (D) - , <rice>: rice retaining its husk after threshing -
+rice retaining its husk after threshing
+
+
- E - , <rice>: rice retaining its husk after threshing - Syn: - F - . -
+rice retaining its husk after threshing
+
+
- F - : - See: - E - . -
+
+
- G (H) - , <rice>: rice retaining its husk after threshing -
+rice retaining its husk after threshing
+
+
- I - , <rice>, US: rice retaining its husk after threshing - Syn: - J - . -
+rice retaining its husk after threshing
+
+
- J - : - See: - I - . -
+
+
- K - , <rice>, eng: rice retaining its husk after threshing - Syn: - L - , fra. -
+rice retaining its husk after threshing
+
+
- L - , fra: - See: - K - , eng. -
+
+
- muddy rice - , n, noun: - See: - paddy - , m, f, sg, noun, en Latn, /pædiː/. -
+
+
- paddy - , <rice>, m, f, sg, noun, en Latn US, /pædiː/: rice retaining its husk after threshing - Syn: - muddy rice - , n, noun. -
+rice retaining its husk after threshing
+
+
- - , <rice>: rice retaining its husk after threshing -
-rice retaining its husk after threshing
+
+
For the purposes of this document, the following terms and definitions apply.
- Term 2
- :
-
-
- Term
- :
+ Definition
+
+
+
+
+
+
+
+ A
+ B
+
+
+
+ C
+ D
+
+ (
+
- First Designation - : Definition 2 - Contrast: - Fifth Designation - , n; - Fourth Designation - , n. - Syn: - Second Designation - . - See also: - Third Designation - , n. -
+Definition 2
+
+
- Second Designation - : - See: - First Designation - . -
+
+
- Second Term - , <Field, Usage Info 1>: Definition 1 -
+Definition 1
+
+
- First Designation - : Definition 2 - Contrast: - **RELATED TERM NOT FOUND**. - See also: - Third Designation - , n. -
+- Second Term - , <Field, Usage Info 1>: Definition 1 -
+**TERM NOT FOUND**:
-- First Designation - : Definition 2 - Contrast: - **RELATED TERM NOT FOUND**. - See also: - Third Designation - , n. -
+
+ **TERM NOT FOUND**:
+
**TERM NOT FOUND**:
-- Second Term - , <Field, Usage Info 1>: Definition 1 -
+
+ **TERM NOT FOUND**:
+