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

Predicted response design

The Predicted response is also of the JSON format. A simple example for our example of the result is the following JSON:

    {
"itemScores":[
{"item":22,"score":4.07},
{"item":62,"score":4.05},
{"item":75,"score":4.04},
{"item":68,"score":3.81}
]
}

The PreictedResult.java file has the class for the preceding conversion:

    package org.template.recommendation;

import java.io.Serializable;
import java.util.List;

public class PredictedResult implements Serializable{
private final List<ItemScore> itemScores;

public PredictedResult(List<ItemScore> itemScores) {
this.itemScores = itemScores;
}

public List<ItemScore> getItemScores() {
return itemScores;
}

@Override
public String toString() {
return "PredictedResult{" +
"itemScores=" + itemScores +
'}';
}
}

The Scala version of the code uses the case class, and you can define the query class and the predictedResult class as a case class:

    package MyRecommedationScala

import org.apache.predictionio.controller.IEngineFactory
import org.apache.predictionio.controller.Engine

case class Query(
user: String,
num: Int,
categories: Option[Set[String]],
whiteList: Option[Set[String]],
blackList: Option[Set[String]]
) extends Serializable

case class PredictedResult(
itemScores: Array[ItemScore]
) extends Serializable

case class ItemScore(
item: String,
score: Double
) extends Serializable

object ECommerceRecommendationEngine extends IEngineFactory {
def apply() = {
new Engine(
classOf[DataSource],
classOf[Preparator],
Map("ecomm" -> classOf[ECommAlgorithm]),
classOf[Serving])
}
}
Case classes in Scala are regular classes that are immutable by default, decomposable through pattern matching, compared by structural equality, and you can instantiate and operate on them.
主站蜘蛛池模板: 临安市| 堆龙德庆县| 类乌齐县| 濮阳县| 花莲市| 上杭县| 垣曲县| 长子县| 济源市| 宁武县| 南城县| 高雄市| 嵊泗县| 汉寿县| 韶山市| 东至县| 通城县| 商河县| 长乐市| 太和县| 威海市| 寿宁县| 顺平县| 洮南市| 嵩明县| 山阴县| 乐东| 冕宁县| 东阳市| 鄯善县| 浦北县| 盘锦市| 韩城市| 忻州市| 德州市| 岳池县| 太仆寺旗| 且末县| 涡阳县| 工布江达县| 格尔木市|