AC automatic machine construction method and device and keyword matching method and device

By introducing the meta-information features of associated keywords in the AC automata, the problem of the inability to recognize associated keyword matching in the prior art is solved, and efficient matching and position recognition of associated keyword groups are achieved.

CN119322833APending Publication Date: 2025-01-17ASPIRE INFORMATION TECH BEIJING
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411434983.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-14
Publication Date
2025-01-17

AI Technical Summary

Technical Problem

Existing AC automatons cannot effectively identify associated keyword matches, and cannot find multiple keywords with associated relationships at the same time in the main text.

Method used

When building AC automata, the associated keywords are used as the lexicon, and the keyword meta-information characteristics are introduced, the keyword meta-information is written into the meta-information set of child nodes of the Trie tree to establish the association relationship between keywords. Therefore, the associated keyword groups can be identified when matching.

Benefits of technology

It realizes efficient matching of independent keywords and associated keywords, and can accurately identify the associated keyword groups and their location information contained in the text.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119322833A_ABST
    Figure CN119322833A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data search, and provides an AC automatic machine construction method and a keyword matching method and device.The construction method comprises the steps that at least one associated keyword library is obtained; traversing the associated keyword word bank, and taking out a group of associated keyword groups from the associated keyword word bank in each traversing; according to a preset separator, keyword extraction is carried out on the currently extracted current associated keyword group, meta-information corresponding to each keyword is generated, the meta-information at least comprises identification information, and the identification information is used for identifying the associated keyword group to which the keyword belongs; and constructing child nodes of the Trie tree according to the keywords, and recording meta-information corresponding to the keywords into a meta-information set of the corresponding child nodes after the child nodes are constructed. According to the method, the independent keywords can be matched, and the associated keyword groups can be matched based on the meta-information set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data search technology, and in particular to an AC automaton construction method, a keyword matching method and a device. Background Art

[0002] AC automaton, short for Aho-Corasick automaton, is an efficient string search algorithm. This algorithm is mainly used to solve the problem of finding multiple keywords in a main text string, and it can efficiently complete the search in linear time.

[0003] Currently, AC automata can be well implemented in independent keyword matching, that is, it can check whether a given main text contains any keyword in the keyword library. For example, when searching for a specific main text, it is hoped that the main text contains any of the two keywords "artificial intelligence" or "machine learning". It is particularly suitable for scenarios where only a specific single keyword needs to be identified in the text.

[0004] However, when encountering a scenario of associated keyword matching and recognition, since the associated keyword matching requires that the main text must contain all the specified keywords at the same time, there is a certain correlation between these keywords. For example, when searching for a specific main text, it is hoped that the main text contains both the keywords "artificial intelligence" and "machine learning" at the same time for the match to be successful. However, the current AC automatic machine cannot match and recognize associated keywords. Summary of the invention

[0005] Based on this, an object of the present invention is to provide an AC automaton construction method, a keyword matching method and a device to solve at least one technical problem in the background technology.

[0006] According to an embodiment of the present invention, a method for constructing an AC automaton comprises the following steps:

[0007] Obtain at least one associated keyword thesaurus, wherein each line of character string in the associated keyword thesaurus represents an associated keyword group, the keywords in the associated keyword group have an associated relationship, and the keywords are separated by a preset separator;

[0008] Traversing the associated keyword thesaurus, and taking out a new group of associated keyword groups from the associated keyword thesaurus each time;

[0009] Perform keyword extraction on the currently retrieved current associated keyword group according to the preset separator to extract each keyword in the current associated keyword group, and generate meta information corresponding to each keyword, wherein the meta information at least includes identification information, and the identification information is used to identify the associated keyword group to which the keyword belongs;

[0010] The child nodes of the Trie tree are constructed according to the keywords, and after the child nodes are constructed, the meta information corresponding to the keywords is recorded into the meta information set of the corresponding child nodes, so as to construct the Trie tree of the AC automaton.

[0011] In addition, the AC automaton construction method according to the above embodiment of the present invention may also have the following additional technical features:

[0012] Furthermore, the step of constructing a child node of the Trie tree according to the keyword includes:

[0013] Traversing the keyword to extract each character in the keyword in sequence;

[0014] Determine whether the current node of the Trie tree has a pointer to the target child node that matches the current character currently extracted. Initially, the construction starts from the root node of the Trie tree.

[0015] If yes, move to the target child node, and return to execute the step of traversing the keyword to extract each character in the keyword in sequence;

[0016] If not, create a child node, store the current character in the created child node, add a pointer to the new child node, move to the new child node, and return to execute the step of traversing the keyword to extract each character in the keyword in sequence.

[0017] Furthermore, after the sub-node is constructed, the step of recording the meta-information corresponding to the keyword into the meta-information set of the corresponding sub-node includes:

[0018] Marking the child node storing the last character of the keyword as a keyword child node;

[0019] The keyword is written into the keyword sub-node, and the meta information corresponding to the keyword is recorded into the meta information set of the keyword sub-node.

