Translation error correction method, electronic device and storage medium based on AC automaton algorithm

By applying the AC automatic machine algorithm and Trie file in the offline translation pen, the translation of poor translation due to the CPU computing power and memory limit is solved, and the rapid and accurate error correction of the scanning text is achieved.

CN118798217BActive Publication Date: 2025-01-28深圳市云希谷科技有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411268252.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2025-01-28
Estimated Expiration
2044-09-11

Smart Images

  • Figure CN118798217B_ABST
    Figure CN118798217B_ABST
Patent Text Reader

Abstract

The present invention proposes a translation error correction method, electronic device and storage medium based on AC automaton algorithm, wherein a terminal device pre-constructs a translation error correction table, the translation error correction table includes original text, erroneous translation and correct translation, a trie file stored in a preset folder of the terminal device is generated according to the original text and a preset vocabulary list, a scanned text to be translated is matched based on the AC automaton algorithm and the trie file, a matching result is quickly obtained, and the erroneous translation corresponding to the scanned text is replaced with a correct translation according to the translation error correction table and the matching result. The problem that the existing offline translation pen cannot effectively translate the scanned text due to CPU computing power and memory limitations can be solved, and fast and accurate matching and error correction can be achieved through the AC automaton algorithm and the constructed trie file, which can avoid the erroneous translation from being unable to be matched.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a translation error correction method, electronic equipment and storage medium based on an AC automaton algorithm, and belongs to the technical field of translation error correction. Background Art

[0002] In offline translation pens, local translation algorithms are usually configured to translate texts. However, due to the limitations of the CPU computing power and memory of the offline scanning pen, the local translation algorithms often produce unsatisfactory translation results, which are usually reflected in the direct translation of texts.

[0003] For example, when scanning the text content of an English textbook, the translation of many English sentences in the textbook is often different from the normal translation. For example, the translation of Listen and number in the textbook is "Listen and write the serial number", while the offline scanner based on the local translation algorithm will directly translate it as "Listen and number"; when the text to be translated is some proverbs, such as Seeing is believing, it will be directly translated as "Seeing is convincing", while the normal translation is "Seeing is believing".

[0004] For this type of erroneous translation, the conventional approach is to match the text to be translated with a pre-built translation error correction table, and correct it if a match is found. However, if there are other characters before or after the text, it may not match. Summary of the invention

[0005] In view of the above-mentioned deficiencies in the prior art, the purpose of the present invention is to provide a translation error correction method, electronic device and storage medium based on the AC automaton algorithm, which can solve the problem that the existing offline translation pen is unable to effectively translate the scanned text due to the limitations of CPU computing power and memory. Through the AC automaton algorithm and the constructed trie file, fast and accurate matching and error correction can be achieved, which can avoid the inability of erroneous translations to be matched.

[0006] According to an implementation scheme of the present invention, a first scheme is provided: a translation error correction method based on an AC automaton algorithm, applied to a terminal device, comprising: constructing a translation error correction table, the translation error correction table comprising an original text, an erroneous translation and a correct translation; generating a trie file according to the original text and a preset vocabulary list, the trie file storing a trie tree; matching a scanned text to be translated based on the AC automaton algorithm and the trie file to obtain a corresponding matching result; and replacing the erroneous translation corresponding to the scanned text with the correct translation according to the translation error correction table and the matching result.

[0007] Further, as a more preferred implementation scheme of the present invention, the generating of the trie file according to the original text and the preset vocabulary list includes: performing sentence reading processing on the original text to obtain sentences to be arranged; performing word segmentation processing on the sentences to be arranged to obtain words to be arranged; constructing a trie tree according to the words to be arranged and the vocabulary list, wherein the nodes of the trie tree correspond one-to-one to the words to be arranged; and sequentially adding mismatch pointers to all nodes of the trie tree;

[0008] The node information of all nodes of the trie tree after adding the mismatch pointer is updated; the node index value of all nodes of the trie tree with updated node information is updated; the trie tree after updating the node index value is recursively traversed based on the breadth-first algorithm to obtain a trie file.

[0009] Further, as a more preferred implementation scheme of the present invention, the trie tree is constructed according to the word to be arranged and the new word list, including: obtaining the character length of the word to be arranged; if the character length is greater than a preset length, obtaining the corresponding identification information in the new word list according to the word to be arranged, and querying whether the child node of the current node has the identification information; if so, updating the child node of the current node with the identification information to the current node; if not, inserting the identification information as a new child node of the current node and updating it to the current node.

[0010] Further, as a more preferred implementation scheme of the present invention, if the character length is less than a preset length, the child nodes of the current node of the trie tree are queried according to the word to be arranged to query whether the child nodes of the current node have the word to be arranged; if so, the child node of the current node that has the word to be arranged is updated to the current node; if not, the word to be arranged is inserted as a new child node of the current node and updated to the current node.

