Document comparison method, apparatus, device, and medium

By filtering candidate differences after parsing in document comparison technology and eliminating abnormal differences, the problem of inaccurate difference analysis caused by low parsing accuracy in document comparison is solved, and more accurate document comparison results are achieved.

CN115937891BActive Publication Date: 2026-02-27BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211742604.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-30
Publication Date
2026-02-27
Estimated Expiration
2042-12-30

AI Technical Summary

Technical Problem

Existing document comparison technologies are affected by the accuracy of document parsing, leading to inaccurate results in difference analysis.

Method used

By parsing the documents to be compared, candidate differences are identified, and abnormal differences are eliminated based on the information at the corresponding positions of the candidate differences in the documents, thereby improving the accuracy of the differences.

Benefits of technology

This improves the accuracy and effectiveness of document comparison, ensuring that the final identified differences do not solely depend on the parsing results, thus enhancing the accuracy of the differences.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115937891B_ABST
    Figure CN115937891B_ABST
Patent Text Reader

Abstract

The present disclosure provides a document comparison method, device, equipment and medium, relates to the field of artificial intelligence, in particular to the technical field of natural language processing and computer vision, and can be applied to the scene of OCR recognition and document comparison. The specific implementation scheme of the document comparison method is as follows: the two documents to be compared are parsed respectively to obtain the text elements included in each document to be compared and the position information of the text elements, which are taken as the parsing results of each document to be compared; at least one candidate difference content between the two documents to be compared is determined according to the parsing results of the two documents to be compared; and the abnormal difference content in the at least one candidate difference content is removed according to the information at the corresponding position of each candidate difference content in the two documents to be compared, to obtain the difference content between the two documents to be compared.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the field of artificial intelligence, in particular to the technical field of natural language processing and computer vision, and can be applied to the scene of OCR recognition and document comparison. BACKGROUND

[0002] With the development of computer technology and electronic technology, an electronic device can parse document text content by using a document comparison technology, and perform difference analysis on the document content. However, the difference analysis result is usually affected by the accuracy of document parsing. If the parsing accuracy is low, the difference analysis result is not accurate. SUMMARY

[0003] The present disclosure aims to provide a document comparison method, device, electronic equipment and storage medium which can improve the comparison effect.

[0004] According to one aspect of the present disclosure, a document comparison method is provided, comprising: parsing two documents to be compared respectively to obtain text elements included in each document to be compared and position information of the text elements as a parsing result of each document to be compared; determining at least one candidate difference content between the two documents to be compared according to the parsing results of the two documents to be compared; and eliminating abnormal difference content in the at least one candidate difference content according to information at positions corresponding to each candidate difference content in the two documents to be compared, to obtain difference content between the two documents to be compared.

[0005] According to another aspect of the present disclosure, a document comparison device is provided, comprising: a document parsing module configured to parse two documents to be compared respectively to obtain text elements included in each document to be compared and position information of the text elements as a parsing result of each document to be compared; a candidate difference determining module configured to determine at least one candidate difference content between the two documents to be compared according to the parsing results of the two documents to be compared; and a difference screening module configured to eliminate abnormal difference content in the at least one candidate difference content according to information at positions corresponding to each candidate difference content in the two documents to be compared, to obtain difference content between the two documents to be compared.

[0006] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the document comparison method provided by the present disclosure.

[0007] According to another aspect of the present disclosure, a non-transitory computer readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to perform the document comparison method provided by the present disclosure.

[0008] According to another aspect of the present disclosure, there is provided a computer program product comprising computer programs / instructions stored on at least one of a readable storage medium and an electronic device, which, when executed by a processor, implement the document comparison method provided by the present disclosure.

[0009] It should be understood that the contents described in this section are not intended to identify key or important features of the embodiments of the present disclosure, nor are they used to limit the scope of the present disclosure. Other features of the present disclosure will become apparent through the following description. BRIEF DESCRIPTION OF DRAWINGS

[0010] The accompanying drawings are used to better understand the present scheme, and do not limit the present disclosure. Among them:

[0011] Figure 1 is an application scenario diagram of the document comparison method and device according to the embodiments of the present disclosure;

[0012] Figure 2 is a flow diagram of the document comparison method according to the embodiments of the present disclosure;

[0013] Figure 3 is a principle diagram for determining candidate difference content according to the embodiments of the present disclosure;

[0014] Figure 4 is a principle diagram for eliminating abnormal difference content according to the embodiments of the present disclosure;

[0015] Figure 5 is a structural block diagram of the document comparison device according to the embodiments of the present disclosure; and

[0016] Figure 6 is a block diagram of an electronic device for implementing the document comparison method according to the embodiments of the present disclosure. DETAILED DESCRIPTION

[0017] Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, which include various details of the embodiments of the present disclosure to assist in understanding, and should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Also, in order to be clear and concise, the description below omits the description of well-known functions and structures.

[0018] Current document comparison techniques first parse the literal content of two documents, and then determine whether the literal content of the two documents is consistent, so as to determine whether the content of the two documents has differences. However, in actual scenarios, the clarity of the document file cannot be guaranteed, and the accuracy of the document parsing technique cannot be guaranteed, so there are often cases where the determined difference content is inaccurate.

