Editing text optimization method and device, electronic equipment and storage medium
By segmenting the formula strings in LaTeX code into symbol sequences, building an abstract syntax tree and performing semantic analysis, the problem of irregular formats and syntax errors in LaTeX code writing is solved, and the readability and standardization of formulas are improved.
Patent Information
- Application Number
- CN202411545856.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-10-31
AI Technical Summary
During the writing of LaTeX code, problems such as irregular formats and syntax errors are prone to occur, which affects the quality and readability of the document, especially when making high-quality mathematics teaching data sets.
By splitting the formula string into symbol sequences, performing syntax analysis to build an abstract syntax tree, and semantic analysis and processing of the abstract syntax tree, automatically adjusting the code format of the formula string to make it conform to the specifications.
Improve the structural clarity and readability of formula strings, enhance the automated syntax checking and code normalization capabilities, and ensure the accuracy and standardization of formulas.
Smart Images

Figure CN119476217A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, specifically to the field of document editing technology, and in particular to an optimization method, device, electronic device and storage medium for editing text. Background Art
[0002] LaTeX (typesetting system) is a typesetting system widely used for academic papers, technical documents and books, but its code writing process is prone to problems such as irregular formatting and grammatical errors, which affect the quality and readability of the document. Especially in the scenario of making high-quality mathematics teaching data sets, the complexity and diversity of mathematical expressions make it easy for irregular formatting problems to occur during code writing. Summary of the invention
[0003] The present invention provides an optimization method, device, electronic device and storage medium for editing text.
[0004] According to one aspect of the present disclosure, a method for optimizing editing text is provided, the method comprising:
[0005] Acquire the edit text to be optimized, wherein the edit text to be optimized includes a formula character string edited by a user;
[0006] Segmenting the formula character string to obtain a symbol sequence;
[0007] Performing grammatical analysis on the symbol sequence according to preset grammatical rules to construct an abstract syntax tree;
[0008] The abstract syntax tree is semantically analyzed and processed to obtain an optimized formula character string.
[0009] According to another aspect of the present disclosure, there is provided an optimization device for editing text, comprising:
[0010] An acquisition module, used for acquiring the edit text to be optimized, wherein the edit text to be optimized includes a formula string edited by a user;
[0011] A segmentation module, used for segmenting the formula string to obtain a symbol sequence;
[0012] A syntax analysis module, used for performing syntax analysis on the symbol sequence according to preset syntax rules to construct an abstract syntax tree;
[0013] The semantic analysis module is used to perform semantic analysis and processing on the abstract syntax tree to obtain an optimized formula string.
[0014] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0015] at least one processor; and
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute any method in any of the above technical solutions.
[0018] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute any one of the methods described in the above technical solutions.
[0019] According to a fifth aspect of the present disclosure, a computer program product is provided, including a computer program, wherein the computer program implements any one of the methods described in the above technical solutions when executed by a processor.
[0020] The present disclosure provides an optimization method, device, equipment and storage medium for editing text. The present disclosure divides the formula string into a symbol sequence first, that is, first breaks down the complex mathematical expression into basic elements that are easy to manage and analyze. In this way, not only the structural clarity of the formula string is enhanced, but also a basis for automated grammar checking is provided. Then, the symbol sequence is subjected to grammatical analysis according to preset grammatical rules to construct an abstract syntax tree, which can ensure that the formula string meets the grammatical rules and ensures the accuracy and standardization of the formula structure. Finally, the abstract syntax tree is semantically analyzed and processed to automatically adjust the code format of the formula string to make it conform to the specification, so that the optimized string structure is more rigorous and the layout is clearer, thereby improving the readability and maintainability of the formula string.
[0021] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0023] Figure 1 is a schematic diagram of steps of an optimization method for editing text in an embodiment of the present disclosure;
[0024] Figure 2 is a schematic diagram of an abstract syntax tree in an embodiment of the present disclosure;
[0025] Figure 3 is a schematic diagram of an abstract syntax tree in another embodiment of the present disclosure;
[0026] Figure 4 is a flowchart of an optimization method for editing text in an embodiment of the present disclosure;
[0027] Figure 5 A functional block diagram of an apparatus for optimizing text editing in an embodiment of the present disclosure;
[0028] Figure 6 It is a block diagram of an electronic device used to implement the optimization method for editing text according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0029] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0030] In the related technical solutions, in order to reduce the problem of typesetting errors caused by editing code in the process of writing mathematical formulas, LaTeX code is generally optimized in the following ways:
[0031] Method 1: By parsing LaTeX code, it provides syntax highlighting and auto-completion functions to help users write code quickly;
[0032] Method 2: Preview the effect of LaTeX documents in real time through the rendering engine, helping users to find and correct typesetting problems in time;
[0033] Method 3: Through plugins and extensions, additional features such as templates, code snippets, and basic syntax checking are provided.
[0034] However, these methods have limited functions in syntax checking and code standardization, cannot fully cover all common code standard issues, and do not support automatic correction and formatting of untidy code.
[0035] In order to solve the above technical problems, the present disclosure provides an optimization method for editing text, see Figure 1 As shown, Figure 1 : is a schematic diagram of the steps of the text editing optimization method in the embodiment of the present disclosure, the method comprising:
[0036] Step S101, obtaining the edit text to be optimized, wherein the edit text to be optimized includes a formula character string edited by a user.
[0037] Specifically, the edited text to be optimized refers to the text content created by the user during the document editing process, which may require further improvement or adjustment to improve its quality, consistency, readability or meet specific format requirements. The edited text to be optimized is, for example, a LaTeX document, that is, a mathematical formula, physical equation, chemical structure, etc. written using the LaTeX typesetting system. In the case where the edited document to be optimized is a LaTeX document, when obtaining the edited text to be optimized, it can be obtained specifically in the following manner, for example, the user can use a LaTeX editor to write or edit the document, the user can edit the mathematical formula in the document, that is, edit the formula string, and then determine the part of the mathematical formula that needs to be optimized, and use the editor's selection tool to select these formulas, thereby obtaining the edited text to be optimized. In this way, by obtaining the edited text to be optimized, it is beneficial to subsequently optimize the edited text to improve the readability of the text.
[0038] Step S102, segmenting the formula character string to obtain a symbol sequence.
[0039] Specifically, after obtaining the edit text to be optimized, since the edit text contains the formula string, it can be understood that obtaining the edit text to be optimized is obtaining the formula string. After obtaining the formula string, the formula string needs to be segmented, that is, the formula string is split into symbols to finally form a symbol sequence. Specifically, before splitting the formula string, it is first necessary to define the lexical rules of the symbols that may appear in the formula. These rules describe how to identify numbers, variables, operators, brackets, function names, etc. Next, create a scanner that will read and analyze the source code string character by character according to the lexical rules. The scanner reads from the formula string character by character to construct potential Tokens (symbols). Then, using technologies such as regular expressions or state machines, the scanner attempts to match the read character sequence with the defined lexical rules. Once the character sequence matches a lexical rule, the scanner generates a Token and adds it to the symbol sequence. This cycle of operations eventually generates an ordered symbol sequence.
[0040] In this way, by first splitting the formula string into a symbol sequence, this process can decompose complex mathematical expressions into basic elements that are easy to manage and analyze. This not only enhances the structural clarity of the formula, but also provides a basis for automated syntax checking, error detection, and further optimization of the formula.
[0041] Step S103: perform syntax analysis on the symbol sequence according to preset syntax rules to construct an abstract syntax tree.
[0042] Specifically, the preset grammar rules are the grammar rules of LaTeX. After obtaining the symbol sequence, the symbol sequence can be parsed according to the preset grammar rules to construct an abstract syntax tree. When constructing the abstract syntax tree, the identified tokens can be organized and parsed according to the LaTeX grammar rules. By recursively applying the grammar rules to match each token, a hierarchical tree model that expresses the semantics of the formula is gradually constructed, so that an abstract syntax tree can be constructed. This process not only ensures the grammatical correctness of the formula, but also provides a clear and structured representation for subsequent semantic analysis, code generation and optimization, making complex formula editing and typesetting more efficient and accurate.
[0043] Step S104: semantically analyze and process the abstract syntax tree to obtain an optimized formula character string.
[0044] Specifically, after constructing the abstract syntax tree, the abstract syntax tree is then semantically analyzed and processed to obtain an optimized formula string. When semantically analyzing and processing the abstract syntax tree, each node in the abstract syntax tree is deeply analyzed to ensure that they comply with the semantic rules of mathematics and LaTeX, identify and correct potential logical errors, simplify the expression structure, standardize the formula format, and delete redundant elements. Finally, through these processing steps, an optimized formula string is generated that is semantically accurate, structurally compact, and visually clear, which improves the readability and professionalism of the formula.
[0045] The present disclosure provides an optimization method, device, equipment and storage medium for editing text. The present disclosure divides the formula string into a symbol sequence first, that is, first breaks down the complex mathematical expression into basic elements that are easy to manage and analyze. In this way, not only the structural clarity of the formula string is enhanced, but also a basis for automated grammar checking is provided. Then, the symbol sequence is subjected to grammatical analysis according to preset grammatical rules to construct an abstract syntax tree, which can ensure that the formula string meets the grammatical rules and ensures the accuracy and standardization of the formula structure. Finally, the abstract syntax tree is semantically analyzed and processed to automatically adjust the code format of the formula string to make it conform to the specification, so that the optimized string structure is more rigorous and the layout is clearer, thereby improving the readability and maintainability of the formula string.
[0046] In some optional embodiments, the formula string is segmented to obtain a symbol sequence, including:
[0047] Get predefined lexical rules;
[0048] The continuous character strings in the formula character string are segmented according to the lexical rules to obtain a symbol sequence.
[0049] Specifically, after obtaining the formula string, the formula string needs to be segmented. The process of segmenting the formula string is to decompose the mathematical formula text written by the user into smaller and manageable units, namely symbol sequences, which is the first step to achieve formula optimization and processing. The specific segmentation process is as follows: First, it is necessary to obtain the pre-defined lexical rules, which are a set of clear guidelines for identifying different types of elements in LaTeX formulas, such as operators, numbers, variable names, function commands, etc. Subsequently, according to these lexical rules, the continuous character sequences in the formula string are scanned and matched. Whenever an element defined by the rule is encountered, it is segmented from the formula string to form independent symbols. These symbols form a symbol sequence according to their order in the original formula, which provides a basis for further syntax analysis and construction of the abstract syntax tree (AST).
[0050] In this way, by segmenting the formula string and obtaining the symbol sequence, the pre-defined lexical rules can be used to accurately identify and separate the various components in the formula, such as variables, numbers, operators, etc. This segmentation not only enhances the understanding of the formula structure, but also lays a solid foundation for further syntax analysis and optimization, making automated syntax checking, error detection and formula reconstruction possible.
[0051] Optionally, when segmenting the formula character string, the formula character string may be input into a lexical analyzer, and a symbol sequence may be obtained through the lexical analyzer.
[0052] In some optional embodiments, performing grammatical analysis on the symbol sequence according to preset grammatical rules to construct an abstract syntax tree includes:
[0053] Identify and match the open brackets and the close brackets in the symbol sequence to determine the expression contained in the formula string;
[0054] Build a node according to each expression, and match the symbol sequence corresponding to each expression with the grammatical structure in the preset grammar rules, and use the matched symbol sequence as a child node;
[0055] All nodes are arranged according to levels and grades to form a tree structure to construct an abstract syntax tree.
[0056] Specifically, after obtaining the symbol sequence, the boundaries of the expressions contained in the formula are determined by identifying and matching the open and closed brackets in the symbol sequence. Subsequently, a corresponding node is constructed for each identified expression, and these nodes represent different components in the formula. Next, the symbol sequence of each expression is matched with the grammatical structure in the preset grammar rules, and for the symbol sequence that meets the rules, it is added as a child node under the corresponding parent node. Finally, all these nodes are arranged according to their hierarchy and level in the formula to form a tree structure with a parent-child relationship, namely the abstract syntax tree. This process not only ensures the structural correctness of the formula, but also provides a clear framework for subsequent semantic analysis, code generation and optimization, making complex formula editing and typesetting more efficient and accurate.
[0057] In this way, the accurate definition of the expression in the formula string is ensured by accurately identifying and matching the opening and closing brackets, and then the nodes are constructed according to the expressions and grammatical rules, and finally all the nodes are arranged in order according to the hierarchy and level, thus forming a clear tree structure. This structured representation method improves the efficiency of formula parsing, enhances the understanding and operation of complex mathematical expressions, and provides a solid foundation for automated formula optimization, error detection and formatting, significantly improving the quality of LaTeX documents and the automation level of editing work.
[0058] Optionally, when an abstract syntax tree is constructed according to a symbol sequence, the symbol sequence can be input into a syntax analyzer, and the abstract syntax tree can be constructed by the syntax analyzer. Figure 2 , Figure 2 is a schematic diagram of an abstract syntax tree in an embodiment of the present disclosure. The figure is a formula y=[log2(x+1) 2 ]+1 is the result obtained after lexical analysis and grammatical analysis. Specifically, assuming that the received formula string has been segmented to obtain a symbol sequence, Figure 2 In the above code, y, left[right], +, 1, log, etc. are all part of the symbol sequence. After getting the symbol sequence, we construct the root node <root>, the node type corresponding to the root node is root, which usually represents the highest level of the entire mathematical expression. It contains multiple child nodes, which represent different parts of the expression, such as function calls, operators, numbers, variables, etc. In the embodiment of the present disclosure, the root node <root>represents the entire formula. After constructing the root node, you need to add child nodes under the root node to construct the abstract syntax tree. When constructing child nodes, first identify and match the open and closed brackets in the symbol sequence to determine the expression contained in the formula string. Since left[right] represents the open and closed brackets respectively, the content in the bracket pair is the content of the sub-expression. By analyzing the formula string, we can identify [log2(x+1) 2 ] belongs to an expression, then a node is constructed for the expression, and is a pair node, and the pair node represents a bracket pair node. Although y, =, +, and 1 do not belong to the content inside the brackets, they are independent individuals of the formula string, and can also be considered as independent sub-expressions, so corresponding nodes are constructed for them respectively, and their node type is normal, and normal represents that the node is an ordinary node. Through the above operations, the child nodes under the root node can be constructed eventually. It should be noted that normal in the embodiments of the present disclosure represents that the node is an ordinary node, and the pair node represents a bracket pair node, which will not be repeated in the following content.
[0059] After splitting the formula string into sub-expressions, we need to perform a complex sub-expression [log2(x+1) 2 ] for further processing. First, a node is constructed for the complex subexpression. The node type is subexpression. <subexpression>Node indicates that the node represents a function expression. Next, the complex sub-expression needs to be further decomposed to construct the next layer of sub-nodes. When processing the complex sub-expression, first identify the function and parameters contained in the sub-expression. The node type corresponding to the function is keyword. By [log2(x+1) 2 ] We can analyze that in this expression, log is used as the function name, (x+1) is used as a whole, sup:2 is used as the superscript, and sub:2 is used as the subscript. Then, corresponding nodes are constructed for each function parameter. Log corresponds to the keyword node type, (x+1) corresponds to the pair node type, sup:2 and sub:2 both correspond to the normal node type, and then the constructed child nodes are added to the function node. Next, (x+1) is split again, and corresponding nodes are constructed for each parameter, that is, x, +, and 1 all correspond to the normal node type, and then the constructed child nodes are added to the corresponding parent nodes. Finally, according to the hierarchical structure of mathematical expressions, all nodes are logically organized into a tree structure, so that an abstract syntax tree can be constructed.
[0060] In some optional embodiments, semantic analysis and processing are performed on the abstract syntax tree to obtain an optimized formula string, including:
[0061] By performing any of the following processing methods on the abstract syntax tree: sub-expression analysis, function parameter normalization, and keyword recognition, an optimized abstract syntax tree is obtained;
[0062] The optimized abstract syntax tree is converted into text form to obtain an optimized formula string.
[0063] Specifically, the embodiment of the present application is to perform in-depth semantic analysis and processing on the abstract syntax tree, specifically including analyzing sub-expressions, normalizing function parameters, and performing keyword recognition, etc., to finally generate an optimized formula string. Among them, the sub-expression analysis of the abstract syntax tree is to review each sub-expression in the abstract syntax tree to ensure that their structure and logic are correct. The function parameter normalization of the abstract syntax tree is for the purpose of adjusting and correcting the order and structure of parameters in the function call to meet the grammatical specifications of LaTeX. In addition, the abstract syntax tree is subjected to keyword recognition, which further improves the accuracy and professionalism of the formula by identifying specific keywords in the AST and replacing them with corresponding LaTeX commands. After these processing steps, an optimized AST is obtained, which is more semantically accurate and more standardized in structure. Finally, the optimized AST is converted back to text form, that is, the optimized formula string. This conversion process involves re-expressing each node and its relationship in the AST as LaTeX code, thereby ensuring the high-quality presentation and easy-to-read format of the formula. The whole process not only improves the readability and accuracy of the formula, but also provides strong support for automated document editing and typesetting.
[0064] In this way, by exhaustively analyzing the sub-expressions in the abstract syntax tree, normalizing function parameters, and accurately identifying keywords, each mathematical concept is ensured to be properly expressed. After these processing steps, the abstract syntax tree is more semantically precise and more structurally reasonable. Subsequently, this optimized abstract syntax tree is converted back to text form to generate an optimized formula string. This conversion not only improves the readability and logical clarity of the formula, but also enhances the consistency and professionalism of the formula, so that the final LaTeX document reaches a higher standard in both typesetting quality and presentation effect.
[0065] In some optional embodiments, the optimized abstract syntax tree is obtained by performing any of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree, including:
[0066] Analyze the sub-expressions in the abstract syntax tree, remove redundant nested parentheses, and normalize different types of parentheses;
[0067] The sub-expressions with associated relationships in the abstract syntax tree are merged to obtain an optimized formula string.
[0068] Specifically, when performing sub-expression analysis on the abstract syntax tree, this process involves in-depth inspection of each sub-expression in the AST, identifying and removing unnecessary nested parentheses, and normalizing different types of parentheses such as round brackets, square brackets, and curly brackets to improve the readability and consistency of the formula. Next, sub-expressions with associated relationships are merged, which not only simplifies the structure of the formula but also enhances the clarity of its logical expression. Through these processes, the AST is optimized, redundant parts are removed, and the core structure and meaning of the formula are retained. Finally, this optimized AST is converted back to a formula string, ensuring that the output formula is not only syntactically correct, but also more precise and easy to understand semantically, thereby improving the quality of the entire document.
[0069] In this way, by carefully analyzing the sub-expressions in the abstract syntax tree, removing redundant nested parentheses, and normalizing parentheses, square brackets, and curly brackets, the clarity and consistency of the formula are enhanced. In addition, by merging sub-expressions with associated relationships, the structure of the formula is further simplified, making the formula more concise and easy to understand. This not only improves the readability and logic of the formula, but also helps avoid typographical errors and ensures the accuracy and professionalism of mathematical expressions.
[0070] In some optional embodiments, the optimized abstract syntax tree is obtained by performing any of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree, including:
[0071] The function parameters in the abstract syntax tree are analyzed, and the functions that are not correctly mounted in the abstract syntax tree are adjusted to obtain an optimized abstract syntax tree.
[0072] Specifically, the disclosed embodiment normalizes function parameters of the abstract syntax tree. This step focuses on analyzing the functions and their parameters in the AST, especially those function calls that are not mounted correctly, and ensures that they comply with the grammatical specifications and mathematical logic of LaTeX by adjusting the order and structure of the parameters.
[0073] In this way, by deeply analyzing the function parameters in the abstract syntax tree, identifying and adjusting those functions that are not correctly mounted, the accuracy and standardization of function calls in the formula are ensured. This process not only corrects possible syntax errors, but also enhances the logical clarity and semantic accuracy of the formula.
[0074] In some optional embodiments, the optimized abstract syntax tree is obtained by performing any of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree, including:
[0075] Scan the nodes in the abstract syntax tree and identify the keywords contained in the abstract syntax tree corresponding to the preset grammar rules;
[0076] The keywords are replaced with keywords that are consistent with the preset grammar rules, and the additional attributes of the nodes are retained to obtain an optimized abstract syntax tree.
[0077] Specifically, the disclosed embodiment performs keyword recognition on the abstract syntax tree, and identifies keywords that match the preset grammar rules by scanning the nodes in the abstract syntax tree. The identified keywords are then replaced with the corresponding forms in the preset grammar rules, while retaining the additional attributes of the nodes, such as superscripts, subscripts, etc., to maintain the integrity and accuracy of the formula. This series of processing not only corrects possible grammatical errors, but also enhances the readability and professionalism of the formula, and ultimately obtains an optimized abstract syntax tree, which lays a solid foundation for generating high-quality and high-accuracy LaTeX formula strings.
[0078] In this way, by scanning each node in the abstract syntax tree, the keywords that match the preset grammar rules are accurately identified and replaced with the standard form in the rules, while carefully retaining the additional attributes of the nodes, such as necessary superscripts and subscripts. This meticulous processing not only improves the grammatical correctness and semantic clarity of the formula, but also ensures the accuracy and consistency of the formula during conversion and typesetting. Ultimately, an optimized formula string with a more standardized structure and clearer expression is generated, which significantly improves the professionalism and readability of the LaTeX document.
[0079] In some optional embodiments, in order to facilitate understanding of the solution of optimizing the abstract syntax tree in the present application, the above example is still used as an example, see Figure 3 , Figure 3 is a schematic diagram of an abstract syntax tree in another embodiment of the present disclosure. The figure is a formula y=[log2(x+1) 2 ]+1 to get a more clear abstract syntax tree from the semantic analyzer. Figure 3 and Figure 2 For comparison, Figure 2 The difference is that in constructing Figure 2 After the abstract syntax tree is generated, the function parameters in the abstract syntax tree are analyzed and the parameters of the log function in the abstract syntax tree are associated with the log function. 2 ]+1 Analysis shows that subscript 2 should be a parameter in the function log. Therefore, when optimizing the abstract syntax tree, we can first associate the parameter subscript sub2 in the abstract syntax tree with the log function. Specifically, we first build a node of type subexpression (i.e. sub-expression), where suberscript represents the subscript. Then, we build a child node with the specific subscript content, and then add the constructed child node to the corresponding parent node. As for superscript 2, it does not belong to the content in the function. In this case, we can first build a node of type subexpression (i.e. sub-expression), where superscript represents the superscript. Then, we build a child node with the specific superscript content, and then add the constructed child node to the corresponding parent node. As for the parameter (x+1), we first build a param (i.e. parameter) node, where the corresponding node type is subexpression. Then, we further split the parameter. After such optimization, we can get the optimized abstract syntax tree, which is Figure 3 After obtaining the optimized abstract syntax tree, it is necessary to convert it into text form to obtain the optimized formula string. The LaTeX code before correction is y=\left[{\log_2(x+1)}^2\right]+1, and after optimization, the corrected code is y=\left[{\log_{2}{(x+1)}}^{2}\right]+1), so that the relationship between the function parameters is clearer and the obtained code is more standardized.
[0080] In order to understand the technical solution of this application as a whole, see Figure 4 , Figure 4 It is a flowchart of the method for optimizing the edited text in the embodiment of the present disclosure. Specifically, the edited text to be optimized is first obtained, and then lexical analysis and syntax analysis are performed to determine whether there are grammatical errors. If there are grammatical errors, modification suggestions are made. If there are no grammatical errors, keyword recognition, sub-expression regularization, function parameter analysis and sub-expression analysis are performed in sequence to normalize the formula code in the edited text and obtain a standardized code.
[0081] In this way, by performing grammatical and semantic analysis on the edited text, especially the processing of brackets and function parameters, the generated code is made clearer and easier to read, which can greatly improve the efficiency and accuracy of users in writing LaTeX mathematical formulas and reduce debugging time caused by grammatical errors and inconsistent code styles.
[0082] The following describes an embodiment of the device of the present application, which can be used to execute the method for optimizing the editing text in the above embodiment of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method for optimizing the editing text in the above embodiment of the present application.
[0083] The present disclosure also provides an optimization device 500 for editing text, such as Figure 5 As shown, including:
[0084] The acquisition module 501 is used to acquire the edit text to be optimized, where the edit text to be optimized includes a formula string edited by the user;
[0085] A segmentation module 502 is used to segment the formula string to obtain a symbol sequence;
[0086] The syntax analysis module 503 is used to perform syntax analysis on the symbol sequence according to preset syntax rules to construct an abstract syntax tree;
[0087] The semantic analysis module 504 is used to perform semantic analysis and processing on the abstract syntax tree to obtain an optimized formula string.
[0088] In some optional embodiments, the segmentation module 502 segments the formula string to obtain a symbol sequence, including:
[0089] Get predefined lexical rules;
[0090] The continuous character strings in the formula character string are segmented according to the lexical rules to obtain a symbol sequence.
[0091] In some optional embodiments, the syntax analysis module 503 performs syntax analysis on the symbol sequence according to preset syntax rules to construct an abstract syntax tree, including:
[0092] Identify and match the open brackets and the close brackets in the symbol sequence to determine the expression contained in the formula string;
[0093] Build a node according to each expression, and match the symbol sequence corresponding to each expression with the grammatical structure in the preset grammar rules, and use the matched symbol sequence as a child node;
[0094] All nodes are arranged according to levels and grades to form a tree structure to construct an abstract syntax tree.
[0095] In some optional embodiments, the semantic analysis module 504 performs semantic analysis and processing on the abstract syntax tree to obtain an optimized formula string, including:
[0096] By performing any of the following processing methods on the abstract syntax tree: sub-expression analysis, function parameter normalization, and keyword recognition, an optimized abstract syntax tree is obtained;
[0097] The optimized abstract syntax tree is converted into text form to obtain an optimized formula string.
[0098] In some optional embodiments, the semantic analysis module 504 processes the abstract syntax tree by performing any of sub-expression analysis, function parameter normalization, and keyword recognition to obtain an optimized abstract syntax tree, including:
[0099] Analyze the sub-expressions in the abstract syntax tree, remove redundant nested parentheses, and normalize different types of parentheses;
[0100] The sub-expressions with associated relationships in the abstract syntax tree are merged to obtain an optimized formula string.
[0101] In some optional embodiments, the semantic analysis module 504 processes the abstract syntax tree by performing any of sub-expression analysis, function parameter normalization, and keyword recognition to obtain an optimized abstract syntax tree, including:
[0102] The function parameters in the abstract syntax tree are analyzed, and the functions that are not correctly mounted in the abstract syntax tree are adjusted to obtain an optimized abstract syntax tree.
[0103] In some optional embodiments, the semantic analysis module 504 processes the abstract syntax tree by performing any of sub-expression analysis, function parameter normalization, and keyword recognition to obtain an optimized abstract syntax tree, including:
[0104] Scan the nodes in the abstract syntax tree and identify the keywords contained in the abstract syntax tree corresponding to the preset grammar rules;
[0105] The keywords are replaced with keywords that are consistent with the preset grammar rules, and the additional attributes of the nodes are retained to obtain an optimized abstract syntax tree.
[0106] In the technical solution disclosed herein, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0107] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0108] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0109] like Figure 6 As shown, the electronic device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0110] A number of components in the device 600 are connected to the I / O interface 605, including: an input unit 606, such as a keyboard, a mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0111] The computing unit 601 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 601 performs the various methods and processes described above, such as the optimization method for editing text. For example, in some embodiments, the optimization method for editing text may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the applet distribution described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the optimization method for editing text by any other appropriate means (e.g., by means of firmware).
[0112] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0113] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0114] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0115] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0116] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0117] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0118] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0119] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.< / subexpression> < / root> < / root>
Claims
1. A method for optimizing editing text, the method comprising: Acquire the edit text to be optimized, wherein the edit text to be optimized includes a formula character string edited by a user; Segmenting the formula character string to obtain a symbol sequence; Performing grammatical analysis on the symbol sequence according to preset grammatical rules to construct an abstract syntax tree; The abstract syntax tree is semantically analyzed and processed to obtain an optimized formula character string.
2. The method according to claim 1, wherein: The step of segmenting the formula character string to obtain a symbol sequence includes: Get predefined lexical rules; The continuous character strings in the formula character string are segmented according to the lexical rules to obtain a symbol sequence.
3. The method according to claim 1, wherein: The step of performing grammatical analysis on the symbol sequence according to preset grammatical rules to construct an abstract syntax tree includes: Identifying and matching the open brackets and the closed brackets in the symbol sequence to determine the expression contained in the formula string; Construct a node according to each expression, and match the symbol sequence corresponding to each expression with the grammatical structure in the preset grammar rule, and use the matched symbol sequence as a child node; All nodes are arranged according to levels and grades to form a tree structure, so as to construct the abstract syntax tree.
4. The method according to any one of claims 1 to 3, wherein: The semantic analysis and processing of the abstract syntax tree to obtain an optimized formula string includes: Obtain an optimized abstract syntax tree by performing any one of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree; The optimized abstract syntax tree is converted into a text form to obtain an optimized formula character string.
5. The method according to claim 4, wherein: The step of performing any one of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree to obtain an optimized abstract syntax tree includes: Analyze the sub-expressions in the abstract syntax tree, delete redundant nested brackets, and normalize different types of brackets; The sub-expressions with associated relationships in the abstract syntax tree are merged to obtain an optimized formula string.
6. The method according to claim 5, wherein: The step of performing any one of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree to obtain an optimized abstract syntax tree includes: The function parameters in the abstract syntax tree are analyzed, and the functions that are not correctly mounted in the abstract syntax tree are adjusted to obtain an optimized abstract syntax tree.
7. The method according to claim 5, wherein: The step of performing any one of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree to obtain an optimized abstract syntax tree includes: Scan the nodes in the abstract syntax tree to identify keywords contained in the abstract syntax tree that correspond to preset grammar rules; The keywords are replaced with keywords consistent with the preset grammar rules, and the additional attributes of the nodes are retained to obtain an optimized abstract syntax tree.
8. An optimization device for editing text, comprising: An acquisition module, used for acquiring the edit text to be optimized, wherein the edit text to be optimized includes a formula string edited by a user; A segmentation module, used for segmenting the formula string to obtain a symbol sequence; A syntax analysis module, used for performing syntax analysis on the symbol sequence according to preset syntax rules to construct an abstract syntax tree; The semantic analysis module is used to perform semantic analysis and processing on the abstract syntax tree to obtain an optimized formula string.
9. The device according to claim 8, wherein: The segmentation module segments the formula string to obtain a symbol sequence, including: Get predefined lexical rules; The continuous character strings in the formula character string are segmented according to the lexical rules to obtain a symbol sequence.
10. The device according to claim 8, wherein: The syntax analysis module performs syntax analysis on the symbol sequence according to preset syntax rules to construct an abstract syntax tree, including: Identifying and matching the open brackets and the closed brackets in the symbol sequence to determine the expression contained in the formula string; Construct a node according to each expression, and match the symbol sequence corresponding to each expression with the grammatical structure in the preset grammar rule, and use the matched symbol sequence as a child node; All nodes are arranged according to levels and grades to form a tree structure, so as to construct the abstract syntax tree.
11. The device according to any one of claims 8 to 10, wherein: The semantic analysis module performs semantic analysis and processing on the abstract syntax tree to obtain an optimized formula string, including: Obtain an optimized abstract syntax tree by performing any one of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree; The optimized abstract syntax tree is converted into a text form to obtain an optimized formula character string.
12. The device according to claim 11, wherein The semantic analysis module processes the abstract syntax tree by performing any one of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree to obtain an optimized abstract syntax tree, including: Analyze the sub-expressions in the abstract syntax tree, delete redundant nested brackets, and normalize different types of brackets; The sub-expressions with associated relationships in the abstract syntax tree are merged to obtain an optimized formula string.
13. The device according to claim 11, wherein: The semantic analysis module processes the abstract syntax tree by performing any one of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree to obtain an optimized abstract syntax tree, including: The function parameters in the abstract syntax tree are analyzed, and the functions that are not correctly mounted in the abstract syntax tree are adjusted to obtain an optimized abstract syntax tree.
14. The device according to claim 11, wherein: The semantic analysis module processes the abstract syntax tree by performing any one of sub-expression analysis, function parameter normalization, and keyword recognition on the abstract syntax tree to obtain an optimized abstract syntax tree, including: Scan the nodes in the abstract syntax tree to identify keywords contained in the abstract syntax tree that correspond to preset grammar rules; The keywords are replaced with keywords consistent with the preset grammar rules, and the additional attributes of the nodes are retained to obtain an optimized abstract syntax tree.
15. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.
16. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-7.
17. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and system of report formula processing
CN103164393A
Automatic formula recognition method and device as well as electronic equipment and storage medium
CN108537183A
Symbol expression tree generation method
CN110321519A
Compiling method and system for mechanical arm program development programming language
CN111580825A
Similarity measurement method for evaluating languages based on mathematical expression
CN113051370A
Cited By
Mathematical formula processing method and device, computer equipment and readable storage medium
CN120449867A
Mathematical formula processing method and device, computer device and readable storage medium
CN120449867B