Text difference degree calculation method and system

By using a method to calculate text differences based on text length and Levenstein distance, the problem of slow manual comparison when dealing with large amounts of text data is solved, and the effect of quickly understanding the degree of text differences is achieved.

CN115455933BActive Publication Date: 2026-03-27TRANSN IOL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-13
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

When dealing with very large amounts of text data, manually comparing the differences between texts is slow, cumbersome, and makes it difficult to quickly understand the degree of difference between texts.

Method used

This paper proposes a method and system for calculating text dissimilarity by calculating the dissimilarity between texts based on the length of the text to be compared and the target Levenstein distance. The method involves segmenting the text into paragraphs or sentences and using the Levenstein distance to calculate the dissimilarity between the texts.

Benefits of technology

It improves the efficiency of text difference calculation, enabling a quick understanding of the degree of difference between texts to be compared, and simplifies the complexity of clustering algorithms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115455933B_ABST
    Figure CN115455933B_ABST
Patent Text Reader

Abstract

The application provides a text difference degree calculation method and system, and the method comprises the following steps: obtaining the length of a first text and the length of a second text; in the case that the length of the first text and the length of the second text satisfy a first preset condition, calculating the difference degree between the first text and the second text according to a target Levenshtein distance between the first text and the second text, the length of the first text and the length of the second text. The application calculates the difference degree between the texts to be compared based on the length of the texts to be compared and the target Levenshtein distance, solves the problems of slow manual comparison speed and complicated operation in the case that the amount of text data is very large, improves the calculation efficiency of the difference degree of the texts to be compared, and enables the user to quickly understand the difference degree between the texts to be compared.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of natural language processing, and particularly relates to a text difference degree calculation method and system. BACKGROUND

[0002] With the continuous development and application of Internet technology, the amount of text data is also growing, and the development of computer technology makes the amount of text data grow exponentially. Under this background, using text differentiation comparison technology to analyze text data can put similar texts together, so that humans can more effectively obtain the required text when searching for text.

[0003] In the case of a large amount of text data, manual comparison of the difference degree of text is slow and cumbersome, making it difficult for users to understand the difference degree between texts in a short period of time. SUMMARY

[0004] The text difference degree calculation method and system provided by the present application solve the above problems in the prior art by calculating the difference degree between the texts to be compared based on the length of the texts to be compared and the target Levenshtein distance, thereby solving the problem of slow manual comparison and cumbersome operation in the case of a large amount of text data, improving the calculation efficiency of the difference degree of the texts to be compared, and enabling users to quickly understand the difference degree between the texts to be compared.

[0005] The text difference degree calculation method provided by the present application comprises:

[0006] obtaining the length of a first text and the length of a second text;

[0007] in the case that the length of the first text and the length of the second text satisfy a first preset condition, calculating the difference degree between the first text and the second text according to the target Levenshtein distance between the first text and the second text, the length of the first text, and the length of the second text;

[0008] wherein the first preset condition is that the length of the first text and the length of the second text are both not equal to a first preset value, and the length of the first text is not equal to the length of the second text or the length of the first text is equal to the length of the second text.

[0009] The application provides a text difference degree calculation method, which comprises the following steps: when the length of the first text and the length of the second text are both not equal to a first preset value, and the length of the first text is not equal to the length of the second text, calculating the difference degree between the first text and the second text according to the length of the first text, the length of the second text and a target Levenshtein distance between the first text and the second text.

[0010] The first text and the second text are spliced into a string respectively to obtain a first string corresponding to the first text and a second string corresponding to the second text.

[0011] The Levenshtein distance between the first string and the second string is taken as the target Levenshtein distance.

[0012] The difference degree is calculated according to the length of the first text, the length of the second text and the target Levenshtein distance.

[0013] The application provides a text difference degree calculation method, which comprises the following steps: when the length of the first text and the length of the second text are both not equal to a first preset value, and the length of the first text is not equal to the length of the second text, calculating the difference degree between the first text and the second text according to the length of the first text, the length of the second text and a target Levenshtein distance between the first text and the second text.

[0014] The Levenshtein distance between the first text and the second text is taken as the target Levenshtein distance.

[0015] The Levenshtein distance between the first text and the second text is taken as the target Levenshtein distance.

[0016] The difference degree is calculated according to the length of the first text, the length of the second text and the target Levenshtein distance.

[0017] According to the text difference degree calculation method provided by the application, in the case that the length of the first text and the length of the second text are not equal to the first preset value, and the length of the first text is equal to the length of the second text, the first text and the second text are calculated according to the length of the first text, the length of the second text and the target Levenshtein distance between the first text and the second text, and the difference degree of the first text and the second text further comprises:

