From 418716166677579b407653959f5d7e8947a4579d Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 1 Jul 2014 00:39:28 -0400 Subject: v5 v6: files renamed: ao_composite.rb, html_concordance.rb * ao_composite.rb (from composite.rb) * html_concordance.rb (from concordance.rb) --- lib/sisu/v5/ao_composite.rb | 267 ++++++++++++++++++++++++++++ lib/sisu/v5/composite.rb | 267 ---------------------------- lib/sisu/v5/concordance.rb | 382 ---------------------------------------- lib/sisu/v5/html_concordance.rb | 382 ++++++++++++++++++++++++++++++++++++++++ lib/sisu/v5/hub.rb | 4 +- lib/sisu/v5/po4a.rb | 2 +- lib/sisu/v5/remote.rb | 2 +- lib/sisu/v6/ao_composite.rb | 267 ++++++++++++++++++++++++++++ lib/sisu/v6/composite.rb | 267 ---------------------------- lib/sisu/v6/concordance.rb | 382 ---------------------------------------- lib/sisu/v6/html_concordance.rb | 382 ++++++++++++++++++++++++++++++++++++++++ lib/sisu/v6/hub.rb | 4 +- lib/sisu/v6/po4a.rb | 2 +- lib/sisu/v6/remote.rb | 2 +- 14 files changed, 1306 insertions(+), 1306 deletions(-) create mode 100644 lib/sisu/v5/ao_composite.rb delete mode 100644 lib/sisu/v5/composite.rb delete mode 100644 lib/sisu/v5/concordance.rb create mode 100644 lib/sisu/v5/html_concordance.rb create mode 100644 lib/sisu/v6/ao_composite.rb delete mode 100644 lib/sisu/v6/composite.rb delete mode 100644 lib/sisu/v6/concordance.rb create mode 100644 lib/sisu/v6/html_concordance.rb diff --git a/lib/sisu/v5/ao_composite.rb b/lib/sisu/v5/ao_composite.rb new file mode 100644 index 00000000..9fd42672 --- /dev/null +++ b/lib/sisu/v5/ao_composite.rb @@ -0,0 +1,267 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * Author: Ralph Amissah + + * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah, + All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: composite documents, assemble/build documents from other + documents or parts of marked up text + +=end +module SiSU_Assemble + require_relative 'sysenv' # sysenv.rb + class RemoteImage + def initialize + @env=SiSU_Env::InfoEnv.new + end + def image(dir) + images=[] + images[0]=dir + images + end + def download_images(images_info) + path="#{@env.processing_path.processing}/external_document/image" + FileUtils::mkdir_p(path) unless FileTest.directory?(path) + download_from=images_info.shift + images_info.each do |i| + image="#{path}/#{i}" + imagefile=File.new(image,'w+') + open("#{download_from}/#{i}") do |g| + imagefile << g.read + end + imagefile.close + end + output_path="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external" + FileUtils::mkdir_p(output_path) unless FileTest.directory?(output_path) + SiSU_Env::SystemCall.new("#{path}/*",output_path,'q').rsync + end + end + class Composite + @@imager={} + def initialize(opt) + @opt=opt + @env=SiSU_Env::InfoEnv.new + end + def read + begin + pwd=Dir.pwd + Dir.chdir(@opt.f_pth[:pth]) + @fns_array=IO.readlines(@opt.fno,'') + assembled=insertions? + write(assembled) + Dir.chdir(pwd) + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + def write(assembled) + assembled_file=File.new("#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst",'w+') + assembled.each {|a| assembled_file << a } + assembled_file.close + end + def download_images(download_from,images_array) + path="#{@env.processing_path.processing}/external_document/image" + FileUtils::mkdir_p(path) unless FileTest.directory?(path) + images_array.each do |i| + image="#{path}/#{i}" + unless FileTest.exists?(image) + imagefile=File.new(image,'w+') + open("#{download_from}/#{i}") do |g| + imagefile << g.read + end + imagefile.close + end + end + end + def insertion(fni,insert_array) + file={ prepared: [], images: [] } + rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ + file[:prepared] << "\n% |#{fni}|@|^|>>ok\n\n" + @code_flag=false + insert_array.each do |i| + @code_flag=if i =~/^code\{/ then true + elsif i =~/^\}code/ then false + else @code_flag + end + if not @code_flag \ + and i !~/^%+\s/ + i=i.gsub(/^([123]|:?[ABCD])~\? /,'% [conditional heading:] \1~ ') #off conditional heading (consider syntax) + if i =~/^@\S+?:/ + i=i.gsub(/\n/m,"\n% "). + gsub(/\n%\s+$/m,''). + gsub(/^@\S+?:/m,"\n% [imported header:] ") #off imported headers + end + end + file[:prepared] << i + if i !~/^%+\s/ \ + and i =~rgx_image + file[:images] << i.scan(rgx_image).uniq + end + end + file[:prepared] << "\n% end import" << "\n\n" + if file[:images].length > 0 + file[:images]=file[:images].flatten.uniq + file[:images].delete_if {|x| x =~/https?:\/\// } + end + file + end + def insertions? + data=@fns_array + tuned_file,imagedir=[],[] + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Composite Document',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").grey_title_hi unless @opt.act[:quiet][:set]==:on + data.each do |para| + if para =~/^<<\s+(\S+?\.ss[it])$/ + loadfile=$1.strip + src_ssm=@opt.fns.sub(/\.ssm\.sst/,'.ssm') + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'loading:',loadfile).txt_grey + end + tuned_file << if loadfile =~ /(?:https?|file):\/\/\S+?\.ss[ti]$/ # and NetTest + imagedir = /((?:https?|file):\/\/\S+?)\/[^\/]+?\.ss[ti]$/.match(loadfile).captures.join + '/_sisu/image' #watch + begin + require 'uri' + require 'open-uri' + require 'pp' + rescue LoadError + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).error('uri, open-uri or pp NOT FOUND (LoadError)') + end + image_uri=URI.parse(imagedir) + insert=open(loadfile) + insert_array=insert.dup + insert.close + file=insertion(loadfile,insert_array) + @@imager[image_uri] ||=[] + @@imager[image_uri] << file[:images] + file[:prepared] + elsif loadfile =~ /\.ss[ti]$/ \ + and FileTest.file?(loadfile) + insert_array=IO.readlines(loadfile,'') + file=insertion(loadfile,insert_array) + file[:prepared] + else + cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX + STDERR.puts %{SKIPPED processing file: [#{@opt.lng}] "#{@opt.fns}" it requires an invalid or non-existent file: "#{loadfile}"} + $process_document = :skip; break #remove this line to continue processing documents that have missing include files + para + end + else tuned_file << para + end + tuned_file=tuned_file.flatten.compact + end + if @@imager.length >0 + @@imager.each do |d,i| + i=i.flatten.uniq + image_info=d + i + download_images(image_info.flatten) + end + end + tuned_file + end + end + class CompositeFileList + @@imager={} + def initialize(opt) + @opt=opt + @env=SiSU_Env::InfoEnv.new + end + def read + begin + @opt.fns=@opt.fns.gsub(/\.ssm\.sst$/,'.ssm') #FIX earlier, hub + @fns_array=IO.readlines(@opt.fns,'') + insertions? + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + def insertions? + data=@fns_array + tuned_file=[] + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Composite Document',@opt.fno).grey_title_hi unless @opt.act[:quiet][:set]==:on + @ssm=[@opt.fns] + data.each do |para| + if para =~/^<<\s+(\S+?\.ss[it])$/ + loadfile=$1.strip + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'loading:',loadfile).txt_grey + end + tuned_file << if loadfile =~ /(?:https?|file):\/\/\S+?\.ss[ti]$/ + @ssm << loadfile + elsif loadfile =~ /\.ss[ti]$/ \ + and FileTest.file?(loadfile) + @ssm << loadfile + else + cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX + STDERR.puts %{SKIPPED processing file: [#{@opt.lng}] "#{@opt.fns}" it requires an invalid or non-existent file: "#{loadfile}"} + $process_document = :skip; break #remove this line to continue processing documents that have missing include files + para + end + end + end + @ssm + end + end +end +__END__ diff --git a/lib/sisu/v5/composite.rb b/lib/sisu/v5/composite.rb deleted file mode 100644 index 9f722799..00000000 --- a/lib/sisu/v5/composite.rb +++ /dev/null @@ -1,267 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * Author: Ralph Amissah - - * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah, - All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) Ralph Amissah - - This program is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - this program. If not, see . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: composite documents, assemble/build documents from other - documents or parts of marked up text - -=end -module SiSU_Assemble - require_relative 'sysenv' # sysenv.rb - class RemoteImage - def initialize - @env=SiSU_Env::InfoEnv.new - end - def image(dir) - images=[] - images[0]=dir - images - end - def download_images(images_info) - path="#{@env.processing_path.processing}/external_document/image" - FileUtils::mkdir_p(path) unless FileTest.directory?(path) - download_from=images_info.shift - images_info.each do |i| - image="#{path}/#{i}" - imagefile=File.new(image,'w+') - open("#{download_from}/#{i}") do |g| - imagefile << g.read - end - imagefile.close - end - output_path="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external" - FileUtils::mkdir_p(output_path) unless FileTest.directory?(output_path) - SiSU_Env::SystemCall.new("#{path}/*",output_path,'q').rsync - end - end - class Composite - @@imager={} - def initialize(opt) - @opt=opt - @env=SiSU_Env::InfoEnv.new - end - def read - begin - pwd=Dir.pwd - Dir.chdir(@opt.f_pth[:pth]) - @fns_array=IO.readlines(@opt.fno,'') - assembled=insertions? - write(assembled) - Dir.chdir(pwd) - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - def write(assembled) - assembled_file=File.new("#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst",'w+') - assembled.each {|a| assembled_file << a } - assembled_file.close - end - def download_images(download_from,images_array) - path="#{@env.processing_path.processing}/external_document/image" - FileUtils::mkdir_p(path) unless FileTest.directory?(path) - images_array.each do |i| - image="#{path}/#{i}" - unless FileTest.exists?(image) - imagefile=File.new(image,'w+') - open("#{download_from}/#{i}") do |g| - imagefile << g.read - end - imagefile.close - end - end - end - def insertion(fni,insert_array) - file={ prepared: [], images: [] } - rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ - file[:prepared] << "\n% |#{fni}|@|^|>>ok\n\n" - @code_flag=false - insert_array.each do |i| - @code_flag=if i =~/^code\{/ then true - elsif i =~/^\}code/ then false - else @code_flag - end - if not @code_flag \ - and i !~/^%+\s/ - i=i.gsub(/^([123]|:?[ABCD])~\? /,'% [conditional heading:] \1~ ') #off conditional heading (consider syntax) - if i =~/^@\S+?:/ - i=i.gsub(/\n/m,"\n% "). - gsub(/\n%\s+$/m,''). - gsub(/^@\S+?:/m,"\n% [imported header:] ") #off imported headers - end - end - file[:prepared] << i - if i !~/^%+\s/ \ - and i =~rgx_image - file[:images] << i.scan(rgx_image).uniq - end - end - file[:prepared] << "\n% end import" << "\n\n" - if file[:images].length > 0 - file[:images]=file[:images].flatten.uniq - file[:images].delete_if {|x| x =~/https?:\/\// } - end - file - end - def insertions? - data=@fns_array - tuned_file,imagedir=[],[] - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Composite Document',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").grey_title_hi unless @opt.act[:quiet][:set]==:on - data.each do |para| - if para =~/^<<\s+(\S+?\.ss[it])$/ - loadfile=$1.strip - src_ssm=@opt.fns.sub(/\.ssm\.sst/,'.ssm') - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'loading:',loadfile).txt_grey - end - tuned_file << if loadfile =~ /(?:https?|file):\/\/\S+?\.ss[ti]$/ # and NetTest - imagedir = /((?:https?|file):\/\/\S+?)\/[^\/]+?\.ss[ti]$/.match(loadfile).captures.join + '/_sisu/image' #watch - begin - require 'uri' - require 'open-uri' - require 'pp' - rescue LoadError - SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).error('uri, open-uri or pp NOT FOUND (LoadError)') - end - image_uri=URI.parse(imagedir) - insert=open(loadfile) - insert_array=insert.dup - insert.close - file=insertion(loadfile,insert_array) - @@imager[image_uri] ||=[] - @@imager[image_uri] << file[:images] - file[:prepared] - elsif loadfile =~ /\.ss[ti]$/ \ - and FileTest.file?(loadfile) - insert_array=IO.readlines(loadfile,'') - file=insertion(loadfile,insert_array) - file[:prepared] - else - cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX - STDERR.puts %{SKIPPED processing file: [#{@opt.lng}] "#{@opt.fns}" it requires an invalid or non-existent file: "#{loadfile}"} - $process_document = :skip; break #remove this line to continue processing documents that have missing include files - para - end - else tuned_file << para - end - tuned_file=tuned_file.flatten.compact - end - if @@imager.length >0 - @@imager.each do |d,i| - i=i.flatten.uniq - image_info=d + i - download_images(image_info.flatten) - end - end - tuned_file - end - end - class CompositeFileList - @@imager={} - def initialize(opt) - @opt=opt - @env=SiSU_Env::InfoEnv.new - end - def read - begin - @opt.fns=@opt.fns.gsub(/\.ssm\.sst$/,'.ssm') #FIX earlier, hub - @fns_array=IO.readlines(@opt.fns,'') - insertions? - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - def insertions? - data=@fns_array - tuned_file=[] - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Composite Document',@opt.fno).grey_title_hi unless @opt.act[:quiet][:set]==:on - @ssm=[@opt.fns] - data.each do |para| - if para =~/^<<\s+(\S+?\.ss[it])$/ - loadfile=$1.strip - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'loading:',loadfile).txt_grey - end - tuned_file << if loadfile =~ /(?:https?|file):\/\/\S+?\.ss[ti]$/ - @ssm << loadfile - elsif loadfile =~ /\.ss[ti]$/ \ - and FileTest.file?(loadfile) - @ssm << loadfile - else - cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX - STDERR.puts %{SKIPPED processing file: [#{@opt.lng}] "#{@opt.fns}" it requires an invalid or non-existent file: "#{loadfile}"} - $process_document = :skip; break #remove this line to continue processing documents that have missing include files - para - end - end - end - @ssm - end - end -end -__END__ diff --git a/lib/sisu/v5/concordance.rb b/lib/sisu/v5/concordance.rb deleted file mode 100644 index b9030123..00000000 --- a/lib/sisu/v5/concordance.rb +++ /dev/null @@ -1,382 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * Author: Ralph Amissah - - * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah, - All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) Ralph Amissah - - This program is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - this program. If not, see . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: concordance file (html concordance, wordmap, linked index of - words in document) - -=end -module SiSU_Concordance - require_relative 'particulars' # particulars.rb - include SiSU_Particulars - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'html_format' # html_format.rb - include SiSU_HTML_Format - require_relative 'html_minitoc' # html_minitoc.rb - class Source - def initialize(opt) - @opt=opt - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - end - def read - begin - @env,@md=@particulars.env,@particulars.md - @env.url.output_tell - unless @md.opt.act[:quiet][:set]==:on - tool=(@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) \ - ? "#{@env.program.web_browser} #{@md.file.output_path.html_concordance.dir}/#{@md.file.base_filename.html_concordance}" - : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" - (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Concordance",tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Concordance',tool).green_title_hi - end - wordmax=@env.concord_max - unless @md.wc_words.nil? - if @md.wc_words < wordmax - SiSU_Concordance::Source::Words.new(@particulars).songsheet - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"concordance skipped, large document has over #{wordmax} words (#{@md.wc_words})").warn unless @md.opt.act[:quiet][:set]==:on - end - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"wc (word count) is off, concordance will be processed for all files including those over the max set size of: #{wordmax} words").warn unless @md.opt.act[:quiet][:set]==:on - SiSU_Concordance::Source::Words.new(@particulars).songsheet - end - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - SiSU_Env::CreateSite.new(@opt.cmd).cp_css - end - end - private - class DocTitle - include SiSU_Viz - #revisit, both requires (html & xml_shared) needed for stand alone operation (sisu -w [filename]) - require_relative 'xml_shared' # xml_shared.rb - require_relative 'html' # html.rb - def initialize(particulars) - @particulars,@md=particulars,particulars.md - @data=SiSU_HTML::Source::HTML_Environment.new(particulars).tuned_file_instructions - @file=SiSU_Env::FileOp.new(@md) - @fnb=@md.fnb - @lex_button=%{SiSU home -->} - @doc_details =< 

