|
| 1 | +<?php |
| 2 | +/* |
| 3 | + This file is auto-generated, do not edit |
| 4 | +*/ |
| 5 | + |
| 6 | +/** |
| 7 | + * CompositeRecommendation request |
| 8 | + */ |
| 9 | +namespace Recombee\RecommApi\Requests; |
| 10 | +use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException; |
| 11 | + |
| 12 | +/** |
| 13 | + * Composite Recommendation returns both a *source entity* (e.g., an Item or [Item Segment](https://docs.recombee.com/segmentations.html)) and a list of related recommendations in a single response. |
| 14 | + * It is ideal for use cases such as personalized homepage sections (*Articles from <category>*), *Because You Watched <movie>*, or *Artists Related to Your Favorite Artist <artist>*. |
| 15 | + * See detailed **examples and configuration guidance** in the [Composite Scenarios documentation](https://docs.recombee.com/scenarios#composite-recommendations). |
| 16 | + * **Structure** |
| 17 | + * The endpoint operates in two stages: |
| 18 | + * 1. Recommends the *source* (e.g., an Item Segment or item) to the user. |
| 19 | + * 2. Recommends *results* (items or Item Segments) related to that *source*. |
| 20 | + * For example, *Articles from <category>* can be decomposed into: |
| 21 | + * - [Recommend Item Segments To User](https://docs.recombee.com/api#recommend-item-segments-to-user) to find the category. |
| 22 | + * - [Recommend Items To Item Segment](https://docs.recombee.com/api#recommend-items-to-item-segment) to recommend articles from that category. |
| 23 | + * Since the first step uses [Recommend Item Segments To User](https://docs.recombee.com/api#recommend-items-to-user), you must include the `userId` parameter in the *Composite Recommendation* request. |
| 24 | + * Each *Composite Recommendation* counts as a single recommendation API request for billing. |
| 25 | + * **Stage-specific Parameters** |
| 26 | + * Additional parameters can be supplied via [sourceSettings](https://docs.recombee.com/api#composite-recommendation-param-sourceSettings) and [resultSettings](https://docs.recombee.com/api#composite-recommendation-param-resultSettings). |
| 27 | + * In the example above: |
| 28 | + * - `sourceSettings` may include any parameter valid for [Recommend Item Segments To User](https://docs.recombee.com/api#recommend-items-to-user) (e.g., `filter`, `booster`). |
| 29 | + * - `resultSettings` may include any parameter valid for [Recommend Items To Item Segment](https://docs.recombee.com/api#recommend-items-to-item-segment). |
| 30 | + * See [this example](https://docs.recombee.com/api#composite-recommendation-example-setting-parameters-for-individual-stages) for more details. |
| 31 | + */ |
| 32 | +class CompositeRecommendation extends Request { |
| 33 | + |
| 34 | + /** |
| 35 | + * @var string $scenario Scenario defines a particular application of recommendations. It can be, for example, "homepage", "cart", or "emailing". |
| 36 | + * You can set various settings to the [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com). You can also see the performance of each scenario in the Admin UI separately, so you can check how well each application performs. |
| 37 | + * The AI that optimizes models to get the best results may optimize different scenarios separately or even use different models in each of the scenarios. |
| 38 | + */ |
| 39 | + protected $scenario; |
| 40 | + /** |
| 41 | + * @var int $count Number of items to be recommended (N for the top-N recommendation). |
| 42 | + */ |
| 43 | + protected $count; |
| 44 | + /** |
| 45 | + * @var string $item_id ID of the item for which the recommendations are to be generated. |
| 46 | + */ |
| 47 | + protected $item_id; |
| 48 | + /** |
| 49 | + * @var string $user_id ID of the user for which the recommendations are to be generated. |
| 50 | + */ |
| 51 | + protected $user_id; |
| 52 | + /** |
| 53 | + * @var string|array $logic Logic specifies the particular behavior of the recommendation models. You can pick tailored logic for your domain and use case. |
| 54 | + * See [this section](https://docs.recombee.com/recommendation_logics) for a list of available logics and other details. |
| 55 | + * The difference between `logic` and `scenario` is that `logic` specifies mainly behavior, while `scenario` specifies the place where recommendations are shown to the users. |
| 56 | + * Logic can also be set to a [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com). |
| 57 | + */ |
| 58 | + protected $logic; |
| 59 | + /** |
| 60 | + * @var string $segment_id ID of the segment from `contextSegmentationId` for which the recommendations are to be generated. |
| 61 | + */ |
| 62 | + protected $segment_id; |
| 63 | + /** |
| 64 | + * @var bool $cascade_create If the entity for the source recommendation does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that entity, as the entity will be already known to the system. |
| 65 | + */ |
| 66 | + protected $cascade_create; |
| 67 | + /** |
| 68 | + * @var array $source_settings Parameters applied for recommending the *Source* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Source*. |
| 69 | + */ |
| 70 | + protected $source_settings; |
| 71 | + /** |
| 72 | + * @var array $result_settings Parameters applied for recommending the *Result* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Result*. |
| 73 | + */ |
| 74 | + protected $result_settings; |
| 75 | + /** |
| 76 | + * @var array $expert_settings Dictionary of custom options. |
| 77 | + */ |
| 78 | + protected $expert_settings; |
| 79 | + /** |
| 80 | + * @var array Array containing values of optional parameters |
| 81 | + */ |
| 82 | + protected $optional; |
| 83 | + |
| 84 | + /** |
| 85 | + * Construct the request |
| 86 | + * @param string $scenario Scenario defines a particular application of recommendations. It can be, for example, "homepage", "cart", or "emailing". |
| 87 | + * You can set various settings to the [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com). You can also see the performance of each scenario in the Admin UI separately, so you can check how well each application performs. |
| 88 | + * The AI that optimizes models to get the best results may optimize different scenarios separately or even use different models in each of the scenarios. |
| 89 | + * @param int $count Number of items to be recommended (N for the top-N recommendation). |
| 90 | + * @param array $optional Optional parameters given as an array containing pairs name of the parameter => value |
| 91 | + * - Allowed parameters: |
| 92 | + * - *itemId* |
| 93 | + * - Type: string |
| 94 | + * - Description: ID of the item for which the recommendations are to be generated. |
| 95 | + * - *userId* |
| 96 | + * - Type: string |
| 97 | + * - Description: ID of the user for which the recommendations are to be generated. |
| 98 | + * - *logic* |
| 99 | + * - Type: string|array |
| 100 | + * - Description: Logic specifies the particular behavior of the recommendation models. You can pick tailored logic for your domain and use case. |
| 101 | + * See [this section](https://docs.recombee.com/recommendation_logics) for a list of available logics and other details. |
| 102 | + * The difference between `logic` and `scenario` is that `logic` specifies mainly behavior, while `scenario` specifies the place where recommendations are shown to the users. |
| 103 | + * Logic can also be set to a [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com). |
| 104 | + * - *segmentId* |
| 105 | + * - Type: string |
| 106 | + * - Description: ID of the segment from `contextSegmentationId` for which the recommendations are to be generated. |
| 107 | + * - *cascadeCreate* |
| 108 | + * - Type: bool |
| 109 | + * - Description: If the entity for the source recommendation does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that entity, as the entity will be already known to the system. |
| 110 | + * - *sourceSettings* |
| 111 | + * - Type: array |
| 112 | + * - Description: Parameters applied for recommending the *Source* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Source*. |
| 113 | + * - *resultSettings* |
| 114 | + * - Type: array |
| 115 | + * - Description: Parameters applied for recommending the *Result* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Result*. |
| 116 | + * - *expertSettings* |
| 117 | + * - Type: array |
| 118 | + * - Description: Dictionary of custom options. |
| 119 | + * @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional |
| 120 | + */ |
| 121 | + public function __construct($scenario, $count, $optional = array()) { |
| 122 | + $this->scenario = $scenario; |
| 123 | + $this->count = $count; |
| 124 | + $this->item_id = isset($optional['itemId']) ? $optional['itemId'] : null; |
| 125 | + $this->user_id = isset($optional['userId']) ? $optional['userId'] : null; |
| 126 | + $this->logic = isset($optional['logic']) ? $optional['logic'] : null; |
| 127 | + $this->segment_id = isset($optional['segmentId']) ? $optional['segmentId'] : null; |
| 128 | + $this->cascade_create = isset($optional['cascadeCreate']) ? $optional['cascadeCreate'] : null; |
| 129 | + $this->source_settings = isset($optional['sourceSettings']) ? $optional['sourceSettings'] : null; |
| 130 | + $this->result_settings = isset($optional['resultSettings']) ? $optional['resultSettings'] : null; |
| 131 | + $this->expert_settings = isset($optional['expertSettings']) ? $optional['expertSettings'] : null; |
| 132 | + $this->optional = $optional; |
| 133 | + |
| 134 | + $existing_optional = array('itemId','userId','logic','segmentId','cascadeCreate','sourceSettings','resultSettings','expertSettings'); |
| 135 | + foreach ($this->optional as $key => $value) { |
| 136 | + if (!in_array($key, $existing_optional)) |
| 137 | + throw new UnknownOptionalParameterException($key); |
| 138 | + } |
| 139 | + $this->timeout = 3000; |
| 140 | + $this->ensure_https = false; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Get used HTTP method |
| 145 | + * @return static Used HTTP method |
| 146 | + */ |
| 147 | + public function getMethod() { |
| 148 | + return Request::HTTP_POST; |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Get URI to the endpoint |
| 153 | + * @return string URI to the endpoint |
| 154 | + */ |
| 155 | + public function getPath() { |
| 156 | + return "/{databaseId}/recomms/composite/"; |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * Get query parameters |
| 161 | + * @return array Values of query parameters (name of parameter => value of the parameter) |
| 162 | + */ |
| 163 | + public function getQueryParameters() { |
| 164 | + $params = array(); |
| 165 | + return $params; |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * Get body parameters |
| 170 | + * @return array Values of body parameters (name of parameter => value of the parameter) |
| 171 | + */ |
| 172 | + public function getBodyParameters() { |
| 173 | + $p = array(); |
| 174 | + $p['scenario'] = $this->scenario; |
| 175 | + $p['count'] = $this->count; |
| 176 | + if (isset($this->optional['itemId'])) |
| 177 | + $p['itemId'] = $this-> optional['itemId']; |
| 178 | + if (isset($this->optional['userId'])) |
| 179 | + $p['userId'] = $this-> optional['userId']; |
| 180 | + if (isset($this->optional['logic'])) |
| 181 | + $p['logic'] = $this-> optional['logic']; |
| 182 | + if (isset($this->optional['segmentId'])) |
| 183 | + $p['segmentId'] = $this-> optional['segmentId']; |
| 184 | + if (isset($this->optional['cascadeCreate'])) |
| 185 | + $p['cascadeCreate'] = $this-> optional['cascadeCreate']; |
| 186 | + if (isset($this->optional['sourceSettings'])) |
| 187 | + $p['sourceSettings'] = $this-> optional['sourceSettings']; |
| 188 | + if (isset($this->optional['resultSettings'])) |
| 189 | + $p['resultSettings'] = $this-> optional['resultSettings']; |
| 190 | + if (isset($this->optional['expertSettings'])) |
| 191 | + $p['expertSettings'] = $this-> optional['expertSettings']; |
| 192 | + return $p; |
| 193 | + } |
| 194 | + |
| 195 | +} |
0 commit comments