HTML-based document comparison methods, control devices, and computer program products

By extracting elements from HTML documents and using a sliding window to divide the comparison groups, the problem of not being able to correctly handle differences in HTML tag documents in existing technologies is solved, realizing an HTML-based document comparison method that can correctly mark document differences and improve comparison speed.

CN114492372BActive Publication Date: 2026-03-13CHINA CONSTRUCTION BANK
View PDF 1 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing text comparison algorithms cannot properly handle document differences with HTML tags, resulting in incorrect display of comparison results.

Method used

By extracting elements based on HTML text string attributes, generating comparison objects, dividing comparison groups using a sliding window, determining the type of difference, and regenerating the document to display the differences.

Benefits of technology

It implements HTML-based document comparison, which can correctly mark document differences and improves comparison speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114492372B_ABST
    Figure CN114492372B_ABST
Patent Text Reader

Abstract

This invention provides an HTML-based document comparison method, control device, and computer program product, belonging to the field of computer technology. The HTML-based document comparison method includes: segmenting a first document and a second document according to HTML text string attributes, and generating corresponding first and second comparison objects; comparing the first and second comparison objects to determine their differences; and regenerating the first or second document based on the first and second comparison objects, and displaying the differences on the generated first or second document. This invention implements HTML-based document comparison based on HTML text string attributes and can correctly mark document differences using HTML syntax.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and more specifically to an HTML-based document comparison method, control device, and computer program product. Background Technology

[0002] Documents displayed on web pages consist of files in Hyper Text Markup Language (HTML) format. When a document on a page is edited, its content changes. Users need to understand the changes before and after editing, and this should be displayed on the page.

[0003] Typical text comparison algorithms, such as the Myer difference algorithm, cannot handle text with HTML tags. The comparison results obtained by the Myer difference algorithm will merge HTML tags and HTML text, and this result cannot be displayed correctly on the page. Summary of the Invention

[0004] The purpose of this invention is to provide an HTML-based document comparison method that can perform HTML-based document comparison.

[0005] To achieve the above objectives, embodiments of the present invention provide an HTML-based document comparison method, which includes: extracting elements from a first document and a second document based on HTML text string attributes, and generating corresponding first comparison objects and second comparison objects; comparing the first comparison objects and the second comparison objects to determine their differences; and regenerating the first document or the second document based on the first comparison objects and the second comparison objects, and displaying the differences on the generated first document or the second document.

[0006] Optionally, the step of extracting elements from the first document and the second document based on HTML text string attributes and generating corresponding first comparison objects and second comparison objects includes: extracting elements from the first document and the second document using regular expressions, wherein the extracted elements include HTML tags, ordinary characters, and special characters.

[0007] Optionally, if the extracted element is an HTML tag, then the tag attributes are removed.

[0008] Optionally, the first comparison object and the second comparison object are divided into corresponding first comparison groups and second comparison groups by means of a sliding window, wherein the size of the sliding window is a preset minimum comparison unit length; the first comparison group and the second comparison group are compared to determine the differences between them.

[0009] Optionally, dividing the first comparison object and the second comparison object into corresponding first and second comparison groups by means of a sliding window includes: dividing the items in the first comparison object or the second comparison object into combinations in sequence, using the size of the sliding window as the unit, to generate corresponding first and second comparison groups, wherein the combined characters after the combination are used as the key of the item in the first or second comparison group, and the position of the first character of the combined characters in the first or second comparison object is used as the value of the item in the first or second comparison group.

[0010] Optionally, if items in the first comparison group or the second comparison group have the same key, coordinates are added to the items with the same key.

[0011] Optionally, comparing the first comparison group and the second comparison group to determine their differences includes: using an item with the same value in the first comparison group and the second comparison group as a comparison item, comparing the key of the comparison item, wherein when the key of the comparison item is the same, the next item in the first comparison group and the second comparison group is used as the comparison item in turn, and the key of the comparison item is continued to be compared; when the key of the comparison item is different, the position of the comparison item is recorded; using the next item with the same value in the first comparison group and the second comparison group as the comparison item, the key of the comparison item is compared again, until the positions of all items with different keys in the first comparison group and the second comparison group are determined.

[0012] Optionally, comparing the first comparison group and the second comparison group to determine the differences between them further includes: determining the difference type of the item based on the position of the item with different keys, and generating a difference result set containing the positions and difference types of all items with different keys, wherein the difference type includes replacement, addition, and deletion.

[0013] This invention also provides a control device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor executes the computer program to implement the HTML-based document comparison method described in any of the above embodiments.

[0014] This invention also provides a machine-readable storage medium storing instructions that cause a machine to execute the HTML-based document comparison method described in any of the preceding embodiments.

[0015] This invention also provides a computer program product, including a computer program, characterized in that the computer program, when executed by a processor, implements the HTML-based document comparison method described in any one of the above embodiments.

[0016] Through the above technical solution, the embodiments of the present invention realize HTML-based document comparison based on HTML text string attributes, and can correctly mark document differences using HTML syntax.

[0017] Other features and advantages of the embodiments of the present invention will be described in detail in the following detailed description section. Attached Figure Description

[0018] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings:

[0019] Figure 1A This is a sample original document illustration;

[0020] Figure 1B This is a sample target document illustration;

[0021] Figure 1C This is a schematic diagram illustrating the comparison results;

[0022] Figure 2 This is a flowchart illustrating the HTML-based document comparison method provided in an embodiment of the present invention.

[0023] Figure 3 This is a flowchart illustrating the comparison of the first comparison object and the second comparison object provided in a preferred embodiment of the present invention;

[0024] Figure 4 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Detailed Implementation

[0025] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.

[0026] Before explaining the embodiments of the present invention in detail, an example is given to illustrate the technical problem that the embodiments of the present invention aim to solve. Please refer to... Figure 1A , 1B 1C, Figure 1A This shows a portion of the original document. Figure 1B This shows a portion of the target document. Figure 1CThis illustrates the comparison effect to be achieved by an embodiment of the present invention. The following explanations will all use this example.

[0027] Figure 2 This is a flowchart illustrating the HTML-based document comparison method provided in this embodiment of the invention. Please refer to it. Figure 2 This HTML-based document comparison method may include the following steps:

[0028] Step S110: Extract elements from the first and second documents based on the HTML text string attributes, and generate the corresponding first and second comparison objects.

[0029] Please combine Figure 1A , Figure 1B ,and Figure 1C Based on the first document Figure 1A The original document contains a portion of the content, and the second document is... Figure 1B The content of the first document's HTML text can be represented as follows:

[0030]

[0031]

[0032] Hospital supplies management refers to the organizational and management work of hospitals in planning, purchasing, storing, and supplying various materials needed to complete medical, teaching, and scientific research tasks.

[0033]

[0034] Hospital supplies management refers to the organizational and management work of hospitals in planning, purchasing, storing, and supplying various materials needed to complete medical, teaching, and scientific research tasks.

[0035]

[0036] The text strings of the first and second documents are segmented into indivisible comparison objects. These include ordinary characters such as Chinese, English, and punctuation marks; and HTML tags such as... , <strong>< / strong> ... etc.; special characters, such as: (<;), (>;), (&;), etc.

[0037] Preferably, step S110 may include: extracting elements from the first document and the second document using regular expressions, wherein the extracted elements include HTML tags, ordinary characters, and special characters.

[0038] Further optimization involves removing tag attributes if the extracted element is an HTML tag.

[0039] As illustrated by the example, the process of extracting elements from the HTML text of the first document and the HTML text of the second document using regular expressions to generate the corresponding first and second comparison objects is as follows:

[0040] 1) If the extracted element is a regular character, store the element in the corresponding comparison object of the document in order.