#{@md.title.full}

#{@md.author}

-WOK - @make=SiSU_Env::ProcessingSettings.new(@md) - end - def create - head_banner=SiSU_HTML_Format::HeadToc.new(@md) - minitoc=SiSU_HTML_MiniToc::TocMini.new(@md,@data).songsheet.join("\n") - stylesheet=SiSU_Style::CSS_HeadInfo.new(@md).stylesheet - if @make.build.manifest_minitoc? - toc='
' + minitoc + '
' - div_class='content' - else - toc='' - div_class='content0' - end - top_band=if @make.build.html_top_band? - head_banner.concordance_navigation_band - else '' - end - < - - - - SiSU created WordIndex for: #{@md.title.full} - - - - - - - - #{stylesheet.css_head_seg} - - - #{top_band} - #{toc} -
- #{@doc_details} -

Word index links are to html versions of the text the segmented version followed by the scroll (single document) version.
[For segmented text references [T1], [T2] or [T3] appearing without a link, indicates that the word appears in a title (or subtitle) of the text (that is identifiable by the appended object citation number).]

-

(The word listing/index is Case sensitive: Capitalized words appear before lower case)

-

- word (number of occurences)
linked references to word within document
- [if number of occurences exceed number of references - word occurs more than once in at least one reference. Footnote/endnotes are either assigned to the paragraph from which they are referenced or ignored, so it is relevant to check the footnotes referenced from within a paragraph as well.] -

