Html text comparison method and device, equipment and storage medium

By splitting and removing the text comparison after html tags, using the Myers algorithm to generate comparison results, the problem that traditional tools cannot effectively compare html text on web pages is solved, and convenient text changes are viewed and user experience is improved.

CN119903828APending Publication Date: 2025-04-29FOUNDER INT(WUHAN)TECH DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411906739.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-04-29

AI Technical Summary

Technical Problem

Traditional text comparison tools cannot effectively process html text, especially in content created on web pages. The impact of html tags is difficult to remove, resulting in a cumbersome comparison process.

Method used

By obtaining the main content of the html document, split it into multiple lines of text, and removing the html tags in each line of text, obtaining the target text, and then using the Myers algorithm to compare and generate comparison results.

Benefits of technology

Effectively removes the impact of html tags, simplifies the text comparison process, enables users to easily view text changes on the web page, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119903828A_ABST
    Figure CN119903828A_ABST
Patent Text Reader

Abstract

The invention relates to an html text comparison method and device, equipment and a storage medium. The method comprises the steps of obtaining main body content of a first html document structure and main body content of a second html document structure; respectively splitting the main body content of the first html document structure and the main body content of the second html document structure into multiple lines of texts to obtain a corresponding first initial text and a corresponding second initial text; respectively removing the html label of each line of text in the first initial text and the second initial text to obtain a corresponding first target text and a corresponding second target text; and comparing the first target text with the second target text by using a Myers algorithm to generate a comparison result. According to the method and the device, the tag of the html tag can be eliminated, so that a user can conveniently check the text change on the web page.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of text comparison, and in particular to an HTML text comparison method, device, equipment and storage medium. Background Art

[0002] General text comparison tools compare all contents as text. With the increasing development of online media, if you create content in Word or other places first and then copy it to online media, you cannot ensure that the layout style of the text is correct. You need to typeset the text again. It is more popular and convenient to create content directly on the web screen, but the content displayed on the web screen is based on HTML tags. For content created on the web screen, traditional comparison tools cannot remove the impact of HTML tags. When comparing, you need to manually delete the tags and then compare. Therefore, how to conveniently view text changes on the web screen is an urgent problem that needs to be solved. Summary of the invention

[0003] Based on the above statements, the present application provides an HTML text comparison method, device, equipment and storage medium, which can eliminate the tags of HTML tags, making it convenient for users to easily view HTML text changes on web pages.

[0004] According to a first aspect, the present application provides an HTML text comparison method, comprising: Get the main content of the first HTML document structure and the main content of the second HTML document structure; Split the main content of the first HTML document structure and the main content of the second HTML document structure into multiple lines of text respectively, and obtain corresponding first initial text and second initial text; Respectively remove the HTML tags of each line of text in the first initial text and the second initial text to obtain the corresponding first target text and second target text; The Myers algorithm is used to compare the first target text and the second target text to generate a comparison result.

[0005] In one or more embodiments, the main content of the first HTML document structure or the main content of the second HTML document structure is used as the content to be processed; and the main content of the first HTML document structure and the main content of the second HTML document structure are divided into multiple lines of text, including: According to the master-slave relationship of tags, parse out all HTML tags from the content to be processed; According to the block-level element types defined in the HTML specification, match and determine whether each HTML tag of the content to be processed is a block-level element; If any html tag in the content to be processed is a block-level element, the text content of the html tag belonging to the block-level element is divided into a line of text; If any html tag in the to-be-processed content is not a block-level element, the text content of the html tag that is not a block-level element is merged into the html tag of the previous level of the current html tag.