[0019] To solve this problem, the present disclosure provides a document comparison method and device for improving the document comparison effect, equipment and medium. The following first combines Figure 1 The application scenario of the method and device provided by the present disclosure is described.

[0020] Figure 1 The application scenario of the document comparison method and device according to the embodiments of the present disclosure is shown in the figure.

[0021] As Figure 1 shown, the application scenario 100 of this embodiment can include a terminal device 110, which can be various electronic devices with processing functions, including but not limited to smartphones, tablet computers, laptop computers, desktop computers, and the like.

[0022] The terminal device 110 can be used to parse and compare two documents 120 that need to be compared, and the difference content obtained by comparison is taken as candidate difference content. Then, the candidate difference content is screened through post-processing, so as to screen the difference content 130 of the two documents 120.

[0023] Among them, the candidate difference content can be screened by re-comparing the information of the difference content at the corresponding positions of the two documents, so as to determine whether the difference really exists, so as to screen the candidate difference content.

[0024] In an embodiment, after determining the difference content 130 of the two documents 120, the terminal device can also display the two documents 120, and highlight the difference content 130, so as to achieve the effect of showing the comparison result to the user.

[0025] In an embodiment, the application scenario 100 can further include a server 140, and the terminal device 110 can be in communication connection with the server 140 through a network. The network can include a wireless or wired communication link. The terminal device 110 can send the two documents 120 to be compared to the server 140 through the network, for example, and the server 140 can perform document parsing and comparison to obtain the difference content 130. Alternatively, the terminal device 110 can send the obtained candidate difference content and the two documents 120 to the server 140, and the server 140 can perform post-processing on the candidate difference content. The server 140 can also send the determined difference content 130 to the terminal device 110, so that the terminal device can highlight the display of the difference content 130 while displaying the two documents 120.

[0026] In an embodiment, the timing of the comparison of the two documents 120 can be, for example, the operation timing of a comparison button or the like displayed by the terminal device 110, and the two documents 120 can be the documents determined in response to the user operation, without limitation in the present disclosure.

[0027] It can be understood that the server 140 can be, for example, a background management server supporting the running of an application installed in the terminal device and having a document comparison function, and can also be a cloud server or a block chain server, without limitation in the present disclosure.

[0028] It should be noted that the document comparison method provided by the present disclosure can be executed by the terminal device 110 or the server 140. Accordingly, the document comparison apparatus provided by the present disclosure can be arranged in the terminal device 110 or the server 140.

[0029] It should be understood that Figure 1 The number and type of terminal devices 110 and servers 140 in the application scenario 100 are only illustrative. Any number and type of terminal devices 110 and servers 140 can be provided according to the implementation needs.

[0030] The document comparison method provided by the present disclosure will be described in detail below. Figures 2 to 4 The document comparison method provided by the present disclosure will be described in detail below.

[0031] Figure 2 is a flowchart of a document comparison method according to an embodiment of the present disclosure.

[0032] As shown in Figure 2 The document comparison method 200 of this embodiment can include operation S210 to operation S230.

[0033] In operation S210, the two documents to be compared are parsed respectively to obtain the text elements included in each document to be compared and the position information of the text elements, as the parsing result of each document to be compared.

[0034] According to embodiments of this disclosure, a document parsing tool can be used to parse the two documents to be compared separately. The document parsing tool may include, for example, a tool built on OCR technology, or a parsing operator. For example, a tool built on OCR technology may include PaddleOCR, TrOCR, etc. The parsing operator may be, for example, a parser, or the PyPDF operator provided by the Python language, etc., and this disclosure does not limit its scope.

[0035] The two documents to be compared can be documents with extensions such as .doc, .wps, .pdf, etc. This disclosure does not limit the format of the two documents to be compared.

[0036] According to embodiments of this disclosure, by parsing each document to be compared, the text elements included in each document and their position information within that document can be obtained. For example, text elements may include characters, images, table lines, etc. The position information of the text elements within the document to be compared can be represented, for example, by the position of the smallest bounding box surrounding the text element in a coordinate system constructed based on the document to be compared. This can include, for example, the coordinates of the top-left and bottom-right corners of the smallest bounding box, or the coordinates of the top-left corner of the smallest bounding box and the width and height of the smallest bounding box.

[0037] For example, the position information of a text element can be represented as [x0, y0, x1-x0, y1-y0]. Here, x0 is the starting value of the text element's coordinates in the width direction, which can be understood as the x-coordinate of the top-left vertex of the smallest rectangle. y0 is the starting value of the text element's coordinates in the height direction, which can be understood as the y-coordinate of the top-left vertex of the smallest rectangle. x1 is the ending value of the text element's coordinates in the width direction, which can be understood as the x-coordinate of the bottom-right vertex of the smallest rectangle. y1 is the ending value of the text element's coordinates in the height direction, which can be understood as the y-coordinate of the bottom-right vertex of the smallest rectangle.

[0038] In one embodiment, the format information of the text elements in the document to be compared can also be parsed. When the text element is a character, the format information may include, for example, font type, font size, etc. When the text element is an image, the format information may include, for example, the image embedding type, etc. When the text element is a table line, the format information may include, for example, the table line width value, etc.

[0039] The embodiment can take the information parsed from each document to be compared as the parsed result of the each document to be compared. For example, the embodiment can arrange the parsed information of the text elements according to the positions of the text elements in the document to be compared, line by line, to obtain a set of information of the text elements as the parsed result.

[0040] In operation S220, at least one candidate difference content between the two documents to be compared is determined according to the parsed results of the two documents to be compared.

[0041] In an embodiment, the information of two text elements located at the same or similar positions in the two documents to be compared can be determined according to the position information in the parsed results of the two documents to be compared, and if the information of the two text elements is different, the two text elements are determined as a candidate difference content. The two similar positions can be understood as two positions with a position difference less than a predetermined threshold. The predetermined threshold can be much smaller than the width interval and the height interval between adjacent text elements in a document.

[0042] In an embodiment, the technique of determining the edit distance between the two documents to be compared can be used to determine the candidate difference content. For example, the two parsed results can be taken as the input of an existing tool for determining the edit distance of a document, and the minimum operation step information between the two documents to be compared is output by the tool for determining the edit distance of a document. According to the character arrangement position information carried in the minimum operation step information, the difference point between the two documents to be compared can be located, and thus the candidate difference content can be determined.

[0043] In an embodiment, operation S210 and operation S220 can be implemented by using an existing document comparison technique, and the embodiment can take the content at the difference point determined by the document comparison technique as the candidate difference content.

[0044] In operation S230, according to the information at the position corresponding to each candidate difference content in the two documents to be compared, an abnormal difference content in at least one candidate difference content is removed, and the difference content between the two documents to be compared is obtained.

[0045] According to the embodiment of the present disclosure, the information at the position corresponding to each candidate difference content can be extracted according to the difference type of each candidate difference content.

[0046] For example, if the difference type is the replacement type, the embodiment can perform similar character recognition on two groups of information at positions corresponding to the candidate difference content in the two documents to be compared. If the characters in the two groups of information are similar to each other, it can be determined that the candidate difference content is likely to be caused by inaccurate parsing, and the candidate difference content is determined to be abnormal difference content and is removed. It can be understood that the replacement type can eliminate the difference content by replacing the text element at the corresponding position in any one of the two documents to be compared.

[0047] For example, if the difference type is the insertion type or the deletion type, the width of the information at the corresponding position in the document in which the text element needs to be inserted or in which the text element does not need to be deleted can be determined first. If the width is greater than or equal to a predetermined width, it can be determined that the information at the corresponding position should include the text element, rather than a blank area. It can be determined that the candidate difference content is likely to be caused by the text element in the non-blank area that is not parsed, so that the candidate difference content is determined to be abnormal difference content and is removed. It can be understood that the insertion type can eliminate the difference content by inserting the text element at the corresponding position in the other document into the document in which the text element needs to be inserted. The deletion type can eliminate the difference content by deleting the text element that does not exist at the corresponding position in the other document in the document in which the text element needs to be deleted.

[0048] The embodiment can take the difference content left in the candidate difference content after removing the abnormal difference content in the above manner as the difference content between the two documents to be compared.

[0049] The embodiment of the present disclosure can realize post-processing of the candidate difference content by taking the difference content determined according to the parsing result as the candidate difference content, and then determining and removing the abnormal difference content according to the information at the positions corresponding to the candidate difference content in the two documents to be compared. The final determined difference content is not only dependent on the parsing result, which is beneficial to improve the accuracy of the final determined difference content and improve the document comparison effect.

[0050] In an embodiment, the two documents to be compared can be converted into portable document format documents first, and the obtained two portable document format documents are taken as the two documents to be compared for document parsing and difference content determination. The portable document format can be a file format with a.pdf suffix. In this way, the determined difference content can be visually displayed. This is because the portable document format document reader usually has multiple types of annotation tools and rendering tools, which can be used to distinguish and display different types of difference content. The types of difference content may, for example, include the insertion type, the deletion type, and the replacement type described above, which are not limited by the present disclosure.

[0051] For example, if the two documents to be compared are documents with suffixes.doc and.wps, the two documents to be compared can be converted into portable document format documents by using a win32com.client module executable in Python language or the like. It can be understood that the tool used for converting the two documents to be compared can be determined according to the format of the two documents to be compared, and the present disclosure does not limit this.

[0052] Figure 3 is a schematic diagram of a principle of determining candidate difference content according to an embodiment of the present disclosure.

[0053] In an embodiment, when determining the candidate difference content, the two documents to be compared can be aligned first, and then the edit distance can be used to determine the candidate difference content. In this way, the accuracy of the determined edit distance can be improved, and thus the precision of the determined candidate difference content can be improved.

[0054] As shown in Figure 3 In an embodiment 300, when aligning the documents, the target text element 330 serving as an alignment point can be determined according to the parsing result 321 of the document 311 and the parsing result 322 of the document 312 of the two documents to be compared first. Then, the two documents to be compared can be aligned according to the target text element 330.