[0011] Furthermore, as a more preferred implementation scheme of the present invention, it also includes: if the word to be arranged does not exist in the new word list, inserting the word to be arranged into the new word list, and configuring identification information in the new word list.

[0012] Furthermore, as a more preferred implementation scheme of the present invention, the updating of node information of all nodes of the trie tree after adding the mismatch pointer includes: recursively traversing the trie tree based on a breadth-first algorithm to obtain the number of child nodes of the current node; creating a corresponding node array at the current node according to the number of child nodes; looping through several child nodes of the current node, determining the array element corresponding to the child node according to the hash value of the word to be arranged corresponding to the child node and the number of child nodes; and determining the node information of the child node according to the array element.

[0013] Further, as a more preferred implementation scheme of the present invention, determining the node information of the child node based on the array element includes: if the array element is empty, determining that the array element is the node information of the child node; if the array element is not empty, obtaining a preset node position value of the child node, and determining the node information of the child node based on the node position value.

[0014] Further, as a more preferred implementation scheme of the present invention, the AC automaton algorithm and the trie file are matched with the scanned text to be translated to obtain the corresponding matching result, including: performing word segmentation processing on the scanned text to be translated to obtain a plurality of words to be scanned; performing matching operations on the plurality of words to be scanned in turn based on the AC automaton algorithm, and the matching operations include: calculating the hash value of the word to be scanned; obtaining the index value to be searched according to the hash value of the word to be scanned and the number of child nodes of the current node of the trie tree; determining the corresponding child node according to the index value to be searched and the node index value of the child node; if the word to be arranged corresponding to the child node is the same as the word to be scanned, returning the matching result.

[0015] According to an implementation scheme of the present invention, a second scheme provided by utilizing the first scheme provided by the present invention is: an electronic device, comprising: at least one processor, and a memory communicatively connected to the at least one processor; wherein the memory stores instructions, and the instructions are executed by the at least one processor, so that when the at least one processor executes the instructions, the translation error correction method based on the AC automaton algorithm as described in the first scheme is implemented.

[0016] According to an embodiment of the present invention, a third solution provided by utilizing the first solution provided by the present invention is: a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, wherein the computer-executable instructions are used to enable a computer to execute the translation error correction method based on the AC automaton algorithm as described in the first solution.

[0017] Compared with the prior art, the technical solution provided by the present invention is applied to a translation error correction method based on an AC automaton algorithm of a terminal device, wherein the terminal device pre-constructs a translation error correction table, the translation error correction table includes an original text, an erroneous translation and a correct translation, a trie file stored in a preset folder of the terminal device is generated based on the original text and a preset vocabulary list, a scanned text to be translated is matched based on the AC automaton algorithm and the trie file, a matching result is quickly obtained, and the erroneous translation corresponding to the scanned text is replaced with a correct translation based on the translation error correction table and the matching result. The problem that the existing offline translation pen cannot effectively translate the scanned text due to CPU computing power and memory limitations can be solved, and fast and accurate matching and error correction can be achieved through the AC automaton algorithm and the constructed trie file, which can avoid the erroneous translation from being unable to be matched. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 A flowchart of a translation error correction method based on an AC automaton algorithm in the present invention;

[0019] Figure 2 A flowchart of step S200 in the translation error correction method based on the AC automaton algorithm of the present invention;

[0020] Figure 3 A flowchart of step S230 in the translation error correction method based on the AC automaton algorithm of the present invention;

[0021] Figure 4 A flowchart of step S250 in the translation error correction method based on the AC automaton algorithm of the present invention;

[0022] Figure 5 A flowchart of step S300 in the translation error correction method based on the AC automaton algorithm of the present invention;

[0023] Figure 6 A specific example diagram of the translation error correction method based on the AC automaton algorithm in the present invention;

[0024] Figure 7 FIG. 4 is another specific example diagram of the translation error correction method based on the AC automaton algorithm in the present invention. DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0026] All other embodiments obtained under the premise of creative work shall fall within the scope of protection of the present invention.

[0027] It should be noted that a logical sequence is shown in the flow chart, but in some cases, the steps shown or described can be performed in the order in different flow charts. If it is related to "several", its meaning is more than one, if it is related to "multiple", its meaning is more than two, if it is related to "below", it should be understood to include this number. The use of any and all examples or exemplary language ("for example", "such as", etc.) provided herein is only intended to better illustrate the embodiments of the application, and unless otherwise required, the scope of the application will not be limited.

