An article error serial number automatic correction method, system, device and storage medium
Patent Information
- Application Number
- CN202610693227.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-20
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2046-05-20
AI Technical Summary
然而在实际编辑过程中,由于人工录入失误、内容增删、多人协同编辑等原因,文章中极易出现序号跳级、序号重复、序号类型不统一、多级序号层级混乱等错误,严重破坏文档结构,降低阅读体验
1、本发明通过预定义的正则表达式实现多种序号类型的自动识别,并利用映射关系将中文数字、带圈数字等统一转换为可排序数值,解决了现有技术仅能处理单一类型序号、兼容性差的问题,无需人工干预即可适应公文、论文、手册等多场景文档的序号纠正需求;
Smart Images

Figure CN122242487B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of document processing technology, specifically to a method, system, device, and storage medium for automatically correcting document error serial numbers. Background Technology
[0002] In scenarios such as official document processing, academic paper formatting, and technical document organization, articles commonly use hierarchical numbering to present content in a structured manner. As a core identifier of the article's structure, the standardization of numbering directly affects the document's readability and rigor. However, in actual editing processes, due to human input errors, content additions and deletions, and collaborative editing by multiple people, errors such as skipped number levels, duplicate numbering, inconsistent number types, and chaotic multi-level numbering hierarchies are easily found in articles, severely damaging the document structure and reducing the reading experience.
[0003] To address the aforementioned issue of incorrect serial numbers, current methods primarily rely on manual line-by-line proofreading and correction, which is time-consuming, labor-intensive, and prone to omissions, especially for long documents. Some document editing software's automatic numbering function can only generate new serial numbers in an orderly manner, failing to identify and correct existing disordered serial numbers. While regular expression-based text processing tools can perform search and replace for single-type serial numbers, they are incompatible with diverse serial number formats such as Chinese numerals, letters, circled numbers, and multi-level numbers. More critically, existing solutions lack the ability to automatically identify serial number levels, failing to distinguish between first-level and second-level serial numbers. This makes it extremely easy for errors to occur in multi-level serial number disorder scenarios, resulting in corrections that are insufficient to meet practical needs.
[0004] In summary, existing technologies struggle to automatically identify, differentiate, and accurately correct various types of error sequences in documents without human intervention. Therefore, providing a highly compatible, accurate, and automated technical solution with stable correction results has become a pressing issue in the field of document processing. Summary of the Invention
[0005] The purpose of this invention is to provide a method, system, device, and storage medium for automatically correcting article error numbers. It achieves automatic correction of error numbers, ensures the standardization of document numbering, and improves article editing efficiency.
[0006] To achieve the above objectives, the present invention employs the following technical solution: On the one hand, the present invention provides a method for automatically correcting article error serial numbers, including the following steps: Step S1: Read the input document, split the document content into lines according to the newline character, and filter out blank lines to obtain valid content lines; Step S2: Traverse each valid content line, match the serial number prefix at the beginning of the line through a predefined regular expression, identify serial number lines and non-serial number lines, and extract the serial number prefix string; Step S3: Analyze the extracted serial number prefix string to determine the serial number type, and convert the serial number into a sortable numerical form; Step S4: According to the serial number type and the characteristics between adjacent serial numbers, distinguish first-level serial numbers and second-level serial numbers, and establish a hierarchical association relationship between the first-level serial numbers and the second-level serial numbers; Step S5: Based on the hierarchical association relationship, sort the first-level serial numbers and the second-level serial numbers respectively to generate a correct serial number sequence that is continuous and of the same type; Step S6: Recombine the correct serial number sequence with the corresponding document content and non-serial number lines in the original order, and output the corrected document, where the original content of the non-serial number lines remains its position and text unchanged.
[0007] Preferably, in step S1, if the number of valid content lines obtained after filtering empty lines is no more than 1, it is determined that no serial number correction is required, and the process ends directly.
[0008] Preferably, in step S2, the predefined regular expression is configured to be able to match the following serial number types at the beginning of the line through a single expression: Arabic numeral serial numbers, Chinese numeral serial numbers, letter serial numbers, circled numeral serial numbers, multi-level numeral serial numbers, bracketed serial numbers, and structured serial numbers containing the word "第" and any one of the suffixes "章", "节", "条"; The regular expression also captures the leading indentation whitespace and the subsequent separator of the serial number; The non-serial number line is specifically: If a line of content fails to match the predefined regular expression, then this line is marked as a non-serial number line.
[0009] Preferably, step S3 includes: According to a predetermined judgment rule, perform type judgment and numerical conversion on the captured serial number body, and the judgment rule includes: Judge the serial number type according to the captured serial number body. If it is a structured serial number containing the word "第" and the suffixes "章", "节", "条", then extract the internal numerical characters and mark the corresponding type; If it is a bracketed serial number, remove the brackets and extract the internal numbers or characters and mark the type; If it is a multi-level number, split it into a tuple of numbers according to the separator; If it is a pure Arabic numeral, pure Chinese numeral, pure letter or circled numeral, extract them respectively; By establishing a pre-defined mapping relationship between Chinese numerals and Arabic numerals, and between circled numerals and Arabic numerals, Chinese numerals and circled numerals are uniformly converted into Arabic numerals, letters are converted into numerical values in alphabetical order, and multi-level numbers are converted into numerical tuples, so that all identified serial numbers are converted into comparable numerical forms. When encountering a sequence number prefix whose type cannot be identified according to the judgment rules, a flag indicating an unknown type is returned, and a prompt message is output in subsequent processing and the current correction process is terminated.
[0010] Preferably, step S4 includes: Traverse all identified sequence number lines, and determine whether a sequence number is a first-level sequence number or a second-level sequence number based on the length of the indentation blank at the beginning of the line, the sequence number type, and the type relationship between adjacent sequence numbers. Assign a first-level sequence number to each second-level sequence number and record the hierarchical relationship. The method for determining whether a serial number is a first-level serial number or a second-level serial number includes: when the indentation length of a certain serial number is greater than the indentation length of the previous serial number, and the serial number type of that row belongs to the sub-serial number part of parenthesized serial numbers or multi-level numbers, the serial number of that row is determined to be the second-level serial number to which the serial number of the previous row belongs.
[0011] Preferably, step S5 includes: Sort all first-level serial numbers in ascending order according to their corresponding numerical forms, and regenerate consecutive first-level serial numbers. For each primary sequence number, all its subordinate secondary sequence numbers are sorted in ascending order according to their respective numerical forms, and consecutive secondary sequence numbers are regenerated. When generating the correct sequence number, ensure that all first-level sequence numbers have the same type, and that second-level sequence numbers within the same level have the same type.
[0012] On the other hand, the present invention also provides an automatic error number correction system for articles, used to implement the above-described automatic error number correction method for articles, including: The document reading module reads the input document, splits the document content into lines according to newline characters, and filters out blank lines to obtain valid content lines. The sequence number recognition module is used to traverse each valid content line, match the sequence number prefix at the beginning of the line using a predefined regular expression, identify the sequence number line and the non-sequence number line, and extract the sequence number prefix string; The serial number parsing module is used to parse the extracted serial number prefix string, determine the serial number type, and convert the serial number into a sortable numerical form; The hierarchy differentiation module distinguishes between first-level and second-level serial numbers based on the serial number type and the characteristics between adjacent serial numbers, and establishes a hierarchical relationship between first-level and second-level serial numbers. The sorting correction module sorts the first-level and second-level serial numbers based on hierarchical relationships, generating a continuous and uniform sequence of correct serial numbers. The document reorganization module reassembles the correct sequence number, the corresponding document content, and the non-sequence lines in the original order, and outputs the corrected document.
[0013] On the other hand, the present invention also provides an automatic error number correction device for articles, comprising: Memory is used to store non-transitory computer-readable instructions; And a processor for executing the computer-readable instructions such that when the computer-readable instructions are executed by the processor, the above-described method for automatically correcting article error numbers is implemented.
[0014] On the other hand, the present invention also provides a storage medium for storing non-transitory computer-readable instructions, which, when executed by a computer, cause the computer to perform the above-described method for automatically correcting article error serial numbers.
[0015] Compared with the prior art, the beneficial effects of the present invention are as follows: 1. This invention achieves automatic recognition of multiple serial number types through predefined regular expressions, and uses mapping relationships to uniformly convert Chinese numerals, circled numerals, etc. into sortable numerical values. This solves the problem that existing technologies can only handle a single type of serial number and have poor compatibility. It can adapt to the serial number correction needs of documents such as official documents, papers, and manuals in multiple scenarios without manual intervention. 2. This invention automatically distinguishes between first-level and second-level serial numbers and establishes hierarchical relationships. Based on the hierarchical relationships, it sorts the serial numbers at each level to generate a continuous and uniform correct sequence, which makes up for the lack of hierarchical recognition capability in existing solutions and effectively solves the problem of hierarchical misalignment after multi-level serial number confusion correction. 3. This invention reassembles the correct serial numbers and content in the original order while keeping the non-serial numbered rows unchanged, ensuring the integrity and rigor of the corrected document structure. It also has identification prompts for unknown serial number types and an abnormal termination mechanism, balancing the correction effect with system stability. It is easy to operate and suitable for batch document processing. Attached Figure Description
[0016] Figure 1 This is a flowchart of the method of the present invention; Figure 2 This is a schematic diagram of the system structure of the present invention. Detailed Implementation
[0017] The present invention will be further illustrated below with reference to specific embodiments. It should be understood that these embodiments are for illustrative purposes only and are not intended to limit the scope of the invention. Furthermore, it should be understood that after reading the teachings of this invention, those skilled in the art can make various alterations or modifications to the invention, and these equivalent forms also fall within the scope defined in this application.
[0018] In this invention, terms such as "upper," "lower," "left," "right," "front," "back," "vertical," "horizontal," "side," and "bottom" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. These terms are used only to facilitate the description of the structural relationships of the various components or elements of this invention and do not specifically refer to any component or element in this invention. They should not be construed as limiting the invention.
[0019] Example 1: like Figure 1 As shown, this embodiment provides a method for automatically correcting article error serial numbers. This method can be implemented using the Python programming language and relies on technologies such as regular expressions, string processing, and sorting algorithms to complete the serial number correction. Specifically, it includes the following steps: Step S1: Read the input document, split the document content into lines according to the newline character, and filter out blank lines to obtain valid content lines; Step S2: Traverse each valid content line, match the sequence number prefix at the beginning of the line using a predefined regular expression, identify the numbered lines and non-numbered lines, and extract the sequence number prefix string; Step S3: Parse the extracted serial number prefix string, determine the serial number type, and convert the serial number into a sortable numerical form; Step S4: Based on the serial number type and the characteristics between adjacent serial numbers, distinguish between primary serial numbers and secondary serial numbers, and establish a hierarchical relationship between primary serial numbers and secondary serial numbers; Step S5: Based on the hierarchical relationship, sort the first-level serial numbers and second-level serial numbers respectively to generate a continuous and consistent correct serial number sequence; Step S6: Reassemble the correct sequence number, the corresponding document content, and the non-sequence lines in the original order, and output the corrected document. The original content of the non-sequence lines retains its position and text unchanged.
[0020] The steps described above are explained in detail below.
[0021] Step S1 is as follows: Read the content of the input document. The input document is in plain text format. First, use the file reading function to open the input file in read-only mode and read the complete text content of the document. Then, split the document content into lines by line breaks, and each line is used as an independent processing unit. Traverse all lines, filter out the lines with blank content, count and retain the valid content lines, and judge the number of valid content lines. If the number of valid content lines is not greater than 1, it means that the document content is too short, there is no serial number structure or no need to correct the serial number, and the process is directly ended without subsequent processing steps. If the number of valid content lines is greater than 1, then continue to execute the subsequent step S2.
[0022] Step S2 is specifically as follows: Pre-define a regular expression, which is configured to be able to match multiple types of serial numbers at the beginning of a line through a single expression. The covered serial number types include: Arabic numeral serial numbers, such as "1", "2", "10"; Chinese numeral serial numbers, such as "one", "two", "ten"; Letter serial numbers, such as "A", "B", "a", "b"; Circled numeral serial numbers, such as "①", "②", "③"; Multi-level numeral serial numbers, such as "1.1", "2.1.3"; Parenthesized serial numbers, such as "(1)", "(2)", "[3]", "【4】"; And structured serial numbers containing the character "第" and any one of the suffixes "章", "节", "条", such as "第一章", "第2节", "第三条"; This regular expression also captures the indentation whitespace at the beginning of the line and the delimiters following the serial number. The subsequent delimiters include ".", "、", ":", ",", "是", ")", "]", "】" and spaces, etc.; As a specific implementation, this regular expression can adopt the following form: "^(\s*)([\(\(\[]?)(\d+\.\d+|[0-9]+|[一二三四五六七八九十]+|[A-Z]+|[a-z]+|[①②③④⑤⑥⑦⑧⑨⑩]+|第([一二三四五六七八九十百千万零]+|\d+)|第([一二三四五六七八九十百千万零]+|\d+)([章节条]))([\.、::,,是\)\)\]\s])"; In the above regular expression: "^(\s*)": Matches the whitespace characters at the beginning of the line, captures the indentation information, and is used for subsequent hierarchical judgment; "([\(\(\[]?)": Matches an optional left parenthesis, including the Chinese full-width parentheses "(", "【" and the English half-width parentheses "(","["; "(\d+\.\d+|[0-9]+|[一二三四五六七八九十]+|[A-Z]+|[a-z]+|[①②③④⑤⑥⑦⑧⑨⑩]+|第([一二三四五六七八九十百千万零]+|\d+)|第([一二三四五六七八九十百千万零]+|\d+)([章节条]))": Captures the main body of the serial number, and matches multi-level numbers (such as 1.1), pure Arabic numerals, pure Chinese numerals, capital letters, lowercase letters, circled numbers, the form of "第X" (Chinese numerals or Arabic numerals), and the form of "第X章 / 节 / 条" in turn in the form of alternative branches; "([\.、::,,是\)\)\]\s])": Matches common delimiters or words following the serial number; Traverse each valid content line obtained in step S1, apply this regular expression to each line of content for matching. If the match is successful, mark this line as a serial number line, and extract the serial number prefix string as the object for subsequent parsing; at the same time, record the remaining content part after removing the serial number prefix in this line. If a line of content fails to match the predefined regular expression, mark this line as a non-serial number line, and its complete original content will remain in place and unchanged in the subsequent reorganization step; After processing all lines, obtain a list of serial number lines and a set of non-serial number line information for parsing in subsequent step S3.
[0023] Step S3 is specifically as follows: For each serial number prefix string extracted in step S2, call the serial number parsing function to parse it, determine the specific type of the serial number, and convert the serial number into a sortable numerical form. The parsing process includes the following sub-steps: First, judge the type of the serial number prefix string. The basis and order of judgment are as follows: (1)If the serial number prefix contains the character "第" and ends with one of "章", "节", "条", it is determined as a structured serial number, divided into "第X章", "第X节" or "第X条". Further extract the internal numerical characters between "第" and the suffix, judge whether the internal number is a Chinese numeral or an Arabic numeral, and record its corresponding type mark; (2)If the serial number prefix starts with a left parenthesis (including the Chinese full-width parentheses "(", "【" and the English half-width parentheses "(","["), then take the corresponding right parenthesis as the boundary, remove the parentheses and extract the internal numerical or character content, and determine it as a parenthesized serial number, and record the type mark; (3) If the serial number prefix contains one or more digit separators ".", and each segment is an Arabic numeral, it is determined as a multi-level digital serial number. The serial number is split into multiple digits according to the "." separator to form a digital tuple. For example, "1.1" is split into the tuple (1, 1), and "2.1.3" is split into the tuple (2, 1, 3), and the type flag is recorded; (4) If the serial number prefix consists only of pure Arabic numeral characters, it is determined as a pure Arabic numeral serial number; (5) If the serial number prefix consists only of Chinese numeral characters (such as "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", etc.), it is determined as a pure Chinese numeral serial number; (6) If the serial number prefix consists only of capital letter characters or only of lowercase letter characters, it is determined as an alphabetic serial number; (7) If the serial number prefix is a circled digit character (such as "①", "②", "③", etc.), it is determined as a circled digit serial number; (8) If none of the above items are satisfied, it is determined as an unknown type; After the above type determination, a numerical conversion operation is performed: A mapping relation table between Chinese numerals and Arabic numerals is established in advance. This mapping relation table contains the following corresponding relations: "one" corresponds to 1, "two" corresponds to 2, "three" corresponds to 3, "four" corresponds to 4, "five" corresponds to 5, "six" corresponds to 6, "seven" corresponds to 7, "eight" corresponds to 8, "nine" corresponds to 9, "ten" corresponds to 10, "hundred" corresponds to 100, "thousand" corresponds to 1000, "ten thousand" corresponds to 10000, "zero" corresponds to 0; At the same time, a mapping relation table between circled digits and Arabic numerals is established in advance, including: "①" corresponds to 1, "②" corresponds to 2, "③" corresponds to 3, "④" corresponds to 4, "⑤" corresponds to 5, "⑥" corresponds to 6, "⑦" corresponds to 7, "⑧" corresponds to 8, "⑨" corresponds to 9, "⑩" corresponds to 10; For Chinese numerals, according to the above mapping relations, the Chinese characters are converted into the corresponding Arabic numerals; for the two-digit cases starting with "ten", if it is "ten" followed by a single-digit number, it is converted into the value of 10 plus the single-digit number; if it is a number followed by "ten", it is converted into the value of that number multiplied by 10; if it is "hundred", "thousand", "ten thousand", etc., the corresponding place value is accumulated and calculated, and finally converted into a single Arabic numeral; for circled digits, directly look up through the mapping relation table and convert them into the corresponding Arabic numerals; for alphabetic serial numbers, the letters are converted into the corresponding serial number values according to the alphabetical order. Capital letter "A" corresponds to 1, "B" corresponds to 2, and so on; lowercase letter "a" corresponds to 1, "b" corresponds to 2, and so on; for multi-level digital serial numbers, after splitting it into each segment of digits according to ".", a numerical tuple is formed; for pure Arabic numeral serial numbers, directly extract its integer value; Through the above transformation, all identified serial numbers are converted into a uniform, comparable numerical form; During the parsing process, when a serial number prefix whose type cannot be identified according to the above judgment rules is encountered, a flag indicating an unknown type is returned. At the same time, a prompt message containing the information of the unknown serial number is output to the user in subsequent processing, and the current correction process is terminated to avoid erroneous output due to unrecognizable serial numbers.
[0024] Step S4 is as follows: Traverse all the numbered rows identified in step S2, and determine whether the number is a first-level number or a second-level number based on the length of the indentation blank at the beginning of the line, the number type, and the type relationship between adjacent numbers, and establish the hierarchical relationship between the first-level number and the second-level number. The identified rows are processed sequentially according to their order of appearance in the document: First, examine the length of the initial indentation space. The indentation space length is determined by the "(\s*)" part captured by the regular expression in step S2. The length of this string is calculated as the indentation depth value. If the indentation depth of the current number line is zero or equal to the minimum indentation depth used by most number lines in the document, it is initially determined that the number has the tendency to be a first-level number. If the indentation depth of the current number line is significantly greater than the indentation depth of the previous line number, and the number type of the line number belongs to the sub-number part of parenthesized numbers or multi-level numbers (i.e., the characteristics of multi-level numbers excluding the first paragraph), then the line number is determined to be a second-level number to which the previous line number belongs. Regarding type association, the following rules are also considered: If the previous line number is a first-level number (such as "1.") and the current line number is a number with parentheses (such as "(1)"), even if the indentation depth is the same, according to the convention that numbers with parentheses usually appear as second-level numbers, the current line is determined to be the second-level number of the previous line number. For multi-level numbers, if the form "1.1" appears and its previous line is "1.", then "1.1" is determined to be the second-level number of "1.". For each row that is determined to be a second-level sequence number, record its first-level sequence number identifier, establish a hierarchical relationship, and store all sequence numbers and their hierarchical information, belonging relationship, original number, numerical form, row number, etc. in the data structure for use in step S5.
[0025] Step S5 is as follows: Based on the hierarchical relationship established in step S4, the first-level serial numbers and second-level serial numbers are sorted respectively to generate a continuous and consistent sequence of correct serial numbers: Extract all rows identified as first-level serial numbers and sort them in ascending order according to their corresponding numerical forms. The comparison of numerical forms follows the usual numerical comparison rules. After sorting, generate a new consecutive first-level serial number for each first-level serial number in the sorted order. That is, the first first-level serial number after sorting is numbered 1, the second is numbered 2, and so on, ensuring that all first-level serial numbers are numerically consecutive without skipping levels. While renumbering the first-level serial numbers, determine the uniform type of the first-level serial numbers. Prioritize the first-level serial number type that appears most frequently in the original document as the uniform type. For example, if the original first-level serial numbers are mostly Arabic numerals in the form of "1." with a suffix period, then uniformly adopt this form to generate new first-level serial numbers. For each first-level sequence number, extract all its subordinate second-level sequence numbers and arrange them in ascending order according to their respective numerical forms. If the value corresponding to a certain second-level sequence number is a single numeric value, then arrange them in ascending order according to that value. If it is a multi-level numeric tuple, then arrange them according to the multi-level comparison rules of the tuple. After sorting, regenerate consecutive second-level sequence number numbers for all second-level sequence numbers under the first-level sequence number, that is, starting from 1 and increasing sequentially. At the same time, the second-level sequence numbers within the same level should maintain a unified type. Prioritize the use of the second-level sequence number type with the highest original occurrence rate under this level as the unified type. For example, if the second-level sequence numbers under a certain level are mostly parenthesized sequence numbers in the form of "(1)", then uniformly use this form to generate new second-level sequence numbers. After completing the above renumbering, assign a new correct sequence number string to each sequence number row, replacing its original sequence number prefix, to form a correct sequence number sequence.
[0026] Step S6 is as follows: Reassemble the correct sequence number generated in step S5 with the corresponding document content and the non-sequence numbered lines marked in step S2 according to the original document's chronological order: Maintain a reconstructed content sequence. Traverse each line of the original document after it is split by a newline character. If the line is the numbered line marked in step S2, take out the corresponding new number from the correct numbered sequence generated in step S5 in order. Concatenate the new number with the remaining content of the line after removing the number prefix as recorded in step S2 to form the corrected content line. Place it in the reconstructed content sequence in its original position. If the line is not a numbered line, put its original complete content directly into the corresponding position in the reconstructed content sequence, keeping its text content and relative position unchanged. After the reorganization is complete, the entire reorganized content sequence is concatenated line by line into a complete text and written to the specified output file. UTF-8 encoding is used during writing to ensure the correct display of Chinese characters and other characters. At the same time, the running time of the entire method can be counted, and feedback on the completion status of sequence number correction can be given to the user.
[0027] Example 2: like Figure 2 As shown in the figure, this embodiment provides an automatic correction system for article error serial numbers, which is used to implement the automatic correction method for article error serial numbers described in Embodiment 1. This system adopts a modular architecture design and includes a document reading module, a serial number recognition module, a serial number parsing module, a hierarchy differentiation module, a sorting and correction module, and a document recombination module.
[0028] The document reading module is used to read the input document, split the document content into lines according to the line break character, and filter out the blank lines to obtain the valid content lines. The document reading module first obtains the path of the input file, opens the file in read-only mode and reads all the text content. Subsequently, it calls the string splitting function to split the text into a list of lines according to the line break character, traverses the list of lines, filters out the lines whose content is an empty string or only contains whitespace characters, and retains the valid content lines. The document reading module is also responsible for judging the number of valid content lines. If the number of lines is not greater than 1, it returns an empty result or a termination signal to the main control program to end the entire correction process.
[0029] The serial number recognition module is used to traverse each valid content line output by the document reading module, match the serial number prefix at the beginning of the line through a predefined regular expression, identify the serial number lines and non-serial number lines, and extract the serial number prefix string. In the serial number recognition module, there is a pre-set regular expression that can match multiple serial number types through a single expression. The serial number types covered by this regular expression include Arabic numeral serial numbers, Chinese numeral serial numbers, letter serial numbers, circled numeral serial numbers, multi-level numeral serial numbers, bracketed serial numbers, and structured serial numbers containing the suffix of "Chapter", "Section", or "Article" after the word "Article". The specific form of the regular expression is the same as that described in step S2 of Embodiment 1. The serial number recognition module performs regular matching operations on each line. If the match is successful, it records the serial number line information. If the match fails, it records the non-serial number line information. Finally, it outputs a list of serial number lines and a set of non-serial number line information.
[0030] The serial number parsing module is used to parse the serial number prefix string output by the serial number recognition module, determine the serial number type, and convert the serial number into a sortable numerical form. In the serial number parsing module, there are pre-set mapping relation tables of Chinese numerals to Arabic numerals and of circled numerals to Arabic numerals. The Chinese numeral mapping relation table contains entries such as "one" corresponding to 1, "two" corresponding to 2, "three" corresponding to 3, "four" corresponding to 4, "five" corresponding to 5, "six" corresponding to 6, "seven" corresponding to 7, "eight" corresponding to 8, "nine" corresponding to 9, "ten" corresponding to 10, "hundred" corresponding to 100, "thousand" corresponding to 1000, "ten thousand" corresponding to 10000, "zero" corresponding to 0, etc. The circled numeral mapping relation table contains entries such as "①" corresponding to 1, "②" corresponding to 2, "③" corresponding to 3, "④" corresponding to 4, "⑤" corresponding to 5, "⑥" corresponding to 6, "⑦" corresponding to 7, "⑧" corresponding to 8, "⑨" corresponding to 9, "⑩" corresponding to 10, etc. The serial number parsing module judges the serial number type according to the predetermined rules, including judging whether it is a structured serial number, whether it is a bracketed serial number, whether it is a multi-level digital serial number, whether it is a pure Arabic numeral, pure Chinese numeral, pure letter or circled numeral serial number, and performs numerical conversion according to the corresponding rules respectively. For the serial number prefix of an unrecognized type, the serial number parsing module outputs an unknown type mark, triggers the system to output a prompt message and terminates the correction process.
[0031] The level differentiation module is used to differentiate the first-level serial numbers and the second-level serial numbers according to the serial number type output by the serial number parsing module and the characteristics between adjacent serial numbers, and establish a hierarchical association relationship between the first-level serial numbers and the second-level serial numbers. The level differentiation module traverses all the recognized serial number lines, extracts the indentation blank length information of each serial number line, and performs level determination in combination with the serial number type and the type association characteristics between adjacent serial numbers. When the indentation blank length of a certain line of serial numbers is greater than the indentation blank length of the previous line of serial numbers, and the serial number type of this line belongs to the part of the bracketed serial number or the sub-serial number of the multi-level number, this line of serial numbers is determined as the second-level serial number belonging to the previous line of serial numbers; otherwise, it is determined as the first-level serial number. The level differentiation module records the identifier of the first-level serial number to which each second-level serial number belongs, and generates a complete hierarchical association relationship data structure.
[0032] The sorting and correction module is used to sort the first-level serial numbers and the second-level serial numbers respectively based on the hierarchical association relationship established by the level differentiation module, and generate a correct serial number sequence that is continuous and of the same type. The sorting and correction module sorts all the first-level serial numbers in ascending order according to their numerical forms and re-numbers them continuously, and determines the unified first-level serial number type; sorts the second-level serial numbers under each first-level serial number in ascending order according to their numerical forms and re-numbers them continuously, and determines the unified second-level serial number type; the sorting and correction module finally outputs the new serial number string corresponding to each serial number line.
[0033] The document reorganization module is used to reorganize the correct sequence number generated by the sorting correction module, the corresponding document content, and the non-sequence lines marked by the sequence number recognition module in the original order, and output the corrected document. The document reorganization module processes each line of the original document in turn. For the sequence lines, it obtains the new sequence number from the correct sequence number and concatenates it with the remaining part of the original content. For the non-sequence lines, it retains the original content unchanged. Finally, it generates the complete corrected document text and writes it to the output file.
[0034] The above is a detailed description of the preferred embodiments of the present invention, but the present invention is not limited to the embodiments described. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention, and these equivalent modifications or substitutions are all included within the scope defined by the claims of this application.
Claims
1. A method for automatically correcting article error serial numbers, characterized in that, It includes the following steps: Step S1: Read the input document, split the document content into lines by line breaks, and filter out blank lines to obtain valid content lines; Step S2: Traverse each valid content line, match the serial number prefix at the beginning of the line through a predefined regular expression, identify serial number lines and non-serial number lines, and extract the serial number prefix string; Step S3: Analyze the extracted serial number prefix string, determine the serial number type, and convert the serial number into a sortable numerical form; Step S4: According to the serial number type and the characteristics between adjacent serial numbers, distinguish first-level serial numbers and second-level serial numbers, and establish a hierarchical association relationship between the first-level serial numbers and the second-level serial numbers; Step S5: Based on the hierarchical association relationship, sort the first-level serial numbers and the second-level serial numbers respectively to generate a correct serial number sequence that is continuous and of the same type; Step S6: Recombine the correct serial number sequence with the corresponding document content and non-serial number lines in the original order, and output the corrected document, where the original content of the non-serial number lines remains unchanged in terms of its position and text; In Step S1, if the number of valid content lines obtained after filtering out blank lines is no more than 1, it is determined that no serial number correction is required, and the process ends directly; In Step S2, the predefined regular expression is configured to be able to match the following serial number types at the beginning of the line through a single expression: Arabic numeral serial numbers, Chinese numeral serial numbers, letter serial numbers, circled numeral serial numbers, multi-level numeral serial numbers, bracketed serial numbers, and structured serial numbers containing the character "第" and any one of the suffixes "章", "节", "条"; The regular expression also captures the leading indentation whitespace and the subsequent separator of the serial number; The non-serial number line is specifically: if the content of a line fails to match the predefined regular expression, then mark this line as a non-serial number line; Step S3 includes: Based on a predefined judgment rule, perform type determination and numerical conversion on the captured serial number body. The judgment rule includes: Judge the serial number type according to the captured serial number body. If it is a structured serial number containing the character "第" and the suffixes "章", "节", "条", then extract the internal numeric characters and mark the corresponding type; If it is a bracketed serial number, remove the brackets and extract the internal numbers or characters and mark the type; If it is a multi-level numeral, split it into a tuple of numbers according to the separator; If it is a pure Arabic numeral, pure Chinese numeral, pure letter, or circled numeral, extract them respectively; Through the pre-established mapping relationship between Chinese numerals and Arabic numerals and the mapping relationship between circled numerals and Arabic numerals, convert Chinese numerals and circled numerals into Arabic numerals uniformly, convert letters into numerical values in alphabetical order, and convert multi-level numerals into numerical tuples, so that all identified serial numbers are converted into comparable numerical forms; When encountering a serial number prefix that cannot be recognized as a type according to the judgment rule, return a mark indicating an unknown type, and output a prompt message and terminate the current correction process in subsequent processing; Step S4 includes: Traverse all identified sequence number lines, and determine whether a sequence number is a first-level sequence number or a second-level sequence number based on the length of the indentation blank at the beginning of the line, the sequence number type, and the type relationship between adjacent sequence numbers. Assign a first-level sequence number to each second-level sequence number and record the hierarchical relationship. The method of determining whether a serial number is a first-level serial number or a second-level serial number includes: when the indentation length of a certain serial number is greater than the indentation length of the previous serial number, and the serial number type of the certain serial number belongs to the sub-serial number part of parenthesized serial numbers or multi-level numbers, the serial number of the certain serial number is determined to be the second-level serial number to which the serial number of the previous serial number belongs. Step S5 includes: Sort all first-level serial numbers in ascending order according to their corresponding numerical forms, and regenerate consecutive first-level serial numbers. For each primary sequence number, all its subordinate secondary sequence numbers are sorted in ascending order according to their respective numerical forms, and consecutive secondary sequence numbers are regenerated. When generating the correct sequence number, ensure that all first-level sequence numbers have the same type, and that second-level sequence numbers within the same level have the same type.
2. An automatic error number correction system for articles, used to implement the automatic error number correction method for articles as described in claim 1, characterized in that, include: The document reading module reads the input document, splits the document content into lines according to newline characters, and filters out blank lines to obtain valid content lines. The sequence number recognition module is used to traverse each valid content line, match the sequence number prefix at the beginning of the line using a predefined regular expression, identify the sequence number line and the non-sequence number line, and extract the sequence number prefix string; The serial number parsing module is used to parse the extracted serial number prefix string, determine the serial number type, and convert the serial number into a sortable numerical form; The hierarchy differentiation module distinguishes between first-level and second-level serial numbers based on the serial number type and the characteristics between adjacent serial numbers, and establishes a hierarchical relationship between first-level and second-level serial numbers. The sorting correction module sorts the first-level and second-level serial numbers based on hierarchical relationships, generating a continuous and uniform sequence of correct serial numbers. The document reorganization module reassembles the correct sequence number, the corresponding document content, and the non-sequence lines in the original order, and outputs the corrected document.
3. An automatic error number correction device for articles, characterized in that, include: Memory is used to store non-transitory computer-readable instructions; And a processor for executing the computer-readable instructions such that when the computer-readable instructions are executed by the processor, they implement the automatic correction method for article error serial numbers according to claim 1.
4. A storage medium, characterized in that, Used to store non-transitory computer-readable instructions, which, when executed by a computer, cause the computer to perform the automatic correction method for article error serial numbers as described in claim 1.
Citation Information
Patent Citations
Document chapter structure identification method, device, equipment and storage medium
CN110427884A
Directory generation method and device
CN112069126A