書名: Learning Salesforce Einstein作者名: Mohith Shrivastava本章字數(shù): 236字更新時間: 2021-07-02 21:44:04
Query data structure
The engine takes a query in the form of a JSON structure to output prediction.
The JSON input structure is like the following code snippet for our Recommendation Engine example:
{
"userEntityId": "u1",
"number": 10,
"categories": ["c4", "c3"]
}
The query JSON structure is mapped via the Query class. The following piece of code shows the example of the Query Class for this engine:
org.template.recommendation;
import java.io.Serializable;
import java.util.Collections;
import java.util.Set;
public class Query implements Serializable {
private final String userEntityId;
private final int number;
private final Set<String> categories;
private final Set<String> whitelist;
private final Set<String> blacklist;
public Query(String userEntityId, int number,
Set<String> categories, Set<String> whitelist,
Set<String> blacklist) {
this.userEntityId = userEntityId;
this.number = number;
this.categories = categories;
this.whitelist = whitelist;
this.blacklist = blacklist;
}
public String getUserEntityId() {
return userEntityId;
}
public int getNumber() {
return number;
}
public Set<String> getCategories() {
if (categories == null) return Collections.emptySet();
return categories;
}
public Set<String> getWhitelist() {
if (whitelist == null) return Collections.emptySet();
return whitelist;
}
public Set<String> getBlacklist() {
if (blacklist == null) return Collections.emptySet();
return blacklist;
}
@Override
public String toString() {
return "Query{" +
"userEntityId='" + userEntityId + ''' +
", number=" + number +
", categories=" + categories +
", whitelist=" + whitelist +
", blacklist=" + blacklist +
'}';
}
}
Note how the data structure of JSON for query is simply mapped to a class structure.
推薦閱讀
- JavaScript全程指南
- Kibana Essentials
- Learning Cython Programming
- GraphQL學(xué)習(xí)指南
- Java應(yīng)用開發(fā)與實踐
- Apache Hive Essentials
- HTML5游戲開發(fā)案例教程
- C語言程序設(shè)計
- Backbone.js Blueprints
- MySQL數(shù)據(jù)庫基礎(chǔ)實例教程(微課版)
- 人人都懂設(shè)計模式:從生活中領(lǐng)悟設(shè)計模式(Python實現(xiàn))
- Yii Project Blueprints
- Spring MVC+MyBatis開發(fā)從入門到項目實踐(超值版)
- Visual Basic程序設(shè)計習(xí)題與上機實踐
- GitHub入門與實踐