[0028] It should be noted that, unless otherwise specified, the singular forms of "a", "said" and "the" used in the embodiments are also intended to include plural forms, unless the context clearly indicates other meanings. In addition, unless otherwise defined, all technical and scientific terms used herein have the same meanings as those generally understood by those skilled in the art. The terms used in this specification are only for describing specific embodiments, not for limiting this application. The term "and / or" used herein includes any combination of one or more related listed items.

[0029] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features.

[0030] In a first embodiment, the present invention provides a translation error correction method based on an AC automaton algorithm and applied to a terminal device.

[0031] It should be noted that the terminal device mentioned in the present invention is a terminal device with a translation function, such as the offline translation pen mentioned in the background technology, and the terminal device has CPU computing power and a certain amount of memory (RAM), and the terminal device has a preset folder in which the generated trie file can be stored. At this time, the trie file is not stored in the memory, but in the ROM of the terminal device.

[0032] The AC automaton algorithm mentioned in the present invention is the abbreviation of Aho-Corasick automaton, which is an algorithm for string search, which can efficiently find multiple pattern strings / strings in a text. Through this algorithm, the corresponding content can be found in the text. Based on the AC automaton algorithm, this solution optimizes the trie tree accordingly, so that it exists in the form of a file structure and is stored in a folder of a terminal device. During the use of the AC automaton algorithm, the corresponding node is quickly found through file seek.

[0033] In some embodiments, the terminal device pre-builds a translation correction table, which includes the original text, incorrect translations and correct translations. A trie file is generated and stored in a preset folder of the terminal device based on the original text and a preset vocabulary list. The scanned text to be translated is matched based on the AC automaton algorithm and the trie file to quickly obtain a matching result. The incorrect translation corresponding to the scanned text is replaced with a correct translation based on the translation correction table and the matching result.

[0034] In some embodiments, reference Figure 1 The translation error correction method based on the AC automaton algorithm applied to the terminal device of the present invention comprises the steps of:

[0035] S100, constructing a translation error correction table, wherein the translation error correction table includes the original text, the incorrect translation and the correct translation;

[0036] S200, generating a trie file according to the original text and a preset vocabulary list, wherein the trie file stores a trie tree;

[0037] S300, matching the scanned text to be translated based on the AC automaton algorithm and the trie file to obtain a corresponding matching result;

[0038] S400: replacing the erroneous translation corresponding to the scanned text with the correct translation according to the translation error correction table and the matching result.

[0039] In step S100, the terminal device pre-builds a translation error correction table, wherein the translation error correction table includes the original text, the incorrect translation and the correct translation. Specifically, the contents that are easy to be translated incorrectly, such as English teaching materials and proverbs, can be executed once using the existing translation algorithm, and the incorrectly translated data can be extracted to build a translation error correction table, which contains multiple records, each record represents a content, and each record includes three fields: the original text, the incorrect translation and the correct translation.

[0040] In step S200, a trie file is generated according to the original text and the new word list, and the trie file stores the created trie tree, and the new word list is generated by the original text. Specifically, the new word list stores various words, and these words can be generated from several words in the original text, that is, the words in the original text are read, and the new word list is constructed in sequence. At this time, the new word list contains all the words in the original text; in addition, the new word list can also collect commonly used words and be generated based on commonly used words. In a specific application, the new word list can store 5,000 words, and each word has an average of 10 characters, which only takes up 50k of memory. When in use, the trie tree is stored in the trie file, and the new word list can be directly stored in the memory because it takes up less memory. During the operation, it only takes up less than 70K of memory, and the time complexity of the operation is 0 (1). The vocabulary list mentioned in the present invention also includes identification information, which is used to correspond to the nodes in the tire tree. For example, the tire tree node can record the identification information and the words to be arranged. When the identification information is recorded, the node of the tire tree points to the vocabulary list, and the word corresponding to the identification information in the vocabulary list is consistent with the word to be arranged.

[0041] In some embodiments, Figure 2 As shown, step S200 also includes the steps of:

[0042] S210, performing sentence reading processing on the original text to obtain sentences to be arranged;

[0043] S220, performing word segmentation processing on the sentence to be arranged to obtain words to be arranged;

[0044] S230, constructing a trie tree according to the words to be arranged and the new word list, wherein the nodes of the trie tree correspond one-to-one to the words to be arranged;

[0045] S240, adding mismatch pointers to all nodes of the trie tree in sequence;

[0046] S250, updating node information of all nodes of the trie tree after adding the mismatch pointer;

[0047] S260, updating node index values ​​for all nodes of the trie tree whose node information is updated;

[0048] S270, recursively traverse the trie tree after updating the node index value based on breadth-first order to obtain a trie file.

