Word segmentation method, device, electronic device and storage medium based on dictionary matching
By adopting a word segmentation method based on dictionary matching in natural speech processing technology, and using a method that combines search linked lists and prefix dictionary trees, the problem of limited hardware resources and complex word form changes is solved, and efficient word segmentation result generation is achieved, which is suitable for hardware Devices with poor resources.
Patent Information
- Application Number
- CN202210472878.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-29
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2042-04-29
AI Technical Summary
When the hardware resources of existing natural speech processing technology are limited, especially when there is a lack of annotated data, the word segmentation scheme based on dictionary matching is inefficient, and the time complexity is too high due to complex word form change rules, which affects the algorithm. efficiency.
The word segmentation method based on dictionary matching is used to split the text at the word level and store the split terms in the search linked list. It combines the prefix dictionary tree to find candidate deformed words, and uses priority indicators to determine the word segmentation results to reduce the time and space complexity.
While ensuring the integrity and correctness of the word segmentation results, it reduces the time and space complexity of the word segmentation algorithm, making it suitable for offline deployment on devices with poor hardware resources.
Smart Images

Figure CN114925686B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural speech processing technology, and in particular, to a word segmentation method, device, electronic device, and storage medium based on dictionary matching. Background Art
[0002] In the existing natural speech processing technology, word segmentation is the first step in language processing. The word segmentation schemes can be divided into three types: dictionary matching-based, probability statistics-based, and deep learning-based. The probability statistics-based word segmentation scheme and the deep learning-based word segmentation scheme both require a large amount of word segmentation annotation data as support. These two schemes have a large memory occupancy. Therefore, in the scenarios where individual words need to be explained, there is no large amount of annotation data, and the hardware resources are limited, the dictionary matching-based word segmentation scheme has a large application space. In dictionary matching, since there are cases where a single word has multiple forms in some languages. For example, the changes of "de", "di", "de" in Chinese, and the tense changes in English, etc. In this case, if the entries are processed according to the input form, the number of entries will be greatly increased, which will affect the algorithm efficiency. Therefore, there are usually only entries in a single form in the dictionary; and when attempting to perform word form processing during the word segmentation process, in some cases of word form change rules and word segmentation rule priorities, the time complexity of word segmentation exceeds the linear level, which will also lead to a decrease in algorithm efficiency. Summary of the Invention
[0003] To solve the above technical problems, the embodiments of this application provide a word segmentation method, device, electronic device, and storage medium based on dictionary matching.
[0004] In a first aspect, the embodiments of this application provide a word segmentation method based on dictionary matching. The method includes:
[0005] Perform word-level splitting on the text to be segmented to obtain multiple split entries, and store each of the split entries in the corresponding node of the search linked list;
[0006] Search for candidate variant words that match the split entries in each node from the prefix dictionary tree;
[0007] Determine whether there is a first target node in each node of the search linked list. The first target node is a node with a non-zero number of candidate variant words;
[0008] If there is the first target node, arrange the candidate variant words corresponding to the first target node into a substring, and store the substring in the first target node;
[0009] Determine the first target word segmentation of the first target node from the substring stored in the first target node according to the priority index;
[0010] Generate a word segmentation result according to the first target word segmentation.
[0011] In one embodiment, the method further comprises:
[0012] Determine whether there is a second target node in each of the nodes in the search linked list, where the second target node is a node with 0 candidate inflected words;
[0013] If the second target node exists, mark the second target node as dead;
[0014] Mark the first target node as alive.
[0015] In one implementation, the step of acquiring the prefix dictionary tree includes:
[0016] Perform word-level splitting on the dictionary text to obtain multiple entries;
[0017] A prefix dictionary tree including the multiple entries is constructed with characters as nodes.
[0018] In one embodiment, before the step of storing each of the split terms in a corresponding node of the search linked list, the method further comprises:
[0019] Determine whether the head pointer of the search linked list is empty;
[0020] If the head pointer of the search linked list is empty, obtaining the head of the search linked list;
[0021] The step of storing each of the split terms in a corresponding node of the search linked list comprises:
[0022] Starting from the table header, each of the split terms is stored in turn in each node of the search linked list.
[0023] In one embodiment, the method further comprises:
[0024] If the head pointer of the search linked list is not empty, the historical data of the search linked list is deleted.
[0025] In one embodiment, the step of searching the prefix dictionary tree for candidate inflected words that match the split terms in each of the nodes includes:
[0026] The candidate inflected words matching the split terms in each of the nodes are searched from the root node of the prefix dictionary tree.
[0027] In one implementation, each of the nodes includes a state pointer bit, a first state identification bit, a second state identification bit, and a third state identification bit; and the method further includes:
[0028] The state pointer is stored in the state pointer position, and the state pointer is used to point to the root node corresponding to the candidate inflected word of each node;
[0029] storing the last complete vocabulary of each of the nodes in the first state flag;
[0030] Storing the vocabulary deformation sequence parameter of each of the nodes in the second state flag bit;
[0031] The third state flag stores the alive state or dead state of each node.
[0032] In a second aspect, an embodiment of the present application provides a word segmentation device based on dictionary matching, and the word segmentation device based on dictionary matching includes:
[0033] A splitting module is used to split the text to be segmented at the word level to obtain multiple split terms, and store each of the split terms in a corresponding node of the search linked list;
[0034] A search module, used for searching candidate inflected words matching the split terms in each of the nodes from the prefix dictionary tree;
[0035] A determination module, configured to determine whether there is a first target node among the nodes in the search linked list, wherein the first target node is a node whose number of candidate inflected words is not 0;
[0036] a processing module, configured to, if the first target node exists, arrange the candidate inflected words corresponding to the first target node into substrings, and store the substrings into the first target node;
[0037] A determination module, configured to determine a first target word of the first target node from the substring stored in the first target node according to a priority index;
[0038] A generation module is used to generate a segmentation result according to the first target segmentation.
[0039] In a third aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory is used to store a computer program, and when the computer program is run by the processor, the word segmentation method based on dictionary matching provided in the first aspect is executed.
[0040] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when running on a processor, executes the word segmentation method based on dictionary matching provided in the first aspect.
[0041] The word segmentation method, device, electronic device and storage medium based on dictionary matching provided by the present application above perform word-level splitting on the text to be segmented to obtain multiple split terms, and store each of the split terms in the corresponding node of the search list; search for candidate inflected words matching the split terms in each node from the prefix dictionary tree; determine whether there is a first target node in each of the nodes in the search list, the first target node is a node with a non-zero number of candidate inflected words; if the first target node exists, arrange the candidate inflected words corresponding to the first target node into a substring, and store the substring in the first target node; determine the first target word segmentation of the first target node from the substring stored in the first target node according to the priority index; generate the word segmentation result according to the first target word segmentation. In this way, by combining the two data structures of the search list and TrieTree, all possibilities of word form restoration and word form change are found, and the word segmentation result is obtained according to the priority index. Under the condition of ensuring the complete search and correct results, the time and space complexity required by the word segmentation algorithm is reduced to achieve the purpose of offline deployment on devices with poor hardware resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present application and should not be regarded as limiting the scope of protection of the present application. In each of the drawings, similar components are numbered similarly.
[0043] Figure 1 A schematic diagram of a process of a word segmentation method based on dictionary matching provided in an embodiment of the present application is shown;
[0044] Figure 2 Another schematic diagram of the process of the word segmentation method based on dictionary matching provided in an embodiment of the present application is shown;
[0045] Figure 3 A structural schematic diagram of a word segmentation device based on dictionary matching provided in an embodiment of the present application is shown.
[0046] Icons: 300 - word segmentation device based on dictionary matching; 301 - splitting module; 302 - search module; 303 - judgment module; 304 - processing module; 305 - determination module; 306 - generation module. DETAILED DESCRIPTION
[0047] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0048] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0049] Hereinafter, the terms "including", "having" and their cognates, which may be used in various embodiments of the present application, are intended only to indicate specific features, numbers, steps, operations, elements, components, or combinations of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components, or combinations of the foregoing items or adding the possibility of one or more features, numbers, steps, operations, elements, components, or combinations of the foregoing items.
[0050] Furthermore, the terms “first”, “second”, “third”, etc. are merely used for distinguishing descriptions and are not to be understood as indicating or implying relative importance.
[0051] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by ordinary technicians in the field to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.
[0052] Example 1
[0053] The embodiment of the present disclosure provides a word segmentation method based on dictionary matching.
[0054] For details, see Figure 1 , word segmentation methods based on dictionary matching include:
[0055] Step S101, splitting the text to be segmented at word level to obtain multiple split terms, and storing each of the split terms in a corresponding node of a search linked list.
[0056] In this embodiment, a linked list is set for each text to be segmented, and the linked list is used to represent the segmentation result of the text to be segmented. Specifically, the linked list can be called a search linked list. The search linked list includes multiple nodes, each node of the search linked list stores a state pointer and 3 state flags, the state pointer points to the tree node corresponding to the prefix dictionary tree (TrieTree), and the 3 state flags are used to store the last complete vocabulary of the linked list node, the vocabulary deformation sequence parameter, and the survival status of the linked list node, wherein the survival status of the linked list node indicates that the node is in a survival state or in a non-survival state. The word segmentation method based on dictionary matching can be divided into two sections, the first section is the search process of inputting the split characters in sequence, and the second section is the selection process of reading the word segmentation results from the search linked list. The core of the search process lies in the processing of the search linked list, and the processing of the search linked list includes the following two aspects: first, checking whether a new node is inserted in the search linked list; second, processing the nodes that have been inserted in the search linked list (i.e., not including all the nodes inserted in this round), and if the search linked list is empty, it is not processed. To ensure that new nodes are not treated as old nodes, the inserted nodes are processed before the insertion of new nodes is detected.
[0057] In one embodiment, before the step of storing each of the split terms in a corresponding node of the search linked list, the word segmentation method based on dictionary matching further includes:
[0058] Determine whether the head pointer of the search linked list is empty;
[0059] If the head pointer of the search linked list is empty, obtaining the head of the search linked list;
[0060] The step of storing each of the split terms in a corresponding node of the search linked list may include:
[0061] Starting from the table header, each of the split terms is stored in turn in each node of the search linked list.
[0062] In this embodiment, each of the nodes includes a state pointer bit, a first state identification bit, a second state identification bit, and a third state identification bit; the word segmentation method based on dictionary matching also includes:
[0063] The state pointer is stored in the state pointer position, and the state pointer is used to point to the root node corresponding to the candidate inflected word of each node;
[0064] storing the last complete vocabulary of each of the nodes in the first state flag;
[0065] Storing the vocabulary deformation sequence parameter of each of the nodes in the second state flag bit;
[0066] The third state flag stores the alive state or dead state of each node.
[0067] Step S102: searching the prefix dictionary tree for candidate inflected words that match the split terms in each of the nodes.
[0068] In this embodiment, in the process of checking and inserting, all possible word forms of the currently input split word entry are searched at the root node of the prefix dictionary tree (TrieTree).
[0069] In one implementation, step S102 may include:
[0070] The candidate inflected words matching the split terms in each of the nodes are searched from the root node of the prefix dictionary tree.
[0071] In one embodiment, the word segmentation method based on dictionary matching further includes:
[0072] If the head pointer of the search linked list is not empty, the historical data of the search linked list is deleted.
[0073] In one implementation, the step of acquiring the prefix dictionary tree includes:
[0074] Perform word-level splitting on the dictionary text to obtain multiple entries;
[0075] A prefix dictionary tree including the multiple entries is constructed with characters as nodes.
[0076] Step S103, determining whether there is a first target node among the nodes in the search linked list, wherein the first target node is a node whose number of candidate inflected words is not zero.
[0077] Step S104: if the first target node exists, the candidate inflected words corresponding to the first target node are arranged into substrings, and the substrings are stored in the first target node.
[0078] In one implementation, if the first target node exists, the first target node is marked as alive.
[0079] Step S105 , determining a first target word segment of the first target node from the substring stored in the first target node according to a priority indicator.
[0080] In this embodiment, multiple candidate inflected words of the first target node are arranged in sequence according to the priority index to form a substring, and stored in the first target node corresponding to the search list. Specifically, the priority index can be a preset priority, for example, multiple candidate inflected words are arranged in sequence according to the preset priority to obtain a substring, and the substring is stored in the first target node corresponding to the search list. In the processing flow of the inserted node, the entire search list is traversed, and for all surviving nodes (i.e., the first target node), the split terms and candidate inflected words of each node are retrieved according to the priority index, and the subsequent word form changes are arranged in sequence to form a substring and its status is updated, and the substring is stored in the corresponding first target node.
[0081] For example, for words ending with -es, the restoration priority order is: -, -s, -es. When the input word is does, three child nodes will be added to the end of the linked list, and the words in the initial state are does, doe (meaning female deer), and do, respectively. The three child nodes constitute one node; when the input word is cafes, only two child nodes will be added, because caf, which is a variation of -es, is not in the dictionary, and the two child nodes constitute one node.
[0082] It should be noted that each time a character input is processed, all surviving nodes in the linked list will process the character. For nodes with subsequent matches, a linked list substring will be generated to replace the split terms stored in the node. Here, a single node is also regarded as a special substring, and a single node can be composed of multiple subnodes. Nodes that have no subsequent matches are marked as non-surviving and no other modifications are made to them.
[0083] The following is an example of a surviving node. For example, if the input text sequence fragment is "China clay has...", its prototype is that when China is processed, two nodes with current matching sequences "china" and "China" will appear in the search list. There is only the word "china clay" in the vocabulary, but no capitalized first letter of the phrase, and clay cannot form a longer word with "China" through word form transformation, that is, in the prefix dictionary tree (TrieTree), the "China" node does not have a subsequent root node of the word "clay". When clay is processed, the node with the matching sequence "China" is "no subsequent node", and the node with no subsequent node is set as a dead node, while the other node "china" has a subsequent node, and the node with a subsequent node is set as a surviving node.
[0084] The purpose of setting nodes as non - surviving nodes is to avoid incorrect matching and invalid searches without affecting the matching order. For example, in the text "initial dynamic parameters", for the word "initialization", the first, second, and fifth characters will not be combined into the word "initialization" because when processing the character "d", the node that matches the word "initialization" has been set as non - surviving.
[0085] Taking A, B, C, and D to represent four English words as an example: If the previous input is the English word A, all the current words of the currently surviving nodes must end with - A or a variant of A. If the current input is the English word B, and B can be lemmatized to C and D, with the lemmatization priority from high to low as D -> B -> C, then there are roughly the following situations: (1). The - A node is in a non - surviving state and is not processed; (2). If there are words AC - and AD - in the lexicon, then before processing, a part of the linked list is like... -> - A ->...; generate sub - chains - AD -> - AC; after processing, it is like... -> - AD -> - AC ->...; after processing, update the complete word deformation sequence, and the pointers in the nodes respectively point to the tree nodes representing the last inserted character in the TrieTree. (3). When there are no AB -, AC -, or AD - in the lexicon, before processing, it is like... -> - A ->...; no sub - chains are generated, the linked list structure is not changed, and the current node is set as non - surviving.
[0086] It should be noted that the words already matched by each node will not change. For example, if the already matched word is China, and the actual input is China clay, the lexical prototype china clay will not change the first letter "C" to lowercase, and the matching sequence for the lowercase - first - letter "china" will be stored in other nodes in the form of the lemmatized morphology.
[0087] For a text to be split, the splitting process is carried out until the last word of the text to be split is reached, and the reaching - end word is updated to the last word of the text to be split. For example, if the already matched text sequence is "初" (beginning), and there are words "初始" (initial) and "初始化" (initialization) in the dictionary, but no word for just "初", the reaching - end word is empty; when the new character "始" (start) enters, the matching sequence is updated to "初始", and since there is the word "初始" in the dictionary, the reaching - end word is updated to "初始". When the character "化" (change) enters, similarly, the matching sequence and the reaching - end word are updated to "初始化".
[0088] In one embodiment, the word - segmentation method based on dictionary matching further includes:
[0089] Determine whether there is a second target node among the nodes of the search linked list, where the second target node is a node with 0 candidate variant words;
[0090] If the second target node exists, mark the second target node as dead;
[0091] Mark the first target node as alive.
[0092] Step S106: Generate a word segmentation result according to the first target word segmentation.
[0093] It should be noted that different word segmentation rules may conflict. For example, A, B, C, and D represent four English words. In the word library, there are words ADC, ABA, AB, A, B, C, and D. If there is a rule that can restore the word form of B to D and the restoration priority is BD, when the input text is ABABC, different preset rules will be used to obtain different results. The following are some examples:
[0094] In the first case, the pre-set rule is maximum forward matching, matching length priority / word form level priority, and the result is: ABA->B->C, because the maximum forward matching result is obtained when matching ABA, and then the matching results are obtained in sequence.
[0095] In the second case, the pre-set rule is maximum bidirectional matching, with matching length first and word form level second, and the result is: AB->ADC, because the maximum bidirectional result is obtained when matching AB-ADC, and the matching length is the largest.
[0096] In the third case, the preset rule is maximum bidirectional matching, with word form level taking priority and matching length taking second place. The word segmentation result is: AB->AB->C, because the maximum bidirectional result is obtained when matching AB-AB-C, with the highest word form priority and the largest matching length.
[0097] For example, suppose there are words such as "China", "china clay", "china", "clay", "has" in the vocabulary, and there is a morphological restoration rule of converting the first letter of the word to lowercase. A single word will not be repeatedly divided into multiple phrases, and the priority of the change without restoration is higher than the uppercase to lowercase conversion. When the input text is "China clay has...", the resulting chain means:
[0098] Head->"China"->"china clay"->"clay"->"has"->...
[0099] Since the nodes "China" and "china clay" have the same starting position, they are compared together. When applying the priority of word form changes, "China" has a higher priority than "china clay", that is, "China" is a word that complies with the rules, while "china clay" does not comply with the rules because "China" has been divided. Similarly, when applying the rule with the longest matching length first, "china clay" is regarded as a word that complies with the rules, and the "China" and "clay" nodes are ignored.
[0100] See also Figure 2 ,like Figure 2 As shown, the word segmentation method based on dictionary matching may include the following steps:
[0101] Step S201, start word segmentation.
[0102] In this embodiment, the text to be split can be segmented.
[0103] Step S202: input text to be segmented.
[0104] Step S203: text preprocessing.
[0105] Specifically, the text to be segmented is subjected to text preprocessing to obtain word-level entries.
[0106] Step S204, determine whether the head pointer of the search linked list is empty.
[0107] In this embodiment, if yes, step S105 is executed, and if no, step S206 is executed.
[0108] Step S205, establish a new search linked list, and obtain the header of the new search linked list.
[0109] Step S206, clean up historical data and delete the linked list.
[0110] Step S207, split the text.
[0111] Step S208, input the split character / word level text in sequence.
[0112] Step S209: the existing node processing status is updated.
[0113] Step S2010, processing the newly added node, if it is the starting character of a vocabulary, then adding a new search list.
[0114] Step S2011, determining whether the input of the text to be split is completed.
[0115] In this embodiment, if yes, execute step S2012, if no, return to execute step S208.
[0116] Step S2012, selecting words that meet the rules in the new search list in turn.
[0117] Step S2013, returning the word segmentation result.
[0118] Step S2014, obtaining dictionary text.
[0119] Step S2015, dictionary text preprocessing.
[0120] Step S2016, construct TrieTree.
[0121] Step S2017, save TrieTree.
[0122] Steps S2013 to S2017 are the initialization part. During initialization, the dictionary text is preprocessed into a single read entry, and the single entry text does not contain any special additional characters. During the splitting process, the text is split into the smallest granularity characters with complete meaning in its language. For example, Chinese is a single word and English is a word. TrieTree is constructed with characters as nodes.
[0123] Step S2018, end word segmentation.
[0124] In this embodiment, a search list is combined with TrieTree to perform text segmentation based on dictionary matching. All possible word form changes and word form restoration in the dictionary are taken into consideration for word segmentation. The priority order of word form restoration rules can be configured, and when there is a conflict with the word segmentation rules, the priority index can be configured to be applied first. In this way, the time and space complexity of the linear level word segmentation algorithm can be achieved.
[0125] In terms of configurable word form restoration and word segmentation rule application priority: in this embodiment, the configured word form restoration and word form change library are used to determine the change rule priority; the rule conflict handling method is determined by the preset rule application priority, so as to enhance the adaptability of the matching word segmentation algorithm to various data and scenarios.
[0126] In terms of the time and space complexity of the linear-level word segmentation algorithm: Since this embodiment uses a matching method combining a linked list and TrieTree, it does not affect the time and space complexity level of the algorithm when trying to change word forms, restore, and resolve rule conflicts.
[0127] The word segmentation method based on dictionary matching provided in this embodiment performs word-level splitting on the text to be segmented to obtain multiple split terms, and stores each of the split terms in the corresponding node of the search list; searches for candidate inflected words matching the split terms in each node from the prefix dictionary tree; determines whether there is a first target node in each of the nodes in the search list, and the first target node is a node whose number of candidate inflected words is not 0; if the first target node exists, the candidate inflected words corresponding to the first target node are arranged into substrings, and the substrings are stored in the first target node; the first target word segmentation of the first target node is determined from the substring stored in the first target node according to the priority index; and the word segmentation result is generated according to the first target word segmentation. In this way, by combining the two data structures of the search list and TrieTree, all possibilities of word form restoration and word form change are found, and the word segmentation result is obtained according to the priority index. Under the condition of ensuring the complete search and correct results, the time and space complexity required by the word segmentation algorithm is reduced to achieve the purpose of offline deployment on devices with poor hardware resources.
[0128] Example 2
[0129] In addition, the embodiment of the present disclosure provides a word segmentation device based on dictionary matching.
[0130] Specifically, Figure 3 As shown, the word segmentation device 300 based on dictionary matching includes:
[0131] The splitting module 301 is used to split the text to be segmented at the word level to obtain multiple split terms, and store each of the split terms in a corresponding node of the search linked list;
[0132] A search module 302 is used to search the prefix dictionary tree for candidate inflected words that match the split terms in each of the nodes;
[0133] A judgment module 303 is used to judge whether there is a first target node among the nodes in the search list, where the first target node is a node whose number of candidate inflected words is not 0;
[0134] The processing module 304 is configured to arrange the candidate inflected words corresponding to the first target node into substrings if the first target node exists, and store the substrings into the first target node;
[0135] A determination module 305, configured to determine a first target word segment of the first target node from the substring stored in the first target node according to a priority index;
[0136] The generating module 306 is used to generate a word segmentation result according to the first target word segmentation.
[0137] In one implementation, the determination module 303 is further configured to determine whether there is a second target node in each of the nodes in the search list, where the second target node is a node with 0 candidate inflected words.
[0138] If the second target node exists, mark the second target node as dead;
[0139] Mark the first target node as alive.
[0140] In one embodiment, the word segmentation device 300 based on dictionary matching further includes:
[0141] An acquisition module is used to perform word-level splitting processing on the dictionary text to obtain multiple entries;
[0142] A prefix dictionary tree including the multiple entries is constructed with characters as nodes.
[0143] In one implementation, the determination module 303 is further configured to determine whether the head pointer of the search linked list is empty;
[0144] If the head pointer of the search linked list is empty, obtaining the head of the search linked list;
[0145] The splitting module 301 is also used to store each of the split terms in each node of the search linked list in sequence starting from the table header.
[0146] In one implementation, the judgment module 303 is further configured to delete the historical data of the search list if the head pointer of the search list is not empty.
[0147] In one embodiment, the search module 302 is further configured to search, from the root node of the prefix dictionary tree, candidate inflected words that match the split terms in each of the nodes.
[0148] In one implementation, each of the nodes includes a state pointer bit, a first state identification bit, a second state identification bit, and a third state identification bit; the word segmentation device 300 based on dictionary matching also includes:
[0149] A storage module, used for storing a state pointer in the state pointer position, wherein the state pointer is used for pointing to a root node corresponding to the candidate inflected word of each node;
[0150] storing the last complete vocabulary of each of the nodes in the first state flag;
[0151] Storing the vocabulary deformation sequence parameter of each of the nodes in the second state flag bit;
[0152] The third state flag stores the alive state or dead state of each node.
[0153] The word segmentation device based on dictionary matching provided in this embodiment performs word-level splitting on the text to be segmented to obtain multiple split terms, and stores each of the split terms in the corresponding node of the search list; searches for candidate inflected words matching the split terms in each node from the prefix dictionary tree; determines whether there is a first target node in each of the nodes in the search list, and the first target node is a node whose number of candidate inflected words is not 0; if the first target node exists, the candidate inflected words corresponding to the first target node are arranged into substrings, and the substrings are stored in the first target node; the first target word segmentation of the first target node is determined from the substring stored in the first target node according to the priority index; and the word segmentation result is generated according to the first target word segmentation. In this way, by combining the two data structures of the search list and the TrieTree, all possibilities of word form restoration and word form change are found, and the word segmentation result is obtained according to the priority index. Under the condition of ensuring the complete search and correct results, the time and space complexity required by the word segmentation algorithm is reduced to achieve the purpose of offline deployment on devices with poor hardware resources.
[0154] Example 3
[0155] In addition, an embodiment of the present disclosure provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program runs on the processor, the word segmentation method based on dictionary matching provided in Embodiment 1 is executed.
[0156] The electronic device provided in this embodiment can implement the word segmentation method based on dictionary matching provided in Embodiment 1, and will not be described again here to avoid repetition.
[0157] Example 4
[0158] The present application also provides a computer-readable storage medium storing a computer program, which executes the word segmentation method based on dictionary matching provided in Example 1 when running on a processor.
[0159] In this embodiment, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0160] The computer-readable storage medium provided in this embodiment can implement the word segmentation method based on dictionary matching provided in Example 1, and will not be described again here to avoid repetition.
[0161] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or terminal including the element.
[0162] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0163] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A word segmentation method based on dictionary matching, characterized in that: The method comprises: Perform word-level splitting on the text to be segmented to obtain multiple split terms, and store each of the split terms in a corresponding node of the search linked list; Searching for candidate inflected words matching the split terms in each of the nodes from the prefix dictionary tree; Determining whether there is a first target node among the nodes in the search linked list, the first target node being a node whose number of candidate inflected words is not 0; If the first target node exists, arranging the plurality of candidate inflected words corresponding to the first target node into substrings in sequence according to the priority index, and storing the substrings into the first target node corresponding to the search linked list; Determining a first target word of the first target node from the substring stored in the first target node according to the priority index; Generate a segmentation result according to the first target segmentation; Determine whether there is a second target node in each of the nodes in the search linked list, where the second target node is a node with 0 candidate inflected words; If the second target node exists, mark the second target node as dead; Mark the first target node as alive.
2. The method according to claim 1, characterized in that The step of obtaining the prefix dictionary tree includes: Perform word-level splitting on the dictionary text to obtain multiple entries; A prefix dictionary tree including the multiple entries is constructed with characters as nodes.
3. The method according to claim 1, characterized in that Before the step of storing each of the split terms in a corresponding node of the search linked list, the method further comprises: Determine whether the head pointer of the search linked list is empty; If the head pointer of the search linked list is empty, obtaining the head of the search linked list; The step of storing each of the split terms in a corresponding node of the search linked list comprises: Starting from the table header, each of the split terms is stored in turn in each node of the search linked list.
4. The method according to claim 1, characterized in that: The method further comprises: If the head pointer of the search linked list is not empty, the historical data of the search linked list is deleted.
5. The method according to claim 1, characterized in that The step of searching the prefix dictionary tree for candidate inflected words that match the split terms in each of the nodes comprises: The candidate inflected words matching the split terms in each of the nodes are searched from the root node of the prefix dictionary tree.
6. The method according to claim 5, characterized in that Each of the nodes includes a state pointer bit, a first state identification bit, a second state identification bit and a third state identification bit; the method further includes: The state pointer is stored in the state pointer position, and the state pointer is used to point to the root node corresponding to the candidate inflected word of each node; storing the last complete vocabulary of each of the nodes in the first state flag; Storing the vocabulary deformation sequence parameter of each of the nodes in the second state flag bit; The third state flag stores the alive state or dead state of each node.
7. A word segmentation device based on dictionary matching, characterized in that: The device comprises: A splitting module is used to split the text to be segmented at the word level to obtain multiple split terms, and store each of the split terms in a corresponding node of the search linked list; A search module, used for searching candidate inflected words matching the split terms in each of the nodes from the prefix dictionary tree; A determination module, configured to determine whether there is a first target node among the nodes in the search linked list, wherein the first target node is a node whose number of candidate inflected words is not 0; a processing module, configured to, if the first target node exists, sequentially arrange the plurality of candidate inflected words corresponding to the first target node into substrings according to priority indicators, and store the substrings into the first target node corresponding to the search linked list; A determination module, configured to determine a first target word of the first target node from the substring stored in the first target node according to a priority index; A generating module, used for generating a segmentation result according to the first target segmentation; The judgment module is further used to judge whether there is a second target node in each of the nodes in the search linked list, and the second target node is a node with 0 candidate inflected words; If the second target node exists, mark the second target node as dead; Mark the first target node as alive.
8. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is run on the processor, the word segmentation method based on dictionary matching according to any one of claims 1 to 6 is executed.
9. A computer-readable storage medium, characterized in that: The computer program stores a computer program, which executes the word segmentation method based on dictionary matching according to any one of claims 1 to 6 when running on a processor.
Citation Information
Patent Citations
Word segmentation method and device
CN109918664A
Dictionary tree-based search processing method,device and equipment,and storage medium
CN110851722A
Intelligent word segmentation method
CN111160014A
Technique for automatically splitting words
US20190266239A1
Error correction method and apparatus, and computer readable medium
US20200272668A1
