Text analysis method and device

By embedding or co-running with the Golang template text parser on the client, using regular matching processing and parsing replacement technology, the problem of inefficiency in parsing Golang template text on the TypeScript client is solved, and a more efficient parsing process is achieved.

CN120179255APending Publication Date: 2025-06-20LANXIN MOBILE (BEIJING) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510194917.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-21
Publication Date
2025-06-20

AI Technical Summary

Technical Problem

When a client developed based on the TypeScript language parses Golang template text, the existing parsing methods take a long time and are less efficient.

Method used

By embedding or co-running with the Golang template text parser on the client, regular matching is performed using regular expressions corresponding to single-factor syntax and multi-factor syntax, and the text content is gradually parsed and replaced until the final parsing result is obtained.

Benefits of technology

This method can effectively reduce the time overhead of parsing Golang template text and improve the parsing efficiency of Golang template text by clients developed based on TypeScript language.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120179255A_ABST
    Figure CN120179255A_ABST
Patent Text Reader

Abstract

The invention discloses a text analysis method and device. The method comprises the steps that a to-be-analyzed text sent by a server side is received, regular matching processing is conducted on the to-be-analyzed text and a regular expression corresponding to each single-factor grammar, so that one or more target single-factor objects contained in the to-be-analyzed text are obtained, and the to-be-analyzed text is a Golang template text; performing analysis processing on each target single-factor object to obtain an analysis result corresponding to each target single-factor object; performing replacement processing on corresponding contents of the to-be-analyzed text by using the analysis result corresponding to each target single factor object to obtain a first analyzed text; performing regular matching processing on the regular expression corresponding to each multi-factor grammar and the first analysis text to obtain one or more target multi-factor objects contained in the first analysis text; and performing analysis processing on each target multi-factor object to obtain an analysis result corresponding to the to-be-analyzed text.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data processing, and in particular, to a text parsing method and device. Background Art

[0002] The Golang language is a statically typed programming language developed by Google. Due to its advantages such as high performance and excellent concurrency processing ability, it has gradually become the preferred programming language for server-side development. Among them, GolangTemplate is a template engine in the Golang language standard library, which provides powerful dynamic text generation capabilities. Server-side applications developed based on the Golang language often use the Golang Template template engine to generate Golang template text.

[0003] The TypeScript language is a programming language based on JavaScript developed by Microsoft. Since the TypeScript language does not have an effective parser for the Golang Template template engine, when a client developed based on the TypeScript language receives the Golang template text sent by a server developed based on the Golang language, it cannot effectively parse the Golang template text, and thus cannot obtain the parsing result corresponding to the Golang template text.

[0004] Currently, usually, after a client developed based on the TypeScript language receives the Golang template text sent by the server, it sends a parsing request carrying the Golang template text to the server. After receiving the parsing request, the server parses the Golang template text and feeds back the parsing result to the client. Therefore, for a client developed based on the TypeScript language, the existing Golang template text parsing method is time-consuming and has low parsing efficiency. Summary of the Invention

[0005] Embodiments of this application provide a text parsing method and device, and the main purpose is to improve the parsing efficiency of a client developed based on the TypeScript language for parsing Golang template text.

[0006] To solve the above technical problems, embodiments of this application provide the following technical solutions:

[0007] In a first aspect, the present application provides a text parsing method, which is applied to a target client, and the target client is a client developed based on the TypeScript language. The method includes:

[0008] Receiving the text to be parsed sent by the server, and performing regular matching processing on the text to be parsed using the regular expression corresponding to each single-factor grammar, so as to obtain one or more target single-factor objects included in the text to be parsed, where the text to be parsed is a Golang template text;

[0009] Performing parsing processing on each of the target single-factor objects to obtain the parsing result corresponding to each of the target single-factor objects;

[0010] Using the parsing result corresponding to each target single-factor object to perform replacement processing on the corresponding content of the text to be parsed, so as to obtain a first parsed text;

[0011] Performing regular matching processing on the first parsed text using the regular expression corresponding to each multi-factor grammar, so as to obtain one or more target multi-factor objects included in the first parsed text;

[0012] Performing parsing processing on each of the target multi-factor objects to obtain the parsing result corresponding to the text to be parsed.

[0013] In a second aspect, the present application further provides a text parsing device, which is applied to a target client, and the target client is a client developed based on the TypeScript language. The device includes:

[0014] A first processing unit, configured to receive the text to be parsed sent by the server, and perform regular matching processing on the text to be parsed using the regular expression corresponding to each single-factor grammar, so as to obtain one or more target single-factor objects included in the text to be parsed, where the text to be parsed is a Golang template text;

[0015] A second processing unit, configured to perform parsing processing on each of the target single-factor objects to obtain the parsing result corresponding to each of the target single-factor objects;

[0016] A replacement unit, configured to use the parsing result corresponding to each target single-factor object to perform replacement processing on the corresponding content of the text to be parsed, so as to obtain a first parsed text;

[0017] A third processing unit, configured to perform regular matching processing on the first parsed text using the regular expression corresponding to each multi-factor grammar, so as to obtain one or more target multi-factor objects included in the first parsed text;

[0018] A fourth processing unit, configured to perform parsing processing on each of the target multi-factor objects to obtain a parsing result corresponding to the text to be parsed.

[0019] In a third aspect, an embodiment of the present application provides a storage medium, which includes a stored program. When the program runs, it controls the device where the storage medium is located to execute the text parsing method described in the first aspect.

[0020] In a fourth aspect, an embodiment of the present application provides a text parsing device, which includes a storage medium; and one or more processors. The storage medium is coupled to the processors, and the processors are configured to execute program instructions stored in the storage medium; when the program instructions run, they execute the text parsing method described in the first aspect.

[0021] By means of the above technical solutions, the technical solutions provided by the present application have at least the following advantages:

[0022] The present application provides a text parsing method and apparatus. After the Golang template text parser in the present application receives the text to be parsed (i.e., the Golang template text) sent by the server, the Golang template text parser first performs regular matching processing on the text to be parsed using the regular expression corresponding to each single-factor syntax, so as to obtain one or more target single-factor objects included in the text to be parsed; secondly, perform parsing processing on each target single-factor object to obtain the parsing result corresponding to each target single-factor object; thirdly, use the parsing result corresponding to each target single-factor object to perform replacement processing on the corresponding content of the text to be parsed, so as to obtain the first parsed text; then, perform regular matching processing on the first parsed text using the regular expression corresponding to each multi-factor syntax, so as to obtain one or more target multi-factor objects included in the first parsed text; finally, perform parsing processing on each target multi-factor object to obtain the parsing result corresponding to the text to be parsed, and use the parsing result corresponding to each target multi-factor object to perform replacement processing on the corresponding content in the first parsed text. The first parsed text after the replacement processing is the parsing result corresponding to the text to be parsed. Since, in the present application, after the client developed based on the TypeScript language receives the Golang template text sent by the server, the Golang template text parser embedded in the client (or the Golang template text parser running on the terminal device together with the client) can directly parse the Golang template text to obtain the parsing result, without having to interact with the server to request the server to parse the Golang template text. Therefore, it can effectively reduce the time consumed for parsing the Golang template text, and thus can effectively improve the parsing efficiency of the client developed based on the TypeScript language for parsing the Golang template text.

[0023] The above description is only an overview of the technical solution of the present application. In order to be able to understand the technical means of the present application more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features and advantages of the present application more obvious and understandable, the specific embodiments of the present application are specifically given below. Brief Description of the Drawings

[0024] By referring to the accompanying drawings and reading the detailed description below, the above and other purposes, features and advantages of the exemplary embodiments of the present application will become easy to understand. In the drawings, several embodiments of the present application are shown in an exemplary rather than restrictive manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:

[0025] Figure 1 The figure shows a flowchart of a text parsing method provided by an embodiment of the present application;

[0026] Figure 2 The figure shows a flowchart of another text parsing method provided by an embodiment of the present application;

[0027] Figure 3 The figure shows a block diagram of the composition of a core text parsing device provided by an embodiment of the present application;

[0028] Figure 4 The figure shows a block diagram of the composition of another text parsing device provided by an embodiment of the present application. Detailed implementation manners