[0018] The Levenshtein distance between any paragraph in the first text and the paragraph at the second target position in the second text is calculated, and the maximum value of the length of the fifth string and the length of the sixth string is determined, the second target position is the same position as the position of any paragraph in the first text in the first text, the fifth string is the string corresponding to any paragraph in the first text, and the sixth string is the string corresponding to the paragraph at the second target position in the second text.

[0019] The sum of the Levenshtein distance between each paragraph in the first text and each paragraph in the second text is taken as the target Levenshtein distance, and the maximum value of the length of the fifth string corresponding to each paragraph in the first text and the length of the sixth string corresponding to each paragraph in the second text is taken as the sum of the length of the first text and the length of the second text.

[0020] According to the target Levenshtein distance and the sum of the length of the first text and the length of the second text, the difference degree is calculated.

[0021] According to the text difference degree calculation method provided by the application, the first preset condition comprises:

[0022] The length of the first text or the length of the second text is equal to the second preset value.

[0023] According to the text difference degree calculation method provided by the application, the method further comprises:

[0024] In the case that the length of the first text and the length of the second text satisfy the second preset condition, the difference degree of the first text and the second text is determined as the second preset value.

[0025] The first preset condition is that the length of the first text or the length of the second text is equal to the first preset value.

[0026] The application further provides a text difference degree calculation system, comprising a data acquisition module and a first calculation module.

[0027] The data acquisition module is configured to acquire a length of the first text and a length of the second text.

[0028] The first calculation module is configured to calculate a difference degree between the first text and the second text according to a target Levenshtein distance between the first text and the second text, the length of the first text and the length of the second text, when the length of the first text and the length of the second text satisfy a first preset condition.

[0029] The first preset condition is that the length of the first text and the length of the second text are both not equal to a first preset value, and the length of the first text is not equal to the length of the second text or the length of the first text is equal to the length of the second text.

[0030] According to the text difference degree calculation system provided by the application, the system further comprises:

[0031] The second calculation module is configured to determine that the difference degree between the first text and the second text is a second preset value when the length of the first text and the length of the second text satisfy a second preset condition.

[0032] The second preset condition is that the length of the first text or the length of the second text is equal to the first preset value.

[0033] The application further provides an electronic device comprising a processor and a memory storing a computer program, wherein the processor implements the text difference degree calculation method according to any one of the above-mentioned methods when executing the program.

[0034] The application further provides a non-transitory computer readable storage medium storing a computer program, wherein the computer program is executed by a processor to implement the text difference degree calculation method according to any one of the above-mentioned methods.

[0035] The application further provides a computer program product comprising a computer program, wherein the computer program is executed by a processor to implement the text difference degree calculation method according to any one of the above-mentioned methods.

[0036] The text difference degree calculation method and system provided by the application calculate the difference degree between the texts to be compared based on the lengths of the texts to be compared and the target Levenshtein distance, solve the problems of slow manual comparison speed and complicated operation in the case of very large amount of text data, improve the calculation efficiency of the difference degree between the texts to be compared, and enable the user to quickly understand the difference degree between the texts to be compared. BRIEF DESCRIPTION OF DRAWINGS

[0037] In order to more clearly illustrate the technical solutions of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings described below are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort based on these drawings.

[0038] Figure 1 is a flowchart of the text difference degree calculation method provided by the present application;

[0039] Figure 2 is a structural diagram of the text difference degree calculation system provided by the present application;

[0040] Figure 3 is a physical structure diagram of the electronic device provided by the present application. DETAILED DESCRIPTION

[0041] In order to make the objects, technical solutions and advantages of the present application clearer, the technical solutions of the present application will be described clearly and completely below with reference to the drawings in the present application. Obviously, the described embodiments are only some embodiments of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present application.

[0042] Figure 1 is a flowchart of the text difference degree calculation method provided by the present application, as shown in Figure 1 , the method comprises:

[0043] Step 110, obtaining the length of the first text and the length of the second text;

[0044] Step 120, in the case that the length of the first text and the length of the second text satisfy a first preset condition, calculating the difference degree between the first text and the second text according to the target Levenshtein distance between the first text and the second text, the length of the first text and the length of the second text;

[0045] Wherein, the first preset condition is that the length of the first text and the length of the second text are not equal to a first preset value, and the length of the first text is not equal to the length of the second text or the length of the first text is equal to the length of the second text.

