WO2021184765A1 - 规则处理方法、装置、介质及电子设备 - Google Patents

规则处理方法、装置、介质及电子设备 Download PDF

Info

Publication number
WO2021184765A1
WO2021184765A1 PCT/CN2020/124732 CN2020124732W WO2021184765A1 WO 2021184765 A1 WO2021184765 A1 WO 2021184765A1 CN 2020124732 W CN2020124732 W CN 2020124732W WO 2021184765 A1 WO2021184765 A1 WO 2021184765A1
Authority
WO
WIPO (PCT)
Prior art keywords
stack
result
word segmentation
temporary stack
temporary
Prior art date
Application number
PCT/CN2020/124732
Other languages
English (en)
French (fr)
Inventor
袁康
Original Assignee
平安科技(深圳)有限公司
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 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2021184765A1 publication Critical patent/WO2021184765A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data

Definitions

  • the present disclosure relates to the field of artificial intelligence technology, and in particular to a rule processing method, device, medium and electronic equipment based on reverse Polish expressions.
  • the purpose of the present disclosure is to provide a rule processing method, device, medium, and electronic equipment based on inverse Polish expressions.
  • a rule processing method based on inverse Polish expressions including:
  • word segmentation is performed on the rule text to obtain a prefix expression, and the prefix expression includes a plurality of word segmentation result elements;
  • the prefix expression is traversed in the order from left to right, and the first push operation of the corresponding word segmentation result element is performed according to the type of the word segmentation result element obtained by each traversal to obtain the suffix expression.
  • a stack operation corresponds to the result stack or the first temporary stack, and the suffix expression includes multiple elements;
  • the suffix expression is traversed in the order from left to right, and the corresponding element is traversed or the second stack operation based on the result of at least two element operations is performed according to the type of the element obtained by each traversal to obtain the The final operation result of the regular text, wherein the second stacking operation corresponds to the second temporary stack.
  • a rule processing device based on inverse Polish expressions comprising:
  • the definition module is configured to define and initialize the result stack, the first temporary stack and the second temporary stack;
  • the word segmentation module is configured to, when a rule text is received, segment the rule text to obtain a prefix expression, and the prefix expression includes a plurality of word segmentation result elements;
  • the first traversal module is configured to traverse the prefix expression in the order from left to right, and execute the corresponding first stack operation of the word segmentation result element according to the type of the word segmentation result element obtained by each traversal to obtain the suffix An expression, wherein the first stacking operation corresponds to the result stack or the first temporary stack, and the suffix expression includes multiple elements;
  • the second traversal module is configured to traverse the suffix expressions in the order from left to right, and execute the second entry and exit of the corresponding element or the result obtained based on the operation of at least two elements according to the type of the element obtained by each traversal Stack operation to obtain a final operation result of the rule text, wherein the second stack operation corresponds to the second temporary stack.
  • a computer-readable program medium which stores computer program instructions, and when the computer program instructions are executed by a computer, the computer executes the following method:
  • word segmentation is performed on the rule text to obtain a prefix expression, and the prefix expression includes a plurality of word segmentation result elements;
  • the prefix expression is traversed in the order from left to right, and the first push operation of the corresponding word segmentation result element is performed according to the type of the word segmentation result element obtained by each traversal to obtain the suffix expression.
  • a stack operation corresponds to the result stack or the first temporary stack, and the suffix expression includes multiple elements;
  • the suffix expression is traversed in the order from left to right, and the corresponding element is traversed or the second stack operation based on the result of at least two element operations is performed according to the type of the element obtained by each traversal to obtain the The final operation result of the regular text, wherein the second stacking operation corresponds to the second temporary stack.
  • an electronic device including:
  • a memory where computer readable instructions are stored, and when the computer readable instructions are executed by the processor, the following method is implemented:
  • word segmentation is performed on the rule text to obtain a prefix expression, and the prefix expression includes a plurality of word segmentation result elements;
  • the prefix expression is traversed in the order from left to right, and the first push operation of the corresponding word segmentation result element is performed according to the type of the word segmentation result element obtained by each traversal to obtain the suffix expression.
  • a stack operation corresponds to the result stack or the first temporary stack, and the suffix expression includes multiple elements;
  • the suffix expression is traversed in the order from left to right, and the corresponding element is traversed or the second stack operation based on the result of at least two element operations is performed according to the type of the element obtained by each traversal to obtain the The final operation result of the regular text, wherein the second stacking operation corresponds to the second temporary stack.
  • the rule processing method based on the reverse Polish expression provided by the present disclosure improves the reverse Polish expression, introduces a dual-stack design, and puts intermediate results into the temporary stack to assist in generating the final result stack, so that the improved Inverse Polish expressions can be used for complex rule calculations, thereby realizing efficient calculation of rules and reducing security risks.
  • Fig. 1 is a schematic diagram showing an application scenario of a rule processing method based on reverse Polish expressions according to an exemplary embodiment
  • Fig. 2 is a flow chart showing a method for processing rules based on reverse Polish expressions according to an exemplary embodiment
  • Fig. 3 is a schematic diagram showing a processing process of a rule engine to which a rule processing method based on reverse Polish expressions is applied according to an exemplary embodiment
  • Fig. 4 is a block diagram showing a device for processing rules based on reverse Polish expressions according to an exemplary embodiment
  • Fig. 5 is an exemplary block diagram of an electronic device that implements the foregoing rule processing method based on inverse Polish expressions according to an exemplary embodiment
  • Fig. 6 shows a computer-readable storage medium for realizing the above-mentioned rule processing method based on reverse Polish expressions according to an exemplary embodiment.
  • the present disclosure first provides a rule processing method based on reverse Polish expressions.
  • the rule here can be any rule that can be relied on or followed that can be run by computer instructions, and it can be used to restrict the behavior of the object to a certain extent.
  • a rule usually consists of symbols, numbers, etc.
  • a rule can be a judgment sentence or a calculation expression.
  • Inverse Polish expression is also called postfix expression. By expressing an expression through inverse Polish expression, each operator can be placed after its operand or operand.
  • the implementation terminal of the present disclosure can be any device with computing and processing functions.
  • the device can be connected to an external device for receiving or sending data.
  • it can be a portable mobile device, such as a smart phone, a tablet computer, a notebook computer, or a PDA ( Personal Digital Assistant), etc., can also be fixed devices, such as computer equipment, field terminals, desktop computers, servers, workstations, etc., or a collection of multiple devices, such as cloud computing physical infrastructure or server clusters.
  • the implementation terminal of the present disclosure may be a server or a physical infrastructure of cloud computing.
  • Fig. 1 is a schematic diagram showing an application scenario of a rule processing method based on reverse Polish expressions according to an exemplary embodiment.
  • it includes a server 110 and a plurality of user terminals 120.
  • the plurality of user terminals 120 are respectively connected to the server 110 through a communication link, and can receive data sent by the server 110 and can send data to the server 110.
  • the server 110 is the implementation terminal of the present disclosure, and multiple user terminals 120 can access the server 110 through a communication link.
  • the server 110 runs a rule engine. When the rule engine is running, the rule engine can be executed.
  • the disclosed embodiments provide a rule processing method based on reverse Polish expressions.
  • the rule processing method can realize efficient calculation of the rules for restricting the access behavior of the user terminal 120, thereby improving calculation efficiency and security.
  • FIG. 1 is only one embodiment of the present disclosure.
  • the implementing terminal in this embodiment is a server, in other embodiments, the implementing terminal may be various terminals or devices as described above; although in this embodiment, the rules are used to access other terminals. However, in other embodiments or specific applications, the rules can also be used to judge the processing flow of the local end, that is, the operation of the rules may not depend on external interaction behaviors.
  • the present disclosure does not make any limitation on this, and the protection scope of the present disclosure should not be limited in any way.
  • Fig. 2 is a flow chart showing a method for processing rules based on reverse Polish expressions according to an exemplary embodiment.
  • the rule processing method based on the reverse Polish expression of this embodiment can be executed by the server, as shown in FIG. 2, and includes the following steps:
  • Step 210 Define and initialize the result stack, the first temporary stack and the second temporary stack.
  • the result stack, the first temporary stack, and the second temporary stack are all stacks.
  • Stack also known as stack, is a linear table with limited operations. Limit the linear table that only inserts and deletes at the end of the table. This end is called the top of the stack, while the other end is called the bottom of the stack. Inserting a new element into a stack is also called pushing, pushing or pushing. It is to put the new element on top of the top element of the stack to make it a new top element; deleting an element from a stack is also called making a stack or Unstack, it is to delete the top element of the stack so that the adjacent element becomes the new top element of the stack.
  • the stack is a data structure in which data items are arranged in order, and data items can only be inserted and deleted at the top of the stack. The elements in the stack are accessed according to the principle of "first in, last out”.
  • the definition and initialization of the result stack, the first temporary stack and the second temporary stack include:
  • the method before applying memory space for the result stack, the first temporary stack and the second temporary stack respectively, the method includes:
  • the application of memory space for the result stack, the first temporary stack and the second temporary stack respectively includes:
  • memory space is applied for the result stack, the first temporary stack and the second temporary stack respectively.
  • Step 220 When the rule text is received, word segmentation is performed on the rule text to obtain a prefix expression.
  • the prefix expression includes a plurality of word segmentation result elements.
  • a rule text is a text used to describe one or more rules, which can be a Boolean rule, a numeric rule, a character rule, a branch rule, etc.
  • rule text can be varied.
  • the rule text may specifically be a risk control rule text, which is used for risk control and prevention in financial and other fields.
  • Boolean rules The values handled by Boolean rules are discrete and categorized. It shows the relationship between these variables, such as the relationship between equal, unequal, contain, and non-containable quantities that can be included.
  • Numerical rules generally process numerical fields, and may include operations such as addition, subtraction, multiplication, and division.
  • Prefix expression is a kind of arithmetic expression without parentheses. It writes the operator at the front and the operand at the back. Each operator or operand is a participle result element.
  • the rule text can be directly read locally by the implementing terminal of the present disclosure, or it can be received from other terminals, that is, it can be obtained from an external terminal through a transmission medium.
  • Step 230 Traverse the prefix expressions in the order from left to right, and perform the first stacking operation of the corresponding word segmentation result element according to the type of the word segmentation result element obtained by each traversal to obtain the suffix expression.
  • the first stacking operation corresponds to the result stack or the first temporary stack
  • the suffix expression includes multiple elements.
  • the rule text is a Boolean rule
  • the prefix expression is traversed from left to right
  • the corresponding word segmentation result element type is executed according to the type of the word segmentation result element obtained by each traversal.
  • the first stacking operation to get the suffix expression including:
  • the first traversal step includes: obtaining the first word segmentation result element in order from left to right as the current word segmentation result element;
  • the elements in the first temporary stack are popped sequentially and put into the result stack until the left brace in the first temporary stack is popped and put into the Result stack, and then go to the first traversal step;
  • the elements in the first temporary stack are popped sequentially and put into the result stack, until the left parenthesis in the first temporary stack is popped and put into the Result stack, and then go to the first traversal step;
  • the operator is put into the result stack and the elements of the first temporary stack are popped sequentially, and put into the result stack until the last time from the first temporary stack.
  • the element popped by the temporary stack is a closing brace or the priority of the operator is greater than the priority of the element to be popped from the first temporary stack next time, and then the first traversal step is transferred;
  • An expression may contain multiple data objects of different data types connected by different operators; because the expression has multiple operations, different combinations may give different results or even error operations, because when When the expression contains multiple operations, they must be combined in a certain order to ensure the rationality of the operation and the correctness and uniqueness of the result.
  • the priority setting of the operator enables the expression to be correctly operated.
  • the precedence of can be equal to 0, the precedence of the sum operator and averaging operator can be less than 0, and the precedence of other operators can be greater than 0.
  • the rule text is a numerical rule
  • the prefix expression is traversed from left to right
  • the corresponding word segmentation result element type is executed according to the type of the word segmentation result element obtained by each traversal.
  • the first stacking operation to get the suffix expression including:
  • the second traversal step includes: obtaining the first word segmentation result element in the order from left to right as the current word segmentation result element;
  • the current word segmentation result element is a numeric type or a parameter type, put the current word segmentation result element into the result stack and go to the second traversal step;
  • the elements in the first temporary stack are popped sequentially and put into the result stack until the left brace in the first temporary stack is popped and put into the Result stack, and then go to the second traversal step;
  • the elements in the first temporary stack are popped sequentially and put into the result stack, until the left parenthesis in the first temporary stack is popped and put into the Result stack, and then go to the second traversal step;
  • the operator is put into the result stack and the elements of the first temporary stack are popped sequentially, and put into the result stack until the last time from the first temporary stack.
  • the element popped by the temporary stack is a right brace or the priority of the operator is greater than the priority of the element to be popped from the first temporary stack next time, and then the second traversal step is transferred;
  • Step 240 traverse the suffix expression in the order from left to right, and perform a corresponding second stack operation on the elements or based on the result of at least two element operations according to the type of the element obtained by each traversal, to obtain The final calculation result of the rule text.
  • the second stacking operation corresponds to the second temporary stack.
  • the rule text is a Boolean rule
  • the suffix expression is traversed in order from left to right
  • the corresponding pair of elements is executed according to the type of the element obtained by each traversal or based on at least two elements.
  • the second stacking operation of the result obtained by the element operation to obtain the final operation result of the rule text includes:
  • the third traversal step includes: obtaining the first element of the suffix expression in order from left to right as the current element;
  • the current element is a character string or a left brace, put the current element into the second temporary stack and go to the third traversal step;
  • the first element in the second temporary stack is popped as the final operation result of the rule text.
  • the rule text is a numerical rule
  • the suffix expression is traversed in the order from left to right
  • the corresponding pair of elements is executed according to the type of the element obtained by each traversal or based on at least two
  • the second stacking operation of the result obtained by the element operation to obtain the final operation result of the rule text includes:
  • the fourth traversal step includes: obtaining the first element of the suffix expression in the order from left to right as the current element;
  • the current element is a character string or a left brace, put the current element into the second temporary stack and go to the fourth traversal step;
  • the first element in the second temporary stack is popped as the final operation result of the rule text.
  • the reverse Polish expression is improved, and the dual-stack design is introduced, and the intermediate results are put into the temporary stack to assist in generating the final
  • the result stack of the improved inverse Polish expression can be used for complex rule calculations, thus realizing efficient calculation of rules and reducing security risks.
  • Fig. 3 is a schematic diagram showing a processing process of a rule engine to which a rule processing method based on reverse Polish expressions is applied, according to an exemplary embodiment.
  • the specific processing process can be as follows: First, the rule engine obtains a piece of rule text, which can be an expression of Boolean, character, numeric value, branch, etc.; next, the rule text is segmented . You can use different word segmentation algorithms for different types of expressions; then, to convert the result of word segmentation (prefix expression) into suffix expression, the realization of this process depends on the design of dual stack, that is, it depends on the result stack and the first A temporary stack; then, the final operation result must be obtained based on the suffix expression.
  • This process includes popping elements, performing calculations by operators, and pushing the intermediate calculation results onto the stack, depending on the second temporary stack; finally, take out the second temporary
  • the top element of the stack is output as the final operation result on the rule text, thereby completing the operation on the rule text.
  • the present disclosure also provides a rule processing device based on inverse Polish expressions.
  • the following are device embodiments of the present disclosure.
  • Fig. 4 is a block diagram showing a device for processing rules based on reverse Polish expressions according to an exemplary embodiment. As shown in FIG. 4, the apparatus 400 includes:
  • the definition module 410 is configured to define and initialize the result stack, the first temporary stack, and the second temporary stack;
  • the word segmentation module 420 is configured to, when a rule text is received, segment the rule text to obtain a prefix expression, and the prefix expression includes a plurality of word segmentation result elements;
  • the first traversal module 430 is configured to traverse the prefix expressions in the order from left to right, and execute the corresponding first stack operation of the word segmentation result element according to the type of the word segmentation result element obtained by each traversal to obtain A suffix expression, wherein the first stacking operation corresponds to the result stack or the first temporary stack, and the suffix expression includes a plurality of elements;
  • the second traversal module 440 is configured to traverse the suffix expressions in the order from left to right, and perform a corresponding pair of elements according to the type of elements obtained by each traversal or a second operation based on at least two elements.
  • a stacking operation is performed to obtain a final operation result of the regular text, wherein the second stacking operation is corresponding to the second temporary stack.
  • an electronic device capable of implementing the above method.
  • the electronic device 500 according to this embodiment of the present application will be described below with reference to FIG. 5.
  • the electronic device 500 shown in FIG. 5 is only an example, and should not bring any limitation to the function and scope of use of the embodiments of the present application.
  • the electronic device 500 is represented in the form of a general-purpose computing device.
  • the components of the electronic device 500 may include, but are not limited to: the aforementioned at least one processing unit 510, the aforementioned at least one storage unit 520, and a bus 530 connecting different system components (including the storage unit 520 and the processing unit 510).
  • the storage unit stores program code, and the program code can be executed by the processing unit 510, so that the processing unit 510 executes the various exemplary methods described in the "Embodiment Method" section of this specification. Steps of implementation.
  • the storage unit 520 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 521 and/or a cache storage unit 522, and may further include a read-only storage unit (ROM) 523.
  • RAM random access storage unit
  • ROM read-only storage unit
  • the storage unit 520 may also include a program/utility tool 524 having a set of (at least one) program module 525.
  • program module 525 includes but is not limited to: an operating system, one or more application programs, other program modules, and program data. Each of these examples or some combination may include the implementation of a network environment.
  • the bus 530 may represent one or more of several types of bus structures, including a storage unit bus or a storage unit controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local area using any bus structure among multiple bus structures. bus.
  • the electronic device 500 may also communicate with one or more external devices 700 (such as keyboards, pointing devices, Bluetooth devices, etc.), and may also communicate with one or more devices that enable a user to interact with the electronic device 500, and/or communicate with Any device (such as a router, modem, etc.) that enables the electronic device 500 to communicate with one or more other computing devices. Such communication can be performed through an input/output (I/O) interface 550.
  • the electronic device 500 may also communicate with one or more networks (for example, a local area network (LAN), a wide area network (WAN), and/or a public network, such as the Internet) through the network adapter 560.
  • networks for example, a local area network (LAN), a wide area network (WAN), and/or a public network, such as the Internet
  • the network adapter 560 communicates with other modules of the electronic device 500 through the bus 530.
  • other hardware and/or software modules can be used in conjunction with the electronic device 500, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives And data backup storage system, etc.
  • the example embodiments described here can be implemented by software, or can be implemented by combining software with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, U disk, mobile hard disk, etc.) or on the network , Including several instructions to make a computing device (which may be a personal computer, a server, a terminal device, or a network device, etc.) execute the method according to the embodiments of the present disclosure.
  • a computing device which may be a personal computer, a server, a terminal device, or a network device, etc.
  • a computer-readable storage medium on which is stored a program product capable of implementing the above-mentioned method of this specification.
  • each aspect of the present application can also be implemented in the form of a program product, which includes program code.
  • the program product runs on a terminal device, the program code is used to make the The terminal device executes the steps according to various exemplary embodiments of the present application described in the above-mentioned "Exemplary Method" section of this specification.
  • a program product 600 for implementing the above method according to an embodiment of the present application is described. It can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be installed in a terminal device, For example, running on a personal computer.
  • CD-ROM compact disk read-only memory
  • the program product of this application is not limited to this.
  • the readable storage medium can be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, device, or device.
  • the computer storage medium may be non-volatile or volatile.
  • the program product can use any combination of one or more readable media.
  • the readable medium may be a readable signal medium or a readable storage medium.
  • the readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or a combination of any of the above. More specific examples (non-exhaustive list) of readable storage media include: electrical connections with one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable Type programmable read only memory (EPROM or flash memory), optical fiber, portable compact disk read only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above.
  • the computer-readable signal medium may include a data signal propagated in baseband or as a part of a carrier wave, and readable program code is carried therein. This propagated data signal can take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing.
  • the readable signal medium may also be any readable medium other than a readable storage medium, and the readable medium may send, propagate, or transmit a program for use by or in combination with the instruction execution system, apparatus, or device.
  • the program code contained on the readable medium can be transmitted by any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
  • the program code used to perform the operations of the present application can be written in any combination of one or more programming languages.
  • the programming languages include object-oriented programming languages—such as Java, C++, etc., as well as conventional procedural programming languages. Programming language-such as "C" language or similar programming language.
  • the program code can be executed entirely on the user's computing device, partly on the user's device, executed as an independent software package, partly on the user's computing device and partly executed on the remote computing device, or entirely on the remote computing device or server Executed on.
  • the remote computing device can be connected to a user computing device through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (for example, using Internet service providers). Business to connect via the Internet).
  • LAN local area network
  • WAN wide area network
  • Internet service providers for example, using Internet service providers.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Machine Translation (AREA)

