Method and system for correcting abnormal line feed of Chinese corpus

By correcting symbols and line breaks in Chinese corpus, identifying and processing different types of paragraph line breaks, the problem of abnormal line breaks is solved, and the readability of the corpus is improved and the retention of semantic structure is improved.

CN118586378APending Publication Date: 2024-09-03ROCK AI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410300933.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-15
Publication Date
2024-09-03

AI Technical Summary

Technical Problem

Abnormal line breaks often occur in Chinese corpus, which affects the recognition of sentence boundaries by text processing algorithms, thereby affecting the accuracy and efficiency of natural language processing tasks.

Method used

By obtaining the Chinese corpus, we perform symbol check and line break correction, cut it into a paragraph list, and perform different processing according to the category of paragraph sub-items, including the identification and splicing of normal paragraphs, regular titles and abnormal title line breaks, and finally eliminate redundant symbols to Get correction results.

Benefits of technology

It effectively solves the problem of abnormal line breaks, improves the readability of Chinese corpus and retains the semantic structure, and avoids misjudgment of normal line breaks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118586378A
    Figure CN118586378A
Patent Text Reader

Abstract

The invention discloses a method and a system for correcting abnormal line feed of Chinese corpora. By judging whether the arrangement of the line feed positions is correct or not, the problem that a large number of illegal line feeds appear in the long Chinese corpus is solved, and the readability of the Chinese corpus is improved; normal line feed, title line feed, abnormal title line feed and other strategies are screened layer by layer through multiple groups of strategies, the semantic structure of the Chinese corpus is reserved, and misjudgment of normal line feed is avoided to the maximum extent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and system for correcting abnormal line breaks in Chinese corpus. Background Art

[0002] In the field of natural language processing and text mining, the quality of Chinese corpus directly affects the accuracy and efficiency of subsequent tasks such as information extraction, text analysis, machine translation, and sentiment analysis. However, in the actual process of collecting and organizing Chinese corpus, a problem often encountered is the phenomenon of abnormal line breaks. Abnormal line breaks refer to the situation in which sentences are forcibly divided into two or more lines where they should not be broken due to various reasons (such as format conversion, manual input errors, original document format restrictions, etc.) during the writing, typesetting or digitization process of text, which seriously affects the coherence and semantic integrity of the sentence.

[0003] For example, in Chinese corpora from various sources such as web crawled web pages, e-books, historical archives, and social media data, there are often abnormal line breaks due to page layout, word count limits, etc. These abnormal line breaks may cause text processing algorithms to fail to correctly identify sentence boundaries, thus affecting the results of advanced natural language processing tasks such as syntactic analysis and paragraph comprehension. Therefore, it is very necessary to correct the abnormal line breaks in the Chinese corpus. Summary of the invention

[0004] The present invention provides a method and system for correcting abnormal line breaks in Chinese corpus, so as to solve the problem that a large number of illegal line breaks appear in Chinese corpus.

[0005] In a first aspect, a method for correcting abnormal line breaks in Chinese corpus specifically comprises the following steps:

[0006] Step S1: obtaining Chinese corpus and checking and correcting symbols of the Chinese corpus;

[0007] Step S2: correcting the line break of the Chinese corpus after the symbol check and correction to obtain corpus T;

[0008] Step S3: Using line breaks as cutting points, the corpus T is segmented to obtain a paragraph list T1;

[0009] Step S4: traverse the paragraph list T1 to obtain each paragraph sub-item T2 in the paragraph list T1;

[0010] Step S5: define a variable T0 for concatenating each paragraph sub-item to generate a complete corpus;

[0011] Step S6: starting from the second paragraph sub-item, determine the category of each paragraph sub-item T2 in turn, and perform different operations according to the category of each paragraph sub-item T2;

[0012] Step S7: Determine whether the current paragraph sub-item T2 is a normal paragraph line break. If it is a normal paragraph line break, concatenate it in the form of T0+line break+T2. Otherwise, proceed to step S8;

