Text alignment method and apparatus, electronic device, and storage medium
By calculating the sliding window ratio and optimizing the edit distance, the text alignment problem for language types with limited text corpora was solved, achieving efficient text alignment with limited resources, simplifying the operation and improving the alignment effect.
Patent Information
- Application Number
- CN202310277940.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-15
- Publication Date
- 2026-08-25
- Estimated Expiration
- 2043-03-15
AI Technical Summary
Existing technologies struggle to achieve text alignment for language types with limited text corpora using deep learning language models, especially for classical Chinese texts which lack punctuation and have uncertain chapter order.
The sliding window ratio is calculated by obtaining the text length of the original text fragment to obtain the original sliding window ratio. The sliding window ratio is then continuously optimized based on the edit distance to achieve text alignment, including the initial edit distance, target edit distance, and the current sliding window ratio filtering process.
With limited resources, it achieves both accuracy and ease of text alignment, improves text alignment performance, and avoids dependence on large amounts of data for training.
Smart Images

Figure CN116306557B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a text alignment method and apparatus, electronic device and storage medium. Background Technology
[0002] With the development of computer science and natural language processing technology, text alignment has been automated with computer assistance. One related technology involves training large amounts of text corpora using deep learning to build deep learning language models, which are then used to achieve text alignment. However, for some language types with limited text corpora, it is difficult to achieve text alignment by training deep learning language models. Therefore, how to achieve text alignment for language types with limited text corpora is a problem that urgently needs to be solved. Summary of the Invention
[0003] The main objective of this application is to provide a text alignment method, apparatus, electronic device, and storage medium, which aims to achieve text alignment through edit distance with a small amount of practice corpus and improve the text alignment effect.
[0004] To achieve the above objectives, a first aspect of this application proposes a text alignment method, the method comprising:
[0005] Obtain the text to be aligned and the preset reference text; wherein, the text to be aligned includes: the original text fragment;
[0006] The original sliding window ratio is obtained by calculating the sliding window ratio based on the text length of the original text segment;
[0007] Based on the original sliding window ratio and the baseline text, the edit distance of the original text fragment is calculated to obtain the preliminary edit distance;
[0008] The original sliding window ratio is filtered based on the preliminary editing distance to obtain a preliminary sliding window ratio;
[0009] The original sliding window ratio is reduced based on the preliminary sliding window ratio to obtain the target sliding window ratio.
[0010] The target edit distance is obtained by calculating the edit distance of the original text segment based on the target sliding window ratio and the reference text.
[0011] The target sliding window ratio is filtered based on the target edit distance to obtain the current sliding window ratio.
[0012] The original text fragment and the reference text are aligned according to the current sliding window ratio to obtain the target text.
[0013] In some embodiments, the step of calculating the edit distance of the original text fragment based on the original sliding window ratio and the reference text to obtain the preliminary edit distance includes:
[0014] Based on the original sliding window ratio, the original text fragment is slid across the reference text to obtain a preliminary sliding window fragment;
[0015] The initial edit distance is obtained by calculating the edit distance between the initial sliding window segment and the original text segment.
[0016] In some embodiments, the step of sliding the original text fragment over the reference text according to the original sliding window ratio to obtain a preliminary sliding window fragment includes:
[0017] Obtain the text length of the original text fragment;
[0018] The original sliding window size is obtained by calculating the sliding window size based on the text length and the original sliding window ratio.
[0019] The original text fragment is slid across the base text at the original sliding window size to obtain the initial sliding window fragment.
[0020] In some embodiments, the step of filtering the original sliding window ratio based on the preliminary edit distance to obtain the preliminary sliding window ratio includes:
[0021] Obtain the minimum value of the initial edit distance to get the minimum edit distance;
[0022] The original sliding window ratio is filtered based on the minimum edit distance to obtain the preliminary sliding window ratio.
[0023] In some embodiments, the step of filtering the original sliding window ratio based on the minimum edit distance to obtain the preliminary sliding window ratio includes:
[0024] Obtain the initial sliding window segment with the minimum edit distance to obtain candidate sliding window segments;
[0025] Obtain the number of candidate sliding window segments for each of the original sliding window ratios;
[0026] The original sliding window ratio is filtered based on the number of segments to obtain the preliminary sliding window ratio.
[0027] In some embodiments, the step of shrinking the original sliding window ratio based on the preliminary sliding window ratio to obtain the target sliding window ratio includes:
[0028] Obtain the upper limit value of the original sliding window ratio to get the upper limit value of the sliding window;
[0029] The upper limit value of the sliding window is replaced based on the preliminary sliding window ratio to obtain the target sliding window ratio.
[0030] In some embodiments, the step of calculating the edit distance of the original text segment based on the target sliding window ratio and the reference text to obtain the target edit distance includes:
[0031] The target sliding window size is obtained by calculating the sliding window size based on the text length and the target sliding window ratio;
[0032] The original text fragment is slid over the base text at the target sliding window size to obtain the target sliding window fragment;
[0033] The edit distance between the target sliding window segment and the original text segment is calculated to obtain the target edit distance.
[0034] To achieve the above objectives, a second aspect of this application provides a text alignment device, the device comprising:
[0035] The text acquisition module is used to acquire the text to be aligned and the preset reference text; wherein, the text to be aligned includes: the original text fragment;
[0036] The sliding window ratio calculation module is used to calculate the sliding window ratio based on the text length of the original text segment to obtain the original sliding window ratio.
[0037] The preliminary calculation module is used to calculate the edit distance of the original text segment based on the original sliding window ratio and the reference text, so as to obtain the preliminary edit distance;
[0038] The preliminary screening module is used to filter the original sliding window ratio based on the preliminary editing distance to obtain a preliminary sliding window ratio.
[0039] The shrinking module is used to shrink the original sliding window ratio based on the preliminary sliding window ratio to obtain the target sliding window ratio.
[0040] The target calculation module is used to calculate the edit distance of the original text segment based on the target sliding window ratio and the reference text to obtain the target edit distance;
[0041] The target filtering module is used to perform ratio filtering on the target sliding window ratio based on the target editing distance to obtain the current sliding window ratio;
[0042] The alignment module is used to align the original text fragment and the reference text according to the current sliding window ratio to obtain the target text.
[0043] To achieve the above objectives, a third aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the text alignment method described in the first aspect.
[0044] To achieve the above objectives, a fourth aspect of the present application provides a storage medium storing a computer program that, when executed by a processor, implements the text alignment method described in the first aspect.
[0045] The text alignment method, apparatus, electronic device, and storage medium proposed in this application calculate the edit distance between the sliding window segment and the original text segment for each original sliding window ratio, continuously optimize the sliding window ratio based on the edit distance to obtain the optimal current sliding window ratio, and align the original text segment and the reference text based on the current sliding window ratio. Therefore, by calculating the edit distance to determine the matching degree between the original text segment and the sliding window segment, and continuously optimizing the sliding window ratio based on the edit distance to determine the optimal current sliding window ratio, the original text segment is aligned with the reference text based on the current sliding window ratio. This achieves accurate text alignment even for text of a limited number of language types, and the alignment operation is simpler and the alignment effect is better. Furthermore, compared to directly calculating the edit distance between the original text segment and the sliding window segment for alignment, continuously optimizing the sliding window ratio based on the edit distance to perform text alignment based on the optimized current sliding window ratio results in a superior text alignment effect. Attached Figure Description
[0046] Figure 1 This is a flowchart of the text alignment method provided in the embodiments of this application;
[0047] Figure 2 yes Figure 1 The flowchart of step S103 in the process;
[0048] Figure 3 yes Figure 2 The flowchart of step S201 in the text;
[0049] Figure 4 yes Figure 1 The flowchart of step S104 in the process;
[0050] Figure 5 yes Figure 4 The flowchart of step S402 in the document;
[0051] Figure 6 yes Figure 1 The flowchart of step S105 in the process;
[0052] Figure 7 yes Figure 1The flowchart of step S106 in the process;
[0053] Figure 8 This is a schematic diagram of the structure of the text alignment device provided in the embodiments of this application;
[0054] Figure 9 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0055] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0056] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0058] First, let's analyze some of the terms used in this application:
[0059] Artificial intelligence (AI) is a new branch of computer science that studies, develops, and applies theories, methods, technologies, and systems to simulate, extend, and expand human intelligence. It aims to understand the essence of intelligence and produce intelligent machines that can react in a way similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. AI can simulate the information processes of human consciousness and thought. Furthermore, AI utilizes digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceiving the environment, acquiring knowledge, and using that knowledge to achieve optimal results.
[0060] Text alignment: The process of establishing correspondences between identical linguistic units in the source and translation texts of parallel corpora. There are multiple levels of correspondences between parallel text corpora, such as paragraph alignment, sentence alignment, phrase alignment, and word alignment.
[0061] Edit distance is a quantitative measure of the difference between two strings (such as English words). It measures the minimum number of processing steps required to transform one string into the other. Edit distance is used in natural language processing; for example, spell checking can determine which (or more) spelling words are more likely based on their edit distance to other correct words. DNA can also be viewed as a string composed of A, C, G, and T, so edit distance is also used in bioinformatics to determine the similarity between two DNA sequences. The diff and patch functions in Unix are examples of using edit distance for text editing comparison.
[0062] Levenshtein distance, also known as Levenshtein's distance, is a type of edit distance. It refers to the minimum number of edit operations required to transform one string into the other. Allowed edit operations include replacing one character with another, inserting a character, and deleting a character. Levenshtein distance is used to measure the similarity between two strings.
[0063] Iteration: Iteration is an activity involving repeated feedback processes, typically aimed at approximating a desired goal or result. Each repetition of the process is called an "iteration," and the result of each iteration serves as the initial value for the next iteration. It involves repeatedly executing a series of computational steps, sequentially deriving subsequent quantities from preceding ones. Each result in this process is obtained by applying the same computational steps to the result obtained in the previous iteration.
[0064] In the field of document alignment, due to changes in chapter and paragraph order or alterations in word choice during transcription between different versions, researchers need to compare and align different versions of documents to create reliable ones. With the development of computer science and natural language processing, this tedious text comparison and alignment work can be automated with computer assistance. One related technology involves constructing deep learning language models to learn sentence segmentation and meaning, aligning sentences based on their meaning. However, with the increasing number of language types and the scarcity of corpora for some language types, it is difficult to accurately achieve text alignment using deep learning language models. For example, if the language is Classical Chinese, where corpora are scarce compared to modern vernacular Chinese, and Classical Chinese suffers from issues such as lack of punctuation, word differences, and uncertain chapter and paragraph order, it is impossible to accurately align Classical Chinese using deep learning language models.
[0065] Based on this, embodiments of this application provide a text alignment method, apparatus, electronic device, and storage medium. The method involves acquiring an original text fragment and a reference text, calculating an initial sliding window ratio based on the text length of the original text fragment, calculating an edit distance between the original text fragment and the reference text to obtain a preliminary edit distance, and then shrinking the original sliding window ratio based on the preliminary edit distance to obtain a target sliding window ratio. The method then calculates the edit distance between the original text fragment and the reference text to obtain the target edit distance, performs ratio filtering on the target sliding window ratio based on the target edit distance to obtain the current sliding window ratio, and finally aligns the original text fragment and the reference text based on the current sliding window ratio to obtain the target text. Therefore, by calculating the preliminary edit distance between the original text fragment and the sliding window fragment, continuously reducing the original sliding window ratio based on the preliminary edit distance to obtain the optimal current sliding window ratio, and aligning the original text fragment and the reference text based on the current sliding window ratio, text alignment can be achieved without relying on a large amount of data to train a deep learning language model, and the text alignment effect is superior.
[0066] The text alignment method, apparatus, electronic device, and storage medium provided in this application are specifically described through the following embodiments. First, the text alignment method in the embodiments of this application is described.
[0067] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0068] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0069] The text alignment method provided in this application relates to the field of artificial intelligence technology. The text alignment method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the text alignment method, but is not limited to the above forms.
[0070] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0071] It should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, and user location information, user permission or consent is obtained first. Furthermore, the collection, use, and processing of this data comply with relevant laws, regulations, and standards of the relevant countries and regions. In addition, when embodiments of this application require access to sensitive personal information of users, separate permission or consent from the user is obtained through pop-ups or redirects to confirmation pages. Only after obtaining the user's separate permission or consent is the necessary user-related data for the proper functioning of the embodiments of this application obtained.
[0072] Figure 1 This is an optional flowchart of the text alignment method provided in the embodiments of this application. Figure 1 The method may include, but is not limited to, steps S101 to S108.
[0073] Step S101: Obtain the text to be aligned and the preset reference text; wherein, the text to be aligned includes: the original text fragment;
[0074] Step S102: Calculate the sliding window ratio based on the text length of the original text segment to obtain the original sliding window ratio;
[0075] Step S103: Calculate the edit distance of the original text fragment based on the original sliding window ratio and the reference text to obtain the preliminary edit distance;
[0076] Step S104: Filter the original sliding window ratio based on the initial editing distance to obtain the initial sliding window ratio;
[0077] Step S105: Shrink the original sliding window ratio based on the preliminary sliding window ratio to obtain the target sliding window ratio;
[0078] Step S106: Calculate the edit distance of the original text fragment based on the target sliding window ratio and the reference text to obtain the target edit distance;
[0079] Step S107: Filter the target sliding window ratio based on the target editing distance to obtain the current sliding window ratio;
[0080] Step S108: Align the original text fragment and the reference text according to the current sliding window ratio to obtain the target text.
[0081] Steps S101 to S108 of this embodiment involve acquiring the text to be aligned and a preset reference text. The text to be aligned includes an original text fragment. An original sliding window ratio is calculated based on the length of the original text fragment. An initial editing distance is calculated based on the original sliding window ratio and the reference text. The original sliding window ratio is then filtered based on the initial editing distance to obtain a final preliminary sliding window ratio. The original sliding window ratio is then shrunk based on the initial sliding window ratio to obtain a target sliding window ratio. The original text fragment is then recalculated based on the target sliding window ratio and the reference text to obtain a final target editing distance. Finally, the target sliding window ratio is filtered based on the target editing distance to obtain a current sliding window ratio. The original text fragment and the reference text are then aligned based on the current sliding window ratio to obtain the target text. Therefore, by calculating the matching degree between the original text fragment and the reference text using edit distance, and continuously optimizing the sliding window ratio to determine the optimal current sliding window ratio, the original text fragment is aligned with the reference text based on the current sliding window ratio. This makes the alignment operation simpler and yields better results. Furthermore, compared to directly calculating the edit distance between the original text fragment and the sliding window fragment for text alignment, continuously optimizing the sliding window ratio based on the edit distance and then aligning the text according to the optimized current sliding window ratio results in superior text alignment performance.
[0082] In step S101 of some embodiments, the text to be aligned is obtained, and two sets of text to be aligned are obtained. One set of text to be aligned is selected as a preset reference text, and the other set of text to be aligned is aligned with the reference text. The text to be aligned includes original text fragments, specifically at least two original text fragments. Therefore, by obtaining the original text fragments and determining the preset reference text based on the original text fragments, the original text fragments are aligned with the reference text.
[0083] It should be noted that if at least two reference fragments are obtained, these two fragments are concatenated to obtain the reference text. For example, if the two reference fragments are x1 = [ABCDEF] and x2 = [GHIJKL], then the reference fragments x1 and x2 are concatenated to obtain the reference text X = x1 + x2 = [ABCDEFGHIJKL]. Therefore, by concatenating the scattered reference fragments into the reference text, the original text fragments can be aligned with the reference text.
[0084] In step S102 of some embodiments, the text length of the original text fragment is obtained, and the original sliding window ratio is calculated based on the text length. Specifically, the corresponding original sliding window ratio is extracted from a preset ratio mapping relationship according to the text length, and at least two original sliding window ratios are set and ordered in ascending order. Therefore, obtaining the corresponding original sliding window ratio from the preset ratio mapping relationship according to the text length facilitates the selection of sliding window ratios that match the original text fragment from the original sliding window ratios.
[0085] Specifically, the length of the reference text is obtained to get the reference length, and the length ratio is calculated by dividing the text length by the reference length. If three original sliding window ratios are set, when the length ratio is greater than 0 and less than 0.3, the original sliding window ratios are 1, 1.5, and 2 obtained from the preset ratio mapping relationship. If the length ratio is greater than 0.3 and less than 0.5, the original sliding window ratios are 1, 1.3, and 1.6 obtained from the preset ratio mapping relationship. If the length ratio is greater than 0.5 and less than 1, the original sliding window ratios are 1, 1.1, and 1.2 obtained from the preset ratio mapping relationship. Therefore, the original sliding window ratios obtained from the preset ratio mapping relationship are different depending on the length ratio. By determining the original sliding window ratio with better alignment effect before optimizing the sliding window ratio, the number of sliding window ratio optimizations can be reduced, thereby improving the efficiency of text alignment.
[0086] Please see Figure 2 In some embodiments, step S103 may include, but is not limited to, steps S201 to S202:
[0087] Step S201: Slide the original text fragment on the reference text according to the original sliding window ratio to obtain the preliminary sliding window fragment;
[0088] Step S202: Calculate the edit distance between the initial sliding window fragment and the original text fragment to obtain the initial edit distance.
[0089] In step S201 of some embodiments, the original text segment is slid over a reference text segment according to each original sliding window ratio to obtain at least one preliminary sliding window segment. If at least two original sliding window ratios are set, the original text segment is slid over the reference text segment according to at least two original sliding window ratios to obtain at least two preliminary sliding window segments.
[0090] In step S202 of some embodiments, the initial edit distance is calculated by performing an edit distance calculation on the initial sliding window segment and the original text segment. In this embodiment, the Levenstein distance is calculated on the initial sliding window segment and the original text segment to obtain the segment edit distance, and then the initial edit distance is calculated based on the segment edit distance, the original sliding window ratio, and the text length. The specific calculation of the segment edit distance is shown in formula (1):
[0091]
[0092] In the formula, |a| and |b| represent the lengths of the original text segment and the initial sliding window segment, respectively; i represents the character index of the original text segment; and j represents the character index of the initial sliding window segment. Is when a i ≠b j The indicator function whose value is 1 when it is active and 0 otherwise, lev a,b (i,j) is the distance between the first i characters of a and the first j characters of b.
[0093] The initial edit distance is calculated by substituting the fragment edit distance, the original sliding window ratio, and the text length into formula (2), and formula (2) is shown below:
[0094] D=(d-(len*r–len)) / r (2)
[0095] In the formula, D is the initial edit distance, d is the fragment edit distance, r is the original sliding window ratio, and len is the text length. len*r – len represents the length difference between the initial sliding window fragment and the original text fragment. When r = 1, the initial sliding window distance and the fragment edit distance are equal. When the initial sliding window fragment contains the original text fragment, the fragment edit distance and the length difference are equal, then d – (len*r – len) = 0. Clearly, for an initial sliding window fragment containing the original text fragment, the best match is an initial sliding window fragment with the same length as the original text fragment. Therefore, when r = 1, the initial sliding window edit distance should be minimized, and the length difference divided by the original sliding window ratio, in the case of an initial sliding window fragment containing the original text fragment, the larger r is, the smaller the length difference divided by the original sliding window ratio, meaning the larger the initial edit distance.
[0096] Steps S201 to S202 as shown in the embodiments of this application involve sliding the original text fragment on the reference text according to the original sliding window ratio to obtain a preliminary sliding window fragment, calculating the editing distance between the preliminary sliding window fragment and the original text fragment to obtain a preliminary editing distance, and judging the similarity between the preliminary sliding window fragment and the original text fragment based on the preliminary editing distance, so as to filter the original sliding window ratio according to the preliminary editing distance.
[0097] In some embodiments, please refer to Figure 3 Step S201 may include, but is not limited to, steps S301 to S303:
[0098] Step S301: Obtain the text length of the original text fragment;
[0099] Step S302: Calculate the original sliding window size based on the text length and the original sliding window ratio;
[0100] Step S303: Slide the original text fragment on the reference text with the original sliding window size to obtain the preliminary sliding window fragment.
[0101] In step S301 of some embodiments, the text length of the original text fragment is obtained, and since there are at least two original text fragments, the text lengths of the different original text fragments are different. For example, if the original text fragment is y2 = [DEFG], then the text length of y2 is determined to be len(y2) = 4.
[0102] In step S302 of some embodiments, the original sliding window size is obtained by multiplying the text length and the original sliding window ratio. Each original sliding window ratio yields an original sliding window size. For example, if the text length is 4 and the original sliding window ratio is 1, the original sliding window size is 4; if the original sliding window ratio is 1.5, the original sliding window size is 6; and if the original sliding window ratio is 2, the original sliding window size is 8. Therefore, by multiplying each original sliding window ratio by the text length to obtain the original sliding window size, the sliding window size of the original text fragment on the reference text is determined based on the original sliding window size.
[0103] In step S303 of some embodiments, the original text fragment is slid across the reference text at the original sliding window size, that is, slid across the reference text once per character according to the original sliding window size, so as to obtain a preliminary sliding window fragment.
[0104] For example, if the original text segment is y2 = [DEFG], then the original sliding window size is 6, and the base text is x = [ABCDEFGHIJK]. Sliding the original text segment across the base text with the original sliding window size will yield preliminary sliding window segments z1 = [ABCDEF], [BCDEFG], [CDEFGH], ..., [FGHIJK]. Therefore, selecting sliding window segments based on an original sliding window ratio can yield at least two preliminary sliding window segments.
[0105] In steps S301 to S303 of this embodiment, the text length of the original text fragment is obtained, and the original sliding window size is calculated based on the ratio of the text length to the original sliding window. The original text fragment is then slid across the reference text with the original sliding window size to obtain a preliminary sliding window fragment. Therefore, by calculating the original sliding window size, the original text fragment can be slid across the reference text with the original sliding window size, making it easy to obtain the preliminary sliding window fragment. This facilitates the calculation of the editing distance between the preliminary sliding window fragment and the original text fragment, thereby determining the alignment position of the original text fragment on the reference text.
[0106] In some embodiments, please refer to Figure 4 Step S104 may include, but is not limited to, steps S401 to S402:
[0107] Step S401: Obtain the minimum value of the initial edit distance to get the minimum edit distance;
[0108] Step S402: Filter the original sliding window ratio based on the minimum edit distance to obtain the preliminary sliding window ratio.
[0109] In step S401 of some embodiments, since an original sliding window ratio can yield at least two preliminary sliding window segments, the edit distance between the at least two preliminary sliding window segments and the original text segment is calculated to obtain at least two preliminary edit distances. Then, the minimum value is selected from the at least two edit distances to obtain the minimum edit distance. The number of minimum edit distances selected is at least one.
[0110] In step S402 of some embodiments, after obtaining the minimum edit distance, a preliminary sliding window ratio is selected from at least two original sliding window ratios based on the minimum edit distance, so as to further shrink the original sliding window ratio based on the preliminary sliding window ratio to further optimize the sliding window ratio, thereby determining that the alignment effect of the original text fragment on the reference text is better based on the optimized current sliding window ratio.
[0111] Steps S401 to S402 as shown in the embodiments of this application obtain the minimum edit distance by acquiring the minimum value of the preliminary edit distance, and filter out the preliminary slide window ratio from the original slide window ratio based on the minimum edit distance, so as to initially filter out a better slide window ratio, so as to achieve a better alignment effect of the original text fragment on the reference text based on the optimized slide window ratio.
[0112] Please see Figure 5 In some embodiments, step S402 may also include, but is not limited to, steps S501 to S503:
[0113] Step S501: Obtain the initial sliding window segment with the minimum edit distance to obtain candidate sliding window segments;
[0114] Step S502: Obtain the number of candidate sliding window segments for each original sliding window ratio;
[0115] Step S503: Filter the original sliding window ratio based on the number of segments to obtain a preliminary sliding window ratio.
[0116] In step S501 of some embodiments, a preliminary sliding window segment with the minimum edit distance is obtained, and the number of minimum edit distances is at least one, so as to obtain at least one candidate sliding window segment, so as to determine the sliding window ratio that best matches the original text segment based on the candidate sliding window segment.
[0117] For example, if the initial sliding window ratio is 1.5 and the initial sliding window segments with a minimum edit distance of 1 are [BCDEFG], [CDEFGH], and [DEFGHI], then there are three candidate sliding window segments with a minimum edit distance of 1, which makes it easier to determine the best matching sliding window ratio of the original text segment based on the candidate sliding window segments.
[0118] In step S502 of some embodiments, the number of candidate sliding window segments for each original sliding window segment is obtained so as to filter out an initial sliding window ratio from the original sliding window ratio based on the number of segments, thereby optimizing the sliding window ratio.
[0119] In step S503 of some embodiments, the original sliding window ratio is filtered according to the number of segments, that is, the original sliding window ratio corresponding to the highest number of segments is taken as the preliminary sliding window ratio. For example, if the original sliding window ratio is 1.5, the number of candidate sliding window segments is 3, and the number of segments is 3, then the original sliding window ratio of 1.5 is determined as the preliminary sliding window ratio.
[0120] In the embodiments of this application, steps S501 to S503 involve obtaining candidate sliding window segments by acquiring the preliminary sliding window segment corresponding to the minimum edit distance, and then obtaining the number of segments of the candidate sliding window segment corresponding to each original sliding window ratio. The original sliding window ratio with the highest number of segments is then used as the preliminary sliding window ratio, so as to shrink the original sliding window ratio according to the preliminary sliding window ratio and optimize the sliding window ratio.
[0121] Please see Figure 6 In some embodiments, step S105 includes, but is not limited to, steps S601 to S602:
[0122] Step S601: Obtain the upper limit value of the original sliding window ratio to get the upper limit value of the sliding window;
[0123] Step S602: Replace the upper limit value of the sliding window with the initial sliding window ratio to obtain the target sliding window ratio.
[0124] In step S601 of some embodiments, the upper limit value of the original sliding window ratio is obtained, that is, the maximum value of the original sliding window ratio is obtained to obtain the upper limit value of the sliding window. For example, if the upper limit value of the original sliding window ratio is 2, then 2 is determined as the upper limit value of the sliding window.
[0125] In step S602 of some embodiments, the upper limit value of the sliding window is replaced with a preliminary sliding window ratio to obtain a target sliding window ratio, thereby narrowing the range of the original sliding window ratio and obtaining a smaller target sliding window ratio. For example, if the preliminary sliding window ratio is 1.5, then 2 is replaced with 1.5 to update the upper limit value of the sliding window, and the upper limit value of the target sliding window ratio is determined to be 1.5, that is, the range of the target sliding window ratio is determined to be 1-1.5, so as to calculate the edit distance between the original text fragment and the sliding window fragment based on the target sliding window ratio of 1-1.5. Therefore, by narrowing the original sliding window ratio through the preliminary sliding window ratio and iteratively calculating the optimal current sliding window ratio, the alignment position of the original text fragment on the reference text can be determined based on the current sliding window ratio, resulting in a better alignment effect of the original text fragment.
[0126] Steps S601 to S602, as illustrated in this embodiment, involve obtaining the upper limit value of the original sliding window ratio to obtain the upper limit value of the sliding window, and then replacing the upper limit value with the preliminary sliding window ratio to shrink the original sliding window ratio, thereby obtaining the target sliding window ratio. Therefore, by shrinking the original sliding window ratio after each calculation of the preliminary sliding window ratio, a better sliding window ratio can be further selected until the target sliding window ratio range is reduced to a constant range to determine the current sliding window ratio, thereby improving the text alignment effect.
[0127] Please see Figure 7 In some embodiments, step S106 may include, but is not limited to, steps S701 to S703:
[0128] Step S701: Calculate the target sliding window size based on the ratio of text length to target sliding window.
[0129] Step S702: Slide the original text fragment on the reference text with the target sliding window size to obtain the target sliding window fragment;
[0130] Step S703: Calculate the edit distance between the target sliding window fragment and the original text fragment to obtain the target edit distance.
[0131] In step S701 of some embodiments, after shrinking the original sliding window ratio to obtain the target sliding window ratio, the text length and the target sliding window ratio are calculated again, that is, the text length and the target sliding window ratio are multiplied to obtain the target sliding window size, so as to determine the alignment position of the original text fragment according to the target sliding window size.
[0132] For example, after obtaining the target sliding window ratio, and given that the upper limit of the target sliding window ratio is 1.5, the target sliding window ratio can be any value between 1, 1.25, and 1.5 to calculate the target sliding window size for each target sliding window ratio and the text length. When the text length is len(y2) = 4, if the target sliding window ratio is 1, the target sliding window size is 4; if the target sliding window ratio is 1.25, the target sliding window size is 5; and if the target sliding window ratio is 1.5, the target sliding window size is 6. Therefore, the range of target sliding window sizes is smaller than the range of original sliding window sizes. By reducing the original sliding window ratio and the sliding window size, the alignment of the original text fragment on the reference text is improved through the reduced target sliding window size.
[0133] In step S702 of some embodiments, the original text fragment is slid across the reference text at the target sliding window size to obtain the target sliding window fragment. Since the target sliding window size is obtained by reducing the original sliding window size, the number of target sliding window fragments also increases. Therefore, the target edit distance between each target sliding window fragment and the original text fragment also increases accordingly. This increased target edit distance allows for the selection of a better sliding window ratio, that is, it allows for the selection of alignment positions that better match the original text fragment, resulting in a better alignment effect for the original text fragment.
[0134] In step S703 of some embodiments, the edit distance between the target sliding window segment and the original text segment is calculated. That is, the segment edit distance between the target sliding window segment and the original text segment is calculated first, and then the target edit distance is calculated by substituting the segment edit distance, text length and target sliding window ratio into formula (2). The similarity between the target sliding window segment and the original text segment is determined by the target edit distance, so as to find the target sliding window ratio that matches the original text segment, and then determine the alignment position of the original text segment on the reference text.
[0135] It should be noted that steps S103 to S106 need to be repeated to continuously narrow the range of the sliding window ratio. After each narrowing of the range, the target sliding window ratio needs to be redefined. If three target sliding window ratios are determined, and the differences between the three target sliding window ratios are equal, then if the target sliding window size calculated based on the target sliding window ratio and text length is not an integer, it is rounded to the nearest integer. Therefore, after determining the integer target sliding window size, the original text segment is slid across the base text with the target sliding window size to obtain the target sliding window segment. Then, the edit distance between the target sliding window segment and the original text segment is calculated to obtain the target edit distance, which is used to optimize the target sliding window ratio.
[0136] Steps S701 to S703 of this embodiment involve calculating the target sliding window size by multiplying the text length and the target sliding window ratio, then sliding the original text segment onto the reference text with the target sliding window size to obtain the target sliding window segment, and finally calculating the edit distance between the target sliding window segment and the original text segment to obtain the target edit distance. The similarity between the target sliding window segment and the original text segment can be determined through the target edit distance, and the target sliding window ratio is optimized based on the target edit distance to select the optimal current sliding window ratio. Therefore, by gradually reducing the sliding window ratio to filter out the optimal current sliding window ratio, and then aligning the original text segment onto the reference text using the current sliding window ratio, the alignment effect of the original text segment on the reference text is improved.
[0137] In step S107 of some embodiments, after calculating the target edit distance, the target sliding window ratio is filtered based on the target edit distance. Specifically, the minimum target edit distance is obtained, and the target sliding window ratio with the most target sliding window segments corresponding to the minimum target edit distance is determined as the current sliding window ratio. This means that the current sliding window ratio that is more optimal for the original text segment is selected. Therefore, by selecting the current sliding window ratio and determining it as the optimal sliding window ratio, the current sliding window size can be recalculated based on the current sliding window ratio, and the optimal alignment position of the original text segment on the reference text can be found based on the current sliding window size, thereby improving the alignment effect of the original text segment.
[0138] It should be noted that the optimal current sliding window ratio is selected from the target sliding window ratios based on the target edit distance. Specifically, when the range of target sliding window ratios is narrowed down to a constant range, the constant target sliding window ratio is used as the current sliding window ratio, i.e., the optimal sliding window ratio is determined. Therefore, by continuously optimizing the sliding window ratio, rather than directly determining the alignment position of the original text fragment based on the edit distance between the sliding window fragment and the original text fragment, the alignment effect of the original text fragment is improved.
[0139] In step S108 of some embodiments, the original text fragment and the reference text fragment are aligned according to the current sliding window ratio. Specifically, the current sliding window size is first calculated by using the current sliding window ratio and the text length. The original text fragment is then slid across the reference text with the current sliding window size to obtain the current sliding window fragment. The current editing distance is calculated between the current sliding window fragment and the original text fragment, and the current sliding window fragment with the smallest current editing distance is taken as the current alignment position of the original text fragment. The original text fragment is then aligned with the current alignment position. Therefore, compared to directly aligning based on the editing distance between the sliding window fragment and the original text fragment, by continuously optimizing the sliding window ratio to obtain the current sliding window ratio, and then calculating the current editing distance based on the current sliding window ratio to determine the alignment position of the original text fragment using the current editing distance, the alignment effect of the original text fragment is better.
[0140] It should be noted that if there are at least two current sliding window segments corresponding to the smallest calculated current edit distance, then the current sliding window segment whose first character matches the first character of the original text segment is selected as the current alignment position, making the alignment of the original text segments more accurate. If there are at least two original text segments, then the current sliding window ratio of each original text segment is different. The original text segments are first aligned according to their original state before sorting, and then aligned according to their original state after sorting, to complete the alignment operation of multiple original text segments on the base text, thus obtaining the target text. Therefore, the text alignment operation does not require building a deep learning language model beforehand; it directly performs editing calculations to optimize the sliding window ratio before alignment, enabling text alignment even with limited corpus resources and improving the text alignment effect.
[0141] This application embodiment obtains at least two original text segments to be processed and a preset reference text. Based on the text length of the original text segments, it obtains the original sliding window ratio from a preset ratio mapping relationship. Then, it performs sliding window calculation using the original sliding window ratio and text length to obtain the original sliding window size. The original text segment is then slid across the reference text with the original sliding window size to obtain a preliminary sliding window segment. An editing distance is calculated between the preliminary sliding window segment and the original text segment to obtain the preliminary editing distance. The minimum editing distance is obtained by finding the minimum value of the preliminary editing distance, and the preliminary sliding window segment with the minimum editing distance is obtained to obtain candidate sliding window segments. Then, the number of candidate sliding window segments corresponding to each original sliding window ratio is calculated, and the original sliding window ratio with the highest number of segments is obtained as the preliminary sliding window ratio. The initial sliding window ratio is replaced with the upper limit of the original sliding window ratio to obtain the target sliding window ratio. Then, based on the target sliding window ratio and the text length, the target sliding window size is calculated. The original text fragment is then slid across the base text with the target sliding window size to obtain the target sliding window fragment. Next, the edit distance between the target sliding window fragment and the original text fragment is calculated to obtain the target edit distance. The number of target sliding window fragments corresponding to the minimum target edit distance is obtained, and the target sliding window ratio with the highest number of fragments is used as the current sliding window ratio, thereby filtering out the optimal current sliding window ratio. Finally, based on the current sliding window ratio and the text length, the current sliding window size is calculated. The original text fragment is then slid across the base text with the current sliding window size to obtain the current sliding window fragment. The edit distance between the current sliding window fragment and the original text fragment is calculated to obtain the current edit distance. The current sliding window fragment with the minimum current edit distance is used as the current alignment position. Finally, the original text fragment is aligned to the current alignment position to obtain the target text. Therefore, by continuously optimizing the sliding window ratio to select the optimal current sliding window ratio, the current edit distance is calculated based on the optimal current sliding window ratio, and then the current alignment position of the original text fragment is determined based on the current edit distance. This allows the original text alignment to avoid the need to train a deep learning language model in advance, thus eliminating the need to rely on a large amount of data. This ensures both the effectiveness and efficiency of text alignment.
[0142] Please see Figure 8 This application also provides a text alignment device that can implement the above-described text alignment method. The device includes:
[0143] The text acquisition module 801 is used to acquire the text to be aligned and the preset reference text; wherein, the text to be aligned includes: the original text fragment;
[0144] The sliding window ratio calculation module 802 is used to calculate the sliding window ratio based on the text length of the original text segment to obtain the original sliding window ratio.
[0145] The preliminary calculation module 803 is used to calculate the editing distance of the original text fragment based on the original sliding window ratio and the reference text, and obtain the preliminary editing distance.
[0146] The preliminary screening module 804 is used to filter the original sliding window ratio based on the preliminary editing distance to obtain the preliminary sliding window ratio.
[0147] The shrinking module 805 is used to shrink the original sliding window ratio based on the preliminary sliding window ratio to obtain the target sliding window ratio;
[0148] The target calculation module 806 is used to calculate the edit distance of the original text fragment based on the target sliding window ratio and the baseline text to obtain the target edit distance;
[0149] The target filtering module 807 is used to perform ratio filtering on the target sliding window ratio based on the target editing distance to obtain the current sliding window ratio.
[0150] Alignment module 808 is used to align the original text fragment and the reference text according to the current sliding window ratio to obtain the target text.
[0151] The specific implementation of this text alignment device is basically the same as the specific embodiment of the text alignment method described above, and will not be repeated here.
[0152] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described text alignment method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0153] Please see Figure 9 , Figure 9 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes:
[0154] The processor 901 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.
[0155] The memory 902 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 902 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 902 and is called and executed by the processor 901 using the text alignment method of the embodiments of this application.
[0156] The input / output interface 903 is used to implement information input and output;
[0157] The communication interface 904 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0158] Bus 905 transmits information between various components of the device (e.g., processor 901, memory 902, input / output interface 903, and communication interface 904);
[0159] The processor 901, memory 902, input / output interface 903, and communication interface 904 are connected to each other within the device via bus 905.
[0160] This application also provides a storage medium, which is a computer-readable storage medium, storing a computer program that, when executed by a processor, implements the above-described text alignment method.
[0161] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0162] The text alignment method, apparatus, electronic device, and storage medium provided in this application embodiment acquire an original text fragment to be processed and a preset reference text. They calculate an original sliding window ratio based on the text length of the original text fragment, and calculate a preliminary editing distance based on the original sliding window ratio and the reference text. The original sliding window ratio is then filtered based on this preliminary editing distance to obtain a target sliding window ratio. The original sliding window ratio is then contracted using the preliminary sliding window ratio to narrow its range, resulting in a target sliding window ratio. The target editing distance is then calculated based on the target sliding window ratio and the reference text. Finally, the current sliding window ratio is filtered from the target sliding window ratios based on the target editing distance, and the original text fragment and the reference text are aligned according to the current sliding window ratio to obtain the target text. Therefore, by calculating the edit distance to optimize the sliding window ratio, the best current sliding window ratio is selected. Then, the original text fragment and the reference text are aligned according to the current sliding window ratio to obtain the target text. This achieves text alignment with limited corpus resources, which can improve both the effect and efficiency of text alignment.
[0163] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0164] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0165] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0166] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0167] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0168] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0169] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0170] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0171] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0172] If the integrated unit is implemented as a software functional unit 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 all 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 multiple 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 of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0173] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A text alignment method, characterized in that, The method includes: Obtain the text to be aligned and the preset reference text; wherein, the text to be aligned includes: the original text fragment; The original sliding window ratio is obtained by calculating the sliding window ratio based on the text length of the original text segment; Based on the original sliding window ratio and the baseline text, the edit distance of the original text fragment is calculated to obtain the preliminary edit distance; The original sliding window ratio is filtered based on the preliminary editing distance to obtain a preliminary sliding window ratio; The original sliding window ratio is reduced based on the preliminary sliding window ratio to obtain the target sliding window ratio. The target edit distance is obtained by calculating the edit distance of the original text segment based on the target sliding window ratio and the reference text. The target sliding window ratio is filtered based on the target edit distance to obtain the current sliding window ratio. The original text fragment and the reference text are aligned according to the current sliding window ratio to obtain the target text; The step of calculating the edit distance of the original text segment based on the original sliding window ratio and the reference text to obtain the preliminary edit distance includes: Based on the original sliding window ratio, the original text fragment is slid across the reference text to obtain a preliminary sliding window fragment; The initial edit distance is obtained by calculating the edit distance between the initial sliding window segment and the original text segment; The step of sliding the original text fragment on the reference text according to the original sliding window ratio to obtain a preliminary sliding window fragment includes: Obtain the text length of the original text fragment; The original sliding window size is obtained by calculating the sliding window size based on the text length and the original sliding window ratio. The original text fragment is slid over the reference text at the original sliding window size to obtain the initial sliding window fragment; The step of filtering the original sliding window ratio based on the preliminary editing distance to obtain the preliminary sliding window ratio includes: Obtain the minimum value of the initial edit distance to get the minimum edit distance; The original sliding window ratio is filtered based on the minimum edit distance to obtain the preliminary sliding window ratio; The step of shrinking the original sliding window ratio based on the preliminary sliding window ratio to obtain the target sliding window ratio includes: Obtain the upper limit value of the original sliding window ratio to get the upper limit value of the sliding window; The upper limit value of the sliding window is replaced based on the preliminary sliding window ratio to obtain the target sliding window ratio.
2. The method according to claim 1, characterized in that, The step of filtering the original sliding window ratio based on the minimum edit distance to obtain the preliminary sliding window ratio includes: Obtain the initial sliding window segment with the minimum edit distance to obtain candidate sliding window segments; Obtain the number of candidate sliding window segments for each of the original sliding window ratios; The original sliding window ratio is filtered based on the number of segments to obtain the preliminary sliding window ratio.
3. The method according to claim 2, characterized in that, The step of calculating the edit distance of the original text segment based on the target sliding window ratio and the reference text to obtain the target edit distance includes: The target sliding window size is obtained by calculating the sliding window size based on the text length and the target sliding window ratio. The original text fragment is slid over the base text at the target sliding window size to obtain the target sliding window fragment; The edit distance between the target sliding window segment and the original text segment is calculated to obtain the target edit distance.
4. A text alignment device, characterized in that, The device includes: The text acquisition module is used to acquire the text to be aligned and the preset reference text; wherein, the text to be aligned includes: the original text fragment; The sliding window ratio calculation module is used to calculate the sliding window ratio based on the text length of the original text segment to obtain the original sliding window ratio. The preliminary calculation module is used to calculate the edit distance of the original text segment based on the original sliding window ratio and the reference text, so as to obtain the preliminary edit distance; The preliminary screening module is used to filter the original sliding window ratio based on the preliminary editing distance to obtain a preliminary sliding window ratio. The shrinking module is used to shrink the original sliding window ratio based on the preliminary sliding window ratio to obtain the target sliding window ratio; The target calculation module is used to calculate the edit distance of the original text segment based on the target sliding window ratio and the reference text to obtain the target edit distance; The target filtering module is used to perform ratio filtering on the target sliding window ratio based on the target editing distance to obtain the current sliding window ratio; The alignment module is used to align the original text fragment and the reference text according to the current sliding window ratio to obtain the target text; The step of calculating the edit distance of the original text segment based on the original sliding window ratio and the reference text to obtain the preliminary edit distance includes: Based on the original sliding window ratio, the original text fragment is slid across the reference text to obtain a preliminary sliding window fragment; The initial edit distance is obtained by calculating the edit distance between the initial sliding window segment and the original text segment; The step of sliding the original text fragment on the reference text according to the original sliding window ratio to obtain a preliminary sliding window fragment includes: Obtain the text length of the original text fragment; The original sliding window size is obtained by calculating the sliding window size based on the text length and the original sliding window ratio. The original text fragment is slid over the reference text at the original sliding window size to obtain the initial sliding window fragment; The step of filtering the original sliding window ratio based on the preliminary editing distance to obtain the preliminary sliding window ratio includes: Obtain the minimum value of the initial edit distance to get the minimum edit distance; The original sliding window ratio is filtered based on the minimum edit distance to obtain the preliminary sliding window ratio; The step of shrinking the original sliding window ratio based on the preliminary sliding window ratio to obtain the target sliding window ratio includes: Obtain the upper limit value of the original sliding window ratio to get the upper limit value of the sliding window; The upper limit value of the sliding window is replaced based on the preliminary sliding window ratio to obtain the target sliding window ratio.
5. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the text alignment method according to any one of claims 1 to 4.
6. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the text alignment method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Text pair fusion method and device
CN110825863A
Ultrasonic guided wave signal temperature compensation method based on sliding window dynamic time sequence alignment
CN115184474A