Text matching method, knowledge base construction method and device

By dividing the text to be matched into text fragments and matching, the problem of low text matching efficiency in natural language processing is solved, and a more efficient text matching process is achieved.

CN114997136BActive Publication Date: 2024-12-17ALIBABA (CHINA) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210501545.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-09
Publication Date
2024-12-17
Estimated Expiration
2042-05-09

AI Technical Summary

Technical Problem

The prior art has low text matching efficiency in natural language processing and is difficult to effectively improve.

Method used

By dividing the text to be matched into text fragments, and determining whether the text fragment matches the target statement based on the slicing granularity and slicing offset, the final comprehensive fragment matching result determines the matching result between the text to be matched and the target statement.

Benefits of technology

This reduces the complexity of the algorithm, improves the efficiency of text matching, and realizes a more efficient text matching process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114997136B_ABST
    Figure CN114997136B_ABST
Patent Text Reader

Abstract

The specification discloses a text matching method, a knowledge base construction method and a device. The text matching method comprises: determining the sentence length of the target sentence; calculating the segmentation granularity and segmentation offset of the text segmentation according to the sentence length; segmenting the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset; for each text segment, determining whether the text segment matches the target sentence; and determining the text matching result between the to-be-matched text and the target sentence by synthesizing the segment matching results of each text segment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of natural language processing technology, and in particular to a text matching method, a knowledge base construction method and a device. Background Art

[0002] Natural Language Processing (NLP) is an important field in computer science and artificial intelligence, and can be applied to machine translation, text classification, question answering, knowledge base construction, etc. In natural language processing, text matching is often required, and how to improve the efficiency of text matching has become a focus of attention in the industry. Summary of the invention

[0003] In view of this, this specification provides a text matching method, a knowledge base construction method and a device.

[0004] Specifically, this specification is implemented through the following technical solutions:

[0005] A text matching method, comprising:

[0006] Determine the sentence length of the target sentence;

[0007] Calculating the segmentation granularity and segmentation offset of the text segmentation according to the sentence length;

[0008] Segmenting the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset;

[0009] For each text segment, determining whether the text segment matches the target sentence;

[0010] The fragment matching results of each text fragment are integrated to determine the text matching result between the to-be-matched text and the target sentence.

[0011] Optionally, dividing the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset includes:

[0012] For each segmentation offset, determining a segmentation start word for the current segmentation for the text to be matched according to the segmentation offset;

[0013] Starting from the segmentation start word, a text segment conforming to the segmentation granularity is segmented out from the to-be-matched text.

[0014] Optionally, determining whether the text segment matches the target sentence includes:

[0015] Determine a first word position parameter of a first word in the target sentence in the text segment and a last word position parameter of a last word in the text segment;

[0016] Determining whether the difference between the first word position parameter and the last word position parameter is greater than or equal to the sentence length of the target sentence;

[0017] When the difference is greater than or equal to the sentence length, it is determined whether the text segment matches the target sentence.

[0018] Optionally, also include:

[0019] When the difference is less than the sentence length, it is determined that the text segment does not match the target sentence.

[0020] Optionally, the synthesizing the segment matching results of each text segment to determine the text matching result between the text to be matched and the target sentence includes:

[0021] In a case where there is a segment matching result that is a matching text segment, determining that the text matching result is that the to-be-matched text matches the target sentence;

[0022] In the case that there is no segment matching result that is a matched text segment, it is determined that the text matching result is that the to-be-matched text does not match the target sentence.

[0023] Optionally, also include:

[0024] Determine whether the text to be matched has each word in the target sentence;

[0025] In the case that the to-be-matched text does not have every word in the target sentence, it is determined that the to-be-matched text does not match the target sentence.

[0026] Optionally, calculating the segmentation granularity and segmentation offset of the text segmentation according to the sentence length includes:

[0027] In the case where the to-be-matched text has each word in the target sentence, a segmentation granularity and a segmentation offset of text segmentation are calculated according to the sentence length.

[0028] A method for constructing a knowledge base, comprising:

[0029] Extract the text to be structured;

[0030] Determining whether the text to be structured matches a preset sentence;

[0031] In the case where the text to be structured matches the preset sentence, extracting an index sentence matching the preset sentence from the text to be structured;

[0032] Building a knowledge base according to the index statement and the text to be structured;

[0033] The text to be structured and the preset sentence are matched using the aforementioned text matching method.

[0034] A text matching device, comprising:

[0035] A length determination unit, which determines the sentence length of the target sentence;

[0036] A segmentation calculation unit, which calculates a segmentation granularity and a segmentation offset of text segmentation according to the sentence length;

[0037] A text segmentation unit, which segments the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset;

[0038] A segment matching unit, for each text segment, determines whether the text segment matches the target sentence;

[0039] The text matching unit integrates the fragment matching results of each text fragment to determine the text matching result between the to-be-matched text and the target sentence.

[0040] A knowledge base construction device, comprising:

[0041] A text extraction unit extracts the text to be structured;

[0042] A matching judgment unit, judging whether the text to be structured matches a preset sentence;

