Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presentation XML refactor, terms: https://github.com/metanorma/isodoc… #373

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-iso", git: "https://github.com/metanorma/metanorma-iso", branch: "feature/presentation-terms"
gem "mn-requirements", git: "https://github.com/metanorma/mn-requirements", branch: "main"
5 changes: 5 additions & 0 deletions lib/isodoc/iec/base_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def terms_parse(node, out)
end
end

def termdef_parse(node, out)
node.at(ns("./fmt-preferred")) or return
super
end

def para_class(node)
case node["class"]
when "zzSTDTitle1", "zzSTDTitle2" then "zzSTDTitle1"
Expand Down
89 changes: 77 additions & 12 deletions lib/isodoc/iec/presentation_terms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ def concept_iev1(termref, docpart, labels)
def terms(docxml)
otherlang_designations(docxml)
super
remove_otherlang_designations(docxml)
merge_fr_into_en_term(docxml)
end

def termdomain(elem)
def termdomain(elem, fmt_defn)
if @is_iev
d = elem.at(ns("./domain")) or return
d["hidden"] = true
#d = elem.at(ns("./domain")) or return
#d["hidden"] = true
else super
end
end
Expand All @@ -55,17 +56,21 @@ def merge_fr_into_en_term(docxml)
docxml.xpath(ns("//term[@language = 'en'][@tag]")).each do |en|
fr = docxml.at(ns("//term[@language = 'fr'][@tag = '#{en['tag']}']"))
merge_fr_into_en_term1(en, fr) if fr
en.xpath(ns("./fmt-name | ./fmt-xref-label")).each(&:remove)
term1(en)
end
# renumber
@xrefs.parse_inclusions(clauses: true).parse docxml
#docxml.xpath(ns("//term/fmt-name | //term/fmt-xref")).each(&:remove)
#term(docxml)
docxml.xpath(ns("//term/fmt-name | //term/fmt-xref-label")).each(&:remove)
term(docxml)
end

def merge_fr_into_en_term1(en_term, fr_term)
dl = en_term&.at(ns("./dl[@type = 'other-lang']"))&.remove
en_term << fr_term.remove.children
#en_term << fr_term.remove.children
dup = semx_fmt_dup(fr_term)
dup.xpath(ns("./fmt-name | ./fmt-xref-label")).each(&:remove)
en_term << dup
fr_term.xpath(ns(".//fmt-name | .//fmt-xref-label | .//fmt-preferred | .//fmt-admitted | .//fmt-deprecates | .//fmt-definition | .//fmt-related | .//fmt-termsource")).each(&:remove)
fr_term["unnumbered"] = "true"
en_term << dl if dl
en_term["language"] = "en,fr"
en_term.delete("tag")
Expand All @@ -78,19 +83,41 @@ def otherlang_designations(docxml)
end
end

def remove_otherlang_designations(docxml)
@is_iev or return
docxml.xpath(ns("//term")).each do |t|
remove_otherlang_designations1(t, t["language"]&.split(",") || %w(en fr))
end
end

# KILL
def extract_otherlang_designations(term, lgs)
term.xpath(ns(".//preferred/expression[@language]"))
.each_with_object([]) do |d, m|
lg = d["language"]
d.delete("language")
lgs.include?(lg) and next
p = d.parent
designation_annotate(p, d.at(ns("./name")))
designation_annotate(p, p.at(ns("./name")))
m << { lang: lg, script: Metanorma::Utils.default_script(lg),
designation: to_xml(l10n_recursive(p.remove, lg)).strip }
end
end

def extract_otherlang_designations(term, lgs)
term.xpath(ns(".//preferred/expression[@language]"))
.each_with_object([]) do |d, m|
lg = d["language"]
lgs.include?(lg) and next
p = semx_fmt_dup(d.parent)
e = p.at(ns("./expression"))
e.delete("language")
designation_annotate(p, p.at(ns(".//name")), d.parent)
m << { lang: lg, script: Metanorma::Utils.default_script(lg),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

designation: to_xml(l10n_recursive(p, lg)).strip }
end
end

def l10n_recursive(xml, lang)
script = Metanorma::Utils.default_script(lang)
c = HTMLEntities.new
Expand Down Expand Up @@ -125,18 +152,36 @@ def otherlang_designations1(term, lgs)
term << "<dl type='other-lang'>#{prefs.join}</dl>"
end

def remove_otherlang_designations1(term, lgs)
term.xpath(ns(".//fmt-preferred/p/semx[@element = 'preferred']")).each do |s|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [85/80]

p = semx_orig(s, term)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not 4) spaces for indentation.

lg = p.at(ns("./expression/@language"))&.text or next
lgs.include?(lg) and next
s.parent.remove
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 161, 6 is not aligned with term.xpath(ns(".//fmt-preferred/p/semx[@element = 'preferred']")).each do |s| at 156, 8.

end