[0029] Hereinafter, the exemplary embodiments of the present application will be described in more detail with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that a more thorough understanding of the present application can be obtained, and the scope of the present application can be fully conveyed to those skilled in the art.

[0030] In addition, the "first", "second" and similar terms used in the present application do not denote any order, quantity or importance, but are only used to distinguish different parts.

[0031] It should be noted that unless otherwise specified, the technical terms or scientific terms used in the present application should have the ordinary meanings understood by those skilled in the art to which the present application belongs.

[0032] Currently, generally, a client developed based on the TypeScript language, after receiving the Golang template text sent by the server, sends a parsing request carrying the Golang template text to the server. After receiving the parsing request, the server parses the Golang template text and feeds back the parsing result to the client. Therefore, for a client developed based on the TypeScript language, the existing Golang template text parsing method takes a long time and has low parsing efficiency.

[0033] Therefore, in order to improve the parsing efficiency of a client developed based on the TypeScript language for parsing Golang template text, an embodiment of the present application provides a text parsing method, which is applied to a target client, and the target client is a client developed based on the TypeScript language, such as Figure 1 shown, this method at least includes 101-105.

[0034] 101. Receive the text to be parsed sent by the server, and perform regular matching processing on the text to be parsed using the regular expression corresponding to each single-factor syntax, so as to obtain one or more target single-factor objects included in the text to be parsed.

[0035] Among them, the text to be parsed is a Golang template text.

[0036] In the embodiment of the present application, the execution subject in each step is a Golang template text parser. Among them, the Golang template text parser can be embedded in the target client, and the target client runs on the target terminal device. The Golang template text parser can also be independent of the target client and run on the target terminal device together with the target client. Among them, the target terminal device can be, but is not limited to: a computer, a tablet computer, a laptop computer, etc.

[0037] Among them, the single-factor syntax is a syntax in the Golang language that contains one syntax tag. For example, the {{eq}} syntax, the {{ne}} syntax, the {{and}} syntax, the {{or}} syntax, etc.; the multi-factor syntax is a syntax in the Golang language that contains multiple syntax tags. For example, the {{if}}{{end}} syntax, the {{if}}{{else}}{{end}} syntax, the {{range}}{{end}} syntax, etc.; among them, the mapping relationship between each single-factor syntax and its corresponding regular expression, preset algorithm, and extraction rule, as well as the mapping relationship between each multi-factor syntax and its corresponding regular expression, preset algorithm, and extraction rule are pre-stored in the local storage space of the target terminal device; among them, for any single-factor syntax, the regular expression, preset algorithm, and extraction rule corresponding to the single-factor syntax are all determined according to the semantics of the single-factor syntax; among them, for any multi-factor syntax, the regular expression, preset algorithm, and extraction rule corresponding to the multi-factor syntax are all determined according to the semantics of the multi-factor syntax.

[0038] When the target client receives the text to be parsed sent by the server, the target client will send the text to be parsed to the Golang template text parser; after receiving the text to be parsed sent by the server, the Golang template text parser needs to perform regular matching processing on the text to be parsed using the regular expression corresponding to each single-factor syntax. For example, first perform regular matching processing on the text to be parsed using the regular expression corresponding to the {{eq}} syntax, and then perform regular matching processing on the text to be parsed using the regular expression corresponding to the {{ne}} syntax...; after completing the operation of performing regular matching processing on the text to be parsed using multiple regular expressions, one or more target single-factor objects included in the text to be parsed can be obtained.

[0039] 102. Parse each target single-factor object to obtain the parsing result corresponding to each target single-factor object.

[0040] After the Golang template text parser obtains one or more target single-factor objects included in the text to be parsed, it can parse each target single-factor object to obtain the parsing result corresponding to each target single-factor object.

[0041] 103. Use the parsing result corresponding to each target single-factor object to replace the corresponding content of the text to be parsed to obtain the first parsed text.

[0042] After the Golang template text parser parses and obtains the parsing result corresponding to each target single-factor object, it can use the parsing result corresponding to each target single-factor object to replace the corresponding content in the text to be parsed. The text to be parsed after the replacement process is the first parsed text.

[0043] 104. Use the regular expression corresponding to each multi-factor syntax to perform regular matching processing on the first parsed text to obtain one or more target multi-factor objects included in the first parsed text.

[0044] After the Golang template text parser obtains the first parsed text, it can use the regular expression corresponding to each multi-factor syntax to perform regular matching processing on the first parsed text. For example, first perform regular matching processing on the first parsed text using the regular expression corresponding to the {{if}}{{end}} syntax, and then perform regular matching processing on the first parsed text using the regular expression corresponding to the {{if}}{{else}}{{end}} syntax...; after completing the operation of performing regular matching processing on the first parsed text using multiple regular expressions, one or more target multi-factor objects included in the first parsed text can be obtained.

[0045] It should be noted that in the actual application process, when it is determined that the first parsed text does not contain multi-factor objects, the subsequent step 105 does not need to be executed, and the first parsed text can be directly determined as the parsing result corresponding to the text to be parsed.

[0046] 105. Parse each target multi-factor object to obtain the parsing result corresponding to the text to be parsed.

[0047] After the Golang template text parser obtains one or more target multi-factor objects included in the first parsed text, it can parse each target multi-factor object, thereby obtaining the parsing result corresponding to the text to be parsed. That is, first parse each target multi-factor object to obtain the parsing result corresponding to each target multi-factor object, and then use the parsing result corresponding to each target multi-factor object to replace the corresponding content in the first parsed text. The first parsed text after the replacement process is the parsing result corresponding to the text to be parsed.

[0048] An embodiment of the present application provides a text parsing method. In the embodiment of the present application, after the Golang template text parser receives the text to be parsed (i.e., the Golang template text) sent by the server, the Golang template text parser first uses the regular expression corresponding to each single-factor syntax to perform regular matching processing with the text to be parsed, so as to obtain one or more target single-factor objects included in the text to be parsed; secondly, perform parsing processing on each target single-factor object to obtain the parsing result corresponding to each target single-factor object; thirdly, use the parsing result corresponding to each target single-factor object to perform replacement processing on the corresponding content of the text to be parsed, so as to obtain the first parsed text; then, use the regular expression corresponding to each multi-factor syntax to perform regular matching processing with the first parsed text, so as to obtain one or more target multi-factor objects included in the first parsed text; finally, perform parsing processing on each target multi-factor object to obtain the parsing result corresponding to the text to be parsed, and use the parsing result corresponding to each target multi-factor object to perform replacement processing on the corresponding content in the first parsed text. The first parsed text after the replacement processing is the parsing result corresponding to the text to be parsed. Since, in the embodiment of the present application, after the client developed based on the TypeScript language receives the Golang template text sent by the server, the Golang template text parser embedded in the client (or the Golang template text parser running on the terminal device together with the client) can directly parse the Golang template text to obtain the parsing result, without interacting with the server again to request the server to parse the Golang template text. Therefore, it can effectively reduce the time consumed for parsing the Golang template text, and thus can effectively improve the parsing efficiency of the client developed based on the TypeScript language for parsing the Golang template text.

[0049] For a more detailed description below, another text parsing method is provided in the embodiment of the present application, specifically as Figure 2 shown, and this method at least includes 201-206.

[0050] 201. Receive the text to be parsed sent by the server.

[0051] Among them, regarding step 201, receiving the text to be parsed sent by the server, reference can be made to Figure 1 the description of the corresponding part 101, and it will not be elaborated here in the embodiment of the present application.

[0052] 202. Use the regular expression corresponding to each single-factor grammar to perform regular matching processing with the text to be parsed, so as to obtain one or more target single-factor objects included in the text to be parsed.

[0053] After receiving the text to be parsed sent by the server, the Golang template text parser needs to use the regular expression corresponding to each single-factor grammar to perform regular matching processing with the text to be parsed, so as to obtain one or more target single-factor objects included in the text to be parsed.

