Developing UnittedQuantity Handlers
Last revised
06/22/2023.
Contact us.
Handling of instances of UnittedQuantity occurring in expressions
during editing and inference is treated as a subset of type checking. A
helper class may be specified in the SADL preferences under "UnittedQuantity
Handler".
A helper class must implement the Interface class
ITypedBuiltinFunctionHelper. This Interface class defines the enum
UnittedQuantityBuiltinHandlingType which categorizes built-in functions
with respect to restrictions on UnittedQuantity arguments and which
has the following members.
- SingleArgument -- the function takes only a single argument of type
UnittedQuantity.
- SameUnitsRequired -- the function may have two or more arguments of
type UnittedQuantity but all must arguments must have the same
units. Examples include sum, difference, minimum, maximum, and comparison
operators.
- DifferentUnitAllowedOrLeftOnly -- the function may have multiple
arguments of type UnittedQuantity or the first argument may be of
type UnittedQuantity and subsequent arguments are not of type
UnittedQuantity. Examples include multiplication and division.
- LeftUnitsOnly -- the function have a UnittedQuantity argument
only as the first argument. An example is exponentiation.
- UnitsNotSupported -- the function does not support arguments of type
UnittedQuantity.
Implementations of the Interface must override the following methods.
- combineUnits -- takes a binary operator and two arguments, which are
the units of the binary operation. Returns the units of the output of the
operation.
- performUnitConversions -- takes four inputs: first argument, first
argument units, second argument, second argument units. It returns a array
with four elements: new first argument value, first argument units, second
argument value, second argument units.
- validateArgumentTypes -- this method is not restricted to
UnittedQuantity arguments but will take any set of arguments and argument
types and check them to see if they are valid. It will return the type(s)
of the output of the function.
- getTranslator -- returns the translator being used. This is necessary
as the translator may be used in the implementation of some method
functionality.
- setTranslator -- sets the translator being used.
- getUnittedQuantityBuiltinHandlingTypeOfBuiltinFromTranslator -- calls
the translator to obtain the UnittedQuantityBuiltinHandlingType.
In addition, the static method
getUnittedQuantityBuiltinHandlingTypeOfCommonBuiltins may be overridden if
desired.
A simple implementation of the Interface ITypedBuiltinFunctionHelper
be found in the class com.ge.research.sadl.jena.reasoner.SimpleJenaTypedBuiltinFunctionHelper.
This implementation does not support unit conversions and the implemented
approach to combining units is very simple. Given a richer semantic model of
units, such as that provided by QUDT,
these methods could be made very powerful.