Method and system for querying keywords by sharing data structure in multiple word banks and electronic equipment
By constructing a dictionary tree, the keywords of multiple lexicon are integrated into one data structure, which solves the problems of data management complexity and large storage space occupation in traditional methods, achieves efficient integration and resource sharing of multiple lexicon, and improves efficiency. Query efficiency.
Patent Information
- Application Number
- CN202410628699.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-05-21
AI Technical Summary
Traditional string search methods have problems with data management complexity and excessive storage space usage in multi-project environments, resulting in ineffective use of system resources.
Using a multi-lexicon shared data structure query method, the keywords of multiple lexicon are integrated into one data structure by constructing a dictionary tree, and dynamic data structure and segmented storage technology are used to achieve efficient keyword query and resource sharing.
It achieves efficient integration and resource sharing of multiple lexicon, reduces storage space occupation, improves query efficiency, and reduces the complexity of building different lexicon.
Smart Images

Figure CN118550932A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information technology, and in particular to a method, system and electronic device for querying keywords using a multi-lexicon shared data structure. Background Art
[0002] Keyword search is a crucial technology in fields such as information retrieval, natural language processing, and data mining. Traditional string search methods mainly rely on specific algorithms to encapsulate multiple keywords into a data structure that is easy to search for in order to achieve efficient string matching. When it is necessary to query whether a string contains a specified keyword, the system will compare the string to be queried with the constructed data structure to determine whether it contains the specified keyword.
[0003] This traditional string search method has significant limitations in practice. Especially when dealing with multiple projects, each project often has its own independent vocabulary data structure. This means that as the number of projects increases, the number of vocabulary that needs to be built will also increase dramatically. This not only increases the complexity of data management and maintenance, but more importantly, a large amount of vocabulary data takes up valuable storage space, making system resources inefficiently utilized.
[0004] Therefore, it is necessary to improve the existing keyword query method to overcome the defects of the prior art. Summary of the invention
[0005] In order to overcome the problems existing in the related art, one of the purposes of the present invention is to provide a method for querying keywords using a shared data structure for multiple vocabularies. The method can achieve efficient integration and resource sharing of multiple vocabularies, improve the accuracy and efficiency of information query, and avoid the redundancy of storing keywords separately for each vocabularies, which can greatly reduce the required storage space.
[0006] A method for searching keywords using a multi-lexicon shared data structure, comprising:
[0007] Get the keywords of a single item and construct the first dictionary tree of the keywords of the single item;
[0008] Get the keywords of all items, insert the keywords of all items into the first dictionary tree, and get the second dictionary tree;
[0009] Traversing all nodes of the second dictionary tree, and constructing a match failure jump node in the second dictionary tree, to obtain a third dictionary tree; wherein, a dynamic data structure is used to store child nodes of the third dictionary tree, and each node of the obtained third dictionary tree is stored in segments;
[0010] Use the third dictionary tree to perform keyword search.
[0011] In a preferred technical solution of the present invention, the step of inserting the keywords of all items into the first dictionary tree further includes:
[0012] Use different tags to mark the keywords of different projects.
[0013] In a preferred technical solution of the present invention, the use of different tags to mark keywords of different items includes:
[0014] Build the end of each keyword;
[0015] A data structure is hung at the end of each keyword; the data structure is used to mark the item information.
[0016] In a preferred technical solution of the present invention, the step of obtaining a keyword of a single item includes:
[0017] Get keywords for a single item;
[0018] Preprocessing the acquired keywords;
[0019] Extract keywords from preprocessed keywords.
[0020] In a preferred technical solution of the present invention, the preprocessing of the acquired keywords includes:
[0021] Remove duplicates, merge synonyms, and handle inflection.
[0022] In a preferred technical solution of the present invention, the step of constructing a match failure jump node in the second dictionary tree includes:
[0023] Add a failure pointer to each node except the root node in the second dictionary tree; the failure pointer points to the node to jump to when the current node fails to match;
[0024] In the process of adding the failure pointer, breadth-first search is used to construct the failure pointer.
[0025] In a preferred technical solution of the present invention, inserting the keywords of all items into the first dictionary tree to obtain the second dictionary tree includes:
[0026] During the insertion process, if an existing character node is encountered, the existing character node is shared.
[0027] In a preferred technical solution of the present invention, the keyword search using the third dictionary tree includes:
[0028] Construct a unified query interface in the third dictionary tree;
[0029] Perform keyword search through the unified query interface.
[0030] The second object of the present invention is to provide a system for querying keywords using a shared data structure for multiple vocabularies, the system being used to implement the method for querying keywords using a shared data structure for multiple vocabularies as described above, the system comprising:
[0031] A shared data structure unit is used to store keyword information in multiple word libraries, and to integrate keywords in multiple word libraries into one dictionary tree by constructing a dictionary tree;
[0032] Process keywords, remove duplicates, merge synonyms, and handle word form changes;
[0033] A keyword query unit, used to traverse all nodes of the dictionary tree according to the character sequence of the keyword and search for matching keywords;
[0034] A result returning unit, used to feed back the search results of the keyword query unit to the user;
[0035] The word library updating unit is used to update the word library of the shared data structure unit and modify the dictionary tree in the shared data structure unit.
[0036] A third object of the present invention is to provide an electronic device, comprising:
[0037] Processor; and
[0038] The memory stores executable codes thereon, and when the executable codes are executed by the processor, the processor is caused to execute the method for querying keywords using a multi-thesaurus shared data structure as described above.
[0039] The beneficial effects of the present invention are:
[0040] The present invention provides a method for querying keywords using a shared data structure of multiple lexicons, the method comprising: obtaining keywords of a single item and constructing a first dictionary tree of the keywords of the single item; obtaining keywords of all items and inserting the keywords of all items into the first dictionary tree to obtain a second dictionary tree; traversing all nodes of the second dictionary tree and constructing a match failure jump node in the second dictionary tree to obtain a third dictionary tree; and using the third dictionary tree to perform keyword query. The method realizes the sharing and reuse of lexicons by integrating keywords of multiple lexicons into one dictionary tree, saving storage space. Moreover, the more items there are and the larger the repeated lexicons are, the more space the method of the present application can save. In addition, since the dictionary tree is a data structure based on prefix matching, when performing keyword query, there is no need to traverse the entire lexicon, and only needs to go down along the architecture of the dictionary tree, which can greatly improve the query efficiency.
[0041] The present application also provides an electronic device for querying keywords using a shared data structure for multiple vocabularies. The system can achieve efficient integration and resource sharing of multiple vocabularies, reduce the work of constructing different vocabularies, and reduce the space occupied by the data structures of different vocabularies. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is a flow chart of a method for searching keywords using a multi-lexicon shared data structure provided by the present invention;
[0043] Figure 2 It is a flow chart of preprocessing keywords provided by the present invention;
[0044] Figure 3 It is a schematic diagram of a dictionary tree constructed by the "Star" project provided in Example 1 of the present invention;
[0045] Figure 4 It is a schematic diagram of a dictionary tree constructed by the "flag" project provided in Example 1 of the present invention;
[0046] Figure 5 It is a schematic diagram of a dictionary tree for constructing a match-failed jump node in the dictionary tree of the "star" and "flag" items provided in Example 1 of the present invention. DETAILED DESCRIPTION
[0047] The preferred embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present invention more thorough and complete, and to fully convey the scope of the present invention to those skilled in the art.
[0048] Keyword search is a crucial technology in fields such as information retrieval, natural language processing, and data mining. Traditional string search methods mainly rely on specific algorithms to encapsulate multiple keywords into a data structure that is easy to search for in order to achieve efficient string matching. When it is necessary to query whether a string contains a specified keyword, the system will compare the string to be queried with the constructed data structure to determine whether it contains the specified keyword.
[0049] This traditional string search method has significant limitations in practice. Especially when dealing with multiple projects, each project often has its own independent vocabulary data structure. This means that as the number of projects increases, the number of vocabulary that needs to be built will also increase dramatically. This not only increases the complexity of data management and maintenance, but more importantly, a large amount of vocabulary data takes up valuable storage space, making system resources inefficiently utilized.
[0050] Based on this, the present application provides a method for querying keywords using a multi-lexicon shared data structure.
[0051] Example 1
[0052] like Figure 1-Figure 2 As shown, this embodiment provides a method for searching keywords using a multi-lexicon shared data structure, including the following steps:
[0053] S100, obtaining keywords of a single item, and constructing a first dictionary tree of keywords of the single item;
[0054] S200, obtaining keywords of all items, inserting the keywords of all items into the first dictionary tree, and obtaining a second dictionary tree;
[0055] S300, traversing all nodes of the second dictionary tree, and constructing a match failure jump node in the second dictionary tree to obtain a third dictionary tree; wherein, a dynamic data structure is used to store child nodes of the third dictionary tree, and each node of the obtained third dictionary tree is stored in segments;
[0056] Specifically, the dynamic data structures of the present application include linked lists, dynamic arrays (such as std::vector in C++ or list in Python), and hash tables (such as std::unordered_map in C++ or d ict in Python);
[0057] More specifically, when storing child nodes, it is necessary to define a node class (or structure) of the dictionary tree, which includes a character field to store the character of the current node and a dynamic data structure field pointing to the child node.
[0058] For example, in Python, a node can be defined as follows:
[0059] classTrieNode:
[0060] def __init__(self):
[0061] self.char=None
[0062] self.children = {} #Use dictionary as a dynamic data structure to store child nodes
[0063] self.is_end_of_word=False
[0064] In C++, a node is defined as follows:
[0065] classTrieNode{
[0066] public:
[0067] charch;
[0068] std::unordered_map<char,TrieNode*> children; / / Use hash table to store child nodes
[0069] boolis_end_of_word;
[0070] TrieNode(charc):ch(c),is_end_of_word(false){}
[0071] };
[0072] After defining the node class of the dictionary tree, the dictionary tree is segmented according to the defined dictionary tree node class. The segmentation strategy can be based on factors such as the height of the dictionary tree, the number of nodes, memory limitations, or access patterns. For example, segmentation can be performed by the layer of the dictionary tree, or segmentation can be performed based on the number of child nodes of each node.
[0073] Split the trie into smaller parts or "segments" based on the chosen segmentation strategy. Each segment can contain a subset of trie nodes and subtrees. Make sure each segment is of the right size, not too large to cause memory problems, nor too small to be difficult to manage.
[0074] After segmentation is completed, each segment is stored as a separate file or memory block. Specifically, a file system can be used to store files, or memory-mapped files, databases, or other memory management technologies can be used to store memory blocks. It should be noted that when segmenting, a node mapping table needs to be established to record which segment each node is in and its position within the segment. In this way, when searching, the segment where the corresponding node is located can be found according to the node mapping table, and the search can be performed within the segment. Alternatively, an index can be created to track the node information contained in each segment. The index can be a simple file list or a more complex data structure, such as a hash table or B-tree, which is used to quickly locate the segment containing a specific node. The index should contain enough information so that the segment containing the target node can be quickly located.
[0075] After the segmentation is completed and stored, if you need to insert and delete nodes, first determine the segment where the new node or the node to be deleted is located. Then, load the segment and perform the corresponding operation. In the insertion operation, if the new node causes the current segment to be too large, the new node needs to be split into two or more segments. Similarly, in the deletion operation, if the deletion of the node causes the current segment to be too small, it needs to be merged with other segments. In addition, the dictionary tree of segmented storage needs to be regularly checked and optimized later. This may include rebalancing the segment size, updating the index, cleaning up the segments that are no longer needed, etc. Ensure that the dictionary tree of segmented storage remains efficient and manageable.
[0076] More preferably, the present application also provides a method for quickly finding each node file after storing the dictionary e-tree in segments, specifically including:
[0077] Create a separate index file that records the information of each segment file. The index file can contain information such as the start node, end node, file path or file handle of each segment. When you need to find a node, first query the index file to determine which segment file the node is located in, and then load the corresponding segment file.
[0078] It can also include encoding the path of the dictionary tree so that the location information of the node can be directly calculated through the encoding. For example, the depth of the node and the order of the pre-order traversal can be used as the encoding. When a node needs to be found, the segment file where it is located is directly calculated based on the node's encoding. This method does not require an additional index file, but it is necessary to ensure that the encoding scheme is efficient and reliable.
[0079] In the process of encoding the path of the dictionary tree:
[0080] First, we need a coding structure that can uniquely identify each node path in the dictionary tree. This coding structure usually includes the depth of the node in the dictionary tree and its relative position in the current level (for example, from left to right order)
[0081] Then use depth-first traversal: Starting from the root node of the dictionary tree, use depth-first traversal (DFS) to assign a unique code to each node. This code can be an integer, a string, or any data structure that can uniquely identify a path. The code can consist of two parts: The first is the segment identifier: indicating the segment in which the node is located. This can be a simple segment index (for example, the name or number of the segment file), or segment information based on the depth of the node. The first is the node position: indicating the position of the node within its segment. This can be a relative position index based on the level, or a code based on some order (such as lexicographical order).
[0082] Store the code of each node in a data structure so that it can be quickly looked up. This data structure can be a hash table that maps the code to a reference to the node or node information.
[0083] When it is necessary to search for a node in the dictionary tree, first generate the corresponding code according to the given keyword; use the code to find the node information from the hash table; locate the corresponding segment file according to the node information, and find the specific node in the file.
[0084] For example: suppose we have a dictionary tree and divide it into two segments according to depth: the first segment contains nodes with depth 0 and 1, and the second segment contains nodes with depth 2 and above. Then each node is assigned a code as follows:
[0085] Root node (depth 0): Encoded as 0:root (where 0 represents the segment identifier and root represents the special identifier of the root node)
[0086] First-layer nodes (depth 1): encoded as 1:A, 1:B, ... (where 1 represents the segment identifier, and A, B, etc. represent the characters of the node)
[0087] Second-level and deeper nodes: Encoded as 2:AB, 2:AC, ... (where 2 represents the segment identifier, and AB, AC, etc. represent the path from the root node to the node)
[0088] In this way, through coding, the segment where any node is located and the position within the segment can be quickly located. It should be noted that the coding scheme should be designed according to the specific dictionary tree structure and segmentation strategy to ensure coding effectiveness and efficiency.
[0089] S400: Use the third dictionary tree to perform keyword search.
[0090] Specifically, the keyword of obtaining a single item includes:
[0091] S110, obtaining keywords for a single project;
[0092] S120, preprocessing the acquired keywords; wherein the preprocessing of the acquired keywords includes:
[0093] Remove duplicates, merge synonyms, and handle inflection.
[0094] De-duplication means removing duplicates of all keywords in a single project.
[0095] When synonyms are encountered during the synonym processing, they are merged into the same node. This node can contain a list of synonyms and pointers to shared child nodes at the next level.
[0096] Processing word form changes helps to build an accurate and efficient dictionary tree. Specifically, methods for processing word form changes include but are not limited to the following:
[0097] Stemming: Stemming is the process of reducing words to their base form or stem. For example, "running", "ran", and "runs" are all reduced to "run". With this method, only the stems are stored in the dictionary tree, which reduces storage space and improves query efficiency.
[0098] Lemmatization is a more precise process than stemming, which attempts to restore a word to its base form or lemma in the dictionary. This usually depends on language rules and dictionary resources. Lemmatization can better handle irregular verbs and plural forms of nouns.
[0099] Use regular expressions: Before building the dictionary tree, you can use regular expressions to preprocess the input word forms. For example, you can use regular expressions to remove special characters, punctuation marks, or convert them to lowercase. This ensures that the dictionary tree stores standardized word forms.
[0100] Write common processing rules: For some common word forms (such as adding or removing prefixes and suffixes), you can write common processing rules. These rules can be automatically applied when building the dictionary tree to handle common word forms.
[0101] S130, extracting keywords of the preprocessed keywords. Extracting the preprocessed keywords as input of the dictionary tree can reduce redundant nodes of the dictionary tree, simplify the structure of the dictionary tree, and reduce memory.
[0102] The process of constructing the first trie of the key for a single item is:
[0103] Build a dictionary tree starting from an empty root node. Each node represents a character, and the path from the root node to any node represents a specific keyword prefix. Each node represents a character, and the path from the root node to any node represents a specific keyword prefix.
[0104] Add the preprocessed keywords to the dictionary tree one by one. For each keyword, start from the root node and traverse down the tree structure. If there is a node matching the current character of the keyword in the child nodes of the current node, continue to traverse down; otherwise, create a new child node and use the current character as the tag of the node.
[0105] Repeat the above process until all keywords are added to the dictionary tree, and obtain the data structure of the first dictionary tree.
[0106] After the first dictionary tree is obtained, the same preprocessing method is used to preprocess the keywords of all items, and the preprocessed keywords are used as input and inserted into the data structure of the first dictionary tree.
[0107] More preferably, the process of inserting the keywords of all items into the first dictionary tree to obtain the second dictionary tree includes:
[0108] During the insertion process, if an existing character node is encountered, the existing character node is shared.
[0109] By merging keywords from multiple vocabularies into a shared dictionary tree, the redundancy of storing keywords separately for each vocabularies is avoided. This greatly reduces the required storage space.
[0110] In a preferred technical solution of the present invention, the step of inserting the keywords of all items into the first dictionary tree further includes:
[0111] Use different tags to mark the keywords of different projects.
[0112] Tagging keywords for different projects helps to distinguish and identify vocabulary from different projects, ensuring that results can be accurately associated with the corresponding projects during query and retrieval. This is crucial for data management and analysis in a multi-project environment to avoid confusion and misunderstanding. In addition, tagging different projects can also improve query efficiency. In the dictionary tree, through project tags, the system can quickly locate the vocabulary of a specific project, thereby avoiding traversing the entire dictionary tree and reducing unnecessary calculations and resource consumption. Furthermore, project tags also help to achieve data isolation and security. In multi-user or multi-project scenarios, different projects may involve sensitive or private information. By setting unique tags for each project, it can be ensured that only authorized users can access and operate the vocabulary of a specific project, thereby protecting the integrity and security of the data. Finally, project tags can also facilitate data analysis. By counting and analyzing the vocabulary of different projects, you can understand the vocabulary usage, popular vocabulary and other information of each project, and provide data support for project optimization and improvement.
[0113] The present application also provides a method for marking keywords of different items: the method of marking keywords of different items by using different tags includes:
[0114] Construct the end of each keyword; specifically, mark the node corresponding to the last character of each keyword to indicate that the node is the end of a string. This can be achieved by setting a Boolean variable _isEnd, or adding a special marker to the node structure, such as the end marker.
[0115] A data structure is hung at the end of each keyword; the data structure is used to mark the item information.
[0116] The data structure can be an integer, enumeration value, string, or other appropriate data type, depending on the number and identification of items.
[0117] The data structure hanging at the end of each keyword can be an object, list, or other container to store the item information related to the keyword. For example, if implemented in C++, you can add an unordered_map to the TrieNode structure to store the item information.
[0118] The keyword can be queried and updated after the hanging data structure at the end of each keyword: when querying or updating, the corresponding keyword node can be found by traversing the dictionary tree, and then the operation is performed through the hanging data structure.
[0119] Specifically, constructing the match failure jump node in the second dictionary tree includes:
[0120] Add a failure pointer to each node except the root node in the second dictionary tree; the failure pointer points to the node to jump to when the current node fails to match;
[0121] In the process of adding the failure pointer, a breadth-first search is used to construct the failure pointer. The process of constructing the failure pointer by breadth-first search is as follows: start from the child nodes of the root node and process downward layer by layer. For each node, if a child node of a certain character does not exist, then the failure pointer corresponding to the character points to the root node. If a child node of a certain character exists, then the failure pointer corresponding to the character points to the child node of the same character in the node pointed to by the failure pointer of its parent node (if it exists). If it does not exist, continue to search upward along the failure pointer until a matching character is found or the root node is reached.
[0122] In a more preferred embodiment, the construction process of the failure pointer can also be optimized and extended. For example, additional information can be added to speed up the matching process or handle more complex matching patterns.
[0123] In one implementation, the keyword search using the third dictionary tree includes:
[0124] Construct a unified query interface in the third dictionary tree;
[0125] Perform keyword search through the unified query interface.
[0126] Specifically, the process of building a unified query interface is as follows:
[0127] First, design the query interface. Define a unified query interface that receives user query requests and returns query results. This interface can be a function, API call, or other forms of interaction.
[0128] The query request is then parsed through the query interface. In the query interface, the query request entered by the user is parsed. This may include steps such as word segmentation, removal of irrelevant characters, and conversion to a unified format to ensure that the query request matches the vocabulary in the dictionary tree.
[0129] In the query interface, a project identifier can be introduced to distinguish the lexicon of different projects. Specifically, a project identifier can also be introduced in the query request. This identifier can be the name, ID or other unique identifier of the project, and the identifier corresponds to the tag of the project.
[0130] During the query process, the word library of the corresponding item is located in the dictionary tree according to the item identifier provided by the user. Then, the query operation is performed in the word library, and the matching words are found using the dictionary tree's search algorithm.
[0131] The above-mentioned method of querying keywords using a shared data structure of multiple lexicons realizes the sharing and reuse of lexicons by integrating the keywords of multiple lexicons into a dictionary tree, thereby saving storage space. Moreover, the more items there are and the larger the repeated lexicons are, the more space the method of the present application can save. In addition, since the dictionary tree is a data structure based on prefix matching, when performing a keyword query, there is no need to traverse the entire lexicon, and only needs to go down along the structure of the dictionary tree, which can greatly improve the query efficiency.
[0132] A detailed implementation of a method for searching keywords using a multi-lexicon shared data structure is provided below:
[0133] Step 1: Construct n keyword dictionaries for a single project and mark the keyword records of the project. Figure 3 Taking the "Star" project as an example, add the search keywords "not good-looking, good-looking, easy to make, good-looking but not good-looking" to construct a dictionary tree.
[0134] Step 2: Repeat step 1 to construct the keywords of all items into the same dictionary tree. Figure 4 , taking the "flag" project as an example, add the keywords "good looking, not good looking, easy to do" to the same dictionary tree.
[0135] Step 3: Loop through each node in the dictionary tree and construct a matching failure jump node. Figure 5 , the first dotted line is the match failure jump point of the "star" item, and the second dotted line is the match failure jump point of the "flag" item.
[0136] After the above three steps, we can get a data structure of a common query dictionary tree that integrates the vocabulary of the two projects. The two projects have a total of 7 keywords, 2 of which are common "not good-looking, not easy to do", so the generated query structure tree has only 4 branches, which can effectively reduce space usage.
[0137] Query process: For example, if the query is "If it doesn't look good, can I get on?", if the "Xingxing" project team goes to query, they will first query the branch "not good->good->good-looking" to find the keyword "not good-looking", and then jump to the "look" node of the branch "good->good-looking->get on->no", and then find the keyword "good-looking", and then further query to get the keyword "good-looking or not", and then jump to the branch "not good->good->good-looking", but there is no matching branch, so the final result is the three keywords "not good-looking, good-looking, good-looking but not on".
[0138] If the "flag" project team searches for the same string "It doesn't look good, so I can't go up", they will also first search the "not good->good->look" branch to find the keyword "not good-looking", and then jump to the "look->good" branch, but no keyword is found. Then they enter the "not good->look->look" branch, but still can't find the keyword. The final result is that there is only one keyword, "not good-looking".
[0139] In actual applications, assuming that the number of projects is m and the number of vocabularies is n, the space required for the query is m*n. If 90% of the vocabularies n in these m projects are repeated, then the space occupied by this method is only n*90%+(m*n*10%). The more repeated vocabularies there are and the larger the number of projects, the more space this method can save.
[0140] Example 2
[0141] This embodiment provides a system for querying keywords using a common data structure for a vocabulary library, and the system for querying keywords using a common data structure for a vocabulary library is used to implement the method for querying keywords using a common data structure for a vocabulary library as described above.
[0142] The system comprises:
[0143] A shared data structure unit is used to store keyword information in multiple word libraries, and to integrate keywords in multiple word libraries into one word library by constructing a word library tree; to process keywords, remove duplicates in keywords, merge synonyms, and process word form changes;
[0144] The shared data structure unit uses a dictionary tree as its basic structure, and forms a shared dictionary tree containing multiple lexicons by inserting keywords from different lexicons. At the same time, this module is also responsible for handling keyword conflicts and duplications to ensure the correctness and consistency of the shared dictionary tree.
[0145] The keyword query unit is used to traverse all nodes of the dictionary tree according to the character order of the keyword, search for matching keywords, and query in the dictionary tree of the shared data structure unit. During the query process, the module first traverses layer by layer from the root node of the dictionary tree of the shared data structure unit according to the character order of the keyword until a matching keyword is found or the traversal reaches the leaf node. In order to improve the query efficiency, the unit also uses the failure pointer technology. When the current character does not exist in the child node of the current node, the failure pointer jumps to other possible nodes to continue the query.
[0146] The result return unit is used to feed back the search results of the keyword query unit to the user. When the user's query is successful, the result return unit returns the matching keywords and related information; when the query fails, the result return unit returns the corresponding prompt information. At the same time, the result return unit also supports functions such as multi-keyword query and fuzzy query to meet the needs of different users.
[0147] The word library update unit is used to update the word library of the shared data structure unit and modify the dictionary tree in the shared data structure unit. When a new word library or keyword is added, the word library update unit inserts it into the dictionary tree of the shared data structure unit; when a word library or keyword is deleted, the word library update unit deletes the corresponding node from the dictionary tree of the shared data structure unit. In addition, the word library update unit can also support batch import and export functions of the word library, which is convenient for users to manage and maintain the word library.
[0148] Example 3
[0149] This embodiment provides an electronic device, which includes a memory and a processor.
[0150] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), or application-specific integrated circuits.
[0151] (Application Specific Integrated Circuit, ASIC), Field Programmable Gate Array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general processor can be a microprocessor or the processor can also be any conventional processor, etc.
[0152] Memory may include various types of storage units such as system memory, read-only memory (ROM), and permanent storage.
[0153] The memory stores executable codes, and when the executable codes are processed by the processor, the processor can execute part or all of the above-mentioned method for querying keywords using a shared data structure of multiple word libraries.
[0154] Unless otherwise specifically stated, the relative arrangement, numerical expressions and numerical values of the parts and steps set forth in these embodiments do not limit the scope of the application. In all examples shown and discussed here, any specific value should be interpreted as being merely exemplary, rather than as a restriction. Therefore, other examples of exemplary embodiments can have different values. It should be noted that similar reference numerals and letters represent similar items in the following drawings, and therefore, once a certain item is defined in an accompanying drawing, it does not need to be further discussed in the subsequent accompanying drawings.
[0155] It should be understood that spatially relative terms are intended to encompass different orientations of the device in use or operation in addition to the orientation depicted in the figures. For example, if the device in the figures is inverted, a device described as "above" or "above" other devices or structures would then be positioned "below" or "below" the other devices or structures. Thus, the exemplary term "above" can include both the orientations of "above" and "below." The device may also be positioned in other different ways (rotated 90 degrees or in other orientations), and the spatially relative descriptions used herein should be interpreted accordingly.
[0156] In addition, it should be noted that the use of terms such as "first" and "second" to limit components is only for the convenience of distinguishing the corresponding components. Unless otherwise stated, the above terms have no special meaning and therefore cannot be understood as limiting the scope of protection of this application.
[0157] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for searching keywords using a multi-lexicon shared data structure, characterized in that: include: Get the keywords of a single item and construct the first dictionary tree of the keywords of the single item; Get the keywords of all items, insert the keywords of all items into the first dictionary tree, and get the second dictionary tree; Traversing all nodes of the second dictionary tree, and constructing a match failure jump node in the second dictionary tree, to obtain a third dictionary tree; wherein, a dynamic data structure is used to store child nodes of the third dictionary tree, and each node of the obtained third dictionary tree is stored in segments; Use the third dictionary tree to perform keyword search.
2. The method for searching keywords using a multi-lexicon shared data structure according to claim 1, characterized in that: The method of inserting the keywords of all items into the first dictionary tree further includes: Use different tags to mark the keywords of different projects.
3. The method for searching keywords using a multi-lexicon shared data structure according to claim 2, characterized in that: The method of using different tags to mark keywords of different items includes: Build the end of each keyword; A data structure is hung at the end of each keyword; the data structure is used to mark the item information.
4. The method for searching keywords using a multi-lexicon shared data structure according to claim 1, characterized in that: The keywords for obtaining a single item include: Get keywords for a single item; Preprocessing the acquired keywords; Extract keywords from preprocessed keywords.
5. The method for searching keywords using a multi-lexicon shared data structure according to claim 4, characterized in that: The preprocessing of the acquired keywords includes: Remove duplicates, merge synonyms, and handle inflection.
6. The method for searching keywords using a multi-lexicon shared data structure according to claim 1, characterized in that: The step of constructing a match failure jump node in the second dictionary tree includes: Add a failure pointer to each node except the root node in the second dictionary tree; the failure pointer points to the node to jump to when the current node fails to match; In the process of adding the failure pointer, breadth-first search is used to construct the failure pointer.
7. The method for searching keywords using a multi-lexicon shared data structure according to claim 1, characterized in that: The method inserts the keywords of all items into the first dictionary tree to obtain a second dictionary tree, including: During the insertion process, if an existing character node is encountered, the existing character node is shared.
8. The method for searching keywords using a multi-lexicon shared data structure according to any one of claims 1 to 7, characterized in that: The keyword search using the third dictionary tree includes: Construct a unified query interface in the third dictionary tree; Perform keyword search through the unified query interface.
9. A system for searching keywords using a common data structure of a vocabulary library, characterized in that: The system is used to implement the method for querying keywords using a multi-lexicon shared data structure as described in any one of claims 1 to 8; the system comprises: A shared data structure unit is used to store keyword information in multiple word libraries, and to integrate keywords in multiple word libraries into one dictionary tree by constructing a dictionary tree; Process keywords, remove duplicates, merge synonyms, and handle word form changes; A keyword query unit, used to traverse all nodes of the dictionary tree according to the character sequence of the keyword and search for matching keywords; A result returning unit, used to feed back the search results of the keyword query unit to the user; The word library updating unit is used to update the word library of the shared data structure unit and modify the dictionary tree in the shared data structure unit.
10. An electronic device, characterized in that: include: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method for querying keywords using a multi-thesaurus shared data structure as described in any one of claims 1-8.
Citation Information
Patent Citations
User thesaurus management system and management method
CN101140585A
Chinese AC (Aho-Corasick) automaton working method based on keyword dictionary tree structure
CN105260354A
Novel database structure data index method
CN108681577A
Dictionary tree-based search processing method and device, equipment and storage medium
CN111460311A
New word discovery method and device based on left and right information entropy and mutual information
CN114330336A
