Skip Headers

Oracle9iAS Personalization Programmer's Guide
Release 2 (v9.0.2)

Part Number A95245-02
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

A
REAPI Sample Program

This appendix contains ProxyTest.java , a sample Java program that illustrates using REAPI.

Before you can execute this program, an appropriate model must be built and deployed to an RE. If no data is returned, it may indicate that the model is not sufficient for the data. The code is installed in ${ORACLE_HOME}/dmt/reapi/rt/ on the system where Oracle9iAS is installed.


Note:

REAPI is installed on the system where Oracle9iAS is installed. It is simplest to run this program on that system.



// Copyright (c) 2001, 2002 Oracle Corp

///////////////////////////////////////////////////////////////////////
//
// Test program exercises the functionality of
// REAPI.
//
// Step 1 creates a unique session ID
// Step 2 creates a proxy instance
// Step 3 creates a session
// Step 4 creates settings data (IdentificationData, TuningSettings,
//        FilteringSettings, hotPick list, item list)
// Step 5 gets recomendations and ratings
// Step 6 closes session
// Step 7 destroys the proxy and flushes data cache
////////////////////////////////////////////////////////////////////////

import java.math.BigDecimal;
import java.lang.Long;
import java.sql.*;
import java.io.IOException;
import java.io.StringWriter;
import java.io.PrintWriter;
import oracle.jdeveloper.cm.CMException;
import oracle.dmt.op.re.reapi.rt.*;
import oracle.dmt.op.re.reapi.batch.*;
import oracle.dmt.op.re.reexception.*;
import oracle.dmt.op.re.base.*;
import oracle.dmt.oputil.exceptions.MessageLogException;
import oracle.dmt.oputil.exceptions.StringTooLongException;

/**
 * Class ProxyTest
 * <P>
 * @author Oracle Corporation
 */
public class ProxyTest
{
  static boolean bVerbose;
  static final String SESSIONEXISTS = "";
  /**
   * Constructor
   */
  public ProxyTest()
  {
  }

