Skip to content

Commit c7ab39b

Browse files
committed
Support Item Segmentations
1 parent 8f0829d commit c7ab39b

File tree

112 files changed

+1967
-215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1967
-215
lines changed

recombee_api_client/api_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __get_base_uri(options: dict, region: str) -> str:
9494

9595
@staticmethod
9696
def __get_http_headers(additional_headers: dict = None) -> dict:
97-
headers = {'User-Agent': 'recombee-python-api-client/4.0.0'}
97+
headers = {'User-Agent': 'recombee-python-api-client/4.1.0'}
9898
if additional_headers:
9999
headers.update(additional_headers)
100100
return headers

recombee_api_client/api_requests/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,27 @@
6060
from recombee_api_client.api_requests.recommend_next_items import RecommendNextItems
6161
from recombee_api_client.api_requests.recommend_users_to_user import RecommendUsersToUser
6262
from recombee_api_client.api_requests.recommend_users_to_item import RecommendUsersToItem
63+
from recombee_api_client.api_requests.recommend_item_segments_to_user import RecommendItemSegmentsToUser
64+
from recombee_api_client.api_requests.recommend_item_segments_to_item import RecommendItemSegmentsToItem
65+
from recombee_api_client.api_requests.recommend_item_segments_to_item_segment import RecommendItemSegmentsToItemSegment
6366
from recombee_api_client.api_requests.search_items import SearchItems
67+
from recombee_api_client.api_requests.search_item_segments import SearchItemSegments
6468
from recombee_api_client.api_requests.add_search_synonym import AddSearchSynonym
6569
from recombee_api_client.api_requests.list_search_synonyms import ListSearchSynonyms
6670
from recombee_api_client.api_requests.delete_all_search_synonyms import DeleteAllSearchSynonyms
6771
from recombee_api_client.api_requests.delete_search_synonym import DeleteSearchSynonym
72+
from recombee_api_client.api_requests.create_property_based_segmentation import CreatePropertyBasedSegmentation
73+
from recombee_api_client.api_requests.update_property_based_segmentation import UpdatePropertyBasedSegmentation
74+
from recombee_api_client.api_requests.create_auto_reql_segmentation import CreateAutoReqlSegmentation
75+
from recombee_api_client.api_requests.update_auto_reql_segmentation import UpdateAutoReqlSegmentation
76+
from recombee_api_client.api_requests.create_manual_reql_segmentation import CreateManualReqlSegmentation
77+
from recombee_api_client.api_requests.update_manual_reql_segmentation import UpdateManualReqlSegmentation
78+
from recombee_api_client.api_requests.add_manual_reql_segment import AddManualReqlSegment
79+
from recombee_api_client.api_requests.update_manual_reql_segment import UpdateManualReqlSegment
80+
from recombee_api_client.api_requests.delete_manual_reql_segment import DeleteManualReqlSegment
81+
from recombee_api_client.api_requests.list_segmentations import ListSegmentations
82+
from recombee_api_client.api_requests.get_segmentation import GetSegmentation
83+
from recombee_api_client.api_requests.delete_segmentation import DeleteSegmentation
6884
from recombee_api_client.api_requests.reset_database import ResetDatabase
6985
from recombee_api_client.api_requests.batch import Batch
7086
from recombee_api_client.api_requests.request import Request

recombee_api_client/api_requests/add_bookmark.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class AddBookmark(Request):
88
"""
9-
Adds a bookmark of a given item made by a given user.
9+
Adds a bookmark of the given item made by the given user.
1010
1111
Required parameters:
1212
@@ -29,7 +29,7 @@ class AddBookmark(Request):
2929
"""
3030

3131
def __init__(self, user_id: str, item_id: str, timestamp: Union[str, int] = DEFAULT, cascade_create: bool = DEFAULT, recomm_id: str = DEFAULT, additional_data: dict = DEFAULT):
32-
super().__init__(path="/bookmarks/" % (), method='post', timeout=1000, ensure_https=False)
32+
super().__init__(path="/bookmarks/", method='post', timeout=1000, ensure_https=False)
3333
self.user_id = user_id
3434
self.item_id = item_id
3535
self.timestamp = timestamp