[0020] Furthermore, after constructing the Trie tree of the AC automaton, it also includes:

[0021] Based on each child node of the constructed Trie tree, a corresponding failure pointer is added according to the preset rules to construct an AC automaton.

[0022] In addition, an embodiment of the present invention further proposes a keyword matching method, which is implemented based on an AC automaton constructed based on any of the above methods, and includes the following steps:

[0023] Get at least one given text;

[0024] Searching the given text based on the AC automaton to search for matching keywords from the given text;

[0025] The meta information corresponding to the keyword is obtained from the corresponding child node of the Trie tree of the AC automaton, and the associated keyword group is matched from the given text based on the meta information corresponding to the keyword.

[0026] In addition, the AC automaton construction method according to the above embodiment of the present invention may also have the following additional technical features:

[0027] Furthermore, the step of searching the given text based on the AC automaton to search for matching keywords from the given text includes:

[0028] Traversing the given text to extract each character in the given text in sequence;

[0029] Starting from the root node of the Trie tree of the AC automaton, the extracted current character is matched with the characters stored in the child nodes of the Trie tree in sequence;

[0030] Among them, when matching, if the current character extracted matches the character stored in the current child node, then the next character is matched with the character stored in the next child node pointed to by the pointer of the current child node; if the current character extracted does not match the character stored in the current child node, then jump to another child node through the failure pointer of the current child node to continue matching;

[0031] In addition, if the characters are matched successfully, it is determined whether the current child node that is matched successfully has a keyword written therein. If a keyword is written therein, the keyword written therein is used as a keyword matched from the given text.

[0032] Furthermore, the step of obtaining meta information corresponding to the keyword from the corresponding child node of the Trie tree of the AC automaton, and matching the associated keyword group from the given text based on the meta information corresponding to the keyword includes:

[0033] Obtaining a meta information set from the child nodes corresponding to each of the keywords;

[0034] Traversing each of the obtained meta information sets, allocating a group counter to the associated keyword group to which each meta information in the meta information set belongs, specifically allocating a group counter once for the same meta information, and when the group counter is initially allocated, its count value is the number of keywords in the corresponding associated keyword group, and when different keywords in the associated keyword group appear, the count value of the corresponding group counter is reduced by 1;

[0035] After the allocation is completed, it is determined whether the count value of the group counter corresponding to the target associated keyword group is equal to 0;

[0036] If not, the target associated keyword group is used as the associated keyword group matched from the given text.

[0037] Furthermore, after the step of matching the associated keyword group from the given text based on the meta information corresponding to the keyword, the method further includes:

[0038] Outputting the associated keyword groups matched from the given text in a predetermined format;

[0039] The output content includes the associated keyword group and the position information of each associated keyword in the given text.

[0040] According to an embodiment of the present invention, an AC automaton construction device comprises:

[0041] A word library acquisition module, used to acquire at least one related keyword word library, each line of character string in the related keyword word library represents a related keyword group, the keywords in the related keyword group have a related relationship, and the keywords are separated by a preset separator;

[0042] A word library traversal module, used for traversing the associated keyword word library, and taking out a new group of associated keyword groups from the associated keyword word library each time traversal;

[0043] An information generation module, used for performing keyword extraction on the currently taken out current associated keyword group according to the preset delimiter to extract each keyword in the current associated keyword group, and generating meta information corresponding to each keyword, wherein the meta information at least includes identification information, and the identification information is used to identify the associated keyword group to which the keyword belongs;

[0044] The Trie tree construction module is used to construct the child nodes of the Trie tree according to the keywords, and after the child nodes are constructed, the meta information corresponding to the keywords is recorded into the meta information set of the corresponding child nodes to construct the Trie tree of the AC automaton.

[0045] A keyword matching device according to an embodiment of the present invention is implemented based on an AC automaton constructed based on any one of the above methods, and the device includes:

[0046] A text acquisition module, used for acquiring at least one given text;

[0047] A keyword search module, used for searching the given text based on the AC automaton to search for matching keywords from the given text;

[0048] The association matching module is used to obtain the meta information corresponding to the keyword from the corresponding child node of the Trie tree of the AC automaton, and match the associated keyword group from the given text based on the meta information corresponding to the keyword.

[0049] Compared with the prior art: when constructing an AC automaton, associated keywords are used as the vocabulary, and keyword meta-information features are introduced, and the keyword meta-information is written into the meta-information set of the corresponding child nodes of the constructed Trie tree, wherein the keyword meta-information is used to identify the associated keyword group to which the keyword belongs, thereby establishing an association relationship between keywords. When performing keyword matching, not only independent keywords can be matched, but also associated keyword groups can be matched based on the meta-information set. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 is a flow chart of the AC automaton construction method in the first embodiment of the present invention;

[0051] Figure 2 This is a diagram showing an example of constructing an AC automaton provided in an embodiment of the present invention;

[0052] Figure 3 is a flowchart of a keyword matching method in a third embodiment of the present invention;

