### Question:
RDFPMMLUtils { public static Pair<DecisionForest,CategoricalValueEncodings> read(PMML pmml) { DataDictionary dictionary = pmml.getDataDictionary(); List<String> featureNames = AppPMMLUtils.getFeatureNames(dictionary); CategoricalValueEncodings categoricalValueEncodings = AppPMMLUtils.buildCategoricalValueEncodings(dictionary); List<Model> models = pmml.getModels(); Model model = models.get(0); MiningSchema miningSchema = model.getMiningSchema(); int targetIndex = Objects.requireNonNull(AppPMMLUtils.findTargetIndex(miningSchema)); DecisionTree[] trees; double[] weights; if (model instanceof MiningModel) { MiningModel miningModel = (MiningModel) model; Segmentation segmentation = miningModel.getSegmentation(); Preconditions.checkArgument( segmentation.getMultipleModelMethod() == Segmentation.MultipleModelMethod.WEIGHTED_AVERAGE || segmentation.getMultipleModelMethod() == Segmentation.MultipleModelMethod.WEIGHTED_MAJORITY_VOTE); List<Segment> segments = segmentation.getSegments(); Preconditions.checkArgument(!segments.isEmpty()); trees = new DecisionTree[segments.size()]; weights = new double[trees.length]; for (int i = 0; i < trees.length; i++) { Segment segment = segments.get(i); Preconditions.checkArgument(segment.getPredicate() instanceof True); weights[i] = segment.getWeight().doubleValue(); TreeModel treeModel = (TreeModel) segment.getModel(); TreeNode root = translateFromPMML(treeModel.getNode(), categoricalValueEncodings, featureNames, targetIndex); trees[i] = new DecisionTree(root); } } else { TreeNode root = translateFromPMML(((TreeModel) model).getNode(), categoricalValueEncodings, featureNames, targetIndex); trees = new DecisionTree[] { new DecisionTree(root) }; weights = new double[] { 1.0 }; } List<MiningField> miningFields = miningSchema.getMiningFields(); double[] featureImportances = new double[featureNames.size()]; for (int i = 0; i < miningFields.size(); i++) { MiningField field = miningFields.get(i); if (field.getImportance() != null) { featureImportances[i] = field.getImportance().doubleValue(); } } return new Pair<>(new DecisionForest(trees, weights, featureImportances), categoricalValueEncodings); } private  RDFPMMLUtils(); static void validatePMMLVsSchema(PMML pmml, InputSchema schema); static Pair<DecisionForest,CategoricalValueEncodings> read(PMML pmml);  }### Answer:
@Test public void testReadClassification() { PMML pmml = buildDummyClassificationModel(); Pair<DecisionForest,CategoricalValueEncodings> forestAndEncodings = RDFPMMLUtils.read(pmml); DecisionForest forest = forestAndEncodings.getFirst(); assertEquals(1, forest.getTrees().length); assertArrayEquals(new double[] { 1.0 }, forest.getWeights()); assertArrayEquals(new double[] { 0.5, 0.0 }, forest.getFeatureImportances()); CategoricalValueEncodings encodings = forestAndEncodings.getSecond(); assertEquals(2, encodings.getValueCount(0)); assertEquals(2, encodings.getValueCount(1)); }
@Test public void testReadRegression() { PMML pmml = buildDummyRegressionModel(); Pair<DecisionForest,CategoricalValueEncodings> forestAndEncodings = RDFPMMLUtils.read(pmml); CategoricalValueEncodings encodings = forestAndEncodings.getSecond(); assertEquals(0, encodings.getCategoryCounts().size()); }
@Test public void testReadClassificationForest() { PMML pmml = buildDummyClassificationModel(3); Pair<DecisionForest,CategoricalValueEncodings> forestAndEncodings = RDFPMMLUtils.read(pmml); DecisionForest forest = forestAndEncodings.getFirst(); assertEquals(3, forest.getTrees().length); }