From 6fd685918309318549009821d73d87d85c558017 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 5 Sep 2013 23:45:58 -0400 Subject: v5: dal, objects, store book index as hash (simplify downstream processing) --- lib/sisu/v5/dal_doc_str.rb | 53 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'lib/sisu/v5/dal_doc_str.rb') diff --git a/lib/sisu/v5/dal_doc_str.rb b/lib/sisu/v5/dal_doc_str.rb index 83493c48..5b6c03bf 100644 --- a/lib/sisu/v5/dal_doc_str.rb +++ b/lib/sisu/v5/dal_doc_str.rb @@ -168,6 +168,54 @@ module SiSU_DAL_DocumentStructureExtract end [str,tags] end + def rgx_idx_ocn_seg + @rgx_idx_ocn_seg=/(.+?)\s*[+](\d+)/ + end + def construct_idx_array_and_hash(idxraw) + idx_array_raw=idxraw.scan(/[^;]+/) + idx_hash,idx_array,idx_lst={},[],[] + idx_array_raw.each do |idx| + idx_lst=case idx + when /\S+?\s*:/ + idx_couplet_tmp=[] + idx_couplet=idx.scan(/\s*[^:]+\s*/) + if idx_couplet[1] =~/[|]/ + idx_couplet_tmp << idx_couplet[0] << idx_couplet[1].scan(/\s*[^|]+\s*/) + else + idx_couplet_tmp << idx_couplet[0] << [idx_couplet[1]] + end + idx_couplet=idx_couplet_tmp + else [idx] + end + term_nodes=[] + idx_lst.each do |term_node| + case term_node + when String + term_node=term_node[0].chr.capitalize + term_node[1,term_node.length] + term_node=(term_node =~/.+?[+]\d+/) \ + ? term_node + : (term_node + '+0') + term_nodes << term_node + @use,plus=rgx_idx_ocn_seg.match(term_node)[1,2] + idx_hash[@use]={ sub: [], plus: plus } unless idx_hash[@use] and defined? idx_hash[@use] + when Array + subterm_nodes=[] + term_node.each do |subterm_node| + subterm_node=(subterm_node =~/.+?[+]\d+/) \ + ? subterm_node + : (subterm_node + '+0') + subterm_nodes << subterm_node + sub,sub_plus=rgx_idx_ocn_seg.match(subterm_node)[1,2] + idx_hash[@use]={ sub: [], plus: 0 } unless idx_hash[@use] and defined? idx_hash[@use] + idx_hash[@use][:sub] << {sub.strip => { plus: sub_plus }} + end + term_nodes << subterm_nodes + end + end + idx_array << term_nodes + end + { hash: idx_hash, array: idx_array } + end def identify_parts tuned_file=[] @tuned_block,@tuned_code=[],[] @@ -205,9 +253,10 @@ module SiSU_DAL_DocumentStructureExtract idx=if t_o=~/^=\{(.+)\}\s*$\Z/m; m=$1 m=m.split(/\n/).join(' '). gsub(/\s+([|:;])\s+/,'\1'). - gsub(/\s+([+])\s+/,'\1') + gsub(/\s+([+]\d+)\s+/,'\1') t_o=t_o.gsub(/\n=\{.+\}\s*$\Z/m,'') - m + idx_array_and_hash=construct_idx_array_and_hash(m) + idx_array_and_hash[:hash] else nil end end -- cgit v1.2.3