[0049] In step S210, the original text is processed by sentence reading to obtain a sentence to be arranged, and S220 is executed for a sentence to be arranged. In a specific application, the original text has a plurality of sentences to be arranged, and each time the sentence reading process is executed, a sentence to be arranged is obtained, and step S220 is executed for this sentence to be arranged, and after executing steps S220 and S230, the sentence reading process is executed again until this sentence to be arranged is the last sentence to be arranged in the original text. A sentence to be arranged refers to a sentence in the original text that ends with a period, which is defined as a sentence to be arranged.

[0050] It should be noted that after S210 is started to be executed to obtain the first sentence to be arranged, a trie tree is created in the memory, and the current node of the trie tree is set as the root node, and S220 is started to be executed.

[0051] The trie tree created in the memory defines the node data structure placed in the memory as shown in Table 1 below:

[0052] Table 1

[0053]

[0054] In Table 1, the field Is_root indicates whether the node is a root node; the field Is_end indicates whether the node is an end node; the field Word indicates the word to be arranged stored in the node, such as Chinese or words; the field Word_length indicates the length of the word to be arranged of this node; the field Fail_index indicates the node information of the Fail pointer in the mismatch pointer; the field collison_next_index indicates the node information re-determined after the word to be arranged collides; the field Child_count indicates the number of child nodes of this node; the field Child_array indicates the array form formed by the node; the field Child_node_map indicates the key and value of the array, where the key is the word to be arranged and the value is the node.

[0055] In step S220, after obtaining a sentence to be arranged, the sentence to be arranged is segmented to obtain a word to be arranged, and step S230 is performed for one word to be arranged. In a specific application, a sentence to be arranged contains multiple words to be arranged, and each time the segmentation process is performed, a word to be arranged is obtained, and step S230 is performed for the word to be arranged. After executing S230, a new word to be arranged is obtained again, until the last word to be arranged completes S230. At this time, the trie tree is constructed in the memory. It should also be noted that if the sentence to be arranged is in English, the segmentation is performed according to the space, and one English word is one word to be arranged; if it is in Chinese, one Chinese character is one word to be arranged.

[0056] In step S230, a trie tree is constructed according to the words to be arranged and the new word list, and the nodes of the trie tree correspond to the words to be arranged one by one. Among them, each node of the trie tree corresponds to a word to be arranged, that is, the nodes of the trie tree represent a word to be arranged. Specifically, the nodes of the trie tree correspond to the words to be arranged, but when the character length of the word to be arranged exceeds the preset length, the new word list can be introduced. At this time, the nodes of the trie tree can only retain the offset corresponding to the word to be arranged and the new word list, and the nodes of the trie tree point to the corresponding position in the new word list. It should be noted that the conventional trie tree uses letters, that is, one node corresponds to one letter, and the trie tree created in the present invention adopts the form of words, that is, one node corresponds to one word. Through this method, the size of the trie tree can be greatly reduced.

[0057] In some embodiments, Figure 3 As shown, step S230 also includes the steps of:

[0058] S231, obtaining the character length of the word to be arranged;

[0059] S232, if the character length is greater than a preset length, obtaining corresponding identification information in the new word list according to the word to be arranged, and querying whether the child node of the current node has the identification information;

[0060] S2321, if it exists, updating the child node with the identification information in the current node to be the current node;

[0061] S2322: If it does not exist, insert the identification information as a new child node of the current node and update it to the current node.

[0062] S233, if the character length is less than a preset length, querying the child nodes of the current node of the trie tree according to the word to be arranged, and querying whether the child nodes of the current node have the word to be arranged;

[0063] S2331, if it exists, then update the child node of the current node containing the word to be arranged as the current node;

[0064] S2332: If it does not exist, insert the word to be arranged as a new child node of the current node and update it to the current node.

[0065] In steps S231, S232 and S223, the character length of the word to be arranged is obtained, and step S232 or S233 is performed respectively according to the size of the character length. Among them, when the character length is greater than the preset length, the corresponding identification information in the vocabulary list is obtained according to the word to be arranged, and according to the returned identification information, all child nodes of the current node of the trie tree are queried to check whether all child nodes of the current node have corresponding identification information. If so, the child node corresponding to the identification information in the current node is updated to the current node, and step S220 is performed again. If not, the identification information is inserted as a new child node of the current node and the inserted child node is updated to the new current node.

[0066] When the character length is less than the preset length, all child nodes of the current node of the trie tree are queried according to the word to be arranged, and it is queried whether the child node of the current node has the word to be arranged. If it does, the child node corresponding to the word to be arranged in the current node is updated to the current node, and step S220 is performed again. If it does not exist, the word to be arranged is inserted as a new child node of the current node and the inserted child node is updated to the new current node.