[0043] An index extraction unit, when the to-be-structured text matches the preset sentence, extracts an index sentence matching the preset sentence from the to-be-structured text;

[0044] A knowledge base construction unit, which constructs a knowledge base according to the index statement and the text to be structured;

[0045] The text to be structured and the preset sentence are matched using the aforementioned text matching method.

[0046] An electronic device, comprising:

[0047] processor;

[0048] memory for storing machine-executable instructions;

[0049] The processor implements the steps of the aforementioned method by running the executable instructions.

[0050] A computer-readable storage medium stores computer instructions, which implement the steps of the above method when executed by a processor.

[0051] By adopting the above implementation, when performing text matching, the text to be matched can be divided into text segments, and then it is determined whether the text segments match the target sentence, and the text matching result of the text to be matched is determined according to the segment matching result of the text segments. The matching of the text to be matched is converted into the matching of a text segment shorter than it, which reduces the complexity of the algorithm and thus improves the efficiency of text matching. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 It is a flowchart of a text matching method shown in an exemplary embodiment of this specification.

[0053] Figure 2 It is a schematic diagram of segmenting a text to be matched as shown in an exemplary embodiment of this specification.

[0054] Figure 3 It is a flowchart of a text segment filtering method shown in an exemplary embodiment of this specification.

[0055] Figure 4 It is a flowchart of a method for constructing a knowledge base shown in an exemplary embodiment of this specification.

[0056] Figure 5 It is a hardware structure diagram of an electronic device where a text matching device is located, shown as an exemplary embodiment of this specification.

[0057] Figure 6 It is a block diagram of a text matching device shown in an exemplary embodiment of this specification.

[0058] Figure 7 It is a block diagram of a knowledge base construction device shown in an exemplary embodiment of this specification. DETAILED DESCRIPTION

[0059] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.

[0060] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit this specification. The singular forms "a", "the" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0061] It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0062] Natural language processing is an important direction in the fields of computer science and artificial intelligence. It can be applied to scenarios such as machine translation, text classification, question answering, and knowledge base construction. In natural language processing, text matching is often required. For example, when classifying text, it is necessary to determine whether the text to be classified matches the text of the specified category. For another example, when implementing intelligent customer service, it is necessary to determine whether the user's question matches the answer in the question library. How to improve the efficiency of text matching has become a focus of attention in the industry.

[0063] This specification provides a text matching solution, which can divide the text to be matched into text segments, then determine whether the text segments match the target sentence, and determine the matching result of the text to be matched according to the matching result of the text segments. Converting the matching of the text to be matched into the matching of text segments reduces the complexity of the algorithm and improves the efficiency of text matching.

[0064] Figure 1 It is a flowchart of a text matching method shown in an exemplary embodiment of this specification.

[0065] Please refer to Figure 1 , the text matching method may include the following steps:

[0066] Step 102, determining the sentence length of the target sentence.

[0067] In this specification, it is necessary to determine whether the text to be matched matches the target sentence. The target sentence can be preset and can be a complete sentence, or a phrase, a word group, a character, etc. The text to be matched matches the target sentence, which can include the target sentence in the text to be matched, or can include a sentence with the same semantics as the target sentence. The specific meaning of the match can be set based on business needs.

[0068] For example, in a text classification scenario, the target sentence is usually a text of a preset known category, and the text to be matched is a text of an unknown category that needs to be classified. If the text to be matched matches the target sentence, it can be determined that the category of the text to be matched is the same as the category of the target sentence; if the text to be matched does not match the target sentence, it can be determined that the category of the text to be matched is different from the category of the target sentence, and then it can be determined whether the text to be matched matches the next target sentence.

[0069] For another example, in an intelligent customer service scenario, the target sentence is usually a preset standard question text, and the text to be matched is the user question entered by the user. If the user question matches the standard question, the answer to the standard question can be returned to the user as the answer to the user question; if the user question does not match the standard question, it can be determined that the user question and the standard question have different meanings, and the answer to the standard question cannot be returned to the user, and the user question can continue to be judged whether it matches the next standard question.

[0070] For another example, in the knowledge base construction scenario, the target sentence is usually a preset text that can be used as an index, and the text to be matched is the original text that has not yet been indexed. If the text to be matched matches the target sentence, the sentence that matches the target sentence can be extracted from the text to be matched as the index sentence, and then the corresponding index is generated for the sentence to be matched based on the index sentence to achieve the structured construction of the knowledge base; if the text to be matched does not match the target sentence, it can continue to determine whether the text to be matched matches the next target sentence.

[0071] In this specification, for each target sentence, the target sentence may be segmented, and then the number of words obtained after the segmentation is counted, and the number of words contained in the target sentence may be used as the sentence length of the target sentence.

[0072] The target words may be segmented using an existing word segmentation algorithm or tool, such as a hidden Markov algorithm, a maximum matching word segmentation algorithm, etc. This specification does not impose any special restrictions on this.

[0073] Step 104: Calculate the segmentation granularity and segmentation offset of the text segmentation according to the sentence length.