[0041] 2) If the extracted elements are HTML tags, then after removing the tag attributes, they are stored sequentially in the corresponding comparison object of the document. For example: <img align="left"height="100"style="margin-right:10px"width="100"> After removing the tag attributes, convert to Store the corresponding comparison object.

[0042] The purpose of element processing is to convert HTML tags in an HTML document into basic comparison elements and process them uniformly with ordinary characters (Chinese and English characters, punctuation marks, etc.).

[0043] A specific example uses regular expressions to extract elements from the first and second documents, generating corresponding first and second comparison objects. These comparison objects can be arrays or other data types. Taking the generation of the first comparison object as array A1 and the second comparison object as data B1 as an example, the first and second documents are split, generating A1 and B1 respectively. The partial structures of A1 and B1 are shown below. The code is for illustrative purposes only and is not intended to be run.

[0044]

[0045]

[0046]

[0047] Step S120: Compare the first comparison object and the second comparison object to determine their differences.

[0048] Each item in A1 and B1 can be directly compared to determine the differences between them. For example, A1_sourceWords

[11] and B1_targetWords

[11] , A1_sourceWords

[12] and B1_targetWords

[12] are different, which is the difference between the first document and the second document. That is, based on the first document, the second document changes its content "system" to "platform".

[0049] Figure 3 This is a flowchart illustrating the comparison of the first and second comparison objects provided in a preferred embodiment of the present invention. Please refer to... Figure 3 The step of comparing the first comparison object and the second comparison object to determine their differences may include the following steps:

[0050] Step S121: Divide the first comparison object and the second comparison object into corresponding first comparison groups and second comparison groups by using a sliding window.

[0051] The size of the sliding window is the preset minimum comparison unit length.

[0052] Preferably, step S121 may include: dividing the items in the first comparison object or the second comparison object in sequence, using the size of the sliding window as the unit, to generate corresponding first comparison group and second comparison group, wherein the combined characters after division are used as the key of the item in the first comparison group or the second comparison group, and the position of the first character of the combined characters after division in the first comparison object or the second comparison object is used as the value of the item in the first comparison group or the second comparison group.

[0053] The first or second comparison group can be an array or other data type.

[0054] For example, if N=4, and the second alignment object is B1, dividing B1 to generate a partial structure of the second alignment group B2 can be shown below:

