Java Code Examples for org.dmg.pmml.OpType#ORDINAL

The following examples show how to use org.dmg.pmml.OpType#ORDINAL . 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: TransformerUtil.java    From jpmml-sklearn with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public OpType getOpType(DataType dataType){

	switch(dataType){
		case STRING:
			return OpType.CATEGORICAL;
		case INTEGER:
		case FLOAT:
		case DOUBLE:
			return OpType.CONTINUOUS;
		case BOOLEAN:
			return OpType.CATEGORICAL;
		case DATE:
		case DATE_TIME:
			return OpType.ORDINAL;
		default:
			throw new IllegalArgumentException();
	}
}
 
Example 2
Source File: OrdinalValue.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public FieldValue create(DataType dataType, List<?> ordering, Object value){

	if(ordering != null && ordering.isEmpty()){
		ordering = null;
	} // End if

	if(value instanceof Collection){
		return new CollectionValue(dataType, OpType.ORDINAL, ordering, (Collection<?>)value);
	}

	switch(dataType){
		case STRING:
			return new OrdinalString(ordering, value);
		default:
			return new OrdinalValue(dataType, ordering, value);
	}
}
 
Example 3
Source File: TypeUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
public OpType getOpType(DataType dataType){

	switch(dataType){
		case STRING:
			return OpType.CATEGORICAL;
		case INTEGER:
		case FLOAT:
		case DOUBLE:
			return OpType.CONTINUOUS;
		case BOOLEAN:
			return OpType.CATEGORICAL;
		case DATE:
		case TIME:
		case DATE_TIME:
			return OpType.ORDINAL;
		case DATE_DAYS_SINCE_0:
		case DATE_DAYS_SINCE_1960:
		case DATE_DAYS_SINCE_1970:
		case DATE_DAYS_SINCE_1980:
		case TIME_SECONDS:
		case DATE_TIME_SECONDS_SINCE_0:
		case DATE_TIME_SECONDS_SINCE_1960:
		case DATE_TIME_SECONDS_SINCE_1970:
		case DATE_TIME_SECONDS_SINCE_1980:
			return OpType.CONTINUOUS;
		default:
			throw new IllegalArgumentException();
	}
}
 
Example 4
Source File: FieldValueTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void ordinalInteger(){
	OrdinalValue zero = (OrdinalValue)FieldValueUtil.create(DataType.INTEGER, OpType.ORDINAL, 0);
	OrdinalValue one = (OrdinalValue)FieldValueUtil.create(DataType.INTEGER, OpType.ORDINAL, 1);

	assertTrue(zero.equalsValue("0"));
	assertTrue(zero.equalsValue("0.0"));

	assertTrue(zero.compareToValue("-1") > 0);
	assertTrue(zero.compareToValue("0") == 0);
	assertTrue(zero.compareToValue("1") < 0);

	assertTrue(zero.compareTo(zero) == 0);
	assertTrue(zero.compareTo(one) < 0);

	assertTrue(one.compareTo(zero) > 0);
	assertTrue(one.compareTo(one) == 0);

	TypeInfo typeInfo = new SimpleTypeInfo(DataType.INTEGER, OpType.ORDINAL, Arrays.asList(1, 0));

	zero = (OrdinalValue)FieldValueUtil.create(typeInfo, zero.getValue());

	assertTrue(zero.compareTo(zero) == 0);
	assertTrue(zero.compareTo(one) > 0);

	one = (OrdinalValue)FieldValueUtil.create(typeInfo, one.getValue());

	assertTrue(one.compareTo(zero) < 0);
	assertTrue(one.compareTo(one) == 0);
}
 
Example 5
Source File: OrdinalDomain.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public OpType getOpType(){
	return OpType.ORDINAL;
}
 
Example 6
Source File: OrdinalValue.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public OpType getOpType(){
	return OpType.ORDINAL;
}
 
Example 7
Source File: FieldValueTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void ordinalString(){
	OrdinalValue loud = (OrdinalValue)FieldValueUtil.create(TypeInfos.ORDINAL_STRING, "loud");
	OrdinalValue louder = (OrdinalValue)FieldValueUtil.create(TypeInfos.ORDINAL_STRING, "louder");
	OrdinalValue insane = (OrdinalValue)FieldValueUtil.create(TypeInfos.ORDINAL_STRING, "insane");

	assertFalse(louder.equalsValue("loud"));
	assertTrue(louder.equalsValue("louder"));
	assertFalse(louder.equalsValue("insane"));

	assertFalse(louder.equalsValue(loud));
	assertTrue(louder.equalsValue(louder));
	assertFalse(louder.equalsValue(insane));

	// Implicit (ie. lexicographic) ordering
	assertNull(loud.getOrdering());

	assertTrue(louder.compareToValue("loud") > 0);
	assertTrue(louder.compareToValue("louder") == 0);
	assertTrue(louder.compareToValue("insane") > 0);

	assertTrue(louder.compareTo(loud) > 0);
	assertTrue(louder.compareTo(louder) == 0);
	assertTrue(louder.compareTo(insane) > 0);

	TypeInfo typeInfo = new SimpleTypeInfo(DataType.STRING, OpType.ORDINAL, Arrays.asList("loud", "louder", "insane"));

	loud = (OrdinalValue)FieldValueUtil.create(typeInfo, loud.getValue());
	louder = (OrdinalValue)FieldValueUtil.create(typeInfo, louder.getValue());
	insane = (OrdinalValue)FieldValueUtil.create(typeInfo, insane.getValue());

	// Explicit ordering
	assertNotNull(loud.getOrdering());

	assertTrue(louder.compareToValue("loud") > 0);
	assertTrue(louder.compareToValue("louder") == 0);
	assertTrue(louder.compareToValue("insane") < 0);

	assertTrue(louder.compareTo(loud) > 0);
	assertTrue(louder.compareTo(louder) == 0);
	assertTrue(louder.compareTo(insane) < 0);
}
 
Example 8
Source File: ExpressionUtilTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
@Test
public void evaluateAggregate(){
	FieldName name = FieldName.create("x");

	TypeInfo typeInfo = new SimpleTypeInfo(DataType.DATE, OpType.ORDINAL);

	List<?> values = Arrays.asList(TypeUtil.parse(DataType.DATE, "2013-01-01"), TypeUtil.parse(DataType.DATE, "2013-02-01"), TypeUtil.parse(DataType.DATE, "2013-03-01"));

	Map<FieldName, FieldValue> arguments = Collections.singletonMap(name, FieldValue.create(typeInfo, values));

	Aggregate aggregate = new Aggregate(name, Aggregate.Function.COUNT);

	assertEquals(3, evaluate(aggregate, arguments));

	aggregate.setFunction(Aggregate.Function.MIN);

	assertEquals(values.get(0), evaluate(aggregate, arguments));

	aggregate.setFunction(Aggregate.Function.MAX);

	assertEquals(values.get(2), evaluate(aggregate, arguments));

	typeInfo = new SimpleTypeInfo(DataType.DATE, OpType.ORDINAL, Lists.reverse(values));

	arguments = Collections.singletonMap(name, FieldValue.create(typeInfo, values));

	aggregate.setFunction(Aggregate.Function.MIN);

	assertEquals(values.get(2), evaluate(aggregate, arguments));

	aggregate.setFunction(Aggregate.Function.MAX);

	assertEquals(values.get(0), evaluate(aggregate, arguments));
}