[0067] In the application example that may be implemented, the word to be arranged is English as an example for explanation. If the character length of the word to be arranged is greater than the preset length (for example, 3 characters), at this time, the word to be arranged is queried in the new word list, and the identification information corresponding to the word to be arranged in the new word list is queried. The identification information can determine the position of the word to be arranged in the new word list. After returning to obtain the identification information, all child nodes of the current node of the trie tree are traversed and searched according to the identification information to find out whether there is corresponding identification information on any child node. If so, step S2321 is executed, and the child node with identification information is updated to the current child node. After the current node is updated, step S220 is executed again to obtain a new word to be arranged, and step S230 is executed again. If not, step S2322 is executed, and the identification information is inserted as a new child node of the current node, and the inserted child node is updated to the current node. After the current node is updated, step S220 is executed again to obtain a new word to be arranged, and step S230 is executed again.

[0068] If the character length of the word to be arranged is less than the preset length (for example, 3 characters), at this time, all child nodes of the current node of the trie tree are traversed and searched according to the word to be arranged to find whether there is a corresponding word to be arranged on any child node. If so, step S2331 is executed, and the corresponding child node is updated to the current child node. After the current node is updated, step S220 is executed again. After a new word to be arranged is obtained, step S230 is executed. If it does not exist, step S2332 is executed, and the identification information is inserted as a new child node of the current node, and the inserted child node is updated to the current node. After the current node is updated, step S220 is executed again. After a new word to be arranged is obtained, step S230 is executed.

[0069] In some embodiments, if the character length of the word to be arranged is greater than a preset length, the corresponding identification information is obtained from the new word list according to the word to be arranged. If the word to be arranged does not exist in the new word list, that is, the word to be arranged does not exist in the new word list, then the word to be arranged is inserted into the new word list and new identification information is configured for it. The identification information is returned, and the child node of the current node is queried to see whether the new identification information exists. According to whether it exists, S2321 or S2322 is executed.

[0070] After executing step S230, that is, all the sentences to be arranged in the original text have executed S220 and S230 in sequence, at this time, the AC automaton successfully creates a trie tree in the memory. Then, step S240 is started to add mismatch pointers, i.e., fail pointers, to all nodes of the created trie tree in sequence. The trie tree can be traversed in a breadth-first manner to find the correct pointing of the fail pointer of each node's child node.

[0071] To explain adding mismatch pointers, assume that the current node is temp, we find the parent node of temp, get the fail node of the parent node, and then find all the child nodes of the fail node, and find whether there is a node with the same value as the temp node among the child nodes. If there is, the fail node of temp points to the node. If not, continue to look for the fail node of the fail node until a node with the same value is found or the root node is reached. It should be noted that the method of adding mismatch pointers mentioned in the present invention is the conventional construction method in AC automata, and the present invention will not go into details.

[0072] In step S250, the node information of all nodes of the trie tree after adding the mismatch pointer is updated. Specifically, the node information can determine the specific arrangement information of each node in the trie tree.

[0073] In some embodiments, Figure 4 As shown, step S250 also includes the steps of:

[0074] S251, recursively traverse the trie tree based on a breadth-first algorithm to obtain the number of child nodes of the current node;

[0075] S252, creating a corresponding node array at the current node according to the number of child nodes;

[0076] S253, looping through all child nodes of the current node, and determining the array element corresponding to the child node according to the hash of the word to be arranged corresponding to the child node and the number of the child nodes;

[0077] S254: Determine the node information of the child node according to the array element.

[0078] In step S251 to step S254, the trie tree is recursively traversed based on the breadth-first algorithm to obtain the number of child nodes of the current node, wherein the breadth-first algorithm is also called the breadth-first search algorithm, which is an existing algorithm and the present invention does not explain it in detail. After obtaining the number of child nodes, a corresponding node array is created on the current node according to the number of child nodes, and the length of the node array is consistent with the number of child nodes. After the node array is established, all child nodes of the current node are looped, and the array element corresponding to the subscript of the child node placed in the node array is determined based on the hash value of the word to be arranged corresponding to the child node and the number of child nodes. Based on the array element, the node information of the child node is determined, that is, the node position of the current node in the trie tree.

[0079] In practical applications, the trie tree is recursively traversed according to the breadth-first algorithm. The trie tree often has a multi-layer node structure. For example, starting from the root node, the root node is the current node and has several child nodes. After determining the number of child nodes, an array with a length equal to the number of child nodes is created, and the child nodes of the root node are looped to determine the node information of each child node. All the child nodes of the first child node are recursively traversed again to determine the node information of all the child nodes of the first child node. Until all the child nodes of the entire trie tree have updated the node information.

[0080] Determining the array element corresponding to the subscript of the child node in the node array based on the hash value of the word to be arranged corresponding to the child node and the number of child nodes is described. In the present invention, the hash value of the word to be arranged corresponding to the child node is calculated, and the remainder is calculated by dividing the hash value by the number of child nodes, and the array element corresponding to the child node is determined according to the remainder.

