Power distribution network data query method and device

By introducing the SQL statement generation model in the distribution network data query system, the natural language query is converted into SQL query statements, which solves the problem of low efficiency and error errors in traditional query methods. The user can quickly and accurately obtain the user without understanding the SQL syntax. The function of the distribution network data.

CN119377251APending Publication Date: 2025-01-28GUANGDONG POWER GRID CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411633496.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-15
Publication Date
2025-01-28

AI Technical Summary

Technical Problem

Traditional distribution network data query methods rely on manual writing of SQL query statements, which are inefficient and error-prone. Especially for practitioners with non-technical backgrounds, it is difficult to understand complex database structures and SQL syntax.

Method used

Generate a model through the SQL statement, convert the user entered natural language query text into the corresponding SQL query statement, and retrieve the target data in the preset distribution network database to achieve the database structure and SQL syntax. The function of data required.

Benefits of technology

Users can quickly and accurately obtain the required distribution network data through simple natural language input, improve the efficiency and accuracy of inquiry, and reduce their dependence on database structures and SQL syntax.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119377251A_ABST
    Figure CN119377251A_ABST
Patent Text Reader

Abstract

The invention discloses a power distribution network data query method and device.The method comprises the steps that firstly, a query text which is input by a user and used for indicating power distribution network data needing to be queried by the user is obtained, and then the query text is input into an SQL statement generation model; sending the query text to the SQL statement generation model, so that the SQL statement generation model generates a corresponding target SQL query statement according to the query text, and finally calling corresponding target power distribution network data from a preset power distribution network database according to the target SQL query statement. By implementing the method and the device, a user can quickly and accurately obtain the required power distribution network data through simple natural language input without knowing a complex database structure and SQL grammar.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing, and in particular to a distribution network data query method and device. Background Art

[0002] In the power industry, the query and management of distribution network data is a crucial link. With the development of smart grids, the amount of distribution network data has increased dramatically. These data are of great significance to the stable operation, fault prediction, energy efficiency management and other aspects of the power system.

[0003] However, traditional distribution network data query methods often rely on manually written SQL query statements, which is not only inefficient but also prone to errors. Especially for practitioners with non-technical backgrounds, they may find it difficult to understand the complex database structure and SQL syntax, making it difficult to accurately express their query needs. Summary of the invention

[0004] The present invention provides a distribution network data query method. The method converts a query text input by a user into a corresponding SQL query statement through an SQL statement generation model, and retrieves corresponding target distribution network data from a preset distribution network database according to the target SQL query statement. Thus, the required distribution network data can be quickly and accurately obtained through simple natural language input without understanding complex database structure and SQL syntax.

[0005] An embodiment of the present invention provides a distribution network data query method, comprising:

[0006] Obtaining a query text input by a user; wherein the query text is used to indicate the distribution network data that the user needs to query;

[0007] Input the query text into an SQL statement generation model, so that the SQL statement generation model generates a corresponding target SQL query statement according to the query text; wherein the SQL statement generation model is obtained after training with a number of labeled query texts and a number of labeled SQL query statements as input and with the predicted SQL query statements as output;

[0008] According to the target SQL query statement, corresponding target distribution network data is retrieved from a preset distribution network database.

[0009] Furthermore, the construction process of the SQL statement generation model includes:

[0010] Obtaining a query text sample set; wherein the query text sample set includes: a number of tag query texts and a number of tag SQL query statements;

[0011] Constructing a Text-to-SQL model, taking the query text sample set as input and the predicted SQL query statement as output, and iteratively training the Text-to-SQL model until the loss function value of the Text-to-SQL model converges;

[0012] The trained Text-to-SQL model is used as the SQL statement generation model;

[0013] In each training process, the loss function value is calculated according to the SQL query statement predicted by the Text-to-SQL model and the label SQL query statement corresponding to the query text sample set, and the weight of the Text-to-SQL model is adjusted according to the calculated loss function value.

[0014] Furthermore, before the query text is input into the SQL statement generation model, the method further includes:

[0015] A preprocessing operation is performed on the query text input by the user to obtain a preprocessed query text; wherein the preprocessing operation includes duplicate text removal and text standardization operation.

[0016] Further, the step of retrieving corresponding target distribution network data from a preset distribution network database according to the target SQL query statement includes:

[0017] Establishing a connection with the power distribution network database through a preset database interface;