[0046] It should be noted that the execution subject of the above method can be a computer device.

[0047] In the embodiment of the present application, the first text and the second text can be specifically texts obtained after segmenting the texts to be compared, and more specifically texts obtained after segmenting or dividing the texts to be compared.

[0048] In the embodiment of the present application, the length of the first text can be specifically the total number of sentences in the first text, or the total number of paragraphs in the first text. The length of the second text can be specifically the total number of sentences in the second text, or the total number of paragraphs in the second text.

[0049] In the embodiment of the present application, in the case that the length of the first text and the length of the second text satisfy the first preset condition, the difference between the first text and the second text can be calculated according to the target Levenshtein distance between the first text and the second text, the length of the first text and the length of the second text. The target Levenshtein distance can be specifically the Levenshtein distance between the string included in each sentence in the first text and the string included in each sentence in the second text, or the Levenshtein distance between the string included in each paragraph in the first text and the string included in each paragraph in the second text.

[0050] In the embodiment of the present application, the second preset condition can be specifically that the length of the first text and the length of the second text are not equal to the first preset value, and the length of the first text and the length of the second text are not equal (i.e., the total number of paragraphs in the first text and the total number of paragraphs in the second text are not the same, or the total number of sentences in the first text and the total number of sentences in the second text are not the same), or that the length of the first text and the length of the second text are not equal to the second preset value, and the length of the first text and the length of the second text are equal (i.e., the total number of paragraphs in the first text and the total number of paragraphs in the second text are the same, or the total number of sentences in the first text and the total number of sentences in the second text are the same), and the first preset value can be specifically 0.

[0051] For example, the texts to be compared text1 and text2 are segmented to obtain the first text T1 and the second text T2, wherein the paragraph lists in the first text and the second text are respectively: T1=[t11, t12, t13,...], T2=[t21, t22, t23,...], wherein t11, t12, t13,... represent each paragraph in T1; t21, t22, t23,... represent each paragraph in T2. The total number of paragraphs included in T1 and T2 can be obtained, and the total number of paragraphs in T1 is taken as the length of the first text, denoted as Len1, and the total number of paragraphs in T2 is taken as the length of the second text, denoted as Len2.

[0052] For example, the texts text1 and text2 to be compared are segmented into sentences to obtain a first text T3 and a second text T4, where the lists of sentences in the first and second texts are respectively: T3=[t111, t121, t131,...], T4=[t211, t221, t231,...], where t111, t121, t131,... represent the respective sentences in T3, and t211, t221, t231,... represent the respective sentences in T4. The total number of sentences included in T3 and T4 can be obtained, and the total number of sentences in T3 is taken as the length of the first text, denoted as Len3, and the total number of sentences in T4 is taken as the length of the second text, denoted as Len4.

[0053] Taking the first text as T1 and the second text as T2 as an example, if Len1=0 or Len2=0, then the difference degree diffValue between the first text T1 and the second text T2 is 1. The first preset condition can be specifically Len1≠0, Len2≠0 and Len1≠Len2, or can be specifically Len1≠0, Len2≠0 and Len1=Len2.

[0054] Further, in an embodiment, the method can further specifically include:

[0055] In a case where the length of the first text and the length of the second text satisfy a second preset condition, determining that the difference degree between the first text and the second text is a second preset value.

[0056] The first preset condition is that the length of the first text or the length of the second text is equal to a first preset value. In the embodiment of the application, in a case where the length of the first text and the length of the second text satisfy the second preset condition, the second preset value is taken as the difference degree between the first text and the second text. The second preset value can be specifically used to describe the difference degree between the first text and the second text, for example, the second preset value is 1, representing that the difference degree between the first text and the second text is the largest, and the second preset value is 0, representing that the difference degree between the first text and the second text is the smallest.

[0057] In the embodiment of the application, the second preset condition can be specifically that the length of one of the length of the first text and the length of the second text is equal to the first preset value, and the first preset value can be specifically set to 0. In a case where the first preset value is 0, the second preset value can be specifically 1.

[0058] The text difference degree calculation method provided by the application calculates the difference degree between the texts to be compared based on the lengths of the texts to be compared and a target Levenshtein distance, solves the problems of slow manual comparison and complicated operation in the case of very large text data, improves the calculation efficiency of the difference degree of the texts to be compared, and enables the user to quickly understand the difference degree between the texts to be compared.