[0081] In some embodiments, when the remainder is calculated by dividing the hash value by the number of child nodes, the array element corresponding to the child node is determined according to the remainder, and the node of the child node is determined according to the array element. Specifically, it also includes: if the determined array element is empty, then this array element is directly used as the node information of the child node; if the determined array element is not empty, then the preset node position value of the child node is obtained, and the node information of the child node is determined according to this node position value.

[0082] Specifically, when an array element is empty, it means that there is no other word to be arranged whose hash value and the number of child nodes are the same as the remainder obtained by the remainder of the hash value of the word to be arranged and the number of child nodes, and the array element can be determined as its node information. When an array element is empty, it means that there is any other word to be arranged whose hash value and the number of child nodes are the same as the remainder obtained by the remainder of the hash value of the word to be arranged and the number of child nodes, and at least two words to be arranged collide, so in order to distinguish two words to be arranged, the field collison_next_index in the node data structure mentioned in Table 1 can be used as the node information of the word to be arranged.

[0083] After the node information of the entire trie tree is updated, step S260 is executed to update the node index values ​​of all nodes of the trie tree after the node information is updated, wherein each node has a unique node index value, and the content of the node can be quickly found through the node index value. The offset is calculated as the node index value * 14, where 14 is determined based on the length of the node design.

[0084] The node design of the trie tree after updating the node index value is as shown in Table 2 below, and the data structure placed in the file:

[0085] Table 2

[0086]

[0087] In Table 2, the field Word indicates the Chinese characters or words with a length less than 3 stored in the node. If it is greater than 3, the offset corresponding to the new word list file is stored, pointing to the new word list; the field Is_end indicates whether the node is an end node; the field Word_length indicates the length of the word or Chinese characters stored in the node; the field Fail_index indicates the pointing of the Fail pointer in the mismatch pointer; the field collison_next_index indicates the node to be re-determined after a collision occurs in the words to be arranged; the field Child_count indicates the number of child nodes of this node; the field child_first_index indicates the index value of the first child node in this node.

[0088] In step S270, the trie tree after updating the node index value is recursively traversed based on the breadth-first algorithm to obtain a trie file. Specifically, after the trie tree updates the node index value, the breadth-first algorithm is used to traverse and update it, and the trie tree is sequentially written into the file according to the data structure mentioned in Table 2, until all the nodes of the trie tree are written into the file after recursive traversal, and finally a trie file generated according to the data structure mentioned in Table 2 is obtained. The breadth-first algorithm mentioned in the present invention is an algorithm for traversing or searching a tree or a graph, which visits nodes layer by layer according to the hierarchy of the trie tree or the hierarchy of the graph. This algorithm first visits the starting node, then traverses all the neighboring nodes of the starting node, and then traverses the neighboring nodes of these neighboring nodes that have not been visited, and expands layer by layer until all reachable nodes have been visited. The main feature of the breadth-first algorithm is to start from the starting node and expand outward layer by layer until all reachable nodes are traversed. During the traversal process, it uses a data structure called a queue to save the nodes to be visited. The trie tree for updating the node index value in the present invention is traversed layer by layer using the breadth-first algorithm, and written into the file according to the data structure in Table 2, and finally a trie file is obtained. The trie tree is stored in the form of a file structure, and the corresponding node can be quickly found through the file seek in the process of using the AC automaton algorithm. Therefore, the data structure placed in the file as shown in Table 2 is designed, and the trie file created according to this data structure can store the trie tree, which is convenient for the AC automaton algorithm to quickly locate the child node.

[0089] In steps S300 and S400, the scanned text to be translated is matched based on the AC automaton algorithm and the trie file to obtain the corresponding matching result. Specifically, through the AC automaton algorithm and the trie file, the AC automaton algorithm uses the data source of the original text in the trie file to identify and judge the scanned text, and determines the corresponding matching result, that is, the text content in the scanned text that will be translated as an incorrect translation. At this time, according to the translation error correction table and the matching result, the correct translation corresponding to the incorrect translation is determined, and after replacing it with the correct translation, the scanned text is translated again, thereby ensuring that the scanned text is translated into a correct translation.

[0090] In some embodiments, Figure 5 As shown, step S300 further includes the steps of:

[0091] S310, performing word segmentation processing on the scanned text to be translated to obtain a plurality of words to be scanned;

[0092] S320, performing matching operations on a number of words to be scanned in sequence based on the AC automaton algorithm, the matching operations comprising: calculating a hash value of the word to be scanned; obtaining an index value to be searched according to the hash value of the word to be scanned and the number of child nodes of the current node of the trie tree; determining a corresponding child node according to the index value to be searched and the node index value of the child node; and returning a matching result if the word to be arranged corresponding to the child node is the same as the word to be scanned.