-

- (After the page is fully loaded) you can jump directly to a word by appending a hash (#) and the word to the url for this text, (do not forget that words are case sensitive, and may be listed twice (starting with and without an upper case letter)), #your_word # [ http://[web host]/#{@fnb}/concordance.html#your_word ] -

-WOK - end - end - class Word - @@word_previous='' - def initialize(word,freq) - @word,@freq=word,freq - end - def html - w=if @word.capitalize==@@word_previous - %{\n

#{@word}

(#{@freq})

\n\t

} - else n=@word.strip.gsub(/\s+/,'_') #also need to convert extended character set to html - %{\n

#{@word}

(#{@freq})

\n\t

} - end - @@word_previous=@word.capitalize - w - end - end - class Words - require_relative 'i18n' # i18n.rb - include SiSU_i18n - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'html_format' # html_format.rb - include SiSU_HTML_Format - require_relative 'sysenv' # sysenv.rb - include SiSU_Screen - @@dp=nil - 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.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - 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.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - @file_concordance.close - end - end - protected - def location_scroll(wordlocation,show) # not used - %{#{wordlocation}; } - end - 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}/ - %{[H]#{show}, } - when /(.+?)\#(\d+)/ - %{#{show}, } - end - end - end - 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 << '

' - alph=@alph[:u] - alph.each {|x| @file_concordance << %{#{x}, }} - @file_concordance << '

' - letter=alph.shift - @file_concordance << %{\n

A

} - 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

#{letter}

} - 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 << '

