class Perseus::IndexXML
Attributes
corpus_by_edition[R]
corpus_by_groupname[R]
Public Instance Methods
by_edition()
click to toggle source
# File lib/perseus/index_xml.rb, line 10 def by_edition @corpus_by_edition ||= generate_structure_by_edition end
by_groupname()
click to toggle source
# File lib/perseus/index_xml.rb, line 7 def by_groupname @corpus_by_groupname ||= generate_structure_by_group end
generate_json_indeces()
click to toggle source
# File lib/perseus/index_xml.rb, line 89 def generate_json_indeces puts "Generating index by groupname" File.write(Perseus::CTS_BY_GROUP_JSON_FILE, JSON.pretty_generate(by_groupname)) puts "Generating index by edition" File.write(Perseus::ALL_EDITIONS_JSON, JSON.pretty_generate(by_edition)) puts "DONE".green end
generate_structure_by_edition()
click to toggle source
# File lib/perseus/index_xml.rb, line 35 def generate_structure_by_edition new_corpus = [] corpus_by_groupname.each do |t| groupname = t.groupname t.work.each_with_index do |work, i| begin # Check if we have many editions unless work["edition"].nil? if work.edition.kind_of?(Array) work.edition.each do |edition| new_corpus.push(CorpusHash.new({ groupname: groupname, language: work["xml:lang"], type: "edition", }).merge(edition)) end else new_corpus.push(CorpusHash.new({ groupname: groupname, language: work["xml:lang"], type: "edition", }).merge(work.edition)) end end # Check to see if we have translations unless work["translation"].nil? # Check if we have many translations if work.translation.kind_of?(Array) work.translation.each do |translation| new_corpus.push(CorpusHash.new({ groupname: groupname, language: translation["xml:lang"], type: "edition", }).merge(translation)) end else new_corpus.push(CorpusHash.new({ groupname: groupname, language: work.translation["xml:lang"], type: "edition", }).merge(work.translation)) end end rescue Exception => e puts "exception: #{e.message.red}" #puts "Stack trace: #{backtrace.map {|l| " #{l}\n"}.join}" puts "We were working in group: #{groupname.cyan} with the following data point:".green puts work.inspect.yellow end end end new_corpus end
generate_structure_by_group()
click to toggle source
# File lib/perseus/index_xml.rb, line 14 def generate_structure_by_group to_h["TextInventory"]["textgroup"].map do |text| CorpusHash.new text end.map do |t| tmp_hash = CorpusHash.new t.work.each_with_index do |work, i| if work.kind_of?(Array) # This is a special kind of array and we need to make # it adhere to our protocol tmp_hash[work[0]] = work[1] #puts work.inspect #puts tmp_hash if t.work.size - 1 == i t.work = [tmp_hash] tmp_hash = CorpusHash.new end end end && t end end