Created
August 8, 2014 09:40
-
-
Save sasamijp/3a5f0ee3f468282f368c to your computer and use it in GitHub Desktop.
dbからランダムに選んできて手動で5パターンに分類して教師データを作る
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
# -*- encoding: utf-8 -*- | |
require 'classifier' | |
require './db_manager.rb' | |
require 'natto' | |
@nm = Natto::MeCab.new | |
def wakati(str) | |
array = [] | |
@nm.parse(str) do |n| | |
array.push(n.surface) | |
end | |
array.join(" ") | |
end | |
b = nil | |
#b = Classifier::Bayes.new 'tere', 'sad', 'normal', 'talking', 'glad' | |
File.open("./bayes_data/amami", "r") {|f| b = Marshal.load(f)} | |
db = DbManager.new | |
responds = db.read("amami.db").delete_if{|v|v[:in_reply_to].length > 70}.map!{|v|v[:serif]} | |
loop do | |
a = wakati(responds.sample) | |
puts a | |
case gets.to_i | |
when 1 | |
b.train_tere a | |
when 2 | |
b.train_sad a | |
when 3 | |
b.train_normal a | |
when 4 | |
b.train_talking a | |
when 5 | |
b.train_glad a | |
when 114514 | |
File.open("./bayes_data/amami", "wb") {|f| Marshal.dump(b, f)} | |
break | |
else | |
puts 'none?' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment