Skip to content

Commit

Permalink
update jubatus to 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
holidayworking committed Feb 18, 2013
1 parent b010637 commit 21b7991
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'https://rubygems.org'

gem 'jubatus'
gem 'jubatus', '0.4.0'
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
GEM
remote: https://rubygems.org/
specs:
cool.io (1.1.0)
iobuffer (>= 1.0.0)
iobuffer (1.1.2)
jubatus (0.1.0)
msgpack-rpc (~> 0.4.5)
jubatus (0.4.0)
msgpack-rpc (~> 0.5.1)
msgpack (0.4.7)
msgpack-rpc (0.4.5)
msgpack (>= 0.4.4)
rev (>= 0.3.0)
rev (0.3.2)
iobuffer (>= 0.1.3)
msgpack-rpc (0.5.1)
cool.io (~> 1.1.0)
msgpack (~> 0.4.4)

PLATFORMS
ruby

DEPENDENCIES
jubatus
jubatus (= 0.4.0)
20 changes: 20 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"method": "PA",
"converter": {
"string_filter_types": {
"detag": { "method": "regexp", "pattern": "<[^>]*>", "replace": "" }
},
"string_filter_rules": [
{ "key": "message", "type": "detag", "suffix": "-detagged" }
],
"num_filter_types": {},
"num_filter_rules": [],
"string_types": {},
"string_rules": [
{ "key": "message-detagged", "type": "space", "sample_weight": "bin", "global_weight": "bin"}
],
"num_types": {},
"num_rules": []
},
"parameter": {}
}
29 changes: 3 additions & 26 deletions tutorial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ def parse_args
:host => '127.0.0.1',
:port => '9199',
:name => 'tutorial',
:algorithm => 'PA'
}

ARGV.options do |opts|
opts.on('-h', '--host HOST') { |host| options[:host] = host }
opts.on('-p', '--port NUMBER') { |port| options[:port] = port }
opts.on('-n', '--name NAME') { |name| options[:name] = name }
opts.on('-a', '--algorithm NAME') { |algorithm| options[:algorithm] = algorithm }
opts.parse!
end

Expand All @@ -39,51 +37,30 @@ def get_most_likely(estimates)
def main
options = parse_args

classifier = Jubatus::Client::Classifier.new(options[:host], options[:port])

converter = {
'string_filter_types' => {
'detag' => { 'method' => 'regexp', 'pattern' => '<[^>]*>', 'replace' => '' }
},
'string_filter_rules' => [
{ 'key' => 'message', 'type' => 'detag', 'suffix' => '-detagged' }
],
'num_filter_types' => {},
'num_filter_rules' => [],
'string_types' => {},
'string_rules' => [
{ 'key' => 'message-detagged', 'type' => 'space', 'sample_weight' => 'bin', 'global_weight' => 'bin' }
],
'num_types' => {},
'num_rules' => []
}

config = Jubatus::Config_data.new(options[:algorithm], JSON.generate(converter))
classifier = Jubatus::Classifier::Client::Classifier.new(options[:host], options[:port])

name = options[:name]

puts classifier.set_config(name, config)
puts classifier.get_config(name)
puts classifier.get_status(name)

IO.foreach('train.dat') do |line|
label, file = line.chomp.split(',')
dat = open(file).read
datum = Jubatus::Datum.new([['message', dat]], [])
datum = Jubatus::Classifier::Datum.new([['message', dat]], [])
classifier.train(name, [[label, datum]])
puts classifier.get_status(name)
end

puts classifier.save(name, 'tutorial')

puts classifier.load(name, 'tutorial')
puts classifier.set_config(name, config)
puts classifier.get_config(name)

IO.foreach('test.dat') do |line|
label, file = line.chomp.split(',')
dat = open(file).read
datum = Jubatus::Datum.new([['message', dat]], [])
datum = Jubatus::Classifier::Datum.new([['message', dat]], [])
answer = classifier.classify(name, [datum])
unless answer.nil?
estimate = get_most_likely(answer[0])
Expand Down

0 comments on commit 21b7991

Please sign in to comment.