- Learning Salesforce Einstein
- Mohith Shrivastava
- 232字
- 2021-07-02 21:44:04
Engine design
The starting point of the application is the Engine. This is indicated in the engine.json file of your project shown as follows:
{
"id": "default",
"description": "Default settings",
"engineFactory":
"org.template.recommendation.RecommendationEngine",
"datasource": {
"params" : {
"appName": "Recommenderapp"
}
},
"algorithms": [
----
}
The Engine class for our reference is written as follows:
public class RecommendationEngine extends EngineFactory {
@Override
public BaseEngine<EmptyParams, Query, PredictedResult,
Set<String>> apply() {
return new Engine<>(
DataSource.class,
Preparator.class,
Collections.<String, Class<? extends
BaseAlgorithm<PreparedData,
?, Query, PredictedResult>>>singletonMap("algo",
Algorithm.class),
Serving.class
);
}
}
Key points to make a note from the preceding code are as follows:
- An engine class extends from EngineFactory, which is provided by PredictionIO
- The apply() interface method of the EngineFactory base class is overridden
- The apply() method returns an instance of the engine class that has constructor parameters for the Datasource class, the Preparator class, the Singleton Map of Algorithm class, and the serving class
Let's observe the following lines of code:
Collections.<String, Class<? extends BaseAlgorithm<PreparedData,
?, Query, PredictedResult>>>singletonMap(
"algo", Algorithm.class)
The preceding lines may be hard to interpret; class <? extends BaseAlgorithm<>> means that the type of the class is undetermined, but you are guaranteed that it extends BaseAlgorithm.
If you are familiar with Scala, the Scala code for the Engine would look as follows:
object ECommerceRecommendationEngine extends IEngineFactory {
def apply() = {
new Engine(
classOf[DataSource],
classOf[Preparator],
Map("ecomm" -> classOf[ECommAlgorithm]),
classOf[Serving])
}
}
推薦閱讀
- 數據結構簡明教程(第2版)微課版
- aelf區塊鏈應用架構指南
- Python Network Programming Cookbook(Second Edition)
- Mastering Ext JS
- Learning Python Design Patterns
- HTML5從入門到精通(第4版)
- 匯編語言編程基礎:基于LoongArch
- App Inventor 2 Essentials
- Zend Framework 2 Cookbook
- MySQL從入門到精通
- Game Development Patterns and Best Practices
- Java程序設計
- C#程序開發教程
- Visual C++ 2017網絡編程實戰
- Scratch 3少兒交互式游戲編程一本通