Abstract

一种基于逆波兰表达式的规则处理方法、装置、介质及电子设备,涉及人工智能领域。该方法包括:定义并初始化结果栈、第一临时栈和第二临时栈(210);当接收到规则文本,对规则文本进行分词,得到前缀表达式(220);按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式(230);按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果(240),其中,所述第二出入栈操作与所述第二临时栈对应。此方法下,实现了对规则的高效计算,降低了安全风险。

Description

规则处理方法、装置、介质及电子设备
本申请要求于2020年3月16日提交中国专利局、申请号为202010180995X,发明名称为“规则处理方法、装置、介质及电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本公开涉及人工智能技术领域,特别涉及一种基于逆波兰表达式的规则处理方法、装置、介质及电子设备。
背景技术
随着计算机技术的发展,越来越多的项目利用规则进行运算和事务处理。然而,发明人发现传统规则复杂的表达形式并不适合计算机的处理,导致了规则的计算效率低下,不能满足人们对高效规则计算的需求,特别是在安全领域,由于规则计算效率越高,在一定程度上就越能增强防护的安全性并能避免损失,因此目前亟需一种实现对规则进行高效运算的方法。
技术问题
目前亟需一种实现对规则进行高效运算的方法。
技术解决方案
在安全防护技术领域,为了解决上述技术问题,本公开的目的在于提供一种基于逆波兰表达式的规则处理方法、装置、介质及电子设备。
根据本公开的一方面,提供了一种基于逆波兰表达式的规则处理方法,所述方法包括:
定义并初始化结果栈、第一临时栈和第二临时栈;
当接收到规则文本,对所述规则文本进行分词,得到前缀表达式,所述前缀表达式包括多个分词结果元素;
按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素;
按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,其中,所述第二出入栈操作与所述第二临时栈对应。
根据本公开的另一方面,提供了一种基于逆波兰表达式的规则处理装置,所述装置包括:
定义模块,被配置为定义并初始化结果栈、第一临时栈和第二临时栈;
分词模块,被配置为当接收到规则文本,对所述规则文本进行分词,得到前缀表达式,所述前缀表达式包括多个分词结果元素;
第一遍历模块,被配置为按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素;
第二遍历模块,被配置为按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,其中,所述第二出入栈操作与所述第二临时栈对应。
根据本公开的另一方面,提供了一种计算机可读程序介质,其存储有计算机程序指令,当所述计算机程序指令被计算机执行时,使计算机执行实现如下方法:
定义并初始化结果栈、第一临时栈和第二临时栈;
当接收到规则文本,对所述规则文本进行分词,得到前缀表达式,所述前缀表达式包括多个分词结果元素;
按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素;
按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,其中,所述第二出入栈操作与所述第二临时栈对应。
根据本公开的另一方面,提供了一种电子设备,所述电子设备包括:
处理器;
存储器,所述存储器上存储有计算机可读指令,所述计算机可读指令被所述处理器执行时,实现如下方法:
定义并初始化结果栈、第一临时栈和第二临时栈;
当接收到规则文本,对所述规则文本进行分词,得到前缀表达式,所述前缀表达式包括多个分词结果元素;
按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素;
按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,其中,所述第二出入栈操作与所述第二临时栈对应。
应当理解的是,以上的一般描述和后文的细节描述仅是示例性的,并不能限制本申请。
有益效果
本公开所提供的基于逆波兰表达式的规则处理方法通过对逆波兰表达式做出改进,通过引入双栈的设计,将中间结果放入临时栈以辅助生成最终的结果栈,使改进后的逆波兰表达式可以用于复杂的规则计算,从而实现了对规则的高效计算,降低了安全风险。
附图说明
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本申请的实施例,并与说明书一起用于解释本申请的原理。
图1是根据一示例性实施例示出的一种基于逆波兰表达式的规则处理方法的应用场景示意图;
图2是根据一示例性实施例示出的一种基于逆波兰表达式的规则处理方法的流程图;
图3是根据一示例性实施例示出的应用了基于逆波兰表达式的规则处理方法的规则引擎的处理过程示意图;
图4是根据一示例性实施例示出的一种基于逆波兰表达式的规则处理装置的框图;
图5是根据一示例性实施例示出的一种实现上述基于逆波兰表达式的规则处理方法的电子设备示例框图;
图6是根据一示例性实施例示出的一种实现上述基于逆波兰表达式的规则处理方法的计算机可读存储介质。
本发明的实施方式
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本申请相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本申请的一些方面相一致的装置和方法的例子。
此外,附图仅为本公开的示意性图解,并非一定是按比例绘制。图中相同的附图标记表示相同或类似的部分,因而将省略对它们的重复描述。附图中所示的一些方框图是功能实体,不一定必须与物理或逻辑上独立的实体相对应。
本公开首先提供了一种基于逆波兰表达式的规则处理方法。这里的规则可以是任何可以通过计算机指令的方式运行的可以依赖或者遵循的规定,它可以用来对对象的行为起到一定的约束作用。规则通常由符号、数字等组成,一个规则可以是一个判断语句,也可以是一个计算表达式。逆波兰表达式又叫做后缀表达式,通过逆波兰表达式来表示一个表达式,可以使每一运算符都置于其运算对象或者运算量之后。
本公开的实施终端可以是任何具有运算和处理功能的设备,该设备可以与外部设备相连,用于接收或者发送数据,具体可以是便携移动设备,例如智能手机、平板电脑、笔记本电脑、PDA(Personal Digital Assistant)等,也可以是固定式设备,例如,计算机设备、现场终端、台式电脑、服务器、工作站等,还可以是多个设备的集合,比如云计算的物理基础设施或者服务器集群。
可选地,本公开的实施终端可以为服务器或者云计算的物理基础设施。
图1是根据一示例性实施例示出的一种基于逆波兰表达式的规则处理方法的应用场景示意图。如图1所示,包括服务器110和多个用户终端120,多个用户终端120分别通过通信链路与服务器110相连,可以接收服务器110发来的数据并可以向服务器110发送数据。在本实施例中,服务器110为本公开的实施终端,多个用户终端120均可以通过通信链路对服务器110进行访问,服务器110上运行有规则引擎,当运行该规则引擎时,可以执行本公开实施例提供的基于逆波兰表达式的规则处理方法。多个用户终端120对服务器110进行访问时,需要在服务器110设置一定的规则来对用户终端120的访问行为进行约束,而通过在服务器110上执行本公开实施例提供的基于逆波兰表达式的规则处理方法,可以实现对用于约束用户终端120的访问行为的规则的高效计算,从而可以提高计算 效率,提高安全性。
值得一提的是,图1仅为本公开的一个实施例。虽然在本实施例中的实施终端为服务器,但在其他实施例中,实施终端可以为如前所述的各种终端或设备;虽然在本实施例中规则是用于对其他终端的访问行为进行判断,但在其他实施例或者具体应用中,规则还可以用于对本端的处理流程进行判断,即规则的运行可以不依赖于外部的交互行为。本公开对此不作任何限定,本公开的保护范围也不应因此而受到任何限制。
图2是根据一示例性实施例示出的一种基于逆波兰表达式的规则处理方法的流程图。本实施例的基于逆波兰表达式的规则处理方法可以由服务器执行,如图2所示,包括以下步骤:
步骤210,定义并初始化结果栈、第一临时栈和第二临时栈。
结果栈、第一临时栈和第二临时栈均为栈。
栈又名堆栈,它是一种运算受限的线性表。限定仅在表尾进行插入和删除操作的线性表。这一端被称为栈顶,相对地,把另一端称为栈底。向一个栈插入新元素又称作进栈、入栈或压栈,它是把新元素放到栈顶元素的上面,使之成为新的栈顶元素;从一个栈删除元素又称作出栈或退栈,它是把栈顶元素删除掉,使其相邻的元素成为新的栈顶元素。由此可见,堆栈是一种数据项按序排列的数据结构,只能在栈顶对数据项进行插入和删除。堆栈中的元素按照“先进后出”的原则存取。
在一个实施例中,所述定义并初始化结果栈、第一临时栈和第二临时栈,包括:
分别为结果栈、第一临时栈和第二临时栈申请内存空间。
在一个实施例中,在分别为结果栈、第一临时栈和第二临时栈申请内存空间之前,所述方法包括:
分别获取要为结果栈、第一临时栈和第二临时栈申请的内存空间的大小;
所述分别为结果栈、第一临时栈和第二临时栈申请内存空间,包括:
按照各栈要申请的内存空间的大小,分别为结果栈、第一临时栈和第二临时栈申请内存空间。
步骤220,当接收到规则文本,对所述规则文本进行分词,得到前缀表达式。
所述前缀表达式包括多个分词结果元素。
规则文本是用于描述一条或多条规则的文本,可以是布尔型规则,亦可以为数值型规则、字符型规则、分支型规则等。
规则文本的用途可以是多种多样的。比如,规则文本具体可以是风控规则文本,用于金融等领域的风险控制和防范。
布尔型规则处理的值都是离散的、种类化的,它显示了这些变量之间的关系,比如可以包含量的等于、不等于、包含、不包含等关系。而数值型规则一般对数值型字段进行处理,可以包括例如加、减、乘、除等运算过程。
针对不同类型的规则文本可以采用不同的分词算法进行分词。
前缀表达式是一种没有括号的算术表达式,其将运算符写在前面,操作数写在后面,其中每一运算符或操作数即为一个分词结果元素。
规则文本可以由本公开的实施终端在本地直接读取得到,也可以从其他终端接收得到,即可以通过传输介质从外部终端获得。
步骤230,按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后 缀表达式。
其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素。
在一个实施例中,所述规则文本为布尔型规则,所述按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,包括:
执行第一遍历步骤,所述第一遍历步骤包括:按照从左至右的顺序获取第一个分词结果元素,作为当前分词结果元素;
若当前分词结果元素为左小括号,则将所述当前分词结果元素放入所述第一临时栈并转至所述第一遍历步骤;
若当前分词结果元素为左大括号,则将所述当前分词结果元素分别放入所述结果栈和所述第一临时栈并转至所述第一遍历步骤;
若当前分词结果元素为数值类型、参数类型、字符类型中的一种,则将所述当前分词结果元素放入所述结果栈并转至所述第一遍历步骤;
若当前分词结果元素为右大括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
若当前分词结果元素为空格,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
若当前分词结果元素为右小括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左小括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
若当前分词结果元素的类型为运算符,确定所述运算符的优先级;
若所述优先级小于0,则将所述运算符放入所述第一临时栈并转至所述第一遍历步骤;
若所述优先级大于或等于0,则将所述运算符放入所述结果栈并将所述第一临时栈的元素依次弹出,放入所述结果栈,直到上次从所述第一临时栈弹出的元素为右大括号或者所述运算符的优先级大于下次要从所述第一临时栈弹出的元素的优先级,然后转至所述第一遍历步骤;
否则,将所述当前分词结果元素放入所述第一临时栈,然后转至所述第一遍历步骤;
当所述前缀表达式的所有分词结果元素均经过了一次遍历,将所述第一临时栈中的元素依次弹出,放入所述结果栈,并将所述结果栈中的元素依次弹出,得到后缀表达式。
在一个表达式中可能包含多个由不同运算符连接起来的、具有不同数据类型的数据对象;由于表达式有多种运算,不同的结合顺序可能得出不同结果甚至出现错误运算错误,因为当表达式中含多种运算时,必须按一定顺序进行结合,才能保证运算的合理性和结果的正确性、唯一性。运算符的优先级的设置使表达式能够被正确运算。
比如,运算符可以包括=、≠、>、<、||、&&、!+、-、*、/、求和运算符、求平均值运算符等,其中,||、&&、!的优先级可以等于0,求和运算符、求平均值运算符的优先级可以小于0,其他运算符的优先级可以大于0。
在一个实施例中,所述规则文本为数值型规则,所述按照从左至右的顺序遍 历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,包括:
执行第二遍历步骤,所述第二遍历步骤包括:按照从左至右的顺序获取第一个分词结果元素,作为当前分词结果元素;
若当前分词结果元素为左小括号,则将所述当前分词结果元素放入所述第一临时栈并转至所述第二遍历步骤;
若当前分词结果元素为左大括号,则将所述当前分词结果元素分别放入所述结果栈和所述第一临时栈并转至所述第二遍历步骤;
若当前分词结果元素为数值类型或者参数类型,则将所述当前分词结果元素放入所述结果栈并转至所述第二遍历步骤;
若当前分词结果元素为右大括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
若当前分词结果元素为空格,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
若当前分词结果元素为右小括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左小括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
若当前分词结果元素的类型为运算符,确定所述运算符的优先级;
若所述优先级小于0,则将所述运算符放入所述第一临时栈并转至所述第二遍历步骤;
若所述优先级大于或等于0,则将所述运算符放入所述结果栈并将所述第一临时栈的元素依次弹出,放入所述结果栈,直到上次从所述第一临时栈弹出的元素为右大括号或者所述运算符的优先级大于下次要从所述第一临时栈弹出的元素的优先级,然后转至所述第二遍历步骤;
否则,将所述当前分词结果元素放入所述第一临时栈,然后转至所述第二遍历步骤;
当所述前缀表达式的所有分词结果元素均经过了一次遍历,将所述第一临时栈中的元素依次弹出,放入所述结果栈,并将所述结果栈中的元素依次弹出,得到后缀表达式。
步骤240,按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果。
其中,所述第二出入栈操作与所述第二临时栈对应。
在一个实施例中,所述规则文本为布尔型规则,所述按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,包括:
执行第三遍历步骤,所述第三遍历步骤包括:按照从左至右的顺序获取所述后缀表达式的第一个元素,作为当前元素;
若当前元素为字符串或左大括号,则将所述当前元素放入所述第二临时栈并转至所述第三遍历步骤;
若当前元素为数值类型,则将所述当前元素放入所述第二临时栈并转至所述 第三遍历步骤;
若当前元素为运算符,确定所述运算符的优先级;
若所述优先级小于0,则将所述第二临时栈中的元素依次弹出,作为第一元素,直至下次要弹出的元素为左大括号;
利用所述运算符和所述第一元素计算出第一结果,并将所述第一结果放入所述第二临时栈,然后转至所述第三遍历步骤;
若所述优先级大于或等于0,则从所述第二临时栈中弹出两个元素,作为第二元素;
利用所述运算符和所述第二元素计算出第二结果,并将所述第二结果放入所述第二临时栈,然后转至所述第三遍历步骤;
当所述后缀表达式的所有元素均经过了一次遍历,将所述第二临时栈中的第一个元素弹出,作为对所述规则文本的最终运算结果。
在一个实施例中,所述规则文本为数值型规则,所述按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,包括:
执行第四遍历步骤,所述第四遍历步骤包括:按照从左至右的顺序获取所述后缀表达式的第一个元素,作为当前元素;
若当前元素为字符串或左大括号,则将所述当前元素放入所述第二临时栈并转至所述第四遍历步骤;
若当前元素为数值类型,则将所述当前元素放入所述第二临时栈并转至所述第四遍历步骤;
若当前元素为运算符,确定所述运算符的优先级;
若所述优先级小于0,则将所述第二临时栈中的元素依次弹出,作为第三元素,直至下次要弹出的元素为左大括号;
利用所述运算符和所述第三元素计算出第三结果,并将所述第三结果放入所述第二临时栈,然后转至所述第四遍历步骤;
若所述优先级大于0,则从所述第二临时栈中弹出两个元素,作为第四元素;
利用所述运算符和所述第四元素计算出第四结果,并将所述第四结果放入所述第二临时栈,然后转至所述第四遍历步骤;
当所述后缀表达式的所有元素均经过了一次遍历,将所述第二临时栈中的第一个元素弹出,作为对所述规则文本的最终运算结果。
综上所述,根据图2实施例提供的基于逆波兰表达式的规则处理方法,通过对逆波兰表达式做出改进,通过引入双栈的设计,将中间结果放入临时栈以辅助生成最终的结果栈,使改进后的逆波兰表达式可以用于复杂的规则计算,从而实现了对规则的高效计算,降低了安全风险。
本公开实施例提供的基于逆波兰表达式的规则处理方法可以以规则引擎的方式运行。图3是根据一示例性实施例示出的应用了基于逆波兰表达式的规则处理方法的规则引擎的处理过程示意图。
如图3所示,该处理过程具体可以为:首先,由规则引擎获取一段规则文本,该规则文本可以是布尔、字符、数值、分支等类型的表达式;接下来,对该规则文本进行分词,可以针对不同类型的表达式使用不同的分词算法;然后,要将分词的结果(前缀表达式)转换为后缀表达式,此过程的实现依赖于双栈的设计,即依赖于结果栈和第一临时栈;接着,要基于后缀表达式得到最终运算结果,此 过程包括弹出元素、运算符进行计算,并将中间计算结果入栈等操作,依赖于第二临时栈;最后,取出第二临时栈的栈顶元素,作为对规则文本的最终运算结果输出,从而完成对规则文本的运算。
本公开还提供了一种基于逆波兰表达式的规则处理装置,以下是本公开的装置实施例。
图4是根据一示例性实施例示出的一种基于逆波兰表达式的规则处理装置的框图。如图4所示,装置400包括:
定义模块410,被配置为定义并初始化结果栈、第一临时栈和第二临时栈;
分词模块420,被配置为当接收到规则文本,对所述规则文本进行分词,得到前缀表达式,所述前缀表达式包括多个分词结果元素;
第一遍历模块430,被配置为按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素;
第二遍历模块440,被配置为按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,其中,所述第二出入栈操作与所述第二临时栈对应。
根据本公开的第三方面,还提供了一种能够实现上述方法的电子设备。
所属技术领域的技术人员能够理解,本申请的各个方面可以实现为系统、方法或程序产品。因此,本申请的各个方面可以具体实现为以下形式,即:完全的硬件实施方式、完全的软件实施方式(包括固件、微代码等),或硬件和软件方面结合的实施方式,这里可以统称为“电路”、“模块”或“系统”。
下面参照图5来描述根据本申请的这种实施方式的电子设备500。图5显示的电子设备500仅仅是一个示例,不应对本申请实施例的功能和使用范围带来任何限制。
如图5所示,电子设备500以通用计算设备的形式表现。电子设备500的组件可以包括但不限于:上述至少一个处理单元510、上述至少一个存储单元520、连接不同系统组件(包括存储单元520和处理单元510)的总线530。
其中,所述存储单元存储有程序代码,所述程序代码可以被所述处理单元510执行,使得所述处理单元510执行本说明书上述“实施例方法”部分中描述的根据本申请各种示例性实施方式的步骤。
存储单元520可以包括易失性存储单元形式的可读介质,例如随机存取存储单元(RAM)521和/或高速缓存存储单元522,还可以进一步包括只读存储单元(ROM)523。
存储单元520还可以包括具有一组(至少一个)程序模块525的程序/实用工具524,这样的程序模块525包括但不限于:操作系统、一个或者多个应用程序、其它程序模块以及程序数据,这些示例中的每一个或某种组合中可能包括网络环境的实现。
总线530可以为表示几类总线结构中的一种或多种,包括存储单元总线或者存储单元控制器、外围总线、图形加速端口、处理单元或者使用多种总线结构中的任意总线结构的局域总线。
电子设备500也可以与一个或多个外部设备700(例如键盘、指向设备、蓝牙设备等)通信,还可与一个或者多个使得用户能与该电子设备500交互的设备 通信,和/或与使得该电子设备500能与一个或多个其它计算设备进行通信的任何设备(例如路由器、调制解调器等等)通信。这种通信可以通过输入/输出(I/O)接口550进行。并且,电子设备500还可以通过网络适配器560与一个或者多个网络(例如局域网(LAN),广域网(WAN)和/或公共网络,例如因特网)通信。如图所示,网络适配器560通过总线530与电子设备500的其它模块通信。应当明白,尽管图中未示出,可以结合电子设备500使用其它硬件和/或软件模块,包括但不限于:微代码、设备驱动器、冗余处理单元、外部磁盘驱动阵列、RAID系统、磁带驱动器以及数据备份存储系统等。
通过以上的实施方式的描述,本领域的技术人员易于理解,这里描述的示例实施方式可以通过软件实现,也可以通过软件结合必要的硬件的方式来实现。因此,根据本公开实施方式的技术方案可以以软件产品的形式体现出来,该软件产品可以存储在一个非易失性存储介质(可以是CD-ROM,U盘,移动硬盘等)中或网络上,包括若干指令以使得一台计算设备(可以是个人计算机、服务器、终端装置、或者网络设备等)执行根据本公开实施方式的方法。
根据本公开的第四方面,还提供了一种计算机可读存储介质,其上存储有能够实现本说明书上述方法的程序产品。在一些可能的实施方式中,本申请的各个方面还可以实现为一种程序产品的形式,其包括程序代码,当所述程序产品在终端设备上运行时,所述程序代码用于使所述终端设备执行本说明书上述“示例性方法”部分中描述的根据本申请各种示例性实施方式的步骤。
参考图6所示,描述了根据本申请的实施方式的用于实现上述方法的程序产品600,其可以采用便携式紧凑盘只读存储器(CD-ROM)并包括程序代码,并可以在终端设备,例如个人电脑上运行。然而,本申请的程序产品不限于此,在本文件中,可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。
所述计算机存储介质可以是非易失性,也可以是易失性。
所述程序产品可以采用一个或多个可读介质的任意组合。可读介质可以是可读信号介质或者可读存储介质。可读存储介质例如可以为但不限于电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。可读存储介质的更具体的例子(非穷举的列表)包括:具有一个或多个导线的电连接、便携式盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。
计算机可读信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了可读程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。可读信号介质还可以是可读存储介质以外的任何可读介质,该可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。
可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于无线、有线、光缆、RF等等,或者上述的任意合适的组合。
可以以一种或多种程序设计语言的任意组合来编写用于执行本申请操作的程序代码,所述程序设计语言包括面向对象的程序设计语言—诸如Java、C++等,还包括常规的过程式程序设计语言—诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算设备上执行、部分地在用户设备上执行、作为一个独立的软件包执行、部分在用户计算设备上部分在远程计算设备上执行、或者完 全在远程计算设备或服务器上执行。在涉及远程计算设备的情形中,远程计算设备可以通过任意种类的网络,包括局域网(LAN)或广域网(WAN),连接到用户计算设备,或者,可以连接到外部计算设备(例如利用因特网服务提供商来通过因特网连接)。
此外,上述附图仅是根据本申请示例性实施例的方法所包括的处理的示意性说明,而不是限制目的。易于理解,上述附图所示的处理并不表明或限制这些处理的时间顺序。另外,也易于理解,这些处理可以是例如在多个模块中同步或异步执行的。
应当理解的是,本申请并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围执行各种修改和改变。本申请的范围仅由所附的权利要求来限制。