[0054] Specifically, in this step, the specific process of the Golang template text parser using the regular expression corresponding to each single-factor grammar to perform regular matching processing with the text to be parsed, so as to obtain one or more target single-factor objects included in the text to be parsed is as follows: Use the regular expression corresponding to each single-factor grammar to perform regular matching processing with the single-factor grammar tags included in the text to be parsed. Among them, when the regular expression corresponding to a certain single-factor grammar matches a certain single-factor grammar tag in the text to be parsed, the object to which the single-factor grammar tag belongs is determined as the target single-factor object included in the text to be parsed; after completing the operation of performing regular matching processing with the single-factor grammar tags included in the text to be parsed using multiple regular expressions, one or more target single-factor objects included in the text to be parsed can be obtained.

[0055] 203. Perform parsing processing on each target single-factor object to obtain the parsing result corresponding to each target single-factor object.

[0056] After the Golang template text parser obtains one or more target single-factor objects included in the text to be parsed, it can perform parsing processing on each target single-factor object to obtain the parsing result corresponding to each target single-factor object. The following will detail how the Golang template text parser performs parsing processing on each target single-factor object to obtain the parsing result corresponding to each target single-factor object:

[0057] (1) Determine the preset algorithm corresponding to each target single-factor object according to the single-factor grammar corresponding to each target single-factor object.

[0058] Since the mapping relationships between each single-factor grammar and its corresponding regular expression, preset algorithm, and extraction rule are pre-stored in the local storage space of the target terminal device, for any target single-factor object, the Golang template text parser can, according to the single-factor grammar corresponding to the target single-factor object, search for the preset algorithm and extraction rule corresponding to the target single-factor object among multiple mapping relationships; among them, for any single-factor grammar, the extraction rule corresponding to the single-factor grammar is used to extract the valid content corresponding to the single-factor object from the single-factor object corresponding to the single-factor grammar, and the preset algorithm corresponding to the single-factor grammar is used to perform corresponding operations on the valid content corresponding to the single-factor object, so as to obtain the parsing result corresponding to the target single-factor object.

[0059] (2) When the text to be parsed contains only one target single-factor object, the Golang template text parser needs to parse and process the target single-factor object according to the preset algorithm corresponding to the target single-factor object to obtain the parsing result corresponding to the target single-factor object. The specific process is as follows: First, determine the extraction rule corresponding to the target single-factor object according to the single-factor grammar corresponding to the target single-factor object; Second, extract multiple valid contents corresponding to the target single-factor object from the target single-factor object according to the extraction rule corresponding to the target single-factor object, where the valid content corresponding to the target single-factor object can be but is not limited to: numerical value, string, environment parameter, etc. When the valid content corresponding to the target single-factor object is specifically an environment parameter, the Golang template text parser can request the parameter value corresponding to the environment parameter from the target client according to the parameter name corresponding to the environment parameter; Finally, parse and process the multiple valid contents corresponding to the target single-factor object according to the preset algorithm corresponding to the target single-factor object, that is, perform corresponding operations on the valid content corresponding to the target single-factor object according to the preset algorithm corresponding to the target single-factor object, so as to obtain the parsing result corresponding to the target single-factor object. For example, if the target single-factor object is: eq(T0 T1), then the multiple valid contents extracted from the target single-factor object according to the extraction rule corresponding to the target single-factor object are T0 and T1, and the specific process of parsing and processing the multiple valid contents corresponding to the target single-factor object according to the preset algorithm corresponding to the target single-factor object is to judge whether T0 is equal to T1. If they are equal, the parsing result corresponding to the target single-factor object is Ture; if they are not equal, the parsing result corresponding to the target single-factor object is False.

[0060] (3) When the text to be parsed contains multiple target single-factor objects, the Golang template text parser needs to first judge whether there is a nesting relationship between the multiple target single-factor objects:

[0061] For a target single-factor object without a nested relationship, perform parsing processing on the target single-factor object according to the preset algorithm corresponding to the target single-factor object to obtain the parsing result corresponding to the target single-factor object. The specific process can refer to the description in part (2) above and will not be elaborated here;

[0062] For multiple target single-factor objects with a nested relationship, perform parsing processing on the multiple target single-factor objects according to the nested relationship between the multiple target single-factor objects and the preset algorithm corresponding to each target single-factor object, so as to obtain the parsing result corresponding to each target single-factor object. The specific process is as follows: First, determine the extraction rule corresponding to each target single-factor object according to the single-factor grammar corresponding to each target single-factor object; Second, determine the parsing order corresponding to each target single-factor object according to the nested relationship between the multiple target single-factor objects, where the parsing order corresponding to the target single-factor object in the innermost layer among the multiple target single-factor objects is earlier; Finally, perform parsing processing on each target single-factor object in turn according to the parsing order, extraction rule, and preset algorithm corresponding to each target single-factor object to obtain the parsing result corresponding to each target single-factor object. The specific process is as follows: S1: Determine the first target single-factor object that needs to be parsed according to the parsing order corresponding to each target single-factor object; S2: Extract multiple valid contents corresponding to the first target single-factor object from the first target single-factor object according to the extraction rule corresponding to the first target single-factor object. The valid contents corresponding to the first target single-factor object can be, but are not limited to, numerical values, strings, environment parameters, etc. When the valid content corresponding to the first target single-factor object is specifically an environment parameter, the Golang template text parser can request the parameter value corresponding to the environment parameter from the target client according to the parameter name corresponding to the environment parameter; S3: Perform parsing processing on the multiple valid contents corresponding to the first target single-factor object according to the preset algorithm corresponding to the first target single-factor object, that is, perform corresponding operations on the valid contents corresponding to the first target single-factor object according to the preset algorithm corresponding to the first target single-factor object, so as to obtain the parsing result corresponding to the first target single-factor object; S4: Determine whether the first target single-factor object is the outermost target single-factor object among the multiple target single-factor objects; if so, end the parsing process; if not, determine the second target single-factor object that needs to be parsed next according to the parsing order corresponding to each target single-factor object, substitute the parsing result corresponding to the first target single-factor object into the second target single-factor object, determine the second target single-factor object as the new first target single-factor object, and return to step S2.

[0063] 204. Use the parsing result corresponding to each target single-factor object to perform replacement processing on the corresponding content of the text to be parsed to obtain the first parsed text.

[0064] After the Golang template text parser obtains the parsing results corresponding to each target single-factor object through parsing, it can use the parsing results corresponding to each target single-factor object to replace the corresponding content in the text to be parsed. The text to be parsed after the replacement process is the first parsed text.

[0065] Specifically, in this step, for a target single-factor object without a nested relationship, in the text to be parsed, use the parsing result corresponding to the target single-factor object to replace the target single-factor object; for multiple target single-factor objects with a nested relationship, in the text to be parsed, use the parsing result corresponding to the outermost target single-factor object among the multiple target single-factor objects to replace the outermost target single-factor object.

[0066] 205. Use the regular expression corresponding to each multi-factor syntax to perform regular matching processing with the first parsed text to obtain one or more target multi-factor objects included in the first parsed text.

[0067] After the Golang template text parser obtains the first parsed text, it can use the regular expression corresponding to each multi-factor syntax to perform regular matching processing with the first parsed text, so as to obtain one or more target multi-factor objects included in the first parsed text.

[0068] Specifically, in this step, the specific process for the Golang template text parser to use the regular expression corresponding to each multi-factor syntax to perform regular matching processing with the first parsed text to obtain one or more target multi-factor objects included in the first parsed text is as follows: use the regular expression corresponding to each multi-factor syntax to perform regular matching processing with the multi-factor syntax tags included in the first parsed text. Among them, when the regular expression corresponding to a certain multi-factor syntax matches a certain group of multi-factor syntax tags in the first parsed text, determine the object to which the group of multi-factor syntax tags belongs as the target multi-factor object included in the first parsed text; after completing the operation of performing regular matching processing on multiple regular expressions with the multi-factor syntax tags included in the first parsed text, one or more target multi-factor objects included in the first parsed text can be obtained.

[0069] 206. Perform parsing processing on each target multi-factor object to obtain the parsing result corresponding to the text to be parsed.

[0070] After obtaining one or more target multi-factor objects contained in the first parsed text by the Golang template text parser, each target multi-factor object can be parsed and processed to obtain the parsing result corresponding to the text to be parsed. The following will detail how the Golang template text parser parses and processes each target multi-factor object to obtain the parsing result corresponding to the text to be parsed:

