cc6b595a0ec8e17808161f73069cc9d65491d15a
[software/sisu] / lib / sisu / develop / ao_numbering.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** system environment, resource control and configuration details
8
9 ** Author: Ralph Amissah
10 <ralph@amissah.com>
11 <ralph.amissah@gmail.com>
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see <http://www.gnu.org/licenses/>.
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 <http://www.fsf.org/licensing/licenses/gpl.html>
39 <http://www.gnu.org/licenses/gpl.html>
40
41 <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 <http://www.jus.uio.no/sisu>
50 <http://www.sisudoc.org>
51
52 ** Git
53 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/develop/ao_numbering.rb;hb=HEAD>
55
56 =end
57 module SiSU_AO_Numbering
58 class Numbering
59 attr_accessor :obj,:osp,:ocn,:lv,:name,:index,:comment
60 @@segments_count=0
61 def initialize(md,data)
62 @md,@data=md,data
63 @obj=@type=@ocn=@lv=@name=@index=@comment=nil
64 @chosen_seg_names=[]
65 end
66 def chosen_seg_names(chosen,chosen_seg_name,dob,md,type)
67 @chosen_seg_names=if chosen.compact.uniq.length \
68 == chosen.compact.length
69 chosen
70 else
71 if md.opt.act[:maintenance][:set]==:on
72 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).
73 mark(
74 "duplicated auto segment name: #{type} #{chosen}\n" \
75 + "#{chosen}\n" \
76 + " manually name level 1 segments '1~given_name'\n" \
77 + 'filename: ' + md.fns + "\n" \
78 + 'heading text: "' + dob.obj + '"' + "\n" \
79 + 'duplication: "' + chosen_seg_name + '" (level: ' + dob.lv + '; numbering type: ' + type.to_s + ')'
80 )
81 end
82 chosen=chosen[0..-2]
83 chosen_seg_name=auto_numbering_exceptions(chosen,md,dob)
84 chosen << chosen_seg_name
85 end
86 end
87 def number_of_segments?
88 if @@segments_count==0
89 @data.each do |dob|
90 if dob.is == :heading \
91 and dob.lv == '1'
92 @@segments_count += 1
93 end
94 end
95 @@segments_count
96 else @@segments_count
97 end
98 end
99 def numbering_song
100 begin
101 data=@data
102 data=number_plaintext_para(data)
103 data=auto_number_heading_ie_title(data.compact) #tr issue
104 data=ocn(data.compact) #watch
105 data=xml(data.compact)
106 data=minor_numbering(data.compact)
107 data,tags_map,ocn_html_seg_map=name_para_seg_filename(data)
108 data=set_heading_top(data) unless @md.set_heading_top
109 [data,tags_map,ocn_html_seg_map]
110 ensure
111 @@segments_count=0
112 end
113 end
114 def set_tags(tags,tag)
115 tags=if not tag.empty? \
116 and tag !~/^\d+$/
117 tag=tag.gsub(/[^a-z0-9._-]/,'')
118 [tag,tags].flatten
119 else tags
120 end
121 end
122 def number_plaintext_para(data)
123 @tuned_file=[]
124 data.each do |dob|
125 if (dob.of !=:block \
126 && dob.of !=:comment \
127 && dob.of !=:layout) \
128 && dob.ocn_ #and dob.obj !~ /#{Mx[:gr_o]}Th|#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}/ #FIX
129 dob.obj=dob.obj.gsub(/(.+)\n/,'\1 ') #messy, but idea is that tables should retain breaks
130 end
131 unless dob.obj.is_a?(Array)
132 dob.obj=dob.obj.gsub(/^\s+/,'').
133 gsub(/\s$/,"\n")
134 end
135 @tuned_file << dob
136 end
137 @tuned_file=@tuned_file.flatten
138 end
139 def number_sub_heading(dob,num,title_no)
140 unless dob.obj =~/\d+\.|(?:chapter|article|section|clause)\s+\d+/i #name selection arbitrary, fix
141 dob.obj=case dob.name
142 when /-/ then dob.obj.gsub(/^/,"#{title_no} ")
143 when /^#/ then dob.obj.gsub(/^/,"#{title_no} ")
144 when /^[a-z_\.]+/ then dob.obj.gsub(/^/,"#{title_no} ")
145 else
146 dob.name=title_no if dob.name=~/^$/ #where title contains title number
147 dob.obj.gsub(/^/,"#{title_no} ") if title_no =~/\d+/ #main, where title number is to be provided #watch changed placement
148 end
149 if @md.toc_lev_limit \
150 and @md.toc_lev_limit < num
151 dob.obj=dob.obj.gsub(/^/,'!_ ') #bold line, watch
152 end
153 end
154 dob
155 end
156 def heading_tag_clean(heading_tag)
157 heading_tag=heading_tag.
158 gsub(/[ ]+/,'_').
159 gsub(/["']/,'').
160 gsub(/[\/]/,'-').
161 gsub(/#{Mx[:fa_bold_o]}|#{Mx[:fa_bold_c]}/,'').
162 gsub(/#{Mx[:fa_italics_o]}|#{Mx[:fa_italics_c]}/,'').
163 gsub(/#{Mx[:fa_underscore_o]}|#{Mx[:fa_underscore_c]}/,'').
164 gsub(/#{Mx[:fa_cite_o]}|#{Mx[:fa_cite_c]}/,'').
165 gsub(/#{Mx[:fa_insert_o]}|#{Mx[:fa_insert_c]}/,'').
166 gsub(/#{Mx[:fa_strike_o]}|#{Mx[:fa_strike_c]}/,'').
167 gsub(/#{Mx[:fa_superscript_o]}|#{Mx[:fa_superscript_c]}/,'').
168 gsub(/#{Mx[:fa_subscript_o]}|#{Mx[:fa_subscript_c]}/,'').
169 gsub(/#{Mx[:fa_hilite_o]}|#{Mx[:fa_hilite_c]}/,'').
170 gsub(/#{Mx[:gl_bullet]}/,'')
171 end
172 def auto_number_heading_ie_title(data) #also does some segment naming
173 @tuned_file=[]
174 if defined? @md.make.num_top \
175 and @md.make.num_top \
176 and @md.make.num_top !~/^$/
177 input||=@md.make.num_top
178 end
179 num_top=(input ? input.to_i : nil)
180 t_no1=t_no2=t_no3=0
181 if num_top
182 no1=num_top; no2=(num_top + 1); no3=(num_top + 2)
183 end
184 chapter_number_counter=0
185 data=data.compact
186 data.each do |dob| #@md.seg_names << [additions to segment names]
187 title_no=nil
188 if dob.is ==:heading \
189 && dob.autonum_ \
190 and defined? @md.make.num_top \
191 and @md.make.num_top !~/^$/
192 if dob.lv=='1' \
193 and dob.obj =~/^#\s|\s#(?:\s|$)/
194 chapter_number_counter +=1
195 dob.obj=dob.obj.gsub(/^#\s/,"#{chapter_number_counter} ").
196 gsub(/#([:,]?\s|[.]?$)/,"#{chapter_number_counter}\\1")
197 end
198 if dob.ln==no1
199 @subnumber=1
200 @subnumber=0 if dob.ln==no1
201 end
202 if dob.ln.to_s =~/^[0-6]/ \
203 and not dob.use_ ==:dummy \
204 and dob.obj !~/#{Mx[:fa_o]}(?:~#|-#)#{Mx[:fa_c]}/ # <-- fix
205 if dob.ln==no1
206 t_no1+=1; t_no2=0; t_no3=0
207 title_no="#{t_no1}"
208 if @md.seg_names.is_a?(Array) \
209 and not @md.seg_names.include?(title_no)
210 if dob.ln==no1
211 dob.name="#{title_no}" if not dob.name
212 dob.tags=set_tags(dob.tags,title_no)
213 tag=dob.obj.
214 gsub(/(Article|Clause|Section|Chapter)\s+/,
215 "\\1_#{title_no}").
216 downcase
217 tag=heading_tag_clean(tag)
218 dob.tags=set_tags(dob.tags,tag)
219 dob.obj=(dob.obj =~/(Article|Clause|Section)\s+/) \
220 ? (dob.obj.gsub(/(Article|Clause|Section)\s+/,"\\1 #{title_no} "))
221 : (dob.obj.gsub(/^/,"#{title_no}. ")) #fix stop later
222 end
223 if dob.ln !=no1 \
224 and dob.obj =~/^[\d.]+\s/ #fix -> if the title starts with a numbering scheme, do not auto-number, review
225 dob.name ="#{title_no}" if not dob.name
226 dob.tags=set_tags(dob.tags,title_no)
227 dob.obj=dob.obj.gsub(/^/,"#{title_no}. ")
228 end
229 @md.seg_names << title_no
230 end
231 if dob.ln!=no1 \
232 and dob.name!~/^[a-z_\.]+$/ \
233 and dob.obj !~/[A-Z]\.?\s/ #bug -> tmp fix, excludes A. B. C. lettering, but not roman numerals, is arbitrary, review required # not fixed, work on
234 dob.tags=set_tags(dob.tags,title_no)
235 dob.obj=dob.obj.gsub(/^/i,"#{title_no}. ")
236 end
237 end
238 if dob.ln==no1 #watch because here you change dob.name
239 dob.tags=set_tags(dob.tags,"h#{title_no}")
240 end
241 if dob.ln==no2 #watch because here you change dob.name
242 t_no2+=1; t_no3=0
243 title_no="#{t_no1}.#{t_no2}"
244 dob.tags=set_tags(dob.tags,"h#{title_no}")
245 dob=number_sub_heading(dob,no2,title_no)
246 end
247 if dob.ln==no3 #watch because here you change dob.name
248 t_no3+=1
249 title_no="#{t_no1}.#{t_no2}.#{t_no3}"
250 dob.tags=set_tags(dob.tags,"h#{title_no}")
251 dob=number_sub_heading(dob,no3,title_no)
252 end
253 elsif dob.ln.to_s =~/^[0-6]/ \
254 and dob.name =~ /^[\w-]+-/ # endnotes, watch2005# endnotes, watch2005
255 dob.tags=set_tags(dob.tags,dob.name)
256 dob.name.gsub(/^([a-z_\.]+)-$/,'\1')
257 end
258 elsif dob.is ==:heading \
259 and dob.autonum_ \
260 and @md.markup =~/num_extract/ #AS DANGEROUS force enable with document, note already does this type of numbering for cisg, locate and coordinate logic, is currently misplaced in code, chengwei inspired 2004w23/4
261 #here lies a bug, as is nil when run from -Dv --update, FIX
262 if (dob.name.nil? or dob.name.empty?) \
263 and dob.ln.to_s =~/^[0-9]/ \
264 and dob.obj =~ /^([\d\.]+)/ #risky (must be unique) consider output to 4~~\d instead of 4~\d
265 dob.name=$1
266 dob.tags=set_tags(dob.tags,dob.name)
267 end
268 if @md.toc_lev_limit
269 end
270 elsif defined? dob.name \
271 and dob.name
272 dob.tags=set_tags(dob.tags,dob.name)
273 end
274 dob.tags=dob.tags.uniq if defined? dob.tags
275 @tuned_file << dob
276 end
277 @tuned_file=@tuned_file.flatten
278 end
279 def ocn(data) #and auto segment numbering increment
280 @tuned_file=SiSU_AO_DocumentStructureExtract::OCN.new(@md,data).ocn
281 @tuned_file
282 end
283 def xml(data)
284 @tuned_file=SiSU_AO_DocumentStructureExtract::XML.new(@md,data).dom
285 @tuned_file
286 end
287 def minor_numbering(data) #and auto segment numbering increment
288 @tuned_file=[]
289 number_small,letter_small=0,0
290 letter=%w( a b c d e f g h i j k l m n o p q r s t u v w x y z )
291 data.each do |dob|
292 if dob.of ==:heading \
293 || dob.of ==:heading_insert \
294 || dob.of ==:para \
295 || dob.of ==:block
296 if dob.is ==:heading \
297 and dob.ln.to_s=~/^[0-9]/ #% sub-number system, (baby numbering) reset with any change of major number (more obviously should be placed in number titles, but that is conditionally executed, check and move later)
298 number_small,letter_small=0,0
299 elsif dob.is ==:para
300 if dob.obj =~/^#[ 1]/ \
301 and dob.obj !~/^#\s+(?:~#)?$/
302 letter_small=0
303 number_small=0 if dob.obj =~ /^#1/
304 number_small+=1
305 dob.obj=dob.obj.gsub(/^#[ 1]/,"#{number_small}. ")
306 end
307 if dob.obj =~/^_# /
308 dob.obj=dob.obj.gsub(/^_# /,"#{letter[letter_small]}. ")
309 dob.indent='1'
310 letter_small+=1
311 end
312 end
313 end
314 @tuned_file << dob
315 end
316 @tuned_file=@tuned_file.flatten
317 end
318 def leading_zeros_fixed_width_number(possible_seg_name)
319 if possible_seg_name.to_s =~/^([0-9]+?\.|[0-9]+)$/m #!~/[.,:-]+/
320 possible_seg_name=possible_seg_name.to_s.
321 gsub(/\.$/,'')
322 nl=possible_seg_name.to_s.length
323 zero='0'
324 zeros_fixed_width=number_of_segments?.to_s.length
325 zero_width=(zeros_fixed_width - nl)
326 zero_width == 0 \
327 ? possible_seg_name.to_s
328 : zero*zero_width +
329 possible_seg_name.to_s
330 end
331 end
332 def auto_numbering_exceptions(chosen_seg_names_,md,dob)
333 number_make=case dob.lv.to_i
334 when 1
335 @num_exc={
336 t1: @num_exc[:t1] += 1,
337 t2: 0,
338 t3: 0,
339 t4: 0
340 }
341 Mx[:segname_prefix_auto_num_other] + '_' \
342 + @num_exc[:t1].to_s
343 when 2
344 @num_exc={
345 t1: @num_exc[:t1],
346 t2: @num_exc[:t2] += 1,
347 t3: 0,
348 t4: 0
349 }
350 Mx[:segname_prefix_auto_num_other] + '_' \
351 + @num_exc[:t1].to_s + '_' \
352 + @num_exc[:t2].to_s
353 when 3
354 @num_exc={
355 t1: @num_exc[:t1],
356 t2: @num_exc[:t2],
357 t3: @num_exc[:t3] += 1,
358 t4: 0
359 }
360 Mx[:segname_prefix_auto_num_other] + '_' \
361 + @num_exc[:t1].to_s + '_' \
362 + @num_exc[:t2].to_s + '_' \
363 + @num_exc[:t3].to_s
364 when 4
365 @num_exc[:t4] += 1
366 @num_exc={
367 t1: @num_exc[:t1],
368 t2: @num_exc[:t2],
369 t3: @num_exc[:t3],
370 t4: @num_exc[:t4] += 1
371 }
372 Mx[:segname_prefix_auto_num_other] + '_' \
373 + @num_exc[:t1].to_s + '_' \
374 + @num_exc[:t2].to_s + '_' \
375 + @num_exc[:t3].to_s + '_' \
376 + @num_exc[:t4].to_s
377 end
378 end
379 def check_that_seg_names_are_unique(chosen_seg_names_,chosen_seg_name,type,md,dob)
380 begin
381 chosen_seg_names_ << chosen_seg_name
382 chosen_seg_names_=chosen_seg_names(chosen_seg_names_,chosen_seg_name,dob,md,type)
383 if chosen_seg_names_.compact.uniq.length \
384 == chosen_seg_names_.compact.length
385 #check that all auto given seg names are unique
386 chosen_seg_names_=chosen_seg_names(chosen_seg_names_,chosen_seg_name,dob,md,type)
387 chosen_seg_name
388 else
389 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).
390 mark(
391 "duplicated auto segment name: #{type} #{chosen_seg_name}\n" \
392 + "#{chosen_seg_names_}\n" \
393 + " manually name level 1 segments '1~given_name'\n" \
394 + 'filename: ' + md.fns + "\n" \
395 + 'heading text: "' + dob.obj + '"' + "\n" \
396 + 'duplication: "' + chosen_seg_name + '" (level: ' + dob.lv + '; numbering type: ' + type.to_s + ')'
397 )
398 chosen_seg_name=auto_numbering_exceptions(chosen_seg_names_,md,dob)
399 check_that_seg_names_are_unique(chosen_seg_names_,chosen_seg_name,:exception,md,dob)
400 end
401 rescue
402 end
403 end
404 def auto_seg_name(possible_seg_name,heading_num_is,dob,type)
405 prefix=case type
406 when :auto then Mx[:segname_prefix_auto_num_provide]
407 when :extract then Mx[:segname_prefix_auto_num_extract]
408 else '_'*dob.lv.to_i #should not occur
409 end
410 if possible_seg_name =~/^[0-9]+?\.$/m #!~/[.,:-]+/
411 possible_seg_name=possible_seg_name.
412 gsub(/\.$/,'')
413 end
414 @chosen_seg_name=
415 if dob.lv=='4' \
416 and possible_seg_name.to_s =~/^[0-9]+(?:[.,:-][0-9]){3}/m
417 possible_seg_name=possible_seg_name.to_s.
418 gsub(/(?:[:,-]|\W)/,'.').
419 gsub(/\.$/,'')
420 prefix + possible_seg_name
421 elsif dob.lv=='3' \
422 and possible_seg_name.to_s =~/^[0-9]+(?:[.,:-][0-9]){2}/m
423 possible_seg_name=possible_seg_name.to_s.
424 gsub(/(?:[:,-]|\W)/,'.').
425 gsub(/\.$/,'')
426 prefix + possible_seg_name
427 elsif dob.lv=='2' \
428 and possible_seg_name.to_s =~/^[0-9]+(?:[.,:-][0-9]){1}/m
429 possible_seg_name=possible_seg_name.to_s.
430 gsub(/(?:[:,-]|\W)/,'.').
431 gsub(/\.$/,'')
432 prefix + possible_seg_name
433 elsif dob.lv=='1' \
434 and possible_seg_name.to_s =~/^[0-9]+[:,-]?$/m
435 if possible_seg_name.to_i <= heading_num_is.to_i
436 prefix + leading_zeros_fixed_width_number(possible_seg_name)
437 else
438 possible_seg_name=possible_seg_name.to_s.
439 gsub(/(?:[:,-]|\W)/,'.').
440 gsub(/\.$/,'')
441 prefix + possible_seg_name
442 end
443 else
444 @chosen_seg_name=auto_numbering_exceptions(@chosen_seg_names,md,dob)
445 end
446 check_that_seg_names_are_unique(@chosen_seg_names,@chosen_seg_name,type,@md,dob)
447 end
448 def set_name_and_tags(dob,possible_seg_name)
449 if @md.seg_names.is_a?(Array) \
450 and not @md.seg_names.include?(possible_seg_name)
451 dob.name=possible_seg_name
452 dob.tags=set_tags(dob.tags,dob.name)
453 @md.seg_names << possible_seg_name
454 elsif (@md.opt.act[:verbose_plus][:set]==:on \
455 or @md.opt.act[:maintenance][:set]==:on)
456 puts 'warn, there may be a conflicting numbering scheme'
457 end
458 end
459 def name_para_seg_filename(data) #segment naming, remaining
460 # paragraph name/numbering rules
461 # manual naming overrides, manual naming may be
462 # alpha-numeric characters mixed,
463 # numeric only (a number), if
464 # all segments have been named,
465 # the numbers used are over 1000 or
466 # it is not minded that auto-numbering uses a funny scheme for naming segments (not yet implemented)
467 # [for now a warning is printed for such documents on use of maintenance or very-verbose flag]
468 # auto-naming takes the form of giving numbers to segments
469 # the rules for which are as follows
470 # if the title/heading text starts with a numeric, then that is used (1 3.1 3rd etc.)
471 # otherwise the level 4 segment number from the embedded document structure info is used
472 # if there is none a sequential number is designated, preceded by an underscore
473 @tuned_file,@unique_auto_name=[],[]
474 tags={}
475 @art_filename_auto=0
476 @counter=1
477 if not @md.seg_autoname_safe \
478 and (@md.opt.act[:verbose_plus][:set]==:on \
479 || @md.opt.act[:maintenance][:set]==:on)
480 puts 'manual segment names, numbers used as names, risk warning (segmented html)'
481 end
482 ocn_html_seg=[]
483 @num_exc={ t1: 0, t2: 0, t3: 0, t4: 0 }
484 data.each do |dob|
485 if dob.is==:heading \
486 && dob.ln \
487 and dob.ln.to_s =~/^[4-7]/
488 heading_num_is=/^\d+:(\d+);\d/m.match(dob.node)[1]
489 if dob.ln==4 \
490 and not dob.name \
491 and not @md.set_heading_seg
492 @md.set_heading_seg=true
493 end
494 if dob.name !~/^\S+/ \
495 and dob.ln.to_s =~/^[5-7]/ \
496 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9])+)/m
497 #heading starts with a recognised numeric
498 #or word followed by a recognised numeric construct,
499 #use that as name
500 if dob.ln==7 \
501 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9]){3})/m
502 possible_seg_name=$1.
503 gsub(/(?:[:,-]|\W)/,'.').
504 gsub(/\.$/,'')
505 possible_seg_name=
506 auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
507 set_name_and_tags(dob,possible_seg_name)
508 elsif dob.ln==6 \
509 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9]){2})/m
510 possible_seg_name=$1.
511 gsub(/(?:[:,-]|\W)/,'.').
512 gsub(/\.$/,'')
513 possible_seg_name=
514 auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
515 set_name_and_tags(dob,possible_seg_name)
516 elsif dob.ln==5 \
517 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9]){1})/m
518 possible_seg_name=$1.
519 gsub(/(?:[:,-]|\W)/,'.').
520 gsub(/\.$/,'')
521 possible_seg_name=
522 auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
523 set_name_and_tags(dob,possible_seg_name)
524 end
525 end
526 if dob.ln==4
527 if dob.name !~/^\S+/ \
528 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+)/m
529 #heading starts with a recognised numeric
530 #or word followed by a recognised numeric construct,
531 #use that as name
532 possible_seg_name=$1
533 possible_seg_name=
534 auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
535 set_name_and_tags(dob,possible_seg_name)
536 end
537 if dob.name
538 #extract segment name from embedded document structure info
539 if @md.seg_names.is_a?(Array) \
540 and not @md.seg_names.include?(dob.name)
541 dob.tags=set_tags(dob.tags,dob.name)
542 @md.seg_names << dob.name
543 end
544 else
545 #if no segment name,
546 #provide a numerical one
547 @art_filename_auto+=1
548 possible_seg_name=
549 auto_seg_name(@art_filename_auto,heading_num_is,dob,:auto)
550 if @md.seg_names.is_a?(Array) \
551 and not @md.seg_names.include?(possible_seg_name)
552 dob.name=possible_seg_name
553 dob.tags=set_tags(dob.tags,dob.name)
554 @md.seg_names << possible_seg_name
555 else puts 'segment name (numbering) error'
556 end
557 end
558 if not dob.name #should not occur
559 puts "e r r o r -\t#{__FILE__}::#{__LINE__}\n#{dob.inspect}"
560 end
561 end
562 end
563 if (dob.is ==:heading \
564 || dob.is ==:heading_insert) \
565 && dob.ln==4
566 @seg=dob.name
567 end
568 @tuned_file << if dob.is==:heading \
569 && (@md.pagenew || @md.pagebreak || @md.pageline)
570 m=dob.ln.to_s
571 dob_tmp=[]
572 if @md.pagenew.inspect =~/#{m}/
573 dob_tmp <<
574 SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) <<
575 dob
576 elsif @md.pagebreak.inspect =~/#{m}/
577 dob_tmp <<
578 SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) <<
579 dob
580 elsif @md.pageline.inspect =~/#{m}/
581 dob_tmp <<
582 SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) <<
583 dob
584 end
585 unless dob_tmp.length > 0; dob
586 else dob_tmp
587 end
588 else dob
589 end
590 if defined? dob.ocn \
591 and dob.ocn
592 @segname=((dob.is==:heading || dob.is==:heading_insert) && dob.ln==4 && (defined? dob.name)) \
593 ? (dob.name)
594 : @segname
595 tags["#{dob.ocn}"]={ segname: @segname }
596 ocn_html_seg[dob.ocn]=if (dob.is==:heading || dob.is==:heading_insert)
597 if dob.ln =~/[0-3]/
598 {
599 seg: nil,
600 level: dob.ln,
601 }
602 #elsif dob.ln =~/[4-6]/
603 else
604 {
605 seg: @seg,
606 level: dob.ln,
607 }
608 end
609 else
610 {
611 seg: @seg,
612 level: nil,
613 }
614 end
615 end
616 dob.tags=dob.tags.uniq if defined? dob.tags
617 if defined? dob.tags \
618 and dob.tags.length > 0
619 #@segname=((dob.is=='heading'|| dob.is=='heading_insert') && dob.ln==4 && (defined? dob.name)) \
620 #? (dob.name) \
621 #: @segname
622 dob.tags.each do |y|
623 tags[y]={ ocn: dob.ocn.to_s, segname: @segname }
624 end
625 end
626 dob
627 end
628 ocn_html_seg.each_with_index do |ocn,i|
629 if ocn \
630 and ocn[:level].to_s=~/[1-3]/
631 (1..4).each do |x|
632 if ocn_html_seg[i+x] \
633 and ocn_html_seg[i+x][:level]==4
634 ocn[:seg]=ocn_html_seg[i+x][:seg]
635 end
636 end
637 end
638 end
639 if @md.seg_names.length > 0
640 @md.set_heading_seg=true
641 end
642 tuned_file=@tuned_file.flatten
643 [tuned_file,tags,ocn_html_seg]
644 end
645 def set_heading_top(data) #% make sure no false positives
646 unless @md.set_heading_top
647 if (@md.opt.act[:verbose_plus][:set]==:on \
648 or @md.opt.act[:maintenance][:set]==:on)
649 puts "\tdocument contains no top level heading, (will have to manufacture one)"
650 end
651 @tuned_file=[]
652 data.each do |t_o|
653 unless @md.set_heading_top
654 if t_o !~/^(?:#{Rx[:meta]}|@\S+:)\s/m \
655 and t_o !~/\A\s*\Z/m
656 @md.set_heading_top=true
657 if defined? @md.title \
658 and @md.title \
659 and defined? @md.title.full \
660 and defined? @md.creator \
661 and @md.creator
662 head=@md.title.main \
663 ? ([@lv='1',@obj=@md.title.main])
664 : ([@lv='1',@obj='[no title provided]'])
665 @tuned_file << head
666 end
667 end
668 end
669 @tuned_file << t_o
670 end
671 @tuned_file=@tuned_file.flatten
672 end
673 end
674 def set_heading_seg(data) #% make sure no false positives
675 unless @md.set_heading_seg
676 if (@md.opt.act[:verbose_plus][:set]==:on \
677 or @md.opt.act[:maintenance][:set]==:on)
678 puts "\tdocument contains no segment level, (will have to manufacture one)"
679 end
680 @tuned_file=[]
681 data.each do |dob|
682 unless @md.set_heading_seg
683 if defined? dob.ln and dob.ln.to_s !~/^[0-3]/m \
684 and dob.obj !~/\A\s*\Z/m \
685 and dob.is !=:layout
686 @md.set_heading_seg=true
687 head=@md.title.main \
688 ? (dob.ln,dob.name,dob.obj=4,'seg',@md.title.main)
689 : (dob.ln,dob.name,dob.obj=4,'seg','[segment]')
690 @tuned_file << head
691 end
692 end
693 @tuned_file << dob
694 end
695 @tuned_file=@tuned_file.flatten
696 end
697 end
698 def set_header_title(data) #% make sure no false positives
699 unless @md.set_header_title
700 if (@md.opt.act[:verbose_plus][:set]==:on \
701 or @md.opt.act[:maintenance][:set]==:on)
702 puts "\t no document title provided, (will have to manufacture one)"
703 end
704 @tuned_file=[]
705 data.each do |t_o|
706 unless @md.set_header_title
707 if t_o !~/^%{1,2}\s/m \
708 and t_o !~/\A\s*\Z/m
709 @tuned_file <<
710 "#{Mx[:meta_o]}title#{Mx[:meta_c]} #{@md.heading_seg_first}"
711 @md.title.main=@md.heading_seg_first
712 @md.set_header_title=true
713 end
714 end
715 @tuned_file << t_o
716 end
717 @tuned_file=@tuned_file.flatten
718 end
719 end
720 end
721 end
722 __END__