Claims (20)

  1. 一种基于逆波兰表达式的规则处理方法,其中,所述方法包括:
    定义并初始化结果栈、第一临时栈和第二临时栈;
    当接收到规则文本,对所述规则文本进行分词,得到前缀表达式,所述前缀表达式包括多个分词结果元素;
    按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素;
    按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,其中,所述第二出入栈操作与所述第二临时栈对应。
  2. 根据权利要求1所述的方法,其中,所述定义并初始化结果栈、第一临时栈和第二临时栈包括:
    分别为结果栈、第一临时栈和第二临时栈申请内存空间。
  3. 根据权利要求1所述的方法,其中,所述规则文本为布尔型规则,所述按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,包括:
    执行第一遍历步骤,所述第一遍历步骤包括:按照从左至右的顺序获取第一个分词结果元素,作为当前分词结果元素;
    若当前分词结果元素为左小括号,则将所述当前分词结果元素放入所述第一临时栈并转至所述第一遍历步骤;
    若当前分词结果元素为左大括号,则将所述当前分词结果元素分别放入所述结果栈和所述第一临时栈并转至所述第一遍历步骤;
    若当前分词结果元素为数值类型、参数类型、字符类型中的一种,则将所述当前分词结果元素放入所述结果栈并转至所述第一遍历步骤;
    若当前分词结果元素为右大括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
    若当前分词结果元素为空格,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
    若当前分词结果元素为右小括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左小括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
    若当前分词结果元素的类型为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述运算符放入所述第一临时栈并转至所述第一遍历步骤;
    若所述优先级大于或等于0,则将所述运算符放入所述结果栈并将所述第一临时栈的元素依次弹出,放入所述结果栈,直到上次从所述第一临时栈弹出的元素为右大括号或者所述运算符的优先级大于下次要从所述第一临时栈弹出的元素的优先级,然后转至所述第一遍历步骤;
    否则,将所述当前分词结果元素放入所述第一临时栈,然后转至所述第一遍历步骤;
    当所述前缀表达式的所有分词结果元素均经过了一次遍历,将所述第一临时栈中的元素依次弹出,放入所述结果栈,并将所述结果栈中的元素依次弹出,得到后缀表达式。
  4. 根据权利要求1所述的方法,其中,所述规则文本为数值型规则,所述按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,包括:
    执行第二遍历步骤,所述第二遍历步骤包括:按照从左至右的顺序获取第一个分词结果元素,作为当前分词结果元素;
    若当前分词结果元素为左小括号,则将所述当前分词结果元素放入所述第一临时栈并转至所述第二遍历步骤;
    若当前分词结果元素为左大括号,则将所述当前分词结果元素分别放入所述结果栈和所述第一临时栈并转至所述第二遍历步骤;
    若当前分词结果元素为数值类型或者参数类型,则将所述当前分词结果元素放入所述结果栈并转至所述第二遍历步骤;
    若当前分词结果元素为右大括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
    若当前分词结果元素为空格,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
    若当前分词结果元素为右小括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左小括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
    若当前分词结果元素的类型为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述运算符放入所述第一临时栈并转至所述第二遍历步骤;
    若所述优先级大于或等于0,则将所述运算符放入所述结果栈并将所述第一临时栈的元素依次弹出,放入所述结果栈,直到上次从所述第一临时栈弹出的元素为右大括号或者所述运算符的优先级大于下次要从所述第一临时栈弹出的元素的优先级,然后转至所述第二遍历步骤;
    否则,将所述当前分词结果元素放入所述第一临时栈,然后转至所述第二遍历步骤;
    当所述前缀表达式的所有分词结果元素均经过了一次遍历,将所述第一临时栈中的元素依次弹出,放入所述结果栈,并将所述结果栈中的元素依次弹出,得到后缀表达式。
  5. 根据权利要求1或3所述的方法,其中,所述规则文本为布尔型规则,所述按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,包括:
    执行第三遍历步骤,所述第三遍历步骤包括:按照从左至右的顺序获取所述后缀表达式的第一个元素,作为当前元素;
    若当前元素为字符串或左大括号,则将所述当前元素放入所述第二临时栈并 转至所述第三遍历步骤;
    若当前元素为数值类型,则将所述当前元素放入所述第二临时栈并转至所述第三遍历步骤;
    若当前元素为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述第二临时栈中的元素依次弹出,作为第一元素,直至下次要弹出的元素为左大括号;
    利用所述运算符和所述第一元素计算出第一结果,并将所述第一结果放入所述第二临时栈,然后转至所述第三遍历步骤;
    若所述优先级大于或等于0,则从所述第二临时栈中弹出两个元素,作为第二元素;
    利用所述运算符和所述第二元素计算出第二结果,并将所述第二结果放入所述第二临时栈,然后转至所述第三遍历步骤;
    当所述后缀表达式的所有元素均经过了一次遍历,将所述第二临时栈中的第一个元素弹出,作为对所述规则文本的最终运算结果。
  6. 根据权利要求1或4所述的方法,其中,所述规则文本为数值型规则,所述按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,包括:
    执行第四遍历步骤,所述第四遍历步骤包括:按照从左至右的顺序获取所述后缀表达式的第一个元素,作为当前元素;
    若当前元素为字符串或左大括号,则将所述当前元素放入所述第二临时栈并转至所述第四遍历步骤;
    若当前元素为数值类型,则将所述当前元素放入所述第二临时栈并转至所述第四遍历步骤;
    若当前元素为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述第二临时栈中的元素依次弹出,作为第三元素,直至下次要弹出的元素为左大括号;
    利用所述运算符和所述第三元素计算出第三结果,并将所述第三结果放入所述第二临时栈,然后转至所述第四遍历步骤;
    若所述优先级大于0,则从所述第二临时栈中弹出两个元素,作为第四元素;
    利用所述运算符和所述第四元素计算出第四结果,并将所述第四结果放入所述第二临时栈,然后转至所述第四遍历步骤;
    当所述后缀表达式的所有元素均经过了一次遍历,将所述第二临时栈中的第一个元素弹出,作为对所述规则文本的最终运算结果。
  7. 一种基于逆波兰表达式的规则处理装置,其中,所述装置包括:
    定义模块,被配置为定义并初始化结果栈、第一临时栈和第二临时栈;
    分词模块,被配置为当接收到规则文本,对所述规则文本进行分词,得到前缀表达式,所述前缀表达式包括多个分词结果元素;
    第一遍历模块,被配置为按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素;
    第二遍历模块,被配置为按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的 结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,其中,所述第二出入栈操作与所述第二临时栈对应。
  8. 根据权利要求7所述的基于逆波兰表达式的规则处理装置,其中,所述定义并初始化结果栈、第一临时栈和第二临时栈包括:
    分别为结果栈、第一临时栈和第二临时栈申请内存空间。
  9. 一种计算机可读程序介质,其中,其存储有计算机程序指令,当所述计算机程序指令被计算机执行时,使计算机执行实现如下方法:
    定义并初始化结果栈、第一临时栈和第二临时栈;
    当接收到规则文本,对所述规则文本进行分词,得到前缀表达式,所述前缀表达式包括多个分词结果元素;
    按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素;
    按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,其中,所述第二出入栈操作与所述第二临时栈对应。
  10. 根据权利要求9所述的计算机可读程序介质,其中,所述定义并初始化结果栈、第一临时栈和第二临时栈包括:
    分别为结果栈、第一临时栈和第二临时栈申请内存空间。
  11. 根据权利要求9所述的计算机可读程序介质,其中,所述规则文本为布尔型规则,所述按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,包括:
    执行第一遍历步骤,所述第一遍历步骤包括:按照从左至右的顺序获取第一个分词结果元素,作为当前分词结果元素;
    若当前分词结果元素为左小括号,则将所述当前分词结果元素放入所述第一临时栈并转至所述第一遍历步骤;
    若当前分词结果元素为左大括号,则将所述当前分词结果元素分别放入所述结果栈和所述第一临时栈并转至所述第一遍历步骤;
    若当前分词结果元素为数值类型、参数类型、字符类型中的一种,则将所述当前分词结果元素放入所述结果栈并转至所述第一遍历步骤;
    若当前分词结果元素为右大括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
    若当前分词结果元素为空格,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
    若当前分词结果元素为右小括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左小括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
    若当前分词结果元素的类型为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述运算符放入所述第一临时栈并转至所述第一 遍历步骤;
    若所述优先级大于或等于0,则将所述运算符放入所述结果栈并将所述第一临时栈的元素依次弹出,放入所述结果栈,直到上次从所述第一临时栈弹出的元素为右大括号或者所述运算符的优先级大于下次要从所述第一临时栈弹出的元素的优先级,然后转至所述第一遍历步骤;
    否则,将所述当前分词结果元素放入所述第一临时栈,然后转至所述第一遍历步骤;
    当所述前缀表达式的所有分词结果元素均经过了一次遍历,将所述第一临时栈中的元素依次弹出,放入所述结果栈,并将所述结果栈中的元素依次弹出,得到后缀表达式。
  12. 根据权利要求9所述的计算机可读程序介质,其中,所述规则文本为数值型规则,所述按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,包括:
    执行第二遍历步骤,所述第二遍历步骤包括:按照从左至右的顺序获取第一个分词结果元素,作为当前分词结果元素;
    若当前分词结果元素为左小括号,则将所述当前分词结果元素放入所述第一临时栈并转至所述第二遍历步骤;
    若当前分词结果元素为左大括号,则将所述当前分词结果元素分别放入所述结果栈和所述第一临时栈并转至所述第二遍历步骤;
    若当前分词结果元素为数值类型或者参数类型,则将所述当前分词结果元素放入所述结果栈并转至所述第二遍历步骤;
    若当前分词结果元素为右大括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
    若当前分词结果元素为空格,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
    若当前分词结果元素为右小括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左小括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
    若当前分词结果元素的类型为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述运算符放入所述第一临时栈并转至所述第二遍历步骤;
    若所述优先级大于或等于0,则将所述运算符放入所述结果栈并将所述第一临时栈的元素依次弹出,放入所述结果栈,直到上次从所述第一临时栈弹出的元素为右大括号或者所述运算符的优先级大于下次要从所述第一临时栈弹出的元素的优先级,然后转至所述第二遍历步骤;
    否则,将所述当前分词结果元素放入所述第一临时栈,然后转至所述第二遍历步骤;
    当所述前缀表达式的所有分词结果元素均经过了一次遍历,将所述第一临时栈中的元素依次弹出,放入所述结果栈,并将所述结果栈中的元素依次弹出,得到后缀表达式。
  13. 根据权利要求9或11所述的计算机可读程序介质,其中,所述规则文 本为布尔型规则,所述按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,包括:
    执行第三遍历步骤,所述第三遍历步骤包括:按照从左至右的顺序获取所述后缀表达式的第一个元素,作为当前元素;
    若当前元素为字符串或左大括号,则将所述当前元素放入所述第二临时栈并转至所述第三遍历步骤;
    若当前元素为数值类型,则将所述当前元素放入所述第二临时栈并转至所述第三遍历步骤;
    若当前元素为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述第二临时栈中的元素依次弹出,作为第一元素,直至下次要弹出的元素为左大括号;
    利用所述运算符和所述第一元素计算出第一结果,并将所述第一结果放入所述第二临时栈,然后转至所述第三遍历步骤;
    若所述优先级大于或等于0,则从所述第二临时栈中弹出两个元素,作为第二元素;
    利用所述运算符和所述第二元素计算出第二结果,并将所述第二结果放入所述第二临时栈,然后转至所述第三遍历步骤;
    当所述后缀表达式的所有元素均经过了一次遍历,将所述第二临时栈中的第一个元素弹出,作为对所述规则文本的最终运算结果。
  14. 根据权利要求9或12所述的计算机可读程序介质,其中,所述规则文本为数值型规则,所述按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,包括:
    执行第四遍历步骤,所述第四遍历步骤包括:按照从左至右的顺序获取所述后缀表达式的第一个元素,作为当前元素;
    若当前元素为字符串或左大括号,则将所述当前元素放入所述第二临时栈并转至所述第四遍历步骤;
    若当前元素为数值类型,则将所述当前元素放入所述第二临时栈并转至所述第四遍历步骤;
    若当前元素为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述第二临时栈中的元素依次弹出,作为第三元素,直至下次要弹出的元素为左大括号;
    利用所述运算符和所述第三元素计算出第三结果,并将所述第三结果放入所述第二临时栈,然后转至所述第四遍历步骤;
    若所述优先级大于0,则从所述第二临时栈中弹出两个元素,作为第四元素;
    利用所述运算符和所述第四元素计算出第四结果,并将所述第四结果放入所述第二临时栈,然后转至所述第四遍历步骤;
    当所述后缀表达式的所有元素均经过了一次遍历,将所述第二临时栈中的第一个元素弹出,作为对所述规则文本的最终运算结果。
  15. 一种电子设备,其中,所述电子设备包括:
    处理器;
    存储器,所述存储器上存储有计算机可读指令,所述计算机可读指令被所述处理器执行时,实现如下方法:
    定义并初始化结果栈、第一临时栈和第二临时栈;
    当接收到规则文本,对所述规则文本进行分词,得到前缀表达式,所述前缀表达式包括多个分词结果元素;
    按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,其中,所述第一出入栈操作与所述结果栈或所述第一临时栈对应,所述后缀表达式包括多个元素;
    按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,其中,所述第二出入栈操作与所述第二临时栈对应。
  16. 根据权利要求15所述的电子设备,其中,所述定义并初始化结果栈、第一临时栈和第二临时栈包括:
    分别为结果栈、第一临时栈和第二临时栈申请内存空间。
  17. 根据权利要求15所述的电子设备,其中,所述规则文本为布尔型规则,所述按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,包括:
    执行第一遍历步骤,所述第一遍历步骤包括:按照从左至右的顺序获取第一个分词结果元素,作为当前分词结果元素;
    若当前分词结果元素为左小括号,则将所述当前分词结果元素放入所述第一临时栈并转至所述第一遍历步骤;
    若当前分词结果元素为左大括号,则将所述当前分词结果元素分别放入所述结果栈和所述第一临时栈并转至所述第一遍历步骤;
    若当前分词结果元素为数值类型、参数类型、字符类型中的一种,则将所述当前分词结果元素放入所述结果栈并转至所述第一遍历步骤;
    若当前分词结果元素为右大括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
    若当前分词结果元素为空格,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
    若当前分词结果元素为右小括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左小括号弹出并放入所述结果栈,然后转至所述第一遍历步骤;
    若当前分词结果元素的类型为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述运算符放入所述第一临时栈并转至所述第一遍历步骤;
    若所述优先级大于或等于0,则将所述运算符放入所述结果栈并将所述第一临时栈的元素依次弹出,放入所述结果栈,直到上次从所述第一临时栈弹出的元素为右大括号或者所述运算符的优先级大于下次要从所述第一临时栈弹出的元素的优先级,然后转至所述第一遍历步骤;
    否则,将所述当前分词结果元素放入所述第一临时栈,然后转至所述第一遍历步骤;
    当所述前缀表达式的所有分词结果元素均经过了一次遍历,将所述第一临时栈中的元素依次弹出,放入所述结果栈,并将所述结果栈中的元素依次弹出,得到后缀表达式。
  18. 根据权利要求15所述的电子设备,其中,所述规则文本为数值型规则,所述按照从左至右的顺序遍历所述前缀表达式,根据每一次遍历得到的分词结果元素的类型执行相应的对分词结果元素的第一出入栈操作,以得到后缀表达式,包括:
    执行第二遍历步骤,所述第二遍历步骤包括:按照从左至右的顺序获取第一个分词结果元素,作为当前分词结果元素;
    若当前分词结果元素为左小括号,则将所述当前分词结果元素放入所述第一临时栈并转至所述第二遍历步骤;
    若当前分词结果元素为左大括号,则将所述当前分词结果元素分别放入所述结果栈和所述第一临时栈并转至所述第二遍历步骤;
    若当前分词结果元素为数值类型或者参数类型,则将所述当前分词结果元素放入所述结果栈并转至所述第二遍历步骤;
    若当前分词结果元素为右大括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
    若当前分词结果元素为空格,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左大括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
    若当前分词结果元素为右小括号,则将所述第一临时栈中的元素依次弹出,放入所述结果栈,直至将所述第一临时栈中的左小括号弹出并放入所述结果栈,然后转至所述第二遍历步骤;
    若当前分词结果元素的类型为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述运算符放入所述第一临时栈并转至所述第二遍历步骤;
    若所述优先级大于或等于0,则将所述运算符放入所述结果栈并将所述第一临时栈的元素依次弹出,放入所述结果栈,直到上次从所述第一临时栈弹出的元素为右大括号或者所述运算符的优先级大于下次要从所述第一临时栈弹出的元素的优先级,然后转至所述第二遍历步骤;
    否则,将所述当前分词结果元素放入所述第一临时栈,然后转至所述第二遍历步骤;
    当所述前缀表达式的所有分词结果元素均经过了一次遍历,将所述第一临时栈中的元素依次弹出,放入所述结果栈,并将所述结果栈中的元素依次弹出,得到后缀表达式。
  19. 根据权利要求15或17所述的电子设备,其中,所述规则文本为布尔型规则,所述按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,包括:
    执行第三遍历步骤,所述第三遍历步骤包括:按照从左至右的顺序获取所述后缀表达式的第一个元素,作为当前元素;
    若当前元素为字符串或左大括号,则将所述当前元素放入所述第二临时栈并转至所述第三遍历步骤;
    若当前元素为数值类型,则将所述当前元素放入所述第二临时栈并转至所述第三遍历步骤;
    若当前元素为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述第二临时栈中的元素依次弹出,作为第一元素,直至下次要弹出的元素为左大括号;
    利用所述运算符和所述第一元素计算出第一结果,并将所述第一结果放入所述第二临时栈,然后转至所述第三遍历步骤;
    若所述优先级大于或等于0,则从所述第二临时栈中弹出两个元素,作为第二元素;
    利用所述运算符和所述第二元素计算出第二结果,并将所述第二结果放入所述第二临时栈,然后转至所述第三遍历步骤;
    当所述后缀表达式的所有元素均经过了一次遍历,将所述第二临时栈中的第一个元素弹出,作为对所述规则文本的最终运算结果。
  20. 根据权利要求15或18所述的电子设备,其中,所述规则文本为数值型规则,所述按照从左至右的顺序遍历所述后缀表达式,根据每一次遍历得到的元素的类型执行相应的对元素或基于至少两个元素运算得到的结果的第二出入栈操作,以得到对所述规则文本的最终运算结果,包括:
    执行第四遍历步骤,所述第四遍历步骤包括:按照从左至右的顺序获取所述后缀表达式的第一个元素,作为当前元素;
    若当前元素为字符串或左大括号,则将所述当前元素放入所述第二临时栈并转至所述第四遍历步骤;
    若当前元素为数值类型,则将所述当前元素放入所述第二临时栈并转至所述第四遍历步骤;
    若当前元素为运算符,确定所述运算符的优先级;
    若所述优先级小于0,则将所述第二临时栈中的元素依次弹出,作为第三元素,直至下次要弹出的元素为左大括号;
    利用所述运算符和所述第三元素计算出第三结果,并将所述第三结果放入所述第二临时栈,然后转至所述第四遍历步骤;
    若所述优先级大于0,则从所述第二临时栈中弹出两个元素,作为第四元素;
    利用所述运算符和所述第四元素计算出第四结果,并将所述第四结果放入所述第二临时栈,然后转至所述第四遍历步骤;
    当所述后缀表达式的所有元素均经过了一次遍历,将所述第二临时栈中的第一个元素弹出,作为对所述规则文本的最终运算结果。