[0071] (1) Determine the preset algorithm corresponding to each target multi-factor object according to the multi-factor syntax corresponding to each target multi-factor object.

[0072] Since the mapping relationships between each multi-factor syntax and its corresponding regular expression, preset algorithm, and extraction rule are pre-stored in the local storage space of the target terminal device, for any target multi-factor object, the Golang template text parser can, according to the multi-factor syntax corresponding to the target multi-factor object, find the preset algorithm and extraction rule corresponding to the target multi-factor object among multiple mapping relationships; among them, for any multi-factor syntax, the extraction rule corresponding to the multi-factor syntax is used to extract the valid content corresponding to the multi-factor object in the multi-factor object corresponding to the multi-factor syntax, and the preset algorithm corresponding to the multi-factor syntax is used to select the target valid content from the multiple valid contents corresponding to the multi-factor object and determine the target valid content as the parsing result corresponding to the multi-factor object.

[0073] (2) When there is only one target multi-factor object in the parsed text, first determine the extraction rule corresponding to the target multi-factor object according to the multi-factor syntax corresponding to the target multi-factor object; then extract multiple valid contents corresponding to the target multi-factor object from the target multi-factor object according to the extraction rule corresponding to the target multi-factor object, where the valid contents corresponding to the target multi-factor object can be, but are not limited to, numerical values, strings, environmental parameters, etc. When the valid content corresponding to the target multi-factor object is specifically an environmental parameter, the Golang template text parser can request the parameter value corresponding to the environmental parameter from the target client according to the parameter name corresponding to the environmental parameter; then, perform parsing processing on the multiple valid contents corresponding to the target multi-factor object according to the preset algorithm corresponding to the target multi-factor object to obtain the parsing result corresponding to the target multi-factor object, that is, select the target valid content from the multiple valid contents corresponding to the target multi-factor object according to the preset algorithm corresponding to the target multi-factor object, and determine the target valid content as the parsing result corresponding to the target multi-factor object; finally, use the parsing result corresponding to the target multi-factor object to replace the corresponding content in the first parsed text to obtain the second parsed text, and determine the second parsed text as the parsing result corresponding to the text to be parsed. For example, if the target multi-factor object is: {{if T0}}T1{{else}}T2{{end}}, then the multiple valid contents extracted from the target multi-factor object according to the extraction rule corresponding to the target multi-factor object are T0, T1, and T2. The specific process of parsing and processing the multiple valid contents corresponding to the target multi-factor object according to the preset algorithm corresponding to the target multi-factor object is to determine whether T0 is true. If T0 is true, then select T1 as the target valid content and determine T1 as the parsing result corresponding to the target multi-factor object. If T0 is false, then select T2 as the target valid content and determine T2 as the parsing result corresponding to the target multi-factor object.

[0074] (3) When there are multiple target multi-factor objects in the parsed text and there is a nested relationship between the multiple target multi-factor objects, first determine the extraction rule corresponding to each target multi-factor object according to the multi-factor syntax corresponding to each target multi-factor object; then determine the parsing order corresponding to each target multi-factor object according to the nested relationship between the multiple target multi-factor objects, where the parsing order corresponding to the target multi-factor object in the innermost layer among the multiple target multi-factor objects is earlier; then, perform parsing processing on each target multi-factor object in turn according to the parsing order, extraction rule, and preset algorithm corresponding to each target multi-factor object to obtain the parsing result corresponding to each target multi-factor object; finally, use the parsing result corresponding to each target multi-factor object to replace the corresponding content in the first parsed text to obtain the third parsed text, and determine the third parsed text as the parsing result corresponding to the text to be parsed.

[0075] Specifically, in this step, according to the parsing order, extraction rules, and preset algorithms corresponding to each target multi-factor object, the specific process of parsing each target multi-factor object in sequence to obtain the parsing result corresponding to each target multi-factor object is as follows: First, according to the extraction rules corresponding to each target multi-factor object, extract multiple valid contents corresponding to each target multi-factor object from each target multi-factor object. Among them, for any target multi-factor object, the valid contents corresponding to this target multi-factor object can be, but are not limited to, numerical values, strings, environmental parameters, other target multi-factor objects embedded in this target multi-factor object, etc. When the valid content corresponding to this target multi-factor object is specifically an environmental parameter, the Golang template text parser can request the parameter value corresponding to this environmental parameter from the target client according to the parameter name corresponding to this environmental parameter; Second, according to the parsing order and multiple valid contents corresponding to each target multi-factor object, generate syntax trees corresponding to multiple target multi-factor objects. The syntax tree contains multiple nodes, and multiple nodes correspond one-to-one with multiple target multi-factor objects. For any target multi-factor object, the node corresponding to this target multi-factor object contains multiple valid contents corresponding to this target multi-factor object. For any node, the hierarchical order of this node in the syntax tree corresponds to the parsing order of the target multi-factor object it corresponds to, that is, the higher the hierarchical order of the node, the earlier its corresponding parsing order. For example, if the parsing order of the target multi-factor object corresponding to node X is the 5th, then node X is in the 5th layer of the syntax tree; Third, according to the hierarchical order corresponding to each node's layer and the preset algorithm corresponding to each target multi-factor object, parse the multiple valid contents included in each node in sequence to obtain the parsing result corresponding to each node; Finally, determine the parsing result corresponding to each target multi-factor object according to the parsing result corresponding to each node, that is, for any node, determine the parsing result corresponding to this node as the parsing result of the target multi-factor object corresponding to this node.

[0076] Among them, according to the hierarchical order corresponding to each node's level and the preset algorithm corresponding to each target multi-factor object, the specific process of successively parsing and processing the multiple valid contents included in each node to obtain the parsing result corresponding to each node is as follows: S11: Determine the first node that needs to be parsed and processed this time according to the hierarchical order corresponding to each node's level; S21: Parse and process the multiple valid contents included in the first node according to the preset algorithm corresponding to the first node to obtain the parsing result corresponding to the first node, that is, select the target valid content from the multiple valid contents included in the first node according to the preset algorithm corresponding to the first node, and determine the target valid content as the parsing result corresponding to the first node; S31: Determine whether the level where the first node is located is the lowest level in the multiple levels; if so, end the parsing process; if not, determine the second node that needs to be parsed and processed next according to the hierarchical order corresponding to each level, substitute the parsing result corresponding to the first node into the second node, determine the second node as the new first node, and return to step S21.

[0077] Further, as an implementation of the above Figure 1 and Figure 2 shown method, another embodiment of the present application further provides a text parsing device, which is applied to a target client, and the target client is a client developed based on the TypeScript language. This device embodiment corresponds to the foregoing method embodiment. For the convenience of reading, the details in the foregoing method embodiment will not be described one by one in this device embodiment, but it should be clear that the device in this embodiment can correspondingly implement all the contents in the foregoing method embodiment. This device is applied to improve the parsing efficiency of parsing Golang template text by a client developed based on the TypeScript language, specifically as Figure 3 shown, this device includes:

[0078] The first processing unit 31 is used to receive the text to be parsed sent by the server, and perform regular matching processing on the text to be parsed with the regular expression corresponding to each single-factor syntax to obtain one or more target single-factor objects included in the text to be parsed, where the text to be parsed is a Golang template text;

[0079] The second processing unit 32 is used to parse and process each of the target single-factor objects to obtain the parsing result corresponding to each of the target single-factor objects;

[0080] The replacement unit 33 is used to replace the corresponding content of the text to be parsed with the parsing result corresponding to each of the target single-factor objects to obtain the first parsed text;

[0081] A third processing unit 34, configured to perform regular matching processing on the first parsed text using a regular expression corresponding to each multi-factor grammar, so as to obtain one or more target multi-factor objects included in the first parsed text;

[0082] A fourth processing unit 35, configured to perform parsing processing on each of the target multi-factor objects, so as to obtain a parsing result corresponding to the text to be parsed.

[0083] Further, as Figure 4 shown, the second processing unit 32 is specifically configured to:

[0084] Determine a preset algorithm corresponding to each target single-factor object according to the single-factor grammar corresponding to each target single-factor object;

