aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v5/db_load_tuple.rb
blob: 661cf52c8f6a3434d4ca8068dcd724acf8659dea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# 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 <http://www.gnu.org/licenses/>.

   If you have Internet connection, the latest version of the GPL should be
   available at these locations:
   <http://www.fsf.org/licensing/licenses/gpl.html>
   <http://www.gnu.org/licenses/gpl.html>

   <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>

 * SiSU uses:
   * Standard SiSU markup syntax,
   * Standard SiSU meta-markup syntax, and the
   * Standard SiSU object citation numbering and system

 * Hompages:
   <http://www.jus.uio.no/sisu>
   <http://www.sisudoc.org>

 * Download:
   <http://www.sisudoc.org/sisu/en/SiSU/download.html>

 * Git
   <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
   <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/v5/db_load_tuple.rb;hb=HEAD>

 * Ralph Amissah
   <ralph@amissah.com>
   <ralph.amissah@gmail.com>

 ** Description: modules shared by the different db types, dbi, postgresql,
    sqlite

=end
module SiSU_DbTuple
  require_relative 'db_columns'                         # db_columns.rb
  class LoadDocuments
    require_relative 'dp'                               # dp.rb
      include SiSU_Param
    def initialize(conn,col,opt,file_maint)
      @conn,@col,@opt,@file_maint=conn,col,opt,file_maint
      @col[:lev]=@col[:lev].to_i
      unless @col[:lev].inspect=~/^[0-7]/ \
      or @col[:lev]==0..7
        @col[:lev]=9
      end
      @col[:ocn]=0 unless @col[:ocn].inspect=~/\d+/
      @cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX
    end
    def tuple                                                                    #% import line
      sql_entry=if @col[:en_a]
        "INSERT INTO doc_objects (lid, metadata_tid, lev, lev_an, clean, body, book_idx, ocn, ocnd, ocns, seg, lev0, lev1, lev2, lev3, lev4, lev5, lev6, lev7, en_a, en_z, t_of, t_is, node, parent, digest_clean, digest_all) " +
        "VALUES (#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:lev_an]}', '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:book_idx]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv0]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:lv7]}', '#{@col[:en_a]}', '#{@col[:en_z]}', '#{@col[:t_of]}', '#{@col[:t_is]}', '#{@col[:node]}', '#{@col[:parent]}', '#{@col[:digest_clean]}', '#{@col[:digest_all]}');"
      else
        "INSERT INTO doc_objects (lid, metadata_tid, lev, lev_an, clean, body, book_idx, ocn, ocnd, ocns, seg, lev0, lev1, lev2, lev3, lev4, lev5, lev6, lev7, t_of, t_is, node, parent, digest_clean, digest_all) " +
        "VALUES (#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:lev_an]}', '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:book_idx]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv0]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:lv7]}', '#{@col[:t_of]}', '#{@col[:t_is]}', '#{@col[:node]}', '#{@col[:parent]}', '#{@col[:digest_clean]}', '#{@col[:digest_all]}');"
      end
      if @opt.act[:verbose_plus][:set]==:on
        if @opt.act[:maintenance][:set]==:on
          puts @file_maint.inspect
          puts sql_entry
        end
        @file_maint.puts sql_entry
      else
        if @opt.act[:verbose_plus][:set]==:on
          puts sql_entry
          @file_maint.puts sql_entry
        end
      end
      if @opt.act[:verbose][:set]==:on
        if @col[:lev].inspect =~/[0-35-7]/
          lev=case @col[:lev].inspect
          when /0/ then ':A'
          when /1/ then ':B'
          when /2/ then ':C'
          when /3/ then ':D'
          when /5/ then ' 2'
          when /6/ then ' 3'
          when /7/ then ' 4'
          end
          puts %{#{lev}>\t#{@col[:lv0]}\t#{@col[:lv1]}\t#{@col[:lv2]}\t#{@col[:lv3]}\t#{@col[:lv4]}\t#{@col[:lv5]}\t#{@col[:lv6]}\t#{@col[:lv7]}\t#{@col[:ocn]}\t#{@col[:node]}\t#{@col[:ocns]}}
        elsif @col[:lev].inspect =~/[4]/
          puts %{ #{@cX.green}1>#{@cX.off}\t#{@col[:lv0]}\t#{@col[:lv1]}\t#{@col[:lv2]}\t#{@col[:lv3]}\t#{@col[:lv4]}\t#{@col[:lv5]}\t#{@col[:lv6]}\t#{@col[:lv7]}\t#{@col[:ocn]}\t#{@col[:node]}\t#{@col[:ocns]}\t#{@col[:seg]}}
        end
      end
      sql_entry
    end
  end
  class LoadMetadata #< SiSU_DbColumns::Columns
    def initialize(conn,id,md,file_maint)
      @conn,@id,@md,@file_maint=conn,id,md,file_maint
      @tp=SiSU_DbColumns::Columns.new(md)
    end
    def tuple
      sql_entry="INSERT INTO metadata_and_text (
#{@tp.column.title.tuple[0]}
#{@tp.column.title_main.tuple[0]}
#{@tp.column.title_sub.tuple[0]}
#{@tp.column.title_short.tuple[0]}
#{@tp.column.title_edition.tuple[0]}
#{@tp.column.title_note.tuple[0]}
#{@tp.column.title_language.tuple[0]}
#{@tp.column.title_language_char.tuple[0]}
#{@tp.column.creator_author.tuple[0]}
#{@tp.column.creator_author_honorific.tuple[0]}
#{@tp.column.creator_author_nationality.tuple[0]}
#{@tp.column.creator_editor.tuple[0]}
#{@tp.column.creator_contributor.tuple[0]}
#{@tp.column.creator_illustrator.tuple[0]}
#{@tp.column.creator_photographer.tuple[0]}
#{@tp.column.creator_translator.tuple[0]}
#{@tp.column.creator_prepared_by.tuple[0]}
#{@tp.column.creator_digitized_by.tuple[0]}
#{@tp.column.creator_audio.tuple[0]}
#{@tp.column.creator_video.tuple[0]}
#{@tp.column.language_document.tuple[0]}
#{@tp.column.language_document_char.tuple[0]}
#{@tp.column.language_original.tuple[0]}
#{@tp.column.language_original_char.tuple[0]}
#{@tp.column.date_added_to_site.tuple[0]}
#{@tp.column.date_available.tuple[0]}
#{@tp.column.date_created.tuple[0]}
#{@tp.column.date_issued.tuple[0]}
#{@tp.column.date_modified.tuple[0]}
#{@tp.column.date_published.tuple[0]}
#{@tp.column.date_valid.tuple[0]}
#{@tp.column.date_translated.tuple[0]}
#{@tp.column.date_original_publication.tuple[0]}
#{@tp.column.date_generated.tuple[0]}
#{@tp.column.publisher.tuple[0]}
#{@tp.column.original_publisher.tuple[0]}
#{@tp.column.original_language.tuple[0]}
#{@tp.column.original_language_char.tuple[0]}
#{@tp.column.original_source.tuple[0]}
#{@tp.column.original_institution.tuple[0]}
#{@tp.column.original_nationality.tuple[0]}
#{@tp.column.rights_all.tuple[0]}
#{@tp.column.rights_copyright_text.tuple[0]}
#{@tp.column.rights_copyright_translation.tuple[0]}
#{@tp.column.rights_copyright_illustrations.tuple[0]}
#{@tp.column.rights_copyright_photographs.tuple[0]}
#{@tp.column.rights_copyright_preparation.tuple[0]}
#{@tp.column.rights_copyright_digitization.tuple[0]}
#{@tp.column.rights_copyright_audio.tuple[0]}
#{@tp.column.rights_copyright_video.tuple[0]}
#{@tp.column.rights_license.tuple[0]}
#{@tp.column.classify_topic_register.tuple[0]}
#{@tp.column.classify_subject.tuple[0]}
#{@tp.column.classify_loc.tuple[0]}
#{@tp.column.classify_dewey.tuple[0]}
#{@tp.column.classify_keywords.tuple[0]}
#{@tp.column.identifier_oclc.tuple[0]}
#{@tp.column.identifier_isbn.tuple[0]}
#{@tp.column.notes_abstract.tuple[0]}
#{@tp.column.notes_description.tuple[0]}
#{@tp.column.notes_comment.tuple[0]}
#{@tp.column.notes_history.tuple[0]}
#{@tp.column.notes_format.tuple[0]}
#{@tp.column.notes_relation.tuple[0]}
#{@tp.column.notes_coverage.tuple[0]}
#{@tp.column.notes_type.tuple[0]}
#{@tp.column.notes_prefix.tuple[0]}
#{@tp.column.notes_prefix_a.tuple[0]}
#{@tp.column.notes_prefix_b.tuple[0]}
#{@tp.column.notes_suffix.tuple[0]}
#{@tp.column.src_filename.tuple[0]}
#{@tp.column.src_fingerprint.tuple[0]}
#{@tp.column.src_filesize.tuple[0]}
#{@tp.column.src_word_count.tuple[0]}
#{@tp.column.src_txt.tuple[0]}
#{@tp.column.fulltext.tuple[0]}
#{@tp.column.links.tuple[0]}
tid)
" +
       "VALUES (
#{@tp.column.title.tuple[1]}
#{@tp.column.title_main.tuple[1]}
#{@tp.column.title_sub.tuple[1]}
#{@tp.column.title_short.tuple[1]}
#{@tp.column.title_edition.tuple[1]}
#{@tp.column.title_note.tuple[1]}
#{@tp.column.title_language.tuple[1]}
#{@tp.column.title_language_char.tuple[1]}
#{@tp.column.creator_author.tuple[1]}
#{@tp.column.creator_author_honorific.tuple[1]}
#{@tp.column.creator_author_nationality.tuple[1]}
#{@tp.column.creator_editor.tuple[1]}
#{@tp.column.creator_contributor.tuple[1]}
#{@tp.column.creator_illustrator.tuple[1]}
#{@tp.column.creator_photographer.tuple[1]}
#{@tp.column.creator_translator.tuple[1]}
#{@tp.column.creator_prepared_by.tuple[1]}
#{@tp.column.creator_digitized_by.tuple[1]}
#{@tp.column.creator_audio.tuple[1]}
#{@tp.column.creator_video.tuple[1]}
#{@tp.column.language_document.tuple[1]}
#{@tp.column.language_document_char.tuple[1]}
#{@tp.column.language_original.tuple[1]}
#{@tp.column.language_original_char.tuple[1]}
#{@tp.column.date_added_to_site.tuple[1]}
#{@tp.column.date_available.tuple[1]}
#{@tp.column.date_created.tuple[1]}
#{@tp.column.date_issued.tuple[1]}
#{@tp.column.date_modified.tuple[1]}
#{@tp.column.date_published.tuple[1]}
#{@tp.column.date_valid.tuple[1]}
#{@tp.column.date_translated.tuple[1]}
#{@tp.column.date_original_publication.tuple[1]}
#{@tp.column.date_generated.tuple[1]}
#{@tp.column.publisher.tuple[1]}
#{@tp.column.original_publisher.tuple[1]}
#{@tp.column.original_language.tuple[1]}
#{@tp.column.original_language_char.tuple[1]}
#{@tp.column.original_source.tuple[1]}
#{@tp.column.original_institution.tuple[1]}
#{@tp.column.original_nationality.tuple[1]}
#{@tp.column.rights_all.tuple[1]}
#{@tp.column.rights_copyright_text.tuple[1]}
#{@tp.column.rights_copyright_translation.tuple[1]}
#{@tp.column.rights_copyright_illustrations.tuple[1]}
#{@tp.column.rights_copyright_photographs.tuple[1]}
#{@tp.column.rights_copyright_preparation.tuple[1]}
#{@tp.column.rights_copyright_digitization.tuple[1]}
#{@tp.column.rights_copyright_audio.tuple[1]}
#{@tp.column.rights_copyright_video.tuple[1]}
#{@tp.column.rights_license.tuple[1]}
#{@tp.column.classify_topic_register.tuple[1]}
#{@tp.column.classify_subject.tuple[1]}
#{@tp.column.classify_loc.tuple[1]}
#{@tp.column.classify_dewey.tuple[1]}
#{@tp.column.classify_keywords.tuple[1]}
#{@tp.column.identifier_oclc.tuple[1]}
#{@tp.column.identifier_isbn.tuple[1]}
#{@tp.column.notes_abstract.tuple[1]}
#{@tp.column.notes_comment.tuple[1]}
#{@tp.column.notes_description.tuple[1]}
#{@tp.column.notes_history.tuple[1]}
#{@tp.column.notes_format.tuple[1]}
#{@tp.column.notes_relation.tuple[1]}
#{@tp.column.notes_coverage.tuple[1]}
#{@tp.column.notes_type.tuple[1]}
#{@tp.column.notes_prefix.tuple[1]}
#{@tp.column.notes_prefix_a.tuple[1]}
#{@tp.column.notes_prefix_b.tuple[1]}
#{@tp.column.notes_suffix.tuple[1]}
#{@tp.column.src_filename.tuple[1]}
#{@tp.column.src_fingerprint.tuple[1]}
#{@tp.column.src_filesize.tuple[1]}
#{@tp.column.src_word_count.tuple[1]}
#{@tp.column.src_txt.tuple[1]}
#{@tp.column.fulltext.tuple[1]}
#{@tp.column.links.tuple[1]}
#{@id}
);"
      if @md.opt.act[:maintenance][:set]==:on
        puts "maintenance mode on: creating sql transaction file (for last transaction set (document) only):\n\t#{@file_maint.inspect}"
        @file_maint.puts sql_entry
      else
        if @md.opt.act[:verbose_plus][:set]==:on
          @file_maint.puts sql_entry
        end
      end
      sql_entry
    end
  end
  class LoadUrls
    def initialize(conn,f,u,id,opt,file_maint)
      @conn,@f,@u,@id,@opt,@file_maint=conn,f,u,id,opt,file_maint
    end
    def tuple
      sql_entry="INSERT INTO urls (#{@f[:txt]} #{@f[:html_toc]} #{@f[:html_doc]} #{@f[:xhtml]} #{@f[:xml_sax]} #{@f[:xml_dom]} #{@f[:odf]} #{@f[:pdf_p]} #{@f[:pdf_l]} #{@f[:concordance]} #{@f[:latex_p]} #{@f[:latex_l]} #{@f[:manifest]} #{@f[:digest]} #{@f[:markup]} #{@f[:sisupod]} metadata_tid) " +
      "VALUES (#{@u[:txt]} #{@u[:html_toc]} #{@u[:html_doc]} #{@u[:xhtml]} #{@u[:xml_sax]} #{@u[:xml_dom]} #{@u[:odf]} #{@u[:pdf_p]} #{@u[:pdf_l]} #{@u[:concordance]} #{@u[:latex_p]} #{@u[:latex_l]} #{@u[:manifest]} #{@u[:digest]} #{@u[:markup]} #{@u[:sisupod]} #{@id});"
      if @opt.act[:maintenance][:set]==:on
        @file_maint.puts sql_entry
      else
        if @opt.act[:verbose_plus][:set]==:on
          @file_maint.puts sql_entry
        end
      end
      sql_entry
    end
  end
  class LoadEndnotes
    def initialize(conn,en,opt,file_maint)
      @conn,@en,@opt,@file_maint=conn,en,opt,file_maint
    end
    def tuple
      sql_entry="INSERT INTO #{@en[:type]} (nid, document_lid, nr, clean, body, ocn, ocnd, ocns, metadata_tid, digest_clean) " +
      "VALUES ('#{@en[:id]}', '#{@en[:lid]}', '#{@en[:nr]}', '#{@en[:txt]}', '#{@en[:body]}', '#{@en[:ocn]}', '#{@en[:ocnd]}', '#{@en[:ocns]}', '#{@en[:id_t]}', '#{@en[:hash]}');"
      if @opt.act[:maintenance][:set]==:on
        @file_maint.puts sql_entry
      else
        if @opt.act[:verbose_plus][:set]==:on
          @file_maint.puts sql_entry
        end
      end
      sql_entry
    end
  end
end
__END__