jubatus 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,123 +1,184 @@
1
- # This file is auto-generated from graph.idl
1
+ # This file is auto-generated from graph.idl(0.4.5-347-g86989a6) with jenerator version 0.4.5-418-gd2d5f04/develop
2
2
  # *** DO NOT EDIT ***
3
3
 
4
4
  require 'rubygems'
5
5
  require 'msgpack/rpc'
6
-
7
- class String
8
- def to_tuple
9
- self
10
- end
11
- end
12
-
13
- class Hash
14
- def to_tuple
15
- self
16
- end
17
- end
6
+ require 'jubatus/common'
18
7
 
19
8
  module Jubatus
20
9
  module Graph
21
10
 
22
11
  class Node
12
+ include Jubatus::Common
13
+ TYPE = TTuple.new(TMap.new(TString.new, TString.new), TList.new(TInt.new(
14
+ false, 8)), TList.new(TInt.new(false, 8)))
15
+
23
16
  def initialize(property, in_edges, out_edges)
24
- @property = property
25
- @in_edges = in_edges
26
- @out_edges = out_edges
17
+ @property = property
18
+ @in_edges = in_edges
19
+ @out_edges = out_edges
20
+ end
21
+
22
+ def to_msgpack(out = '')
23
+ t = [@property, @in_edges, @out_edges]
24
+ return TYPE.to_msgpack(t)
25
+ end
26
+
27
+ def Node.from_msgpack(m)
28
+ val = TYPE.from_msgpack(m)
29
+ Node.new(*val)
30
+ end
31
+
32
+ def to_s
33
+ gen = Jubatus::Common::MessageStringGenerator.new
34
+ gen.open("node")
35
+ gen.add("property", @property)
36
+ gen.add("in_edges", @in_edges)
37
+ gen.add("out_edges", @out_edges)
38
+ gen.close()
39
+ return gen.to_s
27
40
  end
28
- def to_tuple
29
- [@property.each_with_object({}) {|(k,v),h| h[k] = v},
30
- @in_edges.map {|x| x},
31
- @out_edges.map {|x| x}]
41
+
42
+ attr_reader :property, :in_edges, :out_edges
43
+
44
+ end
45
+
46
+ class Query
47
+ include Jubatus::Common
48
+ TYPE = TTuple.new(TString.new, TString.new)
49
+
50
+ def initialize(from_id, to_id)
51
+ @from_id = from_id
52
+ @to_id = to_id
32
53
  end
54
+
33
55
  def to_msgpack(out = '')
34
- to_tuple.to_msgpack(out)
56
+ t = [@from_id, @to_id]
57
+ return TYPE.to_msgpack(t)
35
58
  end
36
- def Node.from_tuple(tuple)
37
- Node.new(
38
- tuple[0].each_with_object({}) {|(k,v),h| h[k] = v },
39
- tuple[1].map { |x| x },
40
- tuple[2].map { |x| x }
41
- )
59
+
60
+ def Query.from_msgpack(m)
61
+ val = TYPE.from_msgpack(m)
62
+ Query.new(*val)
63
+ end
64
+
65
+ def to_s
66
+ gen = Jubatus::Common::MessageStringGenerator.new
67
+ gen.open("query")
68
+ gen.add("from_id", @from_id)
69
+ gen.add("to_id", @to_id)
70
+ gen.close()
71
+ return gen.to_s
42
72
  end
43
- attr_reader :property
44
- attr_accessor :in_edges, :out_edges
73
+
74
+ attr_reader :from_id, :to_id
75
+
45
76
  end
46
77
 
47
- class Preset_query
78
+ class PresetQuery
79
+ include Jubatus::Common
80
+ TYPE = TTuple.new(TList.new(TUserDef.new(Query)), TList.new(TUserDef.new(
81
+ Query)))
82
+
48
83
  def initialize(edge_query, node_query)
49
- @edge_query = edge_query
50
- @node_query = node_query
51
- end
52
- def to_tuple
53
- [@edge_query.map {|x| [x[0], x[1], ] },
54
- @node_query.map {|x| [x[0], x[1], ] }]
84
+ @edge_query = edge_query
85
+ @node_query = node_query
55
86
  end
