jubatus 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/.gitignore +4 -1
  2. data/README.rst +1 -1
  3. data/Rakefile +8 -0
  4. data/VERSION +1 -1
  5. data/{test → integration_test}/jubatus_test/anomaly/test.rb +22 -23
  6. data/{test → integration_test}/jubatus_test/classifier/test.rb +10 -15
  7. data/integration_test/jubatus_test/clustering/test.rb +133 -0
  8. data/integration_test/jubatus_test/error/test.rb +51 -0
  9. data/{test → integration_test}/jubatus_test/graph/test.rb +15 -30
  10. data/integration_test/jubatus_test/nearest_neighbor/test.rb +86 -0
  11. data/integration_test/jubatus_test/recommender/test.rb +111 -0
  12. data/{test → integration_test}/jubatus_test/regression/test.rb +10 -15
  13. data/integration_test/jubatus_test/stat/test.rb +108 -0
  14. data/{test → integration_test}/jubatus_test/test_util.rb +1 -0
  15. data/jubatus.gemspec +1 -1
  16. data/lib/jubatus/anomaly/client.rb +34 -33
  17. data/lib/jubatus/anomaly/types.rb +30 -18
  18. data/lib/jubatus/classifier/client.rb +22 -28
  19. data/lib/jubatus/classifier/types.rb +56 -33
  20. data/lib/jubatus/clustering/client.rb +51 -0
  21. data/lib/jubatus/clustering/types.rb +44 -0
  22. data/lib/jubatus/common/client.rb +83 -0
  23. data/lib/jubatus/common/datum.rb +85 -0
  24. data/lib/jubatus/common/message_string_generator.rb +41 -0
  25. data/lib/jubatus/common/types.rb +247 -0
  26. data/lib/jubatus/common.rb +4 -0
  27. data/lib/jubatus/graph/client.rb +83 -60
  28. data/lib/jubatus/graph/types.rb +146 -85
  29. data/lib/jubatus/nearest_neighbor/client.rb +53 -0
  30. data/lib/jubatus/nearest_neighbor/types.rb +44 -0
  31. data/lib/jubatus/recommender/client.rb +50 -44
  32. data/lib/jubatus/recommender/types.rb +29 -26
  33. data/lib/jubatus/regression/client.rb +22 -28
  34. data/lib/jubatus/regression/types.rb +30 -18
  35. data/lib/jubatus/stat/client.rb +37 -38
  36. data/lib/jubatus/stat/types.rb +5 -4
  37. data/test/jubatus_test/common/client_test.rb +104 -0
  38. data/test/jubatus_test/common/datum_test.rb +43 -0
  39. data/test/jubatus_test/common/message_string_generator_test.rb +50 -0
  40. data/test/jubatus_test/common/types_test.rb +73 -0
  41. metadata +29 -16
  42. data/test/jubatus_test/recommender/test.rb +0 -122
  43. data/test/jubatus_test/stat/test.rb +0 -109
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
- lib/
1
+ lib/jubatus/*
2
+ !lib/jubatus/common
3
+ !lib/jubatus/common.rb
2
4
  *.gem
3
5
  *.rbc
4
6
  .bundle
@@ -14,6 +16,7 @@ test/version_tmp
14
16
  tmp
15
17
  *.model.js
16
18
  *.json
19
+ *~
17
20
 
18
21
  # YARD artifacts
19
22
  .yardoc
data/README.rst CHANGED
@@ -4,7 +4,7 @@ Jubatus Ruby Client
4
4
  Template of Jubatus client in Ruby.
5
5
  See `RubyGems <http://rubygems.org/gems/jubatus>`_ for the latest release.
6
6
 
7
- All codes are generated by `MessagePack IDL <https://github.com/msgpack/msgpack-haskell/tree/master/msgpack-idl>`_ .
7
+ All codes are generated by ``jenerator`` .
8
8
 
9
9
 
10
10
  Install
data/Rakefile CHANGED
@@ -14,6 +14,14 @@ task :test do |test|
14
14
  end
15
15
  end
16
16
 
17
+ task :integration_test do |test|
18
+ Rake::TestTask.new(:integration_test) do |t|
19
+ t.libs << 'lib' << 'integration_test'
20
+ t.test_files = FileList['integration_test/**/*.rb']
21
+ t.verbose = true
22
+ end
23
+ end
24
+
17
25
  # for Ruby 1.8
