Skip to content

Instantly share code, notes, and snippets.

@sasamijp
Created August 8, 2014 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sasamijp/3a5f0ee3f468282f368c to your computer and use it in GitHub Desktop.
Save sasamijp/3a5f0ee3f468282f368c to your computer and use it in GitHub Desktop.
dbからランダムに選んできて手動で5パターンに分類して教師データを作る
# -*- 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