[0053] Figure 4 It is a schematic structural diagram of an AC automatic machine construction device in a fourth embodiment of the present invention;

[0054] Figure 5 Schematic diagram of the structure of a keyword matching device in the fifth embodiment of the present invention.

[0055] The following specific implementations will further illustrate the present invention in conjunction with the above-mentioned drawings. DETAILED DESCRIPTION

[0056] In order to facilitate the understanding of the present invention, the present invention will be described more fully below with reference to the relevant drawings. Several embodiments of the present invention are given in the drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the disclosure of the present invention more thorough and comprehensive.

[0057] It should be noted that when an element is referred to as being "fixed to" another element, it may be directly on the other element or there may be a central element. When an element is considered to be "connected to" another element, it may be directly connected to the other element or there may be a central element at the same time. The terms "vertical", "horizontal", "left", "right" and similar expressions used herein are for illustrative purposes only.

[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used herein in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more related listed items.

[0059] AC automaton, short for Aho-Corasick automaton, is an efficient string search algorithm. This algorithm is mainly used to solve the problem of finding multiple keywords in a main text string. It can efficiently complete the search in linear time. The core features of AC automaton are as follows:

[0060] Basic structure: AC automaton is based on Trie tree, which is also called dictionary tree or prefix tree. Trie tree is an efficient data structure for quickly retrieving specific keywords in string data sets. By building multiple keywords into a Trie tree with state transfer function, AC automaton can match all independent keywords at the same time.

[0061] Failure pointer: Based on the Trie tree, the AC automaton adds failure pointers. These pointers can efficiently transfer to the next possible state when the match fails, thus avoiding repeated matching work. Specifically, when the current character cannot be matched at a certain node, the algorithm will backtrack along the failure pointer until a node that can match the current character is found, or backtrack to the root node.

[0062] Efficient matching: Since the AC automaton combines the advantages of the Trie tree and the failure pointer, it can match multiple independent keywords simultaneously during a single traversal of the main text, greatly improving the search efficiency.

[0063] However, the AC automaton in the prior art does not consider the association between keywords, that is, the existing AC automaton achieves efficient matching of independent keywords, but lacks accurate matching of associated keywords. For example, when searching for a specific main text, it is hoped that the main text contains both the keywords "artificial intelligence" and "machine learning" at the same time to be considered a successful match, but the existing AC automaton cannot achieve this.

[0064] To this end, an embodiment of the present invention provides an AC automaton construction method, by using associated keywords as a vocabulary when constructing the AC automaton, introducing keyword meta-information features, and writing keyword meta-information into the meta-information set of the corresponding child node of the constructed Trie tree, wherein the keyword meta-information is used to identify the associated keyword group to which the keyword belongs, thereby establishing an association relationship between keywords. When performing keyword matching, not only independent keywords can be matched, but also associated keyword groups can be matched based on the meta-information set. In addition, for the AC automaton constructed by the embodiment of the present invention, the embodiment of the present invention also proposes a new keyword matching method that matches the AC automaton, so that the matching of independent keywords and associated keywords can be more efficient and accurate.

[0065] In order to more clearly illustrate an AC automaton construction method and a keyword matching method in an embodiment of the present invention, specific embodiments are given below.

[0066] Embodiment 1

[0067] See also Figure 1 , shown is the AC automaton construction method in the first embodiment of the present invention, which can be specifically implemented by software and / or hardware. The method specifically includes steps S01 to S04.

[0068] Step S01, obtaining at least one associated keyword thesaurus, wherein each line of character string in the associated keyword thesaurus represents an associated keyword group, the keywords in the associated keyword group have an associated relationship, and the keywords are separated by a preset separator.

[0069] Specifically, the associated keyword thesaurus can be pre-constructed, and one or more groups of associated keyword groups can be entered into the thesaurus in the form of lines, so that different associated keyword groups can be extracted line by line from the thesaurus later. Each group of associated keyword groups is composed of multiple keywords with an associated relationship, and the keywords are separated by a preset separator, so that each keyword can be extracted separately from the associated keyword group. In specific implementation, the preset separator can be, but is not limited to, a comma, a semicolon, a period, or special symbols such as @ and &, the main purpose of which is to distinguish different keywords in the same line.

[0070] Step S02, traversing the associated keyword thesaurus, and taking out a new group of associated keyword groups from the associated keyword thesaurus each time traversing.

[0071] It should be understood that since the associated keyword groups in the associated keyword word library are stored in separate lines, for example Figure 2In the example shown, [hers, she], [he, his] and [his, she] are three groups of related keyword groups, and these three groups of related keyword groups are respectively recorded in the first row, the second row and the third row of the related keyword vocabulary. Therefore, by traversing the related keyword vocabulary row by row, each related keyword group can be taken out one by one.

[0072] Step S03, performing keyword extraction on the currently retrieved current associated keyword group according to the preset separator to extract each keyword in the current associated keyword group, and generating meta information corresponding to each keyword, wherein the meta information at least includes identification information, and the identification information is used to identify the associated keyword group to which the keyword belongs.

[0073] Similarly, since the keywords in the associated keyword group are separated by preset delimiters, for example Figure 2 The associated keyword group [hers, she], where the keywords hers and she are separated by the separator "," can be used to distinguish each keyword, so that the keywords in the associated keyword group can be taken out one by one.

[0074] In addition, after extracting the keywords, it is necessary to assign unique corresponding meta information to each keyword, wherein the meta information at least includes identification information, which is the group ID to which the keyword belongs. The identification information is used to identify the associated keyword group to which the keyword belongs. For example, assuming that the associated keyword group [hers, she] is phrase 1, the identification information in the meta information assigned to the keyword hers can be, but is not limited to, phrase 1, 1, or other codes of phrase 1, thereby identifying that the keyword hers belongs to the associated keyword group [hers, she].

[0075] Furthermore, in some preferred embodiments, the associated keyword group may also include information such as group size and keyword position in the group, wherein the group size is used to identify the number of keywords in the associated keyword group, and the keyword position in the group is used to identify the specific position of the keyword in the associated keyword group, for example, the keyword hers is ranked first in the associated keyword group [hers, she], and its position in the group is 1. For example, the meta information of the keyword hers may be [Group Id: 1; Group size: 2; Position in the group: 1].

[0076] It should be noted that the main purpose of setting meta information is to establish a connection between keywords and their groups, and then establish an association relationship between keywords. Therefore, any method that can establish a connection between keywords and their groups is acceptable, and is not limited to the meta information method defined in the above embodiment.

[0077] Step S04, constructing a Trie tree child node according to the keyword, and after the child node is constructed, recording the meta information corresponding to the keyword into the meta information set of the corresponding child node, so as to construct the Trie tree of the AC automaton.

[0078] In a specific implementation, the step of constructing a child node of the Trie tree according to the keyword may specifically include:

[0079] Traversing the keyword to extract each character in the keyword in sequence;

[0080] Determine whether the current node of the Trie tree has a pointer to the target child node that matches the current character currently extracted. Initially, the construction starts from the root node of the Trie tree.

[0081] If yes, move to the target child node, and return to execute the step of traversing the keyword to extract each character in the keyword in sequence;

[0082] If not, create a child node, store the current character in the created child node, add a pointer to the new child node, move to the new child node, and return to execute the step of traversing the keyword to extract each character in the keyword in sequence.

[0083] At the same time, after the sub-node is constructed, the step of recording the meta information corresponding to the keyword into the meta information set of the corresponding sub-node includes:

[0084] Marking the child node storing the last character of the keyword as a keyword child node;

[0085] The keyword is written into the keyword sub-node, and the meta information corresponding to the keyword is recorded into the meta information set of the keyword sub-node.

[0086] like Figure 2 As shown, taking the keyword hers as an example, first extract the characters "h", "e", "r", and "s" in turn, and then start from the root node root of the Trie tree. At this time, the root node root has no pointer, and it is necessary to create child node 1 and store the character "h" in the child node 1. Then create a new child node 2, and add a pointer to child node 2 in child node 1, that is, child node 2 is the child node of child node 1. Then move to child node 2 and store the next character "e" in child node 2. And so on, store the characters "r" and "s" in child nodes 3 and 4 in turn.

[0087] At this time, subnode 4 is the subnode to which the last character is written, so subnode 4 is the keyword subnode of the keyword hers, and the keyword hers and its meta information are written into the meta information set of subnode 4.

[0088] Taking the keyword he as an example, we will first extract the characters "h" and "e" in sequence, and then start from the root node root of the Trie tree. At this time, the root node root has a child node pointing to the character "h", that is, child node 1. At this time, we will move to child node 1. Since the character "h" has been written into child node 1, no storage action will be performed at this time. At the same time, child node 1 also has a child node pointing to the character "e", that is, child node 2, and we will move to child node 2 at this time. Similarly, no writing action will be performed, and child node 2 is the keyword child node of the keyword he. The rest is inferred and will not be repeated. Based on Figure 2 The associated keyword thesaurus in can be constructed as follows Figure 2 The Trie tree shown in .

[0089] also, Figure 2 In the example, the keyword his is associated with the keyword he and the keyword she to form different keyword groups, namely, the associated keyword groups [he,his] and [his,she]. Then, the meta-information set of the keyword child node of the keyword his (child node 5 in the figure) will include two pieces of meta-information, such as Figure 2 shown.

[0090] In summary, the AC automaton construction method in the above-mentioned embodiment of the present invention, when constructing the AC automaton, uses associated keywords as the vocabulary, introduces keyword meta-information features, and writes the keyword meta-information into the meta-information set of the corresponding child node of the constructed Trie tree, wherein the keyword meta-information is used to identify the associated keyword group to which the keyword belongs, thereby establishing an association relationship between the keywords. When performing keyword matching, not only independent keywords can be matched, but also associated keyword groups can be matched based on the meta-information set.

[0091] Embodiment 2

[0092] The second embodiment of the present invention also provides an AC automaton construction method, which can be implemented by software and / or hardware. The AC automaton construction method in this embodiment is different from the AC automaton construction method in the first embodiment in that:

[0093] After constructing the Trie tree of the AC automaton, it also includes:

[0094] Based on each child node of the constructed Trie tree, a corresponding failure pointer is added according to the preset rules to construct an AC automaton.

[0095] It should be noted that, based on the Trie tree constructed in the first embodiment, a failure pointer can also be added to each child node to construct an AC automaton. The role of the failure pointer is to jump from the current child node to a suitable child node in the dictionary tree pointed to by the failure pointer to continue matching when the matching fails, thereby avoiding matching from the beginning and improving matching efficiency.

[0096] In specific implementation, the process of adding failure pointers can be consistent with that of traditional AC automata, that is, the construction of failure pointers usually uses a breadth-first search algorithm (BFS). That is, in specific implementation, the corresponding failure pointers can be added based on each child node of the constructed Trie tree using a breadth-first search algorithm to construct an AC automaton. The specific process of constructing the failure pointer of an AC automaton is as follows:

[0097] Starting from the child nodes of the root node, traverse the dictionary tree layer by layer and set a failure pointer for each node. For the current node N, the node pointed to by its failure pointer should satisfy: the string represented by the path from the root node to this node is the longest suffix of the string represented by the N node. If a child node of the current node does not exist, the pointer of the child node is pointed to the corresponding child node of the node pointed to by the failure pointer of its parent node (if it does not exist, continue to backtrack upward). The specific failure pointers added are as follows Figure 2 Indicated by the dashed arrow.

[0098] It should be noted that the above embodiments and their features can be arbitrarily combined without conflict, and the new technical solutions obtained by the combination still fall within the protection scope of the present invention.

[0099] Embodiment 3

[0100] like Figure 3 As shown, the third embodiment of the present invention provides a keyword matching method, which can be specifically implemented by software and / or hardware. The keyword matching method in this embodiment is implemented based on an AC automaton constructed based on the method described in any of the above embodiments, and the keyword matching method includes steps S11-S13.

[0101] Step S11, obtaining at least one given text.

[0102] Step S12: searching the given text based on the AC automaton to search for matching keywords from the given text.

[0103] In specific implementation, step S12 may specifically include:

[0104] Traversing the given text to extract each character in the given text in sequence;

[0105] Starting from the root node of the Trie tree of the AC automaton, the extracted current character is matched with the characters stored in the child nodes of the Trie tree in sequence;

[0106] Among them, when matching, if the current character extracted matches the character stored in the current child node, then the next character is matched with the character stored in the next child node pointed to by the pointer of the current child node; if the current character extracted does not match the character stored in the current child node, then jump to another child node through the failure pointer of the current child node to continue matching;

[0107] In addition, if the characters are matched successfully, it is determined whether the current child node that is matched successfully has a keyword written therein. If a keyword is written therein, the keyword written therein is used as a keyword matched from the given text.

[0108] Specifically, given a text containing the keyword hers, and using Figure 2 Taking the constructed Trie tree for matching search as an example, when the given text is traversed to the keyword hers, the characters "h", "e", "r", and "s" will be extracted in sequence first, and then starting from the root node of the Trie tree, since the root node has no characters, it will first move to the child node 1 it points to (or move to child node 6 first, but because it does not match the character written in child node 6, it will still jump to child node 1 through the failure pointer) and match the character of child node 1 first. At this time, the match is successful, and it will move to child node 2 pointed to by child node 1, and match the next text character "e" with the character of child node 2. If the match is successful, continue to go down; if the match is unsuccessful, jump to other child nodes through the failure pointer to continue matching, and so on. Finally, the match with the keyword hers of the given text is completed at child node 4. At this time, the keyword written in child node 4 is obtained, and it can be determined that the keyword hers is matched from the text.

[0109] Step S13, obtaining meta information corresponding to the keyword from the corresponding child node of the Trie tree of the AC automaton, and matching the associated keyword group from the given text based on the meta information corresponding to the keyword.

[0110] In some preferred embodiments, step S13 may specifically include:

[0111] Obtaining a meta information set from the child nodes corresponding to each of the keywords;

[0112] Traversing each of the obtained meta information sets to allocate a grouping counter to the associated keyword group to which each meta information in the meta information set belongs;

[0113] Subtract 1 from the count values ​​of the group counters corresponding to all associated keyword groups, and after subtracting 1, determine whether there is a group counter corresponding to the target associated keyword group whose count value is equal to 0;

[0114] If not, the target associated keyword group is used as the associated keyword group matched from the given text.

[0115] That is, when a keyword is identified from a given text, its corresponding associated keyword group will be determined based on the keyword's meta information, and a corresponding group counter will be assigned to the associated keyword group. Specifically, when assigning group counters, the same meta information is assigned a group counter once, that is, the same keyword appears multiple times but is only assigned a group counter once. When different meta information belongs to the same associated keyword group, the corresponding group counter counts accordingly, for example, Figure 2 As shown, when the keyword hers and the keyword she appear in a given text at the same time, because they both belong to the associated keyword group [hers, she], the group counter corresponding to the associated keyword group [hers, she] will be allocated 2 times. If the group counter corresponding to the associated keyword group [hers, she] is group counter 1, the value of group counter 1 is 2;

[0116] Among them, all group counters will be stored in the group counter set. Then the count values ​​of all group counters are reduced by 1. If the count value of a group counter is 0, it means that the keyword in the associated keyword group corresponding to the group counter only appears in one given text, that is, there is no associated keyword. If the count value of a group counter is not 0, it means that there are multiple keywords in the associated keyword group corresponding to the group counter that appear in the given text, indicating that there are associated keywords, and the associated keyword group corresponding to the group counter is the associated keyword group matched from the given text.

[0117] Or as another optional implementation manner, the step of obtaining meta information corresponding to the keyword from the corresponding child node of the Trie tree of the AC automaton, and matching the associated keyword group from the given text based on the meta information corresponding to the keyword includes:

[0118] Obtaining a meta information set from the child nodes corresponding to each of the keywords;

[0119] Traversing each of the obtained meta information sets, allocating a grouping counter to the associated keyword group to which each meta information in the meta information set belongs, specifically allocating a grouping counter once for the same meta information, and the count value of the grouping counter is the number of keywords in the corresponding associated keyword group (i.e., the group size) when the grouping counter is initially allocated, and the count value of the corresponding grouping counter is reduced by 1 when different keywords appear in the associated keyword group;

[0120] After the allocation is completed, it is determined whether the count value of the group counter corresponding to the target associated keyword group is equal to 0;

[0121] If not, the target associated keyword group is used as the associated keyword group matched from the given text.

[0122] That is to say, in this implementation, when a certain keyword appears newly in a given text, the associated keyword group to which the keyword corresponds will be assigned an initialized group counter, and the initial count value of the group counter is equal to the group size of the associated keyword group. For example, if the associated keyword group contains 2 keywords, the group size is 2 and the count value is also 2. At the same time, since a keyword has appeared in it at this time, the count value of the group counter will be reduced by 1. If no other keywords in the associated keyword group are matched thereafter, the count value of the group counter must not be equal to 0. On the contrary, if the other keywords in the associated keyword group are matched thereafter, since the count value is reduced by 1 for each occurrence, after the match, the count value of the group counter is 0, indicating that the associated keyword group has been matched from the given text.

[0123] Furthermore, after the step of matching the associated keyword group from the given text based on the meta information corresponding to the keyword, the method further includes:

[0124] Outputting the associated keyword groups matched from the given text in a predetermined format;

[0125] The output content includes the associated keyword group and the position information of each associated keyword in the given text.

[0126] Specifically, the position information of the associated keyword in the given text may be the character position of the string of the associated keyword. For example, when the given text is "she loves hers new book, and reads it every night beforegoing to bed.", Figure 2The constructed AC automaton and the above-mentioned keyword matching method can output the following result: [0:2=she,10:13=hers], which means that there is an associated keyword group [she,hers] in the given text, where the associated keyword she appears in character positions 0-2 and the associated keyword hers appears in character positions 10-13 (where the space also occupies a character position). This not only tells the user that the associated keyword group has been matched, but also clearly informs the user of the location of the corresponding associated keyword.

[0127] It should be noted that the above embodiments and their features can be arbitrarily combined without conflict, and the new technical solutions obtained by the combination still fall within the protection scope of the present invention.

[0128] Embodiment 4

[0129] Another aspect of the present invention is to provide an AC automatic machine construction device, please refer to Figure 4 , which shows an AC automaton construction device in a fourth embodiment of the present invention, the AC automaton construction device comprises:

[0130] The word library acquisition module 11 is used to acquire at least one related keyword word library, each line of character string in the related keyword word library represents a related keyword group, the keywords in the related keyword group have a related relationship, and the keywords are separated by a preset separator;

[0131] The word library traversal module 12 is used to traverse the associated keyword word library, and each traversal takes out a new group of associated keyword groups from the associated keyword word library;

[0132] The information generating module 13 is used to perform keyword extraction on the currently taken out current associated keyword group according to the preset separator to extract each keyword in the current associated keyword group and generate meta information corresponding to each keyword, wherein the meta information at least includes identification information, and the identification information is used to identify the associated keyword group to which the keyword belongs;

[0133] The Trie tree construction module 14 is used to construct a child node of the Trie tree according to the keyword, and after the child node is constructed, the meta information corresponding to the keyword is recorded into the meta information set of the corresponding child node to construct the Trie tree of the AC automaton.

[0134] Furthermore, in some optional embodiments of the present invention, the Trie tree construction module 14 includes:

[0135] A child node construction unit is used to traverse the keyword to extract each character in the keyword in sequence; determine whether the current node of the Trie tree has a pointer to a target child node that matches the current character currently extracted, and start from the root node of the Trie tree when initially constructed; if yes, move to the target child node, and return to execute the step of traversing the keyword to extract each character in the keyword in sequence; if no, create a child node, store the current character in the created child node, add a pointer to the new child node, then move to the new child node, and return to execute the step of traversing the keyword to extract each character in the keyword in sequence.

[0136] Furthermore, in some optional embodiments of the present invention, the Trie tree construction module 14 further includes:

[0137] The information writing unit is used to mark the subnode storing the last character of the keyword as a keyword subnode; write the keyword into the keyword subnode, and record the meta information corresponding to the keyword into the meta information set of the keyword subnode.

[0138] Furthermore, in some optional embodiments of the present invention, the AC automaton construction device further includes:

[0139] The failure pointer module is used to add corresponding failure pointers according to preset rules based on each child node of the constructed Trie tree to construct an AC automaton.

[0140] The functions or operation steps implemented when the above modules and units are executed are generally the same as those in the above method embodiments, and will not be repeated here.

[0141] Embodiment 5

[0142] Another aspect of the present invention is to provide a keyword matching device. Figure 5 , shown is a keyword matching device in the fifth embodiment of the present invention, the keyword matching device is implemented based on an AC automaton constructed by the method described in any of the above embodiments, and the keyword matching device includes:

[0143] A text acquisition module 21, used for acquiring at least one given text;

[0144] A keyword search module 22, configured to search the given text based on the AC automaton to search for matching keywords from the given text;

[0145] The associated matching module 23 is used to obtain the meta information corresponding to the keyword from the corresponding child node of the Trie tree of the AC automaton, and match the associated keyword group from the given text based on the meta information corresponding to the keyword.

[0146] Furthermore, in some optional embodiments of the present invention, the keyword search module 22 is also used to traverse the given text to extract each character in the given text in sequence; starting from the root node of the Trie tree of the AC automaton, the extracted current character is matched in sequence with the characters stored in the child nodes of the Trie tree; wherein, during matching, if the extracted current character matches the character stored in the current child node, the next character is matched with the character stored in the next child node pointed to by the pointer of the current child node; if the extracted current character does not match the character stored in the current child node, the failure pointer of the current child node is used to jump to another child node to continue matching; in addition, if the character match is successful, it is determined whether the current child node that has been successfully matched has a keyword written in it, and if a keyword is written in it, the keyword written in the current child node is used as a keyword matched from the given text.

[0147] Furthermore, in some optional embodiments of the present invention, the associated matching module 23 is also used to obtain a set of meta-information from the child nodes corresponding to each of the keywords; traverse each of the obtained meta-information sets to allocate a grouping counter to the associated keyword group to which each meta-information in the meta-information set corresponds. When allocating, the same meta-information is allocated a grouping counter once. When the grouping counter is initially allocated, its count value is the number of keywords in the corresponding associated keyword group. When different keywords appear in the associated keyword group, the count value of the corresponding grouping counter is reduced by 1; after the allocation, it is determined whether there is a target associated keyword group whose corresponding grouping counter has a count value equal to 0; if not, the target associated keyword group is used as the associated keyword group matched from the given text.

[0148] Furthermore, in some optional embodiments of the present invention, the keyword matching device further includes:

[0149] The matching output module is used to output the associated keyword group matched from the given text in a predetermined format; wherein the output content includes the associated keyword group and the position information of each associated keyword in the given text.

[0150] The functions or operation steps implemented when the above modules and units are executed are generally the same as those in the above method embodiments, and will not be repeated here.

[0151] Those skilled in the art will appreciate that the logic and / or steps represented in the flowchart or otherwise described herein, for example, may be considered as an ordered list of executable instructions for implementing logical functions, and may be embodied in any computer-readable storage medium for use by an instruction execution system, device, or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device, or apparatus and execute instructions), or in conjunction with such instruction execution systems, devices, or apparatuses. For purposes of this specification, a "computer-readable storage medium" may be any device that can contain, store, communicate, propagate, or transmit a program for use by an instruction execution system, device, or apparatus, or in conjunction with such instruction execution systems, devices, or apparatuses.

