predictionio 0.5.0 → 0.6.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.
- data/lib/predictionio/client.rb +77 -1
- metadata +5 -5
data/lib/predictionio/client.rb
CHANGED
@@ -45,7 +45,7 @@ module PredictionIO
|
|
45
45
|
#
|
46
46
|
# == Installation
|
47
47
|
# The easiest way is to use RubyGems:
|
48
|
-
# gem install predictionio-0.
|
48
|
+
# gem install predictionio-0.6.0.gem
|
49
49
|
#
|
50
50
|
# == Synopsis
|
51
51
|
# The recommended usage of the SDK is to fire asynchronous requests as early as you can in your code,
|
@@ -103,6 +103,21 @@ module PredictionIO
|
|
103
103
|
# rescue ItemRecNotFoundError => e
|
104
104
|
# # graceful error handling
|
105
105
|
# end
|
106
|
+
#
|
107
|
+
# === Retrieving Top N Similar Items for an Item
|
108
|
+
# # PredictionIO call to get similar items
|
109
|
+
# response = client.aget_itemsim_top_n("barengine", "fooitem", 10)
|
110
|
+
#
|
111
|
+
# #
|
112
|
+
# # work you need to do for the page (rendering, db queries, etc)
|
113
|
+
# #
|
114
|
+
#
|
115
|
+
# begin
|
116
|
+
# result = client.get_itemsim_top_n(response)
|
117
|
+
# # display results, store results, or your other work...
|
118
|
+
# rescue ItemSimNotFoundError => e
|
119
|
+
# # graceful error handling
|
120
|
+
# end
|
106
121
|
|
107
122
|
class Client
|
108
123
|
|
@@ -139,6 +154,9 @@ module PredictionIO
|
|
139
154
|
# Raised when ItemRec results cannot be found for a user after a synchronous API call.
|
140
155
|
class ItemRecNotFoundError < StandardError; end
|
141
156
|
|
157
|
+
# Raised when ItemSim results cannot be found for an item after a synchronous API call.
|
158
|
+
class ItemSimNotFoundError < StandardError; end
|
159
|
+
|
142
160
|
# Raised when an user-to-item action is not created after a synchronous API call.
|
143
161
|
class U2IActionNotCreatedError < StandardError; end
|
144
162
|
|
@@ -511,6 +529,64 @@ module PredictionIO
|
|
511
529
|
end
|
512
530
|
end
|
513
531
|
|
532
|
+
# :category: Asynchronous Methods
|
533
|
+
# Asynchronously request to get the top n similar items for an item from an ItemSim engine and return a PredictionIO::AsyncResponse object immediately.
|
534
|
+
#
|
535
|
+
# Corresponding REST API method: GET /engines/itemsim/:engine/topn
|
536
|
+
#
|
537
|
+
# See also #get_itemsim_top_n.
|
538
|
+
def aget_itemsim_top_n(engine, iid, n, params = {})
|
539
|
+
rparams = Hash.new
|
540
|
+
rparams["pio_appkey"] = @appkey
|
541
|
+
rparams["pio_iid"] = iid
|
542
|
+
rparams["pio_n"] = n
|
543
|
+
if params["pio_itypes"] != nil &&
|
544
|
+
params["pio_itypes"].kind_of?(Array) &&
|
545
|
+
params["pio_itypes"].length > 0 then
|
546
|
+
rparams["pio_itypes"] = params["pio_itypes"].join(",")
|
547
|
+
else
|
548
|
+
rparams["pio_itypes"] = params["pio_itypes"]
|
549
|
+
end
|
550
|
+
if params["pio_latitude"] != nil && params["pio_longitude"] != nil then
|
551
|
+
rparams["pio_latlng"] = "#{params["pio_latitude"]},#{params["pio_longitude"]}"
|
552
|
+
end
|
553
|
+
if params["pio_within"] != nil then
|
554
|
+
rparams["pio_within"] = params["pio_within"]
|
555
|
+
end
|
556
|
+
if params["pio_unit"] != nil then
|
557
|
+
rparams["pio_unit"] = params["pio_unit"]
|
558
|
+
end
|
559
|
+
@http.aget(PredictionIO::AsyncRequest.new(versioned_path("/engines/itemsim/#{engine}/topn.#{@apiformat}"), rparams))
|
560
|
+
end
|
561
|
+
|
562
|
+
# :category: Synchronous Methods
|
563
|
+
# Synchronously request to get the top n similar items for an item from an ItemSim engine and block until a response is received.
|
564
|
+
#
|
565
|
+
# See #aget_itemsim_top_n for a description of special argument handling.
|
566
|
+
#
|
567
|
+
# call-seq:
|
568
|
+
# aget_itemsim_top_n(engine, iid, n, params = {})
|
569
|
+
# aget_itemsim_top_n(async_response)
|
570
|
+
def get_itemsim_top_n(*args)
|
571
|
+
iid_or_res = args[0]
|
572
|
+
if iid_or_res.is_a?(PredictionIO::AsyncResponse) then
|
573
|
+
response = iid_or_res.get
|
574
|
+
else
|
575
|
+
response = aget_itemsim_top_n(*args).get
|
576
|
+
end
|
577
|
+
if response.is_a?(Net::HTTPOK) then
|
578
|
+
res = JSON.parse(response.body)
|
579
|
+
res["pio_iids"]
|
580
|
+
else
|
581
|
+
begin
|
582
|
+
msg = response.body
|
583
|
+
rescue Exception
|
584
|
+
raise ItemSimNotFoundError, response
|
585
|
+
end
|
586
|
+
raise ItemSimNotFoundError, msg
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
514
590
|
# :category: Asynchronous Methods
|
515
591
|
# Asynchronously request to record an action on an item and return a PredictionIO::AsyncResponse object immediately.
|
516
592
|
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: predictionio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'PredictionIO is a prediction server for building smart applications.
|
15
15
|
This gem
|
@@ -24,10 +24,10 @@ executables: []
|
|
24
24
|
extensions: []
|
25
25
|
extra_rdoc_files: []
|
26
26
|
files:
|
27
|
-
- lib/predictionio/client.rb
|
28
27
|
- lib/predictionio/async_request.rb
|
29
|
-
- lib/predictionio/connection.rb
|
30
28
|
- lib/predictionio/async_response.rb
|
29
|
+
- lib/predictionio/client.rb
|
30
|
+
- lib/predictionio/connection.rb
|
31
31
|
- lib/predictionio.rb
|
32
32
|
homepage: http://prediction.io
|
33
33
|
licenses: []
|
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
version: '0'
|
50
50
|
requirements: []
|
51
51
|
rubyforge_project:
|
52
|
-
rubygems_version: 1.8.
|
52
|
+
rubygems_version: 1.8.24
|
53
53
|
signing_key:
|
54
54
|
specification_version: 3
|
55
55
|
summary: PredictionIO Ruby SDK
|