A data-to-text conversion method, system, and electronic device
By using a parsing utility class and template rules to obtain fare rule data, formatted row data is generated and written to a file, solving the inefficiency problem caused by code modification and realizing simplified modification and easy maintenance of airfares.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TRAVELSKY TECHNOLOGY LIMITED
- Filing Date
- 2022-11-21
- Publication Date
- 2026-06-30
AI Technical Summary
Current technology requires code modifications when changing airfares, resulting in low work efficiency.
By obtaining the freight rate rule data, a parsing implementation utility class is acquired. Based on the generic parameters, the first template implementation utility class and template rules are matched to generate formatted row data and write it to a specified file. The data text generated by the template can be directly modified without code adjustment.
It simplifies the freight rate modification process, improves work efficiency, and makes changes and maintenance easier.
Smart Images

Figure CN115828879B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information processing, and in particular to a data-to-text conversion method, system, and electronic device. Background Technology
[0002] Airfares are a pricing system established by national aviation authorities for transporting passengers and cargo using civil aircraft or other aircraft. As fare business has accumulated over time, fare publication has become increasingly complex and diverse, with the process from user fare entry to final fare generation being intricate.
[0003] When airfares need to be modified, the code usually needs to be changed, and the process of modifying the code reduces work efficiency. Summary of the Invention
[0004] In view of this, this application provides a data-to-text conversion method, system, and electronic device, the specific solutions of which are as follows:
[0005] A data-to-text conversion method, comprising:
[0006] Obtain the fare rule data to be converted, and obtain the parsing implementation utility class for processing the fare rule data;
[0007] A utility class that implements the first template matching the freight rate rule data is obtained based on the generic parameters of the freight rate rule data;
[0008] Obtain the template rule of the first template that matches the freight rate rule data;
[0009] Based on the template rules of the first template, the utility class implementing the first template, and the utility class implementing the parsing of the fare rule data, the fare rule data is used to generate matching formatted row data.
[0010] Data text is generated based on the formatted line data, and the data text is written to a specified file.
[0011] Furthermore, the step of generating matching formatted row data from the fare rule data based on the template rules of the first template, the utility class implementing the first template, and the parsing implementation utility class of the fare rule data includes:
[0012] Obtain the template file of the first template;
[0013] Iterate through all lines in the template file of the first template and populate them with the custom rules of the utility class implemented by the first template and the parsing implementation utility class of the fare rule data;
[0014] Iterate through the custom rules to generate formatted row data.
[0015] Furthermore, the step of traversing all lines in the template file of the first template and filling in the custom rules of the utility class implementing the first template and the utility class implementing the fare rule data parsing includes:
[0016] Read the current line in the template file of the first template, and determine the line content at the beginning and end positions of the current line;
[0017] If the configuration of the line content is determined to be valid, the configuration information in the line content is set into the configuration object to complete the parsing of the current line;
[0018] Continue traversing the template file of the first template from the next line until all lines of the template file of the first template are completed, and populate the utility class implemented by the first template and the custom rules of the utility class for parsing the fare rule data.
[0019] Furthermore, the step of traversing the custom rules to generate formatted row data includes:
[0020] Read the value of each of the custom rules, where the value of the custom rule is the fare rule data to be converted;
[0021] Determine whether the value of the custom rule is consistent with the preset value;
[0022] If it is determined that the value of the custom rule is consistent with the preset value, then iterate through the values of the next custom rule;
[0023] If it is determined that the value of the custom rule is inconsistent with the preset value, the value of the custom rule is filled into the template file of the first template to generate formatted row data.
[0024] Furthermore, obtaining the template file of the first template includes:
[0025] Determine whether the first template is the specified template;
[0026] If it is determined that the first template is the specified template, then the template file of the first template is obtained;
[0027] If the first template is determined to be a non-specified template, the type of the fare rule data is determined, the name of the first template is determined based on the type of the fare rule data, and the template file of the first template is obtained based on the name of the first template.
[0028] Furthermore, the step of traversing all lines in the template file of the first template includes:
[0029] Iterate through the contents of the template file of the first template;
[0030] If it is determined that the template file of the first template includes lines whose content is comment content, then those lines whose content is comment content are skipped.
[0031] Furthermore, if it is determined that the line content configuration is valid, the configuration information in the line content is set into the configuration object to complete the parsing of the current line, including:
[0032] The line content is split according to a first specific symbol;
[0033] If it is determined that the line content is split into three specific parts, then the line content configuration is determined to be valid, and the type, whether it is the result of a variable, and the two-part configuration of the three specific parts are set into the configuration object;
[0034] The fixed fill string and fill position of the two configuration segments are written into the configuration object to complete the parsing of the current line.
[0035] A data-to-text conversion system, comprising:
[0036] The first obtaining unit is used to obtain the fare rule data to be converted and to obtain a parsing implementation utility class for processing the fare rule data;
[0037] The second obtaining unit is used to obtain a utility class that implements the first template matching the freight rate rule data according to the generic parameters of the freight rate rule data;
[0038] The third obtaining unit is used to obtain the template rules of the first template matched by the freight rate rule data;
[0039] The generation unit is used to generate matching formatted row data from the fare rule data according to the template rules of the first template, the utility class implementing the first template, and the parsing implementation utility class of the fare rule data;
[0040] The writing unit is used to generate data text based on the formatted line data and write the data text into a specified file.
[0041] An electronic device, comprising:
[0042] A processor is configured to: obtain fare rule data to be converted; acquire a parsing implementation utility class for processing the fare rule data; acquire a utility class for implementing a first template matching the fare rule data based on the generic parameters of the fare rule data; acquire the template rules of the first template matching the fare rule data; generate matching formatted line data from the fare rule data based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data; generate data text based on the formatted line data; and write the data text to a specified file.
[0043] The memory is used to store the program used by the processor to execute the above-described processing procedure.
[0044] A readable storage medium for storing at least one set of instructions;
[0045] The instruction set is used to be invoked and to execute at least the data text conversion method described in any of the preceding items.
[0046] As can be seen from the above technical solutions, the data text conversion method, system, and electronic device disclosed in this application obtain fare rule data to be converted, acquire a parsing implementation tool class for processing fare rule data, acquire a tool class for implementing the first template matching the fare rule data based on the generic parameters of the fare rule data, acquire the template rules of the first template matching the fare rule data, generate matching formatted line data from the fare rule data based on the template rules of the first template, the tool class for implementing the first template, and the parsing implementation tool class for the fare rule data, generate data text based on the formatted line data, and write the data text to a specified file. This solution converts fare rule data into data text based on the template rules of the first template, the tool class for implementing the first template, and the parsing implementation tool class for the fare rule data. This allows for direct modification of the template-generated data text when airfares need to be modified, facilitating changes and maintenance without code adjustments and simplifying the fare modification process. Attached Figure Description
[0047] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0048] Figure 1 This is a flowchart of a data-to-text conversion method disclosed in an embodiment of this application;
[0049] Figure 2This is a flowchart of a data-to-text conversion method disclosed in an embodiment of this application;
[0050] Figure 3 This is a flowchart of a data-to-text conversion method disclosed in an embodiment of this application;
[0051] Figure 4 This is a schematic diagram of the structure of a data-to-text conversion system disclosed in an embodiment of this application;
[0052] Figure 5 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application. Detailed Implementation
[0053] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0054] This application discloses a data-to-text conversion method, the flowchart of which is shown below. Figure 1 As shown, it includes:
[0055] Step S11: Obtain the freight rate rule data to be converted, and obtain the parsing implementation utility class for processing the freight rate rule data;
[0056] Step S12: Obtain the utility class that implements the first template matching the freight rate rule data based on the generic parameters of the freight rate rule data;
[0057] Step S13: Obtain the template rule of the first template that matches the freight rate rule data;
[0058] Step S14: Based on the template rules of the first template, the utility class implemented by the first template, and the utility class for parsing the fare rule data, generate matching formatted line data from the fare rule data, generate data text based on the formatted line data, and write the data text into the specified file.
[0059] Airfares are primarily determined based on air transport costs, and are categorized into passenger fares (tickets), cargo fares, mail fares, and special flight fares, with passenger fares generally being the most common.
[0060] This solution primarily uses a template-based modular approach to generate data files, enabling the generation of the entire file without parsing each data entry individually. When data format updates are needed after file generation, only the template needs to be updated, significantly reducing costs and risks. This process does not require code updates, minimizing the risks associated with code modifications and improving work efficiency.
[0061] Template is used to manage templates, such as template loading and parsing.
[0062] Specifically, when there is fare rule data to be converted, the string method in Stringer can be executed. The Stringer.string method converts a given fare rule data into text specified by the interaction protocol. Usually, the converted fare rule data is a line in the fare file, or a segment of a line.
[0063] Executing the `string` method in `Stringer` allows you to obtain the parsing utility class that matches the parameter object through the `string` parameter object. The parsing utility class, which handles the parameter object and the fare rule data to be converted, is used to process and convert the parameter object, such as `R1String`, and assemble and reconstruct personalized data.
[0064] The utility class that retrieves the first template implementation that matches the fare rule data based on the generic parameters of the string parameter object. There is a one-to-one correspondence between generic parameters and utility classes. Each generic parameter has a corresponding type, and the corresponding utility class, i.e., the utility class implemented by the first template, can be obtained through the type of the generic parameter.
[0065] The type of the generic parameter can be determined once the parameter object is determined. That is, once the parameter object is determined, the generic parameter type of the parameter object is determined, and once the type of the generic parameter is determined, the corresponding utility class can be determined.
[0066] The system obtains the template rules of the first template, parses the template rules, and generates matching formatted line data based on the parsed template rules, the obtained utility class for implementing the first template, and the utility class for parsing the fare rule data. It can further generate data text based on the formatted line data and write it to a specified file, thereby converting the fare rule data into text. The changes in fare rules are realized through template updates, simplifying the fare modification process without requiring code modifications.
[0067] Specifically, rule parsing mainly involves reading the template rules of the first template, parsing the text position and orientation values that need to be filled in the template rules, combining these values into an element, and then combining all the elements into a text.
[0068] The data-to-text conversion method disclosed in this embodiment obtains fare rule data to be converted, acquires a parsing implementation utility class for processing fare rule data, acquires a utility class for implementing a first template matching the fare rule data based on the generic parameters of the fare rule data, acquires the template rules of the first template matching the fare rule data, generates matching formatted line data from the fare rule data based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data, generates data text based on the formatted line data, and writes the data text to a specified file. This solution converts fare rule data into data text based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data. This allows for direct modification of the data text generated based on the template when airfares need to be modified, facilitating changes and maintenance without requiring code adjustments and simplifying the fare modification process.
[0069] This embodiment discloses a data-to-text conversion method, the flowchart of which is shown below. Figure 2 As shown, it includes:
[0070] Step S21: Obtain the freight rate rule data to be converted, and obtain the parsing implementation utility class for processing the freight rate rule data;
[0071] Step S22: Obtain the utility class implemented by the first template that matches the freight rate rule data based on the generic parameters of the freight rate rule data;
[0072] Step S23: Obtain the template rule of the first template that matches the freight rate rule data;
[0073] Step S24: Obtain the template file of the first template;
[0074] Step S25: Traverse all lines in the template file of the first template and fill in the custom rules of the utility class implemented by the first template and the parsing implementation utility class of the fare rule data;
[0075] Step S26: Traverse the custom rules to generate formatted row data;
[0076] Step S27: Generate data text based on formatted line data and write the data text to the specified file.
[0077] The template rules of the first template are parsed, and the freight rate rule data is generated into matching formatted row data based on the template rules. Specifically, the contents of the template file of the first template are traversed to fill each row with custom rules, thereby generating formatted row data based on the filled content.
[0078] Specifically, after the rule parsing begins, the template file of the first template is obtained first, and then each line in the template file is traversed. If the content of the currently traversed line is a comment, there is no need to obtain or parse its content, and the line corresponding to the comment content can be skipped directly, and the next line can be traversed; if the content of the currently traversed line is not a comment, then the content of the line needs to be parsed.
[0079] Once all lines in the template file of the first template have been parsed, the custom rules of each utility class and the parsing implementation utility class are populated into the code of the first template. Certain changes need to be made to the code to complete the custom rules. After that, the populated custom rules are parsed to generate formatted line data.
[0080] Parsing a template into data text can be achieved by reading template rules from a database and parsing them into strings. The parameters required for this process include the target parsing object (target), which is the template file of the first template, the template name (templateName), which is the name of the template file of the first template, and the reconstructed data set (data).
[0081] First, a data generation result container `res` needs to be prepared. This container is used to store the fare rule data to be converted and the fare rule reconstruction data. Additionally, a template configuration set `settings` needs to be defined to store the configuration data after parsing the template file. After preparation, the template file for the first template is obtained.
[0082] Specifically, the template file for obtaining the first template can be:
[0083] Determine whether the first template is the specified template. If the first template is the specified template, obtain the template file of the first template. If the first template is not the specified template, determine the type of the freight rate rule data, determine the name of the first template based on the type of the freight rate rule data, and obtain the template file of the first template based on the name of the first template.
[0084] If the first template is a specified template, the template name is obtained, the template file is obtained through the template name, and the template configuration information is read and stored in the configuration collection settings. If the first template is not a specified template, the template name needs to be obtained through target object reflection, the template file is obtained through the template name, and the template configuration is read and stored in the configuration collection settings.
[0085] The template name is obtained by reflecting the target object. Each target object has a corresponding type, and each type has a corresponding template. By determining the type of the target object, the corresponding template name can be determined in order to obtain the template file.
[0086] The target objects can be: Rules, FareClass, Fare, Baggage, Fuel Q / YR, etc.
[0087] The data-to-text conversion method disclosed in this embodiment obtains fare rule data to be converted, acquires a parsing implementation utility class for processing fare rule data, acquires a utility class for implementing a first template matching the fare rule data based on the generic parameters of the fare rule data, acquires the template rules of the first template matching the fare rule data, generates matching formatted line data from the fare rule data based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data, generates data text based on the formatted line data, and writes the data text to a specified file. This solution converts fare rule data into data text based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data. This allows for direct modification of the data text generated based on the template when airfares need to be modified, facilitating changes and maintenance without requiring code adjustments and simplifying the fare modification process.
[0088] This embodiment discloses a data-to-text conversion method, the flowchart of which is shown below. Figure 3 As shown, it includes:
[0089] Step S31: Obtain the freight rate rule data to be converted, and obtain the parsing implementation utility class for processing the freight rate rule data;
[0090] Step S32: Obtain the utility class implemented by the first template that matches the freight rate rule data based on the generic parameters of the freight rate rule data;
[0091] Step S33: Obtain the template rule of the first template that matches the freight rate rule data;
[0092] Step S34: Obtain the template file of the first template;
[0093] Step S35: Read the current line in the template file of the first template, determine the line content at the beginning and end of the current line, and if the line content configuration is determined to be valid, set the configuration information in the line content into the configuration object to complete the parsing of the current line;
[0094] Step S36: Continue traversing the template file of the first template until all lines of the template file of the first template are traversed, and fill in the custom rules of the utility class implemented by the first template and the parsing implementation utility class of the fare rule data.
[0095] Step S37: Traverse the custom rules to generate formatted row data;
[0096] Step S38: Generate data text based on formatted line data and write the data text to a specified file.
[0097] After obtaining the template file of the first template, the content in the template file is traversed. Specifically, the content in the template file is traversed line by line, that is, the first line is traversed first, then the second line, the third line, and so on, until the content in the template file is traversed.
[0098] When iterating through lines in a template file, you can first determine whether the current line is a comment line. If it is a comment line, skip the current line and iterate through the next line. Do not iterate through comment lines. If the current line is not a comment line, you need to read the start and end positions of the current line to extract the content between the start and end positions of the current line.
[0099] After extracting the content between the start and end positions of the current line, the content between the start and end positions of the current line is parsed to determine whether its configuration is valid. If the configuration is invalid, it indicates that there is an error in parsing the content of the current line, or that the content of the current line obtained is abnormal. The subsequent program is terminated and the abnormal situation is detected. If the configuration is valid, the configuration information in the parsed line content is set into the configuration object in order to complete the parsing of the current line.
[0100] Specifically, the content between the start and end positions of the current line is parsed to determine whether its configuration is valid. This can be done by splitting the line content of the current line according to a first specific symbol. If the line content can be split into three specific parts, the line content configuration can be determined to be valid, and the three specific parts are determined as the configuration information of the line content.
[0101] Before splitting the content of the current line according to the first specific symbol, it is also possible to first determine whether the content of the current line contains only newline characters. If it contains only newline characters, there is no need to parse the content of the current line, and the current line is skipped and the content of the next line is parsed. If the content of the current line contains not only newline characters but also other content, then the content of the current line is split.
[0102] The content of the current line is split according to the first specific symbol. If it is split into three specific parts, these three specific parts are: type, whether it is the result of a variable, and two-part configuration. These three specific parts are the configuration information. These three specific parts are set into the configuration object. For the two-part configuration, the configuration fixed fill string and configuration fill position of the two-part configuration can be written into the configuration object to complete the parsing of the current line.
[0103] Among them, whether it is the result of a variable, that is, whether it is a constant or the result of a variable, the two-segment configuration refers to the starting position (i.e., length), alignment and padding symbol of the data output. The configuration of the two-segment configuration is the data in the two-segment configuration, such as: length, alignment or padding symbol.
[0104] After the current line is traversed, the next line is traversed until every line in the template file has been traversed. After that, the custom rules that can only be set in the code of each utility class are populated. That is, the custom rules are populated into the template file of the first template. These custom rules require certain code transformations to complete.
[0105] After the custom rules are populated, the custom rules are traversed to read the value of each custom rule. Based on the value of the rule, it is determined whether the rule needs to be populated. If it does not need to be populated, the next rule is traversed. If it needs to be populated, the row is formatted starting from the current position according to the filling direction and starting position so that the value of the rule that needs to be populated is filled into the corresponding position. After the current rule is populated, the next rule is traversed until the traversal is completed, thus completing the rule population and realizing the update of the first template.
[0106] To determine whether a custom rule needs to be populated, you can: check if the value of the custom rule is consistent with the preset value. If they are consistent, no population is needed, and you can directly iterate through the next custom rule to determine if it needs to be populated. If they are inconsistent, population is needed. Adjust the value of the custom rule and populate it into the template file of the first template to generate formatted row data, thus changing the first template. Then iterate through the next custom rule. When all custom rules have been traversed, the update of the first template is complete, and the updated first template can be directly applied to calculate the freight rate rules.
[0107] The value of the custom rule actually represents the fare rule data to be converted. Determining whether the value of the custom rule is consistent with the preset value is actually determining whether the fare rule data to be converted is consistent with the corresponding data in the first template. If they are consistent, it means that the rule does not need to be changed; if they are inconsistent, it means that the rule needs to be changed.
[0108] Specifically, the data-to-text conversion method disclosed in this embodiment can be implemented as follows:
[0109] Prepare a container `res` containing the generated data. This container will store the fare rule data to be converted and the fare rule reconstruction data. Additionally, define a template configuration set `settings` to store the configuration data after parsing the template file. After preparation, obtain the template file for the first template.
[0110] Determine whether the first template is the specified template. If the first template is the specified template, obtain the template file of the first template, read the configuration information of the template, and store the configuration information in the configuration set. If the first template is not the specified template, determine the type of the fare rule data, determine the name of the first template based on the type of the fare rule data, obtain the template file of the first template based on the name of the first template, read the configuration information of the template, and store the configuration information in the configuration set.
[0111] Define a template of type Map corresponding to a data collection da, and convert the target object into a data collection da that corresponds to the template configuration. For example, associate the attributes in the object with their corresponding values and put them into the collection da. This can convert the target object into a Map collection associated with key values.
[0112] Define a template attribute value `val` to specify the name of the data to be processed in the current configuration line; iterate through the template configuration collection `settings` and name the attribute to be processed in the current iteration as `item`; assign the template attribute value `val` to a default attribute value in the template; check if the type of the attribute being iterated is type `V`; if so, reassign the template attribute value `val` to the value in the data collection `da`, where type `V` represents the variable type, indicating that the output data is obtained from the given data.
[0113] Determine if the current attribute `item` needs to be filled. If it does, call the format string method to format the string according to the rules defined in the template, and reassign the formatted string to the template attribute value `val`. Check if the template attribute value `val` is still unassigned. If it is, assign the template attribute value `val` to the default empty string. Add the formatted template attribute value `val` to the result container `res`. If the current attribute `item` does not need to be filled, assign the template attribute value `val` to the default empty string.
[0114] After all properties in the template configuration set `settings` have been traversed, the formatted characters defined according to the template rules are returned to the caller.
[0115] Furthermore, the process of parsing the template file can be as follows:
[0116] Define the template file name fileName, which represents the full path filename. The template file name name is used to parse the full path filename and assign it to the template file name fileName. Define the file stream is and obtain the file stream by the file name fileName. If the file stream is empty, it indicates that the template does not exist and outputs an abnormal result.
[0117] Read the template configuration information, convert the file stream into a byte array, and then convert the array into a string temStrs using UTF8 encoding. Define the file parsing result items, separate the string temStrs with newline characters, and save the line content results into the line array tmps. Traverse the line array tmps and save the information of the current line to the corresponding position.
[0118] If the current line is determined to begin with a second specific symbol, it is considered a comment line and is skipped. If the current line conforms to the configuration specification, it is parsed into a configuration object and added to the file parsing result items. If the current line does not conform to the configuration specification, a default constant type configuration object is initialized and added to the file parsing result items. If all lines have been traversed, the file parsing result items are returned to the caller.
[0119] The text generation tool for the file is determined. This tool is used to generate text from template data, and can be specifically:
[0120] Prepare the object parameter `target`, obtain the `Class(tgType)` of the object parameter `target`, iterate through the registered `Class` objects, and match the value in `Class(tgType)` with the registered `Class` objects. If a match is found, return the lower-level implementation tool that the template needs to use. If no match is found, iterate through the registered `Class` objects again, and match the value in `Class(tgType)` with the registered `Class` objects. If a match is found, return the lower-level implementation tool that the template needs to use. If no match is found, it indicates that no matching tool exists.
[0121] The definition of the text interface can be as follows: Define a class ToString that can be passed in, and define the generic type T of the entity object; define a constructor method, in which the registerMapping method is executed to register the implementation utility class; define an abstract text generation and format conversion method string(T target) to implement personalized format operations; define the registerMapping method and implement it, the implementation process mainly involves injecting the mapping utility into the global container.
[0122] For the implementation of the text interface, the text interface conversion needs to inherit from ToString and implement the abstract method string. When implementing the abstract method, you can define custom text generation rules that have logical changes beyond the template. Taking R1 generation as an example, define the R1String utility implementation class, which needs to inherit from ToString and pass in the type of object data type, such as: Sequence; implement the abstract method string of ToString, prepare the parameter object sequence; customize the effective time as needed, obtain the effective time of the sequence, format it into a specific time format, store the result in the reconstructed data collection data, and execute the process of parsing the template into data text.
[0123] This solution provides a template-based method for converting data into text without requiring code modification. It generates files based on templates, making it easy to change and maintain. This decouples the code from the data parsing rules and simplifies the file generation process.
[0124] The data-to-text conversion method disclosed in this embodiment obtains fare rule data to be converted, acquires a parsing implementation utility class for processing fare rule data, acquires a utility class for implementing a first template matching the fare rule data based on the generic parameters of the fare rule data, acquires the template rules of the first template matching the fare rule data, generates matching formatted line data from the fare rule data based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data, generates data text based on the formatted line data, and writes the data text to a specified file. This solution converts fare rule data into data text based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data. This allows for direct modification of the data text generated based on the template when airfares need to be modified, facilitating changes and maintenance without requiring code adjustments and simplifying the fare modification process.
[0125] This embodiment discloses a data-to-text conversion system, the structural diagram of which is shown below. Figure 4 As shown, it includes:
[0126] The unit comprises a first obtaining unit 41, a second obtaining unit 42, a third obtaining unit 43, a generating unit 44, and a writing unit 45.
[0127] The first obtaining unit 41 is used to obtain the fare rule data to be converted and to obtain the parsing implementation utility class for processing the fare rule data;
[0128] The second obtaining unit 42 is used to obtain a utility class that implements the first template matching the freight rule data according to the generic parameters of the freight rule data;
[0129] The third obtaining unit 43 is used to obtain the template rules of the first template matched by the freight rate rule data;
[0130] The generation unit 44 is used to generate matching formatted row data from the freight rate rule data according to the template rules of the first template, the utility class implemented by the first template, and the utility class for parsing the freight rate rule data;
[0131] The writing unit 45 is used to generate data text based on formatted line data and write the data text to a specified file.
[0132] Furthermore, the generating unit is used for:
[0133] Obtain the template file of the first template; traverse all rows in the template file of the first template, and populate the custom rules of the utility class implemented by the first template and the parsing implementation utility class of the fare rule data; traverse the custom rules and generate formatted row data.
[0134] Furthermore, the generating unit is used for:
[0135] Read the current line in the template file of the first template, determine the start and end positions of the line content; if the line content configuration is valid, set the configuration information in the line content into the configuration object, and complete the parsing of the current line; continue to traverse the next line in the template file of the first template until all lines in the template file of the first template are traversed, and populate the custom rules of the utility class implemented by the first template and the parsing implementation utility class of the fare rule data.
[0136] Furthermore, the generating unit is used for:
[0137] Read the value of each custom rule, where the value of the custom rule is the fare rule data to be converted; determine whether the value of the custom rule is consistent with the preset value; if the value of the custom rule is consistent with the preset value, then iterate through the value of the next custom rule; if the value of the custom rule is inconsistent with the preset value, then fill the value of the custom rule into the template file of the first template to generate formatted row data.
[0138] Furthermore, the generating unit is used for:
[0139] Determine whether the first template is the specified template; if the first template is the specified template, obtain the template file of the first template; if the first template is not the specified template, determine the type of the freight rate rule data, determine the name of the first template based on the type of the freight rate rule data, and obtain the template file of the first template based on the name of the first template.
[0140] Furthermore, the generating unit is used for:
[0141] Iterate through the contents of the template file of the first template; if it is determined that the template file of the first template includes lines whose content is comments, then skip those lines.
[0142] Furthermore, the generating unit is used for:
[0143] The line content is split according to the first specific symbol;
[0144] If it is determined that the row content is split into three specific parts, then the row content configuration is determined to be valid, and the type, whether it is the result of a variable, and the two-part configuration of the three specific parts are set into the configuration object;
[0145] Write the fixed fill string and fill position of the two-part configuration into the configuration object to complete the parsing of the current line.
[0146] The data text conversion system disclosed in this embodiment is implemented based on the data text conversion method disclosed in the above embodiments, and will not be described again here.
[0147] The data-to-text conversion system disclosed in this embodiment obtains fare rule data to be converted, acquires a parsing implementation utility class for processing the fare rule data, acquires a utility class for implementing the first template matching the fare rule data based on the generic parameters of the fare rule data, acquires the template rules of the first template matching the fare rule data, generates matching formatted line data from the fare rule data based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data, generates data text based on the formatted line data, and writes the data text to a specified file. This solution converts fare rule data into data text based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data. This allows for direct modification of the data text generated based on the template when airfares need to be modified, facilitating changes and maintenance without requiring code adjustments and simplifying the fare modification process.
[0148] This embodiment discloses an electronic device, the structural schematic diagram of which is shown below. Figure 5 As shown, it includes:
[0149] Processor 51 and memory 52.
[0150] The processor 51 is used to obtain the fare rule data to be converted, obtain the parsing implementation utility class for processing the fare rule data; obtain the utility class for the first template implementation that matches the fare rule data according to the generic parameters of the fare rule data; obtain the template rules of the first template that matches the fare rule data; generate matching formatted line data from the fare rule data according to the template rules of the first template, the utility class for the first template implementation, and the parsing implementation utility class for the fare rule data; generate data text based on the formatted line data, and write the data text to a specified file.
[0151] The memory 52 is used to store the program for the processor to execute the above processing procedure.
[0152] The electronic device disclosed in this embodiment is implemented based on the data text conversion method disclosed in the above embodiments, and will not be described again here.
[0153] The electronic device disclosed in this embodiment obtains fare rule data to be converted, acquires a parsing implementation utility class for processing fare rule data, acquires a utility class for implementing a first template matching the fare rule data based on the generic parameters of the fare rule data, acquires the template rules of the first template matching the fare rule data, generates matching formatted line data from the fare rule data based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data, generates data text based on the formatted line data, and writes the data text to a specified file. This solution converts fare rule data into data text based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data. This allows for direct modification of the data text generated based on the template when airfares need to be modified, facilitating changes and maintenance without requiring code adjustments and simplifying the fare modification process.
[0154] This application embodiment also provides a readable storage medium on which a computer program is stored. The computer program is loaded and executed by a processor to implement the steps of the above-described data-text conversion method. The specific implementation process can be referred to the description of the corresponding part of the above embodiment, and will not be repeated in this embodiment.
[0155] This application also proposes a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. The processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the methods provided in the various optional implementations of the data-text conversion method or data-text conversion system described above. Specific implementation processes can be referred to the descriptions of the corresponding embodiments above, and will not be repeated here.
[0156] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.
[0157] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0158] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0159] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A data-to-text conversion method, characterized in that, include: Obtain the fare rule data to be converted, and obtain the parsing implementation utility class for processing the fare rule data; A utility class that implements the first template matching the freight rate rule data is obtained based on the generic parameters of the freight rate rule data; Obtain the template rule of the first template that matches the freight rate rule data; Based on the template rules of the first template, the utility class implementing the first template, and the utility class implementing the parsing of the fare rule data, the fare rule data is used to generate matching formatted row data. Data text is generated based on the formatted line data, and the data text is written to a specified file; The step of generating matching formatted row data from the fare rule data based on the template rules of the first template, the utility class implementing the first template, and the parsing implementation utility class of the fare rule data includes: Obtain the template file of the first template; Iterate through all lines in the template file of the first template and populate them with the custom rules of the utility class implemented by the first template and the parsing implementation utility class of the fare rule data; Iterate through the custom rules to generate formatted row data.
2. The method according to claim 1, characterized in that, The step of traversing all lines in the template file of the first template and filling in the custom rules of the utility class implementing the first template and the utility class implementing the fare rule data parsing includes: Read the current line in the template file of the first template, and determine the line content at the beginning and end positions of the current line; If the configuration of the line content is determined to be valid, the configuration information in the line content is set into the configuration object to complete the parsing of the current line; Continue traversing the template file of the first template from the next line until all lines of the template file of the first template are completed, and populate the utility class implemented by the first template and the custom rules of the utility class for parsing the fare rule data.
3. The method according to claim 1, characterized in that, The process of traversing the custom rules to generate formatted row data includes: Read the value of each of the custom rules, where the value of the custom rule is the fare rule data to be converted; Determine whether the value of the custom rule is consistent with the preset value; If it is determined that the value of the custom rule is consistent with the preset value, then iterate through the values of the next custom rule; If it is determined that the value of the custom rule is inconsistent with the preset value, the value of the custom rule is filled into the template file of the first template to generate formatted row data.
4. The method according to claim 1, characterized in that, The template file for obtaining the first template includes: Determine whether the first template is the specified template; If it is determined that the first template is the specified template, then the template file of the first template is obtained; If the first template is determined to be a non-specified template, the type of the fare rule data is determined, the name of the first template is determined based on the type of the fare rule data, and the template file of the first template is obtained based on the name of the first template.
5. The method according to claim 1, characterized in that, The step of traversing all lines in the template file of the first template includes: Iterate through the contents of the template file of the first template; If it is determined that the template file of the first template includes lines whose content is comment content, then those lines whose content is comment content are skipped.
6. The method according to claim 2, characterized in that, If it is determined that the line content configuration is valid, then the configuration information in the line content is set into the configuration object to complete the parsing of the current line, including: The line content is split according to a first specific symbol; If it is determined that the line content is split into three specific parts, then the line content configuration is determined to be valid, and the type, whether it is the result of a variable, and the two-part configuration of the three specific parts are set into the configuration object; The fixed fill string and fill position of the two configuration segments are written into the configuration object to complete the parsing of the current line.
7. A data-to-text conversion system, characterized in that, include: The first obtaining unit is used to obtain the fare rule data to be converted and to obtain a parsing implementation utility class for processing the fare rule data; The second obtaining unit is used to obtain a utility class that implements the first template matching the freight rate rule data according to the generic parameters of the freight rate rule data; The third obtaining unit is used to obtain the template rules of the first template matched by the freight rate rule data; The generation unit is used to generate matching formatted row data from the fare rule data according to the template rules of the first template, the utility class implementing the first template, and the parsing implementation utility class of the fare rule data; The writing unit is used to generate data text based on the formatted line data and write the data text into a specified file; The generation unit is specifically used for: Obtain the template file of the first template; Iterate through all lines in the template file of the first template and populate them with the custom rules of the utility class implemented by the first template and the parsing implementation utility class of the fare rule data; Iterate through the custom rules to generate formatted row data.
8. An electronic device, characterized in that, include: A processor is configured to obtain fare rule data to be converted, acquire a parsing implementation utility class for processing the fare rule data, acquire a utility class for implementing a first template that matches the fare rule data based on the generic parameters of the fare rule data, acquire the template rules of the first template that matches the fare rule data, and generate matching formatted row data from the fare rule data based on the template rules of the first template, the utility class for implementing the first template, and the parsing implementation utility class for the fare rule data. Data text is generated based on the formatted line data, and the data text is written to a specified file; the step of generating matching formatted line data for the fare rule data according to the template rules of the first template, the utility class implemented by the first template, and the parsing implementation utility class of the fare rule data includes: obtaining the template file of the first template; traversing all lines in the template file of the first template and filling in the custom rules of the utility class implemented by the first template and the parsing implementation utility class of the fare rule data; traversing the custom rules and generating formatted line data; The memory is used to store the program used by the processor to execute the above-described processing procedure.
9. A readable storage medium for storing at least one set of instructions; The instruction set is used to be invoked and to perform at least the data text conversion method as described in any one of claims 1-6.