Data query method and device based on interface generation, equipment and medium
By analyzing natural language query statements and generating interfaces, the problem of accessing multi-source heterogeneous databases was solved, achieving efficient and accurate data acquisition and system compatibility, reducing costs, and ensuring data security.
Patent Information
- Application Number
- CN202511403710.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-29
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2045-09-29
AI Technical Summary
When dealing with multi-source heterogeneous databases, traditional methods require the development of specific interfaces or query tools for each database, which increases development costs, reduces the flexibility and efficiency of data access, and requires users to master the professional knowledge of different databases, thus increasing the cost of use.
By analyzing the received natural language query statements, the system determines the data query requirements and interface requirements, generates the target data query statement, and obtains the target query data based on the preset interface template or existing interface, supporting efficient access to multi-source heterogeneous databases.
It enables users lacking professional database knowledge to efficiently and accurately obtain data through natural language, improving the efficiency and accuracy of data queries, reducing costs, and enhancing system compatibility and data security.
Smart Images

Figure CN120873072A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a data query method, apparatus, device, and medium based on interface generation. Background Technology
[0002] In today's information society, data has become a crucial core asset for enterprises and organizations. With the advent of the big data era, the scale and types of data have increased dramatically, and database systems have also become more diversified and heterogeneous. Multi-source heterogeneous databases refer to systems composed of databases of different types, structures, and storage methods. These databases may include relational databases, non-relational databases, new types of databases, data warehouses, big data platforms, etc.
[0003] When dealing with multi-source heterogeneous databases, due to significant differences in SQL (Structured Query Language) languages, data type mismatches, and schema differences among different databases, traditional methods usually require developing specific interfaces or query tools for each database. This not only increases development costs but also reduces the flexibility and efficiency of data access. Furthermore, it requires users to master specialized database knowledge of different databases, greatly increasing the user's cost. Summary of the Invention
[0004] In view of this, the purpose of this invention is to provide a data query method, apparatus, device, and medium based on interface generation, enabling users lacking professional database knowledge to efficiently and accurately obtain the required data through natural language. The specific solution is as follows: Firstly, this application discloses a data query method based on interface generation, including: The received query statement is analyzed to determine the data query requirement information and interface requirement information corresponding to the query statement; the query statement is natural language used for data query. Based on the data query requirement information, the corresponding data fields and data tables are matched from the preset database, and the target data query statement is generated according to the data fields and data tables; Determine whether a preset interface corresponding to the interface requirement information exists in the preset interface set; If it does not exist, a target interface corresponding to the interface requirement information is generated based on the preset interface template; if it exists, the preset interface is used as the target interface. The target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameters corresponding to the target data query statement.
[0005] Optionally, the step of analyzing the received query statement to determine the data query requirement information and interface requirement information corresponding to the query statement includes: Identify stop words in the query statement and remove the stop words from the query statement to obtain the query statement after removal; The removed query statement is segmented to obtain several query terms, and the parts of speech corresponding to the several query terms are identified. Then, the several query terms are labeled according to the parts of speech to obtain labeled query terms. Identify named entities in the tagged query terms and determine the syntactic relationships between the tagged query terms; Generate the target topology structure corresponding to the tagged query terms based on the named entities and the syntactic relationships; The target topology is analyzed to determine the data query requirements and interface requirements corresponding to the query statement.
[0006] Optionally, the step of analyzing the target topology to determine the data query requirement information and interface requirement information corresponding to the query statement includes: The target topology is analyzed using a preset model to identify the query intent corresponding to the query statement, and data query requirement information is generated based on the query intent. Based on the query intent, determine the interface type corresponding to the query statement, the interface parameters corresponding to the interface type, and the data return format, and generate interface requirement information based on the interface type, the interface parameters, and the data return format.
[0007] Optionally, the step of matching corresponding data fields and data tables from a preset database based on the data query requirement information, and generating a target data query statement based on the data fields and data tables, includes: By matching the data query requirement information with a preset database, the target data table, target data field, and target correspondence between the target data table and the target data field in the preset database are determined. A data query statement to be confirmed is generated based on the target data table, the target data fields, and the target correspondence using preset database syntax rules. A syntax check is performed on the query statement to be confirmed to determine whether there are any syntax errors in the query statement. If there is a syntax error in the data query statement to be confirmed, the data query statement to be confirmed is corrected based on the syntax error to obtain the data query statement to be optimized. If there are no syntax errors in the data query statement to be confirmed, then the data query statement to be confirmed will be used as the data query statement to be optimized. The data query statement to be optimized is optimized based on preset optimization rules to obtain the target data query statement; the preset optimization rules are to add a data index to the data query statement to be optimized or to split the query.
[0008] Optionally, generating the target interface corresponding to the interface requirement information based on the preset interface template includes: Determine the target interface template corresponding to the interface type from the preset interface template set, and generate the target interface based on the target interface template, the interface parameters, and the data return format; Accordingly, the method further includes: The target interface is added to the preset interface set to update the preset interface set, and the updated interface set is used as the new preset interface set.
[0009] Optionally, determining the target data source corresponding to the data query requirement information, and obtaining the target query data corresponding to the data query requirement information from the target data source through the target interface based on the query parameters corresponding to the target data query statement, includes: Determine the target data source corresponding to the data query requirement information; The target data query statement is executed in the preset database, and the corresponding execution result dataset is obtained; The execution result dataset is iterated through in a loop to extract the field values corresponding to the execution result dataset, and query parameters are generated based on the field values. The target interface retrieves target query data corresponding to the data query requirement information from the target data source based on the query parameters corresponding to the target data query statement.
[0010] Optionally, the data query method based on the interface also includes: Monitor the response time of the target interface. If the response time is greater than a preset response time threshold, optimize the target interface according to a preset interface optimization rule, and use the optimized interface as the new target interface. The preset interface optimization rule is a rule for optimizing the query logic and interface code of the target interface.
[0011] Secondly, this application discloses a data query device based on an interface, comprising: The information determination module is used to analyze the received query statement to determine the data query requirement information and interface requirement information corresponding to the query statement; the query statement is natural language used for data query. The query statement generation module is used to match corresponding data fields and data tables from a preset database based on the data query requirement information, and generate a target data query statement based on the data fields and data tables. An interface matching module is used to determine whether there is a preset interface in a preset interface set that corresponds to the interface requirement information. An interface determination module is used to generate a target interface corresponding to the interface requirement information based on a preset interface template if the interface does not exist; if the interface does exist, the preset interface is used as the target interface. The data query module is used to determine the target data source corresponding to the data query requirement information, and to obtain the target query data corresponding to the data query requirement information from the target data source based on the query parameters corresponding to the target data query statement through the target interface.
[0012] Thirdly, this application discloses an electronic device, including: Memory, used to store computer programs; A processor is used to execute the computer program to implement the interface-based data query method as described above.
[0013] Fourthly, this application discloses a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the aforementioned data query method based on interface generation.
[0014] In this application, the received query statement can be analyzed to determine the data query requirement information and interface requirement information corresponding to the query statement; the query statement is natural language used for data query; based on the data query requirement information, corresponding data fields and data tables are matched from a preset database, and a target data query statement is generated according to the data fields and data tables; it is determined whether a preset interface corresponding to the interface requirement information exists in a preset interface set; if it does not exist, a target interface corresponding to the interface requirement information is generated based on a preset interface template; if it exists, the preset interface is used as the target interface; the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameters corresponding to the target data query statement.
[0015] Therefore, the method of this application can analyze query statements to determine the corresponding data query requirements and interface requirements. Then, based on the data query requirements, it matches data fields and tables from a preset database and generates the corresponding target data query statement. It determines whether a preset interface corresponding to the interface requirements exists in the preset interface set. If not, it generates a target interface corresponding to the interface requirements based on a preset interface template. If it exists, it uses the preset interface as the target interface. Finally, it determines the target data source corresponding to the data query requirements and retrieves the target query data corresponding to the data query requirements from the target data source using the target interface and the query parameters corresponding to the target data query statement. This allows users lacking professional database knowledge to easily obtain the required data through natural language, thereby achieving efficient access and operation of multi-source heterogeneous databases, significantly improving the efficiency and accuracy of data queries, reducing data processing costs, enhancing system compatibility, ensuring data security, and providing solid support for enterprises and organizations in data-driven decision-making. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention 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 embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0017] Figure 1 This application discloses a data query method based on interface generation. Figure 2 This is a data query flowchart disclosed in this application; Figure 3 This application discloses a specific data query flowchart; Figure 4 This is a schematic diagram of the structure of a data query device based on interface generation disclosed in this application; Figure 5 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] Currently, when dealing with multi-source heterogeneous databases, due to significant differences in SQL languages, data type mismatches, schema differences, and other issues among different databases, traditional methods usually require developing specific interfaces or query tools for each database separately. This not only increases the development cost but also reduces the flexibility and efficiency of data access. Moreover, users need to master professional database knowledge of different databases, greatly increasing the user's usage cost.
[0020] To overcome the above technical problems, this application discloses a data query method, device, equipment, and medium based on interface generation, which allows users lacking professional database knowledge to efficiently and accurately obtain the required data through natural language.
[0021] See Figure 1 As shown, an embodiment of the present invention discloses a data query method based on interface generation, including: Step S11: Analyze the received query statement to determine the data query requirement information and interface requirement information corresponding to the query statement; the query statement is natural language for data query.
[0022] In this embodiment, data query is performed through a data access system. As Figure 2 shown, first, it is necessary to analyze the query statement input by the user, and the query statement input by the user is natural language for data query. Specifically, as Figure 3 shown, it is necessary to identify the stop words in the query statement and remove the stop words from the query statement to obtain the query statement after removal. For example, identify words such as "of", "is", "in", etc. that have little impact on semantics. Then, it is necessary to perform word segmentation on the query statement after removal to obtain several query words, identify the词性 corresponding to the several query words, and then label the several query words through the词性 to obtain the labeled query words. For example, use natural language processing tools such as NLTK (Natural Language Toolkit), HanLP (Han Language Processing), etc. to segment the input natural language text and label the词性 of each word, such as nouns, verbs, adjectives, etc. Then, it is necessary to identify the named entities in the labeled query words and determine the grammatical relationship between the labeled query words. For example, the subject-predicate-object structure, and generate the target topological structure corresponding to the labeled query words based on the named entities and the grammatical relationship. That is, convert the preprocessed natural language into a structured intermediate representation form. For example, use a tree structure or a graph structure to represent the syntax and semantic relationship of the statement, which is convenient for subsequent modules to process.
[0023] Finally, the target topology needs to be analyzed to determine the corresponding data query requirements and interface requirements for the query statement. This involves analyzing the target topology using a pre-defined model to identify the query intent, generating data query requirements based on that intent, determining the corresponding interface type, interface parameters, and data return format, and then generating interface requirements based on the interface type, parameters, and return format. It's worth noting that identifying the query intent can leverage machine learning algorithms and domain knowledge bases. Deep learning models, such as the Transformer model, can be used to analyze the intermediate representation output by the natural language processing module to identify the user's primary query intent. For example, determining whether the user is performing a single-table query, multi-table join, aggregation statistics, or data comparison. Furthermore, the semantic relationships within the query statement need to be further analyzed. Based on dependency syntax and knowledge graphs, the logical relationships between entities can be inferred, clarifying the connections between entities and the specific meaning of the query conditions, thus eliminating semantic ambiguity. For example, in the above example, "the past month" is determined to be the time range condition, "sales exceeding 100,000 yuan" is the numerical filtering condition, and "product information" is the target data for the query. By considering the context of the query, if the user has performed related queries before, combining historical query records with the current query statement allows for a more accurate understanding of the user's intent. For example, if a user previously queried sales data for a certain type of product, and this query is "Let's take a look at the inventory status of these products," the system can understand from the context that "these products" refers to the products previously queried. In this way, by analyzing the user's input query, the natural language query can be transformed into structured data that the computer can process, facilitating subsequent processing and improving the efficiency of data retrieval.
[0024] Step S12: Based on the data query requirement information, match the corresponding data fields and data tables from the preset database, and generate the target data query statement according to the data fields and data tables.
[0025] In this embodiment, as Figure 2 The SQL generation and optimization feature can match relevant data from a preset database based on data query requirements, and then generate corresponding query statements based on the matched data. Specifically, for example... Figure 3As shown, it's necessary to match the data query requirements with a preset database to determine the target data tables, target data fields, and the corresponding relationships between them. It's important to note that after establishing a connection with the preset database, it's necessary to collect the database's metadata, including table names, field names, field types, primary keys, foreign keys, indexes, and views. This metadata describes the overall structure and data organization of the database. Relational databases obtain table structure, field types, indexes, and foreign keys through metadata interfaces; non-relational databases traverse the collection structure of document-oriented databases like MongoDB to extract field distribution and data types. Then, based on the data query requirements, the database schema model is matched to determine the specific tables, fields involved in the query, and the relationships between them. For example, based on the entity information in the query statement, the corresponding tables and fields in the database are found, and it's determined how to obtain the required data through these tables and fields. Furthermore, schema information can be stored in a cache to support fast queries and updates, reduce redundant parsing overhead, and periodically scan the database to detect table structure changes, such as field additions or deletions, and automatically update the cache.
[0026] Furthermore, it is necessary to generate a query statement to be confirmed based on the target data table, target data fields, and target correspondences using preset database syntax rules. Specifically, an initial SQL statement can be generated according to the SQL syntax rules of the target database. For example, an SQL statement like "SELECT * FROM Product Table WHERE Sales Date BETWEEN [Start Date of the Past Month] AND [End Date of the Past Month] AND Sales Amount > 100000" needs to be generated. Then, a syntax check needs to be performed on the query statement to determine whether there are any syntax errors, thereby ensuring that the statement conforms to the syntax specifications of the target database and avoiding query failures due to syntax errors. If there are syntax errors in the query statement, it is corrected based on the syntax errors to obtain an optimized query statement. If there are no syntax errors in the query statement, it is used as the optimized query statement.
[0027] Finally, the query statement to be optimized can be optimized based on preset optimization rules to obtain the target query statement. These preset optimization rules include adding data indexes or splitting the query. Specifically, various optimization strategies can be used to optimize the generated SQL statement. For example, based on the index information provided by the database schema analysis module, appropriate index hints can be added to the query statement to enable the database to execute queries more efficiently. Complex query statements can be rewritten and decomposed into multiple simple subqueries to reduce the database's processing burden. Finally, the optimal join algorithm and execution plan can be selected based on the characteristics of the query conditions.
[0028] Step S13: Determine whether there is a preset interface in the preset interface set that corresponds to the interface requirement information.
[0029] In this embodiment, as Figure 3 As shown, it's necessary to determine whether a pre-defined interface corresponding to the interface requirement already exists in the pre-defined interface set based on the interface requirement information. For example, if the interface type corresponding to the query statement is RESTful API (Application Programming Interface) or SOAP (Simple Object Access Protocol), it's necessary to check whether these two types of interfaces already exist in the current pre-defined interface set. It should be noted that the pre-defined interface set can be used for interface management, including interface registration, publishing, and version control (e.g., coexistence of / api / v1 / query and / api / v2 / query), access permission settings, rate limiting strategies, caching strategies, and call monitoring. Through interface management, users can easily view and manage their owned interfaces, understand their usage and performance metrics, and system administrators can perform global management of all interfaces to ensure their security and stability. Full lifecycle management of interfaces is achieved through canary releases and interface retirement.
[0030] Step S14: If it does not exist, generate a target interface corresponding to the interface requirement information based on the preset interface template; if it exists, use the preset interface as the target interface.
[0031] In this embodiment, if there is no preset interface corresponding to the interface requirement information in the current preset interface set, it is necessary to generate an interface corresponding to the interface requirement information. Specifically, a target interface template corresponding to the interface type can be determined from the preset interface template set, and a target interface can be generated according to the target interface template, the interface parameters, and the data return format. That is, the interface code and documentation are generated using the template, and the generated interface code has good readability and maintainability, and the documentation can clearly describe the interface's functions, parameters, return values, and other information.
[0032] Step S15: Determine the target data source corresponding to the data query requirement information, and obtain the target query data corresponding to the data query requirement information from the target data source through the target interface based on the query parameters corresponding to the target data query statement.
[0033] In this embodiment, query data needs to be obtained from the target data source corresponding to the data query requirement information. Specifically, the target data source corresponding to the data query requirement information needs to be determined. It should be noted that these data sources can be different types of databases, such as relational databases like MySQL (My Structured Query Language) and Oracle, non-relational databases like MongoDB and Redis (Remote Dictionary Server), or other data storage formats such as file systems and API interfaces. Then, the target data query statement is executed in the preset database, and the corresponding execution result dataset is obtained. The execution result dataset is then iterated to extract the field values corresponding to the execution result dataset, and query parameters are generated based on the field values. Finally, the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameters corresponding to the target data query statement. Since the target query data may come from different data sources, the query results obtained from different data sources need to be integrated, the data format unified, and the issues of missing values and inconsistent types handled. Finally, the results are sorted, deduplicated, and paginated to generate the final query result set to meet the user's display requirements.
[0034] Furthermore, the interface can be optimized. Specifically, the response time of the target interface can be monitored. If the response time is greater than a preset response time threshold, the target interface can be optimized according to the preset interface optimization rules, and the optimized interface can be used as the new target interface. The preset interface optimization rules are rules for optimizing the query logic and interface code of the target interface.
[0035] In this embodiment, the received query statement can be analyzed to determine the data query requirement information and interface requirement information corresponding to the query statement; the query statement is natural language used for data query; based on the data query requirement information, corresponding data fields and data tables are matched from a preset database, and a target data query statement is generated according to the data fields and data tables; it is determined whether a preset interface corresponding to the interface requirement information exists in a preset interface set; if it does not exist, a target interface corresponding to the interface requirement information is generated based on a preset interface template; if it exists, the preset interface is used as the target interface; the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameters corresponding to the target data query statement. Therefore, the method in this embodiment can analyze query statements to determine corresponding data query requirements and interface requirements. Then, based on the data query requirements, it matches data fields and tables from a preset database and generates the corresponding target data query statement. It determines whether a preset interface corresponding to the interface requirements exists in the preset interface set. If not, it generates a target interface corresponding to the interface requirements based on a preset interface template. If it exists, it uses the preset interface as the target interface. Finally, it determines the target data source corresponding to the data query requirements and retrieves the target query data corresponding to the data query requirements from the target data source based on the query parameters corresponding to the target data query statement through the target interface. In this way, on the one hand, users lacking professional database knowledge can easily obtain the required data through natural language, thereby achieving efficient access and operation of multi-source heterogeneous databases; on the other hand, automated semantic understanding, SQL statement generation and optimization, and multi-source data integration functions reduce the time spent manually writing and debugging SQL statements, improving the efficiency and accuracy of data access; furthermore, it supports access to and integration of various types of data sources, adapting to complex heterogeneous data environments in enterprises, improving system compatibility and scalability, and shielding underlying differences.
[0036] As a preferred embodiment, to ensure data security, multiple security mechanisms can be used to ensure that only authorized users can access sensitive data and prevent security issues such as data leakage, tampering, unauthorized access, and malicious attacks. Specifically, user authentication can be performed before accessing the data access system. Multiple authentication methods can be employed, such as username / password authentication, digital certificate authentication, and multi-factor authentication, such as SMS verification codes and fingerprint recognition, to ensure the authenticity and legitimacy of the user's identity and reject unauthenticated requests. Furthermore, different data access permissions can be assigned to users based on their roles and responsibilities. Access management employs fine-grained control strategies, precise down to the table, field, and even data record level. For example, ordinary users can only query the business data they are responsible for, while administrator users can query and manage data across the entire system. Input parameter formats can also be validated, such as whether the date format is correct and whether the value is within a valid range, rejecting illegal parameters. SQL injection protection can also be implemented, for example, using prepared statements or regular expressions to filter dangerous characters, such as... , This system prevents the execution of malicious SQL code. It also performs data encryption, encrypting sensitive data during transmission and storage. Using symmetric or asymmetric encryption algorithms, it ensures data is not stolen or tampered with during transmission, and even if data is illegally accessed during storage, its content cannot be deciphered. Furthermore, it audits and monitors all user data access operations, recording the time, content, and results of each operation. Audit logs allow for the timely detection of abnormal behavior, tracing the source of data leaks, and providing evidence for security incident investigations. Finally, it sends alerts when unauthorized access is detected or system anomalies are discovered. This comprehensive security and access control module safeguards data security from multiple levels, including user authentication, access management, data encryption, and audit monitoring, effectively preventing data leaks and unauthorized access.
[0037] As a preferred embodiment, to improve the performance and response speed of the data access system, various performance indicators of the system can be monitored in real time, including query response time, system throughput, and resource utilization, such as processor utilization, memory utilization, and disk read / write status. Monitoring tools and data collectors are deployed in the system to collect this performance data and present it to the system administrator in the form of intuitive charts or reports. Performance anomalies are identified through threshold judgments, such as response time > 500ms, error rate > 5%, or machine learning algorithms, such as the Isolation Forest algorithm. Furthermore, performance bottlenecks can be analyzed based on the performance monitoring data. For example, if a query response time is found to be too long, the analysis can determine if the performance problem is caused by low SQL statement execution efficiency, unreasonable database indexes, network latency, or other reasons. Then, corresponding optimization strategies are formulated and implemented to address the identified performance problems. Optimization strategies may include adjusting database configuration parameters, optimizing SQL statements, adding caching mechanisms, and horizontally or vertically scaling the system. For example, frequently accessed data can be cached in memory to reduce direct database access; for situations with insufficient system resources, server hardware resources can be increased or a distributed architecture can be adopted for expansion. Ultimately, performance metrics before and after optimization can be compared to reassess the system's performance and verify the optimization effect. Based on the evaluation results, it can be determined whether further adjustments to the optimization strategy are needed to achieve continuous performance optimization of the system, and corresponding optimization reports, such as response time trend charts and throughput comparison tables, can be generated for operation and maintenance personnel to refer to. In this way, through real-time monitoring, bottleneck analysis, and the implementation of optimization strategies, it is possible to ensure that the system maintains good performance and response speed under high concurrency and large data volume conditions, thereby improving the user experience.
[0038] As a preferred embodiment, this embodiment will focus on Figure 2 The content is explained in detail, and specific application scenarios are discussed. Figure 3 The content will be explained in detail. For example, Figure 2As shown, after receiving the user's query, natural language processing (NLP) is required, such as stop word removal and part-of-speech tagging. Then, semantic understanding is needed to interpret the user's intent and semantic information, such as semantic relationships and logical relationships between entities. Further, database schema analysis is required; for example, based on the entity information in the query, the corresponding tables and fields in the database are located, and it is determined how to retrieve the required data using these tables and fields. Next, SQL statement generation is needed. An initial SQL statement can be generated according to the target database's SQL syntax rules, and then optimized to obtain the target data query statement. After the query statement is determined, multi-source data integration can be performed to handle query requests involving multiple data sources. Data from different data sources is integrated, and the optimized SQL statement is executed to obtain the corresponding query results. Finally, it is necessary to determine whether the required interface exists in the current preset interface set. If not, the required interface needs to be generated. Furthermore, to ensure data security, user access permissions and corresponding security measures are required to ensure that only authorized users can access sensitive data and prevent security issues such as data leakage, tampering, unauthorized access, and malicious attacks. Performance monitoring and optimization are also necessary, including real-time monitoring of various system performance indicators such as query response time, system throughput, and resource utilization (e.g., processor utilization, memory utilization, disk read / write activity). This allows for analysis of performance bottlenecks, and the development and implementation of corresponding optimization strategies to address identified performance problems. Finally, during API calls, the generated API and query parameters are used to retrieve the target query data from the target data source, matching the data query requirements.
[0039] Furthermore, taking a specific implementation scenario as an example, regarding... Figure 3 The content is explained in detail, with the specific scenarios as follows: MySQL: stores structured data such as orders and users; MongoDB: stores unstructured data such as product reviews; Elasticsearch: stores search index data. Business users need to retrieve cross-database data through natural language queries, for example: "Query the names and contact information of the top 10 customers in region C by order amount during month B of year A," and encapsulate the query into a reusable API interface for front-end applications to call. The natural language processing procedure is as follows: Word segmentation: "Year B Month Period", "Region C", "Order Amount", "Top 10", "Customer Name", "Contact Information"; Part-of-speech tagging: time words ("during year A and month B"), location words ("region C"), nouns ("order amount"), quantity words ("top 10"); Named entity recognition: Time entity ("Month B"), Location entity ("Region C"), Business entity ("Order Amount", "Customer Name"); Dependency syntax analysis: "query" is the core verb in the subject-predicate structure, "order amount" is the object, and "top 10" is an attributive modifying "customer name".
[0040] The semantic understanding process is as follows: Intent recognition: Aggregate query (filter + sort + TopN); Entity links: "Order Amount" → orders.amount field; "Customer Name" → customers.name field; "Contact Information" → customers.phone field; Relational reasoning: "B month" → orders.create_time BETWEEN 'A year-B month-01' AND 'A year-B month-30'; "C region" → orders.region = 'C'; "Top 10" → ORDER BY orders.amount DESC LIMIT10.
[0041] The database schema analysis process is as follows: Pattern discovery: The MySQL database contains two tables: orders and customers. The order table has the following structure: id, customer_id, amount, create_time, region. The customers table has the following structure: id, name, phone, email. Pattern association: Establish an association by using orders.customer_id = customers.id.
[0042] The SQL generation and optimization process is as follows: Initial SQL generation: Generates the corresponding SQL statement based on the semantic analysis results; Index analysis revealed that the orders table lacked a composite index of create_time and region. Query optimization: It is recommended to create a composite index: CREATE INDEX idx_time_region ON orders(create_time, region).
[0043] The process of multi-source data integration and query execution is as follows: Data source routing: Ensures all data resides in MySQL, eliminating the need for cross-source integration; Query execution: Executes the optimized SQL and returns a result set.
[0044] The process of generating and managing intelligent interfaces is as follows: API metadata retrieval: API name: get-top-customers-by-order-amount; Path: / api / v1 / orders / top-customers; Parameters: startDate, endDate, region; Return value: List<{name:string, phone: string}>; API code and documentation generation: Automatically generate API documentation, including API address, request method (GET / POST), parameter description (if any), and example of return results; Interface configuration: Permission policy: Only the "Data Analyst" role can call it. Caching policy: Result cached for 1 hour.
[0045] The security and access control process is as follows: Identity authentication: Verify the user's JWT token; Permission verification: Check if the user has the "Data Analyst" role; Parameter validation: Verify that startDate and endDate are valid date formats; verify that region is a predefined list of regions; SQL injection protection: Use prepared statements to automatically escape special characters.
[0046] The performance optimization process is as follows: Monitoring metrics: Average API response time: 200ms; Daily call count: 500 times; Cache hit rate: 30%; Optimization suggestions: Create a composite index idx_time_region for the orders table; adjust the caching strategy to extend the cache time for popular regions (such as "C region") to 2 hours.
[0047] See Figure 4 As shown, this embodiment of the invention discloses a data query device based on interface generation, comprising: The information determination module 11 is used to analyze the received query statement to determine the data query requirement information and interface requirement information corresponding to the query statement; the query statement is natural language used for data query. The query statement generation module 12 is used to match corresponding data fields and data tables from a preset database based on the data query requirement information, and generate a target data query statement based on the data fields and data tables. Interface matching module 13 is used to determine whether there is a preset interface in the preset interface set that corresponds to the interface requirement information; The interface determination module 14 is used to generate a target interface corresponding to the interface requirement information based on a preset interface template if the interface does not exist, and to use the preset interface as the target interface if the interface does exist. The data query module 15 is used to determine the target data source corresponding to the data query requirement information, and to obtain the target query data corresponding to the data query requirement information from the target data source through the target interface based on the query parameters corresponding to the target data query statement.
[0048] In this embodiment, the received query statement can be analyzed to determine the data query requirement information and interface requirement information corresponding to the query statement; the query statement is natural language used for data query; based on the data query requirement information, corresponding data fields and data tables are matched from a preset database, and a target data query statement is generated according to the data fields and data tables; it is determined whether a preset interface corresponding to the interface requirement information exists in a preset interface set; if it does not exist, a target interface corresponding to the interface requirement information is generated based on a preset interface template; if it exists, the preset interface is used as the target interface; the target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameters corresponding to the target data query statement. Therefore, the method in this embodiment can analyze query statements to determine corresponding data query requirements and interface requirements. Then, based on the data query requirements, it matches data fields and tables from a preset database and generates the corresponding target data query statement. It determines whether a preset interface corresponding to the interface requirements exists in the preset interface set. If not, it generates a target interface corresponding to the interface requirements based on a preset interface template. If it exists, it uses the preset interface as the target interface. Finally, it determines the target data source corresponding to the data query requirements and retrieves the target query data corresponding to the data query requirements from the target data source using the target interface and the query parameters corresponding to the target data query statement. This allows users lacking professional database knowledge to easily obtain the required data through natural language, thereby achieving efficient access and operation of multi-source heterogeneous databases, significantly improving the efficiency and accuracy of data queries, reducing data processing costs, enhancing system compatibility, ensuring data security, and providing solid support for enterprises and organizations in data-driven decision-making.
[0049] In some embodiments, the information determination module 11 may specifically include: The data removal submodule is used to identify stop words in the query statement and remove the stop words from the query statement to obtain the query statement after removal. The data annotation submodule is used to perform word segmentation on the removed query statement to obtain several query words, identify the parts of speech corresponding to the several query words, and then annotate the several query words according to the parts of speech to obtain annotated query words; The data recognition submodule is used to identify named entities in the labeled query terms and determine the syntactic relationships between the labeled query terms. The structure generation submodule is used to generate the target topology structure corresponding to the labeled query terms based on the named entities and the syntactic relationships. The structural analysis submodule is used to analyze the target topology to determine the data query requirements and interface requirements corresponding to the query statement.
[0050] In some embodiments, the structural analysis submodule may specifically include: The structural analysis unit is used to analyze the target topology using a preset model to identify the query intent corresponding to the query statement and generate data query requirement information based on the query intent. The information generation unit is used to determine the interface type corresponding to the query statement, the interface parameters corresponding to the interface type, and the data return format according to the query intent, and to generate interface requirement information according to the interface type, the interface parameters, and the data return format.
[0051] In some embodiments, the query statement generation module 12 may specifically include: The relationship determination unit is used to match the data query requirement information with a preset database to determine the target data table, target data field, and target correspondence between the target data table and the target data field in the preset database that correspond to the data query requirement information. The query statement generation unit is used to generate a data query statement to be confirmed based on the target data table, the target data fields, and the target correspondence according to preset database syntax rules. The syntax checking unit is used to perform a syntax check on the data query statement to be confirmed in order to determine whether there are any syntax errors in the data query statement to be confirmed. The syntax correction unit is used to correct the data query statement to be confirmed based on the syntax error if there is a syntax error in the data query statement to be confirmed, so as to obtain the data query statement to be optimized. The statement determination unit is used to determine the data query statement to be confirmed as the data query statement to be optimized if there is no syntax error in the data query statement to be confirmed. The statement optimization unit is used to optimize the data query statement to be optimized based on preset optimization rules to obtain the target data query statement; the preset optimization rules are to add a data index to the data query statement to be optimized or to split the query.
[0052] In some embodiments, the interface determination module 14 may specifically include: An interface generation unit is used to determine a target interface template corresponding to the interface type from a preset set of interface templates, and generate a target interface based on the target interface template, the interface parameters, and the data return format.
[0053] In some embodiments, the data query device based on the interface may further include: The set update unit is used to add the target interface to the preset interface set to update the preset interface set, and use the updated interface set as the new preset interface set.
[0054] In some embodiments, the data query module 15 may specifically include: A data source determination unit is used to determine the target data source corresponding to the data query requirement information; The statement execution unit is used to execute the target data query statement in the preset database and obtain the corresponding execution result dataset; The parameter generation unit is used to iterate through the execution result dataset to extract the field values corresponding to the execution result dataset and generate query parameters based on the field values. The data acquisition unit is used to acquire target query data corresponding to the data query requirement information from the target data source through the target interface based on the query parameters corresponding to the target data query statement.
[0055] In some embodiments, the data query device based on the interface may further include: An interface optimization unit is used to monitor the response time of the target interface. If the response time is greater than a preset response time threshold, the target interface is optimized according to a preset interface optimization rule, and the optimized interface is used as the new target interface. The preset interface optimization rule is a rule for optimizing the query logic and interface code of the target interface.
[0056] Furthermore, embodiments of this application also disclose an electronic device, Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0057] Figure 5This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the interface-based data query method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0058] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0059] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0060] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the interface-based data query method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.
[0061] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned data query method based on interface generation. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0062] 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 it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0063] 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.
[0064] 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.
[0065] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0066] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A data query method based on interface generation, characterized in that, include: The received query statement is analyzed to determine the data query requirement information and interface requirement information corresponding to the query statement; The query statement is in natural language used for data retrieval; Based on the data query requirement information, the corresponding data fields and data tables are matched from the preset database, and the target data query statement is generated according to the data fields and data tables; Determine whether a preset interface corresponding to the interface requirement information exists in the preset interface set; If it does not exist, a target interface corresponding to the interface requirement information is generated based on the preset interface template; if it exists, the preset interface is used as the target interface. The target data source corresponding to the data query requirement information is determined, and the target query data corresponding to the data query requirement information is obtained from the target data source through the target interface based on the query parameters corresponding to the target data query statement.
2. The data query method based on interface generation according to claim 1, characterized in that, The process of analyzing the received query statement to determine the corresponding data query requirement information and interface requirement information includes: Identify stop words in the query statement and remove the stop words from the query statement to obtain the query statement after removal; The removed query statement is segmented to obtain several query terms, and the parts of speech corresponding to the several query terms are identified. Then, the several query terms are labeled according to the parts of speech to obtain labeled query terms. Identify named entities in the tagged query terms and determine the syntactic relationships between the tagged query terms; Generate the target topology structure corresponding to the tagged query terms based on the named entities and the syntactic relationships; The target topology is analyzed to determine the data query requirements and interface requirements corresponding to the query statement.
3. The data query method based on interface generation according to claim 2, characterized in that, The analysis of the target topology to determine the corresponding data query requirements and interface requirements of the query statement includes: The target topology is analyzed using a preset model to identify the query intent corresponding to the query statement, and data query requirement information is generated based on the query intent. Based on the query intent, determine the interface type corresponding to the query statement, the interface parameters corresponding to the interface type, and the data return format, and generate interface requirement information based on the interface type, the interface parameters, and the data return format.
4. The data query method based on interface generation according to claim 1, characterized in that, The step of matching corresponding data fields and data tables from a preset database based on the data query requirement information, and generating a target data query statement based on the data fields and data tables, includes: By matching the data query requirement information with a preset database, the target data table, target data field, and target correspondence between the target data table and the target data field in the preset database are determined. A data query statement to be confirmed is generated based on the target data table, the target data fields, and the target correspondence using preset database syntax rules. A syntax check is performed on the query statement to be confirmed to determine whether there are any syntax errors in the query statement. If there is a syntax error in the data query statement to be confirmed, the data query statement to be confirmed is corrected based on the syntax error to obtain the data query statement to be optimized. If there are no syntax errors in the data query statement to be confirmed, then the data query statement to be confirmed will be used as the data query statement to be optimized. The data query statement to be optimized is optimized based on preset optimization rules to obtain the target data query statement; the preset optimization rules are to add a data index to the data query statement to be optimized or to split the query.
5. The data query method based on interface generation according to claim 3, characterized in that, The step of generating a target interface corresponding to the interface requirement information based on a preset interface template includes: Determine the target interface template corresponding to the interface type from the preset interface template set, and generate the target interface based on the target interface template, the interface parameters, and the data return format; Accordingly, the method further includes: The target interface is added to the preset interface set to update the preset interface set, and the updated interface set is used as the new preset interface set.
6. The data query method based on interface generation according to claim 1, characterized in that, The step of determining the target data source corresponding to the data query requirement information, and obtaining the target query data corresponding to the data query requirement information from the target data source through the target interface based on the query parameters corresponding to the target data query statement, includes: Determine the target data source corresponding to the data query requirement information; The target data query statement is executed in the preset database, and the corresponding execution result dataset is obtained; The execution result dataset is iterated through in a loop to extract the field values corresponding to the execution result dataset, and query parameters are generated based on the field values. The target interface retrieves target query data corresponding to the data query requirement information from the target data source based on the query parameters corresponding to the target data query statement.
7. The data query method based on interface generation according to any one of claims 1 to 6, characterized in that, Also includes: Monitor the response time of the target interface. If the response time is greater than a preset response time threshold, optimize the target interface according to the preset interface optimization rules, and use the optimized interface as the new target interface. The preset interface optimization rules are rules for optimizing the query logic and interface code of the target interface.
8. A data query device based on interface generation, characterized in that, include: The information determination module is used to analyze the received query statement to determine the data query requirement information and interface requirement information corresponding to the query statement; The query statement is in natural language used for data retrieval; The query statement generation module is used to match corresponding data fields and data tables from a preset database based on the data query requirement information, and generate a target data query statement based on the data fields and data tables. An interface matching module is used to determine whether there is a preset interface in a preset interface set that corresponds to the interface requirement information. An interface determination module is used to generate a target interface corresponding to the interface requirement information based on a preset interface template if the interface does not exist; if the interface does exist, the preset interface is used as the target interface. The data query module is used to determine the target data source corresponding to the data query requirement information, and to obtain the target query data corresponding to the data query requirement information from the target data source based on the query parameters corresponding to the target data query statement through the target interface.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the interface-based data query method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store a computer program, wherein the computer program, when executed by a processor, implements the data query method based on interface generation as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Method and system for database query
CN102737049A
Database query method and device, equipment and storage medium
CN119557329A
Query method based on query auxiliary information
CN120045582A
Data query method and device, computer equipment and storage medium
CN120216555A
Query statement conversion method and device based on large model, equipment and medium
CN120578683A