c&d: po4a (& git) revisited, revisit
[software/sisu] / lib / sisu / current / 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/current/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,fnx,process)
62 @md,@data,@fnx,@process=md,data,fnx,process
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 if @process==:complete
108 data,tags_map,ocn_html_seg_map=name_para_seg_filename(data)
109 end
110 data=set_heading_top(data) unless @md.set_heading_top
111 [data,tags_map,ocn_html_seg_map]
112 ensure
113 @@segments_count=0
114 end
115 end
116 def set_tags(tags,tag)
117 tags=if not tag.empty? \
118 and tag !~/^\d+$/
119 tag=tag.gsub(/[^a-z0-9._-]/,'')
120 [tag,tags].flatten
121 else tags
122 end
123 end
124 def number_plaintext_para(data)
125 @tuned_file=[]
126 data.each do |dob|
127 if (dob.of !=:block \
128 && dob.of !=:comment \
129 && dob.of !=:layout) \
130 && dob.ocn_ #and dob.obj !~ /#{Mx[:gr_o]}Th|#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}/ #FIX
131 dob.obj=dob.obj.gsub(/(.+)\n/,'\1 ') #messy, but idea is that tables should retain breaks
132 end
133 unless dob.obj.is_a?(Array)
134 dob.obj=dob.obj.gsub(/^\s+/,'').
135 gsub(/\s$/,"\n")
136 end
137 @tuned_file << dob
138 end
139 @tuned_file=@tuned_file.flatten
140 end
141 def number_sub_heading(dob,num,title_no)
142 unless dob.obj =~/\d+\.|(?:chapter|article|section|clause)\s+\d+/i #name selection arbitrary, fix
143 dob.obj=case dob.name
144 when /-/ then dob.obj.gsub(/^/,"#{title_no} ")
145 when /^#/ then dob.obj.gsub(/^/,"#{title_no} ")
146 when /^[a-z_\.]+/ then dob.obj.gsub(/^/,"#{title_no} ")
147 else
148 dob.name=title_no if dob.name=~/^$/ #where title contains title number
149 dob.obj.gsub(/^/,"#{title_no} ") if title_no =~/\d+/ #main, where title number is to be provided #watch changed placement
150 end
151 if @md.toc_lev_limit \
152 and @md.toc_lev_limit < num
153 dob.obj=dob.obj.gsub(/^/,'!_ ') #bold line, watch
154 end
155 end
156 dob
157 end
158 def heading_tag_clean(heading_tag)
159 heading_tag=heading_tag.
160 gsub(/[ ]+/,'_').
161 gsub(/["']/,'').
162 gsub(/[\/]/,'-').
163 gsub(/#{Mx[:fa_bold_o]}|#{Mx[:fa_bold_c]}/,'').
164 gsub(/#{Mx[:fa_italics_o]}|#{Mx[:fa_italics_c]}/,'').
165 gsub(/#{Mx[:fa_underscore_o]}|#{Mx[:fa_underscore_c]}/,'').
166 gsub(/#{Mx[:fa_cite_o]}|#{Mx[:fa_cite_c]}/,'').
167 gsub(/#{Mx[:fa_insert_o]}|#{Mx[:fa_insert_c]}/,'').
168 gsub(/#{Mx[:fa_strike_o]}|#{Mx[:fa_strike_c]}/,'').
169 gsub(/#{Mx[:fa_superscript_o]}|#{Mx[:fa_superscript_c]}/,'').
170 gsub(/#{Mx[:fa_subscript_o]}|#{Mx[:fa_subscript_c]}/,'').
171 gsub(/#{Mx[:fa_hilite_o]}|#{Mx[:fa_hilite_c]}/,'').
172 gsub(/#{Mx[:gl_bullet]}/,'')
173 end
174 def auto_number_heading_ie_title(data) #also does some segment naming
175 @tuned_file=[]
176 if defined? @md.make.num_top \
177 and @md.make.num_top \
178 and @md.make.num_top !~/^$/
179 input||=@md.make.num_top
180 end
181 num_top=(input ? input.to_i : nil)
182 t_no1=t_no2=t_no3=0
183 if num_top
184 no1=num_top; no2=(num_top + 1); no3=(num_top + 2)
185 end
186 chapter_number_counter=0
187 data=data.compact
188 data.each do |dob| #@md.seg_names << [additions to segment names]
189 title_no=nil
190 if dob.is ==:heading \
191 && dob.autonum_ \
192 and defined? @md.make.num_top \
193 and @md.make.num_top !~/^$/
194 if dob.lv=='1' \
195 and dob.obj =~/^#\s|\s#(?:\s|$)/
196 chapter_number_counter +=1
197 dob.obj=dob.obj.gsub(/^#\s/,"#{chapter_number_counter} ").
198 gsub(/#([:,]?\s|[.]?$)/,"#{chapter_number_counter}\\1")
199 end
200 if dob.ln==no1
201 @subnumber=1
202 @subnumber=0 if dob.ln==no1
203 end
204 if dob.ln.to_s =~/^[0-6]/ \
205 and not dob.use_ ==:dummy \
206 and dob.obj !~/#{Mx[:fa_o]}(?:~#|-#)#{Mx[:fa_c]}/ # <-- fix
207 if dob.ln==no1
208 t_no1+=1; t_no2=0; t_no3=0
209 title_no="#{t_no1}"
210 if @md.seg_names.is_a?(Array) \
211 and not @md.seg_names.include?(title_no)
212 if dob.ln==no1
213 dob.name="#{title_no}" if not dob.name
214 dob.tags=set_tags(dob.tags,title_no)
215 tag=dob.obj.
216 gsub(/(Article|Clause|Section|Chapter)\s+/,
217 "\\1_#{title_no}").
218 downcase
219 tag=heading_tag_clean(tag)
220 dob.tags=set_tags(dob.tags,tag)
221 dob.obj=(dob.obj =~/(Article|Clause|Section)\s+/) \
222 ? (dob.obj.gsub(/(Article|Clause|Section)\s+/,"\\1 #{title_no} "))
223 : (dob.obj.gsub(/^/,"#{title_no}. ")) #fix stop later
224 end
225 if dob.ln !=no1 \
226 and dob.obj =~/^[\d.]+\s/ #fix -> if the title starts with a numbering scheme, do not auto-number, review
227 dob.name ="#{title_no}" if not dob.name
228 dob.tags=set_tags(dob.tags,title_no)
229 dob.obj=dob.obj.gsub(/^/,"#{title_no}. ")
230 end
231 @md.seg_names << title_no
232 end
233 if dob.ln!=no1 \
234 and dob.name!~/^[a-z_\.]+$/ \
235 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
236 dob.tags=set_tags(dob.tags,title_no)
237 dob.obj=dob.obj.gsub(/^/i,"#{title_no}. ")
238 end
239 end
240 if dob.ln==no1 #watch because here you change dob.name
241 dob.tags=set_tags(dob.tags,"h#{title_no}")
242 end
243 if dob.ln==no2 #watch because here you change dob.name
244 t_no2+=1; t_no3=0
245 title_no="#{t_no1}.#{t_no2}"
246 dob.tags=set_tags(dob.tags,"h#{title_no}")
247 dob=number_sub_heading(dob,no2,title_no)
248 end
249 if dob.ln==no3 #watch because here you change dob.name
250 t_no3+=1
251 title_no="#{t_no1}.#{t_no2}.#{t_no3}"
252 dob.tags=set_tags(dob.tags,"h#{title_no}")
253 dob=number_sub_heading(dob,no3,title_no)
254 end
255 elsif dob.ln.to_s =~/^[0-6]/ \
256 and dob.name =~ /^[\w-]+-/ # endnotes, watch2005# endnotes, watch2005
257 dob.tags=set_tags(dob.tags,dob.name)
258 dob.name.gsub(/^([a-z_\.]+)-$/,'\1')
259 end
260 elsif dob.is ==:heading \
261 and dob.autonum_ \
262 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
263 #here lies a bug, as is nil when run from -Dv --update, FIX
264 if (dob.name.nil? or dob.name.empty?) \
265 and dob.ln.to_s =~/^[0-9]/ \
266 and dob.obj =~ /^([\d\.]+)/ #risky (must be unique) consider output to 4~~\d instead of 4~\d
267 dob.name=$1
268 dob.tags=set_tags(dob.tags,dob.name)
269 end
270 if @md.toc_lev_limit
271 end
272 elsif defined? dob.name \
273 and dob.name
274 dob.tags=set_tags(dob.tags,dob.name)
275 end
276 dob.tags=dob.tags.uniq if defined? dob.tags
277 @tuned_file << dob
278 end
279 @tuned_file=@tuned_file.flatten
280 end
281 def ocn(data) #and auto segment numbering increment
282 @tuned_file=SiSU_AO_DocumentStructureExtract::OCN.new(@md,data,@fnx,@process).ocn
283 @tuned_file
284 end
285 def xml(data)
286 @tuned_file=SiSU_AO_DocumentStructureExtract::XML.new(@md,data).dom
287 @tuned_file
288 end
289 def minor_numbering(data) #and auto segment numbering increment
290 @tuned_file=[]
291 number_small,letter_small=0,0
292 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 )
293 data.each do |dob|
294 if dob.of ==:heading \
295 || dob.of ==:heading_insert \
296 || dob.of ==:para \
297 || dob.of ==:block
298 if dob.is ==:heading \
299 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)
300 number_small,letter_small=0,0
301 elsif dob.is ==:para
302 if dob.obj =~/^#[ 1]/ \
303 and dob.obj !~/^#\s+(?:~#)?$/
304 letter_small=0
305 number_small=0 if dob.obj =~ /^#1/
306 number_small+=1
307 dob.obj=dob.obj.gsub(/^#[ 1]/,"#{number_small}. ")
308 end
309 if dob.obj =~/^_# /
310 dob.obj=dob.obj.gsub(/^_# /,"#{letter[letter_small]}. ")
311 dob.indent='1'
312 letter_small+=1
313 end
314 end
315 end
316 @tuned_file << dob
317 end
318 @tuned_file=@tuned_file.flatten
319 end
320 def leading_zeros_fixed_width_number(possible_seg_name)
321 if possible_seg_name.to_s =~/^([0-9]+?\.|[0-9]+)$/m #!~/[.,:-]+/
322 possible_seg_name=possible_seg_name.to_s.
323 gsub(/\.$/,'')
324 nl=possible_seg_name.to_s.length
325 zero='0'
326 zeros_fixed_width=number_of_segments?.to_s.length
327 zero_width=(zeros_fixed_width - nl)
328 zero_width == 0 \
329 ? possible_seg_name.to_s
330 : zero*zero_width +
331 possible_seg_name.to_s
332 end
333 end
334 def auto_numbering_exceptions(chosen_seg_names_,md,dob)
335 number_make=case dob.lv.to_i
336 when 1
337 @num_exc={
338 t1: @num_exc[:t1] += 1,
339 t2: 0,
340 t3: 0,
341 t4: 0
342 }
343 Mx[:segname_prefix_auto_num_other] + '_' \
344 + @num_exc[:t1].to_s
345 when 2
346 @num_exc={
347 t1: @num_exc[:t1],
348 t2: @num_exc[:t2] += 1,
349 t3: 0,
350 t4: 0
351 }
352 Mx[:segname_prefix_auto_num_other] + '_' \
353 + @num_exc[:t1].to_s + '_' \
354 + @num_exc[:t2].to_s
355 when 3
356 @num_exc={
357 t1: @num_exc[:t1],
358 t2: @num_exc[:t2],
359 t3: @num_exc[:t3] += 1,
360 t4: 0
361 }
362 Mx[:segname_prefix_auto_num_other] + '_' \
363 + @num_exc[:t1].to_s + '_' \
364 + @num_exc[:t2].to_s + '_' \
365 + @num_exc[:t3].to_s
366 when 4
367 @num_exc[:t4] += 1
368 @num_exc={
369 t1: @num_exc[:t1],
370 t2: @num_exc[:t2],
371 t3: @num_exc[:t3],
372 t4: @num_exc[:t4] += 1
373 }
374 Mx[:segname_prefix_auto_num_other] + '_' \
375 + @num_exc[:t1].to_s + '_' \
376 + @num_exc[:t2].to_s + '_' \
377 + @num_exc[:t3].to_s + '_' \
378 + @num_exc[:t4].to_s
379 end
380 end
381 def check_that_seg_names_are_unique(chosen_seg_names_,chosen_seg_name,type,md,dob)
382 begin
383 chosen_seg_names_ << chosen_seg_name
384 chosen_seg_names_=chosen_seg_names(chosen_seg_names_,chosen_seg_name,dob,md,type)
385 if chosen_seg_names_.compact.uniq.length \
386 == chosen_seg_names_.compact.length
387 #check that all auto given seg names are unique
388 chosen_seg_names_=chosen_seg_names(chosen_seg_names_,chosen_seg_name,dob,md,type)
389 chosen_seg_name
390 else
391 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).
392 mark(
393 "duplicated auto segment name: #{type} #{chosen_seg_name}\n" \
394 + "#{chosen_seg_names_}\n" \
395 + " manually name level 1 segments '1~given_name'\n" \
396 + 'filename: ' + md.fns + "\n" \
397 + 'heading text: "' + dob.obj + '"' + "\n" \
398 + 'duplication: "' + chosen_seg_name + '" (level: ' + dob.lv + '; numbering type: ' + type.to_s + ')'
399 )
400 chosen_seg_name=auto_numbering_exceptions(chosen_seg_names_,md,dob)
401 check_that_seg_names_are_unique(chosen_seg_names_,chosen_seg_name,:exception,md,dob)
402 end
403 rescue
404 end
405 end
406 def auto_seg_name(possible_seg_name,heading_num_is,dob,type)
407 prefix=case type
408 when :auto then Mx[:segname_prefix_auto_num_provide]
409 when :extract then Mx[:segname_prefix_auto_num_extract]
410 else '_'*dob.lv.to_i #should not occur
411 end
412 if possible_seg_name =~/^[0-9]+?\.$/m #!~/[.,:-]+/
413 possible_seg_name=possible_seg_name.
414 gsub(/\.$/,'')
415 end
416 @chosen_seg_name=
417 if dob.lv=='4' \
418 and possible_seg_name.to_s =~/^[0-9]+(?:[.,:-][0-9]){3}/m
419 possible_seg_name=possible_seg_name.to_s.
420 gsub(/(?:[:,-]|\W)/,'.').
421 gsub(/\.$/,'')
422 prefix + possible_seg_name
423 elsif dob.lv=='3' \
424 and possible_seg_name.to_s =~/^[0-9]+(?:[.,:-][0-9]){2}/m
425 possible_seg_name=possible_seg_name.to_s.
426 gsub(/(?:[:,-]|\W)/,'.').
427 gsub(/\.$/,'')
428 prefix + possible_seg_name
429 elsif dob.lv=='2' \
430 and possible_seg_name.to_s =~/^[0-9]+(?:[.,:-][0-9]){1}/m
431 possible_seg_name=possible_seg_name.to_s.
432 gsub(/(?:[:,-]|\W)/,'.').
433 gsub(/\.$/,'')
434 prefix + possible_seg_name
435 elsif dob.lv=='1' \
436 and possible_seg_name.to_s =~/^[0-9]+[:,-]?$/m
437 if possible_seg_name.to_i <= heading_num_is.to_i
438 prefix + leading_zeros_fixed_width_number(possible_seg_name)
439 else
440 possible_seg_name=possible_seg_name.to_s.
441 gsub(/(?:[:,-]|\W)/,'.').
442 gsub(/\.$/,'')
443 prefix + possible_seg_name
444 end
445 else
446 @chosen_seg_name=auto_numbering_exceptions(@chosen_seg_names,md,dob)
447 end
448 check_that_seg_names_are_unique(@chosen_seg_names,@chosen_seg_name,type,@md,dob)
449 end
450 def set_name_and_tags(dob,possible_seg_name)
451 if @md.seg_names.is_a?(Array) \
452 and not @md.seg_names.include?(possible_seg_name)
453 dob.name=possible_seg_name
454 dob.tags=set_tags(dob.tags,dob.name)
455 @md.seg_names << possible_seg_name
456 elsif (@md.opt.act[:verbose_plus][:set]==:on \
457 or @md.opt.act[:maintenance][:set]==:on)
458 puts 'warn, there may be a conflicting numbering scheme'
459 end
460 end
461 def name_para_seg_filename(data) #segment naming, remaining
462 # paragraph name/numbering rules
463 # manual naming overrides, manual naming may be
464 # alpha-numeric characters mixed,
465 # numeric only (a number), if
466 # all segments have been named,
467 # the numbers used are over 1000 or
468 # it is not minded that auto-numbering uses a funny scheme for naming segments (not yet implemented)
469 # [for now a warning is printed for such documents on use of maintenance or very-verbose flag]
470 # auto-naming takes the form of giving numbers to segments
471 # the rules for which are as follows
472 # if the title/heading text starts with a numeric, then that is used (1 3.1 3rd etc.)
473 # otherwise the level 4 segment number from the embedded document structure info is used
474 # if there is none a sequential number is designated, preceded by an underscore
475 @tuned_file,@unique_auto_name=[],[]
476 tags={}
477 @art_filename_auto=0
478 @counter=1
479 if not @md.seg_autoname_safe \
480 and (@md.opt.act[:verbose_plus][:set]==:on \
481 || @md.opt.act[:maintenance][:set]==:on)
482 puts 'manual segment names, numbers used as names, risk warning (segmented html)'
483 end
484 ocn_html_seg=[]
485 @num_exc={ t1: 0, t2: 0, t3: 0, t4: 0 }
486 data.each do |dob|
487 if dob.is==:heading \
488 && dob.ln \
489 and dob.ln.to_s =~/^[4-7]/
490 heading_num_is=/^\d+:(\d+);\d/m.match(dob.node)[1]
491 if dob.ln==4 \
492 and not dob.name \
493 and not @md.set_heading_seg
494 @md.set_heading_seg=true
495 end
496 if dob.name !~/^\S+/ \
497 and dob.ln.to_s =~/^[5-7]/ \
498 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9])+)/m
499 #heading starts with a recognised numeric
500 #or word followed by a recognised numeric construct,
501 #use that as name
502 if dob.ln==7 \
503 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9]){3})/m
504 possible_seg_name=$1.
505 gsub(/(?:[:,-]|\W)/,'.').
506 gsub(/\.$/,'')
507 possible_seg_name=
508 auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
509 set_name_and_tags(dob,possible_seg_name)
510 elsif dob.ln==6 \
511 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9]){2})/m
512 possible_seg_name=$1.
513 gsub(/(?:[:,-]|\W)/,'.').
514 gsub(/\.$/,'')
515 possible_seg_name=
516 auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
517 set_name_and_tags(dob,possible_seg_name)
518 elsif dob.ln==5 \
519 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9]){1})/m
520 possible_seg_name=$1.
521 gsub(/(?:[:,-]|\W)/,'.').
522 gsub(/\.$/,'')
523 possible_seg_name=
524 auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
525 set_name_and_tags(dob,possible_seg_name)
526 end
527 end
528 if dob.ln==4
529 if dob.name !~/^\S+/ \
530 and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+)/m
531 #heading starts with a recognised numeric
532 #or word followed by a recognised numeric construct,
533 #use that as name
534 possible_seg_name=$1
535 possible_seg_name=
536 auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
537 set_name_and_tags(dob,possible_seg_name)
538 end
539 if dob.name
540 #extract segment name from embedded document structure info
541 if @md.seg_names.is_a?(Array) \
542 and not @md.seg_names.include?(dob.name)
543 dob.tags=set_tags(dob.tags,dob.name)
544 @md.seg_names << dob.name
545 end
546 else
547 #if no segment name,
548 #provide a numerical one
549 @art_filename_auto+=1
550 possible_seg_name=
551 auto_seg_name(@art_filename_auto,heading_num_is,dob,:auto)
552 if @md.seg_names.is_a?(Array) \
553 and not @md.seg_names.include?(possible_seg_name)
554 dob.name=possible_seg_name
555 dob.tags=set_tags(dob.tags,dob.name)
556 @md.seg_names << possible_seg_name
557 else puts 'segment name (numbering) error'
558 end
559 end
560 if not dob.name #should not occur
561 puts "e r r o r -\t#{__FILE__}::#{__LINE__}\n#{dob.inspect}"
562 end
563 end
564 end
565 if (dob.is ==:heading \
566 || dob.is ==:heading_insert) \
567 && dob.ln==4
568 @seg=dob.name
569 end
570 @tuned_file << if dob.is==:heading \
571 && (@md.pagenew || @md.pagebreak || @md.pageline)
572 m=dob.ln.to_s
573 dob_tmp=[]
574 if @md.pagenew.inspect =~/#{m}/
575 dob_tmp <<
576 SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) <<
577 dob
578 elsif @md.pagebreak.inspect =~/#{m}/
579 dob_tmp <<
580 SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) <<
581 dob
582 elsif @md.pageline.inspect =~/#{m}/
583 dob_tmp <<
584 SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) <<
585 dob
586 end
587 unless dob_tmp.length > 0; dob
588 else dob_tmp
589 end
590 else dob
591 end
592 if defined? dob.ocn \
593 and dob.ocn
594 @segname=((dob.is==:heading || dob.is==:heading_insert) && dob.ln==4 && (defined? dob.name)) \
595 ? (dob.name)
596 : @segname
597 tags["#{dob.ocn}"]={ segname: @segname }
598 ocn_html_seg[dob.ocn]=if (dob.is==:heading || dob.is==:heading_insert)
599 if dob.ln =~/[0-3]/
600 {
601 seg: nil,
602 level: dob.ln,
603 }
604 #elsif dob.ln =~/[4-6]/
605 else
606 {
607 seg: @seg,
608 level: dob.ln,
609 }
610 end
611 else
612 {
613 seg: @seg,
614 level: nil,
615 }
616 end
617 end
618 dob.tags=dob.tags.uniq if defined? dob.tags
619 if defined? dob.tags \
620 and dob.tags.length > 0
621 #@segname=((dob.is=='heading'|| dob.is=='heading_insert') && dob.ln==4 && (defined? dob.name)) \
622 #? (dob.name) \
623 #: @segname
624 dob.tags.each do |y|
625 tags[y]={ ocn: dob.ocn.to_s, segname: @segname }
626 end
627 end
628 dob
629 end
630 ocn_html_seg.each_with_index do |ocn,i|
631 if ocn \
632 and ocn[:level].to_s=~/[1-3]/
633 (1..4).each do |x|
634 if ocn_html_seg[i+x] \
635 and ocn_html_seg[i+x][:level]==4
636 ocn[:seg]=ocn_html_seg[i+x][:seg]
637 end
638 end
639 end
640 end
641 if @md.seg_names.length > 0
642 @md.set_heading_seg=true
643 end
644 tuned_file=@tuned_file.flatten
645 [tuned_file,tags,ocn_html_seg]
646 end
647 def set_heading_top(data) #% make sure no false positives
648 unless @md.set_heading_top
649 if (@md.opt.act[:verbose_plus][:set]==:on \
650 or @md.opt.act[:maintenance][:set]==:on)
651 puts "\tdocument contains no top level heading, (will have to manufacture one)"
652 end
653 @tuned_file=[]
654 data.each do |t_o|
655 unless @md.set_heading_top
656 if t_o !~/^(?:#{Rx[:meta]}|@\S+:)\s/m \
657 and t_o !~/\A\s*\Z/m
658 @md.set_heading_top=true
659 if defined? @md.title \
660 and @md.title \
661 and defined? @md.title.full \
662 and defined? @md.creator \
663 and @md.creator
664 head=@md.title.main \
665 ? ([@lv='1',@obj=@md.title.main])
666 : ([@lv='1',@obj='[no title provided]'])
667 @tuned_file << head
668 end
669 end
670 end
671 @tuned_file << t_o
672 end
673 @tuned_file=@tuned_file.flatten
674 end
675 end
676 def set_heading_seg(data) #% make sure no false positives
677 unless @md.set_heading_seg
678 if (@md.opt.act[:verbose_plus][:set]==:on \
679 or @md.opt.act[:maintenance][:set]==:on)
680 puts "\tdocument contains no segment level, (will have to manufacture one)"
681 end
682 @tuned_file=[]
683 data.each do |dob|
684 unless @md.set_heading_seg
685 if defined? dob.ln and dob.ln.to_s !~/^[0-3]/m \
686 and dob.obj !~/\A\s*\Z/m \
687 and dob.is !=:layout
688 @md.set_heading_seg=true
689 head=@md.title.main \
690 ? (dob.ln,dob.name,dob.obj=4,'seg',@md.title.main)
691 : (dob.ln,dob.name,dob.obj=4,'seg','[segment]')
692 @tuned_file << head
693 end
694 end
695 @tuned_file << dob
696 end
697 @tuned_file=@tuned_file.flatten
698 end
699 end
700 def set_header_title(data) #% make sure no false positives
701 unless @md.set_header_title
702 if (@md.opt.act[:verbose_plus][:set]==:on \
703 or @md.opt.act[:maintenance][:set]==:on)
704 puts "\t no document title provided, (will have to manufacture one)"
705 end
706 @tuned_file=[]
707 data.each do |t_o|
708 unless @md.set_header_title
709 if t_o !~/^%{1,2}\s/m \
710 and t_o !~/\A\s*\Z/m
711 @tuned_file <<
712 "#{Mx[:meta_o]}title#{Mx[:meta_c]} #{@md.heading_seg_first}"
713 @md.title.main=@md.heading_seg_first
714 @md.set_header_title=true
715 end
716 end
717 @tuned_file << t_o
718 end
719 @tuned_file=@tuned_file.flatten
720 end
721 end
722 end
723 end
724 __END__