Text recognition method, text recognition device and electronic device based on regular matching

By converting the text represented by the variable-length code into target digits and using the finite state automata for matching processing, the problem of resource waste in the prior art is solved and more efficient text recognition is achieved.

CN112580345BActive Publication Date: 2025-03-07CHENGDU WANGAN TECH DEV CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202011576184.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-28
Publication Date
2025-03-07
Estimated Expiration
2040-12-28

Smart Images

  • Figure CN112580345B_ABST
    Figure CN112580345B_ABST
Patent Text Reader

Abstract

The text recognition method, text recognition device and electronic device based on regular matching provided by the present application relate to the field of text recognition technology. In the present application, first, the text to be recognized is obtained, wherein the text to be recognized includes at least one character to be recognized represented based on a variable-length code. Secondly, a target character to be recognized is determined among the at least one character to be recognized, and the target character to be recognized is converted into a target number in the target base. Then, the target number is matched based on a determined finite state automaton, wherein the determined finite state automaton is obtained based on the conversion process of the target regular expression, and the character corresponding to each transfer edge in the determined finite state automaton is represented based on the target base. Finally, if the target number fails to match, the matching process of the text to be recognized is stopped. Based on the above method, the problem of resource waste existing in the existing text recognition technology can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of text recognition, and in particular to a text recognition method, a text recognition device and an electronic device based on regular matching. Background Art

[0002] Regular matching refers to the process of determining whether the text to be matched conforms to the specified regular expression. Before matching, a deterministic finite automaton (DFA) is generally created based on the regular expression. The deterministic finite automaton consists of state nodes and transition edges. Each state node has one or more transition edges, which indicate the next state to be transferred to after entering a character in the current state. In this way, each character of the text to be matched is placed in the deterministic finite automaton one by one, starting from the initial state node of the deterministic finite automaton. Each time a character is placed, it is compared with the character on the transition edge of the current state node to obtain the next state node to jump to.

[0003] Among them, when using C++ code to describe a deterministic finite automaton, State is defined to represent the state node, each state node may contain multiple transfer edges, and the structure Edge is defined to represent the transfer edge. In Edge, a variable accept_character is used to represent the input character, and a variable next_state is used to represent the sequence number of the next state node to jump to. The accept_character of multiple Edges contained in a State is different. When matching, after entering a character, it is necessary to compare the character with which Edge's accept_character of the current State is the same, and jump to the next_state pointed to by this Edge. When the characters in the text and rules are represented by fixed-length encoding, it is easy to enter one character at a time. However, when the characters in the text and rules are represented by variable-length encoding, such as UTF-8 encoding, a character may be 1, 2, 3 or 4 bytes, and accept_character can no longer be directly defined as char or wchar_t type. Based on this, it is necessary to convert the UTF-8 regular expression and text content into unicode code representation in advance before regular matching.

[0004] However, the inventors have discovered through research that there is a problem of waste of resources in the above technology. Summary of the invention

[0005] In view of this, the purpose of the present application is to provide a text recognition method, a text recognition device and an electronic device based on regular matching, so as to improve the problem of resource waste in the existing text recognition technology.

[0006] To achieve the above purpose, the embodiment of the present application adopts the following technical solution:

[0007] A text recognition method based on regular expression matching, comprising:

[0008] Acquire a text to be recognized, wherein the text to be recognized includes at least one character to be recognized, and the character to be recognized is represented based on a variable-length encoding;

[0009] Determine a target character to be recognized among the at least one character to be recognized, and convert the target character to be recognized into a target number in a target base;

[0010] The target number is matched based on a pre-obtained deterministic finite state automaton, wherein the deterministic finite state automaton is obtained based on processing a target regular expression, and the character corresponding to each transfer edge in the deterministic finite state automaton is represented based on the target base;

[0011] If the target number fails to match, the matching process for the text to be recognized is stopped.

[0012] In a preferred embodiment of the present application, in the above-mentioned text recognition method based on regular expression matching, there are multiple characters to be recognized, and the method further includes:

[0013] Step a, if the target number matches successfully, then a new target character to be recognized is determined from other characters to be recognized other than the target character to be recognized;