[0074] Based on the aforementioned step 102, after the sentence length of the target sentence is determined, the segmentation granularity and segmentation offset of the to-be-matched text segmentation may be determined based on the sentence length.

[0075] The segmentation granularity represents the length of the text segment obtained after segmenting the to-be-matched text, and the length of the text segment is usually the number of words contained in the text segment. Assuming the segmentation granularity is 5, it means that each text segment obtained after segmentation contains 5 words.

[0076] The segmentation offset represents the position deviation between the segmentation start word and the first word of the text to be matched, and the position deviation is usually the number of words that differ. There are usually multiple segmentation offsets, and based on each segmentation offset, a text segment can be segmented from the text to be matched. Assume that the segmentation offset is 4, which means that segmentation starts from the 5th word of the text to be matched. If the segmentation granularity is 5, then the 5th to 9th words of the text to be matched will be segmented to obtain the corresponding text segment.

[0077] In this specification, it is assumed that L1 represents the length of the target sentence, C represents the segmentation granularity, and D represents the segmentation offset. C and D can be calculated using the following formula:

[0078] C = 2 × L1-1,

[0079] D=n×(L1-1), n=0, 1, 2,…

[0080] Among them, the algorithm of C can ensure that the text fragments obtained after segmentation can include the complete target sentence, and can only include one complete target sentence at most. The algorithm of D combined with the algorithm of C can ensure that the text fragments obtained after segmentation must contain text fragments including the complete target sentence, and the number of segmented text fragments is relatively small.

[0081] Of course, in other examples, other formulas may be used to calculate the above segmentation granularity and segmentation offset, for example, C=2×L1-2, D=n×(L1-2), etc., so that the number of text segments obtained by segmentation will be relatively larger.

[0082] Step 106: segment the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset.

[0083] Based on the aforementioned step 104, after the segmentation granularity and the segmentation offset are calculated, the text to be matched may be segmented according to the segmentation granularity and the segmentation offset.

[0084] When performing segmentation, for each segmentation offset, the segmentation starting word for this segmentation can be determined based on the segmentation offset, and then starting from the segmentation starting word, a text segment that meets the segmentation granularity is segmented from the text to be matched to obtain a text segment corresponding to the segmentation offset.

[0085] For example, assuming that the sentence length L1 of the target sentence is 5, using the formula C=2×L1-1, D=n×(L1-1), we can calculate the segmentation granularity C=9 and the segmentation offset D=0, 4, 8, 12, 16, 20,...

[0086] Assume that the length of the text to be matched is 20. Figure 2In the example of , when D=0, the starting word of this segmentation is the first word of the text to be matched, and the 1st to 9th words can be segmented from the text to be matched to obtain the text segment 1 corresponding to the segmentation offset 0.

[0087] When D=4, the starting word of this segmentation differs by 4 words from the first word of the text to be matched, that is, the starting word of this segmentation is the 5th word in the text to be matched, and the 5th to 13th words can be segmented from the text to be matched to obtain a text segment 2 corresponding to the segmentation offset 4.

[0088] When D=8, the starting word of this segmentation differs from the first word of the text to be matched by 8 words, that is, the starting word of this segmentation is the 9th word in the text to be matched, and the 9th to 17th words can be segmented from the text to be matched to obtain a text segment 3 corresponding to the segmentation offset 8.

[0089] When D=12, the starting word of this segmentation is 12 words away from the first word of the text to be matched, that is, the starting word of this segmentation is the 13th word in the text to be matched. Since the segmentation according to the segmentation granularity has exceeded the text to be matched, the remaining text in the text to be matched can be extracted as the last text fragment 4, that is, the 13th-20th words in the text to be matched are determined as the text fragment 4 corresponding to the segmentation offset 12.

[0090] At this point, 4 text segments can be segmented from the text to be matched, and the number of text segments is much smaller than the length of the text to be matched.

[0091] Step 108: for each text segment, determine whether the text segment matches the target sentence.

[0092] Based on the aforementioned step 106 , after the to-be-matched text is segmented into text segments, it can be determined whether each text segment matches the target sentence.

[0093] In this specification, for each text segment, a text similarity algorithm may be used to determine whether the text segment matches the target sentence, for example, a cosine similarity algorithm, an edit distance algorithm, and the like.

[0094] In a simpler way, each word in the text segment can be directly compared with the words in the target sentence to determine whether the text segment contains the target sentence. For example, the words can be compared starting from the first word in the text segment. If the text segment contains the target sentence, it can be determined that the text segment matches the target sentence; if the text segment does not contain the target sentence, it can be determined that the text segment does not match the target sentence. Of course, in actual applications, according to business needs, a certain fault tolerance mechanism can also be set. For example, when the text segment includes a sentence and the number of different words between the sentence and the target sentence is less than the fault tolerance threshold, it can also be determined that the text segment matches the target sentence.

[0095] For example, assuming the target sentence is "unregister_netdevice:waiting for*to becomefree.", and the text segment is "unregister_netdevice:waiting for cli-veth to become free.", the text segment and the target sentence only have one different word "cli-veth". Assuming the tolerance threshold is 3, it can be determined that the text segment matches the target sentence. Of course, in other examples, the "*" in the target sentence can also mean that the word does not need to be matched, that is, no matter what word is in the position corresponding to the "*" in the text segment, it can be determined that it matches the "*".

