Creating data provider extensions for SPSS services

A data provider extension can be used to connect to a predictive scoring server to enrich entity attributes in a solution business model. The data provider invokes a Java™™ class that supplies input and output values to the scoring configuration.

Before you begin

Before you begin, create an extension project and define the data provider in the solution BOM.

About this task

You use the Predictive Scoring Data Provider Extension wizard to generate a Java class from a template. The class contains entries that are derived from the external scoring service that you specified in the wizard.

In the Java class, field inputs must be sent as strings, correctly formatted for the data type of the field. Fields that have non-numeric or non-string data types must be formatted as the following types:

  • BOOLEAN: true (case insensitive) or 1, or false (case insensitive) or 0
  • DATE: yyyy-MM-dd
  • DAYTIME: HH:mm:ss
  • TIMESTAMP: yyyy-MM-dd'T'HH:mm:ss

Procedure

  1. In Insight Designer, click File > New > Other > Insight Designer > Predictive Scoring Data Provider Extension, and then click Next.
  2. In the Predictive Scoring Data Provider Extension wizard, select an existing extension project from the menu.
  3. Enter a package name. The package name must comply with Java package naming conventions. For example, com.example.mypackage.
  4. Enter a class name. By convention, Java class names start with an uppercase letter.
  5. Select a data provider interface from the available drop-down menu. The data providers are defined in the solution BOM.
  6. In the Response cache timeout field, enter a value in seconds. The maximum response cache timeout must be expressed as a value; greater than or equal to 0.
  7. Click Next.
  8. On the Connect to the SPSS Collaboration and Deployment Services Server page, specify the URL, user name and password if necessary, and then click Next. If the server does not authenticate users, a user name and password is not necessary.
  9. On the Selecting Scoring Configuration page, select the scoring configuration to be called by the Predictive Scoring Data Provider Extension.
  10. Click Next.
  11. Enter a name for the scoring endpoint.
  12. Click Finish. The Predictive Scoring Data Provider Extension wizard generates a Java™ file in the source folder of the extension project.
  13. Complete the code template in the Java™ source file that is created within the data provider project.

Example

This example shows how a predictive scoring data provider extension calls an SPSS® model with the following input nodes:

  • Orders, which has a field OrderTotal.
  • Data/Time, which has a CustomerDOB field and a CustomerAddress field.
In the solution BOM, the predictive scoring data provider extension is defined as MyDataProvider, and it passes values for the total order (Order Total), customer date of birth (Customer DOB), customer address (Customer Address), and requests an attribute named Sum.
a MyDataProvider is a data provider , 
   accepts an Order Total , a Customer DOB and a Customer Address , 
   returns a Sum.

The code initializes the tables and fields that correlate to the input nodes of the model. The code sets the column values for each row that is sent when the data provider requests a score, and how the input values are taken from the data provider request.

@ScoringConfiguration(configurationId="Config1",endpoint="MyScoringEndpoint")
@DataProviderDescriptor(dataProvider = MyDataProvider.class, responseCacheTimeout = 30)
public class MyScoringDataProvider extends ScoringDataProvider< MyDataProviderRequest, MyDataProviderResponse> implements MyDataProvider {

    @Override
    public MyDataProviderResponse processRequest(MyDataProviderRequest request) throws ComponentException {

    	ScoringInput scoringInput = createScoringInput();

        ScoringInputTable table1 = scoringInput.addTable("Orders");
        ScoringInputRow table1row1 = table1.addRow();
        table1row1.setColumnValue("OrderTotal", request.getOrderTotal());

        ScoringInputTable table2 = scoringInput.addTable("Date/Time");
        ScoringInputRow table2row1 = table2.addRow();
        table2row1.setColumnValue("CustomerDOB", request.getCustomerDOB());
        table2row1.setColumnValue("CustomerAddress", request.getCustomerAddress());

        ScoringOutput scoringOutput = invokeScoring(scoringInput);

        ScoringOutputRow row0 = scoringOutput.getRow(0);

        ConceptFactory factory = getConceptFactory(ConceptFactory.class);
        MyDataProviderResponse response = factory.createMyDataProviderResponse();

        response.setSum(row0.getColumnValue("$E-OrderTotal_Sum"));

        return response;
    }
}