[0152] More specific examples of computer-readable storage media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable storage medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or processing in another suitable manner as necessary, and then stored in a computer memory.

[0153] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or a combination thereof: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0154] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0155] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

Claims

1. A method for constructing an AC automaton, characterized in that: The method comprises the following steps: Obtain at least one associated keyword thesaurus, wherein each line of character string in the associated keyword thesaurus represents an associated keyword group, the keywords in the associated keyword group have an associated relationship, and the keywords are separated by a preset separator; Traversing the associated keyword thesaurus, and taking out a new group of associated keyword groups from the associated keyword thesaurus each time; Perform keyword extraction on the currently retrieved current associated keyword group according to the preset separator to extract each keyword in the current associated keyword group, and generate meta information corresponding to each keyword, wherein the meta information at least includes identification information, and the identification information is used to identify the associated keyword group to which the keyword belongs; The child nodes of the Trie tree are constructed according to the keywords, and after the child nodes are constructed, the meta information corresponding to the keywords is recorded into the meta information set of the corresponding child nodes, so as to construct the Trie tree of the AC automaton.

2. The AC automaton construction method according to claim 1, characterized in that: The steps of constructing a child node of the Trie tree according to the keyword include: Traversing the keyword to extract each character in the keyword in sequence; Determine whether the current node of the Trie tree has a pointer to the target child node that matches the current character currently extracted. Initially, the construction starts from the root node of the Trie tree. If yes, move to the target child node, and return to execute the step of traversing the keyword to extract each character in the keyword in sequence; If not, create a child node, store the current character in the created child node, add a pointer to the new child node, move to the new child node, and return to execute the step of traversing the keyword to extract each character in the keyword in sequence.