[0006] In one or more embodiments, one of the first target text and the second target text is used as a reference text, and the other is used as a revised text; and the first target text and the second target text are compared using the Myers algorithm to generate a comparison result, including: Each line in the reference text and the revised text is regarded as a string, and the shortest diff path from the reference text to the revised text is searched according to the Myers algorithm; According to the shortest diff path, determining a number of lines of first reference HTML text and a number of lines of first revised HTML text with the same content, and determining a number of lines of second reference HTML text and a number of lines of second revised HTML text with different content; Compare each line of the second reference HTML text with the plurality of lines of the second revised HTML text in a circular manner without crossing the line number index of the first revised HTML text; Determine the content ratio of the current second reference HTML text to each line of the second revised HTML text, and use the second revised HTML text with the largest content ratio as the comparison line HTML text; When the content ratio of the current second reference html text to the corresponding comparison line html text is greater than or equal to a preset ratio threshold, determining that the current comparison line html text is a similar line text of the current second reference html text; When the content ratio of the current second reference html text to the corresponding comparison line html text is less than a preset ratio threshold, determining that the current second reference html text is a deletion line text; The second revised html texts in the plurality of lines of second revised html texts except the similar lines of texts are used as newly added lines of texts.

[0007] In one or more embodiments, after the Myers algorithm is used to compare the first target text and the second target text to generate a comparison result, it also includes: marking a new addition mark or a deletion mark on the similar line text, marking a deletion mark or a new addition mark on the second reference html text corresponding to the similar line text, marking a new addition mark on the new line text, and marking a deletion mark on the deleted line text.

[0008] In one or more embodiments, after removing the HTML tags from each line of text in the first initial text and the second initial text to obtain the corresponding first target text and the second target text, the method further includes: Recording the mapping relationship between each line of text in the first target text and the corresponding HTML tag, so that the first target text can be restored to the first HTML document structure; The mapping relationship between each line of text in the second target text and the corresponding HTML tag is recorded so that the second target text can be restored to the second HTML document structure.

[0009] According to a second aspect, the present application provides an HTML text comparison device, comprising: A content acquisition module is used to acquire the main content of the first HTML document structure and the main content of the second HTML document structure; A splitting module, used to split the main content of the first HTML document structure and the main content of the second HTML document structure into multiple lines of text, to obtain corresponding first initial text and second initial text; A tag removal module is used to remove the HTML tags of each line of text in the first initial text and the second initial text respectively to obtain the corresponding first target text and the second target text; The comparison module is used to compare the first target text and the second target text by using the Myers algorithm to generate a comparison result.

[0010] In one or more embodiments, the main content of the first HTML document structure or the main content of the second HTML document structure is used as the content to be processed; the splitting module includes: A parsing unit, used for parsing all HTML tags from the content to be processed according to the master-slave relationship of tags; A matching unit, used for matching and determining whether each HTML tag of the content to be processed is a block-level element according to the block-level element types defined in the HTML specification; A first division unit is used to divide the text content of the current html tag into a line of text if the current html tag in the content to be processed is a block-level element; The second division unit is used to merge the text content of the current html tag into the text content of the previous level html tag if the current html tag in the content to be processed is not a block-level element.

[0011] In one or more embodiments, the comparison module comprises: A search unit, for treating each line in the reference text and the revised text as a string, and searching for the shortest diff path from the reference text to the revised text according to the Myers algorithm; A first determining unit is used to determine, according to the shortest diff path, a number of lines of first reference HTML text and a number of lines of first revised HTML text having the same content, and to determine a number of lines of second reference HTML text and a number of lines of second revised HTML text having different content; a circular comparison unit, used for circularly comparing each line of the second reference HTML text with the plurality of lines of the second revised HTML text, while not crossing the line number index of the first revised HTML text; a proportion calculation unit, used to determine the content proportion of the current second reference HTML text relative to each line of the second revised HTML text, and use the second revised HTML text with the largest content proportion as the comparison line HTML text; A second determining unit, configured to determine that the current comparison line html text is similar text to the current second reference html text when the content ratio of the current second reference html text to the corresponding comparison line html text is greater than or equal to a preset ratio threshold; A third determining unit is used to determine that the current comparison line html text is a deletion line text when the content ratio of the current second reference html text to the corresponding comparison line html text is less than a preset ratio threshold; The fourth determining unit is used to take the second revised HTML texts in the plurality of lines of the second revised HTML texts except the similar texts as the newly added texts.