[0096] Optional, please refer to Figure 3 Before determining whether a text segment matches a target sentence, the present specification may also perform preliminary filtering on the text segment to filter out text segments that obviously match the target sentence, thereby improving subsequent matching efficiency. The filtering may include the following steps:

[0097] Step 302: determining a first word position parameter of a first word in a target sentence in a text segment and a last word position parameter of a last word in the text segment.

[0098] In this specification, the first word and the last word of the target sentence may be obtained first, wherein the first word is the first word and the last word is the last word.

[0099] For each text segment, the first word and the last word of the target sentence can be located in the text segment first, and then the position parameter of the first word in the text segment (hereinafter referred to as the first word position parameter for easy distinction) and the position parameter of the last word (hereinafter referred to as the last word position parameter) can be determined. The position parameter can be the number of the position of the corresponding word after the text segment is segmented, that is, the text segment is segmented, and then each word is sequentially numbered starting from the first word of the text segment according to the segmentation result to obtain the position parameter of each word.

[0100] It is worth noting that if there are multiple first words in the text segment, the position parameter of the first word at the front position can be determined as the first word position parameter; if there are multiple last words in the text segment, the position parameter of the last word at the back position can be determined as the last word position parameter. Of course, the position parameters of all the first words in the text segment can be used as the first word position parameters, and the position parameters of all the last words in the text segment can be used as the last word position parameters. In this way, multiple sets of first word position parameters and last word position parameters can be obtained, and this specification does not impose any special restrictions on this.

[0101] Step 304: determine whether the difference between the first word position parameter and the last word position parameter is greater than or equal to the sentence length of the target sentence.

[0102] Step 306: When the difference is greater than or equal to the sentence length, determine whether the text segment matches the target sentence.

[0103] Based on the aforementioned step 302, after determining the first word position parameter and the last word position parameter, the difference between the first word position parameter and the last word position parameter is calculated, for example, the first word position parameter is subtracted from the last word position parameter, or the first word position parameter is subtracted from the last word position parameter and then the absolute value is taken. Then, it is determined whether the difference is greater than or equal to the sentence length of the aforementioned target sentence.

[0104] When the difference is greater than or equal to the sentence length, it indicates that the text segment may contain the target language sentence, and then it is determined whether the text segment matches the target sentence.

[0105] When the difference is smaller than the sentence length, it indicates that the target sentence cannot be contained in the text segment, and there is no need to determine whether the text segment matches the target sentence. It can be directly determined that the text segment does not match the target sentence.

[0106] Of course, in practical applications, based on business needs, a certain amount of redundancy space can also be set, for example, to determine whether the difference is greater than or equal to a difference threshold, and the difference threshold can be appropriately smaller than the sentence length.

[0107] In addition, if the text segment does not include the first word in the target sentence, or does not include the last word in the target sentence, it can also be directly determined that the text segment does not match the target sentence.

[0108] For example, assuming that the first word of the target sentence is "unregister_netdevice" and the last word is "free", the position parameter of "unregister_netdevice" in the text fragment is 5, and the position parameter of "free" is 12. The difference between the first word position parameter and the last word position parameter is 7. Assuming that the sentence length of the target sentence is also 7, that is, the difference between the first word position parameter and the last word position parameter is equal to the sentence length of the target sentence, it can be determined that the text fragment matches the target sentence.

[0109] In this specification, before determining whether a text fragment matches a target sentence, the text fragment can be filtered by determining whether the difference between the first word position parameter and the last word position parameter is greater than or equal to the sentence length of the target sentence, thereby filtering out text fragments that obviously do not match the target sentence, reducing the number of text fragments to be matched, and improving matching efficiency.

[0110] Step 110 , synthesizing the segment matching results of each text segment, and determining the text matching result between the to-be-matched text and the target sentence.

[0111] Based on the aforementioned step 108, after determining the segment matching result between each text segment and the target sentence, the text matching result between the to-be-matched text and the target sentence can be determined by combining these matching structures.

[0112] When there is at least one text segment that matches the segment matching result of the target sentence, it can be determined that the to-be-matched text matches the target sentence, that is, the text matching result is a match.

[0113] When the segment matching results of all text segments and the target sentence are mismatched, it can be determined that the to-be-matched text does not match the target sentence, that is, the text matching result is mismatched.

[0114] In this specification, when it is determined that the text matching result is a match, subsequent steps can be performed according to business needs. For example, in a text classification scenario, it can be determined that the category of the text to be matched is the same as that of the target sentence. For another example, in a knowledge base construction scenario, a sentence matching the target sentence can be extracted from the text to be matched as an index sentence, and then a corresponding index is generated for the text to be matched based on the index sentence.

