App42_RUBY_SDK 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/App42_RUBY_SDK.gemspec +31 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/lib/App42BadParameterException.rb +31 -0
- data/lib/App42Exception.rb +39 -0
- data/lib/App42LimitException.rb +15 -0
- data/lib/App42NotFoundException.rb +15 -0
- data/lib/App42Response.rb +13 -0
- data/lib/App42ResponseBuilder.rb +64 -0
- data/lib/App42SecurityException.rb +15 -0
- data/lib/App42_RUBY_SDK.rb +236 -0
- data/lib/App42_RUBY_SDK/version.rb +3 -0
- data/lib/ServiceAPI.rb +246 -0
- data/lib/appTab/App.rb +105 -0
- data/lib/appTab/BandwidthUnit.rb +57 -0
- data/lib/appTab/Bill.rb +182 -0
- data/lib/appTab/BillMonth.rb +94 -0
- data/lib/appTab/BillResponseBuilder.rb +242 -0
- data/lib/appTab/BillService.rb +457 -0
- data/lib/appTab/Currency.rb +79 -0
- data/lib/appTab/DiscountResponseBuilder.rb +71 -0
- data/lib/appTab/DiscountService.rb +240 -0
- data/lib/appTab/DiscountType.rb +54 -0
- data/lib/appTab/License.rb +25 -0
- data/lib/appTab/LicenseResponseBuilder.rb +88 -0
- data/lib/appTab/LicenseService.rb +399 -0
- data/lib/appTab/PackageData.rb +83 -0
- data/lib/appTab/PackageResponseBuilder.rb +114 -0
- data/lib/appTab/PackageService.rb +506 -0
- data/lib/appTab/SchemeData.rb +11 -0
- data/lib/appTab/SchemeResponseBuilder.rb +70 -0
- data/lib/appTab/SchemeService.rb +151 -0
- data/lib/appTab/StorageUnit.rb +54 -0
- data/lib/appTab/SubscribeService.rb +180 -0
- data/lib/appTab/Test.rb +41 -0
- data/lib/appTab/TimeUnit.rb +49 -0
- data/lib/appTab/Usage.rb +206 -0
- data/lib/appTab/UsageResponseBuilder.rb +152 -0
- data/lib/appTab/UsageService.rb +1799 -0
- data/lib/connection/RESTConnection.rb +711 -0
- data/lib/email/Email.rb +51 -0
- data/lib/email/EmailMIME.rb +51 -0
- data/lib/email/EmailResponseBuilder.rb +76 -0
- data/lib/email/EmailService.rb +244 -0
- data/lib/gallery/Album.rb +56 -0
- data/lib/gallery/AlbumResponseBuilder.rb +168 -0
- data/lib/gallery/AlbumService.rb +337 -0
- data/lib/gallery/PhotoService.rb +591 -0
- data/lib/game/Game.rb +39 -0
- data/lib/game/GameResponseBuilder.rb +106 -0
- data/lib/game/GameService.rb +268 -0
- data/lib/game/Reward.rb +24 -0
- data/lib/game/RewardResponseBuilder.rb +85 -0
- data/lib/game/RewardService.rb +440 -0
- data/lib/game/ScoreBoardService.rb +433 -0
- data/lib/game/ScoreService.rb +157 -0
- data/lib/geo/Geo.rb +51 -0
- data/lib/geo/GeoPoint.rb +43 -0
- data/lib/geo/GeoResponseBuilder.rb +145 -0
- data/lib/geo/GeoService.rb +506 -0
- data/lib/imageProcessor/Image.rb +42 -0
- data/lib/imageProcessor/ImageProcessorResponseBuilder.rb +40 -0
- data/lib/imageProcessor/ImageProcessorService.rb +1054 -0
- data/lib/log/Log.rb +49 -0
- data/lib/log/LogResponseBuilder.rb +61 -0
- data/lib/log/LogService.rb +920 -0
- data/lib/message/Queue.rb +50 -0
- data/lib/message/QueueResponseBuilder.rb +64 -0
- data/lib/message/QueueService.rb +469 -0
- data/lib/push/DeviceType.rb +56 -0
- data/lib/push/PushNotification.rb +38 -0
- data/lib/push/PushNotificationResposneBuilder.rb +74 -0
- data/lib/push/PushNotificationService.rb +458 -0
- data/lib/recommend/PreferenceData.rb +25 -0
- data/lib/recommend/Recommender.rb +48 -0
- data/lib/recommend/RecommenderResponseBuilder.rb +70 -0
- data/lib/recommend/RecommenderService.rb +1092 -0
- data/lib/recommend/RecommenderSimilarity.rb +52 -0
- data/lib/review/Review.rb +38 -0
- data/lib/review/ReviewResponseBuilder.rb +76 -0
- data/lib/review/ReviewService.rb +590 -0
- data/lib/session/Session.rb +43 -0
- data/lib/session/SessionResponseBuilder.rb +70 -0
- data/lib/session/SessionService.rb +427 -0
- data/lib/shopping/Cart.rb +77 -0
- data/lib/shopping/CartResponseBuilder.rb +118 -0
- data/lib/shopping/CartService.rb +902 -0
- data/lib/shopping/Catalogue.rb +79 -0
- data/lib/shopping/CatalogueResponseBuilder.rb +170 -0
- data/lib/shopping/CatalogueService.rb +649 -0
- data/lib/shopping/ItemData.rb +29 -0
- data/lib/shopping/PaymentStatus.rb +60 -0
- data/lib/social/Social.rb +35 -0
- data/lib/social/SocialResponseBuilder.rb +38 -0
- data/lib/social/SocialService.rb +585 -0
- data/lib/storage/OrderByType.rb +29 -0
- data/lib/storage/Query.rb +39 -0
- data/lib/storage/QueryBuilder.rb +118 -0
- data/lib/storage/Storage.rb +45 -0
- data/lib/storage/StorageResponseBuilder.rb +86 -0
- data/lib/storage/StorageService.rb +775 -0
- data/lib/upload/Upload.rb +40 -0
- data/lib/upload/UploadFileType.rb +83 -0
- data/lib/upload/UploadResponseBuilder.rb +58 -0
- data/lib/upload/UploadService.rb +960 -0
- data/lib/user/User.rb +102 -0
- data/lib/user/UserResponseBuilder.rb +105 -0
- data/lib/user/UserService.rb +1253 -0
- data/lib/util/util.rb +250 -0
- metadata +134 -9
- checksums.yaml +0 -7
@@ -0,0 +1,25 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'recommend/Recommender.rb'
|
6
|
+
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# This PreferenceData object is the value object which contains the properties
|
10
|
+
# of PreferenceData along with the setter & getter for those properties.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
module App42
|
15
|
+
module Recommend
|
16
|
+
class PreferenceData
|
17
|
+
|
18
|
+
attr_accessor :userId, :itemId, :preference
|
19
|
+
|
20
|
+
@userId
|
21
|
+
@ItemId
|
22
|
+
@preference
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42Response.rb'
|
6
|
+
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# This Recommender object is the value object which contains the properties of
|
10
|
+
# Recommender.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
module App42
|
15
|
+
module Recommend
|
16
|
+
class Recommender < App42Response
|
17
|
+
attr_accessor :fileName, :recommendedItemList
|
18
|
+
|
19
|
+
@fileName
|
20
|
+
@recommendedItemList = Array.new()
|
21
|
+
end
|
22
|
+
|
23
|
+
class RecommendedItem
|
24
|
+
attr_accessor :userId, :item, :value
|
25
|
+
@userId
|
26
|
+
@item
|
27
|
+
@value
|
28
|
+
|
29
|
+
#
|
30
|
+
# This is a constructor that takes no parameter
|
31
|
+
#
|
32
|
+
def initialize(recommender)
|
33
|
+
recommender.recommendedItemList.push(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Returns the Recommender Response in JSON format.
|
38
|
+
#
|
39
|
+
# @return the response in JSON format.
|
40
|
+
#
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
return "UserId : #{self.userId}" + "item : #{self.item}" + "value : #{self.value}";
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'json/pure'
|
6
|
+
require 'App42ResponseBuilder.rb'
|
7
|
+
require 'recommend/Recommender.rb'
|
8
|
+
require 'recommend/RecommenderSimilarity.rb'
|
9
|
+
|
10
|
+
module App42
|
11
|
+
module Recommend
|
12
|
+
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# RecommenderResponseBuilder class converts the JSON response retrieved from
|
16
|
+
# the server to the value object i.e Recommender
|
17
|
+
#
|
18
|
+
#
|
19
|
+
class RecommenderResponseBuilder < App42ResponseBuilder
|
20
|
+
|
21
|
+
#
|
22
|
+
# Converts the response in JSON format to the value object i.e Recommender
|
23
|
+
#
|
24
|
+
# @param json
|
25
|
+
# - response in JSON format
|
26
|
+
#
|
27
|
+
# @return Recommender object filled with json data
|
28
|
+
#
|
29
|
+
#
|
30
|
+
def buildResponse(json)
|
31
|
+
puts "testing #{json}"
|
32
|
+
recommenderObj = Recommender.new
|
33
|
+
recommendedItemList = Array.new()
|
34
|
+
recommenderObj.recommendedItemList=recommendedItemList
|
35
|
+
recommenderObj.strResponse=json
|
36
|
+
|
37
|
+
jsonObj = JSON.parse(json)
|
38
|
+
|
39
|
+
jsonObjApp42 = jsonObj["app42"]
|
40
|
+
jsonObjResponse = jsonObjApp42["response"]
|
41
|
+
recommenderObj.isResponseSuccess=(jsonObjResponse.fetch("success"));
|
42
|
+
jsonObjRecommender = jsonObjResponse["recommender"]
|
43
|
+
buildObjectFromJSONTree(recommenderObj, jsonObjRecommender);
|
44
|
+
|
45
|
+
if jsonObjRecommender.key?("recommended") == false
|
46
|
+
return recommenderObj
|
47
|
+
end
|
48
|
+
|
49
|
+
if jsonObjRecommender.fetch("recommended").instance_of?(Hash)
|
50
|
+
# Only One attribute is there
|
51
|
+
jsonObjRecommended = jsonObjRecommender.fetch("recommended");
|
52
|
+
recomItem = App42::Recommend::RecommendedItem.new(recommenderObj)
|
53
|
+
buildObjectFromJSONTree(recomItem, jsonObjRecommended);
|
54
|
+
else
|
55
|
+
|
56
|
+
jsonObjRecommenderArray = jsonObjRecommender.fetch("recommended");
|
57
|
+
|
58
|
+
jsonObjRecommenderArray.length.times do |i|
|
59
|
+
# Get Individual Attribute Node and set it into Object
|
60
|
+
jsonObjRecommended = jsonObjRecommenderArray[i]
|
61
|
+
recomItem = App42::Recommend::RecommendedItem.new(recommenderObj)
|
62
|
+
buildObjectFromJSONTree(recomItem, jsonObjRecommended);
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return recommenderObj
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,1092 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'connection/RESTConnection.rb'
|
7
|
+
require 'util/util.rb'
|
8
|
+
require 'json/pure'
|
9
|
+
require 'App42Response.rb'
|
10
|
+
require 'recommend/RecommenderResponseBuilder.rb'
|
11
|
+
require 'recommend/Recommender.rb'
|
12
|
+
require 'recommend/RecommenderSimilarity.rb'
|
13
|
+
require 'bigdecimal'
|
14
|
+
|
15
|
+
module App42
|
16
|
+
module Recommend
|
17
|
+
#
|
18
|
+
# Recommendation engine which provides recommendation based on customer id, item id and the preference
|
19
|
+
# of the customer for a particular Item.
|
20
|
+
#
|
21
|
+
# Recommendations can be fetched based on User Similarity which finds similarity based on Users
|
22
|
+
# and Item Similarity which finds similarity based on Items.
|
23
|
+
#
|
24
|
+
# The Recommendation Engine currently supports two types of Similarity Algorithms i.e. EuclideanDistanceSimilarity
|
25
|
+
# and PearsonCorrelationSimilarity. By default when similarity is not specified PearsonCorrelationSimilarity is used e.g.
|
26
|
+
# in the method itemBased(String preferenceFileName, long userId, int howMany), it uses PearsonCorrelationSimilarity.
|
27
|
+
# In the method itemBasedBySimilarity(String similarity, String preferenceFileName, long userId, int howMany) one can
|
28
|
+
# specify which similarity algorithm has to be used e.g. Recommender.EUCLIDEAN_DISTANCE or Recommender.PEARSON_CORRELATION.
|
29
|
+
# Preference file can be loaded using the method load_preference_file(String fileName, String preferenceFilePath, String description)
|
30
|
+
# in csv format. This preference file has to be uploaded once which can be a batch process
|
31
|
+
# The csv format for the file is given below.
|
32
|
+
# customerId, itemId, preference
|
33
|
+
#
|
34
|
+
# e.g.
|
35
|
+
# 1,101,5.0
|
36
|
+
# 1,102,3.0
|
37
|
+
# 1,103,2.5
|
38
|
+
#
|
39
|
+
# 2,101,2.0
|
40
|
+
# 2,102,2.5
|
41
|
+
# 2,103,5.0
|
42
|
+
# 2,104,2.0
|
43
|
+
#
|
44
|
+
# 3,101,2.5
|
45
|
+
# 3,104,4.0
|
46
|
+
# 3,105,4.5
|
47
|
+
# 3,107,5.0
|
48
|
+
#
|
49
|
+
# 4,101,5.0
|
50
|
+
# 4,103,3.0
|
51
|
+
# 4,104,4.5
|
52
|
+
# 4,106,4.0
|
53
|
+
#
|
54
|
+
# 5,101,4.0
|
55
|
+
# 5,102,3.0
|
56
|
+
# 5,103,2.0
|
57
|
+
# 5,104,4.0
|
58
|
+
# 5,105,3.5
|
59
|
+
# 5,106,4.0
|
60
|
+
# The customer Id and item id can be any alphanumaric character(s) and preference values can be in any range.
|
61
|
+
#
|
62
|
+
# If app developers have used the Review Service. The Recommendation Engine can be used in conjunction with Review.
|
63
|
+
# In this case a CSV preference file need not be uploaded. The customerId, itemId and preference will be taken from
|
64
|
+
# Review where customerId is mapped with userName, itemId is mapped with itemId and preference with rating.
|
65
|
+
# The methods for recommendations based on Reviews are part of the Review service
|
66
|
+
#
|
67
|
+
# @see ReviewService
|
68
|
+
#
|
69
|
+
class RecommenderService
|
70
|
+
#
|
71
|
+
# this is a constructor that takes
|
72
|
+
#
|
73
|
+
# @param apiKey
|
74
|
+
# @param secretKey
|
75
|
+
# @param baseURL
|
76
|
+
#
|
77
|
+
def initialize(api_key, secret_key, base_url)
|
78
|
+
puts "Recommender Service->initialize"
|
79
|
+
@api_key = api_key
|
80
|
+
@secret_key = secret_key
|
81
|
+
@base_url = base_url
|
82
|
+
@resource = "recommend"
|
83
|
+
@version = "1.0"
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Uploads peference file on the cloud. The preference file should be in CSV format.
|
88
|
+
# This preference file has to be uploaded once which can be a batch process.
|
89
|
+
# New versions of preference file either can be uploaded in a different name or the older one
|
90
|
+
# has to be removed and the uploaded in the same name.
|
91
|
+
# The csv format for the file is given below.
|
92
|
+
# customerId, itemId, preference
|
93
|
+
#
|
94
|
+
# e.g.
|
95
|
+
# 1,101,5.0
|
96
|
+
# 1,102,3.0
|
97
|
+
# 1,103,2.5
|
98
|
+
#
|
99
|
+
# 2,101,2.0
|
100
|
+
# 2,102,2.5
|
101
|
+
# 2,103,5.0
|
102
|
+
# 2,104,2.0
|
103
|
+
#
|
104
|
+
# 3,101,2.5
|
105
|
+
# 3,104,4.0
|
106
|
+
# 3,105,4.5
|
107
|
+
# 3,107,5.0
|
108
|
+
#
|
109
|
+
# 4,101,5.0
|
110
|
+
# 4,103,3.0
|
111
|
+
# 4,104,4.5
|
112
|
+
# 4,106,4.0
|
113
|
+
#
|
114
|
+
# 5,101,4.0
|
115
|
+
# 5,102,3.0
|
116
|
+
# 5,103,2.0
|
117
|
+
# 5,104,4.0
|
118
|
+
# 5,105,3.5
|
119
|
+
# 5,106,4.0
|
120
|
+
# The customer Id and item id can be any alphanumaric character(s) and preference values can be in any range.
|
121
|
+
# If the recommendations have to be done based on Reviews then this file need not be uploaded.
|
122
|
+
#
|
123
|
+
# @param fileName
|
124
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
125
|
+
# @param preferenceFilePath
|
126
|
+
# - Path of the preference file to be loaded
|
127
|
+
# @param description
|
128
|
+
# - Description of the preference file to be loaded
|
129
|
+
#
|
130
|
+
# @return Returns the uploaded preference file details.
|
131
|
+
# @raise App42Exception
|
132
|
+
#
|
133
|
+
|
134
|
+
def load_preference_file(preferenceFilePath)
|
135
|
+
puts "load_preference_file Called "
|
136
|
+
puts "Base url #{@base_url}"
|
137
|
+
response = nil;
|
138
|
+
responseObj = App42Response.new();
|
139
|
+
util = Util.new
|
140
|
+
util.throwExceptionIfNullOrBlank(preferenceFilePath, "PreferenceFilePath");
|
141
|
+
if (FileTest.exists?(preferenceFilePath) == false)
|
142
|
+
raise App42Exception.new("The file with the name #{preferenceFilePath} not found")
|
143
|
+
end
|
144
|
+
begin
|
145
|
+
file = preferenceFilePath
|
146
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
147
|
+
params = Hash.new
|
148
|
+
query_params = Hash.new
|
149
|
+
query_params = {
|
150
|
+
'apiKey'=> @api_key,
|
151
|
+
'version' => @version,
|
152
|
+
'timeStamp' => util.get_timestamp_utc,
|
153
|
+
}
|
154
|
+
params = query_params.clone
|
155
|
+
post_params=Hash.new
|
156
|
+
params = params.merge(post_params)
|
157
|
+
signature = util.sign(@secret_key, params)
|
158
|
+
resource_url = "#{@version}/#{@resource}"
|
159
|
+
response = connection.recommendMultipart(signature, resource_url, query_params, params, preferenceFilePath)
|
160
|
+
responseObj.strResponse=(response)
|
161
|
+
responseObj.isResponseSuccess=(true)
|
162
|
+
rescue App42Exception =>e
|
163
|
+
raise e
|
164
|
+
rescue Exception => e
|
165
|
+
raise App42Exception.new(e)
|
166
|
+
end
|
167
|
+
return responseObj
|
168
|
+
end
|
169
|
+
|
170
|
+
#
|
171
|
+
# Uploads preference file on the cloud via Stream. The preference file should be in CSV
|
172
|
+
# format. This preference file has to be uploaded once which can be a batch
|
173
|
+
# process. New versions of preference file either can be uploaded in a
|
174
|
+
# different name or the older one has to be removed and the uploaded in the
|
175
|
+
# same name. The csv format for the file is given below. customerId,
|
176
|
+
# itemId, preference e.g. 1,101,5.0 1,102,3.0 1,103,2.5
|
177
|
+
#
|
178
|
+
# 2,101,2.0 2,102,2.5 2,103,5.0 2,104,2.0
|
179
|
+
#
|
180
|
+
# 3,101,2.5 3,104,4.0 3,105,4.5 3,107,5.0
|
181
|
+
#
|
182
|
+
# 4,101,5.0 4,103,3.0 4,104,4.5 4,106,4.0
|
183
|
+
#
|
184
|
+
# 5,101,4.0 5,102,3.0 5,103,2.0 5,104,4.0 5,105,3.5 5,106,4.0 The customer
|
185
|
+
# Id and item id can be any alphanumeric character(s) and preference values
|
186
|
+
# can be in any range. If the recommendations have to be done based on
|
187
|
+
# Reviews then this file need not be uploaded.
|
188
|
+
#
|
189
|
+
# @param inputStream
|
190
|
+
# - InputStream of the file to load.
|
191
|
+
#
|
192
|
+
# @return App42Response object.
|
193
|
+
#
|
194
|
+
# @raise App42Exception
|
195
|
+
#
|
196
|
+
|
197
|
+
def load_preference_file_stream(inputStream)
|
198
|
+
puts "load_preference_file stream Called "
|
199
|
+
puts "Base url #{@base_url}"
|
200
|
+
response = nil;
|
201
|
+
responseObj = App42Response.new();
|
202
|
+
util = Util.new
|
203
|
+
if (FileTest.exists?(inputStream) == false)
|
204
|
+
raise App42Exception.new("The file with the name #{inputStream} not found")
|
205
|
+
end
|
206
|
+
begin
|
207
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
208
|
+
params = Hash.new
|
209
|
+
query_params = Hash.new
|
210
|
+
query_params = {
|
211
|
+
'apiKey'=> @api_key,
|
212
|
+
'version' => @version,
|
213
|
+
'timeStamp' => util.get_timestamp_utc,
|
214
|
+
}
|
215
|
+
params = query_params.clone
|
216
|
+
signature = util.sign(@secret_key, params)
|
217
|
+
resource_url = "#{@version}/#{@resource}"
|
218
|
+
response = connection.recommendMultipartStream(signature, resource_url, query_params, params, inputStream)
|
219
|
+
responseObj.strResponse=(response)
|
220
|
+
responseObj.isResponseSuccess=(true)
|
221
|
+
rescue App42Exception =>e
|
222
|
+
raise e
|
223
|
+
rescue Exception => e
|
224
|
+
raise App42Exception.new(e)
|
225
|
+
end
|
226
|
+
return responseObj
|
227
|
+
end
|
228
|
+
|
229
|
+
#
|
230
|
+
# User based recommendations based on Neighborhood. Recommendations are found based on similar users in the Neighborhood
|
231
|
+
# of the given user. The size of the neighborhood can be found.
|
232
|
+
#
|
233
|
+
# @param peferenceFileName
|
234
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
235
|
+
# @param userId
|
236
|
+
# - The user Id for whom recommendations have to be found
|
237
|
+
# @param
|
238
|
+
# - size Size of the Neighborhood
|
239
|
+
# @param howMany
|
240
|
+
# - Specifies that how many recommendations have to be found
|
241
|
+
#
|
242
|
+
# @returns Recommendations
|
243
|
+
#
|
244
|
+
# @raise App42Exception
|
245
|
+
#
|
246
|
+
|
247
|
+
def user_based_neighborhood(userId, size, howMany)
|
248
|
+
puts "userBasedNeighborhood Called "
|
249
|
+
puts "Base url #{@base_url}"
|
250
|
+
response = nil;
|
251
|
+
recommenderObj = nil;
|
252
|
+
recommenderObj = Recommender.new
|
253
|
+
util = Util.new
|
254
|
+
util.validateHowMany(howMany)
|
255
|
+
util.throwExceptionIfNullOrBlank(userId, "User Id");
|
256
|
+
util.throwExceptionIfNullOrBlank(size, "Size");
|
257
|
+
util.throwExceptionIfNullOrBlank(howMany, "HowMany");
|
258
|
+
begin
|
259
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
260
|
+
params = Hash.new
|
261
|
+
query_params = Hash.new
|
262
|
+
params = {
|
263
|
+
'apiKey'=> @api_key,
|
264
|
+
'version' => @version,
|
265
|
+
'timeStamp' => util.get_timestamp_utc,
|
266
|
+
}
|
267
|
+
query_params = params.clone
|
268
|
+
params.store("userId", "" + (userId.to_i).to_s);
|
269
|
+
params.store("size", "" + (size.to_i).to_s);
|
270
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
271
|
+
signature = util.sign(@secret_key, params)
|
272
|
+
resource_url = "#{@version}/#{@resource}/userBasedNeighborhood/#{userId}/#{size}/#{howMany}"
|
273
|
+
response = connection.get(signature, resource_url, query_params)
|
274
|
+
recommend = RecommenderResponseBuilder.new()
|
275
|
+
recommenderObj = recommend.buildResponse(response)
|
276
|
+
rescue App42Exception =>e
|
277
|
+
raise e
|
278
|
+
rescue Exception => e
|
279
|
+
raise App42Exception.new(e)
|
280
|
+
end
|
281
|
+
return recommenderObj
|
282
|
+
end
|
283
|
+
|
284
|
+
#
|
285
|
+
# User based neighborhood recommendations based on Threshold. Recommendations are found based on Threshold
|
286
|
+
# where thereshold represents similarity threshold where user are at least that similar.
|
287
|
+
# Threshold values can vary from -1 to 1
|
288
|
+
#
|
289
|
+
# @param peferenceFileName
|
290
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
291
|
+
# @param userId
|
292
|
+
# - The user Id for whom recommendations have to be found
|
293
|
+
# @param threshold
|
294
|
+
# - Threshold size. Values can vary from -1 to 1
|
295
|
+
# @param howMany
|
296
|
+
# - Specifies that how many recommendations have to be found
|
297
|
+
#
|
298
|
+
# @returns Recommendations
|
299
|
+
#
|
300
|
+
# @raise App42Exception
|
301
|
+
#
|
302
|
+
|
303
|
+
def user_based_threshold(userId, threshold, howMany)
|
304
|
+
puts "userBasedThreshold Called "
|
305
|
+
puts "Base url #{@base_url}"
|
306
|
+
response = nil;
|
307
|
+
recommenderObj = nil;
|
308
|
+
recommenderObj = Recommender.new
|
309
|
+
util = Util.new
|
310
|
+
util.validateHowMany(howMany)
|
311
|
+
util.throwExceptionIfNullOrBlank(userId, "User Id");
|
312
|
+
util.throwExceptionIfNullOrBlank(threshold, "Threshold");
|
313
|
+
util.throwExceptionIfNullOrBlank(howMany, "HowMany");
|
314
|
+
begin
|
315
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
316
|
+
query_params = Hash.new
|
317
|
+
params = {
|
318
|
+
'apiKey'=> @api_key,
|
319
|
+
'version' => @version,
|
320
|
+
'timeStamp' => util.get_timestamp_utc,
|
321
|
+
}
|
322
|
+
query_params = params.clone
|
323
|
+
params.store("userId", "" + (userId.to_i).to_s);
|
324
|
+
params.store("threshold", "" + (threshold.to_f).to_s);
|
325
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
326
|
+
puts query_params
|
327
|
+
signature = util.sign(@secret_key, params)
|
328
|
+
resource_url = "#{@version}/#{@resource}/userBasedThreshold/#{userId}/#{(threshold.to_f).to_s}/#{howMany}"
|
329
|
+
response = connection.get(signature, resource_url, query_params)
|
330
|
+
recommend = RecommenderResponseBuilder.new()
|
331
|
+
recommenderObj = recommend.buildResponse(response)
|
332
|
+
rescue App42Exception =>e
|
333
|
+
raise e
|
334
|
+
rescue Exception => e
|
335
|
+
raise App42Exception.new(e)
|
336
|
+
end
|
337
|
+
return recommenderObj
|
338
|
+
end
|
339
|
+
|
340
|
+
#
|
341
|
+
# User based recommendations based on Neighborhood and Similarity. Recommendations and found based on the similar users in the Neighborhood with
|
342
|
+
# the specified Similarity Algorithm. Algorithim can be specified using the constants Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
|
343
|
+
#
|
344
|
+
# @param recommenderSimilarity
|
345
|
+
# - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
|
346
|
+
# @param peferenceFileName
|
347
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
348
|
+
# @param userId
|
349
|
+
# - The user Id for whom recommendations have to be found
|
350
|
+
# @param size
|
351
|
+
# - Size of the Neighborhood
|
352
|
+
# @param howMany
|
353
|
+
# - Specifies that how many recommendations have to be found
|
354
|
+
#
|
355
|
+
# @returns Recommendations
|
356
|
+
#
|
357
|
+
# @raise App42Exception
|
358
|
+
#
|
359
|
+
|
360
|
+
def user_based_neighborhood_by_similarity(recommenderSimilarity, userId, size, howMany)
|
361
|
+
puts "userBasedNeighborhoodBySimilarity Called "
|
362
|
+
puts "Base url #{@base_url}"
|
363
|
+
response = nil;
|
364
|
+
recommenderObj = nil;
|
365
|
+
recommenderObj = Recommender.new
|
366
|
+
util = Util.new
|
367
|
+
util.validateHowMany(howMany)
|
368
|
+
util.throwExceptionIfNullOrBlank(recommenderSimilarity, "recommenderSimilarity");
|
369
|
+
util.throwExceptionIfNullOrBlank(userId, "User Id");
|
370
|
+
util.throwExceptionIfNullOrBlank(size, "Size");
|
371
|
+
util.throwExceptionIfNullOrBlank(howMany, "HowMany");
|
372
|
+
rs = App42::Recommend::RecommenderSimilarity.new
|
373
|
+
begin
|
374
|
+
if (RecommenderSimilarity.new.isAvailable(recommenderSimilarity) == nil)
|
375
|
+
raise App42NotFoundException.new("The RecommenderSimilarity"+ recommenderSimilarity+ "does not Exist ");
|
376
|
+
end
|
377
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
378
|
+
query_params = Hash.new
|
379
|
+
params = {
|
380
|
+
'apiKey'=> @api_key,
|
381
|
+
'version' => @version,
|
382
|
+
'timeStamp' => util.get_timestamp_utc,
|
383
|
+
}
|
384
|
+
query_params = params.clone
|
385
|
+
params.store("userId", "" + (userId.to_i).to_s);
|
386
|
+
params.store("size", "" + (size.to_i).to_s);
|
387
|
+
params.store("similarity", "" + recommenderSimilarity);
|
388
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
389
|
+
puts query_params
|
390
|
+
signature = util.sign(@secret_key, params)
|
391
|
+
resource_url = "#{@version}/#{@resource}/userBasedNeighborhood/#{recommenderSimilarity}/#{userId}/#{size}/#{howMany}"
|
392
|
+
response = connection.get(signature, resource_url, query_params)
|
393
|
+
recommend = RecommenderResponseBuilder.new()
|
394
|
+
recommenderObj = recommend.buildResponse(response)
|
395
|
+
rescue App42Exception =>e
|
396
|
+
raise e
|
397
|
+
rescue Exception => e
|
398
|
+
raise App42Exception.new(e)
|
399
|
+
end
|
400
|
+
return recommenderObj
|
401
|
+
end
|
402
|
+
|
403
|
+
#
|
404
|
+
# User based neighborood recommendations based on Threshold. Recommendations are found based on Threshold
|
405
|
+
# where thereshold represents similarity threshold where user are at least that similar.
|
406
|
+
# Threshold values can vary from -1 to 1
|
407
|
+
#
|
408
|
+
# @param recommenderSimilarity
|
409
|
+
# - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
|
410
|
+
# @param peferenceFileName
|
411
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
412
|
+
# @param userId
|
413
|
+
# - The user Id for whom recommendations have to be found
|
414
|
+
# @param threshold
|
415
|
+
# - Threshold size. Values can vary from -1 to 1
|
416
|
+
# @param howMany
|
417
|
+
# - Specifies that how many recommendations have to be found
|
418
|
+
#
|
419
|
+
# @returns Recommendations
|
420
|
+
#
|
421
|
+
# @raise App42Exception
|
422
|
+
#
|
423
|
+
|
424
|
+
def user_based_neighborhood_by_similarity(recommenderSimilarity, userId, threshold, howMany)
|
425
|
+
puts "userBasedThresholdBySimilarity Called "
|
426
|
+
puts "Base url #{@base_url}"
|
427
|
+
response = nil;
|
428
|
+
recommenderObj = nil;
|
429
|
+
recommenderObj = Recommender.new
|
430
|
+
util = Util.new
|
431
|
+
util.validateHowMany(howMany)
|
432
|
+
util.throwExceptionIfNullOrBlank(recommenderSimilarity, "recommenderSimilarity");
|
433
|
+
util.throwExceptionIfNullOrBlank(userId, "User Id");
|
434
|
+
util.throwExceptionIfNullOrBlank(threshold, "Threshold");
|
435
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
436
|
+
begin
|
437
|
+
if (RecommenderSimilarity.new.isAvailable(recommenderSimilarity) == nil)
|
438
|
+
raise App42NotFoundException.new("The RecommenderSimilarity #{recommenderSimilarity} does not Exist ");
|
439
|
+
end
|
440
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
441
|
+
params = Hash.new
|
442
|
+
query_params = Hash.new
|
443
|
+
params = {
|
444
|
+
'apiKey'=> @api_key,
|
445
|
+
'version' => @version,
|
446
|
+
'timeStamp' => util.get_timestamp_utc,
|
447
|
+
}
|
448
|
+
query_params = params.clone
|
449
|
+
params.store("similarity", "" + recommenderSimilarity);
|
450
|
+
params.store("userId", "" + (userId.to_i).to_s);
|
451
|
+
params.store("threshold", "" + (threshold.to_f).to_s);
|
452
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
453
|
+
signature = util.sign(@secret_key, params)
|
454
|
+
puts "Signature #{signature}"
|
455
|
+
resource_url = "#{@version}/#{@resource}/userBasedThreshold/#{recommenderSimilarity}/#{userId}/#{(threshold.to_f)}/#{howMany}"
|
456
|
+
response = connection.get(signature, resource_url, query_params)
|
457
|
+
recommend = RecommenderResponseBuilder.new()
|
458
|
+
recommenderObj = recommend.buildResponse(response)
|
459
|
+
rescue App42Exception =>e
|
460
|
+
raise e
|
461
|
+
rescue Exception => e
|
462
|
+
raise App42Exception.new(e)
|
463
|
+
end
|
464
|
+
return recommenderObj
|
465
|
+
end
|
466
|
+
|
467
|
+
#
|
468
|
+
# Item based recommendations. Recommendations and found based item similarity
|
469
|
+
# of the given user. The size of the neighborhood can be found.
|
470
|
+
#
|
471
|
+
# @param peferenceFileName
|
472
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
473
|
+
# @param userId
|
474
|
+
# - The user Id for whom recommendations have to be found
|
475
|
+
# @param howMany
|
476
|
+
# - Specifies that how many recommendations have to be found
|
477
|
+
#
|
478
|
+
# @returns Recommendations
|
479
|
+
#
|
480
|
+
# @raise App42Exception
|
481
|
+
#
|
482
|
+
|
483
|
+
def item_based(userId, howMany)
|
484
|
+
puts "itemBased Called "
|
485
|
+
puts "Base url #{@base_url}"
|
486
|
+
response = nil;
|
487
|
+
recommenderObj = nil;
|
488
|
+
recommenderObj = Recommender.new
|
489
|
+
util = Util.new
|
490
|
+
util.validateHowMany(howMany)
|
491
|
+
util.throwExceptionIfNullOrBlank(userId, "User Id");
|
492
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
493
|
+
begin
|
494
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
495
|
+
query_params = Hash.new
|
496
|
+
params = {
|
497
|
+
'apiKey'=> @api_key,
|
498
|
+
'version' => @version,
|
499
|
+
'timeStamp' => util.get_timestamp_utc,
|
500
|
+
}
|
501
|
+
query_params = params.clone
|
502
|
+
params.store("userId", "" + (userId.to_i).to_s);
|
503
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
504
|
+
puts query_params
|
505
|
+
signature = util.sign(@secret_key, params)
|
506
|
+
resource_url = "#{@version}/#{@resource}/itemBased/#{userId}/#{howMany}"
|
507
|
+
response = connection.get(signature, resource_url, query_params)
|
508
|
+
recommend = RecommenderResponseBuilder.new()
|
509
|
+
recommenderObj = recommend.buildResponse(response)
|
510
|
+
rescue App42Exception =>e
|
511
|
+
raise e
|
512
|
+
rescue Exception => e
|
513
|
+
raise App42Exception.new(e)
|
514
|
+
end
|
515
|
+
return recommenderObj
|
516
|
+
end
|
517
|
+
|
518
|
+
#
|
519
|
+
# Recommendations based on SlopeOne Algorithm
|
520
|
+
#
|
521
|
+
# @param peferenceFileName
|
522
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
523
|
+
# @param userId
|
524
|
+
# - The user Id for whom recommendations have to be found
|
525
|
+
# @param howMany
|
526
|
+
# - Specifies that how many recommendations have to be found
|
527
|
+
#
|
528
|
+
# @return Recommendation object
|
529
|
+
#
|
530
|
+
# @raise App42Exception
|
531
|
+
#
|
532
|
+
|
533
|
+
def slope_one(userId, howMany)
|
534
|
+
puts "slopeOne Called "
|
535
|
+
puts "Base url #{@base_url}"
|
536
|
+
response = nil;
|
537
|
+
recommenderObj = nil;
|
538
|
+
recommenderObj = Recommender.new
|
539
|
+
util = Util.new
|
540
|
+
util.validateHowMany(howMany)
|
541
|
+
util.throwExceptionIfNullOrBlank(userId, "User Id");
|
542
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
543
|
+
begin
|
544
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
545
|
+
query_params = Hash.new
|
546
|
+
params = {
|
547
|
+
'apiKey'=> @api_key,
|
548
|
+
'version' => @version,
|
549
|
+
'timeStamp' => util.get_timestamp_utc,
|
550
|
+
}
|
551
|
+
query_params = params.clone
|
552
|
+
params.store("userId", "" + (userId.to_i).to_s);
|
553
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
554
|
+
puts query_params
|
555
|
+
signature = util.sign(@secret_key, params)
|
556
|
+
resource_url = "#{@version}/#{@resource}/slopeOne/#{userId}/#{howMany}"
|
557
|
+
response = connection.get(signature, resource_url, query_params)
|
558
|
+
recommend = RecommenderResponseBuilder.new()
|
559
|
+
recommenderObj = recommend.buildResponse(response)
|
560
|
+
rescue App42Exception =>e
|
561
|
+
raise e
|
562
|
+
rescue Exception => e
|
563
|
+
raise App42Exception.new(e)
|
564
|
+
end
|
565
|
+
return recommenderObj
|
566
|
+
end
|
567
|
+
|
568
|
+
#
|
569
|
+
# User based neighborood recommendations based on Threshold for all Users. Recommendations are found based on Threshold
|
570
|
+
# where thereshold represents similarity threshold where user are at least that similar.
|
571
|
+
# Threshold values can vary from -1 to 1
|
572
|
+
#
|
573
|
+
# @param peferenceFileName
|
574
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
575
|
+
# @param threshold
|
576
|
+
# - Threshold size. Values can vary from -1 to 1
|
577
|
+
# @param howMany
|
578
|
+
# - Specifies that how many recommendations have to be found
|
579
|
+
#
|
580
|
+
# @return Recommendations for all Users
|
581
|
+
#
|
582
|
+
# @raise App42Exception
|
583
|
+
#
|
584
|
+
|
585
|
+
def user_based_threshold_for_all(threshold, howMany)
|
586
|
+
puts "userBasedThresholdForAll Called "
|
587
|
+
puts "Base url #{@base_url}"
|
588
|
+
response = nil;
|
589
|
+
recommenderObj = nil;
|
590
|
+
recommenderObj = Recommender.new
|
591
|
+
util = Util.new
|
592
|
+
util.validateHowMany(howMany)
|
593
|
+
util.throwExceptionIfNullOrBlank(threshold, "Threshold");
|
594
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
595
|
+
begin
|
596
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
597
|
+
query_params = Hash.new
|
598
|
+
params = {
|
599
|
+
'apiKey'=> @api_key,
|
600
|
+
'version' => @version,
|
601
|
+
'timeStamp' => util.get_timestamp_utc,
|
602
|
+
}
|
603
|
+
query_params = params.clone
|
604
|
+
params.store("threshold", "" + (threshold.to_f).to_s);
|
605
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
606
|
+
puts query_params
|
607
|
+
signature = util.sign(@secret_key, params)
|
608
|
+
resource_url = "#{@version}/#{@resource}/userBasedThreshold/all/#{(threshold.to_f).to_s}/#{(howMany.to_i).to_s}"
|
609
|
+
response = connection.get(signature, resource_url, query_params)
|
610
|
+
recommend = RecommenderResponseBuilder.new()
|
611
|
+
recommenderObj = recommend.buildResponse(response)
|
612
|
+
rescue App42Exception =>e
|
613
|
+
raise e
|
614
|
+
rescue Exception => e
|
615
|
+
raise App42Exception.new(e)
|
616
|
+
end
|
617
|
+
return recommenderObj
|
618
|
+
end
|
619
|
+
|
620
|
+
#
|
621
|
+
# User based recommendations based on Neighborhood and Similarity for all Users. Recommendations and found based similar users in the Neighborhood with
|
622
|
+
# the specified Similarity Algorithm. Algorithim can be specified using the constants Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
|
623
|
+
#
|
624
|
+
# @param recommenderSimilarity
|
625
|
+
# - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
|
626
|
+
# @param peferenceFileName
|
627
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
628
|
+
# @param size
|
629
|
+
# - Size of the Neighborhood
|
630
|
+
# @param howMany
|
631
|
+
# - Specifies that how many recommendations have to be found
|
632
|
+
#
|
633
|
+
# @return Recommendations for all Users
|
634
|
+
#
|
635
|
+
# @raise App42Exception
|
636
|
+
#
|
637
|
+
|
638
|
+
def user_based_neighborhood_by_similarity_for_all(recommenderSimilarity, size, howMany)
|
639
|
+
puts "userBasedNeighborhoodBySimilarityForAll Called "
|
640
|
+
puts "Base url #{@base_url}"
|
641
|
+
response = nil;
|
642
|
+
recommenderObj = nil;
|
643
|
+
recommenderObj = Recommender.new
|
644
|
+
util = Util.new
|
645
|
+
util.validateHowMany(howMany)
|
646
|
+
util.throwExceptionIfNullOrBlank(recommenderSimilarity, "recommenderSimilarity");
|
647
|
+
util.throwExceptionIfNullOrBlank(size, "Size");
|
648
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
649
|
+
begin
|
650
|
+
if (RecommenderSimilarity.new.isAvailable(recommenderSimilarity) == nil)
|
651
|
+
raise App42NotFoundException.new("The RecommenderSimilarity"+ recommenderSimilarity+ "does not Exist ");
|
652
|
+
end
|
653
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
654
|
+
query_params = Hash.new
|
655
|
+
params = {
|
656
|
+
'apiKey'=> @api_key,
|
657
|
+
'version' => @version,
|
658
|
+
'timeStamp' => util.get_timestamp_utc,
|
659
|
+
}
|
660
|
+
query_params = params.clone
|
661
|
+
params.store("size", "" + (size.to_i).to_s);
|
662
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
663
|
+
puts query_params
|
664
|
+
signature = util.sign(@secret_key, params)
|
665
|
+
resource_url = "#{@version}/#{@resource}/userBasedNeighborhood/all/#{size}/#{howMany}"
|
666
|
+
response = connection.get(signature, resource_url, query_params)
|
667
|
+
recommend = RecommenderResponseBuilder.new()
|
668
|
+
recommenderObj = recommend.buildResponse(response)
|
669
|
+
rescue App42Exception =>e
|
670
|
+
raise e
|
671
|
+
rescue Exception => e
|
672
|
+
raise App42Exception.new(e)
|
673
|
+
end
|
674
|
+
return recommenderObj
|
675
|
+
end
|
676
|
+
|
677
|
+
#
|
678
|
+
# User based neighborood recommendations based on Threshold for All. Recommendations are found based on Threshold
|
679
|
+
# where thereshold represents similarity threshold where user are at least that similar.
|
680
|
+
# Threshold values can vary from -1 to 1
|
681
|
+
#
|
682
|
+
# @param recommenderSimilarity
|
683
|
+
# - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
|
684
|
+
# @param peferenceFileName
|
685
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
686
|
+
# @param threshold
|
687
|
+
# - Threshold size. Values can vary from -1 to 1
|
688
|
+
# @param howMany
|
689
|
+
# - Specifies that how many recommendations have to be found
|
690
|
+
#
|
691
|
+
# @return Recommendations for All
|
692
|
+
#
|
693
|
+
# @raise App42Exception
|
694
|
+
#
|
695
|
+
|
696
|
+
def user_based_threshold_by_similarity_for_all(recommenderSimilarity, threshold, howMany)
|
697
|
+
puts "userBasedThresholdBySimilarityForAll Called "
|
698
|
+
puts "Base url #{@base_url}"
|
699
|
+
response = nil;
|
700
|
+
recommenderObj = nil;
|
701
|
+
recommenderObj = Recommender.new
|
702
|
+
util = Util.new
|
703
|
+
util.validateHowMany(howMany)
|
704
|
+
util.throwExceptionIfNullOrBlank(recommenderSimilarity, "recommenderSimilarity");
|
705
|
+
util.throwExceptionIfNullOrBlank(threshold, "Threshold");
|
706
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
707
|
+
begin
|
708
|
+
if (RecommenderSimilarity.new.isAvailable(recommenderSimilarity) == nil)
|
709
|
+
raise App42NotFoundException.new("The RecommenderSimilarity"+ recommenderSimilarity+ "does not Exist ");
|
710
|
+
end
|
711
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
712
|
+
query_params = Hash.new
|
713
|
+
params = {
|
714
|
+
'apiKey'=> @api_key,
|
715
|
+
'version' => @version,
|
716
|
+
'timeStamp' => util.get_timestamp_utc,
|
717
|
+
}
|
718
|
+
query_params = params.clone
|
719
|
+
params.store("similarity", "" + recommenderSimilarity);
|
720
|
+
params.store("threshold", "" + (threshold.to_f).to_s);
|
721
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
722
|
+
puts query_params
|
723
|
+
signature = util.sign(@secret_key, params)
|
724
|
+
resource_url = "#{@version}/#{@resource}/userBasedThreshold/all/#{recommenderSimilarity}/#{(threshold.to_f)}/#{howMany}"
|
725
|
+
response = connection.get(signature, resource_url, query_params)
|
726
|
+
recommend = RecommenderResponseBuilder.new()
|
727
|
+
recommenderObj = recommend.buildResponse(response)
|
728
|
+
rescue App42Exception =>e
|
729
|
+
raise e
|
730
|
+
rescue Exception => e
|
731
|
+
raise App42Exception.new(e)
|
732
|
+
end
|
733
|
+
return recommenderObj
|
734
|
+
end
|
735
|
+
|
736
|
+
#
|
737
|
+
# Item based recommendations for all Users. Recommendations and found based item similarity
|
738
|
+
# of the given user. The size of the neighborhood can be found.
|
739
|
+
#
|
740
|
+
# @param peferenceFileName
|
741
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
742
|
+
# @param howMany
|
743
|
+
# - Specifies that how many recommendations have to be found
|
744
|
+
#
|
745
|
+
# @return Recommendations for all Users
|
746
|
+
#
|
747
|
+
# @raise App42Exception
|
748
|
+
#
|
749
|
+
|
750
|
+
def item_based_for_all(howMany)
|
751
|
+
puts "itemBasedForAll Called "
|
752
|
+
puts "Base url #{@base_url}"
|
753
|
+
response = nil;
|
754
|
+
recommenderObj = nil;
|
755
|
+
recommenderObj = Recommender.new
|
756
|
+
util = Util.new
|
757
|
+
util.validateHowMany(howMany)
|
758
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
759
|
+
begin
|
760
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
761
|
+
query_params = Hash.new
|
762
|
+
params = {
|
763
|
+
'apiKey'=> @api_key,
|
764
|
+
'version' => @version,
|
765
|
+
'timeStamp' => util.get_timestamp_utc,
|
766
|
+
}
|
767
|
+
query_params = params.clone
|
768
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
769
|
+
puts query_params
|
770
|
+
signature = util.sign(@secret_key, params)
|
771
|
+
resource_url = "#{@version}/#{@resource}/itemBased/all/#{howMany}"
|
772
|
+
response = connection.get(signature, resource_url, query_params)
|
773
|
+
recommend = RecommenderResponseBuilder.new()
|
774
|
+
recommenderObj = recommend.buildResponse(response)
|
775
|
+
rescue App42Exception =>e
|
776
|
+
raise e
|
777
|
+
rescue Exception => e
|
778
|
+
raise App42Exception.new(e)
|
779
|
+
end
|
780
|
+
return recommenderObj
|
781
|
+
end
|
782
|
+
|
783
|
+
#
|
784
|
+
# Item based recommendations for all Users. Recommendations and found based one item similarity. Similarity algorithm can be specified.
|
785
|
+
# of the given user. The size of the neighborhood can be found.
|
786
|
+
#
|
787
|
+
# @param recommenderSimilarity
|
788
|
+
# - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
|
789
|
+
# @param peferenceFileName
|
790
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
791
|
+
# @param howMany
|
792
|
+
# - Specifies that how many recommendations have to be found
|
793
|
+
#
|
794
|
+
# @return Recommendations for all Users
|
795
|
+
#
|
796
|
+
# @raise App42Exception
|
797
|
+
#
|
798
|
+
|
799
|
+
def item_based_by_Similarity_for_all(recommenderSimilarity, howMany)
|
800
|
+
puts "itemBasedBySimilarityForAll Called "
|
801
|
+
puts "Base url #{@base_url}"
|
802
|
+
response = nil;
|
803
|
+
recommenderObj = nil;
|
804
|
+
recommenderObj = Recommender.new
|
805
|
+
util = Util.new
|
806
|
+
util.validateHowMany(howMany)
|
807
|
+
util.throwExceptionIfNullOrBlank(recommenderSimilarity, "recommenderSimilarity");
|
808
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
809
|
+
begin
|
810
|
+
if (RecommenderSimilarity.new.isAvailable(recommenderSimilarity) == nil)
|
811
|
+
raise App42NotFoundException.new("The RecommenderSimilarity"+ recommenderSimilarity+ "does not Exist ");
|
812
|
+
end
|
813
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
814
|
+
query_params = Hash.new
|
815
|
+
params = {
|
816
|
+
'apiKey'=> @api_key,
|
817
|
+
'version' => @version,
|
818
|
+
'timeStamp' => util.get_timestamp_utc,
|
819
|
+
}
|
820
|
+
query_params = params.clone
|
821
|
+
params.store("similarity", "" + recommenderSimilarity);
|
822
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
823
|
+
puts query_params
|
824
|
+
signature = util.sign(@secret_key, params)
|
825
|
+
resource_url = "#{@version}/#{@resource}/itemBased/all/#{recommenderSimilarity}/#{howMany}"
|
826
|
+
response = connection.get(signature, resource_url, query_params)
|
827
|
+
recommend = RecommenderResponseBuilder.new()
|
828
|
+
recommenderObj = recommend.buildResponse(response)
|
829
|
+
rescue App42Exception =>e
|
830
|
+
raise e
|
831
|
+
rescue Exception => e
|
832
|
+
raise App42Exception.new(e)
|
833
|
+
end
|
834
|
+
return recommenderObj
|
835
|
+
end
|
836
|
+
|
837
|
+
#
|
838
|
+
# Recommendations based on SlopeOne Algorithm for all Users
|
839
|
+
#
|
840
|
+
# @param peferenceFileName
|
841
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
842
|
+
# @param howMany
|
843
|
+
# - Specifies that how many recommendations have to be found
|
844
|
+
#
|
845
|
+
# @return Recommendations for all Users
|
846
|
+
#
|
847
|
+
# @raise App42Exception
|
848
|
+
#
|
849
|
+
|
850
|
+
def slope_one_for_all(howMany)
|
851
|
+
puts "itemBasedBySimilarityForAll Called "
|
852
|
+
puts "Base url #{@base_url}"
|
853
|
+
response = nil;
|
854
|
+
recommenderObj = nil;
|
855
|
+
recommenderObj = Recommender.new
|
856
|
+
util = Util.new
|
857
|
+
util.validateHowMany(howMany)
|
858
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
859
|
+
begin
|
860
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
861
|
+
query_params = Hash.new
|
862
|
+
params = {
|
863
|
+
'apiKey'=> @api_key,
|
864
|
+
'version' => @version,
|
865
|
+
'timeStamp' => util.get_timestamp_utc,
|
866
|
+
}
|
867
|
+
query_params = params.clone
|
868
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
869
|
+
puts query_params
|
870
|
+
signature = util.sign(@secret_key, params)
|
871
|
+
resource_url = "#{@version}/#{@resource}/slopeOne/all/#{(howMany.to_i).to_s}"
|
872
|
+
response = connection.get(signature, resource_url, query_params)
|
873
|
+
recommend = RecommenderResponseBuilder.new()
|
874
|
+
recommenderObj = recommend.buildResponse(response)
|
875
|
+
rescue App42Exception =>e
|
876
|
+
raise e
|
877
|
+
rescue Exception => e
|
878
|
+
raise App42Exception.new(e)
|
879
|
+
end
|
880
|
+
return recommenderObj
|
881
|
+
end
|
882
|
+
|
883
|
+
#
|
884
|
+
# Item based recommendations. Recommendations and found based one item similarity. Similarity algorithm can be specified.
|
885
|
+
# of the given user. The size of the neighborhood can be found.
|
886
|
+
#
|
887
|
+
# @param recommenderSimilarity
|
888
|
+
# - Similarity algorithm e.g. Recommender.EUCLIDEAN_DISTANCE and Recommender.PEARSON_CORRELATION
|
889
|
+
# @param peferenceFileName
|
890
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
891
|
+
# @param userId
|
892
|
+
# - The user Id for whom recommendations have to be found
|
893
|
+
# @param howMany
|
894
|
+
# - Specifies that how many recommendations have to be found
|
895
|
+
#
|
896
|
+
# @return Recommendation Object
|
897
|
+
#
|
898
|
+
# @raise App42Exception
|
899
|
+
#
|
900
|
+
|
901
|
+
def item_based_by_similarity(recommenderSimilarity, userId, howMany)
|
902
|
+
puts "itemBasedBySimilarity Called "
|
903
|
+
puts "Base url #{@base_url}"
|
904
|
+
response = nil;
|
905
|
+
recommenderObj = nil;
|
906
|
+
recommenderObj = Recommender.new
|
907
|
+
util = Util.new
|
908
|
+
util.validateHowMany(howMany)
|
909
|
+
util.throwExceptionIfNullOrBlank(recommenderSimilarity, "recommenderSimilarity");
|
910
|
+
util.throwExceptionIfNullOrBlank(userId, "User Id");
|
911
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
912
|
+
begin
|
913
|
+
if (RecommenderSimilarity.new.isAvailable(recommenderSimilarity) == nil)
|
914
|
+
raise App42NotFoundException.new("The RecommenderSimilarity"+ recommenderSimilarity+ "does not Exist ");
|
915
|
+
end
|
916
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
917
|
+
query_params = Hash.new
|
918
|
+
params = {
|
919
|
+
'apiKey'=> @api_key,
|
920
|
+
'version' => @version,
|
921
|
+
'timeStamp' => util.get_timestamp_utc,
|
922
|
+
}
|
923
|
+
query_params = params.clone
|
924
|
+
params.store("similarity", "" + recommenderSimilarity);
|
925
|
+
params.store("userId", "" + (userId.to_i).to_s);
|
926
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
927
|
+
puts query_params
|
928
|
+
signature = util.sign(@secret_key, params)
|
929
|
+
resource_url = "#{@version}/#{@resource}/itemBased/#{recommenderSimilarity}/#{userId}/#{howMany}"
|
930
|
+
response = connection.get(signature, resource_url, query_params)
|
931
|
+
recommend = RecommenderResponseBuilder.new()
|
932
|
+
recommenderObj = recommend.buildResponse(response)
|
933
|
+
rescue App42Exception =>e
|
934
|
+
raise e
|
935
|
+
rescue Exception => e
|
936
|
+
raise App42Exception.new(e)
|
937
|
+
end
|
938
|
+
return recommenderObj
|
939
|
+
end
|
940
|
+
|
941
|
+
#
|
942
|
+
# User based recommendations based on Neighborhood for All Users. Recommendations and found based similar users in the Neighborhood
|
943
|
+
# of the given user. The size of the neighborhood can be found.
|
944
|
+
#
|
945
|
+
# @param peferenceFileName
|
946
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
947
|
+
# @param size
|
948
|
+
# - Size of the Neighborhood
|
949
|
+
# @param howMany
|
950
|
+
# - Specifies that how many recommendations have to be found
|
951
|
+
#
|
952
|
+
# @return Recommendations for All users
|
953
|
+
#
|
954
|
+
# @raise App42Exception
|
955
|
+
#
|
956
|
+
|
957
|
+
def user_based_neighborhood_for_all(size, howMany)
|
958
|
+
puts "userBasedNeighborhoodForAll Called "
|
959
|
+
puts "Base url #{@base_url}"
|
960
|
+
response = nil;
|
961
|
+
recommenderObj = nil;
|
962
|
+
recommenderObj = Recommender.new
|
963
|
+
util = Util.new
|
964
|
+
util.validateHowMany(howMany);
|
965
|
+
util.throwExceptionIfNullOrBlank(size, "Size");
|
966
|
+
util.throwExceptionIfNullOrBlank(howMany, "How Many");
|
967
|
+
begin
|
968
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
969
|
+
query_params = Hash.new
|
970
|
+
params = {
|
971
|
+
'apiKey'=> @api_key,
|
972
|
+
'version' => @version,
|
973
|
+
'timeStamp' => util.get_timestamp_utc,
|
974
|
+
}
|
975
|
+
query_params = params.clone
|
976
|
+
params.store("size", "" + (size.to_i).to_s);
|
977
|
+
params.store("howMany", "" + (howMany.to_i).to_s);
|
978
|
+
puts query_params
|
979
|
+
signature = util.sign(@secret_key, params)
|
980
|
+
resource_url = "#{@version}/#{@resource}/userBasedNeighborhood/all/#{size}/#{howMany}"
|
981
|
+
response = connection.get(signature, resource_url, query_params)
|
982
|
+
recommend = RecommenderResponseBuilder.new()
|
983
|
+
recommenderObj = recommend.buildResponse(response)
|
984
|
+
rescue App42Exception =>e
|
985
|
+
raise e
|
986
|
+
rescue Exception => e
|
987
|
+
raise App42Exception.new(e)
|
988
|
+
end
|
989
|
+
return recommenderObj
|
990
|
+
end
|
991
|
+
|
992
|
+
#
|
993
|
+
# Delete existing preference file.
|
994
|
+
#
|
995
|
+
# @param peferenceFileName
|
996
|
+
# - Name of the Prefeence File based on which recommendations have to be found
|
997
|
+
#
|
998
|
+
# @return File name which has been removed
|
999
|
+
#
|
1000
|
+
# @raise App42Exception
|
1001
|
+
#
|
1002
|
+
|
1003
|
+
def delete_all_preferences()
|
1004
|
+
puts "deletePreferenceFile Called "
|
1005
|
+
puts "Base url #{@base_url}"
|
1006
|
+
response = nil;
|
1007
|
+
responseObj = App42Response.new();
|
1008
|
+
util = Util.new
|
1009
|
+
begin
|
1010
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
1011
|
+
query_params = Hash.new
|
1012
|
+
params = {
|
1013
|
+
'apiKey'=> @api_key,
|
1014
|
+
'version' => @version,
|
1015
|
+
'timeStamp' => util.get_timestamp_utc,
|
1016
|
+
}
|
1017
|
+
query_params = params.clone
|
1018
|
+
puts query_params
|
1019
|
+
signature = util.sign(@secret_key, params)
|
1020
|
+
resource_url = "#{@version}/#{@resource}/deleteAllPreferences/"
|
1021
|
+
response = connection.delete(signature, resource_url, query_params)
|
1022
|
+
responseObj.strResponse=(response)
|
1023
|
+
responseObj.isResponseSuccess=(true)
|
1024
|
+
rescue App42Exception =>e
|
1025
|
+
raise e
|
1026
|
+
rescue Exception => e
|
1027
|
+
raise App42Exception.new(e)
|
1028
|
+
end
|
1029
|
+
return responseObj
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
#
|
1033
|
+
# Add or Update preference list on the cloud.
|
1034
|
+
#
|
1035
|
+
# @param preferenceDataList
|
1036
|
+
# - List of PreferenceData which contains customerId, itemId,
|
1037
|
+
# preference
|
1038
|
+
#
|
1039
|
+
# @return App42Response object
|
1040
|
+
#
|
1041
|
+
# @raise App42Exception
|
1042
|
+
#
|
1043
|
+
#
|
1044
|
+
|
1045
|
+
def add_or_update_preference(preferenceDataList)
|
1046
|
+
puts "addOrUpdatePreference Called "
|
1047
|
+
response = nil
|
1048
|
+
responseObj = App42Response.new();
|
1049
|
+
util = Util.new
|
1050
|
+
util.throwExceptionIfNullOrBlank(preferenceDataList, "preferenceDataList")
|
1051
|
+
begin
|
1052
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
1053
|
+
post_params=Hash.new
|
1054
|
+
preferenceDataArray = Array.new()
|
1055
|
+
for preferenceData in preferenceDataList do
|
1056
|
+
post_params.store("userId", preferenceData.userId())
|
1057
|
+
post_params.store("itemId", preferenceData.itemId())
|
1058
|
+
post_params.store("preference", preferenceData.preference())
|
1059
|
+
preferenceDataArray.push(post_params)
|
1060
|
+
end
|
1061
|
+
preference = Array.new
|
1062
|
+
body = {'app42' => {
|
1063
|
+
"preferences" => preference,
|
1064
|
+
"preference"=> preferenceDataArray
|
1065
|
+
}}.to_json
|
1066
|
+
puts "Body #{body}"
|
1067
|
+
params = Hash.new
|
1068
|
+
query_params = Hash.new
|
1069
|
+
params = {
|
1070
|
+
'apiKey'=> @api_key,
|
1071
|
+
'version' => @version,
|
1072
|
+
'timeStamp' => util.get_timestamp_utc,
|
1073
|
+
}
|
1074
|
+
query_params = params.clone
|
1075
|
+
params.store("body", body)
|
1076
|
+
puts query_params
|
1077
|
+
signature = util.sign(@secret_key, params)
|
1078
|
+
resource_url = "#{@version}/#{@resource}/addOrUpdatePreference"
|
1079
|
+
response = connection.post(signature, resource_url, query_params, body)
|
1080
|
+
responseObj.strResponse=(response)
|
1081
|
+
responseObj.isResponseSuccess=(true)
|
1082
|
+
rescue App42Exception =>e
|
1083
|
+
raise e
|
1084
|
+
rescue Exception => e
|
1085
|
+
raise App42Exception.new(e)
|
1086
|
+
end
|
1087
|
+
return responseObj
|
1088
|
+
end
|
1089
|
+
|
1090
|
+
end
|
1091
|
+
end
|
1092
|
+
end
|