[0012] According to a third aspect, the present application provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and wherein the processor implements the steps of the method described in any of the previous embodiments when executing the computer program.

[0013] According to a third aspect, the present application provides a storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method described in any of the preceding embodiments are implemented.

[0014] Compared with the prior art, the technical solution of this application has the following beneficial technical effects: In the above-mentioned HTML text comparison method, device, equipment and storage medium, the main content of the first HTML document structure and the main content of the second HTML document structure are split into multiple lines for processing and HTML tags are removed to obtain the first target text and the second target text, remove the influence of HTML tags, and facilitate the subsequent direct use of Myers algorithm to compare the first target text and the second target text to generate a comparison result. In this way, users can easily view text changes on the web page to improve user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 A schematic diagram of a flow chart of an HTML text comparison method provided in an embodiment of the present application; Figure 2a This is a schematic diagram of the first HTML document structure in an embodiment of the present application; Figure 2b This is a schematic diagram of the second HTML document structure in an embodiment of the present application; Figure 3a A schematic diagram of the first target text in an embodiment of the present application; Figure 3b A schematic diagram of a second target text in an embodiment of the present application; Figure 3c A schematic diagram of a comparison of graph searches of a first target text and a second target text in an embodiment of the present application; Figure 4 for Figure 1 Schematic diagram of the process of step S102; Figure 5 This is a flow chart of an embodiment after step S103 in the embodiment of the present application; Figure 6 for Figure 1 Schematic diagram of the process of step S104; Figure 7a , Figure 7b They are respectively schematic diagrams of text comparison rendering of the first html document and the second html document in the embodiments of the present application; Figure 8 A schematic diagram of the principle of the HTML text comparison device provided in the embodiment of the present application; Fig. 9 A schematic diagram of the principles of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0016] In order to facilitate understanding of the present application, the present application will be described more fully below with reference to the relevant drawings. Embodiments of the present application are provided in the drawings. However, the present application can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the disclosure of the present application more thorough and comprehensive.

[0017] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application.

[0018] Figure 1 A schematic diagram of a process flow of an HTML text comparison method provided by an embodiment of the present application is shown. Figure 2a A schematic diagram showing the structure of a first HTML document in an embodiment of the present application is shown. Figure 2b A schematic diagram showing the structure of a second HTML document in an embodiment of the present application is shown. Figure 3a A schematic diagram of the first target text in an embodiment of the present application is shown. Figure 3b A schematic diagram of the second target text in an embodiment of the present application is shown.

[0019] See also Figure 1 , Figure 2a , Figure 2b , Figure 3a , Figure 3b , an html text comparison method provided by an embodiment of the present application includes the following steps: S101, obtaining the main content of the first HTML document structure and the main content of the second HTML document structure; S102, splitting the main content of the first html document structure and the main content of the second html document structure into multiple lines of text respectively, to obtain corresponding first initial text and second initial text; S103, removing the HTML tags of each line of text in the first initial text and the second initial text respectively, to obtain the corresponding first target text and second target text; S104: Use the Myers algorithm to compare the first target text and the second target text to generate a comparison result.

[0020] It should be noted that the first HTML document structure refers to the basic components of the first HTML document and their arrangement order. The second HTML document structure refers to the basic components of the second HTML document and their arrangement order. The main content refers to the text content of the body element in the corresponding HTML document structure. The first initial text refers to the text after the main content of the first HTML document structure is split into multiple lines. The second initial text refers to the text after the main content of the second HTML document structure is split into multiple lines. The first target text refers to the text after the HTML tags are removed from the first initial text. The second target text refers to the text after the HTML tags are removed from the second initial text.