[0085] When the text to be parsed includes a target single-factor object, perform parsing processing on the target single-factor object according to the preset algorithm corresponding to the target single-factor object, so as to obtain a parsing result corresponding to the target single-factor object;

[0086] When the text to be parsed includes multiple target single-factor objects, determine whether there is a nesting relationship between the multiple target single-factor objects; for the target single-factor objects without a nesting relationship, perform parsing processing on the target single-factor objects according to the preset algorithm corresponding to the target single-factor objects, so as to obtain a parsing result corresponding to the target single-factor objects; for the multiple target single-factor objects with a nesting relationship, perform parsing processing on the multiple target single-factor objects according to the nesting relationship between the multiple target single-factor objects and the preset algorithm corresponding to each target single-factor object, so as to obtain a parsing result corresponding to each target single-factor object.

[0087] Further, as Figure 4 shown, the second processing unit 32 is specifically configured to:

[0088] Determine an extraction rule corresponding to the target single-factor object according to the single-factor grammar corresponding to the target single-factor object;

[0089] Extract multiple valid contents corresponding to the target single-factor object from the target single-factor object according to the extraction rule corresponding to the target single-factor object;

[0090] Perform parsing processing on the multiple valid contents corresponding to the target single-factor object according to the preset algorithm corresponding to the target single-factor object, so as to obtain a parsing result corresponding to the target single-factor object.

[0091] Further, as Figure 4 shown, the second processing unit 32 is specifically configured to:

[0092] Determine the extraction rule corresponding to each of the target single-factor objects according to the single-factor grammar corresponding to each of the target single-factor objects;

[0093] Determine the parsing order corresponding to each of the target single-factor objects according to the nesting relationship among the multiple target single-factor objects, wherein, among the multiple target single-factor objects, the parsing order corresponding to the target single-factor object in the innermost layer is earlier;

[0094] Perform parsing processing on each of the target single-factor objects in sequence according to the parsing order, extraction rule, and preset algorithm corresponding to each of the target single-factor objects, so as to obtain the parsing result corresponding to each of the target single-factor objects.

[0095] Further, as Figure 4 shown, the second processing unit 32 is specifically configured to:

[0096] S1: Determine the first target single-factor object that needs to be parsed this time according to the parsing order corresponding to each of the target single-factor objects;

[0097] S2: Extract multiple valid contents corresponding to the first target single-factor object from the first target single-factor object according to the extraction rule corresponding to the first target single-factor object;

[0098] S3: Perform parsing processing on the multiple valid contents corresponding to the first target single-factor object according to the preset algorithm corresponding to the first target single-factor object, so as to obtain the parsing result corresponding to the first target single-factor object;

[0099] S4: Determine whether the first target single-factor object is the outermost target single-factor object among the multiple target single-factor objects; if so, end the parsing processing; if not, determine the second target single-factor object that needs to be parsed next according to the parsing order corresponding to each of the target single-factor objects, substitute the parsing result corresponding to the first target single-factor object into the second target single-factor object, determine the second target single-factor object as the new first target single-factor object, and return to step S2.

[0100] Further, as Figure 4 shown, the replacement unit 33 is specifically configured to:

[0101] For the target single-factor objects without a nesting relationship, in the text to be parsed, replace the target single-factor objects with the parsing results corresponding to the target single-factor objects;

[0102] For multiple target single-factor objects with a nested relationship, in the text to be parsed, use the parsing result corresponding to the outermost target single-factor object among the multiple target single-factor objects to replace the outermost target single-factor object.

[0103] Further, as Figure 4 shown, the device further includes:

[0104] A fifth processing unit 36, configured to determine a preset algorithm corresponding to each target multi-factor object according to the multi-factor syntax corresponding to each target multi-factor object;

[0105] When the parsed text contains one target multi-factor object, determine an extraction rule corresponding to the target multi-factor object according to the multi-factor syntax corresponding to the target multi-factor object; extract multiple valid contents corresponding to the target multi-factor object from the target multi-factor object according to the extraction rule corresponding to the target multi-factor object, where the preset algorithm corresponding to the target multi-factor object is used to select a target valid content from the multiple valid contents corresponding to the target multi-factor object, and determine the target valid content as the parsing result corresponding to the target multi-factor object;

[0106] When the parsed text contains multiple target multi-factor objects, determine an extraction rule corresponding to each target multi-factor object according to the multi-factor syntax corresponding to each target multi-factor object; determine the parsing order corresponding to each target multi-factor object according to the nested relationship between the multiple target multi-factor objects, where the parsing order corresponding to the more inner target multi-factor object among the multiple target multi-factor objects is more forward;

[0107] A fourth processing unit 35 includes:

[0108] A first processing module 351, configured to, when the parsed text contains one target multi-factor object, perform parsing processing on the multiple valid contents corresponding to the target multi-factor object according to the preset algorithm corresponding to the target multi-factor object to obtain a parsing result corresponding to the target multi-factor object; perform replacement processing on the corresponding content in the first parsed text using the parsing result corresponding to the target multi-factor object to obtain a second parsed text, and determine the second parsed text as the parsing result corresponding to the text to be parsed;

[0109] The second processing module 352 is configured to, when multiple target multi-factor objects are included in the parsed text, sequentially perform parsing processing on each of the target multi-factor objects according to the parsing order, extraction rule, and preset algorithm corresponding to each target multi-factor object, so as to obtain the parsing result corresponding to each target multi-factor object; use the parsing result corresponding to each target multi-factor object to perform replacement processing on the corresponding content in the first parsed text, so as to obtain a third parsed text, and determine the third parsed text as the parsing result corresponding to the text to be parsed.

[0110] Further, as Figure 4 shown, the second processing module 352 is specifically configured to:

[0111] Extract multiple valid contents corresponding to each target multi-factor object from each target multi-factor object according to the extraction rule corresponding to each target multi-factor object;

[0112] Generate syntax trees corresponding to multiple target multi-factor objects according to the parsing order and multiple valid contents corresponding to each target multi-factor object, where the syntax tree includes multiple nodes, the nodes correspond to the target multi-factor objects one by one, the node corresponding to the target multi-factor object includes multiple valid contents corresponding to the target multi-factor object, the hierarchical order of the nodes in the syntax tree corresponds to the parsing order of the corresponding target multi-factor object, and the higher the hierarchical order where the node is located, the earlier the corresponding parsing order;

[0113] Sequentially perform parsing processing on multiple valid contents included in each node according to the hierarchical order corresponding to the level where each node is located and the preset algorithm corresponding to each target multi-factor object, so as to obtain the parsing result corresponding to each node;

[0114] Determine the parsing result corresponding to each target multi-factor object according to the parsing result corresponding to each node.

[0115] Further, as Figure 4 shown, the second processing module 352 is specifically configured to:

[0116] S11: Determine a first node that needs to be parsed this time according to the hierarchical order corresponding to the level where each node is located;

[0117] S21: Perform parsing processing on multiple valid contents included in the first node according to the preset algorithm corresponding to the first node, so as to obtain the parsing result corresponding to the first node;

[0118] S31: Determine whether the level where the first node is located is the lowest level in the multiple levels; if so, end the parsing process; if not, determine the second node that needs to be parsed next according to the level order corresponding to each level, substitute the parsing result corresponding to the first node into the second node, determine the second node as the new first node, and return to step S21.

[0119] Further, as Figure 4 shown, the single-factor grammar is a grammar in the Golang language that contains one grammar label, and the multi-factor grammar is a grammar in the Golang language that contains multiple grammar labels.

[0120] Further, as Figure 4 shown, the first processing unit 31 is specifically configured to:

[0121] Use the regular expression corresponding to each single-factor grammar to perform regular matching processing with the single-factor grammar labels included in the text to be parsed, so as to obtain one or more target single-factor objects included in the text to be parsed;

[0122] The third processing unit 34 is specifically configured to:

[0123] Use the regular expression corresponding to each multi-factor grammar to perform regular matching processing with the multi-factor grammar labels included in the first parsed text, so as to obtain one or more target multi-factor objects included in the first parsed text.

