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

Feature/presentation terms #631

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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: 2 additions & 1 deletion lib/isodoc/function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def location_parse(node, out); end
SPAN_UNWRAP_CLASSES =
%w[fmt-caption-label fmt-label-delim fmt-caption-delim fmt-autonum-delim
fmt-element-name fmt-conn fmt-comma fmt-enum-comma fmt-obligation
fmt-xref-container].freeze
fmt-xref-container fmt-designation-field].freeze

def span_parse(node, out)
klass = node["style"] || node["class"]
Expand Down Expand Up @@ -203,6 +203,7 @@ def children_parse(node, out)
def xref_label_parse(node, out); end

def name_parse(node, out); end
def semx_definition_parse(node, out); end

def floating_title_parse(node, out); end

Expand Down
40 changes: 30 additions & 10 deletions lib/isodoc/function/terms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,42 @@ def modification_parse(node, out)
para.children.each { |n| parse(n, out) }
end

def semx_deprecated_term_parse(node, out); end

def deprecated_term_parse(node, out)
out.p class: "DeprecatedTerms", style: "text-align:left;" do |p|
node.children.each { |c| parse(c, p) }
node.children.each do |c|
if c.name == "p"
out.p class: "DeprecatedTerms", style: "text-align:left;" do |p|
c.children.each { |c1| parse(c1, p) }
end
else parse(c, out)
end
end
end

def semx_admitted_term_parse(node, out); end

def admitted_term_parse(node, out)
out.p class: "AltTerms", style: "text-align:left;" do |p|
node.children.each { |c| parse(c, p) }
node.children.each do |c|
if c.name == "p"
out.p class: "AltTerms", style: "text-align:left;" do |p|
c.children.each { |c1| parse(c1, p) }
end
else parse(c, out)
end
end
end

def semx_term_parse(node, out); end

def term_parse(node, out)
out.p class: "Terms", style: "text-align:left;" do |p|
node.children.each { |c| parse(c, p) }
node.children.each do |c|
if c.name == "p"
out.p class: "Terms", style: "text-align:left;" do |p|
c.children.each { |c1| parse(c1, p) }
end
else parse(c, out)
end
end
end

Expand All @@ -51,16 +72,15 @@ def termnote_parse1(node, para, div)
para&.name != "p" and parse(para, div)
end

def semx_termref_parse(node, out); end

def termref_parse(node, out)
out.p do |p|
node.children.each { |n| parse(n, p) }
end
end

def termdomain_parse(node, out)
node["hidden"] == "true" and return
node.children.each { |n| parse(n, out) }
end
def termdomain_parse(node, out); end

def termdef_parse(node, out)
name = node.at(ns("./fmt-name"))&.remove
Expand Down
15 changes: 10 additions & 5 deletions lib/isodoc/function/to_word_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,17 @@ def parse(node, out)
when "pre" then pre_parse(node, out)
when "annotation" then annotation_parse(node, out)
when "term" then termdef_parse(node, out)
when "preferred" then term_parse(node, out)
when "admitted" then admitted_term_parse(node, out)
when "deprecates" then deprecated_term_parse(node, out)
when "preferred" then semx_term_parse(node, out)
when "fmt-preferred" then term_parse(node, out)
when "admitted" then semx_admitted_term_parse(node, out)
when "fmt-admitted" then admitted_term_parse(node, out)
when "deprecates" then semx_deprecated_term_parse(node, out)
when "fmt-deprecates" then deprecated_term_parse(node, out)
when "domain" then termdomain_parse(node, out)
when "definition" then definition_parse(node, out)
when "termsource" then termref_parse(node, out)
when "definition" then semx_definition_parse(node, out)
when "fmt-definition" then definition_parse(node, out)
when "termsource" then semx_termref_parse(node, out)
when "fmt-termsource" then termref_parse(node, out)
when "modification" then modification_parse(node, out)
when "termnote" then termnote_parse(node, out)
when "terms" then terms_parse(node, out)
Expand Down
18 changes: 16 additions & 2 deletions lib/isodoc/presentation_function/autonum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,23 @@ def transfer_id(old, new)
old.delete("id")
end