recombee_api_client/api_requests/add_cart_addition.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class AddCartAddition(Request):
88
"""
9-
Adds a cart addition of a given item made by a given user.
9+
Adds a cart addition of the given item made by the given user.
1010
1111
Required parameters:
1212
@@ -21,9 +21,9 @@ class AddCartAddition(Request):
2121
2222
:param cascade_create: Sets whether the given user/item should be created if not present in the database.
2323
24-
:param amount: Amount (number) added to cart. The default is 1. For example if `user-x` adds two `item-y` during a single order (session...), the `amount` should equal to 2.
24+
:param amount: Amount (number) added to cart. The default is 1. For example, if `user-x` adds two `item-y` during a single order (session...), the `amount` should equal 2.
2525
26-
:param price: Price of the added item. If `amount` is greater than 1, sum of prices of all the items should be given.
26+
:param price: Price of the added item. If `amount` is greater than 1, the sum of prices of all the items should be given.
2727
2828
:param recomm_id: If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
2929
@@ -33,7 +33,7 @@ class AddCartAddition(Request):
3333
"""
3434

3535
def __init__(self, user_id: str, item_id: str, timestamp: Union[str, int] = DEFAULT, cascade_create: bool = DEFAULT, amount: float = DEFAULT, price: float = DEFAULT, recomm_id: str = DEFAULT, additional_data: dict = DEFAULT):
36-
super().__init__(path="/cartadditions/" % (), method='post', timeout=1000, ensure_https=False)
36+
super().__init__(path="/cartadditions/", method='post', timeout=1000, ensure_https=False)
3737
self.user_id = user_id
3838
self.item_id = item_id
3939
self.timestamp = timestamp

recombee_api_client/api_requests/add_detail_view.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class AddDetailView(Request):
88
"""
9-
Adds a detail view of a given item made by a given user.
9+
Adds a detail view of the given item made by the given user.
1010
1111
Required parameters:
1212
@@ -31,7 +31,7 @@ class AddDetailView(Request):
3131
"""
3232

3333
def __init__(self, user_id: str, item_id: str, timestamp: Union[str, int] = DEFAULT, duration: int = DEFAULT, cascade_create: bool = DEFAULT, recomm_id: str = DEFAULT, additional_data: dict = DEFAULT):
34-
super().__init__(path="/detailviews/" % (), method='post', timeout=1000, ensure_https=False)
34+
super().__init__(path="/detailviews/", method='post', timeout=1000, ensure_https=False)
3535
self.user_id = user_id
3636
self.item_id = item_id
3737
self.timestamp = timestamp

recombee_api_client/api_requests/add_group.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class AddGroup(Request):
88
"""
9-
Creates new group in the database.
9+
Creates a new group in the database.
1010
Required parameters:
1111
1212
:param group_id: ID of the group to be created.

recombee_api_client/api_requests/add_item.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
class AddItem(Request):
88
"""
9-
Adds new item of given `itemId` to the items catalog.
9+
Adds new item of the given `itemId` to the items catalog.
1010
11-
All the item properties for the newly created items are set null.
11+
All the item properties for the newly created items are set to null.
1212
1313
Required parameters:
1414

recombee_api_client/api_requests/add_item_property.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AddItemProperty(Request):
1010
1111
Required parameters:
1212
13-
:param property_name: Name of the item property to be created. Currently, the following names are reserved:`id`, `itemid`, case insensitively. Also, the length of the property name must not exceed 63 characters.
13+
:param property_name: Name of the item property to be created. Currently, the following names are reserved: `id`, `itemid`, case-insensitively. Also, the length of the property name must not exceed 63 characters.
1414
1515
1616
:param type: Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from recombee_api_client.api_requests.request import Request
2+
from typing import Union, List
3+
import uuid
4+
5+
DEFAULT = uuid.uuid4()
6+
7+
class AddManualReqlSegment(Request):
8+
"""
9+
Adds a new Segment into a Manual ReQL Segmentation.
10+
11+
The new Segment is defined by a [ReQL](https://docs.recombee.com/reql.html) filter that returns `true` for an item in case that this item belongs to the segment.
12+
13+
Required parameters:
14+
15+
:param segmentation_id: ID of the Segmentation to which the new Segment should be added
16+
17+
:param segment_id: ID of the newly created Segment
18+
19+
:param filter: ReQL filter that returns `true` for items that belong to this Segment. Otherwise returns `false`.
20+
21+
22+
23+
Optional parameters:
24+
25+
:param title: Human-readable name of the Segment that is shown in the Recombee Admin UI.
26+
27+
28+
29+
"""
30+
31+
def __init__(self, segmentation_id: str, segment_id: str, filter: str, title: str = DEFAULT):
32+
super().__init__(path="/segmentations/manual-reql/%s/segments/%s" % (segmentation_id,segment_id), method='put', timeout=10000, ensure_https=False)
33+
self.segmentation_id = segmentation_id
34+
self.segment_id = segment_id
35+
self.filter = filter
36+
self.title = title
37+
38+
def get_body_parameters(self) -> dict:
39+
"""
40+
Values of body parameters as a dictionary (name of parameter: value of the parameter).
41+
"""
42+
p = dict()
43+
p['filter'] = self.filter
44+
if self.title is not DEFAULT:
45+
p['title'] = self.title
46+
return p
47+
48+
def get_query_parameters(self) -> dict:
49+
"""
50+
Values of query parameters as a dictionary (name of parameter: value of the parameter).
51+
"""
52+
params = dict()
53+
return params

