diff options
Diffstat (limited to 'lib/sisu/v3/dal_idx.rb')
-rw-r--r-- | lib/sisu/v3/dal_idx.rb | 85 |
1 files changed, 48 insertions, 37 deletions
diff --git a/lib/sisu/v3/dal_idx.rb b/lib/sisu/v3/dal_idx.rb index 63735bde..db4ba9c1 100644 --- a/lib/sisu/v3/dal_idx.rb +++ b/lib/sisu/v3/dal_idx.rb @@ -79,7 +79,11 @@ module SiSU_DAL_BookIndex && dob.ln==4 @seg=dob.name end - idx_array << "#{dob.idx}~#{dob.ocn}~#{@seg}" if defined? dob.idx and not (dob.idx.nil? or dob.idx.empty?) + if defined? dob.idx \ + and dob.idx.is_a?(String) \ + and not dob.idx.empty? + idx_array << "#{dob.idx}~#{dob.ocn}~#{@seg}" + end tuned_file << dob if dob end idx_array=construct_idx_array(idx_array) if idx_array.length > 0 @@ -113,35 +117,42 @@ module SiSU_DAL_BookIndex def construct_book_index(idx_array) the_idx={} idx_array.each do |idx| - idx_lst=idx[:rough_idx].scan(/[^|:]+/) - idx_lst[0]=idx_lst[0].strip - if idx_lst[0] =~/.+?\+\d+/ - use,plus=/(.+?)\+(\d+)/.match(idx_lst[0])[1,2] - else use=idx_lst[0] - end - use=use[0].chr.capitalize + use[1,use.length] - the_idx[use]={} unless the_idx[use] and defined? the_idx[use] - idx_lst.each do |i| - i=i.strip - i,r=/(.+?)\+(\d+)/.match(i)[1,2] if i =~/.+?\+\d+/ - x=if idx_lst.length==1 or idx_lst[0].gsub(/\+\d+/,'')==i - the_idx[use]['term_node_lev1']=[] unless the_idx[use]['term_node_lev1'] and defined? the_idx[use]['term_node_lev1'] - x=if r - the_idx[use]['term_node_lev1'] << { ocn: idx[:ocn], range: "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}", seg: idx[:seg] } - "#{i} #{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}" - else - the_idx[use]['term_node_lev1'] << { ocn: idx[:ocn], seg: idx[:seg] } - "#{i} #{idx[:ocn]}" - end - else - the_idx[use]['term_node_lev2']={} unless the_idx[use]['term_node_lev2'] and defined? the_idx[use]['term_node_lev2'] - the_idx[use]['term_node_lev2'][i]=[] unless the_idx[use]['term_node_lev2'][i] and defined? the_idx[use]['term_node_lev2'][i] - x=if r - the_idx[use]['term_node_lev2'][i] << { ocn: idx[:ocn], range: "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}", seg: idx[:seg] } - "#{idx_lst[0]}:#{i} #{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}" + if idx[:rough_idx] =~/[|]/ \ + && idx[:rough_idx] !~/[:]/ + if @md.opt.cmd =~/[MVv]/ + p 'book index error? --> ' + idx[:rough_idx] + end + else + idx_lst=idx[:rough_idx].scan(/[^|:]+/) + idx_lst[0]=idx_lst[0].strip + if idx_lst[0] =~/.+?\+\d+/ + use,plus=/(.+?)\+(\d+)/.match(idx_lst[0])[1,2] + else use=idx_lst[0] + end + use=use[0].chr.capitalize + use[1,use.length] + the_idx[use]={} unless the_idx[use] and defined? the_idx[use] + idx_lst.each do |i| + i=i.strip + i,r=/(.+?)\+(\d+)/.match(i)[1,2] if i =~/.+?\+\d+/ + x=if idx_lst.length==1 or idx_lst[0].gsub(/\+\d+/,'')==i + the_idx[use]['term_node_lev1']=[] unless the_idx[use]['term_node_lev1'] and defined? the_idx[use]['term_node_lev1'] + x=if r + the_idx[use]['term_node_lev1'] << { ocn: idx[:ocn], range: "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}", seg: idx[:seg] } + "#{i} #{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}" + else + the_idx[use]['term_node_lev1'] << { ocn: idx[:ocn], seg: idx[:seg] } + "#{i} #{idx[:ocn]}" + end else - the_idx[use]['term_node_lev2'][i] << { ocn: idx[:ocn], seg: idx[:seg] } - "#{idx_lst[0]}:#{i} #{idx[:ocn]}" + the_idx[use]['term_node_lev2']={} unless the_idx[use]['term_node_lev2'] and defined? the_idx[use]['term_node_lev2'] + the_idx[use]['term_node_lev2'][i]=[] unless the_idx[use]['term_node_lev2'][i] and defined? the_idx[use]['term_node_lev2'][i] + x=if r + the_idx[use]['term_node_lev2'][i] << { ocn: idx[:ocn], range: "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}", seg: idx[:seg] } + "#{idx_lst[0]}:#{i} #{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}" + else + the_idx[use]['term_node_lev2'][i] << { ocn: idx[:ocn], seg: idx[:seg] } + "#{idx_lst[0]}:#{i} #{idx[:ocn]}" + end end end end @@ -193,7 +204,7 @@ module SiSU_DAL_BookIndex idx[:xhtml] << %{\n<p class="letter" id="numeral">0 - 9</p>} the_idx.each do |i| i.each do |x| - if x.class==String + if x.is_a?(String) f=/^(\S)/.match(x)[1] if letter < f while letter < f @@ -216,11 +227,11 @@ module SiSU_DAL_BookIndex @q=idx[:html].index(idx[:html].last) @r=idx[:xhtml].index(idx[:xhtml].last) print "\n" + x + ', ' if @md.opt.cmd =~/V/ - elsif x.class==Array + elsif x.is_a?(Array) p 'array error? -->' print x - elsif x.class==Hash - if x['term_node_lev1'].class==Array + elsif x.is_a?(Hash) + if x['term_node_lev1'].is_a?(Array) x['term_node_lev1'].each do |a| if a[:range] idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}/#{a[:seg]}.html##{a[:ocn]}#{Mx[:rel_c]}, } @@ -283,13 +294,13 @@ module SiSU_DAL_BookIndex def screen_print(the_idx) the_idx.each do |i| i.each do |x| - if x.class==String + if x.is_a?(String) print "\n" + x + ', ' - elsif x.class==Array + elsif x.is_a?(Array) p 'array error? -->' print x - elsif x.class==Hash - if x['term_node_lev1'].class==Array + elsif x.is_a?(Hash) + if x['term_node_lev1'].is_a?(Array) x['term_node_lev1'].each do |a| if a[:range] print a[:range] + ', ' |