[0124] An embodiment of the present application provides a text parsing method and apparatus. In the embodiment of the present application, after the Golang template text parser receives the text to be parsed (i.e., Golang template text) sent by the server, the Golang template text parser first performs regular matching processing on the text to be parsed using the regular expression corresponding to each single-factor syntax, so as to obtain one or more target single-factor objects included in the text to be parsed; secondly, perform parsing processing on each target single-factor object to obtain the parsing result corresponding to each target single-factor object; thirdly, use the parsing result corresponding to each target single-factor object to perform replacement processing on the corresponding content of the text to be parsed, so as to obtain the first parsed text; then, perform regular matching processing on the first parsed text using the regular expression corresponding to each multi-factor syntax, so as to obtain one or more target multi-factor objects included in the first parsed text; finally, perform parsing processing on each target multi-factor object to obtain the parsing result corresponding to the text to be parsed, and use the parsing result corresponding to each target multi-factor object to perform replacement processing on the corresponding content in the first parsed text. The first parsed text after the replacement processing is the parsing result corresponding to the text to be parsed. Since, in the embodiment of the present application, after the client developed based on the TypeScript language receives the Golang template text sent by the server, the Golang template text parser embedded in the client (or the Golang template text parser running on the terminal device together with the client) can directly parse the Golang template text to obtain the parsing result, without interacting with the server again to request the server to parse the Golang template text. Therefore, it can effectively reduce the time consumed for parsing the Golang template text, and thus can effectively improve the parsing efficiency of the client developed based on the TypeScript language for parsing the Golang template text.

[0125] An embodiment of the present application provides a storage medium, the storage medium includes a stored program, wherein, when the program runs, it controls the device where the storage medium is located to execute the above-mentioned text parsing method.

[0126] The storage medium may include non-permanent memory in computer-readable media, random access memory (RAM) and / or non-volatile memory in the form of, for example, read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one storage chip.

[0127] An embodiment of the present application further provides a text parsing device, which includes a storage medium; and one or more processors. The storage medium is coupled to the processors, and the processors are configured to execute program instructions stored in the storage medium; when the program instructions run, they execute the above-mentioned text parsing method.

[0128] An embodiment of the present application provides a device, which includes a processor, a memory, and a program stored on the memory and executable on the processor. When the processor executes the program, the following steps are implemented:

[0129] Receive the text to be parsed sent by the server, and perform regular matching processing on the text to be parsed using the regular expression corresponding to each single-factor grammar to obtain one or more target single-factor objects included in the text to be parsed, where the text to be parsed is a Golang template text;

[0130] Perform parsing processing on each of the target single-factor objects to obtain the parsing result corresponding to each of the target single-factor objects;

[0131] Use the parsing result corresponding to each target single-factor object to perform replacement processing on the corresponding content of the text to be parsed to obtain a first parsed text;

[0132] Perform regular matching processing on the first parsed text using the regular expression corresponding to each multi-factor grammar to obtain one or more target multi-factor objects included in the first parsed text;

[0133] Perform parsing processing on each of the target multi-factor objects to obtain the parsing result corresponding to the text to be parsed.

[0134] Further, the performing parsing processing on each of the target single-factor objects to obtain the parsing result corresponding to each of the target single-factor objects includes:

[0135] Determine the preset algorithm corresponding to each target single-factor object according to the single-factor grammar corresponding to each target single-factor object;

[0136] When there is one target single-factor object included in the text to be parsed, perform parsing processing on the target single-factor object according to the preset algorithm corresponding to the target single-factor object to obtain the parsing result corresponding to the target single-factor object;

[0137] When there are multiple target single-factor objects in the text to be parsed, determine whether there is a nesting relationship between the multiple target single-factor objects; for the target single-factor objects without a nesting relationship, perform parsing processing on the target single-factor objects according to the preset algorithm corresponding to the target single-factor objects to obtain the parsing results corresponding to the target single-factor objects; for the multiple target single-factor objects with a nesting relationship, perform parsing processing on the multiple target single-factor objects according to the nesting relationship between the multiple target single-factor objects and the preset algorithm corresponding to each target single-factor object to obtain the parsing results corresponding to each target single-factor object.

[0138] Further, the method further includes:

[0139] Determine the extraction rule corresponding to the target single-factor object according to the single-factor grammar corresponding to the target single-factor object;

[0140] Extract multiple valid contents corresponding to the target single-factor object from the target single-factor object according to the extraction rule corresponding to the target single-factor object;

[0141] The performing parsing processing on the target single-factor object according to the preset algorithm corresponding to the target single-factor object to obtain the parsing result corresponding to the target single-factor object includes:

[0142] Perform parsing processing on the multiple valid contents corresponding to the target single-factor object according to the preset algorithm corresponding to the target single-factor object to obtain the parsing result corresponding to the target single-factor object.

[0143] Further, the method further includes:

[0144] Determine the extraction rule corresponding to each target single-factor object according to the single-factor grammar corresponding to each target single-factor object;

[0145] Determine the parsing order corresponding to each target single-factor object according to the nesting relationship between the multiple target single-factor objects, where the parsing order corresponding to the target single-factor object in the innermost layer among the multiple target single-factor objects is earlier;

[0146] The performing parsing processing on the multiple target single-factor objects according to the nesting relationship between the multiple target single-factor objects and the preset algorithm corresponding to each target single-factor object to obtain the parsing results corresponding to each target single-factor object includes:

[0147] Perform parsing processing on each target single-factor object in sequence according to the parsing order, extraction rule, and preset algorithm corresponding to each target single-factor object to obtain the parsing results corresponding to each target single-factor object.

[0148] Further, parsing each of the target single-factor objects in sequence according to the parsing order, extraction rule, and preset algorithm corresponding to each target single-factor object to obtain the parsing result corresponding to each target single-factor object includes:

[0149] S1: Determine a first target single-factor object that needs to be parsed this time according to the parsing order corresponding to each target single-factor object;

[0150] S2: Extract multiple valid contents corresponding to the first target single-factor object from the first target single-factor object according to the extraction rule corresponding to the first target single-factor object;

[0151] S3: Parse the multiple valid contents corresponding to the first target single-factor object according to the preset algorithm corresponding to the first target single-factor object to obtain the parsing result corresponding to the first target single-factor object;

[0152] S4: Determine whether the first target single-factor object is the outermost target single-factor object among the multiple target single-factor objects; if so, end the parsing process; if not, determine a second target single-factor object that needs to be parsed next according to the parsing order corresponding to each target single-factor object, substitute the parsing result corresponding to the first target single-factor object into the second target single-factor object, determine the second target single-factor object as the new first target single-factor object, and return to step S2.

[0153] Further, using the parsing result corresponding to each target single-factor object to perform replacement processing on the corresponding content of the text to be parsed to obtain a first parsed text includes:

[0154] For a target single-factor object without a nested relationship, in the text to be parsed, replace the target single-factor object with the parsing result corresponding to the target single-factor object;

[0155] For multiple target single-factor objects with a nested relationship, in the text to be parsed, replace the outermost target single-factor object with the parsing result corresponding to the outermost target single-factor object among the multiple target single-factor objects.

[0156] Further, the method further includes:

[0157] Determine the preset algorithm corresponding to each target multi-factor object according to the multi-factor syntax corresponding to each target multi-factor object;

[0158] When the parsed text contains a target multi-factor object, determine the extraction rule corresponding to the target multi-factor object according to the multi-factor syntax corresponding to the target multi-factor object; extract multiple valid contents corresponding to the target multi-factor object from the target multi-factor object according to the extraction rule corresponding to the target multi-factor object, where the preset algorithm corresponding to the target multi-factor object is used to select a target valid content from the multiple valid contents corresponding to the target multi-factor object, and determine the target valid content as the parsing result corresponding to the target multi-factor object;

[0159] When the parsed text contains multiple target multi-factor objects, determine the extraction rule corresponding to each target multi-factor object according to the multi-factor syntax corresponding to each target multi-factor object; determine the parsing order corresponding to each target multi-factor object according to the nesting relationship between the multiple target multi-factor objects, where the parsing order corresponding to the target multi-factor object in the innermost layer among the multiple target multi-factor objects is earlier;

