From 96049bf591123333b8a17780544a7951146ef03b Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 26 Oct 2007 22:41:42 +0100 Subject: db rearranging, create, drop, import (and a renaming: db_dbi from shared_db) --- lib/sisu/v0/db_import.rb | 384 +++++++++++++++++++++++++---------------------- 1 file changed, 206 insertions(+), 178 deletions(-) (limited to 'lib/sisu/v0/db_import.rb') diff --git a/lib/sisu/v0/db_import.rb b/lib/sisu/v0/db_import.rb index 404d9437..631c3209 100644 --- a/lib/sisu/v0/db_import.rb +++ b/lib/sisu/v0/db_import.rb @@ -95,7 +95,7 @@ module SiSU_DB_import def marshal_load require "#{SiSU_lib}/dal" @dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here - tell=SiSU_Screen::Ansi.new(@opt.cmd,"#{@db.db_psql}::#{@opt.fns}") + tell=SiSU_Screen::Ansi.new(@opt.cmd,"#{@db.psql.db}::#{@opt.fns}") tell.puts_blue unless @opt.cmd =~/q/ tell=SiSU_Screen::Ansi.new(@opt.cmd,'Marshal Load',@fnm) tell.print_grey if @opt.cmd =~/v/ @@ -115,7 +115,7 @@ module SiSU_DB_import @conn.execute('COMMIT') else @db=SiSU_Env::Info_db.new - puts "\n#{@cX.grey}file #{@cX.off} #{@cX.blue}#{@opt.fns}#{@cX.off} #{@cX.grey}already exists in database#{@cX.off} #{@cX.blue}#{@db.db_psql}#{@cX.off} #{@cX.brown}update instead?#{@cX.off}" + puts "\n#{@cX.grey}file #{@cX.off} #{@cX.blue}#{@opt.fns}#{@cX.off} #{@cX.grey}already exists in database#{@cX.off} #{@cX.blue}#{@db.psql.db}#{@cX.off} #{@cX.brown}update instead?#{@cX.off}" end end end @@ -127,9 +127,6 @@ module SiSU_DB_import string.gsub!(/\{\s*(\S+?\.(?:png|jpg))(?:\s+\d+x\d+)?(.+?)\}\S+/,'[image: \1] \2') string.gsub!(/\{\s*(.+?)\s*\}(?:https?|file|ftp):\/\/\S+?([.,!?]?(?:\s|$))/,'\1\2') end - def unicode_special_character_escape(string) - #string.gsub!(/(["';:,])/, %{\\\\\\1}) - end def strip_markup(string) #define rules, make same as in dal clean string.gsub!(/(\d+)<\/sup>/,'[\1]') string.gsub!(/<:i[12]>/,'') @@ -151,7 +148,7 @@ module SiSU_DB_import if @md.title; @tp[:title]=@md.title special_character_escape(@tp[:title]) @tp[:title_f],@tp[:title_i]='title, ',"'#{@tp[:title]}', " - sql="SELECT MAX(tid) FROM metadata" + sql='SELECT MAX(tid) FROM metadata' id_t=@conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } @@id_t=id_t if id_t @@id_t ||=0 @@ -159,191 +156,190 @@ module SiSU_DB_import puts %{\n#{@cX.grey}Processing file number#{@cX.off}: #{@cX.green}#{@@id_t}#{@@cX.off}} unless @opt.cmd =~/q/ end if @md.dc_title; @tp[:long_title]=@md.dc_title - #sql="SELECT MAX(tid) FROM metadata" + #sql='SELECT MAX(tid) FROM metadata' #id_t=@conn.execute( sql ) { |x| x.fetch_all.to_s.to_i } #@@id_t=id_t if id_t #@@id_t ||=0 #@@id_t+=1 #bug related, needs to be performed once at start of file, but consider moving, as, placed here it means program will fail if document header lacks 0~title #puts %{\n#{@cX.grey}Processing file number#{@cX.off}: #{@cX.green}#{@@id_t}#{@@cX.off}} end - if @md.subtitle; @tp[:subtitle]=@md.subtitle - special_character_escape(@tp[:subtitle]) - @tp[:subtitle_f],@tp[:subtitle_i]='subtitle, ',"'#{@tp[:subtitle]}', " + if @md.subtitle; txt=@md.subtitle + special_character_escape(txt) + @tp[:subtitle_f],@tp[:subtitle_i]='subtitle, ',"'#{txt}', " end - if @md.dc_creator; @tp[:creator]=@md.dc_creator - special_character_escape(@tp[:creator]) - @tp[:creator_f],@tp[:creator_i]='creator, ',"'#{@tp[:creator]}', " + if @md.dc_creator; txt=@md.dc_creator + special_character_escape(txt) + @tp[:creator_f],@tp[:creator_i]='creator, ',"'#{txt}', " end - if @md.dc_contributor; @tp[:contributor]=@md.dc_contributor - special_character_escape(@tp[:contributor]) - @tp[:contributor_f],@tp[:contributor_i]='contributor, ',"'#{@tp[:contributor]}', " + if @md.dc_contributor; txt=@md.dc_contributor + special_character_escape(txt) + @tp[:contributor_f],@tp[:contributor_i]='contributor, ',"'#{txt}', " end - if @md.translator; @tp[:translator]=@md.translator - special_character_escape(@tp[:translator]) - @tp[:translator_f],@tp[:translator_i]='translator, ',"'#{@tp[:translator]}', " + if @md.translator; txt=@md.translator + special_character_escape(txt) + @tp[:translator_f],@tp[:translator_i]='translator, ',"'#{txt}', " end - if @md.illustrator; @tp[:illustrator]=@md.illustrator - special_character_escape(@tp[:illustrator]) - @tp[:illustrator_f],@tp[:illustrator_i]='illustrator, ',"'#{@tp[:illustrator]}', " + if @md.illustrator; txt=@md.illustrator + special_character_escape(txt) + @tp[:illustrator_f],@tp[:illustrator_i]='illustrator, ',"'#{txt}', " end - if @md.dc_publisher; @tp[:publisher]=@md.dc_publisher - special_character_escape(@tp[:publisher]) - @tp[:publisher_f],@tp[:publisher_i]='publisher, ',"'#{@tp[:publisher]}', " + if @md.dc_publisher; txt=@md.dc_publisher + special_character_escape(txt) + @tp[:publisher_f],@tp[:publisher_i]='publisher, ',"'#{txt}', " end - if @md.prepared_by; @tp[:prepared_by]=@md.prepared_by - special_character_escape(@tp[:prepared_by]) - @tp[:prepared_by_f],@tp[:prepared_by_i]='prepared_by, ',"'#{@tp[:prepared_by]}', " + if @md.prepared_by; txt=@md.prepared_by + special_character_escape(txt) + @tp[:prepared_by_f],@tp[:prepared_by_i]='prepared_by, ',"'#{txt}', " end - if @md.digitized_by; @tp[:digitized_by]=@md.digitized_by - special_character_escape(@tp[:digitized_by]) - @tp[:digitized_by_f],@tp[:digitized_by_i]='digitized_by, ',"'#{@tp[:digitized_by]}', " + if @md.digitized_by; txt=@md.digitized_by + special_character_escape(txt) + @tp[:digitized_by_f],@tp[:digitized_by_i]='digitized_by, ',"'#{txt}', " end - if @md.dc_subject; @tp[:subject]=@md.dc_subject - special_character_escape(@tp[:subject]) - @tp[:subject_f],@tp[:subject_i]='subject, ',"'#{@tp[:subject]}', " + if @md.dc_subject; txt=@md.dc_subject + special_character_escape(txt) + @tp[:subject_f],@tp[:subject_i]='subject, ',"'#{txt}', " end - if @md.dc_description; @tp[:description]=@md.dc_description - special_character_escape(@tp[:description]) - @tp[:description_f],@tp[:description_i]='description, ',"'#{@tp[:description]}', " + if @md.dc_description; txt=@md.dc_description + special_character_escape(txt) + @tp[:description_f],@tp[:description_i]='description, ',"'#{txt}', " end - if @md.abstract; @tp[:abstract]=@md.abstract - special_character_escape(@tp[:abstract]) - @tp[:abstract_f],@tp[:abstract_i]='abstract, ',"'#{@tp[:abstract]}', " + if @md.abstract; txt=@md.abstract + special_character_escape(txt) + @tp[:abstract_f],@tp[:abstract_i]='abstract, ',"'#{txt}', " end - if @md.dc_type; @tp[:type]=@md.dc_type - special_character_escape(@tp[:type]) - @tp[:type_f],@tp[:type_i]='type, ',"'#{@tp[:type]}', " + if @md.dc_type; txt=@md.dc_type + special_character_escape(txt) + @tp[:type_f],@tp[:type_i]='type, ',"'#{txt}', " end - #if @md.owner; @tp[:owner]=@md.owner - # special_character_escape(@tp[:owner]) - # @tp[:owner_f],@tp[:owner_i]='owner, ',"'#{@tp[:owner}', " + #if @md.owner; txt=@md.owner + # special_character_escape(txt) + # @tp[:owner_f],@tp[:owner_i]='owner, ',"'#{txt}', " #end - #if @md.copyright; @tp[:copyright]=@md.copyright - # special_character_escape(@tp[:copyright]) - # @tp[:copyright_f],@tp[:copyright_i]='copyright, ',"'#{@tp[:copyright]}', " + #if @md.copyright; txt=@md.copyright + # special_character_escape(txt) + # @tp[:copyright_f],@tp[:copyright_i]='copyright, ',"'#{txt}', " #end - if @md.dc_rights; @tp[:rights]=@md.dc_rights - special_character_escape(@tp[:rights]) - @tp[:rights_f],@tp[:rights_i]='rights, ',"'#{@tp[:rights]}', " + if @md.dc_rights; txt=@md.dc_rights + special_character_escape(txt) + @tp[:rights_f],@tp[:rights_i]='rights, ',"'#{txt}', " end - if @md.dc_date; @tp[:date]=@md.dc_date - special_character_escape(@tp[:date]) - @tp[:date_f],@tp[:date_i]='date, ',"'#{@tp[:date]}', " + if @md.dc_date; txt=@md.dc_date + special_character_escape(txt) + @tp[:date_f],@tp[:date_i]='date, ',"'#{txt}', " end - if @md.dc_date_created; @tp[:date_created]=@md.dc_date_created - special_character_escape(@tp[:date_created]) - @tp[:date_created_f],@tp[:date_created_i]='date_created, ',"'#{@tp[:date_created]}', " + if @md.dc_date_created; txt=@md.dc_date_created + special_character_escape(txt) + @tp[:date_created_f],@tp[:date_created_i]='date_created, ',"'#{txt}', " end - if @md.dc_date_issued; @tp[:date_issued]=@md.dc_date_issued - special_character_escape(@tp[:date_issued]) - @tp[:date_issued_f],@tp[:date_issued_i]='date_issued, ',"'#{@tp[:date_issued]}', " + if @md.dc_date_issued; txt=@md.dc_date_issued + special_character_escape(txt) + @tp[:date_issued_f],@tp[:date_issued_i]='date_issued, ',"'#{txt}', " end - if @md.dc_date_available; @tp[:date_available]=@md.dc_date_available - special_character_escape(@tp[:date_available]) - @tp[:date_available_f],@tp[:date_available_i]='date_available, ',"'#{@tp[:date_available]}', " + if @md.dc_date_available; txt=@md.dc_date_available + special_character_escape(txt) + @tp[:date_available_f],@tp[:date_available_i]='date_available, ',"'#{txt}', " end - if @md.dc_date_modified; @tp[:date_modified]=@md.dc_date_modified - special_character_escape(@tp[:date_modified]) - @tp[:date_modified_f],@tp[:date_modified_i]='date_modified, ',"'#{@tp[:date_modified]}', " + if @md.dc_date_modified; txt=@md.dc_date_modified + special_character_escape(txt) + @tp[:date_modified_f],@tp[:date_modified_i]='date_modified, ',"'#{txt}', " end - if @md.dc_date_valid; @tp[:date_valid]=@md.dc_date_valid - special_character_escape(@tp[:date_valid]) - @tp[:date_valid_f],@tp[:date_valid_i]='date_valid, ',"'#{@tp[:date_valid]}', " + if @md.dc_date_valid; txt=@md.dc_date_valid + special_character_escape(txt) + @tp[:date_valid_f],@tp[:date_valid_i]='date_valid, ',"'#{txt}', " end - if @md.dc_language[:name]; @tp[:language]=@md.dc_language[:name] - special_character_escape(@tp[:language]) - @tp[:language_f],@tp[:language_i]='language, ',"'#{@tp[:language]}', " + if @md.dc_language[:name]; txt=@md.dc_language[:name] + special_character_escape(txt) + @tp[:language_f],@tp[:language_i]='language, ',"'#{txt}', " end - if @md.language_original[:name]; @tp[:language_original]=@md.language_original[:name] - special_character_escape(@tp[:language_original]) - @tp[:language_original_f],@tp[:language_original_i]='language_original, ',"'#{@tp[:language_original]}', " + if @md.language_original[:name]; txt=@md.language_original[:name] + special_character_escape(txt) + @tp[:language_original_f],@tp[:language_original_i]='language_original, ',"'#{txt}', " end - if @md.dc_format; @tp[:format]=@md.dc_format - special_character_escape(@tp[:format]) - @tp[:format_f],@tp[:format_i]='format, ',"'#{@tp[:format]}', " + if @md.dc_format; txt=@md.dc_format + special_character_escape(txt) + @tp[:format_f],@tp[:format_i]='format, ',"'#{txt}', " end - if @md.dc_identifier; @tp[:identifier]=@md.dc_identifier - special_character_escape(@tp[:identifier]) - @tp[:identifier_f],@tp[:identifier_i]='identifier, ',"'#{@tp[:identifier]}', " + if @md.dc_identifier; txt=@md.dc_identifier + special_character_escape(txt) + @tp[:identifier_f],@tp[:identifier_i]='identifier, ',"'#{txt}', " end - if @md.dc_source; @tp[:source]=@md.dc_source - special_character_escape(@tp[:source]) - @tp[:source_f],@tp[:source_i]='source, ',"'#{@tp[:source]}', " + if @md.dc_source; txt=@md.dc_source + special_character_escape(txt) + @tp[:source_f],@tp[:source_i]='source, ',"'#{txt}', " end - if @md.dc_relation; @tp[:relation]=@md.dc_relation - special_character_escape(@tp[:relation]) - @tp[:relation_f],@tp[:relation_i]='relation, ',"'#{@tp[:relation]}', " + if @md.dc_relation; txt=@md.dc_relation + special_character_escape(txt) + @tp[:relation_f],@tp[:relation_i]='relation, ',"'#{txt}', " end - if @md.dc_coverage; @tp[:coverage]=@md.dc_coverage - special_character_escape(@tp[:coverage]) - @tp[:coverage_f],@tp[:coverage_i]='coverage, ',"'#{@tp[:coverage]}', " + if @md.dc_coverage; txt=@md.dc_coverage + special_character_escape(txt) + @tp[:coverage_f],@tp[:coverage_i]='coverage, ',"'#{txt}', " end - if @md.keywords; @tp[:keywords]=@md.keywords - special_character_escape(@tp[:keywords]) - @tp[:keywords_f],@tp[:keywords_i]='keywords, ',"'#{@tp[:keywords]}', " + if @md.keywords; txt=@md.keywords + special_character_escape(txt) + @tp[:keywords_f],@tp[:keywords_i]='keywords, ',"'#{txt}', " end - if @md.comments; @tp[:comments]=@md.comments - special_character_escape(@tp[:comments]) - @tp[:comments_f],@tp[:comments_i]='comments, ',"'#{@tp[:comments]}', " + if @md.comments; txt=@md.comments + special_character_escape(txt) + @tp[:comments_f],@tp[:comments_i]='comments, ',"'#{txt}', " end - if @md.cls_loc; @tp[:cls_loc]=@md.cls_loc - special_character_escape(@tp[:cls_loc]) - @tp[:cls_loc_f],@tp[:cls_loc_i]='cls_loc, ',"'#{@tp[:cls_loc]}', " + if @md.cls_loc; txt=@md.cls_loc + special_character_escape(txt) + @tp[:cls_loc_f],@tp[:cls_loc_i]='cls_loc, ',"'#{txt}', " end - if @md.cls_dewey; @tp[:cls_dewey]=@md.cls_dewey - special_character_escape(@tp[:cls_dewey]) - @tp[:cls_dewey_f],@tp[:cls_dewey_i]='cls_dewey, ',"'#{@tp[:cls_dewey]}', " + if @md.cls_dewey; txt=@md.cls_dewey + special_character_escape(txt) + @tp[:cls_dewey_f],@tp[:cls_dewey_i]='cls_dewey, ',"'#{txt}', " end - if @md.cls_pg; @tp[:cls_pg]=@md.cls_pg - special_character_escape(@tp[:cls_pg]) - @tp[:cls_pg_f],@tp[:cls_pg_i]='cls_pg, ',"'#{@tp[:cls_pg]}', " + if @md.cls_pg; txt=@md.cls_pg + special_character_escape(txt) + @tp[:cls_pg_f],@tp[:cls_pg_i]='cls_pg, ',"'#{txt}', " end - if @md.cls_isbn; @tp[:cls_isbn]=@md.cls_isbn - special_character_escape(@tp[:cls_isbn]) - @tp[:cls_isbn_f],@tp[:cls_isbn_i]='cls_isbn, ',"'#{@tp[:cls_isbn]}', " + if @md.cls_isbn; txt=@md.cls_isbn + special_character_escape(txt) + @tp[:cls_isbn_f],@tp[:cls_isbn_i]='cls_isbn, ',"'#{txt}', " end - if @md.prefix_a; @tp[:prefix_a]=@md.prefix_a - special_character_escape(@tp[:prefix_a]) - @tp[:prefix_a_f],@tp[:prefix_a_i]='prefix_a, ',"'#{@tp[:prefix_a]}', " + if @md.prefix_a; txt=@md.prefix_a + special_character_escape(txt) + @tp[:prefix_a_f],@tp[:prefix_a_i]='prefix_a, ',"'#{txt}', " end - if @md.prefix_b; @tp[:prefix_b]=@md.prefix_b - special_character_escape(@tp[:prefix_b]) - @tp[:prefix_b_f],@tp[:prefix_b_i]='prefix_b, ',"'#{@tp[:prefix_b]}', " + if @md.prefix_b; txt=@md.prefix_b + special_character_escape(txt) + @tp[:prefix_b_f],@tp[:prefix_b_i]='prefix_b, ',"'#{txt}', " end - #if @md.suffix; @tp[:suffix]=@md.suffix - # special_character_escape(@tp[:suffix]) - # @tp[:suffix_f],@tp[:suffix_i]='suffix, ',"'#{@tp[:suffix]}', " + #if @md.suffix; txt=@md.suffix + # special_character_escape(txt) + # @tp[:suffix_f],@tp[:suffix_i]='suffix, ',"'#{txt}', " #end - if @md.fns; @tp[:fns]=@md.fns - special_character_escape(@tp[:fns]) - @tp[:fns_f],@tp[:fns_i]="filename, ","'#{@tp[:fns]}', " + if @md.fns; txt=@md.fns + special_character_escape(txt) + @tp[:fns_f],@tp[:fns_i]="filename, ","'#{txt}', " end #if @md.en[:mismatch] > 0 # id,info='WARNING document error in endnote markup, number mismatch',"endnotes: #{@md.en[:note]} != endnote reference marks: #{@md.en[:mark]} (difference = #{@md.en[:mismatch]})" #end - if @md.wc_words; @tp[:wc_words]=@md.wc_words - @tp[:wc_words_f],@tp[:wc_words_i]='wc_words, ',"'#{@tp[:wc_words]}', " + if @md.wc_words; txt=@md.wc_words + @tp[:wc_words_f],@tp[:wc_words_i]='wc_words, ',"'#{txt}', " end - if @md.dgst; @tp[:dgst]=@md.dgst - @tp[:dgst_f],@tp[:dgst_i]='dgst, ',"'#{@tp[:dgst]}', " + if @md.dgst; txt=@md.dgst + @tp[:dgst_f],@tp[:dgst_i]='dgst, ',"'#{txt}', " end - if @md.sc_number; @tp[:sc_number]=@md.sc_number - @tp[:sc_number_f],@tp[:sc_number_i]='sc_number, ',"'#{@tp[:sc_number]}', " + if @md.sc_number; txt=@md.sc_number + @tp[:sc_number_f],@tp[:sc_number_i]='sc_number, ',"'#{txt}', " end - if @md.sc_date; @tp[:sc_date]=@md.sc_date - @tp[:sc_date_f],@tp[:sc_date_i]='sc_date, ',"'#{@tp[:sc_date]}', " + if @md.sc_date; txt=@md.sc_date + @tp[:sc_date_f],@tp[:sc_date_i]='sc_date, ',"'#{txt}', " end - if @md.generated; @tp[:generated]=@md.generated - @tp[:generated_f],@tp[:generated_i]='generated, ',"'#{@tp[:generated]}', " + if @md.generated; txt=@md.generated + @tp[:generated_f],@tp[:generated_i]='generated, ',"'#{@txt}', " end #if @md.sisu_version; special_character_escape(@md.sisu_version) # #id,info='Generated by',"#{@md.sisu_version[:project]} #{@md.sisu_version[:version]} #{@md.sisu_version[:date_stamp]} (#{@md.sisu_version[:date]})" #end #if @md.ruby_version; special_character_escape(@md.ruby_version) - SiSU_DB::Test.new(self,@opt).verify #% import title names, filenames (tuple) - @conn.execute(%{ - INSERT INTO metadata (#{@tp[:fns_f]} #{@tp[:suffix_f]} #{@tp[:title_f]} #{@tp[:subtitle_f]} #{@tp[:creator_f]} #{@tp[:illustrator_f]} #{@tp[:translator_f]} #{@tp[:subject_f]} #{@tp[:description_f]} #{@tp[:publisher_f]} #{@tp[:contributor_f]} #{@tp[:prepared_by_f]} #{@tp[:digitized_by_f]} #{@tp[:date_f]} #{@tp[:date_created_f]} #{@tp[:date_issued_f]} #{@tp[:date_valid_f]} #{@tp[:date_available_f]} #{@tp[:date_modified_f]} #{@tp[:type_f]} #{@tp[:format_f]} #{@tp[:identifier_f]} #{@tp[:source_f]} #{@tp[:language_f]} #{@tp[:language_original_f]} #{@tp[:relation_f]} #{@tp[:coverage_f]} #{@tp[:rights_f]} #{@tp[:copyright_f]} #{@tp[:owner_f]} #{@tp[:keywords_f]} #{@tp[:abstract_f]} #{@tp[:comment_f]} #{@tp[:loc_f]} #{@tp[:dewey_f]} #{@tp[:isbn_f]} #{@tp[:pg_f]} #{@tp[:prefix_a_f]} #{@tp[:prefix_b_f]} tid) VALUES (#{@tp[:fns_i]} #{@tp[:suffix_i]} #{@tp[:title_i]} #{@tp[:subtitle_i]} #{@tp[:creator_i]} #{@tp[:illustrator_i]} #{@tp[:translator_i]} #{@tp[:subject_i]} #{@tp[:description_i]} #{@tp[:publisher_i]} #{@tp[:contributor_i]} #{@tp[:prepared_by_i]} #{@tp[:digitized_by_i]} #{@tp[:date_i]} #{@tp[:date_created_i]} #{@tp[:date_issued_i]} #{@tp[:date_valid_i]} #{@tp[:date_available_i]} #{@tp[:date_modified_i]} #{@tp[:type_i]} #{@tp[:format_i]} #{@tp[:identifier_i]} #{@tp[:source_i]} #{@tp[:language_i]} #{@tp[:language_original_i]} #{@tp[:relation_i]} #{@tp[:coverage_i]} #{@tp[:rights_i]} #{@tp[:copyright_i]} #{@tp[:owner_i]} #{@tp[:keywords_i]} #{@tp[:abstract_i]} #{@tp[:comment_i]} #{@tp[:loc_i]} #{@tp[:dewey_i]} #{@tp[:isbn_i]} #{@tp[:pg_i]} #{@tp[:prefix_a_i]} #{@tp[:prefix_b_i]} #{@@id_t}); - }) + SiSU_DB_DBI::Test.new(self,@opt).verify #% import title names, filenames (tuple) + t=SiSU_DB_tuple::Load_metadata.new(@conn,@tp,@@id_t) + t.tuple end def import_documents(dbi_unit) #% import documents - populate main database table #% import into substantive database tables (tuple) @@ -384,7 +380,7 @@ module SiSU_DB_import end if @en_pls[0]; @en_a_plus,@en_z_plus=@en_pls[0].first,@en_pls[0].last end - t=SiSU_DB_tuple::Load_tuple.new(@conn,@col,@opt) + t=SiSU_DB_tuple::Load_documents.new(@conn,@col,@opt) t.tuple case @col[:lev] when /1/; @col[:lv1]+=1 @@ -425,7 +421,7 @@ module SiSU_DB_import end if @en_pls[0]; @en_a_plus,@en_z_plus=@en_pls[0].first,@en_pls[0].last end - t=SiSU_DB_tuple::Load_tuple.new(@conn,@col,@opt) + t=SiSU_DB_tuple::Load_documents.new(@conn,@col,@opt) t.tuple @col[:lev]=@col[:plaintext]=@col[:body]='' elsif data[/^5~(?:~\S+)?(.+?)<~(\d+);((?:\w|[0-6]:)\d+);(\w\d+)><([0-9a-f]{#{@@dl}}):([0-9a-f]{#{@@dl}})>/] # header lev5 seg level @@ -464,7 +460,7 @@ module SiSU_DB_import end if @en_pls[0]; @en_a_plus,@en_z_plus=@en_pls[0].first,@en_pls[0].last end - t=SiSU_DB_tuple::Load_tuple.new(@conn,@col,@opt) + t=SiSU_DB_tuple::Load_documents.new(@conn,@col,@opt) t.tuple @col[:lev]=@col[:plaintext]=@col[:body]='' elsif data[/^6~(?:~\S+)?(.+?)<~(\d+);((?:\w|[0-6]:)\d+);(\w\d+)><([0-9a-f]{#{@@dl}}):([0-9a-f]{#{@@dl}})>/] # header lev6 seg level @@ -503,7 +499,7 @@ module SiSU_DB_import end if @en_pls[0]; @en_a_plus,@en_z_plus=@en_pls[0].first,@en_pls[0].last end - t=SiSU_DB_tuple::Load_tuple.new(@conn,@col,@opt) + t=SiSU_DB_tuple::Load_documents.new(@conn,@col,@opt) t.tuple @col[:lev]=@col[:plaintext]=@col[:body]='' else #% regular text @@ -553,7 +549,7 @@ module SiSU_DB_import special_character_escape(@col[:body]) @col[:plaintext]=@col[:body].dup strip_markup(@col[:plaintext]) - t=SiSU_DB_tuple::Load_tuple.new(@conn,@col,@opt) + t=SiSU_DB_tuple::Load_documents.new(@conn,@col,@opt) t.tuple @en,@en_ast,@en_pls=[],[],[] @col[:en_a]=@col[:en_z]=nil @@ -564,10 +560,10 @@ module SiSU_DB_import endnote_array.each do |inf| if inf[/~\{\d+.+?<[0-9a-f]{#{@@dl}}>\}~/] # dal new endnotes 2003w31/1 if inf[/~\{(\d+)(.+?)<([0-9a-f]{#{@@dl}})>\}~/] # dal new endnotes 2003w31/1 - en,txt,digest_clean=$1,$2,$3 + nr,txt,digest_clean=$1,$2,$3 end @id_n+=1 - body=SiSU_Format_Shared::CSS_Format.new(@md,txt,@col,en).endnote + body=SiSU_Format_Shared::CSS_Format.new(@md,txt,@col,nr).endnote special_character_escape(body) special_character_escape(txt) strip_markup(txt) @@ -579,10 +575,21 @@ module SiSU_DB_import txt=%{\n\nLARGE TEXT BLOCK OMITTED\n\n} end if txt - #puts "'#{@id_n}', '#{@col[:lid]}', '#{en}', '#{txt}', '#{body}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@@id_t}'" #% endnotes - @conn.execute(%{ - INSERT INTO endnotes (nid, document_lid, nr, clean, body, ocn, ocnd, ocns, metadata_tid, digest_clean) VALUES ('#{@id_n}', '#{@col[:lid]}', '#{en}', '#{txt}', '#{body}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@@id_t}', '#{digest_clean}'); - }) + en={} + en={ :type => 'endnotes', + :id => @id_n, + :lid => @col[:lid], + :nr => nr, + :txt => txt, + :body => body, + :ocn => @col[:ocn], + :ocnd => @col[:ocnd], + :ocns => @col[:ocns], + :id_t => @@id_t, + :hash => digest_clean + } + t=SiSU_DB_tuple::Load_endnotes.new(@conn,en) + t.tuple end end end @@ -593,10 +600,10 @@ module SiSU_DB_import endnote_array.each do |inf| if inf[/~\[\*\d+.+?<[0-9a-f]{#{@@dl}}>\]~/] # dal new endnotes 2003w31/1 if inf[/~\[[*](\d+)(.+?)<([0-9a-f]{#{@@dl}})>\]~/] # dal new endnotes 2003w31/1 - en,txt,digest_clean=$1,$2,$3 + nr,txt,digest_clean=$1,$2,$3 end @id_n+=1 - body=SiSU_Format_Shared::CSS_Format.new(@md,txt,@col,en).endnote + body=SiSU_Format_Shared::CSS_Format.new(@md,txt,@col,nr).endnote special_character_escape(body) special_character_escape(txt) strip_markup(txt) @@ -609,9 +616,21 @@ module SiSU_DB_import end if txt #puts "'#{@id_n}', '#{@col[:lid]}', '#{en}', '#{txt}', '#{body}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@@id_t}'" #% endnotes - @conn.execute(%{ - INSERT INTO endnotes_asterisk (nid, document_lid, nr, clean, body, ocn, ocnd, ocns, metadata_tid, digest_clean) VALUES ('#{@id_n}', '#{@col[:lid]}', '#{en}', '#{txt}', '#{body}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@@id_t}', '#{digest_clean}'); - }) + en={} + en={ :type => 'endnotes_asterisk', + :id => @id_n, + :lid => @col[:lid], + :nr => nr, + :txt => txt, + :body => body, + :ocn => @col[:ocn], + :ocnd => @col[:ocnd], + :ocns => @col[:ocns], + :id_t => @@id_t, + :hash => digest_clean + } + t=SiSU_DB_tuple::Load_endnotes.new(@conn,en) + t.tuple end end end @@ -622,10 +641,10 @@ module SiSU_DB_import endnote_array.each do |inf| if inf[/~\[\+\d+.+?<[0-9a-f]{#{@@dl}}>\]~/] # dal new endnotes 2003w31/1 if inf[/~\[[+](\d+)(.+?)<([0-9a-f]{#{@@dl}})>\]~/] # dal new endnotes 2003w31/1 - en,txt,digest_clean=$1,$2,$3 + nr,txt,digest_clean=$1,$2,$3 end @id_n+=1 - body=SiSU_Format_Shared::CSS_Format.new(@md,txt,@col,en).endnote + body=SiSU_Format_Shared::CSS_Format.new(@md,txt,@col,nr).endnote special_character_escape(body) special_character_escape(txt) strip_markup(txt) @@ -637,10 +656,21 @@ module SiSU_DB_import txt=%{\n\nLARGE TEXT BLOCK OMITTED\n\n} end if txt - #puts "'#{@id_n}', '#{@col[:lid]}', '#{en}', '#{txt}', '#{body}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@@id_t}'" #% endnotes - @conn.execute(%{ - INSERT INTO endnotes_plus (nid, document_lid, nr, clean, body, ocn, ocnd, ocns, metadata_tid, digest_clean) VALUES ('#{@id_n}', '#{@col[:lid]}', '#{en}', '#{txt}', '#{body}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@@id_t}', '#{digest_clean}'); - }) + en={} + en={ :type => 'endnotes_plus', + :id => @id_n, + :lid => @col[:lid], + :nr => nr, + :txt => txt, + :body => body, + :ocn => @col[:ocn], + :ocnd => @col[:ocnd], + :ocns => @col[:ocns], + :id_t => @@id_t, + :hash => digest_clean + } + t=SiSU_DB_tuple::Load_endnotes.new(@conn,en) + t.tuple end end end @@ -703,79 +733,77 @@ module SiSU_DB_import @env=SiSU_Env::Info_env.new(@opt.fns) base=@env.url.root out=@env.path.output - markup,meta,latex,plaintext,html_toc,html_doc,xml_sax,xml_dom,pdf_p,pdf_l,concordance,sisupod='','','','','','','','','','','','' - markup_li,meta_li,latex_li,plaintext_li,html_li,xml_sax_li,xml_dom_li,pdf_p_li,pdf_l_li,concordance_li,sisupod_li='','','','','','','','','','','' + f,u={},{} if @fnb.empty? \ or @fnb.nil? p 'file output path error' #remove end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:plain]}")==true) - plaintext,plaintext_li='plaintext,', "'#{base}/#@fnb/#{@md.fn[:plain]}'," + f[:txt],u[:txt]='plaintext,', "'#{base}/#@fnb/#{@md.fn[:plain]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:toc]}")==true) - html_toc,html_toc_li='html_toc,', "'#{base}/#@fnb/#{@md.fn[:toc]}'," + f[:html_toc],u[:html_toc]='html_toc,', "'#{base}/#@fnb/#{@md.fn[:toc]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:doc]}")==true) - html_doc,html_doc_li='html_doc,', "'#{base}/#@fnb/#{@md.fn[:doc]}'," + f[:html_doc],u[:html_doc]='html_doc,', "'#{base}/#@fnb/#{@md.fn[:doc]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:xhtml]}")==true) - xhtml,xhtml_li='xhtml,', "'#{base}/#@fnb/#{@md.fn[:xhtml]}'," + f[:xhtml],u[:xhtml]='xhtml,', "'#{base}/#@fnb/#{@md.fn[:xhtml]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:sax]}")==true) - xml_sax,xml_sax_li='xml_sax,', "'#{base}/#@fnb/#{@md.fn[:sax]}'," + f[:xml_sax],u[:xml_sax]='xml_sax,', "'#{base}/#@fnb/#{@md.fn[:sax]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:dom]}")==true) - xml_dom,xml_dom_li='xml_dom,', "'#{base}/#@fnb/#{@md.fn[:dom]}'," + f[:xml_dom],u[:xml_dom]='xml_dom,', "'#{base}/#@fnb/#{@md.fn[:dom]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:odf]}")==true) - odf,odf_li='odf,', "'#{base}/#@fnb/#{@md.fn[:odf]}'," + f[:odf],u[:odf]='odf,', "'#{base}/#@fnb/#{@md.fn[:odf]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:pdf_p]}")==true) - pdf_p,pdf_p_li='pdf_p,', "'#{base}/#@fnb/#{@md.fn[:pdf_p]}'," + f[:pdf_p],u[:pdf_p]='pdf_p,', "'#{base}/#@fnb/#{@md.fn[:pdf_p]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:pdf_l]}")==true) - pdf_l,pdf_l_li='pdf_l,', "'#{base}/#@fnb/#{@md.fn[:pdf_l]}'," + f[:pdf_l],u[:pdf_l]='pdf_l,', "'#{base}/#@fnb/#{@md.fn[:pdf_l]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:concordance]}")==true) - concordance,concordance_li='concordance,', "'#{base}/#@fnb/#{@md.fn[:concordance]}'," + f[:concordance],u[:concordance]='concordance,', "'#{base}/#@fnb/#{@md.fn[:concordance]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@opt.fns}.tex")==true) - latex_p,latex_p_li='latex_p,', "'#{base}/#@fnb/#{@opt.fns}.tex'," + f[:latex_p],u[:latex_p]='latex_p,', "'#{base}/#@fnb/#{@opt.fns}.tex'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@opt.fns}.landscape.tex")==true) - latex_l,latex_l_li='latex_l,', "'#{base}/#@fnb/#@opt.fns}.landscape.tex'," + f[:latex_l],u[:latex_l]='latex_l,', "'#{base}/#@fnb/#@opt.fns}.landscape.tex'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:digest]}")==true) - digest,digest_li='digest,', "'#{base}/#@fnb/#{@md.fn[:digest]}'," + f[:digest],u[:digest]='digest,', "'#{base}/#@fnb/#{@md.fn[:digest]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@md.fn[:manifest]}")==true) #revisit, was to be text, this is html - manifest,manifest_li='manifest,', "'#{base}/#@fnb/#{@md.fn[:manifest]}'," + f[:manifest],u[:manifest]='manifest,', "'#{base}/#@fnb/#{@md.fn[:manifest]}'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@opt.fns}.meta")==true) - markup,markup_li='markup,', "'#{base}/#@fnb/#{@opt.fns}.meta'," + f[:markup],u[:markup]='markup,', "'#{base}/#@fnb/#{@opt.fns}.meta'," end if @opt.cmd !~/e/ \ or (@opt.cmd=~/e/ and FileTest.file?("#{out}/#@fnb/#{@opt.fns}.tgz")==true) - sisupod,sisupod_li='sisupod,', "'#{base}/#@fnb/#{@opt.fns}.tgz'," + f[:sisupod],u[:sisupod]='sisupod,', "'#{base}/#@fnb/#{@opt.fns}.tgz'," end - @conn.execute(%{ - INSERT INTO urls (#{plaintext} #{html_toc} #{html_doc} #{xhtml} #{xml_sax} #{xml_dom} #{odf} #{pdf_p} #{pdf_l} #{concordance} #{latex_p} #{latex_l} #{manifest} #{digest} #{markup} #{sisupod} metadata_tid) VALUES (#{plaintext_li} #{html_toc_li} #{html_doc_li} #{xhtml_li} #{xml_sax_li} #{xml_dom_li} #{odf_li} #{pdf_p_li} #{pdf_l_li} #{concordance_li} #{latex_p_li} #{latex_l_li} #{manifest_li} #{digest_li} #{markup_li} #{sisupod_li} #{@@id_t}); - }) + t=SiSU_DB_tuple::Load_urls.new(@conn,f,u,@@id_t) + t.tuple rescue; SiSU_Errors::Info_error.new($!,$@,@opt.cmd,@opt.fns).error ensure end -- cgit v1.2.3