[0018] After successfully connecting to the distribution network database, submitting the target SQL query statement to the distribution network database, so that the distribution network database returns a corresponding query result according to the target SQL query statement;

[0019] The query result is used as the target distribution network data.

[0020] Furthermore, the distribution network data query method further includes:

[0021] After obtaining the target distribution network data, calling a preset API interface;

[0022] The target distribution network data is transmitted to the user's terminal through the API interface.

[0023] An embodiment of the present invention further provides a distribution network data query device, comprising: a query text acquisition module, an SQL query statement generation module and a target distribution network data retrieval module;

[0024] The query text acquisition module is used to acquire the query text input by the user; wherein the query text is used to indicate the power distribution network data that the user needs to query;

[0025] The SQL query statement generation module is used to input the query text into the SQL statement generation model, so that the SQL statement generation model generates a corresponding target SQL query statement according to the query text; wherein the SQL statement generation model is obtained after training with a number of label query texts and a number of label SQL query statements as input and the predicted SQL query statements as output;

[0026] The target distribution network data retrieval module is used to retrieve corresponding target distribution network data from a preset distribution network database according to the target SQL query statement.

[0027] Furthermore, the construction process of the SQL statement generation model includes:

[0028] Obtaining a query text sample set; wherein the query text sample set includes: a number of tag query texts and a number of tag SQL query statements;

[0029] Constructing a Text-to-SQL model, taking the query text sample set as input and the predicted SQL query statement as output, and iteratively training the Text-to-SQL model until the loss function value of the Text-to-SQL model converges;

[0030] The trained Text-to-SQL model is used as the SQL statement generation model;

[0031] In each training process, the loss function value is calculated according to the SQL query statement predicted by the Text-to-SQL model and the label SQL query statement corresponding to the query text sample set, and the weight of the Text-to-SQL model is adjusted according to the calculated loss function value.

[0032] Furthermore, before the query text is input into the SQL statement generation model, the method further includes:

[0033] A preprocessing operation is performed on the query text input by the user to obtain a preprocessed query text; wherein the preprocessing operation includes duplicate text removal and text standardization operation.

[0034] Further, the step of retrieving corresponding target distribution network data from a preset distribution network database according to the target SQL query statement includes:

[0035] Establishing a connection with the power distribution network database through a preset database interface;

[0036] After successfully connecting to the distribution network database, submitting the target SQL query statement to the distribution network database, so that the distribution network database returns a corresponding query result according to the target SQL query statement;

[0037] The query result is used as the target distribution network data.

[0038] Furthermore, the distribution network data query device further includes:

[0039] After obtaining the target distribution network data, calling a preset API interface;

[0040] The target distribution network data is transmitted to the user's terminal through the API interface.

[0041] The following beneficial effects are achieved by implementing the present invention:

[0042] The present invention provides a distribution network voltage control method, device, terminal equipment and storage medium based on photovoltaic access. The method first obtains a query text input by a user, wherein the query text describes the distribution network data that the user needs to query in the form of natural language, and then inputs the query text into a pre-trained SQL statement generation model. Since the SQL statement generation model takes a number of label query texts and corresponding label SQL query statements as inputs and takes predicted SQL query statements as outputs for training, after training, the SQL statement generation model can learn and understand the mapping relationship between the query text and the SQL query statement, thereby being able to generate an SQL query statement corresponding to the query text, and finally, according to the generated SQL query statement, the corresponding target distribution network data is retrieved from a preset distribution network database; in summary, the user can quickly and accurately obtain the required distribution network data through simple natural language input without having to understand complex database structures and SQL syntax. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the implementation manner will be briefly introduced below. Obviously, the drawings described below are only some implementation manners of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0044] Figure 1 It is a flowchart of a distribution network data query method provided by a certain embodiment of the present application;

[0045] Figure 2 It is a structural diagram of a distribution network data query device provided in a certain embodiment of the present application. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0047] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by technicians in the technical field to which this application belongs; the terms used herein are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.

[0048] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.

[0049] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0050] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0051] In the description of the embodiments of the present application, the term "multiple" refers to more than two (including two). Similarly, "multiple groups" refers to more than two groups (including two groups), and "multiple pieces" refers to more than two pieces (including two pieces).

[0052] In the description of the embodiments of the present application, unless otherwise clearly specified and limited, technical terms such as "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, and it can be the internal connection of two elements or the interaction relationship between two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the embodiments of the present application can be understood according to the specific circumstances.

