-
Notifications
You must be signed in to change notification settings - Fork 0
Predicates
As introduced in the challenges of automata learning in practice, not all concrete input symbols can be executed by the SUL at any given moment. For example, a concrete input symbol representing a button press could not be executed if that button is not visible onscreen. We can often invoke the behavior of the button press, but if this wouldn't be possible in a real-world scenario.
To deal with this challenge, it's possible to constrain when input symbols can be asked to the SUL with the help of predicates. If a predicate is true, the input symbol can be passed to the SUL. If a predicate is false, the input symbol cannot be passed to the SUL. In this case, an error is returned.
We have 2 kinds of predicates, "regular" predicates and NFA-based predicates. Both can be used with all types of symbols.
@Predicate(ID = "PredicateA")
public boolean predA(){
//some code
};
@Predicate(ID = "PredicateB")
public boolean predB(){
//some code
};
@FunctionSymbol(symbolID = "FooFunction", predicates = {"PredicateA"})
public void foo() {
// some code
}
@FieldMethodSymbol(fieldID = "BarField", outputIDs = {"output"},
fieldMethods = {"barMethod()"}, predicates = {"PredicateB"})
public Bar bar;
@WidgetSymbol(widgetID = "BazButton", outputIDs = {"output"},
events = {"press", "release"},
predicates = {"PredicateA","PredicateB"})
public Button baz;
The above predicates enforce that the behavior tied to the input symbols (i.e. the annotated methods) can only be executed when the given predicates are true. This means that the behavior tied to "FooFunction" can only be executed by the SUL when the function tied to predicate "PredicateA" returns true, that the behavior tied to "Barfield.BarMethod" can only be executed by the SUL when the function tied to predicate "PredicateB" returns true and that the behavior tied to event handling of the press and release events by the BazButton can only be invoked on the SUL when PredicateA and PredicateB are both true.
@FunctionSymbol(symbolID = "FooFunction", nfapredicates = {"myNFA#NFAFile[T1]#MyGroup"})
public void foo() {
// some code
}
@FieldMethodSymbol(fieldID = "BarField", outputIDs = {"output"},
fieldMethods = {"barMethod()"}, nfapredicates = {"myNFA#NFAFile[T2]#MyGroup",
"myNFA2#NFAFile2[X]#MyGroup2"})
public Bar bar;
@WidgetSymbol(widgetID = "BazButton", outputIDs = {"output"},
events = {"press", "release"},
nfapredicates = {"myNFA#NFAFile[T2]#MyGroup"})
public Button baz;
NFA predicates are quite tricky. The enforce that an input symbol's behavior can only be executed by the SUL if and only if the groups of NFA's accept the word containing all input symbols leading up and including the latest input symbol.
They are constructed in the form costum_nfa_ID#nfa_file_name[transition_label]#nfa_group
, where:
-
costum_nfa_ID
is the ID of the NFA generated from a template NFA, -
nfa_file_name
is the filename of the template NFA, -
transition_label
is the label which should be replaced with the ID of the symbol, -
Group
is the group to which this NFA belongs.
They NFA's used to check input applicability will be generated during runtime. Template NFA's can be created with JFLAP (GUI/CLI) should be in the same folder as the checkers.xml file. Multiple symbols can make use of the same transitions. If a transition label isn't replaced with the ID of a symbol, it will be replaced with a λ-step.
In the above example, the SUL after it's initialized or reset can execute the behavior tied to FooFunction once, twice but not thrice. From that point on we can only execute the behavior tied to the handling of a BazButton_press or a BazButton_release. Additionally, because of the constraints imposed by myNFA2 we can only execute BarField_barMethod() twice.
At the moment, groups aren't of much use. In the future, groups will provide a method for combining and synchronizing NFAs. In future releases, multiple NFA's will be allowed in the same group and you can specify custom rules as to how to synchronize and combine them (This is something which is hardcoded at the moment for the GUI group which enforces JavaFX's GUI constraints where NFA's care combined in a particular way).