[0055] For example, the target text element can be a text element included in both of the two documents to be compared. Alternatively, after obtaining the text element included in both of the two documents to be compared, the two positions of the text element in the two documents to be compared can be compared. If the difference between the two positions is small, the text element can be taken as an alignment point, otherwise the text element is not taken as an alignment point. In this way, the precision of the determined alignment point can be improved.

[0056] In an embodiment, as shown in Figure 3As shown, after obtaining the target text element 320, the two documents to be aligned (i.e., the document 311 and the document 312) can also be segmented according to the target text element 330 to obtain a plurality of document segment pairs 350. Specifically, the document 311 can be segmented to obtain a document segment set 341, and the document 312 can be segmented to obtain a document segment set 342. Subsequently, the document segments in the two document segment sets 331 and 332 can be aligned according to the position of the target text element 330 to obtain a plurality of document segment pairs 350. Each document segment pair includes two document segments respectively belonging to the two documents to be aligned, i.e., each document segment pair includes one document segment belonging to the document segment set 341 and one document segment belonging to the document segment set 342, and the two document segments in each document segment pair are segmented according to the same target text element.

[0057] After obtaining the plurality of document segment pairs 350, the edit distance 360 between the two document segments in each document segment pair can be calculated in parallel, and subsequently, the candidate difference content 370 between the two text segments can be obtained according to the edit distance 360.

[0058] The edit distance refers to the minimum number of edit operations required to convert one string into another string. For example, the Levenshtein distance algorithm can be used to calculate the edit distance between two document segments, or any other edit distance calculation algorithm can be used to determine the edit distance between two document segments. It can be understood that each candidate difference content corresponds to one edit operation representing the edit distance. The edit operation can include, for example, adding a character (e.g., inserting a text element), deleting a character, and replacing a character.

[0059] For example, the Levenshtein.opcodes tool can be invoked to calculate the edit distance, which is used to find a series of edit operations to convert one string to another string. In this embodiment, each pair of text segments included in the pair of text segments can be input to the Levenshtein.opcodes tool, and a series of quintuple sequences can be output by the Levenshtein.opcodes tool. Each quintuple in the quintuple sequence can be represented as [operator, s1, e1, s2, e2]. Wherein, the operator represents an operator, which can be one of an insertion operator insert, a deletion operator delete, and a replacement operator replace. s1 represents the starting position of the character of the string text1 that needs to be changed under the operation represented by the operator to convert text1 to text2, and the position of the changed character includes the starting position. e1 represents the ending position of the character of the string text1 that needs to be changed under the operation represented by the operator to convert text1 to text2, and the position of the changed character does not include the ending position. s2 represents the starting position of the character of the string text1 that needs to be changed under the operation represented by the operator to convert text1 to text2, and the position of the changed character includes the starting position. e2 represents the ending position of the character of the string text1 that needs to be changed under the operation represented by the operator to convert text1 to text2, and the position of the changed character does not include the ending position. It can be understood that the starting position and the ending position mentioned in this embodiment can be represented by the position of the character in the string, for example, if the starting position is 2, it means that the starting position is the position of the character with the second order.

[0060] For example, if text1 is "there is an apple here", and text2 is "there is an apple here", the output [replace, 2, 3, 2, 3] can be obtained by invoking the Levenshtein.opcodes tool, which means that the characters with the second order in text1 (excluding the characters with the third order) are replaced to obtain text2, and the characters with the second order in text1 are replaced, for example, replaced by the characters with the second order in text2, to obtain text2.

[0061] In this embodiment, the pair of text segments can be split according to the alignment points, and a plurality of pairs of aligned document segments can be obtained, so that the edit distance of the plurality of pairs of document segments can be calculated in parallel, and the candidate difference content can be determined in parallel, which can improve the determination efficiency of the candidate difference content. Moreover, since the splitting is performed according to the alignment points, the effectiveness of the determined candidate difference content can be improved.

[0062] In one embodiment, text elements included in both documents to be compared can be used as candidate text elements. Then, elements with a unique position in both documents are selected from the candidate text elements and designated as target text elements. By limiting the target text elements to elements with a unique position in both documents, the situation where the same element appears in multiple positions within a single document, preventing accurate alignment of the two documents, can be avoided. This improves the accuracy of the determined alignment point and the precision of the identified candidate differences.

[0063] Figure 4 This is a schematic diagram illustrating the principle of removing abnormal differences according to an embodiment of this disclosure.

[0064] like Figure 4 As shown, in one embodiment 400, after obtaining at least one candidate difference content, for each candidate difference content 410, information images corresponding to the positions of each candidate difference content 410 can be extracted from two documents to be compared, thereby obtaining an image 431 extracted from one document to be compared 421 and an image 432 extracted from another document to be compared 422. Subsequently, the similarity 440 between images 431 and 432 can be calculated. If it is determined that the similarity 440 is greater than a predetermined similarity threshold (for example, it can be determined by performing operation S401), the candidate difference content 410 can be determined to be abnormal difference content, and the candidate difference content 410 can be removed from at least one candidate difference content (i.e., operation S402 is performed). If the similarity 440 is less than or equal to the predetermined similarity threshold, it can be determined that the candidate difference content 410 actually exists, and the candidate difference content 410 is retained.

