RAG data analysis method, device, equipment and medium in rail transit field
By converting documents in the rail transit field into PDF format and performing layout analysis, identifying tables and text areas, extracting metadata and storing them in vector databases, the problem of difficulty in efficiently extracting information in traditional document management methods is solved, and the complete and accurate extraction of information and the improvement of application value is achieved.
Patent Information
- Application Number
- CN202411806291.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-10
- Publication Date
- 2025-03-25
AI Technical Summary
Traditional document management methods are difficult to efficiently extract and utilize information from unstructured or semi-structured documents in the field of rail transit. The existing document analysis technology is not very accurate in parsing and incomplete information extraction when processing complex documents.
It provides a RAG data analysis method in the field of rail transit. By obtaining documents and converting them into pdf format, layout analysis of documents in pdf format, identifying table areas and text areas, extracting metadata for table areas and text areas, and converting them into structured metadata and storing them in a vector database of RAG.
It realizes the complete and accurate extraction of document information, enhances the application value of documents in actual work, and solves the problem that traditional document management methods are difficult to efficiently extract information.
Smart Images

Figure CN119692336A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of rail transit technology, and in particular to a RAG (Retrieval-augmented Generation) data analysis method, device, equipment, and medium in the field of rail transit. Background Art
[0002] With the rapid development of the rail transit industry, various technical documents, standard documents, research reports and other materials are increasing day by day. These documents contain a lot of valuable information, which is of great significance to the design, construction, operation and maintenance of rail transit.
[0003] However, traditional document management methods have difficulty extracting and utilizing this information efficiently, especially when faced with unstructured or semi-structured documents such as word documents, ppt presentations, pdf files, etc.
[0004] Existing document parsing technologies often have problems such as low parsing accuracy and incomplete information extraction when processing complex documents in specific fields, which limits the application value of these documents in actual work. Summary of the invention
[0005] In order to solve one of the above-mentioned technical defects, the present application provides a RAG data analysis method, device, equipment, and medium in the field of rail transit.
[0006] In a first aspect, the present application provides a RAG data parsing method in the field of rail transit, the method comprising:
[0007] Get the document;
[0008] If the document is not in PDF format, convert it to PDF format;
[0009] Perform layout analysis on documents in PDF format and identify table areas and text areas in documents in PDF format;
[0010] For the table area, identify the single-line text, table structure and cell coordinates in the table, form the recognition result of the cell based on the single-line text and cell coordinates, and form the HTML string of the table element based on the recognition result of the table structure and cell;
[0011] For the text area, the structure of the document and the coordinates of the text elements are identified, the text elements are classified according to the structure of the document and the coordinates of the text elements, and the text content is extracted according to the classification results;
[0012] Convert html strings and text content into structured metadata and store them in RAG's vector database.
[0013] Optionally, performing layout analysis on the document in PDF format to identify table areas and text areas in the document in PDF format includes:
[0014] Analyze the PDF document through a lightweight object detection model to identify the table area and text area;
[0015] Wherein, the text area includes an English text area and a Chinese text area;
[0016] The English text area includes: English text sub-area, Title sub-area, Tale sub-area, Figure sub-area, List sub-area;
[0017] The Chinese text area includes: Chinese text Text class sub-area, Title class sub-area, Figure class sub-area, Figure caption class sub-area, Table class sub-area, Tablecaption class sub-area, Header class sub-area, Footer class sub-area, Reference class sub-area, and Equation class sub-area.
[0018] Optionally, identify single-line text, table structure, and cell coordinates in a table, including:
[0019] Through the single-line text detection model, the coordinates of a single line of text are identified;
[0020] Through the single-line text recognition model, the single-line text is recognized based on the coordinates of the single-line text;
[0021] Through the table structure and cell coordinate prediction model, the boundaries and coordinates of each cell in the table are identified.
[0022] Optionally, forming a recognition result of a cell based on the single-line text and the cell coordinates includes:
[0023] Associate each cell with its neighboring cells based on cell coordinates;
[0024] The contents of the associated cells are extracted from the single-line text to obtain the recognition result of the cell.
[0025] Optionally, identify the structure of the document and the coordinates of text elements, including:
[0026] Identify the text area through the text detection and recognition model to obtain the structure of the document and the coordinates of the text elements;
[0027] The structure of the document includes the structure of the title part and the structure of the body part; the structure of the title part is divided according to the title level, and the structure of the body part is divided according to natural paragraphs.
[0028] Optionally, the text elements are classified according to the structure of the document and the coordinates of the text elements, including:
[0029] According to the document structure and the coordinates of the text elements, combined with the paragraph classification algorithm, the coordinates of the elements of each paragraph are extracted;
[0030] Group the coordinates of the text elements of each paragraph into one category.
[0031] Optionally, extract text content based on the classification results, including:
[0032] Extract the content in each category according to the coordinates of the text elements in each category;
[0033] According to the coordinates of text elements, determine the layout order between categories;
[0034] Based on the layout order between the categories and the content in each category, the text content is formed.
[0035] In a second aspect of the present application, a RAG data parsing device in the field of rail transit is provided, the device comprising:
[0036] The acquisition module is used to obtain documents;
[0037] A conversion module, used for converting a document into a PDF format if the format of the document is not a PDF format;
[0038] A recognition module is used to analyze the layout of a document in PDF format and recognize table areas and text areas in the document in PDF format;
[0039] The table extraction module is used to identify the single-line text, table structure and cell coordinates in the table area, form the recognition result of the cell based on the single-line text and the cell coordinates, and form the HTML string of the table element based on the recognition result of the table structure and the cell;
[0040] A text extraction module is used to identify the structure of the document and the coordinates of the text elements in the text area, classify the text elements according to the structure of the document and the coordinates of the text elements, and extract the text content according to the classification results;
[0041] The storage module is used to convert HTML strings and text content into structured metadata and store them in the RAG vector database.
[0042] In a third aspect of the present application, an electronic device is provided, including:
[0043] Memory;
[0044] Processor; and
[0045] Computer programs;
[0046] The computer program is stored in the memory and is configured to be executed by the processor to implement the method as described in the first aspect above.
[0047] In a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored; the computer program is executed by a processor to implement the method described in the first aspect above.
[0048] The present application provides a RAG data parsing method, device, equipment, and medium in the field of rail transit. The method includes: obtaining a document; if the format of the document is not in PDF format, converting it to PDF format; performing layout analysis on the document in PDF format, and identifying the table area and text area in the document in PDF format; for the table area, identifying the single-line text, table structure, and cell coordinates in the table, forming the recognition result of the cell based on the single-line text and the cell coordinates, and forming the html string of the table element based on the recognition result of the table structure and the cell; for the text area, identifying the structure of the document and the coordinates of the text element, classifying the text element according to the structure of the document and the coordinates of the text element, and extracting the text content according to the classification result; converting the html string and the text content into structured metadata, and storing it in the vector database of RAG. The method of the present application first unifies the format of the document into PDF format, provides a unified input source for data parsing, and avoids the influence of format differences on the parsing results. Then, the layout analysis of the PDF format of the document is performed, the table area and the text area are identified, and then the metadata is extracted for the table area and the text area respectively, so as to realize the complete and accurate extraction of information and enhance the application value of the document in practical work. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0050] Figure 1 A schematic diagram of a flow chart of a RAG data parsing method in the field of rail transit provided in an embodiment of the present application;
[0051] Figure 2 A schematic diagram of the architecture of a PP-Structure provided in an embodiment of the present application;
[0052] Figure 3A schematic diagram of the effect of element information of each element in a document provided in an embodiment of the present application;
[0053] Figure 4 A schematic diagram of an HTML string of a table provided in an embodiment of the present application;
[0054] Figure 5 A schematic diagram of a table provided in an embodiment of the present application;
[0055] Figure 6 A schematic diagram of a process for identifying element information of a table in a document provided in an embodiment of the present application;
[0056] Figure 7 A schematic diagram of a process for recovering a document based on extracted structured data provided in an embodiment of the present application;
[0057] Figure 8 A schematic diagram of a flow chart of another RAG data parsing method in the field of rail transit provided in an embodiment of the present application;
[0058] Fig. 9 A schematic diagram of the structure of a RAG data analysis device in the field of rail transit provided in an embodiment of the present application;
[0059] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0060] In order to make the technical solutions and advantages in the embodiments of the present application more clearly understood, the exemplary embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than an exhaustive list of all the embodiments. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0061] In the process of realizing this application, the inventors found that with the rapid development of the rail transit industry, various technical documents, standard documents, research reports and other materials are increasing. These documents contain a large amount of valuable information, which is of great significance to the design, construction, operation and maintenance of rail transit. However, traditional document management methods are difficult to extract and utilize this information efficiently, especially when faced with unstructured or semi-structured documents, such as word documents, ppt presentations, pdf files, etc. Existing document parsing technologies often have problems such as low parsing accuracy and incomplete information extraction when dealing with complex documents in specific fields, which limits the application value of these documents in actual work.
[0062] In view of the above problems, the present application provides a RAG data parsing method, device, equipment, and medium in the field of rail transit. The method includes: obtaining a document; if the format of the document is not in PDF format, converting it to PDF format; performing layout analysis on the document in PDF format, and identifying the table area and text area in the document in PDF format; for the table area, identifying the single-line text, table structure, and cell coordinates in the table, forming the recognition result of the cell based on the single-line text and cell coordinates, and forming the html string of the table element based on the recognition result of the table structure and the cell; for the text area, identifying the structure of the document and the coordinates of the text element, classifying the text element according to the structure of the document and the coordinates of the text element, and extracting the text content according to the classification result; converting the html string and the text content into structured metadata, and storing it in the vector database of RAG. The method of the present application first unifies the format of the document into PDF format, provides a unified input source for data parsing, and avoids the influence of format differences on the parsing results. Then, the layout analysis of the PDF format of the document is performed, the table area and the text area are identified, and then the metadata is extracted for the table area and the text area respectively, so as to realize the complete and accurate extraction of information and enhance the application value of the document in practical work.
[0063] See also Figure 1 This embodiment provides a RAG data parsing method in the field of rail transit, and the implementation process of the method is as follows:
[0064] 101, Get Document.
[0065] The document acquired in step 101 may be in various formats, such as doc, docx, ppt, pptx, pdf, etc. For example, a document in the field of rail transit is acquired.
[0066] 102. If the document is not in PDF format, convert it to PDF format.
[0067] If the document is in pdf format, step 102 does not need to be executed, and step 103 is directly executed after step 101 is executed, that is, step 102 is not a necessary step.
[0068] The unified processing of the document format can be achieved through step 102. In the specific implementation, the non-PDF format documents can be converted through the libreoffice library, and the doc, docx, ppt, pptx and other format documents can be uniformly converted into PDF format, thereby completing step 102.
[0069] The libreoffice library has a wide range of format support capabilities, can automatically process document format conversions, and maintain the original structure and content of the document during the conversion process. Through the conversion function of libreoffice, standardized processing of multi-format documents can be achieved, laying the foundation for subsequent layout analysis.
[0070] This format conversion not only simplifies the document parsing process, but also solves the parsing problems caused by differences in the structure of multi-format documents. The PDF format is relatively stable and can better preserve the layout information in the document, such as the position and relationship of paragraphs, titles, tables, and diagrams, making layout analysis more accurate. By unifying documents of different formats into PDF, the impact of format differences on parsing results is avoided, providing a unified input source for subsequent data analysis.
[0071] Taking the field of rail transit as an example, step 102 can be used to unify the format of technical documents in the field of rail transit. Documents in the field of rail transit usually exist in a variety of file formats, such as doc, docx, ppt, pptx, pdf, etc. These formats have different storage structures and content presentation forms. It is difficult to maintain the consistency and accuracy of the analysis results using different tools and methods, especially when it comes to scanned files and complex tables, so they cannot be directly processed in the same analysis framework. Therefore, the unification of document formats is the basis of data analysis.
[0072] 103. Perform layout analysis on the document in PDF format, and identify table areas and text areas in the document in PDF format.
[0073] In the specific implementation of step 103, the document in PDF format can be analyzed by a lightweight object detection model to identify the table area and the text area.
[0074] The text area includes an English text area and a Chinese text area.
[0075] The English text area includes: Text (English text) type sub-area, Title (title) type sub-area, Tale (narration) type sub-area, Figure (figure) type sub-area, List (list) type sub-area.
[0076] The Chinese text area includes: Text (Chinese characters) sub-area, Title (title) sub-area, Figure (figure) sub-area, Figure caption (figure title) sub-area, Table (table) sub-area, Tablecaption (table title) sub-area, Header (header) sub-area, Footer (footer) sub-area, Reference (reference) sub-area, Equation (formula) sub-area.
[0077] In addition, the lightweight object detection model may be a lightweight object detection model of an OCR (Optical Character Recognition) model, such as a PaddleOCR model.
[0078] That is, in step 103, the PaddleOCR model of OCR can be used to recognize the document in PDF format, and then the text recognition and layout analysis are performed on the content of the document in PDF format to obtain the table area and text area in the document in PDF format.
[0079] PaddleOCR is an OCR tool based on deep learning. It has efficient character recognition capabilities and supports multiple languages, adapting to the multilingual characteristics of technical documents in the rail transit field.
[0080] During the OCR recognition process, PaddleOCR can not only extract the text content in the document, but also has the ability to analyze the layout, and can identify the table area and text area in the document. At the same time, it can identify the Table sub-area in each table area; the Text, Title, Tale, Figure, List sub-area in each English text area; the Text, Title, Figure, Figure caption, Table, Table caption, Header, Footer, Reference, Equation sub-area in each Chinese text area. The recognition of sub-areas can provide a basis for subsequent text classification and structured storage. This process greatly improves the parsing accuracy of the document content and ensures the integrity and accuracy of the metadata.
[0081] At the same time, the coordinate information of each sub-area will also be extracted. This function is particularly important for rail transit technical documents, because many key technical information is often presented in the form of tables or diagrams, and traditional data parsing methods such as pdfplumber are difficult to accurately parse these contents. The method of this embodiment uses PaddleOCR to perform layout analysis, which can achieve accurate positioning of various types of information in the document, providing important support for subsequent structured extraction.
[0082] In the specific implementation, it can be achieved through Figure 2 The PP-Structure (intelligent document analysis system) of PaddleOCR shown in the figure implements step 103. PP-Structure can better complete document understanding related tasks such as layout analysis and table recognition. In the layout analysis task, the image first passes through the layout analysis model to divide the image into a table area and a text area. So that these areas can be recognized separately later, such as performing structural recognition on the table area through step 104, and performing text recognition on the text area through step 105, and finally restoring it to a word or pdf format file that is consistent with the original image layout. The effect of recognizing the table area and text area in the document is as follows: Figure 3 As shown, each black box represents a (sub) region.
[0083] Layout analysis is not only for text recognition, but also for understanding the relative position and structure of each element in the document in subsequent steps 104 and 105. Documents in the field of rail transit often contain complex tables, equipment diagrams, and annotation information, which are crucial for question-answering applications in RAG (Retrieval-augmented Generation) systems.
[0084] 104. For the table area, identify the single-line text, table structure and cell coordinates in the table, form a recognition result of the cell based on the single-line text and the cell coordinates, and form an HTML string of the table element based on the recognition result of the table structure and the cell.
[0085] In step 104, for the table area, 1) the single-line text, table structure and cell coordinates in the table are identified, 2) the recognition result of the cell is formed based on the single-line text and cell coordinates, and 3) the html string of the table element is formed based on the recognition results of the table structure and the cell.
[0086] Among them, the process of 1) identifying the single-line text, table structure and cell coordinates in the table is as follows:
[0087] 201, identifying the coordinates of a single line of text through a single line text detection model.
[0088] Among them, single-line text detection models such as the DB (Differentiable Binarization) model can analyze the table area and identify the coordinates of the text in the table row through the DB model.
[0089] 202, recognizing the single-line text based on the coordinates of the single-line text through a single-line text recognition model.
[0090] Among them, a single-line text recognition model such as a CRNN (Convolutional Recurrent Neural Network) model can recognize a single line of text based on the coordinates of the single line of text through the CRNN model.
[0091] 203, identifying the boundary and coordinates of each cell in the table through the table structure and the cell coordinate prediction model.
[0092] The table structure and cell coordinate prediction may be a SLANet (Strucutre Location Alignment Network, table structure recognition) model, and the boundary and coordinates of each cell in the table may be identified through the SLANet model.
[0093] When identifying single-line text, table structure and cell coordinates in a table, it is implemented through three models, namely: a DB model for single-line text detection, a CRNN model for single-line text recognition, and a SLANet model for table structure and cell coordinate prediction.
[0094] 2) The process of forming the recognition result of the cell based on the single-line text and the cell coordinates is as follows:
[0095] 301, each cell is associated with an adjacent cell according to the cell coordinates.
[0096] For example, cell coordinate aggregation is used to associate each cell with adjacent cells based on the cell coordinates.
[0097] 302, extracting the content of the associated cell from the single-line text to obtain a recognition result of the cell.
[0098] For example, the content of the associated cell is extracted from a single line of text through a text recognition algorithm and cell text aggregation to obtain a cell recognition result.
[0099] 3) When the HTML string of the table element is formed based on the recognition results of the table structure and the cell, if the recognition results of the table structure and the cell are Figure 4 The Excel table shown in the figure, then the html string can be as follows Figure 5 shown.
[0100] HTML strings are used to represent the element information of a table. HTML is a universal structured markup language that can well describe the row and column relationships and cell contents of a table. By converting the structure and contents of a table into HTML strings, structured storage of table information is achieved, ensuring that the cell data in each table can be accurately recorded. In addition, the HTML representation method also has good cross-platform compatibility, so that the parsed data can be easily applied to various display interfaces and systems.
[0101] In step 104, the boundaries and coordinates of each table cell are accurately identified for the table area, and each element in the table is associated with its adjacent cells, thereby achieving complete extraction and representation of the table content. The cell recognition results and the table structure are used together to construct the table's HTML string.
[0102] For example Figure 6 As shown, the table area is analyzed through the text detection algorithm (including the single-line text detection model and the single-line text recognition model) and the table structure prediction of the cell coordinate prediction model to identify the boundaries and coordinates of each cell in the table. The process of associating each cell with adjacent cells based on boundaries and coordinates is realized through cell coordinate aggregation. The text recognition algorithm and cell text aggregation are used to extract the content of the table based on the associated cells to obtain the recognition result of the cell. Finally, the html string (i.e. Figure 4 The table in Excel), the html string is as follows Figure 5 shown.
[0103] The extraction of table element information is particularly important for Q&A applications in the field of rail transit. Many technical parameters and configuration information are presented in table form, which is directly related to the operation and maintenance of equipment. Table data represented by HTML can not only be stored in the knowledge base, but also be efficiently retrieved and used in the subsequent Q&A process. Figure 6 The table content in the PDF document shown contains English, numbers and symbols, and the cells contain sub-tables, but PaddleOCR can still accurately and completely divide and recognize them.
[0104] 105 , for the text area, identifying the structure of the document and the coordinates of the text elements, classifying the text elements according to the structure of the document and the coordinates of the text elements, and extracting the text content according to the classification result.
[0105] In step 105, for the text region, 1) the structure of the document and the coordinates of the text elements are identified, 2) the text elements are classified according to the structure of the document and the coordinates of the text elements, and 3) the text content is extracted according to the classification result.
[0106] Among them, the process of 1) identifying the structure of the document and the coordinates of the text elements is: identifying the text area through the text detection and recognition model to obtain the structure of the document and the coordinates of the text elements.
[0107] The structure of the document includes the structure of the title part and the structure of the body part. The structure of the title part is divided according to the title level, and the structure of the body part is divided according to natural paragraphs.
[0108] 2) The process of classifying text elements according to the structure of the document and the coordinates of the text elements is as follows: according to the document structure and the coordinates of the text elements, combined with the paragraph classification algorithm, the coordinates of the text elements of each paragraph are extracted, and the coordinates of the text elements of each paragraph are classified into one category.
[0109] For example, for text areas, the type of content in the text is determined based on the structure of the document and the coordinates of the text elements, combined with the paragraph classification algorithm, and then the text of different categories is classified. For example, the title part will be marked as a first-level, second-level, or third-level title, and the body part will be divided according to natural paragraphs. This classification method ensures the structured expression of the document content and provides clear hierarchical information for subsequent question-answering system applications.
[0110] 3) The process of extracting text content according to the classification results is as follows: extract the content in each category according to the coordinates of the text elements in each category. Determine the layout order between the categories according to the coordinates of the text elements. Based on the layout order between the categories and the content in each category, form the text content.
[0111] Through step 104 and step 105, the structured extraction of information in the table area and text area can be realized. When executing step 103 to complete the layout analysis, since PaddleOCR is used for implementation, although PaddleOCR will parse and extract the text, table, diagram and other contents in the document by category, the file generated after PaddleOCR recognition generates a txt file for each page, which contains the content type and text paragraph coordinates of each paragraph of content in disorder. Based on this, it is necessary to perform post-processing analysis on the content recognized by PaddleOCR through steps 104 and 105, that is, to perform structured data extraction according to the recognized document structure and element category, such as extracting the html string of the table area through step 104, and extracting the text content of the text area through step 105.
[0112] When the subsequent question-answering system is applied, Figure 7 As shown, we can obtain the original document recognized by PaddleOCR, filter the document content according to the type of document content, extract the coordinates of each paragraph of text, restore the layout order according to the coordinate order, and finally form the final document.
[0113] 106, convert the html string and text content into structured metadata and store them in the vector database of RAG.
[0114] The RAG data parsing method in the rail transit field provided in this embodiment is a universal multi-type document data OCR parsing method, which simplifies the parsing process, improves the parsing efficiency and versatility, lays a data foundation for subsequent large-scale model applications, and facilitates users to upload documents independently to build a private knowledge base.
[0115] The quality and efficiency of document data parsing are crucial to the construction of the knowledge base of the RAG system, especially in the field of rail transit, where documents are mostly technically complex, information-intensive, and multi-type professional documents that are difficult to parse and process using a unified method. The RAG data parsing method in the field of rail transit provided by this embodiment can automatically process a large number of technical documents in different formats, perform layout analysis and structured data extraction, and ultimately convert the extracted data into structured metadata and store it in a vector database. This process significantly improves the data construction efficiency of the knowledge base, while also improving the response speed and accuracy of the subsequent question-and-answer system. It can provide accurate and efficient metadata input support for the knowledge base built on the RAG system.
[0116] The RAG data analysis method in the field of rail transit provided in this embodiment is a general method for analyzing large model data in the field of rail transit. Figure 8 The RAG data parsing method in the field of rail transit provided in this embodiment obtains a document through step 101. Through step 102, it is judged whether the original data format is in pdf format. If it is not in pdf format, the document format is converted into pdf format, thereby realizing document format conversion. Through step 103, the document layout analysis is performed, and through steps 104 and 105, the structured data extraction is performed, and then through step 106, the extracted data is stored in the vector database.
[0117] The RAG data parsing method in the rail transit field provided in this embodiment optimizes the processing link of large model input files. It batch processes doc, docx, ppt, pptx and other types of documents into pdf documents, and then uses the OCR recognition method to extract text and table content in the documents, and structure the content categories. It improves the standardization and consistency of the large model input data, and can improve the efficiency and accuracy of the domain big model in processing various types of domain documents.
[0118] The RAG data parsing method in the field of rail transit provided by the present embodiment is particularly suitable for parsing multiple types of documents containing various forms in the field of urban rail transit. For example, in view of the current situation of complex document formats and diverse structures in the field of rail transit, the RAG data parsing method in the field of rail transit provided by the present embodiment can perform unified data parsing and extraction on various technical documents in the field of rail transit, especially can effectively parse tables and unstructured paragraph information, and store the parsing results in a structured form in a vector database for use in RAG question and answer applications. The RAG data parsing method in the field of rail transit provided by the present embodiment can simplify the data processing flow of technical documents in the field of rail transit, improve the efficiency of knowledge base construction, and significantly improve the accuracy and knowledge coverage of large model question and answer systems.
[0119] The present embodiment provides a RAG data parsing method in the field of rail transit, which obtains a document; if the format of the document is not in PDF format, it is converted to PDF format; the document in PDF format is analyzed for layout, and the table area and text area in the document in PDF format are identified; for the table area, the single-line text, table structure and cell coordinates in the table are identified, and the recognition result of the cell is formed based on the single-line text and cell coordinates, and the html string of the table element is formed based on the recognition result of the table structure and the cell; for the text area, the structure of the document and the coordinates of the text element are identified, and the text element is classified according to the structure of the document and the coordinates of the text element, and the text content is extracted according to the classification result; the html string and the text content are converted into structured metadata and stored in the vector database of RAG. The method provided in the present embodiment first unifies the format of the document into PDF format, provides a unified input source for data parsing, and avoids the influence of format differences on the parsing results. Then the layout analysis of the PDF format of the document is performed, the table area and the text area are identified, and then the metadata is extracted for the table area and the text area respectively, so as to realize the complete and accurate extraction of information and enhance the application value of the document in practical work.
[0120] Based on the same inventive concept of the RAG data parsing method in the field of rail transit, this embodiment provides a RAG data parsing device in the field of rail transit, such as Fig. 9 As shown, the device comprises:
[0121] The acquisition module 901 is used to acquire a document.
[0122] The conversion module 902 is used to convert the document into a PDF format if the document is not in a PDF format.
[0123] The identification module 903 is used to perform layout analysis on the document in the PDF format and identify the table area and text area in the document in the PDF format.
[0124] The table extraction module 904 is used to identify the single-line text, table structure and cell coordinates in the table area, form the cell recognition result based on the single-line text and cell coordinates, and form the HTML string of the table element based on the table structure and cell recognition results.
[0125] The text extraction module 905 is used to identify the structure of the document and the coordinates of the text elements in the text area, classify the text elements according to the structure of the document and the coordinates of the text elements, and extract the text content according to the classification result.
[0126] The storage module 906 is used to convert the HTML string and text content into structured metadata and store them in the vector database of RAG.
[0127] Among them, the recognition module 903 is used to analyze the document in PDF format through a lightweight object detection model to identify the table area and the text area.
[0128] The text area includes an English text area and a Chinese text area.
[0129] The English text area includes: English text Text class sub-area, Title class sub-area, Tale class sub-area, Figure class sub-area, and List class sub-area.
[0130] The Chinese text area includes: Chinese text Text class sub-area, Title class sub-area, Figure class sub-area, Figure caption class sub-area, Table class sub-area, Tablecaption class sub-area, Header class sub-area, Footer class sub-area, Reference class sub-area, and Equation class sub-area.
[0131] The table extraction module 904 is used to identify the coordinates of a single line of text through a single line text detection model, identify a single line of text based on the coordinates of the single line of text through a single line text recognition model, and identify the boundaries and coordinates of each cell in the table through a table structure and cell coordinate prediction model.
[0132] The table extraction module 904 is used to associate each cell with adjacent cells according to the cell coordinates, and extract the contents of the associated cells from the single-line text to obtain the recognition result of the cell.
[0133] The text extraction module 905 is used to identify the text area through a text detection and recognition model to obtain the structure of the document and the coordinates of the text elements.
[0134] The structure of the document includes the structure of the title part and the structure of the body part. The structure of the title part is divided according to the title level, and the structure of the body part is divided according to natural paragraphs.
[0135] The text extraction module 905 is used to extract the coordinates of the text elements of each paragraph according to the document structure and the coordinates of the text elements in combination with the paragraph classification algorithm, and to classify the coordinates of the text elements of each paragraph into one category.
[0136] The text extraction module 905 is used to extract the content of each category according to the coordinates of the text elements in each category, determine the layout order between the categories according to the coordinates of the text elements, and form text content based on the layout order between the categories and the content in each category.
[0137] The device provided in this embodiment first unifies the format of the document into PDF format, provides a unified input source for data analysis, and avoids the influence of format differences on the analysis results. Then, the PDF format of the document is analyzed, the table area and the text area are identified, and metadata is extracted from the table area and the text area respectively, so as to achieve complete and accurate extraction of information and enhance the application value of the document in practical work.
[0138] Based on the same inventive concept of the RAG data parsing method in the field of rail transit, this embodiment provides an electronic device, such as Fig.10 As shown, it includes: a memory 1001, a processor 1002, and a computer program.
[0139] The computer program is stored in the memory 1001 and is configured to be executed by the processor 1002 to implement the RAG data analysis method in the field of rail transit.
[0140] Specifically,
[0141] Get the document.
[0142] If the document is not in pdf format, convert it to pdf format.
[0143] Perform layout analysis on documents in PDF format and identify table areas and text areas in documents in PDF format.
[0144] For the table area, the single-line text, table structure and cell coordinates in the table are identified, the recognition result of the cell is formed based on the single-line text and the cell coordinates, and the HTML string of the table element is formed based on the recognition result of the table structure and the cell.
[0145] For the text area, the structure of the document and the coordinates of the text elements are identified, the text elements are classified according to the structure of the document and the coordinates of the text elements, and the text content is extracted according to the classification results.
[0146] Convert html strings and text content into structured metadata and store them in RAG's vector database.
[0147] Optionally, performing layout analysis on the document in PDF format to identify table areas and text areas in the document in PDF format includes:
[0148] The PDF document is analyzed using a lightweight object detection model to identify table areas and text areas.
[0149] The text area includes an English text area and a Chinese text area.
[0150] The English text area includes: English text Text class sub-area, Title class sub-area, Tale class sub-area, Figure class sub-area, and List class sub-area.
[0151] The Chinese text area includes: Chinese text Text class sub-area, Title class sub-area, Figure class sub-area, Figure caption class sub-area, Table class sub-area, Tablecaption class sub-area, Header class sub-area, Footer class sub-area, Reference class sub-area, and Equation class sub-area.
[0152] Optionally, identify single-line text, table structure, and cell coordinates in a table, including:
[0153] The coordinates of a single line of text are identified through the single line text detection model.
[0154] The single-line text recognition model is used to recognize single-line text based on its coordinates.
[0155] Through the table structure and cell coordinate prediction model, the boundaries and coordinates of each cell in the table are identified.
[0156] Optionally, forming a recognition result of a cell based on the single-line text and the cell coordinates includes:
[0157] Associate each cell with its neighboring cells based on cell coordinates.
[0158] The contents of the associated cells are extracted from the single-line text to obtain the recognition result of the cell.
[0159] Optionally, identify the structure of the document and the coordinates of text elements, including:
[0160] The text area is identified through the text detection and recognition model to obtain the structure of the document and the coordinates of the text elements.
[0161] The structure of the document includes the structure of the title part and the structure of the body part. The structure of the title part is divided according to the title level, and the structure of the body part is divided according to natural paragraphs.
[0162] Optionally, the text elements are classified according to the structure of the document and the coordinates of the text elements, including:
[0163] According to the document structure and the coordinates of the text elements, combined with the paragraph classification algorithm, the coordinates of the elements of each paragraph are extracted.
[0164] Group the coordinates of the text elements of each paragraph into one category.
[0165] Optionally, extract text content based on the classification results, including:
[0166] The content in each category is extracted according to the coordinates of the text elements in each category.
[0167] According to the coordinates of the text elements, the layout order between each category is determined.
[0168] Based on the layout order between the categories and the content in each category, the text content is formed.
[0169] The electronic device provided by this embodiment has a computer program executed by a processor to first unify the format of the document into a PDF format, provide a unified input source for data analysis, and avoid the influence of format differences on the analysis results. Then, the PDF format of the document is analyzed for layout, the table area and the text area are identified, and metadata is extracted for the table area and the text area respectively, so as to achieve complete and accurate extraction of information and enhance the application value of the document in actual work.
[0170] Based on the same inventive concept of the RAG data parsing method in the field of rail transit, this embodiment provides a computer-readable storage medium, and a computer program is stored thereon. The computer program is executed by a processor to implement the RAG data parsing method in the field of rail transit.
[0171] Specifically,
[0172] Get the document.
[0173] If the document is not in pdf format, convert it to pdf format.
[0174] Perform layout analysis on documents in PDF format and identify table areas and text areas in documents in PDF format.
[0175] For the table area, the single-line text, table structure and cell coordinates in the table are identified, the recognition result of the cell is formed based on the single-line text and the cell coordinates, and the HTML string of the table element is formed based on the recognition result of the table structure and the cell.
[0176] For the text area, the structure of the document and the coordinates of the text elements are identified, the text elements are classified according to the structure of the document and the coordinates of the text elements, and the text content is extracted according to the classification results.
[0177] Convert html strings and text content into structured metadata and store them in RAG's vector database.
[0178] Optionally, performing layout analysis on the document in PDF format to identify table areas and text areas in the document in PDF format includes:
[0179] The PDF document is analyzed using a lightweight object detection model to identify table areas and text areas.
[0180] The text area includes an English text area and a Chinese text area.
[0181] The English text area includes: English text Text class sub-area, Title class sub-area, Tale class sub-area, Figure class sub-area, and List class sub-area.
[0182] The Chinese text area includes: Chinese text Text class sub-area, Title class sub-area, Figure class sub-area, Figure caption class sub-area, Table class sub-area, Tablecaption class sub-area, Header class sub-area, Footer class sub-area, Reference class sub-area, and Equation class sub-area.
[0183] Optionally, identify single-line text, table structure, and cell coordinates in a table, including:
[0184] The coordinates of a single line of text are identified through the single line text detection model.
[0185] The single-line text recognition model is used to recognize single-line text based on its coordinates.
[0186] Through the table structure and cell coordinate prediction model, the boundaries and coordinates of each cell in the table are identified.
[0187] Optionally, forming a recognition result of a cell based on the single-line text and the cell coordinates includes:
[0188] Associate each cell with its neighboring cells based on cell coordinates.
[0189] The contents of the associated cells are extracted from the single-line text to obtain the recognition result of the cell.
[0190] Optionally, identify the structure of the document and the coordinates of text elements, including:
[0191] The text area is identified through the text detection and recognition model to obtain the structure of the document and the coordinates of the text elements.
[0192] The structure of the document includes the structure of the title part and the structure of the body part. The structure of the title part is divided according to the title level, and the structure of the body part is divided according to natural paragraphs.
[0193] Optionally, the text elements are classified according to the structure of the document and the coordinates of the text elements, including:
[0194] According to the document structure and the coordinates of the text elements, combined with the paragraph classification algorithm, the coordinates of the elements of each paragraph are extracted.
[0195] Group the coordinates of the text elements of each paragraph into one category.
[0196] Optionally, extract text content based on the classification results, including:
[0197] The content in each category is extracted according to the coordinates of the text elements in each category.
[0198] According to the coordinates of the text elements, the layout order between each category is determined.
[0199] Based on the layout order between the categories and the content in each category, the text content is formed.
[0200] The computer-readable storage medium provided in this embodiment has a computer program executed by a processor to first unify the format of the document into a PDF format, provide a unified input source for data analysis, and avoid the impact of format differences on the analysis results. Then, the PDF format of the document is analyzed for layout, the table area and the text area are identified, and metadata is extracted for the table area and the text area respectively, so as to achieve complete and accurate extraction of information and enhance the application value of the document in actual work.
[0201] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code. The scheme in the embodiments of the present application can be implemented in various computer languages, for example, object-oriented programming language Java and literal scripting language JavaScript, etc.
[0202] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0203] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0204] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0205] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0206] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A RAG data analysis method in the field of rail transit, characterized in that: The method comprises: Get the document; If the document is not in PDF format, convert it to PDF format; Perform layout analysis on documents in PDF format and identify table areas and text areas in documents in PDF format; For the table area, identify the single-line text, table structure and cell coordinates in the table, form the recognition result of the cell based on the single-line text and cell coordinates, and form the HTML string of the table element based on the recognition result of the table structure and cell; For the text area, the structure of the document and the coordinates of the text elements are identified, the text elements are classified according to the structure of the document and the coordinates of the text elements, and the text content is extracted according to the classification results; Convert html strings and text content into structured metadata and store them in RAG's vector database.
2. The method according to claim 1, characterized in that: The step of performing layout analysis on a document in PDF format and identifying a table area and a text area in the document in PDF format includes: Analyze the PDF document through a lightweight object detection model to identify the table area and text area; Wherein, the text area includes an English text area and a Chinese text area; The English text area includes: English text sub-area, Title sub-area, Tale sub-area, Figure sub-area, List sub-area; The Chinese text area includes: Chinese text Text class sub-area, Title class sub-area, Figure class sub-area, Figure caption class sub-area, Table class sub-area, Table caption class sub-area, Header class sub-area, Footer class sub-area, Reference class sub-area, and Equation class sub-area.
3. The method according to claim 1, characterized in that The identifying of single-line text, table structure and cell coordinates in a table includes: Through the single-line text detection model, the coordinates of a single line of text are identified; Through the single-line text recognition model, the single-line text is recognized based on the coordinates of the single-line text; Through the table structure and cell coordinate prediction model, the boundaries and coordinates of each cell in the table are identified.
4. The method according to claim 1, characterized in that The recognition result of the cell based on the single-line text and the cell coordinates includes: Associate each cell with its neighboring cells based on cell coordinates; The contents of the associated cells are extracted from the single-line text to obtain the recognition result of the cell.
5. The method according to claim 1, characterized in that The structure of the identified document and the coordinates of the text elements include: Identify the text area through the text detection and recognition model to obtain the structure of the document and the coordinates of the text elements; The structure of the document includes the structure of the title part and the structure of the body part; the structure of the title part is divided according to the title level, and the structure of the body part is divided according to natural paragraphs.
6. The method according to claim 1, characterized in that The classifying of text elements according to the structure of the document and the coordinates of the text elements comprises: According to the document structure and the coordinates of the text elements, combined with the paragraph classification algorithm, the coordinates of the elements of each paragraph are extracted; Group the coordinates of the text elements of each paragraph into one category.
7. The method according to claim 6, characterized in that The extracting text content according to the classification result includes: Extract the content in each category according to the coordinates of the text elements in each category; According to the coordinates of text elements, determine the layout order between categories; Based on the layout order between the categories and the content in each category, the text content is formed.
8. A RAG data analysis device in the field of rail transit, characterized in that: The device comprises: The acquisition module is used to obtain documents; A conversion module, used for converting a document into a PDF format if the format of the document is not a PDF format; A recognition module is used to analyze the layout of a document in PDF format and recognize table areas and text areas in the document in PDF format; The table extraction module is used to identify the single-line text, table structure and cell coordinates in the table area, form the recognition result of the cell based on the single-line text and the cell coordinates, and form the HTML string of the table element based on the recognition result of the table structure and the cell; A text extraction module is used to identify the structure of the document and the coordinates of the text elements in the text area, classify the text elements according to the structure of the document and the coordinates of the text elements, and extract the text content according to the classification results; The storage module is used to convert HTML strings and text content into structured metadata and store them in the RAG vector database.
9. An electronic device, characterized in that: include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon; the computer program is executed by a processor to implement the method according to any one of claims 1 to 7.