[0160] The parsing process for each target multi-factor object to obtain the parsing result corresponding to the text to be parsed includes:

[0161] When the parsed text contains a target multi-factor object, perform a parsing process on the multiple valid contents corresponding to the target multi-factor object according to the preset algorithm corresponding to the target multi-factor object to obtain the parsing result corresponding to the target multi-factor object; use the parsing result corresponding to the target multi-factor object to perform a replacement process on the corresponding content in the first parsed text to obtain a second parsed text, and determine the second parsed text as the parsing result corresponding to the text to be parsed;

[0162] When the parsed text contains multiple target multi-factor objects, perform a parsing process on each target multi-factor object in sequence according to the parsing order, extraction rule, and preset algorithm corresponding to each target multi-factor object to obtain the parsing result corresponding to each target multi-factor object; use the parsing result corresponding to each target multi-factor object to perform a replacement process on the corresponding content in the first parsed text to obtain a third parsed text, and determine the third parsed text as the parsing result corresponding to the text to be parsed.

[0163] Further, the performing a parsing process on each target multi-factor object in sequence according to the parsing order, extraction rule, and preset algorithm corresponding to each target multi-factor object to obtain the parsing result corresponding to each target multi-factor object includes:

[0164] Extract multiple valid contents corresponding to each of the target multi-factor objects according to the extraction rules corresponding to each of the target multi-factor objects;

[0165] Generate syntax trees corresponding to multiple target multi-factor objects according to the parsing order and multiple valid contents corresponding to each of the target multi-factor objects, where the syntax tree includes multiple nodes, the nodes correspond to the target multi-factor objects one by one, the nodes corresponding to the target multi-factor objects include multiple valid contents corresponding to the target multi-factor objects, the hierarchical order of the nodes in the syntax tree corresponds to the parsing order of the corresponding target multi-factor objects, and the higher the hierarchical order where the node is located, the earlier the corresponding parsing order;

[0166] Parse and process the multiple valid contents included in each node in turn according to the hierarchical order corresponding to the level where each node is located and the preset algorithm corresponding to each target multi-factor object to obtain the parsing result corresponding to each node;

[0167] Determine the parsing result corresponding to each target multi-factor object according to the parsing result corresponding to each node.

[0168] Further, the step of parsing and processing the multiple valid contents included in each node in turn according to the hierarchical order corresponding to the level where each node is located and the preset algorithm corresponding to each target multi-factor object to obtain the parsing result corresponding to each node includes:

[0169] S11: Determine the first node that needs to be parsed and processed this time according to the hierarchical order corresponding to the level where each node is located;

[0170] S21: Parse and process the multiple valid contents included in the first node according to the preset algorithm corresponding to the first node to obtain the parsing result corresponding to the first node;

[0171] S31: Determine whether the level where the first node is located is the lowest level in the multiple levels; if so, end the parsing process; if not, determine the second node that needs to be parsed and processed next according to the hierarchical order corresponding to each level, substitute the parsing result corresponding to the first node into the second node, determine the second node as the new first node, and return to step S21.

[0172] Further, the single-factor syntax is a syntax in the Golang language that contains one syntax label, and the multi-factor syntax is a syntax in the Golang language that contains multiple syntax labels.

[0173] Further, the process of performing regular matching on the text to be parsed using the regular expression corresponding to each single-factor grammar to obtain one or more target single-factor objects included in the text to be parsed includes:

[0174] Performing regular matching on the single-factor grammar tags included in the text to be parsed using the regular expression corresponding to each single-factor grammar to obtain one or more target single-factor objects included in the text to be parsed;

[0175] The process of performing regular matching on the first parsed text using the regular expression corresponding to each multi-factor grammar to obtain one or more target multi-factor objects included in the first parsed text includes:

[0176] Performing regular matching on the multi-factor grammar tags included in the first parsed text using the regular expression corresponding to each multi-factor grammar to obtain one or more target multi-factor objects included in the first parsed text.

[0177] The present application also provides a computer program product, which when executed on a data processing device, is adapted to execute program code initialized with the following method steps: receiving the text to be parsed sent by the server, and performing regular matching on the text to be parsed using the regular expression corresponding to each single-factor grammar to obtain one or more target single-factor objects included in the text to be parsed, where the text to be parsed is a Golang template text; performing parsing processing on each of the target single-factor objects to obtain the parsing result corresponding to each target single-factor object; using the parsing result corresponding to each target single-factor object to perform replacement processing on the corresponding content of the text to be parsed to obtain the first parsed text; performing regular matching on the first parsed text using the regular expression corresponding to each multi-factor grammar to obtain one or more target multi-factor objects included in the first parsed text; and performing parsing processing on each of the target multi-factor objects to obtain the parsing result corresponding to the text to be parsed.

[0178] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0179] This application is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It should be understood that each flow and / or block in the flowchart and / or block diagram, and combinations of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing devices to generate a machine, such that the instructions executed by the processors of the computer or other programmable data processing devices produce means for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or multiple blocks.

[0180] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufactured article including instruction means that implement the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or multiple blocks.

[0181] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or multiple blocks.

[0182] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.

[0183] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of computer-readable media.

[0184] A computer-readable medium includes permanent and non-permanent, removable and non-removable media that can implement information storage by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transitory medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer-readable medium does not include transitory computer-readable media, such as modulated data signals and carrier waves.

[0185] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.

[0186] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, system or computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0187] The above are only embodiments of the present application and are not used to limit the present application. For those skilled in the art, the present application can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.

Claims

1. A text parsing method, characterized in that: The method is applied to a target client, where the target client is a client developed based on the TypeScript language, and the method includes: Receive the text to be parsed sent by the server, and use the regular expression corresponding to each single factor grammar to perform regular matching processing on the text to be parsed, so as to obtain one or more target single factor objects contained in the text to be parsed, wherein the text to be parsed is a Golang template text; Performing parsing processing on each of the target single factor objects to obtain a parsing result corresponding to each of the target single factor objects; Using the parsing result corresponding to each of the target single factor objects, corresponding content of the text to be parsed is replaced to obtain a first parsed text; Performing regular matching processing on the first parsed text using the regular expression corresponding to each multi-factor grammar to obtain one or more target multi-factor objects contained in the first parsed text; Each of the target multi-factor objects is parsed to obtain a parsing result corresponding to the text to be parsed.

2. The method according to claim 1, characterized in that The parsing process is performed on each of the target single factor objects to obtain a parsing result corresponding to each of the target single factor objects, including: Determining a preset algorithm corresponding to each of the target single factor objects according to the single factor grammar corresponding to each of the target single factor objects; When the to-be-parsed text contains a target single factor object, the target single factor object is parsed according to a preset algorithm corresponding to the target single factor object to obtain a parsing result corresponding to the target single factor object; When the text to be parsed contains multiple target single factor objects, determine whether there is a nested relationship between the multiple target single factor objects; for target single factor objects that do not have a nested relationship, parse the target single factor object according to the preset algorithm corresponding to the target single factor object to obtain the parsing result corresponding to the target single factor object; for multiple target single factor objects that have a nested relationship, parse the multiple target single factor objects according to the nested relationship between the multiple target single factor objects and the preset algorithm corresponding to each of the target single factor objects to obtain the parsing result corresponding to each of the target single factor objects.

3. The method according to claim 2, characterized in that The method further comprises: Determining an extraction rule corresponding to the target single factor object according to the single factor grammar corresponding to the target single factor object; extracting a plurality of valid contents corresponding to the target single factor object from the target single factor object according to an extraction rule corresponding to the target single factor object; The parsing process of the target single factor object according to the preset algorithm corresponding to the target single factor object to obtain the parsing result corresponding to the target single factor object includes: The multiple valid contents corresponding to the target single factor object are parsed according to a preset algorithm corresponding to the target single factor object to obtain a parsing result corresponding to the target single factor object.