[0013] Step S8: Determine whether the current paragraph sub-item T2 is a regular title line break. If it is a regular title line break, concatenate it in the form of T0+line break+T2. Otherwise, go to step S9;

[0014] Step S9: Determine whether the current paragraph sub-item T2 is an unconventional title line break. If it is an unconventional title line break, concatenate it in the form of T0+line break+T2. Otherwise, concatenate the current paragraph sub-item T2 in the form of T0+T2.

[0015] Step S10: after performing corresponding operations on the current paragraph sub-item T2 according to its category, determine whether the current paragraph sub-item T2 is the last paragraph sub-item. If not, jump the next paragraph sub-item T2 to step S7. If yes, proceed to step S11.

[0016] Step S11: remove the leading space and line break in the variable T0 obtained through the above steps to obtain the final correction result T3.

[0017] Preferably, the checking and correction of symbols of the Chinese corpus in step S1 specifically includes replacing English symbols including ".", "?", "!", and ";" with corresponding Chinese symbols ".", "?", "!", and ";".

[0018] Preferably, the step S2 of correcting the line breaks of the Chinese corpus after the symbol check and correction specifically includes replacing multiple consecutive line breaks in the Chinese corpus with a single line break according to the language characteristics of Chinese.

[0019] Preferably, the corpus paragraph segmentation in step S3 is performed in the form of line breaks, which is implemented by Python's split function to obtain T1 = [T2, T2, T2, ...];

[0020] More preferably, the line break is generally located at the beginning of a paragraph of text.

[0021] Preferably, in step S5, the corpus formed by concatenating the variable T0 with the line break character and each paragraph sub-item T2 is still defined as the variable T0.

[0022] Preferably, in step S7, it is determined whether the current paragraph sub-item T2 is a normal paragraph line break by checking the ending content of the previous paragraph sub-item.

[0023] Preferably, in step S8, it is determined whether the current paragraph sub-item T2 is a normal title line break by judging whether the previous sentence is in a common title format;

[0024] More preferably, regular matching is used to judge whether the previous sentence is in a common title format; among them, the common title formats specifically include the following:

[0025] (1) Chapter [\d+一二三四五六七八九十]{1,3};

[0026] (2) Section [\d+一二三四五六七八九十]{1,3};

[0027] (3) Article [\d+一二三四五六七八九十]{1,3};

[0028] (4) [一二三四五六七八九十]{1,3}、;

[0029] (5) [((]+[一二三四五六七八九十]+[一二三四五六七八九]?[))];

[0030] (6) \d+[、.].

[0031] Preferably, in step S9, it is determined whether the current paragraph sub-item T2 is an unconventional title line break by calculating the value of the length of the previous paragraph sub-item T2 / the length of the current paragraph sub-item. When the value of the length of the previous paragraph sub-item T2 / the length of the current paragraph sub-item is less than 20%, it is considered that the current paragraph sub-item T2 is an unconventional title, otherwise, it is an abnormal line break.

[0032] Preferably, in step S11, the spaces and line breaks at the beginning of the variable T0 are removed by using the strip function provided by Python.

[0033] In a second aspect, the present invention also provides a system for correcting abnormal line breaks in Chinese corpora, specifically including:

[0034] A symbol correction module for maintaining the uniformity of the format in the Chinese corpus;

[0035] A line break symbol correction module for replacing multiple consecutive line breaks in the Chinese corpus with a single line break;

[0036] A corpus paragraph cutting module for cutting the corrected Chinese corpus into multiple paragraph sub-items T2 with line breaks as the cutting points, and defining a variable T0 for splicing each paragraph sub-item;

[0037] A line break classification module is used to classify each paragraph sub-item T2;

[0038] A line break processing module, used for processing line breaks in each paragraph sub-item T2 accordingly according to the classification;

[0039] The redundant symbol correction module is used to remove redundant symbols in the Chinese corpus after the abnormal line break correction.

