官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 巴里| 香格里拉县| 邹城市| 雅安市| 吐鲁番市| 二连浩特市| 宣恩县| 朝阳县| 府谷县| 东台市| 蒲城县| 双鸭山市| 呼伦贝尔市| 山东省| 宕昌县| 老河口市| 临朐县| 林甸县| 托克托县| 景洪市| 茶陵县| 宜兰县| 观塘区| 柘城县| 乐昌市| 探索| 延津县| 湟中县| 庆安县| 阿巴嘎旗| 正定县| 泗洪县| 和平区| 邹城市| 自贡市| 台前县| 丽水市| 台南市| 奈曼旗| 泸溪县| 凤山市|