[0021] Specifically, the author creates a first HTML document on a web page, and obtains a second HTML document after subsequent modification. When the user requests to compare the text of the first HTML document with the second HTML document, the server obtains the structure of the first HTML document and the structure of the second HTML document, and reads the main content of the first HTML document structure and the main content of the second HTML document structure, such as Figure 2a , Figure 2b As shown. Then, by identifying the main content of the second HTML document structure and the types of the respective HTML tags in the main content of the second HTML document structure, the main content of the first HTML document structure is split into multiple lines of text to obtain a first initial text, and the main content of the second HTML document structure is split into multiple lines of text to obtain a second initial text. Then, the HTML tags in the first initial text are removed to obtain a corresponding first target text, and the HTML tags in the second initial text are removed to obtain a corresponding second target text.

[0022] In this embodiment, the main content of the first html document structure and the main content of the second html document structure are split into multiple lines and the html tags are removed to obtain the first target text and the second target text. This can remove the influence of the html tags and facilitate the subsequent direct use of the Myers algorithm to compare the first target text and the second target text to generate a comparison result. In this way, users can easily view text changes on the web page, thereby improving user experience.

[0023] See also Figure 4 , Figure 4 Shows Figure 1 In some embodiments, the main content of the first html document structure or the main content of the second html document structure is used as the content to be processed; the main content of the first html document structure and the main content of the second html document structure are respectively divided into multiple lines of text, including: S401, according to the master-slave relationship of tags, parse out all HTML tags from the content to be processed; S402, according to the block-level element types defined in the HTML specification, match and determine whether each HTML tag of the content to be processed is a block-level element; S403: If the current html tag in the content to be processed is a block-level element, divide the text content of the current html tag into a line of text; S404: If the current html tag in the content to be processed is not a block-level element, the text content of the current html tag is merged into the text content of the html tag one level above the current html tag.

[0024] It should be noted that, whether in the main content of the first HTML document structure or in the main content of the second HTML document structure, HTML tags have a parent-child relationship (i.e., a master-slave relationship). Each HTML tag adopts a < > structure, and the HTML tag is followed by text content, and each HTML tag represents the style of the text content.

[0025] Specifically, the main content of the first HTML document structure or the main content of the second HTML document structure is used as the content to be processed. According to the master-slave relationship of tags, the main tag is first parsed from the content to be processed, and then the sub-tag is parsed from the main tag, and the sub-tag may also contain HTML tags. Therefore, after level-by-level parsing, all HTML tags of the content to be processed are obtained. Generally speaking, most of the main tags of the main content of the HTML document structure are block-level elements, and a small number are non-block-level elements (i.e., inline elements). The types of block-level elements defined in the HTML specification include: "div", "p", "h1~h6", "ul", "ol", "dl", "li", "dd", "table", "hr", "blockquote", "address", "menu", "pre", "header", "section", "aside", "footer", "tr", and "td".

[0026] like Figure 2a and Figure 2b As shown, the main content (body content) of the first html text structure and the main content (body content) of the first html text structure both have three main tags and one main tag, all of which are block-level elements, and the main tag and the main tag both include multiple sub-tags, one of the main tags contains a <strong> sub-tag, and the <strong> sub-tag is a non-block-level element, that is, a row-level element.

[0027] According to the block-level element types defined in the HTML specification, match and determine whether each HTML tag of the content to be processed is a block-level element. If so, the text content of the HTML tag belonging to the block-level element is divided into a line of text; if not, it means that the current HTML tag is an inline element, then the text content of the current HTML tag is merged into the HTML tag of the previous level of the current HTML tag, that is, the text content of the HTML tag of the inline element type is merged into the text content of the HTML tag of the previous level block-level element type, and merged into a line of text.

[0028] For example, Figure 2b In, for ABCD <strong> EFG< / strong> HIJKLuuuMN , "EFG" and "HIJKLuuuMN" can be merged into "ABCD", and by removing the tags, we can get a line of text "ABCDEFG HIJKLuuuMN".

[0029] In this way, the main content of the first HTML document structure and the main content of the second HTML document structure are split into multiple lines of text, which facilitates subsequent line-by-line text comparison between the two documents.