[0014] Step b, converting the new target character to be recognized into a new target number in the target base, and performing matching processing on the new target number based on the determined finite state automaton;

[0015] Step c, if the new target number matches successfully, then a new target character to be recognized is determined again from the new target number and other characters to be recognized other than the target character to be recognized, and step b is executed again based on the new target character to be recognized;

[0016] Step d: If the new target number fails to match, stop matching the text to be recognized.

[0017] In a preferred embodiment of the present application, in the above-mentioned text recognition method based on regular expression matching, the step of converting the target character to be recognized into a target number in the target base comprises:

[0018] Determine the byte length of the target character to be recognized;

[0019] Based on the conversion rule corresponding to the byte length, the target character to be recognized is converted into a target number in a target base.

[0020] In a preferred embodiment of the present application, in the above-mentioned text recognition method based on regular expression matching, the step of determining the byte length of the target character to be recognized includes:

[0021] Determine whether the target bit corresponding to the target character to be recognized is 0, wherein the target bit is the highest bit of the first byte of the target character to be recognized stored in binary form in the memory;

[0022] If the target bit is 0, the byte length of the target character to be recognized is determined to be 1;

[0023] If the target bit is 1, the byte length of the target character to be recognized is determined to be the target bit number of the target character to be recognized, wherein the target bit number is the number of consecutive 1 bits in the multi-bit binary data of the target character to be recognized stored in binary form in the memory.

[0024] In a preferred embodiment of the present application, in the above-mentioned text recognition method based on regular matching, the step of converting the target character to be recognized into a target number in the target base based on the conversion rule corresponding to the byte length includes:

[0025] Determine whether the byte length is greater than a preset byte length;

[0026] If the byte length is less than or equal to the preset byte length, converting the first byte of the target character to be recognized stored in the memory in binary form into the target base to obtain a target number corresponding to the target character to be recognized;

[0027] If the byte length is greater than the preset byte length, binary data deletion is performed on each byte of the target character to be recognized that is stored in binary form in the memory, and the retained binary data is converted into the target base to obtain the target number corresponding to the target character to be recognized.

[0028] In a preferred embodiment of the present application, in the above-mentioned text recognition method based on regular expression matching, the step of performing binary data deletion processing on each byte of the target character to be recognized stored in binary form in the memory includes:

[0029] For the first byte of the target character to be recognized stored in the memory in binary form, the highest target length bit binary data in the first byte is deleted, wherein the target length bit is equal to the byte length plus 1;

[0030] For each byte other than the first byte of the target character to be recognized stored in the memory in binary form, the most significant 2 bits of binary data in the byte are deleted.

[0031] In a preferred embodiment of the present application, in the above-mentioned text recognition method based on regular expression matching, a step of determining the finite state automaton is further included, and the step includes:

[0032] Determine whether the target regular expression has a target operator, wherein the target operator is used to perform a AND operation;

[0033] If the target regular expression has the target operator, convert each character corresponding to the target operator into the target base to obtain a target base number corresponding to each character;

[0034] Performing interval conversion processing based on the target base number corresponding to each character to obtain a corresponding target interval, and updating the target regular expression based on the target interval to obtain an updated target regular expression;

[0035] Based on the updated target regular expression, a corresponding deterministic finite state automaton is generated.

[0036] The present application also provides a text recognition device based on regular expression matching, including:

[0037] A text acquisition module, used for acquiring a text to be recognized, wherein the text to be recognized includes at least one character to be recognized, and the character to be recognized is represented based on a variable-length encoding;

[0038] A character conversion module, used for determining a target character to be recognized among the at least one character to be recognized, and converting the target character to be recognized into a target number in a target base;

[0039] A digital matching module, used for matching the target digital number based on a pre-obtained deterministic finite state automaton, wherein the deterministic finite state automaton is obtained based on processing a target regular expression, and the character corresponding to each transfer edge in the deterministic finite state automaton is represented based on the target base;

[0040] The matching stop module is used to stop matching the text to be recognized when the target number fails to match.