[0065] In one embodiment, when multiple text fragment pairs are obtained by dividing two documents to be compared based on the alignment point, images 431 and 432 can be extracted from the two text fragments included in the text fragment pair corresponding to the candidate difference content 410, respectively.

[0066] For example, if the candidate difference content 410 is represented by the quintuple [operator, s1, e1, s2, e2] and the operator is the replace operator, the image between s1 and e1 in the snapshot of the to-be-compared document 421 can be cropped to obtain the image 431. For example, the image 431 can be cropped according to the coordinate range [s1_x0, s1_y0, e1-1_x1, e1-1_y1]. Wherein, (s1_x0, s1_y0) is the coordinate of the top-left corner of the bounding box surrounding the character with the order s1 in the to-be-compared document 421, and (e1-1_x1, e1-1_y1) is the coordinate of the bottom-right corner of the bounding box surrounding the character with the order (e1-1) in the to-be-compared document 421. Meanwhile, the image between s2 and e2 in the snapshot of the to-be-compared document 422 can be cropped to obtain the image 432. For example, the image 432 can be cropped according to the coordinate range [s2_x0, s2_y0, e2-1_x1, e1-2_y1]. Wherein, (s2_x0, s2_y0) is the coordinate of the top-left corner of the bounding box surrounding the character with the order s2 in the to-be-compared document 422, and (e2-1_x1, e2-1_y1) is the coordinate of the bottom-right corner of the bounding box surrounding the character with the order (e2-1) in the to-be-compared document 422.

[0067] For example, if the operator is the insert operator, that is, the operation of inserting a character is performed on the to-be-compared document 421. The image between s1-1 and s1 in the snapshot of the to-be-compared document 421 can be cropped to obtain the image 431. For example, the image 431 can be cropped according to the coordinate range [s1-1_x1, s1_y0, s1_x0, s1_y1]. Wherein, s1-1_x1 is the horizontal axis coordinate of the bottom-right corner of the bounding box surrounding the character with the order (s1-1) in the to-be-compared document 421, (s1_x0, s1_y0) is the coordinate of the top-left corner of the bounding box surrounding the character with the order s1 in the to-be-compared document 421, and s1_y1 is the vertical axis coordinate of the bottom-right corner of the bounding box surrounding the character with the order s1 in the to-be-compared document 421. Meanwhile, the image between s2 and e2 in the snapshot of the to-be-compared document 422 can be cropped to obtain the image 432. For example, the image 432 can be cropped according to the coordinate range [s2_x0, s2_y0, e2_x0, e2_y1]. Wherein, (s2_x0, s2_y0) is the coordinate of the top-left corner of the bounding box surrounding the character with the order s2 in the to-be-compared document 422, e2_x0 is the horizontal axis coordinate of the top-left corner of the bounding box surrounding the character with the order e2 in the to-be-compared document 422, and e2_y1 is the vertical axis coordinate of the bottom-right corner of the bounding box surrounding the character with the order e2 in the to-be-compared document 422.

[0068] For example, if the operator is the delete operator "delete", that is, an operation of deleting characters is performed on the document to be compared 421. Then, an image between s1 and e1 in the snapshot of the document to be compared 421 can be intercepted to obtain image 431. For example, image 431 can be intercepted according to the coordinate range [s1_x0, s1_y0, e1_x0, e1_y1]. Among them, (s1_x0, s1_y0) is the coordinate of the upper left vertex of the bounding box surrounding the character sorted as s1 in the document to be compared 421, e1_x0 is the horizontal axis coordinate of the upper left vertex of the bounding box surrounding the character sorted as e1 in the document to be compared 421, and e1_y1 is the vertical axis coordinate of the lower right vertex of the bounding box surrounding the character sorted as e1 in the document to be compared 421. At the same time, an image between s2-1 and s2 in the snapshot of the document to be compared 422 can be intercepted to obtain image 432. For example, image 432 can be intercepted according to the coordinate range [s2-1_x1, s2_y0, s2_x0, s2_y1]. Among them, s2-1_x1 is the horizontal axis coordinate of the lower right vertex of the bounding box surrounding the character sorted as (s2-1) in the document to be compared 422, (s2_x0, s2_y0) is the coordinate of the upper left vertex of the bounding box surrounding the character sorted as s2 in the document to be compared 422, and s2_y1 is the vertical axis coordinate of the lower right vertex of the bounding box surrounding the character sorted as s2 in the document to be compared 422.

[0069] For example, as Figure 4 shown, if the document to be compared 421 includes the document fragment "There is an apple" and the document to be compared 422 includes the document fragment "The apple here", then a candidate difference content 410 can be determined as the characters "is" and "the", that is, "is" in the document to be compared 421 needs to be replaced with "the". In this way, image 431 can be determined as the image of the character "is", and image 432 can be determined as the image of the character "the".