[0115] As can be seen from the above description, when performing text matching, the present specification can divide the text to be matched into text segments, then determine whether the text segment matches the target sentence, and determine the text matching result of the text to be matched based on the segment matching result of the text segment. By adopting the above scheme, the matching of the text to be matched can be converted into the matching of a text segment shorter than it, which reduces the complexity of the algorithm and thus improves the efficiency of text matching.

[0116] Optionally, in this specification, some text matching scenarios have very strict requirements on text matching. For example, when searching for a target sentence, it may be required that the text to be matched contains sentences that are exactly the same as the target sentence; for another example, in some knowledge base construction scenarios, it may also be required that the text to be matched contains sentences that are exactly the same as the target sentence. For these scenarios, before executing the aforementioned step 104 to calculate the segmentation granularity and segmentation offset, it may also be determined whether the text to be matched has each word in the target sentence.

[0117] In the case that the to-be-matched text has each word in the target sentence, step 104 is performed to calculate the segmentation granularity and segmentation offset of the text segmentation according to the sentence length of the target sentence.

[0118] In the case where the text to be matched does not have every word in the target sentence, for example, the text to be matched does not have the word "free" in the target sentence, it can be directly determined that the text to be matched does not match the target sentence, and there is no need to execute the subsequent step 104.

[0119] It can be seen from this that when performing text matching, this manual can first filter the text to be matched by determining whether the text to be matched includes each word of the target sentence, and then determine the text to be matched that obviously does not match the target sentence, thereby reducing the number of texts to be matched and improving matching efficiency.

[0120] Based on the above text matching method, this manual also provides a method for building a knowledge base, please refer to Figure 4 , the method for constructing the knowledge base may include the following steps:

[0121] Step 402: extract the text to be structured.

[0122] In this specification, the knowledge base may be an operating system knowledge base or a question-and-answer knowledge base, and this specification does not impose any special restrictions on the type of the knowledge base.

[0123] In this specification, the original text used to construct the knowledge base is usually unstructured text, which is irregular and may be incomplete, and is not convenient for search and query.

[0124] Taking the operating system knowledge base as an example, the original text used to build the knowledge base can be uploaded by technical personnel, including problem location experience, tool usage methods, debugging technology introduction, upstream patches and other categories. If it is not structured, the search query effect will be relatively poor.

[0125] Taking the question-and-answer knowledge base as an example, the original text used to build the question-and-answer knowledge base can be uploaded by customer service personnel, including multiple categories such as product introduction, logistics information, after-sales service, etc. If it is not structured, the search query effect will be relatively poor.

[0126] In this specification, when constructing a knowledge base, the original text that has not been structured and is used to construct the knowledge base, that is, the text to be structured, can be first obtained.

[0127] Step 404: determine whether the text to be structured matches a preset sentence.

[0128] In this specification, preset statements can be preset by technicians, and are usually statements suitable for being indexed, for example, statements that are frequently queried by inquiring personnel, etc. The number of preset statements can also be set by technicians according to business needs.

[0129] In this specification, it can be determined whether the text to be structured extracted in the above step 102 matches each preset sentence. Figure 1 The text matching method shown is used to determine whether the text to be structured matches the preset sentence, wherein the text to be structured is equivalent to Figure 1 In the embodiment, the problem to be matched is equivalent to the preset statement Figure 1 The target sentence in the embodiment.

[0130] Step 406: When the text to be structured matches the preset sentence, an index sentence matching the preset sentence is extracted from the text to be structured.

[0131] Step 408: construct a knowledge base according to the index statement and the text to be structured.

[0132] Based on the text matching result of the aforementioned step 404, when the text to be structured matches the preset sentence, an index sentence matching the preset sentence can be extracted from the text to be structured, and a corresponding index can be generated for the text to be structured based on the index sentence, and then a structured knowledge base can be constructed based on the index and the text to be structured.

[0133] If the text to be structured does not match the preset sentence, it can continue to determine whether the text to be structured matches the next preset sentence. If the text to be structured does not match all preset sentences, keywords can be extracted from the text to be structured as indexes to build a knowledge base.

[0134] For example, suppose the text to be structured is a kernel log: "The ali*** plug-in corresponding to the container 8b699***48f4a4*** of the machine a60f01*** is stuck. Looking at the ali*** stack, it is stuck when deleting the device. The corresponding pair of veths is time = '2019-08-26 22:32:24.219326952' level = info msg = 'join interfaceveth***vet**0*'. Checking the system, it is found that a veth is stuck in the front, causing subsequent stucks, and the upgrade and expansion of the container will be stuck: [17730320.628626] unregister_netdevice: waiting for vet**0*tobecome free. Usage count. This vet**0* was detached before, and vet**0* was placed in the container net ns, and vet**0* was connected to the vport. Observing dmesg, similar prints will appear (Usage count=2 may be count=1, count=2, count=9. Because it is very difficult to completely reproduce count=1, the processing logic of pmtu is slightly modified, so the numbers will change, but the code flow is unified): unregister_netdevice: waiting for cli-veth to become free. Usage count=2. The kernel needs to check why.

[0135] The default statement is "unregister_netdevice:waiting for*to become free.Usagecount."

