class SiSU_Concordance::Source::Words
Public Class Methods
new(particulars)
click to toggle source
# File lib/sisu/html_concordance.rb, line 205 def initialize(particulars) @particulars=particulars begin @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array @file=SiSU_Env::FileOp.new(@md) @freq=Hash.new(0) @dp=@@dp ||=SiSU_Env::InfoEnv.new.digest.pattern @rxp_lv1=/^#{Mx[:lv_o]}1:/ #fix @rxp_lv # Mx[:lv_o] @rxp_lv2=/^#{Mx[:lv_o]}2:/ #fix @rxp_lv # Mx[:lv_o] @rxp_lv3=/^#{Mx[:lv_o]}3:/ #fix @rxp_lv # Mx[:lv_o] @rxp_title=Regexp.new("^#{Mx[:meta_o]}title#{Mx[:meta_c]}\s*(.+?)\s*$") @rxp_t1=Regexp.new('^T1') @rxp_t2=Regexp.new('^T2') @rxp_t3=Regexp.new('^T3') @rxp_excluded1=/#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ @rxp_excluded0=/^(?:#{Mx[:fa_bold_o]}|#{Mx[:fa_italics_o]})?(?:to\d+|\d+| |#{Mx[:br_endnotes]}|EOF|#{Mx[:br_eof]}|thumb_\S+|snap_\S+|_+|-+|[(]?(?:ii+|iv|vi+|ix|xi+|xiv|xv|xvi+|xix|xx)[).]?|\S+?_\S+|[\d_]+\w\S+|[\w\d]{1,2}|\d{1,3}\w?|#{@dp}|[0-9a-f]{16,64}|\d{2,3}x\d{2,3}|\S{0,2}sha\d|\S{0,3}\d{4}w\d\d|\b\w\d+|\d_all\b|e\.?g\.?)(?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})?$/mi #this regex causes and cures a stack dump in ruby 1.9 !!! @rgx_splitlist=%r{[—.,;:#{Mx[:nbsp]}-]}mi @alph=SiSU_i18n::Alphabet.new(@md.opt.lng).hash_arrays @alphlst=SiSU_i18n::Alphabet.new(@md.opt.lng).hash_strings @rgx_scanlist=%r{#{Mx[:fa_italics_o]}[#{@alphlst[:l]}#{@alphlst[:u]}0-9"\s]{2,12}#{Mx[:fa_italics_c]}|#{Mx[:fa_bold_o]}[#{@alphlst[:l]}#{@alphlst[:u]}0-9"\s]{2,12}#{Mx[:fa_bold_c]}|(?:https?|file)://\S+|<\S+?>|[#{@alphlst[:l]}#{@alphlst[:u]}]+|\w+}mi rescue SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do __LINE__.to_s + ':' + __FILE__ end end end
Public Instance Methods
songsheet()
click to toggle source
# File lib/sisu/html_concordance.rb, line 231 def songsheet begin FileUtils::mkdir_p(@file.output_path.html_concordance.dir) \ unless FileTest.directory?(@file.output_path.html_concordance.dir) @file_concordance=File.open(@file.place_file.html_concordance.dir,'w') map_para rescue SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do __LINE__.to_s + ':' + __FILE__ end ensure @file_concordance.close end end
Protected Instance Methods
location_scroll(wordlocation,show)
click to toggle source
# File lib/sisu/html_concordance.rb, line 246 def location_scroll(wordlocation,show) # not used %{<a href="doc#{@md.lang_code_insert}#{Sfx[:html]}\##{Mx[:ocn_id_char]}#{wordlocation}">#{wordlocation}</a>; } end
location_seg(wordlocation,show)
click to toggle source
# File lib/sisu/html_concordance.rb, line 249 def location_seg(wordlocation,show) unless wordlocation.nil? wl=wordlocation.gsub(/(.+?)\#(\d+)/, "\\1#{@md.lang_code_insert}#{Sfx[:html]}##{Mx[:ocn_id_char]}\\2") # id="o\d+" always available; a name="\d+" not available if html strict used case wordlocation when /#{@rxp_t1}|@rxp_t2}|#{@rxp_t3}/ %{[<a href="doc#{@md.lang_code_insert}#{Sfx[:html]}##{show}">H</a>]#{show}, } when /(.+?)\#(\d+)/ %{<a href="#{wl}">#{show}</a>, } end end end
map_para()
click to toggle source
# File lib/sisu/html_concordance.rb, line 261 def map_para @seg,ocn=nil,nil @word_map={} @ao_array.each do |line| if defined? line.ocn \ and line.ocn.to_s =~/\d/ if (line.is ==:heading \ || line.is ==:heading_insert) \ && line.ln==4 @seg=line.name end ocn=line.ocn.to_s if ocn =~/\d+/ \ and ocn !~/^0$/ line.obj=line.obj.gsub(/#{@rxp_excluded1}/,' ') line.obj=line.obj.split(@rgx_splitlist).join(' ') #%take in word or other match for word in line.obj.scan(@rgx_scanlist) #%take in word or other match if word =~ /^([#{@alphlst[:l]}])/ firstletter=$1 flu=firstletter.tr(@alphlst[:l],@alphlst[:u]) word=word.gsub(/^#{firstletter}/,flu ) end word=word.gsub(/#{Mx[:lnk_o]}|#{Mx[:lnk_c]}|#{Mx[:url_o]}|#{Mx[:url_c]}/,''). gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,''). gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). gsub(/#{Mx[:gl_o]}#[a-z]+#{Mx[:gl_c]}/,''). gsub(/#{Mx[:gl_o]}#[0-9]+#{Mx[:gl_c]}/,'') word=word.gsub(/[0-9a-f]{10,}/,' ') if word =~/[0-9]/ word=word.gsub(/#{Mx[:br_line]}/,' '). gsub(/^ +/,''). gsub(/^\S$/,'') word=nil if word.empty? word=nil if word =~@rxp_excluded0 #watch word=nil if word =~/^\S$/ if word word=word.gsub(/#{Mx[:br_nl]}|#{Mx[:br_line]}/,' '). gsub(/#{Mx[:fa_o]}[a-z]{1,7}#{Mx[:fa_o_c]}|#{Mx[:fa_c_o]}[a-z]{1,7}#{Mx[:fa_c]}/,''). gsub(/#{Mx[:en_a_o]}(?:\d|[*+])*|#{Mx[:en_b_o]}(?:\d|[*+])*|#{Mx[:en_a_c]}|#{Mx[:en_b_c]}/mi,''). gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,''). gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). gsub(/<\/?\S+?>/,''). gsub(/^\@+/,''). strip. gsub(/#{Mx[:tc_p]}.+/,''). gsub(/[\.,;:"]$/,''). gsub(/["]/,''). gsub(/^\s*[\(]/,''). gsub(/[\(]\s*$/,''). gsub(/^(?:See|e\.?g\.?).+/,''). gsub(/^\s*[.,;:]\s*/,''). strip. gsub(/^\(?[a-zA-Z]\)$/,''). gsub(/^\d+(st|nd|rd|th)$/,''). gsub(/^(\d+\.?)+$/, ''). gsub(/#{Mx[:mk_o]}|#{Mx[:mk_c]}/,''). gsub(/:name#\S+/,''). gsub(/^\S$/,'') word=nil if word =~/^\S$/ word=nil if word =~/^\s*$/ #watch if word unless word =~/[A-Z][A-Z]/ \ or word =~/\w+\s\w+/ word=word.capitalize end @freq[word] +=1 @word_map[word] ||= [] if line !~ /#{@rxp_lv1}|#{@rxp_lv2}|#{@rxp_lv3}/ loc_=%{#{location_seg("#{@seg}\##{ocn}",ocn).to_s}} unless loc_.empty? @word_map[word] << loc_ end else @word_map[word] << case line when @rxp_lv1 then location_seg('T1',ocn) #fix @rxp_lv # Mx[:lv_o] when @rxp_lv2 then location_seg('T2',ocn) #fix @rxp_lv # Mx[:lv_o] when @rxp_lv3 then location_seg('T3',ocn) #fix @rxp_lv # Mx[:lv_o] end end end end end end end end seg='' head=SiSU_Concordance::Source::DocTitle.new(@particulars).create head=head.gsub(/#{Xx[:html_relative2]}/m,@file.path_rel_links.html_seg_2). gsub(/#{Xx[:html_relative1]}/m,@file.path_rel_links.html_seg_1) @file_concordance << head @file_concordance << '<p>' alph=@alph[:u] alph.each {|x| @file_concordance << %{<a href="##{x}">#{x}</a>, }} @file_concordance << '</p>' letter=alph.shift @file_concordance << %{\n<p class="letter"><a name="A">A</a></p>} for word in @freq.keys.sort! {|a,b| a.downcase<=>b.downcase} f=/^(\S)/.match(word)[1] if letter < f.upcase while letter < f.upcase if alph.length > 0 letter=alph.shift @file_concordance << %{\n<p class="letter"><a name="#{letter}">#{letter}</a></p>} else break end end end keyword=SiSU_Concordance::Source::Word.new(word,@freq[word]).html if keyword !~ @rxp_excluded0 if @word_map[word][0] =~ /\d+/ @file_concordance << %{#{keyword}#{seg}#{@word_map[word].uniq.compact.join}} end @file_concordance << '</p>' end # special cases endnotes and header levels 1 - 3 end @file_concordance << %{</div></body>\n</html>} # footer if @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on SiSU_Screen::Ansi.new( @md.opt.act[:color_state][:set], @md.fns, "#{@md.file.output_path.html_concordance.dir}/#{@md.file.base_filename.html_concordance}" ).flow end end