def semx_fmt_dup(elem)
elem["id"] ||= "_#{UUIDTools::UUID.random_create}"
new = Nokogiri::XML(<<~XML).root
<semx xmlns='#{elem.namespace.href}' element='#{elem.name}' source='#{elem['original-id'] || elem['id']}'>#{to_xml(elem.children)}</semx>
XML
strip_duplicate_ids(nil, elem, new)
new
end

def gather_all_ids(elem)
elem.xpath(".//*[@id]").each_with_object([]) do |i, m|
m << i["id"]
end
end

# remove ids duplicated between title and fmt-title
# index terms are assumed transferred to fmt-title from title
# remove ids duplicated between sem_title and pres_title
# index terms are assumed transferred to pres_title from sem_title
def strip_duplicate_ids(_node, sem_title, pres_title)
sem_title && pres_title or return
ids = gather_all_ids(pres_title)
Expand All @@ -75,6 +84,11 @@ def autonum(id, num)
"<semx element='autonum' source='#{id}'>#{num}</semx>"
end

def semx_orig(node, orig = nil)
orig ||= node.parent.parent
orig.at(".//*[@id = '#{node['source']}']")
end

def labelled_autonum(label, id, num)
elem = "<span class='fmt-element-name'>#{label}</span>"
num.blank? and return elem
Expand Down
151 changes: 145 additions & 6 deletions lib/isodoc/presentation_function/concepts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def concept(docxml)
end

def concept1(node)
node.ancestors("definition, termsource, related").empty? or return
xref = node&.at(ns("./xref/@target"))&.text or
return concept_render(node, ital: "true", ref: "true", bold: "false",
linkref: "true", linkmention: "false")
Expand Down Expand Up @@ -71,20 +72,158 @@ def concept1_ref_content(ref)
end

def related(docxml)
docxml.xpath(ns("//related")).each { |f| related1(f) }
docxml.xpath(ns("//fmt-related/semx")).each { |f| related1(f) }
end

