Electronic book data processing method and device, equipment and storage medium
By automatically identifying and splitting chapters of e-books, the problem of low efficiency in chapter splitting in the existing technology is solved, and a more efficient e-book processing process is achieved, which is suitable for ordinary users to operate.
Patent Information
- Application Number
- CN202410961639.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-11-12
AI Technical Summary
Existing e-book editors require manual manual addition of chapter splitting locations in the source code of e-book files, resulting in inefficient chapter splitting and difficult for ordinary users to operate.
By obtaining the HTML file of the e-book, parsing it into a DOM tree, traversing the text nodes to match the title conditions, automatically identifying the section split locations, and splitting the DOM tree based on these locations to generate the HTML file of each chapter.
It improves the efficiency of e-book chapter splitting, reduces manual intervention, is suitable for ordinary users, and reduces the size and download time of chapter files.
Smart Images

Figure CN118940724A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method, device, equipment and storage medium for processing electronic book data. Background Art
[0002] With the popularization of electronic readers and the continuous development of the electronic book market, reading electronic books through terminal devices such as mobile phones and tablet computers has become popular. Currently, users can read through some reading applications (applications, referred to as APPs).
[0003] After the user opens the e-book, the reading APP loads the e-book file locally or downloads it from the cloud server and renders it. The Electronic Publication (Epub) format is a common e-book upload format. Reading APPs usually download and render e-books by chapter, but the e-book files uploaded by the uploader may not be divided into chapters. There are some Epub e-book editors on the market. These editors can split e-book files into chapters, but they need to manually add the split positions of each chapter in the source code of the e-book file. Chapter splitting is time-consuming and labor-intensive, and the splitting efficiency is low. Summary of the invention
[0004] The embodiments of the present application provide an electronic book data processing method, apparatus, device and storage medium, which can automatically identify chapter split positions based on title matching conditions, thereby improving the efficiency of electronic book chapter splitting.
[0005] In a first aspect, an embodiment of the present application provides a method for processing electronic book data, the method comprising:
[0006] Obtaining an HTML file of an electronic book, wherein the original HTML file includes contents of multiple chapters of the electronic book;
[0007] Parsing the original HTML file to obtain an original document object model DOM tree corresponding to the original HTML file, wherein the original DOM tree includes a plurality of element nodes, and the element nodes include at least one text node;
[0008] Traversing the text nodes of the original DOM tree, matching the title matching condition corresponding to the electronic book with each text node, obtaining K matched titles and positions of K target element nodes, wherein the target element node is the element node where the matched title is located;
[0009] The chapter split positions are determined according to the positions of the K target element nodes, the original DOM tree is split according to the chapter split positions to obtain a final DOM tree corresponding to each chapter split position, and the final DOM tree corresponding to each chapter split position is serialized into an HTML file corresponding to the chapter.
[0010] In some exemplary embodiments, determining the chapter split positions according to the positions of the K target element nodes, splitting the original DOM tree according to the chapter split positions, and obtaining a final DOM tree corresponding to each chapter split position includes:
[0011] Traverse the K target element nodes or the remaining K-1 target element nodes except the target element node corresponding to the first title, insert a marker node on the left side of each target element node, and obtain a target DOM tree corresponding to the original DOM tree, where the position of the marker node is the chapter split position;
[0012] The marked nodes in the target DOM tree are traversed, and the target DOM tree is split according to the marked nodes to obtain a final DOM tree corresponding to each marked node.
[0013] In some exemplary embodiments, traversing the marked nodes in the target DOM tree, splitting the target DOM tree according to the marked nodes, and obtaining a DOM tree splitting result corresponding to each marked node includes:
[0014] Traversing the marked nodes in the target DOM tree in a traversal order, and for a current marked node, obtaining an input DOM tree of the current marked node, wherein when the current marked node is the first marked node visited, the input DOM tree of the current marked node is the target DOM tree, and when the current marked node is not the first marked node, the input DOM tree of the current marked node is an intermediate DOM tree corresponding to a previous marked node;
[0015] According to the common ancestor node of all marked nodes in the target DOM tree, a split mark is added to the split node of the input DOM tree of the current marked node, wherein the split node is an element node on the path from the current marked node to the common ancestor node;
[0016] Remove the current marked node, the sibling node on the right side of the current marked node, and the sibling node on the right side of the split node from the input DOM tree of the current marked node to obtain a final DOM tree corresponding to the current marked node;
[0017] The current marked node, the sibling node on the left side of the current marked node, and the sibling node on the left side of the split node are removed from the input DOM tree of the current marked node to obtain an intermediate DOM tree corresponding to the current marked node, and the intermediate DOM tree corresponding to the current marked node is used as the input DOM tree of the next marked node.
[0018] In some exemplary embodiments, the determining of the chapter splitting positions according to the positions of the K target element nodes and before splitting the original DOM tree according to the chapter splitting positions further includes:
[0019] Displaying an editing interface, wherein the editing interface includes the K titles and a delete control for each title;
[0020] In response to a first operation of a delete control on a first title among the K titles, the first title and a position of a target element node corresponding to the first title are deleted.
[0021] In some exemplary embodiments, before removing the current marked node, the sibling node on the left side of the current marked node, and the sibling node on the left side of the split node from the input DOM tree of the current marked node, the method further includes:
[0022] The removed current marked node, the sibling node on the left side of the current marked node, and the sibling node on the right side of the split node are restored to obtain the input DOM tree of the current marked node.
[0023] In some exemplary embodiments, the title matching condition includes: a first-level title matching condition or a multi-level title matching condition.
[0024] In some exemplary embodiments, the title matching condition adopts a regular expression.
[0025] In some exemplary embodiments, before traversing the element nodes of the original DOM tree, matching the title matching condition corresponding to the electronic book with each element node, and obtaining the position of the target element node that matches successfully, the method further includes:
[0026] Display multiple title matching condition templates in chapter split page;
[0027] The title matching condition is selected for the electronic book from the plurality of title matching condition templates based on a user operation.
[0028] In some exemplary embodiments, after serializing the final DOM tree corresponding to each chapter split position into an HTML file corresponding to the chapter, the method further includes:
[0029] Storing locally the HTML files corresponding to each chapter of the e-book;
[0030] Alternatively, the HTML files corresponding to each chapter of the e-book are stored in a cloud server.
[0031] In some exemplary embodiments, the method further comprises:
[0032] In response to a user's triggering operation of reading a target chapter of the electronic book, obtaining an HTML file corresponding to the target chapter from a local server or the cloud server;
[0033] The content of the target chapter is displayed according to the HTML file corresponding to the target chapter.
[0034] In a second aspect, an embodiment of the present application provides an electronic book data processing device, the device comprising:
[0035] An acquisition module, used for acquiring an original HTML file of an electronic book, wherein the original HTML file includes contents of multiple chapters of the electronic book;
[0036] A parsing module, configured to parse the original HTML file to obtain an original document object model DOM tree corresponding to the original HTML file, wherein the original DOM tree includes a plurality of element nodes, and the element nodes include at least one text node;
[0037] A matching module, used for traversing the text nodes of the original DOM tree, matching the title matching condition corresponding to the electronic book with each text node, and obtaining the positions of K matched titles and K target element nodes, wherein the target element node is the element node where the matched title is located;
[0038] The splitting module is used to determine the chapter splitting position according to the positions of the K target element nodes, split the original DOM tree according to the chapter splitting position, obtain the final DOM tree corresponding to each chapter splitting position, and serialize the final DOM tree corresponding to each chapter splitting position into an HTML file corresponding to the chapter.
[0039] In a third aspect, an embodiment of the present application provides a processing device, comprising: a processor and a memory, the memory being used to store a computer program, the processor being used to call and run the computer program stored in the memory to execute the method described in the first aspect above.
[0040] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program enables a computer to execute the method described in the first aspect above.
[0041] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the method described in the first aspect above.
[0042] The electronic book data processing method, device, equipment and storage medium provided by the embodiment of the present application obtain the original HTML file of the electronic book, parse the original HTML file to obtain the original DOM tree, the original DOM tree includes multiple element nodes, and the element nodes include at least one text node; traverse the text nodes of the original DOM tree, match the title matching condition corresponding to the electronic book with each text node, obtain the positions of K matched titles and K target element nodes, and the target element node is the element node where the matched title is located; determine the chapter split position according to the position of the K target element nodes, split the original DOM tree according to the chapter split position, obtain the final DOM tree corresponding to each chapter split position, and serialize the final DOM tree corresponding to each chapter split position into the HTML file corresponding to the chapter. The method can automatically identify the chapter split position based on the title matching condition, thereby improving the efficiency of chapter splitting of the electronic book. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0044] Figure 1 is a flow chart of the data processing method of the electronic book provided in the first embodiment of the present application;
[0045] Figure 2 This is a schematic diagram of the structure of the DOM tree obtained by parsing the original HTML file;
[0046] Figure 3 This is a schematic diagram of the changes in the DOM tree before and after the insertion of the marked node;
[0047] Figure 4 for Figure 3 A schematic diagram of the right splitting process of the first marked node of the target DOM tree shown;
[0048] Figure 5 for Figure 4 A schematic diagram of the left splitting process of the first marked node of the target DOM tree shown;
[0049] Figure 6 for Figure 5 A schematic diagram of the splitting process of the second splitting result shown;
[0050] Figure 7 A flowchart of the electronic book data processing method provided in the second embodiment of the present application;
[0051] Figure 8 A schematic diagram of the editing interface;
[0052] Fig. 9 A structural diagram of the target DOM tree;
[0053] Fig.10 for Fig. 9 A schematic diagram of the right split of the first marked node of the target DOM tree shown;
[0054] Fig.11 for Fig.10 A schematic diagram of the left split of the first marked node of the target DOM tree shown;
[0055] Fig.12 for Fig.11 Schematic diagram of left-side splitting and left-side splitting of splitting result 2 shown;
[0056] Fig.13 A schematic diagram of the structure of an electronic book data processing device provided in Embodiment 3 of the present application;
[0057] Fig.14 A structural schematic diagram of the processing equipment provided in Example 4 of the present application. DETAILED DESCRIPTION
[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0059] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0060] The embodiment of the present application provides a method for processing electronic book data, which can automatically split the chapters of the electronic book.
[0061] E-books are books that store the contents of traditional books in digital form and can be read through electronic devices. Different from traditional publications that use paper as a carrier, e-books are an important way of reading in the digital age. E-books can digitally record multimedia content such as text, pictures, sounds, and images in electronic devices that use light, electricity, and magnetism as media. Accordingly, they must be read, copied, and transmitted with the help of electronic devices.
[0062] The ePub format is an electronic book content format that can be automatically rearranged. The significance of automatic rearrangement is that the text content can be displayed in the most suitable way for reading according to the characteristics of the electronic device currently being read.
[0063] An ePub file of an e-book is a standard format for electronic publications, which may contain one or more Hyper Text Markup Language (HTML) files to present the content of the e-book.
[0064] In actual applications, the original file package of the e-book imported or uploaded by the user through the reading client usually includes one or more HTML files, and the HTML files in the original file package are referred to as original HTML files below. The original HTML files usually include the contents of multiple chapters of multiple e-books. The original file package uploaded by the user can be stored in the local storage of the electronic device where the reading client is located, or in the cloud server.
[0065] The original HTML file is usually large. If the original HTML file is used directly for content display, some problems will arise. On the one hand, the reading client needs to download an original HTML file at one time. Since the HTML file is large, it takes a long time to download, especially in a weak network environment. On the other hand, the reading client needs to render the original HRML file at one time, resulting in excessive memory usage and a long rendering time.
[0066] Therefore, the content in the original HTML file needs to be split into multiple smaller HTML files according to the chapters. When the user reads the e-book through the reading client, only the HTML file of one chapter needs to be downloaded each time and rendered at one time.
[0067] There are some Epub e-book editors on the market that can split e-book files into chapters, but they need to manually add the split positions of each chapter in the source code of the e-book file. On the one hand, chapter splitting is time-consuming and laborious, and the splitting efficiency is low. On the other hand, it is difficult for ordinary users or readers to operate the source code of the e-book file, resulting in the inability to split the e-book into chapters.
[0068] In order to solve the problems in the prior art, an embodiment of the present application provides an e-book data processing method that can automatically identify and split chapters.
[0069] In an embodiment of the present application, a reading client is used to provide an e-book import function and a reading function. The reading client can be a reading app, a browser or a small program, etc. The reading client runs on a terminal device, which can be a mobile phone, a tablet computer, a dedicated e-reader, a smart wearable device, a laptop computer, a desktop computer, a smart TV, a smart car-mounted device, a smart TV, or any other electronic device that can realize e-book reading.
[0070] The Epub file of the e-book can be stored on a terminal device or a storage server.
[0071] After introducing the application scenario of the embodiment of the present application, a data processing method for an e-book provided by the embodiment of the present application is described in detail with reference to the accompanying drawings.
[0072] Figure 1 is a flow chart of the data processing method of an electronic book provided in the first embodiment of the present application. The execution subject of this embodiment is a processing device, which can be a terminal device or a processing server. The processing server is used to provide a chapter splitting function of the electronic book. Figure 1 As shown, the method of this embodiment includes the following steps.
[0073] S101: Acquire an original HTML file of an electronic book, where the original HTML file includes contents of multiple chapters of the electronic book.
[0074] The Epub file of the electronic book may include one or more original HTML files, which are also called HTML documents. The processing device reads each original HTML file in sequence, and the original HTML file includes the contents of multiple chapters of the electronic book. Exemplarily, the Epub file of the electronic book includes only one original HTML file, which includes the contents of all chapters of the electronic book.
[0075] When the processing device is a terminal device, the terminal device can read the original HTML file from a local storage device, or read the original HTML file from a storage server, the storage server is used to store e-books uploaded by users, and users import e-books through the e-book import function of the reading client on the terminal device, and can choose to store them locally or in the storage server. When the processing device is a processing server, the processing server obtains the original HTML file from the storage server.
[0076] The user opens a reading client, which provides an entrance to the chapter splitting function. The user opens the chapter splitting page through the entrance. On the chapter splitting page, the user can select the e-book to be split and trigger the splitting process. After the splitting process is triggered, the processing device downloads the original HTML file of the e-book and reads the original HTML file of the e-book into the memory of the processing device.
[0077] S102: Parse the original HTML file to obtain an original DOM tree corresponding to the original HTML file. The original DOM tree includes a plurality of element nodes, and the element nodes include at least one text node.
[0078] HTML files are composed of a series of elements, which use tags to mark different types of content, such as paragraphs, titles, lists, links, pictures, etc.
[0079] The structure of a typical HTML file includes the following parts:
[0080] <!DOCTYPE html>: Document type declaration, telling the browser that this is an HTML5 document.
[0081] : The root element, which contains the entire HTML document.
[0082] : The header part contains the document's metadata, such as title, character encoding, style sheet link, and script file.
[0083] <title> : Defines the title of the document, which is displayed in the browser title bar or page tab.< / title>
[0084] : The main part contains the content actually displayed on the web page, such as text, pictures, videos, etc.
[0085] Document Object Model (DOM) is a cross-platform and cross-language interface used to structure HTML files into a tree structure. Therefore, the DOM of an HTML file is also called a DOM tree. The smallest unit of a DOM is called a node. The DOM tree of an HTML file consists of various types of nodes. A node in a DOM tree represents a part of a document, such as an element, an attribute, and text content.
[0086] The node types in the DOM tree include: element node, text node, attribute node, document node, etc. Among them, the element node represents the HTML element, such as , , Etc.; text node represents the text content in the element, usually the child node of the element node; attribute node represents the attributes of the element, such as identity (ID for short), class name (class), etc.; document node represents the entire HTML document and is the entrance to the DOM tree.
[0087] In this embodiment, an original HTML file is parsed into an original DOM tree. The main body of the original HTML file is tags. The processing device reads the original HTML file, parses each HTML tag, and converts it into a node on the DOM tree. The node after the HTML tag is converted is called an element node (or element), and the element node includes one or more text nodes.
[0088] Figure 2 This is a schematic diagram of the structure of the DOM tree obtained by parsing the original HTML file, such as Figure 2 As shown, the processing device reads and parses each HTML file in turn to obtain the corresponding DOM tree, which represents the root node, and are the children of the root node. The text node is marked as "#text". The text node has no children and is always a leaf of the DOM tree.
[0089] S103, traversing the text nodes of the original DOM tree, matching the title matching condition corresponding to the electronic book with each text node, obtaining K matched titles and positions of K target element nodes, wherein the target element node is the element node where the matched title is located.
[0090] The title matching condition is used to match the text nodes in the original DOM tree to identify the titles of each chapter in the original HTML file and the positions of the titles. Optionally, if the e-book has subsections, the titles of the subsections and the positions of the subsection titles can also be identified.
[0091] The text node is a child node of the element node. The text node can also be understood as the content or attribute of the element node. Therefore, matching the title matching condition with the text node can also be described as matching the title matching condition with the element node. Matching the title matching condition with the element node means matching the title matching condition with the content of the element node (i.e., the text node).
[0092] In this embodiment, when the title matching condition successfully matches a text node, a matched title is obtained, and the element node of the successfully matched text node is the target element node where the matched title is located, so the position of the target element node is obtained. By traversing the text nodes of the original DOM tree, multiple text nodes and multiple titles can be matched.
[0093] It is not general. E-books usually include multiple chapters. Some chapters in some e-books may include multiple subsections. When splitting, independent chapters (chapter without subsections) can be split into one chapter, and each subsection in the chapter can be split into a separate chapter. For example, if the fifth chapter of the e-book includes 3 subsections, the 3 subsections of the fifth chapter can be split into 3 chapters. When a chapter is an independent chapter, the title of the independent chapter needs to be identified during title recognition. The title of the independent chapter can be called a first-level title. When a chapter includes multiple subsections, the title of the subsection needs to be identified during title recognition. The title of the subsection can be called a second-level title.
[0094] Correspondingly, the title matching conditions for e-books include: first-level title matching conditions or multi-level title matching conditions. The first-level title matching conditions are used to match the chapter titles of independent chapters, and the second-level title matching conditions are used to match the titles of subsections.
[0095] Optionally, the title matching conditions use regular expressions (Regular Expression). A regular expression is a method of describing text patterns, which is used to define rules in operations such as searching, matching, or replacing strings. Regular expressions are usually composed of ordinary characters, special characters, character classes, anchors, grouping and references, and escape characters, etc.
[0096] The regular expression of the title usually starts with the character "第", followed by one or more spaces (\s*), then a number (which can be a Chinese numeral or an Arabic numeral), followed by zero or more spaces, and finally ends with a string ending with "册", "卷", "部", "章", or "回". It can be used to match the numbers of e-books, chapter identifiers, subsections, etc.
[0097] Exemplarily, the regular expression for the first-level title is: ^\s*第\s*[0-9一二三四五六七八九十百千零壹贰叁肆伍陆柒捌玖拾]+\s*[册卷部章回], and the regular expression for the second-level title is: ^\s*第\s*[0-9一二三四五六七八九十百千零壹贰叁肆伍陆柒捌玖拾]+\s*节.
[0098] Among them, "[0-9一二三四五六七八九十百千零壹贰叁肆伍陆柒捌玖拾]+" is a character class that matches any one character in Chinese numerals and Arabic numerals, and this character class can appear once or more times (+). This ensures that whether it is the number "1" or the Chinese character "一", or more complex combinations such as "一千零一" or "拾壹" can be matched.
[0099] Through the above regular expression for the first-level title, chapter titles of the following types can be matched: "第1册", "第二十章", "第壹佰零壹回", etc.
[0100] Through the above regular expression for the second-level title, subsection titles of the following types can be matched: "第1节", "第十二节", "第零零三节", or "第叁拾节", etc.
[0101] The title matching condition corresponding to the e - book can be the system - default title matching condition or the title matching condition selected by the user from multiple title matching conditions provided by the system. Correspondingly, the reading client provides the user with multiple title matching condition templates or examples for selection. The user can select a suitable title matching condition template from the multiple title matching condition templates as the title matching condition for the e - book according to the title type of the e - book to be split.
[0102] Optionally, the user can also write a title matching condition adapted to the title type of the e - book by himself. The title matching condition template can also be continuously updated to meet the needs of different users.
[0103] Exemplarily, the position of text node A can be represented in the following way: text node A is the x - th element node of its parent node, and this position representation can also be understood as the top - down path representation of text node A.
[0104] Take Figure 2 the shown DOM tree as an example. The text node is represented by "#text". Taking the first text node from the right to the left at the bottom layer as an example, that is, "#text Chapter 1 aaaa", the parent node of this text node is the h1 tag. It is the 0 - th element node in the h1 tag, and the parent node of the h1 tag is the body tag. The h1 tag is the 0 - th element node of the body tag, and the parent node of the body tag is the html tag. The body tag is the 1 - st element node of the html tag. Therefore, the position of this node can be represented by an array [1, 0, 0]. Similarly, the position of the first text node from the right to the left at the bottom layer, that is, "#text Chapter 2 bbbb", can be obtained as [1, 1, 0]. In the same way, the positions of each node in the DOM tree can be obtained, and the positions of each node in the DOM tree are as shown in the arrays in the figure.
[0105] Optionally, after the K titles and the positions of the K target element nodes are matched, the user can also delete some titles to adjust the number of split HTML files.
[0106] Exemplarily, an editing interface is displayed. The editing interface includes K titles and a deletion control for each title. In response to a first operation on the deletion control of the first title among the K titles, the first title and the position of the target element node corresponding to the first title are deleted. The first title is any one of the K titles. By deleting the position of the target element node of the first title, it is avoided that the chapter or section corresponding to the first title is separately split into an HTML file.
[0107] S104, determining chapter split positions according to the positions of the K target element nodes, splitting the original DOM tree according to the chapter split positions to obtain a final DOM tree corresponding to each chapter split position, and serializing the final DOM tree corresponding to each chapter split position into an HTML file corresponding to the chapter.
[0108] In this embodiment, the value of K is an integer. When the value of K is 0, it means that no title is matched, and the subsequent steps are not executed. When the value of K is greater than 0, it means that the title is matched and chapter splitting is required. It can be understood that K target element nodes correspond to K titles, each title is a chapter or a subsection title, and after chapter splitting, a total of K chapters need to be split.
[0109] In the first implementation, K chapter split positions are determined according to the positions of K target element nodes. After splitting according to the K split positions, a total of K+1 DOM trees can be obtained. After serialization, a total of K+1 HTML files can be obtained. The K+1 HTML files include HTML files of K chapters and HTML files corresponding to the content before the first chapter (such as the preface and introduction of the novel, etc.). In this implementation, the content before the first chapter is split into a separate HTML file.
[0110] In the second implementation, the target element node corresponding to the first title among the K target element nodes is ignored or deleted, and there are K-1 target element nodes left. K-1 chapter split positions are determined according to the positions of the K-1 target element nodes. After splitting according to the K-1 split positions, a total of K DOM trees can be obtained, and after serialization, a total of K HTML files can be obtained. In this implementation, the first chapter and the content before the first chapter (such as the preface and introduction of the novel, etc.) are split into one HTML file, and each of the remaining chapters corresponds to an HTML file.
[0111] Therefore, K or K-1 chapter split positions are obtained according to the positions of the K target element nodes, and the original DOM tree is split according to the K split positions.
[0112] In an exemplary splitting method, the K target element nodes or the remaining K-1 target element nodes except the target element node corresponding to the first title (the title of the first chapter or the title of the first subsection) are traversed, and a marker node is inserted on the left side of each target element node to obtain a target DOM tree corresponding to the original DOM tree, and the position of each marker node is a chapter split position. Then, the marker nodes in the target DOM tree are traversed, and the target DOM tree is split according to the marker nodes to obtain a final DOM tree corresponding to each marker node, and the final DOM tree corresponding to each marker node is serialized into an HTML file corresponding to a chapter.
[0113] Figure 3 This is a schematic diagram of the changes in the DOM tree before and after the tag node is inserted. The element node h1 and the element node h2 are both target element nodes. Figure 3 As shown in (a), the left side of the target element node is the split position (i.e. the position shown by the dotted line), and a marker node is inserted at each split position (i.e. the left side of each target element node), and the result is Figure 3 (b) shows the DOM tree. Figure 3 As shown, after the marker node is inserted, the position of each node in the original DOM tree changes, but the relative position of each marker node and the corresponding target element node remains unchanged. The position of each marker node is the position of its corresponding target element node minus a preset value.
[0114] Figure 3 The position of each marked node is the position of its corresponding target element node minus 1. For example, if the position of the target element node h1 is [1,2], then the position of its corresponding marked node is [1,1]; if the position of the target element node h2 is [1,4], then the position of its corresponding marked node is [1,3].
[0115] The marked nodes are some newly added nodes in the original DOM tree. The type of the marked nodes is different from the existing nodes in the original DOM tree, and can be a newly added node type, so that the processing device can identify the marked nodes and perform corresponding processing when accessing the target DOM tree. Exemplarily, the value of the class name attribute of the marked node is set to a new value to distinguish the marked node.
[0116] In this splitting method, the splitting position is determined by the position of the marked node. When the method of this embodiment is applied to different systems, even if the indexing method of the position of the node in the original DOM tree changes due to the parsing method or other reasons, the marked node can still be identified and the splitting position can be determined according to the position of the marked node, thereby being able to adapt to different systems and scenarios.
[0117] In another exemplary splitting method, the K target element nodes or the remaining K-1 target element nodes except the target element node corresponding to the first title (the title of the first chapter or the title of the first subsection) are traversed, the left side of each target element node is determined to be the split position, and the positional relationship between the split position and the target element node is recorded, for example, the split position is recorded to be less than the position of the target element node, for example, the split position corresponding to the target element node h1 is recorded to be less than [1,2].
[0118] Then, the original DOM tree is traversed according to the recorded split positions, and the original DOM tree is split according to the split positions to obtain the final DOM tree corresponding to each split position, and the final DOM tree corresponding to each split position is serialized into an HTML file corresponding to a chapter.
[0119] by Figure 3 Taking the target DOM tree shown as an example, the splitting process of the target DOM tree is explained. The marked nodes in the target DOM tree are traversed in order, and the first marked node is found. The first marked node and its brother nodes on the right are temporarily removed from the target DOM tree to obtain split result 1. Split result 1 is the final DOM tree corresponding to the first marked node. The DOM tree of split result 1 is then serialized into an HTML document and saved to obtain an HTML file obtained by splitting the first marked node.
[0120] Figure 4 for Figure 3 A schematic diagram of the right splitting process of the first tag node of the target DOM tree is shown as Figure 4 As shown, Figure 4 (a) is the structure of the target DOM tree. Traverse the target DOM tree to find the first marked node, that is, the marked node [1,1], and then determine the node to be removed by the right split. The node to be removed refers to Figure 4 The nodes corresponding to the gray box in (b) include the marked node [1,1] and its sibling nodes on the right. After removing the marked node [1,1] and its sibling nodes on the right, the final DOM tree corresponding to the marked node [1,1] is obtained. The final DOM tree corresponding to the marked node [1,1] is deserialized to obtain the HTML file corresponding to the marked node [1,1], and the HTML file corresponding to the marked node [1,1] is saved.
[0121] After saving the HTML file corresponding to the first marked node, restore the nodes removed when splitting the first marked node. Since the DOM tree adopts a linked list structure, the removed nodes can be linked again. Then, delete the first marked node and its sibling nodes on the right to obtain split result 2. The difference from split result 1 is that the DOM tree corresponding to split result 2 needs to be used as the input of the next marked node splitting operation. Therefore, split result 2 is also called the intermediate DOM tree corresponding to the first marked node.
[0122] Figure 5 for Figure 4 A schematic diagram of the left splitting process of the first marked node of the target DOM tree is shown as Figure 5 As shown, Figure 5 (a) The DOM tree structure is restored for the nodes removed when the left side of the first marked node is split, and then the nodes to be removed when the right side is split are determined. The nodes to be removed refer to Figure 5 The nodes corresponding to the gray box in (b) include the marked node [1,1] and its sibling nodes on the left. After removing the marked node [1,1] and its sibling nodes on the left, the intermediate DOM tree corresponding to the marked node [1,1] is obtained. The intermediate DOM tree corresponding to the marked node [1,1] is used as the input of the splitting process of the next marked node.
[0123] In this embodiment, two splits are performed on each marked node, namely left split and right split, to obtain a final DOM tree and an intermediate DOM tree corresponding to the marked node. The final DOM tree is converted into an HTML file, and the intermediate DOM tree is used as input in the splitting process of the next marked node.
[0124] Take the intermediate DOM tree corresponding to the first marked node as input, find the first marked node in the intermediate DOM tree in the traversal order, if there is no marked node in the intermediate DOM tree, then determine to end the split, if the first marked node is found in the intermediate DOM tree, then follow Figure 4 and Figure 5 The split shown performs a right split and a left split on the first marked node.
[0125] by Figure 5 Taking the second intermediate result shown as an example, the second intermediate result includes a marked node, and the second intermediate result needs to be further split. Figure 6 for Figure 5 The schematic diagram of the splitting process of the second splitting result shown in FIG. Figure 6 As shown, Figure 5 The second split result shown is taken as input, Figure 6 (a) is used as input, and the first marked node in the intermediate DOM tree corresponding to the second split result is found. The first marked node in the intermediate DOM tree corresponding to the second split result is the second marked node in the target DOM tree. The first marked node in the intermediate DOM tree corresponding to the second split result is the marked node [1,1].
[0126] After determining to split the marked node [1,1] in the intermediate DOM tree corresponding to the second split result, first split the marked node [1,1] on the right side, remove the marked node [1,1] and its sibling nodes on the right, and obtain the third split result as follows Figure 6 As shown in (b), the third split result is the final DOM tree corresponding to the marked node [1,1]. The final DOM tree corresponding to the marked node [1,1] is deserialized to obtain the HTML file corresponding to the marked node [1,1], and the HTML file corresponding to the marked node [1,1] is saved. Then, the marked node [1,1] is split on the left side, and the marked node [1,1] and its sibling nodes on the left are removed, and the fourth split result is obtained as shown in Figure 6 As shown in (c), the fourth split result is the intermediate DOM tree corresponding to the marked node [1,1].
[0127] Figure 6 If the fourth split result does not include the marked node, the splitting of the fourth split result is stopped, and the fourth split result is used as a final DOM tree and serialized into an HTML file. If the fourth split result also includes the marked node, the splitting is continued according to the above splitting method until the split result does not include the marked node, and the splitting is stopped.
[0128] It should be made clear that Figure 3-Figure 6 The DOM tree shown is a relatively simple tree structure. In actual situations, it may include more complex DOM trees. The above splitting method is also applicable to complex DOM trees, and only some simple processing operations are required.
[0129] Optionally, when splitting the DOM tree, the traversal order of the DOM tree may be pre-order traversal, in-order traversal, subsequent traversal or level-order traversal, and this embodiment does not limit the traversal order.
[0130] The HTML file corresponding to each chapter obtained in the above splitting process can be saved in the Epub file of the electronic book, and finally all the HTML files obtained by splitting replace the original HTML file. For example, the original Epub file of the electronic book includes an original HTML file, and the electronic book includes K chapters in total. Through the above splitting method, K HTML files are obtained, that is, each chapter corresponds to an HTML file, and the K HTML files replace the original HTML file in the original Epub file.
[0131] When the title matching condition only includes the first-level title matching condition, the processing device separates each chapter into an HTML file. When the title matching condition includes multi-level title matching conditions, the processing device can separate the unit with smaller granularity than the chapter in the electronic book into an HTML file. For example, when some chapters in the electronic book include multiple subsections, each subsection can also be separated into an HTML file. For example, if the eighth chapter of the electronic book includes 3 subsections, each subsection can be separated into an HTML document.
[0132] After the original HTML file is split, the processing device will also generate a directory of the e-book, which includes the title of each chapter of the e-book. If a chapter includes multiple subsections, the directory of the e-book also includes the title of the subsection. It should be noted that deleting a chapter or subsection title in the editing page does not affect the directory of the e-book. The chapter or subsection title deleted in the editing page is still included in the directory of the e-book. The chapter or title deleted in the editing page is only for the convenience of users to perceive the merging and splitting of chapters or subsections.
[0133] Optionally, after the final DOM tree corresponding to each chapter split position is serialized into an HTML file corresponding to the chapter, the HTML files corresponding to each chapter of the e-book can be stored locally, or the HTML files corresponding to each chapter of the e-book can be stored in a cloud server.
[0134] In this embodiment, the original HTML file of the e-book (including the contents of multiple chapters) is split into HTML files corresponding to multiple chapters. When a user reads any chapter of the e-book, in response to the user's reading trigger operation on the target chapter of the e-book, the HTML file corresponding to the target chapter is obtained from the local or cloud server, and the contents of the target chapter are displayed according to the HTML file corresponding to the target chapter.
[0135] The target chapter is any chapter of the e-book, and the reading trigger operation can be a user clicking on the title of the target chapter in the directory of the e-book, or a user clicking on the "next chapter" control on the reading page. Optionally, in some implementations, the user may not read the next chapter through the "next chapter" control on the reading page. When the user reads the last page of the current chapter, the user may slide or turn the page to switch to the next chapter, that is, the reading operation may be any chapter switching operation.
[0136] In this embodiment, the original HTML file including the contents of multiple chapters is split into multiple HTML files, so that each chapter can correspond to an HTML file. Accordingly, when the reading client loads the contents of a certain chapter, it can only download the HTML file corresponding to the chapter from the cloud server. The HTML file corresponding to the chapter is much smaller than the original HTML file before the split. Therefore, the reading client downloads less content. Even when the network status is not good, the user can quickly download the resources of the chapter and avoid waiting for a long time due to the large size of the downloaded HTML file.
[0137] In addition, when the reading client renders the HTML file, it needs to load the HTML file into the memory. When the HTML file is too large, it occupies a large amount of memory space, which may affect the user's use of other applications and lead to user experience. The method of this embodiment has a smaller HTML file for each chapter and will not occupy too much memory, thereby improving the user experience.
[0138] In this embodiment, the original HTML file of the electronic book is obtained, and the original HTML file is parsed to obtain an original DOM tree, wherein the original DOM tree includes multiple element nodes, and the element nodes include at least one text node; the text nodes of the original DOM tree are traversed, and the title matching condition corresponding to the electronic book is matched with each text node to obtain K matched titles and the positions of K target element nodes, wherein the target element node is the element node where the matched title is located; the chapter splitting position is determined according to the positions of the K target element nodes, and the original DOM tree is split according to the chapter splitting position to obtain the final DOM tree corresponding to each chapter splitting position, and the final DOM tree corresponding to each chapter splitting position is serialized into the HTML file corresponding to the chapter. The method can automatically identify the chapter splitting position based on the title matching condition, thereby improving the efficiency of chapter splitting of the electronic book.
[0139] Figure 7 This is a flow chart of the data processing method of the electronic book provided in the second embodiment of the present application, such as Figure 7 As shown, the method provided in this embodiment includes the following steps.
[0140] S201: Acquire an original HTML file of an electronic book, where the original HTML file includes contents of multiple chapters of the electronic book.
[0141] S202: Parse the original HTML file to obtain an original DOM tree corresponding to the original HTML file.
[0142] S203, traversing the text nodes of the original DOM tree, matching the title matching condition corresponding to the electronic book with each text node, obtaining K matched titles and positions of K target element nodes, wherein the target element node is the element node where the matched title is located.
[0143] Optionally, after matching the positions of K titles and K target element nodes, the user may delete the titles to adjust the number of HTML files after splitting.
[0144] Exemplarily, an editing interface is displayed, which includes K titles and a deletion control for each title. In response to a first operation on the deletion control of a first title among the K titles, the first title and the position of the target element node corresponding to the first title are deleted. The first title is any one of the K titles.
[0145] By deleting the position of the target element node corresponding to the first title, the chapter or subsection corresponding to the first title will not be split into an HTML file separately during subsequent splitting. Instead, the chapter or subsection corresponding to the first title and the chapter or subsection corresponding to the next adjacent title will be split into one HTML file.
[0146] Figure 8 A schematic diagram of the editing interface is shown in Figure 8 As shown, the HTML file of the electronic book to be split is displayed in the left column of the editing interface, and all the matched titles and the delete control of each title are displayed in the right column. The user can view all the matched titles by dragging the rightmost slider. When the user selects the title of Chapter 18 Section (1) and clicks or double-clicks the delete control corresponding to the title of Chapter 18 Section (1), the title of Chapter 18 Section (1) is deleted from the editing interface, and the position of the target element node corresponding to the title of Chapter 18 Section (1) stored in the memory is deleted. After deleting the position of the target element node corresponding to the title of Chapter 18 Section (1), Chapter 18 Section (1) will not be split into an HTML file alone, but will be split into an HTML file together with the next adjacent title (i.e., Chapter 18 Section (2)). It can be understood that if the position of the target element node corresponding to the title of Chapter 18 Section (1) is not deleted, Chapter 18 Section (1) and Chapter 18 Section (2) will be split into an HTML file separately.
[0147] Figure 8 The example shown is just one case. This method can be used to merge and split multiple subsections of the same chapter into one HTML file. Optionally, different chapters can also be merged and split into one HTML file. For example, after the user deletes the title of Chapter 20, Chapter 20 and Chapter 21 will be merged and split into one HTML file.
[0148] like Figure 8 As shown, the editing interface also includes some other controls, such as the "One-click Generate Directory Node" control. When a user clicks the "One-click Generate Directory Node" control, the following steps will be automatically executed to split the original HTML file into multiple HTML files.
[0149] S204, traverse K target element nodes or the remaining K-1 target element nodes except the target element node corresponding to the first title, insert a marker node on the left side of each target element node, and obtain a target DOM tree corresponding to the original DOM tree, where the position of each marker node is a chapter split position.
[0150] The specific implementation of steps S201-S204 refers to the relevant description of the first embodiment and will not be repeated here.
[0151] S205 , traverse the marked nodes in the target DOM tree in a traversal order, and obtain the input DOM tree of the current marked node.
[0152] Relative to Figure 4-Figure 6 The splitting process shown in the figure, in this embodiment, a general splitting process is used to illustrate the splitting process of the target DOM tree. The processing device can traverse the marked nodes in the target DOM tree in a pre-order traversal, a post-order traversal, or an in-order traversal to obtain the input DOM tree of the current marked node, where the current marked node refers to the marked node currently traversed or accessed.
[0153] Fig. 9 A schematic diagram of the target DOM tree, see Figure 3 and Fig. 9 , compared to Figure 3 , Fig. 9 The target DOM tree shown is a relatively complex DOM tree, which includes element nodes and tag nodes. The element nodes are shown as solid circles, and the tag nodes are shown as dotted circles. The target DOM tree includes 5 tag nodes, so the original HTML file will eventually be split into 6 HTML files. Fig. 9 The target DOM tree shown does not show text nodes. It can be understood that each element node may include one or more text nodes, and the text nodes are child nodes of the element nodes.
[0154] Through the splitting process described in Example 1, each marked node will obtain a final DOM tree and an intermediate DOM tree after splitting, wherein the final DOM tree corresponding to the marked node is serialized into the HTML file of the marked node, and the intermediate DOM tree corresponding to the marked node is used as the input of the next split marked node. Therefore, when the current marked node is the first marked node visited, the input DOM tree of the current marked node is the target DOM tree, and when the current marked node is not the first marked node, the input DOM tree of the current marked node is the intermediate DOM tree corresponding to the previous marked node.
[0155] S206 . Add a split identifier to a split node of the input DOM tree of the current marked node according to the common ancestor node of all marked nodes in the target DOM tree. The split node is an element node on the path from the current marked node to the common ancestor node.
[0156] The common ancestor node (Lowest Common Ancestor, LCA for short) in the target DOM tree can be determined by brute force search method, tree doubling method, offline Tarjan algorithm, etc.
[0157] In this embodiment, the common ancestor node of all the marked nodes in the target DOM tree is the body node, and the body node is the main part of the DOM tree. Figure 8 As shown, the right child node of the root node of the target DOM tree is the body node. The split nodes of the input DOM tree of the current mark node do not include the current mark node and the common ancestor node, but only include all element nodes on the path from the current mark node to the common ancestor node.
[0158] Fig.10 for Fig. 9 The schematic diagram of the right side split of the first marked node of the target DOM tree is shown in the figure, which shows a schematic diagram of the common ancestor node and the split node in the target DOM tree. The split node is the node shown by the gray circle. In this embodiment, after determining the split node, the processing device adds a split identifier to each split node, and the split identifier can be used to distinguish the split node from other element nodes.
[0159] S207 , remove the current marked node, the sibling node on the right side of the current marked node, and the sibling node on the right side of the split node from the input DOM tree of the current marked node to obtain a final DOM tree corresponding to the current marked node.
[0160] like Fig.10 As shown, the current marked node, the sibling nodes on the right side of the current marked node, and all the sibling nodes on the right side of the three split nodes are removed to obtain the split result 1, that is, the final DOM tree corresponding to the current marked node.
[0161] S208: Remove the current marked node, the sibling node on the left side of the current marked node, and the sibling node on the left side of the split node from the input DOM tree of the current marked node to obtain an intermediate DOM tree corresponding to the current marked node, and use the intermediate DOM tree corresponding to the current marked node as the input DOM tree of the next marked node.
[0162] Optionally, before removing the current marked node, the sibling node on the left side of the current marked node, and the sibling node on the left side of the split node from the input DOM tree of the current marked node, the removed current marked node, the sibling node on the left side of the current marked node, and the sibling node on the right side of the split node are restored to obtain the input DOM tree of the current marked node.
[0163] Fig.11 for Fig.10 A schematic diagram of the left split of the first tag node of the target DOM tree is shown as Fig.11 As shown, the first marked node, the sibling nodes on the left of the first marked node, and all the sibling nodes on the left of the three split nodes are removed to obtain split result 2. There are no sibling nodes on the left of the three split nodes, and there is one sibling node on the left of the first marked node. Split result 2 is the intermediate DOM tree corresponding to the current marked node. Split result 2 is used as the input for the next split.
[0164] Fig.12 for Fig.11 The schematic diagram of the left and right splits of the split result 2 is shown, as Fig.12 As shown, after the first marked node is split, the second marked node in the target DOM is split, the second marked node of the target DOM tree is the first marked node in the split result 2, the input DOM tree of the second marked node (i.e., split result 2) includes two split nodes, and the sibling nodes on the right side of the two split nodes are removed from the input DOM tree of the second marked node to obtain split result 3, which is the final DOM tree of the second marked node. Then, the sibling nodes on the right side of the two removed split nodes are restored to obtain the input DOM tree of the second marked node, and the sibling nodes on the left side of the two marked nodes are removed from the input DOM tree of the second marked node to obtain split result 4, which is the intermediate DOM tree of the second marked node.
[0165] Steps S205-S208 are executed in a loop to split each marked node in turn until there is no marked node in the intermediate DOM tree corresponding to the marked node after a certain split. In this case, the split is not continued, but the intermediate DOM tree corresponding to the marked node is taken as a final DOM tree and serialized.
[0166] S209: Serialize the final DOM tree corresponding to each marked node into an HTML file corresponding to the chapter.
[0167] Steps S205-S208 are executed in a loop to split and obtain the final DOM trees corresponding to all the marked nodes, and then the final DOM trees corresponding to each marked node are serialized into an HTML file. In this embodiment, the processing device can obtain the final DOM trees corresponding to all the marked nodes after all the marked nodes are visited, and then uniformly serialize the final DOM trees corresponding to all the marked nodes, or after each split to obtain the final DOM tree corresponding to a marked node, serialize the final DOM corresponding to the marked node, and then visit the next marked node.
[0168] In this embodiment, the original HTML file of the electronic book is obtained, and the original HTML file is parsed to obtain an original DOM tree, wherein the original DOM tree includes multiple element nodes, and the element nodes include at least one text node; the text nodes of the original DOM tree are traversed, and the title matching condition corresponding to the electronic book is matched with each text node to obtain the positions of K matched titles and K target element nodes, and a marking node is inserted on the left side of each target element node to obtain a target DOM tree, and the marking nodes in the target DOM tree are traversed, and the target DOM tree is split according to the marking nodes to obtain a final DOM tree corresponding to each marking node, and the final DOM tree corresponding to each marking node is serialized into an HTML file corresponding to a chapter. The method can automatically identify the title of the chapter based on the title matching condition, and insert a marking node on the left side of the target element node where the title is located, mark the chapter split position by the marking node, and split the target DOM tree based on the marking node to obtain the HTML files of each chapter. The method does not require the user to manually determine the split position, thereby improving the efficiency of chapter splitting of the electronic book.
[0169] In order to better implement the electronic book data processing method of the embodiment of the present application, the embodiment of the present application also provides an electronic book data processing device. Fig.13 This is a schematic diagram of the structure of the electronic book data processing device provided in the third embodiment of the present application. Fig.13 As shown, the electronic book data processing device 100 may include:
[0170] An acquisition module 11 is used to acquire an original hypertext markup language HTML file of an electronic book, wherein the original HTML file includes contents of multiple chapters of the electronic book;
[0171] A parsing module 12, configured to parse the original HTML file to obtain an original document object model DOM tree corresponding to the original HTML file, wherein the original DOM tree includes a plurality of element nodes, and the element nodes include at least one text node;
[0172] A matching module 13 is used to traverse the text nodes of the original DOM tree, match the title matching condition corresponding to the electronic book with each text node, and obtain the positions of K matched titles and K target element nodes, wherein the target element node is the element node where the matched title is located;
[0173] The splitting module 14 is used to determine the chapter splitting position according to the positions of the K target element nodes, split the original DOM tree according to the chapter splitting position, obtain the final DOM tree corresponding to each chapter splitting position, and serialize the final DOM tree corresponding to each chapter splitting position into an HTML file corresponding to the chapter.
[0174] In some exemplary implementations, the splitting module 14 is specifically used to:
[0175] Traverse the K target element nodes or the remaining K-1 target element nodes except the target element node corresponding to the first title, insert a marker node on the left side of each target element node, and obtain a target DOM tree corresponding to the original DOM tree, where the position of the marker node is the chapter split position;
[0176] The marked nodes in the target DOM tree are traversed, and the target DOM tree is split according to the marked nodes to obtain a final DOM tree corresponding to each marked node.
[0177] In some exemplary implementations, the splitting module 14 is specifically used to:
[0178] Traversing the marked nodes in the target DOM tree in a traversal order, and for a current marked node, obtaining an input DOM tree of the current marked node, wherein when the current marked node is the first marked node visited, the input DOM tree of the current marked node is the target DOM tree, and when the current marked node is not the first marked node, the input DOM tree of the current marked node is an intermediate DOM tree corresponding to a previous marked node;
[0179] According to the common ancestor node of all marked nodes in the target DOM tree, a split mark is added to the split node of the input DOM tree of the current marked node, wherein the split node is an element node on the path from the current marked node to the common ancestor node;
[0180] Remove the current marked node, the sibling node on the right side of the current marked node, and the sibling node on the right side of the split node from the input DOM tree of the current marked node to obtain a final DOM tree corresponding to the current marked node;
[0181] The current marked node, the sibling node on the left side of the current marked node, and the sibling node on the left side of the split node are removed from the input DOM tree of the current marked node to obtain an intermediate DOM tree corresponding to the current marked node, and the intermediate DOM tree corresponding to the current marked node is used as the input DOM tree of the next marked node.
[0182] In some exemplary implementations, a display module and a deletion module are also included;
[0183] The display module is used to display an editing interface, wherein the editing interface includes the K titles and a delete control for each title;
[0184] The deleting module is used to delete the first title and the position of the target element node corresponding to the first title in response to a first operation of a delete control on the first title among the K titles.
[0185] In some exemplary implementations, the splitting module 14 is further configured to:
[0186] Before removing the current marked node, the sibling node on the left side of the current marked node, and the sibling node on the left side of the split node from the input DOM tree of the current marked node, the removed current marked node, the sibling node on the left side of the current marked node, and the sibling node on the right side of the split node are restored to obtain the input DOM tree of the current marked node.
[0187] In some exemplary implementations, the title matching condition includes: a first-level title matching condition or a multi-level title matching condition.
[0188] In some exemplary implementations, the title matching condition uses a regular expression.
[0189] In some exemplary implementations, the apparatus further includes a display module and a selection module;
[0190] The display module is used to display multiple title matching condition templates in the chapter split page;
[0191] The selection module is used to select the title matching condition for the electronic book from the multiple title matching condition templates based on user operations.
[0192] In some exemplary implementations, the apparatus further includes a storage module, configured to:
[0193] Storing locally the HTML files corresponding to each chapter of the e-book;
[0194] Alternatively, the HTML files corresponding to each chapter of the e-book are stored in a cloud server.
[0195] In some exemplary implementations, the device further includes a display module, configured to:
[0196] In response to a user's triggering operation of reading a target chapter of the electronic book, obtaining an HTML file corresponding to the target chapter from a local server or the cloud server;
[0197] The content of the target chapter is displayed according to the HTML file corresponding to the target chapter.
[0198] It should be understood that the device embodiment and the method embodiment may correspond to each other, and similar descriptions may refer to the method embodiment. To avoid repetition, they will not be described here.
[0199] The above describes the device 100 of the embodiment of the present application from the perspective of the functional module in conjunction with the accompanying drawings. It should be understood that the functional module can be implemented in hardware form, can be implemented by instructions in software form, and can also be implemented by a combination of hardware and software modules. Specifically, the steps of the method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit and / or software form instructions in the processor, and the steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or a combination of hardware and software modules in the decoding processor to perform. Optionally, the software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory, and completes the steps in the above method embodiment in conjunction with its hardware.
[0200] The embodiment of the present application also provides a processing device. Fig.14 A structural schematic diagram of a processing device provided in Example 4 of the present application, such as Fig.14 As shown, the processing device 200 may include:
[0201] The memory 21 and the processor 22, the memory 21 is used to store the computer program and transmit the program code to the processor 22. In other words, the processor 22 can call and run the computer program from the memory 21 to implement the method in the embodiment of the present application.
[0202] For example, the processor 22 may be configured to execute the above method embodiments according to instructions in the computer program.
[0203] In some embodiments of the present application, the processor 22 may include but is not limited to:
[0204] General-purpose processor, digital signal processor (DSP), application-specific integrated circuit (ASIC), field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, etc.
[0205] In some embodiments of the present application, the memory 21 includes but is not limited to:
[0206] Volatile memory and / or non-volatile memory. Among them, the non-volatile memory can be read-only memory (ROM), programmable ROM (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM) or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM bus random access memory (DR RAM).
[0207] In some embodiments of the present application, the computer program may be divided into one or more modules, which are stored in the memory 21 and executed by the processor 22 to complete the method provided by the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program in the processing device.
[0208] like Fig.14 As shown, the processing device 200 may also include: a transceiver 23 and a display screen (not shown in the figure), etc. The transceiver 23 can be connected to the processor 22 or the memory 21, and the display can be connected to the processor 22 or the memory 21.
[0209] The processor 22 may control the transceiver 23 to communicate with other devices, specifically, to send information or data to other devices, or to receive information or data sent by other devices. The transceiver 23 may include a transmitter and a receiver. The transceiver 23 may further include an antenna, and the number of antennas may be one or more.
[0210] The display screen can be used to display a graphical user interface and receive operation instructions generated by the user acting on the graphical user interface. The display screen can be a touch display screen, and the touch display screen can include a display panel and a touch panel. Among them, the display panel can be used to display information input by the user or information provided to the user and various graphical user interfaces of the computer device, and these graphical user interfaces can be composed of graphics, text, icons, videos and any combination thereof. Optionally, the display panel can be configured in the form of a liquid crystal display (LCD, Liquid Crystal Display), an organic light-emitting diode (OLED, Organic Light-Emitting Diode) and the like. The touch panel can be used to collect the user's touch operation on or near it (such as the user uses any suitable object or attachment such as a finger, a stylus, etc. on the touch panel or near the touch panel), and generate corresponding operation instructions, and the operation instructions execute corresponding programs. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch position, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the touch point coordinates, and then sends it to the processor 22, and can receive and execute the command sent by the processor 22. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it is transmitted to the processor 22 to determine the type of touch event, and then the processor 22 provides corresponding visual output on the display panel according to the type of touch event.
[0211] Understandable, although Fig.14 Not shown in the figure, the processing device 200 may also include a camera module, a wireless fidelity WIFI module, a positioning module, a Bluetooth module, an audio module, etc., which will not be repeated here.
[0212] It should be understood that the various components in the processing device are connected via a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus and a status signal bus.
[0213] The present application also provides a computer storage medium on which a computer program is stored, and when the computer program is executed by a computer, the computer can perform the method of the above method embodiment. In other words, the present application embodiment also provides a computer program product containing instructions, and when the instructions are executed by a computer, the computer can perform the method of the above method embodiment.
[0214] The present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of the processor reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the processor executes the corresponding process in the data processing method of the electronic book in the embodiment of the present application, which will not be described in detail for the sake of brevity.
[0215] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the module is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0216] The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. For example, each functional module in each embodiment of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0217] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for processing electronic book data, characterized in that: The method comprises: Acquire an original hypertext markup language file of an electronic book, wherein the original hypertext markup language file includes contents of multiple chapters of the electronic book; Parsing the original hypertext markup language file to obtain an original document object model tree corresponding to the original hypertext markup language file, wherein the original document object model tree includes a plurality of element nodes, and the element nodes include at least one text node; Traversing the text nodes of the original document object model tree, matching the title matching condition corresponding to the electronic book with each text node, obtaining K matched titles and positions of K target element nodes, wherein the target element node is the element node where the matched title is located; The chapter split positions are determined according to the positions of the K target element nodes, the original document object model tree is split according to the chapter split positions to obtain a final document object model tree corresponding to each chapter split position, and the final document object model tree corresponding to each chapter split position is serialized into a hypertext markup language file corresponding to the chapter.
2. The method according to claim 1, characterized in that The determining of the chapter splitting position according to the positions of the K target element nodes, splitting the original document object model tree according to the chapter splitting position, and obtaining a final document object model tree corresponding to each chapter splitting position includes: Traversing the K target element nodes or the remaining K-1 target element nodes except the target element node corresponding to the first title, inserting a marking node on the left side of each target element node to obtain a target document object model tree corresponding to the original document object model tree, wherein the position of the marking node is the chapter split position; The marked nodes in the target document object model tree are traversed, and the target document object model tree is split according to the marked nodes to obtain a final document object model tree corresponding to each marked node.
3. The method according to claim 2, characterized in that The traversing the marked nodes in the target document object model tree, splitting the target document object model tree according to the marked nodes, and obtaining a document object model tree splitting result corresponding to each marked node, includes: Traversing the marked nodes in the target document object model tree in a traversal order, for a current marked node, obtaining an input document object model tree of the current marked node, wherein when the current marked node is the first marked node visited, the input document object model tree of the current marked node is the target document object model tree, and when the current marked node is not the first marked node, the input document object model tree of the current marked node is an intermediate document object model tree corresponding to a previous marked node; According to the common ancestor node of all the marked nodes in the target document object model tree, a split mark is added to the split node of the input document object model tree of the current marked node, wherein the split node is an element node on the path from the current marked node to the common ancestor node; Remove the current marked node, the sibling node on the right side of the current marked node, and the sibling node on the right side of the split node from the input document object model tree of the current marked node to obtain a final document object model tree corresponding to the current marked node; Remove the current marked node, the sibling node on the left side of the current marked node, and the sibling node on the left side of the split node from the input document object model tree of the current marked node, obtain the intermediate document object model tree corresponding to the current marked node, and use the intermediate document object model tree corresponding to the current marked node as the input document object model tree of the next marked node.
4. The method according to claim 1, characterized in that: Before determining the chapter splitting position according to the positions of the K target element nodes and splitting the original document object model tree according to the chapter splitting position, the method further includes: Displaying an editing interface, wherein the editing interface includes the K titles and a delete control for each title; In response to a first operation of a delete control on a first title among the K titles, the first title and a position of a target element node corresponding to the first title are deleted.
5. The method according to claim 3, characterized in that: Before removing the current marked node, the sibling node on the left side of the current marked node and the sibling node on the left side of the split node from the input document object model tree of the current marked node, the method further includes: The removed current marked node, the sibling node on the left side of the current marked node and the sibling node on the right side of the split node are restored to obtain the input document object model tree of the current marked node.
6. The method according to any one of claims 1 to 5, characterized in that The title matching condition includes: a first-level title matching condition or a multi-level title matching condition.
7. The method according to any one of claims 1 to 5, characterized in that The title matching condition adopts a regular expression.
8. The method according to any one of claims 1 to 5, characterized in that Before traversing the element nodes of the original document object model tree, matching the title matching condition corresponding to the electronic book with each element node, and obtaining the position of the target element node with successful matching, the method further includes: Display multiple title matching condition templates in chapter split page; The title matching condition is selected for the electronic book from the plurality of title matching condition templates based on a user operation.
9. The method according to any one of claims 1 to 5, characterized in that After the final document object model tree corresponding to each chapter split position is serialized into a hypertext markup language file corresponding to the chapter, the method further includes: Locally storing the hypertext markup language files corresponding to each chapter of the electronic book; Alternatively, the hypertext markup language files corresponding to the chapters of the electronic book are stored in a cloud server.
10. The method according to claim 9, characterized in that Also includes: In response to a user's triggering operation of reading a target chapter of the electronic book, obtaining a hypertext markup language file corresponding to the target chapter from a local server or the cloud server; The content of the target chapter is displayed according to the hypertext markup language file corresponding to the target chapter.
11. An electronic book data processing device, characterized in that: The device comprises: An acquisition module, used for acquiring an original hypertext markup language (HTML) file of an electronic book, wherein the original HTML file includes contents of multiple chapters of the electronic book; A parsing module, configured to parse the original hypertext markup language file to obtain an original document object model tree corresponding to the original hypertext markup language file, wherein the original document object model tree includes a plurality of element nodes, and the element nodes include at least one text node; A matching module, used for traversing the text nodes of the original document object model tree, matching the title matching condition corresponding to the electronic book with each text node, and obtaining the positions of K matched titles and K target element nodes, wherein the target element node is the element node where the matched title is located; A splitting module is used to determine the chapter splitting position according to the positions of the K target element nodes, split the original document object model tree according to the chapter splitting position, obtain the final document object model tree corresponding to each chapter splitting position, and serialize the final document object model tree corresponding to each chapter splitting position into a hypertext markup language file corresponding to the chapter.
12. A processing device, characterized in that: include: A processor and a memory, the memory being used to store a computer program, and the processor being used to call and run the computer program stored in the memory to execute the method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein the computer program causes a computer to execute the method according to any one of claims 1 to 10.