87
+
56
88
  def to_msgpack(out = '')
57
- to_tuple.to_msgpack(out)
89
+ t = [@edge_query, @node_query]
90
+ return TYPE.to_msgpack(t)
58
91
  end
59
- def Preset_query.from_tuple(tuple)
60
- Preset_query.new(
61
- tuple[0].map { |x| [x[0] , x[1] ] },
62
- tuple[1].map { |x| [x[0] , x[1] ] }
63
- )
92
+
93
+ def PresetQuery.from_msgpack(m)
94
+ val = TYPE.from_msgpack(m)
95
+ PresetQuery.new(*val)
64
96
  end
65
- attr_accessor :edge_query, :node_query
97
+
98
+ def to_s
99
+ gen = Jubatus::Common::MessageStringGenerator.new
100
+ gen.open("preset_query")
101
+ gen.add("edge_query", @edge_query)
102
+ gen.add("node_query", @node_query)
103
+ gen.close()
104
+ return gen.to_s
105
+ end
106
+
107
+ attr_reader :edge_query, :node_query
108
+
66
109
  end
67
110
 
68
111
  class Edge
112
+ include Jubatus::Common
113
+ TYPE = TTuple.new(TMap.new(TString.new, TString.new), TString.new,
114
+ TString.new)
115
+
69
116
  def initialize(property, source, target)
70
- @property = property
71
- @source = source
72
- @target = target
73
- end
74
- def to_tuple
75
- [@property.each_with_object({}) {|(k,v),h| h[k] = v},
76
- @source,
77
- @target]
117
+ @property = property
118
+ @source = source
119
+ @target = target
78
120
  end
121
+
79
122
  def to_msgpack(out = '')
80
- to_tuple.to_msgpack(out)
123
+ t = [@property, @source, @target]
124
+ return TYPE.to_msgpack(t)
81
125
  end
82
- def Edge.from_tuple(tuple)
83
- Edge.new(
84
- tuple[0].each_with_object({}) {|(k,v),h| h[k] = v },
85
- tuple[1],
86
- tuple[2]
87
- )
126
+
127
+ def Edge.from_msgpack(m)
128
+ val = TYPE.from_msgpack(m)
129
+ Edge.new(*val)
130
+ end
131
+
132
+ def to_s
133
+ gen = Jubatus::Common::MessageStringGenerator.new
134
+ gen.open("edge")
135
+ gen.add("property", @property)
136
+ gen.add("source", @source)
137
+ gen.add("target", @target)
138
+ gen.close()
139
+ return gen.to_s
88
140
  end
89
- attr_reader :property
90
- attr_accessor :source, :target
141
+
142
+ attr_reader :property, :source, :target
143
+
91
144
  end
92
145
 
93
- class Shortest_path_query
146
+ class ShortestPathQuery
147
+ include Jubatus::Common
148
+ TYPE = TTuple.new(TString.new, TString.new, TInt.new(false, 4), TUserDef.new(
149
+ PresetQuery))
150
+
94
151
  def initialize(source, target, max_hop, query)
95
- @source = source
96
- @target = target
97
- @max_hop = max_hop
98
- @query = query
99
- end
100
- def to_tuple
101
- [@source,
102
- @target,
103
- @max_hop,
104
- @query.to_tuple]
152
+ @source = source
153
+ @target = target
154
+ @max_hop = max_hop
155
+ @query = query
105
156
  end
157
+
106
158
  def to_msgpack(out = '')
