Self-adaptive chart automatic generation method and device based on MCP

By leveraging MCP technology to achieve natural language intent parsing and intelligent matching of multi-function tools, the complexity of data visualization processes and the rigidity of charts are resolved, generating high-quality interactive charts and improving the efficiency and scalability of data insights.

CN122045482APending Publication Date: 2026-05-15E SURFING IOT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
E SURFING IOT CO LTD
Filing Date
2026-01-30
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

In existing technologies, data visualization processes rely on users to have certain data analysis and chart design capabilities, which are complex and have a high barrier to entry. Users cannot understand complex natural language intent, function tool calls are isolated, lack unified context management, make it difficult to support complex analysis tasks, and chart type selection is rigid. There is also a lack of data quality assessment, which affects the accuracy of the charts.

Method used

The system introduces MCP to achieve natural language intent parsing, intelligent matching of multi-function tools, data quality scoring, and adaptive selection of chart types. Interactive charts are generated through the semantic intent parsing module, function tool registry center, and rendering engine.

Benefits of technology

It enables users to generate high-quality visualizations without needing data analysis skills, improving data insight efficiency, supporting complex analysis tasks, adaptive chart selection, reliable data quality assessment, strong scalability, and highly interpretable output.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122045482A_ABST
    Figure CN122045482A_ABST
Patent Text Reader

Abstract

The invention relates to a self-adaptive chart automatic generation method and device based on an MCP, and belongs to the technical field of chart automatic generation. The method comprises the steps that a natural language query request input by a user is received, and the natural language query request is preprocessed; obtaining a structured intention object comprising a user intention semantic tag; loading a complete description of a function from a function tool registration center, screening out a candidate function set, and obtaining original data; respectively calculating the integrity, consistency, rationality and timeliness of the original data, performing four-dimensional weighting to obtain a quality score of the original data, and judging the size of the quality score of the original data and a preset quality score; when the judgment result is that the quality score is greater than the preset quality score, calculating an original data trend, a cardinal number and structural complexity respectively to obtain a visual matching degree; calculating final scores of the charts, and selecting the chart type with the highest final score as a selected chart type; and calling a rendering engine, and generating the interactive chart based on the selected chart type and the cleaned original data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of automatic chart generation technology, and particularly relates to an adaptive automatic chart generation method and apparatus based on MCP. Background Technology

[0002] With the advent of the big data era, data visualization, as an important tool for data analysis and decision support, has been widely applied in various fields such as business intelligence, scientific research analysis, and government regulation. Traditional data visualization processes typically rely on users to have certain data analysis and chart design capabilities, involving multiple steps such as data extraction, cleaning, modeling, chart selection, and rendering, which are complex and have a high barrier to entry.

[0003] In recent years, although there has been research on natural language to SQL or natural language to API (NL2API), the following shortcomings exist: 1. Limited intent parsing capability: Most systems rely on keyword matching or fixed templates, making it difficult to understand complex, ambiguous, or multi-turn natural language intents, leading to query failures or result deviations.

[0004] 2. Isolated function tool calls: Some systems often separate data query, processing, visualization and other steps, lacking a unified context management mechanism, resulting in a lack of coordination between function calls and making it difficult to support complex multi-step analysis tasks.

[0005] 3. Poor scalability: Existing solutions rely on specific data sources or closed ecosystems, making it difficult to flexibly integrate third-party function tools or adapt to different business scenarios, thus limiting the portability and scalability of the system.

[0006] 4. Rigid chart type selection: Unable to adaptively select visualization charts based on data characteristics.

[0007] 5. Lack of data quality assessment mechanism: In the automatically generated visualization process, data quality issues (such as missing values, outliers, and poor timeliness) are often overlooked, which directly affects the accuracy and credibility of the charts.

[0008] Against this backdrop, there is an urgent need for a visualization solution that can understand natural language intent, intelligently schedule multiple types of function tools, dynamically evaluate data quality, and adaptively select chart types. Summary of the Invention

[0009] In view of the shortcomings of the existing technology, the purpose of the invention is to provide an adaptive chart automatic generation method and device based on MCP. By introducing MCP, natural language intent parsing, intelligent matching of multi-function tools, data quality scoring, adaptive selection of chart type and automatic generation of visualization results are realized, thereby reducing the user threshold and improving the efficiency of data insight.

[0010] In a first aspect, the present invention proposes an adaptive chart automatic generation method based on MCP, comprising: Receive a natural language query request input by the user and preprocess the natural language query request; The preprocessed natural language query request is input into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain a structured intent object including user intent semantic tags; The complete description of the function is loaded from the function tool registry. Based on the MCP matching of the user intent semantic tags in the core semantic elements and the function semantic tags in the complete description of the function, a set of candidate functions is selected. The comprehensive similarity between the structured intent object and each function in the set of candidate functions is calculated. The raw data is then called in batches and obtained in order of the comprehensive similarity score. The completeness, consistency, reasonableness, and timeliness of the original data are calculated separately. The quality score of the original data is obtained by weighting the four dimensions of completeness, consistency, reasonableness, and timeliness. The size of the quality score of the original data is then compared with the preset quality score. When the judgment result is that the quality score of the original data is greater than or equal to the preset quality score, the trend, cardinality and structural complexity of the original data are calculated respectively, and the visualization matching degree is calculated based on the trend, cardinality and structural complexity of the original data. The final score of the chart is calculated based on the visual matching degree, the triggering conditions of each chart type, and the base score. The chart type with the highest final score is selected as the selected chart type. The rendering engine is invoked to generate interactive charts based on the selected chart type and the cleaned raw data.

