Indexing method, device, electronic equipment and storage medium for dictionary data
By performing hierarchical processing and maintaining transfer relationships on dictionary data, the problems of low space utilization and high resource consumption in existing technologies are solved, achieving efficient dictionary indexing and dynamic data updates.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
- Filing Date
- 2022-08-18
- Publication Date
- 2026-05-12
AI Technical Summary
In existing technologies, dictionary indexing technology suffers from low space utilization, high resource consumption, inability to support dynamic data updates, and long construction time, especially under large-scale data.
By processing dictionary data into layers and maintaining the data based on the transfer relationships between the layers, an index is created to achieve efficient compression and fast retrieval.
It improves the space utilization of dictionary data, reduces resource consumption, supports dynamic data updates, and maintains high indexing speed under large-scale data.
Smart Images

Figure CN115422426B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information indexing, and more specifically, to a method, apparatus, electronic device, and storage medium for indexing dictionary data. Background Technology
[0002] With the rapid development of internet technology, text and image information streams disseminated through digital devices have become one of the main forms of online data. Numerous internet applications require information retrieval or natural language processing; scenarios such as web search engines, information retrieval systems, and illegal data filtering and identification all necessitate efficient dictionary indexing technologies. Therefore, among related technologies, how to efficiently index and retrieve massive amounts of text data has become a new challenge for internet businesses. Summary of the Invention
[0003] In view of the above problems, this application proposes a method, apparatus, electronic device and storage medium for indexing dictionary data, which can hierarchically divide the data used to construct the dictionary and maintain the data according to the transfer relationship between the data at each level after hierarchical division, thereby achieving efficient compression of dictionary data and improving the efficiency of indexing the dictionary.
[0004] In a first aspect, embodiments of this application provide a method for indexing dictionary data. The method includes: obtaining a word list to be processed, wherein the word list includes multiple words to be processed, each of the multiple words to be processed consisting of at least one character; for each word to be processed, according to the arrangement order of the characters in each word to be processed, layering the characters in each word to obtain multiple levels, wherein each level includes at least one character; determining the level corresponding to each character in each word to be processed, and determining the transition relationship of the characters in each word to be processed based on the level corresponding to each character in each word to be processed; and establishing an index of the word list to be processed based on the transition relationship of the characters in each word to be processed to obtain a target dictionary.
[0005] Secondly, embodiments of this application provide an indexing device for dictionary data. The device includes: a word list acquisition module, a word layering module, a transfer relationship determination module, and a target dictionary acquisition module. The word list acquisition module acquires a word list, which includes multiple words to be processed, each word consisting of at least one character. The word layering module, for each word to be processed, layers the characters in each word according to their arrangement order to obtain multiple layers, each layer including at least one character. The transfer relationship determination module determines the layer corresponding to each character in each word to be processed and, based on the layer corresponding to each character in each word to be processed, determines the transfer relationship of the characters in each word to be processed. The target dictionary acquisition module, based on the transfer relationship of the characters in each word to be processed, establishes an index of the word list to be processed to obtain a target dictionary.
[0006] Thirdly, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory is coupled to the processor, the memory stores instructions, and when the instructions are executed by the processor, the processor performs the above-described method.
[0007] Fourthly, embodiments of this application provide a computer-readable storage medium storing program code, which can be invoked by a processor to execute the above-described method.
[0008] The dictionary data indexing method, apparatus, electronic device, and storage medium provided in this application obtain a word list to be processed, wherein the word list includes multiple words to be processed, and each word to be processed consists of at least one character; for each word to be processed, the characters in each word to be processed are layered according to the arrangement order of the characters in each word to obtain multiple levels, wherein each level includes at least one character; the level corresponding to each character in each word to be processed is determined, and the transition relationship of the characters in each word to be processed is determined based on the level corresponding to each character in each word to be processed; based on the transition relationship of the characters in each word to be processed, an index of the word list to be processed is established to obtain the target dictionary. This layering of dictionary data and maintenance of dictionary data according to the transition relationships between the layers achieves efficient compression of dictionary data and improves the efficiency of indexing the dictionary. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 A flowchart illustrating a dictionary data indexing method provided in an embodiment of this application is shown;
[0011] Figure 2 This illustration shows a schematic diagram of target dictionary data storage provided in an embodiment of this application;
[0012] Figure 3 This illustration shows a schematic diagram of target dictionary data storage provided in an embodiment of this application;
[0013] Figure 4 A flowchart illustrating a dictionary data indexing method provided in an embodiment of this application is shown;
[0014] Figure 5 A flowchart illustrating a dictionary data indexing method provided in an embodiment of this application is shown;
[0015] Figure 6 This illustration shows a schematic diagram of target dictionary data storage provided in an embodiment of this application;
[0016] Figure 7 A flowchart illustrating a dictionary data indexing method provided in an embodiment of this application is shown;
[0017] Figure 8 This illustration shows a schematic diagram of target dictionary data storage provided in an embodiment of this application;
[0018] Figure 9 A flowchart illustrating a dictionary data indexing method provided in an embodiment of this application is shown;
[0019] Figure 10 A flowchart illustrating a dictionary data indexing method provided in an embodiment of this application is shown;
[0020] Figure 11 A flowchart illustrating a dictionary data indexing method provided in an embodiment of this application is shown;
[0021] Figure 12 A block diagram of a dictionary data indexing device provided in one embodiment of this application is shown;
[0022] Figure 13 A block diagram of an electronic device for performing a dictionary data indexing method according to an embodiment of this application is shown;
[0023] Figure 14 A storage unit for storing or carrying program code implementing a dictionary data indexing method according to an embodiment of this application is shown. Detailed Implementation
[0024] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0025] Currently, common text indexes take the form of character-to-word page numbers, as seen in dictionaries like the Xinhua Dictionary. This indexing technology makes books a widely used standard tool for text indexing. With the rapid development of internet technology, text and image information streams disseminated through digital devices have become one of the main forms of online data. Many internet applications require information retrieval or natural language processing. Scenarios such as web search engines, information retrieval systems, and illegal data filtering and identification all require efficient dictionary indexing technology.
[0026] In internet businesses, dictionaries are typically very large, often containing tens or even hundreds of millions of data points. For dictionaries with massive amounts of data, commonly used data structures include linear index tables, inverted indexes, hash tables, and search trees for storing and indexing the data.
[0027] Among related technologies, the most widely used applications of text indexing are Trie trees and DAT. Trie trees, also known as prefix trees or dictionary trees, are ordered trees used to store dictionaries, where the keys are usually strings. DAT (double array trie) is a double array trie tree, which is an implementation of trie trees.
[0028] Classic Trie trees use arrays or lists to store pointers to child nodes. Because many child nodes of each node in the tree are null, the data storage in the dictionary exhibits severe sparsity, resulting in low space utilization. In practical applications, especially with large datasets, the problem of space bloat becomes severe, leading to high resource consumption.
[0029] DAT, a data structure based on double arrays, still has several problems. First, it doesn't support dynamic data insertion and updates. Second, because it retains empty elements resulting from deletions, the space utilization efficiency of the double array decreases as the number of deletions increases. Third, when storing large amounts of data, the reconstruction of all previously stored data states and array expansion during dictionary construction significantly increase the time required to build the double array. Therefore, in practical applications, within limited space, DAT suffers from excessive space consumption due to array expansion, sometimes even preventing the completion of construction. Consequently, dictionary indexing techniques in related technologies suffer from low space utilization.
[0030] To address the aforementioned problems, the inventors, through long-term research, discovered and proposed the dictionary data indexing method, apparatus, electronic device, and storage medium provided in the embodiments of this application. By layering the dictionary data and maintaining the dictionary data according to the transfer relationships between the layers, efficient compression of dictionary data is achieved, thus improving the efficiency of indexing the dictionary. The specific dictionary data indexing method will be described in detail in subsequent embodiments.
[0031] Please see Figure 1 , Figure 1 A flowchart illustrating a dictionary data indexing method according to an embodiment of this application is shown. This dictionary data indexing method achieves efficient compression of dictionary data and improves the efficiency of dictionary indexing by hierarchically dividing the dictionary data into layers and maintaining the data based on the transfer relationships between the layers. In specific embodiments, this dictionary data indexing method can be applied to, for example... Figure 12 The dictionary data indexing device 200 and the electronic device 100 configured with the dictionary data indexing device 200 are shown. Figure 13 The following will use an electronic device as an example to illustrate the specific process of this embodiment. Of course, it is understood that the electronic device used in this embodiment may include smartphones, tablets, wearable electronic devices, etc., and is not limited thereto. The following will focus on... Figure 1 The process shown will be described in detail. The indexing method for the dictionary data may specifically include the following steps:
[0032] Step S110: Obtain a word list to be processed, wherein the word list to be processed includes multiple words to be processed, and each word to be processed consists of at least one character.
[0033] In some embodiments, an electronic device may obtain a to-be-processed vocabulary from an associated cloud or electronic device through wireless communication technologies (such as Bluetooth, WiFi, ZigBee, etc.); it may also obtain a to-be-processed vocabulary from an associated electronic device through a serial communication interface (such as a Serial Peripheral Interface (SPI), etc.); or it may be a to-be-processed vocabulary pre-set in the electronic device. In the embodiments of the present application, the manner in which the electronic device obtains the to-be-processed vocabulary is not limited herein.
[0034] Among them, the to-be-processed vocabulary includes data for constructing a dictionary, which may include multiple to-be-processed words, and each to-be-processed word in the multiple to-be-processed words consists of at least one character. Among them, the to-be-processed vocabulary can be understood as a text file including multiple to-be-processed words.
[0035] Exemplarily, the to-be-processed vocabulary may include to-be-processed words such as app, spran, cat, season, etc. Among them, the to-be-processed word "app" consists of the characters "a", "p", and "p". The to-be-processed vocabulary may also include words such as Zhonghua, Tsinghua, Huaxi, etc. Among them, the to-be-processed word "Zhonghua" consists of the characters "Zhong" and "Hua".
[0036] Step S120: For each of the to-be-processed words, according to the arrangement order of the characters in each to-be-processed word, the characters in each to-be-processed word are layered to obtain multiple levels, where each level in the multiple levels includes at least one character.
[0037] In some embodiments, an electronic device may, for each to-be-processed word, according to the arrangement order of the characters in each to-be-processed word, layer the characters in each to-be-processed word to obtain multiple levels.
[0038] Exemplarily, please refer to Figure 2 , Figure 2 which shows a schematic diagram of layering the characters in each to-be-processed word to obtain multiple levels. Among them, the to-be-processed vocabulary includes multiple to-be-processed words, such as to-be-processed words app (word1), spran (word2), cat (word3), season (word4), as (word5), etc. The electronic device may layer (Layer) the characters in each to-be-processed word according to the arrangement order of the characters in each to-be-processed word to obtain multiple levels (such as L1, L2, L3, L4, L5, L6, etc.), and each level in the multiple levels includes at least one character, and the number of levels is determined by the number of characters in the longest to-be-processed word.
[0039] Step S130: Determine the level corresponding to each character in each word to be processed, and based on the level corresponding to each character in each word to be processed, determine the transfer relationship of the characters in each word to be processed.
[0040] In some implementations, the electronic device can determine the level corresponding to each character in each word to be processed, and based on the level corresponding to each character in each word to be processed, determine the transition relationship of the characters in each word to be processed. The transition relationship of the characters in each word to be processed can be understood as the order in which the characters in each word to be processed are ordered.
[0041] In one implementation method, the electronic device can divide each character in each word to be processed into multiple levels, define the characters in each level as nodes, and define the next character of each character in a word to be processed as the child node of the current character, thereby determining the transition relationship of the characters in each word to be processed.
[0042] For example, please refer to [the document / reference]. Figure 2 In L1, the character 'a' is a node. In the word 'app' to be processed, the next level corresponding to the character 'a', that is, the next character 'p', can be defined as a child node of the current character 'a'.
[0043] In some implementations, after the electronic device determines the level corresponding to each character in each word to be processed, each level may include multiple identical characters. For each level, the electronic device can store one of the multiple identical characters. Furthermore, the characters of the next level corresponding to the identical character in different words to be processed can be stored in an array or other collection as pointers to lower-level queries, so as to efficiently compress the data for constructing the dictionary.
[0044] For example, please refer to [the document / reference]. Figure 2 The character s in L1 exists in two words to be processed (spran and season), and it has two child nodes, p and e. That is, the s node in L1 needs to store the p and e nodes in L2 as pointers to the child nodes in L2.
[0045] Step S140: Based on the transfer relationship of characters in each word to be processed, establish an index of the word list to be processed to obtain the target dictionary.
[0046] In some implementations, the electronic device can store the transition relationships of each character in each word to be processed, based on the transition relationships of the characters in each word to be processed. As one implementation, the electronic device can store the transition relationships of each character in each word to be processed by: establishing a mapping relationship between the word to be processed and the characters based on the transition relationships of each character in each word to be processed, and storing the mapping relationship; or establishing a preset model based on the transition relationships of each character in each word to be processed, and storing the preset model; or establishing a mapping relationship table between the word to be processed and the characters based on the transition relationships of each character in each word to be processed, and storing the mapping relationship table.
[0047] Furthermore, the electronic device can obtain the target dictionary by establishing an index of the word to be processed based on the transfer relationships of characters in each word to be processed. This can be achieved by the electronic device establishing an index of the word to be processed based on the mapping relationship between words and characters; or by establishing a preset model based on the transfer relationships of characters in each word to be processed, and then establishing an index of the word to be processed to obtain the target dictionary; or by establishing a mapping relationship table between words and characters based on the transfer relationships of characters in each word to be processed, and then establishing an index of the word to be processed to obtain the target dictionary.
[0048] For example, please refer to Figure 3 , Figure 3 This diagram illustrates how multiple levels are obtained by layering the characters within each word to be processed. For example... Figure 3 The character 's' in L1 exists in two words to be processed, and it has two child nodes, p and e. Therefore, the 's' node in L1 needs to store pointers to the p and e nodes in L2 as points to the child nodes in L2. Specifically, the p and e nodes in L2 can be marked as the 'children' attribute of the 's' node in L1 and stored accordingly. If the node is the last node (i.e., the last character) of a word to be processed, such as... Figure 3 If the last node of the word app in word1 is p, then in L3, this node can be marked as a leaf node and stored. The leaf node mark is used to indicate that the current node p is the end node of a word to be processed, such as... Figure 3 In L3, the `isleaf` attribute of node `p`. If the node is the end node of a word to be processed, all characters before the current last character can be stored in the end node as the source path of the leaf node for matching during retrieval, such as... Figure 3 The `leafParentPath` property of the `s` node example. For example... Figure 3 In the L3 p node, the word 'app' is recorded. The preceding character 'ap' needs to be recorded in the L3 p node, and the current L3 p node isLeaf needs to be marked as true, with the leafParentPath attribute set to "ap".
[0049] The nodes at each level of the words to be processed can be stored using an integer array, or extended to any index-addressable data structure. The child nodes corresponding to each node in each level structure can be stored using data structures including, but not limited to, arrays, sets, and bitmaps. Storage can be based on the number of child nodes using integer arrays, sets, or rising-bitmaps, or a data structure with constant-level equality matching. In some implementations, storing the characters in each word to be processed and their transition relationships results in a data structure that still contains some empty spaces at each level of the target dictionary, indicating some wasted space. Electronic devices can use variable-length, indexable data structures (such as lists) to better compress the target dictionary, achieving optimal data compression while maintaining high retrieval speed without compromising the time complexity of word retrieval in the target dictionary.
[0050] Understandably, strict hierarchical data storage allows for dictionary management based on the length of a given string of words to be processed. This enables the system to jump to either the starting layer or the layer corresponding to the last character of the string, allowing for retrieval of dictionary data from the end or the beginning, thus improving the efficiency of dictionary data management.
[0051] The dictionary data indexing method provided in this application involves obtaining a word list to be processed, wherein the word list includes multiple words to be processed, and each word consists of at least one character. For each word to be processed, the characters in each word are layered according to their arrangement order to obtain multiple levels, wherein each level includes at least one character. The level corresponding to each character in each word is determined, and the transition relationship of the characters in each word is determined based on the level corresponding to each character in each word. Based on the transition relationship of the characters in each word, an index of the word list to be processed is established to obtain the target dictionary. This layering of dictionary data and maintenance of the dictionary data according to the transition relationships between the layers achieves efficient compression of dictionary data and improves the efficiency of indexing the dictionary.
[0052] Please see Figure 4 , Figure 4 A flowchart illustrating a dictionary data indexing method according to an embodiment of this application is shown. This method is applied to the aforementioned electronic device, and will be discussed below. Figure 4 The process shown will be described in detail. The indexing method for the dictionary data may specifically include the following steps:
[0053] Step S210: Obtain a word list to be processed, wherein the word list to be processed includes multiple words to be processed, and each word to be processed consists of at least one character.
[0054] Step S220: For each word to be processed, according to the arrangement order of each character in each word to be processed, the characters in each word to be processed are divided into multiple levels, wherein each level includes at least one character.
[0055] In some implementations, for each of the multiple levels, after dividing the characters in each word to be processed into multiple levels, it is also possible to detect whether there are multiple identical characters among the characters included in the level. If multiple identical characters are detected among the characters included in the level, then only one identical character is retained in the level, which significantly reduces the space occupied by the dictionary data and lowers the cost of building the dictionary. In addition, by dividing the data for building the dictionary into layers according to the text length, maintaining forward and backward pointers in each layer, and using the character encoding value as the array index within the layer, with only one node for the same character in the same layer, a large number of duplicate characters are removed compared to the classic Trie and DAT, thereby achieving efficient data compression, reducing space occupation, and supporting dictionary retrieval efficiently with low resource consumption, which is highly practical.
[0056] Step S230: Determine the level corresponding to each character in each word to be processed, and based on the level corresponding to each character in each word to be processed, determine the transfer relationship of the characters in each word to be processed.
[0057] Step S240: Obtain the character code value corresponding to each character in each of the words to be processed.
[0058] In some implementations, the electronic device can use Unicode encoding to encode each character in each word to be processed, and the character code value corresponding to each character in each word can be used to represent that character. The same character is represented by the same character code value, which compresses the amount of dictionary data and improves the efficiency of dictionary indexing.
[0059] This method utilizes Unicode character encoding, which can encode character code values ranging from 0 to 65533. By using character code values to represent characters, character retrieval can be performed by matching the character code value. In other words, when searching for a character in the dictionary, the corresponding character code value can be retrieved. This reduces the dictionary's data storage space while improving the efficiency of indexing the dictionary.
[0060] For example, the words to be processed include "Tsinghua", "Zhonghua", and "Zhonghua Youwei". The electronic device obtains the character code value corresponding to each character in each word to be processed. It can use Unicode to encode characters and obtain the character code values 28165 (Qing), 21326 (Hua), 20013 (Zhong), 26377 (You), and 20026 (Wei).
[0061] Step S250: Based on the transfer relationship of characters in each word to be processed and the character code value corresponding to each character in each word to be processed, establish an index of the word list to be processed to obtain the target dictionary.
[0062] In some implementations, the electronic device can obtain the character code value corresponding to each character in each word to be processed, and then divide the characters in each word to be processed into multiple levels according to the order of the characters in each word to be processed; alternatively, it can divide the characters in each word to be processed into multiple levels according to the order of the characters in each word to be processed, and then obtain the character code value corresponding to each character in each word to be processed. In each level, the characters of the word to be processed can be defined as nodes, and in a word to be processed, the next character is the child node of the current character.
[0063] Furthermore, the electronic device can establish an index for the word to be processed based on the transition relationships of characters in each word and the character code values corresponding to each character in each word to obtain the target dictionary. In the target dictionary, each level uses a variable-length array (array length <= 65533) to store all nodes at each level; within each level's nodes, nodes with the same character can be stored only once, at the position indexed by that character code value; the code values of each node's child nodes can be stored using an array or other collection, serving as pointers for querying lower levels.
[0064] Please see Figure 5 In some implementations, the target dictionary is obtained by establishing an index of the word list to be processed based on the transfer relationship of characters in each word to be processed, which may include steps S251-S254.
[0065] Step S251: Based on the transfer relationship of characters in each word to be processed, determine the first attribute of each character in each word to be processed, wherein the first attribute is used to characterize the character of the next level of the level in which each character in the word is located.
[0066] In some implementations, the electronic device can determine a first attribute for each character in each word to be processed based on the hierarchy of the characters in that word. The first attribute characterizes the character at the next level below the current character in the word. It is understood that the next level of characters can include multiple characters, and the first attribute of a character can be a set including these multiple characters.
[0067] For example, please refer to again Figure 3 ,like Figure 3 The character 's' in L1 exists in two words to be processed, and it has two child nodes, p and e. That is, the 's' node in L1 needs to store the character code values of the p and e nodes in L2 as pointers to the child nodes in L2. Figure 3 The children attribute in the example of the s node.
[0068] Step S252: Based on the transition relationship of characters in each of the words to be processed, determine the second attribute of each character in each of the words to be processed, wherein the second attribute is used to characterize whether each character in the word is the last character of the corresponding word.
[0069] In some implementations, the electronic device can determine a second attribute of each character in each word to be processed based on the transition relationship of the characters in each word to be processed. The second attribute is used to characterize whether each character in the word is the last character of the corresponding word. The second attribute of a character can be that the character is the last character of the corresponding word or that the character is not the last character of the corresponding word.
[0070] For example, such as Figure 3 In the word1 word app, the last node is 'p'. In L3, this node can be marked as a leaf node (second attribute), indicating that the current node is the end node of a word to be processed. Figure 3 The `isleaf` attribute of the `p` node example. When the character is the last character of the corresponding word in the word to be processed, the second attribute of that character is true; for example, the `isleaf` attribute of the `p` node example is true. When the character is not the last character of the corresponding word in the word to be processed, the second attribute of that character is false; for example, the `isleaf` attribute of the `s` node example is false.
[0071] The electronic device can use a second attribute to identify each character in each word to be processed. This second attribute identifier can be represented by a bit or an integer; no limitation is made here. As one implementation method, since using bits to represent the second attribute of characters allows for better data compression, the electronic device can use bit identifiers to mark the second attribute of each character to compress the data used to construct the dictionary.
[0072] Step S253: Based on the transition relationship of characters in each of the words to be processed, determine the third attribute of each character in each of the words to be processed, wherein the third attribute is used to characterize the characters included in the corresponding word when the character is the last character of the corresponding word.
[0073] In some implementations, the electronic device can determine the third attribute of each character in each word to be processed based on the transition relationship of the characters in each word to be processed. The third attribute can be used to characterize the characters included in the corresponding word when the character is the last character of the corresponding word; or it can be used to characterize all characters in the corresponding word except for the last character when the character is the last character of the corresponding word.
[0074] For example, please refer to again Figure 3 Electronic devices use characters at each level as nodes. If a node is the end node of a word to be processed, then all characters of the word to be processed before the end character corresponding to the end node can be stored in the end node as the leaf node source path (i.e., the third attribute) of that character, which can be used for matching during retrieval. For example... Figure 3 In the L3 example, the leafParentPath attribute (["ap"]) of the p node. For example... Figure 3 For the word "as" to be processed, in the s node of L2, the isLeaf flag (second attribute) of the current L2 s node is saved as true, and the preceding character "a" is saved as the leafParentPath attribute (third attribute) of the s node.
[0075] It is understandable that the second attribute of a character can be used to indicate whether the character is the last character of the corresponding word or not; the third attribute of a character can be used to indicate the characters included in the corresponding word when the character is the last character of the word. That is, when the second attribute of a character indicates that the character is the last character of the corresponding word, the third attribute of the character is the characters included in the corresponding word; when the second attribute of a character indicates that the character is not the last character of the corresponding word, the third attribute of the character does not include the corresponding word. It is also understandable that a character can be the last character of multiple words, and the third attribute of a character can be a set including those multiple words.
[0076] Step S254: Based on the level corresponding to each character in each word to be processed, the first attribute, the second attribute, and the third attribute, establish an index for the word to be processed to obtain the target dictionary.
[0077] In some implementations, when an electronic device builds an index for a word to be processed to obtain a target dictionary, it can store characters at the corresponding levels within each word to be processed, and mark the first, second, and third attributes of each character for each word. Then, based on the character levels and the first, second, and third attributes, an index for the word to be processed is built to obtain the target dictionary. This eliminates the need for pre-sorting the dictionary, thus improving the speed of dictionary construction. By constructing the dictionary using a reasonable data structure, the time spent on dictionary construction is reduced. Simultaneously, reasonable space utilization and data compression reduce the large number of time-consuming memory reclamation operations during dictionary construction. Furthermore, hierarchical management of dictionary data improves the speed of indexing the target dictionary and facilitates dynamic updates of data in the dictionary.
[0078] In some implementations, the electronic device can obtain the character code value corresponding to each character and, based on the level, first attribute, second attribute, and third attribute corresponding to each character in each word to be processed, build an index of the word list to be processed to obtain the target dictionary. By using character code values to represent characters and layering the data for constructing the dictionary, storing the transfer relationships between each layer, the large and contiguous storage space (such as memory space) occupied by the constructed dictionary is significantly reduced while maintaining the same computational complexity (O(n)), effectively alleviating the problem of rapidly expanding dictionary data space usage. Even with large amounts of data, such as tens or hundreds of millions, reasonable space consumption can still be maintained. Here, O(n) represents the computational complexity method, and n is the length of the text to be retrieved.
[0079] For example, please refer to Figure 6 , Figure 6 The diagram shows that after an electronic device encodes characters using Unicode, each character is treated as a node. The first attribute of a character is identified by children, the second by isleaf, and the third by leafParentPath.
[0080] Please see Figure 7 In some implementations, the dictionary data indexing method may further include steps S2511-S2515.
[0081] Step S2511: Obtain the word to be inserted, wherein the word to be inserted consists of at least one character.
[0082] In some embodiments, the electronic device can obtain the words to be inserted from an associated cloud or electronic device through wireless communication technology; it can also obtain the words to be inserted from an associated electronic device through a serial communication interface. In the embodiments of the present application, the manner in which the electronic device obtains the words to be inserted is not limited herein.
[0083] Among them, the words to be inserted are the words that need to be inserted into the target dictionary, and the words to be inserted are composed of at least one character. Among them, the words to be inserted can be Chinese, or English, and can be a single word or multiple words. In the embodiments of the present application, this is not limited herein. Exemplarily, the words to be inserted are words such as "Tsinghua", "China", "Huawei".
[0084] Step S2512: Layer the characters in the word to be inserted according to the arrangement order of the characters in the word to be inserted, and determine the levels corresponding to the characters in the word to be inserted.
[0085] In some embodiments, the electronic device can layer the characters in the word to be inserted according to the arrangement order of the characters in the word to be inserted, and determine the levels corresponding to the characters in the word to be inserted. Exemplarily, layer the characters in the words to be inserted such as "Tsinghua", "China", "Huawei" according to the arrangement order of the characters in the words to be inserted, and determine the levels corresponding to the characters in the words to be inserted. The levels corresponding to "Qing" and "Zhong" are L1, the level corresponding to "Hua" is L2, the level corresponding to "You" is L3, and the level corresponding to "Wei" is L4.
[0086] Step S2513: Determine the transfer relationship of the characters in the word to be inserted based on the levels corresponding to the characters in the word to be inserted.
[0087] In some embodiments, the electronic device can determine the order relationship of the characters in the word to be inserted based on the levels corresponding to the characters in the word to be inserted.
[0088] Exemplarily, layer the characters in the words to be inserted such as "Tsinghua", "China", "Huawei" according to the arrangement order of the characters in the words to be inserted, and determine the levels corresponding to the characters in the words to be inserted. The levels corresponding to "Qing" and "Zhong" are L1, the level corresponding to "Hua" is L2, the level corresponding to "You" is L3, and the level corresponding to "Wei" is L4. The electronic device determines, based on the levels corresponding to the characters in the word to be inserted, that the character "Qing" in the word to be inserted "Tsinghua" is at a higher level than the character "Hua", and the character "Hua" in the word to be inserted "China" is at a lower level than the character "Zhong".
[0089] Step S2514: Determine the first attribute, the second attribute, and the third attribute of the characters in the to-be-inserted word based on the transfer relationship of the characters in the to-be-inserted word.
[0090] In some embodiments, the electronic device determines the first attribute, the second attribute, and the third attribute of the characters in the to-be-inserted word based on the transfer relationship of the characters in the to-be-inserted word. Exemplarily, in accordance with the arrangement order of the characters in words such as "Tsinghua", "China", "Huawei", etc., the characters in the to-be-inserted word are stratified, and the corresponding levels of the characters in the to-be-inserted word are determined. The levels corresponding to "Qing" and "Zhong" are L1, the level corresponding to "Hua" is L2, the level corresponding to "You" is L3, and the level corresponding to "Wei" is L4. Further, the electronic device determines, based on the levels corresponding to the characters in the to-be-inserted word, that the character "Qing" in the to-be-inserted word "Tsinghua" is at a higher level than the character "Hua", and the character "Hua" in the to-be-inserted word "China" is at a lower level than the character "Zhong". Further, the electronic device determines, based on the transfer relationship of the characters in the to-be-inserted word, that the first attribute of the character "Qing" in "Tsinghua" is "Hua", the second attribute is that the character "Qing" is not the last character of the corresponding word "Tsinghua", and the third attribute does not include "Tsinghua".
[0091] Step S2515: Update the target dictionary based on the levels corresponding to the characters in the to-be-inserted word, the first attribute, the second attribute, and the third attribute.
[0092] In some embodiments, the electronic device can update the target dictionary based on the levels corresponding to the characters in the to-be-inserted word, the first attribute, the second attribute, and the third attribute, corresponding to the levels, the first attribute, the second attribute, and the third attribute of the characters in each to-be-processed word in the target dictionary.
[0093] Among them, the way to update the target dictionary can be to update the first attribute, the second attribute, and the third attribute corresponding to the characters at the corresponding levels. It can be to add the character to the corresponding level in the target dictionary and add the first attribute, the second attribute, and the third attribute of the character at the corresponding level; it can also be to add the first attribute of the character corresponding to the first attribute of the character in the to-be-inserted word to the corresponding character at the same level in the target dictionary, or to add the second attribute corresponding to the character to the second attribute of the corresponding character at the same level in the target dictionary, or to add the second attribute corresponding to the character to the second attribute of the corresponding character at the same level in the target dictionary.
[0094] In some embodiments, if the target dictionary includes the to-be-inserted word, after updating the target dictionary based on the levels corresponding to the characters in the to-be-inserted word, the first attribute, the second attribute, and the third attribute, the attributes and levels of the to-be-processed words in the target dictionary may not change.
[0095] Exemplarily, the construction of the target dictionary is as follows Figure 8 As shown, the words to be inserted obtained by the electronic device are "Tsinghua", "China", and "Huawei". The electronic device can obtain the character code values corresponding to each character of the word to be inserted, and update the target dictionary based on the character code values corresponding to each character in the word to be inserted, the levels corresponding to each character in the word to be inserted, the first attribute, the second attribute, and the third attribute.
[0096] Among them, the process of inserting "Tsinghua" can be as follows: First, add a Node node at the index position (index position) of the code value 28165 of "Qing" in L1. Set the isLeaf of the code value of "Qing" in L1 to false (second attribute), the leafParentPath to empty (third attribute), and the children to the code value 21326 of "Hua" (third attribute). Then, add a Node node at the index position 21326 of "Hua" in L2. Set the isLeaf of "Hua" in L2 to true (second attribute), the leafParentPath to "Qing" (third attribute), and the children to empty (first attribute).
[0097] Furthermore, the process of inserting "China" can be as follows: First, add a Node node at the index position of the code value 20013 of "Zhong" in L1. Set the isLeaf of "Zhong" in L1 to false (second attribute), the leafParentPath to empty (third attribute), and the children to the code value 21326 of "Hua" (first attribute). Then, check that the Node node at the position 21326 in L2 has been added and the isLeaf has been set to true, so set the leafParentPath to the added character "Zhong", and the children still remain empty.
[0098] Furthermore, the process of inserting "China Huawei" can be as follows: Check that there is already a Node node at the index position of the code value 20013 of "Zhong" in L1, the isLeaf is set to false, the leafParentPath is set to empty, and there are already child nodes of "Hua". Then, check that the Node node at the position 21326 in L2 has been added, and add the code value 26377 of "You" to the children. Then, at the code value 26377 of "You" in L3, it is found that the node is empty, so add a Node node, set the isLeaf to false, the leafParentPath to empty, and add the code value 20026 of "Wei" to the children. Then, after checking that it is empty at the code value 20026 of "Wei" in L4, add a Node node, the isLeaf has been set to true, the leafParentPath is added with the string "China You", and the children are set to empty.
[0099] Among them, when retrieving the target dictionary, instead of checking each character, it is to check whether the node corresponding to the index bit of the character code value exists. At the same time, due to the strict data hierarchical storage, for the given string of the word to be processed, it can jump to the starting layer or the layer corresponding to the last character of the string according to the string length to start matching, and it can be retrieved from back to front or from front to back, ensuring the efficient multi-mode matching of the word to be retrieved and the data in the target dictionary. While efficiently compressing and constructing the data of the target dictionary, the efficiency of retrieving the target dictionary is improved.
[0100] Please refer to Figure 9 , in some embodiments, after obtaining the target dictionary by establishing the index of the word list to be processed based on the transition relationship of the characters in each word to be processed, the index method of the dictionary data may further include steps S2521 - step S2524.
[0101] Step S2521: Obtain the word to be deleted, where the word to be deleted consists of at least one character.
[0102] In some embodiments, the electronic device can obtain the word to be deleted from the associated cloud or electronic device through wireless communication technology; it can also obtain the word to be deleted from the associated electronic device through the serial communication interface. In the embodiments of the present application, the manner in which the electronic device obtains the word to be deleted is not limited herein.
[0103] Among them, the word to be deleted is the word that needs to be cleared from the target dictionary, and the word to be deleted consists of at least one character. Among them, the word to be deleted can be Chinese, English, a single word or multiple words. In the embodiments of the present application, it is not limited herein. Exemplarily, the words to be deleted are words such as "Tsinghua", "China", "Huawei".
[0104] Step S2522: Stratify each character in the word to be deleted according to the arrangement order of the characters in the word to be deleted, and determine the target layer corresponding to the last character in the word to be deleted.
[0105] In some embodiments, the electronic device can stratify each character in the word to be deleted according to the arrangement order of the characters in the word to be deleted, and determine the target layer corresponding to the last character in the word to be deleted. Among them, the target layer is the layer where the last character in the word to be deleted is located. Exemplarily, the word to be deleted is "Tsinghua", and the electronic device stratifies each character in "Tsinghua" according to the arrangement order of the characters in "Tsinghua". For example, the layer corresponding to "Qing" is L1, the layer corresponding to "Hua" is L2, and the layer L2 corresponding to the last character "Hua" in "Tsinghua" is determined as the target layer.
[0106] Step S2523: Retrieve the characters in the target dictionary that are classified at the target level, and determine the third attribute corresponding to the character that is the same as the last character of the word to be deleted from the characters classified at the target level, and use it as the target third attribute.
[0107] In some implementations, the electronic device can retrieve characters classified at the target level in the target dictionary, and determine a third attribute corresponding to a character that matches the last character of the word to be deleted from the characters classified at the target level, as the target third attribute. The characters classified at the target level in the target dictionary may include one or more, or none.
[0108] As one implementation method, if there is no character classified at the target level in the target dictionary, and it is determined that there is no corresponding word to be deleted in the target dictionary, then the operation of deleting the word to be deleted from the target dictionary is terminated.
[0109] As another implementation method, after the electronic device retrieves characters classified at the target level from the target dictionary, it determines the third attribute corresponding to the character that is the same as the last character of the word to be deleted from the characters classified at the target level, and uses it as the target third attribute.
[0110] It is understandable that the third attribute corresponding to the character that is the same as the last character in the word to be deleted is used as the target third attribute. This character can be the last character of multiple words to be processed, that is, the target third attribute corresponding to this character can include multiple words to be processed.
[0111] Step S2524: If the target third attribute includes the word to be deleted, then delete the word to be deleted included in the target third attribute.
[0112] In some implementations, the third attribute corresponding to the character in the target level of the target dictionary that has the same last character as the word to be deleted is used as the target third attribute. The target third attribute may include multiple words to be processed, or it may include only one word. If the word to be processed included in the target third attribute is the same as the word to be deleted, then the word to be deleted included in the target third attribute is deleted.
[0113] In some implementations, after the electronic device deletes the words to be deleted from the third attribute corresponding to the characters that end with the last character of the words to be deleted in the target level of the target dictionary, the third attribute corresponding to the characters that end with the last character of the words to be deleted in the target level of the target dictionary may also include other words to be processed. After the electronic device deletes the words to be deleted from the target third attribute, it can end the operation of deleting words in the target dictionary.
[0114] Please see Figure 10, in some embodiments, after deleting the word to be deleted included in the target third attribute if the target third attribute includes the word to be deleted, step S2525 may further be included.
[0115] Step S2525: If it is determined that the target third attribute does not include the word to be processed, update the second attribute corresponding to the end character in the target dictionary.
[0116] In some embodiments, after the electronic device deletes the word to be deleted included in the third attribute corresponding to the character that is the same as the end character in the word to be deleted in the target level of the target dictionary, if the third attribute corresponding to the character that is the same as the end character in the word to be deleted in the target level of the target dictionary does not include the word to be processed, that is, the character is no longer the end character of the word to be processed in the target dictionary, modify the second attribute corresponding to the character to indicate that the character is not the end character of the word to be processed.
[0117] Exemplarily, please refer to again Figure 8 , the word to be deleted obtained by the electronic device is "Tsinghua". The process for the electronic device to delete this word to be deleted may be: check whether the node at position 28165 in L1 is empty. If it is empty, end the operation and determine that the target dictionary does not contain this word to be deleted; if the check result is not empty, continue to check whether children (the first attribute) of the node at position 28165 contains 21326. If it does not contain, end the operation and determine that the target dictionary does not contain this word to be deleted. Further, if the check result of children of the node at position 28165 is not empty, check whether the isLeaf flag (the second attribute) of the node at position 21326 in L2 is true. If it is not true, it indicates that the target dictionary does not contain this word to be deleted, and end the operation. Further, if the isLeaf flag of the node at position 21326 in L2 is true, check whether leafParentPath (the third attribute) of the node at position 21326 contains "清". If it does not contain, it indicates that the target dictionary does not contain this word to be deleted, and end the operation; if the check result of leafParentPath of the node at position 21326 is that it contains, delete "清" from leafParentPath. After deletion, continue to check whether leafParentPath is an empty set. If it is not empty, end the operation; if the check result of leafParentPath of the node at position 21326 is empty, it indicates that this node is no longer the end character of the word to be processed in the target dictionary after the word to be deleted in the current generation is deleted. Modify isLeaf (the second attribute) of the node at position 21326 to false and end the operation.
[0118] It can be understood that the target dictionary constructed in the embodiments of the present application supports dynamic updates, can dynamically add and delete data for constructing the target dictionary, supports target dictionary retrieval in more business scenarios, and improves the practicality of the target dictionary.
[0119] Please refer to Figure 11 , in some embodiments, after obtaining the target dictionary by establishing the index of the to-be-processed word list based on the transfer relationship of the characters in each to-be-processed word, the index method of the dictionary data may further include steps S2531-step S2524.
[0120] Step S2531: Obtain the to-be-retrieved word, where the to-be-retrieved word is composed of at least one character.
[0121] In some embodiments, the electronic device may obtain the to-be-retrieved word from an associated cloud or electronic device through wireless communication technology; it may also obtain the to-be-retrieved word from an associated electronic device through a serial communication interface. In the embodiments of the present application, the manner in which the electronic device obtains the to-be-retrieved word is not limited herein.
[0122] Among them, the to-be-retrieved word is a word in the to-be-processed words in the target dictionary that hits the to-be-retrieved word, and the to-be-retrieved word is composed of at least one character. Among them, the to-be-retrieved word can be Chinese, can also be English, can be a single word or multiple words, and can also be a string composed of multiple characters. In the embodiments of the present application, it is not limited herein. Exemplarily, the to-be-retrieved words are words such as "Tsinghua", "China", "Huawei", and "Admitted to Tsinghua".
[0123] Step S2532: Determine the arrangement order of each character in the to-be-retrieved word, and retrieve whether the first level in the target dictionary includes the first character of the to-be-retrieved word, where each first character of the to-be-processed word is divided in the first level.
[0124] In some embodiments, the electronic device can retrieve the situation where the to-be-processed word in the target dictionary hits the to-be-retrieved word, determine the arrangement order of each character in the to-be-retrieved word, and retrieve whether the first level in the target dictionary includes the first character of the to-be-retrieved word, and then start retrieving from the first character of the to-be-retrieved word the situation where the to-be-processed word in the target dictionary hits the to-be-retrieved word. Among them, each first character of the to-be-processed word is divided in the first level of the target dictionary.
[0125] In some implementations, if the electronic device finds that the first character of the word to be searched is not included in the first level of the target dictionary, then the characters in the word to be searched, excluding the first character, are used as substitute first characters, and the first level of the target dictionary is searched to see if the substitute first character is included, until the first level of the target dictionary is found to include the substitute first character, or the characters in the word to be searched have been completely searched.
[0126] In some implementations, if the electronic device finds that the first level of the target dictionary does not include the first character of the word to be searched, then according to the character order of the word to be searched, the characters in the word to be searched, excluding the first character, are used as substitute first characters, and the first level of the target dictionary is searched to see if the substitute first character is included, until the first level of the target dictionary is found to include the substitute first character, or the characters in the word to be searched have been completely searched.
[0127] Step S2533: If the first character of the word to be searched is found in the first level of the target dictionary, then the first attribute corresponding to the first character of the target dictionary is obtained.
[0128] In some implementations, if the electronic device finds that the first character of the word to be searched is included in the first level of the target dictionary, it obtains the first attribute corresponding to the first character of the target dictionary. The first attribute of the first character includes the characters in the next level of the target dictionary for all words to be processed that begin with that character.
[0129] Step S2534: If the first attribute corresponding to the first character includes the second character of the word to be searched, then obtain the second attribute and the third attribute of the second character in the second level of the target dictionary, wherein the second level stores the second character of each word to be processed, and the second character is the next character corresponding to the first character of the word to be searched.
[0130] Furthermore, if the electronic device detects that the first attribute corresponding to the first character in the target dictionary includes the second character of the word to be searched, then it obtains the second and third attributes of the second character in the second level of the target dictionary. The second level stores the second character of each word to be processed, and the second character is the character of the next level corresponding to the first character of the word to be searched.
[0131] Specifically, the second and third attributes of the second character in the second level of the target dictionary are obtained. The second attribute can be used to determine whether the second character is the last character of the word to be processed in the target dictionary, and the third attribute can be used to obtain the word to be processed that ends with the second character.
[0132] Step S2535: If the second attribute of the second character indicates that the second character is the last character of the target word to be processed among the plurality of words to be processed, and the third attribute of the second character indicates that when the second character is the last character of the target word to be processed, the target word to be processed includes the first character and the second character, then it is determined that the target word to be processed matches the word to be retrieved.
[0133] The target word to be processed is the word to be processed in the target dictionary. It can be the same as the word to be retrieved, or it can be the same as a word in the word to be retrieved that consists of at least one consecutive character.
[0134] In some implementations, if the electronic device finds that the second attribute of the second character indicates that the second character is the last character of the target word among multiple words to be processed, and the third attribute of the second character indicates that when the second character is the last character of the target word to be processed, the target word to be processed includes the first character and the second character, then it is determined that the target word to be processed matches the searched word. That is, the words to be processed in the target dictionary match the searched word.
[0135] Understandably, electronic devices can choose whether to continue longer word matching between the target dictionary and the searched words, or they can end the search for the target dictionary immediately after a word is matched.
[0136] For example, please refer to [the document / reference]. Figure 8, if the word to be retrieved obtained by the electronic device is "admitted to Tsinghua University", the process for the electronic device to check the words hit by the word to be retrieved in the target dictionary can be as follows: 1) First, check the first character "被". If the node "被" in L1 of the target dictionary does not exist, continue to use "清" as the replacement first character for retrieval; perform step 2). If it is checked that the node "清" in the target dictionary L1 is not empty, further check whether the isLeaf (second attribute) of this node is true. If the result is false, continue to check whether the children (first attribute) of this node contains the child node "华". If the check result is that it contains; perform step 3). Check whether the isLeaf (second attribute) of the node "华" in the target dictionary L2 is true. If the result is true, continue to check whether the leafParentPath (third node) of this node contains "清". If the check result is that it contains, it indicates that the word "清华" exists in the target dictionary, and record this word. The electronic device can choose whether to continue the matching of the longer word to be retrieved and the word to be retrieved as needed, or can immediately end the query after determining that the target dictionary hits the word to be retrieved. If it is necessary to continue the matching of longer words, step 3) can be repeated for the string after the word to be retrieved and the target word to be processed. The hit words are continuously recorded until the last character of the target word to be processed or the last character of the word to be retrieved is retrieved.
[0137] The embodiments of the present application provide technical solutions. Compared with Figure 1 the method shown, the character code values corresponding to each character in each word to be processed are also obtained. Based on the transfer relationship of the characters in each word to be processed and the character code values corresponding to each character in each word to be processed, an index of the word list to be processed is established to obtain the target dictionary. Using the character code values to represent characters efficiently compresses the data for constructing the dictionary, reduces the time-consuming for constructing the dictionary, and improves the efficiency of retrieving the dictionary.
[0138] Please refer to Figure 12 , Figure 12 shows a module block diagram of an index device for dictionary data provided by an embodiment of the present application. The index device 200 for dictionary data is applied to the above-mentioned electronic device. The following will be a detailed elaboration on Figure 12 the process shown. The index device 200 for dictionary data includes: a word list to be processed acquisition module 210, a word layering module 220, a transfer relationship determination module 230, and a target dictionary acquisition module 240, where:
[0139] The word list to be processed acquisition module 210 is used to acquire the word list to be processed. Among them, the word list to be processed includes multiple words to be processed, and each word to be processed in the multiple words to be processed is composed of at least one character.
[0140] The word layering module 220 is used to layer each character in each word to be processed according to the order of the characters in each word to obtain multiple layers, wherein each of the multiple layers includes at least one character.
[0141] The transfer relationship determination module 230 is used to determine the level corresponding to each character in each word to be processed, and to determine the transfer relationship of the characters in each word to be processed based on the level corresponding to each character in each word to be processed.
[0142] The target dictionary acquisition module 240 is used to obtain the target dictionary by establishing an index of the word list to be processed based on the transfer relationship of the characters in each word to be processed.
[0143] Furthermore, the target dictionary acquisition module 240 includes: a character code value acquisition module and a first target dictionary acquisition module, wherein:
[0144] The character code value acquisition module is used to acquire the character code value corresponding to each character in each of the words to be processed.
[0145] The first module for obtaining the target dictionary is used to establish an index of the word list to be processed based on the transfer relationship of characters in each word to be processed and the character code value corresponding to each character in each word to be processed to obtain the target dictionary.
[0146] Furthermore, the word layering module 220 includes: a identical character detection module and an identical character retention module, wherein:
[0147] The identical character detection module is used to detect whether there are multiple identical characters among the characters included in the level.
[0148] The identical character retention module is used to retain one identical character in the level if multiple identical characters are detected among the characters included in the level.
[0149] Furthermore, the target dictionary acquisition module 240 further includes: a first attribute determination module, a second attribute determination module, a third attribute determination module, and a second target dictionary acquisition module, wherein:
[0150] The first attribute determination module is used to determine the first attribute of each character in each word to be processed based on the transfer relationship of the characters in each word to be processed, wherein the first attribute is used to characterize the character of the next level of the level in which each character in the word is located.
[0151] The second attribute determination module is used to determine the second attribute of each character in each word to be processed based on the transition relationship of the characters in each word to be processed, wherein the second attribute is used to characterize whether each character in the word is the last character of the corresponding word.
[0152] The third attribute determination module is used to determine the third attribute of each character in each word to be processed based on the transition relationship of the characters in each word to be processed, wherein the third attribute is used to characterize the characters included in the corresponding word when the character is the last character of the corresponding word.
[0153] The second module for obtaining the target dictionary is used to establish an index of the word list to be processed based on the level corresponding to each character in each word to be processed, the first attribute, the second attribute, and the third attribute to obtain the target dictionary.
[0154] Furthermore, the dictionary data indexing device 200 may further include: a word-to-be-inserted acquisition unit, a word-to-be-inserted hierarchical unit, a character transfer relationship acquisition unit in the word-to-be-inserted, a character attribute acquisition unit in the word-to-be-inserted, and a target dictionary update unit, wherein:
[0155] The word to be inserted acquisition unit is used to acquire the word to be inserted, wherein the word to be inserted consists of at least one character.
[0156] The word-to-be-inserted layering unit is used to layer the characters in the word-to-be-inserted according to their arrangement order, and to determine the layer corresponding to each character in the word-to-be-inserted.
[0157] The character transfer relationship acquisition unit in the word to be inserted is used to determine the character transfer relationship in the word to be inserted based on the level corresponding to each character in the word to be inserted.
[0158] The character attribute acquisition unit in the word to be inserted is used to determine the first attribute, the second attribute, and the third attribute of the characters in the word to be inserted based on the transfer relationship of the characters in the word to be inserted.
[0159] The target dictionary update unit is used to update the target dictionary based on the level corresponding to each character in the word to be inserted, the first attribute, the second attribute, and the third attribute.
[0160] Furthermore, the dictionary data indexing device 200 may further include: a word-to-be-deleted acquisition unit, a target level determination unit, a target third attribute determination unit, and a word-to-be-deleted deletion unit, wherein:
[0161] The word to be deleted acquisition unit is used to acquire the word to be deleted, wherein the word to be deleted consists of at least one character.
[0162] The target level determination unit is used to divide the characters in the word to be deleted into layers according to the order of the characters in the word to be deleted, and determine the target level corresponding to the last character in the word to be deleted.
[0163] The target third attribute determination unit is used to retrieve characters in the target dictionary that are classified at the target level, and determine the third attribute corresponding to the character that is the same as the last character of the word to be deleted from the characters classified at the target level, as the target third attribute.
[0164] The word deletion unit is used to delete the word to be deleted if the target third attribute includes the word to be deleted.
[0165] Further, after deleting the word to be deleted if the target third attribute includes the word to be deleted, the word to be deleted deletion unit includes: a second attribute update unit, wherein:
[0166] The second attribute update unit is used to update the second attribute corresponding to the last character in the target dictionary if it is determined that the target third attribute does not include the word to be processed.
[0167] Furthermore, the dictionary data indexing device 200 may further include: a word-to-be-searched acquisition unit, a first character determination unit, a first attribute determination unit, a second and third attribute acquisition unit, and a hit determination unit, wherein:
[0168] The term acquisition unit is used to acquire the term to be retrieved, wherein the term to be retrieved consists of at least one character.
[0169] The first character determination unit is used to determine the order of characters in the word to be searched, and to search whether the first character of the word to be searched is included in the first level of the target dictionary, wherein the first level is divided into the first character of each word to be processed.
[0170] The first attribute determination unit is used to obtain the first attribute corresponding to the first character of the target dictionary if the first level of the target dictionary contains the first character of the word to be searched.
[0171] The second and third attribute acquisition unit is used to acquire the second and third attributes of the second character in the second level of the target dictionary if the first attribute corresponding to the first character includes the second character of the word to be retrieved. The second level stores the second character of each word to be processed, and the second character is the next character corresponding to the first character of the word to be retrieved.
[0172] The hit determination unit is configured to determine that the target word to be processed hits the searched word if the second attribute of the second character indicates that the second character is the last character of the target word to be processed among the plurality of words to be processed, and the third attribute of the second character indicates that the target word to be processed includes the first character and the second character when the second character is the last character of the target word to be processed.
[0173] Furthermore, the first character determination unit includes: a replacement first character acquisition unit, wherein:
[0174] The alternative first character acquisition unit is used to, if the first character of the word to be searched is not found in the first level of the target dictionary, take the characters in the word to be searched other than the first character as alternative first characters, and search whether the first level of the target dictionary includes the alternative first character, until the first level of the target dictionary includes the alternative first character, or the characters in the word to be searched have been completely searched.
[0175] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device and module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0176] In the several embodiments provided in this application, the coupling between modules can be electrical, mechanical, or other forms of coupling.
[0177] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0178] Please see Figure 13This document illustrates a structural block diagram of an electronic device 100 provided in an embodiment of this application. The electronic device 100 can be a smartphone, tablet computer, e-reader, or other electronic device capable of running applications. The electronic device 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more applications, wherein the one or more applications can be stored in the memory 120 and configured to be executed by one or more processors 110, and the one or more applications are configured to perform the methods described in the foregoing method embodiments.
[0179] The processor 110 may include one or more processing cores. The processor 110 connects to various parts within the electronic device 100 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 120, and by calling data stored in the memory 120. Optionally, the processor 110 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 110 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content to be displayed; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 110 and may be implemented separately using a communication chip.
[0180] The memory 120 may include random access memory (RAM) or read-only memory (ROM). The memory 120 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 120 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created by the electronic device 100 during use (such as phonebook data, audio and video data, chat log data, etc.).
[0181] Please see Figure 14 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable medium 300 stores program code that can be invoked by a processor to execute the methods described in the above method embodiments.
[0182] The computer-readable storage medium 300 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 300 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 300 has storage space for program code 310 that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 310 may be compressed, for example, in a suitable form.
[0183] In summary, the dictionary data indexing method, apparatus, electronic device, and storage medium provided in this application obtain a word list to be processed, wherein the word list includes multiple words to be processed, and each word to be processed consists of at least one character; for each word to be processed, the characters in each word to be processed are layered according to the arrangement order of the characters in each word to obtain multiple levels, wherein each level includes at least one character; the level corresponding to each character in each word to be processed is determined, and the transition relationship of the characters in each word to be processed is determined based on the level corresponding to each character in each word to be processed; based on the transition relationship of the characters in each word to be processed, an index of the word list to be processed is established to obtain the target dictionary. Thus, the data for constructing the dictionary is layered, and the data for constructing the dictionary is maintained according to the transition relationship between the data in each layered level, achieving efficient compression of dictionary data and improving the efficiency of indexing the dictionary.
[0184] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for indexing dictionary data, characterized in that, The method includes: Obtain a word list to be processed, wherein the word list includes multiple words to be processed, and each word to be processed consists of at least one character; For each word to be processed, the characters in each word to be processed are divided into multiple levels according to the order of their arrangement. Each level includes at least one character. Determine the level corresponding to each character in each word to be processed, and based on the level corresponding to each character in each word to be processed, determine the transition relationship of the characters in each word to be processed; Based on the transfer relationship of characters in each of the words to be processed, a first attribute of each character in each of the words to be processed is determined, wherein the first attribute is used to characterize the character of the next level of the level in which each character in the word is located; Based on the transition relationship of characters in each of the words to be processed, a second attribute of each character in each of the words to be processed is determined, wherein the second attribute is used to characterize whether each character in the word is the last character of the corresponding word; Based on the transition relationship of characters in each of the words to be processed, a third attribute of each character in each of the words to be processed is determined, wherein the third attribute is used to characterize the characters included in the corresponding word when the character is the last character of the corresponding word; Based on the level corresponding to each character in each word to be processed, the first attribute, the second attribute, and the third attribute, an index is established for the word list to be processed to obtain the target dictionary.
2. The method according to claim 1, characterized in that, The step of establishing an index for the word list to be processed based on the character transition relationships in each word to be processed to obtain the target dictionary includes: Obtain the character code value corresponding to each character in each of the words to be processed; Based on the transfer relationships of characters in each word to be processed and the character code values corresponding to each character in each word to be processed, an index is established for the word list to be processed to obtain the target dictionary.
3. The method according to claim 1, characterized in that, For each of the multiple levels, after dividing each character in each word to be processed into multiple levels, the method further includes: Detect whether there are multiple identical characters among the characters included in the level; If multiple identical characters are detected among the characters included in the level, then only one identical character is retained in the level.
4. The method according to claim 1, characterized in that, After obtaining the target dictionary by establishing an index of the word list based on the transition relationships of characters in each word to be processed, the method further includes: Obtain the word to be inserted, wherein the word to be inserted consists of at least one character; According to the order of the characters in the word to be inserted, the characters in the word to be inserted are divided into layers, and the layer corresponding to each character in the word to be inserted is determined. Based on the level corresponding to each character in the word to be inserted, the transfer relationship of the characters in the word to be inserted is determined; Based on the transfer relationship of the characters in the word to be inserted, the first attribute, the second attribute, and the third attribute of the characters in the word to be inserted are determined; The target dictionary is updated based on the level corresponding to each character in the word to be inserted, the first attribute, the second attribute, and the third attribute.
5. The method according to claim 1, characterized in that, After obtaining the target dictionary by establishing an index of the word list based on the transition relationships of characters in each word to be processed, the method further includes: Obtain the word to be deleted, wherein the word to be deleted consists of at least one character; According to the order of the characters in the word to be deleted, the characters in the word to be deleted are divided into layers, and the target layer corresponding to the last character in the word to be deleted is determined. Retrieve characters from the target dictionary that are classified at the target level, and determine the third attribute corresponding to the character that is the same as the last character of the word to be deleted from the characters classified at the target level, and use it as the target third attribute; If the target third attribute includes the word to be deleted, then the word to be deleted included in the target third attribute is deleted.
6. The method according to claim 5, characterized in that, After deleting the word to be deleted if the target third attribute includes the word to be deleted, the method further includes: If it is determined that the target third attribute does not include the word to be processed, then the second attribute corresponding to the last character in the target dictionary is updated.
7. The method according to claim 1, characterized in that, After obtaining the target dictionary by establishing an index of the word list based on the transition relationships of characters in each word to be processed, the method further includes: Obtain the term to be searched, wherein the term to be searched consists of at least one character; The order of characters in the word to be searched is determined, and the first level of the target dictionary is searched to see if the first character of the word to be searched is included. The first level is divided into the first character of each word to be processed. If the first character of the word to be searched is found in the first level of the target dictionary, then the first attribute corresponding to the first character of the target dictionary is obtained; If the first attribute corresponding to the first character includes the second character of the word to be retrieved, then the second and third attributes of the second character in the second level of the target dictionary are obtained, wherein the second level stores the second character of each word to be processed, and the second character is the next character corresponding to the first character of the word to be retrieved; If the second attribute of the second character indicates that the second character is the last character of the target word to be processed among the plurality of words to be processed, and the third attribute of the second character indicates that when the second character is the last character of the target word to be processed, the target word to be processed includes the first character and the second character, then it is determined that the target word to be processed matches the searched word.
8. The method according to claim 7, characterized in that, The method further includes: If the first level of the target dictionary does not contain the first character of the word to be searched, then each character in the word to be searched other than the first character is used as a substitute first character, and the first level of the target dictionary is searched to see if the substitute first character is included, until the first level of the target dictionary is found to contain the substitute first character, or the characters in the word to be searched have been completely searched.
9. An indexing device for dictionary data, characterized in that, The device includes: The unprocessed word list acquisition module is used to acquire the unprocessed word list, wherein the unprocessed word list includes multiple unprocessed words, and each unprocessed word consists of at least one character; The word layering module is used to layer each character in each word to be processed into multiple layers according to the order of the characters in each word to be processed, wherein each layer includes at least one character. The transfer relationship determination module is used to determine the level corresponding to each character in each word to be processed, and to determine the transfer relationship of the characters in each word to be processed based on the level corresponding to each character in each word to be processed; The target dictionary acquisition module is used to determine a first attribute of each character in each word to be processed based on the transfer relationship of the characters in each word to be processed, wherein the first attribute is used to characterize the character of the next level of the level in which each character in the word is located; determine a second attribute of each character in each word to be processed based on the transfer relationship of the characters in each word to be processed, wherein the second attribute is used to characterize whether each character in the word is the last character of the corresponding word; determine a third attribute of each character in each word to be processed based on the transfer relationship of the characters in each word to be processed, wherein the third attribute is used to characterize the characters included in the corresponding word when the character is the last character of the corresponding word; and establish an index of the word to be processed based on the level corresponding to each character in each word to be processed, the first attribute, the second attribute, and the third attribute to obtain the target dictionary.
10. An electronic device, characterized in that, include: One or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, the one or more applications being configured to perform the method as described in any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains program code that can be invoked by a processor to execute the method as described in any one of claims 1-8.