[0070] In one embodiment, image 431 and image 432 can be input into an image feature extraction model constructed based on CNN, and two image features are extracted. Subsequently, the cosine similarity between the two image features, etc., is used as the similarity between image 431 and image 432. Alternatively, the image similarity calculation tool skimage.metrics.structural_similarity applicable to the Python language can be directly called to calculate the similarity between image 431 and image 432. Alternatively, image 431 and image 432 can be converted into histograms, and the similarity between the two histograms is used as the similarity between image 431 and image 432. It can be understood that the above methods for calculating similarity are only examples for the purpose of facilitating the understanding of the present disclosure, and the present disclosure makes no limitations in this regard.

[0071] The embodiment of the present disclosure can compare the difference part of the document from the visual angle, improve the identification accuracy of the abnormal difference content, and improve the accuracy of the determined difference content and the effect of the document comparison.

[0072] In an embodiment, in a case where the editing operation corresponding to the candidate difference content is one of a deletion operation and an insertion operation, the space size at the position corresponding to the candidate difference content in a target document in the two documents to be compared can be determined first. The target document is a document that does not include the difference content. If the space size is greater than or equal to a predetermined size, the image 431 and the image 432 in the target document are intercepted, and whether the candidate difference content is abnormal difference content is determined according to the size relationship between the similarity between the image 431 and the image 432 and the predetermined similarity threshold. If the space size is less than the predetermined size, it can be determined that the candidate difference content actually exists, and the candidate difference content is retained. Figure 4

[0073] For example, if the editing operation is a deletion operation performed on the document to be compared 421, the target document is the document to be compared 422, and the space size at the position corresponding to the candidate difference content in the target document can be, for example, the space size between the character ranked S2 and the character ranked e2 in the document to be compared 422. If the editing operation is an insertion operation performed on the document to be compared 421, the target document is the document to be compared 421, and the space size at the position corresponding to the candidate difference content in the target document can be, for example, the space size between the character ranked S1 and the character ranked e1 in the document to be compared 421. The space size can be represented by the width of the space (i.e., the size in the horizontal direction). The predetermined size can be related to the interval between two adjacent text elements in the document. For example, the predetermined size can be a predetermined multiple of the interval between two adjacent characters in the horizontal direction. The value of the predetermined multiple can be, for example, a value less than 1, or can be 1, or can be a value greater than 1, which can be set according to actual conditions.

[0074] The embodiment of the present disclosure can compare the difference part of the document from the visual angle, improve the identification accuracy of the abnormal difference content, and improve the accuracy of the determined difference content and the effect of the document comparison.

[0075] ​Based on the document comparison method provided in the present disclosure, the present disclosure further provides a document comparison device. The following will be described in detail in combination with Figure 5 The device is described in detail.

[0076] Figure 5 is a structural block diagram of a document comparison device according to an embodiment of the present disclosure.

[0077] As shown in Figure 5 , the document comparison device 500 can include a document parsing module 510, a candidate difference determining module 520, and a difference screening module 530.

[0078] The document parsing module 510 is configured to parse two documents to be compared respectively, to obtain text elements included in each document to be compared and position information of the text elements, as a parsing result of each document to be compared. In an embodiment, the document parsing module 510 can be configured to perform the operation S210 described above, and details are not repeated here.

[0079] The candidate difference determining module 520 is configured to determine at least one candidate difference content between the two documents to be compared according to the parsing results of the two documents to be compared. In an embodiment, the candidate difference determining module 520 can be configured to perform the operation S220 described above, and details are not repeated here.

[0080] The difference screening module 530 is configured to eliminate abnormal difference content in the at least one candidate difference content according to information at positions corresponding to each candidate difference content in the two documents to be compared, to obtain difference content between the two documents to be compared. In an embodiment, the difference screening module 530 can be configured to perform the operation S230 described above, and details are not repeated here.

[0081] According to an embodiment of the present disclosure, the difference screening module 530 described above can include an image capturing sub-module and an eliminating sub-module. The image capturing sub-module is configured to capture images of information at positions corresponding to each candidate difference content in the two documents to be compared, to obtain two images. The eliminating sub-module is configured to determine each candidate difference content as abnormal difference content and eliminate it in response to a similarity between the two images being greater than a predetermined similarity threshold.

[0082] According to an embodiment of the present disclosure, the candidate difference determining module 520 can include an alignment point determining sub-module, a document segmentation sub-module, and a difference determining sub-module. The alignment point determining sub-module is configured to determine, according to the parsing results of the two documents to be aligned, a target text element in the two documents to be aligned as an alignment point. The document segmentation sub-module is configured to segment the two documents to be aligned according to the target text element to obtain a plurality of document segment pairs; each document segment pair includes two document segments respectively belonging to the two documents to be aligned; and the two document segments are segmented according to the same target text element. The difference determining sub-module is configured to determine, according to an edit distance between the two document segments in each document segment pair, a candidate difference content between the two document segments. Each candidate difference content corresponds to one edit operation representing the edit distance.

