Created
May 13, 2023 02:16
-
-
Save noqisofon/ad1bf28c875068e26339ef4abf40db7f to your computer and use it in GitHub Desktop.
( ノ╹◡◡╹)ノ てきとーな称号を 50 個くらい生成してくれるサイトのデータをカテゴリ分けして INSERT 文にしてくれると思われるすくりぷよ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my @championships = './championship000.tsv'.IO.lines; | |
my %classificated = classify { | |
when /['女皇帝' || '皇帝'] $/ { '皇帝' } | |
when /'内親王' $/ { '内親王' } | |
when /'親王' $/ { '親王' } | |
when /'法王' $/ { '法王' } | |
when /'上級王' $/ { '上級王' } | |
when /['王' || '女王' ] $/ { '王' } | |
when /['王子' || '王女' ] $/ { '王息' } | |
when /['大公' || '大公爵' ] $/ { '大公' } | |
when /'大司教' $/ { '大司教' } | |
when /'大主教' $/ { '大主教' } | |
when /'公爵' $/ { '公爵' } | |
when /['公子' || '公女' ] $/ { '公息' } | |
when /'選帝侯' $/ { '選帝侯' } | |
when /'宮中伯' $/ { '宮中伯' } | |
when /'辺境伯' $/ { '辺境伯' } | |
when /'方伯' $/ { '方伯' } | |
when /'侯爵' $/ { '侯爵' } | |
when /'城伯' $/ { '城伯' } | |
when /'伯爵' $/ { '伯爵' } | |
when /'子爵' $/ { '子爵' } | |
when /'男爵' $/ { '男爵' } | |
when /'首長' $/ { '首長' } | |
when /'国主' $/ { '国主' } | |
when /'領主' $/ { '領主' } | |
when /'教皇' $/ { '教皇' } | |
when /'司教' $/ { '司教' } | |
when /'主教' $/ { '主教' } | |
when /'修道院長' $/ { '修道院長' } | |
when /'騎士団長' $/ { '騎士団長' } | |
when /'郷士' $/ { '郷士' } | |
default { '' } | |
}, @championships; | |
my @sorted-championship-names = %classificated.keys.sort; | |
{ | |
my $championshop_kinds = './championship_kinds000.insert.sql'.IO.open(:w); | |
$championshop_kinds.put: 'INSERT INTO "championship_kinds" ( "champion_kind_name" ) VALUES'; | |
for @sorted-championship-names.kv -> $key, $value { | |
$championshop_kinds.print: " ( '{$value}' )"; | |
if $key < %classificated.keys.elems - 1 { | |
$championshop_kinds.print: ','; | |
} | |
$championshop_kinds.put: ''; | |
} | |
$championshop_kinds.put: ';'; | |
LEAVE $championshop_kinds.close; | |
} | |
{ | |
my $championships = './championships000.insert.sql'.IO.open(:w); | |
$championships.put: 'INSERT INTO "championships" ( "champion_kind_id", "name" ) VALUES'; | |
for %classificated.kv -> $key, @values { | |
# `.grep` は `List` を返すので、リストの最初の要素を取り出さないといけない。 | |
my $kind-index = @sorted-championship-names.grep($key, :k).first + 1; | |
for @values.kv -> $index, $value { | |
$championships.print: " ( {$kind-index}, '{$value}' )"; | |
$championships.put: ','; # 横着しちゃったので、最後のコンマを手動で削除しないといけない。 | |
} | |
} | |
$championships.put: ';'; | |
LEAVE $championships.close; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment