Skip to content

Commit

Permalink
Support Item Segmentations
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraFiedler committed Jan 6, 2023
1 parent 8f0829d commit c7ab39b
Show file tree
Hide file tree
Showing 112 changed files with 1,967 additions and 215 deletions.
2 changes: 1 addition & 1 deletion recombee_api_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __get_base_uri(options: dict, region: str) -> str:

@staticmethod
def __get_http_headers(additional_headers: dict = None) -> dict:
headers = {'User-Agent': 'recombee-python-api-client/4.0.0'}
headers = {'User-Agent': 'recombee-python-api-client/4.1.0'}
if additional_headers:
headers.update(additional_headers)
return headers
Expand Down
16 changes: 16 additions & 0 deletions recombee_api_client/api_requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,27 @@
from recombee_api_client.api_requests.recommend_next_items import RecommendNextItems
from recombee_api_client.api_requests.recommend_users_to_user import RecommendUsersToUser
from recombee_api_client.api_requests.recommend_users_to_item import RecommendUsersToItem
from recombee_api_client.api_requests.recommend_item_segments_to_user import RecommendItemSegmentsToUser
from recombee_api_client.api_requests.recommend_item_segments_to_item import RecommendItemSegmentsToItem
from recombee_api_client.api_requests.recommend_item_segments_to_item_segment import RecommendItemSegmentsToItemSegment
from recombee_api_client.api_requests.search_items import SearchItems
from recombee_api_client.api_requests.search_item_segments import SearchItemSegments
from recombee_api_client.api_requests.add_search_synonym import AddSearchSynonym
from recombee_api_client.api_requests.list_search_synonyms import ListSearchSynonyms
from recombee_api_client.api_requests.delete_all_search_synonyms import DeleteAllSearchSynonyms
from recombee_api_client.api_requests.delete_search_synonym import DeleteSearchSynonym
from recombee_api_client.api_requests.create_property_based_segmentation import CreatePropertyBasedSegmentation
from recombee_api_client.api_requests.update_property_based_segmentation import UpdatePropertyBasedSegmentation
from recombee_api_client.api_requests.create_auto_reql_segmentation import CreateAutoReqlSegmentation
from recombee_api_client.api_requests.update_auto_reql_segmentation import UpdateAutoReqlSegmentation
from recombee_api_client.api_requests.create_manual_reql_segmentation import CreateManualReqlSegmentation
from recombee_api_client.api_requests.update_manual_reql_segmentation import UpdateManualReqlSegmentation
from recombee_api_client.api_requests.add_manual_reql_segment import AddManualReqlSegment
from recombee_api_client.api_requests.update_manual_reql_segment import UpdateManualReqlSegment
from recombee_api_client.api_requests.delete_manual_reql_segment import DeleteManualReqlSegment
from recombee_api_client.api_requests.list_segmentations import ListSegmentations
from recombee_api_client.api_requests.get_segmentation import GetSegmentation
from recombee_api_client.api_requests.delete_segmentation import DeleteSegmentation
from recombee_api_client.api_requests.reset_database import ResetDatabase
from recombee_api_client.api_requests.batch import Batch
from recombee_api_client.api_requests.request import Request
4 changes: 2 additions & 2 deletions recombee_api_client/api_requests/add_bookmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AddBookmark(Request):
"""
Adds a bookmark of a given item made by a given user.
Adds a bookmark of the given item made by the given user.
Required parameters:
Expand All @@ -29,7 +29,7 @@ class AddBookmark(Request):
"""

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):
super().__init__(path="/bookmarks/" % (), method='post', timeout=1000, ensure_https=False)
super().__init__(path="/bookmarks/", method='post', timeout=1000, ensure_https=False)
self.user_id = user_id
self.item_id = item_id
self.timestamp = timestamp
Expand Down
8 changes: 4 additions & 4 deletions recombee_api_client/api_requests/add_cart_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AddCartAddition(Request):
"""
Adds a cart addition of a given item made by a given user.
Adds a cart addition of the given item made by the given user.
Required parameters:
Expand All @@ -21,9 +21,9 @@ class AddCartAddition(Request):
:param cascade_create: Sets whether the given user/item should be created if not present in the database.
: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.
: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.
:param price: Price of the added item. If `amount` is greater than 1, sum of prices of all the items should be given.
:param price: Price of the added item. If `amount` is greater than 1, the sum of prices of all the items should be given.
:param recomm_id: If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
Expand All @@ -33,7 +33,7 @@ class AddCartAddition(Request):
"""

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):
super().__init__(path="/cartadditions/" % (), method='post', timeout=1000, ensure_https=False)
super().__init__(path="/cartadditions/", method='post', timeout=1000, ensure_https=False)
self.user_id = user_id
self.item_id = item_id
self.timestamp = timestamp
Expand Down
4 changes: 2 additions & 2 deletions recombee_api_client/api_requests/add_detail_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AddDetailView(Request):
"""
Adds a detail view of a given item made by a given user.
Adds a detail view of the given item made by the given user.
Required parameters:
Expand All @@ -31,7 +31,7 @@ class AddDetailView(Request):
"""

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):
super().__init__(path="/detailviews/" % (), method='post', timeout=1000, ensure_https=False)
super().__init__(path="/detailviews/", method='post', timeout=1000, ensure_https=False)
self.user_id = user_id
self.item_id = item_id
self.timestamp = timestamp
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/add_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AddGroup(Request):
"""
Creates new group in the database.
Creates a new group in the database.
Required parameters:
:param group_id: ID of the group to be created.
Expand Down
4 changes: 2 additions & 2 deletions recombee_api_client/api_requests/add_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class AddItem(Request):
"""
Adds new item of given `itemId` to the items catalog.
Adds new item of the given `itemId` to the items catalog.
All the item properties for the newly created items are set null.
All the item properties for the newly created items are set to null.
Required parameters:
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/add_item_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AddItemProperty(Request):
Required parameters:
: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.
: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.
:param type: Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
Expand Down
53 changes: 53 additions & 0 deletions recombee_api_client/api_requests/add_manual_reql_segment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from recombee_api_client.api_requests.request import Request
from typing import Union, List
import uuid

DEFAULT = uuid.uuid4()

class AddManualReqlSegment(Request):
"""
Adds a new Segment into a Manual ReQL Segmentation.
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.
Required parameters:
:param segmentation_id: ID of the Segmentation to which the new Segment should be added
:param segment_id: ID of the newly created Segment
:param filter: ReQL filter that returns `true` for items that belong to this Segment. Otherwise returns `false`.
Optional parameters:
:param title: Human-readable name of the Segment that is shown in the Recombee Admin UI.
"""

def __init__(self, segmentation_id: str, segment_id: str, filter: str, title: str = DEFAULT):
super().__init__(path="/segmentations/manual-reql/%s/segments/%s" % (segmentation_id,segment_id), method='put', timeout=10000, ensure_https=False)
self.segmentation_id = segmentation_id
self.segment_id = segment_id
self.filter = filter
self.title = title

def get_body_parameters(self) -> dict:
"""
Values of body parameters as a dictionary (name of parameter: value of the parameter).
"""
p = dict()
p['filter'] = self.filter
if self.title is not DEFAULT:
p['title'] = self.title
return p

def get_query_parameters(self) -> dict:
"""
Values of query parameters as a dictionary (name of parameter: value of the parameter).
"""
params = dict()
return params
10 changes: 5 additions & 5 deletions recombee_api_client/api_requests/add_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AddPurchase(Request):
"""
Adds a purchase of a given item made by a given user.
Adds a purchase of the given item made by the given user.
Required parameters:
Expand All @@ -21,11 +21,11 @@ class AddPurchase(Request):
:param cascade_create: Sets whether the given user/item should be created if not present in the database.
: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.
: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.
: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.
: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.
: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.
: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.
:param recomm_id: If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.
Expand All @@ -35,7 +35,7 @@ class AddPurchase(Request):
"""

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):
super().__init__(path="/purchases/" % (), method='post', timeout=1000, ensure_https=False)
super().__init__(path="/purchases/", method='post', timeout=1000, ensure_https=False)
self.user_id = user_id
self.item_id = item_id
self.timestamp = timestamp
Expand Down
4 changes: 2 additions & 2 deletions recombee_api_client/api_requests/add_rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AddRating(Request):
"""
Adds a rating of given item made by a given user.
Adds a rating of the given item made by the given user.
Required parameters:
Expand All @@ -31,7 +31,7 @@ class AddRating(Request):
"""

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):
super().__init__(path="/ratings/" % (), method='post', timeout=1000, ensure_https=False)
super().__init__(path="/ratings/", method='post', timeout=1000, ensure_https=False)
self.user_id = user_id
self.item_id = item_id
self.rating = rating
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/add_search_synonym.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AddSearchSynonym(Request):
"""

def __init__(self, term: str, synonym: str, one_way: bool = DEFAULT):
super().__init__(path="/synonyms/items/" % (), method='post', timeout=10000, ensure_https=False)
super().__init__(path="/synonyms/items/", method='post', timeout=10000, ensure_https=False)
self.term = term
self.synonym = synonym
self.one_way = one_way
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/add_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AddSeries(Request):
"""
Creates new series in the database.
Creates a new series in the database.
Required parameters:
:param series_id: ID of the series to be created.
Expand Down
4 changes: 2 additions & 2 deletions recombee_api_client/api_requests/add_user_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

class AddUserProperty(Request):
"""
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.
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.
Required parameters:
: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.
: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.
:param type: Value type of the user property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`.
Expand Down
61 changes: 61 additions & 0 deletions recombee_api_client/api_requests/create_auto_reql_segmentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from recombee_api_client.api_requests.request import Request
from typing import Union, List
import uuid

DEFAULT = uuid.uuid4()

class CreateAutoReqlSegmentation(Request):
"""
Segment the items using a [ReQL](https://docs.recombee.com/reql.html) expression.
For each item, the expression should return a set that contains IDs of segments to which the item belongs to.
Required parameters:
:param segmentation_id: ID of the newly created Segmentation
:param source_type: What type of data should be segmented. Currently only `items` are supported.
:param expression: ReQL expression that returns for each item a set with IDs of segments to which the item belongs
Optional parameters:
:param title: Human-readable name that is shown in the Recombee Admin UI.
:param description: Description that is shown in the Recombee Admin UI.
"""

def __init__(self, segmentation_id: str, source_type: str, expression: str, title: str = DEFAULT, description: str = DEFAULT):
super().__init__(path="/segmentations/auto-reql/%s" % (segmentation_id), method='put', timeout=10000, ensure_https=False)
self.segmentation_id = segmentation_id
self.source_type = source_type
self.expression = expression
self.title = title
self.description = description

def get_body_parameters(self) -> dict:
"""
Values of body parameters as a dictionary (name of parameter: value of the parameter).
"""
p = dict()
p['sourceType'] = self.source_type
p['expression'] = self.expression
if self.title is not DEFAULT:
p['title'] = self.title
if self.description is not DEFAULT:
p['description'] = self.description
return p

def get_query_parameters(self) -> dict:
"""
Values of query parameters as a dictionary (name of parameter: value of the parameter).
"""
params = dict()
return params
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from recombee_api_client.api_requests.request import Request
from typing import Union, List
import uuid

DEFAULT = uuid.uuid4()

class CreateManualReqlSegmentation(Request):
"""
Segment the items using multiple [ReQL](https://docs.recombee.com/reql.html) filters.
Use the Add Manual ReQL Items Segment endpoint to create the individual segments.
Required parameters:
:param segmentation_id: ID of the newly created Segmentation
:param source_type: What type of data should be segmented. Currently only `items` are supported.
Optional parameters:
:param title: Human-readable name that is shown in the Recombee Admin UI.
:param description: Description that is shown in the Recombee Admin UI.
"""

def __init__(self, segmentation_id: str, source_type: str, title: str = DEFAULT, description: str = DEFAULT):
super().__init__(path="/segmentations/manual-reql/%s" % (segmentation_id), method='put', timeout=10000, ensure_https=False)
self.segmentation_id = segmentation_id
self.source_type = source_type
self.title = title
self.description = description

def get_body_parameters(self) -> dict:
"""
Values of body parameters as a dictionary (name of parameter: value of the parameter).
"""
p = dict()
p['sourceType'] = self.source_type
if self.title is not DEFAULT:
p['title'] = self.title
if self.description is not DEFAULT:
p['description'] = self.description
return p

def get_query_parameters(self) -> dict:
"""
Values of query parameters as a dictionary (name of parameter: value of the parameter).
"""
params = dict()
return params
Loading

0 comments on commit c7ab39b

Please sign in to comment.