From 33e650bc23a5c1b506186ee32cadd4f1b5c9ae66 Mon Sep 17 00:00:00 2001 From: Villu Ruusmann Date: Mon, 25 Jan 2021 13:28:35 +0200 Subject: [PATCH] Refactored the encoding of PMML elements. Fixes #103 --- src/main/java/org/jpmml/sparkml/PMMLBuilder.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jpmml/sparkml/PMMLBuilder.java b/src/main/java/org/jpmml/sparkml/PMMLBuilder.java index 88f5888e..3e5a2c62 100644 --- a/src/main/java/org/jpmml/sparkml/PMMLBuilder.java +++ b/src/main/java/org/jpmml/sparkml/PMMLBuilder.java @@ -153,19 +153,19 @@ public PMML build(){ org.dmg.pmml.Model model; - if(models.size() == 1){ - model = Iterables.getOnlyElement(models); + if(models.size() == 0){ + model = null; } else - if(models.size() > 1){ - model = MiningModelUtil.createModelChain(models); + if(models.size() == 1){ + model = Iterables.getOnlyElement(models); } else { - throw new IllegalArgumentException("Expected a pipeline with one or more models, got a pipeline with zero models"); + model = MiningModelUtil.createModelChain(models); } // End if - if(postProcessorNames.size() > 0){ + if((model != null) && (postProcessorNames.size() > 0)){ org.dmg.pmml.Model finalModel = MiningModelUtil.getFinalModel(model); Output output = ModelUtil.ensureOutput(finalModel); @@ -185,7 +185,7 @@ public PMML build(){ PMML pmml = encoder.encodePMML(model); - if((predictionColumns.size() > 0 || probabilityColumns.size() > 0) && (verification != null)){ + if((model != null) && (predictionColumns.size() > 0 || probabilityColumns.size() > 0) && (verification != null)){ Dataset dataset = verification.getDataset(); Dataset transformedDataset = verification.getTransformedDataset(); Double precision = verification.getPrecision();