[0053] See also Figure 1 , is a flow chart of a distribution network data query method provided by an embodiment of the present invention, comprising:

[0054] S1. Obtaining a query text input by a user; wherein the query text is used to indicate the distribution network data that the user needs to query;

[0055] Specifically, in step S1, it is necessary to obtain the query text input by the user, where the query text expresses the user's query demand for power distribution network data.

[0056] In a preferred embodiment, before inputting the query text into the SQL statement generation model, the method further includes:

[0057] Performing a preprocessing operation on the query text input by the user to obtain a preprocessed query text; wherein the preprocessing operation includes repeated text removal and text standardization operation;

[0058] Specifically, in actual applications, the query text input by the user may contain redundant information, such as repeated words or terms with different expressions, which will affect the accuracy and efficiency of the SQL statement generation model. Therefore, the query text needs to be preprocessed, wherein the preprocessing operation includes but is not limited to repeated text removal and text standardization operations.

[0059] S2, inputting the query text into an SQL statement generation model, so that the SQL statement generation model generates a corresponding SQL query statement according to the query text; wherein the SQL statement generation model is obtained after training with a number of label query texts and a number of label SQL query statements as input and with the predicted SQL query statements as output;

[0060] In a preferred embodiment, the construction process of the SQL statement generation model includes:

[0061] Obtaining a query text sample set; wherein the query text sample set includes: a number of tag query texts and a number of tag SQL query statements;

[0062] Constructing a Text-to-SQL model, taking the query text sample set as input and the predicted SQL query statement as output, and iteratively training the Text-to-SQL model until the loss function value of the Text-to-SQL model converges;

[0063] The trained Text-to-SQL model is used as the SQL statement generation model;

[0064] In each training process, a loss function value is calculated according to the SQL query statement predicted by the Text-to-SQL model and the label SQL query statement corresponding to the query text sample set, and the weight of the Text-to-SQL model is adjusted according to the calculated loss function value;

[0065] Specifically, first, a query text sample set needs to be prepared, which includes several pairs of label query texts and corresponding label SQL query statements. One of the samples is used as an example for explanation:

[0066] Tag query text 1: "Get the average capacity of solar power generation units in area D.".

[0067] Corresponding tag SQL query statement 1: SELECT AVG(capacity)FROM wind_turbinesWHEREregion='D'AND power_source='solar energy';

[0068] Then, a Text-to-SQL model is built. It should be noted that the working principle of the Text-to-SQL model is to parse the natural language query input by the user, understand its semantics and intention, and then map the query to the corresponding SQL statement according to the database mode (such as table structure, column name, etc.), and finally generate an executable SQL statement and return the query result;

[0069] Specifically, the query text sample set is used as input, and the predicted SQL query statement is used as output, and the Text-to-SQL model is iteratively trained. In each iterative training, the SQL query statement predicted by the current Text-to-SQL model is compared with the label SQL query statement corresponding to the query text sample set, and a loss function value is calculated according to the comparison result, and it is determined whether the loss function value converges. If it converges, the training is stopped to obtain the Catboost model after the training is completed. If it does not converge, the weight of the Text-to-SQL model is adjusted to obtain the Text-to-SQL model for the next iterative training, until the loss function value of the Text-to-SQL model converges, and the Text-to-SQL model after the training is used as the SQL statement generation model.

[0070] In an illustrative manner, after obtaining the query text input by the user in step S1, the query text needs to be input into the SQL statement generation model, so that the SQL statement generation model generates a corresponding SQL query statement according to the query text;

[0071] Specifically, assume that there is a table named wind_turbines in the preset distribution network database, which contains the following fields:

[0072] region: region

[0073] turbine_id: turbine ID

[0074] capacity: unit capacity

[0075] power_source: power source type (such as wind power, solar power, etc.);

[0076] Specifically, assuming that the query text currently input by the user is: query the capacity of all units used for wind power generation in area A, then based on the query text input by the user, the SQL query statement generated by the SQL statement generation model is specifically as follows:

[0077] SELECT SUM(capacity)AS total_capacity

[0078] FROM wind_turbines

[0079] WHEREregion='A'AND power_source='wind';

[0080] It should be noted that the purpose of the generated SQL query statement is to retrieve the capacity of all wind power generation units in area A from the wind_turbines table of the distribution network database, and calculate the total capacity of all wind turbines in area A by using the SUM function, and name the result column with the AS keyword.

[0081] S3. According to the target SQL query statement, corresponding target distribution network data is retrieved from a preset distribution network database.

[0082] In a preferred embodiment, the step of retrieving corresponding target distribution network data from a preset distribution network database according to the target SQL query statement includes:

[0083] Establishing a connection with the distribution network database through a preset database interface;

[0084] After successfully connecting to the distribution network database, submitting the target SQL query statement to the distribution network database, so that the distribution network database returns a corresponding query result according to the target SQL query statement;

[0085] Using the query result as target distribution network data;

[0086] Specifically, a preset database interface (such as JDBC, ODBC, Python database connection library, etc.) attempts to establish a connection with the distribution network database;

[0087] It should be noted that there is no specific limitation on the database interface here;

[0088] After successfully connecting to the distribution network database, the generated SQL query statement is submitted to the distribution network database, and after receiving the query statement, the database parses and executes the statement;

[0089] Specifically, the database filters data in the wind_turbines table according to the condition (region = 'A' AND power_source = 'wind power') in the SQL query statement, and performs a SUM (capacity) operation on the filtered data to calculate the total capacity of all wind turbines used for wind power generation in region A. Finally, the database returns the query result (i.e., the calculated total capacity of all wind turbines used for wind power generation in region A).

[0090] Then, the query result is used as the target distribution network data.

[0091] In a preferred embodiment, the distribution network data query method further includes:

[0092] After obtaining the target distribution network data, calling a preset API interface;

[0093] The target distribution network data is transmitted to the user's terminal through the API interface;

[0094] Specifically, the target distribution network data is encapsulated into a format matching the API interface, a connection with the API interface is established, and the encapsulated target distribution network data is sent to the API interface through the connection, so that the API interface parses the encapsulated target distribution network data and constructs a response including the target distribution network data, and then the constructed response is sent to the user's terminal and displayed on the user's terminal;

[0095] It should be noted that the terminal may be a web page, a mobile application or other user interface, and the type of the terminal is not specifically limited here.

[0096] See also Figure 2 , is a distribution network data query device provided by an embodiment of the present invention, comprising: a query text acquisition module, an SQL query statement generation module and a target distribution network data retrieval module;

[0097] The query text acquisition module is used to acquire the query text input by the user; wherein the query text is used to indicate the power distribution network data that the user needs to query;

[0098] The SQL query statement generation module is used to input the query text into the SQL statement generation model, so that the SQL statement generation model generates a corresponding target SQL query statement according to the query text; wherein the SQL statement generation model is obtained after training with a number of label query texts and a number of label SQL query statements as input and the predicted SQL query statements as output;

[0099] The target distribution network data retrieval module is used to retrieve corresponding target distribution network data from a preset distribution network database according to the target SQL query statement.

[0100] In a preferred embodiment, the construction process of the SQL statement generation model includes:

[0101] Obtaining a query text sample set; wherein the query text sample set includes: a number of tag query texts and a number of tag SQL query statements;

[0102] Constructing a Text-to-SQL model, taking the query text sample set as input and the predicted SQL query statement as output, and iteratively training the Text-to-SQL model until the loss function value of the Text-to-SQL model converges;

[0103] The trained Text-to-SQL model is used as the SQL statement generation model;

[0104] In each training process, the loss function value is calculated according to the SQL query statement predicted by the Text-to-SQL model and the label SQL query statement corresponding to the query text sample set, and the weight of the Text-to-SQL model is adjusted according to the calculated loss function value.

[0105] In a preferred embodiment, before inputting the query text into the SQL statement generation model, the method further includes:

[0106] A preprocessing operation is performed on the query text input by the user to obtain a preprocessed query text; wherein the preprocessing operation includes duplicate text removal and text standardization operation.

[0107] In a preferred embodiment, the step of retrieving corresponding target distribution network data from a preset distribution network database according to the target SQL query statement includes:

[0108] Establishing a connection with the power distribution network database through a preset database interface;

[0109] After successfully connecting to the distribution network database, submitting the target SQL query statement to the distribution network database, so that the distribution network database returns a corresponding query result according to the target SQL query statement;

[0110] The query result is used as the target distribution network data.

[0111] In a preferred embodiment, the distribution network data query device further includes:

[0112] After obtaining the target distribution network data, calling a preset API interface;