[0011] A second aspect of the present invention also proposes an adaptive chart automatic generation device based on MCP, comprising: Receiving module: Used to receive natural language query requests input by the user and preprocess the natural language query requests; The parsing module is used to input the preprocessed natural language query request into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain a structured intent object including user intent semantic tags; Matching module: Used to load the complete description of a function from the function tool registry. Based on MCP matching, it selects a set of candidate functions by matching the user intent semantic tags in the core semantic elements and the function semantic tags in the complete description of the function. It calculates the comprehensive similarity between the structured intent object and each function in the set of candidate functions, and calls and retrieves the raw data in batches according to the score of the comprehensive similarity. The first calculation module is used to calculate the completeness, consistency, reasonableness, and timeliness of the original data respectively, and to obtain the quality score of the original data by weighting the completeness, consistency, reasonableness, and timeliness of the original data in four dimensions, and to determine the size of the quality score of the original data compared with the preset quality score. The second calculation module is used to calculate the trend, cardinality, and structural complexity of the original data when the judgment result is that the quality score of the original data is greater than or equal to the preset quality score, and to calculate the visualization matching degree based on the trend, cardinality, and structural complexity of the original data. The third calculation module is used to calculate the final score of a chart based on the visualization matching degree, the triggering conditions of each chart type, and the base score, and select the chart type with the highest final score as the selected chart type. Rendering module: Used to call the rendering engine to generate interactive charts based on the selected chart type and the cleaned raw data.

[0012] A third aspect of the present invention also provides an electronic device comprising: a processor and a memory; The processor executes any of the above-mentioned adaptive graph automatic generation methods based on MCP by calling programs or instructions stored in memory.

[0013] In a fourth aspect, the present invention also provides a computer-readable storage medium storing a program or instructions that cause a computer to execute any of the above-mentioned MCP-based adaptive chart automatic generation methods.

[0014] The beneficial effects of this invention are as follows: 1. Intent-driven unified scheduling: Based on MCP, unstructured natural language intents are transformed into structured contexts that can drive the collaborative work of heterogeneous tools, realizing the connection from "semantic understanding" to "physical invocation".

[0015] 2. Data quality quantitative assessment model: Introducing a four-dimensional quality scoring and business weight adjustment mechanism to ensure the reliability of visualization results.

[0016] 3. Intelligent Chart Recommendation: Based on trends, cardinality, and structural complexity, the visualization matching degree S is calculated to achieve adaptive matching of chart types.

[0017] 4. High scalability: The loosely coupled design based on MCP allows for easy registration and integration of new functions, new data sources, and new chart types, enabling rapid adaptation to different business domains and complex analysis needs, such as expanding from gas to electricity and water.

[0018] 5. Low barrier to entry and improved efficiency: Users do not need to master any query language or data analysis skills. They can obtain high-quality visual analysis results through natural language, which greatly improves the efficiency and accessibility of data insights.

[0019] 6. High interpretability: The output includes data sources, quality scores, and reasons for recommendation, enhancing user trust. Attached Figure Description

[0020] The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Throughout the drawings, the same reference numerals denote the same parts. It is obvious that the drawings described below are merely some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings.

[0021] Figure 1 A schematic diagram of an adaptive chart automatic generation method based on MCP provided in an embodiment of the present invention; Figure 2 This is a schematic diagram illustrating a method for obtaining a structured intent object according to an embodiment of the present invention; Figure 3 This is a schematic diagram of a method for filtering a set of candidate functions according to an embodiment of the present invention; Figure 4 A schematic diagram of an adaptive chart automatic generation device based on MCP provided in an embodiment of the present invention; Figure 5 This is a schematic block diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0022] To enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions 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, not all embodiments. It should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0023] Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concepts disclosed in this invention.

[0024] In the description of this invention, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. The terms "installed," "connected," and "linked" should be interpreted broadly; for example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art will understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0025] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of methods and systems consistent with some aspects of the invention as detailed in the appended claims.

[0026] This invention proposes an adaptive chart automatic generation method and device based on MCP. Through multi-agent collaborative analysis and multi-tool enhanced analysis, it introduces MCP to realize natural language intent parsing, intelligent matching of multi-function tools, data quality scoring, adaptive selection of chart type, and automatic generation of visualization results, thereby reducing the user threshold and improving the efficiency of data insight.

[0027] Before introducing the embodiments of the present invention, the technical terms involved in the present invention will be introduced first.

[0028] MCP (Model Context Protocol) is a unified context description protocol for the interaction of large models with external tools, data, and knowledge sources.

[0029] Method Implementation Examples In a first aspect, this invention proposes an adaptive chart automatic generation method based on MCP, combining... Figure 1 It includes seven steps, S1 to S7: S1: Receives natural language query requests from users and preprocesses the natural language query requests.

[0030] Specifically, in this embodiment of the invention, the means of preprocessing natural language query requests are to remove special characters, segment long sentences, etc., to improve the accuracy and robustness of semantic parsing; for example: the natural language query request input by the user is: query the monthly gas consumption of gas user A in the first half of this year, and the natural language query request input by the user is processed by removing special characters, segmenting long sentences, etc.

[0031] S2: Input the preprocessed natural language query request into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain a structured intent object including user intent semantic tags.

[0032] Specifically, in this embodiment of the invention, the monthly gas consumption of gas user A in the first half of this year is input into the semantic intent parsing module for deep semantic parsing and structured parsing. The parsing result is represented by a structured intent object in JSON format. The specific parsing method is described in detail below.