107
- to_tuple.to_msgpack(out)
108
- end
109
- def Shortest_path_query.from_tuple(tuple)
110
- Shortest_path_query.new(
111
- tuple[0],
112
- tuple[1],
113
- tuple[2],
114
- Preset_query.from_tuple(tuple[3])
115
- )
116
- end
117
- attr_reader :query
118
- attr_accessor :source, :target, :max_hop
119
- end
159
+ t = [@source, @target, @max_hop, @query]
160
+ return TYPE.to_msgpack(t)
161
+ end
162
+
163
+ def ShortestPathQuery.from_msgpack(m)
164
+ val = TYPE.from_msgpack(m)
165
+ ShortestPathQuery.new(*val)
166
+ end
167
+
168
+ def to_s
169
+ gen = Jubatus::Common::MessageStringGenerator.new
170
+ gen.open("shortest_path_query")
171
+ gen.add("source", @source)
172
+ gen.add("target", @target)
173
+ gen.add("max_hop", @max_hop)
174
+ gen.add("query", @query)
175
+ gen.close()
176
+ return gen.to_s
177
+ end
178
+
179
+ attr_reader :source, :target, :max_hop, :query
120
180
 
121
- end
122
181
  end
123
182
 
183
+ end # Graph
184
+ end # Jubatus
@@ -0,0 +1,53 @@
1
+ # This file is auto-generated from nearest_neighbor.idl(0.4.5-347-g86989a6) with jenerator version 0.4.5-418-gd2d5f04/develop
2
+ # *** DO NOT EDIT ***
3
+
4
+ require 'rubygems'
5
+ require 'msgpack/rpc'
6
+ require 'jubatus/common'
7
+ require File.join(File.dirname(__FILE__), 'types')
8
+
9
+ module Jubatus
10
+
11
+ module NearestNeighbor
12
+ module Client
13
+
14
+ class NearestNeighbor < Jubatus::Common::ClientBase
15
+ include Jubatus::Common
16
+ def initialize(host, port, name, timeout_sec=10)
17
+ super
18
+ end
19
+
20
+ def clear
21
+ @jubatus_client.call("clear", [], TBool.new, [])
22
+ end
23
+
24
+ def set_row(id, d)
25
+ @jubatus_client.call("set_row", [id, d], TBool.new, [TString.new,
26
+ TDatum.new])
27
+ end
28
+
29
+ def neighbor_row_from_id(id, size)
30
+ @jubatus_client.call("neighbor_row_from_id", [id, size], TList.new(
31
+ TUserDef.new(IdWithScore)), [TString.new, TInt.new(false, 4)])
32
+ end
33
+
34
+ def neighbor_row_from_data(query, size)
35
+ @jubatus_client.call("neighbor_row_from_data", [query, size], TList.new(
36
+ TUserDef.new(IdWithScore)), [TDatum.new, TInt.new(false, 4)])
37
+ end
38
+
39
+ def similar_row_from_id(id, ret_num)
40
+ @jubatus_client.call("similar_row_from_id", [id, ret_num], TList.new(
41
+ TUserDef.new(IdWithScore)), [TString.new, TInt.new(true, 4)])
42
+ end
43
+
44
+ def similar_row_from_data(query, ret_num)
45
+ @jubatus_client.call("similar_row_from_data", [query, ret_num], TList.new(
46
+ TUserDef.new(IdWithScore)), [TDatum.new, TInt.new(true, 4)])
47
+ end
48
+ end
49
+
50
+ end # Client
51
+ end # NearestNeighbor
52
+
53
+ end # Jubatus
@@ -0,0 +1,44 @@
1
+ # This file is auto-generated from nearest_neighbor.idl(0.4.5-347-g86989a6) with jenerator version 0.4.5-418-gd2d5f04/develop
2
+ # *** DO NOT EDIT ***
3
+
4
+ require 'rubygems'
5
+ require 'msgpack/rpc'
6
+ require 'jubatus/common'
7
+
8
+ module Jubatus
9
+ module NearestNeighbor
10
+
11
+ class IdWithScore
12
+ include Jubatus::Common
13
+ TYPE = TTuple.new(TString.new, TFloat.new)
14
+
15
+ def initialize(id, score)
16
+ @id = id
17
+ @score = score
18
+ end
19
+
20
+ def to_msgpack(out = '')
21
+ t = [@id, @score]
22
+ return TYPE.to_msgpack(t)
23
+ end
24
+
25
+ def IdWithScore.from_msgpack(m)
26
+ val = TYPE.from_msgpack(m)
27
+ IdWithScore.new(*val)
28
+ end
29
+
30
+ def to_s
31
+ gen = Jubatus::Common::MessageStringGenerator.new
32
+ gen.open("id_with_score")
33
+ gen.add("id", @id)
34
+ gen.add("score", @score)
35
+ gen.close()
36
+ return gen.to_s
37
+ end
38
+
39
+ attr_reader :id, :score
40
+
41
+ end
42
+
43
+ end # NearestNeighbor
44
+ end # Jubatus
@@ -1,68 +1,74 @@
1
- # This file is auto-generated from recommender.idl
1
+ # This file is auto-generated from recommender.idl(0.4.5-347-g86989a6) with jenerator version 0.4.5-418-gd2d5f04/develop
2
2
  # *** DO NOT EDIT ***
