A numerical extraction method and device, electronic equipment and storage medium
By obtaining element coordinates and parsing word parameter information from PDF files, a tree structure is created, solving the problem of low efficiency in numerical extraction from PDF files and achieving fast and accurate numerical extraction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHENGDU ZHIZHI CHUANGYU INFORMATION TECH CO LTD
- Filing Date
- 2022-09-20
- Publication Date
- 2026-06-12
AI Technical Summary
In existing technologies, numerical extraction from PDF files relies on manual methods, which leads to low efficiency and is prone to errors.
By obtaining the element coordinates in the PDF file, identifying sentences and tables, parsing word parameter information, creating a tree structure, and obtaining user keywords, numerical values can be extracted quickly and accurately from the PDF file.
It enables the rapid and accurate extraction of keyword values from a large number of PDF files, reducing data extraction costs and avoiding errors and inefficiencies caused by manual statistics.
Smart Images

Figure CN115422340B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and more specifically, to a numerical extraction method, apparatus, electronic device, and storage medium. Background Technology
[0002] Scientific and technological literature is the culmination of technological development and accumulation, and it is essential for modern enterprises in scientific research, production organization, and product quality improvement. With the continuous development of science and technology, the accumulation of scientific and technological literature is becoming increasingly abundant. The internet offers many publicly available PDF resources of scientific and technological literature, containing a wealth of valuable and explorable information. However, compared to traditional web pages, Word documents, and TXT files, PDFs of scientific and technological literature come in various formats and often lack structural information, making it very difficult to extract table data and image data.
[0003] Currently, numerical values are typically extracted from PDF files manually. When there are many PDF files, a significant amount of manpower is required to extract the necessary values. This extraction method is prone to errors and inefficient. Summary of the Invention
[0004] The purpose of this invention is to provide a numerical extraction method, apparatus, electronic device, and storage medium that can improve the efficiency of extracting numerical values from PDFs.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows:
[0006] In a first aspect, embodiments of this application provide a numerical extraction method, the method comprising:
[0007] Obtain the PDF file to be extracted;
[0008] Determine the coordinates of each element in the PDF file to be extracted, where each element includes text and lines;
[0009] Based on the coordinates of each element, determine the sentences and / or tables in the PDF file to be extracted;
[0010] The sentence is parsed to obtain each word and its corresponding parameter information, wherein the parameter information includes word attributes and the relationship between words above and below;
[0011] Based on each word and its corresponding parameter information, a tree structure is created for each sentence;
[0012] Get the keywords entered by the user;
[0013] Based on the keywords, determine the numerical values corresponding to the keywords from each tree structure and / or table.
[0014] In an optional implementation, the step of determining the sentences in the PDF file to be extracted based on the coordinates of each element includes:
[0015] Based on the coordinates of each element;
[0016] Determine the distance between adjacent elements;
[0017] When the distance between adjacent elements is less than a preset distance, a sentence is formed based on the adjacent elements.
[0018] In an optional implementation, the method further includes:
[0019] For each sentence, determine the first starting coordinate of the sentence and the second starting coordinate of the sentence in the next line;
[0020] If the x-coordinates of the first starting coordinate and the second starting coordinate are the same, determine whether there are lines within the preset range of the sentence;
[0021] If they exist, create a table from the sentences.
[0022] In an optional implementation, the step of determining the numerical value corresponding to the keyword from each tree structure based on the keyword includes:
[0023] Based on the keywords, traverse each tree structure;
[0024] If the target word in the target tree structure matches the keyword, determine the word attribute of the target word;
[0025] When the word attribute of the target word is a noun, the object corresponding to the target word is determined in the target tree structure;
[0026] Obtain the numerical value corresponding to the object in the target tree structure.
[0027] In an optional implementation, the step of traversing each tree structure based on the keyword includes:
[0028] Based on the keywords, each tree structure is traversed using an inorder traversal.
[0029] In an optional implementation, the step of determining the numerical value corresponding to the keyword from each table based on the keyword includes:
[0030] Based on the keywords, the numerical values corresponding to the keywords are determined from each table using regular expression matching.
[0031] In an optional implementation, the method further includes:
[0032] Save each tree structure and / or each table in protobuf format.
[0033] Secondly, embodiments of this application provide a numerical extraction apparatus, the apparatus comprising:
[0034] The first acquisition module is used to acquire the PDF file to be extracted;
[0035] The first determining module is used to extract the coordinates of each element in the PDF file to be extracted, wherein each element includes text and lines;
[0036] The second determining module is used to determine sentences and / or tables in the PDF file to be extracted based on the coordinates of each element.
[0037] The parsing module is used to parse the sentence to obtain each word and the corresponding parameter information, wherein the parameter information includes word attributes and the relationship between words above and below;
[0038] Create a module to generate a tree structure for each sentence based on each word and its corresponding parameter information;
[0039] The second acquisition module is used to acquire keywords input by the user;
[0040] The third determining module is used to determine the numerical value corresponding to the keyword from each tree structure and / or table based on the keyword.
[0041] Thirdly, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the numerical extraction method.
[0042] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the numerical extraction method.
[0043] This application has the following beneficial effects:
[0044] This application obtains a PDF file to be extracted, determines the coordinates of each element in the PDF file, identifies sentences and / or tables in the PDF file based on the coordinates of each element, parses the sentences to obtain each word and its corresponding parameter information, creates a tree structure for each sentence based on each word and its corresponding parameter information, obtains user-input keywords, and determines the corresponding values for the keywords from each tree structure and / or table. This method can quickly and accurately find all data corresponding to keywords from a large number of PDF files, reducing data extraction costs and avoiding the problems of inaccurate and inefficient data extraction caused by manual statistics. Attached Figure Description
[0045] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0046] Figure 1 A block diagram of an electronic device provided in an embodiment of the present invention;
[0047] Figure 2 This is one of the flowcharts illustrating the steps of numerical extraction provided in an embodiment of the present invention;
[0048] Figure 3 This is a second schematic diagram of a numerical extraction process provided in an embodiment of the present invention;
[0049] Figure 4 This is the third step in the flowchart of a numerical extraction method provided in an embodiment of the present invention;
[0050] Figure 5 A schematic diagram of the PDF file to be extracted, provided for an embodiment of the present invention;
[0051] Figure 6 This is the fourth step in the flowchart of a numerical extraction method provided in an embodiment of the present invention;
[0052] Figure 7 This is a structural block diagram of a numerical extraction device provided in an embodiment of the present invention. Detailed Implementation
[0053] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0054] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0055] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0056] In the description of this invention, it should be noted that if terms such as "upper," "lower," "inner," or "outer" are used to indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship in which the product of this invention is usually placed, they are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this invention.
[0057] Furthermore, the terms "first" and "second" are used only to distinguish descriptions and should not be interpreted as indicating or implying relative importance.
[0058] In the description of this application, it should also be noted that, unless otherwise expressly specified and limited, the terms "set up," "install," "connect," and "link" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances.
[0059] Extensive research by the inventors revealed that current methods for extracting numerical values from PDF files are generally manual. When there are many PDF files, a significant amount of manpower is required to extract the necessary values. This extraction method is prone to errors and inefficient.
[0060] In view of the above-mentioned problems, this embodiment provides a numerical extraction method, apparatus, electronic device, and storage medium. It can acquire a PDF file to be extracted, determine the coordinates of each element in the PDF file, determine the sentences and / or tables in the PDF file based on the coordinates of each element, parse the sentences to obtain each word and its corresponding parameter information, create a tree structure for each sentence based on the words and their corresponding parameter information, obtain user-input keywords, and determine the numerical values corresponding to the keywords from the tree structures and / or tables. This method can quickly and accurately find all data corresponding to keywords from a large number of PDF files, reducing data extraction costs and avoiding the problems of inaccurate and inefficient data extraction caused by manual statistics. The solution provided in this embodiment is described in detail below.
[0061] This embodiment provides an electronic device capable of extracting numerical values. In one possible implementation, the electronic device can be a user terminal, such as, but not limited to, a server, smartphone, personal computer (PC), tablet computer, personal digital assistant (PDA), mobile internet device (MID), etc.
[0062] Please refer to Figure 1 , Figure 1 This is a schematic diagram of the structure of the electronic device 100 provided in the embodiments of this application. The electronic device 100 may further include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.
[0063] The electronic device 100 includes a data extraction device 110, a memory 120, and a processor 130.
[0064] The components of the memory 120 and processor 130 are electrically connected directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. The value extraction device 110 includes at least one software function module that can be stored in the memory 120 in the form of software or firmware or embedded in the operating system (OS) of the electronic device 100. The processor 130 is used to execute the executable modules stored in the memory 120, such as the software function modules and computer programs included in the value extraction device 110.
[0065] The memory 120 may be, but is not limited to, Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), etc. The memory 120 is used to store programs, and the processor 130 executes the programs after receiving execution instructions.
[0066] Please refer to Figure 2 , Figure 2 For application Figure 1 The flowchart below shows a numerical extraction method for an electronic device 100, and the method includes a detailed description of each step.
[0067] Step 201: Obtain the PDF file to be extracted.
[0068] Step 202: Extract the coordinates of each element in the PDF file to be extracted.
[0069] The elements include text and lines.
[0070] Step 203: Based on the coordinates of each element, determine the sentences and / or tables in the PDF file to be extracted.
[0071] Step 204: Parse the sentence to obtain each word and its corresponding parameter information.
[0072] The parameter information includes word attributes and the relationship between words in the preceding and following sentences.
[0073] Step 205: Based on each word and its corresponding parameter information, create a tree structure for each sentence.
[0074] Step 206: Obtain the keywords entered by the user.
[0075] Step 207: Based on the keywords, determine the corresponding numerical values for the keywords from each tree structure and / or table.
[0076] It should be noted that the PDF file to be extracted can be a PDF file of financial data, a PDF file of experimental data, a PDF file of research data, etc. This application does not impose specific restrictions on the type of PDF file to be extracted.
[0077] To facilitate the extraction of the required values from the PDF file, it is necessary to first extract the coordinates of each element in the PDF file. Since the elements in the PDF file contain text and lines, the coordinates of each text and line in the PDF file need to be determined.
[0078] It should be noted that the coordinates of the text can be determined by taking the bottom left position of the current page as the zero point, and then determining the horizontal and vertical coordinates of the text in the current coordinate system.
[0079] The coordinates of the lines can be based on the bottom left position of the current page as the zero point. The lines can be parallel to the horizontal axis or parallel to the vertical axis. When the line is parallel to the horizontal axis, determine the vertical coordinate of the line, as well as the start and end coordinates of the horizontal coordinate. When the line is parallel to the vertical axis, determine the horizontal coordinate of the line, as well as the start and end coordinates of the vertical coordinate.
[0080] Based on the relationship between the coordinates of each element, the sentences and / or tables in the PDF file to be extracted are determined.
[0081] In one example, when it is determined that the PDF file to be extracted contains five text elements, the coordinates of each element are determined. When the distance between the coordinates of two adjacent text elements is less than a preset distance, it is determined that the five elements constitute a sentence. The sentence is segmented using jieba to obtain multiple words. Natural Language Processing (NLP) is then used to determine the word attributes of these words, such as subject, predicate, object, noun, verb, etc. Each word is linked to another word. For example, in the sentence: "Net profit margin value is A", after segmenting the sentence, we obtain "net profit margin value", "for", and "A". "Net profit margin value" is the preceding word of "for", "for" is the following word of "net profit margin value", and "A" is the following word of "for", forming a tree structure.
[0082] When the user inputs keywords, if the keyword is "net profit margin", the tree structure of each sentence can be traversed and searched. From the tree structure composed of "net profit margin", "for", and "A", the value corresponding to the keyword is determined to be "A", and A is extracted.
[0083] In another example, when it is determined that the PDF file to be extracted contains 5 sentence elements, and it is also determined that the PDF file to be extracted contains line elements, and lines are detected around each sentence, it is determined that the five sentences in the PDF file to be extracted constitute a table.
[0084] In another example, if it is determined that the PDF file to be extracted contains 10 text elements, and based on the coordinates of each element, it is determined that the 10 text elements constitute two sentences, and the first sentence and the second sentence are left-aligned, then the two sentences are determined to constitute a table.
[0085] Saving each tree structure and / or table in protobuf format avoids excessive storage space usage and improves retrieval speed.
[0086] When the user inputs keywords, each table can be searched to determine the corresponding value for each keyword.
[0087] This application obtains a PDF file to be extracted, determines the coordinates of each element in the PDF file, identifies sentences and / or tables in the PDF file based on the coordinates of each element, parses the sentences to obtain each word and its corresponding parameter information, creates a tree structure for each sentence based on each word and its corresponding parameter information, obtains user-input keywords, and determines the corresponding values for the keywords from each tree structure and / or table. This method can quickly and accurately find all data corresponding to keywords from a large number of PDF files, reducing data extraction costs and avoiding the problems of inaccurate and inefficient data extraction caused by manual statistics.
[0088] Regarding how to determine the sentences in the PDF file to be extracted, such as Figure 3 As shown, a numerical extraction method is provided, including the following steps:
[0089] Step 203-1: Based on the coordinates of each element.
[0090] Step 203-2: Determine the distance between adjacent elements.
[0091] Step 203-3: When the distance between adjacent elements is less than the preset distance, construct a sentence based on the adjacent elements.
[0092] For example, the coordinates of each character in the PDF file to be extracted are determined, and the distance between the coordinates of two adjacent characters is determined. There are multiple ways to determine the distance between the coordinates of two characters. In one example, the distance between the two coordinates can be calculated based on Euclidean distance.
[0093] The distance between adjacent characters is compared to a preset distance. If the distance between adjacent characters is greater than the preset distance, the adjacent characters cannot form a sentence. If the distance between adjacent characters is less than the preset distance, a sentence is formed based on adjacent elements.
[0094] It should be noted that the preset distance can be set to 3mm, 4mm, 5mm, etc., and this application does not impose specific restrictions on it.
[0095] A table regarding how to determine the PDF files to be extracted, such as Figure 4 As shown, a numerical extraction method is provided, including the following steps:
[0096] Step 301: For each sentence, determine the first starting coordinate of the sentence and the second starting coordinate of the sentence in the next line.
[0097] Step 302: If the x-coordinates of the first and second starting coordinates are the same, determine whether there are lines within the preset range of the sentence.
[0098] Step 303: If they exist, construct a table from the sentences.
[0099] For example, when determining the table in the PDF file to be extracted, the coordinates of each text element are first determined. Based on the coordinates of each text element, sentences are formed. Then, the first starting coordinate of each sentence is determined. The first starting coordinate of each sentence and the second starting coordinate of the next sentence are determined. When the horizontal coordinates of the first and second starting coordinates are the same, and there is a line within the preset range of the sentence, that is, when the distance between a certain text element in the sentence and the line meets the preset condition, the sentences that meet the condition are formed into a table. The preset condition is that there is a line within the preset range of the sentence.
[0100] For example, such as Figure 5 As shown, this is the PDF file to be extracted. The sentences identified in the figure are those in the first column. The first and second starting coordinates of the sentences in the first row and first column and the sentences in the second row and first column are determined, that is, the first starting coordinate of "key accounting data" and the second starting coordinate of "total operating revenue" are determined. The horizontal coordinates of the first starting coordinates of "key accounting data" and the second starting coordinates of "total operating revenue" are the same. For each sentence, the first and second starting coordinates of each sentence and the sentence in the next row are determined. All sentences that satisfy the first and second starting coordinates with the same horizontal coordinate are identified. It is determined whether there are lines within the preset range of each sentence. Sentences with lines are used to form a table.
[0101] In another instance, when determining the table of the PDF file to be extracted, the first starting coordinate and the second starting coordinate of each sentence and the next sentence are determined respectively. All sentences with the same x-coordinate that satisfy the first starting coordinate and the second starting coordinate are identified, and the sentences with the same x-coordinate are formed into a table.
[0102] For keywords based on user input, numerical values are determined from the sentence's tree structure, such as... Figure 6 As shown, a numerical extraction method is provided, including the following steps:
[0103] Step 207-1: Based on the keywords, traverse each tree structure.
[0104] Step 207-2: If the target word in the target tree structure matches the keyword, determine the word attribute of the target word.
[0105] Step 207-3: When the word attribute of the target word is a noun, determine the object corresponding to the target word in the target tree structure.
[0106] Step 207-4: Obtain the numerical value corresponding to the object in the target tree structure.
[0107] Traverse the tree structure corresponding to each sentence. When a tree structure matching the keyword is detected, the matching tree structure is identified as the target tree structure. From the target tree structure, determine the word attributes of the target word matching the keyword. When the target word is a noun, determine the object of the target word in the target tree structure. Determine the value after determining the object in the target tree structure and output the value.
[0108] In another example, multiple sentences can be combined into paragraphs. Based on the words and their attributes within each paragraph, a tree structure corresponding to the paragraph can be constructed. When a keyword is input by the user, the tree structure corresponding to each paragraph can be traversed, and the numerical value corresponding to the keyword can be extracted from each tree structure.
[0109] It should be noted that, based on keywords, the numerical value corresponding to the keyword can be determined from the tree structure through preorder traversal, inorder traversal, or postorder traversal. This application does not impose specific restrictions on the traversal method.
[0110] When you need to determine the numerical values corresponding to keywords from a table in a PDF file to be extracted, you can use regular expression matching to determine the numerical values corresponding to keywords from the table.
[0111] Please refer to Figure 7 This application embodiment also provides an application for Figure 1 The electronic device 100 includes a data extraction device 110, which comprises:
[0112] The first acquisition module 111 is used to acquire the PDF file to be extracted;
[0113] The first determining module 112 is used to extract the coordinates of each element in the PDF file to be extracted, wherein each element includes text and lines.
[0114] The second determining module 113 is used to determine sentences and / or tables in the PDF file to be extracted based on the coordinates of each element.
[0115] The parsing module 114 is used to parse the sentence to obtain each word and the parameter information corresponding to each word, wherein the parameter information includes word attributes and the relationship between words above and below;
[0116] Create module 115 to create a tree structure for each sentence based on each word and the parameter information corresponding to each word;
[0117] The second acquisition module 116 is used to acquire keywords input by the user;
[0118] The third determining module 117 is used to determine the numerical value corresponding to the keyword from each tree structure and / or table based on the keyword.
[0119] Preferably, the second determining module 113 is further configured to:
[0120] Based on the coordinates of each element;
[0121] Determine the distance between adjacent elements;
[0122] When the distance between adjacent elements is less than a preset distance, a sentence is formed based on the adjacent elements.
[0123] Preferably, the device further includes:
[0124] The fourth determination module is used to determine the first starting coordinate of each sentence and the second starting coordinate of the next sentence in the line below it.
[0125] The fifth determining module is used to determine whether there are lines within a preset range of the sentence when the x-coordinates of the first starting coordinate and the second starting coordinate are the same.
[0126] The building block is used to construct a table from the sentences, if it exists.
[0127] Preferably, the third determining module 117 is further configured to:
[0128] Based on the keywords, traverse each tree structure;
[0129] If the target word in the target tree structure matches the keyword, determine the word attribute of the target word;
[0130] When the word attribute of the target word is a noun, the object corresponding to the target word is determined in the target tree structure;
[0131] Obtain the numerical value corresponding to the object in the target tree structure.
[0132] Preferably, the third determining module 117 is further configured to:
[0133] Based on the keywords, each tree structure is traversed using an inorder traversal.
[0134] Preferably, the third determining module 117 is further configured to:
[0135] Based on the keywords, the numerical values corresponding to the keywords are determined from each table using regular expression matching.
[0136] Preferably, each tree structure and / or each table is saved in protobuf format.
[0137] This application also provides an electronic device 100, which includes a processor 130 and a memory 120. The memory 120 stores computer-executable instructions, which, when executed by the processor 130, implement the value extraction method.
[0138] This application embodiment also provides a computer-readable storage medium storing a computer program, which, when executed by the processor 130, implements the numerical extraction method.
[0139] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0140] Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part. If the function is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.
[0141] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0142] The above descriptions are merely various embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A numerical extraction method, characterized in that, The method includes: Obtain the PDF file to be extracted; Determine the coordinates of each element in the PDF file to be extracted, where each element includes text and lines; Based on the coordinates of each element, determine the sentences and / or tables in the PDF file to be extracted; The sentence is parsed to obtain each word and its corresponding parameter information, wherein the parameter information includes word attributes and the relationship between words above and below; Based on each word and its corresponding parameter information, a tree structure is created for each sentence; Get the keywords entered by the user; Based on the keywords, determine the numerical values corresponding to the keywords from each tree structure and / or table; The step of determining the numerical value corresponding to the keyword from each tree structure based on the keyword includes: Based on the keywords, traverse each tree structure; If the target word in the target tree structure matches the keyword, determine the word attribute of the target word; When the word attribute of the target word is a noun, the object corresponding to the target word is determined in the target tree structure; Obtain the numerical value corresponding to the object in the target tree structure.
2. The method according to claim 1, characterized in that, The steps for determining the sentences in the PDF file to be extracted based on the coordinates of each element include: Based on the coordinates of each element; Determine the distance between adjacent elements; When the distance between adjacent elements is less than a preset distance, a sentence is formed based on the adjacent elements.
3. The method according to claim 2, characterized in that, The method further includes: For each sentence, determine the first starting coordinate of the sentence and the second starting coordinate of the sentence in the next line; If the x-coordinates of the first starting coordinate and the second starting coordinate are the same, determine whether there are lines within the preset range of the sentence; If they exist, create a table from the sentences.
4. The method according to claim 1, characterized in that, The step of traversing each tree structure based on the keyword includes: Based on the keywords, each tree structure is traversed using an inorder traversal.
5. The method according to claim 1, characterized in that, The step of determining the numerical value corresponding to the keyword from each table based on the keyword includes: Based on the keywords, the numerical values corresponding to the keywords are determined from each table using regular expression matching.
6. The method according to claim 1, characterized in that, The method further includes: Save each tree structure and / or each table in protobuf format.
7. A numerical extraction device, characterized in that, The device includes: The first acquisition module is used to acquire the PDF file to be extracted; The first determining module is used to extract the coordinates of each element in the PDF file to be extracted, wherein each element includes text and lines; The second determining module is used to determine sentences and / or tables in the PDF file to be extracted based on the coordinates of each element. The parsing module is used to parse the sentence to obtain each word and the corresponding parameter information, wherein the parameter information includes word attributes and the relationship between words above and below; Create a module to generate a tree structure for each sentence based on each word and its corresponding parameter information; The second acquisition module is used to acquire keywords input by the user; The third determining module is used to determine the numerical value corresponding to the keyword from each tree structure and / or table based on the keyword; The third determining module is specifically used to: traverse each tree structure based on the keyword; If the target word in the target tree structure matches the keyword, determine the word attribute of the target word; When the word attribute of the target word is a noun, the object corresponding to the target word is determined in the target tree structure; Obtain the numerical value corresponding to the object in the target tree structure.
8. An electronic device, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the method according to any one of claims 1-6.
9. A storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the method described in any one of claims 1-6.
Citation Information
Patent Citations
Method and device for analyzing table in a PDF file, computing equipment and storage medium
CN112287660A
Method and device for mining PDF table in PDF file and medium
CN114201620A