recombee_api_client/api_requests/add_purchase.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class AddPurchase(Request):
88
"""
9-
Adds a purchase of a given item made by a given user.
9+
Adds a purchase of the given item made by the given user.
1010
1111
Required parameters:
1212
@@ -21,11 +21,11 @@ class AddPurchase(Request):
2121
2222
:param cascade_create: Sets whether the given user/item should be created if not present in the database.
2323
24-
:param amount: Amount (number) of purchased items. The default is 1. For example if `user-x` purchases two `item-y` during a single order (session...), the `amount` should equal to 2.
24+
:param amount: Amount (number) of purchased items. The default is 1. For example, if `user-x` purchases two `item-y` during a single order (session...), the `amount` should equal 2.
2525
26-
:param price: Price paid by the user for the item. If `amount` is greater than 1, sum of prices of all the items should be given.
26+
:param price: Price paid by the user for the item. If `amount` is greater than 1, the sum of prices of all the items should be given.
2727
28-
:param profit: Your profit from the purchased item. The profit is natural in e-commerce domain (for example if `user-x` purchases `item-y` for $100 and the gross margin is 30 %, then the profit is $30), but is applicable also in other domains (for example at a news company it may be income from displayed advertisement on article page). If `amount` is greater than 1, sum of profit of all the items should be given.
28+
:param profit: Your profit from the purchased item. The profit is natural in the e-commerce domain (for example, if `user-x` purchases `item-y` for $100 and the gross margin is 30 %, then the profit is $30) but is also applicable in other domains (for example, at a news company it may be income from a displayed advertisement on article page). If `amount` is greater than 1, the sum of profit of all the items should be given.
2929
3030
:param recomm_id: If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.
3131
@@ -35,7 +35,7 @@ class AddPurchase(Request):
3535
"""
3636

3737
def __init__(self, user_id: str, item_id: str, timestamp: Union[str, int] = DEFAULT, cascade_create: bool = DEFAULT, amount: float = DEFAULT, price: float = DEFAULT, profit: float = DEFAULT, recomm_id: str = DEFAULT, additional_data: dict = DEFAULT):
38-
super().__init__(path="/purchases/" % (), method='post', timeout=1000, ensure_https=False)
38+
super().__init__(path="/purchases/", method='post', timeout=1000, ensure_https=False)
3939
self.user_id = user_id
4040
self.item_id = item_id
4141
self.timestamp = timestamp

recombee_api_client/api_requests/add_rating.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class AddRating(Request):
88
"""
9-
Adds a rating of given item made by a given user.
9+
Adds a rating of the given item made by the given user.
1010
1111
Required parameters:
1212
@@ -31,7 +31,7 @@ class AddRating(Request):
3131
"""
3232

3333
def __init__(self, user_id: str, item_id: str, rating: float, timestamp: Union[str, int] = DEFAULT, cascade_create: bool = DEFAULT, recomm_id: str = DEFAULT, additional_data: dict = DEFAULT):
34-
super().__init__(path="/ratings/" % (), method='post', timeout=1000, ensure_https=False)
34+
super().__init__(path="/ratings/", method='post', timeout=1000, ensure_https=False)
3535
self.user_id = user_id
3636
self.item_id = item_id
3737
self.rating = rating

recombee_api_client/api_requests/add_search_synonym.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AddSearchSynonym(Request):
3232
"""
3333

3434
def __init__(self, term: str, synonym: str, one_way: bool = DEFAULT):
35-
super().__init__(path="/synonyms/items/" % (), method='post', timeout=10000, ensure_https=False)
35+
super().__init__(path="/synonyms/items/", method='post', timeout=10000, ensure_https=False)
3636
self.term = term
3737
self.synonym = synonym
3838
self.one_way = one_way

recombee_api_client/api_requests/add_series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class AddSeries(Request):
88
"""
9-
Creates new series in the database.
9+
Creates a new series in the database.
1010
Required parameters:
1111
1212
:param series_id: ID of the series to be created.

