From 1529e474fd5c8a67679438e8f2cea5cd6d26db3d Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 8 Sep 2008 23:09:37 -0400 Subject: book index, sample html file and to screen sisu markup sample added (-M flag) --- lib/sisu/v0/dal_idx.rb | 144 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 128 insertions(+), 16 deletions(-) (limited to 'lib/sisu/v0/dal_idx.rb') diff --git a/lib/sisu/v0/dal_idx.rb b/lib/sisu/v0/dal_idx.rb index 607686a3..26fc66b6 100644 --- a/lib/sisu/v0/dal_idx.rb +++ b/lib/sisu/v0/dal_idx.rb @@ -61,14 +61,21 @@ =end module SiSU_book_index class Book_index - def initialize(data) - @data=data - end - def indexing_song + def initialize(md,data,env=nil) + @md,@data,@env=md,data,env @rgx_idx=/#{Mx[:idx_o]}(?:.+?)#{Mx[:idx_c]}\s*/ #@rgx_idx=/\s*#{Mx[:idx_o]}(?:.+?)#{Mx[:idx_c]}\s*/ @rgx_idx_ocn_init=/#{Mx[:idx_o]}(.+?)#{Mx[:idx_c]}\s*#{Mx[:id_o]}~(\d+)\S+?#{Mx[:id_c]}/ + @rgx_idx_ocn_seg=/(.+?)~(\d+)~(\S+)/ @rgx_idx_ocn=/(.+?)~(\d+)/ + @rxp_lv1=/^#{Mx[:lv_o]}1:/ + @rxp_lv2=/^#{Mx[:lv_o]}2:/ + @rxp_lv3=/^#{Mx[:lv_o]}3:/ + @rxp_seg=/^#{Mx[:lv_o]}4:(\S+?)#{Mx[:lv_c]}/ + @rxp_to=Regexp.new("#{Mx[:id_o]}~(\\d+);(?:[oh]|[0-6]:)\\d+;\\w\\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}|#{Mx[:id_o]}\S+?#{Mx[:id_c]}$") + @env ||=SiSU_Env::Info_env.new(@md.fns) + end + def indexing_song @data=extract_book_index(@data) @data=clean_index(@data) @data @@ -77,7 +84,9 @@ module SiSU_book_index tuned_file=[] idx_array=[] data.each do |para| - idx_array << @rgx_idx_ocn_init.match(para)[0].gsub(@rgx_idx_ocn_init,'\1~\2') if para =~ @rgx_idx_ocn_init + if para =~@rxp_seg; @seg=para[@rxp_seg,1] + end + idx_array << @rgx_idx_ocn_init.match(para)[0].gsub(@rgx_idx_ocn_init,"\\1~\\2~#{@seg}") if para =~ @rgx_idx_ocn_init tuned_file << para if para end #idx_array.each do |i| @@ -85,23 +94,32 @@ module SiSU_book_index #end idx_array=construct_idx_array(idx_array) if idx_array.length > 0 if idx_array.length > 0 - the_idx=construct_book_index(idx_array) - screen_print(the_idx) + if @md.cmd.inspect =~/M/ + the_idx=construct_book_index(idx_array) + screen_print(the_idx) if @md.cmd.inspect =~/M/ + puts "\n---" + path="#{@env.path.output}/#{@md.fnb}" + @file_index_all=File.open("#{path}/#{@md.fn[:book_index]}",'w') + screen_html(the_idx) + @file_index_all.close + puts "\n---" + screen_sisu_markup(the_idx) + end end tuned_file end def construct_idx_array(idx_array) idx_lst=[] idx_array.each do |idx| - idx_list,ocn=@rgx_idx_ocn.match(idx)[1,2] + idx_list,ocn,seg=@rgx_idx_ocn_seg.match(idx)[1..3] idx_lst <<=if idx_list =~/;/ g=idx_list.scan(/[^;]+/) idxl=[] g.each do |i| - idxl << { :rough_idx => i, :ocn => ocn } + idxl << { :rough_idx => i, :ocn => ocn, :seg => seg } end idxl - else { :rough_idx => idx_list, :ocn => ocn } + else { :rough_idx => idx_list, :ocn => ocn, :seg => seg } end end idx_lst.flatten! @@ -122,20 +140,20 @@ module SiSU_book_index x=if idx_lst.length == 1 or idx_lst[0] == i @the_idx[use]['a1']=[] unless @the_idx[use]['a1'] and defined? @the_idx[use]['a1'] x=if r - @the_idx[use]['a1'] << { :ocn => idx[:ocn], :range => "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}" } + @the_idx[use]['a1'] << { :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]['a1'] << { :ocn => idx[:ocn] } + @the_idx[use]['a1'] << { :ocn => idx[:ocn], :seg => idx[:seg] } "#{i} #{idx[:ocn]}" end else @the_idx[use]['b1']={} unless @the_idx[use]['b1'] and defined? @the_idx[use]['b1'] @the_idx[use]['b1'][i]=[] unless @the_idx[use]['b1'][i] and defined? @the_idx[use]['b1'][i] x=if r - @the_idx[use]['b1'][i] << { :ocn => idx[:ocn], :range => "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}" } + @the_idx[use]['b1'][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]['b1'][i] << { :ocn => idx[:ocn] } + @the_idx[use]['b1'][i] << { :ocn => idx[:ocn], :seg => idx[:seg] } "#{idx_lst[0]}:#{i} #{idx[:ocn]}" end end @@ -186,6 +204,102 @@ module SiSU_book_index end end end + def screen_html(the_idx) + @file_index_all << %{\n } + the_idx.each do |i| + i.each do |x| + if x.class == String + @file_index_all << %{\n

