Text comparison method and device, electronic equipment, medium and product
By using difference analysis of index items and comparison items in text comparison, the accuracy problem of text comparison tools when the content order is inconsistent is solved, and efficient and accurate comparison is achieved when the text record order is different.
Patent Information
- Application Number
- CN202511264384.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-05
- Publication Date
- 2025-12-19
AI Technical Summary
Existing text comparison tools cannot accurately handle situations where the content order of two texts is inconsistent, leading to inaccurate comparison results.
By obtaining the index and comparison items of the text, determining the differences between the index and comparison items according to preset rules, establishing a mapping relationship between text records, realizing logical record comparison, and improving comparison accuracy.
It can efficiently and accurately compare texts when the order of the text records is different, thus improving the accuracy and efficiency of the comparison results.
Smart Images

Figure CN121168439A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of artificial intelligence, and in particular to a text comparison method and device, an electronic device, a medium and a product. BACKGROUND
[0002] Text data comparison is a common requirement in data processing and verification, especially in system migration, data synchronization, version control and other scenarios.
[0003] The existing text comparison tools often directly compare each line when comparing the contents of two texts. When the contents of the two texts are consistent but the recording order of the contents is inconsistent, the text comparison result will show that there are many differences, and the comparison result is not accurate.
[0004] Therefore, how to accurately compare texts is a problem to be solved in the industry. SUMMARY
[0005] The present application provides a text comparison method, device, electronic device, medium and product to accurately compare texts.
[0006] In a first aspect, the present application provides a text comparison method, comprising:
[0007] Obtaining a first text and a second text, and determining an index item and at least one comparison item corresponding to each line in the first text and the second text according to a preset comparison rule; the index item is used to uniquely identify the line where the index item is located;
[0008] Comparing the index item differences of the first text and the second text, and comparing the comparison item differences of the first text and the second text under the same index item to obtain a comparison result.
[0009] In a second aspect, the present application provides a text comparison device, comprising:
[0010] A determination module is configured to obtain a first text and a second text, and determine an index item and at least one comparison item corresponding to each line in the first text and the second text according to a preset comparison rule; the index item is used to uniquely identify the line where the index item is located;
[0011] A comparison module is configured to compare the index item differences of the first text and the second text, and compare the comparison item differences of the first text and the second text under the same index item to obtain a comparison result.
[0012] In a third aspect, the present application provides an electronic device, comprising a processor and a memory in communication with the processor;
[0013] The memory stores computer execution instructions;
[0014] The processor executes the computer-executed instructions stored in the memory to implement the method as described above.
[0015] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executed instructions, and the computer-executed instructions are executed by a processor to implement the method as described above.
[0016] In a fifth aspect, the present application provides a computer program product, comprising a computer program, and the computer program is executed by a processor to implement the method as described above.
[0017] The text comparison method, device, electronic equipment, medium and product provided by the present application can determine the index item and at least one comparison item corresponding to each line in the first text and the second text according to the preset comparison rule, uniquely identify the lines of the text through the index item, and represent the line records of the text through the comparison item, so that the mapping relationship between the records of the first text and the second text can be established, and the physical line comparison is upgraded to logical record comparison; by comparing the index item difference and the comparison item difference under the same index item of the first text and the second text, the comparison of the two text files can be efficiently and accurately performed when the record orders of the two text files are different. BRIEF DESCRIPTION OF DRAWINGS
[0018] The accompanying drawings, which are incorporated herein and constitute part of the specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0019] Figure 1 A flowchart of a text comparison method provided by an embodiment of the present application is shown in the figure.
[0020] Figure 2 A structural diagram of a text comparison device provided by an embodiment of the present application is shown in the figure.
[0021] Figure 3 A structural diagram of an electronic equipment provided by an embodiment of the present application is shown in the figure.
[0022] The specific embodiments of the present application have been shown in the above-described figures, and will be described in more detail hereinafter. These figures and textual descriptions are not intended to limit the scope of the concept of the present application by any means, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0023] The exemplary embodiments will be described in detail herein with reference to the attached drawings. In the following description, like reference numerals refer to like elements, unless the context clearly dictates otherwise. The following description of exemplary embodiments is not intended to represent all embodiments in accordance with the present application. Rather, they are merely examples in accordance with some aspects of the present application as detailed in the appended claims.
[0024] The exemplary embodiments will be described in detail herein with reference to the attached drawings. In the following description, like reference numerals refer to like elements, unless the context clearly dictates otherwise. The following description of exemplary embodiments is not intended to represent all embodiments in accordance with the present application. Rather, they are merely examples in accordance with some aspects of the present application as detailed in the appended claims.
[0025] It should be noted that the text comparison method, device, electronic equipment, medium and product provided by the present application can be used in the field of artificial intelligence, and can also be used in any field other than artificial intelligence. The application field of the text comparison method, device, electronic equipment, medium and product of the present application is not limited.
[0026] Text data comparison is a common requirement in data processing and verification, especially in system migration, data synchronization, version control and other scenarios.
[0027] For example, in the process of database localization transformation, when migrating the original database to a domestic database, it is necessary to verify whether the text data (such as reports and export files) generated by the application program after migration is consistent with that before migration.
[0028] In the financial industry, in bank or securities systems, the consistency of transaction reconciliation files generated by multiple channels (such as fixed-length UnionPay files) needs to be checked daily.
[0029] In the software testing and version release scenario, it is necessary to test whether the output files (such as CSV logs) generated by the new version of software are compatible with the old version.
[0030] In the cross-system scenario, when heterogeneous systems interact with data through files, it is necessary to ensure the consistency of data between the two parties.
[0031] The existing text comparison tools often directly compare line by line when comparing the contents of two texts. When the contents of the two texts are consistent but the recording order of the contents is different, the text comparison result will show that there are a large number of differences, and the comparison result is not accurate.
[0032] Therefore, how to accurately compare texts is a problem that needs to be solved in the industry.
[0033] The text comparison method, device, electronic equipment, medium and product provided in the application aim to solve the above technical problems of the prior art. In the text comparison process, as long as the corresponding records exist in both texts, even if the order and position of the records are different, the comparison is considered consistent. Compared with the direct comparison method without logic in the prior art, the text can be accurately compared.
[0034] The technical solutions of the application and how the technical solutions of the application solve the above technical problems will be described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes can not be described again in some embodiments. The embodiments of the application will be described below with reference to the drawings.
[0035] Figure 1 The flowchart of the text comparison method provided in the embodiments of the application is shown in FIG. 1. Figure 1 As shown in the figure, the method comprises the following steps.
[0036] S101, obtaining a first text and a second text, and determining, according to a preset comparison rule, an index item and at least one comparison item corresponding to each row in the first text and the second text; the index item is used to uniquely identify the row where the index item is located.
[0037] Optionally, the two text files to be compared can be taken as a file group, and a corresponding comparison rule is set for each file group. The comparison rules of different file groups can be different, so that the comparison of the text content can be flexibly performed.
[0038] Optionally, the index items of the first text and the second text can be primary keys of the first text and the second text, and the comparison items of the first text and the second text can be field values of each primary key.
[0039] Optionally, the index items of the first text and the second text can be unique keys of the first text and the second text, and the comparison items of the first text and the second text can be field values of each unique key.
[0040] S102, comparing the differences of the index items of the first text and the second text, and comparing the differences of the comparison items of the first text and the second text under the same index item, to obtain a comparison result.
[0041] Optionally, the comparison result file can be generated in file granularity, and the line comparison result is written in the comparison result file according to the index item, so as to quickly locate the text problem of the user and improve the processing efficiency.
[0042] For example, the A file and the a file are defined as a comparison group, and after comparison of the comparison group, a comparison result file is generated to store the differences between the A file and the a file.
[0043] If the index item 1 exists in the file A and does not exist in the file a, the file A. index item 1 does not exist in the file a is recorded in the comparison result file. If the index item 2 exists in the file A and the file a, and the comparison item value corresponding to the index item 2 in the file A is inconsistent with the comparison item value corresponding to the index item 2 in the file a, the file A. index item 1. comparison item is not equal to the file a. index item 1. comparison item is recorded in the comparison result file.
[0044] Optionally, the above steps can be repeatedly performed for multiple comparison groups to achieve batch efficient comparison of multiple groups of texts.
[0045] In the embodiments of the present application, according to the preset comparison rule, the index item and the at least one comparison item corresponding to each row in the first text and the second text are determined, the rows of the text are uniquely identified through the index item, and the mapping relationship between the records of the first text and the second text is established through the comparison item, which upgrades the comparison of physical rows to the comparison of logical records; by comparing the index item difference and the comparison item difference under the same index item of the first text and the second text, the comparison of the texts can be efficiently and accurately performed when the record orders of the two text files are different.
[0046] On the basis of the above embodiments, the comparison rule can be flexibly configured according to actual needs. In some embodiments, the comparison rule includes: the index item and the at least one comparison item are obtained according to a preset length; or, the index item and the at least one comparison item are obtained according to a separator.
[0047] In a specific implementation, each file group to be compared is configured with a corresponding comparison rule in advance. Each comparison rule includes the file name of the first file, the file name of the second file, and the acquisition rule of the index item and the comparison item. The first file is used to store the first text, and the second file is used to store the second text.
[0048] In a possible implementation, the acquisition rule of the index item and the comparison item can be that the index item and the at least one comparison item are obtained according to a preset length.
[0049] Optionally, the lengths of the index item and the comparison item can be different, and the lengths of different comparison items can also be different. The length of each index item and each comparison item can be flexibly set according to the actual text type or comparison needs.
[0050] Optionally, when the acquisition rule of the index item and the comparison item is that the index item and the at least one comparison item are obtained according to a preset length; the comparison rule further includes: the start point and the end point of the index item and the at least one comparison item, or the length of the index item and the at least one comparison item.
[0051] According to the start point and the end point of the index item and the at least one comparison item or the length of the index item and the at least one comparison item, each line of the first text and the second text can be divided into the index item and the at least one comparison item.
[0052] It can be understood that the division of the index item and the comparison item in each line of the first text and the second text is the same, so that the index item and the comparison item in different lines of the first text and the second text can be compared.
[0053] For example, the comparison rule can include:
[0054] File group number: 1;
[0055] First file name: A.bin;
[0056] Second file name: a.bin;
[0057] Acquisition rule of the index item and the comparison item: fixed length;
[0058] Start point and end point of the index item: 1, 10;
[0059] Start point and end point of the comparison item 1: 11, 15;
[0060] Start point and end point of the comparison item 2: 16, 17;
[0061] Start point and end point of the comparison item 3: 18, 26;
[0062] Start point and end point of the comparison item 4: 27, 30.
[0063] For example, the comparison rule can further include:
[0064] File group number: 1;
[0065] First file name: A.bin;
[0066] Second file name: a.bin;
[0067] Acquisition rule of the index item and the comparison item: fixed length;
[0068] Length of the index item: 10;
[0069] Length of the comparison item 1: 5;
[0070] Length of the comparison item 2: 2;
[0071] Length of the comparison item 3: 9;
[0072] Length of the comparison item 4: 4.
[0073] In a possible implementation, the obtaining rule of the index item and the contrast item can be that the index item and the at least one contrast item are obtained according to the delimiters.
[0074] The delimiters can include, but are not limited to, line breaks, paragraph marks (such as commas, periods), or other logical delimiters for organizing text in a document.
[0075] In the embodiments of the present application, the index item and the contrast item obtained in the fixed-length or delimiter manner are supported, and the contrast rule is flexible and can be adapted to various text types.
[0076] In some embodiments, the difference between the index items of the first text and the second text is contrasted, including:
[0077] The first index item and the second index item are determined by contrasting the respective index items of the first text and the second text; wherein the first text contains the first index item and does not contain the second index item, and the second text contains the second index item and does not contain the first index item.
[0078] In a specific implementation, by contrasting the index items in the first text with the index items in the second text, the index items not contained by each other in the first text and the second text can be determined, that is, the first index item contained by the first text but not contained by the second text, and the second index item contained by the second text but not contained by the first text, so as to determine the row record missing in the first text and the second text.
[0079] In a possible implementation, the difference between the contrast items of the first text and the second text under the same index item is contrasted, including:
[0080] The third index item is determined, which is an index item contained by both the first text and the second text.
[0081] For the third index item, a first contrast item corresponding to the third index item in the first text is obtained, and a second contrast item corresponding to the third index item in the second text is obtained.
[0082] The difference between the first contrast item and the second contrast item is determined.
[0083] In a specific implementation, after the third index item contained by both the first text and the second text is determined, each first contrast item value corresponding to the third index item in the first text can be contrasted with each first contrast item value corresponding to the third index item in the second text, so that the field value difference of the row record in the first text and the second text can be determined.
[0084] In the embodiments of the present application, by contrasting the index item missing and the contrast item difference of the first text and the second text, the row record level difference and the field level difference of the first text and the second text can be determined, and the contrast of the text can be accurately and clearly implemented.
[0085] In some embodiments, the first text and the second text are obtained, including:
[0086] loading the first text and the second text into memory;
[0087] determining, according to a preset comparison rule, an index item and at least one comparison item corresponding to each line in the first text and the second text, including:
[0088] parsing, according to the comparison rule, the memory object of the first text and the memory object of the second text to determine the index item and the at least one comparison item corresponding to each line in the first text and the second text;
[0089] storing the parsed first text and the parsed second text as a memory object in memory respectively, and storing the index item and the at least one comparison item corresponding to each line as a sub-object of the memory object.
[0090] In a specific implementation, the first file and the second file to be compared are stored in different file directories, the first file stores the first text, and the second file stores the second text. The first file, the second file, and the corresponding comparison rule are loaded into memory respectively, and the first file and the second file are parsed according to the comparison rule, and each line of the first file and the second file is divided to obtain the index item and the at least one comparison item. The parsed first file and the parsed second file are stored as a memory object in memory, wherein each memory object includes a plurality of sub-objects, and each sub-object is used to store the index item and the comparison item corresponding to a line of the text.
[0091] When comparing the first file and the second file, the index item stored in each sub-object in the memory object corresponding to the first file can be compared with the index item stored in each sub-object in the memory object corresponding to the second file to determine the difference between the index items of the first file and the second file. For the index item involved in both the first file and the second file, the comparison item value in the sub-object of the first file corresponding to the index item and the comparison item value in the sub-object of the second file corresponding to the index item are obtained and compared to determine the difference between the comparison items of the first text and the second text under the same index item, so that the comparison of the texts is efficiently and orderly performed.
[0092] The above is a text comparison method provided by the embodiments of the present application. Figure 2 The structure of the text comparison device provided by the embodiments of the present application is shown in the figure. Figure 2 As shown in the figure, the method includes:
[0093] The determining module 21 is configured to acquire the first text and the second text, and determine an index item and at least one comparison item corresponding to each line in the first text and the second text according to a preset comparison rule; the index item is used to uniquely identify the line where the index item is located.
[0094] The comparison module 22 is configured to compare the index item difference between the first text and the second text, and compare the comparison item difference between the first text and the second text under the same index item, to obtain a comparison result.
[0095] It should be noted that the text comparison device is used to perform the text comparison method as described above, and the specific implementation manner can refer to the method embodiments provided in the embodiments of the present application, which will not be described here.
[0096] Figure 3 A structural schematic diagram of an electronic device provided in the embodiments of the present application is shown in FIG. 1. Figure 3 As shown in FIG. 1, the electronic device includes:
[0097] The electronic device further includes a processor 291, a memory 292, a communication interface 293 and a bus 294. The processor 291, the memory 292 and the communication interface 293 can communicate with each other through the bus 294. The communication interface 293 can be used for information transmission. The processor 291 can call the logical instructions in the memory 292 to execute the method of the above-mentioned embodiments.
[0098] In addition, the logical instructions in the memory 292 described above can be implemented in the form of a software function unit and sold or used as an independent product, which can be stored in a computer readable storage medium.
[0099] The memory 292 as a computer readable storage medium can be used to store software programs, computer executable programs, such as program instructions / modules corresponding to the method in the embodiments of the present application. The processor 291 executes the functions and data processing by running the software programs, instructions and modules stored in the memory 292, that is, implements the method in the above-mentioned method embodiments.
[0100] The memory 292 can include a program storage area and a data storage area, wherein the program storage area can store an operating system and at least one application required by a function; the data storage area can store data created according to the use of the terminal device, etc. In addition, the memory 292 can include a high-speed random access memory, and can also include a non-volatile memory.
[0101] The embodiment of the present application provides a kind of non-transitory computer readable storage medium, the computer readable storage medium has computer execution instruction, the computer execution instruction is executed by processor when for realizing the method as described in the foregoing embodiments of the present application.
[0102] The embodiment of the present application provides a kind of computer program product, including computer program, computer program is executed by processor when realizing the method provided in any embodiment of the present application.
[0103] It should be noted that, for the foregoing method embodiments, in order to simply describe, it is expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited to the order of the described actions, because according to the present application, certain steps can be performed in other order or simultaneously.Secondly, those skilled in the art should know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0104] Further need to be explained is that although each step in the flow chart is displayed in turn according to the indication of arrow, these steps are not necessarily executed in turn according to the order indicated by arrow. Unless explicitly stated in this paper, the execution of these steps has no strict order limit, and these steps can be executed in other order. Moreover, at least part of the steps in the flow chart can include multiple sub-steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily sequential, but can be executed alternately or alternately with other steps or sub-steps or stages of other steps.
[0105] It should be understood that the above-mentioned device embodiment is only schematic, and the device of the present application can also be realized by other ways.For example, the division of units / modules in the above embodiments is only a logical function division, and another division method can be used in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0106] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application can be integrated in one unit / module, or each unit / module can exist physically, or two or more units / modules can be integrated together. The above integrated unit / module can be realized in the form of hardware or in the form of software program module.
[0107] If the integrated units / modules are implemented in the form of hardware, the hardware can be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor can be any appropriate hardware processor, such as a CPU, a GPU, an FPGA, a DSP, an ASIC, etc. Unless otherwise specified, the storage unit can be any appropriate magnetic storage medium or magneto-optical storage medium, such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), etc.
[0108] If the integrated units / modules are implemented in the form of software program modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the essential part or all or part of the technical solutions that make contributions to the prior art can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the embodiments of the present application. The aforementioned storage medium includes a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0109] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described, but as long as the combination of the technical features does not exist contradictory, it should be considered as the scope of the present application.
[0110] Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. It is intended that the specification and examples be considered as exemplary only, with the true scope and spirit of the application being indicated by the following claims.
[0111] It is to be understood that the application is not limited to the precise construction herein disclosed and shown in the drawings, and that various modifications and changes can be made by those skilled in the art without departing from the scope of the application. The scope of the application is limited only by the claims that follow.
Claims
1. A text comparison method, characterized in that, include: Obtain the first text and the second text, and determine the index item and at least one comparison item corresponding to each line in the first text and the second text according to the preset comparison rules; The index entry is used to uniquely identify the row in which the index entry is located; The comparison results are obtained by comparing the differences in index entries between the first text and the second text, and by comparing the differences in comparison entries under the same index entry between the first text and the second text.
2. The method according to claim 1, characterized in that, The comparison rules include: dividing the index item and the at least one comparison item according to a preset length; or dividing the index item and the at least one comparison item according to a separator.
3. The method according to claim 2, characterized in that, The comparison rule includes dividing the index item and the at least one comparison item according to a preset length; the comparison rule also includes: the starting point and ending point of the index item and the at least one comparison item, or the length of the index item and the at least one comparison item.
4. The method according to claim 1, characterized in that, The comparison of the index differences between the first text and the second text includes: By comparing the index entries of the first text and the second text, a first index entry and a second index entry are determined; wherein the first text contains the first index entry but does not contain the second index entry, and the second text contains the second index entry but does not contain the first index entry.
5. The method according to claim 1, characterized in that, The comparison of the differences between the first text and the second text under the same index item includes: Determine a third index item, which is an index item contained in both the first text and the second text; For the third index item, obtain the first comparison item corresponding to the third index item in the first text, and obtain the second comparison item corresponding to the third index item in the second text; Determine the differences between the first comparison item and the second comparison item.
6. The method according to any one of claims 1-5, characterized in that, The acquisition of the first text and the second text includes: Load the first text and the second text into memory; The step of determining the index item and at least one comparison item corresponding to each line in the first text and the second text according to the preset comparison rules includes: According to the comparison rules, the first text and the second text are parsed to determine the index item and at least one comparison item corresponding to each line in the first text and the second text. The parsed first text and second text are stored in memory as memory objects, and the index item and at least one comparison item corresponding to each line are stored as sub-objects of the memory objects.
7. A text comparison device, characterized in that, include: The determination module is used to acquire a first text and a second text, and determine the index item and at least one comparison item corresponding to each line in the first text and the second text according to a preset comparison rule; the index item is used to uniquely identify the line where the index item is located. The comparison module is used to compare the differences in index terms between the first text and the second text, and to compare the differences in comparison terms between the first text and the second text under the same index terms, so as to obtain the comparison results.
8. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 6.
10. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 6.