[0030] See also Figure 5 In some embodiments, after step 103, that is, removing the HTML tags of each line of text in the first initial text and the second initial text respectively to obtain the corresponding first target text and the second target text, the method of this embodiment further includes: S501, recording the mapping relationship between each line of text in the first target text and the corresponding HTML tag, so that the first target text can be restored to the first HTML document structure; S502: Record the mapping relationship between each line of text in the second target text and the corresponding HTML tag, so that the second target text can be restored to the second HTML document structure.

[0031] Specifically, in the process of splitting the main content of the first html document structure / the second html document structure into lines and removing html tags, the mapping relationship between each line of text in the first target text and the corresponding html tag, as well as the mapping relationship between each line of text in the second target text and the corresponding html tag can be recorded in the form of a mapping table. In this way, after the subsequent comparison is completed, the first target text / the second target text can be restored to the first html document structure / the second html document structure, keeping the html document structure unchanged.

[0032] In some embodiments, one of the first target text and the second target text is used as a reference text, and the other is used as a revised text. Specifically, the reference text can be regarded as the source text, and the revised text can be regarded as the current text. In this embodiment, the first target text is used as the reference text, and the second target text is used as the revised text. Figure 3a , Figure 3b shown.

[0033] For further information, see Figure 6 In step S104, the first target text and the second target text are compared using the Myers algorithm to generate a comparison result, including: S601, taking each line in the reference text and the revised text as a string, and searching for the shortest diff path from the reference text to the revised text according to the Myers algorithm; S602, determining, according to the shortest diff path, a number of lines of first reference HTML text and a number of lines of first revised HTML text with identical contents, and determining a number of lines of second reference HTML text and a number of lines of second revised HTML text with different contents; S603, cyclically comparing each line of the second reference HTML text with a plurality of lines of the second revised HTML text, while not crossing the line number index of the first revised HTML text; S604, determining the content ratio of the current second reference HTML text to each line of the second revised HTML text, and taking the second revised HTML text with the largest content ratio as the comparison line HTML text; S605: when the content ratio of the current second reference html text to the corresponding comparison line html text is greater than or equal to a preset ratio threshold, determine that the current comparison line html text is a similar line text of the current second reference html text; S606: When the content ratio of the current second reference html text to the corresponding comparison line html text is less than a preset ratio threshold, determine that the current second reference html text is a deletion line text; S607 , taking the second revised html text in the plurality of lines of the second revised html text except the similar lines of text as the newly added lines of text.

[0034] It should be noted that the first reference html text refers to the text in the first target text that has the same content as the corresponding first revised html text in the second target text, and the first revised html text refers to the text in the second target text that has the same content as the corresponding first reference text in the first target text. The second reference html text refers to the text in the first target text that has a different content from all the second revised html texts of the second target text. The second revised html text refers to the text in the second target text that has a different content from all the second reference html texts of the first target text.

[0035] In this embodiment, the Myers algorithm, also known as the Myers difference algorithm, is mainly used to find the minimum edit distance between two texts, that is, to convert one text into another text through the least deletion, insertion, and replacement operations. The Myers algorithm solves this problem by using a graph search method. Its core idea is to abstract the process of finding diffs into a graph search problem and solve it through a dynamic programming method. When the Myers algorithm performs a graph search, the search principle is: differences should be expressed as more continuous additions or deletions, and the same content should be as much as possible, that is, the differences should be as few as possible, and deletions should take precedence over additions.

[0036] Specifically, each line in the reference text and the revised text is taken as a string, and the shortest diff path from the reference text to the revised text is transformed by graph search according to the Myers algorithm to determine a number of first reference html texts and a number of lines of first revised html texts with the same content and the largest number of consecutive lines, thereby determining a number of lines of second reference html text and a number of lines of second revised html text with different contents. Figure 3c As shown, it is determined that the first reference html text of the first target text (i.e., reference text) in lines 4, 5, 7, and 9 is the same as the first revised html text content of the second target text (i.e., revised text) in lines 4, 5, 7, and 9. The second reference html text of the first target text (i.e., reference text) in lines 1, 2, 3, 6, and 8 is the same as the second revised html text content of the second target text (i.e., revised text) in lines 1, 2, 3, 6, and 8.

