The Serve method processes predicted results. Also, you can combine multiple predicted results into one for more than one predictive model.
The Java class for serve is written as follows:
package org.template.recommendation;
import org.apache.predictionio.controller.java.LJavaServing;
import scala.collection.Seq;
public class Serving extends LJavaServing<Query, PredictedResult> {
@Override
public PredictedResult serve(Query query, Seq<PredictedResult>
predictions) {
return predictions.head();
}
}
The Scala version would obviously be smaller and the code is shown here:
package MyRecommedationScala
import org.apache.predictionio.controller.LServing
class Serving
extends LServing[Query, PredictedResult] {
override
def serve(query: Query,
predictedResults: Seq[PredictedResult]): PredictedResult = {
predictedResults.head
}
}
Note that we call the head method and the Seq function (Trait in Scala) to order the results.
Similar to interfaces in Java, traits are used to define object types by specifying the signature of the supported methods.
Note that we are skipping the evaluation part of the engine. We will cover it in the next chapter in detail.