Multi-attribute text matching method, device, equipment and storage medium
By filtering and calculating common continuous subsequences in multi-attribute text, combining character length and position difference, the problem of low accuracy in text similarity judgment in the prior art is solved, and higher matching accuracy and lower error rate are achieved.
Patent Information
- Application Number
- CN202110605479.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-31
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2041-05-31
AI Technical Summary
The prior art is not very accurate when judging similarity or difference in multi-attribute texts, and the calculation of the longest continuous subsequence ignores character positions, resulting in a single-sided and arbitrary similarity judgment.
By obtaining candidate common continuous subsequences of subtexts corresponding to each set of the same attribute fields in the multi-attribute text, combining character length and position difference, the target common continuous subsequence is selected, and the similarity is calculated to improve matching accuracy.
It improves the accuracy of text matching, reduces the error rate, and can handle text matching of multi-attribute fields more accurately, reduces labor costs and improves work efficiency.
Smart Images

Figure CN113268567B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data analysis technology, and in particular to a multi-attribute text matching method, device, equipment and storage medium. Background Art
[0002] In natural language processing, it is often necessary to compare two texts to determine their similarities or to calculate their differences. However, the existing technologies all judge the text differences of texts with a single attribute, so their scope of application is relatively narrow. Especially for texts with multiple attributes, the existing technologies can only judge from a single attribute, resulting in an incomplete dimension of similarity judgment and inaccurate judgment results. In addition, the existing technologies usually calculate the similarity by calculating the longest continuous subsequence of the two. Since the factors considered are too single, the final similarity judgment is relatively one-sided, arbitrary, and lacks accuracy. Summary of the invention
[0003] In order to solve the technical problem that the prior art has low accuracy in judging the similarity or difference of texts, the present application provides a multi-attribute text matching method, apparatus, device and storage medium, the main purpose of which is to improve the accuracy of text matching and reduce the error rate.
[0004] To achieve the above object, the present application provides a multi-attribute text matching method, which includes:
[0005] Obtaining a first text and a second text to be matched, wherein each of the first text and the second text includes at least one attribute field, and each attribute field corresponds to a subtext;
[0006] Respectively calculating candidate common continuous subsequences of subtexts corresponding to each group of identical attribute fields in the first text and the second text, and obtaining the character length of each candidate common continuous subsequence;
[0007] Obtain the position difference of each candidate common continuous subsequence in the corresponding two different subtexts;
[0008] Based on the preset screening rules, the character length of each candidate common continuous subsequence and the corresponding position difference, the target common continuous subsequence corresponding to each group of the same attribute field is screened out;
[0009] Calculate the similarity of two subtexts corresponding to each group of the same attribute fields according to the character lengths of the two subtexts corresponding to the same attribute fields and the character lengths of the corresponding target common continuous subsequences;
[0010] According to the similarity, the matching degree between the first text and the second text is obtained.
[0011] In addition, to achieve the above-mentioned purpose, the present application also provides a multi-attribute text matching device, which includes:
[0012] A text acquisition module, used to acquire a first text and a second text to be matched, wherein the first text and the second text each contain at least one attribute field, and each attribute field corresponds to a subtext;
[0013] A first calculation module is used to calculate candidate common continuous subsequences of subtexts corresponding to each group of identical attribute fields in the first text and the second text, and obtain the character length of each candidate common continuous subsequence;
[0014] A position difference acquisition module, used for acquiring the position difference of each candidate common continuous subsequence in two corresponding different subtexts;
[0015] A screening module, used to screen out target common continuous subsequences corresponding to each group of identical attribute fields based on preset screening rules, character lengths of each candidate common continuous subsequence and corresponding position differences;
[0016] A second calculation module is used to calculate the similarity of two subtexts corresponding to each group of the same attribute field according to the character lengths of the two subtexts corresponding to the same attribute field and the character lengths of the corresponding target common continuous subsequences;
[0017] The third calculation module is used to obtain the matching degree between the first text and the second text according to the similarity.
[0018] To achieve the above objectives, the present application also provides a computer device, including a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor. When the processor executes the computer-readable instructions, the steps of the multi-attribute text matching method as described in any of the above items are performed.
[0019] To achieve the above objectives, the present application also provides a computer-readable storage medium, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor, the processor executes the steps of any of the above multi-attribute text matching methods.
[0020] The multi-attribute text matching method, device, equipment and storage medium proposed in the present application comprehensively consider the position difference and character length to obtain the optimal target common continuous subsequence corresponding to each attribute field, and combine natural language processing technology to make text matching more accurate, improve recognition accuracy, and reduce error rate. In addition, comprehensive consideration of multi-attribute fields can meet the situation of many data attributes and quickly match the results. It is more accurate than the results of single field matching, and reduces labor costs and improves work efficiency by automatically matching text. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 This is an application scenario diagram of the multi-attribute text matching method in one embodiment of the present application;
[0022] Figure 2 This is a flowchart of a multi-attribute text matching method in one embodiment of the present application;
[0023] Figure 3 This is a structural block diagram of a multi-attribute text matching device in an embodiment of the present application;
[0024] Figure 4 This is a block diagram of the internal structure of a computer device in one embodiment of the present application.
[0025] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of this application. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0027] The multi-attribute text matching method provided in this application can be applied in Figure 1 In the application environment, the terminal device can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The terminal device obtains a first text and a second text to be matched, and the first text and the second text both contain at least one attribute field, and each attribute field corresponds to a subtext; the terminal device respectively calculates the candidate common continuous subsequences of the subtexts corresponding to each group of the same attribute fields in the first text and the second text, and obtains the character length of each candidate common continuous subsequence; obtains the position difference of each candidate common continuous subsequence in the corresponding two different subtexts; based on the preset screening rules, the character length of each candidate common continuous subsequence and the corresponding position difference, the target common continuous subsequence corresponding to each group of the same attribute field is screened out; according to the character length of the two subtexts corresponding to the same attribute field and the character length of the corresponding target common continuous subsequence, the similarity of the two subtexts corresponding to each group of the same attribute field is calculated; according to the similarity, the matching degree of the first text and the second text is obtained.
[0028] Of course, the multi-attribute text matching method provided in the present application can be implemented by a terminal device and a server together. The terminal device and the server are connected via a network.
[0029] Figure 2 Schematic diagram of the process of a multi-attribute text matching method in an embodiment of the present application. Figure 2 , this method is applied in Figure 1 The multi-attribute text matching method includes the following steps S100-S600.
[0030] S100: Acquire a first text and a second text to be matched.
[0031] Specifically, the first text and the second text each contain at least one attribute field, and the number of attribute fields contained in the first text and the second text may be the same or different; the first text and the second text may contain the same attribute field or different attribute fields. Each attribute field corresponds to a subtext. For example, the first text and the second text may be information about the first pollution source enterprise and information about the second pollution source enterprise, and the multiple attribute fields of the first text include at least one of the company name, company address, credit code, founder, official website address, etc. of the first pollution source enterprise. The multiple attribute fields of the second text include at least one of the company name, company address, credit code, founder, official website address, etc. of the second pollution source enterprise. Each attribute field corresponds to a subtext, for example, the attribute field of the company name corresponds to the name of the first pollution source enterprise or the name of the second pollution source enterprise. In this specific embodiment, it is necessary to judge whether the first pollution source enterprise and the second pollution source enterprise are the same enterprise based on the comprehensive matching of multiple attribute fields. Of course, the multi-attribute text matching method of the present application is not only applied to the matching of pollution source enterprises, but also to many other fields. For example, scenario 1: information duplication judgment of e-commerce backend enterprises, scenario 2: information duplication judgment of various monitoring equipment and points, scenario 3: duplication judgment of some manually entered data in traditional industries, etc., are not limited to this.
[0032] S200: Calculate candidate common continuous subsequences of subtexts corresponding to each group of identical attribute fields in the first text and the second text respectively, and obtain the character length of each candidate common continuous subsequence.
[0033] Specifically, the first text and the second text both contain at least one attribute field, and only the subtexts corresponding to the same attribute fields have comparative matching significance. For example, the company name of the first pollution source enterprise and the company name of the second pollution source enterprise have comparative significance, but the company name and the company address do not have comparative significance. The first text and the second text may contain multiple groups of the same attribute fields. For example: the company name in the first text and the company name in the second text belong to one group of the same attribute fields, and the company address in the first text and the company address in the second text belong to another group of the same attribute fields.
[0034] In this embodiment, the SequenceMatcher algorithm is used to calculate the candidate common continuous subsequences between the two subtexts corresponding to the same attribute field. The candidate common continuous subsequence is a continuous and common substring that exists in both subtexts. Each group of candidate common continuous subsequences obtained for the same attribute field may contain 0, 1 or more, and the lengths of these candidate common continuous subsequences may be the same or not completely the same.
[0035] S300: Obtain the position difference of each candidate common continuous subsequence in two corresponding different subtexts.
[0036] Specifically, the first position and the second position of each candidate common continuous subsequence in the corresponding two different subtexts are obtained, and the position difference corresponding to each candidate common continuous subsequence is obtained according to the first position and the second position. Because the candidate common continuous subsequences are in different subtexts corresponding to two identical attribute fields, the position of each candidate common continuous subsequence in two different subtexts may be the same or different. If the first position and the second position are the same, the position difference calculated based on the two is 0, and if the first position and the second position are different, the position difference is greater than 0. The position difference is specifically the absolute value of the difference between the first position and the second position of the same candidate common continuous subsequence. In theory, the more the position difference is 0, the more it can reflect that the two subtexts are similar, and the larger the position difference is, the less it can reflect that the two subtexts are similar. That is, the similarity between the two subtexts can be further judged according to the position difference.
[0037] S400: based on a preset screening rule, the character length of each candidate common continuous subsequence and the corresponding position difference, screening out a target common continuous subsequence corresponding to each group of identical attribute fields.
[0038] Specifically, each pair of identical attribute fields may contain multiple candidate common contiguous subsequences. We need to select the best target common contiguous subsequence from multiple candidate common contiguous subsequences according to certain screening rules. The target common contiguous subsequence is selected by comprehensively considering the character length and position difference. Theoretically, the longer the character length and the smaller the position difference, the better the common contiguous subsequence. The target common contiguous subsequence may be the longest common contiguous subsequence, the common contiguous subsequence with the smallest position difference, or other common contiguous subsequences between the longest common contiguous subsequence and the common contiguous subsequence with the smallest position difference.
[0039] S500: Calculate the similarity between each group of two subtexts corresponding to the same attribute field according to the character lengths of the two subtexts corresponding to the same attribute field and the character lengths of the corresponding target common continuous subsequences.
[0040] Specifically, the similarity between the two subtexts corresponding to each group of the same attribute field is twice the character length of the target common continuous subsequence divided by the sum of the character lengths of the two subtexts corresponding to the attribute field. The specific formula is: s = 2m / t; where s is the similarity, m is the character length of the target common continuous subsequence, and t is the sum of the character lengths of the two corresponding subtexts. s is between 0 and 1. The larger S is, the more similar the two subtexts are.
[0041] S600: Obtaining a matching degree between the first text and the second text according to the similarity.
[0042] Specifically, the matching degree can be obtained by calculating the average of the similarities corresponding to the same attribute fields of all groups, or by calculating the weighted average of the similarities corresponding to the same attribute fields of all groups.
[0043] The prior art ignores the position of characters in the text. Therefore, the longest continuous subsequence obtained cannot truly reflect the same part between two different texts, and the similarity obtained is not true and accurate enough. The present application comprehensively considers the position difference and character length to obtain the optimal target common continuous subsequence corresponding to each attribute field, and combines natural language processing technology to make text matching more accurate, improve recognition accuracy, and reduce error rate. In addition, comprehensive consideration of multiple attribute fields can meet the situation of multiple data attributes, quickly match results, and be more accurate than the results of single field matching. By automatically matching text, labor costs are reduced and work efficiency is improved.
[0044] In one embodiment, step S400 specifically includes:
[0045] Eliminate candidate common continuous subsequences whose position difference is greater than the distance threshold;
[0046] Select the candidate common continuous subsequence with the longest character length or the shortest position difference from the remaining candidate common continuous subsequences of each group of the same attribute field;
[0047] The candidate common continuous subsequence with the longest character length or the shortest position difference is taken as the target common continuous subsequence corresponding to the same attribute field.
[0048] Specifically, the candidate common continuous subsequence whose position difference is greater than the distance threshold can no longer be considered as the common continuous subsequence of the two subtexts in a certain sense. The distance threshold is set according to the actual application scenario. Generally, when the subtext is long, the distance threshold can be set larger, and when the subtext is short, the distance threshold should be set smaller.
[0049] From each group of candidate common continuous subsequences corresponding to the same attribute field, select candidate common continuous subsequences whose position difference is less than or equal to the distance threshold, and select the candidate common continuous subsequence with the longest character length from the selected candidate common continuous subsequences as the target common continuous subsequence.
[0050] Of course, after the first screening based on the position difference, there may be no other candidate public continuous subsequences for some groups of the same attribute fields. In this case, the target public continuous subsequence corresponding to the same attribute field is empty.
[0051] This embodiment uses character length as a condition for a second screening after the first screening, which is equivalent to placing more emphasis on the effect of character length on similarity.
[0052] Alternatively, candidate public continuous subsequences whose position difference is less than or equal to a distance threshold are screened out from public continuous subsequences corresponding to each group of the same attribute fields, and the candidate public continuous subsequence with the shortest position difference is used as the target public continuous subsequence.
[0053] In this embodiment, the position difference is used as a condition for the second screening after the first screening, which is equivalent to placing more emphasis on the influence of the position difference on the similarity.
[0054] Alternatively, the target common continuous subsequence found has the longest character length and the shortest position difference among the other candidate common continuous subsequences remaining after the first screening. In this embodiment, both character length and position difference are considered, and the similarity of the two subtexts obtained is more referenceable and accurate.
[0055] Of course, in the above, if the candidate common continuous subsequence with the longest character length and the candidate common continuous subsequence with the shortest position difference are not the same candidate common continuous subsequence, the absolute value of the difference between the character length and the mean character length of the candidate common continuous subsequence with the longest character length is divided by the mean character length to obtain the first result; the absolute value of the difference between the position difference and the mean position difference of the candidate common continuous subsequence with the shortest position difference is divided by the mean position difference to obtain the second result. Compare the first result and the second result, and select the one with the largest value between the first result and the second result from the candidate common continuous subsequence with the longest character length and the candidate common continuous subsequence with the shortest position difference as the target common continuous subsequence.
[0056] The mean value of character length and the mean value of position difference are calculated based on the candidate common continuous subsequences remaining after the first screening of the same attribute field.
[0057] The distance threshold of the present application limits the allowed range of occurrence of candidate common contiguous subsequences. Only when candidate common contiguous subsequences appear in the same place or adjacent to each other within a certain range are they considered to be commonly discovered common contiguous subsequences. This approach can make the matching result more accurate.
[0058] Based on the above embodiment, step S500 specifically includes:
[0059] The similarity of the two subtexts corresponding to the same attribute field in which the target common continuous subsequence exists is calculated according to the character lengths of the two subtexts corresponding to the same attribute field and the character lengths of the corresponding target common continuous subsequences.
[0060] Specifically, after eliminating the candidate common continuous subsequences whose position difference is greater than the distance threshold, if there are other candidate common continuous subsequences remaining, it means that the target common continuous subsequence exists in the same attribute field of the group. Then the similarity between the two subtexts corresponding to the same attribute field where the target common continuous subsequence exists is twice the character length of the target common continuous subsequence divided by the sum of the character lengths of the two subtexts corresponding to the attribute field. The specific formula is: s = 2m / t; where s is the similarity, m is the character length of the target common continuous subsequence, and t is the sum of the character lengths of the corresponding two subtexts. s is between 0-1. The larger S is, the more similar the two subtexts are.
[0061] Based on the above embodiment, after step S400, the method further includes:
[0062] The similarity between two subtexts of the same attribute field without a target common continuous subsequence is determined as a preset value.
[0063] Specifically, if there is no other candidate common continuous subsequence with the same attribute field after eliminating the candidate common continuous subsequence with a position difference greater than the distance threshold, the similarity of the two subtexts without the same attribute field in other candidate common continuous subsequence is determined as a preset value.
[0064] If there is no other candidate common continuous subsequence with the same attribute field, the target common continuous subsequence is equivalent to being empty. Therefore, the similarity between the two subtexts corresponding to the same attribute field without the target common continuous subsequence can be determined as a preset value. The preset value can be 0 or a very small value such as 0.01, 0.001, etc.
[0065] In one embodiment, before step S200, the method further includes:
[0066] A filtering process is performed on each sub-text to filter out irrelevant characters in each sub-text.
[0067] Specifically, a first filtering process is performed on each subtext to filter out first irrelevant characters in each subtext; and / or a second filtering process is performed on each subtext to filter out second irrelevant characters in each subtext.
[0068] More specifically, the first filtering process is to filter out useless data in each subtext, such as blank lines, blank spaces, tabs, special punctuation marks or characters, etc. More specifically, the isjunk function in the SequenceMatcher object may be used to perform the first filtering process on each subtext.
[0069] The first filtering process can reduce the interference of useless data on the calculation of the common continuous subsequence, reduce the amount of calculation, and improve the accuracy of the calculation of the common continuous subsequence.
[0070] The second irrelevant character is specifically a frequently appearing character, or a common character common to the sub-texts corresponding to the same attribute field. For example, in a company name, "company", "enterprise", "Beijing", "Limited Liability Company", etc., these characters are all regular characters. For another example, in a company address, "China", "Beijing", etc. The second irrelevant character can be set and pre-stored by the engineering staff according to the current application scenario based on experience. During the execution of this method, the second filtering process can be performed on each sub-text according to the pre-stored second irrelevant character.
[0071] Optionally, in the above, no matter it is the first filtering process or the second filtering process, the positions of the filtered out characters are sequentially filled with the subsequent characters that are not filtered out.
[0072] In one embodiment, step S600 specifically includes: calculating an average of all similarities as the matching degree between the first text and the second text.
[0073] In one embodiment, step S600 specifically includes: obtaining a target weight of each attribute field in the same attribute field corresponding to the similarity, and obtaining a matching degree between the first text and the second text according to the target weight and the similarity.
[0074] Specifically, a weighted average is calculated based on the target weight and all similarities as the matching degree between the first text and the second text. The matching degree is calculated as follows:
[0075]
[0076] s represents the similarity corresponding to a group of identical attribute fields, f represents the weight of an attribute field in the identical attribute fields, i represents the number of identical attribute fields, n represents the number of identical attribute fields, that is, the number of identical attribute fields, and n can also represent the number of identical attribute fields with similarity, i is greater than or equal to 1 and less than or equal to n, n is greater than or equal to 1, and both i and n are positive integers.
[0077] In this embodiment, the first text and the second text both contain at least one attribute field, but in fact different attribute fields reflect different attribute characteristics of the first text or the second text. A weight is set for each attribute field so that the more important the field that can better reflect the attributes of the first text and the second text, the higher the weight, so that the similarity obtained is closer to the most realistic similarity between the first text and the second text.
[0078] Based on the above embodiment, in a specific embodiment, obtaining the target weight of each attribute field in the same attribute field corresponding to the similarity specifically includes:
[0079] Generate multiple sets of weight value sets according to the value range of the weight of each attribute field in the same attribute field corresponding to the preset similarity, wherein the sum of all the candidate weights in each set of weight value sets is 1, and each set of weight value sets contains a candidate weight corresponding to each attribute field in the same attribute field corresponding to the similarity;
[0080] According to the similarity and the selected weights in each set of weight values, the weighted mean variance corresponding to each set of weight values is calculated;
[0081] The selected weight in the weight value set corresponding to the minimum weighted mean variance is used as the target weight of the corresponding attribute field in the same attribute field corresponding to the similarity.
[0082] Specifically, the weight of each attribute field in the same attribute field corresponding to the similarity corresponds to a value range, and a candidate weight value is selected from the value range for each attribute field to obtain a set of weight value sets. Each set of weight value sets contains multiple candidate weights, and a candidate weight is a candidate weight corresponding to an attribute field in the same attribute field corresponding to the similarity. Moreover, the sum of all candidate weights in each set of weight value sets is 1. Therefore, multiple sets of different weight value sets can be obtained by this method. The specific number of sets of weight value sets that need to be obtained can be set according to the actual calculation overhead and the accuracy that needs to be achieved, and this application does not impose any restrictions.
[0083] Substituting the weights of the attribute fields in each set of weighted values and all similarities into the weighted average formula, the weighted average corresponding to each set of weighted values can be obtained. The weighted mean variance corresponding to each set can be calculated based on the weighted average and all similarities.
[0084] The formula for calculating the weighted mean variance is:
[0085]
[0086] in, s represents the similarity corresponding to a group of identical attribute fields, f represents the weight of each attribute field in the identical attribute field, n represents the number of identical attribute fields, that is, how many groups of identical attribute fields there are, and n can also represent the number of identical attribute fields with similarity, i represents the number of identical attribute fields, i is greater than or equal to 1, less than or equal to n, n is greater than or equal to 1, and both i and n are positive integers. Since there are multiple sets of weight value sets, the weighted mean variance DX corresponding to each set of weight value sets can be obtained. The obtained multiple weighted mean variances DX are compared, and a set of weight value sets corresponding to the minimum weighted mean variance is used as the target weight value set. The target weight value set includes a target weight corresponding to each attribute field in the identical attribute field corresponding to the similarity. The rationality of the weight design can be judged according to the size of the variance. If it is too large, it means that the weight setting is unreasonable, and then a relatively high-quality set of weights can be screened out.
[0087] The target weight is obtained, and the corresponding matching degree M is also calculated during the target weight calculation process. Therefore, the matching degree M corresponding to the target weight can be obtained without repeating the calculation in this embodiment.
[0088] Of course, the target weight can also be calculated in advance by R&D personnel based on a large amount of data according to the specific application scenario, and preset in this application.
[0089] The multi-attribute text matching method of this application can be applied to a variety of fields. For example, the information of pollution source enterprises has always been an important part of data governance, which directly affects the supervision and decision-making of related enterprises. Because there is a large amount of manually uploaded data, the content is not standardized, such as enterprise name, unit, address, etc. There are many differences in the names reported by different data sources, different batches, and different people. If the name cannot be unified, it will cause the enterprise information and historical record information to not match, the data cannot be associated and displayed normally, or it will cause duplicate data, affecting business functions such as statistics and reporting. Therefore, for data from different data sources and different batches, and whenever there is new enterprise information, it is necessary to recheck and verify. Most of the previous practices were through manual matching, which consumed a lot of manpower and time costs, and was prone to omissions and errors. Through this application, the information of pollution source enterprises containing multiple attributes can be accurately matched.
[0090] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0091] Figure 3 This is a structural block diagram of a multi-attribute text matching device in an embodiment of the present application. Figure 3 , the device comprises:
[0092] The text acquisition module 100 is used to acquire a first text and a second text to be matched, wherein the first text and the second text each contain at least one attribute field, and each attribute field corresponds to a subtext;
[0093] The first calculation module 200 is used to calculate candidate common continuous subsequences of subtexts corresponding to each group of the same attribute fields in the first text and the second text, and obtain the character length of each candidate common continuous subsequence;
[0094] A position difference acquisition module 300 is used to acquire the position difference of each candidate common continuous subsequence in two corresponding different subtexts;
[0095] A screening module 400 is used to screen out target common continuous subsequences corresponding to each group of identical attribute fields based on preset screening rules, character lengths of each candidate common continuous subsequence and corresponding position differences;
[0096] The second calculation module 500 is used to calculate the similarity of two subtexts corresponding to the same attribute field in each group according to the character lengths of the two subtexts corresponding to the same attribute field and the character lengths of the corresponding target common continuous subsequences;
[0097] The third calculation module 600 is used to obtain the matching degree between the first text and the second text according to the similarity.
[0098] The multi-attribute text matching device is generally arranged in a terminal device.
[0099] In one embodiment, the screening module 400 specifically includes:
[0100] A removal unit, used to remove candidate common continuous subsequences whose position difference is greater than a distance threshold;
[0101] A screening unit, used to screen out the candidate common continuous subsequence with the longest character length or the shortest position difference from the remaining other candidate common continuous subsequences of each group of the same attribute field;
[0102] The determination unit is used to take the candidate common continuous subsequence with the longest character length or the shortest position difference as the target common continuous subsequence corresponding to the same attribute field.
[0103] Based on the above embodiment, the second calculation module 500 is specifically used to calculate the similarity of two subtexts corresponding to the same attribute field having a target common continuous subsequence according to the character length of the two subtexts corresponding to the same attribute field and the character length of the corresponding target common continuous subsequence.
[0104] Based on the above embodiment, the device further includes:
[0105] The value assignment module is used to determine the similarity of two subtexts of the same attribute field without a target common continuous subsequence as a preset value.
[0106] In one embodiment, the apparatus further comprises:
[0107] The filtering module is used to filter each sub-text to filter out irrelevant characters in each sub-text.
[0108] In one embodiment, the third calculation module 600 specifically includes:
[0109] A weight acquisition module is used to obtain the target weight of each attribute field in the same attribute field corresponding to the similarity;
[0110] The sub-calculation module is used to obtain the matching degree between the first text and the second text according to the target weight and the similarity.
[0111] In one embodiment, the third calculation module 600 is specifically used for:
[0112] The average of all similarities is calculated to obtain the matching degree between the first text and the second text.
[0113] In one embodiment, the weight acquisition module specifically includes:
[0114] A combining unit, used to generate multiple sets of weight value sets according to the value range of the weight of each attribute field in the same attribute field corresponding to the preset similarity, wherein the sum of all the candidate weights in each set of weight value sets is 1, and each set of weight value sets contains a candidate weight corresponding to each attribute field in the same attribute field corresponding to the similarity;
[0115] A sub-calculation unit, used to calculate the weighted mean variance corresponding to each set of weight value sets according to the similarity and the selected weights in each set of weight value sets;
[0116] The selection unit is used to use the selected weight in the weight value set corresponding to the minimum weighted mean variance as the target weight of the corresponding attribute field in the same attribute field corresponding to the similarity.
[0117] The meaning of "first" and "second" in the above modules / units is only to distinguish different modules / units, and is not used to define which module / unit has a higher priority or other limiting meanings. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The division of modules in this application is only a logical division, and there may be other division methods when implemented in actual applications.
[0118] The specific definition of the multi-attribute text matching device can be found in the definition of the multi-attribute text matching method above, which will not be repeated here. Each module in the above-mentioned multi-attribute text matching device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0119] Figure 4 This is a block diagram of the internal structure of a computer device in one embodiment of the present application. The computer device may specifically be Figure 1 The terminal device in. Figure 4As shown, the computer device includes a processor, a memory, a network interface, an input device and a display screen connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory includes a storage medium and an internal memory. The storage medium can be a non-volatile storage medium or a volatile storage medium. The storage medium stores an operating system and can also store computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor can implement a multi-attribute text matching method. The internal memory provides an environment for the operation of the operating system and computer-readable instructions in the storage medium. The internal memory can also store computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor can execute the multi-attribute text matching method. The network interface of the computer device is used to communicate with an external server through a network connection. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse.
[0120] In one embodiment, a computer device is provided, including a memory, a processor, and computer-readable instructions (such as a computer program) stored in the memory and executable on the processor. When the processor executes the computer-readable instructions, the steps of the multi-attribute text matching method in the above embodiment are implemented, such as Figure 2 Alternatively, when the processor executes the computer-readable instructions, the functions of each module / unit of the multi-attribute text matching device in the above embodiment are realized, for example Figure 3 The functions of the text acquisition module 100, the first calculation module 200, the position difference acquisition module 300, the screening module 400, the second calculation module 500 and the third calculation module 600 are not described here in detail to avoid repetition.
[0121] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of a computer device, and uses various interfaces and lines to connect various parts of the entire computer device.
[0122] The memory can be used to store computer-readable instructions and / or modules. The processor implements various functions of the computer device by running or executing the computer-readable instructions and / or modules stored in the memory and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, video data, etc.), etc.
[0123] The memory may be integrated into the processor or provided separately from the processor.
[0124] Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0125] In one embodiment, a computer-readable storage medium is provided on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor, the steps of the multi-attribute text matching method in the above embodiment are implemented, such as Figure 2 Alternatively, when the computer-readable instructions are executed by the processor, the functions of each module / unit of the multi-attribute text matching device in the above embodiment are realized, for example Figure 3 The functions of the text acquisition module 100, the first calculation module 200, the position difference acquisition module 300, the screening module 400, the second calculation module 500 and the third calculation module 600 are not described here in detail to avoid repetition.
[0126] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the computer-readable instructions are executed, they can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0127] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, device, article or method including the element.
[0128] The serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments. Through the description of the above implementation modes, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware, but in many cases the former is a better implementation mode. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, including a number of instructions to enable a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0129] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A multi-attribute text matching method, characterized in that: The method comprises: Acquire a first text and a second text to be matched, wherein the first text and the second text each contain at least one attribute field, and each attribute field corresponds to a subtext; Respectively calculating candidate common continuous subsequences of subtexts corresponding to each group of the same attribute fields in the first text and the second text, and obtaining the character length of each candidate common continuous subsequence; Obtaining the position difference of each candidate common continuous subsequence in the corresponding two different subtexts; the obtaining the position difference of each candidate common continuous subsequence in the corresponding two different subtexts includes obtaining the first position and the second position of each candidate common continuous subsequence in the corresponding two different subtexts, and obtaining the position difference corresponding to each candidate common continuous subsequence according to the first position and the second position, wherein the position difference is specifically the absolute value of the difference between the first position and the second position of the same candidate common continuous subsequence in the corresponding two different subtexts; Based on the preset screening rule, the character length of each candidate public continuous subsequence and the corresponding position difference, the target public continuous subsequence corresponding to each group of the same attribute field is screened out; Based on the preset screening rule, the character length of each candidate public continuous subsequence and the corresponding position difference, the target public continuous subsequence corresponding to each group of the same attribute field is screened out, including: removing the candidate public continuous subsequences whose position difference is greater than the distance threshold, and respectively screening the candidate public continuous subsequences with the longest character length or the shortest position difference from the remaining other candidate public continuous subsequences of each group of the same attribute field, and taking the candidate public continuous subsequences with the longest character length or the shortest position difference as the target public continuous subsequence corresponding to the same attribute field; Calculating the similarity of the two subtexts corresponding to each group of the same attribute fields according to the character lengths of the two subtexts corresponding to the same attribute fields and the character lengths of the corresponding target common continuous subsequences; Calculating the similarity of the two subtexts corresponding to each group of the same attribute fields according to the character lengths of the two subtexts corresponding to the same attribute fields and the character lengths of the corresponding target common continuous subsequences, including calculating the similarity of the two subtexts corresponding to the same attribute fields in which the target common continuous subsequence exists according to the character lengths of the two subtexts corresponding to the same attribute fields and the character lengths of the corresponding target common continuous subsequences; According to the similarity, a matching degree between the first text and the second text is obtained.
2. The method according to claim 1, characterized in that After screening out the target common continuous subsequences corresponding to each group of identical attribute fields, the method further includes: The similarity between two subtexts of the same attribute field without a target common continuous subsequence is determined as a preset value.
3. The method according to claim 1, characterized in that Before respectively calculating the candidate common continuous subsequences of the subtexts corresponding to each group of the same attribute fields in the first text and the second text, the method further includes: A filtering process is performed on each of the sub-texts to filter out irrelevant characters in each of the sub-texts.
4. The method according to any one of claims 1 to 3, characterized in that: The obtaining, according to the similarity, a matching degree between the first text and the second text includes: The target weight of each attribute field in the same attribute field corresponding to the similarity is obtained, and the matching degree between the first text and the second text is obtained according to the target weight and the similarity.
5. The method according to any one of claims 1 to 3, characterized in that: The obtaining, according to the similarity, a matching degree between the first text and the second text includes: An average of all the similarities is calculated to obtain a matching degree between the first text and the second text.
6. The method according to claim 4, characterized in that The obtaining of the target weight of each attribute field in the same attribute field corresponding to the similarity includes: Generate multiple groups of weight value sets according to the preset value range of the weight of each attribute field in the same attribute field corresponding to the similarity, wherein the sum of all the candidate weights in each group of the weight value sets is 1, and each group of the weight value sets contains a candidate weight corresponding to each attribute field in the same attribute field corresponding to the similarity; Calculate the weighted mean variance corresponding to each set of the weight value sets according to the similarity and the selected weights in each set of the weight value sets; The selected weight in the weight value set corresponding to the minimum weighted mean variance is used as the target weight of the corresponding attribute field in the same attribute field corresponding to the similarity.
7. A multi-attribute text matching device, characterized in that: The device comprises: A text acquisition module, used for acquiring a first text and a second text to be matched, wherein the first text and the second text each contain at least one attribute field, and each attribute field corresponds to a subtext; A first calculation module is used to calculate candidate common continuous subsequences of subtexts corresponding to each group of the same attribute fields in the first text and the second text, respectively, and obtain the character length of each candidate common continuous subsequence; A position difference acquisition module, used for acquiring the position difference of each candidate common continuous subsequence in two corresponding different subtexts; The position difference acquisition module is specifically used to acquire the first position and the second position of each candidate common continuous subsequence in the corresponding two different subtexts, and obtain the position difference corresponding to each candidate common continuous subsequence according to the first position and the second position, wherein the position difference is specifically the absolute value of the difference between the first position and the second position of the same candidate common continuous subsequence in the corresponding two different subtexts; A screening module is used to screen out a target public continuous subsequence corresponding to each group of the same attribute field based on a preset screening rule, the character length of each candidate public continuous subsequence and the corresponding position difference; the screening module includes a removal unit, a screening unit and a determination unit, the removal unit is used to remove the candidate public continuous subsequences whose position difference is greater than a distance threshold; the screening unit is used to screen out the candidate public continuous subsequences with the longest character length or the shortest position difference from the remaining other candidate public continuous subsequences of each group of the same attribute field; the determination unit is used to use the candidate public continuous subsequence with the longest character length or the shortest position difference as the target public continuous subsequence corresponding to the same attribute field; The second calculation module is used to calculate the similarity of the two subtexts corresponding to each group of the same attribute field according to the character lengths of the two subtexts corresponding to the same attribute field and the character lengths of the corresponding target common continuous subsequences; the second calculation module is specifically used to calculate the similarity of the two subtexts corresponding to the same attribute field in which the target common continuous subsequence exists according to the character lengths of the two subtexts corresponding to the same attribute field and the character lengths of the corresponding target common continuous subsequences; The third calculation module is used to obtain the matching degree between the first text and the second text according to the similarity.
8. A computer device comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the computer-readable instructions, the processor performs the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having computer-readable instructions stored thereon, characterized in that: When the computer readable instructions are executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Text similarity determination method and device, equipment and storage medium
CN112149414A