Last active
August 29, 2015 14:13
-
-
Save Furu222/a52a31be8604d7ba7725 to your computer and use it in GitHub Desktop.
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
require 'csv' | |
# ここでWikipediaとはてなキーワード一覧のファイルを指定 | |
original_data = { | |
wikipedia: 'jawiki-latest-all-titles-in-ns0', | |
hatena: 'keywordlist_furigana.csv' | |
} | |
# wiki_hatena.csvを作成し,上記のファイルを順番に読み込む | |
CSV.open("wiki_hatena.csv", 'w') do |csv| | |
original_data.each do |type, filename| | |
next unless File.file? filename | |
open(filename).each do |title| | |
title.strip! | |
# いらないタイトル名を省く | |
# ここでは記号から始まるもの, 数字, 曖昧さ回避, _, PJ(Wikipediaプロジェクト), の登場人物, 一覧を省いている | |
next if title =~ %r(^[+-.$()?*/&%!"'_,]+) | |
next if title =~ /^[-.0-9]+$/ | |
next if title =~ /曖昧さ回避/ | |
next if title =~ /_\(/ | |
next if title =~ /^PJ:/ | |
next if title =~ /の登場人物/ | |
next if title =~ /一覧/ | |
# スコアの決定とCSVの作成。ここでは全て名詞となり、最後にWikipediaかhatenaをつけている | |
# また,1文字以下のものは省いている | |
title_length = title.length | |
if title_length > 1 | |
score = [-36000.0, -400 * (title_length ** 1.5)].max.to_i | |
csv << [title, nil, nil, score, '名詞', '一般', '*', '*', '*', '*', title, '*', '*', type] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment