Text Automatic Generation Method and System Based on Data Elements
By obtaining and processing preset data values, generating and executing SQL statements, and automatically generating report text, the problem of manually writing templates in the existing technology is solved, and the rapid generation of reports under different conditions is achieved.
Patent Information
- Application Number
- CN202111034181.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-03
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2041-09-03
AI Technical Summary
In the prior art, it is necessary to manually write text templates, which is time-consuming and labor-intensive, and needs to be manually and frequently modified when generating reports with different conditions.
By obtaining the preset data values used to configure the report data, including time conditions, condition list, statistical model, result fields, numerical types and related tables, the first SQL statement and the second SQL statement are generated, and the result set is executed and the report text is obtained, and the report text is automatically generated.
It realizes that when changing the report data query conditions, you only need to enter relevant data elements to generate reports under different conditions in one click, solving the time and energy problem of manually writing templates.
Smart Images

Figure CN113947063B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information technology, and in particular, to a method and system for automatically generating text based on data elements. Background Art
[0002] In general automatic report generation, it is necessary to manually write a fixed text template, where numerical values are represented by variables. When generating a report, the variables are associated with SQL statements, and the results of executing the SQL statements are used to replace the variables in the report, thereby completing the generation of the report. It can be seen that the automatic report generation technology based on text templates requires manual writing of text templates, which is time-consuming and laborious. When generating reports under different conditions, it is even necessary to manually find the places that need to be modified and make frequent changes.
[0003] Currently, no effective solution has been proposed for the problem of manually writing text templates in related technologies. Summary of the Invention
[0004] Embodiments of this application provide a method and system for automatically generating text based on data elements to at least solve the problem of manually writing text templates in related technologies.
[0005] In a first aspect, embodiments of this application provide a method for automatically generating text based on data elements, and the method includes:
[0006] Obtain preset data values for configuring report data, where the preset data values include time conditions, condition lists, statistical models, result fields, numerical types, and related tables;
[0007] Generate a first SQL statement and a second SQL statement according to the time condition, the condition list, the result field, and the related table;
[0008] Execute the first SQL statement and the second SQL statement to obtain a first result set and a second result set;
[0009] Automatically generate a report text according to the first result set and the second result set.
[0010] In some of these embodiments, generating a first SQL statement and a second SQL statement according to the time condition, the condition list, the result field, and the related table includes:
[0011] Generate a first time condition string according to the time condition, and generate a second time condition string according to the time condition and the statistical model;
[0012] Generate a condition string according to the condition list, and generate a table name string according to the related table;
[0013] Generate a first SQL statement according to the first time condition string, the condition string, the result field, and the table name string;
[0014] Generate a second SQL statement according to the second time condition string, the condition string, the result field, and the table name string.
[0015] In some embodiments, automatically generating a report text according to the first result set and the second result set includes:
[0016] Compare the first result set and the second result set to obtain a change value;
[0017] Obtain a change direction according to the change value, and obtain a change value according to the change value and the numerical type;
[0018] Obtain an expression of a comparison method according to the statistical model, obtain an expression of a table name according to the related table, obtain an expression of a time condition according to the time condition, and obtain an expression of a condition list according to the condition list;
[0019] Automatically generate a report text according to the expression of the comparison method, the expression of the table name, the expression of the time condition, the expression of the condition list, and the numerical expression.
[0020] In some embodiments, generating a first time condition string according to the time condition, and generating a second time condition string according to the time condition and the statistical model includes:
[0021] Determine a time unit according to the time condition, obtain a lower limit of a first time range and an upper limit of the first time range, and further generate a first time condition string;
[0022] Determine a time unit according to the time condition, determine a statistical type according to the statistical model, and then obtain a lower limit of a second time range and an upper limit of the second time range according to the time unit and the statistical type, and further generate a second time condition string.
[0023] In some embodiments, obtaining an expression of a comparison method according to the statistical model includes:
[0024] Determine a time unit according to the time condition, and determine a statistical type according to the statistical model;
[0025] Then obtain an expression of the comparison method according to the time unit and the statistical type.
[0026] In a second aspect, an embodiment of the present application provides a text automatic generation system based on data elements, and the system includes an acquisition module, a processing module, an execution module, and a generation module;
[0027] The obtaining module obtains preset data values for configuring report data, where the preset data values include time conditions, a condition list, a statistical model, result fields, value types, and related tables;
[0028] The processing module generates a first SQL statement and a second SQL statement according to the time conditions, the condition list, the result fields, and the related tables;
[0029] The execution module executes the first SQL statement and the second SQL statement to obtain a first result set and a second result set;
[0030] The generating module automatically generates a report text according to the first result set and the second result set.
[0031] In some embodiments, the processing module generates a first SQL statement and a second SQL statement according to the time conditions, the condition list, the result fields, and the related tables, including:
[0032] The processing module generates a first time condition string according to the time conditions, and generates a second time condition string according to the time conditions and the statistical model;
[0033] The processing module generates a condition string according to the condition list, and generates a table name string according to the related tables;
[0034] The processing module generates a first SQL statement according to the first time condition string, the condition string, the result fields, and the table name string;
[0035] The processing module generates a second SQL statement according to the second time condition string, the condition string, the result fields, and the table name string.
[0036] In some embodiments, the generating module automatically generates a report text according to the first result set and the second result set, including:
[0037] The generating module compares the first result set and the second result set to obtain a change value;
[0038] The generating module obtains a change direction according to the change value, and obtains a change value according to the change value and the value type;
[0039] The generating module obtains an expression of a comparison method according to the statistical model, obtains an expression of a table name according to the related tables, obtains an expression of time conditions according to the time conditions, and obtains an expression of the condition list according to the condition list;
[0040] The generation module automatically generates a report text according to the expression of the comparison method, the expression of the table name, the expression of the time condition, the expression of the condition list, and the numerical expression.
[0041] In some embodiments, the processing module generates a first time condition string according to the time condition, and generating a second time condition string according to the time condition and the statistical model includes:
[0042] The processing module determines a time unit according to the time condition, obtains a lower limit of a first time range and an upper limit of the first time range, and then generates a first time condition string;
[0043] The processing module determines a time unit according to the time condition, determines a statistical type according to the statistical model, and then obtains a lower limit of a second time range and an upper limit of the second time range according to the time unit and the statistical type, and then generates a second time condition string.
[0044] In some embodiments, the generation module obtaining the expression of the comparison method according to the statistical model includes:
[0045] The generation module determines a time unit according to the time condition and determines a statistical type according to the statistical model;
[0046] Then, an expression of the comparison method is obtained according to the time unit and the statistical type.
[0047] Compared with the related art, a method and a system for automatically generating text based on data elements provided by an embodiment of the present application obtain preset data values for configuring report data, where the preset data values include a time condition, a condition list, a statistical model, a result field, a numerical type, and a related table; generate a first SQL statement and a second SQL statement according to the time condition, the condition list, the result field, and the related table, execute the first SQL statement and the second SQL statement to obtain a first result set and a second result set, and automatically generate a report text according to the first result set and the second result set, solving the problem of manually writing a text template in automatic report generation, and realizing that when changing the report data query condition, only relevant data elements need to be input to generate reports under different conditions with one key. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The drawings described herein are used to provide a further understanding of the present application, and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:
[0049] Figure 1 is a flowchart of steps of a method for automatically generating text based on data elements according to an embodiment of the present application;
[0050] Figure 2 is a flowchart of steps for generating SQL statements according to an embodiment of the present application;
[0051] Figure 3 is a block diagram of the structure of a text automatic generation system based on data elements according to an embodiment of the present application;
[0052] Figure 4 is a schematic internal structure diagram of an electronic device according to an embodiment of the present application.
[0053] Description of the drawings: 31, acquisition module; 32, processing module; 33, execution module; 34, generation module. Detailed implementation manners
[0054] In order to make the objectives, technical solutions and advantages of the present application clearer and more understandable, the present application will be described and explained below in conjunction with the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments provided in the present application without creative efforts fall within the scope of protection of the present application.
[0055] Obviously, the drawings in the following description are only some examples or embodiments of the present application. For those of ordinary skill in the art, the present application can be applied to other similar scenarios based on these drawings without creative efforts. In addition, it can also be understood that although the efforts made in this development process may be complex and lengthy, for those of ordinary skill in the art related to the content disclosed in the present application, some design, manufacturing or production changes based on the technical content disclosed in the present application are only conventional technical means and should not be understood as insufficient disclosure of the content of the present application.
[0056] Referring to "embodiment" in the present application means that the specific features, structures or characteristics described in combination with the embodiment can be included in at least one embodiment of the present application. The appearance of this phrase in various positions in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those of ordinary skill in the art explicitly and implicitly understand that the embodiments described in the present application can be combined with other embodiments without conflict.
[0057] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the ordinary meanings understood by those with ordinary skills in the technical field to which this application pertains. The words such as "a", "one", "a kind of", "the" and the like involved in this application do not indicate a quantity limitation and may represent a singular or plural number. The terms "comprising", "including", "having" and any variations thereof involved in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may further include steps or units not listed, or may further include other steps or units inherent to these processes, methods, products or devices. The similar words such as "connected", "linked", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application means two or more than two. "And / or" describes the association relationship of associated objects and indicates that three relationships may exist. For example, "A and / or B" may represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the front and rear associated objects. The terms "first", "second", "third" and the like involved in this application are only used to distinguish similar objects and do not represent a specific order for the objects.
[0058] The following are the explanations of some terms appearing in this application:
[0059] Data element: The attribute or value of data, which can be the name of a database table, the name of a field, or the value of a field
[0060] Expression: A short name for a natural language representation. The natural language representation of a data element is the words, phrases or sentences used to represent the meaning of the data element in a report. For example, for a table representing company information, its expression is "company".
[0061] Concatenation: Multiple strings are sequentially connected into one string.
[0062] Condition field: Each field in the condition of an SQL statement for numerical query involved in a report.
[0063] SQL string: The string participating in the composition of an SQL statement, or simply referred to as a string.
[0064] Main table: The database table that must be provided in an SQL statement.
[0065] Associated field: When two tables are associated for query, the field used to associate the two tables.
[0066] distinct field: Represents the non-repeated values of a certain database field in a query.
[0067] Logical operators: include ">", which represents greater than, "=", which represents equal to, "<", which represents less than, ">=", which represents greater than or equal to, and "<=", which represents less than or equal to.
[0068] Line break character: a symbol indicating the end of the current line and that subsequent strings will start on the next line.
[0069] An embodiment of the present application provides a method for automatically generating text based on data elements. Figure 1 It is a flowchart of the steps of the method for automatically generating text based on data elements according to an embodiment of the present application, as Figure 1 shown, and the method includes the following steps:
[0070] Step S102, obtain preset data values for configuring report data, where the preset data values include time conditions, condition lists, statistical models, result fields, value types, and related tables;
[0071] Specifically, obtain preset data values for configuring report data, where the preset data values include the following data elements:
[0072] Time condition: stipulates the time range of the data queried in the report, and also includes the field name of the time condition, the expression of the time condition field, the time unit, and the time value. There are 4 options for the time unit - year, month, first half of the year, second half of the year. When the time unit is year, first half of the year, or second half of the year, the format of the time value is "yyyy"; when the time unit is month, the format of the time value is "yyyy-MM" (where yyyy represents the 4-digit year entered, and MM represents the 2-digit month entered).
[0073] Condition list: The condition list consists of several conditions, and each of the conditions includes a field name, an expression of the field, a logical operator, and a condition value.
[0074] Statistical model: "year-on-year" or "month-on-month".
[0075] Result field: represents the field in the query result, which may be a general field or a distinct field.
[0076] Value type: "percentage" or "numeric".
[0077] Related table: includes the table name and its expression.
[0078] Optionally, the related table includes a main table and an associated table, where the main table includes the table name of the main table and the expression of the main table; the associated table includes the table name of the associated table, the expression of the associated table, and a quantifier.
[0079] Step S104: Generate a first SQL statement and a second SQL statement according to the time condition, condition list, result field, and related table;
[0080] Step S106: Execute the first SQL statement and the second SQL statement to obtain a first result set and a second result set;
[0081] Step S108: Automatically generate a report text according to the first result set and the second result set.
[0082] Through steps S102 to S108 in the embodiments of the present application, the problem of manually writing a text template in automatic report generation is solved, and it is realized that when changing the report data query conditions, only relevant data elements need to be input, and reports under different conditions can be generated with one key.
[0083] In some of the embodiments, Figure 2 is a flowchart of the steps for generating SQL statements according to the embodiments of the present application. As Figure 2 shown, step S104, generating a first SQL statement and a second SQL statement according to the time condition, condition list, result field, and related table includes:
[0084] Step S202: Generate a first time condition string according to the time condition, and generate a second time condition string according to the time condition and the statistical model;
[0085] Step S204: Generate a condition string according to the condition list, and generate a table name string according to the related table;
[0086] Specifically, the condition string is generated according to the input condition list. The field name, logical operator, condition value, and "AND" of each condition in the condition list are concatenated into a single condition string. The concatenation of "1 = 1 AND" and all single condition strings, and then removing the trailing "AND", obtains the condition string.
[0087] The table name string is formed by concatenating the SQL string of "FROM" and the related table.
[0088] Optionally, the related table includes a main table and an associated table. Among them, if the table name of the input associated table exists, the SQL string of the associated table exists. The SQL string of the associated table is formed by the concatenation of "a JOIN", the table name of the associated table, "b ON", the associated field of the main table, "=", and the associated field of the associated table.
[0089] Step S206: Generate a first SQL statement according to the first time condition string, condition string, result field, and table name string;
[0090] Specifically, in the case where the result field exists, the result field string is the name of the result field; in other cases, the result string is "*".
[0091] The first SQL statement is concatenated by "SELECT", the result field string, the table name string, "WHERE", the first time condition string, "AND", and the condition string.
[0092] Step S208, generate a second SQL statement according to the second time condition string, the condition string, the result field, and the table name string.
[0093] Specifically, in the case where the result field exists, the result field string is the name of the result field; in other cases, the result string is "*".
[0094] The second SQL statement is concatenated by "SELECT", the result field string, the table name string, "WHERE", the second time condition string, "AND", and the condition string.
[0095] In some embodiments, step S108, automatically generating a report text according to the first result set and the second result set includes:
[0096] Compare the first result set and the second result set to obtain a change value;
[0097] Obtain a change direction according to the change value, and obtain a change value according to the change value and the numerical type;
[0098] Specifically, the number of elements in the first result set minus the number of elements in the second result set gives the change value.
[0099] Obtain a change direction according to the change value. If the change value is greater than 0, the change direction is "risen"; if the change value is equal to 0, the change direction is "no change"; if the change value is less than 0, the change direction is "fallen".
[0100] Obtain a change value according to the change value and the numerical type. If the change value is 0, the change value is an empty string;
[0101] If the change value is not 0 and the numerical type is "percentage":
[0102] If the number of elements in the second result set is 0, the program outputs an error message "Required to display the percentage of change, but the denominator is 0! Changed to display the change value", and exits;
[0103] If the number of elements in the second result set is not 0, the change value is the absolute value of the change value divided by the number of elements in the second result set, multiplied by 100, plus "%".
[0104] If the change value is not 0 and the value type is "numerical value", the change value is the absolute value of the change value.
[0105] Obtain the expression of the comparison method according to the statistical model, obtain the expression of the table name according to the relevant table, obtain the expression of the time condition according to the time condition, and obtain the expression of the condition list according to the condition list;
[0106] Specifically, determine the time unit according to the time condition and determine the statistical type according to the statistical model.
[0107] If the input statistical model is "year-on-year":
[0108] If the input time unit is year, the expression of the comparison method is "compared with last year"; if the input time unit is the first half or the second half of the year, the expression of the comparison method is "compared with the same period last year"; if the input time unit is month, the expression of the comparison method is "compared with the same period last year".
[0109] If the input statistical model is "month-on-month":
[0110] If the input time unit is year, the expression of the comparison method is "compared with last year"; if the input time unit is the first half of the year, the expression of the comparison method is "compared with the second half of last year"; if the input time unit is the second half of the year, the expression of the comparison method is "compared with the first half of this year"; if the input time unit is month, the expression of the comparison method is "compared with the previous month".
[0111] Obtain the expression of the table name according to the relevant table, and the relevant table may include the main table and the associated table;
[0112] If the input does not include the expression of the associated table name, the expression of the table name is the expression of the input main table name;
[0113] If the input includes the expression of the associated table name, the expression of the table name is the concatenation of the expression of the input main table name and the expression of the associated table name.
[0114] Obtain the expression of the time condition according to the time condition;
[0115] If the input time unit is year, the expression of the time unit is "year"; if the input time unit is the first half of the year, the expression of the time unit is "the first half of the year"; if the input time unit is the second half of the year, the expression of the time unit is "the second half of the year"; if the input time unit is month, the expression of the time unit is "month".
[0116] If the input time unit is year, the expression of the time condition prefix is "this"; if the input time unit is the first half or the second half of the year, the expression of the time condition prefix is "this year"; if the input time unit is month, the expression of the time condition prefix is "this".
[0117] The expression of the time condition is the concatenation of the expression of the time condition field, the expression of the time condition prefix, and the expression of the time unit.
[0118] Obtain the expression of the condition list according to the condition list.
[0119] The expression of the condition list is the concatenation of the expressions of all conditions included in the condition list. Among them, the expression of each condition is the condition value of that condition.
[0120] Automatically generate a report text according to the expression of the comparison method, the expression of the table name, the expression of the time condition, the expression of the condition list, and the numerical expression.
[0121] Specifically, if there is an associated table in the relevant table, the numerical expression is the concatenation of "of", the expression of the table name, the number of elements in the first result set, and the quantifier of the associated table; otherwise, it is the common numerical expression, where the common numerical expression is the concatenation of "of", the expression of the table name, "the number is", and the number of elements in the first result set.
[0122] The report text is the concatenation of the expression of the comparison method, ",", the expression of the time condition, ",", the expression of the condition list, the expression of the table name, "number", the change direction, the quantity, the line break character, the expression of the time condition, ",", the expression of the condition list, the expression of the table name, and the numerical expression. For example, the generated report text is as follows:
[0123] "Compared with the same period last year, the investment in artificial intelligence companies in Zhejiang Province decreased by 34.38% in the first half of this year.
[0124] There were 63 investments in artificial intelligence companies in Zhejiang Province in the first half of this year."
[0125] In some of these embodiments, in step S202, generating a first time condition string according to the time condition and generating a second time condition string according to the time condition and the statistical model includes:
[0126] Determine the time unit according to the time condition, obtain the lower limit of the first time range and the upper limit of the first time range, and then generate the first time condition string;
[0127] Specifically, determine the time unit according to the time condition, and obtain the lower limit of the first time range and the upper limit of the first time range:
[0128] When the input time unit is year and the time value format is "yyyy", the lower limit of the first time range is "yyyy-01-01" and the upper limit of the first time range is "yyyy-12-31";
[0129] When the input time unit is the first half of the year and the time value format is "yyyy", the lower limit of the first time range is "yyyy-01-01" and the upper limit of the first time range is "yyyy-06-31";
[0130] When the input time unit is the second half of the year and the time value format is "yyyy", the lower limit of the first time range is "yyyy-07-01" and the upper limit of the first time range is "yyyy-12-31";
[0131] When the input time unit is month and the time value format is "yyyy-MM", the lower limit of the first time range is "yyyy-MM-01" and the upper limit of the first time range is "yyyy-MM-31".
[0132] Furthermore, a first time condition string is obtained. The first time condition string is formed by concatenating the time condition field name, ">='", the lower limit of the time range, "', AND", the input time condition field name, "<='", the upper limit of the time range, and "'".
[0133] Determine the time unit according to the time condition, determine the statistical type according to the statistical model, then obtain the lower limit and upper limit of the second time range based on the time unit and the statistical type, and further generate a second time condition string.
[0134] Specifically, Table 1 is a specific table for obtaining the lower limit and upper limit of the second time range. As shown in Table 1, determine the time unit according to the time condition. The time units include "year", "the first half of the year", "the second half of the year", and "month"; determine the statistical type according to the statistical model. The statistical types include "year-on-year" and "month-on-month".
[0135] Table 1
[0136]
[0137] In some embodiments, the expressions of the comparison method obtained according to the statistical model include:
[0138] Determine the time unit according to the time condition and determine the statistical type according to the statistical model;
[0139] Then obtain the expression of the comparison method based on the time unit and the statistical type.
[0140] It should be noted that the steps shown in the above process or the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0141] The embodiments of the present application provide a text automatic generation system based on data elements.Figure 3 is a structural block diagram of a text automatic generation system based on data elements according to an embodiment of the present application, as Figure 3 shown, the system includes an acquisition module 31, a processing module 32, an execution module 33, and a generation module 34;
[0142] The acquisition module 31 acquires preset data values for configuring report data, where the preset data values include time conditions, condition lists, statistical models, result fields, value types, and related tables;
[0143] The processing module 32 generates a first SQL statement and a second SQL statement according to the time condition, condition list, result field, and related table;
[0144] The execution module 33 executes the first SQL statement and the second SQL statement to obtain a first result set and a second result set;
[0145] The generation module 34 automatically generates a report text according to the first result set and the second result set.
[0146] Through the acquisition module 31, processing module 32, execution module 33, and generation module 34 in the embodiments of the present application, the problem of manually writing text templates in automatic report generation is solved, and when changing the report data query conditions, only relevant data elements need to be input to generate reports under different conditions with one key.
[0147] In some of the embodiments, the processing module 32 generating a first SQL statement and a second SQL statement according to the time condition, condition list, result field, and related table includes:
[0148] The processing module 32 generates a first time condition string according to the time condition, and generates a second time condition string according to the time condition and the statistical model;
[0149] The processing module 32 generates a condition string according to the condition list, and generates a table name string according to the related table;
[0150] The processing module 32 generates a first SQL statement according to the first time condition string, condition string, result field, and table name string;
[0151] The processing module 32 generates a second SQL statement according to the second time condition string, condition string, result field, and table name string.
[0152] In some of the embodiments, the generation module 34 automatically generating a report text according to the first result set and the second result set includes:
[0153] The generation module 34 compares the first result set and the second result set to obtain a change value;
[0154] The generation module 34 obtains the change direction based on the change value, and obtains the change value based on the change value and the numerical type;
[0155] The generation module 34 obtains the expression of the comparison method according to the statistical model, obtains the expression of the table name according to the relevant table, obtains the expression of the time condition according to the time condition, and obtains the expression of the condition list according to the condition list;
[0156] The generation module 34 automatically generates a report text according to the expression of the comparison method, the expression of the table name, the expression of the time condition, the expression of the condition list, and the numerical expression.
[0157] In some of these embodiments, the processing module 32 generates a first time condition string according to the time condition, and generates a second time condition string according to the time condition and the statistical model, including:
[0158] The processing module 32 determines the time unit according to the time condition, obtains the lower limit of the first time range and the upper limit of the first time range, and then generates the first time condition string;
[0159] The processing module 32 determines the time unit according to the time condition, determines the statistical type according to the statistical model, and then obtains the lower limit of the second time range and the upper limit of the second time range according to the time unit and the statistical type, and then generates the second time condition string.
[0160] In some of these embodiments, the generation module 34 obtains the expression of the comparison method according to the statistical model, including:
[0161] The generation module 34 determines the time unit according to the time condition, and determines the statistical type according to the statistical model;
[0162] Then, the expression of the comparison method is obtained according to the time unit and the statistical type.
[0163] It should be noted that the above-mentioned various modules can be functional modules or program modules, and can be implemented either by software or by hardware. For the modules implemented by hardware, the above-mentioned various modules can be located in the same processor; or the above-mentioned various modules can also be located in different processors in any combined form.
[0164] This embodiment also provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0165] Optionally, the above-mentioned electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the above-mentioned processor, and the input / output device is connected to the above-mentioned processor.
[0166] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation manners, and will not be elaborated herein.
[0167] In addition, in combination with the above-described method for automatically generating text based on data elements in the embodiments, an embodiment of the present application can provide a storage medium to implement the same. A computer program is stored on the storage medium; when the computer program is executed by a processor, it implements any one of the methods for automatically generating text based on data elements in the above embodiments.
[0168] In one embodiment, a computer device is provided. The computer device may be a terminal. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements a method for automatically generating text based on data elements. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device may be a touch layer covering the display screen, or a button, a trackball, or a touchpad provided on the housing of the computer device, or an external keyboard, a touchpad, or a mouse, etc.
[0169] In one embodiment, Figure 4 is a schematic internal structure diagram of an electronic device according to an embodiment of the present application. As Figure 4 shown, an electronic device is provided. The electronic device may be a server, and its internal structure diagram may be as Figure 4 shown. The electronic device includes a processor, a network interface, an internal memory, and a non-volatile memory connected through an internal bus. Among them, the non-volatile memory stores an operating system, a computer program, and a database. The processor is used to provide computing and control capabilities. The network interface is used to communicate with an external terminal through a network connection. The internal memory is used to provide an environment for the operation of the operating system and the computer program. When the computer program is executed by the processor, it implements a method for automatically generating text based on data elements. The database is used to store data.
[0170] Those skilled in the art can understand that Figure 4 the structure shown in only represents a block diagram of some structures related to the solution of the present application, and does not constitute a limitation on the electronic device to which the solution of the present application is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0171] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. This computer program can be stored in a non-volatile computer-readable storage medium. When this computer program is executed, it can include the processes of the embodiments of the above various methods. Among them, any reference to a memory, storage, database, or other medium used in the various embodiments provided in this application can include non-volatile and / or volatile memories. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or an external cache. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0172] Those skilled in the art should understand that the technical features of the above-described embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as falling within the scope described in this specification.
[0173] The above-described embodiments merely represent several implementation manners of this application. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the concept of this application, several modifications and improvements can still be made, and these all belong to the protection scope of this application. Therefore, the protection scope of the patent of this application should be subject to the appended claims.
Claims
1. A text automatic generation method based on data elements, characterized in that The method includes: Obtaining a preset data value for configuring report data, where the preset data value includes a time condition, a condition list, a statistical model, result fields, a numerical type, and a related table; Generating a first time condition string according to the time condition, and generating a second time condition string according to the time condition and the statistical model; Generating a condition string according to the condition list, and generating a table name string according to the related table; Generating a first SQL statement according to the first time condition string, the condition string, the result fields, and the table name string; Generating a second SQL statement according to the second time condition string, the condition string, the result fields, and the table name string; Executing the first SQL statement and the second SQL statement to obtain a first result set and a second result set; Comparing the first result set and the second result set to obtain a change value; Obtaining a change direction according to the change value, and obtaining a change numerical value according to the change value and the numerical type; Obtaining an expression of the comparison method according to the statistical model, obtaining an expression of the table name according to the related table, obtaining an expression of the time condition according to the time condition, and obtaining an expression of the condition list according to the condition list; Automatically generating a report text according to the expression of the comparison method, the expression of the table name, the expression of the time condition, the expression of the condition list, and a numerical expression.
2. The method according to claim 1, wherein Generating a first time condition string according to the time condition, and generating a second time condition string according to the time condition and the statistical model includes: Determining a time unit according to the time condition, obtaining a lower limit of a first time range and an upper limit of the first time range, and further generating a first time condition string; Determining a time unit according to the time condition, determining a statistical type according to the statistical model, and then obtaining a lower limit of a second time range and an upper limit of the second time range according to the time unit and the statistical type, and further generating a second time condition string.
3. The method according to claim 1, characterized in that, Obtaining an expression of the comparison method according to the statistical model includes: Determining a time unit according to the time condition, and determining a statistical type according to the statistical model; Then obtaining an expression of the comparison method according to the time unit and the statistical type.
4. A text automatic generation system based on data elements, characterized in that, The system includes an acquisition module, a processing module, an execution module, and a generation module; The acquisition module obtains a preset data value for configuring report data, where the preset data value includes a time condition, a condition list, a statistical model, result fields, a numerical type, and a related table; The processing module generates a first time condition string according to the time condition, and generates a second time condition string according to the time condition and the statistical model; The processing module generates a condition string according to the condition list, and generates a table name string according to the related table; The processing module generates a first SQL statement according to the first time condition string, the condition string, the result fields, and the table name string; The processing module generates a second SQL statement according to the second time condition string, the condition string, the result fields, and the table name string; The execution module executes the first SQL statement and the second SQL statement to obtain a first result set and a second result set; The generation module compares the first result set and the second result set to obtain a change value; The generation module obtains a change direction based on the change value, and obtains a change value based on the change value and the numerical type; The generation module obtains an expression of the comparison method according to the statistical model, obtains an expression of the table name according to the relevant table, obtains an expression of the time condition according to the time condition, and obtains an expression of the condition list according to the condition list; The generation module automatically generates a report text according to the expression of the comparison method, the expression of the table name, the expression of the time condition, the expression of the condition list, and the numerical expression; 5. The system according to claim 4, characterized in that, The processing module generates a first time condition string according to the time condition, and generates a second time condition string according to the time condition and the statistical model, including: The processing module determines a time unit according to the time condition, obtains a lower limit of the first time range and an upper limit of the first time range, and then generates a first time condition string; The processing module determines a time unit according to the time condition, determines a statistical type according to the statistical model, and then obtains a lower limit of the second time range and an upper limit of the second time range according to the time unit and the statistical type, and then generates a second time condition string.
6. The system according to claim 4, characterized in that, The generation module obtains an expression of the comparison method according to the statistical model, including: The generation module determines a time unit according to the time condition and determines a statistical type according to the statistical model; Then obtain an expression of the comparison method according to the time unit and the statistical type.
Citation Information
Patent Citations
Method for generating real-time statistical report
CN102222105A
System and method for automatically generating news based on template
CN106021389A