Default values and staged rules are interrelated. While they may appear unrelated in the SADL grammar, see first section below, their implementation at the translating and reasoning level is interwoven. One implementation of staged rules and default values may be found in the Jena Augmented Reasoner/Translator pair. This reasoner/translator pair translates default values into staged rules. This pair can be selected for a SADL project from the project's Properties dialog window under SADL -> Reasoner Preferences.
Staging of rules means that one set of rules is loaded into the reasoner and inference is run before another stage of rules is added and inference is run again. This enables the modeler to control more precisely the order in which rules are considered for firing. Consider this made-up model.
Thingy is
a top-level
class.
Color is
a top-level
class, must
be one
of {Black,
White, Green}.
dp describes
Thingy
has values
of type
float.
op describes
Thingy
has values
of type
Color.
Suppose that we want to use rules to color any instance of Thingy Black which has a value of dp that is greater than 2 and that we want to color Green any instance of Thingy that doesn't have a color. We could write two rules for this purpose.
Rule RuleOne
given
x
is a
Thingy
if
dp
of x
> 2
then
op
of x
is Black.
Rule
RuleTwo
given
x
is a
Thingy
if
op
of x
is not
known
then
op
of x
is Green.
Now suppose that we have the following instance data.
MyThing1 is
a Thingy.
MyThing2 is
a Thingy,
has dp
2.5
.
Since the rule engine does not guarantee any particular order of rule consideration, MyThing2 could end up either Green or Black, depending on whether RuleOne or RuleTwo fires first. However, this non-determinism is eliminated by staging the rules.
Stage 1 Rule
RuleOne
given
x
is a
Thingy
if
dp
of x
> 2
then
op
of x
is Black.
Stage
2
Rule RuleTwo
given
x
is a
Thingy
if
op
of x
is not
known
then
op
of x
is Green.
Now, if the Jena Augmented Reasoner/Translator pair is used, RuleOne
will first be applied to the data and then RuleTwo will be added
to the loaded rules and applied. This ensures that MyThing1 will
be Green and MyThing2 will be Black.
The SADL grammar allows default values to be given to a property or property chain for instances of a given class. Furthermore, default values can be assigned a level, meaning that they are applied in a sequenced order. This can be useful in much the same way that staging of rules can be useful. Default value declarations are illustrated in this model. (See UnittedQuantity , also The SADL Implicit Model.)
Rectangle
is a
class described
by ^length
with values
of type
UnittedQuantity,
described
by width
with values
of type
UnittedQuantity.
Person
is a
type of
LegalEntity,
described
by friend
with values
of type
Person.
LegalEntity
is a
class, described
by counsel
with values
of type
Person.
FootballField
is a
type of
Rectangle,
described
by owner
with values
of type
LegalEntity.
PerryMason
is a
Person.
TerranceClay
is a
Person.
Arlington
is a
LegalEntity.
owner
of FootballField
has level
1
default Arlington.
unit
of ^length
of FootballField
has level
2
default "yds".
counsel
of owner
of FootballField
has default
PerryMason.
friend
of counsel
of owner
of FootballField
has default
TerranceClay.
^length
of FootballField
has default
100
yds.
In this example, the default value for unit of length of FootballField has a higher level to illustrate the syntax of levels, not because the example requires it.
To illustrate the result of using default values when a reasoner/translator pair supporting them, such as the Jena Augmented Reasoner/Translator pair, is used, consider this sample data.
MyFBF is
a FootballField
with length
(a UnittedQuantity
with ^value
100).
YourFBF
is a
FootballField
with length
100
yds.
AnotherFBF
is a
FootballField
with length
300
ft.
FourthFBF
is a
FootballField.
Running inference on this data, the following tests all pass.
Test: ^value
of ^length
of FourthFBF
is 100.
Test: unit
of ^length
of FourthFBF
is "yds".
Test: owner
of MyFBF
is Arlington.
Test: counsel
of owner
of YourFBF
is PerryMason.
Test: friend
of counsel of owner
of AnotherFBF
is TerranceClay.
This section describes how translation is performed by the Jean Augmented Translator. A rule without an explicit stage is given the stage value of 0. A default value without an explicit level is given the level value 0. If there are rules at multiple stages, then the translator will create multiple rule files with sequential file names, one for each rule stage and one for each default value level. These rule files give preference to rule stages over default value levels. In other words, if there are rules with stage 1 and default values with level 1, the sequence of rule files will first have a file containing the rules with stage 1 and then a file containing the rules derived from the default values with level 1. The result will be a set of files of the form
Note that the sequential numbers in the set of rule file names will not necessarily correspond to the stages or levels specified in the grammar. Rather the rule numbers start with 0 and are incremented without gaps as many times as necessary to create the proper sets of rules for inferencing. In the absence of staged rules and default values, the Jena Augmented Translator will create a single rule file identical to the one created by the regular Jena Reasoner Plugin.
The Jena Augmented Reasoner uses the the sequence of rule files as follows.
Note: the Jena Augmented Reasoner method getInferredModel(false), which returns the deductions model, will only compute a deductions model if there are, in fact, staged rules, if the configuration setting to enable derivations is set to "Shallow" or "Deep". When working in the SADL IDE, this can be set in the reasoner settings accessible from the project properties menu. When not in the SADL IDE, a call to initialize the reasoner with an in-memory OntModel by calling
initializeReasoner(Object kbase, String modelName, String rules, List<ConfigurationItempreferences).
The Java code to create the required preference to pass in as the last argument should be of this form:
import
com.ge.research.sadl.reasoner.ConfigurationItem;
...
List<ConfigurationItem>
preferences
= new
ArrayList<ConfigurationItem>();
String[] catHier
= new
String[1];
catHier[0] = reasoner.getReasonerFamily();
ConfigurationItem ci
= new
ConfigurationItem(catHier);
ci.addNameValuePair(ci.new
NameValuePair("pDerivationLogging",
"Deep"));
// could also be "Shallow"
preferences.add(ci);