[0093] In step S310 to step S320, the scanned text is segmented to obtain a number of words to be scanned, and matching operations are performed on the words to be scanned in turn based on the AC automatic algorithm, wherein the matching operation is to calculate the hash value of the word to be scanned, and the hash value is modulo the number of child nodes of the current node in the trie number to obtain the index value to be searched, and the search is performed according to the index value to be searched and the node index value originally configured for the child node, so as to find the corresponding child node, and the word to be arranged corresponding to the child node is the same as the word to be scanned, then a matching result of successful matching is returned. If they are not equal, it is determined whether there are other node index values ​​for the index value to be searched, and if so, a recursive search is performed, and if the same word to be arranged and the word to be scanned are found, then a return is made, and if not, a matching result of failed matching is returned.

[0094] In possible application examples, such as Figure 6 As shown, a translation error correction table is pre-built, and a trie file of an AC automaton and a preset vocabulary list are generated based on the translation error correction table. The user scans the text to be translated, and the AC automatic calculation method is used to match the scanned text to be translated to determine whether the text to be translated contains text that needs to be corrected. If so, the translation result is replaced, and if not, no replacement is made.

[0095] For generating the trie file of AC automaton and the preset vocabulary list based on the translation error correction table, in the possible application examples, such as Figure 7As shown, after the translation error correction table is constructed, a sentence to be arranged of the original text in the translation error correction table is read, a word segmentation process is performed for the sentence to be arranged, the current node of the trie tree is set as the root node, and a word to be arranged of the arranged sentence is read in sequence. It is judged whether the word to be arranged is greater than 3 characters. If it is greater than 3 characters, the identification information in the new word table is obtained, and it is returned, inserted into the trie tree, and the identification information is searched in the child node of the current node of the trie tree according to the identification information to see whether the identification information exists. If there is no corresponding identification information or word to be arranged in the new word table, it is inserted into the new word table, new identification information is configured, and new identification information is returned. If it exists, the identification information is inserted as a new child node in the current node of the trie tree, and the current node of the trie tree is updated as this child node; if it is less than 3 characters, the child node of the current node of the trie tree is searched according to the word to be arranged to see whether the word to be arranged exists. If it exists, the word to be arranged is inserted as a new child node in the current node of the trie tree, and the current node of the trie tree is updated as this child node. Determine whether it is the last word to be arranged. If not, return to the previous step and continue word segmentation. If so, determine whether it is the last sentence to be arranged. If not, return to the previous step and continue reading the sentence. If so, the trie tree of the AC automaton is created. Traverse all nodes, add mismatch pointers, update the array elements of all nodes, update the index (node ​​index value) of all nodes, and write the trie tree to the trie file in index order, thereby completing the generation of the trie file and the vocabulary list.

[0096] In the translation error correction method based on the AC automaton algorithm provided by the present invention, a translation error correction table is pre-constructed, and the translation error correction table includes an original text, an erroneous translation and a correct translation. A trie file stored in a preset folder of a terminal device is generated according to the original text and a preset vocabulary list. The scanned text to be translated is matched based on the AC automaton algorithm and the trie file to quickly obtain a matching result. The erroneous translation corresponding to the scanned text is replaced with a correct translation according to the translation error correction table and the matching result. This can solve the problem that the existing offline translation pen is unable to effectively translate the scanned text due to CPU computing power and memory limitations. The AC automaton algorithm and the constructed trie file are used to achieve fast and accurate matching and error correction, which can avoid the inability of erroneous translations to be matched.

[0097] In a second embodiment, the present invention further provides an electronic device, comprising: at least one processor, and a memory communicatively connected to the at least one processor;

[0098] The processor is used to execute the translation error correction method based on the AC automaton algorithm applied to the controller in the second embodiment by calling the computer program stored in the memory.

[0099] The memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer executable programs, such as the AC automaton algorithm-based translation error correction method applied to the controller in the second embodiment of the present application. The processor implements the AC automaton algorithm-based translation error correction method applied to the controller in the second embodiment of the above-mentioned solution by running the non-transitory software program and instructions stored in the memory.

[0100] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store a translation error correction method based on an AC automaton algorithm applied to a controller in the above-mentioned second embodiment. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0101] The non-transient software program and instructions required to implement the translation error correction method based on the AC automaton algorithm applied to the controller in the above-mentioned second embodiment are stored in the memory. When executed by one or more processors, the translation error correction method based on the AC automaton algorithm applied to the controller in the above-mentioned second embodiment is executed.