[0033] S3: Load the complete description of the function from the function tool registry, match the user intent semantic tags in the core semantic elements and the function semantic tags in the complete description of the function based on MCP, filter out the candidate function set, calculate the comprehensive similarity between the structured intent object and each function in the candidate function set, and call and obtain the raw data in batches according to the comprehensive similarity score.

[0034] Specifically, in this embodiment of the invention, the method of loading the complete description of a function from the function tool registry and filtering the candidate function set based on the user intent semantic tags in the core semantic elements of MCP matching and the function semantic tags in the complete function description is described in detail below. Batch calls support multi-function combined calls. For example, although the tag of query_gas_usage is clearly defined in the user intent semantic tags and can be called directly, best practice suggests that the user validity should be verified before querying. Therefore, the call chain from validate_user to query_gas_usage is automatically constructed. Taking the query of the monthly gas consumption of user A001 in the first half of this year and comparing it with the gas consumption in the same period last year as an example, MCP_Context loads the user intent and the function from the function tool registry. Among them, the tag ["gas_consumption", "time_series"] of the function query_gas_usage is highly matched with the user intent semantic tags, and it is identified that I.operations contains comparison, which requires two sets of data. The call chain is automatically constructed. 1) Call validate_user(A001) to verify user validity; 2) Parallel call query_gas_usage(A001, 2024-01-01, 2024-12-31, "month") to retrieve last year's data D1; 3) Parallel call query_gas_usage(A001, 2023-01-01, 2023-12-31, "month") to retrieve the previous year's data D2; 4) Store D1, D2 and the comparison relationship into MCP_Context.

[0035] In some embodiments, the inputs, outputs, and states of the called functions are also recorded in the order of execution, forming a traceable decision chain.

[0036] S4: Calculate the completeness, consistency, reasonableness, and timeliness of the original data respectively. Calculate the quality score of the original data by weighting the four dimensions of completeness, consistency, reasonableness, and timeliness. Determine the size of the quality score of the original data compared with the preset quality score.

[0037] Specifically, in this embodiment of the invention, the integrity, consistency, rationality, and timeliness of the original data are calculated respectively. The method for obtaining the quality score of the original data by weighting the integrity, consistency, rationality, and timeliness of the original data in four dimensions is described in detail below. After obtaining the quality score of the original data, the size of the quality score of the original data is determined with respect to the preset quality score. The size of the preset quality score is flexibly set according to the actual situation, such as 0.6, 0.8, etc.

[0038] S5: When the judgment result is that the quality score of the original data is greater than or equal to the preset quality score, calculate the trend, cardinality and structural complexity of the original data respectively, and calculate the visualization matching degree based on the trend, cardinality and structural complexity of the original data.

[0039] Specifically, in this embodiment of the invention, for example: when the judgment result is that the quality score of the original data is greater than or equal to the preset quality score of 0.6, the trend, cardinality and structural complexity of the original data are calculated respectively, and the visualization matching degree is calculated based on the trend, cardinality and structural complexity of the original data. The specific calculation method is described in detail below.

[0040] S6: Calculate the final score of the chart based on the visualization matching degree, the triggering conditions of each chart type, and the base score, and select the chart type with the highest final score as the selected chart type.

[0041] Specifically, in this embodiment of the invention, the final score of the chart is calculated based on the visual matching degree, the triggering conditions of each chart type, and the base score. For example, the line chart has the highest score, and the line chart is the selected chart type.

[0042] In some embodiments, when the difference between the final scores of the Top 1 and Top 2 charts is less than 0.05, a dual scheme is provided. For example, if the final scores of the line chart and the area chart are in the Top 1 and Top 2, and the difference between the Top 1 and Top 2 scores is less than 0.05, then both the line chart and the area chart are selected chart types.

[0043] S7: Calls the rendering engine to generate an interactive chart based on the selected chart type and the cleaned raw data.

[0044] Specifically, in this embodiment of the invention, the ECharts visualization rendering engine is invoked to generate a visualization chart based on the line chart and the cleaned data.

[0045] Furthermore, in the aforementioned adaptive chart automatic generation method based on MCP, the preprocessed natural language query request is input into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain a structured intent object including user intent semantic tags, combined with... Figure 2 It includes four steps, S21 to S24: S21: Input the preprocessed natural language query request into the fine-tuning model based on LLaMA-3-Chinese-8B.

[0046] Specifically, in this embodiment of the invention, for example, the monthly gas consumption of gas user A in the first half of this year is input into a fine-tuning model based on LLaMA-3-Chinese-8B. Here, the fine-tuning model based on LLaMA-3-Chinese-8B is a language model that has been fine-tuned with gas business work order data and professional terminology. It should be understood that the business work order data and professional terminology here are adaptively adjusted according to different natural language query requests.

[0047] S22: Use the constructed domain corpus to pre-train the fine-tuning model, and then use natural language query requests and structured intent object pairing data to perform supervised fine-tuning on the pre-trained fine-tuning model.

[0048] Specifically, in this embodiment of the invention, for example, a fine-tuning model is pre-trained using a constructed gas domain corpus. In this stage, the fine-tuning model learns the general associations of concepts such as gas users and gas consumption in the context. It should be understood that the domain adaptively adjusts according to different natural language query requests. The pre-trained fine-tuning model is then supervised and fine-tuned using natural language query requests and structured intent object pairing data.

[0049] S23: The supervised fine-tuning model identifies the core semantic elements in natural language query requests through an integrated domain entity recognition module, transforms the ambiguous time descriptions in the core semantic elements into absolute time ranges and aggregation granularities for machine processing, and triggers a multi-round interactive clarification mechanism when key parameters are missing or semantically ambiguous.