' - end - # special cases endnotes and header levels 1 - 3 - end - @file_concordance << %{
\n} # 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 - end - end -end -__END__ diff --git a/lib/sisu/v5/html_concordance.rb b/lib/sisu/v5/html_concordance.rb new file mode 100644 index 00000000..b9030123 --- /dev/null +++ b/lib/sisu/v5/html_concordance.rb @@ -0,0 +1,382 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * Author: Ralph Amissah + + * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah, + All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: concordance file (html concordance, wordmap, linked index of + words in document) + +=end +module SiSU_Concordance + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'html_format' # html_format.rb + include SiSU_HTML_Format + require_relative 'html_minitoc' # html_minitoc.rb + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @env,@md=@particulars.env,@particulars.md + @env.url.output_tell + unless @md.opt.act[:quiet][:set]==:on + tool=(@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) \ + ? "#{@env.program.web_browser} #{@md.file.output_path.html_concordance.dir}/#{@md.file.base_filename.html_concordance}" + : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Concordance",tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Concordance',tool).green_title_hi + end + wordmax=@env.concord_max + unless @md.wc_words.nil? + if @md.wc_words < wordmax + SiSU_Concordance::Source::Words.new(@particulars).songsheet + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"concordance skipped, large document has over #{wordmax} words (#{@md.wc_words})").warn unless @md.opt.act[:quiet][:set]==:on + end + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"wc (word count) is off, concordance will be processed for all files including those over the max set size of: #{wordmax} words").warn unless @md.opt.act[:quiet][:set]==:on + SiSU_Concordance::Source::Words.new(@particulars).songsheet + end + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + SiSU_Env::CreateSite.new(@opt.cmd).cp_css + end + end + private + class DocTitle + include SiSU_Viz + #revisit, both requires (html & xml_shared) needed for stand alone operation (sisu -w [filename]) + require_relative 'xml_shared' # xml_shared.rb + require_relative 'html' # html.rb + def initialize(particulars) + @particulars,@md=particulars,particulars.md + @data=SiSU_HTML::Source::HTML_Environment.new(particulars).tuned_file_instructions + @file=SiSU_Env::FileOp.new(@md) + @fnb=@md.fnb + @lex_button=%{SiSU home -->} + @doc_details =< 

#{@md.title.full}

#{@md.author}

+WOK + @make=SiSU_Env::ProcessingSettings.new(@md) + end + def create + head_banner=SiSU_HTML_Format::HeadToc.new(@md) + minitoc=SiSU_HTML_MiniToc::TocMini.new(@md,@data).songsheet.join("\n") + stylesheet=SiSU_Style::CSS_HeadInfo.new(@md).stylesheet + if @make.build.manifest_minitoc? + toc='
' + minitoc + '
' + div_class='content' + else + toc='' + div_class='content0' + end + top_band=if @make.build.html_top_band? + head_banner.concordance_navigation_band + else '' + end + < + + + + SiSU created WordIndex for: #{@md.title.full} + + + + + + + + #{stylesheet.css_head_seg} + + + #{top_band} + #{toc} +
+ #{@doc_details} +

Word index links are to html versions of the text the segmented version followed by the scroll (single document) version.
[For segmented text references [T1], [T2] or [T3] appearing without a link, indicates that the word appears in a title (or subtitle) of the text (that is identifiable by the appended object citation number).]

+

(The word listing/index is Case sensitive: Capitalized words appear before lower case)

+

+ word (number of occurences)
linked references to word within document
+ [if number of occurences exceed number of references - word occurs more than once in at least one reference. Footnote/endnotes are either assigned to the paragraph from which they are referenced or ignored, so it is relevant to check the footnotes referenced from within a paragraph as well.] +

+

+ (After the page is fully loaded) you can jump directly to a word by appending a hash (#) and the word to the url for this text, (do not forget that words are case sensitive, and may be listed twice (starting with and without an upper case letter)), #your_word # [ http://[web host]/#{@fnb}/concordance.html#your_word ] +

+WOK + end + end + class Word + @@word_previous='' + def initialize(word,freq) + @word,@freq=word,freq + end + def html + w=if @word.capitalize==@@word_previous + %{\n

#{@word}

(#{@freq})

\n\t

} + else n=@word.strip.gsub(/\s+/,'_') #also need to convert extended character set to html + %{\n

#{@word}

(#{@freq})

\n\t

} + end + @@word_previous=@word.capitalize + w + end + end + class Words + require_relative 'i18n' # i18n.rb + include SiSU_i18n + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'html_format' # html_format.rb + include SiSU_HTML_Format + require_relative 'sysenv' # sysenv.rb + include SiSU_Screen + @@dp=nil + 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.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + 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.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + @file_concordance.close + end + end + protected + def location_scroll(wordlocation,show) # not used + %{#{wordlocation}; } + end + 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}/ + %{[H]#{show}, } + when /(.+?)\#(\d+)/ + %{#{show}, } + end + end + end + 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 << '

' + alph=@alph[:u] + alph.each {|x| @file_concordance << %{#{x}, }} + @file_concordance << '

' + letter=alph.shift + @file_concordance << %{\n

A

} + 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

#{letter}

} + 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 << '

