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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
# encoding: utf-8
=begin
* Name: SiSU
** Description: documents, structuring, processing, publishing, search
*** preprocessing, (document abstraction), data abstraction used in subsequent
processing
** Author: Ralph Amissah
<ralph@amissah.com>
<ralph.amissah@gmail.com>
** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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>
** 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/ao.rb;hb=HEAD>
=end
module SiSU_AO
require_relative 'se' # se.rb
include SiSU_Env
require_relative 'dp' # dp.rb
include SiSU_Param
require_relative 'ao_doc_objects' # ao_doc_objects.rb
require_relative 'ao_syntax' # ao_syntax.rb
include SiSU_AO_Syntax
require_relative 'ao_doc_str' # ao_doc_str.rb
require_relative 'ao_appendices' # ao_appendices.rb
require_relative 'ao_idx' # ao_idx.rb
require_relative 'ao_numbering' # ao_numbering.rb
require_relative 'ao_hash_digest' # ao_hash_digest.rb
require_relative 'ao_endnotes' # ao_endnotes.rb
require_relative 'ao_images' # ao_images.rb
require_relative 'ao_metadata' # ao_metadata.rb
require_relative 'ao_character_check' # ao_character_check.rb
require_relative 'ao_misc_arrange' # ao_misc_arrange.rb
require_relative 'ao_expand_insertions' # ao_expand_insertions.rb
require_relative 'ao_persist' # ao_persist.rb
require_relative 'prog_text_translation' # prog_text_translation.rb
require_relative 'shared_sem' # shared_sem.rb
class Instantiate < SiSU_Param::Parameters::Instructions
def initialize
@@flag_vocab=0
@@line_mode=''
end
end
class Source <Instantiate
def initialize(opt,fnx=nil,process=:complete)
@opt,@fnx,@process=opt,fnx,process
@per ||=SiSU_AO_Persist::Persist.new.persist_init
@per.fns ||=opt.fns
fn_use=if fnx \
and fnx =~/\.ss[tmi]$/
fnx
elsif opt.fns =~/\.ssm$/
opt.fns + '.sst'
else
opt.fns
end
@make_fns=SiSU_Env::InfoFile.new(fn_use)
@fnm=@make_fns.marshal.ao_metadata
@fnc=@make_fns.marshal.ao_content
@idx_sst=@make_fns.marshal.ao_idx_sst_rel_html_seg
@idx_raw=@make_fns.marshal.ao_idx_sst_rel
@idx_html=@make_fns.marshal.ao_idx_html
@idx_xhtml=@make_fns.marshal.ao_idx_xhtml
@map_nametags=@make_fns.marshal.ao_map_nametags
@map_ocn_htmlseg=@make_fns.marshal.ao_map_ocn_htmlseg
@env=SiSU_Env::InfoEnv.new
end
def read #creates ao
begin
@per=SiSU_AO_Persist::Persist.new
@per.ao_arr=[]
@per.fns=(@fnx && @fnx =~/\.ss[tmi]$/) \
? @fnx
: @opt.fns
create_ao
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections,@per.fns).location do
__LINE__.to_s + ':' + __FILE__
end
ensure
SiSU_AO_Persist::Persist.new.persist_init
SiSU_AO::Instantiate.new
end
end
def get #reads ao, unless does not exist then creates first
begin
ao=[]
unless @per.fns==@opt.fns \
or @per.fns==@fnx
@per.fns=(@fnx && @fnx =~/\.ss[tmi]$/) \
? @fnx
: @opt.fns
@per.ao_arr=[]
end
ao=(@per.ao_arr.empty?) \
? read_fnc
: @per.ao_arr.dup
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections,@opt.fns).location do
__LINE__.to_s + ':' + __FILE__
end
ensure
SiSU_AO::Instantiate.new
end
end
def get_idx_sst #reads ao idx.sst, #unless does not exist then creates first
begin
ao=[]
unless @per.fns==@opt.fns \
or @per.fns==@fnx
@per.fns=(@fnx && @fnx =~/\.ss[tmi]$/) \
? @fnx
: @opt.fns
@per.idx_arr_sst=[]
end
ao=(@per.idx_arr_sst.empty?) \
? read_idx_sst
: @per.idx_arr_sst.dup #check
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections,@opt.fns).location do
__LINE__.to_s + ':' + __FILE__
end
ensure
SiSU_AO::Instantiate.new
end
end
def get_idx_raw
begin
ao=[]
unless @per.fns==@opt.fns \
or @per.fns==@fnx
@per.fns=(@fnx && @fnx =~/\.ss[tmi]$/) \
? @fnx
: @opt.fns
@per.idx_arr_tex=[]
end
ao=(@per.idx_arr_tex.empty?) \
? read_idx_raw
: @per.idx_arr_tex.dup #check
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections,@opt.fns).location do
__LINE__.to_s + ':' + __FILE__
end
ensure
SiSU_AO::Instantiate.new
end
end
def get_idx_html #reads ao idx.html, #unless does not exist then creates first
begin
ao=[]
unless @per.fns==@opt.fns \
or @per.fns==@fnx
@per.fns=(@fnx && @fnx =~/\.ss[tmi]$/) \
? @fnx
: @opt.fns
@per.idx_arr_html=[]
end
ao=(@per.idx_arr_html.empty?) \
? read_idx_html
: @per.idx_arr_html.dup
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections,@opt.fns).location do
__LINE__.to_s + ':' + __FILE__
end
ensure
SiSU_AO::Instantiate.new
end
end
def get_idx_xhtml #reads ao idx.xhtml, #unless does not exist then creates first
begin
ao=[]
unless @per.fns==@opt.fns \
or @per.fns==@fnx
@per.fns=(@fnx && @fnx =~/\.ss[tmi]$/) \
? @fnx
: @opt.fns
@per.idx_arr_xhtml=[] #...
end
ao=(@per.idx_arr_xhtml.empty?) \
? read_idx_xhtml
: @per.idx_arr_xhtml.dup
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections,@opt.fns).location do
__LINE__.to_s + ':' + __FILE__
end
ensure
SiSU_AO::Instantiate.new
end
end
def get_map_nametags #reads ao map.nametags, #unless does not exist then creates first
begin
ao=[]
unless @per.fns==@opt.fns \
or @per.fns==@fnx
@per.fns=(@fnx && @fnx =~/\.ss[tmi]$/) \
? @fnx
: @opt.fns
@per.map_arr_nametags=[]
end
ao=(@per.map_arr_nametags.empty?) \
? read_map_nametags
: @per.map_arr_nametags.dup
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections,@opt.fns).location do
__LINE__.to_s + ':' + __FILE__
end
ensure
SiSU_AO::Instantiate.new
end
end
def get_map_ocn_htmlseg #reads ao map.ocn_htmlseg, #unless does not exist then creates first
begin
ao=[]
unless @per.fns==@opt.fns \
or @per.fns==@fnx
@per.fns=(@fnx && @fnx =~/\.ss[tmi]$/) \
? @fnx
: @opt.fns
@per.map_arr_ocn_htmlseg=[]
end
ao=(@per.map_arr_ocn_htmlseg.empty?) \
? read_map_ocn_htmlseg
: @per.map_arr_ocn_htmlseg.dup
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections,@opt.fns).location do
__LINE__.to_s + ':' + __FILE__
end
ensure
SiSU_AO::Instantiate.new
end
end
protected
def create_ao
ao_array=[]
fnp = @fnx ? "#{@opt.fno} #{@fnx}" : @opt.fno
unless @opt.act[:quiet][:set]==:on
tell=(@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],
'Document Abstraction'
)
: SiSU_Screen::Ansi.new(
@opt.act[:color_state][:set],
'Document Abstraction',
"[#{@opt.f_pth[:lng_is]}] #{fnp}"
)
tell.blue_title_hi
end
fn=(@fnx && @fnx =~/\.ss[tmi]$/) \
? @fnx
: @opt.fns
if @opt.fno =~/\.txz$/
Dir.chdir(@opt.f_pth[:pth])
end
meta=file_array=@env.source_file_processing_array(fn)
@md=SiSU_Param::Parameters::Instructions.new(meta,@opt).extract
meta=nil
ao=SiSU_AO::Make.new(fn,@md,file_array,@fnx,@process).song
if (@opt.act[:verbose][:set]==:on \
|| @opt.act[:verbose_plus][:set]==:on \
|| @opt.act[:maintenance][:set]==:on)
cf=SiSU_Env::CreateFile.new(fn)
if (@opt.act[:verbose][:set]==:on \
|| @opt.act[:verbose_plus][:set]==:on)
SiSU_Screen::Ansi.new(
@opt.act[:color_state][:set],
@opt.fns,
"~meta/#{@opt.fns}.meta"
).output
elsif @opt.act[:maintenance][:set]==:on
SiSU_Screen::Ansi.new(
@opt.act[:color_state][:set],
"ao -> #{cf.meta}"
).txt_grey
end
end
ao.each {|s| ao_array << s}
if @opt.act[:maintenance][:set]==:on
ao_array.each do |obj|
if defined? obj.parent
if defined? obj.ln
if defined? obj.node
puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}}
else
puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent}}
end
else
if defined? obj.node
puts %{ #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}}
else
puts %{ #{obj.ocn} : #{obj.parent}}
end
end
end
end
end
ao_array
end
def read_fnm
ao=[]
ao=(FileTest.file?(@fnm)) \
? (File.open(@fnm,'r:utf-8'){ |f| ao=Marshal.load(f)})
: SiSU_AO::Source.new(@opt).create_ao
end
def read_fnc
ao=[]
ao=(FileTest.file?(@fnc)) \
? (File.open(@fnc,'r:utf-8'){ |f| ao=Marshal.load(f)})
: SiSU_AO::Source.new(@opt,@fnx,@process).create_ao
end
def read_idx_sst
m=[]
m=(FileTest.file?(@idx_sst)) \
? (File.open(@idx_sst,'r:utf-8'){ |f| m=Marshal.load(f)})
: nil
end
def read_idx_raw
m=[]
m=(FileTest.file?(@idx_raw)) \
? (File.open(@idx_raw,'r:utf-8'){ |f| m=Marshal.load(f)})
: nil
end
def read_idx_html
m=[]
m=(FileTest.file?(@idx_html)) \
? (File.open(@idx_html,'r:utf-8'){ |f| m=Marshal.load(f)})
: nil
end
def read_idx_xhtml
m=[]
m=(FileTest.file?(@idx_xhtml)) \
? (File.open(@idx_xhtml,'r:utf-8'){ |f| m=Marshal.load(f)})
: nil
end
def read_map_nametags
m=[]
m=(FileTest.file?(@map_nametags)) \
? (File.open(@map_nametags,'r:utf-8'){ |f| m=Marshal.load(f)})
: nil
end
def read_map_ocn_htmlseg
m=[]
m=(FileTest.file?(@map_ocn_htmlseg)) \
? (File.open(@map_ocn_htmlseg,'r:utf-8'){ |f| m=Marshal.load(f)})
: nil
end
end
class Output
def initialize(fn,md,data)
@fn,@md,@data=fn,md,data
@cf=SiSU_Env::CreateFile.new(@fn)
@make=SiSU_Env::InfoFile.new(@fn)
@dir=SiSU_Env::InfoEnv.new(@fn)
end
def screen_dump(o)
if defined? o.of
print %{OF: #{o.of}; }
end
if defined? o.is
print %{IS: #{o.is.to_s}; }
end
if defined? o.ocn
print %{OCN: #{o.ocn}; }
end
if defined? o.node
print %{NODE: #{o.node}; }
end
if defined? o.parent
print %{Parent: #{o.parent}; }
end
if defined? o.obj and not o.obj.empty?
puts %{\n#{o.obj}; }
else "\n"
end
end
def screen_print(t_o)
if defined? t_o
print ' ' + t_o.to_s
end
end
def screen_output(data)
data.each do |o|
print o.class
screen_print(o.ocn)
screen_print(o.obj)
puts "\n"
end
end
def hard_output
if @md.opt.act[:maintenance][:set]==:on
filename_meta=@cf.metaverse.file_meta
@data.each {|o| filename_meta.puts o.inspect.sub(/:0x[0-9a-f]{8}\s/,': ')} #to make diffing easier
filename_txt=@cf.metaverse.file_txt
@data.each do |o|
if defined? o.ocn
filename_txt.puts case o.is
when :heading
"[#{o.is.to_s} #{o.lv}~#{o.name} [#{o.ocn}]] #{o.obj}"
else "[#{o.is.to_s} [#{o.ocn}]] #{o.obj}"
end
else
filename_txt.puts case o.is
when :meta
"[m~#{o.tag}] #{o.obj}"
else "[#{o.is.to_s}] #{o.obj}"
end
end
end
filename_debug=@cf.file_debug
@data.each do |o|
if defined? o.ocn
case o.is
when :heading
filename_debug.puts
"#{o.is.to_s} #{o.lv}~#{o.name} odv=#{o.odv} osp=#{o.osp} [#{o.ocn}] -->\n\t#{o.obj}"
end
end
end
else
hard="#{@dir.processing_path.ao}/#{@md.fns}.meta"
File.unlink(hard) if FileTest.file?(hard)
hard="#{@dir.processing_path.ao}/#{@md.fns}.txt"
File.unlink(hard) if FileTest.file?(hard)
hard="#{@dir.processing_path.ao}/#{@md.fns}.debug.txt"
File.unlink(hard) if FileTest.file?(hard)
end
end
def make_marshal_content
marshal_ao=@make.marshal.ao_content
File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array)
end
def make_marshal_metadata
marshal_ao=@make.marshal.ao_metadata
File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array)
end
def idx_html_hard_output
if @md.book_idx \
and @md.opt.act[:maintenance][:set]==:on
filename_meta=@cf.file_meta_idx_html
if @data.is_a?(Array)
@data.each {|s| p s.inspect + "\n" unless s.is_a?(String)}
@data.each {|s| filename_meta.puts s.strip + "\n" unless s.strip.empty?}
end
else
hard_idx_html="#{@dir.processing_path.ao}/#{@md.fns}.idx.html"
File.unlink(hard_idx_html) if FileTest.file?(hard_idx_html)
end
end
def make_marshal_idx_sst_html_seg
marshal_ao=@make.marshal.ao_idx_sst_rel_html_seg
File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} \
if @data.is_a?(Array)
end
def make_marshal_idx_sst_rel
marshal_ao=@make.marshal.ao_idx_sst_rel
File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} \
if @data.is_a?(Array)
end
def make_marshal_idx_html
marshal_ao=@make.marshal.ao_idx_html
File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} \
if @data.is_a?(Array)
end
def make_marshal_idx_xhtml
marshal_ao=@make.marshal.ao_idx_xhtml
File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} \
if @data.is_a?(Array)
end
def make_marshal_map_nametags
marshal_ao=@make.marshal.ao_map_nametags
File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} \
if @data.is_a?(Hash)
end
def make_marshal_map_name_ocn_htmlseg
marshal_ao=@make.marshal.ao_map_ocn_htmlseg
File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} \
if @data.is_a?(Hash)
end
end
class Make
def initialize(fn,md,data,fnx,process)
@fn,@md,@data,@fnx,@process=fn,md,data,fnx,process
@env=SiSU_Env::InfoEnv.new(@md.fns)
end
def reset
@@flag_vocab=0
@@line_mode=''
end
def song
reset
data_txt=@data
data_txt=
SiSU_AO_Insertions::Insertions.new(@md,data_txt). # ao_expand_insertions.rb
expand_insertions?
data_txt=
SiSU_AO_MiscArrangeText::SI.new(@md,data_txt). # ao_misc_arrange.rb
prepare_text
data_obj,
metadata,
bibliography=
SiSU_AO_DocumentStructureExtract::Build.new(@md,data_txt). # ao_doc_str.rb
identify_parts
data_obj=
SiSU_AO_Syntax::Markup.new(@md,data_obj,bibliography).songsheet # ao_syntax.rb
data_obj,
endnote_array=
SiSU_AO_CharacterCheck::Check.new(data_obj). # ao_character_check.rb
character_check_and_oldstyle_endnote_array
data_obj=
SiSU_AO_Images::Images.new(@md,data_obj).images # ao_images.rb
data_obj,
tags_map,
ocn_html_seg_map=
SiSU_AO_Numbering::Numbering.new(@md,data_obj,@fnx,@process). # ao_numbering.rb
numbering_song
data_obj,
book_index_rel,
book_index_rel_html_seg,
html_idx,
xhtml_idx=
SiSU_AO_BookIndex::BookIndex.new(@md,data_obj,@env). # ao_idx.rb
indexing_song if @md.book_idx
data_obj=
SiSU_AO_Endnotes::Endnotes.new(@md,data_obj,endnote_array). # ao_endnotes.rb
endnotes
outputdata=data_obj
if (@md.opt.act[:ao][:set]==:on \
|| @md.opt.act[:maintenance][:set]==:on)
SiSU_AO::Output.new(@fn,@md,outputdata).hard_output
SiSU_AO::Output.new(@fn,@md,outputdata).make_marshal_content
SiSU_AO::Output.new(@fn,@md,metadata).make_marshal_metadata
SiSU_AO::Output.new(@fn,@md,html_idx).idx_html_hard_output
SiSU_AO::Output.new(@fn,@md,book_index_rel_html_seg).make_marshal_idx_sst_html_seg
SiSU_AO::Output.new(@fn,@md,book_index_rel).make_marshal_idx_sst_rel
SiSU_AO::Output.new(@fn,@md,html_idx).make_marshal_idx_html
SiSU_AO::Output.new(@fn,@md,xhtml_idx).make_marshal_idx_xhtml
SiSU_AO::Output.new(@fn,@md,tags_map).make_marshal_map_nametags
SiSU_AO::Output.new(@fn,@md,ocn_html_seg_map).make_marshal_map_name_ocn_htmlseg
end
reset
outputdata
end
protected
end
end
__END__
|