[0050] Specifically, in this embodiment of the invention, the supervised fine-tuning model accurately identifies the core semantic elements in the query statement through an integrated domain entity recognition module. These elements include the subject, such as gas user A; entity identifiers, such as name or account number; indicator fields, such as gas consumption and the default aggregation method sum; time range, such as the first half of this year; aggregation dimension, such as monthly; and analysis operations, such as comparison, sort, and filter. The model transforms the ambiguous time descriptions in the core semantic elements into absolute time ranges and aggregation granularities for machine processing. For example, it converts the description of the first half of this year into a start date of 2025-01-01 and an end date of 2025-06-30, with the aggregation granularity set to monthly. When it identifies missing key parameters or semantic ambiguity in the parsing results, such as when a user only inputs the gas consumption of user A without specifying a time range, a multi-round interactive clarification mechanism is automatically triggered.

[0051] S24: After completing deep semantic parsing and structured parsing, a set of user intent semantic tags is automatically generated based on the parsed complete semantic elements and dialogue context.

[0052] Specifically, in this embodiment of the invention, automatically generating a set of user intent semantic tags can be based on basic element tagging and business scenario identification tagging. Basic element tagging first extracts core elements from the parsed structured fields and maps them to a predefined atomic tag library. For example, `metrics.alias: “gas_consumption”` in the structured intent matches the tag `[“gas_consumption”]`. Business scenario identification tagging combines basic elements to identify higher-level business scenarios or query patterns. For example: “gas_consumption” + “monthly” + single user matching [“time_series”] tag; “gas_consumption”+“comparison”+multiple time period matching [“trend_analysis”] tag.

[0053] For example, the monthly gas consumption of user A001 in the first half of this year can be queried and compared with the gas consumption in the same period last year. The data is then input into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain the parsing results. The parsing results are represented as a structured intent object in JSON format.

