Java Code Examples for org.dmg.pmml.DataType#BOOLEAN

The following examples show how to use org.dmg.pmml.DataType#BOOLEAN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeUtil.java    From jpmml-tensorflow with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public DataType getDataType(Output output){
	org.tensorflow.DataType dataType = output.dataType();

	switch(dataType){
		case FLOAT:
			return DataType.FLOAT;
		case DOUBLE:
			return DataType.DOUBLE;
		case INT32:
		case INT64:
			return DataType.INTEGER;
		case STRING:
			return DataType.STRING;
		case BOOL:
			return DataType.BOOLEAN;
		default:
			throw new IllegalArgumentException();
	}
}
 
Example 2
Source File: DatasetUtil.java    From jpmml-sparkml with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public DataType translateDataType(org.apache.spark.sql.types.DataType sparkDataType){

	if(sparkDataType instanceof StringType){
		return DataType.STRING;
	} else

	if(sparkDataType instanceof IntegralType){
		return DataType.INTEGER;
	} else

	if(sparkDataType instanceof DoubleType){
		return DataType.DOUBLE;
	} else

	if(sparkDataType instanceof BooleanType){
		return DataType.BOOLEAN;
	} else

	{
		throw new IllegalArgumentException("Expected string, integral, double or boolean data type, got " + sparkDataType.typeName() + " data type");
	}
}
 
Example 3
Source File: RExpUtil.java    From jpmml-r with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public DataType getDataType(String type){

	switch(type){
		case "character":
		case "factor":
			return DataType.STRING;
		case "numeric":
			return DataType.DOUBLE;
		case "logical":
			return DataType.BOOLEAN;
		default:
			break;
	}

	throw new IllegalArgumentException(type);
}
 
Example 4
Source File: TypeUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see DataType#BOOLEAN
 */
static
private Boolean toBoolean(Object value){

	if(value instanceof Boolean){
		return (Boolean)value;
	} else

	if((value instanceof Double) || (value instanceof Float) || (value instanceof Long) || (value instanceof Integer) || (value instanceof Short) || (value instanceof Byte)){
		Number number = (Number)value;

		if(number.doubleValue() == 0d){
			return Boolean.FALSE;
		} else

		if(number.doubleValue() == 1d){
			return Boolean.TRUE;
		}
	}

	throw new TypeCheckException(DataType.BOOLEAN, value);
}
 
Example 5
Source File: CategoricalValue.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int compareToValue(Object value){

	if(value instanceof Boolean){
		return Boolean.compare(asBoolean(), (Boolean)value);
	}

	Number number;

	try {
		number = (Number)TypeUtil.parseOrCast(DataType.DOUBLE, value);
	} catch(NumberFormatException nfe){
		throw nfe;
	} catch(TypeCheckException tce){
		throw new TypeCheckException(DataType.BOOLEAN, value);
	}

	return ((Comparable)asDouble()).compareTo(number);
}
 
Example 6
Source File: RBooleanVector.java    From jpmml-r with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public DataType getDataType(){
	return DataType.BOOLEAN;
}
 
Example 7
Source File: CategoricalValue.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
CategoricalBoolean(Object value){
	super(DataType.BOOLEAN, value);
}
 
Example 8
Source File: ObjectMapperTest.java    From jpmml-model with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
@Test
public void jsonClone() throws Exception {
	DataField dataField = new DataField(FieldName.create("x"), OpType.CATEGORICAL, DataType.BOOLEAN);

	DataDictionary dataDictionary = new DataDictionary()
		.addDataFields(dataField);

	MiningField miningField = new MiningField(FieldName.create("x"));

	MiningSchema miningSchema = new MiningSchema()
		.addMiningFields(miningField);

	assertSame(dataField.getName(), miningField.getName());

	SimplePredicate simplePredicate = new SimplePredicate(FieldName.create("x"), SimplePredicate.Operator.IS_NOT_MISSING, null);

	Node node = new ComplexNode(simplePredicate);

	TreeModel treeModel = new TreeModel()
		.setMiningSchema(miningSchema)
		.setNode(node);

	PMML pmml = new PMML()
		.setDataDictionary(dataDictionary)
		.addModels(treeModel);

	DirectByteArrayOutputStream buffer = new DirectByteArrayOutputStream(1024);

	JacksonUtil.writePMML(pmml, buffer);

	PMML jsonPmml;

	try(InputStream is = buffer.getInputStream()){
		jsonPmml = JacksonUtil.readPMML(is);
	}

	DataDictionary jsonDataDictionary = jsonPmml.getDataDictionary();

	List<DataField> jsonDataFields = jsonDataDictionary.getDataFields();

	assertEquals(1, jsonDataFields.size());

	DataField jsonDataField = jsonDataFields.get(0);

	assertEquals(dataField.getName(), jsonDataField.getName());
	assertEquals(dataField.getOpType(), jsonDataField.getOpType());
	assertEquals(dataField.getDataType(), jsonDataField.getDataType());

	List<Model> jsonModels = jsonPmml.getModels();

	assertEquals(1, jsonModels.size());

	TreeModel jsonTreeModel = (TreeModel)jsonModels.get(0);

	MiningSchema jsonMiningSchema = jsonTreeModel.getMiningSchema();

	List<MiningField> jsonMiningFields = jsonMiningSchema.getMiningFields();

	assertEquals(1, jsonMiningFields.size());

	MiningField jsonMiningField = jsonMiningFields.get(0);

	assertEquals(miningField.getName(), jsonMiningField.getName());
	assertEquals(miningField.getUsageType(), jsonMiningField.getUsageType());

	assertSame(jsonDataField.getName(), jsonMiningField.getName());

	Node jsonNode = jsonTreeModel.getNode();

	SimplePredicate jsonSimplePredicate = (SimplePredicate)jsonNode.getPredicate();

	assertEquals(simplePredicate.getField(), jsonSimplePredicate.getField());
	assertEquals(simplePredicate.getOperator(), jsonSimplePredicate.getOperator());

	assertSame(jsonDataField.getName(), jsonSimplePredicate.getField());
	assertSame(jsonMiningField.getName(), jsonSimplePredicate.getField());
}