[0059] Further, in one embodiment, when the length of the first text and the length of the second text are both not equal to the first preset value, and the length of the first text is not equal to the length of the second text, the calculation of the difference degree between the first text and the second text according to the length of the first text, the length of the second text and the target Levenshtein distance between the first text and the second text can specifically include:

[0060] The first text and the second text are spliced into a string respectively to obtain a first string corresponding to the first text and a second string corresponding to the second text;

[0061] The Levenshtein distance between the first string and the second string is taken as the target Levenshtein distance;

[0062] The difference degree is calculated according to the length of the first text, the length of the second text and the target Levenshtein distance.

[0063] In the embodiment of the application, when the length of the first text and the length of the second text are both not equal to 0, and the length of the first text is not equal to the length of the second text, the characters included in each sentence or each paragraph in the first text are spliced in order to obtain a string corresponding to the first text, i.e., a first string, and the characters included in each sentence or each paragraph in the second text are spliced in order to obtain a string corresponding to the second text, i.e., a second string.

[0064] In the embodiment of the application, the Levenshtein distance between the first string and the second string can specifically refer to the Levenshtein distance between the first string and the second string after the characters in the first string and the second string are replaced into meta characters according to the difference of languages. For example, one word of English or other western characters is replaced into one meta character, and Chinese, Japanese and Korean characters do not need to be replaced.

[0065] In the embodiment of the application, the Levenshtein distance between the first string and the second string after the replacement is taken as the target Levenshtein distance.

[0066] In the embodiment of the present application, the character length in the first string is taken as the length of the first text, the character length in the second string is taken as the length of the second text, and the maximum of the length of the first text and the length of the second text is obtained. The difference degree can be specifically obtained based on the target Levenshtein distance and the maximum, and more specifically can be the quotient of the target Levenshtein distance and the maximum.

[0067] For example, in the case of len1≠0, len2≠0 and len1≠len2, then the respective paragraphs in the first text T1 and the second text T2 are spliced into a string respectively to obtain the first string S1 and the second string S2, the Levenshtein distance distance between the first string S1 and the second string S2 is calculated, the maximum maxLen of the character length in the first string S1 and the second string S2 is determined, and then the difference degree diffValue between the first text T1 and the second text T2 is calculated.

[0068] The method for calculating the text difference degree provided by the present application fully utilizes the semantic information of the text, can quickly calculate the difference degree between the texts to be compared, and has simple algorithm principle and is relatively easy to implement.

[0069] Further, in one embodiment, in the case that the length of the first text and the length of the second text are both not equal to a first preset value, and the length of the first text is equal to the length of the second text, the calculating of the difference degree between the first text and the second text according to the length of the first text, the length of the second text and the target Levenshtein distance between the first text and the second text comprises:

[0070] traversing each sentence in the first text, calculating the Levenshtein distance between any sentence in the first text and the sentence at a first target position in the second text, and determining the maximum of the lengths of a third string and a fourth string, the first target position being the same position as the position of any sentence in the first text in the first text, the third string being the string corresponding to any sentence in the first text, and the fourth string being the string corresponding to the sentence at the first target position in the second text;

[0071] taking the sum of the Levenshtein distances between each sentence in the first text and each sentence in the second text as the target Levenshtein distance, and taking the sum of the maximum of the lengths of the third string corresponding to each sentence in the first text and the fourth string corresponding to each sentence in the second text as the sum of the length of the first text and the length of the second text;

[0072] The difference degree is calculated according to the target Levenshtein distance and the sum of the length of the first text and the length of the second text.

[0073] In the embodiment of the present application, when the length of the first text and the length of the second text are both not equal to 0 and the length of the first text is equal to the length of the second text, for the first text and the second text obtained by dividing the text into sentences, the Levenshtein distance between any sentence in the first text and the sentence at the first target position in the second text can be specifically the Levenshtein distance between the string corresponding to the any sentence and the string corresponding to the sentence at the first target position in the second text. The first target position can be specifically the sentence in the second text which is at the same position as the position of the any sentence in the first text. The position of the any sentence in the first text can be specifically the order of the total sentences in the first text before and after the sentence, for example, the position of the first sentence in the first text and the second text can be recorded as 1, the position of the second sentence in the first text and the second text can be recorded as 2, and so on.

[0074] In the embodiment of the present application, the maximum value can be specifically the maximum value of the length of the third string and the length of the fourth string, the third string can be specifically the string corresponding to any sentence in the first text, and the fourth string can be specifically the string corresponding to the sentence at the first target position in the second text.

