Skip to content

Commit ecbb9d4

Browse files
committed
Use new recommendation endpoints
1 parent f189761 commit ecbb9d4

File tree

11 files changed

+64
-63
lines changed

11 files changed

+64
-63
lines changed

README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The client is available in the [Maven Central Repository](https://mvnrepository.
1313
<dependency>
1414
<groupId>com.recombee</groupId>
1515
<artifactId>api-client</artifactId>
16-
<version>1.6.2</version>
16+
<version>2.0.0</version>
1717
</dependency>
1818
```
1919

@@ -28,6 +28,7 @@ package com.recombee.api_client.examples;
2828

2929
import com.recombee.api_client.RecombeeClient;
3030
import com.recombee.api_client.api_requests.*;
31+
import com.recombee.api_client.bindings.RecommendationResponse;
3132
import com.recombee.api_client.bindings.Recommendation;
3233
import com.recombee.api_client.exceptions.ApiException;
3334

@@ -37,7 +38,7 @@ import java.util.Random;
3738
public class BasicExample {
3839
public static void main(String[] args) {
3940

40-
RecombeeClient client = new RecombeeClient("client-test", "jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L");
41+
RecombeeClient client = new RecombeeClient("--my-database-id--", "--my-secret-token--");
4142
try {
4243
client.send(new ResetDatabase());
4344
final int NUM = 100;
@@ -59,17 +60,16 @@ public class BasicExample {
5960
client.send(new Batch(addPurchaseRequests)); //Use Batch for faster processing of larger data
6061

6162
// Get 5 recommendations for user 'user-25'
62-
Recommendation[] recommended = client.send(new UserBasedRecommendation("user-25", 5));
63+
RecommendationResponse recommendationResponse = client.send(new RecommendItemsToUser("user-25", 5));
6364
System.out.println("Recommended items:");
64-
for(Recommendation rec: recommended) System.out.println(rec.getId());
65+
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
6566

6667
} catch (ApiException e) {
6768
e.printStackTrace();
6869
//use fallback
6970
}
7071
}
7172
}
72-
7373
```
7474

7575
### Using property values
@@ -79,6 +79,7 @@ package com.recombee.api_client.examples;
7979

8080
import com.recombee.api_client.RecombeeClient;
8181
import com.recombee.api_client.api_requests.*;
82+
import com.recombee.api_client.bindings.RecommendationResponse;
8283
import com.recombee.api_client.bindings.Recommendation;
8384
import com.recombee.api_client.exceptions.ApiException;
8485

@@ -114,15 +115,15 @@ public class ItemPropertiesExample {
114115
for(int i=0; i<NUM; i++)
115116
{
116117
final SetItemValues req = new SetItemValues(
117-
String.format("computer-%s",i), //itemId
118-
//values:
119-
new HashMap<String, Object>() {{
120-
put("price", 600.0 + 400*rand.nextDouble());
121-
put("num-cores", 1 + rand.nextInt(7));
122-
put("description", "Great computer");
123-
}}
118+
String.format("computer-%s",i), //itemId
119+
//values:
120+
new HashMap<String, Object>() {{
121+
put("price", 600.0 + 400*rand.nextDouble());
122+
put("num-cores", 1 + rand.nextInt(7));
123+
put("description", "Great computer");
124+
}}
124125
).setCascadeCreate(true); // Use cascadeCreate for creating item
125-
// with given itemId, if it doesn't exist;
126+
// with given itemId, if it doesn't exist;
126127
requests.add(req);
127128
}
128129
client.send(new Batch(requests)); // Send catalog to the recommender system
@@ -134,31 +135,30 @@ public class ItemPropertiesExample {
134135
for (int j = 0; j < NUM; j++)
135136
if (rand.nextDouble() < PROBABILITY_PURCHASED) {
136137
AddPurchase req = new AddPurchase(String.format("user-%s", i),String.format("computer-%s", j))
137-
.setCascadeCreate(true); //use cascadeCreate to create the users
138+
.setCascadeCreate(true); //use cascadeCreate to create the users
138139
addPurchaseRequests.add(req);
139140
}
140141
client.send(new Batch(addPurchaseRequests)); // Send purchases to the recommender system
141142

142143

143144
// Get 5 recommendations for user-42, who is currently viewing computer-6
144-
Recommendation[] recommended = client.send(new ItemBasedRecommendation("computer-6", 5)
145-
.setTargetUserId("user-42"));
145+
RecommendationResponse recommendationResponse = client.send(new RecommendItemsToItem("computer-6", "user-42", 5));
146146
System.out.println("Recommended items:");
147-
for(Recommendation rec: recommended) System.out.println(rec.getId());
147+
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
148148

149149

150-
// Get 5 recommendations for user-42, but recommend only computers that have at least 3 cores
151-
recommended = client.send(new ItemBasedRecommendation("computer-6", 5).setTargetUserId("user-42")
152-
.setFilter(" 'num-cores'>=3 "));
150+
// Recommend only computers that have at least 3 cores
151+
recommendationResponse = client.send(new RecommendItemsToItem("computer-6", "user-42", 5)
152+
.setFilter(" 'num-cores'>=3 "));
153153
System.out.println("Recommended items with at least 3 processor cores:");
154-
for(Recommendation rec: recommended) System.out.println(rec.getId());
154+
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
155155

156-
// Get 5 recommendations for user-42, but recommend only items that are more expensive then currently viewed item (up-sell)
157-
recommended = client.send(new ItemBasedRecommendation("computer-6", 5).setTargetUserId("user-42")
158-
.setFilter(" 'price' > context_item[\"price\"] "));
156+
// Recommend only items that are more expensive then currently viewed item (up-sell)
157+
recommendationResponse = client.send(new RecommendItemsToItem("computer-6", "user-42", 5)
158+
.setFilter(" 'price' > context_item[\"price\"] "));
159159

160160
System.out.println("Recommended up-sell items:");
161-
for(Recommendation rec: recommended) System.out.println(rec.getId());
161+
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
162162

163163
} catch (ApiException e) {
164164
e.printStackTrace();

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.recombee</groupId>
88
<artifactId>api-client</artifactId>
9-
<version>1.6.2</version>
9+
<version>2.0.0</version>
1010
<name>Recombee API Client</name>
1111
<description>A client library for easy use of the Recombee recommendation API</description>
1212
<url>http://recombee.com</url>

src/examples/java/com/recombee/api_client/examples/BasicExample.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.recombee.api_client.RecombeeClient;
44
import com.recombee.api_client.api_requests.*;
5+
import com.recombee.api_client.bindings.RecommendationResponse;
56
import com.recombee.api_client.bindings.Recommendation;
67
import com.recombee.api_client.exceptions.ApiException;
78

@@ -11,7 +12,7 @@
1112
public class BasicExample {
1213
public static void main(String[] args) {
1314

14-
RecombeeClient client = new RecombeeClient("client-test", "jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L");
15+
RecombeeClient client = new RecombeeClient("--my-database-id--", "--my-secret-token--");
1516
try {
1617
client.send(new ResetDatabase());
1718
final int NUM = 100;
@@ -24,22 +25,22 @@ public static void main(String[] args) {
2425
if (r.nextDouble() < PROBABILITY_PURCHASED) {
2526

2627
AddPurchase request = new AddPurchase(String.format("user-%s", i),String.format("item-%s", j))
27-
.setCascadeCreate(true); // Use cascadeCreate parameter to create
28-
// the yet non-existing users and items
28+
.setCascadeCreate(true); // Use cascadeCreate parameter to create
29+
// the yet non-existing users and items
2930
addPurchaseRequests.add(request);
3031
}
3132

3233
System.out.println("Send purchases");
3334
client.send(new Batch(addPurchaseRequests)); //Use Batch for faster processing of larger data
3435

3536
// Get 5 recommendations for user 'user-25'
36-
Recommendation[] recommended = client.send(new UserBasedRecommendation("user-25", 5));
37+
RecommendationResponse recommendationResponse = client.send(new RecommendItemsToUser("user-25", 5));
3738
System.out.println("Recommended items:");
38-
for(Recommendation rec: recommended) System.out.println(rec.getId());
39+
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
3940

4041
} catch (ApiException e) {
4142
e.printStackTrace();
4243
//use fallback
4344
}
4445
}
45-
}
46+
}

src/examples/java/com/recombee/api_client/examples/ItemPropertiesExample.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.recombee.api_client.RecombeeClient;
44
import com.recombee.api_client.api_requests.*;
5+
import com.recombee.api_client.bindings.RecommendationResponse;
56
import com.recombee.api_client.bindings.Recommendation;
67
import com.recombee.api_client.exceptions.ApiException;
78

@@ -12,7 +13,7 @@
1213
public class ItemPropertiesExample {
1314
public static void main(String[] args) {
1415

15-
RecombeeClient client = new RecombeeClient("client-test", "jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L");
16+
RecombeeClient client = new RecombeeClient("--my-database-id--", "--my-secret-token--");
1617

1718
try {
1819
client.send(new ResetDatabase()); //Clear everything from the database
@@ -37,15 +38,15 @@ public static void main(String[] args) {
3738
for(int i=0; i<NUM; i++)
3839
{
3940
final SetItemValues req = new SetItemValues(
40-
String.format("computer-%s",i), //itemId
41-
//values:
42-
new HashMap<String, Object>() {{
43-
put("price", 600.0 + 400*rand.nextDouble());
44-
put("num-cores", 1 + rand.nextInt(7));
45-
put("description", "Great computer");
46-
}}
41+
String.format("computer-%s",i), //itemId
42+
//values:
43+
new HashMap<String, Object>() {{
44+
put("price", 600.0 + 400*rand.nextDouble());
45+
put("num-cores", 1 + rand.nextInt(7));
46+
put("description", "Great computer");
47+
}}
4748
).setCascadeCreate(true); // Use cascadeCreate for creating item
48-
// with given itemId, if it doesn't exist;
49+
// with given itemId, if it doesn't exist;
4950
requests.add(req);
5051
}
5152
client.send(new Batch(requests)); // Send catalog to the recommender system
@@ -57,35 +58,34 @@ public static void main(String[] args) {
5758
for (int j = 0; j < NUM; j++)
5859
if (rand.nextDouble() < PROBABILITY_PURCHASED) {
5960
AddPurchase req = new AddPurchase(String.format("user-%s", i),String.format("computer-%s", j))
60-
.setCascadeCreate(true); //use cascadeCreate to create the users
61+
.setCascadeCreate(true); //use cascadeCreate to create the users
6162
addPurchaseRequests.add(req);
6263
}
6364
client.send(new Batch(addPurchaseRequests)); // Send purchases to the recommender system
6465

6566

6667
// Get 5 recommendations for user-42, who is currently viewing computer-6
67-
Recommendation[] recommended = client.send(new ItemBasedRecommendation("computer-6", 5)
68-
.setTargetUserId("user-42"));
68+
RecommendationResponse recommendationResponse = client.send(new RecommendItemsToItem("computer-6", "user-42", 5));
6969
System.out.println("Recommended items:");
70-
for(Recommendation rec: recommended) System.out.println(rec.getId());
70+
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
7171

7272

73-
// Get 5 recommendations for user-42, but recommend only computers that have at least 3 cores
74-
recommended = client.send(new ItemBasedRecommendation("computer-6", 5).setTargetUserId("user-42")
75-
.setFilter(" 'num-cores'>=3 "));
73+
// Recommend only computers that have at least 3 cores
74+
recommendationResponse = client.send(new RecommendItemsToItem("computer-6", "user-42", 5)
75+
.setFilter(" 'num-cores'>=3 "));
7676
System.out.println("Recommended items with at least 3 processor cores:");
77-
for(Recommendation rec: recommended) System.out.println(rec.getId());
77+
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
7878

79-
// Get 5 recommendations for user-42, but recommend only items that are more expensive then currently viewed item (up-sell)
80-
recommended = client.send(new ItemBasedRecommendation("computer-6", 5).setTargetUserId("user-42")
81-
.setFilter(" 'price' > context_item[\"price\"] "));
79+
// Recommend only items that are more expensive then currently viewed item (up-sell)
80+
recommendationResponse = client.send(new RecommendItemsToItem("computer-6", "user-42", 5)
81+
.setFilter(" 'price' > context_item[\"price\"] "));
8282

8383
System.out.println("Recommended up-sell items:");
84-
for(Recommendation rec: recommended) System.out.println(rec.getId());
84+
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
8585

8686
} catch (ApiException e) {
8787
e.printStackTrace();
8888
//Use fallback
8989
}
9090
}
91-
}
91+
}

src/main/java/com/recombee/api_client/RecombeeClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class RecombeeClient {
8585

8686
final int BATCH_MAX_SIZE = 10000; //Maximal number of requests within one batch request
8787

88-
final String USER_AGENT = "recombee-java-api-client/1.6.2";
88+
final String USER_AGENT = "recombee-java-api-client/2.0.0";
8989

9090
private final OkHttpClient httpClient = new OkHttpClient();
9191

src/main/java/com/recombee/api_client/api_requests/ItemBasedRecommendation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
/**
1414
* Recommends set of items that are somehow related to one given item, *X*. Typical scenario for using item-based recommendation is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Item-recommendation request gives you Top-N such items, optionally taking the target user *A* into account.
1515
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
16+
* @deprecated Deprecated since version 2.0.0. Use RecommendItemsToItem request instead.
1617
*/
18+
@Deprecated
1719
public class ItemBasedRecommendation extends Request {
1820

1921
/**

src/main/java/com/recombee/api_client/api_requests/RecommendItemsToItem.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.recombee.api_client.util.HTTPMethod;
1212

1313
/**
14-
* This feature is currently in beta.
1514
* Recommends set of items that are somehow related to one given item, *X*. Typical scenario is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Recommend items to item request gives you Top-N such items, optionally taking the target user *A* into account.
1615
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1716
*/
@@ -32,8 +31,8 @@ public class RecommendItemsToItem extends Request {
3231
* If you insist on not specifying the user, pass `null`
3332
* (`None`, `nil`, `NULL` etc. depending on language) to *targetUserId*.
3433
* Do not create some special dummy user for getting recommendations,
35-
* as it could cause mislead the recommendation models,
36-
* leading to wrong recommendations.
34+
* as it could mislead the recommendation models,
35+
* and result in wrong recommendations.
3736
* For anonymous/unregistered users it is possible to use for example their session ID.
3837
*/
3938
protected String targetUserId;
@@ -153,8 +152,8 @@ public class RecommendItemsToItem extends Request {
153152
* If you insist on not specifying the user, pass `null`
154153
* (`None`, `nil`, `NULL` etc. depending on language) to *targetUserId*.
155154
* Do not create some special dummy user for getting recommendations,
156-
* as it could cause mislead the recommendation models,
157-
* leading to wrong recommendations.
155+
* as it could mislead the recommendation models,
156+
* and result in wrong recommendations.
158157
* For anonymous/unregistered users it is possible to use for example their session ID.
159158
* @param count Number of items to be recommended (N for the top-N recommendation).
160159
*/

src/main/java/com/recombee/api_client/api_requests/RecommendItemsToUser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.recombee.api_client.util.HTTPMethod;
1212

1313
/**
14-
* This feature is currently in beta.
1514
* Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
1615
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1716
*/

src/main/java/com/recombee/api_client/api_requests/RecommendUsersToItem.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.recombee.api_client.util.HTTPMethod;
1212

1313
/**
14-
* This feature is currently in beta.
1514
* Recommend users that are likely to be interested in a given item.
1615
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1716
*/

src/main/java/com/recombee/api_client/api_requests/RecommendUsersToUser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.recombee.api_client.util.HTTPMethod;
1212

1313
/**
14-
* This feature is currently in beta.
1514
* Get similar users as some given user, based on the user's past interactions (purchases, ratings, etc.) and values of properties.
1615
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1716
*/

0 commit comments

Comments
 (0)