[0055] key(" \r\n <strong>(Medical): value(0)1

[0056] key("\r\n <strong>Medical): value(3)

[0057] key(" <strong>Medical supplies): value(7)

[0058] Preferably, if items in the first comparison group or the second comparison group have the same key, coordinates are added to the items with the same key.

[0059] For example, if there are two identical keys in B2: <strong>For the key "medical supplies", coordinates are added to point to the location of the corresponding value, which can be represented as follows:

[0060]

[0061] Step S122: Compare the first comparison group and the second comparison group to determine the differences between them.

[0062] According to step S121, after generating the first comparison group A2 and the second comparison group B2, the first comparison group and the second comparison group are compared to determine the differences between them.

[0063] We can directly compare each item in A2 and B2 to determine the differences between them. This is different from directly comparing each item in A1 and B1. Figure 3 The preferred embodiment of the present invention shown can greatly improve the comparison speed.

[0064] Preferably, step S122 may include: using the item with the same value in the first comparison group and the second comparison group as the comparison item, comparing the key of the comparison item, wherein, when the key of the comparison item is the same, the next item in the first comparison group and the second comparison group is used as the comparison item in sequence, and the key of the comparison item is continued to be compared, and when the key of the comparison item is different, the position of the comparison item is recorded; using the next item with the same value in the first comparison group and the second comparison group as the comparison item, the key of the comparison item is compared again, until the positions of all items with different keys in the first comparison group and the second comparison group are determined.

[0065] Preferably, before step S122, all items with the same value in A2 and B2 can be recorded as the starting point for comparison. For example, if A2[0].value = B2[0].value, the comparison can start from the first item of the first comparison group and the first comparison group.

[0066] As an example, with the sliding window size N=4 as the initial matching length, the comparison can start from the first item of the first comparison group and the first comparison group.

[0067] First loop comparison: First item of A2 = First item of B2, then record:

[0068] startSource=0, startTarget=0;

[0069] endSource=3, endTarget=3.

[0070] Where startSource represents the position of the first character of the value of the comparison item A2 in A1, endSource represents the position of the last character of the value of the comparison item A2 in A1, startTarget represents the position of the first character of the value of the comparison item B2 in B1, and endTarget=3 represents the position of the last character of the value of the comparison item B2 in B1.

[0071] Furthermore, if the second term of A2 equals the second term of B2, and the next adjacent terms of A2 and B2 can be merged, increasing the matching length by 5, then append:

[0072] endSource=4, endTarget=4.

[0073] If the merging process is repeated and the item in A2 is not equal to the corresponding item in B2 (for example, the 9th item in A2 and the 9th item in B2 cannot be merged), then record endSource=11 and endTarget=11.

[0074] Re-compare the next item whose value is the same in the first comparison group and the second comparison group, and record the new comparison object.

[0075] For example, the second cyclic alignment:

[0076] startSource=13, startTarget=13;

[0077] endSource=17, endTarget=17.

[0078] Repeat the above process, comparing all items in A2 and B2 to find all differences.

[0079] Part of the record comparison process can be shown below:

[0080]

[0081]

[0082] Preferably, step S123 may further include: determining the difference type of the item based on the position of the item with different keys, and generating a difference result set containing the positions and difference types of all items with different keys.

[0083] The types of differences include replacement, addition, and deletion.

[0084] For example, if the coordinates of the start position startSource(13) and startTarget(13) of the second loop alignment are different from the coordinates of the end position endSource(11) and endTarget(11) of the first loop alignment, then the difference type is replacement; if the coordinates of the start position startSource of the next loop alignment of A2 are the same as the coordinates of the endSource of the current loop alignment, but the coordinates of the start position startTarget of the next loop alignment of B2 are different from the coordinates of the endTarget of the current loop alignment, then the difference type is addition; if the coordinates of the start position startSource of the next loop alignment of A2 are different from the coordinates of the endSource of the current loop alignment, then the difference type is deletion.

[0085] The difference result set can include the difference type of each difference and the coordinates of the start and end positions in A1 and B1, and can also directly store the difference characters.

[0086] Step S130: Based on the first comparison object and the second comparison object, regenerate the first document or the second document, and display the differences on the generated first document or the second document.

[0087] by Figure 1C Taking the document shown as an example, regenerate the second document B1, and display the differences on the second document B1 based on the difference result set.

[0088] Accordingly, this invention implements HTML-based document comparison based on HTML text string attributes, and can correctly mark document differences using HTML syntax. It also provides embodiments to improve comparison speed.

[0089] This invention also provides a control device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor executes the computer program to implement the HTML-based document comparison method according to steps S110-S130.

[0090] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and by adjusting kernel parameters, the external investigation system can be adapted to the investigation needs of authorized agencies.

[0091] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0092] This invention also provides a machine-readable storage medium storing instructions that cause a machine to execute the HTML-based document comparison method described in steps S110-S130.

[0093] This invention also provides a computer program product, including a computer program that, when executed by a processor, implements the HTML-based document comparison method described in steps S110-S130.

[0094] This invention also provides a computer device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it implements the HTML-based document comparison method described in steps S110-S130. The device in this invention can be a server, PC, PAD, mobile phone, etc.

[0095] As an example, the computer device can be a terminal, and its internal structure diagram can be as follows: Figure 4 As shown. The computer device includes a processor A01, a network interface A02, a display screen A04, an input device A05, and a memory (not shown) connected via a system bus. The processor A01 provides computing and control capabilities. The memory includes internal memory A03 and a non-volatile storage medium A06. The non-volatile storage medium A06 stores an operating system B01 and a computer program B02. The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 stored in the non-volatile storage medium A06. The network interface A02 is used for communication with external terminals via a network connection. When the computer program is executed by the processor A01, it implements the HTML-based document comparison method described in steps S110-S130. The display screen A04 can be a liquid crystal display (LCD) or an e-ink display. The input device A05 can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.

[0096] It should be noted that the technical content and effects of the control device, storage medium, computer program product, and equipment provided in the embodiments of the present invention are similar to those of the HTML-based document comparison method embodiments described in S110-S130 of the present invention. For details, please refer to the method embodiments, which will not be repeated here.

[0097] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0098] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more flowchart illustrations and / or one or more block diagrams.

[0099] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.

[0100] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.

[0101] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0102] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0103] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0104] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0105] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.< / strong> < / strong> < / strong> < / strong>