[0041] In a preferred embodiment of the present application, in the text recognition device based on regular expression matching, the character conversion module includes:

[0042] A byte length determination submodule, used to determine the byte length of the target character to be recognized;

[0043] The character conversion submodule to be recognized is used to convert the target character to be recognized into a target number in a target base based on the conversion rule corresponding to the byte length.

[0044] Based on the above, an embodiment of the present application further provides an electronic device, including:

[0045] Memory for storing computer programs;

[0046] The processor connected to the memory is used to execute the computer program stored in the memory to implement the above-mentioned text recognition method based on regular matching.

[0047] The text recognition method, text recognition device and electronic device based on regular matching provided by the present application convert a target character to be recognized in at least one character to be recognized included in the text to be recognized into a target number in the target base, so that the target number can be matched based on a predetermined finite state automaton, and then, when the match fails, the matching process of the text to be recognized is stopped. In this way, the problem of directly converting all the characters to be recognized into target numbers, which results in the need to occupy more memory resources, can be avoided, thereby improving the problem of resource waste in the existing text recognition technology, and having high practical value.

[0048] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 A structural block diagram of an electronic device provided in an embodiment of the present application.

[0050] Figure 2 A flowchart of the steps included in the text recognition method based on regular expression matching provided in an embodiment of the present application.

[0051] Figure 3 for Figure 2 Schematic diagram of the flow chart of the sub-steps included in step S120.

[0052] Figure 4 The text recognition method based on regular expression matching provided in the embodiment of the present application includes a flowchart of the steps of obtaining and determining a finite state automaton.

[0053] Figure 5 A flowchart of other steps included in the text recognition method based on regular expression matching provided in an embodiment of the present application.

[0054] Figure 6 A block diagram of the functional modules included in the text recognition device based on regular expression matching provided in an embodiment of the present application.

[0055] Icons: 10 - electronic device; 12 - memory; 14 - processor; 100 - text recognition device based on regular matching; 110 - text acquisition module; 120 - character conversion module; 130 - digital matching module; 140 - matching stop module. DETAILED DESCRIPTION

[0056] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.

[0057] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0058] like Figure 1 As shown, an embodiment of the present application provides an electronic device 10, which may include a memory 12, a processor 14 and a text recognition device 100 based on regular matching.

[0059] The memory 12 and the processor 14 are electrically connected directly or indirectly to realize data transmission or interaction. For example, they can be electrically connected to each other through one or more communication buses or signal lines. The regular matching-based text recognition device 100 includes at least one software function module that can be stored in the memory 12 in the form of software or firmware. The processor 14 is used to execute an executable computer program stored in the memory 12, for example, the software function module and computer program included in the regular matching-based text recognition device 100, so as to realize the regular matching-based text recognition method provided in the embodiment of the present application.

[0060] Optionally, the memory 12 can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), etc.

[0061] Furthermore, the processor 14 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), a system on chip (SoC), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0062] Understandably, Figure 1 The structure shown is for illustration only. The electronic device 10 may also include Figure 1 More or fewer components as shown, or with Figure 1 The different configurations shown, for example, may also include a communication unit for exchanging information with other devices (for example, when the electronic device 10 is a background server, the other device may be a terminal device such as a mobile phone or a computer) (for example, the communication unit may be used to obtain the text to be recognized from the other device, or the recognition result of the text to be recognized may be sent to the other device).

[0063] Combination Figure 2 The embodiment of the present application further provides a text recognition method based on regular expression matching, which can be applied to the above electronic device 10. The method steps defined in the process related to the text recognition method can be implemented by the electronic device 10.

[0064] The following will Figure 2 The specific process shown is explained in detail.

[0065] Step S110, obtaining the text to be recognized.

[0066] In this embodiment, when it is necessary to recognize the text to be recognized, the electronic device 10 can obtain the text to be recognized. The text to be recognized may include at least one character to be recognized, and the character to be recognized may be represented based on variable-length coding (variable-length coding refers to coding in which the length of a non-regular operation code is not fixed and is scattered at different positions of an instruction word).

[0067] Step S120, determining a target character to be recognized from the at least one character to be recognized, and converting the target character to be recognized into a target number in a target base.

[0068] In this embodiment, after acquiring the text to be recognized based on step S110, the electronic device 10 can determine a character to be recognized from at least one character to be recognized included in the text to be recognized, and use the character to be recognized as a target character to be recognized, and then convert the target character to be recognized into a target number in a target system (the target system is not binary).

[0069] Step S130, performing matching processing on the target number based on a predetermined deterministic finite state automaton.

[0070] In this embodiment, after obtaining the target number based on step S120, the electronic device 10 can perform matching processing on the target number based on a predetermined determined finite state automaton, so as to obtain a matching result corresponding to the target number.

[0071] The finite state automaton is determined based on processing the target regular expression, and the characters corresponding to each transfer edge in the finite state automaton are represented based on the target base. If the matching result is that the target number fails to match, step S140 may be executed.

[0072] Step S140, stop matching the text to be recognized.

[0073] In this embodiment, after determining that the target number fails to match based on step S130, the electronic device 10 may stop matching the text to be recognized.

[0074] Based on the above method, since the matching process of the text to be recognized is stopped when the target number corresponding to the target character to be recognized fails, the problem of directly converting all the characters to be recognized into target numbers and occupying more memory resources can be avoided, thereby improving the problem of resource waste in the existing text recognition technology and having high practical value.

[0075] Firstly, it should be noted that for step S110, when the characters to be recognized in the text to be recognized are represented based on variable-length coding, the specific coding rules are not restricted.

[0076] For example, in an alternative example, the character to be recognized may be represented based on UTF-8 encoding (a standard mechanism of Unicode for converting wide character values ​​into byte streams).

[0077] Secondly, it should be noted that for step S120, the specific method of determining a target character to be recognized is not limited and can be selected according to actual application requirements.

[0078] For example, in an alternative example, a character to be recognized may be randomly determined from the at least one character to be recognized as a target character to be recognized.

[0079] For another alternative example, a character to be recognized may be determined according to the sequence of each character to be recognized in the at least one character to be recognized, such as taking the first (first) character to be recognized as the target character to be recognized.

[0080] Furthermore, it should be noted that for step S120, the specific method of converting the target character to be recognized into the target number in the target base is not limited and can be selected according to actual needs.

[0081] For example, in an alternative example, the target character to be recognized may be converted according to a predetermined conversion rule to obtain a corresponding target number.

[0082] For example, in another alternative example, combining Figure 3 Step S120 may include step S121 and step S122, the specific contents of which are described as follows.

[0083] Step S121, determining the byte length of the target character to be recognized.

[0084] In this embodiment, after the text to be recognized is obtained based on step S110 and the target character to be recognized is determined based on the aforementioned steps, the byte length of the target character to be recognized can be determined.

[0085] Step S122, based on the conversion rule corresponding to the byte length, convert the target character to be recognized into a target number in a target base.

[0086] In this embodiment, after the byte length is determined based on step S121, the target character to be recognized can be converted into a target number in a target base based on the conversion rule corresponding to the byte length. In this way, the target characters to be recognized with different byte lengths can be converted in a targeted manner, thereby ensuring that the obtained target number can effectively represent the target character to be recognized.

[0087] Optionally, in the above example, the specific method for determining the byte length based on step S121 is not limited and can be selected according to actual application requirements.

[0088] For example, in an alternative example, in order to make the determined byte length have a higher reliability, thereby ensuring that the conversion rule corresponding to the byte length can perform effective conversion processing, step S121 may include the following steps:

[0089] First, determine whether the target bit corresponding to the target character to be recognized is 0, wherein the target bit is the highest bit of the first byte of the target character to be recognized stored in binary form in the memory; secondly, if the target bit is 0, determine the byte length of the target character to be recognized to be 1; then, if the target bit is 1, determine the byte length of the target character to be recognized to be the target number of bits of the target character to be recognized, wherein the target number of bits is the number of bits that are consecutively 1 in the multi-bit binary data of the target character to be recognized stored in binary form in the memory.

[0090] For the above steps, in a specific application example, if the target character to be recognized is "a", "a" is represented in binary form in the memory as "01100001", then the highest bit of the first byte of the target character to be recognized is 0, so that the determined byte length is 1. If the target character to be recognized is "I", "I" is represented in binary form in the memory as "11100110 10001000 10010001", then the highest bit of the first byte of the target character to be recognized is 1, and starting from the highest bit, the number of bits that are continuously 1 is 3, so that the determined byte length is 3.

[0091] Optionally, in the above example, the specific method of converting the target character to be recognized into a target number in the target base based on step S122 is not limited and can be selected according to actual application requirements.

[0092] For example, in an alternative example, in order to ensure that the target number obtained by conversion can effectively represent the target character to be recognized, step S122 may include the following steps:

[0093] First, determine whether the byte length is greater than the preset byte length; if the byte length is less than or equal to the preset byte length, convert the first byte of the target character to be recognized stored in binary form in the memory into the target base, and obtain the target number corresponding to the target character to be recognized; if the byte length is greater than the preset byte length, perform binary data deletion processing on each byte of the target character to be recognized stored in binary form in the memory, and convert the retained binary data into the target base, and obtain the target number corresponding to the target character to be recognized.

[0094] For the above steps, in a specific application example, such as the aforementioned example, the target character to be recognized is represented in binary form in the memory as "01100001", and the corresponding byte length is 1. If the preset byte length is 1, the first byte "01100001" is converted to the target base, such as decimal, to obtain the target number 97.

[0095] That is, the number "97" can be used to represent the character "a".

[0096] It is understandable that when the byte length is greater than the preset byte length, the specific method of performing binary data deletion processing is not limited and can be selected according to actual application requirements.

[0097] For example, in an alternative example, binary data deletion processing may be performed on each byte of the target character to be recognized stored in binary form in the memory based on the following steps:

[0098] First, for the first byte of the target character to be recognized stored in binary form in the memory, the highest target length bit of binary data in the first byte is deleted, where the target length bit is equal to the byte length plus 1; secondly, for each byte other than the first byte of the target character to be recognized stored in binary form in the memory, the highest 2 bits of binary data in the byte are deleted.

[0099] For the above steps, in a specific application example, such as the aforementioned example, the target character to be recognized is represented in binary form in the memory as "11100110 10001000 10010001", and the corresponding byte length is 3. If the byte preset length is 1, that is, the byte length is greater than the byte preset length, then the target length can be 3+1=4, so that the highest 4 bits of binary data in the first byte "11100110" can be deleted to obtain "0110"; the highest 2 bits of binary data in the second byte "10001000" can be deleted to obtain "001000"; the highest 2 bits of binary data in the second byte "10010001" can be deleted to obtain "010001".

[0100] Based on this, “converting the retained binary data into the target base” means converting “0110 001000010001” into the target base, such as converting it into decimal, and obtaining the target number 25105.

[0101] That is, the number "25105" can be used to represent the character "I".

[0102] Thirdly, it should be noted that, in order to ensure the effective execution of step S130, it is necessary to first obtain the finite state automaton. Figure 4 The step of obtaining the determined finite state automaton may include step S151, step S152, step S153 and step S154, the specific contents of which are described as follows.

[0103] Step S151, determining whether the target regular expression has a target operator.

[0104] In this embodiment, before performing the matching process based on step S130, it is necessary to first determine whether the target regular expression used for the matching process has a target operator.

[0105] The target operator is used for performing a AND operation, for example, the metacharacter "." indicates that all characters in the alphabet except the line break character are used for performing a AND operation. When the target regular expression has the target operator, step S152 may be executed.

[0106] Step S152, converting each character corresponding to the target operator into the target base, and obtaining a target base number corresponding to each character.

[0107] In this embodiment, since the target character to be recognized has been converted into a target number in the target base in step S120, in order to effectively carry out the matching process, when it is determined based on step S151 that the target regular expression has the target operator, each character corresponding to the target operator can be converted into the target base. In this way, the target base number corresponding to each character can be obtained.

[0108] Step S153 , performing interval conversion processing based on the target base number corresponding to each character to obtain the corresponding target interval, and updating the target regular expression based on the target interval to obtain an updated target regular expression.

[0109] In this embodiment, after obtaining the target base number corresponding to each character based on step S152, interval conversion processing can be performed based on the target base number corresponding to each character to obtain the corresponding target interval. Then, the target regular expression is updated based on the target interval to obtain an updated target regular expression.

[0110] For example, for a single character "a" that is not continuous in value, the corresponding number "97" can be used as the upper and lower limits of the target interval, respectively, to obtain [97,97]. For another example, for multiple characters that are continuous in value and the relationship between the multiple characters is a AND operation, such as "a|b|c", it can be expressed as [97,99]. For another example, since the decimal data corresponding to the line feed character is "11", the metacharacter "." can be expressed as [0,10]∪[12,Max], where Max represents the maximum value in the corresponding alphabet, such as the maximum value of the ASCII code in the alphabet is 255.

[0111] Step S154: Generate a corresponding deterministic finite state automaton based on the updated target regular expression.

[0112] In this embodiment, after the updated target regular expression is obtained based on step S153, a corresponding determined finite state automatic expression may be generated based on the updated target regular expression.

[0113] Based on this, by using interval representation to process the union transport, it is possible to avoid the problem that when generating an automaton, more state nodes need to be configured due to the need to configure more transfer edges, thereby effectively avoiding the problem of the explosion of the number of state nodes.

[0114] Optionally, in the above example, the specific method of generating the corresponding determination finite state automaton based on step S154 is not limited and can be selected according to actual application requirements.

[0115] For example, in an alternative example, an NFA (non-deterministic finite state automaton, which is a finite state automaton that can have multiple possible next states for each state and input symbol pair) equivalent to the updated target regular expression can be constructed based on the Thompson construction method, and then the NFA can be converted into a DFA (i.e., a deterministic finite state automaton, which has a uniquely determined next possible state) based on the subset construction method.

[0116] Fourthly, it is also necessary to explain step S130 that, in the above example, after it is determined based on step S130 that the target number matches unsuccessfully, step S140 can be executed to stop matching the text to be recognized, thus avoiding the problem of waste of resources. If it is determined based on step S130 that the target number matches successfully, other characters to be recognized can continue to be matched to complete the recognition and matching of the text to be recognized.

[0117] Based on this, combined Figure 5 The text recognition method based on regular matching may further include step S160, step S170, step S180 and step S190, the specific contents of which are described as follows.

[0118] Step S160, determining a new target character to be recognized from other characters to be recognized other than the target character to be recognized.

[0119] In this embodiment, when the matching result obtained based on step S130 is that the target number is successfully matched, the electronic device 10 can select another character to be recognized other than the target character to be recognized from the multiple characters to be recognized included in the text to be recognized (for example, the next character to be recognized of the target character to be recognized, that is, if the target character to be recognized is the first character in the text to be recognized, the other character to be recognized is the second character in the text to be recognized), and determine the other character to be recognized as a new target character to be recognized.

[0120] Step S170, converting the new target character to be recognized into a new target number in the target base, and performing matching processing on the new target number based on the determined finite state automaton.

[0121] In this embodiment, after determining the new target character to be recognized based on step S160, the electronic device can convert the new target character to be recognized into a new target number in the target base, and then, the new target number can be matched based on the determined finite state automaton (wherein, the specific processing process can refer to the previous explanation of the relevant contents of step S120 and step S130, which will not be repeated here).

[0122] Furthermore, if the result of matching the new target number is that the new target number matches successfully, step S180 may be executed; otherwise, if the result of matching the new target number is that the new target number matches unsuccessfully, step S190 may be executed.

[0123] Step S180, determining a new target character to be recognized again from the new target character to be recognized and other characters to be recognized other than the target character to be recognized.

[0124] In this embodiment, after obtaining the result that the new target number is matched successfully based on step S170, the electronic device 10 can select the new target character to be recognized and other characters to be recognized other than the target character to be recognized from the multiple characters to be recognized included in the text to be recognized, and determine the other characters to be recognized as the new target character to be recognized. Then, step 170 can be performed again based on the new target character to be recognized, and the cycle is repeated. When the match is successful each time, the multiple characters to be recognized included in the text to be recognized can be matched.

[0125] Step S190, stop matching the text to be recognized.

[0126] In this embodiment, after obtaining the result that the new target number fails to match based on step S170, the electronic device 10 can stop matching the text to be recognized, so that other characters to be recognized do not need to be converted, effectively avoiding the problem of resource waste.

[0127] Combination Figure 6 The embodiment of the present application further provides a text recognition device 100 based on regular expression matching, which can be applied to the above electronic device 10. The text recognition device 100 based on regular expression matching can include a text acquisition module 110, a character conversion module 120, a number matching module 130 and a matching stop module 140.

[0128] The text acquisition module 110 can be used to acquire a text to be recognized, wherein the text to be recognized includes at least one character to be recognized, and the character to be recognized is represented based on a variable-length encoding. In this embodiment, the text acquisition module 110 can be used to perform Figure 2 As shown in step S110 , the relevant contents of the text acquisition module 110 may refer to the above description of step S110 .

[0129] The character conversion module 120 may be used to determine a target character to be recognized from the at least one character to be recognized, and convert the target character to be recognized into a target number in a target base. Figure 2 As shown in step S120, the relevant contents of the character conversion module 120 can refer to the above description of step S120.

[0130] The digital matching module 130 can be used to match the target number based on a pre-obtained deterministic finite state automaton, wherein the deterministic finite state automaton is obtained by processing the target regular expression, and the characters corresponding to each transfer edge in the deterministic finite state automaton are represented based on the target base. Figure 2 As shown in step S130 , the relevant contents of the digital matching module 130 may refer to the above description of step S130 .

[0131] The matching stop module 140 can be used to stop matching the text to be recognized when the target number fails to match. Figure 2 As shown in step S140 , the relevant contents of the matching stopping module 140 may refer to the above description of step S140 .

[0132] Optionally, in an alternative example, the character conversion module 120 may include a byte length determination submodule and a to-be-recognized character conversion submodule.

[0133] In detail, the byte length determination submodule is used to determine the byte length of the target character to be recognized. The character conversion submodule is used to convert the target character to be recognized into a target number in a target base based on a conversion rule corresponding to the byte length.

[0134] In summary, the text recognition method, text recognition device and electronic device based on regular matching provided by the present application convert a target character to be recognized in at least one character to be recognized included in the text to be recognized into a target number in the target base, so that the target number can be matched based on a predetermined finite state automaton, and then, when the match fails, the matching process of the text to be recognized is stopped. In this way, the problem of directly converting all the characters to be recognized into target numbers, which results in the need to occupy more memory resources, can be avoided, thereby improving the problem of resource waste in the existing text recognition technology, and having high practical value.

[0135] In several embodiments provided in the embodiments of the present application, it should be understood that the disclosed device and method can also be implemented in other ways. The device and method embodiments described above are merely schematic, for example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the device, method and computer program product according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0136] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0137] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, an electronic device, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk. It should be noted that, in this article, the term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, article or device. Without more constraints, an element defined by the phrase "comprising a..." does not exclude the existence of other identical elements in the process, method, article or apparatus comprising the element.

[0138] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A text recognition method based on regular matching, characterized in that: include: Acquire a text to be recognized, wherein the text to be recognized includes at least one character to be recognized, and the character to be recognized is represented based on a variable-length encoding; Determine a target character to be recognized among the at least one character to be recognized, and convert the target character to be recognized into a target number in a target base; The target number is matched based on a pre-obtained deterministic finite state automaton, wherein the deterministic finite state automaton is obtained based on processing a target regular expression, and the character corresponding to each transfer edge in the deterministic finite state automaton is represented based on the target base; If the target number fails to match, then stop matching the text to be recognized; The step of converting the target character to be recognized into a target number in a target base comprises: Determine the byte length of the target character to be recognized; Determine whether the byte length is greater than a preset byte length; If the byte length is less than or equal to the preset byte length, converting the first byte of the target character to be recognized stored in the memory in binary form into the target base to obtain a target number corresponding to the target character to be recognized; If the byte length is greater than the preset byte length, binary data deletion is performed on each byte of the target character to be recognized that is stored in binary form in the memory, and the retained binary data is converted into the target base to obtain the target number corresponding to the target character to be recognized.

2. The text recognition method based on regular matching according to claim 1, characterized in that: The character to be recognized is multiple, and the method further includes: Step a, if the target number matches successfully, then a new target character to be recognized is determined from other characters to be recognized other than the target character to be recognized; Step b, converting the new target character to be recognized into a new target number in the target base, and performing matching processing on the new target number based on the determined finite state automaton; Step c, if the new target number matches successfully, then a new target character to be recognized is determined again from the new target number and other characters to be recognized other than the target character to be recognized, and step b is executed again based on the new target character to be recognized; Step d: If the new target number fails to match, stop matching the text to be recognized.

3. The text recognition method based on regular matching according to claim 2 is characterized in that: The step of determining the byte length of the target character to be recognized comprises: Determine whether the target bit corresponding to the target character to be recognized is 0, wherein the target bit is the highest bit of the first byte of the target character to be recognized stored in binary form in the memory; If the target bit is 0, the byte length of the target character to be recognized is determined to be 1; If the target bit is 1, the byte length of the target character to be recognized is determined to be the target bit number of the target character to be recognized, wherein the target bit number is the number of consecutive 1 bits in the multi-bit binary data of the target character to be recognized stored in binary form in the memory.

4. The text recognition method based on regular matching according to claim 3 is characterized in that: The step of performing binary data deletion processing on each byte of the target character to be recognized stored in binary form in the memory comprises: For the first byte of the target character to be recognized stored in the memory in binary form, the highest target length bit binary data in the first byte is deleted, wherein the target length bit is equal to the byte length plus 1; For each byte other than the first byte of the target character to be recognized stored in the memory in binary form, the most significant 2 bits of binary data in the byte are deleted.

5. The text recognition method based on regular matching according to claim 1 or 2, characterized in that: The step of obtaining the determined finite state automaton is also included, the step comprising: Determine whether the target regular expression has a target operator, wherein the target operator is used to perform a AND operation; If the target regular expression has the target operator, convert each character corresponding to the target operator into the target base to obtain a target base number corresponding to each character; Performing interval conversion processing based on the target base number corresponding to each character to obtain a corresponding target interval, and updating the target regular expression based on the target interval to obtain an updated target regular expression; Based on the updated target regular expression, a corresponding deterministic finite state automaton is generated.

6. A text recognition device based on regular expression matching, characterized in that: include: A text acquisition module, used for acquiring a text to be recognized, wherein the text to be recognized includes at least one character to be recognized, and the character to be recognized is represented based on a variable-length encoding; A character conversion module, used for determining a target character to be recognized among the at least one character to be recognized, and converting the target character to be recognized into a target number in a target base; A digital matching module, used for matching the target digital number based on a pre-obtained deterministic finite state automaton, wherein the deterministic finite state automaton is obtained based on processing a target regular expression, and the character corresponding to each transfer edge in the deterministic finite state automaton is represented based on the target base; A matching stop module, used for stopping matching processing of the to-be-recognized text when the target number fails to match; Wherein, the character conversion module comprises: A byte length determination submodule, used to determine the byte length of the target character to be recognized; The character conversion submodule for to be recognized is used to determine whether the byte length is greater than the preset byte length; if the byte length is less than or equal to the preset byte length, the first byte of the target character to be recognized stored in binary form in the memory is converted into the target base to obtain the target number corresponding to the target character to be recognized; if the byte length is greater than the preset byte length, binary data deletion processing is performed on each byte of the target character to be recognized stored in binary form in the memory, and the retained binary data is converted into the target base to obtain the target number corresponding to the target character to be recognized.

7. An electronic device, characterized in that: include: Memory for storing computer programs; A processor connected to the memory is used to execute the computer program stored in the memory to implement the text recognition method based on regular matching as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Text data scanning method and device

    CN108734149A