3. The AC automaton construction method according to claim 2, characterized in that: The step of recording the meta information corresponding to the keyword into the meta information set of the corresponding sub node after the sub node is constructed includes: Marking the child node storing the last character of the keyword as a keyword child node; The keyword is written into the keyword sub-node, and the meta information corresponding to the keyword is recorded into the meta information set of the keyword sub-node.

4. The AC automaton construction method according to claim 1, characterized in that: After constructing the Trie tree of the AC automaton, it also includes: Based on each child node of the constructed Trie tree, a corresponding failure pointer is added according to the preset rules to construct an AC automaton.

5. A keyword matching method, characterized in that: The AC automaton constructed based on the method according to any one of claims 1 to 4 is implemented, comprising the following steps: Get at least one given text; Searching the given text based on the AC automaton to search for matching keywords from the given text; The meta information corresponding to the keyword is obtained from the corresponding child node of the Trie tree of the AC automaton, and the associated keyword group is matched from the given text based on the meta information corresponding to the keyword.

6. The keyword matching method according to claim 5, characterized in that: The step of searching the given text based on the AC automaton to search for matching keywords from the given text includes: Traversing the given text to extract each character in the given text in sequence; Starting from the root node of the Trie tree of the AC automaton, the extracted current character is matched with the characters stored in the child nodes of the Trie tree in sequence; Among them, when matching, if the current character extracted matches the character stored in the current child node, then the next character is matched with the character stored in the next child node pointed to by the pointer of the current child node; if the current character extracted does not match the character stored in the current child node, then jump to another child node through the failure pointer of the current child node to continue matching; In addition, if the characters are matched successfully, it is determined whether the current child node that is matched successfully has a keyword written therein. If a keyword is written therein, the keyword written therein is used as a keyword matched from the given text.