recombee_api_client/api_requests/add_user_property.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
class AddUserProperty(Request):
88
"""
9-
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.
9+
Adding a 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.
1010
1111
Required parameters:
1212
13-
:param 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.
13+
:param 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.
1414
1515
1616
:param type: Value type of the user property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from recombee_api_client.api_requests.request import Request
2+
from typing import Union, List
3+
import uuid
4+
5+
DEFAULT = uuid.uuid4()
6+
7+
class CreateAutoReqlSegmentation(Request):
8+
"""
9+
Segment the items using a [ReQL](https://docs.recombee.com/reql.html) expression.
10+
11+
For each item, the expression should return a set that contains IDs of segments to which the item belongs to.
12+
13+
Required parameters:
14+
15+
:param segmentation_id: ID of the newly created Segmentation
16+
17+
:param source_type: What type of data should be segmented. Currently only `items` are supported.
18+
19+
20+
:param expression: ReQL expression that returns for each item a set with IDs of segments to which the item belongs
21+
22+
23+
24+
Optional parameters:
25+
26+
:param title: Human-readable name that is shown in the Recombee Admin UI.
27+
28+
29+
:param description: Description that is shown in the Recombee Admin UI.
30+
31+
32+
33+
"""
34+
35+
def __init__(self, segmentation_id: str, source_type: str, expression: str, title: str = DEFAULT, description: str = DEFAULT):
36+
super().__init__(path="/segmentations/auto-reql/%s" % (segmentation_id), method='put', timeout=10000, ensure_https=False)
37+
self.segmentation_id = segmentation_id
38+
self.source_type = source_type
39+
self.expression = expression
40+
self.title = title
41+
self.description = description
42+
43+
def get_body_parameters(self) -> dict:
44+
"""
45+
Values of body parameters as a dictionary (name of parameter: value of the parameter).
46+
"""
47+
p = dict()
48+
p['sourceType'] = self.source_type
49+
p['expression'] = self.expression
50+
if self.title is not DEFAULT:
51+
p['title'] = self.title
52+
if self.description is not DEFAULT:
53+
p['description'] = self.description
54+
return p
55+
56+
def get_query_parameters(self) -> dict:
57+
"""
58+
Values of query parameters as a dictionary (name of parameter: value of the parameter).
59+
"""
60+
params = dict()
61+
return params
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from recombee_api_client.api_requests.request import Request
2+
from typing import Union, List
3+
import uuid
4+
5+
DEFAULT = uuid.uuid4()
6+
7+
class CreateManualReqlSegmentation(Request):
8+
"""
9+
Segment the items using multiple [ReQL](https://docs.recombee.com/reql.html) filters.
10+
11+
Use the Add Manual ReQL Items Segment endpoint to create the individual segments.
12+
13+
Required parameters:
14+
15+
:param segmentation_id: ID of the newly created Segmentation
16+
17+
:param source_type: What type of data should be segmented. Currently only `items` are supported.
18+
19+
20+
21+
Optional parameters:
22+
23+
:param title: Human-readable name that is shown in the Recombee Admin UI.
24+
25+
26+
:param description: Description that is shown in the Recombee Admin UI.
27+
28+
29+
30+
"""
31+
32+
def __init__(self, segmentation_id: str, source_type: str, title: str = DEFAULT, description: str = DEFAULT):
33+
super().__init__(path="/segmentations/manual-reql/%s" % (segmentation_id), method='put', timeout=10000, ensure_https=False)
34+
self.segmentation_id = segmentation_id
35+
self.source_type = source_type
36+
self.title = title
37+
self.description = description
38+
39+
def get_body_parameters(self) -> dict:
40+
"""
41+
Values of body parameters as a dictionary (name of parameter: value of the parameter).
42+
"""
43+
p = dict()
44+
p['sourceType'] = self.source_type
45+
if self.title is not DEFAULT:
46+
p['title'] = self.title
47+
if self.description is not DEFAULT:
48+
p['description'] = self.description
49+
return p
50+
51+
def get_query_parameters(self) -> dict:
52+
"""
53+
Values of query parameters as a dictionary (name of parameter: value of the parameter).
54+
"""
55+
params = dict()
56+
return params

0 commit comments

Comments
 (0)