Claims

1. An HTML-based document comparison method, characterized by, The HTML-based document comparison method comprises: According to the HTML text string attribute, elements of the first document and the second document are extracted, and corresponding first comparison objects and second comparison objects are generated; By means of a sliding window, the items in the first comparison objects or the second comparison objects are combined and divided in sequence in units of the size of the sliding window, and corresponding first comparison groups and second comparison groups are generated, wherein the combined characters after the combined division are taken as the key of the items of the first comparison groups or the second comparison groups, and the first character of the combined characters after the combined division is taken as the value of the items of the first comparison groups or the second comparison groups. The first comparison groups and the second comparison groups are compared to determine the differences between them, wherein all the items with the same value in the first comparison groups and the second comparison groups are taken as the starting point of the comparison; and According to the first comparison objects and the second comparison objects, the first document or the second document is regenerated, and the differences are displayed on the generated first document or second document.

2. The HTML-based document comparison method of claim 1, wherein, According to the HTML text string attribute, elements of the first document and the second document are extracted, and corresponding first comparison objects and second comparison objects are generated, which comprises: The elements of the first document and the second document are extracted by means of a regular expression, wherein the extracted elements include HTML tags, normal characters and special characters.

3. The HTML-based document comparison method of claim 2, wherein, If the extracted element is an HTML tag, the tag attribute is removed.

4. The HTML-based document comparison method according to claim 3, wherein The size of the sliding window is a preset minimum comparison unit length.

5. The HTML-based document comparison method of claim 1, wherein, If the items of the first comparison groups or the second comparison groups have the same key, the coordinates of the items with the same key are increased.

6. The HTML-based document comparison method of claim 1, wherein, The comparison of the first comparison groups and the second comparison groups to determine the differences between them comprises: An item with the same value of the first comparison groups and the second comparison groups is taken as a comparison item, and the key of the comparison item is compared, wherein when the keys of the comparison items are the same, the next item of the first comparison groups and the second comparison groups is sequentially taken as the comparison item, and the key of the comparison item is continuously compared, and when the keys of the comparison items are different, the position of the comparison item is recorded; The next item with the same value of the first comparison groups and the second comparison groups is taken as a comparison item, and the key of the comparison item is compared again until the positions of all the items with different keys of the first comparison groups and the second comparison groups are determined.

7. The HTML-based document comparison method of claim 6, wherein, The comparison of the first comparison groups and the second comparison groups to determine the differences between them further comprises: According to the determined positions of the items with different keys, the difference types of the items are determined, and a difference result set containing the positions of all the items with different keys and the difference types is generated, wherein the types of the differences include replacement, addition and deletion.

8. A control device characterized by comprising: The control device comprises a memory, a processor, and a computer program stored on the memory and executable on the processor, and the processor executes the computer program to implement the HTML-based document comparison method according to any one of claims 1-7.

9. A machine-readable storage medium, characterized in that, The machine readable storage medium stores instructions, which cause the machine to execute the HTML-based document comparison method according to any one of claims 1-7.

10. A computer program product comprising a computer program, characterized in that, The computer program, when executed by the processor, implements the HTML-based document comparison method according to any one of claims 1-7.

Citation Information

Patent Citations

  • HTML (Hypertext Markup Language) content contrast device and method

    CN101916255A