comparative-mythology / scripts /export_to_huggingface.rb
itslenoid's picture
Initial release of Syncretica comparative mythology dataset
f1d3e0b verified
Raw History Blame Contribute Delete
3.04 kB
# frozen_string_literal: true
require "json"
require "fileutils"
output_dir = Rails.root.join("huggingface-dataset", "data")
FileUtils.mkdir_p(output_dir)
puts "Exporting Pantheons, Gods, and Myths from Syncretica to #{output_dir}..."
# 1. Pantheons
pantheons = Pantheon.ordered.to_a
gods_count_by_pantheon = God.group(:pantheon_id).count
pantheon_rows = pantheons.map do |p|
{
pantheon_id: p.id,
name: p.name,
description: p.description,
gods_count: gods_count_by_pantheon[p.id] || 0,
created_at: p.created_at.iso8601,
updated_at: p.updated_at.iso8601
}
end
File.open(output_dir.join("pantheons.jsonl"), "w") do |f|
pantheon_rows.each { |row| f.puts(JSON.generate(row)) }
end
puts "Exported #{pantheon_rows.size} pantheons to pantheons.jsonl"
# 2. Gods
gods = God.includes(:pantheon).order(:id).to_a
god_rows = gods.map do |g|
{
god_id: g.id,
pantheon_id: g.pantheon_id,
pantheon_name: g.pantheon.name,
name: g.name,
description: g.description,
themes: g.themes,
embedding_model: g.embedding_model,
embedding: g.embedding,
created_at: g.created_at.iso8601,
updated_at: g.updated_at.iso8601
}
end
File.open(output_dir.join("gods.jsonl"), "w") do |f|
god_rows.each { |row| f.puts(JSON.generate(row)) }
end
puts "Exported #{god_rows.size} gods to gods.jsonl"
# 3. Myths
myths = Myth.includes(god: :pantheon).order(:id).to_a
myth_rows = myths.map do |m|
themes_list = (m.themes || {}).map { |title, desc| { "title" => title, "description" => desc } }
{
myth_id: m.id,
god_id: m.god_id,
god_name: m.god.name,
pantheon_id: m.god.pantheon_id,
pantheon_name: m.god.pantheon.name,
themes: themes_list,
themes_count: themes_list.size,
embedding_model: m.embedding_model,
embedding: m.embedding,
created_at: m.created_at.iso8601,
updated_at: m.updated_at.iso8601
}
end
File.open(output_dir.join("myths.jsonl"), "w") do |f|
myth_rows.each { |row| f.puts(JSON.generate(row)) }
end
puts "Exported #{myth_rows.size} myths to myths.jsonl"
# 4. Train (Unified Denormalized Pantheons -> Gods -> Myths)
myths_by_god_id = myths.index_by(&:god_id)
train_rows = gods.map do |g|
m = myths_by_god_id[g.id]
myth_themes_list = m ? (m.themes || {}).map { |title, desc| { "title" => title, "description" => desc } } : []
{
pantheon_id: g.pantheon_id,
pantheon_name: g.pantheon.name,
pantheon_description: g.pantheon.description,
god_id: g.id,
god_name: g.name,
god_description: g.description,
god_themes: g.themes,
god_embedding: g.embedding,
myth_id: m&.id,
myth_themes: myth_themes_list,
myth_themes_count: myth_themes_list.size,
myth_embedding: m&.embedding,
embedding_model: g.embedding_model || m&.embedding_model || "qwen3-embedding:0.6b"
}
end
File.open(output_dir.join("train.jsonl"), "w") do |f|
train_rows.each { |row| f.puts(JSON.generate(row)) }
end
puts "Exported #{train_rows.size} unified records to train.jsonl"
puts "JSONL export complete!"