class SiSU_AO_Appendices::Citations
Public Class Methods
new(md='',data='')
click to toggle source
# File lib/sisu/ao_appendices.rb, line 414 def initialize(md='',data='') @md,@data=md,data #@biblio=[] end
Public Instance Methods
citation_detail(citations)
click to toggle source
# File lib/sisu/ao_appendices.rb, line 494 def citation_detail(citations) #could be useful, keep ... extract shortref bibahash=[] number=0 missed=0 citations.select do |b| z=if b =~citations_regex.authors_year_title_publication_editor_pages c=citations_regex.authors_year_title_publication_editor_pages.match(b) { is: :article, author_raw: c[:authors], year: c[:year], title: c[:title], publication: c[:publication], editor: c[:editor], } elsif b =~citations_regex.authors_title_publication_year_editor_pages c=citations_regex.authors_title_publication_year_editor_pages.match(b) { is: :article, author_raw: c[:authors], year: c[:year], title: c[:title], publication: c[:publication], editor: c[:editor], } elsif b =~citations_regex.authors_title_publication_editor_year_pages c=citations_regex.authors_title_publication_editor_year_pages.match(b) { is: :article, author_raw: c[:authors], year: c[:year], title: c[:title], publication: c[:publication], editor: c[:editor], } elsif b =~citations_regex.authors_title_publication_editor_pages_year c=citations_regex.authors_title_publication_editor_pages_year.match(b) { is: :article, author_raw: c[:authors], year: c[:year], title: c[:title], publication: c[:publication], editor: c[:editor], } elsif b =~citations_regex.authors_year_title_publication_pages c=citations_regex.authors_year_title_publication_pages.match(b) { is: :article, author_raw: c[:authors], year: c[:year], title: c[:title], publication: c[:publication], } elsif b =~citations_regex.authors_title_publication_year_pages c=citations_regex.authors_title_publication_year_pages.match(b) { is: :article, author_raw: c[:authors], year: c[:year], title: c[:title], publication: c[:publication], } elsif b =~citations_regex.authors_year_publication_pages c=citations_regex.authors_year_publication_pages.match(b) { is: :book, author_raw: c[:authors], year: c[:year], publication: c[:publication], } elsif b =~citations_regex.authors_publication_year_pages c=citations_regex.authors_publication_year_pages.match(b) { is: :book, author_raw: c[:authors], year: c[:year], publication: c[:publication], } else b end if not z.is_a?(NilClass) \ and z.is_a?(Hash) \ and z[:author_raw].length > 0 z[:author_arr]=z[:author_raw].split(/;\s*/) z[:author]=z[:author_arr].map do |author| author.gsub(/(.+?),\s+(.+)/,'\2 \1').strip end.join(', ').strip if @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on number +=1 if z.is_a?(Hash) missed +=1 if z.is_a?(String) (z.is_a?(Hash)) \ ? (p '[' + number.to_s + '] ' + z.to_s) : (p '<' + missed.to_s + '> ' + z.to_s) end end bibahash << z if z.is_a?(Hash) end bibahash=sort_bibliography_array_by_author_year(bibahash.compact) bibahash end
citations_regex()
click to toggle source
# File lib/sisu/ao_appendices.rb, line 428 def citations_regex def pages_pattern %r{(?:[,.:]?\s+(?:p{1,2}\.?\s+)?(?:\d+--?\d+)[,.]?\s+)?} end def editor_pattern %r{(?<editor>(?:editor|edited by)\s+.+?)} end def year_pattern %r{[(\[]?(?<year>\d{4})[\])]?[.,]?} end def authors_year_title_publication_editor_pages /(?<authors>.+?)\s+#{year_pattern}\s+"(?<title>.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?<publication>.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+#{editor_pattern}#{pages_pattern}/m # note ed. is usually edition rather than editor end def authors_title_publication_year_editor_pages /(?<authors>.+?)\s+"(?<title>.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?<publication>.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+#{year_pattern}\s+#{editor_pattern}#{pages_pattern}/m # note ed. is usually edition rather than editor end def authors_title_publication_editor_year_pages ### /(?<authors>.+?)\s+"(?<title>.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?<publication>.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+ed.\s+#{editor_pattern}#{year_pattern}#{pages_pattern}/m # note ed. is usually edition rather than editor end def authors_title_publication_editor_pages_year ### /(?<authors>.+?)\s+"(?<title>.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?<publication>.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+#{editor_pattern}#{pages_pattern}#{year_pattern}/m # note ed. is usually edition rather than editor end def authors_year_title_publication_pages /(?<authors>.+?)\s+#{year_pattern}\s+"(?<title>.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?<publication>.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})[,.;]?#{pages_pattern}/m end def authors_title_publication_year_pages /(?<authors>.+?)\s+"(?<title>.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?<publication>.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+#{year_pattern}\s+#{pages_pattern}/m end def authors_title_publication_pages_year ### /(?<authors>.+?)\s+"(?<title>.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?<publication>.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})#{pages_pattern}#{year_pattern}/m end def authors_year_publication_pages /(?<authors>.+?)\s+#{year_pattern}\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?<publication>.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})#{pages_pattern}/m end def authors_publication_year_pages /(?<authors>.+?)\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?<publication>.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})[,.;]?\s+(?<publisher>.+?)?#{year_pattern}#{pages_pattern}[.;]?/m end self end
citations_scan(data)
click to toggle source
# File lib/sisu/ao_appendices.rb, line 596 def citations_scan(data) citations=[] #short_ref=[] tuned_file = data.compact.select do |dob| if dob.is !=:meta \ && dob.is !=:comment \ && dob.is !=:code \ && dob.is !=:table if dob.obj =~/\.:.+?:\./ citations << dob.obj.scan(/\.:\s*(.+?)\s*:\./m) #short_ref << dob.obj.scan(/\.:\s+(.+?)\s+::([^:]+)::\./m) #look at later ##short_ref << dob.obj.scan(/\.:\s+(.+?)\s+::(.+?)::\./m) #look at later #short_ref << dob.obj.scan(/\.:\s*(.+?)\s*(::(.+?):)?:\./m) #look at later citations=citations.flatten.compact dob.obj=dob.obj. #remove citations delimiter & helpers from text gsub(/\.:|:\./,'') end end dob if dob.is_a?(Object) end #bib=long_and_short_ref?(citations) #could be useful, keep ... extract shortref citations=citation_detail(citations) [tuned_file,citations] end
editor_pattern()
click to toggle source
# File lib/sisu/ao_appendices.rb, line 432 def editor_pattern %r{(?<editor>(?:editor|edited by)\s+.+?)} end
long_and_short_ref?(citations)
click to toggle source
# File lib/sisu/ao_appendices.rb, line 481 def long_and_short_ref?(citations) #could be useful, keep ... ectract shortref citations.each.map do |b| if b =~ /^.+\s+::.+?:$/ c=/^(?<citation>.+?)\s+::(?<shortref>.+?):$/.match(b) { citation: c[:citation], shortref: c[:shortref], c[:shortref].to_s => c[:citation] } else { citation: b } end end end
pages_pattern()
click to toggle source
# File lib/sisu/ao_appendices.rb, line 429 def pages_pattern %r{(?:[,.:]?\s+(?:p{1,2}\.?\s+)?(?:\d+--?\d+)[,.]?\s+)?} end
songsheet()
click to toggle source
# File lib/sisu/ao_appendices.rb, line 418 def songsheet tuned_file,citations=citations_scan(@data) [tuned_file,citations] end
year_pattern()
click to toggle source
# File lib/sisu/ao_appendices.rb, line 435 def year_pattern %r{[(\[]?(?<year>\d{4})[\])]?[.,]?} end