' + end + # special cases endnotes and header levels 1 - 3 + end + @file_concordance << %{
\n} # 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 + end + end +end +__END__ diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 152de391..f57274ad 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -307,7 +307,7 @@ module SiSU $process_document = :ok unless @opt.act[:po4a][:set]==:on # --po4a, -P if @opt.fno =~ /\.ssm$/ - require_relative 'composite' # composite.rb #pre-processing + require_relative 'ao_composite' # ao_composite.rb #pre-processing SiSU_Assemble::Composite.new(@opt).read end require_relative 'ao' # -m ao.rb @@ -357,7 +357,7 @@ module SiSU end end if @opt.act[:concordance][:set]==:on #% --concordance, -w - require_relative 'concordance' # concordance.rb + require_relative 'html_concordance' # html_concordance.rb SiSU_Concordance::Source.new(@opt).read end if @opt.act[:epub][:set]==:on #% --epub, -e diff --git a/lib/sisu/v5/po4a.rb b/lib/sisu/v5/po4a.rb index 990600aa..0b11600a 100644 --- a/lib/sisu/v5/po4a.rb +++ b/lib/sisu/v5/po4a.rb @@ -65,7 +65,7 @@ module SiSU_Po4a require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'composite' # composite.rb + require_relative 'ao_composite' # ao_composite.rb require_relative 'shared_metadata' # shared_metadata.rb require_relative 'po4a_set' # po4a_set.rb include SiSU_Param diff --git a/lib/sisu/v5/remote.rb b/lib/sisu/v5/remote.rb index e06e7b33..191b2edc 100644 --- a/lib/sisu/v5/remote.rb +++ b/lib/sisu/v5/remote.rb @@ -118,7 +118,7 @@ module SiSU_Remote rescue LoadError SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).error('open-uri or pp NOT FOUND (LoadError)') end - require_relative 'composite' # composite.rb + require_relative 'ao_composite' # ao_composite.rb @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ threads=[] for requested_page in @get_s diff --git a/lib/sisu/v6/ao_composite.rb b/lib/sisu/v6/ao_composite.rb new file mode 100644 index 00000000..f8c4b396 --- /dev/null +++ b/lib/sisu/v6/ao_composite.rb @@ -0,0 +1,267 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * Author: Ralph Amissah + + * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah, + All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: composite documents, assemble/build documents from other + documents or parts of marked up text + +=end +module SiSU_Assemble + require_relative 'sysenv' # sysenv.rb + class RemoteImage + def initialize + @env=SiSU_Env::InfoEnv.new + end + def image(dir) + images=[] + images[0]=dir + images + end + def download_images(images_info) + path="#{@env.processing_path.processing}/external_document/image" + FileUtils::mkdir_p(path) unless FileTest.directory?(path) + download_from=images_info.shift + images_info.each do |i| + image="#{path}/#{i}" + imagefile=File.new(image,'w+') + open("#{download_from}/#{i}") do |g| + imagefile << g.read + end + imagefile.close + end + output_path="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external" + FileUtils::mkdir_p(output_path) unless FileTest.directory?(output_path) + SiSU_Env::SystemCall.new("#{path}/*",output_path,'q').rsync + end + end + class Composite + @@imager={} + def initialize(opt) + @opt=opt + @env=SiSU_Env::InfoEnv.new + end + def read + begin + pwd=Dir.pwd + Dir.chdir(@opt.f_pth[:pth]) + @fns_array=IO.readlines(@opt.fno,'') + assembled=insertions? + write(assembled) + Dir.chdir(pwd) + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + def write(assembled) + assembled_file=File.new("#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst",'w+') + assembled.each {|a| assembled_file << a } + assembled_file.close + end + def download_images(download_from,images_array) + path="#{@env.processing_path.processing}/external_document/image" + FileUtils::mkdir_p(path) unless FileTest.directory?(path) + images_array.each do |i| + image="#{path}/#{i}" + unless FileTest.exists?(image) + imagefile=File.new(image,'w+') + open("#{download_from}/#{i}") do |g| + imagefile << g.read + end + imagefile.close + end + end + end + def insertion(fni,insert_array) + file={ prepared: [], images: [] } + rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ + file[:prepared] << "\n% |#{fni}|@|^|>>ok\n\n" + @code_flag=false + insert_array.each do |i| + @code_flag=if i =~/^code\{/ then true + elsif i =~/^\}code/ then false + else @code_flag + end + if not @code_flag \ + and i !~/^%+\s/ + i=i.gsub(/^([123]|:?[ABCD])~\? /,'% [conditional heading:] \1~ ') #off conditional heading (consider syntax) + if i =~/^@\S+?:/ + i=i.gsub(/\n/m,"\n% "). + gsub(/\n%\s+$/m,''). + gsub(/^@\S+?:/m,"\n% [imported header:] ") #off imported headers + end + end + file[:prepared] << i + if i !~/^%+\s/ \ + and i =~rgx_image + file[:images] << i.scan(rgx_image).uniq + end + end + file[:prepared] << "\n% end import" << "\n\n" + if file[:images].length > 0 + file[:images]=file[:images].flatten.uniq + file[:images].delete_if {|x| x =~/https?:\/\// } + end + file + end + def insertions? + data=@fns_array + tuned_file,imagedir=[],[] + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Composite Document',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").grey_title_hi unless @opt.act[:quiet][:set]==:on + data.each do |para| + if para =~/^<<\s+(\S+?\.ss[it])$/ + loadfile=$1.strip + src_ssm=@opt.fns.sub(/\.ssm\.sst/,'.ssm') + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'loading:',loadfile).txt_grey + end + tuned_file << if loadfile =~ /(?:https?|file):\/\/\S+?\.ss[ti]$/ # and NetTest + imagedir = /((?:https?|file):\/\/\S+?)\/[^\/]+?\.ss[ti]$/.match(loadfile).captures.join + '/_sisu/image' #watch + begin + require 'uri' + require 'open-uri' + require 'pp' + rescue LoadError + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).error('uri, open-uri or pp NOT FOUND (LoadError)') + end + image_uri=URI.parse(imagedir) + insert=open(loadfile) + insert_array=insert.dup + insert.close + file=insertion(loadfile,insert_array) + @@imager[image_uri] ||=[] + @@imager[image_uri] << file[:images] + file[:prepared] + elsif loadfile =~ /\.ss[ti]$/ \ + and FileTest.file?(loadfile) + insert_array=IO.readlines(loadfile,'') + file=insertion(loadfile,insert_array) + file[:prepared] + else + cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX + STDERR.puts %{SKIPPED processing file: [#{@opt.lng}] "#{@opt.fns}" it requires an invalid or non-existent file: "#{loadfile}"} + $process_document = :skip; break #remove this line to continue processing documents that have missing include files + para + end + else tuned_file << para + end + tuned_file=tuned_file.flatten.compact + end + if @@imager.length >0 + @@imager.each do |d,i| + i=i.flatten.uniq + image_info=d + i + download_images(image_info.flatten) + end + end + tuned_file + end + end + class CompositeFileList + @@imager={} + def initialize(opt) + @opt=opt + @env=SiSU_Env::InfoEnv.new + end + def read + begin + @opt.fns=@opt.fns.gsub(/\.ssm\.sst$/,'.ssm') #FIX earlier, hub + @fns_array=IO.readlines(@opt.fns,'') + insertions? + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + def insertions? + data=@fns_array + tuned_file=[] + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Composite Document',@opt.fno).grey_title_hi unless @opt.act[:quiet][:set]==:on + @ssm=[@opt.fns] + data.each do |para| + if para =~/^<<\s+(\S+?\.ss[it])$/ + loadfile=$1.strip + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'loading:',loadfile).txt_grey + end + tuned_file << if loadfile =~ /(?:https?|file):\/\/\S+?\.ss[ti]$/ + @ssm << loadfile + elsif loadfile =~ /\.ss[ti]$/ \ + and FileTest.file?(loadfile) + @ssm << loadfile + else + cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX + STDERR.puts %{SKIPPED processing file: [#{@opt.lng}] "#{@opt.fns}" it requires an invalid or non-existent file: "#{loadfile}"} + $process_document = :skip; break #remove this line to continue processing documents that have missing include files + para + end + end + end + @ssm + end + end +end +__END__ diff --git a/lib/sisu/v6/composite.rb b/lib/sisu/v6/composite.rb deleted file mode 100644 index 2afff1bf..00000000 --- a/lib/sisu/v6/composite.rb +++ /dev/null @@ -1,267 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * Author: Ralph Amissah - - * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah, - All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) Ralph Amissah - - This program is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - this program. If not, see . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: composite documents, assemble/build documents from other - documents or parts of marked up text - -=end -module SiSU_Assemble - require_relative 'sysenv' # sysenv.rb - class RemoteImage - def initialize - @env=SiSU_Env::InfoEnv.new - end - def image(dir) - images=[] - images[0]=dir - images - end - def download_images(images_info) - path="#{@env.processing_path.processing}/external_document/image" - FileUtils::mkdir_p(path) unless FileTest.directory?(path) - download_from=images_info.shift - images_info.each do |i| - image="#{path}/#{i}" - imagefile=File.new(image,'w+') - open("#{download_from}/#{i}") do |g| - imagefile << g.read - end - imagefile.close - end - output_path="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external" - FileUtils::mkdir_p(output_path) unless FileTest.directory?(output_path) - SiSU_Env::SystemCall.new("#{path}/*",output_path,'q').rsync - end - end - class Composite - @@imager={} - def initialize(opt) - @opt=opt - @env=SiSU_Env::InfoEnv.new - end - def read - begin - pwd=Dir.pwd - Dir.chdir(@opt.f_pth[:pth]) - @fns_array=IO.readlines(@opt.fno,'') - assembled=insertions? - write(assembled) - Dir.chdir(pwd) - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - def write(assembled) - assembled_file=File.new("#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst",'w+') - assembled.each {|a| assembled_file << a } - assembled_file.close - end - def download_images(download_from,images_array) - path="#{@env.processing_path.processing}/external_document/image" - FileUtils::mkdir_p(path) unless FileTest.directory?(path) - images_array.each do |i| - image="#{path}/#{i}" - unless FileTest.exists?(image) - imagefile=File.new(image,'w+') - open("#{download_from}/#{i}") do |g| - imagefile << g.read - end - imagefile.close - end - end - end - def insertion(fni,insert_array) - file={ prepared: [], images: [] } - rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ - file[:prepared] << "\n% |#{fni}|@|^|>>ok\n\n" - @code_flag=false - insert_array.each do |i| - @code_flag=if i =~/^code\{/ then true - elsif i =~/^\}code/ then false - else @code_flag - end - if not @code_flag \ - and i !~/^%+\s/ - i=i.gsub(/^([123]|:?[ABCD])~\? /,'% [conditional heading:] \1~ ') #off conditional heading (consider syntax) - if i =~/^@\S+?:/ - i=i.gsub(/\n/m,"\n% "). - gsub(/\n%\s+$/m,''). - gsub(/^@\S+?:/m,"\n% [imported header:] ") #off imported headers - end - end - file[:prepared] << i - if i !~/^%+\s/ \ - and i =~rgx_image - file[:images] << i.scan(rgx_image).uniq - end - end - file[:prepared] << "\n% end import" << "\n\n" - if file[:images].length > 0 - file[:images]=file[:images].flatten.uniq - file[:images].delete_if {|x| x =~/https?:\/\// } - end - file - end - def insertions? - data=@fns_array - tuned_file,imagedir=[],[] - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Composite Document',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").grey_title_hi unless @opt.act[:quiet][:set]==:on - data.each do |para| - if para =~/^<<\s+(\S+?\.ss[it])$/ - loadfile=$1.strip - src_ssm=@opt.fns.sub(/\.ssm\.sst/,'.ssm') - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'loading:',loadfile).txt_grey - end - tuned_file << if loadfile =~ /(?:https?|file):\/\/\S+?\.ss[ti]$/ # and NetTest - imagedir = /((?:https?|file):\/\/\S+?)\/[^\/]+?\.ss[ti]$/.match(loadfile).captures.join + '/_sisu/image' #watch - begin - require 'uri' - require 'open-uri' - require 'pp' - rescue LoadError - SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).error('uri, open-uri or pp NOT FOUND (LoadError)') - end - image_uri=URI.parse(imagedir) - insert=open(loadfile) - insert_array=insert.dup - insert.close - file=insertion(loadfile,insert_array) - @@imager[image_uri] ||=[] - @@imager[image_uri] << file[:images] - file[:prepared] - elsif loadfile =~ /\.ss[ti]$/ \ - and FileTest.file?(loadfile) - insert_array=IO.readlines(loadfile,'') - file=insertion(loadfile,insert_array) - file[:prepared] - else - cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX - STDERR.puts %{SKIPPED processing file: [#{@opt.lng}] "#{@opt.fns}" it requires an invalid or non-existent file: "#{loadfile}"} - $process_document = :skip; break #remove this line to continue processing documents that have missing include files - para - end - else tuned_file << para - end - tuned_file=tuned_file.flatten.compact - end - if @@imager.length >0 - @@imager.each do |d,i| - i=i.flatten.uniq - image_info=d + i - download_images(image_info.flatten) - end - end - tuned_file - end - end - class CompositeFileList - @@imager={} - def initialize(opt) - @opt=opt - @env=SiSU_Env::InfoEnv.new - end - def read - begin - @opt.fns=@opt.fns.gsub(/\.ssm\.sst$/,'.ssm') #FIX earlier, hub - @fns_array=IO.readlines(@opt.fns,'') - insertions? - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - def insertions? - data=@fns_array - tuned_file=[] - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Composite Document',@opt.fno).grey_title_hi unless @opt.act[:quiet][:set]==:on - @ssm=[@opt.fns] - data.each do |para| - if para =~/^<<\s+(\S+?\.ss[it])$/ - loadfile=$1.strip - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'loading:',loadfile).txt_grey - end - tuned_file << if loadfile =~ /(?:https?|file):\/\/\S+?\.ss[ti]$/ - @ssm << loadfile - elsif loadfile =~ /\.ss[ti]$/ \ - and FileTest.file?(loadfile) - @ssm << loadfile - else - cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX - STDERR.puts %{SKIPPED processing file: [#{@opt.lng}] "#{@opt.fns}" it requires an invalid or non-existent file: "#{loadfile}"} - $process_document = :skip; break #remove this line to continue processing documents that have missing include files - para - end - end - end - @ssm - end - end -end -__END__ diff --git a/lib/sisu/v6/concordance.rb b/lib/sisu/v6/concordance.rb deleted file mode 100644 index 5422056f..00000000 --- a/lib/sisu/v6/concordance.rb +++ /dev/null @@ -1,382 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * Author: Ralph Amissah - - * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah, - All Rights Reserved. - - * License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) Ralph Amissah - - This program is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - this program. If not, see . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: concordance file (html concordance, wordmap, linked index of - words in document) - -=end -module SiSU_Concordance - require_relative 'particulars' # particulars.rb - include SiSU_Particulars - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'html_format' # html_format.rb - include SiSU_HTML_Format - require_relative 'html_minitoc' # html_minitoc.rb - class Source - def initialize(opt) - @opt=opt - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - end - def read - begin - @env,@md=@particulars.env,@particulars.md - @env.url.output_tell - unless @md.opt.act[:quiet][:set]==:on - tool=(@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) \ - ? "#{@env.program.web_browser} #{@md.file.output_path.html_concordance.dir}/#{@md.file.base_filename.html_concordance}" - : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" - (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Concordance",tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Concordance',tool).green_title_hi - end - wordmax=@env.concord_max - unless @md.wc_words.nil? - if @md.wc_words < wordmax - SiSU_Concordance::Source::Words.new(@particulars).songsheet - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"concordance skipped, large document has over #{wordmax} words (#{@md.wc_words})").warn unless @md.opt.act[:quiet][:set]==:on - end - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"wc (word count) is off, concordance will be processed for all files including those over the max set size of: #{wordmax} words").warn unless @md.opt.act[:quiet][:set]==:on - SiSU_Concordance::Source::Words.new(@particulars).songsheet - end - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - SiSU_Env::CreateSite.new(@opt.cmd).cp_css - end - end - private - class DocTitle - include SiSU_Viz - #revisit, both requires (html & xml_shared) needed for stand alone operation (sisu -w [filename]) - require_relative 'xml_shared' # xml_shared.rb - require_relative 'html' # html.rb - def initialize(particulars) - @particulars,@md=particulars,particulars.md - @data=SiSU_HTML::Source::HTML_Environment.new(particulars).tuned_file_instructions - @file=SiSU_Env::FileOp.new(@md) - @fnb=@md.fnb - @lex_button=%{SiSU home -->} - @doc_details =< 

