static public List<? extends Map<FieldName, ?>> groupRows(HasGroupFields hasGroupFields, List<? extends Map<FieldName, ?>> table){ List<InputField> groupFields = hasGroupFields.getGroupFields(); if(groupFields.size() == 1){ InputField groupField = groupFields.get(0); table = EvaluatorUtil.groupRows(groupField.getName(), table); } else if(groupFields.size() > 1){ ModelEvaluator<?> modelEvaluator = (ModelEvaluator<?>)hasGroupFields; // XXX throw modelEvaluator.createMiningSchemaException("Expected 0 or 1 group field(s), got " + groupFields.size() + " group fields"); } return table; }
public static List<InputField> parseInputFields(Object model) { List<InputField> inputFields = new ArrayList<InputField>(); Field[] field = model.getClass().getDeclaredFields(); try { for (int j = 0; j < field.length; j++) { InputField inputField = new InputField(); inputField.setName(field[j].getName()); inputField.setValue(String.valueOf(field[j].get(model)); inputFields.add(inputField); } } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return inputFields; }
@Override public OpType getOpType(){ return FieldUtil.getOpType(getField(), getMiningField()); }
static protected EvaluationResponse evaluate(Evaluator evaluator, EvaluationRequest request){ logger.info("Received {}", request); Map<String, ?> requestArguments = request.getArguments(); EvaluationResponse response = new EvaluationResponse(request.getId()); Map<FieldName, FieldValue> arguments = new LinkedHashMap<>(); List<InputField> inputFields = evaluator.getInputFields(); for(InputField inputField : inputFields){ FieldName inputName = inputField.getName(); String key = inputName.getValue(); Object value = requestArguments.get(key); if(value == null && !requestArguments.containsKey(key)){ logger.warn("Evaluation request {} does not specify an input field {}", request.getId(), key); } FieldValue inputValue = inputField.prepare(value); arguments.put(inputName, inputValue); } logger.debug("Evaluation request {} has prepared arguments: {}", request.getId(), arguments); Map<FieldName, ?> results = evaluator.evaluate(arguments); // Jackson does not support the JSON serialization of <code>null</code> map keys results = replaceNullKey(results); logger.debug("Evaluation response {} has result: {}", response.getId(), results); response.setResults(EvaluatorUtil.decode(results)); logger.info("Returned {}", response); return response; }
protected List<InputField> createInputFields(MiningField.UsageType usageType){ M model = getModel(); MiningSchema miningSchema = model.getMiningSchema(); List<InputField> inputFields = new ArrayList<>(); if(miningSchema.hasMiningFields()){ List<MiningField> miningFields = miningSchema.getMiningFields(); for(MiningField miningField : miningFields){ FieldName name = miningField.getName(); if(!(miningField.getUsageType()).equals(usageType)){ continue; } Field<?> field = getDataField(name); if(field == null){ field = new VariableField(name); } InputField inputField = new InputField(field, miningField); inputFields.add(inputField); } } return ImmutableList.copyOf(inputFields); }
@Override public DataField getField(){ return (DataField)super.getField(); } }
public InputField(Field<?> field, MiningField miningField){ super(field); setMiningField(Objects.requireNonNull(miningField)); if(!Objects.equals(field.getName(), miningField.getName())){ throw new IllegalArgumentException(); } }
/** * <p> * Returns the domain of valid values for this categorical or ordinal field. * If specified, then all input values that are contained in this list shall be considered valid, and all others invalid. * In not specified, then all input values shall be considered valid. * </p> * * <p> * List elements are all valid values in PMML representation. * For example, if the data type of this field is {@link DataType#INTEGER}, then all list elements shall be {@link Integer}. * </p> * * @return A non-empty list, or <code>null</code>. * * @see #getDataType() * @see #getOpType() * * @see TypeUtil#parse(DataType, String) * @see TypeUtil#parseOrCast(DataType, Object) */ public List<?> getDiscreteDomain(){ Field<?> field = getField(); if(field instanceof HasDiscreteDomain){ List<?> validValues = FieldUtil.getValidValues((Field & HasDiscreteDomain)field); if(validValues != null && !validValues.isEmpty()){ return validValues; } } return null; }
InputField groupField = groupFields.get(0); requests = aggregateRequests(groupField.getName(), requests); } else
/** * <p> * Prepares the input value for a field. * </p> * * <p> * First, the value is converted from the user-supplied representation to PMML representation. * After that, the value is subjected to missing value treatment, invalid value treatment and outlier treatment. * </p> * * @param value The input value in user-supplied representation. * Use <code>null</code> to represent a missing input value. * * @throws EvaluationException If the input value preparation fails. * @throws InvalidMarkupException * @throws UnsupportedMarkupException */ public FieldValue prepare(Object value){ return InputFieldUtil.prepareInputValue(getField(), getMiningField(), value); }
/** * <p> * Returns the domain of valid values for this continuous field. * If specified, then all input values that are contained in this set shall be considered valid, and all others invalid. * If not specified, then all input values shall be considered valid. * </p> * * @return A non-empty set, or <code>null</code>. * * @see #getOpType() */ public RangeSet<Double> getContinuousDomain(){ Field<?> field = getField(); if(field instanceof HasContinuousDomain){ RangeSet<Double> validRanges = FieldUtil.getValidRanges((Field & HasContinuousDomain)field); if(validRanges != null && !validRanges.isEmpty()){ return validRanges; } } return null; }
name = activeField.getName(); category = value; } else
protected boolean assessPurity(){ List<InputField> inputFields = getInputFields(); for(InputField inputField : inputFields){ Field<?> field = inputField.getField(); MiningField miningField = inputField.getMiningField(); if(!InputFieldUtil.isDefault(field, miningField)){ return false; } } return this.localDerivedFields.isEmpty() && this.outputFields.isEmpty(); }
protected boolean assessParentCompatibility(){ List<InputField> inputFields = getInputFields(); for(InputField inputField : inputFields){ Field<?> field = inputField.getField(); MiningField miningField = inputField.getMiningField(); if(!(field instanceof DataField)){ continue; } // End if if(!InputFieldUtil.isDefault(field, miningField)){ return false; } } return true; }