#{x}, } + #@file_index_all << %{
\n#{x}, } + print %{
\n#{x}, } + elsif x.class == Array + p 'array error? -->' + print x + elsif x.class == Hash + if x['a1'].class == Array + x['a1'].each do |a| + if a[:range] + @file_index_all << %{#{a[:range]}, } + print %{#{a[:range]}, } + elsif a[:ocn] + @file_index_all << %{#{a[:ocn]}, } + print %{#{a[:ocn]}, } + else p 'error' + end + end + @file_index_all << '

' + end + if x['b1'] + m=x['b1'] + m=m.sort + m.each do |k,y| + if k !~/a1/ + @file_index_all << %{\n

#{k}, } + #@file_index_all << %{
\n\t#{k}, } + print %{
\n\t#{k}, } + #p y + y.each do |z| + if z[:range] + @file_index_all << %{#{z[:range]}, } + print %{#{z[:range]}, } + elsif z[:ocn] + @file_index_all << %{#{z[:ocn]}, } + print %{#{z[:ocn]}, } + else p 'error' + end + end + @file_index_all << '

' + end + end + end + end + end + end + end + def screen_sisu_markup(the_idx) + the_idx.each do |i| + i.each do |x| + if x.class == String + print %{\n\n#{Mx[:fa_bold_o]}#{x}#{Mx[:fa_bold_c]}, } + #print %{\n\n#{Mx[:gr_o]}\n#{Mx[:fa_bold_o]}#{x}#{Mx[:fa_bold_c]}, } + #print "\n" + x + ', ' + elsif x.class == Array + p 'array error? -->' + print x + elsif x.class == Hash + if x['a1'].class == Array + x['a1'].each do |a| + if a[:range] + print %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{a[:seg]}.html##{a[:ocn]}, } + elsif a[:ocn] + print %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{a[:seg]}.html##{a[:ocn]}, } + else p 'error' + end + end + end + if x['b1'] + m=x['b1'] + m=m.sort + m.each do |k,y| + if k !~/a1/ + print %{\n #{k}, } + #print "\n\t" + k + ', ' + y.each do |z| + if z[:range] + print %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{z[:seg]}.html##{z[:ocn]}, } + elsif z[:ocn] + print %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{z[:seg]}.html##{z[:ocn]}, } + else p 'error' + end + end + puts " #{Mx[:id_o]}~0;0:0;u0#{Mx[:id_c]}" + end + end + end + end + end + end + end def clean_index(data) tuned_file=[] data.each do |para| @@ -196,6 +310,4 @@ module SiSU_book_index end end end - __END__ - -- cgit v1.2.3