#{@md.title.full}

#{@md.author}

-WOK - @make=SiSU_Env::ProcessingSettings.new(@md) - end - def create - head_banner=SiSU_HTML_Format::HeadToc.new(@md) - minitoc=SiSU_HTML_MiniToc::TocMini.new(@md,@data).songsheet.join("\n") - stylesheet=SiSU_Style::CSS_HeadInfo.new(@md).stylesheet - if @make.build.manifest_minitoc? - toc='
' + minitoc + '
' - div_class='content' - else - toc='' - div_class='content0' - end - top_band=if @make.build.html_top_band? - head_banner.concordance_navigation_band - else '' - end - < - - - - SiSU created WordIndex for: #{@md.title.full} - - - - - - - - #{stylesheet.css_head_seg} - - - #{top_band} - #{toc} -
- #{@doc_details} -

Word index links are to html versions of the text the segmented version followed by the scroll (single document) version.
[For segmented text references [T1], [T2] or [T3] appearing without a link, indicates that the word appears in a title (or subtitle) of the text (that is identifiable by the appended object citation number).]

-

(The word listing/index is Case sensitive: Capitalized words appear before lower case)

-

- word (number of occurences)
linked references to word within document
- [if number of occurences exceed number of references - word occurs more than once in at least one reference. Footnote/endnotes are either assigned to the paragraph from which they are referenced or ignored, so it is relevant to check the footnotes referenced from within a paragraph as well.] -