def related(docxml)
docxml.xpath(ns("//term[related]")).each { |f| move_related(f) }
#docxml.xpath(ns("//term[related]")).each { |f| move_related(f) }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after #.

super
docxml.xpath(ns("//term[related]")).each { |f| move_related(f) }
end

def move_related(term)
# KILL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation detected (column 6 instead of 12).

def move_related(term)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not 8) spaces for indentation.
Inconsistent indentation detected.

defn = term.at(ns("./definition")) or return
term.xpath(ns("./related")).reverse_each do |r|
defn.next = r.remove
end
end

def move_related(term)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method IsoDoc::Iec::PresentationXMLConvert#move_related is defined at both lib/isodoc/iec/presentation_terms.rb:171 and lib/isodoc/iec/presentation_terms.rb:178.

defn = term.at(ns("./fmt-definition")) or return
rel = term.at(ns("./fmt-related")) or return
defn << rel.children
end

# KILL
def related1(node)
lg = node.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
Expand All @@ -148,14 +193,25 @@ def related1(node)
@i18n = @i18n_lg["default"]
end

def related1(node)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not 8) spaces for indentation.
Inconsistent indentation detected.
Method IsoDoc::Iec::PresentationXMLConvert#related1 is defined at both lib/isodoc/iec/presentation_terms.rb:185 and lib/isodoc/iec/presentation_terms.rb:196.
Assignment Branch Condition size for related1 is too high. [<8, 14, 3> 16.4/15]

lg = node.at("./ancestor::xmlns:term/@language")&.text
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not -4) spaces for indentation.

@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
p, ref, orig = related1_prep(node)
label = @i18n.relatedterms[orig["type"]].upcase
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

node.children =(l10n("<p>#{label}: " \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surrounding space missing for operator =.

"#{to_xml(p)} (#{Common::to_xml(ref)})</p>"))
@i18n = @i18n_lg["default"]
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 204, 6 is not aligned with def at 196, 12.


def termsource_modification(node)
lg = node&.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
super
@i18n = @i18n_lg["default"]
end

def termsource1(node)
# KILL
def termsource1xx(node)
lg = node&.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
if @is_iev then termsource1_iev(node)
Expand All @@ -164,13 +220,22 @@ def termsource1(node)
@i18n = @i18n_lg["default"]
end

# KILL
def termsource1_iev(elem)
while elem&.next_element&.name == "termsource"
elem << "; #{to_xml(elem.next_element.remove.children)}"
end
elem.children = l10n("#{@i18n.source}: #{to_xml(elem.children).strip}")
end

def termsource_label(elem, sources)
@is_iev or return super
lg = elem&.at("./ancestor::xmlns:term/@language")&.text
@i18n = @i18n_lg[lg] if lg && @i18n_lg[lg]
elem.replace(l10n("#{@i18n.source}: #{sources}"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

@i18n = @i18n_lg["default"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 237, 4 is not aligned with def at 231, 6.


def termexample(docxml)
docxml.xpath(ns("//termexample")).each do |f|
termexample1(f)
Expand Down
5 changes: 4 additions & 1 deletion lib/isodoc/iec/xref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ def terms_iev_names(docxml)
#xref: l10n("#{@labels['section_iev']} #{num}"),
xref: labelled_autonum(@labels['section_iev'], num),
level: 2, type: "clause", elem: @labels["section_iev"] }
t.xpath(ns("./term")).each_with_index do |c, j|
j = 0
t.xpath(ns("./term")).each do |c|
c["unnumbered"] == "true" and next
num2 = semx(c, "%02d" % [j + 1])
#section_names1(c, "#{num}#{delim_wrap("-")}#{num2}", 3)
section_names1(c, num, num2, 3)
j += 1
end
end
end
Expand Down
30 changes: 24 additions & 6 deletions spec/isodoc/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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 @@ -190,7 +190,16 @@
<span class="fmt-autonum-delim">.</span>
<semx element="autonum" source="J">1</semx>
</fmt-xref-label>
<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 @@ -447,7 +456,7 @@
<div id="I">
<h2>3.1  Normal Terms</h2>
<p class="TermNum" id="J">3.1.1</p>
<p class="Terms" style="text-align:left;">Term2</p>
<p class="Terms" style="text-align:left;"><b>Term2</b></p>
</div>
<div id="K">
<h2>3.2  Symbols</h2>
Expand Down Expand Up @@ -687,7 +696,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 @@ -846,7 +855,16 @@
<span class="fmt-autonum-delim">.</span>
<semx element="autonum" source="J">1</semx>
</fmt-xref-label>
<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 @@ -1104,7 +1122,7 @@
<div id="I">
<h2>3.1  Normal Terms</h2>
<p class="TermNum" id="J">3.1.1</p>
<p class="Terms" style="text-align:left;">Term2</p>
<p class="Terms" style="text-align:left;"><b>Term2</b></p>
</div>
<div id="K">
<h2>3.2  Symboles</h2>
Expand Down
Loading
Loading