Method, apparatus and device for processing electronic document, and storage medium
By using an asynchronous coroutine concurrency mechanism to process electronic documents, the inefficiency of neural network algorithms in processing electronic documents is solved, achieving efficient parsing and support for multiple document types, making it suitable for large-scale document processing.
Patent Information
- Application Number
- CN202211183841.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-27
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2042-09-27
AI Technical Summary
Existing neural network algorithms consume a lot of computing resources when processing electronic documents, resulting in low processing efficiency and difficulty in meeting the needs of increasingly complex document processing scenarios.
The electronic document parsing task is processed asynchronously based on a coroutine concurrency mechanism. By obtaining the document parsing request, a document parsing task is created, and the document content is converted into structured data. The data is then matched with preset chapter rules to mark the chapter text.
It enables efficient processing and parsing of electronic documents, is suitable for processing and producing large batches of electronic documents, supports the processing of various document types, meets the needs of complex scenarios, and converts documents into structured data to support further data processing.
Smart Images

Figure CN116992853B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer science, and more particularly to the field of artificial intelligence, and provides a method, apparatus, device, and storage medium for processing electronic documents. Background Technology
[0002] With the rapid development of computer networks, people have entered the Internet age. A wide variety of electronic documents are flooding the cyberspace. How to organize and archive various electronic documents has become a key research focus at present.
[0003] Currently, document processing models based on neural network algorithms can be used to intelligently annotate the table of contents, chapters, etc. of electronic documents for archiving.
[0004] To ensure processing accuracy, the document processing model contains a massive number of neurons. A neuron is an abstraction, simplification, and simulation of neurons in the human brain. As the basic unit of a neural network, a neuron can be viewed as a small processing unit that includes input, output, and computational functions.
[0005] However, these neurons also consume a lot of computing resources in the process of processing electronic documents, reducing processing efficiency; moreover, the document processing model can only process a single electronic document, which is difficult to meet the needs of increasingly complex document processing scenarios. Summary of the Invention
[0006] This application provides a method, apparatus, device, and storage medium for processing electronic documents to solve the problems of low processing efficiency and poor scalability.
[0007] In a first aspect, embodiments of this application provide a method for processing electronic documents, including:
[0008] Obtain a document parsing request sent by the client, wherein the document parsing request contains the first download links of the document to be parsed for each page of an electronic document;
[0009] Based on the obtained first download links, document parsing tasks are created for the documents to be parsed on each page.
[0010] An asynchronous approach, based on a coroutine concurrency mechanism, is used to process each document parsing task and obtain the corresponding document processing results. The processing procedure for each document parsing task is as follows:
[0011] Based on the first download link carried by a document parsing task, download a page of the document to be parsed, and convert the document content of the page of the document to be parsed into structured data;
[0012] The structured data is parsed to obtain the text data of each line of the document to be parsed on one page, and the text data of each line of the document is matched with the preset chapter rules in turn to mark the chapter text of the document to be parsed on one page.
[0013] Secondly, embodiments of this application also provide an electronic document processing apparatus, comprising:
[0014] The data transmission module is used to obtain a document parsing request sent by the client, wherein the document parsing request contains the first download link of each page of the document to be parsed in an electronic document;
[0015] The task creation module is used to create document parsing tasks for each page of the document to be parsed based on the obtained first download links.
[0016] The document processing module is used to process each document parsing task asynchronously, based on a coroutine concurrency mechanism, and obtain the corresponding document processing results. The processing procedure for each document parsing task is as follows:
[0017] Based on the first download link carried by a document parsing task, download a page of the document to be parsed, and convert the document content of the page of the document to be parsed into structured data;
[0018] The structured data is parsed to obtain the text data of each line of the document to be parsed on one page, and the text data of each line of the document is matched with the preset chapter rules in turn to mark the chapter text of the document to be parsed on one page.
[0019] Optionally, after converting the document content of the page to be parsed into structured data, and before marking the chapter text of the page to be parsed, the document processing module is further configured to:
[0020] When a page of the document to be parsed contains an image, the MD5 file of the image is obtained from the structured data, and the MD5 file of the image is uploaded to the cloud object storage space to obtain the corresponding image link;
[0021] When a page of the document to be parsed contains tables, formulas, or functions, the corresponding mathematical file is obtained from the structured data, and the mathematical parsing service is called to parse the mathematical file to obtain the file parsing result.
[0022] Optionally, after sequentially matching each line of text data with preset chapter rules, the document processing module is further configured to:
[0023] If a coroutine's task of parsing a page of a document to be parsed times out or fails, and the preset number of retries has not been reached, the page of the document to be parsed will be downloaded again.
[0024] When it is determined that the document parsing task of a coroutine for processing the document to be parsed on a page has timed out or failed, and the preset number of retries has been reached, the current task status of the corresponding document parsing task is updated to processing failure.
[0025] Optionally, after the document parsing service is successfully initialized, the electronic document processing device further includes a status query module, the status query being used for:
[0026] Obtain the status query request sent by the client;
[0027] Based on the task identifier carried in the status query request, the current task status of the corresponding document parsing task is queried in the cache, and the query result is returned to the client.
[0028] Optionally, after obtaining the document processing results of each document parsing task, the document processing module is further configured to:
[0029] Upload the processing results of each document to the cloud object storage space, and receive the second download link of the processing results of each document sent by the cloud object storage space;
[0030] Send each of the second download links to the client;
[0031] Based on the obtained second download links, the client loads the processing results of each document and displays the corresponding target document. The loading process for each document processing result is as follows:
[0032] The client parses a document processing result to obtain the marked chapter text, the file parsing results of tables, formulas or functions, and the image links of the images, and sends an image download request containing the image links to the cloud object storage space to download the corresponding images;
[0033] The client loads the marked chapter text, the file parsing results, and the corresponding images to display a page of the target document.
[0034] Thirdly, embodiments of this application also provide a computer device, including a processor and a memory, wherein the memory stores program code, and when the program code is executed by the processor, the processor performs the steps of any of the above-described electronic document processing methods.
[0035] Fourthly, embodiments of this application also provide a computer-readable storage medium including program code, which, when the program product is run on a computer device, is used to cause the computer device to perform the steps of any of the above-described electronic document processing methods.
[0036] Fifthly, embodiments of this application also provide a computer program product, including computer instructions, which are executed by a processor to perform the steps of any of the above-described electronic document processing methods.
[0037] The beneficial effects of this application are as follows:
[0038] This application provides a method, apparatus, device, and storage medium for processing electronic documents. The method includes: obtaining a document parsing request sent by a client, the document parsing request containing first download links for each page of an electronic document to be parsed; creating document parsing tasks for each page of the document to be parsed based on each first download link; processing each document parsing task asynchronously based on a coroutine concurrency mechanism to obtain corresponding document processing results. The processing procedure for each document parsing task is as follows: downloading one page of the document to be parsed based on the first download link carried by the document parsing task, and converting the document content of this page of the document to be parsed into structured data; parsing the structured data to obtain the text data of each line of the document to be parsed, and sequentially matching each line of text data with preset chapter rules to mark the chapter text of this page of the document to be parsed.
[0039] This application's embodiments employ an asynchronous approach to process single-page granular electronic documents, achieving efficient processing and parsing of electronic documents. Furthermore, due to the stateless, highly concurrent, and scalable characteristics of the document parsing service, it is more suitable for application in scenarios involving the processing and production of large batches of electronic documents.
[0040] Moreover, the electronic document processing method provided in this application is highly versatile and can support the processing of various types of electronic documents, meeting the needs of increasingly complex document processing scenarios. Furthermore, the electronic document processing method provided in this application converts the input electronic document into structured data, providing support for further data processing.
[0041] Other features and advantages of this application will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description
[0042] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0043] Figure 1 This is an optional schematic diagram of an application scenario in the embodiments of this application;
[0044] Figure 2A A flowchart illustrating the process of processing electronic documents provided in an embodiment of this application;
[0045] Figure 2B Metadata diagram provided for embodiments of this application;
[0046] Figure 2C A flowchart illustrating the process of processing a document parsing task provided in an embodiment of this application;
[0047] Figure 2D A schematic diagram illustrating the transition of task states when processing a document parsing task, as provided in an embodiment of this application;
[0048] Figure 2E This is a schematic diagram of the data structure of the document processing results provided in the embodiments of this application;
[0049] Figure 2F This is a schematic diagram of the annotation result display page provided in the embodiments of this application;
[0050] Figure 2G This is a schematic diagram of a navigation pop-up provided in an embodiment of this application;
[0051] Figure 3A This is a partial flowchart illustrating the process of processing electronic documents provided in an embodiment of this application;
[0052] Figure 3B This is another schematic diagram of the process for processing electronic documents provided in the embodiments of this application;
[0053] Figure 4 A schematic diagram of the structure of an electronic document processing device provided in an embodiment of this application;
[0054] Figure 5 This is a schematic diagram of the composition structure of a computer device provided in the embodiments of this application;
[0055] Figure 6 This is a schematic diagram of the structure of a computing device in an embodiment of this application. Detailed Implementation
[0056] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments of this application. Obviously, the described embodiments are only some embodiments of the technical solutions of this application, and not all embodiments. Based on the embodiments recorded in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the technical solutions of this application.
[0057] The following explanations of some terms used in the embodiments of this application are provided to facilitate understanding by those skilled in the art.
[0058] 1. Artificial Intelligence (AI):
[0059] Artificial intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess the functions of perception, reasoning, and decision-making.
[0060] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily include computer vision, speech processing, natural language processing, and machine learning / deep learning.
[0061] With the research and advancement of artificial intelligence technology, AI is being studied and applied in various fields, such as smart homes, intelligent customer service, virtual assistants, smart speakers, intelligent marketing, autonomous driving, robotics, and smart healthcare. It is believed that with the development of technology, AI will be applied in more fields and play an increasingly important role.
[0062] 2. Machine Learning:
[0063] Machine learning is a multidisciplinary field that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory, and many other disciplines. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance.
[0064] Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are found in all areas of artificial intelligence, including deep learning, reinforcement learning, transfer learning, inductive learning, and instructional learning.
[0065] 3. Natural Language Processing (NLP):
[0066] Natural Language Processing (NLP) is an important area of computer science and artificial intelligence. It studies various theories and methods that enable effective communication between humans and computers using natural language.
[0067] Natural Language Processing (NLP) is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field involves natural language—the language people use in daily life—and thus it is closely related to linguistic research. NLP techniques typically include text processing, semantic understanding, machine translation, question answering, and knowledge graphs.
[0068] 4. Distributed caching: This is an extension of the traditional single-machine caching concept and has been widely used in the fields of distributed systems and cloud computing.
[0069] Distributed caching can read data with high performance, dynamically expand cache nodes, automatically discover and switch faulty nodes, and automatically balance data partitions. It also provides users with a graphical management interface, making deployment and maintenance very convenient.
[0070] The design concept of the embodiments of this application is briefly introduced below:
[0071] With the rapid development of computer networks, people have entered the Internet age. A wide variety of electronic documents are flooding the cyberspace. How to organize and archive various electronic documents has become a key research focus at present.
[0072] Currently, document processing models based on neural network algorithms can be used to intelligently annotate the table of contents, chapters, etc. of electronic documents for archiving.
[0073] To ensure processing accuracy, the document processing model contains a massive number of neurons. A neuron is an abstraction, simplification, and simulation of neurons in the human brain. As the basic unit of a neural network, a neuron can be viewed as a small processing unit that includes input, output, and computational functions.
[0074] However, these neurons also consume a lot of computing resources in the process of processing electronic documents, reducing processing efficiency; moreover, the document processing model can only process a single electronic document, which is difficult to meet the needs of increasingly complex document processing scenarios.
[0075] In view of this, embodiments of this application provide a method, apparatus, device, and storage medium for processing electronic documents. The method includes: obtaining a document parsing request sent by a client, the document parsing request containing first download links for each page of an electronic document to be parsed; creating document parsing tasks for each page of the document to be parsed based on each first download link; processing each document parsing task asynchronously using a coroutine concurrency mechanism to obtain corresponding document processing results, wherein the processing procedure for each document parsing task is as follows: downloading one page of the document to be parsed based on the first download link carried by a document parsing task, and converting the document content of this page of the document to be parsed into structured data; parsing the structured data to obtain the text data of each line of the document to be parsed, and sequentially matching each line of text data with preset chapter rules to mark the chapter text of this page of the document to be parsed.
[0076] This application's embodiments employ an asynchronous approach to process single-page granular electronic documents, achieving efficient processing and parsing of electronic documents. Furthermore, due to the stateless, highly concurrent, and scalable characteristics of the document parsing service, it is more suitable for application in scenarios involving the processing and production of large batches of electronic documents.
[0077] Moreover, the electronic document processing method provided in this application is highly versatile and can support the processing of various types of electronic documents, meeting the needs of increasingly complex document processing scenarios. Furthermore, the electronic document processing method provided in this application converts the input electronic document into structured data, providing support for further data processing.
[0078] The preferred embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit this application. Furthermore, the embodiments and features in the embodiments of this application can be combined with each other without conflict.
[0079] Figure 1 One application scenario is shown, which includes two physical terminal devices 110 and a server 130. Each physical terminal device 110 establishes a communication connection with the server 130 through a wired network or a wireless network.
[0080] In this embodiment, the physical terminal device 110 is a computer device used by a user. Computer devices include, but are not limited to, mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle terminals, and aircraft.
[0081] The server 130 in this application embodiment can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. This application does not impose any restrictions on these services.
[0082] A client 120 is deployed on the physical terminal device 110, and a document parsing service and cloud object storage space are deployed on the server 130. Deploying the document parsing service, especially on a server cluster or distributed system composed of multiple physical servers, leverages the concurrent processing of the cluster to optimize its parsing efficiency. The client 120 is used to process electronic documents, such as editing, annotating, and inputting test questions, creating a teaching aid annotation and processing platform for producing new test questions. The document parsing service efficiently parses electronic documents, obtains structured data, and, based on this structured data, marks the chapter text within the electronic document.
[0083] Client 120 obtains the electronic document uploaded by the user, performs pagination on the electronic document to obtain multiple pages of the document to be parsed. It then uploads each page of the document to be parsed to the cloud object storage space and receives the first download link for each page of the document to be parsed from the cloud object storage space. The first download link includes: the document number, document MD5 value, and page number information of each page of the document to be parsed.
[0084] Finally, the client 120 sends the first download link of each page of the document to be parsed in a document parsing request to the document parsing service through the communication channel established between the physical terminal device 110 and the server 130.
[0085] By parsing the document parsing request, the document parsing service obtains the first download link of the document to be parsed on each page, and creates a document parsing task for each page based on the obtained first download link.
[0086] Then, an asynchronous approach is adopted, calling multiple coroutines to process each document parsing task and obtain the corresponding document processing results. The processing procedure for each document parsing task is as follows: based on the first download link carried by a document parsing task, download a page of the document to be parsed and convert the document content of this page of the document to be parsed into structured data; by parsing the structured data, obtain the text data of each line of the document to be parsed, and match each line of text data with the preset chapter rules in turn to mark the chapter text of this page of the document to be parsed.
[0087] Next, please refer to Figure 2AThe flowchart shown illustrates the specific implementation process of processing electronic documents as proposed in the embodiments of this application.
[0088] S201: The document parsing service receives a document parsing request sent by the client, which contains the first download link of each page of an electronic document to be parsed.
[0089] Before executing step 201, the document parsing service is initialized. After successful initialization, multiple coroutines for handling document parsing tasks are created, and multiple detection commands are initiated to detect multiple send and receive interfaces of the document parsing service in order to obtain the document parsing requests, status query requests sent by the client, and newly added document parsing tasks in the parsing task queue.
[0090] The document parsing request is generated by the client, and the specific request generation process is as follows:
[0091] The client receives an electronic document uploaded by the user (e.g., txt, doc, docx, pdf, etc.), and performs pagination on the document to obtain multiple pages of the document to be parsed. It then uploads each page of the document to cloud object storage and receives the first download link for each page from the cloud object storage service. Finally, the client encapsulates each first download link in a document parsing request and sends the request to the document parsing service.
[0092] S202: The document parsing service creates document parsing tasks for each page of the document to be parsed based on the obtained first download links.
[0093] Optionally, the document parsing service creates each document parsing task in the following way:
[0094] Create a task identifier (ID) for a page of document to be parsed, and use the task identifier and the first download link of this page of document to be parsed as metadata to create a corresponding document parsing task.
[0095] As mentioned earlier, the first download link includes: the document number of the document to be parsed, the document's MD5 value, and page number information. Therefore, as... Figure 2B As shown, in this embodiment of the application, the task identifier of a page of document to be parsed, the first download link of this page of document to be parsed, the page number information, and the document MD5 value are used as metadata.
[0096] After creating a document parsing task, the document parsing service writes the current task status of the document parsing service into the cache and sets the current task status to "created"; then it adds the document parsing task to the parsing task queue and calls a coroutine to process the document parsing task.
[0097] The server has multiple nodes acting as "containers," and the document parsing service is deployed across these nodes. Due to the distributed nature of this multi-node system, the document parsing service uses a distributed cache to store the current task state of each document parsing task. The key value for the current task state is named based on the task identifier and page number information. For example, if the task identifier is "5748e3f840fd93c473f7d2cd23561916" and the page number is "0", then the key value for the current task state is "5748e3f840fd93c473f7d2cd23561916:0".
[0098] After adding the document parsing task to the parsing task queue, the document parsing service sends a task identifier to the client so that the client can query the current task status based on the task identifier of each document to be parsed and keep abreast of the task processing progress.
[0099] S203: The document parsing service adopts an asynchronous approach, using a coroutine concurrency mechanism to process each document parsing task and obtain the corresponding document processing results. The processing procedure for each document parsing task is as follows: Based on the first download link carried by a document parsing task, download one page of the document to be parsed and convert the content of this page of the document to be parsed into structured data; by parsing the structured data, obtain the text data of each line of the document to be parsed, and match each line of text data with the preset chapter rules in turn to mark the chapter text of this page of the document to be parsed.
[0100] The document parsing service is deployed across multiple nodes, with each node maintaining a coroutine pool. Each coroutine pool contains multiple coroutines. Therefore, the document parsing service uses an asynchronous approach, processing each document parsing task in the parsing task queue based on a coroutine concurrency mechanism, achieving the goal of efficiently parsing electronic documents. Furthermore, the service design allows for dynamic adjustment of the node scale or the concurrency of individual nodes according to the actual production needs of the application scenario.
[0101] Since the process of handling document parsing tasks is the same for each coroutine, for ease of description, we will take a document parsing task as an example to understand the specific implementation process of handling that task. Figures 2C-2D As shown, the processing procedure for a document parsing task is as follows:
[0102] S2031: Based on the first download link carried by a document parsing task, download a page of the document to be parsed, update the current task status to be running, and convert the document content of this page of the document to be parsed into structured data;
[0103] S2032: Check if this page of the document to be parsed contains images. If yes, proceed to step 2033; otherwise, proceed to step 2034.
[0104] S2033: When this page of the document to be parsed contains images, obtain the MD5 file of the image from the structured data, upload the MD5 file of the image to the cloud object storage space, and obtain the corresponding image link;
[0105] S2034: Check if this page of the document to be parsed contains tables, formulas, or functions. If yes, proceed to step 2035; otherwise, go to step 2036.
[0106] S2035: When the document to be parsed contains tables, formulas, or functions, retrieve the corresponding mathematical file from the structured data, call the mathematical parsing service to parse the mathematical file, and obtain the file parsing result;
[0107] S2036: By parsing structured data, obtain the text data of each line of the document to be parsed on this page, and match each line of text data with the preset chapter rules in turn to mark the chapter text of the document to be parsed on this page;
[0108] S2037: Check whether a coroutine has successfully processed the document parsing task of the document to be parsed. If so, update the current task status of the corresponding document parsing task to "processed successfully". If it times out or fails, trigger a retry operation.
[0109] S2038: Check if the preset number of resets has been reached. If yes, update the current task status to processing failure; otherwise, return to step 2031.
[0110] After the document parsing service is successfully initialized, the status query request sent by the client is obtained by detecting the send and receive interface. Then, based on the task identifier carried in the status query request, the current task status of the corresponding document parsing task is queried in the cache, and the query result is returned to the client.
[0111] The document parsing service uploads the document processing results of each document parsing service to the cloud object storage space, and receives the second download link of each document processing result sent by it. The second download link includes: the task identifier of the corresponding document processing result, the document MD5 value, and the page number information.
[0112] The document parsing service sends a second download link for each document's processing result to the client. Based on these download links, the client loads the processing results and displays the corresponding target document. For example... Figure 2E As shown, the data structure of each document processing result includes at least the following layers: parsed structured data, each line of text data, and document attributes. Specifically, document attributes include root attributes such as data type, text content, and text number; each root attribute also includes sub-attributes with finer granularity.
[0113] The loading process for each document processing result is as follows:
[0114] The client parses the document processing result to obtain the marked chapter text, the file parsing result of tables, formulas or functions, and the image links of the images, and sends the image download request containing the image links to the cloud object storage space to download the corresponding images;
[0115] The client loads the marked chapter text, file parsing results, and corresponding images to display a page of the target document.
[0116] like Figure 2F As shown, the client displays the annotation results for one page of the target document. The left side of the page displays the table of contents annotation results, ensuring the hierarchical structure of the annotations remains consistent with the original book; the right side of the page is the table of contents annotation operation area, highlighting the table of contents, page numbers, and other annotation results.
[0117] like Figure 2G As shown, in response to a user-triggered click, the client displays a navigation pop-up on the page, which includes a labeled table of contents and corresponding page number information.
[0118] Users can also use forward slashes to mark the chapter table of contents text and use the @ symbol at the end of the text to mark page numbers, and check and revise the annotation results. For example, the annotation result " / Lecture 1 From Natural Numbers / / to Rational Numbers / 1" contains errors in the chapter table of contents text division and page number annotation. The corrected annotation result is " / Lecture 1 From Natural Numbers to Rational Numbers / @1".
[0119] like Figures 3A-3B As shown, the complete process of processing electronic documents is as follows:
[0120] S301: Initialize document parsing service.
[0121] S302: Determine whether the initialization was successful. If yes, proceed to step 303; otherwise, end the process.
[0122] S303: While creating multiple coroutines to handle document parsing tasks, it also initiates multiple detection commands to detect multiple send and receive interfaces of the document parsing service in order to obtain document parsing requests, status query requests sent by the client, and newly added document parsing tasks in the parsing task queue.
[0123] S304: By detecting the send and receive interface, obtain the document parsing request sent by the client, and by parsing the document parsing request, obtain the first download link of each page of the document to be parsed in an electronic document.
[0124] S305: Create each document parsing task in the following manner: Create a task identifier for a page of document to be parsed, and use the task identifier and the first download link of the page of document to be parsed as metadata to create the corresponding document parsing task.
[0125] After creating a document parsing task, the document parsing service writes the current task status of the document parsing service into the cache, adds the document parsing task to the parsing task queue, and sends the task identifier to the client.
[0126] S306: Determine whether all pages of the document to be parsed have been processed. If yes, return to step 303; otherwise, return to step 305.
[0127] S307: Detect whether the client has sent a status query request. If yes, proceed to step 308; otherwise, return to step 303.
[0128] S308: When the document parsing service obtains the status query request sent by the client through the detection send / receive interface, it then queries the current task status of the corresponding document parsing task in the cache based on the task identifier carried in the status query request, and returns the query result to the client.
[0129] S309: Check if there are any newly added document parsing tasks in the parsing task queue. If yes, proceed to step 310; otherwise, return to step 303.
[0130] S310: Processes document parsing tasks based on a coroutine concurrency mechanism.
[0131] S3101: Based on the first download link carried by a document parsing task, download one page of the document to be parsed and convert the document content of this page into structured data. When the document page contains an image, obtain the MD5 file of the image from the structured data, upload the MD5 file of the image to the cloud object storage space, and obtain the corresponding image link. When the document page contains a table, formula, or function, obtain the corresponding mathematical file from the structured data, call the mathematical parsing service to parse the mathematical file, and obtain the file parsing result.
[0132] S3102: By parsing the structured data, obtain the text data of each line of the document to be parsed, and match each line of text data with the preset chapter rules in turn to mark the chapter text of the document to be parsed. When it is detected that the coroutine has successfully processed the document parsing task, update the current task status of the corresponding document parsing task to processing success; if timeout or failure occurs, trigger a retry operation.
[0133] Before performing a retry operation, if the preset number of retry attempts has been reached, the current task status is updated to processing failure; if the preset number of retry attempts has not been reached, the document to be parsed is reprocessed.
[0134] Based on the same inventive concept as the above-described method embodiments, this application also provides an electronic document processing apparatus. For example... Figure 4 As shown, the electronic document processing apparatus 400 may include:
[0135] The data transmission module 401 is used to obtain the document parsing request sent by the client. The document parsing request contains the first download link of each page of the document to be parsed in an electronic document.
[0136] Task creation module 402 is used to create document parsing tasks for each page of the document to be parsed based on the obtained first download links.
[0137] The document processing module 403 is used to process each document parsing task asynchronously based on a coroutine concurrency mechanism to obtain the corresponding document processing results; the processing procedure for each document parsing task is as follows:
[0138] Based on the first download link carried by a document parsing task, download a page of the document to be parsed, and convert the content of the page of the document to be parsed into structured data;
[0139] The structured data is parsed to obtain the text data of each line of a document to be parsed, and each line of text data is matched with the preset chapter rules in turn to mark the chapter text of the document to be parsed.
[0140] Optionally, the task creation module 402 is used for:
[0141] Each document parsing task is created using the following methods:
[0142] Create a task identifier for a page of a document to be parsed;
[0143] Create a corresponding document parsing task by using the task identifier and the first download link of the document to be parsed as metadata.
[0144] Optionally, the first download link for a page of the document to be parsed includes: the page number information and the document's MD5 value. Task creation module 402 is used for:
[0145] The task identifier of a page of document to be parsed, the first download link of the page of document to be parsed, the page number information, and the document MD5 value are used as metadata.
[0146] Optionally, after creating a corresponding document parsing task, the task creation module 402 is also used for:
[0147] Write the current task status of a document parsing service into the cache and set the current task status to "created".
[0148] Add a document parsing task to the parsing task queue and call a coroutine to process the document parsing task.
[0149] Optionally, after converting the document content of a page of the document to be parsed into structured data, and before marking the chapter text of a page of the document to be parsed, the document processing module 403 is further configured to:
[0150] When a page of a document to be parsed contains an image, the MD5 file of the image is obtained from the structured data, and the MD5 file of the image is uploaded to the cloud object storage space to obtain the corresponding image link;
[0151] When a document to be parsed contains tables, formulas, or functions, the corresponding mathematical file is retrieved from the structured data, and the mathematical parsing service is called to parse the mathematical file and obtain the parsing result.
[0152] Optionally, after matching each line of text data with the preset chapter rules in sequence, the document processing module 403 is further used to:
[0153] If a coroutine's task of parsing a single page of a document times out or fails before the preset number of retries has been reached, download the single page of the document again.
[0154] When a coroutine's task of parsing a single page of a document times out or fails, and the preset number of retries has been reached, the current task status of the corresponding document parsing task is updated to "processing failed".
[0155] Optionally, after the document parsing service is successfully initialized, the electronic document processing device 400 further includes a status query module 404, which is used for:
[0156] Get the status query request sent by the client;
[0157] Based on the task identifier carried in the status query request, the current task status of the corresponding document parsing task is retrieved from the cache, and the query result is returned to the client.
[0158] Optionally, after obtaining the document processing results of each document parsing task, the document processing module 403 is further used for:
[0159] Upload the processing results of each document to the cloud object storage space, and receive the second download link of each document processing result sent by the cloud object storage space;
[0160] Send each of the second download links to the client;
[0161] Based on the obtained second download links, the processing results of each document are loaded through the client, and the corresponding target document is displayed. The loading process for each document processing result is as follows:
[0162] The client parses the document processing result to obtain the marked chapter text, the file parsing result of tables, formulas or functions, and the image links of the images, and sends the image download request containing the image links to the cloud object storage space to download the corresponding images;
[0163] The client loads the marked chapter text, file parsing results, and corresponding images to display a page of the target document.
[0164] For ease of description, the above sections are divided into modules (or units) according to their functions and described separately. Of course, in implementing this application, the functions of each module (or unit) can be implemented in one or more software or hardware components.
[0165] Having introduced the service platform access method and apparatus according to exemplary embodiments of this application, the computer device according to another exemplary embodiment of this application will now be described.
[0166] Those skilled in the art will understand that various aspects of this application can be implemented as a system, method, or program product. Therefore, various aspects of this application can be specifically implemented in the following forms: a completely hardware implementation, a completely software implementation (including firmware, microcode, etc.), or a combination of hardware and software implementations, collectively referred to herein as a "circuit," "module," or "system."
[0167] Based on the same inventive concept as the above-described method embodiments, this application also provides a computer device, see reference. Figure 5 As shown, the computer device 500 may include at least a processor 501 and a memory 502. The memory 502 stores program code, which, when executed by the processor 501, causes the processor 501 to perform the steps of any of the above-described electronic document processing methods.
[0168] In some possible implementations, the computing device according to this application may include at least one processor and at least one memory. The memory stores program code that, when executed by the processor, causes the processor to perform the steps in the electronic document processing methods according to the various exemplary embodiments of this application described above. For example, the processor may perform actions such as... Figure 2A The steps are shown in the figure.
[0169] The following reference Figure 6 To describe a computing device 600 according to this embodiment of the present application. Figure 6 The computing device 600 is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0170] like Figure 6 As shown, the computing device 600 is presented in the form of a general-purpose computing device. The components of the computing device 600 may include, but are not limited to: at least one processing unit 601, at least one storage unit 602, and a bus 603 connecting different system components (including storage unit 602 and processing unit 601).
[0171] Bus 603 represents one or more of several bus structures, including a memory bus or memory controller, peripheral bus, processor, or local bus using any of the various bus structures.
[0172] Storage unit 602 may include a readable medium in the form of volatile memory, such as random access memory (RAM) 6021 and / or cache memory unit 6022, and may further include read-only memory (ROM) 6023.
[0173] Storage unit 602 may also include a program / utility 6025 having a set (at least one) of program modules 6024, such program modules 6024 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.
[0174] The computing device 600 can also communicate with one or more external devices 604 (e.g., keyboard, pointing device, etc.), one or more devices that enable a user to interact with the computing device 600, and / or any device that enables the computing device 600 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 605. Furthermore, the computing device 600 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 606. As shown, network adapter 606 communicates with other modules used in the computing device 600 via bus 603. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with the computing device 600, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0175] Based on the same inventive concept as the above-described method embodiments, various aspects of the electronic document processing method provided in this application can also be implemented as a program product, which includes program code. When the program product is run on a computer device, the program code is used to cause the computer device to execute the steps in the electronic document processing method according to the various exemplary embodiments of this application described above. For example, the computer device can execute... Figure 2A The steps are shown in the figure.
[0176] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0177] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.
[0178] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A method for processing electronic documents, characterized in that, include: Obtain a document parsing request sent by the client, wherein the document parsing request contains the first download links of the document to be parsed for each page of an electronic document; Based on the obtained first download links, document parsing tasks are created for the documents to be parsed on each page. An asynchronous approach, based on a coroutine concurrency mechanism, is used to process each document parsing task and obtain the corresponding document processing results. The processing procedure for each document parsing task is as follows: Based on the first download link carried by the document parsing task, a page of the document to be parsed is downloaded, and the document content of the page is converted into structured data. When the page contains images, the MD5 file of the image is obtained from the structured data, and the MD5 file is uploaded to the cloud object storage space to obtain the corresponding image link. When the page contains tables, formulas, or functions, the corresponding mathematical file is obtained from the structured data, and a mathematical parsing service is called to parse the mathematical file to obtain the file parsing result. The structured data is parsed to obtain the text data of each line of the page, and each line of text data is matched sequentially with preset chapter rules to mark the chapter text of the page. After obtaining the document processing results of each document parsing task, the document processing results are uploaded to the cloud object storage space, and the second download link of the document processing results sent by the cloud object storage space is received. Send each of the second download links to the client; Based on the obtained second download links, the client loads the document processing results and displays the corresponding target documents. The loading process for each document processing result is as follows: the client parses a document processing result to obtain the marked chapter text, the file parsing results of tables, formulas, or functions, and the image links of the images. An image download request containing the image links is sent to the cloud object storage space to download the corresponding images. The client then loads the marked chapter text, the file parsing results, and the corresponding images to display one page of the target document.
2. The method as described in claim 1, characterized in that, Based on the obtained first download links, corresponding document parsing tasks are created for each page of the document to be parsed, including: Each document parsing task is created using the following methods: Create a task identifier for the page of the document to be parsed; Using the task identifier and the first download link of the document to be parsed on the page as metadata, a corresponding document parsing task is created.
3. The method as described in claim 2, characterized in that, The first download link for the page of the document to be parsed includes: the page number information and the document MD5 value of the corresponding page of the document to be parsed; The step of using the task identifier and the first download link of the page of document to be parsed as metadata includes: The task identifier of the page to be parsed, the first download link of the page to be parsed, the page number information, and the document MD5 value are used as the metadata.
4. The method as described in claim 2, characterized in that, After creating a corresponding document parsing task, the following is also included: Write the current task status of the document parsing task into the cache, and set the current task status to "created"; Add the document parsing task to the parsing task queue and call a coroutine to process the document parsing task.
5. The method as described in claim 1, characterized in that, After matching each line of text data with the preset chapter rules in sequence, the process also includes: If a coroutine's task of parsing a page of a document to be parsed times out or fails, and the preset number of retries has not been reached, the page of the document to be parsed will be downloaded again. When it is determined that the document parsing task of a coroutine for processing the document to be parsed on a page has timed out or failed, and the preset number of retries has been reached, the current task status of the corresponding document parsing task is updated to processing failure.
6. The method according to any one of claims 1 to 5, characterized in that, After the document parsing service is successfully initialized, the following is also included: Obtain the status query request sent by the client; Based on the task identifier carried in the status query request, the current task status of the corresponding document parsing task is queried in the cache, and the query result is returned to the client.
7. An electronic document processing apparatus, characterized in that, include: The data transmission module is used to obtain a document parsing request sent by the client, wherein the document parsing request contains the first download link of each page of the document to be parsed in an electronic document; The task creation module is used to create document parsing tasks for each page of the document to be parsed based on the obtained first download links. The document processing module is used to process each document parsing task asynchronously based on a coroutine concurrency mechanism to obtain the corresponding document processing results. The processing procedure for each document parsing task is as follows: Based on the first download link carried by the document parsing task, a page of the document to be parsed is downloaded, and the document content of the page is converted into structured data; when the page contains images, the MD5 file of the image is obtained from the structured data, and the MD5 file is uploaded to the cloud object storage space to obtain the corresponding image link; when the page contains tables, formulas, or functions, the corresponding mathematical file is obtained from the structured data, and the mathematical parsing service is called to parse the mathematical file to obtain the file parsing result; the structured data is parsed to obtain the text data of each line of the page, and each line of text data is matched sequentially with preset chapter rules to mark the chapter text of the page. After obtaining the document processing results of each document parsing task, the document processing results are uploaded to the cloud object storage space, and the second download link of the document processing results sent by the cloud object storage space is received. Send each of the second download links to the client; Based on the obtained second download links, the client loads the document processing results and displays the corresponding target documents. The loading process for each document processing result is as follows: the client parses a document processing result to obtain the marked chapter text, the file parsing results of tables, formulas, or functions, and the image links of the images. An image download request containing the image links is sent to the cloud object storage space to download the corresponding images. The client then loads the marked chapter text, the file parsing results, and the corresponding images to display one page of the target document.
8. The apparatus as claimed in claim 7, characterized in that, The task creation module is used for: Each document parsing task is created using the following methods: Create a task identifier for the page of the document to be parsed; Using the task identifier and the first download link of the document to be parsed on the page as metadata, a corresponding document parsing task is created.
9. The apparatus as claimed in claim 8, characterized in that, The first download link for the page of the document to be parsed includes: the page number information and the document MD5 value of the corresponding page of the document to be parsed. The task creation module is used for: The task identifier of the page to be parsed, the first download link of the page to be parsed, the page number information, and the document MD5 value are used as the metadata.
10. The apparatus as claimed in claim 8, characterized in that, After creating a corresponding document parsing task, the task creation module is also used for: Write the current task status of the document parsing task into the cache, and set the current task status to "created"; Add the document parsing task to the parsing task queue and call a coroutine to process the document parsing task.
11. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores program code that, when executed by the processor, causes the processor to perform the steps of the method according to any one of claims 1 to 6.
12. A computer-readable storage medium, characterized in that, It includes program code that, when run on a computer device, causes the computer device to perform the steps of the method according to any one of claims 1 to 6.
13. A computer program product, characterized in that, It includes computer instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Distributed XML data processing method and system
CN110297944A
Document processing method and device and equipment and storage medium
CN112733056A
