/** * Retrieves a Map whose entries consist of * key -> a model identifier * value -> the PMML4Model object that the key refers to * where the PMML4Model indicates that it * @param parentModelId * @return */ public Map<String, PMML4Model> getChildModels(String parentModelId) { PMML4Model parent = modelsMap.get(parentModelId); Map<String, PMML4Model> childMap = parent.getChildModels(); return (childMap != null && !childMap.isEmpty()) ? new HashMap<>(childMap) : new HashMap<>(); }
/** * Recursive method that adds children models (i.e. models contained within models) * to the internal map of models * @param parentModel The model which may contain child models */ private void addChildModelsToMap(PMML4Model parentModel) { Map<String, PMML4Model> childModels = parentModel.getChildModels(); if (childModels != null && !childModels.isEmpty()) { for (PMML4Model model : childModels.values()) { modelsMap.put(model.getModelId(), model); addChildModelsToMap(model); } } }
private PMMLOutputField getChildOutputField( PMML4Model parentModel, String fieldName) { PMMLOutputField output = null; for (Iterator<PMML4Model> childIter = parentModel.getChildModels().values().iterator(); childIter.hasNext() && output == null;) { PMML4Model child = childIter.next(); List<PMMLOutputField> fields = child.getOutputFields(); if (fields != null && !fields.isEmpty()) { for (Iterator<PMMLOutputField> fieldIter = fields.iterator(); fieldIter.hasNext() && output == null;) { PMMLOutputField fld = fieldIter.next(); if (fieldName.equals(fld.getName())) { output = fld; } } } if (child instanceof Miningmodel && output == null) { output = getChildOutputField(child,fieldName); } } return output; }
/** * Retrieves a Map with entries that consist of * key -> a model identifier * value -> the List of raw MiningField objects belonging to the model referenced by the key * @return The Map of model identifiers and their corresponding list of raw MiningField objects */ public Map<String, List<MiningField>> getMiningFields() { Map<String, List<MiningField>> miningFieldsMap = new HashMap<>(); for (PMML4Model model : getModels()) { List<MiningField> miningFields = model.getRawMiningFields(); miningFieldsMap.put(model.getModelId(), miningFields); model.getChildModels(); } return miningFieldsMap; }