[0037] Then, each line of the second reference HTML text is compared with several lines of the second revised HTML text in a loop, while not crossing the line number index of the first revised HTML text; further, the content ratio (i.e., edit distance) of the current second reference HTML text relative to each line of the second revised HTML text is determined. The closer the edit distance, the greater the content ratio. The second revised HTML text with the largest content ratio is used as the comparison line HTML text. For example, Figure 3a , Figure 3b As shown, the second reference html text in the first line of the first target text (also known as the reference text) is compared cyclically with the second revised html text in the first, second and third lines of the second target text (also known as the revised text), without skipping the fourth line of the second target text, and then it is determined that the second reference html text in the first line of the first target text has the largest content proportion relative to the second revised html text in the first line of the second target text.

[0038] When the content ratio of the current second reference html text to the corresponding comparison line html text is greater than or equal to the preset ratio threshold, the current comparison line html text is determined to be a similar line text of the current second reference html text. In this embodiment, the ratio threshold can be set according to actual conditions. For example, Figure 3a , Figure 3b As shown, the second revised html text of the first line of the second target text is used as the similar line text of the second reference html text of the first line of the first target text, and through character string splitting and comparison, the characters newly added in the second revised html text of the first line of the second target text relative to the second revised html text of the first line of the second target text can be determined. For another example, the second revised html text of the sixth line of the second target text is used as the similar line text of the second reference html text of the sixth line of the first target text, and through character string splitting and comparison, the characters reduced (that is, the deleted characters) in the second reference html text of the sixth line of the first target text relative to the second revised html text of the sixth line of the second target text can be determined.

[0039] When the content ratio of the current second reference HTML text to the corresponding comparison line HTML text is less than a preset ratio threshold, the current second reference HTML text is determined to be a deleted line text. Figure 3a , Figure 3b As shown, the second reference HTML text in the third line of the first target text is used as the deleted line text. Further, the second revised HTML text in several lines of the second revised HTML text except the similar line text is used as the added line text. For example, Figure 3a , Figure 3b As shown, the second revised HTML text in the second line of the second target text is used as the newly added line text.

[0040] In this way, the first target text and the second target text are compared through the Myers algorithm, and the similarities, similarities and differences between the first target text and the second target text can be clearly compared.

[0041] In some embodiments, after the first target text and the second target text are compared by Myers algorithm and the comparison result is generated, the method further includes: inserting a difference mark in the comparison result. Further, marking a new mark or a deletion mark on the similar line text, marking a deletion mark or a new mark on the second reference html text corresponding to the similar line text, marking a new mark on the new line text, and marking a deletion mark on the deleted line text.

[0042] It should be noted that the new addition mark and the deletion mark can be in the form of icons or color markings. In a specific embodiment, the similar lines of text in the second target text use new addition marks in the form of color markings and deletion marks in the form of icons, and the new lines of text also use new addition marks in the form of color markings; in the first target text, the second reference html text corresponding to the similar lines of text uses new addition marks in the form of icons and deletion marks in the form of color markings, and the deleted lines of text use deletion marks in the form of color markings. Then, through web page rendering, users can easily view the similarities and differences between the first html document and the second html document, such as Figure 7a and Figure 7b shown.

[0043] In one embodiment, the present application provides an html text comparison device, which corresponds one-to-one to an html text comparison method in the above embodiment. Figure 8 As shown, the html text comparison device 800 includes a content acquisition module 810, a splitting module 820, a tag removal module 830 and a comparison module 840. The detailed description of each functional module is as follows: A content acquisition module 810 is used to acquire the main content of the first HTML document structure and the main content of the second HTML document structure; A splitting module 820 is used to split the main content of the first HTML document structure and the main content of the second HTML document structure into multiple lines of text to obtain corresponding first initial text and second initial text; The tag removal module 830 is used to remove the HTML tags of each line of text in the first initial text and the second initial text respectively to obtain the corresponding first target text and the second target text; The comparison module 840 is used to compare the first target text and the second target text using the Myers algorithm to generate a comparison result.

