recombee_api_client 1.2.5 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -24
- data/lib/recombee_api_client/api/add_user_property.rb +55 -0
- data/lib/recombee_api_client/api/delete_user_property.rb +50 -0
- data/lib/recombee_api_client/api/get_user_property_info.rb +50 -0
- data/lib/recombee_api_client/api/get_user_values.rb +51 -0
- data/lib/recombee_api_client/api/item_based_recommendation.rb +9 -3
- data/lib/recombee_api_client/api/list_user_properties.rb +47 -0
- data/lib/recombee_api_client/api/set_item_values.rb +9 -28
- data/lib/recombee_api_client/api/set_user_values.rb +42 -0
- data/lib/recombee_api_client/api/user_based_recommendation.rb +1 -1
- data/lib/recombee_api_client/version.rb +1 -1
- data/lib/recombee_api_client.rb +11 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01eda031f563d917d6ab45fc0df38088548040f0
|
4
|
+
data.tar.gz: 4cde01351f86b3fdf7eb7d860e765e9aab61d324
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 554558dbacfc64473c3611ed0a258921cedf8541e19fb1555f567c6dac1ea718f80a2e7db19ea4a7f44fb20a516ec971ef8571ff73eeea4f5216aae3b7d7a6a8
|
7
|
+
data.tar.gz: b632b4e5ba2dc78402955a4a418a555e14fa89a9a767d10d46329282723764e6490a77ef8d387266030244cc430163295d9b81f5e80f5095307eda437f7534b2
|
data/README.md
CHANGED
@@ -29,36 +29,37 @@ Or install it yourself as:
|
|
29
29
|
require 'recombee_api_client'
|
30
30
|
include RecombeeApiClient
|
31
31
|
|
32
|
-
|
33
|
-
NUM = 100
|
34
|
-
my_users = (1..NUM).map { |i| "user-#{i}" }
|
35
|
-
my_items = (1..NUM).map { |i| "item-#{i}" }
|
32
|
+
client = RecombeeClient.new('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L')
|
36
33
|
|
37
|
-
#Generate some random purchases of items by users
|
34
|
+
# Generate some random purchases of items by users
|
35
|
+
NUM = 100
|
38
36
|
PROBABILITY_PURCHASED = 0.1
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
|
38
|
+
users = (1..NUM).map { |i| "user-#{i}" }
|
39
|
+
items = (1..NUM).map { |i| "item-#{i}" }
|
40
|
+
purchases = []
|
41
|
+
|
42
|
+
users.each do |user_id|
|
43
|
+
purchased = items.select { |_| rand(0.0..1.0) < PROBABILITY_PURCHASED }
|
44
|
+
purchased.each { |item_id| purchases.push(
|
45
|
+
|
46
|
+
AddPurchase.new(user_id, item_id,'cascadeCreate' => true)
|
47
|
+
# Use cascadeCreate to create the
|
48
|
+
# yet non-existing users and items
|
49
|
+
)}
|
50
|
+
|
43
51
|
end
|
44
52
|
|
45
|
-
# Use Recombee recommender
|
46
|
-
client = RecombeeClient.new('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L')
|
47
53
|
begin
|
48
|
-
# Send the data to Recombee, use Batch for faster processing
|
49
|
-
|
50
|
-
client.send(Batch.new(my_users.map { |userId| AddUser.new(userId) }))
|
51
|
-
puts 'Send items'
|
52
|
-
client.send(Batch.new(my_items.map { |itemId| AddItem.new(itemId) }))
|
53
|
-
puts 'Send purchases'
|
54
|
-
client.send(Batch.new(my_purchases.map { |p| AddPurchase.new(p['userId'], p['itemId']) }))
|
54
|
+
# Send the data to Recombee, use Batch for faster processing of larger data
|
55
|
+
client.send(Batch.new(purchases))
|
55
56
|
|
56
57
|
# Get recommendations for user 'user-25'
|
57
|
-
|
58
|
-
|
59
|
-
puts "Recommended items: #{recommended}"
|
58
|
+
recommended = client.send(UserBasedRecommendation.new('user-25', 5))
|
59
|
+
puts "Recommended items for user-25: #{recommended}"
|
60
60
|
rescue APIError => e
|
61
61
|
puts e
|
62
|
+
# Use fallback
|
62
63
|
end
|
63
64
|
```
|
64
65
|
|
@@ -71,7 +72,8 @@ NUM = 100
|
|
71
72
|
PROBABILITY_PURCHASED = 0.1
|
72
73
|
|
73
74
|
client = RecombeeClient.new('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L')
|
74
|
-
client.send(ResetDatabase.new)
|
75
|
+
client.send(ResetDatabase.new) # Clear everything from the database
|
76
|
+
|
75
77
|
# We will use computers as items in this example
|
76
78
|
# Computers have three properties
|
77
79
|
# - price (floating point number)
|
@@ -82,6 +84,7 @@ client.send(ResetDatabase.new)
|
|
82
84
|
client.send(AddItemProperty.new('price', 'double'))
|
83
85
|
client.send(AddItemProperty.new('num-cores', 'int'))
|
84
86
|
client.send(AddItemProperty.new('description', 'string'))
|
87
|
+
client.send(AddItemProperty.new('time', 'timestamp'))
|
85
88
|
|
86
89
|
# Prepare requests for setting a catalog of computers
|
87
90
|
requests = (1..NUM).map do |i|
|
@@ -92,14 +95,18 @@ requests = (1..NUM).map do |i|
|
|
92
95
|
'price' => rand(15000.0 .. 25000.0),
|
93
96
|
'num-cores' => rand(1..8),
|
94
97
|
'description' => 'Great computer',
|
95
|
-
'
|
98
|
+
'time' => DateTime.now
|
99
|
+
},
|
100
|
+
#optional parameters:
|
101
|
+
{
|
102
|
+
'cascadeCreate' => true # Use cascadeCreate for creating item
|
96
103
|
# with given itemId, if it doesn't exist
|
97
104
|
}
|
98
105
|
)
|
99
106
|
end
|
100
107
|
|
101
108
|
# Send catalog to the recommender system
|
102
|
-
client.send(Batch.new(requests))
|
109
|
+
puts client.send(Batch.new(requests))
|
103
110
|
|
104
111
|
# Prepare some purchases of items by users
|
105
112
|
requests = []
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# This file is auto-generated, do not edit
|
3
|
+
#
|
4
|
+
|
5
|
+
module RecombeeApiClient
|
6
|
+
require_relative 'request'
|
7
|
+
require_relative '../errors'
|
8
|
+
|
9
|
+
##
|
10
|
+
#Adding an user property is somehow equivalent to adding a column to the table of users. The users may be characterized by various properties of different types.
|
11
|
+
#
|
12
|
+
class AddUserProperty < ApiRequest
|
13
|
+
attr_reader :property_name, :type
|
14
|
+
attr_accessor :timeout
|
15
|
+
attr_accessor :ensure_https
|
16
|
+
|
17
|
+
##
|
18
|
+
# * *Required arguments*
|
19
|
+
# - +property_name+ -> Name of the user property to be created. Currently, the following names are reserved:`id`, `userid`, case insensitively. Also, the length of the property name must not exceed 63 characters.
|
20
|
+
#
|
21
|
+
# - +type+ -> Value type of the user property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`
|
22
|
+
#
|
23
|
+
#
|
24
|
+
def initialize(property_name, type)
|
25
|
+
@property_name = property_name
|
26
|
+
@type = type
|
27
|
+
@timeout = 1000
|
28
|
+
@ensure_https = false
|
29
|
+
end
|
30
|
+
|
31
|
+
# HTTP method
|
32
|
+
def method
|
33
|
+
:put
|
34
|
+
end
|
35
|
+
|
36
|
+
# Values of body parameters as a Hash
|
37
|
+
def body_parameters
|
38
|
+
p = Hash.new
|
39
|
+
p
|
40
|
+
end
|
41
|
+
|
42
|
+
# Values of query parameters as a Hash.
|
43
|
+
# name of parameter => value of the parameter
|
44
|
+
def query_parameters
|
45
|
+
params = {}
|
46
|
+
params['type'] = @type
|
47
|
+
params
|
48
|
+
end
|
49
|
+
|
50
|
+
# Relative path to the endpoint
|
51
|
+
def path
|
52
|
+
"/{databaseId}/users/properties/#{@property_name}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# This file is auto-generated, do not edit
|
3
|
+
#
|
4
|
+
|
5
|
+
module RecombeeApiClient
|
6
|
+
require_relative 'request'
|
7
|
+
require_relative '../errors'
|
8
|
+
|
9
|
+
##
|
10
|
+
#Deleting an user property is roughly equivalent to removing a column from the table of users.
|
11
|
+
#
|
12
|
+
class DeleteUserProperty < ApiRequest
|
13
|
+
attr_reader :property_name
|
14
|
+
attr_accessor :timeout
|
15
|
+
attr_accessor :ensure_https
|
16
|
+
|
17
|
+
##
|
18
|
+
# * *Required arguments*
|
19
|
+
# - +property_name+ -> Name of the property to be deleted.
|
20
|
+
#
|
21
|
+
def initialize(property_name)
|
22
|
+
@property_name = property_name
|
23
|
+
@timeout = 1000
|
24
|
+
@ensure_https = false
|
25
|
+
end
|
26
|
+
|
27
|
+
# HTTP method
|
28
|
+
def method
|
29
|
+
:delete
|
30
|
+
end
|
31
|
+
|
32
|
+
# Values of body parameters as a Hash
|
33
|
+
def body_parameters
|
34
|
+
p = Hash.new
|
35
|
+
p
|
36
|
+
end
|
37
|
+
|
38
|
+
# Values of query parameters as a Hash.
|
39
|
+
# name of parameter => value of the parameter
|
40
|
+
def query_parameters
|
41
|
+
params = {}
|
42
|
+
params
|
43
|
+
end
|
44
|
+
|
45
|
+
# Relative path to the endpoint
|
46
|
+
def path
|
47
|
+
"/{databaseId}/users/properties/#{@property_name}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# This file is auto-generated, do not edit
|
3
|
+
#
|
4
|
+
|
5
|
+
module RecombeeApiClient
|
6
|
+
require_relative 'request'
|
7
|
+
require_relative '../errors'
|
8
|
+
|
9
|
+
##
|
10
|
+
#Gets information about specified user property.
|
11
|
+
#
|
12
|
+
class GetUserPropertyInfo < ApiRequest
|
13
|
+
attr_reader :property_name
|
14
|
+
attr_accessor :timeout
|
15
|
+
attr_accessor :ensure_https
|
16
|
+
|
17
|
+
##
|
18
|
+
# * *Required arguments*
|
19
|
+
# - +property_name+ -> Name of the property about which the information is to be retrieved.
|
20
|
+
#
|
21
|
+
def initialize(property_name)
|
22
|
+
@property_name = property_name
|
23
|
+
@timeout = 1000
|
24
|
+
@ensure_https = false
|
25
|
+
end
|
26
|
+
|
27
|
+
# HTTP method
|
28
|
+
def method
|
29
|
+
:get
|
30
|
+
end
|
31
|
+
|
32
|
+
# Values of body parameters as a Hash
|
33
|
+
def body_parameters
|
34
|
+
p = Hash.new
|
35
|
+
p
|
36
|
+
end
|
37
|
+
|
38
|
+
# Values of query parameters as a Hash.
|
39
|
+
# name of parameter => value of the parameter
|
40
|
+
def query_parameters
|
41
|
+
params = {}
|
42
|
+
params
|
43
|
+
end
|
44
|
+
|
45
|
+
# Relative path to the endpoint
|
46
|
+
def path
|
47
|
+
"/{databaseId}/users/properties/#{@property_name}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# This file is auto-generated, do not edit
|
3
|
+
#
|
4
|
+
|
5
|
+
module RecombeeApiClient
|
6
|
+
require_relative 'request'
|
7
|
+
require_relative '../errors'
|
8
|
+
|
9
|
+
##
|
10
|
+
#Get all the current property values of a given user.
|
11
|
+
#
|
12
|
+
class GetUserValues < ApiRequest
|
13
|
+
attr_reader :user_id
|
14
|
+
attr_accessor :timeout
|
15
|
+
attr_accessor :ensure_https
|
16
|
+
|
17
|
+
##
|
18
|
+
# * *Required arguments*
|
19
|
+
# - +user_id+ -> ID of the user properties of which are to be obtained.
|
20
|
+
#
|
21
|
+
#
|
22
|
+
def initialize(user_id)
|
23
|
+
@user_id = user_id
|
24
|
+
@timeout = 1000
|
25
|
+
@ensure_https = false
|
26
|
+
end
|
27
|
+
|
28
|
+
# HTTP method
|
29
|
+
def method
|
30
|
+
:get
|
31
|
+
end
|
32
|
+
|
33
|
+
# Values of body parameters as a Hash
|
34
|
+
def body_parameters
|
35
|
+
p = Hash.new
|
36
|
+
p
|
37
|
+
end
|
38
|
+
|
39
|
+
# Values of query parameters as a Hash.
|
40
|
+
# name of parameter => value of the parameter
|
41
|
+
def query_parameters
|
42
|
+
params = {}
|
43
|
+
params
|
44
|
+
end
|
45
|
+
|
46
|
+
# Relative path to the endpoint
|
47
|
+
def path
|
48
|
+
"/{databaseId}/users/#{@user_id}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -21,6 +21,12 @@ module RecombeeApiClient
|
|
21
21
|
#
|
22
22
|
# * *Optional arguments (given as hash optional)*
|
23
23
|
# - +targetUserId+ -> ID of the user who will see the recommendations.
|
24
|
+
#
|
25
|
+
#Specifying the *targetUserId* is beneficial because:
|
26
|
+
#
|
27
|
+
#* It makes the recommendations personalized
|
28
|
+
#* Allows calculations of Actions and Conversions in the graphical user interface, as Recombee can pair the user who got recommendations and who afterwards viewed/purchased an item.
|
29
|
+
#
|
24
30
|
# - +userImpact+ -> If *targetUserId* parameter is present, the recommendations are biased towards the user given. Using *userImpact*, you may control this bias. For an extreme case of `userImpact=0.0`, the interactions made by the user are not taken into account at all (with the exception of history-based blacklisting), for `userImpact=1.0`, you'll get user-based recommendation. The default value is `0.1`
|
25
31
|
#
|
26
32
|
# - +filter+ -> Boolean-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to filter recommended items based on the values of their attributes.
|
@@ -70,11 +76,11 @@ module RecombeeApiClient
|
|
70
76
|
#
|
71
77
|
# - +diversity+ -> **Expert option** Real number from [0.0, 1.0] which determines how much mutually dissimilar should the recommended items be. The default value is 0.0, i.e., no diversification. Value 1.0 means maximal diversification.
|
72
78
|
#
|
73
|
-
# - +minRelevance+ -> **Expert option** Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested qualit, and may return less than *count* items when there is not enough data to fulfill it.
|
79
|
+
# - +minRelevance+ -> **Expert option** If the *targetUserId* is provided: Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested qualit, and may return less than *count* items when there is not enough data to fulfill it.
|
74
80
|
#
|
75
|
-
# - +rotationRate+ -> **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items.
|
81
|
+
# - +rotationRate+ -> **Expert option** If the *targetUserId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items.
|
76
82
|
#
|
77
|
-
# - +rotationTime+ -> **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization.
|
83
|
+
# - +rotationTime+ -> **Expert option** If the *targetUserId* is provided: Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. For example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour.
|
78
84
|
#
|
79
85
|
#
|
80
86
|
def initialize(item_id, count, optional = {})
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# This file is auto-generated, do not edit
|
3
|
+
#
|
4
|
+
|
5
|
+
module RecombeeApiClient
|
6
|
+
require_relative 'request'
|
7
|
+
require_relative '../errors'
|
8
|
+
|
9
|
+
##
|
10
|
+
#Gets the list of all the user properties in your database.
|
11
|
+
#
|
12
|
+
class ListUserProperties < ApiRequest
|
13
|
+
|
14
|
+
attr_accessor :timeout
|
15
|
+
attr_accessor :ensure_https
|
16
|
+
|
17
|
+
##
|
18
|
+
#
|
19
|
+
def initialize()
|
20
|
+
@timeout = 1000
|
21
|
+
@ensure_https = false
|
22
|
+
end
|
23
|
+
|
24
|
+
# HTTP method
|
25
|
+
def method
|
26
|
+
:get
|
27
|
+
end
|
28
|
+
|
29
|
+
# Values of body parameters as a Hash
|
30
|
+
def body_parameters
|
31
|
+
p = Hash.new
|
32
|
+
p
|
33
|
+
end
|
34
|
+
|
35
|
+
# Values of query parameters as a Hash.
|
36
|
+
# name of parameter => value of the parameter
|
37
|
+
def query_parameters
|
38
|
+
params = {}
|
39
|
+
params
|
40
|
+
end
|
41
|
+
|
42
|
+
# Relative path to the endpoint
|
43
|
+
def path
|
44
|
+
"/{databaseId}/users/properties/list/"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,16 +1,12 @@
|
|
1
|
-
#
|
2
|
-
# This file is auto-generated, do not edit
|
3
|
-
#
|
4
|
-
|
5
1
|
module RecombeeApiClient
|
6
|
-
require_relative '
|
2
|
+
require_relative 'set_values'
|
7
3
|
require_relative '../errors'
|
8
4
|
|
9
5
|
##
|
10
6
|
#Set/update (some) property values of a given item. The properties (columns) must be previously created by [Add item property](https://docs.recombee.com/api.html#add-item-property).
|
11
7
|
#
|
12
|
-
class SetItemValues <
|
13
|
-
attr_reader :item_id
|
8
|
+
class SetItemValues < SetValues
|
9
|
+
attr_reader :item_id
|
14
10
|
attr_accessor :timeout
|
15
11
|
attr_accessor :ensure_https
|
16
12
|
|
@@ -26,6 +22,7 @@ module RecombeeApiClient
|
|
26
22
|
# "product_description": "4K TV with 3D feature",
|
27
23
|
# "categories": ["Electronics", "Televisions"],
|
28
24
|
# "price_usd": 342,
|
25
|
+
# "in_stock_from": "2016-11-16T08:00Z",
|
29
26
|
# "!cascadeCreate": true
|
30
27
|
# }
|
31
28
|
#```
|
@@ -33,32 +30,16 @@ module RecombeeApiClient
|
|
33
30
|
#Special parameter `!cascadeCreate` may be used. It indicates that the item of the given itemId should be created if it does not exist in the database, as if the corresponding PUT method was used. Note the exclamation mark (!) at the beginning of the parameter's name to distinguish it from item property names.
|
34
31
|
#
|
35
32
|
#
|
36
|
-
|
33
|
+
# * *Optional arguments (given as hash optional)*
|
34
|
+
# - +cascadeCreate+ -> Sets whether the item should be created if not present in the database.
|
35
|
+
#
|
36
|
+
def initialize(item_id, values, optional = {})
|
37
|
+
super(values, optional)
|
37
38
|
@item_id = item_id
|
38
|
-
@values = values
|
39
39
|
@timeout = 1000
|
40
40
|
@ensure_https = false
|
41
41
|
end
|
42
42
|
|
43
|
-
# HTTP method
|
44
|
-
def method
|
45
|
-
:post
|
46
|
-
end
|
47
|
-
|
48
|
-
# Values of body parameters as a Hash
|
49
|
-
def body_parameters
|
50
|
-
p = Hash.new
|
51
|
-
p = p.merge(@values)
|
52
|
-
p
|
53
|
-
end
|
54
|
-
|
55
|
-
# Values of query parameters as a Hash.
|
56
|
-
# name of parameter => value of the parameter
|
57
|
-
def query_parameters
|
58
|
-
params = {}
|
59
|
-
params
|
60
|
-
end
|
61
|
-
|
62
43
|
# Relative path to the endpoint
|
63
44
|
def path
|
64
45
|
"/{databaseId}/items/#{@item_id}"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RecombeeApiClient
|
2
|
+
require_relative 'set_values'
|
3
|
+
require_relative '../errors'
|
4
|
+
|
5
|
+
##
|
6
|
+
#Set/update (some) property values of a given user. The properties (columns) must be previously created by [Add user property](https://docs.recombee.com/api.html#add-user-property).
|
7
|
+
#
|
8
|
+
class SetUserValues < SetValues
|
9
|
+
attr_reader :user_id
|
10
|
+
attr_accessor :timeout
|
11
|
+
attr_accessor :ensure_https
|
12
|
+
|
13
|
+
##
|
14
|
+
# * *Required arguments*
|
15
|
+
# - +user_id+ -> ID of the user which will be modified.
|
16
|
+
#
|
17
|
+
# - +values+ -> The values for the individual properties.
|
18
|
+
#
|
19
|
+
#Example of body:
|
20
|
+
#```
|
21
|
+
# {
|
22
|
+
# "country": "US",
|
23
|
+
# "sex": "F",
|
24
|
+
# }
|
25
|
+
#```
|
26
|
+
#
|
27
|
+
# * *Optional arguments (given as hash optional)*
|
28
|
+
# - +cascadeCreate+ -> Sets whether the item should be created if not present in the database.
|
29
|
+
#
|
30
|
+
def initialize(user_id, values, optional = {})
|
31
|
+
super(values, optional)
|
32
|
+
@user_id = user_id
|
33
|
+
@timeout = 1000
|
34
|
+
@ensure_https = false
|
35
|
+
end
|
36
|
+
|
37
|
+
# Relative path to the endpoint
|
38
|
+
def path
|
39
|
+
"/{databaseId}/users/#{@user_id}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -71,7 +71,7 @@ module RecombeeApiClient
|
|
71
71
|
#
|
72
72
|
# - +rotationRate+ -> **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items.
|
73
73
|
#
|
74
|
-
# - +rotationTime+ -> **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization.
|
74
|
+
# - +rotationTime+ -> **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to fully recover from the penalization. For example, `rotationTime=7200.0` means that items recommended more than 2 hours ago are definitely not penalized anymore. Currently, the penalization is linear, so for `rotationTime=7200.0`, an item is still penalized by `0.5` to the user after 1 hour.
|
75
75
|
#
|
76
76
|
#
|
77
77
|
def initialize(user_id, count, optional = {})
|
data/lib/recombee_api_client.rb
CHANGED
@@ -17,6 +17,8 @@ module RecombeeApiClient
|
|
17
17
|
class RecombeeClient
|
18
18
|
include HTTParty
|
19
19
|
|
20
|
+
BATCH_MAX_SIZE = 10000
|
21
|
+
|
20
22
|
##
|
21
23
|
# - +account+ -> Name of your account at Recombee
|
22
24
|
# - +token+ -> Secret token obtained from Recombee for signing requests
|
@@ -33,6 +35,9 @@ module RecombeeApiClient
|
|
33
35
|
##
|
34
36
|
# - +request+ -> ApiRequest to be sent to Recombee recommender
|
35
37
|
def send(request)
|
38
|
+
|
39
|
+
return send_multipart_batch(request) if request.kind_of? Batch and request.requests.size > BATCH_MAX_SIZE
|
40
|
+
|
36
41
|
timeout = request.timeout / 1000
|
37
42
|
uri = process_request_uri(request)
|
38
43
|
uri = sign_url(uri)
|
@@ -94,6 +99,12 @@ module RecombeeApiClient
|
|
94
99
|
fail ResponseError.new(request, status_code, response.body)
|
95
100
|
end
|
96
101
|
|
102
|
+
def send_multipart_batch(request)
|
103
|
+
requests_parts = request.requests.each_slice(BATCH_MAX_SIZE)
|
104
|
+
responses = requests_parts.map {|rqs| Batch.new(rqs)}.map{|batch| send(batch)}
|
105
|
+
responses.inject([]){|result,resp| result + resp}
|
106
|
+
end
|
107
|
+
|
97
108
|
def process_request_uri(request)
|
98
109
|
uri = request.path
|
99
110
|
uri.slice! ('/{databaseId}/')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recombee_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondřej Fiedler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/recombee_api_client/api/add_rating.rb
|
103
103
|
- lib/recombee_api_client/api/add_series.rb
|
104
104
|
- lib/recombee_api_client/api/add_user.rb
|
105
|
+
- lib/recombee_api_client/api/add_user_property.rb
|
105
106
|
- lib/recombee_api_client/api/batch.rb
|
106
107
|
- lib/recombee_api_client/api/delete_bookmark.rb
|
107
108
|
- lib/recombee_api_client/api/delete_cart_addition.rb
|
@@ -113,8 +114,11 @@ files:
|
|
113
114
|
- lib/recombee_api_client/api/delete_rating.rb
|
114
115
|
- lib/recombee_api_client/api/delete_series.rb
|
115
116
|
- lib/recombee_api_client/api/delete_user.rb
|
117
|
+
- lib/recombee_api_client/api/delete_user_property.rb
|
116
118
|
- lib/recombee_api_client/api/get_item_property_info.rb
|
117
119
|
- lib/recombee_api_client/api/get_item_values.rb
|
120
|
+
- lib/recombee_api_client/api/get_user_property_info.rb
|
121
|
+
- lib/recombee_api_client/api/get_user_values.rb
|
118
122
|
- lib/recombee_api_client/api/insert_to_group.rb
|
119
123
|
- lib/recombee_api_client/api/insert_to_series.rb
|
120
124
|
- lib/recombee_api_client/api/item_based_recommendation.rb
|
@@ -132,6 +136,7 @@ files:
|
|
132
136
|
- lib/recombee_api_client/api/list_user_bookmarks.rb
|
133
137
|
- lib/recombee_api_client/api/list_user_cart_additions.rb
|
134
138
|
- lib/recombee_api_client/api/list_user_detail_views.rb
|
139
|
+
- lib/recombee_api_client/api/list_user_properties.rb
|
135
140
|
- lib/recombee_api_client/api/list_user_purchases.rb
|
136
141
|
- lib/recombee_api_client/api/list_user_ratings.rb
|
137
142
|
- lib/recombee_api_client/api/list_users.rb
|
@@ -141,6 +146,7 @@ files:
|
|
141
146
|
- lib/recombee_api_client/api/request.rb
|
142
147
|
- lib/recombee_api_client/api/reset_database.rb
|
143
148
|
- lib/recombee_api_client/api/set_item_values.rb
|
149
|
+
- lib/recombee_api_client/api/set_user_values.rb
|
144
150
|
- lib/recombee_api_client/api/user_based_recommendation.rb
|
145
151
|
- lib/recombee_api_client/errors.rb
|
146
152
|
- lib/recombee_api_client/version.rb
|
@@ -165,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
171
|
version: '0'
|
166
172
|
requirements: []
|
167
173
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.6.8
|
169
175
|
signing_key:
|
170
176
|
specification_version: 4
|
171
177
|
summary: Client for Recombee recommendation API
|