18
26
  task :coverage do |coverage|
19
27
  system("rcov -o test/coverage -I lib:test --exclude . --include-file lib/jubatus --aggregate coverage.info test/**/*.rb")
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
@@ -5,7 +5,6 @@ require 'test/unit'
5
5
  require 'json'
6
6
 
7
7
  require 'jubatus/anomaly/client'
8
- require 'jubatus/anomaly/types'
9
8
  require 'jubatus_test/test_util'
10
9
 
11
10
  class AnomalyTest < Test::Unit::TestCase
@@ -31,7 +30,7 @@ class AnomalyTest < Test::Unit::TestCase
31
30
  "reverse_nearest_neighbor_num" => 30,
32
31
  "method" => "euclid_lsh",
33
32
  "parameter" => {
34
- "lsh_num" => 8,
33
+ "hash_num" => 8,
35
34
  "table_num" => 16,
36
35
  "probe_num" => 64,
37
36
  "bin_width" => 10.0,
@@ -43,7 +42,7 @@ class AnomalyTest < Test::Unit::TestCase
43
42
 
44
43
  TestUtil.write_file("config_anomaly.json", @config.to_json)
45
44
  @srv = TestUtil.fork_process("anomaly", PORT, "config_anomaly.json")
46
- @cli = Jubatus::Anomaly::Client::Anomaly.new(HOST, PORT)
45
+ @cli = Jubatus::Anomaly::Client::Anomaly.new(HOST, PORT, "name")
47
46
  end
48
47
 
49
48
  def teardown
@@ -55,55 +54,55 @@ class AnomalyTest < Test::Unit::TestCase
55
54
  end
56
55
 
57
56
  def test_clear_row
58
- d = Jubatus::Anomaly::Datum.new([], [])
59
- (row_id, score) = @cli.add("name", d)
60
- assert_equal(true, @cli.clear_row("name", row_id))
57
+ d = Jubatus::Common::Datum.new
58
+ res = @cli.add(d)
59
+ assert_equal(true, @cli.clear_row(res.id))
61
60
  end
62
61
 
63
62
  def test_add
64
- d = Jubatus::Anomaly::Datum.new([], [])
65
- (row_id, score) = @cli.add("name", d)
63
+ d = Jubatus::Common::Datum.new
64
+ res = @cli.add(d)
66
65
  end
67
66
 
68
67
  def test_update
69
- d = Jubatus::Anomaly::Datum.new([], [])
70
- (row_id, score) = @cli.add("name", d)
71
- d = Jubatus::Anomaly::Datum.new([], [['val', 3.1]])
72
- score = @cli.update("name", row_id, d)
68
+ d = Jubatus::Common::Datum.new
69
+ res = @cli.add(d)
70
+ d = Jubatus::Common::Datum.new('val' => 3.1)
71
+ score = @cli.update(res.id, d)
73
72
  end
74
73
 
75
74
  def test_clear
76
- assert_equal(true, @cli.clear("name"))
75
+ assert_equal(true, @cli.clear)
77
76
  end
78
77
 
79
78
  def test_calc_score
80
- d = Jubatus::Anomaly::Datum.new([], [['val', 1.1]])
81
- (row_id, score) = @cli.add("name", d)
82
- d = Jubatus::Anomaly::Datum.new([], [['val', 3.1]])
83
- score = @cli.calc_score("name", d)
79
+ d = Jubatus::Common::Datum.new('val' => 1.1)
80
+ res = @cli.add(d)
81
+ d = Jubatus::Common::Datum.new('val' => 3.1)
82
+ score = @cli.calc_score(d)
84
83
  end
85
84
 
86
85
  def test_get_all_rows
87
- @cli.get_all_rows("name")
86
+ @cli.get_all_rows
88
87
  end
89
88
 
90
89
  def test_get_config
91
- config = @cli.get_config("name")
90
+ config = @cli.get_config
92
91
  assert_equal(JSON.parse(config), @config)
93
92
  end
94
93
 
95
94
  def test_save
96
- assert_equal(true, @cli.save("name", "anomaly.save_test.model"))
95
+ assert_equal(true, @cli.save("anomaly.save_test.model"))
97
96
  end
98
97
 
99
98
  def test_load
100
99
  model_name = "anomaly.load_test.model"
101
- @cli.save("name", model_name)
102
- assert_equal(true, @cli.load("name", model_name))
100
+ @cli.save(model_name)
101
+ assert_equal(true, @cli.load(model_name))
103
102
  end
104
103
 
105
104
  def test_get_status
106
- @cli.get_status("name")
105
+ @cli.get_status
107
106
  end
108
107
 
109
108
  end
@@ -5,7 +5,6 @@ require 'test/unit'
5
5
  require 'json'
6
6
 
7
7
  require 'jubatus/classifier/client'
8
- require 'jubatus/classifier/types'
9
8
  require 'jubatus_test/test_util'
10
9
 
11
10
  class ClassifierTest < Test::Unit::TestCase
@@ -33,7 +32,7 @@ class ClassifierTest < Test::Unit::TestCase
33
32
 
34
33
  TestUtil.write_file("config_classifier.json", @config.to_json)
35
34
  @srv = TestUtil.fork_process("classifier", PORT, "config_classifier.json")
36
- @cli = Jubatus::Classifier::Client::Classifier.new(HOST, PORT)
35
+ @cli = Jubatus::Classifier::Client::Classifier.new(HOST, PORT, "name")
37
36
  end
38
37
 
39
38
  def teardown
@@ -45,38 +44,34 @@ class ClassifierTest < Test::Unit::TestCase
45
44
  end
46
45
 
47
46
  def test_get_config
48
- config = @cli.get_config("name")
47
+ config = @cli.get_config
49
48
  assert_equal(JSON.parse(config), @config)
50
49
  end
51
50
 
52
51
  def test_train
53
- string_values = [["key1", "val1"], ["key2", "val2"]]
54
- num_values = [["key1", 1.0], ["key2", 2.0]]
55
- d = Jubatus::Classifier::Datum.new(string_values, num_values)
52
+ d = Jubatus::Common::Datum.new("skey1" => "val1", "skey2" => "val2", "nkey1" => 1.0, "nkey2" => 2.0)
56
53
  data = [["label", d]]
57
- assert_equal(@cli.train("name", data), 1)
54
+ assert_equal(@cli.train(data), 1)
58
55
  end
59
56
 
60
57
  def test_classify
61
- string_values = [["key1", "val1"], ["key2", "val2"]]
62
- num_values = [["key1", 1.0], ["key2", 2.0]]
63
- d = Jubatus::Classifier::Datum.new(string_values, num_values)
58
+ d = Jubatus::Common::Datum.new("skey1" => "val1", "skey2" => "val2", "nkey1" => 1.0, "nkey2" => 2.0)
64
59
  data = [d]
65
- result = @cli.classify("name", data)
60
+ result = @cli.classify(data)
66
61
  end
67
62
 
68
63
  def test_save
69
- assert_equal(@cli.save("name", "classifier.save_test.model"), true)
64
+ assert_equal(@cli.save("classifier.save_test.model"), true)
70
65
  end
71
66
 
72
67
  def test_load
73
68
  model_name = "classifier.load_test.model"
74
- @cli.save("name", model_name)
75
- assert_equal(@cli.load("name", model_name), true)
69
+ @cli.save(model_name)
70
+ assert_equal(@cli.load(model_name), true)
76
71
  end
77
72
 
78
73
  def test_get_status
79
- @cli.get_status("name")
74
+ @cli.get_status
80
75
  end
81
76
 
82
77
  end
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ require 'json'
6
+
7
+ require 'jubatus/clustering/client'
8
+ require 'jubatus_test/test_util'
9
+
10
+ class ClusteringTest < Test::Unit::TestCase
11
+ HOST = "127.0.0.1"
12
+ PORT = 23008
13
+ TIMEOUT = 10
14
+
15
+ def setup
16
+ @config = {
17
+ "method" => "kmeans",
18
+ "converter" => {
19
+ "string_filter_types" => {},
20
+ "string_filter_rules" => [],
21
+ "num_filter_types" => {},
22
+ "num_filter_rules" => [],
23
+ "string_types" => {},
24
+ "string_rules" => [
25
+ { "key" => "*", "type" => "str", "sample_weight" => "bin", "global_weight" => "bin" }
26
+ ],
27
+ "num_types" => {},
28
+ "num_rules" => [
29
+ { "key" => "*", "type" => "num" }
30
+ ]
31
+ },
32
+ "parameter" => {
33
+ "k" => 10,
34
+ "compressor_method" => "simple",
35
+ "bucket_size" => 1,
36
+ "compressed_bucket_size" => 1,
37
+ "bicriteria_base_size" => 10,
38
+ "bucket_length" => 1,
39
+ "forgetting_factor" => 0,
40
+ "forgetting_threshold" => 0.5
41
+ }
42
+ }
43
+
44
+ TestUtil.write_file("config_clustering.json", @config.to_json)
45
+ @srv = TestUtil.fork_process("clustering", PORT, "config_clustering.json")
46
+ @cli = Jubatus::Clustering::Client::Clustering.new(HOST, PORT, "name")
47
+ end
48
+
49
+ def teardown
50
+ TestUtil.kill_process(@srv)
51
+ end
52
+
53
+ def test_get_client
54
+ assert_instance_of( MessagePack::RPC::Client, @cli.get_client )
55
+ end
56
+
57
+ def test_get_config
58
+ config = @cli.get_config
59
+ assert_equal(JSON.parse(config), @config)
60
+ end
61
+
62
+ def test_save
63
+ assert_equal(true, @cli.save("clustering.save_test.model"))
64
+ end
65
+
66
+ def test_load
67
+ model_name = "clustering.load_test.model"
68
+ @cli.save(model_name)
69
+ assert_equal(true, @cli.load(model_name))
70
+ end
71
+
72
+ def test_get_status
73
+ @cli.get_status
74
+ end
75
+
76
+ def test_push
77
+ d = Jubatus::Common::Datum.new
78
+ res = @cli.push([d])
79
+ end
80
+
81
+ def test_get_revision
82
+ r = @cli.get_revision
83
+ assert_instance_of(Fixnum, r)
84
+ end
85
+
86
+ def test_get_core_members
87
+ d = Jubatus::Common::Datum.new
88
+ @cli.push([d])
89
+ res = @cli.get_core_members()
90
+ assert_equal(10, res.length)
91
+ assert_equal(1, res[0].length)
92
+ assert_instance_of(Jubatus::Clustering::WeightedDatum, res[0][0])
93
+ end
94
+
95
+ def test_k_center
96
+ for i in 0..99
97
+ d = Jubatus::Common::Datum.new({"nkey1" => i, "nkey2" => -i})
98
+ @cli.push([d])
99
+ end
100
+ res = @cli.get_k_center()
101
+ assert_equal(10, res.length)
102
+ assert_instance_of(Jubatus::Common::Datum, res[0])
103
+ end
104
+
105
+ def test_nearest_center
106
+ for i in 0..99
107
+ d = Jubatus::Common::Datum.new({"nkey1" => i, "nkey2" => -i})
108
+ @cli.push([d])
109
+ end
110
+ q = Jubatus::Common::Datum.new({"nkey1" => 2.0, "nkey2" => 1.0})
111
+ res = @cli.get_nearest_center(q)
112
+ assert_instance_of(Jubatus::Common::Datum, res)
113
+ end
114
+
115
+ def test_nearest_center
116
+ for i in 0..99
117
+ d = Jubatus::Common::Datum.new({"nkey1" => i, "nkey2" => -i})
118
+ @cli.push([d])
119
+ end
120
+ q = Jubatus::Common::Datum.new({"nkey1" => 2.0, "nkey2" => 1.0})
121
+ res = @cli.get_nearest_center(q)
122
+ assert_instance_of(Jubatus::Common::Datum, res)
123
+ end
124
+
125
+ def test_nearest_members
126
+ d = Jubatus::Common::Datum.new({"nkey1" => 1.0, "nkey2" => 1.0})
127
+ q = Jubatus::Common::Datum.new({"nkey1" => 2.0, "nkey2" => 1.0})
128
+ @cli.push([d])
129
+ res = @cli.get_nearest_members(q)
130
+ assert_instance_of(Jubatus::Clustering::WeightedDatum, res[0])
131
+ end
132
+
133
+ end
@@ -0,0 +1,51 @@
1
+ require 'json'
2
+ require 'test/unit'
3
+ require 'jubatus/common'
4
+ require 'jubatus_test/test_util'
5
+
6
+ class ErrorTest < Test::Unit::TestCase
7
+ HOST = "127.0.0.1"
8
+ PORT = 23000
9
+ TIMEOUT = 10
10
+
11
+ def setup
12
+ @config = {
13
+ "method" => "AROW",
14
+ "converter" => {
15
+ "string_filter_types" => {},
16
+ "string_filter_rules" => [],
17
+ "num_filter_types" => {},
18
+ "num_filter_rules" => [],
19
+ "string_types" => {},
20
+ "string_rules" => [],
21
+ "num_types" => {},
22
+ "num_rules" => []
23
+ },
24
+ "parameter" => {
25
+ "regularization_weight" => 1.001
26
+ }
27
+ }
28
+
29
+ TestUtil.write_file("config_for_error.json", @config.to_json)
30
+ @srv = TestUtil.fork_process("classifier", PORT, "config_for_error.json")
31
+ cli = MessagePack::RPC::Client.new(HOST, PORT)
32
+ @cli = Jubatus::Common::Client.new(cli, "name")
33
+ end
34
+
35
+ def teardown
36
+ TestUtil.kill_process(@srv)
37
+ end
38
+
39
+ def test_unknownmethod
40
+ assert_raise(Jubatus::Common::UnknownMethod) {
41
+ @cli.call("unknown_method", [], nil, [])
42
+ }
43
+ end
44
+
45
+ def test_typemismatch
46
+ # 'train' method requires list of labeled datum, but this test sends a string.
47
+ assert_raise(Jubatus::Common::TypeMismatch) {
48
+ @cli.call("train", [""], nil, [Jubatus::Common::TString.new])
49
+ }
50
+ end
51
+ end
@@ -6,7 +6,6 @@ require 'jubatus_test/test_util'
6
6
  require 'json'
7
7
 
8
8
  require 'jubatus/graph/client'
9
- require 'jubatus/graph/types'
10
9
 
11
10
  class GraphTest < Test::Unit::TestCase
12
11
  HOST = "127.0.0.1"
@@ -24,7 +23,7 @@ class GraphTest < Test::Unit::TestCase
24
23
 
25
24
  TestUtil.write_file("config_graph.json", @config.to_json)
26
25
  @srv = TestUtil.fork_process("graph", PORT, "config_graph.json")
27
- @cli = Jubatus::Graph::Client::Graph.new(HOST, PORT)
26
+ @cli = Jubatus::Graph::Client::Graph.new(HOST, PORT, "name")
28
27
  end
29
28
 
30
29
  def teardown
@@ -38,56 +37,42 @@ class GraphTest < Test::Unit::TestCase
38
37
  def test_node_info
39
38
  edge_query = [["a", "b"], ["c", "d"], ["e", "f"]]
40
39
  node_query = [["0", "1"], ["2", "3"]]
41
- p = Jubatus::Graph::Preset_query.new(edge_query, node_query)
40
+ p = Jubatus::Graph::PresetQuery.new(edge_query, node_query)
42
41
  in_edges = [0, 0]
43
42
  out_edges = [0, 0]
44
43
  Jubatus::Graph::Node.new(p, in_edges, out_edges)
45
44
  end
46
45
 
47
46
  def test_create_node
48
- name = "name"
49
- @cli.clear(name)
50
- nid = @cli.create_node("sample_node")
47
+ @cli.clear
48
+ nid = @cli.create_node
51
49
  assert_equal(nid.to_i.to_s, nid)
52
50
  end
53
51
 
54
52
  def test_remove_node
55
- name = "name"
56
- @cli.clear(name)
57
- nid = @cli.create_node(name)
58
- assert_equal(@cli.remove_node(name, nid), true)
53
+ @cli.clear
54
+ nid = @cli.create_node
55
+ assert_equal(@cli.remove_node(nid), true)
59
56
  end
60
57
 
61
58
  def test_update_node
62
- name = "name"
63
- @cli.clear(name)
64
- nid = @cli.create_node(name)
59
+ @cli.clear
60
+ nid = @cli.create_node
65
61
  prop = {"key1" => "val1", "key2" => "val2"}
66
- assert_equal(@cli.update_node(name, nid, prop), true)
62
+ assert_equal(@cli.update_node(nid, prop), true)
67
63
  end
68
64
 
69
65
  def test_create_edge
70
- name = "name"
71
- @cli.clear(name)
72
- src = @cli.create_node(name)
73
- tgt = @cli.create_node(name)
66
+ @cli.clear
67
+ src = @cli.create_node
68
+ tgt = @cli.create_node
74
69
  prop = {"key1" => "val1", "key2" => "val2"}
75
70
  ei = Jubatus::Graph::Edge.new(prop, src, tgt)
76
- eid = @cli.create_edge("name", tgt, ei)
77
- end
78
-
79
- def test_create_edge
80
- name = "name"
81
- @cli.clear(name)
82
- src = @cli.create_node(name)
83
- tgt = @cli.create_node(name)
84
- prop = {"key1" => "val1", "key2" => "val2"}
85
- ei = Jubatus::Graph::Edge.new(prop, src, tgt)
86
- eid = @cli.create_edge(src, tgt, ei)
71
+ eid = @cli.create_edge(tgt, ei)
87
72
  end
88
73
 
89
74
  def test_get_config
90
- config = @cli.get_config("name")
75
+ config = @cli.get_config
91
76
  assert_equal(JSON.parse(config), @config)
92
77
  end
93
78
 
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ require 'json'
6
+
7
+ require 'jubatus/nearest_neighbor/client'
8
+ require 'jubatus_test/test_util'
9
+
10
+ class NearestNeighborTest < Test::Unit::TestCase
11
+ HOST = "127.0.0.1"
12
+ PORT = 23007
13
+ TIMEOUT = 10
14
+
15
+ def setup
16
+ @config = {
17
+ "method" => "lsh",
18
+ "converter" => {
19
+ "string_filter_types" => {},
20
+ "string_filter_rules" => [],
21
+ "num_filter_types" => {},
22
+ "num_filter_rules" => [],
23
+ "string_types" => {},
24
+ "string_rules" => [{"key" => "*", "type" => "str", "sample_weight" => "bin", "global_weight" => "bin"}],
25
+ "num_types" => {},
26
+ "num_rules" => [{"key" => "*", "type" => "num"}]
27
+ },
28
+ "parameter" => {
29
+ "hash_num" => 64
30
+ }
31
+ }
32
+
33
+ TestUtil.write_file("config_nearest_neighbor.json", @config.to_json)
34
+ @srv = TestUtil.fork_process("nearest_neighbor", PORT, "config_nearest_neighbor.json")
35
+ @cli = Jubatus::NearestNeighbor::Client::NearestNeighbor.new(HOST, PORT, "name")
36
+ end
37
+
38
+ def teardown
39
+ TestUtil.kill_process(@srv)
40
+ end
41
+
42
+ def test_get_client
43
+ assert_instance_of( MessagePack::RPC::Client, @cli.get_client )
44
+ end
45
+
46
+ def test_get_config
47
+ config = @cli.get_config
48
+ assert_equal(JSON.parse(config), @config)
49
+ end
50
+
51
+ def test_neighbor_row
52
+ @cli.clear
53
+ d = Jubatus::Common::Datum.new("skey1" => "val1", "skey2" => "val2", "nkey1" => 1.0, "nkey2" => 2.0)
54
+ @cli.set_row("neighbor_row", d)
55
+ d1 = @cli.neighbor_row_from_id("neighbor_row", 10)
56
+ d2 = @cli.neighbor_row_from_data(d, 10)
57
+ end
58
+
59
+ def test_similar_row
60
+ @cli.clear
61
+ d = Jubatus::Common::Datum.new("skey1" => "val1", "skey2" => "val2", "nkey1" => 1.0, "nkey2" => 2.0)
62
+ @cli.set_row("similar_row", d)
63
+ s1 = @cli.similar_row_from_id("similar_row", 10)
64
+ s2 = @cli.similar_row_from_data(d, 10)
65
+ end
66
+
67
+ def test_clear
68
+ @cli.clear
69
+ end
70
+
71
+ def test_save
72
+ assert_equal(@cli.save("nearest_neighbor.save_test.model"), true)
73
+ end
74
+
75
+ def test_load
76
+ model_name = "nearest_neighbor.load_test.model"
77
+ @cli.save(model_name)
78
+ assert_equal(@cli.load(model_name), true)
79
+ end
80
+
81
+ def test_get_status
82
+ @cli.get_status
83
+ end
84
+
85
+ end
86
+
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ require 'json'
6
+
7
+ require 'jubatus/recommender/client'
8
+ require 'jubatus_test/test_util'
9
+
10
+ class RecommenderTest < Test::Unit::TestCase
11
+ HOST = "127.0.0.1"
12
+ PORT = 23003
13
+ TIMEOUT = 10
14
+
15
+ def setup
16
+ @config = {
17
+ "method" => "inverted_index",
18
+ "converter" => {
19
+ "string_filter_types" => {},
20
+ "string_filter_rules" => [],
21
+ "num_filter_types" => {},
22
+ "num_filter_rules" => [],
23
+ "string_types" => {},
24
+ "string_rules" => [{"key" => "*", "type" => "str", "sample_weight" => "bin", "global_weight" => "bin"}],
25
+ "num_types" => {},
26
+ "num_rules" => [{"key" => "*", "type" => "num"}]
27
+ }
28
+ }
29
+
30
+ TestUtil.write_file("config_recommender.json", @config.to_json)
31
+ @srv = TestUtil.fork_process("recommender", PORT, "config_recommender.json")
32
+ @cli = Jubatus::Recommender::Client::Recommender.new(HOST, PORT, "name")
33
+ end
34
+
35
+ def teardown
36
+ TestUtil.kill_process(@srv)
37
+ end
38
+
39
+ def test_get_client
40
+ assert_instance_of( MessagePack::RPC::Client, @cli.get_client )
41
+ end
42
+
43
+ def test_get_config
44
+ config = @cli.get_config
45
+ assert_equal(JSON.parse(config), @config)
46
+ end
47
+
48
+ def test_complete_row
49
+ @cli.clear_row("complete_row")
50
+ d = Jubatus::Common::Datum.new("skey1" => "val1", "skey2" => "val2", "nkey1" => 1.0, "nkey2" => 2.0)
51
+ @cli.update_row("complete_row", d)
52
+ d1 = @cli.complete_row_from_id("complete_row")
53
+ d2 = @cli.complete_row_from_datum(d)
54
+ end
55
+
56
+ def test_get_similar_row
57
+ @cli.clear_row("similar_row")
58
+ d = Jubatus::Common::Datum.new("skey1" => "val1", "skey2" => "val2", "nkey1" => 1.0, "nkey2" => 2.0)
59
+ @cli.update_row("similar_row", d)
60
+ s1 = @cli.similar_row_from_id("similar_row", 10)
61
+ s2 = @cli.similar_row_from_datum(d, 10)
62
+ end
63
+
64
+ def test_decode_row
65
+ @cli.clear_row("decode_row")
66
+ d = Jubatus::Common::Datum.new("skey1" => "val1", "skey2" => "val2", "nkey1" => 1.0, "nkey2" => 2.0)
67
+ @cli.update_row("decode_row", d)
68
+ decoded_row = @cli.decode_row("decode_row")
69
+ assert_equal(d.string_values, decoded_row.string_values)
70
+ assert_equal(d.num_values, decoded_row.num_values)
71
+ end
72
+
73
+ def test_get_row
74
+ @cli.clear
75
+ d = Jubatus::Common::Datum.new("skey1" => "val1", "skey2" => "val2", "nkey1" => 1.0, "nkey2" => 2.0)
76
+ @cli.update_row("get_row", d)
77
+ row_names = @cli.get_all_rows
78
+ assert_equal(row_names, ["get_row"])
79
+ end
80
+
81
+
82
+ def test_clear
83
+ @cli.clear
84
+ end
85
+
86
+ def test_calcs
87
+ d = Jubatus::Common::Datum.new("skey1" => "val1", "skey2" => "val2", "nkey1" => 1.0, "nkey2" => 2.0)
88
+ assert_in_delta(@cli.calc_similarity(d, d), 1, 0.000001)
89
+ assert_in_delta(@cli.calc_l2norm(d), Math.sqrt(1*1 + 1*1+ 1*1 + 2*2), 0.000001)
90
+ end
91
+
92
+ def test_clear
93
+ @cli.clear
94
+ end
95
+
96
+ def test_save
97
+ assert_equal(@cli.save("recommender.save_test.model"), true)
98
+ end
99
+
100
+ def test_load
101
+ model_name = "recommender.load_test.model"
102
+ @cli.save(model_name)
103
+ assert_equal(@cli.load(model_name), true)
104
+ end
105
+
106
+ def test_get_status
107
+ @cli.get_status
108
+ end
109
+
110
+ end
111
+