-

- (After the page is fully loaded) you can jump directly to a word by appending a hash (#) and the word to the url for this text, (do not forget that words are case sensitive, and may be listed twice (starting with and without an upper case letter)), #your_word # [ http://[web host]/#{@fnb}/concordance.html#your_word ] -

-WOK - end - end - class Word - @@word_previous='' - def initialize(word,freq) - @word,@freq=word,freq - end - def html - w=if @word.capitalize==@@word_previous - %{\n

#{@word}

(#{@freq})

\n\t

} - else n=@word.strip.gsub(/\s+/,'_') #also need to convert extended character set to html - %{\n

#{@word}

(#{@freq})

\n\t

} - end - @@word_previous=@word.capitalize - w - end - end - class Words - require_relative 'i18n' # i18n.rb - include SiSU_i18n - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'html_format' # html_format.rb - include SiSU_HTML_Format - require_relative 'sysenv' # sysenv.rb - include SiSU_Screen - @@dp=nil - 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.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - 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.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - @file_concordance.close - end - end - protected - def location_scroll(wordlocation,show) # not used - %{#{wordlocation}; } - end - 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}/ - %{[H]#{show}, } - when /(.+?)\#(\d+)/ - %{#{show}, } - end - end - end - 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 << '

' - alph=@alph[:u] - alph.each {|x| @file_concordance << %{#{x}, }} - @file_concordance << '

' - letter=alph.shift - @file_concordance << %{\n

A

} - 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

#{letter}

} - 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 << '