[0040] Preferably, the symbol correction module checks the punctuation marks in the Chinese corpus and replaces the English symbols including ".", "?", "!", and ";" with the corresponding Chinese symbols ".", "?", "!", and ";".

[0041] Preferably, the line break classification module classifies each paragraph sub-item T2 into four categories: normal paragraph line break, regular title line break, abnormal line break and irregular title line break.

[0042] Preferably, the line break processing module specifically includes the following submodules:

[0043] The normal paragraph line break processing submodule splices the paragraph sub-item T2 of the normal paragraph line break in the form of T0+line break+T2;

[0044] The regular title line break processing submodule splices the paragraph sub-item T2 of the regular title line break in the form of T0+line break+T2;

[0045] The abnormal line break processing submodule splices the paragraph sub-item T2 with abnormal line breaks in the form of T0+T2;

[0046] The submodule for processing the irregular title line breaks concatenates the paragraph sub-item T2 of the irregular title line breaks in the form of T0+T2.

[0047] Preferably, the redundant symbol correction module removes redundant line breaks and leading spaces in the variable T0 obtained finally.

[0048] Compared with the prior art, the present invention has the following obvious outstanding substantial features and significant advantages:

[0049] The present invention not only solves the problem of a large number of illegal line breaks in long Chinese corpora by judging whether the setting of the line break position is correct, thereby improving the readability of the Chinese corpora; it also retains the semantic structure of the Chinese corpora by screening normal line breaks, title line breaks, and abnormal title line breaks through multiple sets of strategies, thereby avoiding misjudgment of normal line breaks to the greatest extent. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] The accompanying drawings, which constitute part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention. In the accompanying drawings:

[0051] Figure 1 It is a flow chart of a method for correcting abnormal line breaks in Chinese corpus according to a preferred embodiment of the present invention.

[0052] Figure 2 It is a schematic diagram of a system for correcting abnormal line breaks in Chinese corpus according to a preferred embodiment of the present invention.

[0053] Figure 3 It is a structural schematic diagram of a line break processing module in a system for correcting abnormal line breaks in Chinese corpus in a preferred embodiment of the present invention. DETAILED DESCRIPTION

[0054] The present invention provides a method for correcting abnormal line breaks in Chinese corpus. In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0055] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0056] Embodiment 1:

[0057] like Figure 1 As shown, a method for correcting abnormal line breaks in Chinese corpus specifically includes the following steps:

[0058] Step S1: Acquire Chinese corpus and check and correct the symbols of the Chinese corpus, and replace the English symbols including ".", "?", "!", and ";" with the corresponding Chinese symbols ".", "?", "!", and ";".

[0059] Step S2: correcting the line breaks of the Chinese corpus after symbol checking and correction; according to the language characteristics of Chinese, replacing multiple consecutive line breaks in the Chinese corpus with a single line break to obtain Chinese corpus T.

[0060] Step S3: Split the Chinese corpus T in the form of line breaks, using Python's split() function.

[0061] Step S4: traverse the paragraph list T1 to obtain each paragraph sub-item T2 of the paragraph list T1, where T1 is recorded as [T2, T2, T2, …].

[0062] Step S5: define a variable T0 for concatenating each paragraph sub-item. The corpus formed by concatenating the variable T0 with the line break and each paragraph sub-item T2 is still defined as the variable T0. T0 is used to generate a complete corpus.

[0063] Step S6: Starting from the second paragraph sub-item, determine the category of each paragraph sub-item T2 in turn, and perform different operations according to the category to which each paragraph sub-item T2 belongs; wherein the categories include: normal paragraph line break, regular title line break, abnormal line break and abnormal title line break.

[0064] Normal line break, for example: Should retired people have a dinner at noon? \nAn American health expert said: Scientists' latest research found that one of the causes of many diseases is bad eating habits at night. But for office workers, dinner is a headache...