[0075] In the embodiment of the present application, the Levenshtein distance between each sentence in the first text and each sentence in the second text can be specifically obtained by calculating the Levenshtein distance between any sentence in the first text and the sentence at the first target position in the second text, and traversing each sentence in the first text to obtain the Levenshtein distance between each sentence in the first text and each sentence in the second text. It should be noted that when calculating the Levenshtein distance between any sentence in the first text and the sentence at the first target position in the second text, the characters corresponding to any sentence and the sentence at the first target position need to be replaced into meta characters according to the language before calculation.

[0076] In the embodiment of the present application, the target Levenshtein distance can be specifically obtained by adding the Levenshtein distance between each sentence in the first text and each sentence in the second text.

[0077] In the embodiment of the present application, the difference degree can be specifically the quotient of the target Levenshtein distance and the sum of the length of the first text and the length of the second text, and the sum of the length of the first text and the length of the second text can be specifically obtained by adding the maximum value of the length of the third string corresponding to each sentence in the first text and the length of the fourth string corresponding to each sentence in the second text.

[0078] For example, in the case of len3≠0 and len4≠0 and len3=len4, the calculation of the difference degree between the first text T3 and the second text T4 can be specifically to sequentially calculate the Levenshtein distance between each sentence in the first text T3 and the sentence at the first target position in the second text T4, and the maximum value of the character length of the third string corresponding to each sentence in the first text T3 and the fourth string corresponding to the sentence at the first target position in the second text T4. For example, sequentially calculate the Levenshtein distance distance1 of t111, t211; the Levenshtein distance distance2 of t121, t221; the Levenshtein distance distance3 of t131, t231; and the maximum value maxLen1 of the character length corresponding to t111, t211; the maximum value maxLen2 of the character length corresponding to t121, t221; the maximum value maxLen3 of the character length corresponding to t131, t231; and so on. Thus, the target Levenshtein distance totalDistance=distance1+distance2+distance3...; the sum of the lengths of the first text T3 and the second text T4 totalMaxLen=maxLen1+maxLen2+maxLen3...; and the difference degree diffValue of the first text T3 and the second text T4 totalMaxLen=totalDistance / totalMaxLen.

[0079] Further, in one embodiment, in the case that the length of the first text and the length of the second text are both not equal to the first preset value, and the length of the first text is equal to the length of the second text, the calculation of the difference degree of the first text and the second text according to the length of the first text, the length of the second text, and the target Levenshtein distance between the first text and the second text further comprises:

[0080] traversing each paragraph in the first text, calculating the Levenshtein distance between any paragraph in the first text and the paragraph at the second target position in the second text, and determining the maximum value of the lengths of the fifth string and the sixth string, the second target position being the same position as the position of any paragraph in the first text in the first text, the fifth string being the string corresponding to any paragraph in the first text, and the sixth string being the string corresponding to the paragraph at the second target position in the second text;

[0081] Sum the Levenshtein distance between each paragraph in the first text and each paragraph in the second text as the target Levenshtein distance, and the maximum value of the length of the fifth string corresponding to each paragraph in the first text and the length of the sixth string corresponding to each paragraph in the second text as the sum of the length of the first text and the length of the second text;

[0082] According to the target Levenshtein distance and the sum of the length of the first text and the length of the second text, calculate the difference degree.

[0083] In the embodiment of the application, when the length of the first text and the length of the second text are both not equal to 0, and the length of the first text is equal to the length of the second text, for the first text and the second text segmented from the text, the Levenshtein distance between any paragraph in the first text and the paragraph at the second target position in the second text can be specifically the Levenshtein distance between the string corresponding to the any paragraph and the string corresponding to the paragraph at the second target position in the second text. The second target position can be specifically the paragraph in the second text at the same position as the position of the any paragraph in the first text. The position of the any paragraph in the first text can be specifically the front and back order of the total paragraphs in the first text, for example, the position of the first paragraph in the first text and the second text can be recorded as 1, the second paragraph in the first text and the second text can be recorded as 2, and so on.

[0084] In the embodiment of the application, the maximum value can be specifically the maximum value of the character length in the fifth string and the character length in the sixth string, the fifth string can be specifically the string corresponding to any paragraph in the first text, and the sixth string can be specifically the string corresponding to the sentence at the second target position in the second text.

[0085] In the embodiment of the application, the Levenshtein distance between each paragraph in the first text and each paragraph in the second text can be specifically obtained by calculating the Levenshtein distance between any paragraph in the first text and the paragraph at the second target position in the second text, and traversing each paragraph in the first text to obtain the Levenshtein distance between each paragraph in the first text and each paragraph in the second text. It should be noted that when calculating the Levenshtein distance between any paragraph in the first text and the paragraph at the second target position in the second text, the characters corresponding to any paragraph and the paragraph at the second target position need to be replaced into meta characters according to the language before calculation.

