Connecting to YModelCli from a third-party application

On many occasions a dfx script isn’t executed directly in esProc, but instead esProc is integrated into a third-party application. In such cases, in order to use the external library feature, you need to get raqsoftConfig.xml from esProc installation root directory/esProc/config directory and add the following code manually in the configuration file’s <Runtime><EsProc> ... </EsProc></Runtime>, specifying the reference path of jars the external library needs:

<extLibsPath> path of external library folder </extLibsPath>

<importLibs>

<lib> name of external library folder </lib> 

</importLibs>

Now we take embedding esProc into a Java application as an example to look at how YModelCli external library can be used in a third-party application:

1. Load jar files esProc JDBC needs

Put all jar files esProc JDBC needs in place. Find details in Deploying JDBC.

2. Configure esProc JDBC raqsoftConfig.xml file

Find details in Configuring raqsoftConfig.xml.

3. Load jar files of YModelCli

Copy YModelCli external library’s core jar (scu-ymodel-cli-2.10.jar) and files listed below into a separate directory, like D:\extlib\YModelCli:

commons-beanutils.jar

commons-io-2.4.jar

commons-lang-2.6.jar

esproc-ent-xxxxxxxx.jar

esproc-ext-xxxxxxxx.jar

ezmorph-1.0.2.jar

fastjson-1.2.58.jar

gson-2.8.0.jar

jackson-annotations-2.9.6.jar

jackson-core-2.9.6.jar

jackson-databind-2.9.6.jar

jackson-dataformat-msgpack-0.8.14.jar

json-lib-1.1-jdk13.jar

mining.jar

msgpack-0.6.12.jar

msgpack-core-0.8.16.jar

userconfig.xml

4. Configure the XML file YModelCli needs

Configure related parameters in userconfig.xml under YModelCli external library directory:

<?xml version="1.0" encoding="UTF-8"?>

<Config Version="1">

<Options>

<!-- YModel application directory -->

<Option Name="sAppHome" Value=""/>

<!-- Path of Python under YModel installation directory --> 

<Option Name="sPythonHome" Value=""/>

<!—Python service network port -->

<Option Name="iPythonServerPort" Value="8510"/>

<!—Number of Python processes-->

<Option Name="iPythonProcessNumber" Value="2"/>

<!-- Automatically impute or not --> 

<Option Name="bAutoDecideImpute" Value="true"/>

<!--Number of resamplings --> 

<Option Name="iResampleMultiple" Value="150"/>

</Options>

</Config>

The configuration of parameter sPythonHome varies under Windows and under Linux. The configuration path for Windows is [sAppHome]/Python39/python.exe, and that for Linux is [sAppHome]/Python39/bin/python3.9.

5. Add external library node <lib> in esProc JDBC’s raqsoftConfig.xml file

Configure external library node <lib>. In step 3 we already put jar file YModelCli needs under D:\ extlib\YModelCli directory and add the node directly:

<Esproc>

      … …

    //Configure path of external library folder

  <extLibsPath>D:\extlib</extLibsPath>

  <importLibs>

//Configure name of external library folder

      <lib>YModelCli</lib>

  </importLibs>

</Esproc>

6. Deploy the dfx file for accessing YModelCli

 

A

 

1

=ym_env()

Initialize environment

2

=ym_load_pcf("model.pcf")

Generate model object according to modeling files

3

=ym_predict(A2,"train_t.csv")

Execute prediction operation and return prediction result object

4

=ym_json(A2)

Obtain model information based on model object

5

=ym_json(A3)

Return model performance information evaluated according to the prediction data

6

>ym_close(A1)

Release resource

Find how to deploy the dfx file in Invocation from Java.

Now you can invoke a dfx file within a Java application.