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

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.

主站蜘蛛池模板: 休宁县| 昆山市| 那坡县| 衡南县| 乌苏市| 巍山| 安乡县| 吴堡县| 尚志市| 乐平市| 井陉县| 建宁县| 噶尔县| 吴旗县| 固安县| 灵台县| 德兴市| 柳林县| 普宁市| 津南区| 农安县| 抚远县| 营口市| 新泰市| 崇阳县| 襄樊市| 资中县| 囊谦县| 石柱| 河间市| 西吉县| 咸丰县| 平顺县| 忻州市| 阿合奇县| 教育| 千阳县| 嘉义县| 香格里拉县| 平潭县| 磐石市|