3
3
 
4
4
  require 'rubygems'
5
5
  require 'msgpack/rpc'
6
+ require 'jubatus/common'
6
7
  require File.join(File.dirname(__FILE__), 'types')
7
8
 
8
9
  module Jubatus
10
+
9
11
  module Recommender
10
12
  module Client
11
13
 
12
- class Recommender
13
- def initialize(host, port)
14
- @cli = MessagePack::RPC::Client.new(host, port)
15
- end
16
- def get_client
17
- @cli
18
- end
19
- def get_config(name)
20
- @cli.call(:get_config, name)
21
- end
22
- def clear_row(name, id)
23
- @cli.call(:clear_row, name, id)
24
- end
25
- def update_row(name, id, row)
26
- @cli.call(:update_row, name, id, row)
27
- end
28
- def clear(name)
29
- @cli.call(:clear, name)
14
+ class Recommender < Jubatus::Common::ClientBase
15
+ include Jubatus::Common
16
+ def initialize(host, port, name, timeout_sec=10)
17
+ super
30
18
  end
31
- def complete_row_from_id(name, id)
32
- Datum.from_tuple(@cli.call(:complete_row_from_id, name, id))
19
+
20
+ def clear_row(id)
21
+ @jubatus_client.call("clear_row", [id], TBool.new, [TString.new])
33
22
  end
34
- def complete_row_from_datum(name, row)
35
- Datum.from_tuple(@cli.call(:complete_row_from_datum, name, row))
23
+
24
+ def update_row(id, row)
25
+ @jubatus_client.call("update_row", [id, row], TBool.new, [TString.new,
26
+ TDatum.new])
36
27
  end
37
- def similar_row_from_id(name, id, size)
38
- Similar_result.from_tuple(@cli.call(:similar_row_from_id, name, id, size))
28
+
29
+ def clear
30
+ @jubatus_client.call("clear", [], TBool.new, [])
39
31
  end
40
- def similar_row_from_datum(name, row, size)
41
- Similar_result.from_tuple(@cli.call(:similar_row_from_datum, name, row, size))
32
+
33
+ def complete_row_from_id(id)
34
+ @jubatus_client.call("complete_row_from_id", [id], TDatum.new,
35
+ [TString.new])
42
36
  end
43
- def decode_row(name, id)
44
- Datum.from_tuple(@cli.call(:decode_row, name, id))
37
+
38
+ def complete_row_from_datum(row)
39
+ @jubatus_client.call("complete_row_from_datum", [row], TDatum.new,
40
+ [TDatum.new])
45
41
  end
46
- def get_all_rows(name)
47
- @cli.call(:get_all_rows, name)
42
+
43
+ def similar_row_from_id(id, size)
44
+ @jubatus_client.call("similar_row_from_id", [id, size], TList.new(
45
+ TUserDef.new(IdWithScore)), [TString.new, TInt.new(false, 4)])
48
46
  end
49
- def calc_similarity(name, lhs, rhs)
50
- @cli.call(:calc_similarity, name, lhs, rhs)
47
+
48
+ def similar_row_from_datum(row, size)
49
+ @jubatus_client.call("similar_row_from_datum", [row, size], TList.new(
50
+ TUserDef.new(IdWithScore)), [TDatum.new, TInt.new(false, 4)])
51
51
  end