[0086] In the embodiment of the application, the target Levenshtein distance can be specifically obtained by adding the Levenshtein distance between each paragraph in the first text and each paragraph in the second text.

[0087] In the embodiment of the present application, the difference degree can be specifically the target Levenshtein distance and the quotient of the sum of the length of the first text and the length of the second text, and the sum of the length of the fifth string corresponding to each paragraph in the first text and the length of the sixth string corresponding to each paragraph in the second text can be specifically obtained by adding the maximum value of the length of the fifth string corresponding to each paragraph in the first text and the length of the sixth string corresponding to each paragraph in the second text.

[0088] For example, in the case of len1≠0 and len2≠0 and len1=len2, the difference degree between the first text T1 and the second text T2 can be specifically calculated by sequentially calculating the Levenshtein distance between each sentence in the first text T1 and the paragraph at the second target position in the second text T2, and the maximum value of the character length of the fifth string corresponding to each paragraph in the first text T3 and the sixth string corresponding to the paragraph at the second target position in the second text T4. For example, sequentially calculate the Levenshtein distance distance4 of t11, t21; the Levenshtein distance distance5 of t12, t22; the Levenshtein distance distance6 of t13, t23; and the maximum value of the character length maxLen4 of t11, t21; the maximum value of the character length maxLen5 of t12, t22; the maximum value of the character length maxLen6 of t13, t23. Thus, the target Levenshtein distance totalDistance1=distance4+distance5+distance6...; the sum of the lengths of the first text T1 and the second text T2 totalMaxLen1=maxLen4+maxLen5+maxLen6...; and the difference degree diffValue1 of the first text T1 and the second text T2 totalDistance1 / totalMaxLen1.

[0089] The text difference degree calculation method provided by the present application fully utilizes the semantic information of the text, can quickly calculate the difference degree between the texts to be compared, and can maximize the similarity of the texts by using the difference degree, thereby simplifying the algorithm complexity of clustering.

[0090] The text difference degree calculation system provided by the present application is described below, and the text difference degree calculation system described below can be correspondingly referred to the text difference degree calculation method described above.

[0091] Figure 2 is a structural schematic diagram of the text difference degree calculation system provided by the present application, as Figure 2 shown, comprising:

[0092] a data acquisition module 210 and a first calculation module 211;

[0093] The data acquisition module is configured to acquire the length of the first text and the length of the second text.

[0094] The first calculation module is configured to calculate the difference degree between the first text and the second text according to the target Levenshtein distance between the first text and the second text, the length of the first text and the length of the second text, when the length of the first text and the length of the second text satisfy a first preset condition.

[0095] The first preset condition is that the length of the first text and the length of the second text are both not equal to a first preset value, and the length of the first text is not equal to the length of the second text or the length of the first text is equal to the length of the second text.

[0096] Further, in an embodiment, the system can further specifically include:

[0097] The second calculation module 212 is configured to determine that the difference degree between the first text and the second text is a second preset value when the length of the first text and the length of the second text satisfy a second preset condition.

[0098] The second preset condition is that the length of the first text or the length of the second text is equal to the first preset value.

[0099] The text difference degree calculation system provided by the application calculates the difference degree between the texts to be compared based on the length of the texts to be compared and the target Levenshtein distance, solves the problem of slow manual comparison speed and complicated operation in the case of very large amount of text data, improves the calculation efficiency of the difference degree of the texts to be compared, and enables the user to quickly understand the difference degree between the texts to be compared.

[0100] Figure 3 is a schematic diagram of an entity structure of an electronic device provided by the application, as shown in Figure 3 The electronic device can include a processor 310, a communication interface 311, a memory 312 and a bus 313, wherein the processor 310, the communication interface 311 and the memory 312 can communicate with each other through the bus 313. The processor 310 can call the logical instructions in the memory 312 to execute the following method:

[0101] Acquire the length of the first text and the length of the second text.

[0102] In a case where the length of the first text and the length of the second text satisfy a first preset condition, a difference degree between the first text and the second text is calculated according to a target Levenshtein distance between the first text and the second text, the length of the first text, and the length of the second text.

[0103] The first preset condition is that the length of the first text and the length of the second text are not equal to a first preset value, and the length of the first text is not equal to the length of the second text or the length of the first text is equal to the length of the second text.