[0083] According to an embodiment of the present disclosure, at least one candidate difference content is determined according to an edit distance between the two documents to be aligned, and each candidate difference content corresponds to one edit operation representing the edit distance. The difference screening module 530 can include a space determining sub-module, an image capturing sub-module, and a rejection sub-module. The space determining sub-module is configured to, in response to the edit operation corresponding to each candidate difference content being one of a deletion operation and an insertion operation, determine a space size at a position corresponding to each candidate difference content in a target document of the two documents to be aligned; the target document is a document that does not include the difference content. The image capturing sub-module is configured to, in response to the space size being greater than or equal to a predetermined size, capture an image of information at the position corresponding to each candidate difference content in the two documents to be aligned to obtain two images. The rejection sub-module is configured to, in response to a similarity between the two images being greater than a predetermined similarity threshold, determine each candidate difference content as an abnormal difference content and reject it. The predetermined size is related to an interval between two adjacent text elements in a document.

[0084] According to an embodiment of the present disclosure, the alignment point determining sub-module can include a candidate element determining unit and a target element determining unit. The candidate element determining unit is configured to determine, according to the parsing results of the two documents to be aligned, a text element included in both of the two documents to be aligned as a candidate text element. The target element determining unit is configured to determine a target text element in the candidate text element as an alignment point. The target text element is an element that has a unique position in both of the two documents to be aligned.

[0085] According to an embodiment of the present disclosure, the document alignment apparatus 500 can further include a document conversion module configured to convert the two documents to be compared into Portable Document Format (PDF) documents to obtain the two documents to be aligned.

[0086] It should be noted that the collection, storage, use, processing, transmission, provision, disclosure, and application of user personal information in this disclosed technical solution comply with relevant laws and regulations, necessary confidentiality measures have been taken, and it does not violate public order and good morals. In this disclosed technical solution, user authorization or consent has been obtained before acquiring or collecting user personal information.

[0087] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0088] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement the document comparison method of embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0089] like Figure 6 As shown, device 600 includes a computing unit 601, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 602 or a computer program loaded from storage unit 608 into random access memory (RAM) 603. RAM 603 may also store various programs and data required for the operation of device 600. The computing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.

[0090] Multiple components in device 600 are connected to I / O interface 605, including: input unit 606, such as keyboard, mouse, etc.; output unit 607, such as various types of monitors, speakers, etc.; storage unit 608, such as disk, optical disk, etc.; and communication unit 609, such as network card, modem, wireless transceiver, etc. Communication unit 609 allows device 600 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0091] The computing unit 601 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs various methods and processes described above, such as the document comparison method. For example, in some embodiments, the document comparison method can be implemented as a computer software program tangibly embodied in a machine-readable medium, such as the storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed onto the device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded onto the RAM 603 and executed by the computing unit 601, one or more steps of the document comparison method described above can be performed. Alternatively, in other embodiments, the computing unit 601 can be configured to perform the document comparison method by any other suitable means, such as by means of firmware.

[0092] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a complex programmable logic device (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.

[0093] Program code for carrying out methods of the present disclosure can be written in any combination of one or more programming languages. The program code can be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the program code, when executed by the processor or controller, produces the functions / operations specified in the flowcharts and / or the block diagrams. The program code can be executed entirely on a machine, partially on a machine, partially on a machine and partially on a remote machine or entirely on a remote machine or server.

[0094] In the context of this disclosure, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium will include one or more lines of electrical connections, portable computer disks, hard disk drives, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), optical fibers, portable compact disc read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0095] To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.

[0096] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.

[0097] The computer system can include clients and servers. This relationship can be. The servers can be cloud servers, also known as cloud computing servers or cloud hosts, which are mainframe products in the cloud computing service system, and solve the defects of large management difficulty and weak business scalability in traditional physical hosts and VPS services (Virtual Private Server, or VPS for short). The servers can also be servers of a distributed system, or servers combined with a blockchain.

[0098] It should be understood that the steps shown above can be reordered, added to, or deleted from. For example, the steps described in the present disclosure can be executed in parallel, in sequence, or in a different order, as long as the desired results of the technical solutions of the present disclosure can be achieved, and the present disclosure is not limited herein.

[0099] The above detailed description does not constitute a limitation on the protection scope of the present disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A method for document alignment, comprising: parsing two documents to be aligned respectively to obtain text elements and position information of the text elements included in each of the two documents to be aligned as a parsing result of the each of the two documents to be aligned; determining target text elements as alignment points in the two documents to be aligned according to the parsing results of the two documents to be aligned; segmenting the two documents to be aligned according to the target text elements to obtain a plurality of document segment pairs; each of the document segment pairs includes two document segments respectively belonging to the two documents to be aligned; the two document segments are segmented according to the same target text element; determining candidate difference contents between the two document segments in each of the document segment pairs according to an edit distance between the two document segments, wherein each of the candidate difference contents corresponds to one edit operation representing the edit distance; and eliminating abnormal difference contents in at least one of the candidate difference contents according to information at positions corresponding to each of the candidate difference contents in the two documents to be aligned to obtain difference contents between the two documents to be aligned, comprising: capturing images of the information at the positions corresponding to each of the candidate difference contents in the two documents to be aligned to obtain two images; and determining that each of the candidate difference contents is an abnormal difference content and eliminating the same in response to a similarity between the two images being greater than a predetermined similarity threshold, wherein the capturing of the images of the information at the positions corresponding to each of the candidate difference contents in the two documents to be aligned to obtain the two images comprises: capturing two images from the two document segments included in the document segment pair corresponding to each of the candidate difference contents respectively.

