CN113031959B - Variable replacement method, device, system and storage medium - Google Patents

Variable replacement method, device, system and storage medium Download PDF

Info

Publication number
CN113031959B
CN113031959B CN202110266762.6A CN202110266762A CN113031959B CN 113031959 B CN113031959 B CN 113031959B CN 202110266762 A CN202110266762 A CN 202110266762A CN 113031959 B CN113031959 B CN 113031959B
Authority
CN
China
Prior art keywords
value
variable
data type
preset
key
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110266762.6A
Other languages
Chinese (zh)
Other versions
CN113031959A (en
Inventor
李�瑞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingsoft Cloud Network Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Kingsoft Cloud Network Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN202110266762.6A priority Critical patent/CN113031959B/en
Publication of CN113031959A publication Critical patent/CN113031959A/en
Application granted granted Critical
Publication of CN113031959B publication Critical patent/CN113031959B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing

Abstract

The embodiment of the invention relates to a variable replacement method, a device, a system and a storage medium, wherein the method comprises the following steps: acquiring first description information containing a preset variable expression, at least one variable value and identification information; analyzing the first description information to obtain key value pairs; traversing the data types corresponding to the values in the key value pairs in sequence; when the data type of the first value is a first preset data type, extracting a preset variable expression from the first value; extracting a first variable value corresponding to the variable according to the identification information and the variable; and replacing the variables in the preset variable expression with the first variable values according to the preset variable expression and the first variable values until all the variables in the first description information are replaced with the variable values corresponding to the variables, and outputting the second description information. In this way, the original syntax of Json or Yaml is preserved, and the replacement process of variables is completed with sufficient support for Json or Yaml data types.

Description

Variable replacement method, device, system and storage medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a variable replacement method, a variable replacement device, a variable replacement system and a storage medium.
Background
When describing information with Json or Yaml, some of the data in the expression describing the information needs to be determined at run time, so that in the initial expression, the some data is temporarily embodied in the form of variables. When the specific value of the part of data is determined, the part of data is replaced by the corresponding variable.
In related art, a stencil engine is generally used to implement a process of replacing data with corresponding variables, such as Go Template, beetl, enjoy, freemarker, etc. However, when these template engines are used to perform the above operations, there are the following problems:
first, the template engine's own grammar hierarchy breaks down the json or Yaml original grammar.
Taking Go Template as an example, in the grammar hierarchy of Go Template, the contents of the { } package grammar will be parsed, and the contents not wrapped by { } will be output as it is. Referring specifically to FIG. 1, FIG. 1 schematically processes a code expression under the Go Template grammar hierarchy. For the content in { { } in fig. 1, the syntax parsing tool of Json or Yaml cannot recognize, and further cannot continue to run the program.
Second, the basic data types of Json and Yaml include: string, number, object, array, boolean, null, etc. However, the general template engine does not support the data types natively, and if the data types are to be output, other plug-in implementation is needed, and the operation process is complicated.
Disclosure of Invention
In view of this, in order to solve all or part of the above technical problems in the prior art, embodiments of the present invention provide a variable replacement method, device, system, and storage medium.
In a first aspect, an embodiment of the present invention provides a variable replacement method, including:
acquiring first description information containing a preset variable expression, at least one variable value and identification information corresponding to each variable value;
analyzing the first description information to obtain at least one key value pair;
traversing the data types corresponding to the values in each key value pair in sequence;
when the data type of the first value is a first preset data type, extracting a preset variable expression from the first value, wherein the first value is a value corresponding to a first key value pair in at least one key value pair, the first key value pair is any key value pair in the at least one key value pair, and the preset variable expression comprises a variable;
extracting a first variable value corresponding to the variable from at least one variable value according to the identification information and the variable;
and replacing the variables in the preset variable expression with the first variable values according to the preset variable expression and the first variable values until all the variables in the first description information are replaced with the variable values corresponding to the variables, and outputting the second description information.
In one possible embodiment, when the data type of the first value is the second preset data type, the method further includes:
taking the first value as a key value pair of the ith sub-layer, and carrying out hierarchical progressive division;
taking the current layer as a key word in the key value pair of the ith sub-layer, and taking the sub-layer of the current layer as the ith value corresponding to the key value of the ith sub-layer;
identifying a data type of the ith value;
when the data type of the ith value is the first data type, extracting a preset variable expression from the ith value,
or when the data type of the ith value is still the second preset data type, taking the ith value as a key value pair of the (i+1) th sub-layer, carrying out hierarchical division again, and traversing until the data type of the value contained in the final sub-layer corresponding to the key value of the ith sub-layer is identified as the first data type, and extracting a preset variable expression from the final sub-layer, wherein i is a positive integer.
In one possible embodiment, when the data type of the value is not the first preset data type or the second preset data type, any processing operation of the key-value pair corresponding to the value is stopped, wherein the value includes a first value, an i-th value, and a value of the i+1-th sub-layer.
In one possible embodiment, when the first variable value is the second preset data type, after extracting the first variable value corresponding to the variable from the at least one variable value according to the identification information and the variable, the method further includes:
the first variable value is used as a new key value pair to carry out hierarchical division;
taking the current layer as a key word in the new key value pair, and taking the sub-layer of the current layer as a value in the new key value pair;
identifying a data type of the new key value pair median;
when the data type of the median value of the new key value pair is still the second preset data type, taking the value in the new key value pair as another new key value pair again, and carrying out hierarchical division again and traversing;
and (3) finishing traversing to the last sub-level in the first variable value, and taking the value corresponding to the last sub-level as the final variable value corresponding to the variable.
In one possible embodiment, the preset variable expression further includes: the variable value presets an output data type expression and/or a variable default output value;
the variable value is preset to output a data type expression for indicating the data type of the final output of the variable value corresponding to the variable;
And the variable default output value is used for replacing the variable with the default output value when the variable value corresponding to the variable is determined to be empty.
In one possible implementation, the first data type is a string type and the second data type is an object and/or array type.
In a second aspect, an embodiment of the present invention provides a variable displacement apparatus, including:
the acquisition unit is used for acquiring first description information containing a preset variable expression, at least one variable value and identification information corresponding to each variable value;
the analysis unit is used for analyzing the first description information and acquiring at least one key value pair;
the processing unit is used for traversing the data types corresponding to the values in each key value pair in sequence;
the extraction unit is used for extracting a preset variable expression from the first value when the data type of the first value is a first preset data type, wherein the first value is a value corresponding to a first key value pair in at least one key value pair, the first key value pair is any key value pair in the at least one key value pair, and the preset variable expression comprises a variable;
extracting a first variable value corresponding to the variable from at least one variable value according to the identification information and the variable;
And the replacing unit is used for replacing the variables in the preset variable expression with the first variable values according to the preset variable expression and the first variable values until all the variables in the first description information are replaced with the variable values corresponding to the variables, and outputting the second description information.
In a possible implementation manner, when the data type of the first value is the second preset data type, the processing unit is further configured to use the first value as a key value pair of the ith sublayer to perform hierarchical progressive division; taking the current layer as a key word in the key value pair of the ith sub-layer, and taking the sub-layer of the current layer as the ith value corresponding to the key value of the ith sub-layer;
identifying a data type of the ith value;
when the processing unit recognizes that the data type of the ith value is still the second preset data type, the ith value is used as a key value pair of the (i+1) th sub-layer, hierarchical division is carried out again, and traversal is carried out;
or when the processing unit identifies that the data type of the ith value is the first data type, the extracting unit is further configured to extract a preset variable expression from the ith value, where i is a positive integer.
In a third aspect, embodiments of the present invention provide a variable replacement system, the system comprising: at least one processor and memory;
The processor is configured to execute a variable replacement program stored in the memory, such as the variable replacement method described in any of the embodiments of the first aspect.
In a fourth aspect, an embodiment of the present invention provides a computer storage medium storing one or more programs executable by a variable replacement system as described in the third aspect to implement a variable replacement method as described in any of the embodiments of the first aspect.
According to the variable replacement method provided by the embodiment of the invention, the first description information containing the preset variable expression, at least one variable value and the identification information corresponding to each variable value are obtained. And then analyzing the first description information to obtain at least one key value pair. Traversing the data types corresponding to the values in each key value pair in turn, and extracting a preset variable expression from the first value if the data type is the first data type. That is, the data type of the variable expression is the first data type. And extracting the variable from the variable expression, and acquiring a variable value corresponding to the variable according to the identification information and the variable. And outputting the second descriptive information after all variables in the first descriptive information have been replaced with variable values. In this way, the variables and variable values are saved by using data in the form of Json or Yaml, the original grammar of the Json or Yaml is maintained, and the replacement process of the variables is completed on the premise of fully supporting the data types of the Json or Yaml. The operation is simple and convenient, and the working cost can not be increased.
Drawings
FIG. 1 is a schematic flow chart of a variable replacement method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a variable substitution method provided by the present invention;
FIG. 3 is a schematic diagram of steps of a processing method when a variable value provided by the present invention is a second preset data type such as an array or an object;
FIG. 4 is a schematic diagram of a variable displacement device according to an embodiment of the present invention;
fig. 5 is a schematic diagram of a variable replacement system according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
For the purpose of facilitating an understanding of the embodiments of the present invention, reference will now be made to the following description of specific embodiments, taken in conjunction with the accompanying drawings, which are not intended to limit the embodiments of the invention.
Fig. 1 is a schematic flow chart of a variable replacement method according to an embodiment of the present invention, where, as shown in fig. 1, the method is executed by an application program that replaces a running variable with a variable value, for example, to include:
step 110, obtaining first description information including a preset variable expression, at least one variable value, and identification information corresponding to each variable value.
Specifically, the first description information is the description information of the variable that needs to be replaced. The variable in the first description information requires a replacement variable value, i.e. one of the at least one variables mentioned above. And identification information corresponding to the variable value may be used to identify the variable corresponding to the variable value.
And 120, analyzing the first description information to obtain at least one key value pair.
Specifically, the first description information is in the form of an expression of a key value pair. Some of the key values correspond to the corresponding expressions and include preset variable expressions. Some key value pairs do not include preset variable expressions. Therefore, the description information needs to be parsed first to obtain at least one key value pair. For example, the first description information is: version: "@ { V@str }"; labels: "@ { L@ obj }" and "
After analysis, the key is found to comprise two key value pairs, wherein key1 is A, value1 is version: "@ { V@str }"; key2 is B, value2 is: labels: "@ { L@ obj }.
Each time a key-value pair is executed, only one key-value pair is processed, i.e. the subsequent steps are performed. After the execution is completed, the subsequent steps are repeatedly executed on the other key value. And ending the operation until all the key value pairs execute the subsequent steps. Specifically, the following steps are seen as follows:
step 130, traversing the data types corresponding to the values in each key-value pair in turn.
Specifically, the expression form of the key-value pair includes key-value. For example, the first description information is: name, "@ { A:15@ num }). The first description information is a key value pair, the key is name, and the value is: "@ { A:15@ num }).
Or, the first description information is: metadata:
name:"@{A:15@num}"
wherein, the key is metadata, and the value is name: "@ { A:15@ num }.
In step 140, when the data type of the first value is the first preset data type, a preset variable expression is extracted from the first value.
Specifically, in the two examples listed in step 130, the value in the first example is @ { A:15@ num }. The value is defined as a first value, i.e. the string type, assuming that the first predetermined data type is the string type. The value extracts a preset variable expression, and expression information in the character string can be extracted in the form of a regular expression during specific execution.
The first value is a value corresponding to a first key value in at least one key value pair, the first key value pair is any key value pair in at least one key value pair, and the preset variable expression comprises a variable. For example, the default variable expression in name @ { A:15@ num } "is @ { A:15@ num. The preset variable expression comprises a variable A.
Optionally, the preset variable expression may further include a variable value preset output data type expression, and/or a variable default output value.
The variable value presets an output data type expression which is used for indicating the data type of the final output of the variable value. And the variable default output value is used for replacing the variable with the default output value when the variable value corresponding to the variable is determined to be empty. In the preset variable expression, 15 is a variable default output value, and num is a variable value preset output data type expression.
In a specific example, the preset variable expression is expressed as follows: @ { key: default @ type }. Wherein the key represents a variable name, further, the key may be a representation form such as a key a.key b, which represents that a variable value corresponding to the key b in the key a object is acquired. "." represents recursively acquiring the next set of data.
default: for the default output value of the variable, when a variable value corresponding to the variable cannot be found from at least one variable value, the value specified by default is used as the variable value. Of course, the variable default output value may not be specified. Then, the preset variable expression is shaped as: @ { key @ type }.
type: the variable value presets an output data type expression for indicating the data type of the final output of the variable value corresponding to the variable. When the output type is not specified, the output is outputted by the type of the variable value by default.
Specifically, the data output types include, but are not limited to, one or more of the following:
when the expression of the type is str or string, determining that the output type is a character string;
when the expression of the type is num or number, determining that the output type is a number;
when the expression of the type is obj or object or map, determining that the output type is a Json or Yaml object;
when the expression of the type is ar or array, determining the output type as an array;
when the expression of type is bool or bootan, it is determined that the output type is boolean.
And step 150, extracting a first variable value corresponding to the variable from at least one variable value according to the identification information and the variable.
Step 160, replacing the variable in the preset variable expression with the first variable value according to the preset variable expression and the first variable value; and outputting the second description information after all variables in the first description information are replaced by variable values corresponding to the variables.
Specifically, taking the above first description information as an example, for example, the input data includes first description information metadata:
name: "@ { A:15@ num }"; the variable value and the identification information corresponding to the variable value specifically comprise: and A is 5, namely the identification information corresponding to the variable value is A, and the variable value is 5.
According to the identification information A: and 5, and the variable A, determining that the first variable value corresponding to the variable is 5.
According to the preset variable expression and the first variable value, after the variables in the preset variable expression are replaced by the first variable value, outputting second description information as follows:
metadata:
name:5。
because in this example there is only one key value pair, the value in the key value pair is the string type, and there is only one variable value. The execution process is relatively simple.
In another case, assuming that the data type of the first value is the second preset data type, the method may further include:
taking the first value as a key value pair of the ith sub-layer, and carrying out hierarchical progressive division;
taking the current layer as a key word in the key value pair of the ith sub-layer, and taking the sub-layer of the current layer as the ith value corresponding to the key value of the ith sub-layer;
identifying a data type of the ith value;
when the data type of the ith value is the first data type, extracting a preset variable expression from the ith value,
Or when the data type of the ith value is still the second preset data type, taking the ith value as a key value pair of the (i+1) th sub-layer, carrying out hierarchical division again, and traversing until the data type of the value contained in the final sub-layer corresponding to the key value of the ith sub-layer is identified as the first data type, and extracting a preset variable expression from the final sub-layer, wherein i is a positive integer.
Optionally, the second preset data type is an object and/or array type. Taking the second data type as an object type as an example, for example, the first description information corresponds to:
metadata:
data:
version:"@{V@str}"
labels:"@{L@obj}"
metadata is key, data:
version:"@{V@str}"
labels: "@ { L@obj }" is velue.
It is apparent that the data type included in the data is an array type. Therefore, data can be used as a key value pair of the ith sub-layer, and then hierarchical division is performed. Namely, data:
version:"@{V@str}"
labels: "@ { L@obj }" is used as the key value pair of the first sub-layer, and then hierarchical division is performed, including: data (version (@ { V@str }), labels (@ { L@obj }). The current layer data is used as a key word in the key value pair of the first sub-layer;
data sublayer: version: "@ { V@str }" and labels: "@ { L@obj }" are used as two values in the key value pair, respectively.
It can be identified that both values are of the second preset data type, so that further hierarchy partitioning is required.
That is, version: "@ { V@str }" and labels: "@ { L@obj }" are taken as the key value pairs of the second sub-layer, respectively.
The following operations are then performed for each key value pair, respectively:
taking version: "@ { V@str }" as an example, version is taken as a key in the key pair version: "@ { V@str }" of the second sub-level, and "@ { V@str }" is taken as a value in the key pair version: "@ { V@str }" of the second sub-level. Then, the data type of the value of the second sub-level is determined again. The data type of the second sub-level value may be determined to be a character string type, and thus the preset variable expression may be extracted from the second sub-level value. The second sub-level here, i.e. the final sub-level to which the key value of the first sub-level corresponds. The extracted preset variable expression is @ { V@str }.
Similarly, the preset variable expression is @ { L@obj } can be extracted from the final sub-level "@ { L@obj }" of labels @ { L@obj }.
In another specific example, for example, the first description information is: metadata:
data:
version:"@{V@str}"
the first value is data:
version:"@{V@str}"。
the first value is used as a key value pair of the first sub-layer, and after hierarchical division, a keyword version is obtained, wherein value is "@ { V@str }. It is apparent that the data type of the value is the first data type. Therefore, the preset variable expression @ { V@str }, can be extracted directly from value.
In yet another case, when the data type of the value is not the first preset data type or the second preset data type, any operation of the key value pair corresponding to the value is stopped. Wherein the values include a first value, an i-th value, and a value of an i+1-th sub-layer.
In a specific example, when the data type corresponding to the value is a data type such as a number, boolean or null, it is obvious that the data type does not include the first preset data type, and therefore no special processing is required.
In the above, the description is given of the case where the data type included in the first description information includes the first data type, the second data type, or the other data types. In practice, there may also be situations in which the variable value is of the second preset data type.
Optionally, when the first variable value is of the second preset data type, for example, the first variable value is of the array type, after the first variable value corresponding to the variable is extracted from at least one variable value according to the identification information and the variable, the method further includes:
the first variable value is used as a new key value pair to carry out hierarchical division;
taking the current layer as a key word in the new key value pair, and taking the sub-layer of the current layer as a value in the new key value pair;
Identifying a data type of the new key value pair median;
when the data type of the median value of the new key value pair is still the second preset data type, taking the value in the new key value pair as another new key value pair again, and carrying out hierarchical division again and traversing;
and (3) finishing traversing to the last sub-level in the first variable value, and taking the value corresponding to the last sub-level as the final variable value corresponding to the variable.
Specifically, the processing manner in which the first value corresponding to the first description information is the second preset data type is similar. The first variable value is also used as a new key value pair to carry out hierarchical division.
For example, the first variable value is: a:
B:
5
and taking the first variable value as a new key value pair, wherein A is a keyword, and B is a value. If the data type in the value is the second data type, that is, the data type of B is still the second data type, B needs to be taken as another new key value pair again, and then hierarchical division is performed. And taking the current layer, namely B as a key in the new key value pair, and taking the sublayer xxx of the current layer as a value. The value corresponding to data may be determined to be 5, which is a specific value, and which is the highest sub-level of the first variable value. That is, the last sub-level in the first variable value has been traversed, at which point the traversal is ended, with the final variable value corresponding to the value 5 variable corresponding to the last sub-level.
Hereinafter, the above operation processes will be summarized and summarized, and specific operation flows are shown in fig. 2, and fig. 2 is a schematic diagram of a variable replacement method provided in the present invention. Comprising the following steps:
1. and acquiring first description information containing a preset variable expression, at least one variable value and identification information corresponding to each variable value.
2. And analyzing the first description information to obtain at least one key value pair, wherein the number of the key value pairs is assumed to be 2. The key-value pairs include key and value, respectively noted SK, and SV. Each key-value pair includes a variable. In response, two variable values are recorded as CTX.
3. Traversing each key value pair and looking up the type of the median value of the key value pairs.
4. If the type of the key value pair is a character string, extracting a preset variable expression from the SV by using a regular expression. I.e. extracting key, default, type information. And then, acquiring a variable value of the key from the CTX, and determining the variable value of the key according to the identification information, namely the PV. See if PV is empty, in one case, if not, the variable value of the key is PV. The type that converts PV to type is PV'. SV is replaced with PV'.
In another case, if the PV is empty, it is checked whether the value of default is empty. If the default is not null, the variable value is the value corresponding to the default. The variable value (default) is then converted to a type, namely PV'.
In another case, if default is null, then the variable value is null. The variable value (null) is converted to type, i.e., PV'.
And step 5, if the data type of the value in the key value pair is the second preset data type such as an object, an array and the like, taking the value as a new key value pair, and checking the type of the median value of the new key value pair. If the object or array type is still present, the operation of step 5 is still repeated. And (4) repeating the operation of the step (4) until the data type of the value is determined to be the character string type.
Step 6, if the data type of the value in the key value pair is a type other than a character string, an object or an array, for example, a numeric, boolean or null type, any processing on the current key value pair is ended.
After the above process is performed, a conversion process of the key value pair variable is completed. It is also necessary to determine whether there is a next key value pair. If so, the above process is repeatedly performed to complete the replacement of the variable in the key value pair. If there is no next key value pair, then end.
Fig. 3 illustrates the steps of the processing method when the variable value is the second preset data type such as an array or an object, and the processing method is specifically shown in fig. 3.
Step 1, the first variable value is marked as CTX. The keys are partitioned into arrays. That is, if the first variable value is in the form of an array, the corresponding variable must also be in the form of an array. For example, the variable is a.b, the variable value is a:
B:8。
that is, the variable value corresponding to the key b in the object key a is finally acquired.
2. The variables are converted into A { B }, traversing A, and recording K.
3. And acquiring data from the CTX, namely C.
4. If C is the second preset data type such as the object or the array, C is marked as CTX, and then the CTX type is continuously judged. If the CTX type is the second preset data type, re-executing the step 3.
5. If the CTX type is not the second preset data type, then CTX is either null or there is a specific value. In either case, the traversal may be stopped. That is, both cases may indicate that the final sub-level corresponding to the first variable value has been reached. The final value (null or concrete value) obtained is taken as the final variable value corresponding to the variable.
As in the example described above, the value of the variable corresponding to key b is 8.
According to the variable replacement method provided by the embodiment of the invention, the first description information containing the preset variable expression, at least one variable value and the identification information corresponding to each variable value are obtained. And then analyzing the first description information to obtain at least one key value pair. Traversing the data types corresponding to the values in each key value pair in turn, and extracting a preset variable expression from the first value if the data type is the first data type. That is, the data type of the variable expression is the first data type. And extracting the variable from the variable expression, and acquiring a variable value corresponding to the variable according to the identification information and the variable. And outputting the second descriptive information after all variables in the first descriptive information have been replaced with variable values. In this way, the variables and variable values are saved by using data in the form of Json or Yaml, the original grammar of the Json or Yaml is maintained, and the replacement process of the variables is completed on the premise of fully supporting the data types of the Json or Yaml. The operation is simple and convenient, and the working cost can not be increased.
Fig. 4 is a variable displacement device according to an embodiment of the present invention, where the variable displacement device includes: an acquisition unit 401, a parsing unit 402, a processing unit 403, an extraction unit 404, and a replacement unit 405.
An obtaining unit 401, configured to obtain first description information including a preset variable expression, at least one variable value, and identification information corresponding to each variable value;
an parsing unit 402, configured to parse the first description information to obtain at least one key value pair;
a processing unit 403, configured to traverse the data types corresponding to the values in each key value pair in sequence;
an extracting unit 404, configured to extract a preset variable expression from the first value when the data type of the first value is a first preset data type, where the first value is a value corresponding to a first key value pair in at least one key value pair, the first key value pair is any key value pair in at least one key value pair, and the preset variable expression includes a variable;
extracting a first variable value corresponding to the variable from at least one variable value according to the identification information and the variable;
and the replacing unit 405 is configured to replace the variables in the preset variable expression with the first variable values according to the preset variable expression and the first variable values until all the variables in the first description information have been replaced with the variable values corresponding to the variables, and output the second description information.
Optionally, when the data type of the first value is the second preset data type, the processing unit 403 is further configured to use the first value as a key value pair of the ith sub-layer to perform progressive hierarchical division; taking the current layer as a key word in the key value pair of the ith sub-layer, and taking the sub-layer of the current layer as the ith value corresponding to the key value of the ith sub-layer;
identifying a data type of the ith value;
when the processing unit 403 identifies that the data type of the ith value is still the second preset data type, the ith value is used as the key value pair of the (i+1) th sub-layer, and the hierarchy division is performed again and the traversal is performed;
alternatively, when the processing unit 403 identifies that the data type of the i-th value is the first data type, the extracting unit 404 is further configured to extract the preset variable expression from the i-th value, where i is a positive integer.
Optionally, when the data type of the value is not the first preset data type or the second preset data type, any processing operation of the key-value pair corresponding to the value is stopped, wherein the value includes a first value, an i-th value, and a value of the i+1th sub-layer.
Optionally, when the first variable value is the second preset data type, the processing unit 403 is further configured to perform hierarchical division on the first variable value as a new key value pair;
Taking the current layer as a key word in the new key value pair, and taking the sub-layer of the current layer as a value in the new key value pair;
identifying a data type of the new key value pair median;
when the data type of the median value of the new key value pair is still the second preset data type, taking the value in the new key value pair as another new key value pair again, and carrying out hierarchical division again and traversing;
and (3) finishing traversing to the last sub-level in the first variable value, and taking the value corresponding to the last sub-level as the final variable value corresponding to the variable.
Optionally, the preset variable expression further includes: the variable value presets an output data type expression and/or a variable default output value;
the variable value is preset to output a data type expression for indicating the data type of the final output of the variable value corresponding to the variable;
and the variable default output value is used for replacing the variable with the default output value when the variable value corresponding to the variable is determined to be empty.
Optionally, the first data type is a string type, and the second data type is an object and/or array type.
The functions executed by the functional components in the variable replacement device provided in this embodiment are described in detail in the embodiment corresponding to fig. 1, so that the details are not repeated here.
The variable replacement device provided by the embodiment of the invention acquires first description information containing a preset variable expression, at least one variable value and identification information corresponding to each variable value. And then analyzing the first description information to obtain at least one key value pair. Traversing the data types corresponding to the values in each key value pair in turn, and extracting a preset variable expression from the first value if the data type is the first data type. That is, the data type of the variable expression is the first data type. And extracting the variable from the variable expression, and acquiring a variable value corresponding to the variable according to the identification information and the variable. And outputting the second descriptive information after all variables in the first descriptive information have been replaced with variable values. In this way, the variables and variable values are saved by using data in the form of Json or Yaml, the original grammar of the Json or Yaml is maintained, and the replacement process of the variables is completed on the premise of fully supporting the data types of the Json or Yaml. The operation is simple and convenient, and the working cost can not be increased.
Fig. 5 is a schematic structural diagram of a variable replacement system according to an embodiment of the present invention, and a variable replacement system 500 shown in fig. 5 includes: at least one processor 501, memory 502, at least one network interface 503, and other user interfaces 504. The various components in variable substitution system 500 are coupled together by bus system 505. It is understood that bus system 505 is used to enable connected communications between these components. The bus system 505 includes a power bus, a control bus, and a status signal bus in addition to a data bus. But for clarity of illustration the various buses are labeled as bus system 505 in fig. 5.
The user interface 504 may include, among other things, a display, a keyboard, or a pointing device (e.g., a mouse, a trackball, a touch pad, or a touch screen, etc.).
It will be appreciated that the memory 502 in embodiments of the invention can be either volatile memory or nonvolatile memory, or can include both volatile and nonvolatile memory. The nonvolatile Memory may be a Read-Only Memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically Erasable EPROM (EEPROM), or a flash Memory. The volatile memory may be random access memory (Random Access Memory, RAM) which acts as an external cache. By way of example, and not limitation, many forms of RAM are available, such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (Double Data Rate SDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), and Direct memory bus RAM (DRRAM). The memory 502 described herein is intended to comprise, without being limited to, these and any other suitable types of memory.
In some implementations, the memory 502 stores the following elements, executable units or data structures, or a subset thereof, or an extended set thereof: an operating system 5021 and application programs 5022.
The operating system 5021 includes various system programs, such as a framework layer, a core library layer, a driver layer, and the like, for implementing various basic services and processing hardware-based tasks. The application 5022 includes various application programs such as a Media Player (Media Player), a Browser (Browser), and the like for realizing various application services. A program for implementing the method according to the embodiment of the present invention may be included in the application 5022.
In the embodiment of the present invention, the processor 501 is configured to execute the method steps provided by the method embodiments by calling a program or an instruction stored in the memory 502, specifically, a program or an instruction stored in the application 5022, for example, including:
acquiring first description information containing a preset variable expression, at least one variable value and identification information corresponding to each variable value;
analyzing the first description information to obtain at least one key value pair;
traversing the data types corresponding to the values in each key value pair in sequence;
When the data type of the first value is a first preset data type, extracting a preset variable expression from the first value, wherein the first value is a value corresponding to a first key value pair in at least one key value pair, the first key value pair is any key value pair in the at least one key value pair, and the preset variable expression comprises a variable;
extracting a first variable value corresponding to the variable from at least one variable value according to the identification information and the variable;
and replacing the variables in the preset variable expression with the first variable values according to the preset variable expression and the first variable values until all the variables in the first description information are replaced with the variable values corresponding to the variables, and outputting the second description information.
Optionally, taking the first value as a key value pair of the ith sub-layer to carry out hierarchical progressive division;
taking the current layer as a key word in the key value pair of the ith sub-layer, and taking the sub-layer of the current layer as the ith value corresponding to the key value of the ith sub-layer;
identifying a data type of the ith value;
when the data type of the ith value is the first data type, extracting a preset variable expression from the ith value,
or when the data type of the ith value is still the second preset data type, taking the ith value as a key value pair of the (i+1) th sub-layer, carrying out hierarchical division again, and traversing until the data type of the value contained in the final sub-layer corresponding to the key value of the ith sub-layer is identified as the first data type, and extracting a preset variable expression from the final sub-layer, wherein i is a positive integer.
Optionally, when the data type of the value is not the first preset data type or the second preset data type, any processing operation of the key-value pair corresponding to the value is stopped, wherein the value includes a first value, an i-th value, and a value of the i+1th sub-layer.
Optionally, when the first variable value is the second preset data type, performing hierarchical division on the first variable value as a new key value pair;
taking the current layer as a key word in the new key value pair, and taking the sub-layer of the current layer as a value in the new key value pair;
identifying a data type of the new key value pair median;
when the data type of the median value of the new key value pair is still the second preset data type, taking the value in the new key value pair as another new key value pair again, and carrying out hierarchical division again and traversing;
and (3) finishing traversing to the last sub-level in the first variable value, and taking the value corresponding to the last sub-level as the final variable value corresponding to the variable.
Optionally, the preset variable expression further includes: the variable value presets an output data type expression and/or a variable default output value;
the variable value is preset to output a data type expression for indicating the data type of the final output of the variable value corresponding to the variable;
And the variable default output value is used for replacing the variable with the default output value when the variable value corresponding to the variable is determined to be empty.
Optionally, the first data type is a string type, and the second data type is an object and/or array type.
The method disclosed in the above embodiment of the present invention may be applied to the processor 501 or implemented by the processor 501. The processor 501 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuitry in hardware or instructions in software in the processor 501. The processor 501 may be a general purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), an off-the-shelf programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The disclosed methods, steps, and logic blocks in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be embodied directly in the execution of a hardware decoding processor, or in the execution of a combination of hardware and software elements in a decoding processor. The software elements may be located in a random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, registers, etc. as well known in the art. The storage medium is located in a memory 502, and the processor 501 reads information in the memory 502 and, in combination with its hardware, performs the steps of the method described above.
It is to be understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For a hardware implementation, the processing units may be implemented within one or more application specific integrated circuits (Application Specific Integrated Circuits, ASIC), digital signal processors (Digital Signal Processing, DSP), digital signal processing devices (dspev, DSPD), programmable logic devices (Programmable Logic Device, PLD), field programmable gate arrays (Field-Programmable Gate Array, FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions of the application, or a combination thereof.
For a software implementation, the techniques herein may be implemented by means of units that perform the functions herein. The software codes may be stored in a memory and executed by a processor. The memory may be implemented within the processor or external to the processor.
The variable replacement system provided in this embodiment may be a variable replacement system as shown in fig. 5, and may perform all steps of the variable replacement method as shown in fig. 1, so as to achieve the technical effects of the variable replacement method as shown in fig. 1, and the description is specifically referred to in fig. 1, and is omitted herein for brevity.
The embodiment of the invention also provides a storage medium (computer readable storage medium). The storage medium here stores one or more programs. Wherein the storage medium may comprise volatile memory, such as random access memory; the memory may also include non-volatile memory, such as read-only memory, flash memory, hard disk, or solid state disk; the memory may also comprise a combination of the above types of memories.
When one or more programs in the storage medium are executable by one or more processors, the variable replacement method performed on the variable replacement system side described above is implemented.
The processor is configured to execute a variable replacement program stored in the memory to implement the following steps of a variable replacement method executed on a variable replacement system side:
acquiring first description information containing a preset variable expression, at least one variable value and identification information corresponding to each variable value;
analyzing the first description information to obtain at least one key value pair;
traversing the data types corresponding to the values in each key value pair in sequence;
when the data type of the first value is a first preset data type, extracting a preset variable expression from the first value, wherein the first value is a value corresponding to a first key value pair in at least one key value pair, the first key value pair is any key value pair in the at least one key value pair, and the preset variable expression comprises a variable;
Extracting a first variable value corresponding to the variable from at least one variable value according to the identification information and the variable;
and replacing the variables in the preset variable expression with the first variable values according to the preset variable expression and the first variable values until all the variables in the first description information are replaced with the variable values corresponding to the variables, and outputting the second description information.
Optionally, taking the first value as a key value pair of the ith sub-layer to carry out hierarchical progressive division;
taking the current layer as a key word in the key value pair of the ith sub-layer, and taking the sub-layer of the current layer as the ith value corresponding to the key value of the ith sub-layer;
identifying a data type of the ith value;
when the data type of the ith value is the first data type, extracting a preset variable expression from the ith value,
or when the data type of the ith value is still the second preset data type, taking the ith value as a key value pair of the (i+1) th sub-layer, carrying out hierarchical division again, and traversing until the data type of the value contained in the final sub-layer corresponding to the key value of the ith sub-layer is identified as the first data type, and extracting a preset variable expression from the final sub-layer, wherein i is a positive integer.
Optionally, when the data type of the value is not the first preset data type or the second preset data type, any processing operation of the key-value pair corresponding to the value is stopped, wherein the value includes a first value, an i-th value, and a value of the i+1th sub-layer.
Optionally, when the first variable value is the second preset data type, performing hierarchical division on the first variable value as a new key value pair;
taking the current layer as a key word in the new key value pair, and taking the sub-layer of the current layer as a value in the new key value pair;
identifying a data type of the new key value pair median;
when the data type of the median value of the new key value pair is still the second preset data type, taking the value in the new key value pair as another new key value pair again, and carrying out hierarchical division again and traversing;
and (3) finishing traversing to the last sub-level in the first variable value, and taking the value corresponding to the last sub-level as the final variable value corresponding to the variable.
Optionally, the preset variable expression further includes: the variable value presets an output data type expression and/or a variable default output value;
the variable value is preset to output a data type expression for indicating the data type of the final output of the variable value corresponding to the variable;
and the variable default output value is used for replacing the variable with the default output value when the variable value corresponding to the variable is determined to be empty.
Optionally, the first data type is a string type, and the second data type is an object and/or array type.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative elements and steps are described above generally in terms of function in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied in hardware, in a software module executed by a processor, or in a combination of the two. The software modules may be disposed in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The foregoing detailed description of the invention has been presented for purposes of illustration and description, and it should be understood that the invention is not limited to the particular embodiments disclosed, but is intended to cover all modifications, equivalents, alternatives, and improvements within the spirit and principles of the invention.

Claims (10)

1. A method of variable substitution, the method comprising:
acquiring first description information containing a preset variable expression, at least one variable value and identification information corresponding to each variable value;
analyzing the first description information to obtain at least one key value pair;
traversing the data types corresponding to the values in each key value pair in sequence;
when the data type of the first value is a first preset data type, extracting a preset variable expression from the first value, wherein the first value is a value corresponding to a first key value pair in the at least one key value pair, the first key value pair is any key value pair in the at least one key value pair, and the preset variable expression comprises a variable;
extracting a first variable value corresponding to the variable from the at least one variable value according to the identification information and the variable;
and replacing the variables in the preset variable expression with the first variable value according to the preset variable expression and the first variable value until all the variables in the first description information are replaced with the variable values corresponding to the variables, and outputting second description information.
2. The method of claim 1, wherein when the data type of the first value is a second preset data type, the method further comprises:
taking the first value as a key value pair of an ith sub-layer, and carrying out hierarchical progressive division;
taking the current layer as a key word in the key value pair of the ith sub-layer, and taking the sub-layer of the current layer as the ith value corresponding to the key value of the ith sub-layer;
identifying a data type of the ith value;
extracting the preset variable expression from the ith value when the data type of the ith value is the first preset data type,
or when the data type of the ith value is still the second preset data type, the ith value is used as a key value pair of the (i+1) th sub-layer, the hierarchy division is carried out again, and traversal is carried out until the data type of the value included in the final sub-layer corresponding to the key value of the ith sub-layer is identified as the first data type, and the preset variable expression is extracted from the final sub-layer, wherein i is a positive integer.
3. The method of claim 2, wherein when the data type of a value is not the first preset data type or the second preset data type, then stopping any processing operation of a key-value pair corresponding to the value, wherein the value comprises the first value, the i-th value, and the i+1-th sublayer value.
4. The method according to claim 1, wherein when the first variable value is the second preset data type, after extracting a first variable value corresponding to the variable from the at least one variable value according to the identification information and the variable, the method further comprises:
performing hierarchical division on the first variable value as a new key value pair;
taking the current layer as a key word in the new key value pair, and taking the sub-layer of the current layer as a value in the new key value pair;
identifying a data type of the new key value pair median;
when the data type of the median value of the new key value pair is still the second preset data type, taking the value in the new key value pair as another new key value pair again, and carrying out hierarchical division again and traversing;
and finishing until the last sub-level in the first variable value is traversed, and taking the value corresponding to the last sub-level as the final variable value corresponding to the variable.
5. The method of claim 4, wherein the preset variable expression further comprises: the variable value presets an output data type expression and/or a variable default output value;
The variable value preset output data type expression is used for indicating the data type of the final output of the variable value corresponding to the variable;
and the variable default output value is used for replacing the variable with the default output value when the variable value corresponding to the variable is determined to be empty.
6. The method according to any of claims 2-5, wherein the first data type is a string type and the second data type is an object and/or array type.
7. A variable displacement device, the device comprising:
the device comprises an acquisition unit, a storage unit and a control unit, wherein the acquisition unit is used for acquiring first description information containing a preset variable expression, at least one variable value and identification information corresponding to each variable value;
the analysis unit is used for analyzing the first description information and acquiring at least one key value pair;
the processing unit is used for traversing the data types corresponding to the values in each key value pair in sequence;
an extracting unit, configured to extract a preset variable expression from a first value when the data type of the first value is a first preset data type, where the first value is a value corresponding to a first key value pair in the at least one key value pair, the first key value pair is any key value pair in the at least one key value pair, and the preset variable expression includes a variable;
Extracting a first variable value corresponding to the variable from the at least one variable value according to the identification information and the variable;
and the replacing unit is used for replacing the variables in the preset variable expression with the first variable value according to the preset variable expression and the first variable value until all the variables in the first description information are replaced with the variable values corresponding to the variables, and outputting second description information.
8. The apparatus of claim 7, wherein when the data type of the first value is a second preset data type, the processing unit is further configured to use the first value as a key value pair of an i-th sublayer to perform hierarchical progressive division; taking the current layer as a key word in the key value pair of the ith sub-layer, and taking the sub-layer of the current layer as the ith value corresponding to the key value of the ith sub-layer;
identifying a data type of the ith value;
when the processing unit identifies that the data type of the ith value is still the second preset data type, the ith value is used as a key value pair of an (i+1) th sublayer, hierarchical division is conducted again, and traversal is conducted;
or when the processing unit identifies that the data type of the ith value is the first preset data type, the extracting unit is further configured to extract the preset variable expression from the ith value, where i is a positive integer.
9. A variable replacement system, the system comprising: at least one processor and memory;
the processor is configured to execute a variable replacement program stored in the memory to implement the variable replacement method of any one of claims 1 to 6.
10. A computer storage medium storing one or more programs executable by the variable replacement system according to claim 9 to implement the variable replacement method according to any one of claims 1 to 6.
CN202110266762.6A 2021-03-11 2021-03-11 Variable replacement method, device, system and storage medium Active CN113031959B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110266762.6A CN113031959B (en) 2021-03-11 2021-03-11 Variable replacement method, device, system and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110266762.6A CN113031959B (en) 2021-03-11 2021-03-11 Variable replacement method, device, system and storage medium

Publications (2)

Publication Number Publication Date
CN113031959A CN113031959A (en) 2021-06-25
CN113031959B true CN113031959B (en) 2023-11-03

Family

ID=76470194

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110266762.6A Active CN113031959B (en) 2021-03-11 2021-03-11 Variable replacement method, device, system and storage medium

Country Status (1)

Country Link
CN (1) CN113031959B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112231616A (en) * 2020-09-29 2021-01-15 北京五八信息技术有限公司 Page data refreshing method and device, electronic equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9690594B2 (en) * 2013-04-29 2017-06-27 Honeywell International Inc. System for configuring a controller

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112231616A (en) * 2020-09-29 2021-01-15 北京五八信息技术有限公司 Page data refreshing method and device, electronic equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
陈新林 ; 张双武 ; .管理报表系统用户自定义函数解析器算法实现.武汉理工大学学报(信息与管理工程版).2008,(03),全文. *

Also Published As

Publication number Publication date
CN113031959A (en) 2021-06-25

Similar Documents

Publication Publication Date Title
JP4533682B2 (en) Trace analysis apparatus and trace analysis method
CN111176996A (en) Test case generation method and device, computer equipment and storage medium
CN108491207B (en) Expression processing method, device, equipment and computer readable storage medium
CN108108260B (en) Resource file verification method and device
US20090049431A1 (en) Method and compiler of compiling a program
CN113190849A (en) Webshell script detection method and device, electronic equipment and storage medium
CN111079408B (en) Language identification method, device, equipment and storage medium
CN110866152A (en) Fault code retrieval method and device, electronic equipment and readable storage medium
CN114625844B (en) Code searching method, device and equipment
CN112306620B (en) Multi-language loading method and device for user-defined form control
CN112420145A (en) Electronic medical record document data processing method and device and computer readable storage medium
CN112948828A (en) Binary program malicious code detection method, terminal device and storage medium
CN103593277A (en) Log processing method and system
CN109739824B (en) Log obtaining method and device
CN113778852B (en) Code analysis method based on regular expression
CN113031959B (en) Variable replacement method, device, system and storage medium
US10782942B1 (en) Rapid onboarding of data from diverse data sources into standardized objects with parser and unit test generation
CN115495082B (en) TLV format data automatic conversion method and related equipment
CN111240790A (en) Multi-language adaptation method and device for application, client and storage medium
CN110688303A (en) Software workpiece relation mining method based on integrated development platform
CN113721928B (en) Binary analysis-based dynamic library clipping method
CN116204692A (en) Webpage data extraction method and device, electronic equipment and storage medium
CN113010550A (en) Batch processing object generation and batch processing method and device for structured data
CN111241191A (en) Database synchronization method and device
CN112148581A (en) Code specification checking method, device, system and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant