String matching method and device
By encoding characters in the document and generating a set of key-value pairs, combining bitmap and B+ tree methods, the problem of inefficient string matching in the prior art is solved, and fast and efficient string matching is achieved.
Patent Information
- Application Number
- CN202111387749.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-22
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2041-11-22
AI Technical Summary
The calculation method used in the prior art for document string matching is time-consuming and inefficient, which affects the speed of character matching.
By reading the document and encoding its characters, a key-value pair set of characters is generated, and a bitmap and B+ tree combination method is used to quickly determine the existence of a specific string in the document.
It realizes fast matching of strings in documents, while consuming less memory, improving the efficiency of character matching.
Smart Images

Figure CN114168807B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of nuclear power technology, and in particular relates to a string matching method and device. Background Art
[0002] At present, the method used to match strings in documents is usually to use regular expressions to match the content in the document, and to quickly search and judge based on the KMP (Knuth-Morris-Pratt) algorithm and its variants. However, the above method is time-consuming and inefficient, which seriously affects the speed of character matching. Therefore, it is urgent to improve the matching efficiency of document strings. Summary of the invention
[0003] In order to overcome the problems existing in the related art, a string matching method and device are provided.
[0004] According to one aspect of an embodiment of the present disclosure, a string matching method is provided, the method comprising:
[0005] Reading an input document, and encoding each character in the document to obtain a code corresponding to each character;
[0006] For each character, set the value of the character's encoding at the corresponding bit in the bitmap to the target value, and generate a key-value pair set for the character. In each character's key-value pair set, the key is the character's encoding, and the value is the position of the character in the document.
[0007] Generate the character encoding of the specific string to be matched;
[0008] When reading each page of the document, determining whether the number of target values of all characters in the document page within the range of corresponding bits of the bitmap matches the number of characters in the specific character string;
[0009] When it is determined that the number of target values of all characters in the page document within the range of the corresponding bitmap position meets the number of characters in the specific character string, it is determined whether the specific character string exists in the page document according to the position where the characters whose corresponding bitmap position values are the target values appear in the page document;
[0010] When it is determined that the number of target values of all characters on the page of the document within the range of the corresponding bits of the bitmap does not meet the number of characters in the specific string, the next page of the document is read until the document content ends.
[0011] In a possible implementation, the method further includes:
[0012] If a character appears in multiple positions in a document, all positions of the character in the document are stored in the storage space corresponding to the character.
[0013] In a possible implementation, judging whether a specific character string exists in the page document according to the position where a character having a target value corresponding to a bitmap appears in the page document includes:
[0014] A B+ tree is established with the value of the key-value pair set of each character in the specific string as the index. The value of the leaf node in the B+ tree is the key of the key-value pair set. The existing key and its position are found according to the value of the index to determine whether the specific string exists in the page document.
[0015] According to another aspect of an embodiment of the present disclosure, a string matching device is provided, the device comprising:
[0016] The first module is used to read the input document and encode each character in the document to obtain the code corresponding to each character;
[0017] The second module is used to set the value of the encoding of each character at the corresponding bit of the bitmap to the target value, and generate a key-value pair set of the character, in which the key is the encoding of the character and the value is the position of the character in the document;
[0018] The third module is used to generate the character encoding of the specific string to be matched;
[0019] The fourth module is used to determine whether the number of target values of all characters in the document page within the range of corresponding bits of the bitmap meets the number of characters in the specific character string each time a document page is read;
[0020] The fifth module is used to determine whether there is a specific string in the page document according to the position where the character whose value of the corresponding bitmap position is the target value appears in the page document when it is determined that the number of target values of all characters in the page document within the range of the corresponding bitmap position meets the number of characters of the specific string;
[0021] The sixth module is used to read the next page of the document when it is determined that the number of target values of all characters in the page document within the range of corresponding bits of the bitmap does not meet the number of characters in the specific string, until the document content ends.
[0022] In a possible implementation manner, the device further includes:
[0023] The seventh module is used for storing all the positions of the character in the document in the storage space corresponding to the character when the character appears in multiple positions in the document.
[0024] In a possible implementation, the fifth module includes:
[0025] The first submodule is used to establish a B+ tree with the value of the key-value pair set of each character in the specific string as the index, the value of the leaf node in the B+ tree is the key of the key-value pair set, and the existing key and its position are searched according to the value of the index to determine whether the specific string exists in the page document.
[0026] According to another aspect of an embodiment of the present disclosure, a string matching device is provided, the device comprising:
[0027] processor;
[0028] a memory for storing processor-executable instructions;
[0029] Wherein, the processor is configured to execute the above method.
[0030] According to another aspect of an embodiment of the present disclosure, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor.
[0031] The beneficial effect of the present disclosure is that: in the present disclosure, when each page of a document is read, it is determined whether the number of target values of all characters of the document on the page within the range of the corresponding bit of the bitmap meets the number of characters of the specific string. When it is determined that the number of target values of all characters of the document on the page within the range of the corresponding bit of the bitmap meets the number of characters of the specific string, it is determined whether there is a specific string in the document on the page according to the position of the character with the target value of the corresponding bit of the bitmap appearing in the document on the page. The present disclosure uses the idea of the bitmap algorithm to enable the computer to perform fast matching while consuming less memory. In addition, the present disclosure is designed to combine the bitmap with the corresponding key-value pair set to achieve the purpose of matching a specific string. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 The figure is a flowchart of a string matching method according to an exemplary embodiment.
[0033] Figure 2 is a schematic diagram of a B+ tree according to an exemplary embodiment.
[0034] Figure 3 The figure is a block diagram of a string matching device according to an exemplary embodiment.
[0035] Figure 4 The figure is a block diagram of a string matching device according to an exemplary embodiment. DETAILED DESCRIPTION
[0036] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0037] Figure 1 1 is a flowchart of a string matching method according to an exemplary embodiment. The method can be executed by a terminal device, for example, the terminal device can be a server, a desktop computer, a laptop computer, a tablet computer, etc. The terminal device can also be, for example, a user device, a vehicle-mounted device or a wearable device, etc. The embodiment of the present disclosure does not limit the type of the terminal device. Figure 1 As shown, the method includes:
[0038] Step 100, reading an input document, and encoding each character in the document to obtain a code corresponding to each character;
[0039] Step 101, for each character, set the value of the character's code at the corresponding bit in the bitmap to the target value, and generate a key-value pair set for the character, in which the key is the character's code and the value is the position of the character in the document;
[0040] Step 102, generating a character code of a specific character string to be matched;
[0041] Step 103, when each page of the document is read, determining whether the number of target values of all characters in the page of the document within the range of corresponding bits of the bitmap matches the number of characters in the specific character string;
[0042] Step 104, when it is determined that the number of target values of all characters in the page document within the range of the corresponding bitmap position meets the number of characters in the specific string, it is determined whether the page document contains the specific string according to the position where the characters whose corresponding bitmap position values are the target values appear in the page document;
[0043] Step 105, when it is determined that the number of target values of all characters in the page document within the range of corresponding bits in the bitmap does not meet the number of characters in the specific string, read the next page document of the page document until the document content ends.
[0044] As an example of this embodiment, a document input by a user is obtained, and all characters in the document are encoded page by page (Chinese and English characters have corresponding encodings, such as: UTF-8, ASCII code), for example, the ASCII code of 'A' is '65', so as to facilitate data storage and search;
[0045] The encoding of each character will correspond to the target value of the position on the bitmap. For example, if the 10th character position of the read document is 'A', the 65th position of the bitmap will be set to 1 (an example of the target value), and 10 will be put into a key-value pair with the key 65 as the value. The key-value pair is: <65,
[10] >, and the value of this key-value pair is a set. For another example, if the current page document does not have the character 'B', the value of the 66th position of the Bitmap is not 1.
[0046] Store the character code and the position of the character in the document into a key-value pair set, where the key is the character code and the value is the position of the character in the document. For example, <65, [10, 11]> means that the 10th and 11th characters in the current page document are both 'A'. '65' is the key and [10, 11] is the value.
[0047] Perform character encoding on the string to be matched, and make a preliminary judgment on whether there is a possible matching value based on the bitmap, including:
[0048] First, generate the character code of the specific string to be matched. For example, if the specific string is 'abc', the corresponding ASCII codes are 97, 98, and 99;
[0049] Next, the bit range corresponding to the string 'abc' in the bitmap is the 97th to 99th bits. After reading each page of the document, traverse the page of the document. If the 97th to 99th bits are not all 1 during the traversal of the page of the document, it can be determined that the string 'abc' does not exist in the current page of the document; then read the next page of the document.
[0050] If the document of this page is traversed and it is determined that bits 97-99 are all 1, it can be determined that the string 'abc' may exist in the document of the current page. Then a B+ tree is generated based on the key-value pair set corresponding to the characters in the specific string to determine whether there is a matching value and locate the matching value position.
[0051] Figure 2 FIG. 1 is a schematic diagram of a B+ tree according to an exemplary embodiment. Figure 2 As shown, select the key-value pair set corresponding to the characters in a specific string. For the string 'KSB', select all key-value pairs with key values of 75, 83, and 66. Use the key-value pairs to create a B+ tree index. The key of each key-value pair, that is, the character code, is stored in the leaf node. According to the sequential arrangement of the B+ tree index, find the leaf nodes of the continuous index and determine whether the data in the node is consistent with the value to be matched. If they are consistent, record the index value. Figure 2 As shown: There are consecutive indexes 10, 11, and 12 in the B+ tree, and the stored data are 75, 83, and 66 respectively, which indicates that there is a matching value 'KSB' at position 10-12 of the current page of the document;
[0052] Read each page of the document until the file content is finished.
[0053] It should be noted that when there are multiple keys with values in the bitmap, the key-value pair information can be converted into a B+ tree structure, so that a large number of documents can be quickly searched without traversing these arrays. For example: if there are many key-value pairs with corresponding codes for uppercase letters, the values of these key-value pairs are used as indexes to construct a B+ tree structure, such as Figure 2 As shown. At this time, all the values of the B+ tree, that is, the keys of the original key-value pairs are stored in the leaf nodes, and the leaf nodes are connected by a bidirectional linked list. Because all the data of the B+ tree index is stored in the leaf nodes, and the data is arranged in order. Therefore, the B+ tree makes range search, sorted search and grouped search very simple. If you want to judge a specific string, such as three consecutive uppercase letters, you can quickly determine whether it exists based on the index. At this time, if there are 4 consecutive uppercase letters interfering, you can also find it quickly. When inserting a new key-value pair into the B+ tree, compare the value with each node of the binary tree, and update the field in the leaf node. There is no need to traverse the entire key-value pair set. After the B+ tree is generated, you can directly match the string you want to find based on the index value and the value stored in the leaf node. As shown Figure 2 As shown, for a B+ tree with a degree of 3, to determine whether the leaf node under index 11 can form a continuous string with the leaf node under index 25, it is only necessary to determine whether the leaf nodes under the respective indexes are the same.
[0054] In a possible implementation, a string matching device is provided, the device comprising:
[0055] The first module is used to read the input document and encode each character in the document to obtain the code corresponding to each character;
[0056] The second module is used to set the value of the encoding of each character at the corresponding bit of the bitmap to the target value, and generate a key-value pair set of the character, in which the key is the encoding of the character and the value is the position of the character in the document;
[0057] The third module is used to generate the character encoding of the specific string to be matched;
[0058] The fourth module is used to determine whether the number of target values of all characters in the document page within the range of corresponding bits of the bitmap meets the number of characters in the specific character string each time a document page is read;
[0059] The fifth module is used to determine whether there is a specific string in the page document according to the position where the character whose value of the corresponding bitmap position is the target value appears in the page document when it is determined that the number of target values of all characters in the page document within the range of the corresponding bitmap position meets the number of characters of the specific string;
[0060] The sixth module is used to read the next page of the document when it is determined that the number of target values of all characters in the page document within the range of corresponding bits of the bitmap does not meet the number of characters in the specific string, until the document content ends.
[0061] In a possible implementation manner, the device further includes:
[0062] The seventh module is used for storing all the positions of the character in the document in the storage space corresponding to the character when the character appears in multiple positions in the document.
[0063] In a possible implementation, the fifth module includes:
[0064] The first submodule is used to establish a B+ tree with the value of the key-value pair set of each character in the specific string as the index, the value of the leaf node in the B+ tree is the key of the key-value pair set, and the existing key and its position are searched according to the value of the index to determine whether the specific string exists in the page document.
[0065] The description of the above-mentioned device has been explained in detail in the description of the above-mentioned method, and will not be repeated here.
[0066] Figure 3 800 is a block diagram of a string matching device according to an exemplary embodiment. For example, the device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0067] Reference Figure 3 , the device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .
[0068] The processing component 802 generally controls the overall operation of the device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned device. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.
[0069] The memory 804 is configured to store various types of data to support operations on the device 800. Examples of such data include instructions for any application or device operating on the device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0070] The power supply component 806 provides power to the various components of the device 800. The power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 800.
[0071] The multimedia component 808 includes a screen that provides an output interface between the device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0072] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the device 800 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.
[0073] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: home button, volume button, start button, and lock button.
[0074] The sensor assembly 814 includes one or more sensors for providing various aspects of status assessment for the device 800. For example, the sensor assembly 814 can detect the open / closed state of the device 800, the relative positioning of components, such as the display and keypad of the device 800, the sensor assembly 814 can also detect the position change of the device 800 or a component of the device 800, the presence or absence of user contact with the device 800, the orientation or acceleration / deceleration of the device 800 and the temperature change of the device 800. The sensor assembly 814 can include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 814 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 can also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor or a temperature sensor.
[0075] The communication component 816 is configured to facilitate wired or wireless communication between the device 800 and other devices. The device 800 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0076] In an exemplary embodiment, the apparatus 800 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0077] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 804 including computer program instructions, which can be executed by the processor 820 of the device 800 to perform the above method.
[0078] Figure 4 1 is a block diagram of a string matching device according to an exemplary embodiment. For example, the device 1900 can be provided as a server. Figure 4, the apparatus 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions, such as an application, that can be executed by the processing component 1922. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.
[0079] The device 1900 may also include a power supply component 1926 configured to perform power management of the device 1900, a wired or wireless network interface 1950 configured to connect the device 1900 to a network, and an input / output (I / O) interface 1958. The device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server™, MacOS X™, Unix™, Linux™, FreeBSD™, or the like.
[0080] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the device 1900 to perform the above method.
[0081] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.
[0082] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the above. More specific examples (a non-exhaustive list) of computer-readable storage media include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the above. The computer-readable storage medium used herein is not to be interpreted as a transient signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0083] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0084] The computer program instructions for performing the operations of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The computer-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect through the Internet). In some embodiments, by using the state information of the computer-readable program instructions to personalize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), the electronic circuit may execute the computer-readable program instructions, thereby implementing various aspects of the present disclosure.
[0085] Various aspects of the present disclosure are described herein with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of boxes in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0086] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0087] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0088] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.
[0089] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A string matching method, characterized in that: The method comprises: Reading an input document, and encoding each character in the document to obtain a code corresponding to each character; For each character, set the value of the character's encoding at the corresponding bit in the bitmap to the target value, and generate a key-value pair set for the character. In each character's key-value pair set, the key is the character's encoding, and the value is the position of the character in the document. Generate the character encoding of the specific string to be matched; When reading each page of the document, determining whether the number of target values of all characters in the document page within the range of corresponding bits of the bitmap matches the number of characters in the specific character string; When it is determined that the number of target values of all characters in the page document within the range of the corresponding bits of the bitmap meets the number of characters in the specific string, it is determined whether the specific string exists in the page document according to the position where the characters whose corresponding bitmap values are the target values appear in the page document, wherein a B+ tree is established with the value of the key-value pair set of each character in the specific string as an index, the value of the leaf node in the B+ tree is the key of the key-value pair set, and the existing key and its position are searched according to the value of the index to determine whether the specific string exists in the page document; When it is determined that the number of target values of all characters on the page of the document within the range of the corresponding bits of the bitmap does not meet the number of characters in the specific string, the next page of the document is read until the document content ends.
2. The method according to claim 1, characterized in that The method further comprises: If a character appears in multiple positions in a document, all positions of the character in the document are stored in the storage space corresponding to the character.
3. The method according to claim 1, characterized in that According to the position where the character whose bit value is the target value appears in the document page, it is determined whether a specific character string exists in the document page, including: A B+ tree is established with the value of the key-value pair set of each character in the specific string as an index. The value of the leaf node in the B+ tree is the key of the key-value pair set. The existing key and its position are found according to the value of the index to determine whether the specific string exists in the page document.
4. A string matching device, characterized in that: The device comprises: The first module is used to read the input document and encode each character in the document to obtain the code corresponding to each character; The second module is used to set the value of the encoding of each character at the corresponding bit of the bitmap to the target value, and generate a key-value pair set of the character, in which the key is the encoding of the character and the value is the position of the character in the document; The third module is used to generate the character encoding of the specific string to be matched; The fourth module is used to determine whether the number of target values of all characters in the document page within the range of corresponding bits of the bitmap meets the number of characters in the specific character string each time a document page is read; The fifth module is used to determine whether the specific string exists in the page document according to the position where the character whose bitmap corresponding bit value is the target value appears in the page document when it is determined that the number of target values of all characters in the page document within the range of the corresponding bit of the bitmap meets the number of characters of the specific string, wherein a B+ tree is established with the value of the key-value pair set of each character in the specific string as an index, the value of the leaf node in the B+ tree is the key of the key-value pair set, and the existing key and its position are searched according to the value of the index to determine whether the specific string exists in the page document; The sixth module is used to read the next page of the document when it is determined that the number of target values of all characters in the page document within the range of corresponding bits of the bitmap does not meet the number of characters in the specific string, until the document content ends.
5. The device according to claim 4, characterized in that The device also includes: The seventh module is used for storing all the positions of the character in the document in the storage space corresponding to the character when the character appears in multiple positions in the document.
6. The device according to claim 4, characterized in that The fifth module comprises: The first submodule is used to establish a B+ tree with the value of the key-value pair set of each character in the specific string as an index, the value of the leaf node in the B+ tree is the key of the key-value pair set, and the existing key and its position are searched according to the value of the index to determine whether the specific string exists in the page document.
7. A string matching device, characterized in that: The device comprises: processor; a memory for storing processor-executable instructions; The processor is configured to execute the method according to any one of claims 1 to 3.
8. A non-volatile computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Operation entry obtaining method and apparatus
CN107402702A
JSON character string processing method and device
CN110263104A