Merge tag 'v0.6.0-develop'
[maven-release-plugin] copy for tag v0.6.0-develop
Conflicts:
README.md
examples/import/pom.xml
examples/import_deprecated/pom.xml
examples/simpletasks1/pom.xml
examples/simpletasks1_deprecated/pom.xml
diff --git a/README.md b/README.md
index 487cda1..4d5a46c 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
<dependency>
<groupId>io.prediction</groupId>
<artifactId>client</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
</dependency>
</dependencies>
...
@@ -26,7 +26,7 @@
<ivy-module ...>
...
<dependencies>
- <dependency org="io.prediction" name="client" rev="0.5.0" />
+ <dependency org="io.prediction" name="client" rev="0.6.0" />
...
</dependencies>
...
@@ -35,7 +35,7 @@
If you have an sbt project, add the library dependency to your build definition.
- libraryDependencies += "io.prediction" % "client" % "0.5.0"
+ libraryDependencies += "io.prediction" % "client" % "0.6.0"
### Building from Source
diff --git a/client/pom.xml b/client/pom.xml
index 6e61784..3210304 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -5,7 +5,7 @@
<groupId>io.prediction</groupId>
<artifactId>sdk</artifactId>
<relativePath>../pom.xml</relativePath>
- <version>0.5.0</version>
+ <version>0.6.0</version>
</parent>
<artifactId>client</artifactId>
diff --git a/client/src/main/java/io/prediction/Client.java b/client/src/main/java/io/prediction/Client.java
index a89932a..06a5abc 100644
--- a/client/src/main/java/io/prediction/Client.java
+++ b/client/src/main/java/io/prediction/Client.java
@@ -26,7 +26,7 @@
* Multiple simultaneous asynchronous requests is made possible by the high performance backend provided by the <a href="https://github.com/AsyncHttpClient/async-http-client">Async Http Client</a>.
*
* @author The PredictionIO Team (<a href="http://prediction.io">http://prediction.io</a>)
- * @version 0.4.1
+ * @version 0.6.0
* @since 0.1
*/
public class Client {
@@ -538,12 +538,14 @@
}
/**
- * Deprecated. Get a get top-n recommendations request builder that can be used to add additional request parameters.
+ * Get a get top-n recommendations request builder that can be used to add additional request parameters.
+ * @deprecated Use {@link Client#getItemRecGetTopNRequestBuilder(String engine, int n)} instead.
*
* @param engine engine name
* @param uid ID of the User whose recommendations will be gotten
- * @param n number of top recommendations to get
+ * @param n number of top recommendations to get
*/
+ @Deprecated
public ItemRecGetTopNRequestBuilder getItemRecGetTopNRequestBuilder(String engine, String uid, int n) {
return new ItemRecGetTopNRequestBuilder(this.apiUrl, this.apiFormat, this.appkey, engine, uid, n);
}
@@ -565,13 +567,15 @@
}
/**
- * Deprecated. Get a get top-n recommendations request builder that can be used to add additional request parameters.
+ * Get a get top-n recommendations request builder that can be used to add additional request parameters.
+ * @deprecated Use {@link Client#getItemRecGetTopNRequestBuilder(String engine, int n, String[] attributes)} instead.
*
* @param engine engine name
* @param uid ID of the User whose recommendations will be gotten
* @param n number of top recommendations to get
* @param attributes array of item attribute names to be returned with the result
*/
+ @Deprecated
public ItemRecGetTopNRequestBuilder getItemRecGetTopNRequestBuilder(String engine, String uid, int n, String[] attributes) {
return (new ItemRecGetTopNRequestBuilder(this.apiUrl, this.apiFormat, this.appkey, engine, uid, n)).attributes(attributes);
}
@@ -603,7 +607,8 @@
}
/**
- * Deprecated. Sends a synchronous get recommendations request to the API.
+ * Sends a synchronous get recommendations request to the API.
+ * @deprecated Use {@link Client#getItemRecTopN(String engine, int n)} instead.
*
* @param engine engine name
* @param uid ID of the User whose recommendations will be gotten
@@ -613,6 +618,7 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public String[] getItemRecTopN(String engine, String uid, int n) throws ExecutionException, InterruptedException, IOException {
return this.getItemRecTopN(this.getItemRecTopNAsFuture(this.getItemRecGetTopNRequestBuilder(engine, uid, n)));
}
@@ -670,7 +676,8 @@
}
/**
- * Deprecated. Sends a synchronous get recommendations request to the API.
+ * Sends a synchronous get recommendations request to the API.
+ * @deprecated Use {@link Client#getItemRecTopNWithAttributes(String engine, int n, String[] attributes)} instead.
*
* @param engine engine name
* @param uid ID of the User whose recommendations will be gotten
@@ -679,8 +686,9 @@
*
* @throws ExecutionException indicates an error in the HTTP backend
* @throws InterruptedException indicates an interruption during the HTTP operation
- * @throws IOException indicates an error from the API response
+ * @throws IOException indicates an error from the API response
*/
+ @Deprecated
public Map<String, String[]> getItemRecTopNWithAttributes(String engine, String uid, int n, String[] attributes) throws ExecutionException, InterruptedException, IOException {
return this.getItemRecTopNWithAttributes(this.getItemRecTopNAsFuture(this.getItemRecGetTopNRequestBuilder(engine, uid, n, attributes)));
}
@@ -742,6 +750,144 @@
}
/**
+ * Get a get top-n similar items request builder that can be used to add additional request parameters.
+ *
+ * @param engine engine name
+ * @param iid ID of the Item
+ * @param n number of top similar items to get
+ */
+ public ItemSimGetTopNRequestBuilder getItemSimGetTopNRequestBuilder(String engine, String iid, int n) {
+ return new ItemSimGetTopNRequestBuilder(this.apiUrl, this.apiFormat, this.appkey, engine, iid, n);
+ }
+
+ /**
+ * Get a get top-n similar items request builder that can be used to add additional request parameters.
+ *
+ * @param engine engine name
+ * @param iid ID of the Item
+ * @param n number of top similar items to get
+ * @param attributes array of item attribute names to be returned with the result
+ */
+ public ItemSimGetTopNRequestBuilder getItemSimGetTopNRequestBuilder(String engine, String iid, int n, String[] attributes) {
+ return new ItemSimGetTopNRequestBuilder(this.apiUrl, this.apiFormat, this.appkey, engine, iid, n).attributes(attributes);
+ }
+
+ /**
+ * Sends an asynchronous get similar items request to the API.
+ *
+ * @param builder an instance of {@link ItemSimGetTopNRequestBuilder} that will be turned into a request
+ */
+ public FutureAPIResponse getItemSimTopNAsFuture(ItemSimGetTopNRequestBuilder builder) throws IOException {
+ return new FutureAPIResponse(this.client.executeRequest(builder.build(), this.getHandler()));
+ }
+
+ /**
+ * Sends a synchronous get similar items request to the API.
+ *
+ * @param engine engine name
+ * @param iid ID of the Item
+ * @param n number of top recommendations to get
+ *
+ * @throws ExecutionException indicates an error in the HTTP backend
+ * @throws InterruptedException indicates an interruption during the HTTP operation
+ * @throws IOException indicates an error from the API response
+ */
+ public String[] getItemSimTopN(String engine, String iid, int n) throws ExecutionException, InterruptedException, IOException {
+ return this.getItemSimTopN(this.getItemSimTopNAsFuture(this.getItemSimGetTopNRequestBuilder(engine, iid, n)));
+ }
+
+ /**
+ * Sends a synchronous get similar items request to the API.
+ *
+ * @param builder an instance of {@link ItemSimGetTopNRequestBuilder} that will be turned into a request
+ *
+ * @throws ExecutionException indicates an error in the HTTP backend
+ * @throws InterruptedException indicates an interruption during the HTTP operation
+ * @throws IOException indicates an error from the API response
+ */
+ public String[] getItemSimTopN(ItemSimGetTopNRequestBuilder builder) throws ExecutionException, InterruptedException, IOException {
+ return this.getItemSimTopN(this.getItemSimTopNAsFuture(builder));
+ }
+
+ /**
+ * Synchronize a previously sent asynchronous get similar items request.
+ *
+ * @param response an instance of {@link FutureAPIResponse} returned from {@link Client#getItemSimTopNAsFuture}
+ *
+ * @throws ExecutionException indicates an error in the HTTP backend
+ * @throws InterruptedException indicates an interruption during the HTTP operation
+ * @throws IOException indicates an error from the API response
+ */
+ public String[] getItemSimTopN(FutureAPIResponse response) throws ExecutionException, InterruptedException, IOException {
+ // Do not use getStatus/getMessage directly as they do not pass exceptions
+ int status = response.get().getStatus();
+ String message = response.get().getMessage();
+
+ if (status == Client.HTTP_OK) {
+ JsonObject messageAsJson = (JsonObject) parser.parse(message);
+ JsonArray iidsAsJson = messageAsJson.getAsJsonArray("pio_iids");
+ return this.jsonArrayAsStringArray(iidsAsJson);
+ } else {
+ throw new IOException(message);
+ }
+ }
+
+ /**
+ * Sends a synchronous get similar items request to the API.
+ *
+ * @param engine engine name
+ * @param iid ID of the Item
+ * @param n number of top recommendations to get
+ * @param attributes array of item attribute names to be returned with the result
+ *
+ * @throws ExecutionException indicates an error in the HTTP backend
+ * @throws InterruptedException indicates an interruption during the HTTP operation
+ * @throws IOException indicates an error from the API response
+ */
+ public Map<String, String[]> getItemSimTopNWithAttributes(String engine, String iid, int n, String[] attributes) throws ExecutionException, InterruptedException, IOException {
+ return this.getItemSimTopNWithAttributes(this.getItemSimTopNAsFuture(this.getItemSimGetTopNRequestBuilder(engine, iid, n, attributes)));
+ }
+
+ /**
+ * Sends a synchronous get similar items request to the API.
+ *
+ * @param builder an instance of {@link ItemSimGetTopNRequestBuilder} that will be turned into a request
+ *
+ * @throws ExecutionException indicates an error in the HTTP backend
+ * @throws InterruptedException indicates an interruption during the HTTP operation
+ * @throws IOException indicates an error from the API response
+ */
+ public Map<String, String[]> getItemSimTopNWithAttributes(ItemSimGetTopNRequestBuilder builder) throws ExecutionException, InterruptedException, IOException {
+ return this.getItemSimTopNWithAttributes(this.getItemSimTopNAsFuture(builder));
+ }
+
+ /**
+ * Synchronize a previously sent asynchronous get similar items request.
+ *
+ * @param response an instance of {@link FutureAPIResponse} returned from {@link Client#getItemSimTopNAsFuture}
+ *
+ * @throws ExecutionException indicates an error in the HTTP backend
+ * @throws InterruptedException indicates an interruption during the HTTP operation
+ * @throws IOException indicates an error from the API response
+ */
+ public Map<String, String[]> getItemSimTopNWithAttributes(FutureAPIResponse response) throws ExecutionException, InterruptedException, IOException {
+ // Do not use getStatus/getMessage directly as they do not pass exceptions
+ int status = response.get().getStatus();
+ String message = response.get().getMessage();
+
+ if (status == Client.HTTP_OK) {
+ HashMap<String, String[]> results = new HashMap();
+ JsonObject messageAsJson = (JsonObject) parser.parse(message);
+ for (Map.Entry<String, JsonElement> member : messageAsJson.entrySet()) {
+ results.put(member.getKey(), this.jsonArrayAsStringArray(member.getValue().getAsJsonArray()));
+ }
+ return results;
+ } else {
+ throw new IOException(message);
+ }
+ }
+
+ /**
* Get a user-action-on-item request builder that can be used to add additional request parameters.
* Identified user ID will be used. See {@link Client#identify}.
*
@@ -828,12 +974,14 @@
}
/**
- * Deprecated. Get a user-rate-item action request builder that can be used to add additional request parameters.
+ * Get a user-rate-item action request builder that can be used to add additional request parameters.
+ * @deprecated Use {@link Client#getUserActionItemRequestBuilder(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
* @param rate the rating of this action
*/
+ @Deprecated
public UserActionItemRequestBuilder getUserRateItemRequestBuilder(String uid, String iid, int rate) {
UserActionItemRequestBuilder builder = new UserActionItemRequestBuilder(this.apiUrl, this.apiFormat, this.appkey, UserActionItemRequestBuilder.RATE, uid, iid);
builder.rate(rate);
@@ -841,16 +989,19 @@
}
/**
- * Deprecated. Sends an asynchronous user-rate-item action request to the API.
+ * Sends an asynchronous user-rate-item action request to the API.
+ * @deprecated Use {@link Client#userActionItemAsFuture(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*/
+ @Deprecated
public FutureAPIResponse userRateItemAsFuture(UserActionItemRequestBuilder builder) throws IOException {
return new FutureAPIResponse(this.client.executeRequest(builder.build(), this.getHandler()));
}
/**
- * Deprecated. Sends a synchronous user-rate-item action request to the API.
+ * Sends a synchronous user-rate-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
@@ -860,12 +1011,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userRateItem(String uid, String iid, int rate) throws ExecutionException, InterruptedException, IOException {
this.userRateItem(this.userRateItemAsFuture(this.getUserRateItemRequestBuilder(uid, iid, rate)));
}
/**
- * Deprecated. Sends a synchronous user-rate-item action request to the API.
+ * Sends a synchronous user-rate-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*
@@ -873,12 +1026,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userRateItem(UserActionItemRequestBuilder builder) throws ExecutionException, InterruptedException, IOException {
this.userRateItem(this.userRateItemAsFuture(builder));
}
/**
- * Deprecated. Synchronize a previously sent asynchronous user-rate-item action request.
+ * Synchronize a previously sent asynchronous user-rate-item action request.
+ * @deprecated Use {@link Client#userActionItem(FutureAPIResponse response)} instead.
*
* @param response an instance of {@link FutureAPIResponse} returned from {@link Client#userRateItemAsFuture}
*
@@ -886,31 +1041,37 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userRateItem(FutureAPIResponse response) throws ExecutionException, InterruptedException, IOException {
this.userActionItem(response);
}
/**
- * Deprecated. Get a user-like-item action request builder that can be used to add additional request parameters.
+ * Get a user-like-item action request builder that can be used to add additional request parameters.
+ * @deprecated Use {@link Client#getUserActionItemRequestBuilder(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
*/
+ @Deprecated
public UserActionItemRequestBuilder getUserLikeItemRequestBuilder(String uid, String iid) {
return new UserActionItemRequestBuilder(this.apiUrl, this.apiFormat, this.appkey, UserActionItemRequestBuilder.LIKE, uid, iid);
}
/**
- * Deprecated. Sends an asynchronous user-like-item action request to the API.
+ * Sends an asynchronous user-like-item action request to the API.
+ * @deprecated Use {@link Client#userActionItemAsFuture(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*/
+ @Deprecated
public FutureAPIResponse userLikeItemAsFuture(UserActionItemRequestBuilder builder) throws IOException {
return new FutureAPIResponse(this.client.executeRequest(builder.build(), this.getHandler()));
}
/**
- * Deprecated. Sends a synchronous user-like-item action request to the API.
+ * Sends a synchronous user-like-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
@@ -919,12 +1080,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userLikeItem(String uid, String iid) throws ExecutionException, InterruptedException, IOException {
this.userLikeItem(this.userLikeItemAsFuture(this.getUserLikeItemRequestBuilder(uid, iid)));
}
/**
- * Deprecated. Sends a synchronous user-like-item action request to the API.
+ * Sends a synchronous user-like-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*
@@ -932,12 +1095,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userLikeItem(UserActionItemRequestBuilder builder) throws ExecutionException, InterruptedException, IOException {
this.userLikeItem(this.userLikeItemAsFuture(builder));
}
/**
- * Deprecated. Synchronize a previously sent asynchronous user-like-item action request.
+ * Synchronize a previously sent asynchronous user-like-item action request.
+ * @deprecated Use {@link Client#userActionItem(FutureAPIResponse response)} instead.
*
* @param response an instance of {@link FutureAPIResponse} returned from {@link Client#userLikeItemAsFuture}
*
@@ -945,31 +1110,38 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userLikeItem(FutureAPIResponse response) throws ExecutionException, InterruptedException, IOException {
this.userActionItem(response);
}
/**
- * Deprecated. Get a user-dislike-item action request builder that can be used to add additional request parameters.
+ * Get a user-dislike-item action request builder that can be used to add additional request parameters.
+ * @deprecated Use {@link Client#getUserActionItemRequestBuilder(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
+ *
*/
+ @Deprecated
public UserActionItemRequestBuilder getUserDislikeItemRequestBuilder(String uid, String iid) {
return new UserActionItemRequestBuilder(this.apiUrl, this.apiFormat, this.appkey, UserActionItemRequestBuilder.DISLIKE, uid, iid);
}
/**
- * Deprecated. Sends an asynchronous user-dislike-item action request to the API.
+ * Sends an asynchronous user-dislike-item action request to the API.
+ * @deprecated Use {@link Client#userActionItemAsFuture(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*/
+ @Deprecated
public FutureAPIResponse userDislikeItemAsFuture(UserActionItemRequestBuilder builder) throws IOException {
return new FutureAPIResponse(this.client.executeRequest(builder.build(), this.getHandler()));
}
/**
- * Deprecated. Sends a synchronous user-dislike-item action request to the API.
+ * Sends a synchronous user-dislike-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
@@ -978,12 +1150,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userDislikeItem(String uid, String iid) throws ExecutionException, InterruptedException, IOException {
this.userDislikeItem(this.userDislikeItemAsFuture(this.getUserDislikeItemRequestBuilder(uid, iid)));
}
/**
- * Deprecated. Sends a synchronous user-dislike-item action request to the API.
+ * Sends a synchronous user-dislike-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*
@@ -991,12 +1165,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userDislikeItem(UserActionItemRequestBuilder builder) throws ExecutionException, InterruptedException, IOException {
this.userDislikeItem(this.userDislikeItemAsFuture(builder));
}
/**
- * Deprecated. Synchronize a previously sent asynchronous user-dislike-item action request.
+ * Synchronize a previously sent asynchronous user-dislike-item action request.
+ * @deprecated Use {@link Client#userActionItem(FutureAPIResponse response)} instead.
*
* @param response an instance of {@link FutureAPIResponse} returned from {@link Client#userDislikeItemAsFuture}
*
@@ -1004,31 +1180,37 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userDislikeItem(FutureAPIResponse response) throws ExecutionException, InterruptedException, IOException {
this.userActionItem(response);
}
/**
- * Deprecated. Get a user-view-item action request builder that can be used to add additional request parameters.
+ * Get a user-view-item action request builder that can be used to add additional request parameters.
+ * @deprecated Use {@link Client#getUserActionItemRequestBuilder(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
*/
+ @Deprecated
public UserActionItemRequestBuilder getUserViewItemRequestBuilder(String uid, String iid) {
return new UserActionItemRequestBuilder(this.apiUrl, this.apiFormat, this.appkey, UserActionItemRequestBuilder.VIEW, uid, iid);
}
/**
- * Deprecated. Sends an asynchronous user-view-item action request to the API.
+ * Sends an asynchronous user-view-item action request to the API.
+ * @deprecated Use {@link Client#userActionItemAsFuture(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*/
+ @Deprecated
public FutureAPIResponse userViewItemAsFuture(UserActionItemRequestBuilder builder) throws IOException {
return new FutureAPIResponse(this.client.executeRequest(builder.build(), this.getHandler()));
}
/**
- * Deprecated. Sends a synchronous user-view-item action request to the API.
+ * Sends a synchronous user-view-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
@@ -1037,12 +1219,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userViewItem(String uid, String iid) throws ExecutionException, InterruptedException, IOException {
this.userViewItem(this.userViewItemAsFuture(this.getUserViewItemRequestBuilder(uid, iid)));
}
/**
- * Deprecated. Sends a synchronous user-view-item action request to the API.
+ * Sends a synchronous user-view-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*
@@ -1050,12 +1234,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userViewItem(UserActionItemRequestBuilder builder) throws ExecutionException, InterruptedException, IOException {
this.userViewItem(this.userViewItemAsFuture(builder));
}
/**
- * Deprecated. Synchronize a previously sent asynchronous user-view-item action request.
+ * Synchronize a previously sent asynchronous user-view-item action request.
+ * @deprecated Use {@link Client#userActionItem(FutureAPIResponse response)} instead.
*
* @param response an instance of {@link FutureAPIResponse} returned from {@link Client#userViewItemAsFuture}
*
@@ -1063,31 +1249,37 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userViewItem(FutureAPIResponse response) throws ExecutionException, InterruptedException, IOException {
this.userActionItem(response);
}
/**
- * Deprecated. Get a user-conversion-item action request builder that can be used to add additional request parameters.
+ * Get a user-conversion-item action request builder that can be used to add additional request parameters.
+ * @deprecated Use {@link Client#getUserActionItemRequestBuilder(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
*/
+ @Deprecated
public UserActionItemRequestBuilder getUserConversionItemRequestBuilder(String uid, String iid) {
return new UserActionItemRequestBuilder(this.apiUrl, this.apiFormat, this.appkey, UserActionItemRequestBuilder.CONVERSION, uid, iid);
}
/**
- * Deprecated. Sends an asynchronous user-conversion-item action request to the API.
+ * Sends an asynchronous user-conversion-item action request to the API.
+ * @deprecated Use {@link Client#userActionItemAsFuture(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*/
+ @Deprecated
public FutureAPIResponse userConversionItemAsFuture(UserActionItemRequestBuilder builder) throws IOException {
return new FutureAPIResponse(this.client.executeRequest(builder.build(), this.getHandler()));
}
/**
- * Deprecated. Sends a synchronous user-conversion-item action request to the API.
+ * Sends a synchronous user-conversion-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(String action, String iid)} instead.
*
* @param uid ID of the User of this action
* @param iid ID of the Item of this action
@@ -1096,12 +1288,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userConversionItem(String uid, String iid) throws ExecutionException, InterruptedException, IOException {
this.userConversionItem(this.userConversionItemAsFuture(this.getUserConversionItemRequestBuilder(uid, iid)));
}
/**
- * Deprecated. Sends a synchronous user-conversion-item action request to the API.
+ * Sends a synchronous user-conversion-item action request to the API.
+ * @deprecated Use {@link Client#userActionItem(UserActionItemRequestBuilder builder)} instead.
*
* @param builder an instance of {@link UserActionItemRequestBuilder} that will be turned into a request
*
@@ -1109,12 +1303,14 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userConversionItem(UserActionItemRequestBuilder builder) throws ExecutionException, InterruptedException, IOException {
this.userConversionItem(this.userConversionItemAsFuture(builder));
}
/**
- * Deprecated. Synchronize a previously sent asynchronous user-conversion-item action request.
+ * Synchronize a previously sent asynchronous user-conversion-item action request.
+ * @deprecated Use {@link Client#userActionItem(FutureAPIResponse response)} instead.
*
* @param response an instance of {@link FutureAPIResponse} returned from {@link Client#userConversionItemAsFuture}
*
@@ -1122,6 +1318,7 @@
* @throws InterruptedException indicates an interruption during the HTTP operation
* @throws IOException indicates an error from the API response
*/
+ @Deprecated
public void userConversionItem(FutureAPIResponse response) throws ExecutionException, InterruptedException, IOException {
this.userActionItem(response);
}
diff --git a/client/src/main/java/io/prediction/ItemSimGetTopNRequestBuilder.java b/client/src/main/java/io/prediction/ItemSimGetTopNRequestBuilder.java
new file mode 100644
index 0000000..b3ef236
--- /dev/null
+++ b/client/src/main/java/io/prediction/ItemSimGetTopNRequestBuilder.java
@@ -0,0 +1,154 @@
+package io.prediction;
+
+import com.ning.http.client.Request;
+import com.ning.http.client.RequestBuilder;
+
+/**
+ * Get top n similar items request builder for item similarity engine
+ *
+ * @author The PredictionIO Team (<a href="http://prediction.io">http://prediction.io</a>)
+ * @version 0.6.0
+ * @since 0.6.0
+ */
+
+public class ItemSimGetTopNRequestBuilder {
+ private String apiUrl;
+ private String apiFormat;
+ private String appkey;
+ private String engine;
+ private String iid;
+ private int n;
+ private String[] itypes;
+ private Double latitude;
+ private Double longitude;
+ private Double within;
+ private String unit;
+ private String[] attributes;
+
+ /**
+ * Instantiate a request builder with mandatory arguments.
+ * <p>
+ * Do not use this directly. Please refer to "See Also".
+ *
+ * @param apiUrl the API URL
+ * @param apiFormat the return format of the API
+ * @param appkey the new app key to be used
+ * @param engine engine name
+ * @param iid IID
+ * @param n number of recommendations to return
+ *
+ * @see Client#getItemSimGetTopNRequestBuilder
+ */
+ public ItemSimGetTopNRequestBuilder(String apiUrl, String apiFormat, String appkey, String engine, String iid, int n) {
+ this.apiUrl = apiUrl;
+ this.apiFormat = apiFormat;
+ this.appkey = appkey;
+ this.engine = engine;
+ this.iid = iid;
+ this.n = n;
+ }
+
+ /**
+ * Add the "itypes" optional argument to the request.
+ *
+ * @param itypes array of item types
+ */
+ public ItemSimGetTopNRequestBuilder itypes(String[] itypes) {
+ this.itypes = itypes;
+ return this;
+ }
+
+ /**
+ * Add the "latitude" optional argument to the request.
+ * <p>
+ * Only certain data backend support geospatial indexing.
+ * Please refer to the main documentation for more information.
+ *
+ * @param latitude latitude
+ */
+ public ItemSimGetTopNRequestBuilder latitude(Double latitude) {
+ this.latitude = latitude;
+ return this;
+ }
+
+ /**
+ * Add the "longitude" optional argument to the request.
+ * <p>
+ * Only certain data backend support geospatial indexing.
+ * Please refer to the main documentation for more information.
+ *
+ * @param longitude longitude
+ */
+ public ItemSimGetTopNRequestBuilder longitude(Double longitude) {
+ this.longitude = longitude;
+ return this;
+ }
+
+ /**
+ * Add the "within" optional argument to the request.
+ * <p>
+ * Only certain data backend support geospatial indexing.
+ * Please refer to the main documentation for more information.
+ *
+ * @param within radius of search from the specified location
+ */
+ public ItemSimGetTopNRequestBuilder within(Double within) {
+ this.within = within;
+ return this;
+ }
+
+ /**
+ * Add the "unit" optional argument to the request.
+ * <p>
+ * Only certain data backend support geospatial indexing.
+ * Please refer to the main documentation for more information.
+ *
+ * @param unit unit of "within" (radius)
+ */
+ public ItemSimGetTopNRequestBuilder unit(String unit) {
+ this.unit = unit;
+ return this;
+ }
+
+ /**
+ * Add the "attributes" optional argument to the request.
+ *
+ * @param attributes array of item attribute names to be returned with the result
+ */
+ public ItemSimGetTopNRequestBuilder attributes(String[] attributes) {
+ this.attributes = attributes;
+ return this;
+ }
+
+ /**
+ * Build a request.
+ * <p>
+ * Do not use this directly. Please refer to "See Also".
+ *
+ * @see Client#getItemSimTopN(ItemSimGetTopNRequestBuilder)
+ * @see Client#getItemSimTopNAsFuture(ItemSimGetTopNRequestBuilder)
+ */
+ public Request build() {
+ RequestBuilder builder = new RequestBuilder("GET");
+ builder.setUrl(this.apiUrl + "/engines/itemsim/" + this.engine + "/topn." + this.apiFormat);
+ builder.addQueryParameter("pio_appkey", this.appkey);
+ builder.addQueryParameter("pio_iid", this.iid);
+ builder.addQueryParameter("pio_n", Integer.toString(this.n));
+ if (this.itypes != null && this.itypes.length > 0) {
+ builder.addQueryParameter("pio_itypes", Utils.arrayToString(this.itypes));
+ }
+ if (this.latitude != null && this.longitude != null) {
+ builder.addQueryParameter("pio_latlng", this.latitude.toString() + "," + this.longitude.toString());
+ }
+ if (this.within != null) {
+ builder.addQueryParameter("pio_within", this.within.toString());
+ }
+ if (this.unit != null) {
+ builder.addQueryParameter("pio_unit", this.unit.toString());
+ }
+ if (this.attributes != null && this.attributes.length > 0) {
+ builder.addQueryParameter("pio_attributes", Utils.arrayToString(this.attributes));
+ }
+ return builder.build();
+ }
+}
diff --git a/examples/import/pom.xml b/examples/import/pom.xml
index 7caefbb..601ec44 100644
--- a/examples/import/pom.xml
+++ b/examples/import/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.prediction.samples</groupId>
<artifactId>sample-import</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
<packaging>jar</packaging>
<name>PredictionIO Java SDK Examples: Import</name>
@@ -11,7 +11,7 @@
<dependency>
<groupId>io.prediction</groupId>
<artifactId>client</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
</dependency>
</dependencies>
diff --git a/examples/import_deprecated/pom.xml b/examples/import_deprecated/pom.xml
index 7caefbb..601ec44 100644
--- a/examples/import_deprecated/pom.xml
+++ b/examples/import_deprecated/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.prediction.samples</groupId>
<artifactId>sample-import</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
<packaging>jar</packaging>
<name>PredictionIO Java SDK Examples: Import</name>
@@ -11,7 +11,7 @@
<dependency>
<groupId>io.prediction</groupId>
<artifactId>client</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
</dependency>
</dependencies>
diff --git a/examples/simpletasks1/pom.xml b/examples/simpletasks1/pom.xml
index 5b72aa3..1f42f23 100644
--- a/examples/simpletasks1/pom.xml
+++ b/examples/simpletasks1/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.prediction.samples</groupId>
<artifactId>sample-client</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
<packaging>jar</packaging>
<name>PredictionIO Java SDK Examples: Client</name>
@@ -11,7 +11,7 @@
<dependency>
<groupId>io.prediction</groupId>
<artifactId>client</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
</dependency>
</dependencies>
diff --git a/examples/simpletasks1_deprecated/pom.xml b/examples/simpletasks1_deprecated/pom.xml
index 5b72aa3..1f42f23 100644
--- a/examples/simpletasks1_deprecated/pom.xml
+++ b/examples/simpletasks1_deprecated/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.prediction.samples</groupId>
<artifactId>sample-client</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
<packaging>jar</packaging>
<name>PredictionIO Java SDK Examples: Client</name>
@@ -11,7 +11,7 @@
<dependency>
<groupId>io.prediction</groupId>
<artifactId>client</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
</dependency>
</dependencies>
diff --git a/examples/simpletasks2/.gitignore b/examples/simpletasks2/.gitignore
new file mode 100644
index 0000000..0c5e318
--- /dev/null
+++ b/examples/simpletasks2/.gitignore
@@ -0,0 +1,15 @@
+*.class
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# IDE working files
+*.iws
+*.ipr
+*.iml
+.idea/
+.settings
+.project
+.classpath
diff --git a/examples/simpletasks2/pom.xml b/examples/simpletasks2/pom.xml
new file mode 100644
index 0000000..1f42f23
--- /dev/null
+++ b/examples/simpletasks2/pom.xml
@@ -0,0 +1,78 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>io.prediction.samples</groupId>
+ <artifactId>sample-client</artifactId>
+ <version>0.6.0</version>
+ <packaging>jar</packaging>
+ <name>PredictionIO Java SDK Examples: Client</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.prediction</groupId>
+ <artifactId>client</artifactId>
+ <version>0.6.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>false</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.0</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <mainClass>io.prediction.SampleClient</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>io.prediction.samples.SampleClient</mainClass>
+ </manifest>
+ </archive>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/examples/simpletasks2/src/main/java/io/prediction/samples/SampleClient.java b/examples/simpletasks2/src/main/java/io/prediction/samples/SampleClient.java
new file mode 100644
index 0000000..efe2eb8
--- /dev/null
+++ b/examples/simpletasks2/src/main/java/io/prediction/samples/SampleClient.java
@@ -0,0 +1,114 @@
+package io.prediction.samples;
+
+import io.prediction.Client;
+import io.prediction.CreateItemRequestBuilder;
+import io.prediction.CreateUserRequestBuilder;
+import io.prediction.Item;
+import io.prediction.User;
+import io.prediction.ItemSimGetTopNRequestBuilder;
+
+import org.joda.time.DateTime;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cqin
+ * Date: 2/10/13
+ * Time: 11:11 PM
+ */
+public class SampleClient {
+ public static void main(String[] args) {
+ /* set appurl to your API server */
+ String appurl = "http://localhost:8000";
+ /* Handle command line arguments */
+ String appkey = null;
+ String engine = null;
+ try {
+ appkey = args[0];
+ engine = args[1];
+ } catch (ArrayIndexOutOfBoundsException e) {
+ System.err.println("You must provide appkey (1st arg) and engine name (2nd arg)");
+ System.exit(1);
+ }
+
+ Client client = new Client(appkey, appurl);
+ // Get API system status
+ try {
+ System.out.println(client.getStatus());
+ } catch (Exception e) {
+ System.out.println("Unable to get status: "+e.getMessage());
+ }
+
+ // Get similar items (request more than available)
+ System.out.print("10 similar items for Item ID 3:");
+ try {
+ for (String iid : client.getItemSimTopN(engine, "3", 10)) {
+ System.out.print(" " + iid);
+ }
+ } catch (Exception e) {
+ System.out.println("Unable to get similar items: "+e.getMessage());
+ }
+ System.out.println();
+
+ // Get similar items (request less than available)
+ System.out.print("1 similar item for Item ID 2:");
+ try {
+ for (String iid : client.getItemSimTopN(engine, "2", 1)) {
+ System.out.print(" " + iid);
+ }
+ } catch (Exception e) {
+ System.out.println("Unable to get similar items: "+e.getMessage());
+ }
+ System.out.println();
+
+ // Get similar items using request builder
+ System.out.print("10 similar items for Item ID 3:");
+ try {
+ ItemSimGetTopNRequestBuilder requestBuilder = client.getItemSimGetTopNRequestBuilder(engine, "3", 10);
+ for (String iid : client.getItemSimTopN(requestBuilder)) {
+ System.out.print(" " + iid);
+ }
+ } catch (Exception e) {
+ System.out.println("Unable to get similar items: "+e.getMessage());
+ }
+ System.out.println();
+
+ // Get similar items with attributes
+ System.out.print("10 similar items for Item ID 3:");
+ try {
+ String[] attr = {"attr1", "attr2"};
+ Map<String, String[]> data = client.getItemSimTopNWithAttributes(engine, "3", 10, attr);
+
+ for (int i = 0; i < data.size(); i++) {
+ System.out.print("[ " + data.get("pio_iids")[i]);
+ System.out.print(", " + data.get("attr1")[i]);
+ System.out.print(", " + data.get("attr2")[i] + " ]");
+ }
+ } catch (Exception e) {
+ System.out.println("Unable to get similar items: "+e.getMessage());
+ }
+ System.out.println();
+
+ // Get similar items with attributes using request builder
+ System.out.print("10 similar items for Item ID 3:");
+ try {
+ String[] attr = {"attr1", "attr2"};
+ ItemSimGetTopNRequestBuilder requestBuilder = client.getItemSimGetTopNRequestBuilder(engine, "3", 10, attr);
+ Map<String, String[]> data = client.getItemSimTopNWithAttributes(requestBuilder);
+ for (int i = 0; i < data.size(); i++) {
+ System.out.print("[ " + data.get("pio_iids")[i]);
+ System.out.print(", " + data.get("attr1")[i]);
+ System.out.print(", " + data.get("attr2")[i] + " ]");
+ }
+ } catch (Exception e) {
+ System.out.println("Unable to get similar items: "+e.getMessage());
+ }
+ System.out.println();
+
+
+
+ client.close();
+ }
+}
diff --git a/pom.xml b/pom.xml
index 5def53a..2b92f48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.prediction</groupId>
<artifactId>sdk</artifactId>
- <version>0.5.0</version>
+ <version>0.6.0</version>
<url>http://prediction.io</url>
<packaging>pom</packaging>
<name>PredictionIO Java SDK</name>