[0113] The target distribution network data is transmitted to the user's terminal through the API interface.

[0114] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.

Claims

1. A distribution network data query method, characterized in that: include: Obtaining a query text input by a user; wherein the query text is used to indicate the distribution network data that the user needs to query; Input the query text into an SQL statement generation model, so that the SQL statement generation model generates a corresponding target SQL query statement according to the query text; wherein the SQL statement generation model is obtained after training with a number of labeled query texts and a number of labeled SQL query statements as input and with the predicted SQL query statements as output; According to the target SQL query statement, corresponding target distribution network data is retrieved from a preset distribution network database.

2. The method for querying distribution network data according to claim 1, characterized in that: The construction process of the SQL statement generation model includes: Obtaining a query text sample set; wherein the query text sample set includes: a number of tag query texts and a number of tag SQL query statements; Constructing a Text-to-SQL model, taking the query text sample set as input and the predicted SQL query statement as output, and iteratively training the Text-to-SQL model until the loss function value of the Text-to-SQL model converges; The trained Text-to-SQL model is used as the SQL statement generation model; In each training process, the loss function value is calculated according to the SQL query statement predicted by the Text-to-SQL model and the label SQL query statement corresponding to the query text sample set, and the weight of the Text-to-SQL model is adjusted according to the calculated loss function value.

3. The method for querying distribution network data according to claim 1, characterized in that: Before inputting the query text into the SQL statement generation model, the method further includes: A preprocessing operation is performed on the query text input by the user to obtain a preprocessed query text; wherein the preprocessing operation includes duplicate text removal and text standardization operation.

4. The method for querying distribution network data according to claim 1, characterized in that: The step of retrieving corresponding target distribution network data from a preset distribution network database according to the target SQL query statement includes: Establishing a connection with the distribution network database through a preset database interface; After successfully connecting to the distribution network database, submitting the target SQL query statement to the distribution network database, so that the distribution network database returns a corresponding query result according to the target SQL query statement; The query result is used as the target distribution network data.

5. The method for querying distribution network data according to claim 4, characterized in that: Also includes: After obtaining the target distribution network data, calling a preset API interface; The target distribution network data is transmitted to the user's terminal through the API interface.

6. A distribution network data query device, characterized in that: include: Query text acquisition module, SQL query statement generation module and target distribution network data retrieval module; The query text acquisition module is used to acquire the query text input by the user; wherein the query text is used to indicate the power distribution network data that the user needs to query; The SQL query statement generation module is used to input the query text into the SQL statement generation model, so that the SQL statement generation model generates a corresponding target SQL query statement according to the query text; wherein the SQL statement generation model is obtained after training with a number of label query texts and a number of label SQL query statements as input and the predicted SQL query statements as output; The target distribution network data retrieval module is used to retrieve corresponding target distribution network data from a preset distribution network database according to the target SQL query statement.

7. The distribution network data query device according to claim 6, characterized in that: The construction process of the SQL statement generation model includes: Obtaining a query text sample set; wherein the query text sample set includes: a number of tag query texts and a number of tag SQL query statements; Constructing a Text-to-SQL model, taking the query text sample set as input and the predicted SQL query statement as output, and iteratively training the Text-to-SQL model until the loss function value of the Text-to-SQL model converges; The trained Text-to-SQL model is used as the SQL statement generation model; In each training process, the loss function value is calculated according to the SQL query statement predicted by the Text-to-SQL model and the label SQL query statement corresponding to the query text sample set, and the weight of the Text-to-SQL model is adjusted according to the calculated loss function value.

8. The distribution network data query device according to claim 6, characterized in that: Before inputting the query text into the SQL statement generation model, the method further includes: A preprocessing operation is performed on the query text input by the user to obtain a preprocessed query text; wherein the preprocessing operation includes duplicate text removal and text standardization operation.

9. The distribution network data query device according to claim 6, characterized in that: The step of retrieving corresponding target distribution network data from a preset distribution network database according to the target SQL query statement includes: Establishing a connection with the distribution network database through a preset database interface; After successfully connecting to the distribution network database, submitting the target SQL query statement to the distribution network database, so that the distribution network database returns a corresponding query result according to the target SQL query statement; The query result is used as the target distribution network data.

10. The distribution network data query device according to claim 9, characterized in that: Also includes: After obtaining the target distribution network data, calling a preset API interface; The target distribution network data is transmitted to the user's terminal through the API interface.