Search in sources :

Example 1 with ModelOutputs

use of org.apache.storm.pmml.model.ModelOutputs in project storm by apache.

the class JpmmlModelOutputs method create.

// ======
private static ModelOutputs create(PMML pmmlModel, List<String> streams) {
    final Set<String> fieldNames = new LinkedHashSet<>();
    final Evaluator evaluator = JpmmlFactory.newEvaluator(pmmlModel);
    for (FieldName predictedField : evaluator.getPredictedFields()) {
        fieldNames.add(predictedField.getValue());
    }
    for (FieldName outputField : evaluator.getOutputFields()) {
        fieldNames.add(outputField.getValue());
    }
    final Map<String, Fields> toDeclare = streams.stream().collect(Collectors.toMap(Function.identity(), (x) -> new Fields(new ArrayList<>(fieldNames))));
    return new JpmmlModelOutputs(toDeclare);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Evaluator(org.jpmml.evaluator.Evaluator) JpmmlFactory(org.apache.storm.pmml.runner.jpmml.JpmmlFactory) PMML(org.dmg.pmml.PMML) Set(java.util.Set) ModelOutputs(org.apache.storm.pmml.model.ModelOutputs) Fields(org.apache.storm.tuple.Fields) Utils(org.apache.storm.utils.Utils) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) Objects(java.util.Objects) FieldName(org.dmg.pmml.FieldName) List(java.util.List) Map(java.util.Map) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) InputStream(java.io.InputStream) Fields(org.apache.storm.tuple.Fields) Evaluator(org.jpmml.evaluator.Evaluator) FieldName(org.dmg.pmml.FieldName)

Aggregations

File (java.io.File)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ModelOutputs (org.apache.storm.pmml.model.ModelOutputs)1 JpmmlFactory (org.apache.storm.pmml.runner.jpmml.JpmmlFactory)1 Fields (org.apache.storm.tuple.Fields)1 Utils (org.apache.storm.utils.Utils)1 FieldName (org.dmg.pmml.FieldName)1 PMML (org.dmg.pmml.PMML)1 Evaluator (org.jpmml.evaluator.Evaluator)1