[0136] The index statements "unregister_netdevice:waiting forvet**0*to become free.Usage count" and "unregister_netdevice:waiting forcli-veth to become free.Usage count=2" can be extracted from the aforementioned text to be structured.

[0137] It can be seen from this that when constructing a structured knowledge base, this specification can divide the text to be structured into shorter text segments and match them with preset sentences, and then extract index sentences from the text to be structured, and generate indexes for the text to be structured based on the index sentences, so as to construct a structured knowledge base. By adopting the above scheme, the matching of the text to be structured can be converted into matching of text segments shorter than it, which reduces the complexity of the algorithm, improves the efficiency of text matching, and thus improves the efficiency of constructing a structured knowledge base.

[0138] Corresponding to the above-mentioned embodiments of the text matching method, this specification also provides embodiments of a text matching device.

[0139] The embodiments of the text matching device of this specification can be applied in electronic devices. The device embodiments can be implemented by software, hardware, or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of the electronic device in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory and running them. From the hardware level, if Figure 5 The figure is a hardware structure diagram of the electronic device where the text matching device of this manual is located, except Figure 5 In addition to the processor, memory, network interface, and non-volatile memory shown, the electronic device in which the device in the embodiment is located may also include other hardware according to the actual function of the electronic device, which will not be described in detail.

[0140] Figure 6 It is a block diagram of a text matching device shown in an exemplary embodiment of this specification.

[0141] Please refer to Figure 6 The text matching device 600 can be applied in Figure 5 The electronic device shown includes: a length determination unit 601 , a segmentation calculation unit 602 , a text segmentation unit 603 , a segment matching unit 604 and a text matching unit 605 .

[0142] Wherein, the length determination unit 601 determines the sentence length of the target sentence;

[0143] A segmentation calculation unit 602 calculates a segmentation granularity and a segmentation offset for text segmentation according to the sentence length;

[0144] A text segmentation unit 603, which segments the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset;

[0145] A segment matching unit 604 determines, for each text segment, whether the text segment matches the target sentence;

[0146] The text matching unit 605 integrates the segment matching results of each text segment to determine the text matching result between the to-be-matched text and the target sentence.

[0147] Optionally, the text segmentation unit 603:

[0148] For each segmentation offset, determining a segmentation start word for the current segmentation for the text to be matched according to the segmentation offset;

[0149] Starting from the segmentation start word, a text segment conforming to the segmentation granularity is segmented out from the to-be-matched text.

[0150] Optionally, the segment matching unit 604:

[0151] Determine a first word position parameter of a first word in the target sentence in the text segment and a last word position parameter of a last word in the text segment;

[0152] Determining whether the difference between the first word position parameter and the last word position parameter is greater than or equal to the sentence length of the target sentence;

[0153] When the difference is greater than or equal to the sentence length, it is determined whether the text segment matches the target sentence.

[0154] Optionally, the text matching unit 605:

[0155] When the difference is less than the sentence length, it is determined that the text segment does not match the target sentence.

[0156] Optionally, the text matching unit 605:

[0157] In a case where there is a segment matching result that is a matching text segment, determining that the text matching result is that the to-be-matched text matches the target sentence;

[0158] In the case that there is no segment matching result that is a matching text segment, it is determined that the text matching result is that the to-be-matched text does not match the target sentence.

[0159] Optionally, the text matching unit 605:

[0160] Determine whether the text to be matched has each word in the target sentence;

[0161] In the case that the to-be-matched text does not have every word in the target sentence, it is determined that the to-be-matched text does not match the target sentence.

[0162] Optionally, the segmentation calculation unit 602:

[0163] In the case where the to-be-matched text has each word in the target sentence, a segmentation granularity and a segmentation offset of text segmentation are calculated according to the sentence length.

[0164] Corresponding to the aforementioned embodiment of the method for constructing a knowledge base, this specification also provides an embodiment of an apparatus for constructing a knowledge base.

[0165] The embodiments of the apparatus for constructing the knowledge base of this specification can be applied in electronic devices. The apparatus embodiments can be implemented by software, hardware, or a combination of software and hardware. Taking software implementation as an example, as a logically sensed apparatus, the processor of the electronic device in which it is located reads the corresponding computer program instructions in the non-volatile memory into the memory and runs them. From a hardware perspective, the hardware structure of the electronic device in which the apparatus for constructing the knowledge base of this specification is similar to that of the apparatus in which the knowledge base of this specification is constructed. Figure 5 The hardware structure of the electronic device shown is similar and will not be described in detail.

[0166] Figure 7 It is a block diagram of a knowledge base construction device shown in an exemplary embodiment of this specification.

[0167] Please refer to Figure 7 , the knowledge base construction device 700 may include:

[0168] A text extraction unit 701 extracts the text to be structured;

[0169] A matching judgment unit 702 is used to judge whether the text to be structured matches a preset sentence;

[0170] The index extraction unit 703 extracts an index sentence matching the preset sentence from the text to be structured when the text to be structured matches the preset sentence;

[0171] A knowledge base construction unit 704 constructs a knowledge base according to the index statement and the text to be structured;

