Example: Create a Custom Function extension to default a value

Note: This example is somewhat more advanced than the example Create a Custom Function to capitalize text and builds on the concepts already demonstrated there.

 

By default a custom function does not see unknown and uncertain value, and their presence will automatically return unknown or uncertain as the result. However some functions can return a value even when some parameters are unknown.

In this example, a function is required to assume some default value in the case where a question hasn’t been answered; that is, when it is unknown.

Note: Because this example function transforms unknown values into known values, it may cause a rulebase to prematurely draw conclusions when required values have not been asked. If a distinction is required between a ‘genuine’ conclusion and a ‘default’ conclusion, use of this function may not be suitable.

 

The function is defined inside the extension.xml file as follows:

<extension>
    <functions>
        <function name="DefaultNumber" return-type="number">
            <arg name="value" type="number"/>
            <arg name="default" type="number"/>

            <handler platform="java"
                class="com.oracle.determinations.examples.DefaultFunction"/>
            <handler platform="dotnet"
                class="Oracle.Determinations.Examples.DefaultFunction"/>
        </function>
    </functions>
</extension>

This file is saved inside an extension folder, which is then itself copied into the project’s “Extensions” folder.




The class that implements this function is called DefaultFunction, derives from the CustomFunction class and must override three methods:

 

The rulebase to use for this example can be found at:

examples\determinations-engine\custom-functions\rulebase in the appropriate runtime zip.

 

For sample source code, go to:

Java:

examples\determinations-engine\custom-functions\src in Java runtime zip.

C#:

examples\determinations-engine\custom-functions\src\csharp in .NET runtime zip.

 

Once this code is compiled into a Java JAR file or .NET assembly DLL, it should be copied into the ‘lib’ folder of the extension and can then be used in the project:





See also:

Write a Custom Function extension

Custom Function extensions

Example: Create a Custom Function extension to capitalize text