' - end - # special cases endnotes and header levels 1 - 3 - end - @file_concordance << %{
\n} # 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 - end - end -end -__END__ diff --git a/lib/sisu/v6/html_concordance.rb b/lib/sisu/v6/html_concordance.rb new file mode 100644 index 00000000..b94949b9 --- /dev/null +++ b/lib/sisu/v6/html_concordance.rb @@ -0,0 +1,382 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * Author: Ralph Amissah + + * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah, + All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: concordance file (html concordance, wordmap, linked index of + words in document) + +=end +module SiSU_Concordance + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'html_format' # html_format.rb + include SiSU_HTML_Format + require_relative 'html_minitoc' # html_minitoc.rb + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @env,@md=@particulars.env,@particulars.md + @env.url.output_tell + unless @md.opt.act[:quiet][:set]==:on + tool=(@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) \ + ? "#{@env.program.web_browser} #{@md.file.output_path.html_concordance.dir}/#{@md.file.base_filename.html_concordance}" + : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Concordance",tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Concordance',tool).green_title_hi + end + wordmax=@env.concord_max + unless @md.wc_words.nil? + if @md.wc_words < wordmax + SiSU_Concordance::Source::Words.new(@particulars).songsheet + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"concordance skipped, large document has over #{wordmax} words (#{@md.wc_words})").warn unless @md.opt.act[:quiet][:set]==:on + end + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"wc (word count) is off, concordance will be processed for all files including those over the max set size of: #{wordmax} words").warn unless @md.opt.act[:quiet][:set]==:on + SiSU_Concordance::Source::Words.new(@particulars).songsheet + end + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + SiSU_Env::CreateSite.new(@opt.cmd).cp_css + end + end + private + class DocTitle + include SiSU_Viz + #revisit, both requires (html & xml_shared) needed for stand alone operation (sisu -w [filename]) + require_relative 'xml_shared' # xml_shared.rb + require_relative 'html' # html.rb + def initialize(particulars) + @particulars,@md=particulars,particulars.md + @data=SiSU_HTML::Source::HTML_Environment.new(particulars).tuned_file_instructions + @file=SiSU_Env::FileOp.new(@md) + @fnb=@md.fnb + @lex_button=%{SiSU home -->} + @doc_details =< 

#{@md.title.full}

#{@md.author}

+WOK + @make=SiSU_Env::ProcessingSettings.new(@md) + end + def create + head_banner=SiSU_HTML_Format::HeadToc.new(@md) + minitoc=SiSU_HTML_MiniToc::TocMini.new(@md,@data).songsheet.join("\n") + stylesheet=SiSU_Style::CSS_HeadInfo.new(@md).stylesheet + if @make.build.manifest_minitoc? + toc='
' + minitoc + '
' + div_class='content' + else + toc='' + div_class='content0' + end + top_band=if @make.build.html_top_band? + head_banner.concordance_navigation_band + else '' + end + < + + + + SiSU created WordIndex for: #{@md.title.full} + + + + + + + + #{stylesheet.css_head_seg} + + + #{top_band} + #{toc} +
+ #{@doc_details} +

Word index links are to html versions of the text the segmented version followed by the scroll (single document) version.
[For segmented text references [T1], [T2] or [T3] appearing without a link, indicates that the word appears in a title (or subtitle) of the text (that is identifiable by the appended object citation number).]

+

(The word listing/index is Case sensitive: Capitalized words appear before lower case)

+

+ word (number of occurences)
linked references to word within document
+ [if number of occurences exceed number of references - word occurs more than once in at least one reference. Footnote/endnotes are either assigned to the paragraph from which they are referenced or ignored, so it is relevant to check the footnotes referenced from within a paragraph as well.] +

+

+ (After the page is fully loaded) you can jump directly to a word by appending a hash (#) and the word to the url for this text, (do not forget that words are case sensitive, and may be listed twice (starting with and without an upper case letter)), #your_word # [ http://[web host]/#{@fnb}/concordance.html#your_word ] +

+WOK + end + end + class Word + @@word_previous='' + def initialize(word,freq) + @word,@freq=word,freq + end + def html + w=if @word.capitalize==@@word_previous + %{\n

#{@word}

(#{@freq})

\n\t

} + else n=@word.strip.gsub(/\s+/,'_') #also need to convert extended character set to html + %{\n

#{@word}

(#{@freq})

\n\t

} + end + @@word_previous=@word.capitalize + w + end + end + class Words + require_relative 'i18n' # i18n.rb + include SiSU_i18n + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'html_format' # html_format.rb + include SiSU_HTML_Format + require_relative 'sysenv' # sysenv.rb + include SiSU_Screen + @@dp=nil + 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.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + 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.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + @file_concordance.close + end + end + protected + def location_scroll(wordlocation,show) # not used + %{#{wordlocation}; } + end + 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}/ + %{[H]#{show}, } + when /(.+?)\#(\d+)/ + %{#{show}, } + end + end + end + 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 << '

' + alph=@alph[:u] + alph.each {|x| @file_concordance << %{#{x}, }} + @file_concordance << '

' + letter=alph.shift + @file_concordance << %{\n

A

} + 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

#{letter}

} + 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 << '

' + end + # special cases endnotes and header levels 1 - 3 + end + @file_concordance << %{
\n} # 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 + end + end +end +__END__ diff --git a/lib/sisu/v6/hub.rb b/lib/sisu/v6/hub.rb index 736fa8bc..bfe0cbe2 100644 --- a/lib/sisu/v6/hub.rb +++ b/lib/sisu/v6/hub.rb @@ -307,7 +307,7 @@ module SiSU $process_document = :ok unless @opt.act[:po4a][:set]==:on # --po4a, -P if @opt.fno =~ /\.ssm$/ - require_relative 'composite' # composite.rb #pre-processing + require_relative 'ao_composite' # ao_composite.rb #pre-processing SiSU_Assemble::Composite.new(@opt).read end require_relative 'ao' # -m ao.rb @@ -357,7 +357,7 @@ module SiSU end end if @opt.act[:concordance][:set]==:on #% --concordance, -w - require_relative 'concordance' # concordance.rb + require_relative 'html_concordance' # html_concordance.rb SiSU_Concordance::Source.new(@opt).read end if @opt.act[:epub][:set]==:on #% --epub, -e diff --git a/lib/sisu/v6/po4a.rb b/lib/sisu/v6/po4a.rb index 3f890cec..66c68fce 100644 --- a/lib/sisu/v6/po4a.rb +++ b/lib/sisu/v6/po4a.rb @@ -65,7 +65,7 @@ module SiSU_Po4a require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'composite' # composite.rb + require_relative 'ao_composite' # ao_composite.rb require_relative 'shared_metadata' # shared_metadata.rb require_relative 'po4a_set' # po4a_set.rb include SiSU_Param diff --git a/lib/sisu/v6/remote.rb b/lib/sisu/v6/remote.rb index ed5d7fba..37ff723f 100644 --- a/lib/sisu/v6/remote.rb +++ b/lib/sisu/v6/remote.rb @@ -118,7 +118,7 @@ module SiSU_Remote rescue LoadError SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).error('open-uri or pp NOT FOUND (LoadError)') end - require_relative 'composite' # composite.rb + require_relative 'ao_composite' # ao_composite.rb @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ threads=[] for requested_page in @get_s -- cgit v1.2.3