52
- def calc_l2norm(name, row)
53
- @cli.call(:calc_l2norm, name, row)
52
+
53
+ def decode_row(id)
54
+ @jubatus_client.call("decode_row", [id], TDatum.new, [TString.new])
54
55
  end
55
- def save(name, id)
56
- @cli.call(:save, name, id)
56
+
57
+ def get_all_rows
58
+ @jubatus_client.call("get_all_rows", [], TList.new(TString.new), [])
57
59
  end
58
- def load(name, id)
59
- @cli.call(:load, name, id)
60
+
61
+ def calc_similarity(lhs, rhs)
62
+ @jubatus_client.call("calc_similarity", [lhs, rhs], TFloat.new, [TDatum.new,
63
+ TDatum.new])
60
64
  end
61
- def get_status(name)
62
- @cli.call(:get_status, name)
65
+
66
+ def calc_l2norm(row)
67
+ @jubatus_client.call("calc_l2norm", [row], TFloat.new, [TDatum.new])
63
68
  end
64
69
  end
65
70
 
66
- end
67
- end
68
- end
71
+ end # Client
72
+ end # Recommender
73
+
74
+ end # Jubatus
@@ -1,41 +1,44 @@
1
- # This file is auto-generated from recommender.idl
1
+ # This file is auto-generated from recommender.idl(0.4.5-347-g86989a6) with jenerator version 0.4.5-418-gd2d5f04/develop
2
2
  # *** DO NOT EDIT ***
3
3
 
4
4
  require 'rubygems'
5
5
  require 'msgpack/rpc'
6
+ require 'jubatus/common'
7
+
6
8
  module Jubatus
7
9
  module Recommender
8
10
 
9
- class Similar_result
10
- def Similar_result.from_tuple(tuple)
11
- tuple.map { |x| [x[0] , x[1] ] }
12
- end
13
- def to_tuple(o)
14
- o
15
- end
16
- end
11
+ class IdWithScore
12
+ include Jubatus::Common
13
+ TYPE = TTuple.new(TString.new, TFloat.new)
17
14
 
18
- class Datum
19
- def initialize(string_values, num_values)
20
- @string_values = string_values
21
- @num_values = num_values
22
- end
23
- def to_tuple
24
- [@string_values.map {|x| [x[0], x[1], ] },
25
- @num_values.map {|x| [x[0], x[1], ] }]
15
+ def initialize(id, score)
16
+ @id = id
17
+ @score = score
26
18
  end
19
+
27
20
  def to_msgpack(out = '')
28
- to_tuple.to_msgpack(out)
21
+ t = [@id, @score]
22
+ return TYPE.to_msgpack(t)
29
23
  end
30
- def Datum.from_tuple(tuple)
31
- Datum.new(
32
- tuple[0].map { |x| [x[0] , x[1] ] },
33
- tuple[1].map { |x| [x[0] , x[1] ] }
34
- )
24
+
25
+ def IdWithScore.from_msgpack(m)
26
+ val = TYPE.from_msgpack(m)
27
+ IdWithScore.new(*val)
35
28
  end
36
- attr_accessor :string_values, :num_values
37
- end
38
29
 
39
- end
30
+ def to_s
31
+ gen = Jubatus::Common::MessageStringGenerator.new
32
+ gen.open("id_with_score")
33
+ gen.add("id", @id)
34
+ gen.add("score", @score)
35
+ gen.close()
36
+ return gen.to_s
37
+ end
38
+
39
+ attr_reader :id, :score
40
+
40
41
  end
41
42
 
43
+ end # Recommender
44
+ end # Jubatus
@@ -1,44 +1,38 @@
1
- # This file is auto-generated from regression.idl
1
+ # This file is auto-generated from regression.idl(0.4.5-347-g86989a6) with jenerator version 0.4.5-418-gd2d5f04/develop
2
2
  # *** DO NOT EDIT ***
3
3
 
4
4
  require 'rubygems'
5
5
  require 'msgpack/rpc'
