Replacing lambda expressions in a rete network with corresponding code classes
Lambda expressions in a Rete network class can be replaced with code classes according to some examples herein. In one particular example, a system can generate a Rete network based on a set of rules. The Rete network can include nodes corresponding to conditions defined in the set of rules. The system can generate a network class based on the Rete network, where the network class is source code that includes lambda expressions representing the conditions associated with the nodes. The system can also generate replacement classes based on the lambda expressions. The system can then generate a modified network class by replacing the lambda expressions with the replacement classes in the network class.
1 . A non-transitory computer-readable medium comprising program code that is executable by one or more processors for causing the one or more processors to perform operations including:
generating a Rete network based on a set of rules, the Rete network including nodes corresponding to conditions defined in the set of rules;
generating a network class based on the Rete network, the network class being source code that includes lambda expressions representing the conditions associated with the nodes;
generating replacement classes based on the lambda expressions, each of the replacement classes being configured to represent one of the lambda expressions, wherein generating the replacement classes involves:
parsing the network class to identify a lambda expression in the network class;
extracting a parameter of the lambda expression from the network class;
generating a field accessor based on the parameter; and
generating a replacement class that includes the field accessor, the replacement class being one of the replacement classes;
generating a modified network class by replacing the lambda expressions with the replacement classes in the network class; and
compiling the modified network class into bytecode, wherein a rule engine is configured to execute the compiled bytecode to evaluate input data against the Rete network.
2 . The non-transitory computer-readable medium of claim 1 , wherein generating the field accessor involves:
obtaining field metadata from one or more pattern declarations of the Rete network; and
generating the field accessor based on the parameter and the field metadata.
3 . The non-transitory computer-readable medium of claim 1 , wherein the nodes are alpha nodes of an alpha network of the Rete network, the alpha network being a discrimination network configured to select working memory elements that match the conditions associated with the alpha nodes.
4 . The non-transitory computer-readable medium of claim 1 , wherein the operations further comprise receiving the set of rules as input from a user via a graphical user interface of the rule engine.
5 . The non-transitory computer-readable medium of claim 1 , wherein the operations further comprise generating the network class using one or more predefined metaprogramming libraries.
6 . A method comprising:
generating, by one or more processors, a Rete network based on a set of rules, the Rete network including nodes corresponding to conditions defined in the set of rules;
generating, by the one or more processors, a network class based on the Rete network, the network class being source code that includes lambda expressions representing the conditions associated with the nodes;
prior to initiating compilation of the network class, generating, by the one or more processors, replacement classes based on the lambda expressions, each of the replacement classes being source code configured to represent one of the lambda expressions, wherein generating the replacement classes involves:
parsing the network class to identify a lambda expression in the network class;
extracting a parameter of the lambda expression from the network class; and
generating a replacement class based on the parameter, the replacement class being one of the replacement classes;
prior to initiating compilation of the network class, modifying, by the one or more processors, the network class by replacing the lambda expressions with the replacement classes in the network class to thereby generate a modified network class; and
after modifying the network class, compiling the modified network class into byte code, wherein the bytecode is executable by a rule engine to evaluate input data against the Rete Network.
7 . The method of claim 6 , wherein generating the replacement classes involves:
generating a field accessor based on the parameter; and
generating the replacement class to include the field accessor.
8 . The method of claim 7 , wherein generating the field accessor involves:
obtaining field metadata from one or more pattern declarations of the Rete network; and
generating the field accessor based on the parameter and the field metadata.
9 . The method of claim 6 , wherein the nodes are alpha nodes of an alpha network of the Rete network, the alpha network being a discrimination network configured to select working memory elements that match the conditions associated with the alpha nodes.
10 . The method of claim 6 , further comprising receiving the set of rules as input from a user via a graphical user interface of the rule engine.
11 . The method of claim 6 , further comprising generating the network class using one or more predefined metaprogramming libraries.
12 . A system comprising:
one or more processors; and
a memory that includes instructions executable by the one or more processors for causing the one or more processors to perform operations including:
generating a Rete network based on a set of rules, the Rete network including nodes corresponding to conditions defined in the set of rules;
generating a network class based on the Rete network, the network class being source code that includes lambda expressions representing the conditions associated with the nodes;
prior to initiating compilation of the network class, generating replacement classes based on the lambda expressions, each of the replacement classes being source code configured to represent one of the lambda expressions, wherein generating the replacement classes involves:
parsing the network class to identify a lambda expression in the network class;
extracting a parameter of the lambda expression from the network class; and
generating a replacement class based on the parameter, the replacement class being one of the replacement classes;
prior to initiating compilation of the network class, modifying the network class by replacing the lambda expressions with the replacement classes in the network class to thereby generate a modified network class;
after modifying the network class, compiling the modified network class into bytecode; and
executing, by a rule engine, the compiled bytecode to evaluate input data against the Rete network.
13 . The system of claim 12 , wherein generating the replacement classes involves:
generating a field accessor based on the parameter; and
generating the replacement class to include the field accessor.
14 . The system of claim 13 , wherein generating the field accessor involves:
obtaining field metadata from one or more pattern declarations of the Rete network; and
generating the field accessor based on the parameter and the field metadata.
15 . The system of claim 12 , wherein the nodes are alpha nodes of an alpha network of the Rete network, the alpha network being a discrimination network configured to select working memory elements that match the conditions associated with the alpha nodes.
16 . The system of claim 12 , wherein the operations further comprise generating the network class using one or more predefined metaprogramming libraries.
17 . The system of claim 12 , wherein modifying the network class involves:
identifying a reference to the lambda expression in the network class; and
replacing the reference in the network class with a call to the replacement class.