[0065] Regular title line breaks, for example: 1. Scope of compensation\nReasonable outpatient / inpatient medical expenses (including Class B drugs) of Shanghai's Level II and above public hospitals, excluding items listed as "not within the scope of medical insurance reimbursement" (self-paid part will not be compensated).

[0066] Abnormal line break, for example: Today is a\nhappy day.

[0067] Unconventional title line breaks, for example: Wandering in Youth\nTo narrate my story, I have to go back to my distant past. If possible, I really want to go back further, to the earliest years of my childhood, and then to the life of my distant ancestors.

[0068] Step S7: By checking the ending content of the previous paragraph sub-item, determine whether the current paragraph sub-item T2 is a normal paragraph line break. If it is a normal paragraph line break, it will be spliced ​​in the form of T0+line break+T2. Otherwise, go to step S8.

[0069] Step S8: By judging whether the previous sentence is a common title format, determine whether the current paragraph sub-item T2 is a regular title line break. If it is a regular title line break, it is spliced ​​in the form of T0+line break+T2. Otherwise, go to step S9; wherein the format of the regular title specifically includes the following:

[0070] (1) Chapter [one, two, three, four, five, six, seven, eight, nine, ten]{1,3};

[0071] (2) Section [one, two, three, four, five, six, seven, eight, nine, ten]{1,3};

[0072] (3) Article [one, two, three, four, five, six, seven, eight, nine, ten]{1,3};

[0073] (4) [one, two, three, four, five, six, seven, eight, nine, ten]{1,3};

[0074] (5) [((]+[one, two, three, four, five, six, seven, eight, nine, ten]+[one, two, three, four, five, six, seven, eight, nine]?[))];

[0075] (6) \d+[.,].

[0076] Step S9: Determine whether the current paragraph sub-item T2 is an unconventional title line break. By calculating the value of the length of the previous paragraph sub-item T2 / the length of the current paragraph sub-item, if the value of the length of the previous paragraph sub-item T2 / the length of the current paragraph sub-item is less than 20%, it is considered that the current paragraph sub-item T2 is an unconventional title, and it will be concatenated in the form of T0 + line break + T2. Otherwise, it is considered that the current paragraph sub-item T2 is an abnormal line break, and the current paragraph sub-item T2 will be concatenated in the form of T0 + T2.

[0077] Step S10: After performing the corresponding operations on the current paragraph sub-item T2 according to its category, determine whether the current paragraph sub-item T2 is the last paragraph sub-item. If not, jump the next paragraph sub-item T2 to Step S7. If so, enter Step S11.

[0078] Step S11: Remove the leading space and line break of the variable T0 obtained in the above steps through the strip function provided by Python to obtain the final corrected result T3.

[0079] Embodiment 2:

[0080] As Figure 2 、 Figure 3 shown, a system for correcting abnormal line breaks in Chinese corpora specifically includes:

[0081] Symbol correction module, which checks the punctuation marks in the Chinese corpus and replaces the English symbols including ".", "?", "!", ";" with the corresponding Chinese symbols "。", "?", "!", ";" respectively.

[0082] Line break symbol correction module, which replaces multiple consecutive line breaks in the Chinese corpus with a single line break.

[0083] The corpus paragraph cutting module cuts the Chinese corpus in the form of line breaks, cuts the Chinese corpus into multiple paragraph sub-items T2, and defines a variable T0 for splicing each paragraph sub-item.

[0084] The line break classification module divides each paragraph sub-item T2 into four categories: normal paragraph line break, regular title line break, abnormal paragraph line break and irregular title line break.

[0085] The line break processing module is used to correct the abnormal line breaks in each paragraph sub-item T2; wherein the line break processing module specifically includes the following sub-modules:

[0086] The normal paragraph line break processing submodule concatenates the paragraph sub-item T2 of the normal paragraph line break in the form of T0+line break+T2.

[0087] The regular title line break processing submodule splices the paragraph sub-item T2 of the regular title line break in the form of T0+line break+T2.

