Creating a java classifier

You can create a java classifier. Java classifier can be used to classify data by writing custom logic in Java classes to classify a set of data.

About this task

You must have the write permissions on the ASBServer/lib and ASBNode/lib/java folders.

All java based classifiers have to implement ValueBasedClassifier interface by overriding public boolean matchValue(Object value). When a classifier is deployed by overriding the public boolean matchValue(Object value) of the ValueBasedClassifier interface, you should compare the implementation with the actual value. For example, if you want to classify all the values which is between 600000000 and 999999999, you must verify if the value lies between the specified numbers. If the value is between the specified numbers, then it is classified as true and otherwise as false. When the value is true, it is classified with the name you provided in the xml definition.

Procedure

  1. Create a project in eclipse or Integrated Development Environment (IDE) for java.
  2. Get the ia-common.jar from the InfoSphere® Information Server (IIS) installation location, and add it to your project classpath. This jar file can be found at ASBNODE\lib\java or ASBServer\lib folders.
  3. Create a class file with your custom name and implement ValueBasedClassifier.
  4. Resolve the compiler issue by importing ValueBasedClassifier interface to the custom class which resides in ia-common.jar.
  5. Implement the method public boolean matchValue(Object value) and write the custom logic inside it. The method returns true or false based on the passed value.
  6. Export the classifier as a jar file with any required name.

Example

package my.test.classifier;

import com.ibm.infosphere.ia.classification.ValueBasedClassifier;

public class MyCustom implements ValueBasedClassifier {
	public boolean matchValue(Object value) {
		// if the value is a number, it matches the class if it is in the expected range
		if (value instanceof Number) {
			int intValue = ((Number)value).intValue();
			return intValue>600000000 && intValue<999999999;
		}
		// if the value is not a number, it cannot match the class
		else {
			return false;
		}
	}
}

XML definition for the above classifier:

<?xml version="1.0" encoding="UTF-8"?>
<tns:DataClasses
		xmlns:tns="http://www.ibm.com/infosphere/ia/classification/DataclassesDefinition"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ibm.com/infosphere/ia/classification
/DataclassesDefinition/../../../model/DataClassesDefinition.xsd ">
			  		<tns:DataClass id="customID" name="CustomName"
description="Custom description" example="999999999">
	 					<tns:JavaClassifier
		 				className="my.test.classifier.MyCustom" />
		 				<tns:DataTypeFilter>
								<tns:LogicalDataType>numeric</tns:LogicalDataType>
				 		</tns:DataTypeFilter>
		 			  </tns:DataClass>
</tns:DataClasses>

What to do next

After the two files are created bundle them again into a jar with the required name. The main jar file is a bundle of Customjar and xml file. At the time of deployment pass the Mainjar as the parameter.

Deploy the data classes into the model using the following command:
IAAdmin -user user_name -password password -url https://host:port -deployDataClasses <path of the Mainjar file>
Install the java classes related to the new JAVA classifier using the following command on engine and server tiers.
IAAdmin -installClassifiers <path of the Mainjar file>
Note: On the server tier, IAAdmin script is in <InformationServer Home>/ASBServer/bin and on engine tier IAAdmin script is on <InformationServer Home>/ASBNode/bin