[0104] In addition, the logic instructions in the memory described above can be implemented in the form of a software functional unit and sold or used as an independent product, and can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the parts that contribute to the prior art or parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer power supply screen (which can be a personal computer, a server, or a network power supply screen) to execute all or part of the steps of the method described in the various embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0105] Further, the present application discloses a computer program product, the computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, enable the computer to perform the text difference degree calculation method provided by the above-mentioned method embodiments, for example comprising:

[0106] obtaining the length of the first text and the length of the second text;

[0107] In a case where the length of the first text and the length of the second text satisfy a first preset condition, a difference degree between the first text and the second text is calculated according to a target Levenshtein distance between the first text and the second text, the length of the first text, and the length of the second text.

[0108] The first preset condition is that the length of the first text and the length of the second text are not equal to a first preset value, and the length of the first text is not equal to the length of the second text or the length of the first text is equal to the length of the second text.

[0109] In another aspect, the present application also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method for calculating the text difference degree provided by the above-mentioned embodiments, for example comprising:

[0110] obtaining the length of the first text and the length of the second text;

[0111] in the case where the length of the first text and the length of the second text satisfy a first preset condition, calculating the difference degree between the first text and the second text according to the target Levenshtein distance between the first text and the second text, the length of the first text and the length of the second text;

[0112] wherein the first preset condition is that the length of the first text and the length of the second text are both not equal to a first preset value, and the length of the first text is not equal to the length of the second text or the length of the first text is equal to the length of the second text.

[0113] The system embodiments described above are only illustrative, wherein the units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, i.e. they can be located in one place or distributed on multiple network units. Part or all of the modules can be selected to achieve the purpose of the embodiment according to actual needs. Those skilled in the art can understand and implement without creative labor.

[0114] From the above description of the embodiments, those skilled in the art can clearly understand that the embodiments can be realized by means of software plus necessary general hardware platforms, and of course can also be realized by hardware. Based on such understanding, the above technical solutions, essentially or in terms of the contribution to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a plurality of instructions for causing a computer power supply screen (which can be a personal computer, a server, or a network power supply screen, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0115] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements to some technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method of calculating a degree of difference of text, characterized by, The method comprises the following steps: obtaining the length of the first text and the length of the second text, wherein the length of the first text is the total number of sentences in the first text or the total number of paragraphs in the first text, and the length of the second text is the total number of sentences in the second text or the total number of paragraphs in the second text; in the case that the length of the first text and the length of the second text satisfy a first preset condition, calculating the difference degree between the first text and the second text according to a target Levenshtein distance between the first text and the second text, the length of the first text and the length of the second text, wherein the target Levenshtein distance is the Levenshtein distance between the string included in each sentence in the first text and the string included in each sentence in the second text, or the Levenshtein distance between the string included in each paragraph in the first text and the string included in each paragraph in the second text; wherein the first preset condition is that the length of the first text and the length of the second text are not equal to a first preset value, and the length of the first text is not equal to the length of the second text or the length of the first text is equal to the length of the second text; the target Levenshtein distance is: if the length of the first text is not equal to the length of the second text, the Levenshtein distance between the string formed by sequentially splicing each sentence or paragraph in the first text and the string formed by sequentially splicing each sentence or paragraph in the second text, and the difference degree = the target Levenshtein distance / the maximum value of the two spliced strings; if the length of the first text is equal to the length of the second text, the sum of the Levenshtein distances between each sentence or paragraph in the first text and the same position sentence or paragraph in the second text, and the difference degree = the target Levenshtein distance / the sum of the maximum string lengths of each corresponding sentence or paragraph in the first text and the second text.

2. The method of claim 1, wherein, in the case that the length of the first text and the length of the second text are not equal to the first preset value, and the length of the first text is not equal to the length of the second text, the calculating the difference degree between the first text and the second text according to the length of the first text, the length of the second text and the target Levenshtein distance between the first text and the second text comprises: splicing the first text and the second text into a string respectively to obtain a first string corresponding to the first text and a second string corresponding to the second text; taking the Levenshtein distance between the first string and the second string as the target Levenshtein distance; calculating the difference degree according to the length of the first text, the length of the second text and the target Levenshtein distance.