[0044] In some embodiments, the main content of the first HTML document structure or the main content of the second HTML document structure is used as the content to be processed; the splitting module 820 includes: The parsing unit is used to parse out all HTML tags from the content to be processed according to the master-slave relationship of the tags; the matching unit is used to match and determine whether each HTML tag in the content to be processed is a block-level element according to the block-level element types defined in the HTML specification; the first division unit is used to divide the text content of the current HTML tag into a line of text if the current HTML tag in the content to be processed is a block-level element; the second division unit is used to merge the text content of the current HTML tag into the text content of the upper-level HTML tag if the current HTML tag in the content to be processed is not a block-level element.

[0045] In some embodiments, the comparison module 830 includes: a search unit, which is used to treat each line of the reference text and the revised text as a string as a whole, and search for the shortest diff path from the reference text to the revised text according to the Myers algorithm; a first determination unit, which is used to determine, according to the shortest diff path, a number of lines of the first reference html text and a number of lines of the first revised html text with the same content, and to determine a number of lines of the second reference html text and a number of lines of the second revised html text with different contents; a cyclic comparison unit, which is used to cyclically compare each line of the second reference html text with the number of lines of the second revised html text, while not skipping the line number index of the first revised html text; a proportion calculation unit, which is used to determine the current second reference html text l text relative to each line of the second revised html text, and taking the second revised html text with the largest content ratio as the comparison line html text; a second determining unit, used to determine that the current comparison line html text is a similar text of the current second reference html text when the content ratio of the current second reference html text to the corresponding comparison line html text is greater than or equal to a preset proportion threshold; a third determining unit, used to determine that the current comparison line html text is a deleted line text when the content ratio of the current second reference html text to the corresponding comparison line html text is less than a preset proportion threshold; a fourth determining unit, used to take the second revised html text in the several lines of second revised html text except the similar text as newly added text.

[0046] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig. 9As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as a first HTML document structure, a second HTML document structure, a first initial text, a second initial text, a first target text, a second target text and a comparison result. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps of an HTML text comparison method in the above embodiment are implemented.

[0047] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of an HTML text comparison method in the above embodiment are implemented.

[0048] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

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

Claims

1. A method for comparing HTML texts, characterized in that: include: Get the main content of the first HTML document structure and the main content of the second HTML document structure; Splitting the main content of the first HTML document structure and the main content of the second HTML document structure into multiple lines of text respectively to obtain corresponding first initial text and second initial text; Respectively remove the HTML tags of each line of text in the first initial text and the second initial text to obtain the corresponding first target text and second target text; The first target text and the second target text are compared using the Myers algorithm to generate a comparison result.

2. The html text comparison method according to claim 1, characterized in that: Using the main content of the first HTML document structure or the main content of the second HTML document structure as content to be processed; The method of respectively splitting the main content of the first HTML document structure and the main content of the second HTML document structure into multiple lines of text includes: According to the master-slave relationship of tags, parse out all HTML tags from the content to be processed; According to the block-level element types defined in the HTML specification, match and determine whether each HTML tag of the content to be processed is a block-level element; If the current html tag in the content to be processed is a block-level element, the text content of the current html tag is divided into a line of text; If the current html tag in the content to be processed is not a block-level element, the text content of the current html tag is merged into the text content of the previous level html tag.