def related1(node)
p = node.at(ns("./preferred"))
ref = node.at(ns("./xref | ./eref | ./termref"))
label = @i18n.relatedterms[node["type"]].upcase
p, ref, orig = related1_prep(node)
label = @i18n.relatedterms[orig["type"]].upcase
if p && ref
node.replace(l10n("<p><strong>#{label}:</strong> " \
node.children =(l10n("<p><strong>#{label}:</strong> " \
"<em>#{to_xml(p)}</em> (#{Common::to_xml(ref)})</p>"))
else
node.replace(l10n("<p><strong>#{label}:</strong> " \
node.children = (l10n("<p><strong>#{label}:</strong> " \
"<strong>**RELATED TERM NOT FOUND**</strong></p>"))
end
end

def related1_prep(node)
p = node.at(ns("./fmt-preferred"))
ref = node.at(ns("./xref | ./eref | ./termref"))
orig = semx_orig(node)
[p, ref, orig]
end

def related_designation1(desgn)
out = desgn.parent.at(ns("./fmt-#{desgn.name}"))
d1 = semx_fmt_dup(desgn)
%w(preferred admitted deprecates).each do |w|
d = d1.at(ns("./#{w}[last()]")) and d.after("<fmt-#{w}/>")
end
out << d1
end

def designation(docxml)
docxml.xpath(ns("//related")).each { |p| related_designation1(p) }
docxml.xpath(ns("//preferred | //admitted | //deprecates"))
.each { |p| designation1(p) }
docxml.xpath(ns("//fmt-preferred | //fmt-admitted | //fmt-deprecates"))
.each { |t| merge_second_preferred(t) }
docxml.xpath(ns("//fmt-deprecates")).each { |d| deprecates(d) }
docxml.xpath(ns("//fmt-admitted")).each { |d| admits(d) }
end

def deprecates(elem)
ins = elem.at(ns("./p")) || elem
ins.add_first_child @i18n.l10n("#{@i18n.deprecated}: ")
end

def admits(elem); end

def merge_second_preferred(term)
pref = nil
out = term.xpath(ns("./semx")).each_with_index
.with_object([]) do |(p, i), m|
if (i.zero? && (pref = p)) || merge_preferred_eligible?(pref, p)
m << p
else
p.wrap("<p></p>")
end
end
pref&.replace(merge_second_preferred1(out, term))
end

def merge_second_preferred1(desgns, term)
desgns[1..].each(&:remove)
ret = l10n(desgns.map { |x| to_xml(x) }.join("; "))
term.ancestors("fmt-related").empty? and ret = "<p>#{ret}</p>"
ret
end

def merge_preferred_eligible?(first, second)
orig_first, orig_second, firstex, secondex =
merge_preferred_eligible_prep(first, second)
orig_first["geographic-area"] == orig_second["geographic-area"] &&
firstex["language"] == secondex["language"] &&
!orig_first.at(ns("./pronunciation | ./grammar | ./graphical-symbol")) &&
!orig_second.at(ns("./pronunciation | ./grammar | ./graphical-symbol")) &&
orig_first.name == "preferred" && orig_second.name == "preferred"
end

def merge_preferred_eligible_prep(first, second)
orig_first = semx_orig(first)
orig_second = semx_orig(second)
firstex = orig_first.at(ns("./expression")) || {}
secondex = orig_second.at(ns("./expression")) || {}
[orig_first, orig_second, firstex, secondex]
end

def designation1(desgn)
desgn.parent.name == "related" and return
out = desgn.parent.at(ns("./fmt-#{desgn.name}"))
d1 = semx_fmt_dup(desgn)
s = d1.at(ns("./termsource"))
name = d1.at(ns("./expression/name | ./letter-symbol/name | " \
"./graphical-symbol")) or return
designation_annotate(d1, name, desgn)
out << d1
s and out << s.wrap("<fmt-termsource></fmt-termsource>").parent
end

def designation_annotate(desgn, name, orig)
designation_boldface(desgn)
designation_field(desgn, name, orig)
g = desgn.at(ns("./expression/grammar")) and
name << ", #{designation_grammar(g).join(', ')}"
designation_localization(desgn, name, orig)
designation_pronunciation(desgn, name)
designation_bookmarks(desgn, name)
desgn.children = name.children
end

def designation_boldface(desgn)
desgn["element"] == "preferred" or return
name = desgn.at(ns("./expression/name | ./letter-symbol/name")) or return
name.children = "<strong>#{name.children}</strong>"
end

def designation_field(desgn, name, orig)
f = orig.xpath(ns("./field-of-application | ./usage-info"))
&.map { |u| to_xml(semx_fmt_dup(u)) }&.join(", ")
f&.empty? and return nil
name << "<span class='fmt-designation-field'>, &#x3c;#{f}&#x3e;</span>"
end

def designation_grammar(grammar)
ret = []
grammar.xpath(ns("./gender | ./number")).each do |x|
ret << @i18n.grammar_abbrevs[x.text]
end
%w(isPreposition isParticiple isAdjective isVerb isAdverb isNoun)
.each do |x|
grammar.at(ns("./#{x}[text() = 'true']")) and
ret << @i18n.grammar_abbrevs[x]
end
ret
end

def designation_localization(desgn, name, orig_desgn)
loc = [desgn.at(ns("./expression/@language"))&.text,
desgn.at(ns("./expression/@script"))&.text,
orig_desgn.at("./@geographic-area")&.text].compact
loc.empty? and return
name << ", #{loc.join(' ')}"
end

def designation_pronunciation(desgn, name)
f = desgn.at(ns("./expression/pronunciation")) or return
name << ", /#{to_xml(f.children)}/"
end

def designation_bookmarks(desgn, name)
desgn.xpath(ns(".//bookmark")).each do |b|
name << b.remove
end
end
end
end
2 changes: 2 additions & 0 deletions lib/isodoc/presentation_function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def quotesource(docxml)
end

def xref1(node)
# Semantic XML
node.ancestors("related, definition, termsource").empty? or return
get_linkend(node)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/presentation_function/refs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def bibliography_bibitem_number_skip(bibitem)
def bibliography_bibitem_number(docxml)
i = 0
docxml.xpath(ns("//references")).each do |r|
r.xpath(ns(".//bibitem")).each do |b|
r.xpath(ns("./bibitem")).each do |b|
i = bibliography_bibitem_number1(b, i, r["normative"] == "true")
end
end
Expand Down
Loading
Loading