7. The keyword matching method according to claim 6, characterized in that: The steps of obtaining meta information corresponding to the keyword from the corresponding child node of the Trie tree of the AC automaton, and matching the associated keyword group from the given text based on the meta information corresponding to the keyword include: Obtaining a meta information set from the child nodes corresponding to each of the keywords; Traversing each of the obtained meta information sets, allocating a group counter to the associated keyword group to which each meta information in the meta information set belongs, specifically allocating a group counter once for the same meta information, and when the group counter is initially allocated, its count value is the number of keywords in the corresponding associated keyword group, and when different keywords in the associated keyword group appear, the count value of the corresponding group counter is reduced by 1; After the allocation is completed, it is determined whether the count value of the group counter corresponding to the target associated keyword group is equal to 0; If not, the target associated keyword group is used as the associated keyword group matched from the given text.

8. The keyword matching method according to claim 5, characterized in that: After the step of matching the associated keyword group from the given text based on the meta information corresponding to the keyword, the method further includes: Outputting the associated keyword groups matched from the given text in a predetermined format; The output content includes the associated keyword group and the position information of each associated keyword in the given text.

9. An AC automaton construction device, characterized in that: The device comprises: A word library acquisition module, used to acquire at least one related keyword word library, each line of character string in the related keyword word library represents a related keyword group, the keywords in the related keyword group have a related relationship, and the keywords are separated by a preset separator; A word library traversal module, used for traversing the associated keyword word library, and taking out a new group of associated keyword groups from the associated keyword word library each time traversal; An information generation module, used for performing keyword extraction on the currently taken out current associated keyword group according to the preset delimiter to extract each keyword in the current associated keyword group, and generating meta information corresponding to each keyword, wherein the meta information at least includes identification information, and the identification information is used to identify the associated keyword group to which the keyword belongs; The Trie tree construction module is used to construct the child nodes of the Trie tree according to the keywords, and after the child nodes are constructed, the meta information corresponding to the keywords is recorded into the meta information set of the corresponding child nodes to construct the Trie tree of the AC automaton.

10. A keyword matching device, characterized in that: The AC automaton constructed based on the method according to any one of claims 1 to 4 is implemented, and the device comprises: A text acquisition module, used for acquiring at least one given text; A keyword search module, used for searching the given text based on the AC automaton to search for matching keywords from the given text; The association matching module is used to obtain the meta information corresponding to the keyword from the corresponding child node of the Trie tree of the AC automaton, and match the associated keyword group from the given text based on the meta information corresponding to the keyword.