[0088] The abnormal paragraph line break processing submodule splices the paragraph sub-item T2 of the abnormal paragraph line break in the form of T0+T2.

[0089] The submodule for processing the irregular title line breaks concatenates the paragraph sub-item T2 of the irregular title line breaks in the form of T0+T2.

[0090] The redundant symbol correction module removes the redundant line breaks and the leading spaces in the final variable T0 through Python's built-in strip function to obtain the final correction result T3.

[0091] The acquired Chinese corpus is input into the symbol correction module, which checks the punctuation marks in the Chinese corpus and replaces the English symbols including ".", "?", "!", and ";" with the corresponding Chinese symbols ".", "?", "!", and ";" respectively; the symbol-corrected Chinese corpus is input into the line break symbol correction module, which replaces the continuous multiple line breaks in the symbol-corrected Chinese corpus with a single line break to obtain corpus T; the corpus paragraph cutting module cuts the corpus T by the line break to obtain a paragraph list T1 = [T2, T2, T2, ...]; the line break classification module classifies each paragraph sub-item T2 in the paragraph list T1, including normal paragraph line breaks , regular title line breaks, abnormal line breaks and abnormal title line breaks; each paragraph sub-item T2 is corrected by each sub-module corresponding to its category in the line break processing module; among them, the normal paragraph line break processing sub-module splices the paragraph sub-item T2 of the normal paragraph line break in the form of T0+line break+T2; the regular title line break processing sub-module splices the paragraph sub-item T2 of the regular title line break in the form of T0+line break+T2; the abnormal line break processing sub-module splices the paragraph sub-item T2 of the abnormal paragraph line break in the form of T0+T2; the abnormal title line break processing sub-module splices the paragraph sub-item T2 of the abnormal title line break in the form of T0+T2. Finally, through the redundant symbol correction module, the redundant line breaks and the leading space in the final variable T0 are removed through the strip function provided by Python to obtain the final correction result T3.

[0092] The present invention not only solves the problem of a large number of illegal line breaks in long Chinese corpora by judging whether the setting of the line break position is correct, thereby improving the readability of the Chinese corpora; it also retains the semantic structure of the Chinese corpora by screening normal line breaks, title line breaks, and abnormal title line breaks through multiple sets of strategies, thereby avoiding misjudgment of normal line breaks to the greatest extent.

[0093] The specific embodiments of the present invention are described in detail above, but they are only examples, and the present invention is not limited to the specific embodiments described above. For those skilled in the art, any equivalent modifications and substitutions made to the present invention are also within the scope of the present invention. Therefore, the equalization changes and modifications made without departing from the spirit and scope of the present invention should be included in the scope of the present invention.

Claims

1. A method for correcting abnormal line breaks in Chinese corpus, characterized in that: Specifically include: Step S1: obtaining Chinese corpus and checking and correcting symbols of the Chinese corpus; Step S2: correcting the line break of the Chinese corpus after the symbol check and correction to obtain corpus T; Step S3: Using line breaks as cutting points, the corpus T is segmented to obtain a paragraph list T1; Step S4: traverse the paragraph list T1 to obtain each paragraph sub-item T2 in the paragraph list T1; Step S5: define a variable T0 for concatenating each paragraph sub-item to generate a complete corpus; Step S6: starting from the second paragraph sub-item, determine the category of each paragraph sub-item T2 in turn, and perform different operations according to the category of each paragraph sub-item T2; Step S7: Determine whether the current paragraph sub-item T2 is a normal paragraph line break. If it is a normal paragraph line break, concatenate it in the form of T0+line break+T2. Otherwise, proceed to step S8; Step S8: Determine whether the current paragraph sub-item T2 is a regular title line break. If it is a regular title line break, concatenate it in the form of T0+line break+T2. Otherwise, go to step S9; Step S9: Determine whether the current paragraph sub-item T2 is an unconventional title line break. If it is an unconventional title line break, concatenate it in the form of T0+line break+T2. Otherwise, concatenate the current paragraph sub-item T2 in the form of T0+T2. Step S10: after performing corresponding operations on the current paragraph sub-item T2 according to its category, determine whether the current paragraph sub-item T2 is the last paragraph sub-item. If not, jump the next paragraph sub-item T2 to step S7. If yes, proceed to step S11. Step S11: remove the leading space and line break in the variable T0 obtained through the above steps to obtain the final correction result T3.

