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

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.
主站蜘蛛池模板: 饶平县| 凤台县| 谷城县| 林周县| 桦川县| 五指山市| 兰坪| 涿鹿县| 鄢陵县| 德江县| 新乐市| 芜湖县| 会理县| 陕西省| 林甸县| 榆树市| 丽水市| 汝州市| 金寨县| 休宁县| 宁海县| 牡丹江市| 交城县| 蒙山县| 吉水县| 抚州市| 沧州市| 治县。| 葫芦岛市| 台江县| 专栏| 彭山县| 黄石市| 依兰县| 贵定县| 屏南县| 疏附县| 永州市| 太谷县| 天门市| 天门市|