[0102] In a third solution, the present invention further provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are used to: execute the translation error correction method based on the AC automaton algorithm applied to the controller in the embodiment of the second solution;

[0103] In some embodiments, the computer-readable storage medium stores computer-executable instructions, which are executed by one or more control processors, for example, by a processor in an electronic device of the third embodiment, so that the one or more processors can execute the translation error correction method based on the AC automaton algorithm applied to the controller in the second embodiment.

[0104] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0105] It will be appreciated by those skilled in the art that all or some of the steps and systems in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or transient medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.

[0106] The above description of the disclosed embodiments enables professionals and technicians in the field to implement or use the present invention. It will be apparent to professionals and technicians in the field that various modifications to these embodiments, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but will meet the widest scope consistent with the principles and novel features disclosed herein. In the description of this specification, the description of reference terms "some embodiments", "examples", "specific examples" or "some examples" etc. means that the specific features or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example.

Claims

1. A translation error correction method based on AC automaton algorithm, characterized in that: Applied to terminal equipment, including: Constructing a translation error correction table, wherein the translation error correction table includes the original text, the erroneous translation and the correct translation; Generate a trie file according to the original text and a preset vocabulary list, wherein the trie file stores a trie tree; Through the AC automaton algorithm and the trie file, the AC automaton algorithm uses the data source of the original text in the trie file to identify and judge the scanned text to be translated, and determines the corresponding matching result, wherein the matching result is the text content with incorrect translation in the scanned file, and replaces the incorrect translation corresponding to the scanned text with the correct translation according to the translation error correction table and the matching result; The method of generating a trie file according to the original text and a preset vocabulary list includes: performing sentence reading processing on the original text to obtain sentences to be arranged; performing word segmentation processing on the sentences to be arranged to obtain words to be arranged; constructing a trie tree according to the words to be arranged and the vocabulary list, wherein the nodes of the trie tree correspond to the words to be arranged one by one; sequentially adding mismatch pointers to all nodes of the trie tree; updating node information of all nodes of the trie tree after adding mismatch pointers; updating node index values ​​of all nodes of the trie tree after updating node information; and recursively traversing the trie tree after updating the node index values ​​based on a breadth-first algorithm to obtain a trie file; The trie tree is constructed according to the word to be arranged and the new word list, including: obtaining the character length of the word to be arranged; if the character length is greater than a preset length, obtaining the corresponding identification information in the new word list according to the word to be arranged, and querying whether the child node of the current node has the identification information; if it exists, updating the child node of the current node with the identification information as the current node; if it does not exist, inserting the identification information as a new child node of the current node and updating it as the current node; The method further includes: if the character length is less than a preset length, querying the child nodes of the current node of the trie tree according to the word to be arranged, and querying whether the child nodes of the current node have the word to be arranged; if so, updating the child nodes of the current node that have the word to be arranged as the current node; if not, inserting the word to be arranged as a new child node of the current node and updating it as the current node.

2. The translation error correction method according to claim 1, characterized in that: Also includes: If the word to be arranged does not exist in the new word list, the word to be arranged is inserted into the new word list, and identification information is configured in the new word list.

3. The translation error correction method according to claim 1, characterized in that: The updating of node information of all nodes of the trie tree after adding the mismatch pointer comprises: Recursively traverse the trie tree based on a breadth-first algorithm to obtain the number of child nodes of the current node; Create a corresponding node array at the current node according to the number of child nodes; Loop through several child nodes of the current node, and determine the array element corresponding to the child node according to the hash value of the word to be arranged corresponding to the child node and the number of the child nodes; The node information of the child node is determined according to the array element.

4. The translation error correction method according to claim 3, characterized in that: The determining the node information of the child node according to the array element includes: If the array element is empty, determining that the array element is node information of a child node; If the array element is not empty, a preset node position value of the child node is obtained, and node information of the child node is determined according to the node position value.

5. The translation error correction method according to claim 1, characterized in that: The AC automaton algorithm and the trie file are matched with the scanned text to be translated to obtain a corresponding matching result, including: Perform word segmentation on the scanned text to be translated to obtain a number of words to be scanned; Based on the AC automaton algorithm, a matching operation is performed on a plurality of words to be scanned in sequence, and the matching operation includes: Calculate the hash value of the word to be scanned; obtain the index value to be searched according to the hash value of the word to be scanned and the number of child nodes of the current node of the trie tree; determine the corresponding child node according to the index value to be searched and the node index value of the child node; if the word to be arranged corresponding to the child node is the same as the word to be scanned, return the matching result.

6. An electronic device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the following is achieved: A translation error correction method as claimed in any one of claims 1 to 5.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to cause a computer to execute: A translation error correction method as claimed in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Candidate phrase querying method and aided translation system for computer aided translation

    CN102693309A