4. The method according to claim 2, characterized in that: The method further comprises: Determine an extraction rule corresponding to each target single factor object according to the single factor grammar corresponding to each target single factor object; Determine the parsing order corresponding to each target single factor object according to the nested relationship between the multiple target single factor objects, wherein the parsing order corresponding to the target single factor object in the innermost layer of the multiple target single factor objects is higher; The parsing of the plurality of target single factor objects according to the nested relationship between the plurality of target single factor objects and the preset algorithm corresponding to each of the target single factor objects to obtain the parsing result corresponding to each of the target single factor objects includes: According to the parsing order, extraction rules and preset algorithm corresponding to each target single factor object, each target single factor object is parsed in turn to obtain a parsing result corresponding to each target single factor object.

5. The method according to claim 4, characterized in that The step of performing parsing processing on each target single factor object in turn according to the parsing order, extraction rule and preset algorithm corresponding to each target single factor object to obtain a parsing result corresponding to each target single factor object includes: S1: determining the first target single factor object to be parsed this time according to the parsing order corresponding to each target single factor object; S2: extracting a plurality of valid contents corresponding to the first target single factor object from the first target single factor object according to an extraction rule corresponding to the first target single factor object; S3: parsing the multiple valid contents corresponding to the first target single factor object according to the preset algorithm corresponding to the first target single factor object to obtain the parsing result corresponding to the first target single factor object; S4: Determine whether the first target single factor object is the outermost target single factor object among the multiple target single factor objects; if so, end the parsing process; if not, determine the second target single factor object that needs to be parsed next time according to the parsing order corresponding to each target single factor object, substitute the parsing result corresponding to the first target single factor object into the second target single factor, determine the second target single factor object as the new first target single factor object, and return to step S2.

6. The method according to claim 2, characterized in that The replacing corresponding content of the to-be-parsed text using the parsing result corresponding to each of the target single factor objects to obtain a first parsed text includes: For a target single factor object that does not have a nested relationship, in the text to be parsed, the target single factor object is replaced with a parsing result corresponding to the target single factor object; For multiple target single factor objects in a nested relationship, in the to-be-parsed text, the outermost target single factor object among the multiple target single factor objects is replaced with the parsing result corresponding to the outermost target single factor object.

7. The method according to claim 1, characterized in that The method further comprises: Determining a preset algorithm corresponding to each of the target multi-factor objects according to the multi-factor syntax corresponding to each of the target multi-factor objects; When the parsed text contains a target multi-factor object, determining an extraction rule corresponding to the target multi-factor object according to the multi-factor grammar corresponding to the target multi-factor object; extracting multiple valid contents corresponding to the target multi-factor object from the target multi-factor object according to the extraction rule corresponding to the target multi-factor object, wherein the preset algorithm corresponding to the target multi-factor object is used to select target valid contents from the multiple valid contents corresponding to the target multi-factor object, and determining the target valid contents as the parsing result corresponding to the target multi-factor object; When the parsed text contains multiple target multi-factor objects, the extraction rule corresponding to each target multi-factor object is determined according to the multi-factor grammar corresponding to each target multi-factor object; the parsing order corresponding to each target multi-factor object is determined according to the nested relationship between the multiple target multi-factor objects, wherein the parsing order corresponding to the target multi-factor object in the innermost layer of the multiple target multi-factor objects is higher; The parsing process is performed on each of the target multi-factor objects to obtain a parsing result corresponding to the text to be parsed, including: When the parsed text contains a target multi-factor object, a plurality of valid contents corresponding to the target multi-factor object are parsed according to a preset algorithm corresponding to the target multi-factor object to obtain a parsing result corresponding to the target multi-factor object; the parsing result corresponding to the target multi-factor object is used to replace the corresponding content in the first parsed text to obtain a second parsed text, and the second parsed text is determined as the parsing result corresponding to the text to be parsed; When the parsed text contains multiple target multi-factor objects, each of the target multi-factor objects is parsed in turn according to the parsing order, extraction rules and preset algorithm corresponding to each of the target multi-factor objects to obtain a parsing result corresponding to each of the target multi-factor objects; the parsing result corresponding to each of the target multi-factor objects is used to replace the corresponding content in the first parsed text to obtain a third parsed text, and the third parsed text is determined as the parsing result corresponding to the text to be parsed.

8. The method according to claim 7, characterized in that The step of performing parsing processing on each target multi-factor object in turn according to the parsing order, extraction rule and preset algorithm corresponding to each target multi-factor object to obtain a parsing result corresponding to each target multi-factor object includes: Extracting a plurality of valid contents corresponding to each target multi-factor object from each target multi-factor object according to an extraction rule corresponding to each target multi-factor object; Generate multiple syntax trees corresponding to the target multi-factor objects according to the parsing order and multiple valid contents corresponding to each of the target multi-factor objects, wherein the syntax tree includes multiple nodes, the nodes correspond to the target multi-factor objects one-to-one, the nodes corresponding to the target multi-factor objects include multiple valid contents corresponding to the target multi-factor objects, the hierarchical order of the nodes in the syntax tree corresponds to the parsing order of the corresponding target multi-factor objects, and the higher the hierarchical order of the nodes, the earlier the corresponding parsing order; According to the hierarchical order corresponding to the hierarchical level of each node and the preset algorithm corresponding to each target multi-factor object, the multiple valid contents contained in each node are parsed in turn to obtain the parsing result corresponding to each node; The parsing result corresponding to each of the target multi-factor objects is determined according to the parsing result corresponding to each of the nodes.

9. The method according to claim 8, characterized in that According to the hierarchical order corresponding to the hierarchical level of each node and the preset algorithm corresponding to each target multi-factor object, the multiple valid contents contained in each node are parsed in turn to obtain the parsing result corresponding to each node, including: S11: determining the first node to be parsed this time according to the hierarchical order corresponding to the hierarchical level of each node; S21: parsing the multiple valid contents included in the first node according to a preset algorithm corresponding to the first node to obtain a parsing result corresponding to the first node; S31: Determine whether the level where the first node is located is the level with the lowest level order among the multiple levels; if so, end the parsing process; if not, determine the second node that needs to be parsed next time according to the level order corresponding to each level, substitute the parsing result corresponding to the first node into the second node, determine the second node as the new first node, and return to step S21.

10. The method according to any one of claims 1 to 9, characterized in that The single-factor grammar is a grammar containing one grammar label in the Golang language, and the multi-factor grammar is a grammar containing multiple grammar labels in the Golang language.

11. The method according to claim 10, characterized in that The method of using the regular expression corresponding to each single factor grammar to perform regular matching processing with the text to be parsed to obtain one or more target single factor objects contained in the text to be parsed includes: Performing regular matching processing on the regular expression corresponding to each of the single-factor grammars and the single-factor grammar labels contained in the text to be parsed, so as to obtain one or more target single-factor objects contained in the text to be parsed; The using a regular expression corresponding to each multi-factor syntax to perform regular matching processing with the first parsed text to obtain one or more target multi-factor objects contained in the first parsed text includes: A regular expression corresponding to each of the multi-factor grammars is used to perform regular matching processing with the multi-factor grammar tags contained in the first parsed text to obtain one or more target multi-factor objects contained in the first parsed text.

12. A text analysis device, characterized in that: The device is applied to a target client, which is a client developed based on the TypeScript language, and includes: A first processing unit is used to receive a text to be parsed sent by a server, and use a regular expression corresponding to each single factor grammar to perform regular matching processing on the text to be parsed, so as to obtain one or more target single factor objects contained in the text to be parsed, wherein the text to be parsed is a Golang template text; A second processing unit is used to perform parsing processing on each of the target single factor objects to obtain a parsing result corresponding to each of the target single factor objects; A replacement unit, configured to use the parsing result corresponding to each of the target single factor objects to replace the corresponding content of the text to be parsed, so as to obtain a first parsed text; A third processing unit is used to perform regular matching processing on the first parsed text using a regular expression corresponding to each multi-factor grammar to obtain one or more target multi-factor objects contained in the first parsed text; The fourth processing unit is used to perform parsing processing on each of the target multi-factor objects to obtain a parsing result corresponding to the text to be parsed.

13. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the text parsing method according to any one of claims 1 to 11.

14. A text analysis device, characterized in that: The device includes a storage medium; and one or more processors, the storage medium is coupled to the processor, and the processor is configured to execute program instructions stored in the storage medium; when the program instructions are executed, the text parsing method described in any one of claims 1 to 11 is executed.