Template matching method and system based on double array dictionary tree
The combination of building a dictionary tree and NLP tools through a double array Trie tree solves the problem of low template matching performance, achieves fast and flexible template matching, improves the performance and accuracy of intelligent technology, and supports high-concurrency semantic search .
Patent Information
- Application Number
- CN202111586054.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-20
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-12-20
AI Technical Summary
Existing technology is difficult to achieve rapid matching of a large number of templates, resulting in low template matching performance and inability to meet the fast and accurate requirements of intelligent technology.
A double array Trie tree (DAT) is used to build a dictionary tree, and template matching is achieved through transfer function arrays and verification arrays. NLP tools are combined for preprocessing and template design, and wildcards and markers are used to improve matching flexibility and accuracy.
It achieves fast, flexible and efficient template matching, reduces space occupation, improves the accuracy and performance of template matching, and supports highly concurrent semantic search requests.
Smart Images

Figure CN114254082B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of template matching, in particular to a template matching method and system based on a dual array dictionary tree. Background Art
[0002] With the continuous development of computer technology and the continuous improvement of informatization, society has entered an era of interconnectedness and intelligence. Template matching is a common method with wide applications in many fields. It can be used in technical fields such as knowledge extraction, search intent recognition, and chatbots. Efficient and fast matching of a large number of templates can effectively improve the performance and accuracy of these technologies, which is of great significance to the advancement of intelligent technology. Double Array Tree DAT is an efficient implementation of Trie dictionary tree, which has the characteristics of high efficiency and space saving, and can be used for fast retrieval of strings.
[0003] How to achieve fast matching of a large number of templates based on the dual-array Trie tree and improve performance is a technical problem that needs to be solved. Summary of the invention
[0004] The technical task of the present invention is to address the above shortcomings and provide a template matching method and system based on a dual-array dictionary tree to solve the technical problem of how to achieve fast matching of a large number of templates based on a dual-array Trie tree and improve performance.
[0005] In a first aspect, the template matching method based on a dual array dictionary tree of the present invention constructs a DAT tree by taking each template as a dictionary item, and performs template matching based on a retrieval method of the DAT tree, the method comprising the following steps:
[0006] Taking the historical input text as the target text, preprocessing the target text to obtain an input sequence including words and parts of speech;
[0007] Design templates based on words, parts of speech, and special characters, and configure template matching rules;
[0008] The designed template is used as a dictionary item to construct a DAT dictionary tree, the DAT dictionary tree is equivalent to an automaton, the state is the number of the tree node, the edge is the character, the DAT dictionary tree is implemented by two arrays, namely a transfer function array and a verification array, the transfer function indicates that a state can be transferred to another state according to the character c, and the verification array is used to verify the validity of the transfer;
[0009] Taking the input text to be detected as the target text, preprocessing the target text to obtain an input sequence including words and parts of speech as a substitute retrieval input sequence;
[0010] Template matching is performed on the input sequence to be searched based on the search rules and template matching rules of the DAT dictionary tree.
[0011] Preferably, the target text is preprocessed by an NLP tool, including word segmentation and part-of-speech tagging, to obtain an input sequence including words and parts of speech.
[0012] Preferably, the special characters are wildcards and markers, including * and #;
[0013] The template matching rules include: when the template encounters *, the following two operations can be performed: skip the current word and continue matching from the next word; do not skip the current word and continue matching; after the matching is completed, output all matching templates and the mapping between template elements and input sequences in the matching templates;
[0014] The template elements are words, parts of speech and special characters.
[0015] Preferably, the transfer function array and the verification array satisfy the following transfer equation:
[0016] base[r]+c=s
[0017] check[s]=r
[0018] Where c is the integer encoding value of the character
[0019] The transfer function g(r, c)=s indicates that the state r can be transferred to the state s according to the character c, and the check array indicates the verification array.
[0020] Preferably, performing template matching on the input sequence to be searched based on the search rules of the DAT dictionary tree comprises the following steps:
[0021] Step 1: Substitute the characters of the input sequence into c in the transfer equation one by one, perform state transfer and check;
[0022] Step 2: If the verification is successful, it means that the character is matched successfully. The state s calculated in step 1 is assigned to r, and the next character is read and substituted into c. Step 2 is executed. If the verification fails, it means that there is no matching template, and the process ends.
[0023] Step 3: All characters are read, the match is successful, and the matching template is output.
[0024] In a second aspect, a template matching system based on a dual-array dictionary tree of the present invention is used to execute the template matching method based on a dual-array dictionary tree as described in any one of items 1 to 5 of the first aspect, and the system comprises:
[0025] A preprocessing module is used to preprocess the historical input text and the text to be retrieved as the target text to obtain an input sequence including words and parts of speech.
[0026] A template design module, the template design module is used to design templates based on words, parts of speech and special characters, and configure template matching rules;
[0027] A dictionary tree construction module, wherein the dictionary tree construction module is used to construct a DAT dictionary tree using the designed template as a dictionary item. The DAT dictionary tree is equivalent to an automaton, wherein the state is the number of the tree node and the edge is the character. The DAT dictionary tree is implemented by two arrays, namely a transfer function array and a verification array. The transfer function indicates that a state can be transferred to another state according to the character c, and the verification array is used to verify the validity of the transfer;
[0028] A template matching module is used to perform template matching on the input sequence to be searched based on the search rules of the DAT dictionary tree and the template matching rules.
[0029] Preferably, the preprocessing module is used to preprocess the target text through NLP tools, including word segmentation and part-of-speech tagging, to obtain an input sequence including words and parts of speech.
[0030] Preferably, the special characters are wildcards and markers, including * and #;
[0031] The template matching rules include: when the template encounters *, the following two operations can be performed: skip the current word and continue matching from the next word; do not skip the current word and continue matching; after the matching is completed, output all matching templates and the mapping between template elements and input sequences in the matching templates;
[0032] The template elements are words, parts of speech and special characters.
[0033] Preferably, the transfer function array and the verification array satisfy the following transfer equation:
[0034] base[r]+c=s
[0035] check[s]=r
[0036] Where c is the integer encoding value of the character
[0037] The transfer function g(r, c)=s indicates that the state r can be transferred to the state s according to the character c, and the check array indicates the verification array.
[0038] Preferably, the matching module is used to perform template matching on the input sequence to be searched based on the search rules of the DAT dictionary tree through the following steps:
[0039] Step 1: Substitute the characters of the input sequence into c in the transfer equation one by one, perform state transfer and check;
[0040] Step 2: If the verification is successful, it means that the character is matched successfully. The state s calculated in step 1 is assigned to r, and the next character is read and substituted into c. Step 2 is executed. If the verification fails, it means that there is no matching template, and the process ends.
[0041] Step 3: All characters are read, the match is successful, and the matching template is output.
[0042] The template matching method and system based on the dual array dictionary tree of the present invention have the following advantages:
[0043] 1. Based on the characteristics of fast retrieval and small space occupied by DAT tree, flexible and fast matching of a large number of templates is achieved through the retrieval rules of the dual array Trie tree and configurable template matching rules;
[0044] 2. Adding special characters such as wildcards and markers to the template and performing targeted processing when searching using the double-array Trie tree can improve the flexibility and accuracy of the template. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0046] The present invention is further described below in conjunction with the accompanying drawings.
[0047] Figure 1 This is a flowchart of the template matching method based on the dual-array dictionary tree of Example 1. DETAILED DESCRIPTION
[0048] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.
[0049] The embodiment of the present invention provides a template matching method and system based on a dual-array dictionary tree, which is used to solve the technical problem of how to achieve fast matching of a large number of templates based on a dual-array Trie tree and improve performance.
[0050] Embodiment 1:
[0051] The template matching method based on the double array dictionary tree of the present invention constructs a DAT tree by taking each template as a dictionary item, and performs template matching based on a retrieval method of the DAT tree. The method comprises the following steps:
[0052] S100, taking the historical input text as the target text, preprocessing the target text to obtain an input sequence including words and parts of speech;
[0053] S200, designing templates based on words, parts of speech and special characters, and configuring template matching rules;
[0054] S300, constructing a DAT dictionary tree using the designed template as a dictionary item. The DAT dictionary tree is equivalent to an automaton. The state is the number of the tree node, and the edge is the character. The DAT dictionary tree is implemented by two arrays, namely a transfer function array and a verification array. The transfer function indicates that a state can be transferred to another state according to the character c, and the verification array is used to verify the validity of the transfer;
[0055] S400, taking the input text to be detected as the target text, preprocessing the target text to obtain an input sequence including words and parts of speech as a substitute retrieval input sequence;
[0056] S500 , performing template matching on the input sequence to be searched based on the search rules and template matching rules of the DAT dictionary tree.
[0057] In this embodiment, the target text is preprocessed by using an NLP tool, including word segmentation and part-of-speech tagging, to obtain an input sequence including words and parts of speech.
[0058] Template rule design: search input is mainly text content. First, the input text is processed by NLP tools such as word segmentation and part-of-speech tagging to generate an input sequence including words and parts of speech. In order to improve accuracy, parts of speech and words are used as templates. Adding words can be used to perform targeted matching of certain special words. At the same time, the * wildcard can be used for fuzzy matching. Template examples include "LOC*PER", "PER u#mother", where LOC and PER are parts of speech, # indicates that the following content is a specific word and needs to be matched completely, and * indicates any word or none. As mentioned above, rich templates can be designed as needed to improve the accuracy of search intent recognition.
[0059] Template matching rules include: when the template encounters *, the following two operations can be performed: skip the current word and continue matching from the next word; do not skip the current word and continue matching; after the matching is completed, output all matching templates and the mapping of template elements and input sequences in the matching templates; template elements are words, parts of speech and special characters.
[0060] The DAT dictionary tree is implemented by two arrays, base and check. The Trie tree can be equivalent to an automaton, where the state is the number of the tree node and the edge is the character; then the transition function g(r, c) = s means that state r can be transferred to state s according to character c. The base array is the implementation of the transfer function array, and the check array is used to verify the validity of the transfer; the two arrays satisfy the following transfer equation:
[0061] base[r]+c=s
[0062] check[s]=r
[0063] In the above formula, c is the integer code value of the character.
[0064] The core of template matching is to use the retrieval algorithm of the DAT tree. In the above transfer equation, the starting state is r, the initial state is 0, and the steps are as follows:
[0065] ①Substitute the characters of the input sequence into c in the equation one by one, perform state transfer and verification.
[0066] ② If the verification is successful, it means that the previous part matches. Assign the state s calculated in step ① to r, read the next character and substitute it into c, and execute step ①. If the verification fails, it means that there is no matching template and the process ends.
[0067] ③All characters have been read, the match is successful, and the matching template is output.
[0068] The entire retrieval process is controllable and can be personalized according to the template rules. For example, when the template encounters an asterisk, two operations can be performed according to the template rules: skip the current word and continue matching from the next word; do not skip the current word and continue matching. Both operations can be performed at the same time to meet the template matching requirements. After the matching is completed, all matched templates and the mapping of the template elements and the input sequence can be output to help with subsequent use.
[0069] The method of this embodiment realizes a semantic search function. The input text is processed through NLP part-of-speech tagging and entity recognition technology to obtain an input sequence of parts of speech and words. A large number of templates are designed with elements such as "part-of-speech", "word", "#", "*", etc. to match the input semantics. The richer the template, the more semantics can be recognized. Due to the high concurrency of the search, there are high requirements for the efficiency of matching a large number of templates. The use of the present invention can quickly find matching content in a large number of templates, and can well support high-concurrency requests for semantic search. At the same time, based on the flexibility of template design and specific word matching, the accuracy and pertinence of the template are greatly improved, which greatly improves the effect of semantic search.
[0070] Embodiment 2:
[0071] The template matching system based on the double-array trie of the present invention includes a preprocessing module, a template design module, a trie construction module, and a template matching module. The preprocessing module is used to preprocess the historical input text and the text to be retrieved as target texts respectively to obtain input sequences including words and part-of-speech tags. The template design module is used to design templates based on words, part-of-speech tags, and special characters and configure template matching rules. The trie construction module is used to construct a DAT trie with the designed templates as dictionary entries. The DAT trie is equivalent to an automaton, where the states are the numbers of the tree nodes and the edges are characters. The DAT trie is implemented by two arrays, namely a transition function array and a verification array. The transition function represents that a state can transition to another state according to character c, and the verification array is used to verify the validity of the transition. The template matching module is used to perform template matching on the input sequence to be retrieved based on the retrieval rules of the DAT trie and the template matching rules.
[0072] Among them, the preprocessing module is used to preprocess the target text through NLP tools, including performing word segmentation and part-of-speech tagging processing to obtain input sequences including words and part-of-speech tags.
[0073] To improve accuracy, part-of-speech tags and words are combined to be used as templates. Adding words can perform targeted matching for certain special words, and at the same time, special characters including wildcards and markers are used. Using the * wildcard can perform fuzzy matching. Template examples are "LOC*PER", "PER u#mother", where LOC and PER are part-of-speech tags, # indicates that the following content is a specific word and needs to be exactly matched, and * represents any word or can also be none. As above, rich templates can be designed according to needs to improve the accuracy of search intent recognition.
[0074] The template matching rules include: when the template encounters *, the following two operations can be performed: skip the current word and continue matching from the next word; do not skip the current word and continue matching; after the matching is completed, output all the matching templates and the mapping between the template elements and the input sequence in the matching templates. The template elements are words, part-of-speech tags, and special characters.
[0075] The transition function array and the verification array satisfy the following transition equations:
[0076] base[r]+c=s
[0077] check[s]=r
[0078] Among them, c is the integer encoding value of the character
[0079] The transition function g(r, c) = s represents that state r can transition to state s according to character c, and the check array represents the verification array.
[0080] The matching module is used to perform template matching on the input sequence to be searched based on the search rules of the DAT dictionary tree through the following steps:
[0081] Step 1: Substitute the characters of the input sequence into c in the transfer equation one by one, perform state transfer and check;
[0082] Step 2: If the verification is successful, it means that the character is matched successfully. The state s calculated in step 1 is assigned to r, and the next character is read and substituted into c. Step 2 is executed. If the verification fails, it means that there is no matching template, and the process ends.
[0083] Step 3: All characters are read, the match is successful, and the matching template is output.
[0084] The system of this embodiment can execute the method disclosed in Embodiment 1.
[0085] The present invention has been shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the means in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.
Claims
1. A template matching method based on a double array dictionary tree, characterized in that Each template is used as a dictionary item to construct a DAT tree, and a retrieval method based on the DAT tree is used to perform template matching. The method comprises the following steps: Taking the historical input text as the target text, preprocessing the target text to obtain an input sequence including words and parts of speech; Design templates based on words, parts of speech, and special characters, and configure template matching rules; The designed template is used as a dictionary item to construct a DAT dictionary tree, the DAT dictionary tree is equivalent to an automaton, the state is the number of the tree node, the edge is the character, the DAT dictionary tree is implemented by two arrays, namely a transfer function array and a verification array, the transfer function indicates that a state can be transferred to another state according to the character c, and the verification array is used to verify the validity of the transfer; Taking the input text to be detected as the target text, preprocessing the target text to obtain an input sequence including words and parts of speech as a substitute retrieval input sequence; Template matching is performed on the input sequence to be searched based on the search rules and template matching rules of the DAT dictionary tree.
2. The template matching method based on the double array dictionary tree according to claim 1 is characterized in that The target text is preprocessed by NLP tools, including word segmentation and part-of-speech tagging, to obtain an input sequence including words and parts of speech.
3. The template matching method based on the double array dictionary tree according to claim 1 is characterized in that The special characters are wildcards and markers, including * and #; The template matching rules include: when the template encounters *, the following two operations can be performed: skip the current word and continue matching from the next word; Do not skip the current word and continue matching. After the matching is completed, output all matching templates and the mapping between template elements and input sequences in the matching templates. The template elements are words, parts of speech and special characters.
4. The template matching method based on the double array dictionary tree according to claim 1 is characterized in that The transfer function array and verification array satisfy the following transfer equation: base[r]+c=s check[s]=r Where c is the integer encoding value of the character The transfer function g(r, c)=s indicates that the state r can be transferred to the state s according to the character c, and the check array indicates the verification array.
5. The template matching method based on the double array dictionary tree according to claim 4 is characterized in that Performing template matching on the input sequence to be searched based on the search rules of the DAT dictionary tree includes the following steps: Step 1: Substitute the characters of the input sequence into c in the transfer equation one by one, perform state transfer and check; Step 2: If the verification is successful, it means that the character is matched successfully. The state s calculated in step 1 is assigned to r, and the next character is read and substituted into c. Step 2 is executed. If the verification fails, it means that there is no matching template, and the process ends. Step 3: All characters are read, the match is successful, and the matching template is output.
6. A template matching system based on a double-array dictionary tree, characterized in that A system for executing the template matching method based on a double-array dictionary tree as described in any one of claims 1 to 5, the system comprising: A preprocessing module is used to preprocess the historical input text and the text to be retrieved as the target text to obtain an input sequence including words and parts of speech. A template design module, the template design module is used to design templates based on words, parts of speech and special characters, and configure template matching rules; A dictionary tree construction module, wherein the dictionary tree construction module is used to construct a DAT dictionary tree using the designed template as a dictionary item. The DAT dictionary tree is equivalent to an automaton, wherein the state is the number of the tree node and the edge is the character. The DAT dictionary tree is implemented by two arrays, namely a transfer function array and a verification array. The transfer function indicates that a state can be transferred to another state according to the character c, and the verification array is used to verify the validity of the transfer; A template matching module is used to perform template matching on the input sequence to be searched based on the search rules of the DAT dictionary tree and the template matching rules.
7. The template matching system based on the double array dictionary tree according to claim 6 is characterized in that The preprocessing module is used to preprocess the target text through NLP tools, including word segmentation and part-of-speech tagging, to obtain an input sequence including words and parts of speech.
8. The template matching system based on the double array dictionary tree according to claim 6 is characterized in that The special characters are wildcards and markers, including * and #; The template matching rules include: when the template encounters *, the following two operations can be performed: skip the current word and continue matching from the next word; Do not skip the current word and continue matching. After the matching is completed, output all matching templates and the mapping between template elements and input sequences in the matching templates. The template elements are words, parts of speech and special characters.
9. The template matching system based on the double array dictionary tree according to claim 6 is characterized in that The transfer function array and verification array satisfy the following transfer equation: base[r]+c=s check[s]=r Where c is the integer encoding value of the character The transfer function g(r, c)=s indicates that the state r can be transferred to the state s according to the character c, and the check array indicates the verification array.
10. The template matching system based on the double array dictionary tree according to claim 9 is characterized in that The matching module is used to perform template matching on the input sequence to be searched based on the search rules of the DAT dictionary tree through the following steps: Step 1: Substitute the characters of the input sequence into c in the transfer equation one by one, perform state transfer and check; Step 2: If the verification is successful, it means that the character is matched successfully. The state s calculated in step 1 is assigned to r, and the next character is read and substituted into c. Step 2 is executed. If the verification fails, it means that there is no matching template, and the process ends. Step 3: All characters are read, the match is successful, and the matching template is output.
Citation Information
Patent Citations
Construction of AC (Aho-Corasick) automata, Chinese multi-pattern matching method and related devices
CN108021569A
Data privacy information detection system
CN109582861A