[0054] { "intent_id": "a1b2c3d4", / / Unique session identifier "data_subject": "Gas User", / / Data Subject "identifier": { / / Identifier "type": "Account Number", "value": "A001" }, "metrics": [ / / List of metric fields] { "name": "Gas Consumption", "alias": "gas_consumption", "aggregation": "sum" / / Aggregation method (sum, avg, max, min, etc.) } ], "time_range": { / / Time range "start": "2025-01-01", "end": "2025-06-30", "granularity": "month" / / Granularity (day, week, month, year) }, "dimensions": [], / / Grouping / dimension field (empty in this example) "operations": [ / / List of identified operations] { "type": "comparison", "target": { / / Target to compare "time_range": { "start": "2024-01-01", "end": "2024-06-30", "granularity": "month } } } ], "implicit_context": { / / Context for implicit completion "default_time_range": "last_30_days", "user_type": "Resident" }, "semantic_tags": ["gas_consumption", "time_series", "monthly"] / / tags }

[0055] Furthermore, in the aforementioned adaptive chart automatic generation method based on MCP, the complete description of the function is loaded from the function tool registry. Based on MCP matching, the user intent semantic tags in the core semantic elements and the function semantic tags in the complete function description are used to filter out a set of candidate functions. Figure 3 It includes three steps, S31 to S33: S31: Load the function name, function description, parameter pattern, return type, and key semantic tag set from the function utility registry.

[0056] Specifically, in this embodiment of the invention, the function tool registry center manages all available data services and computing resources in a unified manner using a standardized metadata format. Each function tool is registered in accordance with the JSON Schema specification, clearly describing its functions, parameter types, return values, and other metadata to ensure that it can be discovered, understood, and invoked. For example, the gas consumption query function query_gas_usage will be tagged with labels such as ["gas_consumption", "time_series", "utility_query"] to provide a basis for matching.

[0057] For example: The function name is query_gas_usage, which queries the gas consumption of a specified gas user within a given time range. The input parameters are user ID, start time, end time, and aggregation granularity. The returned data is a JSON array containing the date and gas consumption, and the semantic tags are ["gas_consumption", "time_series", "utility_query"]. The function name is get_user_info, which retrieves basic user information. The input parameter is user ID, and the returned data is a user information object, and the semantic tags are ["user_profile", "metadata"]. The function name is validate_user, which verifies whether a user ID exists. The input parameter is user ID, and the returned data is a boolean value, and the semantic tags are ["validation", "entity_check"].

[0058] S32: Based on MCP, perform semantic similarity matching between the semantic tags of user intent and the set of key semantic tags of functions.

[0059] Specifically, in this embodiment of the invention, semantic similarity matching is performed between the semantic tags of user intent and the semantic tags of functions based on MCP. For example, querying gas usage will successfully match the semantic tag gas_consumption of the query_gas_usage function.

[0060] S33: Add functions that match semantic similarity to the candidate function set.

[0061] For example: a query using gas volume will successfully match the semantic tag gas_consumption of the query_gas_usage function, and the gas_consumption function will be added to the candidate function set.

[0062] Furthermore, in the aforementioned adaptive chart automatic generation method based on MCP, the completeness, consistency, reasonableness, and timeliness of the original data are calculated respectively. A quality score for the original data is obtained by weighting these four dimensions, including: Based on the temporal granularity and scope of the query intent, the semantic matching degree between the expected data point distribution and the actual returned distribution is calculated to obtain completeness. .

[0063] Specifically, in the embodiments of the present invention, integrity Calculated using the following formula: in, This refers to the set of expected semantic time units parsed from the query intent, such as the past 30 calendar days or 30 hourly times. For the semantic units covered by the actual returned data, This weight represents the business importance weight for time unit t. The weighting of queries is determined by user type (e.g., residential / industrial), query scenario (e.g., billing settlement, trend query), and whether key events are included (e.g., maintenance days, holidays). For example, if a user queries their daily gas consumption over the past 30 days, theoretically 30 records should be returned. If only 27 records are returned, the completeness is questionable. The value is 0.9, where I represents an indicator function used to determine whether a certain time unit exists in the actual returned data. Its value is either 0 or 1. If the expected time unit t exists in the actual returned data... If the value is 1, and the expected time unit t is in the actual returned data The value 0 does not exist in the range.

[0064] Based on autocorrelation analysis and anomaly pattern detection, the continuity of time series is determined, and the presence of abrupt gaps or out-of-order sequences is examined to ensure consistency. .

[0065] Specifically, in the embodiments of the present invention, consistency Calculated using the following formula: in, It is a lightweight time series model trained on real-world data. To adjust the parameters, a value of 2.6 is set so that when the prediction error of the lightweight time series model is greater than 20% in the expected time range, the consistency Q2 is less than 0.6, triggering the degradation or repair process.

[0066] Outlier detection based on Gaussian mixture model and isolated forest determines whether the original values ​​are within a reasonable range. .

[0067] Specifically, in this embodiment of the invention, for example, a negative gas consumption value or a daily gas consumption exceeding the upper limit is considered an unqualified record, and its reasonableness is questionable. This represents the percentage of qualified records out of the total number of records.

[0068] Timeliness is determined by calculating whether the original data covers the requested time range. .

[0069] Specifically, in the embodiments of the present invention, timeliness Calculated using the following formula: in, The number of days is the lag. To request the latest date, For the latest date of the data, For the business half-life, τ is set to 1 day for residential users and 4 hours for industrial users.

[0070] The formula for calculating the quality score of raw data by weighting it according to four dimensions—completeness, consistency, reasonableness, and timeliness—is as follows: , , and These represent the weights for the completeness, consistency, reasonableness, and timeliness of the original data, respectively, and are dynamically adjusted based on the query intent type. This indicates the quality score of the original data.

[0071] Furthermore, the aforementioned adaptive chart automatic generation method based on MCP also includes: When the judgment result is that the quality score of the original data is less than the preset quality score, the original data repair strategy or downgrade processing is triggered.

[0072] Specifically, in this embodiment of the invention, data repair strategies are triggered, such as interpolation and prompting the user that data is missing; downgrade processing is performed, such as shortening the time range. The preset quality score is flexibly set by the user according to the actual situation. For example, if the quality score of the original data is less than 0.6, the original data repair strategy or downgrade processing is triggered.

[0073] Furthermore, in the aforementioned adaptive chart automatic generation method based on MCP, the original data trend, cardinality, and structural complexity are calculated respectively, and the visualization matching degree is calculated based on the original data trend, cardinality, and structural complexity, including: The statistic for the time series y is calculated using the following formula. : When there are identical values ​​in a sequence of ordinal numbers, the variance is calculated using the following formula. : The standardized statistic is calculated from the statistic and variance using the following formula. : In the Mann-Kendall trend test, when the significance level α is set to 0.05 (for a two-tailed test), the critical value of the test statistic Z is ±1.96. When |Z|>1.96, Trend=1 indicates a significant trend in the original data; when |Z|<=1.96, Trend=0 indicates no significant trend in the original data, meaning the original data is non-time-series data. Let represent the sample size, and g represent groups of the same value with length t. The number of observations with the same value within this group This represents the j-th value in a time series, such as the gas consumption in the j-th month. This represents the i-th value in a time series, such as the gas consumption in the i-th month. i represents the position of an earlier data point in the time series, and j represents the position of a later data point in the time series. cardinality Calculated using the following formula: U represents the number of unique values, and n represents the total number of data points. ≤0.3 indicates a low cardinality. Values ​​between 0.3 and 0.7 represent medium-sized numbers. >0.7 indicates a high cardinality.

[0074] For example: A user's daily gas consumption for 12 months in 2024 is: [38.7, 38.7, 39.0, 39.0, 39.0, 45.2, 45.2, 45.2, 45.2, 72.3, 72.3, 38.7], with the unique value being {38.7, 39.0, 45.2, 72.3}. The base value is calculated from this. The base value is 0.33, which is considered a low to medium base. Its values ​​have high repetition, and the trend line is smooth. A line chart to display seasonal peaks is preferred. If daily usage is almost entirely different, for example, 365 different values ​​over 365 days, the base value should be calculated accordingly. If the value is 1, it is considered a high base, and a scatter plot combined with a LOESS curve or bar chart may be used for sampling and display.

[0075] Structural complexity is based on a base score of 0. If there is a grouping field, add one point; if there are multiple indicator columns, add one point; if comparative analysis is required, add one point. It is obtained by normalizing to the [0,1] interval. The formula for calculating the visualization matching degree based on the original data trend, cardinality, and structural complexity is as follows: Where A represents the visual matching degree, Indicates the trend of the original data. Represents the cardinality. Indicates structural complexity.

[0076] Furthermore, in the aforementioned adaptive chart automatic generation method based on MCP, the final chart score is calculated using the following formula based on visualization matching degree, triggering conditions for various chart types, and base score: F = 0.6 × base score for each chart type + 0.4 × A Where F represents the final score of the chart, and A represents the visualization matching degree. The trigger condition for a line chart is Trend=1 and Card≤0.7, with a base score of 0.9; the trigger condition for an area chart is Trend=1 and the cumulative effect needs to be emphasized, with a base score of 0.85; the trigger condition for a bar chart is categorized data and Card>0.3, with a base score of 0.8; the trigger condition for a grouped bar is the presence of a grouping field, with a base score of 0.82; the trigger condition for a stacked bar is the need to display the composition, with a base score of 0.78; the trigger condition for a pie chart is ≤7 categories and the percentage is displayed, with a base score of 0.75; the trigger condition for a radar chart is multiple indicators ≥3 and comparison is required, with a base score of 0.7; the trigger condition for a scatter plot is two continuous variables, with a base score of 0.65; Trend represents the original data trend, and Card represents the cardinality.

[0077] Specifically, in this embodiment of the invention, the final score of the chart is obtained by substituting the visual matching degree, the triggering conditions of various chart types, and the specific values ​​of the base score.

[0078] Device Examples In a second aspect, the present invention also proposes an adaptive chart automatic generation device based on MCP, combined with Figure 4 ,include: Receiving module 41: Used to receive natural language query requests input by the user and preprocess the natural language query requests.

[0079] Specifically, in this embodiment of the invention, the means of preprocessing the natural language query request are to remove special characters, segment long sentences, etc. The receiving module 41 receives the natural language query request input by the user and preprocesses the natural language query request to improve the accuracy and robustness of semantic parsing. For example, the natural language query request input by the user is: query the monthly gas consumption of gas user A in the first half of this year. The natural language query request input by the user is processed by removing special characters, segmenting long sentences, etc.

[0080] Parsing module 42: This module takes the preprocessed natural language query request and inputs it into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain a structured intent object that includes the user's intent semantic tags.

[0081] Specifically, in this embodiment of the invention, if the monthly gas consumption of user A001 in the first half of this year is compared with the gas consumption in the same period last year and input into the parsing module 42 of the semantic intent parsing module for deep semantic parsing and structured parsing, the following parsing result is obtained. The parsing result is represented by a structured intent object in JSON format.

[0082] Matching Module 43: Used to load the complete description of a function from the function tool registry. Based on the user intent semantic tags in the core semantic elements of MCP matching and the function semantic tags in the complete description of the function, it filters out a set of candidate functions, calculates the comprehensive similarity between the structured intent object and each function in the set of candidate functions, and calls and retrieves the raw data in batches according to the score of the comprehensive similarity.

[0083] Specifically, in this embodiment of the invention, the matching module 43 loads the complete description of the function from the function tool registry, selects a set of candidate functions based on the user intent semantic tags in the core semantic elements of MCP matching and the function semantic tags in the complete description of the function, calculates the comprehensive similarity between the structured intent object and each function in the set of candidate functions, and calls and obtains the original data in batches according to the score order of the comprehensive similarity.

[0084] First calculation module 44: used to calculate the completeness, consistency, rationality and timeliness of the original data respectively, to obtain the quality score of the original data by weighting the completeness, consistency, rationality and timeliness of the original data in four dimensions, and to judge the size of the quality score of the original data with the preset quality score.

[0085] Specifically, in this embodiment of the invention, the first calculation module 44 calculates the integrity, consistency, rationality, and timeliness of the original data respectively. The method for obtaining the quality score of the original data by weighting the integrity, consistency, rationality, and timeliness of the original data in four dimensions is described in detail below. After obtaining the quality score of the original data, the size of the quality score of the original data is determined with respect to the preset quality score. The size of the preset quality score is flexibly set according to the actual situation, such as 0.6, 0.8, etc.

[0086] The second calculation module 45 is used to calculate the original data trend, cardinality, and structural complexity when the judgment result is that the quality score of the original data is greater than the preset quality score, and to calculate the visualization matching degree based on the original data trend, cardinality, and structural complexity.

[0087] Specifically, in this embodiment of the invention, for example: when the judgment result is that the quality score of the original data is greater than or equal to the preset quality score of 0.6, the second calculation module 45 calculates the trend, cardinality and structural complexity of the original data respectively, and calculates the visualization matching degree based on the trend, cardinality and structural complexity of the original data.

[0088] The third calculation module 46 is used to calculate the final score of the chart based on the visualization matching degree, the triggering conditions of each chart type and the base score, and select the chart type with the highest final score as the selected chart type.

[0089] Specifically, in this embodiment of the invention, the third calculation module 46 calculates the final score of the chart based on the visual matching degree, the triggering conditions of each chart type, and the base score. For example, the line chart has the highest score, and the line chart is the selected chart type.

[0090] In some embodiments, when the difference between the final scores of the Top 1 and Top 2 charts is less than 0.05, a dual scheme is provided. For example, if the final scores of the line chart and the area chart are in the Top 1 and Top 2, and the difference between the Top 1 and Top 2 scores is less than 0.05, then both the line chart and the area chart are selected chart types.

[0091] Rendering module 47: Used to call the rendering engine to generate interactive charts based on the selected chart type and the cleaned raw data.

[0092] Specifically, in this embodiment of the invention, the rendering module 47 calls the visualization rendering engine ECharts to generate a visualization chart based on the line chart and the cleaned data.

[0093] A third aspect of the present invention also provides an electronic device comprising: a processor and a memory; The processor executes any of the above-mentioned adaptive graph automatic generation methods based on MCP by calling programs or instructions stored in memory.

[0094] In a fourth aspect, the present invention also provides a computer-readable storage medium storing a program or instructions that cause a computer to execute any of the above-mentioned MCP-based adaptive chart automatic generation methods.

[0095] Figure 5 This is a schematic block diagram of an electronic device provided in an embodiment of the present invention.

[0096] like Figure 5 As shown, the electronic device includes at least one processor 501, at least one memory 502, and at least one communication interface 503. The various components in the electronic device are coupled together via a bus system 504. The communication interface 503 is used for information transmission with external devices. It is understood that the bus system 504 is used to implement communication between these components. In addition to a data bus, the bus system 504 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 5 The general designated all buses as Bus System 504.

[0097] It is understood that the memory 502 in this embodiment can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory.

[0098] In some implementations, memory 502 stores elements such as executable units or data structures, or subsets thereof, or extended sets thereof: operating systems and applications.

[0099] The operating system includes various system programs, such as the framework layer, core library layer, and driver layer, used to implement various basic business functions and handle hardware-based tasks. The application programs include various applications, such as media players and browsers, used to implement various application functions. A program implementing any method in the MCP-based adaptive chart automatic generation method provided in this embodiment of the invention can be included in the application programs.

[0100] In this embodiment of the invention, the processor 501 executes the steps of various embodiments of the adaptive chart automatic generation method based on MCP provided by the present invention by calling the program or instructions stored in the memory 502, specifically, the program or instructions stored in the application.

[0101] Receive a natural language query request input by the user and preprocess the natural language query request; The preprocessed natural language query request is input into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain a structured intent object including user intent semantic tags; The complete description of the function is loaded from the function tool registry. Based on the MCP matching of the user intent semantic tags in the core semantic elements and the function semantic tags in the complete description of the function, a set of candidate functions is selected. The comprehensive similarity between the structured intent object and each function in the set of candidate functions is calculated. The raw data is then called in batches and obtained in order of the comprehensive similarity score. The completeness, consistency, reasonableness, and timeliness of the original data are calculated separately. The quality score of the original data is obtained by weighting the four dimensions of completeness, consistency, reasonableness, and timeliness. The size of the quality score of the original data is then compared with the preset quality score. When the judgment result is that the quality score of the original data is greater than the preset quality score, the trend, cardinality and structural complexity of the original data are calculated respectively, and the visualization matching degree is calculated based on the trend, cardinality and structural complexity of the original data. The final score of the chart is calculated based on the visual matching degree, the triggering conditions of each chart type, and the base score. The chart type with the highest final score is selected as the selected chart type. The rendering engine is invoked to generate interactive charts based on the selected chart type and the cleaned raw data.

[0102] Any method in the MCP-based adaptive graph automatic generation method provided in this embodiment of the invention can be applied to or implemented by the processor 501. The processor 501 can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of the processor 501 or by instructions in software form. The processor 501 can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor can be a microprocessor or any conventional processor.

[0103] In the MCP-based adaptive graph automatic generation method provided by this invention, any step of the method can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software units in the decoding processor. The software units can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory 502, and processor 501 reads the information in memory 502 and combines it with hardware to complete the steps of the method.

[0104] Those skilled in the art will understand that although some embodiments described herein include certain features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the invention and form different embodiments.

[0105] Those skilled in the art will understand that the descriptions of the various embodiments have different focuses, and for parts not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0106] Although embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention. All such modifications and variations fall within the scope defined by the appended claims. The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

[0107] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. An adaptive chart automatic generation method based on MCP, characterized in that, include: Receive a natural language query request input by the user and preprocess the natural language query request; The preprocessed natural language query request is input into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain a structured intent object including user intent semantic tags; The complete description of the function is loaded from the function tool registry. Based on the MCP matching of the user intent semantic tags in the core semantic elements and the function semantic tags in the complete description of the function, a set of candidate functions is selected. The comprehensive similarity between the structured intent object and each function in the set of candidate functions is calculated. The raw data is then called in batches and obtained in order of the comprehensive similarity score. The completeness, consistency, reasonableness, and timeliness of the original data are calculated separately. The quality score of the original data is obtained by weighting the four dimensions of completeness, consistency, reasonableness, and timeliness. The size of the quality score of the original data is then compared with the preset quality score. When the judgment result is that the quality score of the original data is greater than or equal to the preset quality score, the trend, cardinality and structural complexity of the original data are calculated respectively, and the visualization matching degree is calculated based on the trend, cardinality and structural complexity of the original data. The final score of the chart is calculated based on the visual matching degree, the triggering conditions of each chart type, and the base score. The chart type with the highest final score is selected as the selected chart type. The rendering engine is invoked to generate interactive charts based on the selected chart type and the cleaned raw data.

2. The adaptive chart automatic generation method based on MCP according to claim 1, characterized in that, The preprocessed natural language query request is input into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain a structured intent object including user intent semantic tags, including: The preprocessed natural language query request is input into the fine-tuning model based on LLaMA-3-Chinese-8B; The model was pre-trained and fine-tuned using a constructed domain corpus, and then the pre-trained fine-tuned model was supervised and fine-tuned using natural language query requests and structured intent object pairing data. The supervised fine-tuning model identifies the core semantic elements in natural language query requests through an integrated domain entity recognition module, transforms the ambiguous time descriptions in the core semantic elements into absolute time ranges and aggregation granularities for machine processing, and triggers a multi-round interactive clarification mechanism when key parameters are missing or semantically ambiguous. After completing deep semantic parsing and structured parsing, a set of user intent semantic tags is automatically generated based on the parsed complete semantic elements and dialogue context; The core semantic elements include at least: subject, entity identifier, indicator field, time range, aggregation dimension, and analysis operation.

3. The adaptive chart automatic generation method based on MCP according to claim 1, characterized in that, The complete description of a function is loaded from the function registry. Based on the user intent semantic tags in the core semantic elements of the MCP matching and the function semantic tags in the complete function description, a set of candidate functions is selected, including: Load the function's name, function description, parameter pattern, return type, and key semantic tag set from the function utility registry; Based on MCP, semantic similarity matching is performed between the semantic tags of user intent and the set of key semantic tags of functions; Functions that match semantic similarity are added to the candidate function set.

4. The adaptive chart automatic generation method based on MCP according to claim 1, characterized in that, The completeness, consistency, reasonableness, and timeliness of the original data are calculated separately. A quality score for the original data is obtained by weighting these four dimensions, including: Based on the temporal granularity and scope of the query intent, the semantic matching degree between the expected data point distribution and the actual returned distribution is calculated to obtain completeness. ; Based on autocorrelation analysis and anomaly pattern detection, the continuity of time series is determined, and the presence of abrupt gaps or out-of-order sequences is examined to ensure consistency. ; Outlier detection based on Gaussian mixture model and isolated forest determines whether the original values ​​are within a reasonable range. ; Timeliness is determined by calculating whether the original data covers the requested time range. ; The formula for calculating the quality score of raw data by weighting it according to four dimensions—completeness, consistency, reasonableness, and timeliness—is as follows: , , and These represent the weights for the completeness, consistency, reasonableness, and timeliness of the original data, respectively, and are dynamically adjusted based on the query intent type. This indicates the quality score of the original data.

5. The adaptive chart automatic generation method based on MCP according to claim 1, characterized in that, The method further includes: When the judgment result is that the quality score of the original data is less than the preset quality score, the original data repair strategy or downgrade processing is triggered.

6. The adaptive chart automatic generation method based on MCP according to claim 1, characterized in that, Calculate the original data trend, cardinality, and structural complexity separately. Based on the original data trend, cardinality, and structural complexity, calculate the visualization matching degree, including: The statistic for the time series y is calculated using the following formula. : When there are identical values ​​in a sequence of ordinal numbers, the variance is calculated using the following formula. : The standardized statistic is calculated from the statistic and variance using the following formula. : When |Z|>1.96, Trend=1 indicates a significant trend in the original data; when |Z|<=1.96, Trend=0 indicates no significant trend in the original data. Let represent the sample size, and g represent groups of the same value with length t. The number of observations with the same value within this group This represents the j-th value in the time series. This represents the i-th value in the time series; cardinality Calculated using the following formula: U represents the number of unique values, and n represents the total number of data points. ≤0.3 indicates a low cardinality. Values ​​between 0.3 and 0.7 represent medium-sized numbers. >0.7 indicates a high cardinality; Structural complexity is based on a base score of 0. If there is a grouping field, add one point; if there are multiple indicator columns, add one point; if comparative analysis is required, add one point. It is obtained by normalizing to the [0,1] interval. The formula for calculating the visualization matching degree based on the original data trend, cardinality, and structural complexity is expressed as follows: Where A represents the visual matching degree, Indicates the trend of the original data. Represents the cardinality. Indicates structural complexity.

7. The adaptive chart automatic generation method based on MCP according to claim 1, characterized in that, The final score for a chart is calculated using the following formula, based on visualization matching, triggering conditions for various chart types, and a base score: F = 0.6 × base score for each chart type + 0.4 × A Where F represents the final score of the chart, and A represents the visualization matching degree. The trigger condition for a line chart is Trend=1 and Card≤0.7, with a base score of 0.9; the trigger condition for an area chart is Trend=1 and the cumulative effect needs to be emphasized, with a base score of 0.85; the trigger condition for a bar chart is categorized data and Card>0.3, with a base score of 0.8; the trigger condition for a grouped bar is the presence of a grouping field, with a base score of 0.82; the trigger condition for a stacked bar is the need to display the composition, with a base score of 0.78; the trigger condition for a pie chart is ≤7 categories and the percentage is displayed, with a base score of 0.75; the trigger condition for a radar chart is multiple indicators ≥3 and comparison is required, with a base score of 0.7; the trigger condition for a scatter plot is two continuous variables, with a base score of 0.65; Trend represents the original data trend, and Card represents the cardinality.

8. An adaptive chart automatic generation device based on MCP, characterized in that, include: Receiving module: Used to receive natural language query requests input by the user and preprocess the natural language query requests; The parsing module is used to input the preprocessed natural language query request into the semantic intent parsing module for deep semantic parsing and structured parsing to obtain a structured intent object including user intent semantic tags; Matching module: Used to load the complete description of a function from the function tool registry. Based on MCP matching, it selects a set of candidate functions by matching the user intent semantic tags in the core semantic elements and the function semantic tags in the complete description of the function. It calculates the comprehensive similarity between the structured intent object and each function in the set of candidate functions, and calls and retrieves the raw data in batches according to the score of the comprehensive similarity. The first calculation module is used to calculate the completeness, consistency, reasonableness, and timeliness of the original data respectively, and to obtain the quality score of the original data by weighting the completeness, consistency, reasonableness, and timeliness of the original data in four dimensions, and to determine the size of the quality score of the original data compared with the preset quality score. The second calculation module is used to calculate the trend, cardinality, and structural complexity of the original data when the judgment result is that the quality score of the original data is greater than or equal to the preset quality score, and to calculate the visualization matching degree based on the trend, cardinality, and structural complexity of the original data. The third calculation module is used to calculate the final score of a chart based on the visualization matching degree, the triggering conditions for each chart type, and the base score, and select the chart type with the highest final score as the selected chart type. Rendering module: Used to call the rendering engine to generate interactive charts based on the selected chart type and the cleaned raw data.

9. An electronic device, characterized in that, include: Processor and memory; The processor executes the adaptive chart automatic generation method based on MCP as described in any one of claims 1 to 7 by calling the program or instructions stored in the memory.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a program or instructions that cause a computer to execute the MCP-based adaptive chart automatic generation method as described in any one of claims 1 to 7.