- Learning Salesforce Einstein
- Mohith Shrivastava
- 201字
- 2021-07-02 21:44:04
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.
推薦閱讀
- Kibana Essentials
- Visual FoxPro程序設計教程
- C#程序設計
- Responsive Web Design by Example
- Learning FuelPHP for Effective PHP Development
- Windows內核編程
- Arduino家居安全系統構建實戰
- Instant PHP Web Scraping
- UML2面向對象分析與設計(第2版)
- 大規模語言模型開發基礎與實踐
- 分布式數據庫HBase案例教程
- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)
- Go語言編程之旅:一起用Go做項目
- 狼書(卷2):Node.js Web應用開發
- Mastering Puppet(Second Edition)