2. The method of claim 1, wherein, the at least one candidate difference content is determined according to the edit distance between the two documents to be aligned; each of the candidate difference contents corresponds to one edit operation representing the edit distance; further comprising: determining a space size at a position corresponding to each of the candidate difference contents in a target document of the two documents to be aligned in response to the edit operation corresponding to each of the candidate difference contents being one of a deletion operation and an insertion operation; the target document is a document not including difference contents; capturing images of the information at the positions corresponding to each of the candidate difference contents in the two documents to be aligned to obtain two images in response to the space size being greater than or equal to a predetermined size; and determining that each of the candidate difference contents is an abnormal difference content and eliminating the same in response to a similarity between the two images being greater than a predetermined similarity threshold, wherein the predetermined size is related to an interval between two adjacent text elements in a document.

3. The method of claim 1, wherein, the determining of the target text elements as the alignment points in the two documents to be aligned according to the parsing results of the two documents to be aligned comprises: determining text elements included in the two documents to be aligned as candidate text elements according to the parsing results of the two documents to be aligned; and determining the target text elements as the alignment points in the candidate text elements, wherein the target text elements are elements having unique positions in the two documents to be aligned. 4.The method according to any one of claims 1-3, further comprising: Converting two documents to be compared into portable document format documents, to obtain the two documents to be compared.

5. A document comparison apparatus, comprising: a document parsing module configured to parse the two documents to be compared respectively to obtain text elements and position information of the text elements included in each of the two documents to be compared as a parsing result of the each of the two documents to be compared; a alignment point determination sub-module configured to determine target text elements as alignment points in the two documents to be compared according to the parsing results of the two documents to be compared; a document segmentation sub-module configured to segment the two documents to be compared according to the target text elements to obtain a plurality of document segment pairs; each of the document segment pairs comprises two document segments respectively belonging to the two documents to be compared; the two document segments are segmented according to the same target text element; a difference determination sub-module configured to determine candidate difference contents between the two document segments of each of the document segment pairs according to an edit distance between the two document segments, wherein each of the candidate difference contents corresponds to one edit operation representing the edit distance; and a difference screening module configured to eliminate abnormal difference contents in at least one of the candidate difference contents according to information at positions corresponding to the each of the candidate difference contents in the two documents to be compared to obtain difference contents between the two documents to be compared; the difference screening module comprises: an image capturing sub-module configured to capture images of the information at the positions corresponding to the each of the candidate difference contents in the two documents to be compared to obtain two images; and an eliminating sub-module configured to determine the each of the candidate difference contents as an abnormal difference content and eliminate the each of the candidate difference contents in response to a similarity between the two images being greater than a predetermined similarity threshold, wherein the image capturing sub-module is further configured to capture the two images respectively from the two document segments of the document segment pair corresponding to the each of the candidate difference contents.

6. The apparatus of claim 5, wherein, the at least one candidate difference content is determined according to an edit distance between the two documents to be compared; each of the candidate difference contents corresponds to one edit operation representing the edit distance; further comprising: a space determination sub-module configured to determine a space size at a position corresponding to the each of the candidate difference contents in a target document of the two documents to be compared in response to the edit operation corresponding to the each of the candidate difference contents being one of a deletion operation and an insertion operation; the target document is a document not including difference contents; an image capturing sub-module configured to capture images of the information at the positions corresponding to the each of the candidate difference contents in the two documents to be compared in response to the space size being greater than or equal to a predetermined size to obtain two images; and an eliminating sub-module configured to determine the each of the candidate difference contents as an abnormal difference content and eliminate the each of the candidate difference contents in response to a similarity between the two images being greater than a predetermined similarity threshold, wherein the predetermined size is related to an interval between two adjacent text elements in a document.

7. The apparatus of claim 5, wherein, the alignment point determination sub-module comprises: a candidate element determination unit configured to determine text elements included in the two documents to be compared as candidate text elements according to the parsing results of the two documents to be compared; and a target element determination unit, configured to determine a target text element in the candidate text elements as the alignment point, wherein the target text element is an element having a unique position in the two documents to be aligned.

8. The apparatus according to any one of claims 5-7, further comprising: a document conversion module, configured to convert the two documents to be compared into Portable Document Format (PDF) documents, to obtain the two documents to be aligned.

9. An electronic device, comprising: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-4.

10. A non-transitory computer readable storage medium having stored thereon computer instructions, wherein, the computer instructions are used to enable the computer to perform the method of any one of claims 1-4.

11. A computer program product, comprising computer programs / instructions stored on at least one of a readable storage medium and an electronic device, and the computer programs / instructions, when executed by a processor, implement the steps of the method of any one of claims 1-4.

Citation Information

Patent Citations

  • A full-text difference comparison method and device

    CN109543614A

  • Automatic page testing method and device, equipment and storage medium

    CN113704111A