[0172] The text to be structured and the preset sentence are matched using the text matching method described above in this specification.

[0173] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.

[0174] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. Ordinary technicians in this field can understand and implement it without paying creative work.

[0175] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.

[0176] Corresponding to the embodiment of the aforementioned text matching method, this specification also provides an electronic device, which includes: a processor and a memory for storing machine executable instructions. The processor and the memory are usually connected to each other via an internal bus. In other possible implementations, the device may also include an external interface to enable communication with other devices or components.

[0177] In this embodiment, by reading and executing the machine executable instructions corresponding to the text matching logic stored in the memory, the processor is prompted to:

[0178] Determine the sentence length of the target sentence;

[0179] Calculating the segmentation granularity and segmentation offset of the text segmentation according to the sentence length;

[0180] Segmenting the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset;

[0181] For each text segment, determining whether the text segment matches the target sentence;

[0182] The fragment matching results of each text fragment are integrated to determine the text matching result between the to-be-matched text and the target sentence.

[0183] Optionally, dividing the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset includes:

[0184] For each segmentation offset, determining a segmentation start word for the current segmentation for the text to be matched according to the segmentation offset;

[0185] Starting from the segmentation start word, a text segment conforming to the segmentation granularity is segmented out from the to-be-matched text.

[0186] Optionally, determining whether the text segment matches the target sentence includes:

[0187] Determine a first word position parameter of a first word in the target sentence in the text segment and a last word position parameter of a last word in the text segment;

[0188] Determining whether the difference between the first word position parameter and the last word position parameter is greater than or equal to the sentence length of the target sentence;

[0189] When the difference is greater than or equal to the sentence length, it is determined whether the text segment matches the target sentence.

[0190] Optionally, also include:

[0191] When the difference is less than the sentence length, it is determined that the text segment does not match the target sentence.

[0192] Optionally, the synthesizing the fragment matching results of each text fragment to determine the text matching result between the text to be matched and the target sentence includes:

[0193] In a case where there is a segment matching result that is a matching text segment, determining that the text matching result is that the to-be-matched text matches the target sentence;

[0194] In the case that there is no segment matching result that is a matching text segment, it is determined that the text matching result is that the to-be-matched text does not match the target sentence.

[0195] Optionally, also include:

[0196] Determine whether the text to be matched has each word in the target sentence;

[0197] In the case that the to-be-matched text does not have every word in the target sentence, it is determined that the to-be-matched text does not match the target sentence.

[0198] Optionally, calculating the segmentation granularity and segmentation offset of the text segmentation according to the sentence length includes:

[0199] In the case where the to-be-matched text has each word in the target sentence, a segmentation granularity and a segmentation offset of text segmentation are calculated according to the sentence length.

[0200] Corresponding to the embodiment of the method for constructing the knowledge base described above, this specification also provides another electronic device, which includes: a processor and a memory for storing machine executable instructions. The processor and the memory are usually connected to each other via an internal bus. In other possible implementations, the device may also include an external interface to enable communication with other devices or components.

[0201] In this embodiment, by reading and executing the machine executable instructions corresponding to the knowledge base construction logic stored in the memory, the processor is prompted to:

[0202] Extract the text to be structured;

[0203] Determining whether the text to be structured matches a preset sentence;

[0204] In the case where the text to be structured matches the preset sentence, extracting an index sentence matching the preset sentence from the text to be structured;

[0205] Building a knowledge base according to the index statement and the text to be structured;

[0206] The text to be structured and the preset sentence are matched using the text matching method described above in this specification.

[0207] Corresponding to the embodiment of the aforementioned text matching method, this specification also provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the following steps are implemented:

[0208] Determine the sentence length of the target sentence;

[0209] Calculating the segmentation granularity and segmentation offset of the text segmentation according to the sentence length;

[0210] Segmenting the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset;

[0211] For each text segment, determining whether the text segment matches the target sentence;

[0212] The fragment matching results of each text fragment are integrated to determine the text matching result between the to-be-matched text and the target sentence.

[0213] Optionally, dividing the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset includes:

[0214] For each segmentation offset, determining a segmentation start word for the current segmentation for the text to be matched according to the segmentation offset;

[0215] Starting from the segmentation start word, a text segment conforming to the segmentation granularity is segmented out from the to-be-matched text.

[0216] Optionally, determining whether the text segment matches the target sentence includes:

[0217] Determine a first word position parameter of a first word in the target sentence in the text segment and a last word position parameter of a last word in the text segment;

[0218] Determining whether the difference between the first word position parameter and the last word position parameter is greater than or equal to the sentence length of the target sentence;

[0219] When the difference is greater than or equal to the sentence length, it is determined whether the text segment matches the target sentence.

[0220] Optionally, also include:

[0221] When the difference is less than the sentence length, it is determined that the text segment does not match the target sentence.

[0222] Optionally, the synthesizing the fragment matching results of each text fragment to determine the text matching result between the text to be matched and the target sentence includes:

[0223] In a case where there is a segment matching result that is a matching text segment, determining that the text matching result is that the to-be-matched text matches the target sentence;

