-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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") | ||
|
@@ -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), | ||
designation: to_xml(l10n_recursive(p, lg)).strip } | ||
end | ||
end | ||
|
||
def l10n_recursive(xml, lang) | ||
script = Metanorma::Utils.default_script(lang) | ||
c = HTMLEntities.new | ||
|
@@ -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| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [85/80] |
||
p = semx_orig(s, term) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect indentation detected (column 6 instead of 12). |
||
def move_related(term) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 (not 8) spaces for indentation. |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
|
@@ -148,14 +193,25 @@ def related1(node) | |
@i18n = @i18n_lg["default"] | ||
end | ||
|
||
def related1(node) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 (not 8) spaces for indentation. |
||
lg = node.at("./ancestor::xmlns:term/@language")&.text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent indentation detected. |
||
node.children =(l10n("<p>#{label}: " \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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}")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent indentation detected. |
||
@i18n = @i18n_lg["default"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent indentation detected. |
||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation detected.