Railway cargo report data query method, computer equipment, readable storage medium and program product
By receiving natural language query text and generating query statements in a structured query language database or freight knowledge base, the problems of technical dependence and response lag in traditional railway freight report data query methods are solved, enabling fast and flexible data query and analysis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-24
- Publication Date
- 2026-04-07
AI Technical Summary
Traditional railway freight data query methods rely on professional technicians to write SQL statements, which cannot meet the needs of business personnel to independently adjust query conditions and respond quickly. This results in slow query response, insufficient analytical flexibility, and difficulty in meeting the needs of real-time decision-making.
A method for querying railway freight report data is provided. By receiving natural language query text, the method first retrieves matching target query language data in a structured query language database. If no match is found, the method obtains target freight knowledge from a freight knowledge base, generates a target query statement, and runs it in the railway freight report database to obtain query results.
It enables business personnel to perform data queries without needing to master complex query languages, significantly reducing technical barriers and time costs, improving query response speed and analytical flexibility, and meeting the diverse needs of real-time business decision-making.
Smart Images

Figure CN121807884A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of railway freight technology, and in particular to a method for querying railway freight report data, computer equipment, computer-readable storage medium, and computer program product. Background Technology
[0002] With the continuous expansion of railway freight business and the in-depth advancement of information technology construction, freight report data has shown a rapid growth trend in both volume and generation speed, and the business departments' demand for real-time data query and flexible analysis has become increasingly prominent.
[0003] Traditional methods of querying cargo report data mainly rely on professional technicians to write specific SQL (Structured Query Language) statements and present the data based on pre-designed fixed report formats (such as daily reports, monthly reports, etc.) or statistical algorithms.
[0004] In this model, business personnel lack the technical skills to independently adjust query conditions or analysis dimensions. When faced with new business needs, they must wait for technical personnel to write new query statements. This process is time-consuming, cannot adapt to rapidly changing business scenarios, and results in slow query response, insufficient analytical flexibility, and difficulty in meeting the needs of real-time decision-making. Summary of the Invention
[0005] Therefore, it is necessary to provide a railway freight report data query method, computer equipment, computer-readable storage medium, and computer program product that can improve the flexibility of railway freight report data query in response to the above-mentioned technical problems.
[0006] Firstly, this application provides a method for querying railway freight report data, including:
[0007] Receive natural language query text for the railway freight report database;
[0008] If target query language data matching the natural language query text is retrieved from a pre-defined structured query language database, a target query statement is generated based on the target query language data and the natural language query text.
[0009] If no target query language data matching the natural language query text is found in the preset structured query language database, target freight knowledge matching the natural language query text is obtained from the preset freight knowledge base, and a target query statement is generated based on the target freight knowledge and the natural language query text.
[0010] Run the target query statement in the railway freight report database to obtain the query results corresponding to the natural language query text.
[0011] Secondly, this application also provides a railway freight report data query device, comprising:
[0012] The receiving module is used to receive natural language query text for the railway freight report database;
[0013] The first generation module is used to generate a target query statement based on the target query language data and the natural language query text when the target query language data that matches the natural language query text is retrieved from the preset structured query language database.
[0014] The second generation module is used to obtain target freight knowledge that matches the natural language query text from a preset freight knowledge base when no target query language data matching the natural language query text is retrieved from the preset structured query language database, and to generate a target query statement based on the target freight knowledge and the natural language query text.
[0015] The query module is used to run target query statements in the railway freight report database and obtain query results corresponding to natural language query text.
[0016] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0017] Receive natural language query text for the railway freight report database;
[0018] If target query language data matching the natural language query text is retrieved from a pre-defined structured query language database, a target query statement is generated based on the target query language data and the natural language query text.
[0019] If no target query language data matching the natural language query text is found in the preset structured query language database, target freight knowledge matching the natural language query text is obtained from the preset freight knowledge base, and a target query statement is generated based on the target freight knowledge and the natural language query text.
[0020] Run the target query statement in the railway freight report database to obtain the query results corresponding to the natural language query text.
[0021] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0022] Receive natural language query text for the railway freight report database;
[0023] If target query language data matching the natural language query text is retrieved from a pre-defined structured query language database, a target query statement is generated based on the target query language data and the natural language query text.
[0024] If no target query language data matching the natural language query text is found in the preset structured query language database, target freight knowledge matching the natural language query text is obtained from the preset freight knowledge base, and a target query statement is generated based on the target freight knowledge and the natural language query text.
[0025] Run the target query statement in the railway freight report database to obtain the query results corresponding to the natural language query text.
[0026] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0027] Receive natural language query text for the railway freight report database;
[0028] If target query language data matching the natural language query text is retrieved from a pre-defined structured query language database, a target query statement is generated based on the target query language data and the natural language query text.
[0029] If no target query language data matching the natural language query text is found in the preset structured query language database, target freight knowledge matching the natural language query text is obtained from the preset freight knowledge base, and a target query statement is generated based on the target freight knowledge and the natural language query text.
[0030] Run the target query statement in the railway freight report database to obtain the query results corresponding to the natural language query text.
[0031] The aforementioned railway freight report data query method, computer equipment, computer-readable storage medium, and computer program product first receive natural language query text input by the user for railway freight report data, and then search in a pre-set structured query language database. If target query language data matching the natural language query text is found, an executable target query statement for the freight report database is directly generated based on the retrieved target query language data and the natural language query text. If no target query language data matching the natural language query text is found, the system extracts target freight knowledge matching the natural language query text from a pre-set freight knowledge base, and then combines the target freight knowledge with the natural language text to construct the target query statement. In this way, business personnel do not need to master complex query language writing knowledge, nor do they need to rely on and wait for technical personnel to develop it; they can initiate queries using only natural language. The system automatically completes the entire process from retrieval, selection of generation criteria to construction of an executable query statement, and runs the query statement in the railway freight report database to return the results. This process enables the automatic conversion from natural language intent to structured queries, significantly reducing the technical threshold and time cost of data querying, greatly improving the speed of query response and the flexibility of business analysis, and enabling timely fulfillment of the diverse and real-time needs of business decision-making for data queries. Attached Figure Description
[0032] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0033] Figure 1 This is a flowchart illustrating a railway freight report data query method in one embodiment of this application;
[0034] Figure 2 This is a flowchart illustrating the process of retrieving target query language data in one embodiment of this application;
[0035] Figure 3 This is a flowchart illustrating the process of storing new query language data in a structured query language database in one embodiment of this application;
[0036] Figure 4 This is a structural block diagram of a railway freight report data query device in one embodiment of this application;
[0037] Figure 5 This is an internal structural diagram of a computer device in one embodiment of this application. Detailed Implementation
[0038] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0039] With the continuous development of railway freight business, freight reporting data has shown explosive growth. Railway freight reporting data covers massive amounts of information such as freight volume, receipt volume, transportation routes, transportation time, cargo type, and vehicle scheduling. This data is of vital importance for railway freight operation decisions, efficiency improvement, cost control, and service optimization.
[0040] Currently, railway freight departments have an increasingly urgent need for querying and analyzing freight report data. Traditionally, business personnel and analysts rely on professional data teams to obtain data by writing complex SQL queries and manually designing statistical algorithms. This only enables simple query functions covering fixed reports and lacks statistical and comparative analysis capabilities. This process involves high technical barriers, long response times, and cannot meet the needs of real-time and flexible decision-making.
[0041] The traditional data querying method relies on reporting systems where the IT (Information Technology) department pre-develops a series of static reports (such as daily, monthly, and annual reports) based on fixed requirements from business departments. Business personnel can only view these pre-formatted reports and cannot perform flexible, ad-hoc, personalized queries.
[0042] Relying on Business Intelligence (BI) tools (such as Tableau and Power BI) for data querying, IT departments typically build a data warehouse or data lake to extract, transform, and load multi-source data and establish data models. Business users then generate visual charts on the BI tool by dragging and dropping dimensions and measure fields. While this provides a degree of flexibility, users still need some data knowledge, an understanding of table structures and relationships, and proficiency in using the BI tool.
[0043] In terms of technology, traditional freight data query and analysis systems suffer from prominent problems such as poor flexibility, slow response, high barriers to entry, and data silos. Traditional reporting systems struggle to support temporary or complex query needs; any changes require redevelopment by the IT department, resulting in long development cycles, slow response times, and an inability to adapt to real-time decision-making scenarios. Furthermore, even relatively flexible BI tools demand high levels of data literacy and operational skills from users, often proving difficult for non-technical personnel to master, creating a technical barrier. In addition, existing systems generally lack the ability to effectively integrate with external data (such as weather and economic policies), making it difficult to support cross-source, in-depth correlation analysis and limiting the full exploitation of data value.
[0044] In terms of efficiency, the current cargo report data query process suffers from bottlenecks such as low human-computer interaction efficiency and a lengthy decision-making chain. From the time business personnel raise a question to the final analysis results, it requires multiple steps, including "problem conception - technical transformation (such as writing SQL or operating BI tools) - execution of operations - result interpretation," making the process cumbersome and time-consuming. When business personnel encounter ad-hoc decision-making needs, they cannot independently and quickly verify hypotheses and must rely on the intervention of data analysts or technical teams, resulting in a passive extension of the decision-making cycle and potentially missing market opportunities or the best scheduling window.
[0045] In terms of cost, the existing data-driven model for shipment reporting results in consistently high labor and maintenance costs. Enterprises need to maintain dedicated data analysis teams to respond to business department inquiries and invest significant resources in system development, report maintenance, and iterative upgrades. This highly manpower-dependent model not only drives up operating costs but also hinders scalable efficiency improvements, thus limiting enterprises' sustainable investment and innovation capabilities in data-driven decision-making.
[0046] In one exemplary embodiment, such as Figure 1 As shown, a method for querying railway freight report data is provided. This embodiment illustrates the application of this method to a terminal, where the terminal can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, projection devices, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc. Head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. It is understood that this method can also be applied to a server, and can also be applied to a system including a terminal and a server, and implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps 102-108. Wherein:
[0047] Step 102: Receive the natural language query text for the railway freight report database.
[0048] Natural language query text refers to query requests written by business personnel using everyday business language rather than a specific programming language. For example, a business person entering "Query the amount of coal shipped from Beijing to Shanghai yesterday" or "What is the cumulative loading volume of the No. 1 silo at Bulian Tower today?" would be a natural language query text.
[0049] The railway freight report database can refer to a database system that stores railway freight report data, which may include, but is not limited to, cargo type, shipment volume, receipt volume, loading location, transportation route, unloading location, and transportation time.
[0050] For example, a business user enters a natural language query text in an input box on a front-end interface (such as a web page, mobile application interface, or chatbot interface) based on their desired query or requirement. The terminal receives the natural language query text through a corresponding interface.
[0051] Step 104: If target query language data matching the natural language query text is retrieved from the preset structured query language database, a target query statement is generated based on the target query language data and the natural language query text.
[0052] The Structured Query Language (SCL) database can refer to a pre-established database that stores multiple SCL data records, each containing at least an SQL statement template. The specific parameter values in the SQL statement template can be null or historical values; this embodiment does not impose any restrictions on this.
[0053] Structured Query Language databases can be built before practical applications.
[0054] As an example, to build a structured query language database, we can first systematically identify typical analytical scenarios in the railway freight sector, such as transportation timeliness analysis, cargo type statistics, and route capacity assessment. For each scenario, we can further refine specific analytical dimensions (such as time, station, cargo type, etc.) and pre-set a batch of corresponding common business questions for each dimension. Subsequently, we can configure corresponding query language data for each pre-set question. Query language data is a structured data unit, the content of which may include, but is not limited to, SQL statement templates, slot keywords, and table field mappings. Slot keywords can refer to parameter markers that need to be dynamically filled in the question and SQL template, such as start time, end time, cargo type, etc. Table field mappings can specify the specific table name and field name corresponding to each slot keyword in the railway freight report database, for example, mapping the slot [cargo type] to the category code field under the cargo information table.
[0055] The construction of query language data can adopt multiple paths, including but not limited to manual construction, generation based on historical logs, and generation by artificial intelligence models.
[0056] Through the above methods, a structured query language database covering common business intentions and containing complete mapping relationships can be systematically constructed, providing core support for the accurate matching and statement generation of natural language queries.
[0057] For example, collect the following original data:
[0058] Question: What is the cumulative loading volume of the No. 1 silo site in Bulianta on the current day?
[0059] Slot keywords: site, date range, count type 1.
[0060] Table field mapping: loading location, operation date, load.
[0061] SQL statement template: SELECT SUM(`weight_charge`) / 10000 AS "total_loading_weight" FROM `odm_logistics_goods_report2` WHERE `site_load` LIKE '%Bulianta No. 1 silo%' AND `report_time` = DATE_FORMAT(NOW(),'%Y-%m-%d').
[0062] Subsequently, the original data is organized into a query language data record according to the structure of the structured query language database.
[0063] The target query language data can refer to the data record in the structured query language database that matches the currently received natural language query text in semantics or intention.
[0064] Exemplarily, after receiving the natural language query text, the natural language query text can be matched with each query language data in the preset structured query language database. The matching process can be achieved by means such as keyword extraction and semantic similarity calculation. If the target query language data that matches the natural language query text can be retrieved from the preset structured query language database, then the target query statement is generated based on the retrieved target query language data and the specific parameter values (such as time, location, goods type, etc.) extracted from the natural language query text.
[0065] In some feasible embodiments, in order to improve matching accuracy and query efficiency, the natural language query text can be first semantically normalized and rewritten to obtain the rewritten text, and then the rewritten text can be matched with the query language data in the preset structured query language database.
[0066] As an example, the rewriting process may include: segmenting and tagging the natural language query text to identify key business entities such as time, location, cargo type, and quantity; then, applying a thesaurus and a business term mapping table to convert non-standard expressions into standard business terms in the railway freight field, such as converting "yesterday" into a specific date format, standardizing "coal" to "coal," and converting "early ear" to "Guangzhou"; next, eliminating ambiguous expressions in the text through syntactic analysis and reconstructing complex sentences into standard query sentences, such as rewriting "all goods shipped from Beijing to Shanghai last month except for electronic products" into "querying all cargo reports with a time range of last month, a dispatch station of Beijing, a destination station of Shanghai, and a cargo type not equal to electronic products"; in addition, the rewritten text can be vectorized to extract key dimensions and metrics, generating a structured representation of query intent.
[0067] In some feasible embodiments, a context-aware mechanism can be introduced during the rewriting process. By acquiring and analyzing contextual query information, the content that may be omitted, referred to, or implied in the current natural language query text can be supplemented, thereby forming a standardized query expression with more complete semantics and clearer description.
[0068] Contextual query information may include, but is not limited to, session history and user profile or preference information. Session history can refer to queries previously submitted by the same user in the current session and the system's returned results. For example, if a user previously searched for "show the shipment volume of Station A this month" and then entered "what about Station B?", the system can use the historical context to complete the current query as "show the shipment volume of Station B this month". User profile or preference information may include the user's business role, frequently used query dimensions, and scope of responsibility. For example, if the current user is identified as a "dispatcher at Station A", when the user enters "today's loading status", the query can be automatically completed as "today's loading status at Station A".
[0069] As an example, the terminal can input both contextual query information and natural language query text into the rewriting module. The rewriting module can use an artificial intelligence model based on attention mechanisms, memory networks, etc., to identify the contextual references, omissions, or context-dependent parts in the natural language query text, extract relevant contextual elements from the contextual query information, and fuse them with the natural language query text to generate a complete rewritten text.
[0070] After rewriting, the generated standardized rewritten text is compared with the query language data in the pre-set structured query language database for similarity calculation or pattern matching. This approach effectively eliminates noise caused by differences in user expression, aligning the query intent with the pre-set patterns in the database at a more standardized and essential level, thereby significantly improving the retrieval hit rate and matching accuracy of the target query language data.
[0071] Step 106: If no target query language data matching the natural language query text is retrieved from the preset structured query language database, target freight knowledge matching the natural language query text is obtained from the preset freight knowledge base, and a target query statement is generated based on the target freight knowledge and the natural language query text.
[0072] The pre-built freight knowledge base refers to a database specifically constructed for freight knowledge in the railway freight sector. Freight knowledge may include, but is not limited to, freight terminology information, business indicator definitions, database table structure information, and freight report knowledge graphs. Freight terminology information may include professional terms used in railway freight operations and their explanations, which may include abbreviations, specific expressions, and their business meanings. Business indicator definitions may refer to the quantitative standards used in freight operations to measure operational status, efficiency, or quality, and their calculation rules. Database table structure information may refer to the logical and physical design information of various data tables in the railway freight report database, including table names, field names, field types, field meanings, and inter-table relationships.
[0073] A freight knowledge graph can refer to a knowledge system in the freight domain organized in the form of a graph structure. In this graph structure, nodes represent entities (such as stations, freight types, and transport indicators), edges represent relationships between entities (such as freight originating from a station, and transport indicators corresponding to freight), and attribute-value pairs attached to nodes represent specific attributes of the entities (such as the name of the freight, the station code, and the definition of the indicator). Knowledge graphs help to better understand the semantic relationships in user queries and improve the accuracy of semantic understanding.
[0074] In some feasible implementations, freight knowledge can be vectorized into text using a semantic encoding model fine-tuned based on freight domain data (such as BERT (Bidirectional Encoder Representations from Transformers)). The resulting freight knowledge vectors are then stored in a freight knowledge base. When no matching target query language data is found, the similarity between the vector of the query text and the knowledge vectors in the freight knowledge base can be calculated to quickly retrieve and extract the target freight knowledge most relevant to the current query intent.
[0075] Target freight knowledge can refer to domain knowledge fragments retrieved from the aforementioned freight knowledge base that are related to the content of the current natural language query text.
[0076] For example, if target query language data matching the natural language query text cannot be retrieved from the preset structured query language database, relevant target freight knowledge is extracted from the freight knowledge base using keywords in the natural language query text or through semantic analysis, and then a target query statement is generated based on the target freight knowledge and the natural language query text.
[0077] In some feasible implementations, the target query can be automatically generated by a large query model that is pre-trained on a large-scale text and code corpus and fine-tuned using historical freight data.
[0078] As an example, a large query model can be a large language model based on the Transformer architecture, capable of mapping natural language descriptions to SQL statements. In the pre-training phase, the model first undergoes self-supervised pre-training on massive amounts of general text corpora and program code (especially SQL code). Through this process, the model learns rich linguistic rules, basic world knowledge, code syntax structure, and the potential correspondence between natural language and code, thus possessing powerful general understanding and generation capabilities. In the fine-tuning phase, to specifically adapt the model to the task of querying railway freight report data, historical freight report query data can be used to construct domain-specific training samples for supervised fine-tuning of the pre-trained model. Through fine-tuning, the model can deeply understand the professional terminology, business logic, and specific table structure, field semantics, and query patterns of the freight report database, thereby significantly improving its accuracy and reliability in generating accurate and executable SQL statements in the target domain.
[0079] In some feasible embodiments, generating a target query statement based on the target query language data and natural language query text may include: constructing prompt words based on the target query language data and natural language query text, inputting the prompt words into a large query statement model, and generating the target query statement through the large query statement model.
[0080] In some feasible embodiments, generating a target query statement based on target freight knowledge and natural language query text may include: constructing prompt words based on target freight knowledge and natural language query text, inputting the prompt words into a query statement big model, and generating the target query statement through the query statement big model.
[0081] Step 108: Run the target query statement in the railway freight report database to obtain the query results corresponding to the natural language query text.
[0082] For example, after generating the target query statement, it can be submitted to the railway freight report database as a database query command through the database connection interface. The railway freight report database management system parses and executes the target query statement, performing at least one operation such as retrieval, calculation, and aggregation on its stored data, and returns the dataset that meets the conditions as the query result to the terminal. After receiving the query result, the terminal can also perform necessary formatting processing (such as converting data types, adding table headers, etc.), and finally display it through the front-end interface in the form of natural language, tables, or charts.
[0083] In some feasible implementations, users can choose how the query results are displayed through the front-end display interface according to their needs, thereby improving the user experience.
[0084] The aforementioned railway freight report data query method first receives the natural language query text input by the user for the railway freight report data, and then searches a pre-set structured query language database. If target query language data matching the natural language query text is found, an executable target query statement for the freight report database is directly generated based on the retrieved target query language data and the natural language query text. If no target query language data matching the natural language query text is found, the system extracts target freight knowledge matching the natural language query text from a pre-set freight knowledge base, and then combines the target freight knowledge with the natural language text to construct the target query statement. In this way, business personnel do not need to master complex query language writing knowledge, nor do they need to rely on and wait for technical personnel to develop it. They can initiate queries using only natural language, and the system automatically completes the entire process from retrieval, selection of generation criteria to construction of an executable query statement, and runs the query statement in the railway freight report database to return the results. This process realizes the automatic conversion from natural language intent to structured query, significantly reducing the technical threshold and time cost of data query, greatly improving the speed of query response and the flexibility of business analysis, and can promptly meet the diverse and real-time needs of business decision-making for data queries.
[0085] In one exemplary embodiment, such as Figure 2 As shown, after receiving the natural language query text for the railway freight report database, the method further includes steps 202 to 208. Wherein:
[0086] Step 202: Perform semantic retrieval on the preset structured query language database based on the natural language query text to obtain at least one first candidate query statement data, and perform keyword retrieval on the preset structured query language database based on the natural language query text to obtain at least one second candidate query statement data.
[0087] Semantic retrieval can refer to a retrieval method that matches texts based on the similarity of their meanings.
[0088] Keyword retrieval refers to searching based on the matching of specific words or phrases in a text, which can be achieved through methods such as word frequency and Boolean matching.
[0089] For example, after receiving a natural language query text, the terminal can perform two types of searches in parallel or in any order. On the one hand, it can search a structured query language database for one or more query statements that are semantically closer to the input natural language query text, as first candidate query statements. On the other hand, it can extract keywords (such as time, location, product category, quantity, and other business entities) from the natural language query text, perform exact matching or fuzzy matching in a preset structured query language database, and select one or more query statements with a high degree of matching as second candidate query statements.
[0090] Step 204: Detect the relevance score between the natural language query text and the data of each candidate query statement, which includes the data of each first candidate query statement and the data of each second candidate query statement.
[0091] Among them, the relevance score can refer to a numerical indicator used to quantify the degree of relevance between the natural language query text and the data of each alternative query statement.
[0092] For example, a trained re-ranking model can be used to encode and perform interactive analysis on the natural language query text and each candidate query data, and output a relevance score between the natural language query text and each candidate query data.
[0093] Re-ranking models refer to text matching or ranking models based on deep neural networks (such as BERT, RoBERTa, and other pre-trained language models). They are specifically trained to deeply understand the semantic relevance between two text fragments (e.g., a natural language question and a structured query description). Their training data can consist of manually labeled triples (natural language query, structured query description, relevance label), and the learning objective is to assign higher matching scores to truly relevant query pairs.
[0094] By introducing a reordering model, the system can go beyond simple literal or vector similarity calculations and use deep learning to make deeper semantic judgments. This allows for more accurate identification of query patterns that truly match the user's intent from the candidate set, and effectively evaluates the reliability of the matching results, providing a more robust basis for subsequent decisions.
[0095] Step 206: Detect the target confidence level of the candidate query data corresponding to the highest relevance score.
[0096] The target confidence level refers to the degree of certainty that the candidate query data corresponding to the highest relevance score can accurately meet the user's query intent. It can be determined by the historical usage accuracy of the candidate query data, its semantic matching tightness with the input text, or the probability value output by the classification model.
[0097] For example, after determining the relevance score between the natural language query text and each candidate query statement data, the highest relevance score is identified. To assess the reliability of the candidate query statement data corresponding to the highest relevance score, the re-ranking model can calculate the target confidence value of the candidate query statement data corresponding to the highest relevance score by analyzing features such as the difference between the highest and second-highest scores, keyword coverage completeness, and consistency of business rules.
[0098] Step 208: If the target confidence level is higher than the preset confidence level, the candidate query statement data corresponding to the highest relevance score is determined as the target query language data.
[0099] For example, the calculated target confidence score is compared with a preset confidence threshold. If the target confidence score is higher than the preset confidence threshold, the matching result is deemed reliable, and the candidate query data corresponding to the highest relevance score is formally determined as the target query language data for subsequent query generation. If the target confidence score is not higher than the preset confidence threshold, it means that the current matching result is not reliable enough, and the system can trigger other processing paths (such as switching to the freight knowledge base).
[0100] In this embodiment, the first round of screening through semantic retrieval and keyword retrieval can cover a wider range of candidate query data from different perspectives. Then, by calculating confidence levels, the search results are rigorously filtered to ensure that the final selected target query language data highly matches the user's true intent. Therefore, the robustness and reliability of the target query language data matching process can be effectively improved.
[0101] In one exemplary embodiment, a preset structured query language database stores multiple query statement data; semantic retrieval is performed on the preset structured query language database based on natural language query text to obtain at least one first candidate query statement data, including:
[0102] The cosine similarity between the natural language query text and each query statement data is detected; based on each cosine similarity, a preset first number of query statement data are selected from the preset structured query language database as the first candidate query statement data, and the cosine similarity corresponding to the first candidate query statement data is higher than the cosine similarity corresponding to other unselected query statement data.
[0103] For example, a semantic encoding model fine-tuned based on freight data can be used to semantically vectorize natural language query text, converting it into semantic vectors. Query language data in a pre-defined structured query language database can also be stored as semantic vectors, or vectorized during the actual matching process. Subsequently, the cosine similarity between the semantic vector corresponding to the natural language query text and the semantic vector corresponding to each query language data in the structured query language database is calculated. Then, the data is sorted in descending order based on the cosine similarity values. According to a pre-defined first quantity, the first quantity of query statements ranked highest in the sorting results is selected as the first candidate query statement data.
[0104] In some feasible embodiments, the cosine similarity can be calculated as follows:
[0105]
[0106] Where q is the semantic vector corresponding to the natural language query text; d is the semantic vector corresponding to any query language data in the structured query language database.
[0107] In this embodiment, cosine similarity can measure the degree of association between a user query and the massive amount of query language data in the database at the semantic level, and can identify candidates with similar intent even if the literal meanings do not match. This significantly broadens the coverage of effective matching, improves the system's ability to understand and respond to diverse and non-standard natural language queries, and provides a richer and more relevant candidate basis for subsequent accurate matching and query generation.
[0108] In one exemplary embodiment, a preset structured query language database stores multiple query statement data; keyword retrieval is performed on the preset structured query language database based on natural language query text to obtain at least one second alternative query statement data, including:
[0109] The natural language query text is segmented into multiple word texts. For each word text, the frequency of its occurrence in each query statement is detected, as well as the number of query statements containing the word text. Based on the frequency of occurrence, the number of query statements containing the word text, the number of query statements in the preset structured query language database, the length of each query statement, and the average length of each query statement, the keyword matching score corresponding to each query statement is detected. Based on the keyword matching scores, a preset second number of query statements are selected from the preset structured query language database as second candidate query statements. The keyword matching score of the second candidate query statements is higher than the keyword matching scores of the other unselected query statements.
[0110] For example, the input natural language query text can first be segmented into an ordered sequence of words using a word segmentation tool (e.g., a dictionary-based or statistical model-based segmenter). During segmentation, meaningless function words can be removed, retaining only meaningful content words. For each word in the sequence, statistical analysis is performed on the entire structured query language database to obtain the frequency of occurrence of that word in each query statement in the database, as well as the number of query statements containing that word in the entire database. After completing the statistical analysis on all word texts, based on the obtained statistical results, combined with the number of query statements in the database, the length of each query statement, and the average length of all query statements in the database, a pre-defined retrieval scoring algorithm is applied to calculate the corresponding keyword matching score for each query statement in the database. Then, all query statements are sorted in descending order of their keyword matching scores. Based on a pre-defined second number, the query statements with the highest ranking in the second number of sorted results are selected as the second candidate query statements.
[0111] In some feasible embodiments, the keyword matching score between the natural language query text q and any query statement data d can be expressed as:
[0112]
[0113] Where N is the number of query statements in the Structured Query Language database; n t d represents the number of query statements in the Structured Query Language database containing the word text t; f(t,d) represents the number of times the word text t appears in the query statement data d; dl represents the length of the query statement data d; avgdl represents the average length of all query statements in the Structured Query Language database; k1 is the word frequency saturation parameter, which can be set to 1.2~2.0 depending on the actual situation or test results, and is used to control the upper limit of the influence of word frequency on the score; b is the document length penalty parameter, which is usually set to 0.75 depending on the actual situation or test results, and is used to control the strength of the length penalty.
[0114] In this embodiment, the keyword retrieval method can more accurately evaluate the relevance of each query template to the user query at the keyword level, ensuring that the selected second candidate query data is highly relevant to the user's intent in terms of both literal meaning and topic. This effectively complements semantic retrieval and together provides a more comprehensive and reliable candidate set for subsequent precise matching and confidence assessment, thereby improving the accuracy and efficiency of the overall query matching.
[0115] In one exemplary embodiment, such as Figure 3As shown, after running the target query statement in the railway freight report database and obtaining the query results corresponding to the natural language query text, the method further includes steps 302 to 308. Wherein:
[0116] Step 302: Display the query results.
[0117] It's important to note that compared to retrieving target query language data from a pre-defined structured query language database and then generating the target query statement based on the target query language data and natural language query text, the method of obtaining target freight knowledge matching the natural language query text from a pre-defined freight knowledge base and then generating the target query statement based on the target freight knowledge and natural language query text, while capable of generating the target query statement, involves a more complex computational process, requires more processing steps, resulting in a larger computational load, slower generation speed, higher computational resource consumption, and slower response time. For query scenarios not pre-recorded in the pre-defined structured query language database, even if they occur repeatedly in actual business, the system still needs to rely on dynamic knowledge matching and complex logical deduction to generate the query statement each time. Repeating this high-consumption generation process for each similar request leads to a continuous waste of computational resources and hinders the continuous improvement of response efficiency and the self-evolution of intelligence.
[0118] For example, after obtaining the query results, the query results can be displayed in a preset visual format (such as data tables, statistical charts, briefing cards, etc.) through the front-end application interface so that the user who made the query request can view them.
[0119] Step 304: Obtain user feedback information regarding the query results.
[0120] User feedback information refers to information provided by users through interactive operations after viewing the query results, used to evaluate the correctness or satisfaction of the results.
[0121] For example, during the process of displaying query results, the user's subjective evaluation or confirmation information on the currently displayed query results can be obtained and recorded through the interactive components provided by the front-end interface, i.e., user feedback information.
[0122] Step 306: If the target query statement used to obtain the query result is not contained in the preset structured query language database, and the query result is determined to be correct based on user feedback, generate the query language data corresponding to the target query statement.
[0123] For example, after obtaining user feedback, the system can determine, based on relevant processing records during the query process, whether the target query statement used to generate the query result is based on a target query statement retrieved from a pre-defined structured query language database. If so, it indicates that the pre-defined structured query language database already covers the current query scenario, and no new query language data is needed. If not, it indicates that the pre-defined structured query language database does not cover the current query scenario. In this case, the system can further determine, based on the obtained user feedback, whether the user considers the query result correct. If the user considers the query result correct, a new query language data record is constructed according to a predetermined format, based on the natural language query text, the target query statement used, and the parameter information that may be parsed from the query statement. If the user considers the query result incorrect, no new query language data is needed.
[0124] Step 308: Store the query language data corresponding to the target query statement in a preset structured query language database.
[0125] For example, the newly generated query language data record is added to a pre-defined structured query language database via a database operation interface. This new record then becomes part of the structured query language database and can be used to respond to future related query requests.
[0126] In this embodiment, by transforming each successfully processed query data into reusable structured knowledge and verifying the correctness of the knowledge based on user feedback, the confirmed correct data is recorded and solidified in the Structured Query Language (SCL) database. This enables the SCL database to continuously learn and evolve its capabilities online. As usage time increases, the coverage of the SCL database expands, significantly improving the hit rate for common and emerging query patterns. This directly reduces the system's reliance on complex generation paths or external knowledge bases, improves the response speed and accuracy of subsequent similar queries, and reduces overall computational overhead.
[0127] In an exemplary embodiment, the target query statement is generated using a preset query statement model, which is obtained by fine-tuning a pre-trained model using historical freight data query data; generating the target query statement based on the target query language data and natural language query text includes:
[0128] Obtain context query information; generate the target query statement by inputting context query information, target query language data, and natural language query text into the query statement big model.
[0129] Among them, context query information can refer to information such as historical session information and user profiles that are associated with the current query request and may affect the generation of the query.
[0130] For example, after obtaining the target query language data, contextual query information related to the current query can be extracted from the current session record, user information, or system configuration. Then, the contextual query information, the target query language data, and the original natural language query text are concatenated or structured and used as complete input, fed into the query statement model. The query statement model comprehensively understands the context, the structured template, and the current query intent to generate the final target query statement.
[0131] Generate target query statements based on target freight knowledge and natural language query text, including:
[0132] Obtain contextual query information; generate the target query statement by inputting contextual query information, target freight knowledge, and natural language query text into the query statement model.
[0133] For example, after obtaining the target freight knowledge, contextual query information related to the current query can be extracted from the current session record, user information, or system configuration. Then, the contextual query information, target freight knowledge, and the original natural language query text are concatenated or structured and fed into the query statement model as complete input. The query statement model comprehensively understands the context, target freight knowledge, and current query intent to generate the final target query statement.
[0134] In this embodiment, by introducing contextual query information, the model can more accurately understand the user's continuous intent and implicit conditions, thereby generating a more complete target query statement that better meets the user's true expectations.
[0135] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0136] Based on the same inventive concept, this application also provides a railway freight report data query device for implementing the railway freight report data query method described above. The solution provided by this device is similar to the solution described in the above method; therefore, the specific limitations of one or more railway freight report data query device embodiments provided below can be found in the limitations of the railway freight report data query method described above, and will not be repeated here.
[0137] In one exemplary embodiment, such as Figure 4 As shown, a railway freight report data query device is provided, comprising: a receiving module 402, a first generating module 404, a second generating module 406, and a query module 408, wherein:
[0138] The receiving module 402 is used to receive natural language query text for the railway freight report database;
[0139] The first generation module 404 is used to generate a target query statement based on the target query language data and the natural language query text when the target query language data that matches the natural language query text is retrieved from the preset structured query language database.
[0140] The second generation module 406 is used to obtain target freight knowledge that matches the natural language query text from a preset freight knowledge base when no target query language data matching the natural language query text is retrieved from the preset structured query language database, and to generate a target query statement based on the target freight knowledge and the natural language query text.
[0141] The query module 408 is used to run the target query statement in the railway freight report database and obtain the query results corresponding to the natural language query text.
[0142] In one exemplary embodiment, the railway freight report data query device further includes a retrieval module, which, after receiving natural language query text for the railway freight report database, is configured to:
[0143] Semantic retrieval is performed on a pre-defined structured query language database based on natural language query text to obtain at least one first candidate query statement data, and keyword retrieval is performed on the pre-defined structured query language database based on natural language query text to obtain at least one second candidate query statement data.
[0144] The relevance score between the natural language query text and the data of each candidate query statement is detected. The candidate query statement data includes the data of each first candidate query statement and the data of each second candidate query statement.
[0145] Detect the target confidence level of the candidate query data corresponding to the highest relevance score;
[0146] If the target confidence level is higher than the preset confidence level, the candidate query data corresponding to the highest relevance score will be determined as the target query language data.
[0147] In one exemplary embodiment, a preset structured query language database stores multiple query statements; the retrieval module is further configured to:
[0148] Detect the cosine similarity between the natural language query text and the data of each query statement;
[0149] Based on the cosine similarity of each query statement, a predetermined first number of query statements are selected from the preset structured query language database as first candidate query statements. The cosine similarity of the first candidate query statements is higher than the cosine similarity of the other unselected query statements.
[0150] In one exemplary embodiment, a preset structured query language database stores multiple query statements; the retrieval module is further configured to:
[0151] The natural language query text is segmented into words to obtain a text containing multiple words.
[0152] For each word text, detect the number of times the word text appears in each query statement data, as well as the number of query statements containing the word text;
[0153] The keyword matching score for each query is determined based on the frequency of occurrence, the number of query data containing word text, the number of query data in the preset structured query language database, the length of each query data, and the average length of each query data.
[0154] Based on the keyword matching scores, a preset second number of query statements are selected from the preset structured query language database as second candidate query statements. The keyword matching scores of the second candidate query statements are higher than the keyword matching scores of the other unselected query statements.
[0155] In an exemplary embodiment, the railway freight report data query device further includes a storage module. After running the target query statement in the railway freight report database and obtaining the query results corresponding to the natural language query text, the storage module is used for:
[0156] Display the query results;
[0157] Obtain user feedback information regarding the query results;
[0158] If the target query statement used to obtain the query result is not contained in the preset structured query language database, and the query result is determined to be correct based on user feedback, then query language data corresponding to the target query statement is generated.
[0159] Store the query language data corresponding to the target query statement in a pre-defined structured query language database.
[0160] In an exemplary embodiment, the target query statement is generated using a preset query statement large model, which is obtained by fine-tuning a pre-trained large model using historical freight report data query data; the first generation module 404 is further configured to:
[0161] Retrieve context query information;
[0162] By inputting contextual query information, target query language data, and natural language query text into the query statement model, the target query statement is generated.
[0163] The second generation module 406 is also used for:
[0164] Retrieve context query information;
[0165] By inputting contextual query information, target freight knowledge, and natural language query text into the query statement model, the target query statement is generated.
[0166] In one exemplary embodiment, the pre-built freight knowledge base includes freight terminology information, business indicator definition information, database table structure information, and a freight report knowledge graph. The freight report knowledge graph is used to characterize entities, entity attributes, and relationships between entities in railway freight report data.
[0167] Each module in the aforementioned railway freight data query device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0168] In one exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 5As shown, the computer device includes a processor, memory, input / output interface, communication interface, display unit, and input device. The processor, memory, and input / output interface are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interface. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interface is used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When the computer program is executed by the processor, it implements a method for querying railway freight report data. The display unit is used to form a visually visible image and can be a display screen, projection device, or virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0169] Those skilled in the art will understand that Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0170] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0171] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0172] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0173] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0174] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0175] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0176] The above embodiments are merely illustrative of several implementation methods of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A method for querying railway freight report data, characterized in that, The method includes: Receive natural language query text for the railway freight report database; If target query language data matching the natural language query text is retrieved from a preset structured query language database, a target query statement is generated based on the target query language data and the natural language query text. If no target query language data matching the natural language query text is found in the preset structured query language database, target freight knowledge matching the natural language query text is obtained from the preset freight knowledge base, and a target query statement is generated based on the target freight knowledge and the natural language query text. The target query statement is executed in the railway freight report database to obtain the query results corresponding to the natural language query text.
2. The method according to claim 1, characterized in that, After receiving the natural language query text for the railway freight report database, the method further includes: Based on the natural language query text, a semantic search is performed on the preset structured query language database to obtain at least one first candidate query statement data, and based on the natural language query text, a keyword search is performed on the preset structured query language database to obtain at least one second candidate query statement data. The relevance score between the natural language query text and each candidate query statement data is detected, wherein the candidate query statement data includes each first candidate query statement data and each second candidate query statement data; Detect the target confidence level of the candidate query data corresponding to the highest relevance score; If the target confidence level is higher than the preset confidence level, the candidate query statement data corresponding to the highest relevance score will be determined as the target query language data.
3. The method according to claim 2, characterized in that, The pre-defined structured query language database stores multiple query statements. The step of performing semantic retrieval on a preset structured query language database based on the natural language query text to obtain at least one first candidate query statement data includes: Detect the cosine similarity between the natural language query text and each of the query statement data; Based on the cosine similarity of each statement, a preset first number of query statement data are selected from a preset structured query language database as first candidate query statement data. The cosine similarity of the first candidate query statement data is higher than the cosine similarity of the other unselected query statement data.
4. The method according to claim 2, characterized in that, The pre-defined structured query language database stores multiple query statements. The step of performing keyword retrieval on a preset structured query language database based on the natural language query text to obtain at least one second alternative query statement data includes: The natural language query text is segmented into words to obtain multiple word texts; For each word text, detect the number of times the word text appears in each query statement data, and the number of query statement data containing the word text; Based on the occurrence frequency, the number of query statement data containing the word text, the number of query statement data in the preset structured query language database, the length of each query statement data, and the average length of each query statement data, the keyword matching score corresponding to each query statement data is detected. Based on the keyword matching scores, a preset second number of query statement data are selected from a preset structured query language database as second candidate query statement data. The keyword matching scores of the second candidate query statement data are higher than the keyword matching scores of other unselected query statement data.
5. The method according to any one of claims 1 to 4, characterized in that, After running the target query statement in the railway freight report database and obtaining the query results corresponding to the natural language query text, the method further includes: Display the query results; Obtain user feedback information regarding the query results; If the target query statement used to obtain the query result is not contained in the preset structured query language database, and the query result is determined to be correct based on the user feedback information, then query language data corresponding to the target query statement is generated. The query language data corresponding to the target query statement is stored in a preset structured query language database.
6. The method according to any one of claims 1 to 4, characterized in that, The target query statement is generated using a preset query statement model, which is obtained by fine-tuning a pre-trained model using historical cargo report data. The step of generating a target query statement based on the target query language data and the natural language query text includes: Retrieve context query information; By inputting the context query information, the target query language data, and the natural language query text into the query statement model, a target query statement is generated. The step of generating a target query statement based on the target freight knowledge and the natural language query text includes: Retrieve context query information; The target query statement is generated by inputting the context query information, the target freight knowledge, and the natural language query text into the query statement model.
7. The method according to any one of claims 1 to 4, characterized in that, The pre-built freight knowledge base includes freight terminology information, business indicator definition information, database table structure information, and freight report knowledge graph. The freight report knowledge graph is used to represent entities, entity attributes, and relationships between entities in railway freight report data.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.