CN110196719B - Business rule generation method and system based on natural language processing - Google Patents

Business rule generation method and system based on natural language processing Download PDF

Info

Publication number
CN110196719B
CN110196719B CN201910417684.8A CN201910417684A CN110196719B CN 110196719 B CN110196719 B CN 110196719B CN 201910417684 A CN201910417684 A CN 201910417684A CN 110196719 B CN110196719 B CN 110196719B
Authority
CN
China
Prior art keywords
rule
business
business rule
natural language
execution
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910417684.8A
Other languages
Chinese (zh)
Other versions
CN110196719A (en
Inventor
朱佳栋
朱波
高峰
郑晓琳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN201910417684.8A priority Critical patent/CN110196719B/en
Publication of CN110196719A publication Critical patent/CN110196719A/en
Application granted granted Critical
Publication of CN110196719B publication Critical patent/CN110196719B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis

Abstract

The invention provides a business rule generation method and a system based on natural language processing, wherein the method comprises the following steps: acquiring business rules written in a natural language mode by a user according to a preset logic rule structure; decomposing the business rule according to a preset logic rule structure and extracting display fields of elements in the business rule, so that each element in the business rule corresponds to a structure class in the logic rule structure; packaging the decomposed business rules according to a preset packaging format to obtain a serialized business rule combination object; translating the serialized business rule combination object into a rule code according to a predetermined mapping relation between the display field of each element and the actual meaning of the corresponding element; and carrying out validity check on the rule code, and releasing the business rule after the verification is passed. The invention improves the usability of rule development, reduces the probability of compiling errors and improves the business rule generation efficiency.

Description

Business rule generation method and system based on natural language processing
Technical Field
The present invention relates to the field of rule engine technologies, and in particular, to a method and system for generating a business rule based on natural language processing.
Background
In the enterprise operation process, the business rules must be adjusted quickly in coordination with the variation of the actual production conditions. Therefore, in order to realize the quick effect of the business rules on the computer system and ensure the accuracy of rule adjustment, decoupling and separation of the business rules and the system architecture are introduced, namely, business personnel complete the writing of the business rules, and the business rules are put into the system for formal starting after operation verification.
However, in practice, currently, the mainstream rule writing software relies on a programming language with very strong expertise to complete the development of rule logic, so that it is very difficult for general service personnel to change and maintain. Moreover, because the coding method of each business person is not standard, compiling errors are easy to generate, or coding rules are inconsistent with actually required business logic, the cost of writing and changing the business rules is greatly increased, and response timeliness to business is reduced.
Disclosure of Invention
In order to solve the technical problems, the embodiment of the invention provides a business rule generation method and a business rule generation system based on natural language processing.
In one aspect, an embodiment of the present invention provides a method for generating a business rule based on natural language processing, where the method includes:
acquiring business rules written in a natural language mode by a user according to a preset logic rule structure;
decomposing the business rule according to a preset logic rule structure and extracting display fields of elements in the business rule, so that each element in the business rule corresponds to a structure class in the logic rule structure;
packaging the decomposed business rules according to a preset packaging format to obtain a serialized business rule combination object;
translating the serialized business rule combination object into a rule code according to a predetermined mapping relation between the display field of each element and the actual meaning of the corresponding element;
carrying out validity check on the rule codes, and releasing the business rules after the verification is passed;
the preset logic rule structure comprises a condition group and an execution group, wherein the condition group is used for describing a condition combination meeting the rule, and the execution group is used for describing an action to be executed after meeting the condition; the condition group comprises at least one condition sentence, and the condition sentence comprises a logic operation object, a logic operator, a relational operation object and a relational operator; the execution group comprises at least one execution statement, the execution statement comprises an assignment statement and/or an execution method statement, the assignment statement comprises an assignment object and an assignment operator, and/or an arithmetic operation object and an arithmetic operator, and the execution method statement comprises an execution method and parameters.
In an embodiment, the preset encapsulation format includes JSON format.
In an embodiment, packaging the decomposed business rule according to a preset packaging format to obtain a serialized business rule combination object, including:
translating and splicing the decomposed business rules one by one into a business rule combination object in a JSON format;
and calling a Java API, and carrying out serialization processing on the service rule combination object in the JSON format to obtain the serialized service rule combination object.
In one embodiment, according to a predetermined mapping relationship between a presentation field of each element and an actual meaning of the corresponding element, translating the serialized business rule combination object into a rule code, including:
and according to the mapping relation between the display field of each element and the actual meaning of the corresponding element, splicing the serialized business rule combination objects one by one according to the DRL grammar requirement, and translating the serialized business rule combination objects into rule codes conforming to the DRL grammar.
In an embodiment, performing validity check on the rule code includes: code compiling is carried out on the rule codes obtained through translation by utilizing a Drools rule engine so as to check the legality of the rule codes.
On the other hand, the embodiment of the invention also provides a business rule generating system based on natural language processing, which comprises the following steps:
the business rule acquisition unit is used for acquiring business rules written in a natural language mode by a user according to a preset logic rule structure;
the business rule analysis unit is used for decomposing the business rule according to a preset logic rule structure and extracting the display field of each element in the business rule so that each element in the business rule corresponds to a structure class in the logic rule structure;
the rule serialization unit is used for packaging the decomposed business rules according to a preset packaging format to obtain a serialized business rule combination object;
the translation unit is used for translating the serialized business rule combination object into a rule code according to the mapping relation between the display field of each element and the actual meaning of the corresponding element;
the rule checking unit is used for carrying out validity check on the rule codes, and releasing the business rules after the rule codes pass the verification;
the preset logic rule structure comprises a condition group and an execution group, wherein the condition group is used for describing a condition combination meeting the rule, and the execution group is used for describing an action to be executed after meeting the condition; the condition group comprises at least one condition sentence, and the condition sentence comprises a logic operation object, a logic operator, a relational operation object and a relational operator; the execution group comprises at least one execution statement, the execution statement comprises an assignment statement and/or an execution method statement, the assignment statement comprises an assignment object and an assignment operator, and/or an arithmetic operation object and an arithmetic operator, and the execution method statement comprises an execution method and parameters.
In an embodiment, the preset encapsulation format includes JSON format.
In an embodiment, the rule serialization unit comprises:
the translation assembly module is used for translating and assembling the decomposed business rules one by one into a business rule combination object in a JSON format;
and the serialization module is used for calling Java API, and carrying out serialization processing on the JSON format business rule combination object to obtain the serialized business rule combination object.
In one embodiment, the translation unit is specifically configured to:
and according to the mapping relation between the display field of each element and the actual meaning of the corresponding element, splicing the serialized business rule combination objects one by one according to the DRL grammar requirement, and translating the serialized business rule combination objects into rule codes conforming to the DRL grammar.
In an embodiment, the rule checking unit is specifically configured to: code compiling is carried out on the rule codes obtained through translation by utilizing a Drools rule engine so as to check the legality of the rule codes.
The business rule generating method and the system based on natural language processing provided by the embodiment of the invention can enable a rule writer to describe complex business rule characteristics and logic judgment descriptions in an expression form close to natural language, and have the characteristics of business independence, extensible combination, easiness in writing and the like. On one hand, the usability of rule development is improved, the probability of compiling errors is reduced, and the business rule generation efficiency is improved; on the other hand, the rule logic is converted from the traditional code structure into the structured canonical form for storage, and the converted format can be conveniently and efficiently converted into the main stream rule engine recognizable development language, so that the application range of the rule code is improved; in addition, the structural form translation makes the logic editing layer clearer, is convenient for reading and management, and also provides guarantee for the expansion of the future grammar form.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow diagram of a business rule generating method based on natural language processing according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a business rule generating system based on natural language processing according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a rule serialization unit 30 according to an embodiment of the present invention;
fig. 4 is a schematic diagram of a rule editing interface according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Fig. 1 is a general flow chart of a business rule generating method based on natural language processing according to an embodiment of the present invention. As shown in fig. 1, the method mainly comprises the following steps:
s1, acquiring business rules written in a natural language mode by a user according to a preset logic rule structure.
The preset logic rule structure comprises a condition group and an execution group, namely a < rule >: = "when" < condition group > "then" < action group >. The condition group is used for describing a condition combination meeting the rule and comprises at least one condition statement, wherein the condition statement is further split according to logic judgment conditions and mainly comprises a logic operation object, a logic operator, a relational operation object and a relational operator, namely < condition statement > = < logic operator > < object > < relational operator > < object >.
The execution group is used for describing actions to be executed after meeting the conditions and comprises at least one execution statement, and the execution statement can be divided into an assignment statement and an execution method statement according to the execution type. The assignment statement is used to describe the processing procedure of the result of the operation of assigning one object to another object or combining several objects, and can be split into an assignment object and an assignment operator, and/or an arithmetic operation object and an arithmetic operator, for example, the structure can be defined as follows: < assignment statement > = < object > < assignment operator > < object > |{ < arithmetic operator > < object > }. The execution method statement is used for describing complex logic processing, and mainly comprises an execution method and parameters, for example, the structure of the execution method statement can be defined as follows: < execution method statement > = < execution method name > < english definition > < chinese definition > < number of parameters > { < parameters > }. The executing method statement can be realized by Java language, compiled into class file and loaded into the system in external import mode.
When a user customizes a service rule by using natural language, the logic rule structure is customized according to the logic rule structure provided by the embodiment of the invention, and the natural language in the invention refers to simplified Chinese.
And S2, decomposing the service rule according to a preset logic rule structure and extracting the display field of each element in the service rule, so that each element in the service rule corresponds to a structural class in the logic rule structure.
And splitting and decomposing the business rule to obtain the most basic elements, and defining the display field and the actual meaning of each element in advance. The display field is used for displaying and using when the natural language edits rules, and the actual meaning is an actual value adopted by the element when the element is translated and spliced into rule codes.
And S3, packaging the decomposed business rules according to a preset packaging format to obtain a serialized business rule combination object.
And S4, translating the serialized business rule combination object into a rule code according to a predetermined mapping relation between the display field of each element and the actual meaning of the corresponding element.
And S5, carrying out validity check on the rule codes, and releasing the business rules after the verification is passed.
In the defined logical rule structure, the < logical operator > refers to logical operations such as AND, OR, NOT, and the like. The < object > is an entity formed by packaging data, i.e. assembling a group of data and the related operation of the group of data, so that the entity of the < object > can be further divided into four types of < attribute > | < method > | < input > | < constant >. Wherein < attribute > is a feature for describing an object, and is composed of < class > < data type > < english definition > < chinese definition >; the term "method" is a concept in object-oriented programming, and is used to describe the encapsulation of the execution result generated after the operation acts on the object, and is composed of the term "method name" < english definition > < chinese definition > < parameter number > { < parameter > } < return value >; the < input > refers to a foreground input tag, consisting of < data type > < value >; < constant > refers to the constant amount in the rule logic definition, consisting of < data type > < name > < value >; the < relational operator > means ">", "<", "=", "> =", "<=", |! = "equal relation operation symbol.
In the defined logical rule structure, < assignment operator > means "=", "+ =", "-", < arithmetic operator > means "+", "-", "/", "%", etc. arithmetic operation symbols.
The logic rule structure in the invention is described by BNF (Backus-Nuar Form, backus-like, a formalized symbol describing the grammar of a given language), and is specifically shown as follows:
< rule > = "when" < condition set > "then" < action set >
< condition set > = { < condition sentence > }
< conditional statement > = < logical operator > < object > < relational operator > < object >
< object > = < attribute > | < method > | < input > | < constant >
< attribute > = < class > < data type > < english definition > < chinese definition >
< method > = < method name > < english definition > < chinese definition > < parameter number > { < parameter > } < return value >
< input > = < data type > < value >
< constant > = < data type > < name > < value >
< action group > = { < execution statement > }
< execution statement > = < assignment statement > | < execution method >
< assignment statement > = < object > < assignment operator > < object > | { arithmetic operator > < object > }
< execution method > = < execution method name > < english definition > < chinese definition > < number of parameters > { < parameters > }
After the user edits a plurality of conditional sentences in natural language according to the logical rule structure, the conditional sentences are connected with bracket separators by a logical judgment symbol, namely, the conditional sentences are written in a format of a logical operator |object|relation operator|object', and the members refer to specific business characteristics such as amount, loan amount and the like and are roughly divided into five types of character type, numerical type, boolean type, date type and method type. After the condition statement is written, the subsequent action meeting the condition is continuously edited, and the subsequent action is usually composed of a plurality of execution statements. The execution method sentences are parallel relations, and the execution sentences in the embodiment of the invention mainly comprise two classes of assignment sentences and execution method sentences, and can be expanded according to actual application. The assignment statement is formed by an object assignment operator object, and for complex execution logic, the assignment statement can be packaged into an execution method in advance and imported into a system from the outside for rule editing and selection; the execution method statement is constructed in the form of "execution method { parameter.}".
In one embodiment, the predetermined encapsulation format includes JSON format (JavaScript Object Notation, a lightweight data exchange format). The JSON format includes a plurality of custom element structure classes and some Java common classes, and each element in the above logical rule structure corresponds to a custom JSON format. After the business rule is split and decomposed by utilizing the step S2, each element in the business rule corresponds to a custom JSON format, and each custom JSON format contains key attribute contents required in translation codes.
In one embodiment, when the decomposed business rules are packaged in the JSON format, the decomposed business rules are firstly translated and assembled into business rule combination objects in the JSON format one by one, then Java APIs are called, and the business rule combination objects in the JSON format are subjected to serialization processing to obtain serialized business rule combination objects, and at the moment, the business rule combination objects are converted into byte sequences.
In an embodiment, when the serialized business rule combination object is translated into the rule code, the serialized business rule combination object can be assembled one by one according to the DRL grammar requirement according to the mapping relation between the display field of each element and the actual meaning of the element, and the serialized business rule combination object is translated into the rule code conforming to the DRL grammar. In the implementation, a Java API is generally called, rule logic is deserialized into a JSON object, key information in the JSON object is extracted, and then the JSON object is spliced one by one according to the DRL grammar requirement, so that the JSON object is finally translated into logic codes which accord with the DRL grammar and can be identified by a rule engine.
In one embodiment, when verifying the validity of the rule code, the rule engine may be used to compile the translated rule code to verify the validity of the rule code. The Drools tool is an implementation of a RETE algorithm-based rule engine customized for Java, and is an open-source business rule engine which is easy to adjust and manage, meets the industry standard, and is high in speed and efficiency. After the rule code enters the Drools rule engine, the Drools rule engine performs validity check on the contents such as the format of the rule code, the referenced class, the called method, the setting of the configuration parameters and the like. After the validity check is passed, the business rule formally enters a life cycle management link, and is issued and validated in a pushing mode at a specified time through a preset flow and time. If the compiling is not passed, prompting an error, and after the adjustment and modification are carried out by service personnel, entering a compiling flow link until the compiling is passed successfully; after the code is compiled successfully, a logic rule model is formed.
Further, after the compiled rule code enters the rule engine, the rule engine builds a condition judgment network according to the hierarchical structure, the sequence, the context association and the condition judgment network of the conditional statement, and builds a judgment network taking the condition as a node in the memory. And when the verification is passed, releasing the business rule to enable the business rule to be effective, wherein the rule is to transmit the data object to be judged into a rule engine, the rule engine uses RETE algorithm to compare and judge the attribute of the transmitted data with the condition in the condition judgment network, judges whether the transmitted data object accords with the condition judgment logic, and executes the follow-up execution action defined by the rule.
Based on the same inventive concept as fig. 1, the embodiment of the present application also provides an inventive concept based on the same method as that of fig. 1 for generating a business rule based on natural language processing, and further provides a business rule generating system based on natural language processing, as described in the following embodiments. Because the principle of the system for solving the problem is similar to that of the business rule generation method based on natural language processing in fig. 1, the implementation of the system can refer to the implementation of the business rule generation method based on natural language processing in fig. 1, and the repetition is omitted.
In another embodiment, the application also provides a business rule generating system based on natural language processing, the structure of which is shown in fig. 2, and the system mainly comprises: business rule acquisition unit 10, business rule analysis unit 20, rule serialization unit 30, translation unit 40, and rule verification unit 50.
The business rule obtaining unit 10 is used for obtaining business rules written by a user in a natural language mode according to a preset logic rule structure; the business rule analysis unit 20 is configured to decompose the business rule according to a preset logic rule structure and extract a display field of each element in the business rule, so that each element in the business rule corresponds to a structure class in the logic rule structure; the rule serialization unit 30 is configured to encapsulate the decomposed service rule according to a preset encapsulation format, so as to obtain a serialized service rule combination object; the translation unit 40 is configured to translate the serialized business rule combination object into a rule code according to a predetermined mapping relationship between the display field of each element and the actual meaning of the corresponding element; the rule checking unit 50 is configured to perform validity check on the rule code, and issue the service rule after the verification passes.
The preset logic rule structure comprises a condition group and an execution group, wherein the condition group is used for describing a condition combination meeting the rule, and the execution group is used for describing an action to be executed after meeting the condition; the condition group comprises at least one condition sentence, and the condition sentence comprises a logic operation object, a logic operator, a relational operation object and a relational operator; the execution group comprises at least one execution statement, the execution statement comprises an assignment statement and/or an execution method statement, the assignment statement comprises an assignment object and an assignment operator, and/or an arithmetic operation object and an arithmetic operator, and the execution method statement comprises an execution method and parameters.
In an embodiment, the preset encapsulation format includes JSON format.
In one embodiment, the rule serialization unit 30 is shown in fig. 3, which mainly includes: a translation assembly module 31 and a serialization module 32. The translation assembly module 31 is configured to translate and assemble the decomposed business rules into a business rule combination object in JSON format one by one; the serialization module 32 is configured to call a Java API and serialize the service rule assembly object in JSON format.
In one embodiment, the translation unit 40 is specifically configured to: and according to the mapping relation between the display field of each element and the actual meaning of the corresponding element, splicing the serialized business rule combination objects one by one according to the DRL grammar requirement, and translating the serialized business rule combination objects into rule codes conforming to the DRL grammar.
In one embodiment, the rule checking unit 50 is specifically configured to: code compiling is carried out on the rule codes obtained through translation by utilizing a Drools rule engine so as to check the legality of the rule codes.
The business rule generating method and the system based on natural language processing provided by the embodiment of the invention can enable a rule writer to describe complex business rule characteristics and logic judgment descriptions in an expression form close to natural language, and have the characteristics of business independence, extensible combination, easiness in writing and the like. On one hand, the usability of rule development is improved, the probability of compiling errors is reduced, and the business rule generation efficiency is improved; on the other hand, the rule logic is converted from the traditional code structure into the structured canonical form for storage, the converted format can be conveniently and efficiently converted into the main stream rule engine recognizable development language, and the application range of the rule code is provided; in addition, the structural form translation makes the logic editing layer clearer, is convenient for reading and management, and also provides guarantee for the expansion of the future grammar form.
For a clearer description of the present invention, the technical solution of the present invention will be described with reference to specific embodiments.
In this embodiment, an editing interface is provided for user-oriented natural language customization rules, as shown in fig. 4. The rule editing interface is mainly divided into two large areas, namely a condition area and an execution area, wherein the condition area is used for describing the condition combination meeting the rule, and the execution area is used for editing things which need to be done after meeting the condition. The editing page provides encapsulated rule controls, which can include drop-down selection controls and gap-filling controls for users to customize business rules. The user logs in to a business logic customizing interface taking natural language as editing language, and edits and defines business logic conditions and follow-up actions in a condition area and an execution area in the editing interface according to a control provided by the system, so that the establishment of business rules is completed.
The condition zone: for describing the combination of conditions satisfying the rule, the execution area is used for editing things which need to be done after the conditions are satisfied. Further, the condition definition area can edit a plurality of condition sentences, the condition sentences are connected by a logic judgment symbol and a bracket separator, are written in a format of a logic operator |object|relation operator|object', and the members refer to specific business characteristics such as amount, loan amount and the like, and are roughly divided into five types of characters, numerical values, boolean types, date types and method types.
The execution area: the execution sentences are in parallel relation, the execution sentences can be divided into two types of assignment sentences and execution method sentences, the assignment sentences can be expanded according to actual application, the assignment sentences are formed in an 'object|assignment operator|object' mode, complex execution logic can be packaged into an execution method in advance, and the execution method is imported into a system from the outside for rule editing and selecting; the execution statement is constructed in the form of "execution method { parameter.}".
After the user completes rule logic editing, the system splits the customized business logic according to the customized logic rule structure. The custom logic rule structure is divided into a condition group and an execution group, namely < rule >: = "when" < condition group > "then" < action group >. Wherein the condition group comprises a plurality of < condition statement >, < condition statement > is further split according to logic judgment condition, namely < condition statement >: = < logical operator > < object > < relational operator > < object > < logical operator > -and "," or "," not ", and the like, wherein < object > is encapsulation of data, namely an entity formed by assembling a group of data and related operations of the group of data, so that the entity of < object > can be further divided into four types of < attribute > | < method > | < input > | < constant >, wherein < attribute > is a feature for describing the object, and is composed of < type > < data type > < English definition > < Chinese definition >; the term "method" is a concept in object-oriented programming, and is used to describe the encapsulation of the execution result generated after the operation acts on the object, and is composed of the term "method name" < english definition > < chinese definition > < parameter number > { < parameter > } < return value >; the < input > refers to a foreground input tag, consisting of < data type > < value >; < constant > refers to the constant amount in the rule logic definition, consisting of < data type > < name > < value >; the < relational operator > means ">", "<", "=", "> =", "<=", |! = "equal relation operation.
Wherein the action group includes a plurality of < execution statement >, < execution statement > is divided into < assignment statement > and < execution method statement > according to execution type. < assignment statement > for describing the processing procedure of the result of the operation of assigning one object to another object or combining several objects, the definition structure is as follows: < assignment statement > = < object > < assignment operator > < object > | { < arithmetic operator > < object > }, where < assignment operator > means arithmetic operations of "=", "+ =", "- =", < arithmetic operator > means "+", "-", "/", "%", etc. The definition structure of the execution method statement is that the definition structure is that the execution method statement is = < execution method name > < English definition > < Chinese definition > < parameter number > { < parameter > }.
Specifically, after the logic rule is split and decomposed, each element in the business rule corresponds to a custom JSON format, and each custom JSON format contains key attribute contents required in translation codes. And packaging the decomposed business rules, calling Java API after packaging, and serializing the JSON object into a byte sequence.
According to the definition of the logic rule structure, the invention defines a rule block (rule block) for describing a < rule > set, a condition block (conditional block) for describing a < condition statement > set, a condition block (multi-conditional block) for describing a condition statement set, a logic decision block (logicaljudblock) for describing a logic operator, a member block (membrane block) for describing a main body in a condition statement, a field block (field block) for defining an object field, an object block (ObjectBlock) for describing an object, a constant block (constant block) for defining a describing a constant, a method block (Functionblock) for defining a call method, a parameter block (ParaBlock) for defining a parameter, a judgment block set (Judblock) for describing a relation, an input value block (Inputblock) for describing a user-defined input value, an operation block (Oplubar) for describing a main body in a condition statement, an action block (block) for describing an action of an action, and a block for assigning an action (block) for describing a value of an action of a linkage statement, and a block for assigning a value to each other, and a block for performing a value-assigning function (block) for assigning a value-assigning function (block) for a value-assigning function-related function-block.
Taking a conditional statement as an example, a JSON structure conditional statement block (conditional block) of the conditional statement is defined as follows, wherein the JSON structure conditional statement block comprises LogicalJudgeBlock, objectBlock, judgeBlock three custom element structure classes, an integer attribute isTrue and a character attribute group, and description objects and detailed actions of the classes refer to table 1.
Table 1 part of the attributes and description thereof
Further, a business rule customized by a business person is used for explaining the encapsulation process of the business rule:
if it is
The transaction number of the transaction begins at "a001" or the transaction number ends at "Z",
and the message type of the transaction is equal to '1'
Then
Rejecting a transaction
Wherein, the transaction is a business category defined according to the actual business scene, the transaction number and the message type are the attributes of the business category, and the transaction numbers and the message types are specific values of the attributes. The specific value is set by the business personnel in the customization process, can be manually input, and can be selected according to a drop-down box list provided by the system.
This business rule can be divided into three < conditional statements > and one < execution statement > according to the defined logical rule structure. In order to conform to the expression habit of natural language, the editing page makes default setting when organizing rule text, and hides some characters when displaying, and supplements the rule logic description, namely the parts indicated by () in the following way. The method comprises the following steps:
Conditional statement 1 = (and) | (transacted) transaction number| starts with |a001'
Conditional statement 2: = or | (transactional) transaction number| ends with | "Z"
Conditional statement 3 =and | (transacted) message type | equals | "1"
Executing statement 1: = refusal transaction
Further, taking conditional statement 1 as an example, this conditional statement can be split into the following four elements:
element 1: logic predicate= "and"
Element 2: object a= "transaction number of transaction"
Element 3: relational operator= "start at"
Element 4: object b= "a001"
The display field and the actual meaning of each element are defined in advance in the custom JSON format of the element, wherein the display field is mainly used when a user edits rules in natural language, and the actual meaning is an actual value adopted when the element is translated and spliced into a rule code.
Taking the "and" element as an example, the JSON format design of this element is further described. "and" expresses logical and meaning in natural language, and the meaning in code logic recognizable by the rule engine is "&". Thus, the custom element structure class "LogicalJudbegeBlock" is used to define the element, and the converted code logic is "& &". Moreover, in order to conform to the expression habit of natural language, "and" this element needs to be displayed in a hidden manner in this sentence, "displayMode" is defined as 1, that is, the hidden manner is needed, and finally "and" the JSON format of this element is designed as:
"logicalJudgeBlock": { "displayMode":1, "cnName": and "," type ":0," name ":" & }
According to the principle, the JSON definition structure of each element is specially packaged so that the actual meaning of the element can be accurately obtained in the later period of code translation. Therefore, after the statement of the conditional statement 1 is encapsulated, the following JSON object is converted:
{
the "/" and "(& & gt) is a logical judgment symbol of the conditional statement, which indicates that the logical connection relationship between the conditional statement and other conditional statements is a logical AND relationship, and the logical judgment symbol of the first conditional statement is subjected to hidden display processing (display=1): and × & gt as the first conditional statement of the rule
"logicalJudgeBlock": { "displayMode":1, "cnName": "and", "type":0, "name": "-and" },
the trade number (SEQ) is an attribute (field) of the object "trade" (class = "MessageObject", ref = "$mo") whose value type is character type (dataType =1), the call is invoked by means of getString ("SEQ"), the statement of the class "trade" of this attribute is obtained by hiding the display process (displayMode =1) for the sake of simplicity of expression of natural language
"memberA": { "type":0, "field": { "value": "getString" (\"SEQ") "," dataType ":1," displayMode ":0," cnName ":" transaction number "," name ":" SEQ ",
"objectBlock": { "class": "MessageObject", "displayMode":0 "," ref ":" $mo "," cnName ":" transaction
","uniqueName":"MessageObject","displayMode":1}}},
The/'start from' is a character type (datatype=1) predicate, and the bottom implementation calling method is startsWith ()
"judgeBlock": { "dataType":1, "operartype": 4, "value": "startsWith", "displayName": "start from" },
the/'a 001' is a text value (datatype=1) of the input type (input)
"memberB":{"input":{"value":"A001","dataType":1},"type":2},
Execution of the conditional statement when the global logic is true
"isTrue":1,
The condition/is used to describe that condition 1 and condition 2 are combined sentence, and the condition group number is 0 + -
"group":0,
}
Thus, the task of converting and packaging the conditional statement 1 in the business rule into the JSON object is completed. The rest conditional sentences in the attendant rules can be translated sequentially one by one in the above manner, and finally assembled into a complete JSON format (rule block). Then, java API is called, and the complete JSON format business rule is serialized and then is processed later.
Before translation, the serialized business rules are usually required to be deserialized into JSON objects by using a Java deserialization API, key information in the JSON objects is extracted, and the JSON objects are spliced one by one according to the requirement of DRL grammar, so that the JSON objects are finally translated into logic codes which conform to the DRL grammar and can be identified by a rule engine. The grammar of the Rule code adopted in the embodiment is DRL grammar, and the DRL file grammar Rule is a grammar Rule applicable to a Drools Rule engine, and is mainly divided into a plurality of modules such as Package definition (Package), introduction class definition (report), rule definition (Rule) and the like, and the grammar Rule is very similar to Java language and can be well fused with the Java language.
Taking a conditional statement 1 as an example, according to a predetermined mapping relation between display fields of elements and actual meanings of corresponding elements, performing splicing translation on serialized business rules according to DRL grammar requirements, and obtaining the following results:
&&(eval($mo.getString("SEQ").startsWith("A001"))
a translation result of "& & &" yes "and"; "eval" is the translation result of "istrue=1" in JSON format; "$mo" is the setting of the reference name "ref" for "transaction"; ". getString (" SEQ ")" is a value setting for "transaction number", and is also a label for a method for evaluating transaction number; ". startsWith ()" is a setting for "start from" element "value"; "A001" is the input meaning of the input-type element directly acquired. The whole conversion process of the logic rule from the text conforming to the natural language to the serialized business rule and finally to the translated code is completed.
Finally, the translated logical rule codes are put into a rule engine for code compiling, the rule engine performs validity checking on the contents such as the format of the rule codes, the referenced class, the called method, the setting of configuration parameters and the like, so as to check the validity of the converted codes, if the compiling is not passed, an error is prompted, and otherwise, the rule compiling is prompted to be successful. To this end, the business rules are successfully converted from the original natural language text mode into rule engine logic codes which are compiled and completed and pass through the validity check.
In this embodiment, after the validity verification is completed on the business rule customized by natural language, the life cycle management can be performed on the business rule, and the business rule is issued in a push mode for a specified time to be effective through a preset flow and time.
After receiving the pushed business rule, the system responsible for executing the rule starts a rule engine running kernel deployed in the system, compiles and constructs an imported rule code, carries out condition judgment network construction on each condition in the code according to the hierarchical structure, the sequence and the context association of the conditional statement, establishes a rule base rule, waits for the input of data, and verifies whether the data can meet the logic in the rule condition.
The reasoning steps of the rule engine are mainly as follows: firstly, inputting data into a rule engine operation kernel; then, using RETE algorithm to compare rule condition in rule base in kernel with input data; if the execution rules have conflicts, namely a plurality of rules are activated simultaneously, putting the conflicting rules into a conflict set; after conflict is resolved, the activated rules are put into a cache in sequence; executing the rules in the memory queue until all the rules in the finish cache are executed. In this way, business rules customized in natural language are converted into valid rules.
It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The principles and embodiments of the present invention have been described in detail with reference to specific examples, which are provided to facilitate understanding of the method and core ideas of the present invention; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present invention, the present description should not be construed as limiting the present invention in view of the above.

Claims (10)

1. A business rule generation method based on natural language processing, the method comprising:
acquiring business rules written in a natural language mode by a user according to a preset logic rule structure;
decomposing the business rule according to a preset logic rule structure and extracting display fields of elements in the business rule, so that each element in the business rule corresponds to a structure class in the logic rule structure;
packaging the decomposed business rules according to a preset packaging format to obtain a serialized business rule combination object;
translating the serialized business rule combination object into a rule code according to a predetermined mapping relation between the display field of each element and the actual meaning of the corresponding element; the display field is used for displaying the natural language editing rule, and the actual meaning is the actual value adopted by the element when the element is translated and spliced into the rule code;
carrying out validity check on the rule codes, and releasing the business rules after the verification is passed;
the preset logic rule structure comprises a condition group and an execution group, wherein the condition group is used for describing a condition combination meeting the rule, and the execution group is used for describing an action to be executed after meeting the condition; the condition group comprises at least one condition sentence, and the condition sentence comprises a logic operation object, a logic operator, a relational operation object and a relational operator; the execution group comprises at least one execution statement, the execution statement comprises an assignment statement and/or an execution method statement, the assignment statement comprises an assignment object and an assignment operator, and/or an arithmetic operation object and an arithmetic operator, and the execution method statement comprises an execution method and parameters.
2. The business rule generation method based on natural language processing according to claim 1, wherein the preset encapsulation format comprises JSON format.
3. The method for generating business rules based on natural language processing according to claim 2, wherein the step of encapsulating the decomposed business rules according to a preset encapsulation format to obtain serialized business rule combination objects comprises the steps of:
translating and splicing the decomposed business rules one by one into a business rule combination object in a JSON format;
and calling a Java API, and carrying out serialization processing on the JSON-format business rule combination object to obtain the serialized business rule combination object.
4. The business rule generating method based on natural language processing according to claim 1, wherein translating the serialized business rule combination object into a rule code according to a predetermined mapping relationship between a presentation field of each element and an actual meaning of the corresponding element, comprises:
and according to the mapping relation between the display field of each element and the actual meaning of the corresponding element, splicing the serialized business rule combination objects one by one according to the DRL grammar requirement, and translating the serialized business rule combination objects into rule codes conforming to the DRL grammar.
5. The natural language processing based business rule generation method according to claim 1, wherein the rule code is legally verified, comprising: code compiling is carried out on the rule codes obtained through translation by utilizing a Drools rule engine so as to check the legality of the rule codes.
6. A business rule generation system based on natural language processing, the system comprising:
the business rule acquisition unit is used for acquiring business rules written in a natural language mode by a user according to a preset logic rule structure;
the business rule analysis unit is used for decomposing the business rule according to a preset logic rule structure and extracting the display field of each element in the business rule so that each element in the business rule corresponds to a structure class in the logic rule structure;
the rule serialization unit is used for packaging the decomposed business rules according to a preset packaging format to obtain a serialized business rule combination object;
the translation unit is used for translating the serialized business rule combination object into a rule code according to the mapping relation between the display field of each element and the actual meaning of the corresponding element; the display field is used for displaying the natural language editing rule, and the actual meaning is the actual value adopted by the element when the element is translated and spliced into the rule code;
The rule checking unit is used for carrying out validity check on the rule codes, and releasing the business rules after the rule codes pass the verification;
the preset logic rule structure comprises a condition group and an execution group, wherein the condition group is used for describing a condition combination meeting the rule, and the execution group is used for describing an action to be executed after meeting the condition; the condition group comprises at least one condition sentence, and the condition sentence comprises a logic operation object, a logic operator, a relational operation object and a relational operator; the execution group comprises at least one execution statement, the execution statement comprises an assignment statement and/or an execution method statement, the assignment statement comprises an assignment object and an assignment operator, and/or an arithmetic operation object and an arithmetic operator, and the execution method statement comprises an execution method and parameters.
7. The natural language processing based business rule generation system of claim 6, wherein the preset encapsulation format comprises JSON format.
8. The natural language processing based business rule generating system according to claim 7, wherein the rule serialization unit comprises:
the translation assembly module is used for translating and assembling the decomposed business rules one by one into a business rule combination object in a JSON format;
And the serialization module is used for calling Java API, and carrying out serialization processing on the JSON format business rule combination object to obtain the serialized business rule combination object.
9. The business rule generation system based on natural language processing of claim 6, wherein the translation unit is specifically configured to:
and according to the mapping relation between the display field of each element and the actual meaning of the corresponding element, splicing the serialized business rule combination objects one by one according to the DRL grammar requirement, and translating the serialized business rule combination objects into rule codes conforming to the DRL grammar.
10. The business rule generation system based on natural language processing of claim 6, wherein the rule checking unit is specifically configured to: code compiling is carried out on the rule codes obtained through translation by utilizing a Drools rule engine so as to check the legality of the rule codes.
CN201910417684.8A 2019-05-20 2019-05-20 Business rule generation method and system based on natural language processing Active CN110196719B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910417684.8A CN110196719B (en) 2019-05-20 2019-05-20 Business rule generation method and system based on natural language processing

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910417684.8A CN110196719B (en) 2019-05-20 2019-05-20 Business rule generation method and system based on natural language processing

Publications (2)

Publication Number Publication Date
CN110196719A CN110196719A (en) 2019-09-03
CN110196719B true CN110196719B (en) 2023-08-15

Family

ID=67752860

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910417684.8A Active CN110196719B (en) 2019-05-20 2019-05-20 Business rule generation method and system based on natural language processing

Country Status (1)

Country Link
CN (1) CN110196719B (en)

Families Citing this family (18)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110837362A (en) * 2019-11-01 2020-02-25 无锡数信互融科技发展有限公司 Method, system and editor for editing rule of guide type visual graphic modularization
CN110991191A (en) * 2019-12-05 2020-04-10 南京品微智能科技有限公司 Method for realizing flow self-definition based on natural semantic conversion
CN111427560B (en) * 2020-02-27 2022-05-20 平安医疗健康管理股份有限公司 Method and device for creating visualization of rule code and computer equipment
CN111414438B (en) * 2020-03-13 2023-06-02 上海银赛计算机科技有限公司 Real-time rule matching method and system based on mysql
CN111444727A (en) * 2020-04-01 2020-07-24 神州数码融信软件有限公司 Business rule analysis method
CN111443900B (en) * 2020-04-20 2021-05-25 广州城市信息研究所有限公司 City design management and control rule base construction method, rule base and rule base calling method
CN111652644A (en) * 2020-06-01 2020-09-11 湖南快乐阳光互动娱乐传媒有限公司 Advertisement strategy configuration method and system
CN111966342A (en) * 2020-08-10 2020-11-20 上海中通吉网络技术有限公司 Rule configuration and analysis method, system and equipment based on similar natural language
CN112101869B (en) * 2020-09-17 2024-04-16 深圳市丰巢网络技术有限公司 Express cabinet-based method and device for accessing pieces, server and storage medium
CN113516412A (en) * 2021-08-06 2021-10-19 上海中通吉网络技术有限公司 Business assessment method
CN113741873B (en) * 2021-09-03 2024-02-27 江苏维邦软件有限公司 SARP-based data processing rule compiling method and data processing method
CN113703740A (en) * 2021-09-17 2021-11-26 厦门中盾安信科技有限公司 Method and system for configuring and executing service request command based on service rule
CN115169295B (en) * 2022-04-07 2023-05-05 唐旸 Interface interaction method, device, system and medium based on model
US11954458B2 (en) * 2022-04-26 2024-04-09 Accenture Global Solutions Limited Decision logic translation system and method
CN115167826B (en) * 2022-05-27 2023-05-05 唐旸 Method and device for realizing Chinese business rule engine, server side and storage medium
CN115390821B (en) * 2022-08-08 2023-05-05 唐旸 Natural language code-free programming-oriented software application construction method
CN115438240A (en) * 2022-09-16 2022-12-06 中国建设银行股份有限公司 Data processing method and device, electronic equipment and storage medium
CN115599355B (en) * 2022-12-12 2023-03-14 卓望数码技术(深圳)有限公司 Object-oriented big data processing method

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103927174A (en) * 2014-04-17 2014-07-16 北京视博数字电视科技有限公司 Service processing method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP5777186B2 (en) * 2013-07-04 2015-09-09 ソフトバンク株式会社 Language conversion device, language conversion method, and language conversion program

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103927174A (en) * 2014-04-17 2014-07-16 北京视博数字电视科技有限公司 Service processing method and device

Also Published As

Publication number Publication date
CN110196719A (en) 2019-09-03

Similar Documents

Publication Publication Date Title
CN110196719B (en) Business rule generation method and system based on natural language processing
US10540436B2 (en) Evaluating rules applied to data
EP2530583B1 (en) Computer-implemented method, system and computer program product for displaying a user interface component
US20060161414A1 (en) Event-driven model generated from an ordered natural language interface
CN106648662B (en) Report generation device and method based on project cost calculation description language BCL
CN107851001B (en) Method for displaying computer applications of software-type application based on design specifications
JPS6375835A (en) Apparatus for generating intended code, program, list and design document
CN111104106A (en) Visual development method, system and medium for integrating business process and communication message
CN111581920A (en) Document conversion method, device, equipment and computer storage medium
Zhao et al. Pattern-based design evolution using graph transformation
CN113655996A (en) Enterprise-level system generation method based on demand model
Zhang et al. Automated Extraction of Grammar Optimization Rule Configurations for Metamodel-Grammar Co-evolution
CN116521155B (en) Method for dynamically generating Restful interface based on JSON description
Angelo et al. Rule-based Validation Module on EssenceBoard Method Editor
Tomić et al. An explanation facility framework for rule-based systems
CN115268907A (en) Method for generating software system control interaction logic by using json data
CN117591095A (en) Code generation method based on expression AST analysis and configurable template
Heckel et al. Advanced Modelling-Language Definition: Integrating Metamodelling with Graph Transformation
Liu et al. Context-Aware Automatic Code Segment Extraction and Refactoring in Object-Oriented Systems
CN113408597A (en) Java method name recommendation method based on two-stage framework
CN116700732A (en) Method, system, equipment and medium for realizing business rule engine
CN117667089A (en) Front-end form generation method and device, storage medium and electronic equipment
CN113971028A (en) Data processing method, device, equipment, storage medium and computer program product
CN117850752A (en) Method and system for constructing low-code platform through domain model instantiation generator
CN116339819A (en) VUE file analysis method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant