From 520f2bc4d8332eae80c90bba173953605a1b7910 Mon Sep 17 00:00:00 2001
From: Nick Nicholas
Date: Thu, 2 Jan 2025 01:58:28 +0200
Subject: [PATCH 1/5] Presentation XML refactor, terms:
https://github.com/metanorma/isodoc/issues/630
---
Gemfile.devel | 3 +
lib/isodoc/ieee/presentation_terms.rb | 232 ++++++++++++++++++++------
lib/metanorma/ieee/biblio.rng | 18 +-
spec/isodoc/terms_spec.rb | 38 +++++
spec/isodoc/word_spec.rb | 6 +-
spec/spec_helper.rb | 1 +
6 files changed, 237 insertions(+), 61 deletions(-)
create mode 100644 Gemfile.devel
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..e7b0e5a 100644
--- a/lib/isodoc/ieee/presentation_terms.rb
+++ b/lib/isodoc/ieee/presentation_terms.rb
@@ -1,78 +1,142 @@
module IsoDoc
module Ieee
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
- def multidef(elem)
- # require "debug"; binding.b
- number_multidef(elem)
- collapse_multidef(elem)
- end
-
- def number_multidef(elem)
+ def multidef(elem, defn, fmt_defn)
c = IsoDoc::XrefGen::Counter.new("@")
- elem.xpath(ns("./definition")).each do |d|
+ coll = defn.each_with_object([]) do |d, m|
c.increment(d)
- d.elements.first.add_first_child "(#{c.print}) "
+ m << semx_fmt_dup(d).elements.first.add_first_child("(#{c.print}) ")
end
- end
-
- def collapse_multidef(elem)
- ins = elem.at(ns("./definition")).previous_element
- coll = elem.xpath(ns("./definition"))
- coll.each(&:remove)
- ins.next = "#{unwrap_multidef(coll)}"
+ fmt_defn << unwrap_multidef(coll)
end
def unwrap_multidef(coll)
if coll.all? do |c|
- c.elements.size == 1 && c.elements.first.name == "p"
- end
- ret = coll.map { |c| to_xml(c.elements.first.children) }
- return "
#{ret.join}
"
+ 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
+=begin
+ def unwrap_definition(elem)
+ elem.xpath(ns("./definition")).each do |d|
+ %w(verbal-definition non-verbal-representation).each do |e|
+ v = d&.at(ns("./#{e}"))
+ v&.replace(v.children)
+ end
+ end
+ end
+
+ 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
+ end
+ en
+
+=end
+
+def designation1(desgn)
+ #require 'debug'; binding.b
+ super
+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 =
"
TERM
@@ -192,7 +297,7 @@ def collapse_term_template(opt)
def collapse_unwrap_definition(defn)
defn.nil? and return nil
- s = defn.remove.xpath(ns("./termsource"))
+ 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
@@ -210,6 +315,17 @@ def termsource1(elem)
elem.children = l10n("#{adapt}#{to_xml(elem.children).strip}")
end
+ def termsource1(elem)
+ ret = [semx_fmt_dup(elem)]
+ while elem&.next_element&.name == "termsource"
+ ret << semx_fmt_dup(elem.next_element.remove)
+ end
+ s = ret.map { |x| to_xml(x) }.map(&:strip).join("; ")
+ adapt = termsource_adapt(elem["status"]) and
+ s = "#{adapt}#{s}"
+ elem.replace(l10n(s))
+ end
+
def termsource_adapt(status)
case status
when "adapted" then @i18n.adapted_from
@@ -217,15 +333,14 @@ 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 , but or equivalent
- def designation_field(desgn, name)
- if desgn.name == "preferred"
- f = desgn.xpath(ns("./../domain | ./../subject")).map(&:remove)
+ def designation_field(desgn, name, orig)
+ if desgn["element"] == "preferred"
+ f = orig.parent.xpath(ns("./../domain | ./../subject"))
.map { |u| to_xml(u.children) }.join(", ")
name << ", <#{f}>" unless f.empty?
end
@@ -244,6 +359,19 @@ def merge_second_preferred(term)
pref << " (#{tail})"
end
+ def merge_second_preferred(term)
+ pref =
+ term.at(ns("./preferred[not(abbreviation-type)][expression/name]"))
+ x = term.xpath(ns("./preferred[expression/name][abbreviation-type] | " \
+ "./admitted[expression/name][abbreviation-type]"))
+ (pref && !x.empty?) or return
+ fmt_pref = term.at(ns(".//semx[@source = '#{pref['id']}']"))
+ tail = x.map do |p|
+ to_xml(term.at(ns(".//semx[@source = '#{p['id']}']")).remove).strip
+ end.join(", ")
+ fmt_pref.next = " (#{tail})"
+ end
+
def termnote1(elem)
lbl = termnote_label(elem)
prefix_name(elem, { label: block_delim }, lower2cap(lbl), "name")
@@ -258,7 +386,7 @@ def term(docxml); end
def concept1(node)
concept_render(node, ital: "false", ref: "false", bold: "false",
- linkref: "false", linkmention: "false")
+ linkref: "false", linkmention: "false")
end
end
end
diff --git a/lib/metanorma/ieee/biblio.rng b/lib/metanorma/ieee/biblio.rng
index 71191b2..66c553a 100644
--- a/lib/metanorma/ieee/biblio.rng
+++ b/lib/metanorma/ieee/biblio.rng
@@ -267,11 +267,11 @@ Detailed in https://www.relaton.org/model/creator/
An identifier of the person according to an international identifier scheme
-
+ Contact information for the person, including URI, address, phone number, and email
-
+
@@ -454,11 +454,11 @@ real names (if the person is named with a pseudonym or user name); previous lega
An identifier of the organization according to an international identifier scheme
-
+ Contact information for the organization, including address, phone number, and email
-
+
A logo for the organization
@@ -540,12 +540,18 @@ real names (if the person is named with a pseudonym or user name); previous lega
Contact information for a person or organization
-
+
+
+
+
+
+
+
-
+
The phone number associated with a person or organization
diff --git a/spec/isodoc/terms_spec.rb b/spec/isodoc/terms_spec.rb
index 01ff1a5..59d00ee 100644
--- a/spec/isodoc/terms_spec.rb
+++ b/spec/isodoc/terms_spec.rb
@@ -101,6 +101,18 @@
For the purposes of this document, the following terms and definitions apply.
+ paddy
+ in agriculture
+ dated
+
+ 3.1
+
+
The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+
+
+
+ rice
+
rice retaining its husk after threshing
paddy
, <rice>, <in agriculture, dated>: rice retaining its husk after threshing (
@@ -179,6 +191,22 @@
For the purposes of this document, the following terms and definitions apply.
-
- paddy
- in agriculture
- dated
-
- 3.1
-
-
The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
-
-
-
- rice
-
rice retaining its husk after threshing
-
- paddy
- , <rice>, <in agriculture, dated>: rice retaining its husk after threshing (
-
-
- 3.1
-
- ISO
- 7301
- :
- 2011
- , 3.1
-
- , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here)
-
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)
@@ -395,14 +501,6 @@
-
adapted from t1, adapted
-
-
-
- ;
- Termbase IEV, term ID xyz, adapted
- —
- with adjustments
paddy
@@ -418,7 +516,6 @@
2011
, 3.1)
-
DEPRECATED: cargo rice
Example
@@ -502,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)
@@ -532,14 +629,6 @@
-
adapted from t1, adapted
-
-
-
- ;
- Termbase IEV, term ID xyz, adapted
- —
- with adjustments
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 (
-
-
-
- 3.1
-
- ISO
- 7301
- :
- 2011
- , 3.1
-
- , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
-
- ) (
+
+
+ paddy
+
+
+ rice
+
+
+
rice retaining its husk after threshing, mark 2
+
rice retaining its husk after threshing, mark 3
+
+
+
+ 3.1
+
+
+
+
The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+
+
+
+
+
+
+
+ paddy
+
+ , <
+ rice
+ >
+
+
+ :
+
+ rice retaining its husk after threshing, mark 2 rice retaining its husk after threshing, mark 3 (
+
+
+
+ 3.1
+
+ ISO
+ 7301
+ :
+ 2011
+ , 3.1
+
+ , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+
+ )
+
+ (
+
+
+ t1
+
+
+ )
+
+
+ t1
- )
-
+
@@ -910,40 +1082,91 @@
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 (
-
-
-
- 3.1
-
- ISO
- 7301
- :
- 2011
- , 3.1
-
- , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
-
- ) (
-
- t1
-
- ;
-
-
-
- , modified — with adjustments)
-
+
+
+ paddy
+
+
+ rice
+
+
+
+ rice retaining its
+
+ husk
+
+ after threshing
+
+
+
+
+
+
rice retaining its husk after threshing, mark 2
+
+
+
+ 3.1
+
+
+
+
The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+
+
+
+
+
+
+
+ paddy
+
+ , <
+ rice
+ >
+
+
+ :
+
+ (A)
+ rice retaining its
+
+ husk
+
+ after threshing
+
+
+ (B)
+ rice retaining its husk after threshing, mark 2 (
+
+
+
+ 3.1
+
+ ISO
+ 7301
+ :
+ 2011
+ , 3.1
+
+ , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+
+ )
+
+ (
+
+
+ t1
+
+
+ ;
+
+
+
+
+ , modified — with adjustments
+
+ )
+
From ca8914197e62db7cdbaa1a82240ffc827446f5ed Mon Sep 17 00:00:00 2001
From: Nick Nicholas
Date: Sun, 5 Jan 2025 19:19:29 +0200
Subject: [PATCH 3/5] refactor: https://github.com/metanorma/isodoc/issues/630
---
lib/isodoc/ieee/presentation_terms.rb | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/lib/isodoc/ieee/presentation_terms.rb b/lib/isodoc/ieee/presentation_terms.rb
index eb80bf7..58e5d54 100644
--- a/lib/isodoc/ieee/presentation_terms.rb
+++ b/lib/isodoc/ieee/presentation_terms.rb
@@ -378,15 +378,10 @@ def termsource1(elem)
elem.children = l10n("#{adapt}#{to_xml(elem.children).strip}")
end
- def termsource1(elem)
- ret = [semx_fmt_dup(elem)]
- while elem&.next_element&.name == "termsource"
- ret << semx_fmt_dup(elem.next_element.remove)
- end
- s = ret.map { |x| to_xml(x) }.map(&:strip).join("; ")
+ def termsource_label(elem, sources)
adapt = termsource_adapt(elem["status"]) and
- s = "#{adapt}#{s}"
- elem.replace(l10n(s))
+ s = "#{adapt}#{sources}"
+ elem.replace(l10n(sources))
end
def termsource_adapt(status)
From b65b9ecad1178f85ba64ebb289436d302e545fa1 Mon Sep 17 00:00:00 2001
From: Nick Nicholas
Date: Tue, 7 Jan 2025 23:19:46 +0200
Subject: [PATCH 4/5] debug: remove fmt-related//xref:
https://github.com/metanorma/isodoc/issues/632
---
lib/isodoc/ieee/presentation_terms.rb | 20 ++++++++++++++++++--
spec/isodoc/terms_spec.rb | 20 --------------------
2 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/lib/isodoc/ieee/presentation_terms.rb b/lib/isodoc/ieee/presentation_terms.rb
index 58e5d54..c9b0290 100644
--- a/lib/isodoc/ieee/presentation_terms.rb
+++ b/lib/isodoc/ieee/presentation_terms.rb
@@ -126,6 +126,7 @@ def related_term(term)
#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
@@ -248,6 +249,20 @@ def admitted_to_related1(adm, pref, out)
TERM
end
+ #KILL
+ def related1(node)
+ require "debug"; binding.b
+ p, ref, orig = related1_prep(node)
+ label = @i18n.relatedterms[orig["type"]].upcase
+ if p
+ node.children =(l10n("
#{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
@@ -370,7 +385,8 @@ def collapse_unwrap_definition(defn)
[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
@@ -380,7 +396,7 @@ def termsource1(elem)
def termsource_label(elem, sources)
adapt = termsource_adapt(elem["status"]) and
- s = "#{adapt}#{sources}"
+ sources = "#{adapt}#{sources}"
elem.replace(l10n(sources))
end
diff --git a/spec/isodoc/terms_spec.rb b/spec/isodoc/terms_spec.rb
index 531b135..3e58e79 100644
--- a/spec/isodoc/terms_spec.rb
+++ b/spec/isodoc/terms_spec.rb
@@ -2656,11 +2656,6 @@
, n
-
- 1
- .
- 1
-
;
@@ -2678,11 +2673,6 @@
, n
-
- 1
- .
- 1
-
.
Syn:
@@ -2710,11 +2700,6 @@
, n
-
- 1
- .
- 1
-
.
@@ -2844,11 +2829,6 @@
Contrast:
**RELATED TERM NOT FOUND**
-
- 1
- .
- 2
-
.
See also:
From 689d13a28e6515a1a523c5896de2335720ba7011 Mon Sep 17 00:00:00 2001
From: Nick Nicholas
Date: Wed, 8 Jan 2025 08:45:26 +0200
Subject: [PATCH 5/5] rspec
---
spec/isodoc/terms_spec.rb | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/spec/isodoc/terms_spec.rb b/spec/isodoc/terms_spec.rb
index 3e58e79..892c4a5 100644
--- a/spec/isodoc/terms_spec.rb
+++ b/spec/isodoc/terms_spec.rb
@@ -153,7 +153,7 @@
2011
, 3.1
- , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+ , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
):
rice retaining its husk after threshing
@@ -169,7 +169,7 @@
- , adapted — with adjustments
+ , adapted — with adjustments
)
@@ -982,7 +982,7 @@
2011
, 3.1
- , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+ , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
)
@@ -1147,7 +1147,7 @@
2011
, 3.1
- , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
+ , modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
)
@@ -1162,7 +1162,7 @@
- , modified — with adjustments
+ , modified — with adjustments
)
@@ -1363,7 +1363,7 @@
- , modified — with adjustments
+ , modified — with adjustments
)