Word library construction method and word query method based on double-array tree
By splitting and encoding sensitive words based on a dual-array tree method, a sensitive word library is constructed, which solves the problems of large storage space and long recognition time, and achieves optimization of storage space and reduction of recognition time.
Patent Information
- Application Number
- CN202511679306.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-17
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2045-11-17
AI Technical Summary
Existing technologies require large storage space for sensitive word databases and take a long time to identify them, resulting in problems such as repeated storage and low query efficiency.
By using a double-array tree-based method, sensitive words are split into text characters, deduplicated, and then dictionary-encoded. The basic encoding of each character node in the sensitive word tree is determined by trial calculation based on random selection, auto-incrementing selection, overall query selection, and preset data selection, thus constructing a sensitive word library.
The storage space of the sensitive word tree was reduced and the sensitive word identification time was decreased, thus improving query efficiency.
Smart Images

Figure CN121166940A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of sensitive word recognition, and particularly relates to a word library construction method and a word query method based on a double array tree. BACKGROUND
[0002] In the prior art, all sensitive words are generally stored in a sensitive word library in full text. Full text storage can cause a large amount of repeated storage of data, for example, the sensitive word "AB" and the sensitive word "AC" can store "A" repeatedly. In addition, full text storage requires full text matching when performing a query, which is time-consuming and labor-intensive. Alternatively, all sensitive words are stored in a sensitive word tree to overcome the problem of repeated storage caused by full text storage. However, the tree structure needs to be stored in the form of a structure body, and the context relationship between the parent and child nodes of the tree structure requires a large amount of structure code, so that the storage of each node in the physical address is discontinuous in the storage process. The memory required to store the sensitive word tree is large, and the pointer needs to be frequently jumped during a query, which is time-consuming. SUMMARY
[0003] Therefore, the present application aims to at least provide a word library construction method and a word query method based on a double array tree, which re-plans the sensitive word library by using a double array tree, solves the technical problems of large storage space and long sensitive word recognition time in the prior art, and achieves the technical effect of reducing the storage space of the sensitive word tree and reducing the sensitive word recognition time.
[0004] The present application mainly includes the following aspects: In a first aspect, the present application provides a word library construction method based on a double array tree, which includes: generating a sensitive word tree based on the text characters split from each sensitive word and the arrangement order of the text characters, wherein each path in the sensitive word tree corresponds to a sensitive word; performing dictionary encoding on the text characters split from the sensitive words after deduplication to obtain character encodings corresponding to all text characters respectively; determining the base encoding of each character node in the sensitive word tree in layers according to at least one of random selection trial, self-increment selection trial, overall query selection trial and preset data selection trial; determining the storage location encoding of the text characters of each character node in the storage space based on the character encoding corresponding to the text characters of each character node and the base encoding of the parent node of each character node, and taking the storage location encoding of the parent node of each character node as the check encoding of each character node, to construct the sensitive word library.
[0005] In a second aspect, the embodiments of the present application further provide a word query method based on a double-array tree. The method applies the sensitive word library created by the method of the first aspect or any possible implementation manner of the first aspect. The method comprises the following steps: determining whether a first query character in a to-be-queried sensitive word is a dictionary-encoded text character; if yes, determining a first target storage location code of the first query character in a storage space based on a preset basic code of a root node of the sensitive word library and a character code corresponding to the first query character of the to-be-queried sensitive word; determining whether the text character stored in the storage location corresponding to the first target storage location code is the first query character and whether an inspection code corresponding to the first target storage location code is a storage location code of the root node; if yes, determining whether a basic code corresponding to the first target storage location code is a preset ending basic code; if no, determining a second target storage location code of a second query character of the to-be-queried sensitive word based on the basic code corresponding to the first target storage location code and a character code corresponding to the second query character; determining whether the current query character meets the sensitive word character determination condition based on the text character stored in the storage location corresponding to the current target storage location code, the basic code and the inspection code; and if yes, determining the to-be-queried sensitive word as a sensitive word stored in the sensitive word library.
[0006] In a third aspect, the embodiments of the present application further provide a double-array tree-based word library construction device. The device comprises: a sensitive word tree generation module, which generates a sensitive word tree based on text characters split from each sensitive word and the arrangement order of each text character, wherein each path in the sensitive word tree corresponds to a sensitive word; an encoding module, which performs dictionary encoding on the text characters split from the sensitive word after deduplication, to obtain character codes corresponding to all text characters respectively; a basic code determination module, which determines the basic code of each character node in the sensitive word tree in layers according to at least one of random selection trial, self-increment selection trial, overall query selection trial and preset data selection trial; and a construction module, which determines the storage location code of the text character of each character node in a storage space based on the character code corresponding to the text character of each character node and the basic code of the parent node of each character node, and takes the storage location code of the parent node of each character node as the inspection code of each character node, to construct the sensitive word library.
[0007] In a fourth aspect, the embodiments of the present application further provide a word query device based on a double-array tree. The device applies the sensitive word library created by the method of the first aspect or any possible implementation manner of the first aspect. The device comprises: a first determining module, which determines whether a first query character in a sensitive word to be queried is a dictionary encoded text character; a second determining module, which, if yes, determines a first target storage location code of the first query character in a storage space based on a preset basic code of a root node of the sensitive word library and a character code corresponding to the first query character of the sensitive word to be queried; an inspection module, which determines whether the text character stored in the storage location corresponding to the first target storage location code is the first query character and whether the inspection code corresponding to the first target storage location code is the storage location code of the root node; a judging module, which, if yes, judges whether the basic code corresponding to the first target storage location code is a preset ending basic code; a third determining module, which, if no, determines a second target storage location code of a second query character in the storage space based on the basic code corresponding to the first target storage location code and the character code corresponding to the second query character of the sensitive word to be queried; a conditional comparison module, which determines whether the current query character meets the sensitive word character determination condition based on the text character stored in the storage location corresponding to the current target storage location code, the basic code and the inspection code; and a fourth determining module, which, if all meet the condition, determines the sensitive word to be queried as a sensitive word stored in the sensitive word library.
[0008] The application provides a word library construction method and a word query method based on a double-array tree. The application provides a word library construction method and a word query method based on a double-array tree. The method comprises the following steps: generating a sensitive word tree based on text characters split by each sensitive word and the arrangement order of the text characters, wherein each path in the sensitive word tree corresponds to a sensitive word; performing dictionary coding on the text characters split by the sensitive word after removing the duplicate text characters, to obtain character codes corresponding to all the text characters; determining the base code of each character node in the sensitive word tree in layers according to at least one of random selection trial, self-increment selection trial, overall query selection trial and preset data selection trial; determining the storage location code of the text characters of each character node in the storage space based on the character code corresponding to the text characters of each character node and the base code of the parent node of each character node, and taking the storage location code of the parent node of each character node as the check code of each character node, to construct the sensitive word library. The sensitive word tree is generated by splitting the sensitive word and according to the arrangement order of the text characters of each sensitive word, the duplicate text characters after splitting are removed and dictionary coding is performed to obtain the character codes of all the text characters, the base code of each character node in each layer of the sensitive word tree is determined in layers according to at least one of random selection trial, self-increment selection trial, overall query selection trial and preset data selection trial, the storage location code of the text characters of each character node in the storage space is determined according to the character code corresponding to the text characters of each character node and the base code of the parent node of each character node, and the storage location code of the parent node of each character node is taken as the check code of each character node, to construct the sensitive word library, thereby solving the technical problems of large storage space and long sensitive word recognition time in the prior art, and achieving the technical effects of reducing the storage space of the sensitive word tree and reducing the sensitive word recognition time.
[0009] In order to make the above objectives, characteristics and advantages of the present application more apparent, clear and easy to understand, the following will describe the preferred embodiments in detail, and the accompanying drawings will be referred to, and the detailed description will be as follows. BRIEF DESCRIPTION OF DRAWINGS
[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments, and it should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as a limitation to the scope, and for those skilled in the art, other related drawings can also be obtained without paying creative labor on the basis of these drawings.
[0011] Figure 1 A flow chart of a word library construction method based on a double-array tree provided by the embodiments of the present application is shown.
[0012] Figure 2 A schematic diagram of a sensitive word tree provided by the embodiments of the present application is shown.
[0013] Figure 3 A functional module diagram of a double-array tree-based dictionary construction device provided by an embodiment of the present application is shown. DETAILED DESCRIPTION
[0014] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described below in connection with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application merely serve the purpose of illustrating and describing and are not intended to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in the present application show the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowcharts can not be implemented in sequence, and the steps that have no logical contextual relationship can be reversed in sequence or implemented simultaneously. In addition, one or more other operations can be added to the flowcharts or one or more operations can be removed from the flowcharts under the guidance of the content of the present application.
[0015] In addition, the described embodiments are merely some of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed present application, but merely represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0016] In the prior art, all sensitive words are combined into a sensitive word library by an exhaustive method. This storage method can cause a large amount of repeatedly stored data, for example, the sensitive word “AB” and the sensitive word “AC” can repeatedly store “A”, causing the sensitive word library to have a large storage space, and when sensitive word recognition is performed, each sensitive word in the sensitive word library needs to be traversed, causing the recognition time to be long. Alternatively, a sensitive word tree is constructed for all sensitive words, different sensitive words are stored by the form of different child nodes collocated with a parent node, and the problem of repeated storage is overcome. However, the sensitive word tree needs to store the connection relationship between different nodes in the form of a structure, so that the storage spaces between different characters of a sensitive word group are discontinuous, for example, a parent node occupies one position in the memory, and a child node of the parent node needs to be stored after being separated by some storage spaces of structures, causing a large amount of structure code to exist in the memory for storing the sensitive word tree. When sensitive word recognition is performed, the structure code needs to be repeatedly read and compiled, and the query pointer needs to be repeatedly jumped, so that the sensitive word recognition is slow and inefficient.
[0017] Based on this, the embodiment of the present application provides a double array tree-based word library construction method and a word query method. The method splits sensitive words and generates a sensitive word tree according to the arrangement order of the text characters of each sensitive word. The method de-duplicates and dictionary encodes each text character after splitting to obtain character encodings of all text characters. The method sequentially determines the base encoding of each character node at each level in the sensitive word tree according to at least one of random selection trial, self-increment selection trial, overall query selection trial, and preset data selection trial. The method determines the storage location encoding of the text character of each character node in the storage space according to the character encoding corresponding to the text character of each character node of the sensitive word tree and the base encoding of the parent node. The method takes the storage location encoding of the parent node of each character node as the check encoding of each character node to construct a sensitive word library. The method solves the technical problems of large storage space and long sensitive word recognition time in the prior art, and achieves the technical effect of reducing the storage space of the sensitive word tree and reducing the sensitive word recognition time. Specifically as follows. Please refer to Figure 1 , Figure 1 The flowchart of the double array tree-based word library construction method provided by the embodiment of the present application. As shown in Figure 1 The double array tree-based word library construction method provided by the embodiment of the present application includes the following steps: S101: Generating a sensitive word tree based on the text characters split from each sensitive word and the arrangement order of the text characters.
[0018] Each path in the sensitive word tree corresponds to a sensitive word.
[0019] That is, each sensitive word is split into at least one text character, and the first text character in all sensitive words is de-duplicated and taken as the first layer character node of the sensitive word tree. In this way, the text characters after the first text character are arranged in each sensitive word according to the arrangement order of the text characters to make each path in the sensitive word tree indicate a sensitive word. That is, for each path in the sensitive word tree, the text characters corresponding to the first layer character node to the bottom layer character node of the path form a sensitive word.
[0020] In addition, each text character obtained by splitting and de-duplicating all sensitive words may be a first layer character node, or only at least one text character is a first layer character node, that is, the number of first layer character nodes is not greater than the number of de-duplicated text characters. Each text character in each sensitive word corresponds to a character node in the sensitive word tree. The same text character may be arranged in multiple character nodes in the sensitive word tree, or different text characters may correspond to different character nodes.
[0021] Please refer to Figure 2 ,Figure 2 This is a schematic diagram of a sensitive word tree provided in an embodiment of this application. Figure 2 As shown, the root node of the entire sensitive word tree is R. If multiple sensitive words include AB, ABB, ABC, AD, BCB, BCD, CBB, CBD, and DAC, each sensitive word is split into multiple text characters. After removing duplicates from the first text character, the first-level character nodes A, B, C, and D of the sensitive word tree are obtained. For the first-level character node A, the sensitive words whose first text character is A are AB, ABB, ABC, and AD. Furthermore, the child nodes of the first-level character node A include child nodes B and D. The first-level character node A and its corresponding child node B can directly form the sensitive word AB. Therefore, the first-level character node A combined with its child node B directly forms a path in the sensitive word tree. The first-level character node A and its corresponding child node B also need to be combined with its grandchild node B to form the sensitive word ABB. The first-level character node A and its corresponding child node B also need to be combined with its grandchild node C to form the sensitive word ABC. The first-level character node A and its corresponding child node D can directly form the sensitive word AD. Therefore, the first-level character node A combined with its child node D directly forms a path in the sensitive word tree. The same logic applies to the first-level character nodes B, C, and D, which will not be elaborated further here. This is how the sensitive word tree is constructed.
[0022] In other words, a sensitive word tree includes at least a root node and character nodes. Character nodes correspond to the text characters of sensitive words. The root node of the sensitive word tree only serves as the parent node of all first-level character nodes and does not correspond to any text characters.
[0023] For example, multiple sensitive words refer to words that need to be identified and processed in advance, such as words that need to be blocked. Furthermore, a text character can correspond to any of the following: a Chinese character, a symbol, a number, a letter, and a word. This application does not limit this.
[0024] S102: After deduplication of the text characters split from the sensitive words, dictionary encoding is performed to obtain the character codes corresponding to each text character.
[0025] In other words, all sensitive words are broken down into individual text characters, and all text characters are deduplicated. The deduplicated text characters are then dictionary-encoded, with each text character corresponding to a character code. The text characters are identified by their individual character codes.
[0026] For example, refer to Table 1, which is a table of correspondence between each text character and its corresponding character code. If the plurality of sensitive words include: AB, ABB, ABC, AD, BCB, BCD, CBB, CBD, and DAC, the text characters obtained by splitting each sensitive word into text characters and removing duplicates are A, B, C, and D.
[0027] Table 1:
[0028] That is, a character code is configured for each text character. The character code can be set as desired, can be set in order of integers, or can be set randomly, as long as the character codes of the text characters are not duplicated. The present application does not limit this.
[0029] Specifically, the sensitive word tree further includes an end leaf node for indicating the end of a path, and each end leaf node includes an end character. The method further includes performing dictionary encoding on the end character to obtain an end character code corresponding to the end character.
[0030] The parent node of the end leaf node is the bottommost character node of a path of the sensitive word tree, or the parent node of the end leaf node corresponds to the character node of the last text character of the sensitive word. Further, the end leaf node does not correspond to a text character, but the parent node of the end leaf node corresponds to a text character.
[0031] Each end leaf node corresponds to an end character, and the end characters corresponding to the end leaf nodes can be different or the same. The end characters corresponding to the end leaf nodes should be different from the text characters, so as to distinguish whether the path is ended.
[0032] Further, when each end leaf node corresponds to a different end character, the end characters can be set in increasing order of integers, and the number of end characters is equal to the number of all sensitive words in the sensitive word tree, so as to quickly identify which sensitive word in the sensitive word tree is hit by the text to be identified. When each end leaf node corresponds to the same end character, the end character is used to represent the end of each path.
[0033] That is, the end characters of the end leaf nodes coupled by each path in the sensitive word tree can be the same or different. For example, the end characters of all end leaf nodes can be set to 0, or different paths can be coupled with different end characters of end leaf nodes.
[0034] If each end leaf node corresponds to a different end character, each end character is dictionary encoded, and the different end characters can be set to the same end character code or different end character codes. If each end leaf node corresponds to the same end character, only one end character needs to be dictionary encoded, i.e., one end character code refers to the end characters of each end leaf node. Moreover, the end character code should be different from the character code (Code) of the text character to distinguish the end character code from the character code of the text character.
[0035] As shown in Figure 2 , each path corresponds to an end character of an end leaf node. For the first layer character node A, the first layer character node A is matched with a child node B as a path corresponding to a sensitive word AB, and the path is set with an end character 1. The first layer character node A and its corresponding child node B and grandchild node B are matched as a path corresponding to a sensitive word ABB, and the path is set with an end character 2. The first layer character node A and its corresponding child node B and grandchild node C are matched as a path corresponding to a sensitive word ABC, and the path is set with an end character 3. The first layer character node A and its corresponding another child node D are matched as a path corresponding to a sensitive word AD, and the path is set with an end character 4. The end characters of each path corresponding to the first layer character node B, the first layer character node C, and the first layer character node D are the same, and thus are not described herein. Figure 2 The end characters in the above include end character 1 to end character 9. Each end character is dictionary encoded, and the end character 1 to end character 9 can be set to different end character codes.
[0036] For example, refer to Table 2, which refers to a table of each end character and its corresponding end character code. If the end characters include end character 1 to end character 9, and the end character code of each end character is set to a negative number.
[0037] Table 2:
[0038] Returning to Figure 1 , S103: sequentially determining the base code of each character node in the sensitive word tree according to at least one of random selection trial, self-increment selection trial, overall query selection trial, and preset data selection trial.
[0039] The random selection of trial refers to randomly setting the basic code for each character node, the self-increment selection of trial refers to setting the basic code for each character node in ascending order of integer, the overall query selection of trial refers to setting the basic code for each character node as a whole storage, and the preset data selection of trial refers to selecting each preset data in a preset data set as the basic code for each character node. Therefore, the basic codes of some character nodes in all character nodes can be the same, or the basic codes of each character node can be different.
[0040] For example, the basic code of the root node in the sensitive word tree can be set to be only for the root node, that is, the basic code of the root node can be preset to be different from the basic codes of any other character node and the end leaf node. Of course, the basic code of the root node can also be preset to be the same as the basic code of any other character node and / or the end leaf node, which is not limited herein. The basic code of the end leaf node in the sensitive word tree can be set according to the setting mode of the basic code of the character node; or the basic code of the end leaf node can be set to be only for the end leaf node, that is, the preset end basic code is different from the basic codes of the root node and any other character node.
[0041] Specifically, the basic code of each character node in the sensitive word tree is determined in sequence and in layers, including: setting a virtual code of the character node according to a preset trial rule, and determining at least one storage location code corresponding to the storage space required to accommodate all child nodes of the character node through the virtual code and the character codes of all child nodes of the character node; when all storage locations corresponding to each storage location code are idle, the virtual code corresponding to the storage location is taken as the basic code of the character node.
[0042] That is, for each character node in the sensitive word tree (each character node corresponding to each path in the sensitive word tree), a virtual code of the character node is assumed according to a preset trial rule, and whether all storage locations corresponding to at least one storage location code required to accommodate all child nodes of the character node are idle is determined through the assumed virtual code and the character codes of all child nodes of the character node. When all storage locations corresponding to all storage location codes are idle, the assumed virtual code is taken as the basic code of the character node.
[0043] The preset trial rule can be that the virtual code is gradually increased from a preset minimum virtual code, and when the virtual code in the current assumption cannot query a storage location code of a storage location that is all idle, the virtual code in the current assumption is added by a preset increase value to calculate the virtual code in the next assumption, and the preset increase value can be 1; or the increase value used each time is set to a different value, for example, if the virtual code in the current assumption does not meet the requirement, one is added to the virtual code in the current assumption as the virtual code in the next assumption, if it still does not meet the requirement, three is added to the virtual code in the next assumption, and the like, and the increase is in an odd number increasing order; or at least one of random selection trial, self-increment selection trial, overall query selection trial, and preset data selection trial is used to determine the virtual code of each character node in the sensitive word tree for trial, which will not be repeated here.
[0044] The storage location code can be a code corresponding to the storage location of each node (including the root node, the character node, and the end leaf node) in the sensitive word tree in storage, and different storage locations correspond to different storage location codes, that is, each node in the sensitive word tree corresponds to a storage location code. In this way, the storage location of the text character corresponding to the root node or the character node or the end character corresponding to the end leaf node indicated by each node is reflected through the storage location code of the node.
[0045] The storage location code can also be a code corresponding to the storage location of the base code and / or the check code of each node (including the root node, the character node, and the end leaf node) in the sensitive word tree in storage, and different storage locations correspond to different storage location codes, that is, the base code and / or the check code of each node in the sensitive word tree correspond to a storage location code.
[0046] For example, for each first layer character node in the sensitive word tree, the sum of the base code of the parent node (i.e., the root node of the sensitive word tree) of the first layer character node and the character code of the first layer character node is taken as the storage location code of the first layer character node, and the base code of the root node of the sensitive word tree is a preset base code, which can be set to 1. Further, the child node of the root node in the sensitive word tree is the first layer character node, or the character node obtained by removing the first text character of all sensitive words. For example, Figure 2As shown, the first layer character nodes of the sensitive word tree include first layer character node A, first layer character node B, first layer character node C, and first layer character node D. Further, the storage location code of the first layer character node A is the sum of the base code 1 of the root node and the character code 1 of the character node A, the storage location code of the first layer character node B is the sum of the base code 1 of the root node and the character code 2 of the character node B, the storage location code of the first layer character node C is the sum of the base code 1 of the root node and the character code 3 of the character node C, and the storage location code of the first layer character node D is the sum of the base code 1 of the root node and the character code 4 of the character node D. Please refer to Table 3, which refers to the double array table of the first layer character nodes.
[0047] Table 3:
[0048] That is, for each character node, it is determined whether the sensitive word library can place all the child nodes of the character node by determining whether the storage location corresponding to at least one storage location code corresponding to the storage space required by all the child nodes of the character node is idle. If the storage locations corresponding to the storage location codes of all the child nodes of the character node are all idle, it means that the storage locations of all the child nodes of the character node can be found in the sensitive word library through virtual coding, and thus the virtual code set this time can be used as the base code of the character node.
[0049] For example, each storage location code can correspond to a fixed space length in the storage space, such as one byte or multiple bytes, or each storage location code can correspond to different byte numbers, which is not limited in the present application. If each storage location code corresponds to 2 bytes, the storage space corresponding to each storage location code occupies 16 bits.
[0050] The virtual code of the character node is set according to a preset trial rule, including: determining whether the overall query condition is met according to the number of child nodes of the character node and the character codes corresponding to each child node; and when the overall query condition is met, determining the value of the virtual code according to the difference between the smallest character code and the largest character code in the child nodes that meet the overall query condition.
[0051] The all child nodes of the character node are divided into a first number of partial child nodes and a second number of other child nodes, the first number is at least one, and the second number is a difference between the number of all child nodes of the character node and the number of partial child nodes. Further, the overall query condition means that the partial child nodes of a character node are determined as a whole to determine whether the storage space of the sensitive word library can place the partial child nodes at one time; if the first number of partial child nodes is equal to the number of all child nodes of the character node, and the second number is 0, all child nodes of the character node are taken as a whole; if the first number of partial child nodes is less than the number of all child nodes of the character node, and the second number is not 0, the partial child nodes of the character node are taken as a whole.
[0052] Further, if the first number of partial child nodes is equal to the number of all child nodes of the character node, the child nodes satisfying the overall query condition refer to all child nodes of the character node, and the difference between the smallest character code and the largest character code in the child nodes satisfying the overall query condition refers to the difference between the smallest character code and the largest character code in all child nodes of the character node; if the first number of partial child nodes is less than the number of all child nodes of the character node, the child nodes satisfying the overall query condition refer to the partial child nodes of the character node, and the difference between the smallest character code and the largest character code in the child nodes satisfying the overall query condition refers to the difference between the smallest character code and the largest character code in the partial child nodes of the character node.
[0053] The determination of whether the overall query condition is satisfied according to the number of child nodes of the character node and the character codes corresponding to the child nodes includes: taking the difference between the largest character code and the smallest character code of all child nodes of the character node as the maximum difference value of all child nodes corresponding to the character node; determining whether the number of all child nodes of the character node is greater than a first preset value, and determining whether the ratio of the maximum difference value of all child nodes corresponding to the character node to the number of all child nodes is less than a second preset value; when the number of all child nodes of the character node is greater than the first preset value, and the ratio of the maximum difference value of all child nodes corresponding to the character node to the number of all child nodes is less than the second preset value, it is determined that all child nodes of the character node satisfy the overall query condition.
[0054] Alternatively, determining whether the overall query conditions are met based on the number of child nodes of the character node and the character codes corresponding to each child node includes: taking the difference between the largest and smallest character codes of some child nodes of the character node as the maximum difference of some child nodes corresponding to the character node; determining whether the number of some child nodes of the character node is greater than a first preset value, and determining whether the ratio of the maximum difference of some child nodes corresponding to the character node to the number of some child nodes is less than a second preset value; when the number of some child nodes of the character node is greater than the first preset value, and the ratio of the maximum difference of some child nodes corresponding to the character node to the number of some child nodes is less than the second preset value, it is determined that some child nodes of the character node meet the overall query conditions.
[0055] Furthermore, by using a first preset value and a second preset value, we can measure whether all or some child nodes are numerous and densely arranged. When the overall query conditions are met, it is considered that all or some child nodes are numerous and densely arranged, thus allowing all or some child nodes to be judged as a whole. This is equivalent to treating all or some child nodes of the character node as a whole to search for storage space, which can significantly improve storage efficiency compared to searching for storage space for each individual child node.
[0056] For example, the first preset value is set to 1, and the second preset value is set to 2. Figure 2 As shown, the child nodes of the first-level character node A include the second-level character node B and the second-level character node D. Both characters are greater than the first preset value. The character code of character node B is 2, and the character code of character node D is 4. Then the maximum difference of all child nodes corresponding to the first-level character node A is 4-2=2. The ratio of the maximum difference (Code Range) to the number of all child nodes is 1. The ratio is less than the second preset value. Therefore, it is considered that the two child nodes of the first-level character node A meet the overall query condition of a large number of densely arranged child nodes. Thus, the second-level character nodes B and D are treated as a whole to determine whether the required storage space is free.
[0057] Specifically, when the overall query condition is met, the value of the virtual code is determined according to a difference between the minimum character code and the maximum character code in the child nodes meeting the overall query condition, including: if all the child nodes of the character node meet the overall query condition, the corresponding storage location code of the minimum character code in the child nodes is taken as the starting point of the corresponding storage location code of the required storage space of all the child nodes of the character node; the storage space from the corresponding storage location code of the minimum character code to the corresponding storage location code of the maximum character code in all the child nodes is taken as the storage space for judging whether it is idle or not; if it is idle, the current virtual code corresponding to the storage location corresponding to each storage location code when all the storage locations are idle is taken as the basic code of the character node; if it is not idle, the value of the next round of virtual code is set to be at least the difference between the maximum character code and the minimum character code in all the child nodes plus 1 on the basis of the current virtual code.
[0058] In the method, the storage locations corresponding to the storage location codes of the overall child nodes of the character node are determined to be idle or not by the following method: the virtual code of the character node is set to be a preset value calculated for the first time, a first sum value of the virtual code of the character node and the minimum character code of the overall child nodes is calculated, and the first sum value is taken as the starting point of the storage location code corresponding to the minimum character code of the overall child nodes; a second sum value obtained by adding 1 to the maximum difference value (Code Range) corresponding to the overall child nodes of the character node is calculated, and the second sum value is taken as the offset length (Jump size), or the second sum value refers to the difference between the minimum character code and the maximum character code in the child nodes meeting the overall query condition plus 1; the length from the starting point of the storage location code to the ending point of the storage location code is the maximum difference value, so as to determine the ending point of the storage location code; when the entire storage location from the starting point of the storage location code to the ending point of the storage location code is idle, it is determined that the storage locations corresponding to the storage location codes of the overall child nodes of the character node are all idle.
[0059] For example, when not all storage locations from the start to the end of the storage location encoding are free, the virtual encoding of the previously assumed character node can be increased by the offset length (Jump size) to obtain the current virtual encoding of the character node. The sum of the virtual encoding of the character node and the minimum character encoding of all child nodes can then be used as the starting point of the current storage location encoding. Alternatively, when not all storage locations from the start to the end of the storage location encoding are free, the virtual encoding of the previously assumed character node can be increased by twice the offset length (Jump size) to obtain the current virtual encoding of the character node. The sum of the current virtual encoding of the character node and the minimum character encoding of all child nodes can then be used as the starting point of the current storage location encoding, thus improving the efficiency of finding storage locations.
[0060] For example, such as Figure 2 As shown, the child nodes of the first-level character node A include the second-level character node B and the second-level character node D. When determining that the two child nodes of the first-level character node A satisfy the overall query condition of a large number of densely arranged child nodes, it is assumed that the initial virtual code of the first-level character node A is 1. The maximum difference between the virtual code 1 of the first-level character node A and the character code of the second-level character node B with the smallest character code is calculated. The maximum difference between the character codes of all child nodes of the first-level character node A is 2, that is, the difference between the character code 4 of the second-level character node D and the character code 2 of the second-level character node B is 2. The maximum difference 2 is calculated and one is added to obtain the second sum value 3. Therefore, the offset length is 3. Then, the storage location code 3 can be used as the starting point, and the storage location code 5 can be determined according to the maximum difference 2 as the ending point. In this way, at least one storage location code corresponding to all child nodes of the first-level character node A is determined to be storage location code 3 to storage location code 5. It is then determined whether the overall storage locations corresponding to storage location codes 3 to storage location code 5 are all free. As shown in Table 3, storage location code 3 is occupied by the first-level character node B, storage location code 4 is occupied by the first-level character node C, and storage location code 5 is occupied by the first-level character node D. Therefore, the basic code of the first-level character node A cannot be the current virtual code 1.
[0061] For example, when it is determined that the base encoding of the first layer character node A cannot be the current virtual encoding 1, the last set virtual encoding 1 of the first layer character node A is added by the calculated offset length 3 (i.e. the difference between the maximum character encoding and the minimum character encoding of the child nodes plus 1) as the virtual encoding of the first layer character node A in this time, i.e. 1+3=4, and the virtual encoding of the first layer character node A is added by the minimum character encoding in the child nodes (4+2=6) as the starting point of the storage location encoding in this time. Then, it is determined whether the overall storage locations corresponding to the storage location encoding 6 to the storage location encoding 8 are all idle, and when it is determined that the storage locations are all idle, it is determined that the base encoding of the first layer character node A is the virtual encoding 4 in this time, which can avoid the one-by-one attempt of the virtual encoding from 1, 2, 3, 4, 5, … when determining the base encoding of the first layer character node A, and can also avoid the one-by-one query of the idle storage space corresponding to the child nodes after assuming the virtual encoding, which greatly improves the storage efficiency.
[0062] Further, when it is determined that the base encoding of the first layer character node A is 4, the storage location encoding of the second layer character node B is calculated as the sum of the base encoding of the parent node of the second layer character node B and the character encoding of the second layer character node B (i.e. 4+2=6), and the storage location encoding of the second layer character node B is 6. The storage location encoding of the second layer character node D is calculated as the sum of the base encoding of the parent node of the second layer character node D and the character encoding of the second layer character node D (i.e. 4+4=8), and the storage location encoding of the second layer character node D is 8.
[0063] For example, the base encoding can be understood as an offset, i.e. the base encoding of the first layer character node A is 4, which can be understood as uniformly moving four storage spaces from the storage location encoding corresponding to the character encoding of the second layer character nodes B and D as child nodes as the starting point.
[0064] Please refer to Table 4, which refers to the double array table of the first layer character node and the child nodes of the first layer character node A.
[0065] Table 4:
[0066] Or, the in meeting the overall query condition, then according to the difference between the smallest character encoding and the largest character encoding in the child node meeting the overall query condition, the value of the virtual encoding is determined, including: if the partial child node of the character node meets the overall query condition, the corresponding storage location encoding of the smallest character encoding in the child node meeting the overall query condition is taken as the starting point of the corresponding storage location encoding of the required storage space of the partial child node of the character node; the storage space from the corresponding storage location encoding of the smallest character encoding to the corresponding storage location encoding of the largest character encoding in the child node meeting the overall query condition is taken as the overall judgment of whether the storage space is idle; and based on the current virtual encoding and the character encoding of the child node of the character node which does not meet the overall query condition, the corresponding storage location encoding of the required storage space of the other child node of the character node is determined, and whether the storage location corresponding to each storage location encoding is idle is judged; if yes, the current virtual encoding corresponding to the storage location when each storage location encoding corresponding to the storage location is idle is taken as the basic encoding of the character node; if no, the value of the next round of virtual encoding is set to be at least the difference between the largest character encoding and the smallest character encoding in the child node meeting the overall query condition plus 1 on the current virtual encoding.
[0067] That is, only the partial child node of the character node is taken as a whole, it is assumed that the virtual encoding of the character node calculated for the first time is 1, the virtual encoding 1 of the character node is added to the smallest character encoding of the partial child node as the storage location encoding of the child node with the smallest character encoding, the storage location encoding is taken as the starting point, the difference between the largest character encoding and the smallest character encoding of the partial child node is taken as the offset length, so that the storage location encoding endpoint corresponding to the partial child node covering the difference is determined from the starting point of the storage location encoding, and whether the overall storage location corresponding to the starting point to the endpoint storage location encoding corresponding to the partial child node is idle is determined; for the other child nodes of the character node except the partial child node, for each other child node, the virtual encoding 1 of the character node is added to the character encoding of the other child node as the storage location encoding of the other child node, and whether the storage location corresponding to each storage location encoding corresponding to the other child node is idle is determined; only when the storage locations corresponding to the storage location encodings corresponding to the partial child node and the other child nodes are all idle, the virtual encoding 1 of the character node is taken as the basic encoding 1 of the character node. If the overall storage space corresponding to the storage location encoding of the partial child node is not idle or the storage location corresponding to the storage location encoding of any other child node is not idle, the virtual encoding of the character node is added to the offset length of the partial child node, that is, the virtual encoding 1 of the character node is added to the difference between the largest character encoding and the smallest character encoding of the partial child node plus 1, as the virtual encoding of the character node in the next trial.
[0068] Specifically, the method further comprises: when the overall query condition is not satisfied, determining a storage location code corresponding to a required storage space of each sub-node of the character node based on a current virtual code and the character code of each sub-node of the character node respectively, and judging whether the storage location corresponding to each storage location code is idle; if yes, taking the current virtual code corresponding to the case that each storage location code corresponds to an idle storage location as the basic code of the character node; if no, setting the value of the next round of virtual code as a preset value added to the current virtual code, or randomly obtaining the value of the next round of virtual code within a preset value range without repetition, or obtaining the value of the next round of virtual code according to a preset value sequence.
[0069] That is, when the number of overall sub-nodes of the character node is less than or equal to a first preset value, and / or the ratio of the maximum difference of the character codes corresponding to the overall sub-nodes to the number of the overall sub-nodes is greater than or equal to a second preset value, it is determined that the overall sub-nodes of the character node do not satisfy the overall query condition, wherein the overall sub-nodes include all sub-nodes or part of the sub-nodes.
[0070] Further, when the overall query condition is not satisfied, it is considered that the number of all sub-nodes or part of the sub-nodes is not large and / or the arrangement is not dense, so that all sub-nodes or part of the sub-nodes cannot be judged as a whole. Further, it is necessary to find storage space for each sub-node of the character node.
[0071] That is, when the overall query condition is not satisfied, for each character node, a virtual code of the character node is assumed, and the sum of the virtual code of the character node and the character code of each sub-node of the character node is taken as a storage location code corresponding to a required storage space of each sub-node of the character node, and it is judged whether the storage location corresponding to each storage location code is idle. When the storage location corresponding to each storage location code is idle, the virtual code of the character node is taken as the basic code of the character node. When the storage location corresponding to any storage location code is not idle, the value of the next virtual code is set as the sum of the current virtual code and a preset value, or a preset value within a preset value range is randomly selected without repetition as the value of the next round of virtual code, or a preset value corresponding to the next sequence in the sequence corresponding to the current virtual code is taken as the value of the next round of virtual code. Further, for each character node, the virtual code of the character node is set to different values each time.
[0072] For example, if the first preset value is 1, the second preset value is 2, the child node of the first layer character node B is the second layer character node C, the number of child nodes of the first layer character node B is not greater than the first preset value 1, and the first layer character node B does not satisfy the overall query condition of a large number of child nodes and dense arrangement, the storage location corresponding to the storage location code of the second layer character node C can be determined by sequentially adding 1 to the virtual code of the first layer character node B. The storage location corresponding to the storage location code of the second layer character node C can also be determined by selecting different values of the virtual code of the first layer character node B each time. If the virtual code of the first layer character node B is sequentially added by 1, and assuming that the first value of the virtual code of the first layer character node B is 1, the storage location code of the second layer character node C is the sum of the virtual code 1 of the first layer character node B and the character code 3 of the second layer character node C, which is 4. At this time, it is necessary to determine whether the storage space with the storage location code 4 is idle. As can be seen from Table 4, the storage location code 4 is occupied by the first layer character node C. Therefore, the virtual code of the first layer character node B needs to be added by 1 to be reset to 2. The storage location code of the second layer character node C is calculated again as the sum of the virtual code 2 of the first layer character node B and the character code 3 of the second layer character node C, which is 5. As can be seen from Table 4, the storage location code 5 is occupied by the first layer character node D. Therefore, the virtual code of the first layer character node B needs to be added by 1 to be reset to 3. In this way, the virtual code of the first layer character node B is set to 4, the storage location code of the second layer character node C is the sum of the virtual code 4 of the first layer character node B and the character code 3 of the second layer character node C, which is 7. As can be seen from Table 4, the storage location corresponding to the storage location code 7 is not occupied. Therefore, the basic code of the first layer character node B can be set to 4. At this time, the storage location code of the second layer character node C is 7. Further, when the number of child nodes is relatively small and / or arranged sparsely, the child nodes can be inserted and stored in the idle storage location by sequentially determining whether the storage location code of the child node is occupied, thereby improving the utilization rate of the fragmented space, improving the storage utilization rate, and reducing the storage volume.
[0073] Further, the basic code of each character node of the sensitive word tree in Figure 2 can be determined in the above manner.
[0074] Returning to Figure 1 , S104: based on the character code corresponding to the text character of each character node and the basic code of the parent node thereof, the storage location code of the text character of the character node in the storage space is determined, and the storage location code of the parent node of the character node is taken as the check code of the character node, so as to construct the sensitive word library.
[0075] That is, after determining the base encoding of each character node of the sensitive word tree, the storage location encoding of the child node of the character node can be set as the sum of the base encoding of the character node and the character encoding corresponding to the text character of the child node, and the storage location encoding of the parent node of the character node is the check encoding of the character node, so that each character node and its parent node can be associated through the check encoding.
[0076] Specifically, the method further comprises: for the bottommost character node of each path, setting a preset end base encoding as the base encoding of the bottommost character node, and setting the storage location encoding of the parent node of the bottommost character node as the check encoding of the bottommost character node, so as to add the bottommost character node to the sensitive word library.
[0077] That is, the character node of the last text character of a path reaching the sensitive word tree is marked by the preset end base encoding, which reaches the effect of informing that the last text character of a sensitive word has been queried. The bottommost character node of a path can also be the parent node of other character nodes, or the last text character of a sensitive word can have other text characters as the next text character of the aforementioned last text character, for example, in the sensitive word AB, the text character B is the last text character, while in the sensitive word ABC and the sensitive word ABC, the text character B is not the last text character. Further, at this time, directly setting the preset end base encoding as the base encoding of the bottommost character node means that only the sensitive word AB needs to be queried when querying, which means that the sensitive word has been queried, and there is no need to determine whether it is the sensitive word AB or the sensitive word ABC. Alternatively, if there is no case in which the bottommost character node of a path is also the parent node of other character nodes in the sensitive word tree, the preset end base encoding can be directly set as the base encoding of the bottommost character node.
[0078] Specifically, the sensitive word tree further comprises an end leaf node for indicating the end of a path, and the method further comprises: for the bottommost character node of each path, if the bottommost character node is also the parent node of the character node of other paths, setting the end leaf node for the bottommost character node, setting a preset end base encoding as the base encoding of the end leaf node, and setting the storage location encoding of the bottommost character node as the check encoding of the end leaf node, so as to add the end leaf node to the sensitive word library; if the bottommost character node is not the parent node of the character node of other paths, setting a preset end base encoding as the base encoding of the bottommost character node, and setting the storage location encoding of the parent node of the bottommost character node as the check encoding of the bottommost character node, so as to add the bottommost character node to the sensitive word library.
[0079] That is, when the bottommost character node of a path is also the parent node of other path character nodes, the bottommost character node in this case needs to be distinguished in order to distinguish the sensitive word AB or the sensitive word ABB in subsequent queries. Further, when the bottommost character node is also the parent node of other path character nodes, an end leaf node is set for the bottommost character node, that is, the end leaf node is taken as the child node of the bottommost character node, and the base encoding of the bottommost character node is calculated according to the virtual encoding manner as described above, the preset end base encoding is taken as the base encoding of the end leaf node, and the storage location encoding of the bottommost character node is taken as the check encoding of the end leaf node. When the bottommost character node is not the parent node of other path character nodes, the end leaf node of the bottommost character node can not be stored, and the preset end base encoding is directly taken as the base encoding of the bottommost character node, and the storage location encoding of the parent node of the bottommost character node is taken as the check encoding of the bottommost character node.
[0080] As Figure 2As shown, the first layer character node A in combination with the child node B directly serves as a path of the sensitive word tree for indicating the sensitive word AB, and the child node B of the first layer character node A is the bottom layer character node of the path; the first layer character node A in combination with the child node B and the grandchild node B serves as a path of the sensitive word tree for indicating the sensitive word ABB, and the grandchild node B of the first layer character node A is the bottom layer character node of the path. Further, the child node B of the first layer character node A is both the bottom layer character node of one path of the sensitive word tree and the parent node of the bottom layer character node of another path of the sensitive word tree. At this time, if only the character nodes are stored in the sensitive word library, the sensitive word AB is missing in the sensitive word library, and further, the ending leaf node 1 of the path corresponding to the sensitive word AB needs to be stored in the sensitive word library. Therefore, for the case that the child node of the bottom layer character node includes both the ending leaf node and other character nodes, the ending leaf node in the child node of the bottom layer character node is taken as the target ending leaf node, the preset ending basic code -1 is directly taken as the basic code of the target ending leaf node, and the storage location code of the bottom layer character node is taken as the check code of the target ending leaf node, so as to add the target ending leaf node to the sensitive word library. At this time, all the ending leaf nodes do not need to be stored in the sensitive word library, and only the target ending leaf node needs to be added to the sensitive word library. For the bottom layer character nodes of the parent nodes of the non-other character nodes in the sensitive word tree, including the bottom layer character node D corresponding to the sensitive word AD, the bottom layer character node B corresponding to the sensitive word ABB, the bottom layer character node C corresponding to the sensitive word ABC, the bottom layer character node B corresponding to the sensitive word BCB, the bottom layer character node D corresponding to the sensitive word BCD, the bottom layer character node B corresponding to the sensitive word CBB, the bottom layer character node D corresponding to the sensitive word CBD, and the bottom layer character node C corresponding to the sensitive word DAC, further, the preset ending basic code -1 is directly taken as the basic code of the bottom layer character node whose child node is only the ending leaf node, and the storage location code of the parent node of the bottom layer character node is taken as the check code of the bottom layer character node, so as to add the bottom layer character node whose child node is only the ending leaf node to the sensitive word library. In the above manner, Table 5 is obtained, which refers to a double array table obtained by adding each character node and the target ending leaf node to the sensitive word library.
[0081] Table 5:
[0082] Further, the basic code of the bottom layer character node whose child node is only the ending leaf node and the target ending leaf node is set to the preset ending basic code -1, so that the ending of the sensitive word is distinguished by the preset ending basic code -1, and thus all the ending leaf nodes do not need to be added to the sensitive word library, and the storage space is saved.
[0083] Specifically, the method further comprises: determining the storage location code of the end character of the end leaf node in the storage space according to the end character code corresponding to the end character of the end leaf node and the base code of the parent node of the end leaf node, taking the preset end base code as the base code of the end leaf node, and taking the storage location code of the parent node of the end leaf node as the check code of the end leaf node, so as to add the end leaf node to the sensitive word library.
[0084] That is, all end leaf nodes are added to the sensitive word library, and for each end leaf node, the sum of the base code of the parent node of the end leaf node and the end character code of the end character of the end leaf node is taken as the storage location code of the end leaf node, the preset end base code is taken as the base code of the end leaf node, and the storage location code of the parent node of the end leaf node is taken as the check code of the end leaf node, so as to add each end leaf node to the sensitive word library and distinguish the end leaf nodes by the preset end base code. For example, refer to Table 6, which refers to the double array table obtained by adding each character node and all end leaf nodes to the sensitive word library.
[0085] Table 6:
[0086] Further, each character node and end leaf node of the sensitive word tree can be stored in the sensitive word library layer by layer, the parent-child relationship of each node can be associated and recorded by the base code and the check code, and subsequent nodes can be inserted into the idle positions of the table in the above manner, so as to improve the storage efficiency and reduce the storage volume.
[0087] Specifically, the sensitive word library further comprises a combined sensitive word, and the method further comprises: setting the character node corresponding to the target text character of the combined word in each combined sensitive word as a first matching number, and setting the character node corresponding to the text character other than the target text character of the combined word as a second matching number, wherein the first matching number is greater than the second matching number, and the matching number is used to indicate the matching number of the query character and the text character of the corresponding character node stored in the sensitive word library.
[0088] The combined sensitive word comprises at least one first text character, a random number of random characters and at least one second text character arranged in sequence. The first text character and the second text character are text characters split from the sensitive word, the random character is an arbitrary character, and the random character can be a text character in a dictionary code or a character in a dictionary code. The random number is an integer greater than 0. The target text character refers to the first text character closest to the random character or the last first text character. The first matching number refers to the maximum order of the first second text character closest to the random character relative to the last first text character. That is, if there is a first second text character within the first matching number after the last first text character, it is considered to possibly contain the combined sensitive word.
[0089] For example, if the combined sensitive word can be AB…C, the text character C is considered to be the combined sensitive word AB…C if it appears within 10 characters after the text characters A and B are identified. Further, in the combined sensitive word AB…C, the first text characters include the text characters A and B, the target text character is the text character B, the first matching number is 10, and the second text character is the text character C. That is, after the target text character B is identified, only the text character C needs to be identified within 10 matches, and it is considered to be the combined sensitive word AB…C.
[0090] For example, only the combined code needs to be added to each node in the double array table. The combined code indicates that the matching number of the node is the first matching number or the second matching number. The combined code of the target text character of the combined sensitive word is set to the first matching number, and the combined code of the text character other than the target text character is set to the second matching number, where the second matching number can be set to 1. Further, the combined code is added to Table 5 to obtain Table 7, which refers to another double array table obtained by adding the sensitive word library to each character node and the target end leaf node.
[0091] Table 7:
[0092] Based on the same application concept, the present embodiment also provides a word query method corresponding to the word library construction method provided in the above-mentioned embodiment. Since the word query method in the present embodiment has a similar problem solving principle as the word library construction method of the above-mentioned embodiment of the present application, the implementation of the word query method can be referred to the implementation of the word library construction method, and the repeated parts will not be described again.
[0093] The method for querying a word based on a double-array tree provided in the embodiments of the present application applies the sensitive word library created by the method described in the foregoing embodiments. Specifically, the method for querying a word based on a double-array tree includes: determining whether a first query character in a to-be-queried sensitive word is a text character coded in a dictionary; if yes, determining a first target storage location code of the first query character in a storage space based on a preset basic code of a root node of the sensitive word library and a character code corresponding to the first query character of the to-be-queried sensitive word; determining whether the text character stored in the storage location corresponding to the first target storage location code is the first query character and whether the check code corresponding to the first target storage location code is the storage location code of the root node; if yes, determining whether the basic code corresponding to the first target storage location code is a preset ending basic code; if no, determining a second target storage location code of a second query character of the to-be-queried sensitive word based on the basic code corresponding to the first target storage location code and the character code corresponding to the second query character; determining whether the current query character meets the sensitive word character determination condition based on the text character stored in the storage location corresponding to the current target storage location code, the basic code and the check code; and if yes, determining the to-be-queried sensitive word as a sensitive word stored in the sensitive word library.
[0094] The to-be-queried sensitive word can be obtained by extracting characters from a sentence in a moving window, and the size of the moving window can be changed. Alternatively, the to-be-queried sensitive word is obtained by randomly selecting adjacent characters from a sentence, or at least one to-be-queried sensitive word is determined by a preset word segmentation dictionary. In this way, multiple to-be-queried sensitive words can be split from a sentence, and the multiple to-be-queried sensitive words can be processed in parallel to identify whether each to-be-queried sensitive word is a sensitive word.
[0095] The first query character refers to a first query character in the sensitive word to be checked. That is, it is determined whether the first query character of the sensitive word to be checked is a text character that enters the dictionary encoding. When the first query character is a text character that enters the dictionary encoding, it is further determined whether the first query character is a text character indicated by a first layer character node of the sensitive word tree (or a text character indicated by a child node of a root node of the sensitive word tree). When it is determined that the first query character is a text character indicated by the first layer character node of the sensitive word tree, a first target storage location encoding of the first query character in the storage space can be calculated according to a sum of a preset basic encoding of a root node of the sensitive word library and a character encoding corresponding to the first query character. Then, it is determined whether a text character stored in a storage location corresponding to the first target storage location encoding is the first query character by using a double array table, and it is determined whether a check encoding corresponding to the first target storage location is a storage location encoding of the root node. In this way, it is determined whether the first query character is a first layer character node of the sensitive word tree.In this way, when the first target storage location code corresponds to the storage location code of the text character stored in the first target storage location code and the check code corresponding to the first target storage location code is the storage location code of the root node, it is determined whether the base code corresponding to the first target storage location code is the preset end base code -1 or whether the storage location corresponding to the storage location code indicated by the sum of the base code corresponding to the first target storage location code and the end character code 0 corresponds to the end character code 0; when the base code corresponding to the first target storage location code is the preset end base code -1 or the storage location corresponding to the storage location code indicated by the sum of the base code corresponding to the first target storage location code and the end character code 0 corresponds to the end character code 0, it is considered that the node indicated by the first target storage location code is the last layer character node of the sensitive word, which means that the first query character is a sensitive word; if the base code corresponding to the first target storage location code is not the preset end base code -1 and the storage location corresponding to the storage location code indicated by the sum of the base code corresponding to the first target storage location code and the end character code 0 does not correspond to the end character code 0, it is considered that the next query character (second query character) of the first query character needs to be sequentially queried; thus, by calculating the sum of the base code corresponding to the first target storage location code and the character code corresponding to the second query character, the second target storage location code of the second query character in the storage space is obtained, and it is again determined whether the text character stored in the double array table corresponding to the second target storage location code is consistent with the second query character and whether the check code corresponding to the second target storage location code is the first target storage location code; in this way, when the text character stored in the double array table corresponding to the second target storage location code is consistent with the second query character and the check code corresponding to the second target storage location code is the first target storage location code, it is considered that the child node of the first query character in the sensitive word tree includes the second query character, and so on. Each query character of the sensitive word to be searched is sequentially matched, and it is determined that each query character is matched and the query character of the sensitive word to be searched includes the bottom layer text character of a path in the sensitive word tree, and it is considered that the sensitive word to be searched is a sensitive word stored in the sensitive word library.
[0096] For example, if the sensitive word to be checked is ABC, first determine that the first query character A has a character code of 1 in the dictionary encoding, and calculate the sum of the character code 1 of A and the preset base code 1 of the root node as 2, considering that the first target storage location code of the query character A is 2, and from Table 5, the character stored in the storage location corresponding to the storage location code 2 is A, which is consistent with the query character A, the check code corresponding to the storage location code 2 is 0, and the check code 0 is the storage location code of the root node. In this way, it is determined that the query character A matches the first layer character node A of the sensitive word tree; determine the character code of the second query character B as 2, and calculate the sum of the character code 2 of the second query character B and the base code 4 of the first layer character node A as 6, considering that the second target storage location code of the second query character B is 6, and from Table 5, the character stored in the storage location corresponding to the storage location code 6 is B, which is consistent with the second query character B, the check code corresponding to the storage location code 6 is 2, and the check code 2 is consistent with the first target storage location code 2. In this way, it is determined that the second query character B is a child node of the first layer character node A of the sensitive word tree, i.e., the second query character B is a second layer character node B of the sensitive word tree; again determine the character code of the third query character C as 3, and calculate the sum of the character code 3 of the third query character C and the base code 13 of the second layer character node B as 16, considering that the third target storage location code of the third query character C is 16, and from Table 5, the character stored in the storage location corresponding to the storage location code 16 is C, which is consistent with the third query character C, the check code corresponding to the storage location code 16 is 6, and the check code 6 is consistent with the second target storage location code 6. In this way, it is determined that the third query character C is a grandchild node of the first layer character node A of the sensitive word tree, and a child node of the second layer character node B of the sensitive word tree, i.e., the third query character C is a third layer character node C of the sensitive word tree, and the third target storage location code 16 corresponds to a preset end base code -1, so that the third layer character node C is the bottom layer character node of the sensitive word, and it is determined that the sensitive word to be checked ABC exists in the sensitive word library.
[0097] For example, if the sensitive word to be checked is BCA, first, the first query character B is determined to have a character code of 2 in the dictionary code, and the sum of the character code 2 of B and the preset base code 1 of the root node is 3, and it is considered that the first target storage location code of the query character B is 3. The character stored in the storage location corresponding to the storage location code 3 is B, which is consistent with the query character B, and the check code corresponding to the storage location code 3 is 0, which is the storage location code of the root node. In this way, it is determined that the query character B matches the first layer character node B of the sensitive word tree. The second query character C is determined to have a character code of 3, and the sum of the character code 3 of the second query character C and the base code 4 of the first layer character node B is 7, and it is considered that the second target storage location code of the second query character C is 7. The character stored in the storage location corresponding to the storage location code 7 is C, which is consistent with the second query character C, and the check code corresponding to the storage location code 7 is 3, which is consistent with the first target storage location code 3. In this way, it is determined that the second query character C is a child node of the first layer character node B of the sensitive word tree, i.e., the second query character C is a second layer character node C of the sensitive word tree. Again, the third query character A is determined to have a character code of 1, and the sum of the character code 1 of the third query character A and the base code 16 of the second layer character node C is 17, and it is considered that the third target storage location code of the third query character A is 17. The storage location corresponding to the storage location code 17 is empty, so it is determined that the sensitive word to be checked BCA is not in the sensitive word library.
[0098] Specifically, the method further comprises: if the first part of the query characters of the sensitive word to be checked satisfies the sensitive word character determination condition, determining the target query location code in the sensitive word library based on the character code of the second part of the query characters of the sensitive word to be checked and the base code corresponding to the target storage location code of the last query character in the first part of the query characters; sequentially determining whether to match based on the text characters stored in the storage location corresponding to the target query location code and the second part of the query characters, and recording the number of matches; if the number of matches is less than or equal to a preset first number of matches, and the third part of the query characters in the second part of the query characters satisfies the sensitive word character determination condition, the sensitive word to be checked is determined as a combined sensitive word stored in the sensitive word library.
[0099] The sensitive word character determination condition means that each query character matches the double array table. That is, each query character can determine the target query location code of the query character according to the character code corresponding to the query character and the base code of the previous query character, and the character stored in the storage location corresponding to the target query location code in the double array table is consistent with the query character, and the check code corresponding to the target query location code is the query location code of the previous query character.
[0100] The first part of the query characters refers to the n query characters in the first order of the sensitive word to be searched that match the double array table; the second part of the query characters refers to the m query characters after the first part of the query characters that do not match the double array table; and the third part of the query characters refers to the p query characters in the second order of the sensitive word to be searched that match the double array table.
[0101] In other words, when identifying sensitive words to be searched, the combined encoding of each text character of the sensitive word to be searched is determined. When the combined encoding is 1, the text character only needs to be matched once. If the match is successful, the next text character is matched. If the match is unsuccessful, the sensitive word to be searched is considered not to be a sensitive word in the sensitive word tree. When the combined encoding is 10, 10 matches can be performed. If the match is unsuccessful once, the next text character can be searched. If the match is successful within 10 matches, the matching continues. If the match is unsuccessful in 10 matches, the sensitive word to be searched is considered not to be a sensitive word in the sensitive word tree.
[0102] For example, if the sensitive word to be searched is BCA, firstly, the character encoding of the first query character B in the dictionary is determined to be 2. The sum of the character encoding 2 of B and the preset base encoding 1 of the root node is calculated to be 3. The first target storage location encoding of the query character B is considered to be 3. The character stored at the storage location corresponding to storage location encoding 3 is found in Table 7 and is B, which matches the query character B. The check encoding corresponding to storage location encoding 3 is 0. Check encoding 0 is the storage location encoding of the root node. Thus, it is determined that the query character B matches the first-level character node B of the sensitive word tree. Next, the character encoding of the second query character C is determined to be 3. The sum of the character encoding 3 of the second query character C and the base encoding 4 of the first-level character node B is calculated to be 7. The second target storage location encoding of the second query character C is considered to be 7. The storage location encoding 7 is found in Table 7. The character stored at the corresponding storage location is C, which is consistent with the second query character C. The check code corresponding to storage location code 7 is 3, which is consistent with the first target storage location code 3. Therefore, it is determined that the second query character C is a child node of the first-level character node B in the sensitive word tree, that is, the second query character C is the second-level character node C in the sensitive word tree. It is further determined that the character code of the third query character A is 1, and the sum of the character code 1 of the third query character A and the basic code 16 of the second-level character node C is 17. It is considered that the third target storage location code of the third query character A is 17. The storage location corresponding to storage location code 17 in Table 7 is empty, and the combined code of the second target storage location code 7 is 1, which is not a combined sensitive word. Therefore, it can only be queried once. Therefore, it is determined that the sensitive word BCA to be queried is not in the sensitive word database.
[0103] For example, if the sensitive word to be searched is AB DAC, first, the first query character A is determined to have a character code of 1 in the dictionary encoding, and the sum of the character code 1 of A and the preset base code 1 of the root node is calculated to be 2, and the first target storage location code of the query character A is considered to be 2. The character stored in the storage location corresponding to the storage location code 2 is queried from Table 7, and is determined to be A, which is consistent with the query character A. The check code corresponding to the storage location code 2 is 0, which is the storage location code of the root node. In this way, it is determined that the query character A matches the first layer character node A of the sensitive word tree. The character code of the second query character B is determined to be 2, and the sum of the character code 2 of the second query character B and the base code 4 of the first layer character node A is calculated to be 6. The second target storage location code of the second query character B is considered to be 6. The character stored in the storage location corresponding to the storage location code 6 is queried from Table 7, and is determined to be B, which is consistent with the second query character B. The check code corresponding to the storage location code 6 is 2, which is consistent with the first target storage location code 2. In this way, it is determined that the second query character B is a child node of the first layer character node A of the sensitive word tree, i.e., the second query character B is a second layer character node B of the sensitive word tree. The character code of the third query character D is determined to be 4, and the sum of the character code 4 of the third query character D and the base code 13 of the second layer character node B is calculated to be 17. The third target storage location code of the third query character D is considered to be 17. The storage location corresponding to the storage location code 17 is queried from Table 7, and is determined to be empty, which does not match the double array table. At this time, the combination code of the second layer character node B is obtained to be 10, and the second matching can be continued. The second query character B is the last query character in the first part of the query characters. The sum of the character code 1 of the fourth query character A and the base code 13 of the second layer character node B is calculated to be 14. The fourth target storage location code 14 corresponding to the storage location is queried from Table 7, and is determined to be empty, which does not match the double array table. Moreover, the current matching number 2 is less than the combination code 10 of the second layer character node B, and the third matching is continued. The sum of the character code 3 of the fifth query character C and the base code 13 of the second layer character node B is calculated to be 16. The character stored in the storage location corresponding to the storage location code 16 is queried from Table 7, and is determined to be C, which is consistent with the fifth query character C. The check code corresponding to the storage location code 16 is 6, which is consistent with the second target storage location code 6. Moreover, the base code corresponding to the storage location code 16 is -1, and it is determined that the fifth query character C is the bottom layer character node of the sensitive word, which satisfies the end matching condition. In this way, it is determined that the sensitive word to be searched AB DAC is the combination sensitive word AB...C.
[0104] Based on the same application concept, the embodiment of the present application also provides a double array tree dictionary construction device corresponding to the double array tree dictionary construction method provided by the above-mentioned embodiment. Since the principle of the device in the embodiment of the present application solves the problem similarly to the double array tree dictionary construction method of the above-mentioned embodiment of the present application, the implementation of the device can be referred to the implementation of the method, and the repeated parts will not be described here.
[0105] As shown in Figure 3 Figure 3 A functional module diagram of a double array tree dictionary construction device provided by the embodiment of the present application. The double array tree dictionary construction device 10 comprises: a sensitive word tree generation module 101, which generates a sensitive word tree based on the text characters split by each sensitive word and the arrangement order of each text character, and each path in the sensitive word tree corresponds to a sensitive word; an encoding module 102, which performs dictionary encoding on the text characters split by the sensitive word after deduplication, to obtain the character encoding corresponding to each text character; a basic code determination module 103, which determines the basic code of each character node in the sensitive word tree in layers according to at least one of random selection trial, self-increment selection trial, overall query selection trial and preset data selection trial; a construction module 104, which determines the storage location code of the text character of each character node in the storage space based on the character encoding corresponding to the text character of each character node and the basic code of the parent node of each character node, and takes the storage location code of the parent node of each character node as the check code of each character node, to construct the sensitive word dictionary.
[0106] Based on the same application concept, the embodiment of the present application also provides a double array tree dictionary construction device corresponding to the double array tree dictionary construction method provided by the above-mentioned embodiment. Since the principle of the device in the embodiment of the present application solves the problem similarly to the double array tree dictionary construction method of the above-mentioned embodiment of the present application, the implementation of the device can be referred to the implementation of the method, and the repeated parts will not be described here.
[0107] The application further provides a word query device based on a double-array tree. The device applies the sensitive word library created by the above-mentioned embodiments. The device comprises: a first determination module, which determines whether a first query character in a sensitive word to be queried is a text character with a dictionary code; a second determination module, which, if yes, determines a first target storage location code of the first query character in a storage space based on a preset basic code of a root node of the sensitive word library and a character code corresponding to the first query character of the sensitive word to be queried; an inspection module, which determines whether the text character stored in the storage location corresponding to the first target storage location code is the first query character and whether an inspection code corresponding to the first target storage location code is a storage location code of the root node; a judgment module, which, if yes, judges whether a basic code corresponding to the first target storage location code is a preset ending basic code; a third determination module, which, if no, determines a second target storage location code of a second query character in the storage space based on the basic code corresponding to the first target storage location code and a character code corresponding to the second query character of the sensitive word to be queried; a conditional comparison module, which determines whether the current query character meets the sensitive word character determination condition based on the text character stored in the storage location corresponding to the current target storage location code, the basic code and the inspection code; and a fourth determination module, which, if yes, determines the sensitive word to be queried as a sensitive word stored in the sensitive word library.
[0108] Furthermore, the storage mode of the double-array tree can improve the storage utilization and reduce the storage space occupation compared with the storage mode of directly storing a sensitive word tree. The word library construction efficiency is improved by the whole query storage location mode of the character node with a large number of and compactly arranged child nodes. The storage location code and the inspection code of each query character are used to double confirm whether the character is stored in the double-array tree, and the method of calculating the storage location code and the inspection code is relatively simple. The sensitive word query efficiency is greatly improved. The combined code is further set to query the combined sensitive word, and the application range is expanded.
[0109] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the foregoing method embodiment, and will not be repeated here. In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and there can be another division manner in actual implementation, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some communication interfaces, devices or units, and can be electrical, mechanical or other forms.
[0110] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., they can be located in one place or distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0111] In addition, the functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0112] If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a non-volatile computer readable storage medium executable by a processor. Based on this understanding, the technical solutions of the present application essentially or the parts of the prior art or the parts of the technical solutions can be embodied in the form of software products, and the computer software products are stored in a storage medium, including a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the embodiments of the present application. The foregoing storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk, and various media that can store program codes.
[0113] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A method for constructing a lexicon based on a double-array tree, characterized in that, The method includes: A sensitive word tree is generated based on the text characters that are split into each sensitive word and the order of these text characters. Each path in the sensitive word tree corresponds to a sensitive word. After deduplication of the text characters split from the sensitive words, dictionary encoding is performed to obtain the character codes corresponding to each text character; The basic encoding of each character node in the sensitive word tree is determined by sequentially layering at least one of the following methods: random selection trial calculation, auto-incrementing selection trial calculation, overall query selection trial calculation, and preset data selection trial calculation. Based on the character encoding corresponding to the text character of each character node and the basic encoding of its parent node, the storage location encoding of the text character of the character node in the storage space is determined, and the storage location encoding of the parent node of the character node is used as the check encoding of the character node to construct a sensitive word library.
2. The method according to claim 1, characterized in that, The step of determining the basic encoding of each character node in the sensitive word tree in a hierarchical manner includes: The virtual encoding of the character node is set according to the preset trial calculation rules, and at least one storage location encoding corresponding to the storage space required by all child nodes of the character node is determined by the virtual encoding and the character encoding of all child nodes of the character node. The virtual encoding corresponding to each storage location encoding when all storage locations are idle is used as the basic encoding of the character node.
3. The method according to claim 2, characterized in that, The step of setting the virtual encoding of the character node according to the preset trial calculation rules includes: Based on the number of child nodes of the character node and the character encoding of each child node, determine whether the overall query conditions are met; When the overall query conditions are met, the value of the virtual code is determined based on the difference between the smallest and largest character codes among the child nodes that meet the overall query conditions.
4. The method according to claim 3, characterized in that, When the overall query conditions are met, the value of the virtual code is determined based on the difference between the smallest and largest character codes among the child nodes that meet the overall query conditions, including: If all child nodes of the character node satisfy the overall query conditions, then the storage location code corresponding to the smallest character code in the child node is taken as the starting point of the storage location code corresponding to the storage space required by all child nodes of the character node. Encode the storage space corresponding to the smallest character encoding in all child nodes to the storage space corresponding to the largest character encoding, and use this as a whole to determine whether it is free; If yes, then the current virtual code corresponding to the storage location where each storage location is free is used as the base code of the character node; if no, then the value of the next round of virtual code is set to be at least the difference between the largest and smallest character codes among all child nodes plus 1 added to the current virtual code.
5. The method according to claim 3, characterized in that, When the overall query conditions are met, the value of the virtual code is determined based on the difference between the smallest and largest character codes among the child nodes that meet the overall query conditions, including: If some of the child nodes of the character node satisfy the overall query conditions, then the storage location code corresponding to the smallest character code among the child nodes that satisfy the overall query conditions shall be used as the starting point of the storage location code corresponding to the storage space required by some of the child nodes of the character node. The storage space corresponding to the smallest character code in the child nodes that meet the overall query conditions is encoded to the storage space corresponding to the largest character code, and then used as a whole to determine whether it is free. Based on the current virtual code and the character codes of the child nodes of the character node that do not meet the overall query conditions, the storage space corresponding to the storage space required by the other child nodes of the character node is determined, and the storage space corresponding to each storage space code is determined to be free. If yes, then the current virtual code corresponding to the storage location where each storage location is free is used as the base code of the character node; if no, then the value of the next round of virtual code is set to be at least the difference between the largest and smallest character codes in the child nodes that satisfy the overall query conditions plus 1.
6. The method according to claim 3, characterized in that, The method further includes: When the overall query conditions are not met, the storage location code corresponding to the storage space required by each child node is determined based on the current virtual code and the character code of each child node of the character node, and it is determined whether the storage location corresponding to each storage location code is free. If yes, then the current virtual code corresponding to the storage location where each storage location is free is used as the basic code of the character node; if no, then the value of the next round of virtual code is set to add a preset value to the current virtual code, or the value of the next round of virtual code is randomly obtained without repetition within the preset value range, or the value of the next round of virtual code is obtained according to the preset value sequence.
7. The method according to claim 1, characterized in that, The method further includes: For the lowest-level character node of each path, the preset end base code is used as the base code of the lowest-level character node, and the storage location code of the parent node of the lowest-level character node is used as the check code of the lowest-level character node, so as to add the lowest-level character node to the sensitive word library.
8. The method according to claim 1, characterized in that, The sensitive word tree also includes an ending leaf node for indicating the end of the path, and the method further includes: For the lowest-level character node of each path, if the lowest-level character node is also the parent node of character nodes in other paths, then the ending leaf node is set for the lowest-level character node, the preset ending base code is used as the base code of the ending leaf node, and the storage location code of the lowest-level character node is used as the check code of the ending leaf node, so as to add the ending leaf node to the sensitive word library. If the bottom-level character node is not the parent node of other path character nodes, then the preset end base code is used as the base code of the bottom-level character node, and the storage location code of the parent node of the bottom-level character node is used as the check code of the bottom-level character node, so as to add the bottom-level character node to the sensitive word library.
9. The method according to claim 1, characterized in that, The sensitive word tree also includes end leaf nodes for indicating the end of the path, each end leaf node including an end character, and the method further includes: Dictionary encoding is performed on the end character to obtain the end character encoding corresponding to the end character; Based on the ending character encoding corresponding to the ending character of the ending leaf node and the basic encoding of its parent node, the storage location encoding of the ending character of the ending leaf node in the storage space is determined. The preset basic ending encoding is used as the basic encoding of the ending leaf node, and the storage location encoding of the parent node of the ending leaf node is used as the check encoding of the ending leaf node, so as to add the ending leaf node to the sensitive word database.
10. The method according to claim 1, characterized in that, The sensitive word database also includes combined sensitive words, and the method further includes: For each combination of sensitive words, the character node corresponding to the target text character of the combined word is set as the first matching number, and the character node corresponding to the text character other than the target text character of the combined word is set as the second matching number. The first matching number is greater than the second matching number. The matching number is used to indicate the number of times the query character matches the text character of the corresponding character node stored in the sensitive word database.
11. A word query method based on a double-array tree, characterized in that, The method applies the sensitive word library created by the method as described in any one of claims 1 to 10, and the method includes: Determine whether the first query character in the sensitive word to be searched is a dictionary-encoded text character; If so, then based on the basic encoding preset in the root node of the sensitive word library and the character encoding corresponding to the first query character of the sensitive word to be searched, the first target storage location encoding of the first query character in the storage space is determined; Based on the first target storage location code, determine whether the text character stored at the storage location is the first query character, and whether the check code corresponding to the first target storage location code is the storage location code of the root node; If so, determine whether the base code corresponding to the first target storage location code is the preset end base code; If not, based on the basic encoding corresponding to the first target storage location encoding and the character encoding corresponding to the second query character of the sensitive word to be searched, the second target storage location encoding of the second query character in the storage space is determined; Based on the text characters stored at the storage location corresponding to the current target storage location encoding, the basic encoding, and the check encoding, determine whether the current query character meets the sensitive word character determination conditions; If all conditions are met, the sensitive word to be searched is identified as a sensitive word stored in the sensitive word database.
12. The method according to claim 11, characterized in that, The method further includes: If the first part of the query characters of the sensitive word to be searched meets the sensitive word character determination condition, then the target query position code in the sensitive word library is determined based on the character encoding of the second part of the query characters of the sensitive word to be searched and the basic encoding corresponding to the target storage position code of the last query character in the first part of the query characters. Based on the second part of the query characters and the text characters stored in the corresponding storage location of the target query location code, determine whether they match in turn and record the number of matches. If the number of matches is less than or equal to the preset first number of matches, and the third part of the query characters in the second part of the query characters meets the sensitive word character determination condition, then the sensitive word to be searched is determined as a combined sensitive word stored in the sensitive word library.
13. A lexicon construction device based on a double-array tree, characterized in that, The device includes: The sensitive word tree generation module generates a sensitive word tree based on the text characters that each sensitive word is split into and the order of these text characters. Each path in the sensitive word tree corresponds to a sensitive word. The encoding module performs dictionary encoding on the text characters split from the sensitive words after deduplication, to obtain the character codes corresponding to each text character; The basic encoding determination module determines the basic encoding of each character node in the sensitive word tree by sequentially layering at least one of the following: random selection trial calculation, auto-incrementing selection trial calculation, overall query selection trial calculation, and preset data selection trial calculation. The construction module determines the storage location encoding of the text character of each character node in the storage space based on the character encoding corresponding to the text character of each character node and the basic encoding of its parent node, and uses the storage location encoding of the parent node of the character node as the check encoding of the character node to construct a sensitive word library.
14. A word query device based on a double-array tree, characterized in that, The apparatus uses the sensitive word library created by the method as described in any one of claims 1 to 10, the apparatus comprising: The first determination module determines whether the first query character in the sensitive word to be searched is a dictionary-encoded text character; If so, the second determining module determines the first target storage location code of the first query character in the storage space based on the basic encoding preset by the root node of the sensitive word library and the character encoding corresponding to the first query character of the sensitive word to be searched. The inspection module determines whether the text character stored in the first target storage location is the first query character based on the first target storage location code, and whether the inspection code corresponding to the first target storage location code is the storage location code of the root node. If the judgment module is correct, it determines whether the basic code corresponding to the first target storage location code is the preset end basic code. The third determining module, if not, determines the second target storage location code of the second query character in the storage space based on the basic code corresponding to the first target storage location code and the character code corresponding to the second query character of the sensitive word to be searched; The condition comparison module determines whether the current query character meets the sensitive word character determination conditions based on the text characters stored in the storage location corresponding to the current target storage location encoding, the basic encoding, and the check encoding. The fourth determination module determines the sensitive word to be searched as a sensitive word stored in the sensitive word library if all conditions are met.
Citation Information
Patent Citations
Sensitive word searching method and device and electronic device
CN107633062A
Sensitive word quick search method and system capable of compressing memory
CN113778678A
Sensitive word recognition method and sensitive word tree construction method
CN115759067A
Input method word stock construction method and related method, device and equipment
CN117149939A
Shielding word recognition method and device based on character coding compression, equipment and medium
CN117272989A