3. The HTML text comparison method according to claim 1, characterized in that: Using one of the first target text and the second target text as a reference text and the other as a revised text; using the Myers algorithm to compare the first target text and the second target text to generate a comparison result includes: Each line in the reference text and the revised text is regarded as a string, and the shortest diff path from the reference text to the revised text is searched according to the Myers algorithm; According to the shortest diff path, determining a number of lines of first reference HTML text and a number of lines of first revised HTML text with the same content, and determining a number of lines of second reference HTML text and a number of lines of second revised HTML text with different content; Compare each line of the second reference HTML text with the plurality of lines of the second revised HTML text in a circular manner without crossing the line number index of the first revised HTML text; Determine the content ratio of the current second reference HTML text to each line of the second revised HTML text, and use the second revised HTML text with the largest content ratio as the comparison line HTML text; When the content ratio of the current second reference html text to the corresponding comparison line html text is greater than or equal to a preset ratio threshold, determining that the current comparison line html text is a similar line text of the current second reference html text; When the content ratio of the current second reference html text to the corresponding comparison line html text is less than a preset ratio threshold, determining that the current second reference html text is a deletion line text; The second revised html texts in the plurality of lines of second revised html texts except the similar lines of texts are used as newly added lines of texts.

4. The html text comparison method according to claim 1, characterized in that: After the Myers algorithm is used to compare the first target text and the second target text to generate a comparison result, the method further includes: marking a new addition mark or a deletion mark on the similar line text, marking a deletion mark or a new addition mark on the second reference html text corresponding to the similar line text, marking a new addition mark on the new line text, and marking a deletion mark on the deleted line text.

5. The HTML text comparison method according to claim 1, characterized in that: After removing the HTML tags of each line of text in the first initial text and the second initial text to obtain the corresponding first target text and the second target text, the method further includes: Recording the mapping relationship between each line of text in the first target text and the corresponding HTML tag, so that the first target text can be restored to the first HTML document structure; The mapping relationship between each line of text in the second target text and the corresponding HTML tag is recorded so that the second target text can be restored to the second HTML document structure.

6. A html text comparison device, characterized in that: include: A content acquisition module is used to acquire the main content of the first HTML document structure and the main content of the second HTML document structure; A splitting module, used to split the main content of the first HTML document structure and the main content of the second HTML document structure into multiple lines of text, to obtain corresponding first initial text and second initial text; A tag removal module is used to remove the HTML tags of each line of text in the first initial text and the second initial text respectively to obtain the corresponding first target text and the second target text; The comparison module is used to compare the first target text and the second target text by using the Myers algorithm to generate a comparison result.

7. The html text comparison device according to claim 6, characterized in that: Using the main content of the first HTML document structure or the main content of the second HTML document structure as content to be processed; The splitting module comprises: A parsing unit, used for parsing all HTML tags from the content to be processed according to the master-slave relationship of tags; A matching unit, used for matching and determining whether each HTML tag of the content to be processed is a block-level element according to the block-level element types defined in the HTML specification; A first division unit is used to divide the text content of the current html tag into a line of text if the current html tag in the content to be processed is a block-level element; The second division unit is used to merge the text content of the current html tag into the text content of the previous level html tag if the current html tag in the content to be processed is not a block-level element.

8. The html text comparison device according to claim 6, characterized in that: The comparison module comprises: A search unit, for treating each line in the reference text and the revised text as a string, and searching for the shortest diff path from the reference text to the revised text according to the Myers algorithm; A first determining unit is used to determine, according to the shortest diff path, a number of lines of first reference HTML text and a number of lines of first revised HTML text having the same content, and to determine a number of lines of second reference HTML text and a number of lines of second revised HTML text having different content; a circular comparison unit, used for circularly comparing each line of the second reference HTML text with the plurality of lines of the second revised HTML text, while not crossing the line number index of the first revised HTML text; a proportion calculation unit, used to determine the content proportion of the current second reference HTML text relative to each line of the second revised HTML text, and use the second revised HTML text with the largest content proportion as the comparison line HTML text; A second determining unit, configured to determine that the current comparative line of html text is a similar line of text to the current second reference html text when the content proportion of the current second reference html text to the corresponding comparative line of html text is greater than or equal to a preset proportion threshold; A third determining unit, configured to determine that the current comparison line html text is a deletion line text when the content ratio of the current second reference html text to the corresponding comparison line html text is less than a preset ratio threshold; The fourth determining unit is used to use the second revised HTML texts in the plurality of lines of second revised HTML texts except the similar lines of text as newly added lines of text.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.

10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.