[0224] In the case that there is no segment matching result that is a matching text segment, it is determined that the text matching result is that the to-be-matched text does not match the target sentence.

[0225] Optionally, also include:

[0226] Determine whether the text to be matched has each word in the target sentence;

[0227] In the case that the to-be-matched text does not have every word in the target sentence, it is determined that the to-be-matched text does not match the target sentence.

[0228] Optionally, calculating the segmentation granularity and segmentation offset of the text segmentation according to the sentence length includes:

[0229] In the case where the to-be-matched text has each word in the target sentence, a segmentation granularity and a segmentation offset of text segmentation are calculated according to the sentence length.

[0230] Corresponding to the embodiment of the method for constructing a knowledge base described above, this specification also provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the following steps are implemented:

[0231] Extract the text to be structured;

[0232] Determining whether the text to be structured matches a preset sentence;

[0233] In the case where the text to be structured matches the preset sentence, extracting an index sentence matching the preset sentence from the text to be structured;

[0234] Building a knowledge base according to the index statement and the text to be structured;

[0235] The text to be structured and the preset sentence are matched using the text matching method described above in this specification.

[0236] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0237] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.

Claims

1. A text matching method, comprising: Determine the sentence length of the target sentence; Calculating the segmentation granularity and segmentation offset of the text segmentation according to the sentence length, wherein the segmentation offset represents the position deviation between the segmentation start word and the first word of the text to be matched; Segmenting the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset; For each text segment, determining whether the text segment matches the target sentence; Summarizing the fragment matching results of each text fragment, determining the text matching result between the to-be-matched text and the target sentence; in The segmenting of the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset includes: For each segmentation offset, determining a segmentation start word for the current segmentation for the text to be matched according to the segmentation offset; Starting from the segmentation start word, a text segment conforming to the segmentation granularity is segmented out from the to-be-matched text.

2. According to the method of claim 1, the determining whether the text segment matches the target sentence comprises: Determine a first word position parameter of a first word in the target sentence in the text segment and a last word position parameter of a last word in the text segment; Determining whether the difference between the first word position parameter and the last word position parameter is greater than or equal to the sentence length of the target sentence; When the difference is greater than or equal to the sentence length, it is determined whether the text segment matches the target sentence.

3. The method according to claim 2, further comprising: When the difference is less than the sentence length, it is determined that the text segment does not match the target sentence.

4. According to the method of claim 1, the step of synthesizing the segment matching results of each text segment to determine the text matching result between the text to be matched and the target sentence comprises: In a case where there is a segment matching result that is a matching text segment, determining that the text matching result is that the to-be-matched text matches the target sentence; In the case that there is no segment matching result that is a matching text segment, it is determined that the text matching result is that the to-be-matched text does not match the target sentence.

5. The method according to claim 1, further comprising: Determine whether the text to be matched has each word in the target sentence; In the case that the to-be-matched text does not have every word in the target sentence, it is determined that the to-be-matched text does not match the target sentence.

6. According to the method of claim 5, the calculating the segmentation granularity and segmentation offset of the text segmentation according to the sentence length comprises: In the case where the to-be-matched text has each word in the target sentence, a segmentation granularity and a segmentation offset of text segmentation are calculated according to the sentence length.

7. A method for constructing a knowledge base, comprising: Extract the text to be structured; Determining whether the text to be structured matches a preset sentence; In the case where the text to be structured matches the preset sentence, extracting an index sentence matching the preset sentence from the text to be structured; Building a knowledge base according to the index statement and the text to be structured; The text to be structured and the preset sentence are matched using the method described in any one of claims 1 to 6.

8. A text matching device, comprising: A length determination unit, which determines the sentence length of the target sentence; A segmentation calculation unit, which calculates a segmentation granularity and a segmentation offset of text segmentation according to the sentence length, wherein the segmentation offset represents a position deviation between a segmentation start word and a first word of the text to be matched; A text segmentation unit, which segments the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset; A segment matching unit, for each text segment, determines whether the text segment matches the target sentence; A text matching unit, which synthesizes the fragment matching results of each text fragment to determine the text matching result between the text to be matched and the target sentence; The step of dividing the to-be-matched text into text segments according to the segmentation granularity and the segmentation offset includes: For each segmentation offset, determining a segmentation start word for the current segmentation for the text to be matched according to the segmentation offset; Starting from the segmentation start word, a text segment conforming to the segmentation granularity is segmented out from the to-be-matched text.

9. A knowledge base construction device, comprising: A text extraction unit extracts the text to be structured; A matching judgment unit, judging whether the text to be structured matches a preset sentence; An index extraction unit, when the to-be-structured text matches the preset sentence, extracts an index sentence matching the preset sentence from the to-be-structured text; A knowledge base construction unit, which constructs a knowledge base according to the index statement and the text to be structured; The text to be structured and the preset sentence are matched using the method described in any one of claims 1 to 6.

10. An electronic device, comprising: processor; memory for storing machine-executable instructions; The processor implements the steps of the method according to any one of claims 1 to 7 by running the executable instructions.

11. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 7.