Atomic rule logic expression visualization method and device
By constructing a parser for atomic rule logical expressions and generating standard data for logic diagrams, the problem of visualization of complex atomic rule logical expressions is solved, and the checksum configuration efficiency of logical relationships is improved.
Patent Information
- Application Number
- CN202411533617.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-02-18
AI Technical Summary
The prior art is difficult to effectively visualize complex atomic rule logical expressions, resulting in inefficient logical relationship checksum configuration.
By creating grammatical rule files, generating lexical analysis interfaces and grammatical parsing interfaces, building a parser for atomic rule logical expressions, parsing target logical relation expressions to obtain standard data of the logic diagram, and rendering the page to show the logic and operational relationships and logic or operational relationship.
It realizes accurate analysis and visualization of logical expressions of complex atomic rules, improves the checksum configuration efficiency of logical relationships, and ensures the correctness of logical relationships.
Smart Images

Figure CN119473303A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to the field of computer technology, and in particular to a method and device for visualizing atomic rule logic expressions. Background Art
[0002] Among the many decision components of the decision engine (a platform for configuring policies and rules, supporting visual configuration of various common policies and policy customization), there is a rule component, the wizard rule component, which is often used in credit policies or anti-fraud policies. The final execution result of this component is a Boolean type, that is, the output result of the configured logic is only True or False. The wizard rule component can configure simple rules or complex rules. Simple rules can be considered to be composed of only one or several simple logical operators, such as: 1&&2, 3||4; complex rules refer to not only a few simple logical operators but also multiple layers of nested combinations such as brackets, such as: (1||2)&&(4||3)&&(5&&(6||7)), where 1, 2, 3, 4, 5, 6, 7, etc. represent atomic rule numbers, which are used to represent atomic rule logic. For example, the logic of atomic rule No. 1 is: amount>=5000 (if the amount is greater than or equal to 5000, the result is True), and the logic of atomic rule No. 2 is: city="Beijing" (if the city is Beijing, the result is True).
[0003] The configuration steps of a complete rule are to first configure the atomic rules, then configure the logical relationship of the atomic rules, and finally visualize the configured logical relationship (visualization is the process of converting the atomic rule logical expression into a logical diagram). The purpose of visualization is, on the one hand, to verify the logical relationship of complex atomic rules, including whether the atomic rule number exists and the syntax of the expression, to ensure the correctness of the logical relationship; on the other hand, the configuration personnel can directly know the logical relationship of the atomic rules through the logical diagram, which is convenient for configuration and error detection, and improves efficiency. Summary of the invention
[0004] The embodiments of the present disclosure provide a method and device for visualizing atomic rule logic expressions.
[0005] In a first aspect, an embodiment of the present disclosure provides a method for visualizing an atomic rule logic expression, comprising: creating a grammar rule file according to a standard data structure of a predefined logic diagram, wherein the grammar rule file defines a grammar for parsing the atomic rule logic expression. A lexical analysis interface and a grammatical parsing interface are generated according to the grammar rule file. According to a target logical relationship expression, a parser for the atomic rule logic expression is created based on the lexical analysis interface and the grammatical parsing interface. The target logical relationship expression is parsed by the parser to obtain standard data of the logic diagram.
[0006] In some embodiments, before the target logical relationship expression is parsed by the parser, the method further comprises: creating a checker for syntax checking and atomic rule number checking based on the parser. In response to the checker failing to check the target logical relationship expression, the parser is modified.
[0007] In some embodiments, the method further includes: rendering a page according to the standard data of the parsed logic diagram, and displaying the logical AND operation relationship and the logical OR operation relationship in the target logical relationship expression in series and parallel respectively.
[0008] In some embodiments, the standard data structure includes a logic type, a logic node set, and a value of an atomic rule number, wherein the logic type includes: an atomic rule number, a logical AND, and a logical OR.
[0009] In some embodiments, generating a lexical analysis interface and a grammar parsing interface according to a grammar rule file includes: converting the grammar rule file into a grammar tree by a grammar analyzer generation tool, and traversing the grammar tree to generate the lexical analysis interface and the grammar parsing interface.
[0010] In some embodiments, a parser for creating an atomic rule logic expression based on a lexical analysis interface and a grammatical parsing interface according to a target logical relationship expression includes: creating a character stream according to the target logical relationship expression and constructing a lexical analyzer. Creating an instruction stream according to the target logical relationship expression and constructing a grammatical parser. Creating a script grammatical error parsing listener and a script grammatical error analyzer, and adding them to the grammatical parsing interface and the lexical analysis interface respectively. A parser for generating an atomic rule logic expression based on a lexical analyzer, a grammatical parser, a grammatical parsing interface and a lexical analysis interface.
[0011] In some embodiments, the target logical relationship expression is parsed by a parser to obtain standard data of the logic diagram, including: defining a stack object of a logic node to store the standard data of the logic diagram, and storing each type of logical relationship data in the target logical relationship expression in a logical node. Loading the logical relationship data in the logical node into the stack object. Obtaining the top value of the stack object as the standard data of the logic diagram.
[0012] In some embodiments, loading the logical relationship data in the logical node into the stack object includes: in response to the left and right sides of the logical AND operator being both logical AND operations, loading all the logical nodes on the left and right sides into the stack object. In response to the left and right sides of the logical AND operator being logical OR operations and logical AND operations respectively, loading all the logical nodes on the right side and the last loaded logical nodes on the left side into the stack object. In response to the left side of the logical AND operator being an atomic rule number and the right side being a logical AND operation, loading all the logical nodes on the right side into the stack object. In response to the left and right sides of the logical AND operator being other situations, loading the last loaded logical nodes on the left and right sides into the stack object.
[0013] In some embodiments, loading the logical relationship data in the logical node into the stack object includes: in response to the left and right sides of the logical OR operator being both logical OR operations, loading all the logical nodes on the left and right sides into the stack object. In response to the left and right sides of the logical OR operator being logical AND operations and logical OR operations respectively, loading all the logical nodes on the right side and the last loaded logical nodes on the left side into the stack object. In response to the left side of the logical OR operator being an atomic rule number and the right side being a logical OR operation, loading all the logical nodes on the right side into the stack object. In response to the left and right sides of the logical OR operator being other situations, loading the last loaded logical nodes on the left and right sides into the stack object.
[0014] In a second aspect, an embodiment of the present disclosure provides an atomic rule logic expression visualization device, including: a file creation unit, configured to create a grammar rule file according to a predefined standard data structure of a logic diagram, wherein the grammar rule file defines a grammar for parsing the atomic rule logic expression. A generation unit, configured to generate a lexical analysis interface and a grammar parsing interface according to the grammar rule file. An interface creation unit, configured to create a parser for the atomic rule logic expression based on the lexical analysis interface and the grammar parsing interface according to a target logical relationship expression. A parsing unit, configured to parse the target logical relationship expression through a parser to obtain standard data of the logic diagram.
[0015] In some embodiments, the device further comprises a checking unit configured to: before the target logical relationship expression is parsed by the parser, create a checker for syntax checking and atomic rule number checking based on the parser. In response to the checker failing to check the target logical relationship expression, the parser is corrected.
[0016] In some embodiments, the device also includes a rendering unit configured to: render a page based on the standard data of the parsed logic diagram, and display the logical AND operation relationship and the logical OR operation relationship in the target logical relationship expression in series and parallel respectively.
[0017] In some embodiments, the standard data structure includes a logic type, a logic node set, and a value of an atomic rule number, wherein the logic type includes: an atomic rule number, a logical AND, and a logical OR.
[0018] In some embodiments, the generating unit is configured to: convert the grammar rule file into a grammar tree through a grammar analyzer generating tool, and traverse the grammar tree to generate a lexical analysis interface and a grammar parsing interface.
[0019] In some embodiments, the interface creation unit is further configured to: create a character stream according to the target logical relationship expression and construct a lexical analyzer. Create an instruction stream according to the target logical relationship expression and construct a grammar parser. Create a script grammar error parsing listener and a script grammar error analyzer, and add them to the grammar parsing interface and the lexical analysis interface respectively. Generate a parser for the atomic rule logic expression based on the lexical analyzer, the grammar parser, the grammar parsing interface and the lexical analysis interface.
[0020] In some embodiments, the parsing unit is further configured to: define a stack object of a logic node to store standard data of the logic diagram, and store each type of logic relationship data in the target logic relationship expression in a logic node. Load the logic relationship data in the logic node into the stack object. Obtain the top value of the stack object as the standard data of the logic diagram.
[0021] In some embodiments, the parsing unit is further configured to: in response to the left and right sides of the logical AND operator being both logical AND operations, all logical nodes on the left and right sides are loaded into the stack object. In response to the left and right sides of the logical AND operator being logical OR operations and logical AND operations respectively, all logical nodes on the right side and the last loaded logical nodes on the left side are loaded into the stack object. In response to the left side of the logical AND operator being an atomic rule number and the right side being a logical AND operation, all logical nodes on the right side are loaded into the stack object. In response to the left and right sides of the logical AND operator being other situations, the last loaded logical nodes on the left and right sides are loaded into the stack object.
[0022] In some embodiments, the parsing unit is further configured to: in response to the left and right sides of the logical OR operator being both logical OR operations, all logical nodes on the left and right sides are loaded into the stack object. In response to the left and right sides of the logical OR operator being logical AND operations and logical OR operations respectively, all logical nodes on the right side and the last loaded logical nodes on the left side are loaded into the stack object. In response to the left side of the logical OR operator being an atomic rule number and the right side being a logical OR operation, all logical nodes on the right side are loaded into the stack object. In response to the left and right sides of the logical OR operator being other situations, the last loaded logical nodes on the left and right sides are loaded into the stack object.
[0023] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising: one or more processors; a storage device having one or more computer programs stored thereon, wherein when the one or more computer programs are executed by the one or more processors, the one or more processors implement the method described in any one of the first aspects.
[0024] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method as described in any one of the first aspects.
[0025] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, which implements the method as described in any one of the first aspect or the second aspect when executed by a processor.
[0026] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Other features, objects and advantages of the present disclosure will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0028] Figure 1 is an exemplary system architecture diagram in which an embodiment of the present disclosure may be applied;
[0029] Figure 2 is a flowchart of an embodiment of a method for visualizing atomic rule logic expressions according to the present disclosure;
[0030] Figure 3 is a schematic diagram of an application scenario of the atomic rule logic expression visualization method according to the present disclosure;
[0031] Figure 4 is a flowchart of another embodiment of the atomic rule logic expression visualization method according to the present disclosure;
[0032] Figure 5 is a structural schematic diagram of an embodiment of an atomic rule logic expression visualization device according to the present disclosure;
[0033] Figure 6 It is a structural diagram of a computer system of an electronic device suitable for implementing an embodiment of the present disclosure. DETAILED DESCRIPTION
[0034] The present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.
[0035] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0036] Figure 1 An exemplary system architecture 100 is shown to which an embodiment of the atomic rule logic expression visualization method or atomic rule logic expression visualization device of the present disclosure can be applied.
[0037] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0038] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as banking applications, 3D video players, web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0039] Terminal devices 101, 102, 103 can be hardware or software. When terminal devices 101, 102, 103 are hardware, they can be various electronic devices with display screens and supporting image display, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, Moving Picture Experts Group Audio Layer 3), MP4 (Moving Picture Experts Group Audio Layer IV, Moving Picture Experts Group Audio Layer 4) players, laptop computers and desktop computers, etc. When terminal devices 101, 102, 103 are software, they can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules (for example, to provide distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0040] The server 105 may be a server that provides various services, such as a logical relationship expression parsing server that supports the logical diagram of the logical relationship expression displayed on the terminal devices 101, 102, and 103. The logical relationship expression parsing server may generate standard data of the logical diagram according to the logical relationship expression, render the standard data of the logical diagram to generate a logical diagram, and feed the logical diagram back to the terminal device for display.
[0041] It should be noted that the server can be hardware or software. When the server is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or it can be implemented as a single server. When the server is software, it can be implemented as multiple software or software modules (for example, multiple software or software modules used to provide distributed services), or it can be implemented as a single software or software module. No specific limitation is made here. The server can also be a server of a distributed system, or a server combined with a blockchain. The server can also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.
[0042] It should be noted that the atomic rule logic expression visualization method provided in the embodiments of the present disclosure is generally executed by the server 105 , and accordingly, the atomic rule logic expression visualization device is generally arranged in the server 105 .
[0043] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0044] Continue to refer Figure 2 , shows a process 200 of an embodiment of a method for visualizing an atomic rule logic expression according to the present disclosure. The method for visualizing an atomic rule logic expression comprises the following steps:
[0045] Step 201: Create a grammar rule file according to a predefined standard data structure of a logic diagram.
[0046] In this embodiment, the execution body of the atomic rule logic expression visualization method (for example Figure 1The server shown in the figure can obtain the standard data structure of the predefined logic diagram (which can be in JSON format or other formats) through a wired connection or a wireless connection. Among them, the standard data structure may include a logic type (exprType), a logic node set (logicNodes) and a value (value) of an atomic rule number, where exprType is an enumeration value including AND (logical AND), OR (logical OR), and ID (atomic rule number); logicNodes is a logic node set for storing simple logic and nested logic relationship data.
[0047] Then create a grammar rule file based on the standard data structure of the pre-defined logic diagram. The grammar rule file defines the grammar for parsing atomic rule logical expressions. Based on the antlr4 framework, you can create a file with the g4 suffix and define the grammar for parsing atomic rule logical expressions, mainly parsing three logical relationships: 1) brackets; 2) logical and &&; 3) logical or ||. antlr4 is a powerful grammar analyzer generator tool that can generate corresponding grammar analyzers based on grammar rule files. It is widely used in DSL construction, language lexical grammar parsing and other fields.
[0048] Step 202: Generate a lexical analysis interface and a grammar parsing interface according to the grammar rule file.
[0049] In this embodiment, a lexical analysis interface AtomRuleLogicConfigLexer and a grammatical parsing interface AtomRuleLogicConfigParser based on the listener and observer modes are generated according to the g4 file described above as the entry for lexical analysis and grammatical parsing, as well as an interface AtomRuleLogicConfigBaseListener of the atomic rule configuration base listener. The interface mainly includes methods such as exitIdentifier, exitAndEpr, and enterOrEpr, which are used to customize the parsing method for processing the left and right relationships of atomic rule numbers, logical AND, and logical OR.
[0050] Step 203: Create a parser for the atomic rule logic expression based on the target logic relationship expression and the lexical analysis interface and the syntax parsing interface.
[0051] In this embodiment, a parser for the atomic rule logic expression is created based on the input logical relationship expression. A lexical analyzer and a grammatical parser can be constructed based on the written lexical analysis code and grammatical analysis, and added to the grammatical analysis interface AtomRuleLogicConfigParser and the lexical analysis interface AtomRuleLogicConfigLexer respectively. A script grammatical error parsing listener and a script grammatical error analyzer can be constructed based on the written error checking code.
[0052] Step 204, parse the target logical relationship expression through a parser to obtain standard data of the logic diagram.
[0053] In this embodiment, the parser can perform lexical analysis and grammatical parsing according to a predetermined standard data structure of the logic diagram, parse the target logical relationship expression, and obtain standard data of the logic diagram.
[0054] The following data example is the standard data of the logic diagram parsed according to the atomic rule logic expression (1||2&&(4||3)&&(5||6||7&&(8||9)))||(10&&11)||(12&&13)||((14||15)&&(16||17))||18||(19&&20).
[0055]
[0056]
[0057]
[0058]
[0059]
[0060] The method provided by the above-mentioned embodiment of the present disclosure can accurately parse the complex logical relationship expression configured by the wizard rule component in the decision engine into a standardized data structure of a logic diagram.
[0061] In some optional implementations of this embodiment, the method further includes: rendering a page based on standard data of the parsed logic diagram, and displaying the logical AND operation relationship and the logical OR operation relationship in the target logical relationship expression in series and parallel respectively.
[0062] Render the page according to the standard data of the logic diagram. First, analyze the corresponding data structure, judge the logical expression composed of the variables, generate true or false output, define a component called Flex-box, pass the data into it, because there are two forms of serial and parallel, so different containers and styles are set through and and or states to distinguish. Secondly, set a big-box container, and then distinguish by node type, set different class names for different types of nodes. If the node type is "or", the class name is 'or-box', otherwise it is 'and-box'. Then set different styles for the left and right borders of different containers by node type. If it is or-box, set the left and right edges for it through absolute positioning. If it is and-box, set the display form of the flex-box node inside by setting whether the node type is flex layout. Finally, render a flex-box as a node unit. Serial data is displayed serially through flex layout. If it is parallel data, it is displayed in the form of up and down tiles, and connected through the specified container. For nested multi-layer data, loop components in a recursive form. Figure 3 This is a logic diagram rendered using the standard data of the above logic diagram.
[0063] In some optional implementations of the present embodiment, a lexical analysis interface and a grammatical parsing interface are generated according to a grammar rule file, including: converting the grammar rule file into a grammar tree through a grammar analyzer generation tool; traversing the grammar tree to generate a lexical analysis interface and a grammatical parsing interface. For example, the grammar rule file is converted into a grammar tree through ANTLR4 (ANother Tool for Language Recognition). The grammar file (with a .g4 suffix) defines the rules of a specific language structure, including lexical rules and grammatical rules. Lexical rules define the lexical elements (Tokens) in a language, while grammatical rules define the structure and grammar of a language.
[0064] Here are some key concepts of ANTLR4 grammars:
[0065] Grammar File: defines the rules of a specific language structure.
[0066] Parser: generated according to the grammar file, used to parse the text and build a parse tree.
[0067] Lexical analyzer (Lexer): Breaks the input text into meaningful symbols (Tokens).
[0068] Parse Tree: represents the grammatical structure of the input text.
[0069] ANTLR4 supports commonly used language features such as recursive descent, syntax trees, and semantic actions. It can generate efficient parsers and lexical analyzers in a variety of programming languages, including Java, C#, JavaScript, etc.
[0070] Using the ANTLR4 tool, a lexical analyzer and a parser can be generated based on this grammar file, and then these tools can be used to parse and verify text that conforms to this grammar, such as expressions such as "3&&4" or "5||2".
[0071] The advantages of ANTLR4 are its powerful syntax analysis capabilities and support for multiple programming languages, as well as the efficient performance and powerful error handling capabilities of the generated parser. This makes it very suitable for handling complex language processing tasks.
[0072] In some optional implementations of the present embodiment, a parser for an atomic rule logical expression is created according to a target logical relationship expression based on a lexical analysis interface and a syntax parsing interface, including: creating a character stream according to the target logical relationship expression and constructing a lexical analyzer; creating an instruction stream according to the target logical relationship expression and constructing a syntax parser; creating a script syntax error parsing listener and a script syntax error analyzer, and adding them to the syntax parsing interface and the lexical analysis interface respectively; and generating a parser for an atomic rule logical expression based on a lexical analyzer, a syntax parser, a syntax parsing interface and a lexical analysis interface.
[0073] First, create a character stream CharStream to construct the lexical analyzer AtomRuleLogicConfigLexer, and create an instruction stream CommonTokenStream (for example, brackets, operators) to construct the syntax parser AtomRuleLogicConfigParser. The instruction stream refers to the sequence of instructions executed by the machine (for example, instructions corresponding to logical operators), and the data stream refers to the sequence of data called by the instruction stream, including input data and intermediate results (for example, atomic rule numbers). The lexical analyzer and syntax parser can be constructed based on the written lexical analysis code and syntax parsing code.
[0074] Create a script syntax error parsing listener ScriptParseErrorListener and a script syntax error analyzer ScriptLexerErrorListener and add them to the syntax parsing interface AtomRuleLogicConfigParser and the lexical analysis interface AtomRuleLogicConfigLexer respectively. The script syntax error parsing listener and the script syntax error analyzer can be constructed based on the written error checking code.
[0075] In some optional implementations of this embodiment, the target logical relationship expression is parsed by a parser to obtain standard data of the logic diagram, including: defining a stack object of a logical node to store standard data of the logic diagram, and storing each type of logical relationship data in the target logical relationship expression in a logical node; loading the logical relationship data in the logical node into the stack object; obtaining the top value of the stack object as the standard data of the logic diagram. A stack object stacks with a generic type of LogicNode is defined to store logic diagram JSON data. For the method of processing atomic rule numbers, because it is an atomic rule number rather than a logical operator, logicNodes is empty. Based on the type on the left side of the expression, data is loaded according to the type on the right side of the expression.
[0076] For the method of processing logical AND, the type on the left side of the expression is used as the basis, and data is loaded according to the type on the right side of the expression. If both the left and right sides are logical AND operations, the LogicNode loads all the logicNodes on the left and right sides; if the left and right sides are logical OR operations and logical AND operations respectively, all the logicNodes on the right side and the original node LogicNode on the left side (the content loaded last time in the stack object) are loaded; if the left side is an atomic rule number and the right side is a logical AND operation, all the logicNodes are loaded, otherwise the original node LogicNode is loaded.
[0077] In some optional implementations of the present embodiment, the logical relationship data in the logical node is loaded into the stack object, including: in response to the left and right sides of the logical AND operator being both logical AND operations, all the logical nodes on the left and right sides are loaded into the stack object; in response to the left and right sides of the logical AND operator being logical OR operations and logical AND operations respectively, all the logical nodes on the right side and the last loaded logical nodes on the left side are loaded into the stack object; in response to the left side of the logical AND operator being an atomic rule number and the right side being a logical AND operation, all the logical nodes on the right side are loaded into the stack object; in response to the left and right sides of the logical AND operator being other situations, the last loaded logical nodes on the left and right sides are loaded into the stack object.
[0078] For the method of processing logical OR, the type on the left side of the expression is also used as the basis, and data is loaded according to the type on the right side of the expression. If both the left and right sides are logical OR operations, the LogicNode is loaded with all the logicNodes on the left and right sides; if the left and right sides are logical AND operations and logical OR operations respectively, the original node LogicNode on the left and all the logicNodes on the right are loaded; if the left side is an atomic rule number and the right side is a logical OR operation, all logicNodes are loaded, otherwise the original node LogicNode is loaded.
[0079] Further references Figure 4 , which shows a process 400 of another embodiment of a method for visualizing an atomic rule logic expression. The process 400 of the method for visualizing an atomic rule logic expression includes the following steps:
[0080] Step 401: Create a grammar rule file according to a predefined standard data structure of a logic diagram.
[0081] Step 402: Generate a lexical analysis interface and a grammar parsing interface according to the grammar rule file.
[0082] Step 403: Create a parser for the atomic rule logic expression based on the target logic relationship expression and the lexical analysis interface and the syntax parsing interface.
[0083] Steps 401-403 are substantially the same as steps 201-203, and thus are not described in detail herein.
[0084] Step 404: Create a checker for syntax checking and atomic rule number checking based on the parser.
[0085] In this embodiment, syntax checking refers to checking whether there are syntax errors in the expression, for example, whether there are missing brackets, whether there are symbols that are neither logical AND nor logical OR. Atomic rule number checking refers to checking whether the atomic rule number in the expression exists in all defined atomic rule numbers.
[0086] Step 405, in response to the failure of the verification of the target logical relationship expression by the verifier, the parser is corrected.
[0087] In this embodiment, if the logic relationship expression is non-empty and the atomic rule number in the atomic rule logic expression does not exist in all defined atomic rule numbers, an exception will be thrown upward. If the check fails, it means that the parser cannot parse the expression correctly, and the parser needs to be modified again until the check passes.
[0088] Step 406, parse the target logical relationship expression through a parser to obtain standard data of the logic diagram.
[0089] Step 406 is substantially the same as step 204 and thus will not be described in detail.
[0090] The embodiment of the present application verifies whether the generated parser is correct by performing syntax verification and atomic rule number verification, so as to avoid using an incorrect parser to obtain an incorrect parsing result.
[0091] Further references Figure 5As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of an atomic rule logic expression visualization device. Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0092] like Figure 5 As shown, the atomic rule logic expression visualization device 500 of this embodiment includes: a file creation unit 501, a generation unit 502, an interface creation unit 503 and a parsing unit 504. Among them, the file creation unit 501 is configured to create a grammar rule file according to a pre-defined standard data structure of a logic diagram, wherein the grammar for parsing the atomic rule logic expression is defined in the grammar rule file. The generation unit 502 is configured to generate a lexical analysis interface and a grammatical parsing interface according to the grammar rule file. The interface creation unit 503 is configured to create a parser for the atomic rule logic expression based on the lexical analysis interface and the grammatical parsing interface according to the target logical relationship expression. The parsing unit 504 is configured to parse the target logical relationship expression through the parser to obtain the standard data of the logic diagram.
[0093] In this embodiment, the specific processing of the file creation unit 501, the generation unit 502, the interface creation unit 503 and the parsing unit 504 of the atomic rule logic expression visualization device 500 can be referred to. Figure 2 Corresponding to step 201, step 202, step 203, and step 204 in the embodiment.
[0094] In some optional implementations of this embodiment, the device 500 further includes a verification unit (not shown in the drawings), which is configured to: before the target logical relationship expression is parsed by the parser, create a verifier for syntax verification and atomic rule number verification based on the parser. In response to the verification of the target logical relationship expression by the verifier failing, the parser is corrected.
[0095] In some optional implementations of this embodiment, the device 500 also includes a rendering unit (not shown in the drawings), which is configured to: render a page based on the standard data of the parsed logic diagram, and display the logical AND operation relationship and the logical OR operation relationship in the target logical relationship expression in series and parallel respectively.
[0096] In some optional implementations of this embodiment, the standard data structure includes a logic type, a logic node set, and a value of an atomic rule number, wherein the logic type includes: an atomic rule number, a logical AND, and a logical OR.
[0097] In some optional implementations of this embodiment, the generating unit 502 is further configured to: convert the grammar rule file into a grammar tree through a grammar analyzer generating tool, and traverse the grammar tree to generate a lexical analysis interface and a grammar parsing interface.
[0098] In some optional implementations of this embodiment, the interface creation unit 503 is further configured to: create a character stream according to the target logical relationship expression and construct a lexical analyzer. Create an instruction stream according to the target logical relationship expression and construct a syntax parser. Create a script syntax error parsing listener and a script syntax error parser, and add them to the syntax parsing interface and the lexical analysis interface respectively. Generate a parser for the atomic rule logic expression based on the lexical analyzer, the syntax parser, the syntax parsing interface and the lexical analysis interface.
[0099] In some optional implementations of this embodiment, the parsing unit 504 is further configured to: define a stack object of a logic node to store standard data of a logic diagram, and store each type of logic relationship data in a target logic relationship expression in a logic node. Load the logic relationship data in the logic node into the stack object. Obtain the top value of the stack object as the standard data of the logic diagram.
[0100] In some optional implementations of this embodiment, the parsing unit 504 is further configured to: in response to the left and right sides of the logical AND operator being both logical AND operations, all the logical nodes on the left and right sides are loaded into the stack object. In response to the left and right sides of the logical AND operator being logical OR operations and logical AND operations respectively, all the logical nodes on the right side and the last loaded logical nodes on the left side are loaded into the stack object. In response to the left side of the logical AND operator being an atomic rule number and the right side being a logical AND operation, all the logical nodes on the right side are loaded into the stack object. In response to the left and right sides of the logical AND operator being other situations, the last loaded logical nodes on the left and right sides are loaded into the stack object.
[0101] In some optional implementations of this embodiment, the parsing unit 504 is further configured to: in response to the left and right sides of the logical OR operator being both logical OR operations, all the logical nodes on the left and right sides are loaded into the stack object. In response to the left and right sides of the logical OR operator being logical AND operations and logical OR operations respectively, all the logical nodes on the right side and the logical nodes on the left side loaded last are loaded into the stack object. In response to the left side of the logical OR operator being an atomic rule number and the right side being a logical OR operation, all the logical nodes on the right side are loaded into the stack object. In response to the left and right sides of the logical OR operator being other situations, the logical nodes on the left and right sides loaded last are loaded into the stack object.
[0102] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution of this disclosure are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information, network security and national security.
[0103] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.
[0104] An electronic device comprises: one or more processors; a storage device on which one or more computer programs are stored, and when the one or more computer programs are executed by the one or more processors, the one or more processors implement the method described in process 200 or 400.
[0105] A computer-readable medium stores a computer program, wherein the computer program implements the method described in process 200 or 400 when executed by a processor.
[0106] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0107] like Figure 6 As shown, the device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0108] A number of components in the device 600 are connected to the I / O interface 605, including: an input unit 606, such as a keyboard, a mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0109] The computing unit 601 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 601 performs the various methods and processes described above, such as the road area planning method. For example, in some embodiments, the road area planning method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the computing unit 601, one or more steps of the road area planning method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the road area planning method in any other appropriate manner (e.g., by means of firmware).
[0110] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0111] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0112] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0113] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0114] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0115] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the respective computers and having a client-server relationship with each other. The server may be a server of a distributed system, or a server combined with a blockchain. The server may also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology. The server may be a server of a distributed system, or a server combined with a blockchain. The server may also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.
[0116] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0117] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for visualizing atomic rule logic expressions, comprising: Creating a grammar rule file according to a standard data structure of a predefined logic graph, wherein the grammar rule file defines a grammar for parsing an atomic rule logic expression; Generate a lexical analysis interface and a grammar parsing interface according to the grammar rule file; According to the target logical relationship expression, a parser for creating an atomic rule logic expression based on the lexical analysis interface and the grammar parsing interface; The target logical relationship expression is parsed by the parser to obtain standard data of the logic diagram.
2. The method according to claim 1, wherein: Before parsing the target logical relationship expression by the parser, the method further includes: Creating a checker for syntax checking and atomic rule number checking based on the parser; In response to failure of verification of the target logical relationship expression by the verifier, the parser is modified.
3. The method according to claim 1, wherein: The method further comprises: The page is rendered according to the standard data of the parsed logic diagram, and the logical AND operation relationship and the logical OR operation relationship in the target logic relationship expression are respectively displayed in series and parallel.
4. The method according to claim 1, wherein: The standard data structure includes a logic type, a logic node set and a value of an atomic rule number, wherein the logic type includes: an atomic rule number, a logical AND, and a logical OR.
5. The method according to claim 1, wherein: The generating of the lexical analysis interface and the grammar parsing interface according to the grammar rule file comprises: Converting the grammar rule file into a grammar tree by a grammar analyzer generation tool; The syntax tree is traversed to generate a lexical analysis interface and a syntax parsing interface.
6. The method according to claim 1, wherein: The parser for creating an atomic rule logic expression based on the lexical analysis interface and the grammar parsing interface according to the target logical relationship expression includes: Create a character stream based on the target logical relationship expression and construct a lexical analyzer; Create an instruction stream based on the target logical relationship expression and construct a syntax parser; Create a script syntax error parsing listener and a script syntax error analyzer, and add them to the syntax parsing interface and the lexical analysis interface respectively; A parser for generating atomic rule logic expressions based on the lexical analyzer, the syntax parser, the syntax parsing interface and the lexical analysis interface.
7. The method according to claim 4, wherein: The step of parsing the target logical relationship expression by the parser to obtain standard data of the logic diagram includes: A stack object of a logic node is defined to store standard data of a logic diagram, and each type of logic relationship data in the target logic relationship expression is stored in a logic node; Loading the logical relationship data in the logical node into the stack object; The top value of the stack object is obtained as standard data of the logic diagram.
8. The method according to claim 1, wherein: The step of loading the logical relationship data in the logical node into the stack object comprises: In response to the left and right sides of the logical AND operator being both logical AND operations, loading all the logical nodes on the left and right sides into the stack object; In response to the logical OR operation and the logical AND operation being performed on the left and right sides of the logical AND operator respectively, all the logical nodes on the right side and the last loaded logical node on the left side are loaded into the stack object; In response to the left side of the logical AND operator being the atomic rule number and the right side being the logical AND operation, all the logical nodes on the right side are loaded into the stack object; In response to the left and right sides of the logical AND operator being other cases, the logical nodes of the left and right sides loaded last time are loaded into the stack object.
9. The method according to claim 1, wherein: The step of loading the logical relationship data in the logical node into the stack object comprises: In response to the left and right sides of the logical OR operator being both logical OR operations, loading all the logical nodes on the left and right sides into the stack object; In response to the logical AND operation and the logical OR operation being performed on the left and right sides of the logical OR operator respectively, loading all the right logical nodes and the last loaded left logical node into the stack object; In response to the left side of the logical OR operator being the atomic rule number and the right side being the logical OR operation, loading all the logical nodes on the right side into the stack object; In response to the left and right sides of the logical OR operator being other cases, the logical nodes of the left and right sides loaded last time are loaded into the stack object.
10. An atomic rule logic expression visualization device, comprising: A file creation unit is configured to create a grammar rule file according to a standard data structure of a predefined logic diagram, wherein the grammar rule file defines a grammar for parsing an atomic rule logic expression; A generating unit, configured to generate a lexical analysis interface and a grammar parsing interface according to the grammar rule file; An interface creation unit, configured to create a parser for an atomic rule logic expression based on the lexical analysis interface and the grammar parsing interface according to a target logic relationship expression; The parsing unit is configured to parse the target logical relationship expression through the parser to obtain standard data of the logic diagram.
11. An electronic device, comprising: one or more processors; a storage device having one or more computer programs stored thereon, When the one or more computer programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 9.
12. A computer readable medium having a computer program stored thereon, wherein: When the computer program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
13. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 9.
Citation Information
Cited By
Logical expression processing method and system based on recursion and double-algorithm collaboration
CN120874979A