PCT/CN2020/124732 2020-03-16 2020-10-29 规则处理方法、装置、介质及电子设备 WO2021184765A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010180995.X 2020-03-16
CN202010180995.XA CN111460815B (zh) 2020-03-16 2020-03-16 规则处理方法、装置、介质及电子设备

Publications (1)

Publication Number Publication Date
WO2021184765A1 true WO2021184765A1 (zh) 2021-09-23

Family

ID=71682850

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/124732 WO2021184765A1 (zh) 2020-03-16 2020-10-29 规则处理方法、装置、介质及电子设备

Country Status (2)

Country Link
CN (1) CN111460815B (zh)
WO (1) WO2021184765A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115268936A (zh) * 2022-09-27 2022-11-01 之江实验室 一种用于计算图编译的优化方法及装置
CN115796166A (zh) * 2023-02-06 2023-03-14 华侨大学 一种智慧物流控制系统的正则表达式测试方法和系统

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111460815B (zh) * 2020-03-16 2022-04-01 平安科技(深圳)有限公司 规则处理方法、装置、介质及电子设备
CN113760367B (zh) * 2021-09-10 2024-05-14 深圳平安医疗健康科技服务有限公司 一种数据处理方法、装置、电子设备以及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140236322A1 (en) * 2008-06-26 2014-08-21 Invensys Systems, Inc. Multi-mode editor for configuring process control blocks including both logical functions and arithmetic computations
CN105677528A (zh) * 2016-01-06 2016-06-15 长园共创电力安全技术股份有限公司 通过逆波兰表达式对五防逻辑表达式进行校验的方法
CN109766524A (zh) * 2018-12-28 2019-05-17 重庆邮电大学 一种并购重组类公告信息抽取方法及系统
CN110489965A (zh) * 2018-07-14 2019-11-22 北京数安鑫云信息技术有限公司 一种深度威胁识别实时引擎的实现方法及系统
CN111460815A (zh) * 2020-03-16 2020-07-28 平安科技(深圳)有限公司 规则处理方法、装置、介质及电子设备

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
FR2896601B1 (fr) * 2006-01-24 2008-08-15 Atmel Nantes Sa Dispositif de traitement en notation polonaise inversee, et circuit integre electronique comprenant un tel dispositif de traitement.
CN101692585B (zh) * 2009-10-16 2011-08-31 国电南京自动化股份有限公司 变电站自动化系统的防误闭锁系统
GB2502565A (en) * 2012-05-31 2013-12-04 Ibm Providing event-processing rules in an event-processing environment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140236322A1 (en) * 2008-06-26 2014-08-21 Invensys Systems, Inc. Multi-mode editor for configuring process control blocks including both logical functions and arithmetic computations
CN105677528A (zh) * 2016-01-06 2016-06-15 长园共创电力安全技术股份有限公司 通过逆波兰表达式对五防逻辑表达式进行校验的方法
CN110489965A (zh) * 2018-07-14 2019-11-22 北京数安鑫云信息技术有限公司 一种深度威胁识别实时引擎的实现方法及系统
CN109766524A (zh) * 2018-12-28 2019-05-17 重庆邮电大学 一种并购重组类公告信息抽取方法及系统
CN111460815A (zh) * 2020-03-16 2020-07-28 平安科技(深圳)有限公司 规则处理方法、装置、介质及电子设备

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115268936A (zh) * 2022-09-27 2022-11-01 之江实验室 一种用于计算图编译的优化方法及装置
CN115268936B (zh) * 2022-09-27 2022-12-27 之江实验室 一种用于计算图编译的优化方法及装置
CN115796166A (zh) * 2023-02-06 2023-03-14 华侨大学 一种智慧物流控制系统的正则表达式测试方法和系统

Also Published As

Publication number Publication date
CN111460815A (zh) 2020-07-28
CN111460815B (zh) 2022-04-01

Similar Documents

Publication Publication Date Title
WO2021184765A1 (zh) 规则处理方法、装置、介质及电子设备
US10862979B2 (en) Techniques for supporting remote micro-services as native functions in spreadsheet applications
US11238099B2 (en) Method and device for obtaining answer, and computer device
US20230004721A1 (en) Method for training semantic representation model, device and storage medium
US20230035910A1 (en) Method, system and device for parallel processing of data, and storage medium
WO2021072863A1 (zh) 文本相似度计算方法、装置、电子设备及计算机可读存储介质
CN108921552A (zh) 一种验证证据的方法及装置
CN108415939A (zh) 基于人工智能的对话处理方法、装置、设备及计算机可读存储介质
WO2021184547A1 (zh) 对话机器人意图语料生成方法、装置、介质及电子设备
JP7291764B2 (ja) イーサリアム仮想マシンのトランザクション処理方法、装置、機器、プログラムおよび媒体
US11176087B2 (en) Efficient handling of bi-directional data
CN111078228A (zh) 网页到小程序的转换方法、装置、服务器及存储介质
US8489537B2 (en) Segmenting sequential data with a finite state machine
WO2021072864A1 (zh) 文本相似度获取方法、装置、电子设备及计算机可读存储介质
CN110765069B (zh) 一种数据迁移方法、装置及系统
US20230141932A1 (en) Method and apparatus for question answering based on table, and electronic device
WO2020252925A1 (zh) 用户特征群中用户特征寻优方法、装置、电子设备及计算机非易失性可读存储介质
WO2023206859A1 (zh) Cpu芯片仿真加速中针对无mmu环境的内存状态恢复方法
WO2024036662A1 (zh) 一种基于数据采样的并行图规则挖掘方法及装置
CN109241164A (zh) 一种数据处理方法、装置、服务器及存储介质
WO2021217915A1 (zh) 人机对话方法、装置、计算机设备和存储介质
CN110245342A (zh) 文本匹配的方法、装置和存储介质
CN113495651B (zh) 一种窗口控制方法和装置
CN111178065B (zh) 分词识别词库构建方法、中文分词方法和装置
CN109656728A (zh) 页面数据操作方法、装置、设备及介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20925519

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20925519

Country of ref document: EP

Kind code of ref document: A1