2. A method for correcting abnormal line breaks in Chinese corpus according to claim 1, characterized in that: In step S1, English symbols are replaced with corresponding Chinese symbol formats to achieve correction of Chinese corpus symbols.

3. A method for correcting abnormal line breaks in Chinese corpus according to claim 1, characterized in that: In step S2, the Chinese corpus after symbol checking and correction is corrected with respect to line breaks, specifically including, according to the language characteristics of Chinese, replacing multiple consecutive line breaks in the Chinese corpus with a single line break.

4. The method for correcting abnormal line breaks in Chinese corpus according to claim 1, characterized in that: In step S3, the corpus paragraph segmentation is performed in the form of line breaks, which is implemented by Python's split function.

5. The method for correcting abnormal line breaks in Chinese corpus according to claim 1, characterized in that: In step S5, the corpus formed by concatenating the variable T0 with the line break character and each paragraph sub-item T2 is still defined as the variable T0.

6. The method for correcting abnormal line breaks in Chinese corpus according to claim 1, characterized in that: In step S7, whether the current paragraph sub-item T2 is a normal paragraph wrap is determined by checking the ending content of the previous paragraph sub-item.

7. The method for correcting abnormal line breaks in Chinese corpus according to claim 1, characterized in that: In step S8, whether the previous sentence is in a common title format is determined to determine whether the current paragraph sub-item T2 is a normal title line break.

8. The method for correcting abnormal line breaks in Chinese corpus according to claim 1, characterized in that: In step S9, it is determined whether the current paragraph sub-item T2 is an irregular title line break by calculating the value of the length of the previous paragraph sub-item T2 / the length of the current paragraph sub-item. When the value of the length of the previous paragraph sub-item T2 / the length of the current paragraph sub-item is less than 20%, it is considered that the current paragraph sub-item T2 is an irregular title, otherwise, it is an abnormal line break.

9. The method for correcting abnormal line breaks in Chinese corpus according to claim 1, characterized in that: In step S11, the leading space and line break of variable T0 are removed by using the strip function provided by Python.

10. A system based on the method for correcting abnormal line breaks in Chinese corpus according to claim 1, characterized in that: Specifically include: Symbol correction module, used to maintain the uniformity of the format in Chinese corpus; The line break symbol correction module is used to replace multiple consecutive line breaks in the Chinese corpus with a single line break; The corpus paragraph cutting module is used to cut the corrected Chinese corpus into multiple paragraph sub-items T2 using line breaks as cutting points, and define a variable T0 for splicing each paragraph sub-item; The line break classification module is used to classify each paragraph sub-item T2 into four categories: normal paragraph line break, regular title line break, abnormal line break and irregular title line break; A line break processing module, used for processing line breaks in each paragraph sub-item T2 accordingly according to the classification; The redundant symbol correction module is used to remove the redundant symbols in the Chinese corpus after the abnormal line break correction; The line break processing module includes the following submodules: The normal paragraph line break processing submodule splices the paragraph sub-item T2 of the normal paragraph line break in the form of T0+line break+T2; The regular title line break processing submodule splices the paragraph sub-item T2 of the regular title line break in the form of T0+line break+T2; The abnormal line break processing submodule splices the paragraph sub-item T2 with abnormal line breaks in the form of T0+T2; The submodule for processing the irregular title line breaks concatenates the paragraph sub-item T2 of the irregular title line breaks in the form of T0+T2.