3. The method of claim 1, wherein, In a case that the length of the first text and the length of the second text are not equal to the first preset value, and the length of the first text is equal to the length of the second text, the calculating the difference degree between the first text and the second text according to the length of the first text, the length of the second text and the target Levenshtein distance between the first text and the second text comprises: traversing each sentence in the first text, calculating the Levenshtein distance between any sentence in the first text and the sentence at the first target position in the second text, and determining the maximum value of the lengths of the third string and the fourth string, the first target position being the same position as the position of any sentence in the first text in the first text, the third string being the string corresponding to any sentence in the first text, and the fourth string being the string corresponding to the sentence at the first target position in the second text; taking the sum of the Levenshtein distances between each sentence in the first text and each sentence in the second text as the target Levenshtein distance, and taking the sum of the maximum values of the lengths of the third string corresponding to each sentence in the first text and the fourth string corresponding to each sentence in the second text as the sum of the length of the first text and the length of the second text; calculating the difference degree according to the target Levenshtein distance and the sum of the length of the first text and the length of the second text.

4. The method of claim 1, wherein, In a case that the length of the first text and the length of the second text are not equal to the first preset value, and the length of the first text is equal to the length of the second text, the calculating the difference degree between the first text and the second text according to the length of the first text, the length of the second text and the target Levenshtein distance between the first text and the second text further comprises: traversing each paragraph in the first text, calculating the Levenshtein distance between any paragraph in the first text and the paragraph at the second target position in the second text, and determining the maximum value of the lengths of the fifth string and the sixth string, the second target position being the same position as the position of any paragraph in the first text in the first text, the fifth string being the string corresponding to any paragraph in the first text, and the sixth string being the string corresponding to the paragraph at the second target position in the second text; taking the sum of the Levenshtein distances between each paragraph in the first text and each paragraph in the second text as the target Levenshtein distance, and taking the sum of the maximum values of the lengths of the fifth string corresponding to each paragraph in the first text and the sixth string corresponding to each paragraph in the second text as the sum of the length of the first text and the length of the second text; calculating the difference degree according to the target Levenshtein distance and the sum of the length of the first text and the length of the second text.

5. The method of claim 1-4, wherein, The method further comprises: In a case where the length of the first text and the length of the second text satisfy a second preset condition, the difference degree of the first text and the second text is determined as a second preset value. The first preset condition is that the length of the first text or the length of the second text is equal to a first preset value.

6. A system for calculating the degree of difference of text, characterized by, The method comprises: a data acquisition module and a first calculation module; The data acquisition module is configured to acquire the length of the first text and the length of the second text, wherein the length of the first text is the total number of sentences in the first text or the total number of paragraphs in the first text, and the length of the second text is the total number of sentences in the second text or the total number of paragraphs in the second text. The first calculation module is configured to, in a case where the length of the first text and the length of the second text satisfy a first preset condition, calculate the difference degree of the first text and the second text according to a target Levenshtein distance between the first text and the second text, the length of the first text and the length of the second text, wherein the target Levenshtein distance is the Levenshtein distance between the string included in each sentence in the first text and the string included in each sentence in the second text, or the Levenshtein distance between the string included in each paragraph in the first text and the string included in each paragraph in the second text. The first preset condition is that the length of the first text and the length of the second text are not equal to the first preset value, and the length of the first text is not equal to the length of the second text or the length of the first text is equal to the length of the second text. The target Levenshtein distance is: If the length of the first text is not equal to the length of the second text, the Levenshtein distance between the string formed by sequentially splicing each sentence or paragraph in the first text and the string formed by sequentially splicing each sentence or paragraph in the second text, and the difference degree = the target Levenshtein distance / the maximum value of the two spliced strings. If the length of the first text is equal to the length of the second text, the sum of the Levenshtein distances between each sentence or paragraph in the first text and the same position sentence or paragraph in the second text, and the difference degree = the target Levenshtein distance / the sum of the maximum string lengths of the corresponding sentences or paragraphs in the first text and the second text.

7. The system for calculating text dissimilarity according to claim 6, wherein, The system further comprises: a second calculation module configured to, in a case where the length of the first text and the length of the second text satisfy a second preset condition, determine the difference degree of the first text and the second text as a second preset value. The second preset condition is that the length of the first text or the length of the second text is equal to the first preset value.

8. An electronic device comprising a processor and a memory having a computer program stored therein, characterized in that, The processor executes the computer program to realize the text difference degree calculation method of any one of claims 1 to 5. 9.A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to realize the text difference degree calculation method of any one of claims 1 to 5.

10. A computer program product comprising a computer program, characterized in that, The computer program, when executed by a processor, implements the method for calculating the text difference degree according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Computing method and device of text difference

    CN106897258A

  • Information sending method and device, terminal equipment and storage medium

    CN111930890A