6
+ require 'jubatus/common'
6
7
  require File.join(File.dirname(__FILE__), 'types')
7
8
 
8
9
  module Jubatus
10
+
9
11
  module Regression
10
12
  module Client
11
13
 
12
- class Regression
13
- def initialize(host, port)
14
- @cli = MessagePack::RPC::Client.new(host, port)
15
- end
16
- def get_client
17
- @cli
18
- end
19
- def get_config(name)
20
- @cli.call(:get_config, name)
21
- end
22
- def train(name, train_data)
23
- @cli.call(:train, name, train_data)
14
+ class Regression < Jubatus::Common::ClientBase
15
+ include Jubatus::Common
16
+ def initialize(host, port, name, timeout_sec=10)
17
+ super
24
18
  end
25
- def estimate(name, estimate_data)
26
- @cli.call(:estimate, name, estimate_data)
27
- end
28
- def clear(name)
29
- @cli.call(:clear, name)
30
- end
31
- def save(name, id)
32
- @cli.call(:save, name, id)
19
+
20
+ def train(train_data)
21
+ @jubatus_client.call("train", [train_data], TInt.new(true, 4), [TList.new(
22
+ TUserDef.new(ScoredDatum))])
33
23
  end
34
- def load(name, id)
35
- @cli.call(:load, name, id)
24
+
25
+ def estimate(estimate_data)
26
+ @jubatus_client.call("estimate", [estimate_data], TList.new(TFloat.new),
27
+ [TList.new(TDatum.new)])
36
28
  end
37
- def get_status(name)
38
- @cli.call(:get_status, name)
29
+
30
+ def clear
31
+ @jubatus_client.call("clear", [], TBool.new, [])
39
32
  end
40
33
  end
41
34
 
42
- end
43
- end
44
- end
35
+ end # Client
36
+ end # Regression
37
+
38
+ end # Jubatus
@@ -1,32 +1,44 @@
1
- # This file is auto-generated from regression.idl
1
+ # This file is auto-generated from regression.idl(0.4.5-347-g86989a6) with jenerator version 0.4.5-418-gd2d5f04/develop
2
2
  # *** DO NOT EDIT ***
3
3
 
4
4
  require 'rubygems'
5
5
  require 'msgpack/rpc'
6
+ require 'jubatus/common'
7
+
6
8
  module Jubatus
7
9
  module Regression
8
10
 
9
- class Datum
10
- def initialize(string_values, num_values)
11
- @string_values = string_values
12
- @num_values = num_values
13
- end
14
- def to_tuple
15
- [@string_values.map {|x| [x[0], x[1], ] },
16
- @num_values.map {|x| [x[0], x[1], ] }]
11
+ class ScoredDatum
12
+ include Jubatus::Common
13
+ TYPE = TTuple.new(TFloat.new, TDatum.new)
14
+
15
+ def initialize(score, data)
16
+ @score = score
17
+ @data = data
17
18
  end
19
+
18
20
  def to_msgpack(out = '')
19
- to_tuple.to_msgpack(out)
21
+ t = [@score, @data]
22
+ return TYPE.to_msgpack(t)
23
+ end
24
+
25
+ def ScoredDatum.from_msgpack(m)
26
+ val = TYPE.from_msgpack(m)
27
+ ScoredDatum.new(*val)
20
28
  end
21
- def Datum.from_tuple(tuple)
22
- Datum.new(
23
- tuple[0].map { |x| [x[0] , x[1] ] },
24
- tuple[1].map { |x| [x[0] , x[1] ] }
25
- )
29
+
30
+ def to_s
31
+ gen = Jubatus::Common::MessageStringGenerator.new
32
+ gen.open("scored_datum")
33
+ gen.add("score", @score)
34
+ gen.add("data", @data)
35
+ gen.close()
36
+ return gen.to_s
26
37
  end
27
- attr_accessor :string_values, :num_values
28
- end
29
38
 
30
- end
39
+ attr_reader :score, :data
40
+
31
41
  end
32
42
 
43
+ end # Regression
44
+ end # Jubatus