  /**
   * main
   * @param args
   */
public static void main(String[] args) throws ClassNotFoundException
  {
    long lStart;
    long lTotal = 0;
    String sProxyName = "REP1";
    String sdbURL = "jdbc:oracle:thin:@server-name:1521:darw900"; // sdbURL must 
be correct for your installation
    String sUser = "RE01";
    String sPass = "REPW";

    int cSize = 3000;   // Kbytes
    int interval = 10000;   // in millisec
    new ProxyTest();
    REProxyRT proxy;
    // Step 1: Create a unique Session ID.
    String custID = "1";
    java.util.Date tmp = new java.util.Date();
    Long tmpInt = new Long(tmp.getTime());
    String sessionID = tmpInt.toString();


    String trace = null;

    lStart = System.currentTimeMillis();
    try
    {
      // Step 2:  Get a proxy instance.
      if ((proxy = REProxyManager.getProxy(sProxyName)) == null)
        proxy = REProxyManager.createProxy(sProxyName, sdbURL, sUser, sPass, 
cSize, interval);

      // Step 3: create OP session
      proxy.createCustomerSession(custID, sessionID);

      // Step 4:  create settings data
      IdentificationData idData =
            IdentificationData.createSessionful(
                sessionID,
                Enum.User.CUSTOMER);

      TuningSettings tunings = new TuningSettings(
        Enum.DataSource.NAVIGATION,
        Enum.InterestDimension.NAVIGATION,
        Enum.PersonalizationIndex.HIGH,
        Enum.ProfileDataBalance.BALANCED,
        Enum.ProfileUsage.EXCLUDE);

      long[] hotPickGroups = {1,2,3,4,5,6,7,10,11}; 

      long[] m_catList = {1,2,3,4,5};

      FilteringSettings filters =
        new FilteringSettings(1);
        int taxonomy=1;
      filters.setItemFiltering( taxonomy, m_catList);
      RecommendationContent recContent = new 
RecommendationContent(Enum.Sorting.ASCENDING);

      try{

     //Create list of items for testing
      DataItem[] items = new DataItem[4];
      items[0] = new DataItem(
            "MOVIE",
            72,
            Enum.DataSource.RATING,
            "1.5");
     items[1] = new DataItem(
            "MOVIE",
            287,
            Enum.DataSource.RATING,
            "1.5");
     items[2] = new DataItem(
            "MOVIE",
            122,
            Enum.DataSource.RATING,
            "1.5");
     items[3] = new DataItem(
            "MOVIE",
            1300,
            Enum.DataSource.RATING,
            "1.5");
    int count =  1;

    // Step 5: Get recomendations and ratings and print them out. 
    // Note use of toString.
    try{
    System.out.println("\n################ " + count++ + " ################");
     //Call recommendBottonItems
     RecommendationList es1 = proxy.recommendBottomItems(
        idData,
        10,
        tunings,
        filters,
        recContent);
    System.out.println("");
    es1.toString();
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }

    try{
    System.out.println("\n################ " + count++ + " ################");
    //Call rateItems
    RecommendationList es2 = proxy.rateItems(
        idData,
        items,
        1,
        tunings,
        recContent);
    System.out.println("");
    System.out.println(es2.toString());
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }

    try{
    System.out.println("\n################ " + count++ + " ################");
    //call selectFromHotPicks
    RecommendationList es3 = proxy.selectFromHotPicks(
        idData,
        10,
        hotPickGroups,
        tunings,
        filters,
        recContent);
        System.out.println("");
    System.out.println("");
    System.out.println(es3.toString());
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }


    try{
    System.out.println("\n################ " + count++ + " ################");
    //Call crossSellForItemFromHotPicks
    RecommendationList es4 = proxy.crossSellForItemFromHotPicks(
        idData,
        items[0],
        10,
        hotPickGroups,
        tunings,
        filters,
        recContent);
    System.out.println("");
    System.out.println(es4.toString());
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }

    try{
    System.out.println("\n################ " + count++ + " ################");
   //Call recommendCrossSellForItem
    RecommendationList es5 = proxy.recommendCrossSellForItem(
        idData,
        items[0],
        10,
        tunings,
        filters,
        recContent);
    System.out.println("");
    System.out.println(es5.toString());
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }

    try{
    System.out.println("\n################ " + count++ + " ################");
     RecommendationList  es6 = proxy.recommendCrossSellForItems(
        idData,
        items,
        10,
        tunings,
        filters,
        recContent);
    System.out.println("");
    System.out.println(es6.toString());
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }

    try{
    System.out.println("\n################ " + count++ + " ################");
    RecommendationList es7 = proxy.crossSellForItemsFromHotPicks(
        idData,
        items,
        10,
        hotPickGroups,
        tunings,
        filters,
        recContent);
    System.out.println("");
    System.out.println(es7.toString());
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }


    try{
    System.out.println("\n################ " + count++ + " ################");
    float es9 = proxy.rateItem(
    idData,
    items[2],
    1,
    tunings,
    recContent
    );
    System.out.println("");
    System.out.println("Result for recomend item:  " + es9);
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }

    try{
    System.out.println("\n################ " + count++ + " ################");
    RecommendationList es10 = proxy.recommendFromHotPicks(
    idData,
    10,
    hotPickGroups,
    tunings,
    filters,
    recContent);
    System.out.println("");
    System.out.println(es10.toString());
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }

    try{
    System.out.println("\n################ " + count++ + " ################");
    RecommendationList es11 = proxy.recommendTopItems(
    idData,
    10,
    tunings,
    filters,
    recContent);
    System.out.println("");
    System.out.println(es11.toString());
    } catch(ErrorExecutingRE e) {
        e.printStackTrace();
    }

    } catch(BadDBConnectionException bdbe) {
        bdbe.printStackTrace();
    }catch (ClassNotFoundException exc) {
        exc.printStackTrace();
    }


    // Step 6: Close session
    proxy.closeSession(idData);

    // Step 7: Call destroy proxy (will flush data cache)
    REProxyManager.destroyProxy(sProxyName);

    } catch (ErrorExecutingRE se) {
      System.err.println(se);
    } catch (InvalidIDException iie) {
        System.err.println(iie);
    } catch(BadDBConnectionException bdbe) {
        bdbe.printStackTrace();
    } catch (Exception e) {
      System.err.println(e);
      e.printStackTrace();
    }
  }


}


Go to previous page Go to next page
Oracle
Copyright © 2001, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index