CN111177180A - Data query method and device and electronic equipment - Google Patents

Data query method and device and electronic equipment Download PDF

Info

Publication number
CN111177180A
CN111177180A CN201911264283.XA CN201911264283A CN111177180A CN 111177180 A CN111177180 A CN 111177180A CN 201911264283 A CN201911264283 A CN 201911264283A CN 111177180 A CN111177180 A CN 111177180A
Authority
CN
China
Prior art keywords
queried
template
target
word
similarity
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201911264283.XA
Other languages
Chinese (zh)
Inventor
刘译璟
于帮付
高体伟
左云鹏
代其锋
徐林杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baifendian Information Science & Technology Co ltd
Original Assignee
Beijing Baifendian Information Science & Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baifendian Information Science & Technology Co ltd filed Critical Beijing Baifendian Information Science & Technology Co ltd
Priority to CN201911264283.XA priority Critical patent/CN111177180A/en
Publication of CN111177180A publication Critical patent/CN111177180A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2452Query translation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a data query method, which is used for solving the problem that in the prior art, for a user without a related professional background, it is usually difficult to modify a slot in an SQL template based on a query request by using a programming language to obtain a structured query statement. The method comprises the following steps: determining a target template; filling target keywords and screening item identifications contained in a target template based on the similarity of each word to be queried and each field and each aggregation function in a database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language; and inquiring target data from the database to be inquired based on the filled target template. The application also discloses a data query device, data query electronic equipment and a storage medium.

Description

Data query method and device and electronic equipment
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a data query method and apparatus, and an electronic device.
Background
With the rapid development of computer technology, numerous database-based related applications have emerged. However, as the amount of data stored in the database is larger and more complicated, how to conveniently and quickly query the data stored in the database becomes a topic of concern for relevant application providers.
In the existing data query technology, an SQL (Structured query language) template associated with a query request is generally obtained according to the received query request, then a database programming language is used to modify a slot in the SQL template based on a value of an item to be filtered and an identifier of the item to be filtered, which are carried in the query request, to obtain a Structured query statement, and finally the Structured query statement is executed to obtain query data. The SQL template is used for instantiating the query request into a structured query statement, and the slots in the SQL template are used for representing the screening keywords and the screening item identifiers.
However, in the process of obtaining the structured query statement by modifying the slot in the SQL template based on the query request using the database programming language, the user is often required to be skilled in the relevant expertise, such as the database programming language, the structure of the table in the database, and the like, so that the slot in the SQL template can be modified using the relevant expertise, but the slot is generally difficult to be used by users without the relevant expertise.
Disclosure of Invention
The embodiment of the application provides a data query method, which is used for solving the problem that in the prior art, in the process of modifying a slot in an SQL template by using a programming language based on a query request to obtain a structured query statement, a user is often required to be skilled in mastering the corresponding programming language, and the table structure and the like in a database are familiar, so that the data query method is difficult to apply to users without related professional backgrounds.
The embodiment of the application further provides a data query device and electronic equipment, which are used for solving the problems that in the prior art, in the process of modifying the slot in the SQL template by using the programming language based on the query request to obtain the structured query statement, a user is often required to be skilled in mastering the corresponding programming language, and the table structure in the database is familiar with the table structure and the like, so that the application is usually difficult for the user without the related professional background.
The embodiment of the application adopts the following technical scheme:
in a first aspect, an embodiment of the present application provides a data query method, where the method includes:
determining a target template;
filling target keywords and screening item identifications contained in the target template based on the similarity between each word to be queried and each field in a database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language;
and inquiring target data from the database to be inquired based on the filled target template.
In one implementation, the determining a target template includes:
obtaining statement vectors of the query statements described by the natural language and template vectors of all preset structured query language templates;
respectively calculating cosine similarity of the statement vector and each template vector;
and determining the structured query language template corresponding to the template vector with the maximum cosine similarity of the statement vector as the target template.
In one implementation manner, the filling the target keywords and the screening item identifiers included in the target template based on the similarity between each word to be queried and each field in the database to be queried includes:
calculating first similarity between each word to be queried and each field in the database to be queried;
and filling the target keywords and the screening item identifications contained in the target template based on the field with the maximum first similarity with each word to be queried.
In one implementation, the calculating a first similarity between each word to be queried and each field in the database to be queried includes:
respectively obtaining word vectors corresponding to the words to be queried;
acquiring field vectors corresponding to all fields in the database to be queried;
and respectively calculating the first similarity of each field vector and each word vector.
In one implementation, when an aggregation function is included in the query statement described in the natural language, the method further includes:
filling target keywords and screening item identifications contained in the target template based on the similarity between each word to be queried and each aggregation function in a database to be queried; the words to be inquired are obtained by segmenting the words of the inquiry sentences described by the natural language.
In one implementation manner, the filling the target keywords and the screening item identifiers included in the target template based on the similarity between each to-be-queried word and each aggregation function in the to-be-queried database includes:
calculating second similarity of each word to be queried and each aggregation function in the database to be queried;
and filling the target key words and the screening item identifications contained in the target template based on the aggregation function with the maximum second similarity to the words to be inquired.
In one implementation, before the determining the target template, the method further includes:
screening a structured query language template which meets the conditions of the preset template from each preset structured query language template so as to facilitate subsequent filling; wherein the preset template conditions include: the dimension of the structured query language template is less than or equal to 1 and/or the number of aggregation functions contained in the structured query language template is less than or equal to 1.
In a second aspect, an embodiment of the present invention provides a frame calculation apparatus for a game, where the apparatus includes a determination module, a filling module, and a query module, where:
the determining module is used for determining a target template;
the filling module is used for filling the target keywords and the screening item identifications contained in the target template based on the similarity between each word to be queried and each field in the database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language;
and the query module is used for querying the target data from the database to be queried based on the filled target template.
In one implementation, the determining module includes:
the acquisition unit is used for acquiring statement vectors of the query statements described by the natural language and template vectors of all preset structured query language templates;
the first calculating unit is used for calculating the cosine similarity of the statement vector and each template vector respectively;
and the determining unit is used for determining the structured query language template corresponding to the template vector with the maximum cosine similarity of the statement vector as the target template.
In one implementation, the fill template includes:
the second calculation unit is used for calculating first similarity of each word to be queried and each field in the database to be queried;
and the filling unit is used for filling the target keywords and the screening item identifications contained in the target template based on the field with the maximum first similarity with each word to be queried.
In one implementation, the second computing unit is configured to:
respectively obtaining word vectors corresponding to the words to be queried;
acquiring field vectors corresponding to all fields in the database to be queried;
and respectively calculating the first similarity of each field vector and each word vector.
In one implementation, when the aggregation function is included in the query statement described in the natural language, the apparatus is further configured to:
filling target keywords and screening item identifications contained in the target template based on the similarity between each word to be queried and each aggregation function in a database to be queried; the words to be inquired are obtained by segmenting the words of the inquiry sentences described by the natural language.
In one implementation, the filling module is further configured to:
calculating second similarity of each word to be queried and each aggregation function in the database to be queried;
and filling the target key words and the screening item identifications contained in the target template based on the aggregation function with the maximum second similarity to the words to be inquired.
In one implementation, the apparatus further comprises:
the screening module is used for screening the structured query language template which meets the preset template condition from each preset structured query language template so as to facilitate subsequent filling; wherein the preset template conditions include: the dimension of the structured query language template is less than or equal to 1 and/or the number of aggregation functions contained in the structured query language template is less than or equal to 1.
In a third aspect, an embodiment of the present invention provides an electronic device, including: a memory, a processor and a computer program stored on the memory and executable on the processor, the computer program implementing the steps of any of the data query methods as described above when executed by the processor.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the computer program implements the steps of any one of the data query methods described above.
The embodiment of the application adopts at least one technical scheme which can achieve the following beneficial effects:
in the data query process, the target keywords and the screening item identifiers contained in the determined target template can be filled based on the similarity between each word to be queried and each field in the database to be queried to obtain the filled target template, so that on one hand, the target keywords and the screening item identifiers contained in the determined target template can be filled only according to the similarity between each word to be queried and each field in the database to be queried, and the slots in the SQL template do not need to be modified based on query requests by using complex languages such as database programming languages and the like, thereby improving the efficiency of data query.
On the other hand, a user without a related professional background can query data in a natural language description mode, the problem that the user needs to be skilled in mastering a corresponding programming language when performing data query in the related technology is solved, and the applicability of data query is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a flowchart illustrating a specific implementation of a data query method according to an embodiment of the present application;
fig. 1a is a flowchart illustrating a specific implementation of determining a target template in a data query method according to an embodiment of the present application;
fig. 1b is a flowchart illustrating a specific implementation of filling a target keyword and a filter item identifier included in a target template in a data query method according to an embodiment of the present application;
fig. 1c is a flowchart illustrating a specific implementation of calculating a first similarity in a data query method according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of a data query device according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure;
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
Example 1
In order to solve the problem that in the prior art, in the data query process, it is generally difficult for a user without a relevant professional background to use, embodiment 1 of the present application provides a data query method. The execution subject of the method may be various types of electronic devices, such as a user terminal, e.g., a desktop computer, a laptop computer, a notebook computer, a desktop computer, a cellular phone, a smart watch, a wearable electronic device, or an implantable electronic device, or may be a server. The server may be a single server or a server group composed of a plurality of servers.
For convenience of description, the embodiment of the present invention takes the execution subject of the method as an example, and introduces the method. It can be understood by those skilled in the art that the embodiment of the present invention is described by taking the electronic device as an example, and is only an exemplary illustration, and does not limit the protection scope of the claims corresponding to the present invention.
Referring to fig. 1, a flowchart of an implementation of a data query method provided in an embodiment of the present application is shown, where the flowchart includes the following steps:
and step 11, determining a target template.
Before describing the step of determining the target template, the purpose of determining the target template will be briefly described below.
As shown in the content recorded in the summary of the invention section, the embodiments of the present application provide a method for performing data query in a natural language description manner, which can improve the applicability of the data query process and reduce the query difficulty, however, the accuracy of the query result may be reduced due to the ambiguity and abstraction of the natural language in the expression.
Therefore, in order to avoid the above problem, in the embodiment of the present application, the target template may be determined first, so that the query statement described in the natural language may be instantiated into a more standard structured query statement through the target template, and due to the accuracy and the certainty of the structured query language itself, the query requirement of the user may be accurately described, so that the accuracy of the data query result may be improved.
In one implementation, the template may be represented, for example, as follows:
{“template”:”*${group}${field1-dim}*${field2-index}”“result”:{"select":[{"f ield":"${field2-index}"}],"group":[{"field":"${field1-dim}"}]}}。
wherein template represents a template; $ group }, $ { field-dim }, and $ field-index } represent slots contained by the template; specifically, $ { group } represents a grouping descriptor; $ field-dim represents a dimension; and { field-index } represents an index. Optionally, the template may also include an aggregation function slot $ { agg }, etc.
It should be noted that the template illustrated above is only an exemplary illustration, and does not set any limit to the embodiments of the present application.
As shown in fig. 1a, the specific implementation of step 11 will be further explained below.
Alternatively, when determining the target template, the determination may be performed according to the sentence structure and the deep semantics of the query sentence described in the natural language. Hereinafter, a mode of determining the target template will be described by taking the deep semantic meaning of the query sentence described in the natural language as an example.
And step 111, obtaining statement vectors of query statements described by the natural language and template vectors of all preset structured query language templates.
Before introducing step 111, concepts such as a query statement described in a natural language are explained below.
In order to describe the query statement described in the natural language, a Structured Query Language (SQL) is referred to as a difference language in the following to more clearly describe the query statement described in the natural language.
Optionally, the general format of SQL is: SELECT < target list expression > FROM < table name or view name > WHERE < conditional expression >. Wherein, the table name contained in the FROM clause is the table name of the data table to be inquired by the SQL query sentence; the target list expression contained in the SELECT clause is the target list expression to be queried by the SQL query sentence; the conditional expression contained in the WHERE clause is the query condition to be queried by the SQL query statement.
The query statement described by the natural language, i.e. the natural form of the demand expressed by people, for example, "how many people in each province have respectively", "general population with different identities", "general population living in Beijing city", etc. The above-mentioned natural description query statement is only an exemplary illustration of the embodiment of the present application, and does not cause any limitation in the embodiment of the present application.
In one implementation, when a statement vector of a query statement described in a natural language is obtained, the query statement described in the natural language may be vectorized, for example, but not limited to, using a bert model.
Alternatively, before obtaining the sentence vector of the query sentence described in the natural language, a word segmentation processing technique may be used to segment the query sentence described in the natural language. For example, assuming that a query statement described in natural language is "how many people in different provinces are", query terms waiting for "different", "provinces", and "population" can be obtained by a word segmentation processing technique, and then an average vector of each query term is obtained as a statement vector of the query statement described in natural language.
It should be noted that, since all the slots included in the target template are abstract concepts, in the embodiment of the present application, before the template vector of each preset structured query language template is obtained, the template may be instantiated first, and the slots in the target template are specifically converted into general terms. For example, using the above template, $ { field-dim } can be instantiated as "region, $ { agg } as" Total, $ { group } as "different," and { field-index } as "population.
The above instantiation manner is only an exemplary illustration, and does not set any limit to the embodiments of the present application.
And step 112, respectively calculating cosine similarity of the statement vector and each template vector.
Optionally, in this embodiment of the present application, for example, the cosine similarity between the statement vector and each template vector may be calculated by successively adopting the steps of word segmentation, word frequency calculation, word frequency vector listing, and the like. Alternatively, the calculation may be performed by referring to a related cosine similarity calculation method, which is not described herein again. The above-mentioned calculation method is only an exemplary one, and does not limit the embodiments of the present application.
And step 113, determining the structured query language template corresponding to the template vector with the maximum cosine similarity of the statement vector as a target template.
Generally, because the euclidean distances or the cosine distances corresponding to the terms with similar semantics are similar, in one implementation, the target template may be determined by considering the cosine similarity between the sentence vector and each template vector.
For example, after the cosine similarity between the statement vector and each template vector is calculated in step 112, the structured query language templates corresponding to each template vector may be sorted in descending order based on the calculated cosine similarity, and the structured query language template corresponding to the template vector with the largest cosine similarity of the statement vector is determined as the target template.
Step 12, filling target keywords and screening item identifications contained in the target template based on the similarity between each word to be queried and each field in the database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language.
In one implementation, in order to enable the target template to instantiate the query statement described in the natural language into a structured query statement, the target keywords and the filter item identifiers included in the target template need to be filled.
Alternatively, the target keyword and the filter item identifier may be descriptions of some names, wherein the target keyword may include: field name, table name, field type, field length, field precision, whether null is allowed, sequence number, default value, etc. The screening item identification may include: table name, table physical name, table category, whether it is a view, whether it is a built-in table, main key field setting, table selection setting, table type setting, etc., and the target keyword and filter item identifier may be specifically set according to the query statement, without being limited to the above-mentioned examples.
As shown in fig. 1b, in one implementation, the target keywords and the filter item identifiers included in the target template may be filled in as follows:
and step 121, calculating first similarity between each word to be queried and each field in the database to be queried.
And step 122, filling the target keywords and the screening item identifications contained in the target template based on the field with the maximum first similarity with each word to be queried.
Optionally, after the first similarity between each word to be queried and each field in the database to be queried is obtained through calculation according to step 121, the field with the maximum first similarity to each word to be queried may be selected in a descending manner, and the target keyword and the filter item identifier included in the target template are filled.
It should be noted that, in an implementation manner, if the query statement described in the natural language includes an aggregation function, the method provided in the embodiment of the present application further includes:
filling target keywords and screening item identifications contained in a target template based on the similarity between each word to be queried and each aggregation function in a database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language.
The aggregation function represents a function for summarizing a plurality of pieces of information. Common aggregation functions include MAX (maximum) functions, MIN (minimum) functions, COUNT (number of records) functions, AVG (average) functions, SUM (SUM) functions, and the like.
Optionally, based on the similarity between each word to be queried and each aggregation function in the database to be queried, filling the target keyword and the screening item identifier included in the target template, including:
calculating second similarity of each word to be queried and each aggregation function in the database to be queried;
and filling the target keywords and the screening item identifications contained in the target template based on the aggregation function with the maximum second similarity to each word to be queried.
Alternatively, as shown in fig. 1c, in an embodiment, the step 121 may be implemented as follows:
step 1211, obtaining word vectors corresponding to the words to be queried respectively.
The word to be queried is obtained by segmenting the query sentence described by the natural language, and in one implementation mode, the word to be queried can be obtained by segmenting the query sentence described by the natural language through a sliding window method. The length of the sliding window can be specifically determined according to actual conditions.
In one embodiment, a sliding window with a preset length may be adopted to slide on the words to be queried, and an average value of the words to be queried in the sliding window is calculated to serve as a word vector corresponding to each word to be queried.
Step 1212, obtaining the field vector corresponding to each field in the database to be queried.
Step 1213, calculate the first similarity between each field vector and each word vector.
In an embodiment, when the first similarity between each field vector and each word vector is calculated, the calculation manner of step 112 may be adopted, which is not described herein again.
And step 13, inquiring target data from the database to be inquired based on the filled target template.
In one embodiment, after obtaining the filled target template according to step 12, the target data may be queried from the database to be queried based on the filled target template.
By adopting the method provided by the embodiment of the application, in the data query process, the target keywords and the screening item identification contained in the determined target template can be filled based on the similarity between each word to be queried and each field in the database to be queried, so that the filled target template is obtained.
On the other hand, a user without a related professional background can query data in a natural language description mode, the problem that the user needs to be skilled in mastering a corresponding programming language when performing data query in the related technology is solved, and the applicability of data query is improved.
In view of the same inventive concept as the above method, an embodiment of the present application further provides a data query apparatus, so as to solve the problem that, in the process of obtaining a structured query statement by modifying a slot in an SQL template based on a query request using a programming language in the prior art, a user is often required to be skilled in the corresponding programming language and is familiar with the structure of a table in a database, and thus, the user without a related professional background is often difficult to use.
The data query device 200 will be described in detail below.
The specific structural diagram of the data query apparatus 200 is shown in fig. 2, and includes the following functional modules:
a determining module 201, configured to determine a target template;
a filling module 202, configured to fill the target keywords and the screening item identifiers included in the target template based on the similarity between each word to be queried and each field in the database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language;
and the query module 203 is used for querying the target data from the database to be queried based on the filled target template.
In one implementation, the determining module includes:
the query processing device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring statement vectors of query statements described by natural language and template vectors of preset structured query language templates;
the first calculating unit is used for calculating cosine similarity of the statement vector and each template vector respectively;
and the determining unit is used for determining the structured query language template corresponding to the template vector with the maximum cosine similarity of the statement vector as the target template.
In one implementation, a fill template includes:
the second calculation unit is used for calculating first similarity of each word to be queried and each field in the database to be queried;
and the filling unit is used for filling the target keywords and the screening item identifications contained in the target template based on the field with the maximum first similarity with each word to be queried.
In one implementation, the second computing unit is configured to:
respectively obtaining a word vector corresponding to each word to be queried;
acquiring field vectors corresponding to all fields in a database to be queried;
and respectively calculating the first similarity of each field vector and each word vector.
In one implementation, when the aggregation function is included in a query statement described in the natural language, the apparatus is further configured to:
filling target keywords and screening item identifications contained in a target template based on the similarity between each word to be queried and each aggregation function in a database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language.
In one implementation, the filling module is further configured to:
calculating second similarity of each word to be queried and each aggregation function in the database to be queried;
and filling the target keywords and the screening item identifications contained in the target template based on the aggregation function with the maximum second similarity to each word to be queried.
In one implementation, the apparatus further comprises:
the screening module is used for screening the structured query language template which meets the conditions of the preset template from each preset structured query language template so as to facilitate subsequent filling; wherein, the preset template conditions comprise: the dimension of the structured query language template is less than or equal to 1 and/or the number of aggregation functions contained in the structured query language template is less than or equal to 1.
By adopting the data query device provided by the embodiment of the application, in the data query process, the target keywords and the screening item identifications contained in the determined target template can be filled based on the similarity between each word to be queried and each field in the database to be queried, so that the filled target template is obtained.
On the other hand, a user without a related professional background can query data in a natural language description mode, the problem that the user needs to be skilled in mastering a corresponding programming language when performing data query in the related technology is solved, and the applicability of data query is improved.
In view of the same inventive concept as the above method, an embodiment of the present application further provides an electronic device, so as to solve the problem that, in the process of obtaining a structured query statement by modifying a slot in an SQL template based on a query request using a programming language in the prior art, a user is often required to be skilled in the corresponding programming language and is familiar with the structure of a table in a database, and thus, the user without a related professional background is often difficult to use.
The electronic device 300 will be described in detail below.
Fig. 3 is a schematic diagram illustrating a hardware structure of an electronic device according to an exemplary embodiment. As shown in fig. 3, electronic device 300 includes, but is not limited to: radio frequency unit 301, network module 302, audio output unit 303, input unit 304, sensor 305, display unit 306, user input unit 307, interface unit 308, memory 309, processor 310, and power supply 311.
Those skilled in the art will appreciate that the electronic device configuration shown in fig. 3 does not constitute a limitation of the electronic device, and that the electronic device may include more or fewer components than shown, or combine certain components, or a different arrangement of components. In the embodiment of the present invention, the electronic device includes, but is not limited to, a mobile phone, a tablet computer, a notebook computer, a palm computer, a vehicle-mounted terminal, a wearable device, a pedometer, and the like.
Wherein the processor 310, coupled to the memory, is configured to: determining a target template; filling target keywords and screening item identifications contained in a target template based on the similarity between each word to be queried and each field in a database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language; and inquiring target data from the database to be inquired based on the filled target template.
In one implementation, the processor 310 may be further configured to obtain a statement vector of a query statement described in a natural language and a template vector of each preset structured query language template; respectively calculating cosine similarity of the statement vector and each template vector; and determining the structured query language template corresponding to the template vector with the maximum cosine similarity of the statement vector as the target template.
In one implementation, the processor 310 may be configured to calculate a first similarity between each word to be queried and each field in the database to be queried; and filling the target keywords and the screening item identifications contained in the target template based on the field with the maximum first similarity with each word to be queried.
In one implementation, the processor 310 is configured to obtain a term vector corresponding to each term to be queried; acquiring field vectors corresponding to all fields in a database to be queried; and respectively calculating the first similarity of each field vector and each word vector.
In one implementation, the processor 310 may be further configured to fill the target keywords and the screening item identifiers included in the target template based on the similarity between each to-be-queried word and each aggregation function in the to-be-queried database; the word to be queried is obtained by segmenting a query sentence described by a natural language.
In one implementation, the processor 310 may be configured to calculate a second similarity between each word to be queried and each aggregation function in the database to be queried; and filling the target keywords and the screening item identifications contained in the target template based on the aggregation function with the maximum second similarity to each word to be queried.
In one implementation, before determining the target template, the processor 310 is further configured to filter a structured query language template meeting the preset template condition from each preset structured query language template for subsequent filling; wherein, the preset template conditions comprise: the dimension of the structured query language template is less than or equal to 1 and/or the number of aggregation functions contained in the structured query language template is less than or equal to 1.
The memory 309 is used for storing a computer program that can be executed on the processor 310, and when the computer program is executed by the processor 310, the above-mentioned functions implemented by the processor 310 are realized.
It should be understood that, in the embodiment of the present invention, the radio frequency unit 301 may be used for receiving and sending signals during a message sending and receiving process or a call process, and specifically, receives downlink data from a base station and then processes the received downlink data to the processor 310; in addition, the uplink data is transmitted to the base station. In general, radio frequency unit 301 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer, and the like. In addition, the radio frequency unit 301 can also communicate with a network and other devices through a wireless communication system.
The electronic device provides wireless broadband internet access to the user via the network module 302, such as assisting the user in sending and receiving e-mails, browsing web pages, and accessing streaming media.
The audio output unit 303 may convert audio data received by the radio frequency unit 301 or the network module 302 or stored in the memory 509 into an audio signal and output as sound. Also, the audio output unit 303 may also provide audio output related to a specific function performed by the electronic apparatus 300 (e.g., a call signal reception sound, a message reception sound, etc.). The audio output unit 303 includes a speaker, a buzzer, a receiver, and the like.
The input unit 304 is used to receive audio or video signals. The input Unit 304 may include a Graphics Processing Unit (GPU) 3041 and a microphone 3042, and the Graphics processor 3041 processes image data of a still picture or video obtained by an image capturing apparatus (e.g., a camera) in a video capturing mode or an image capturing mode. The processed image frames may be displayed on the display unit 306. The image frames processed by the graphic processor 3041 may be stored in the memory 309 (or other storage medium) or transmitted via the radio frequency unit 301 or the network module 302. The microphone 3042 may receive sounds and be capable of processing such sounds into audio data. The processed audio data may be converted into a format output transmittable to a mobile communication base station via the radio frequency unit 301 in case of the phone call mode.
The electronic device 300 also includes at least one sensor 305, such as a light sensor, motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor that adjusts the brightness of the display panel 3061 according to the brightness of ambient light, and a proximity sensor that turns off the display panel 3061 and/or the backlight when the electronic device 300 is moved to the ear. As one type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in each direction (generally three axes), detect the magnitude and direction of gravity when stationary, and can be used to identify the posture of an electronic device (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), and vibration identification related functions (such as pedometer, tapping); the sensors 305 may also include fingerprint sensors, pressure sensors, iris sensors, molecular sensors, gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., which are not described in detail herein.
The display unit 306 is used to display information input by the user or information provided to the user. The Display unit 506 may include a Display panel 3061, and the Display panel 3061 may be configured in the form of a Liquid Crystal Display (LCD), an Organic Light-Emitting Diode (OLED), or the like.
The user input unit 307 may be used to receive input numeric or character information and generate key signal inputs related to user settings and function control of the electronic device. Specifically, the user input unit 307 includes a touch panel 3071 and other input devices 3072. The touch panel 3071, also referred to as a touch screen, may collect touch operations by a user on or near the touch panel 3071 (e.g., operations by a user on or near the touch panel 3071 using a finger, a stylus, or any suitable object or attachment). The touch panel 3071 may include two parts of a touch detection device and a touch controller. The touch detection device detects the touch direction of a user, detects a signal brought by touch operation and transmits the signal to the touch controller; the touch controller receives touch information from the touch sensing device, converts the touch information into touch point coordinates, sends the touch point coordinates to the processor 310, and receives and executes commands sent by the processor 310. In addition, the touch panel 3071 may be implemented using various types, such as resistive, capacitive, infrared, and surface acoustic wave. The user input unit 307 may include other input devices 3072 in addition to the touch panel 3071. Specifically, the other input devices 3072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which are not described herein.
Further, the touch panel 3071 may be overlaid on the display panel 3061, and when the touch panel 3071 detects a touch operation on or near the touch panel, the touch operation is transmitted to the processor 310 to determine the type of the touch event, and then the processor 310 provides a corresponding visual output on the display panel 3061 according to the type of the touch event. Although the touch panel 3071 and the display panel 3061 are shown in fig. 3 as two separate components to implement the input and output functions of the electronic device, in some embodiments, the touch panel 3071 and the display panel 3061 may be integrated to implement the input and output functions of the electronic device, which is not limited herein.
The interface unit 308 is an interface for connecting an external device to the electronic apparatus 300. For example, the external device may include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device having an identification module, an audio input/output (I/O) port, a video I/O port, an earphone port, and the like. The interface unit 308 may be used to receive input (e.g., data information, power, etc.) from an external device and transmit the received input to one or more elements within the electronic apparatus 300 or may be used to transmit data between the electronic apparatus 300 and the external device.
The memory 309 may be used to store software programs as well as various data. The memory 309 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as audio data, a phonebook, etc.) created according to the use of the cellular phone, and the like. Further, the memory 309 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
The processor 310 is a control center of the electronic device, connects various parts of the whole electronic device by using various interfaces and lines, performs various functions of the electronic device and processes data by operating or executing software programs and/or modules stored in the memory 309 and calling data stored in the memory 309, thereby performing overall monitoring of the electronic device. Processor 310 may include one or more processing units; optionally, the processor 310 may integrate an application processor and a modem processor, wherein the application processor mainly handles operating systems, user interfaces, application programs, and the like, and the modem processor mainly handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 310.
The electronic device 300 may further include a power supply 311 (such as a battery) for supplying power to various components, and preferably, the power supply 311 may be logically connected to the processor 310 through a power management system, so as to implement functions of managing charging, discharging, and power consumption through the power management system.
In addition, the electronic device 300 includes some functional modules that are not shown, and are not described in detail herein.
In an exemplary embodiment, a storage medium including instructions is further provided, and a computer program is stored on the computer-readable storage medium, and when being executed by a processor, the computer program implements each process of any one of the method embodiments described in the foregoing embodiments, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here. Alternatively, the storage medium may be a non-transitory computer readable storage medium, which may be, for example, a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
Other embodiments of the invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the invention and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the invention being indicated by the following claims.
It will be understood that the invention is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the invention is limited only by the appended claims.

Claims (10)

1. A method for querying data, comprising:
determining a target template;
filling target keywords and screening item identifications contained in the target template based on the similarity between each word to be queried and each field in a database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language;
and inquiring target data from the database to be inquired based on the filled target template.
2. The method of claim 1, wherein determining the target template comprises:
obtaining statement vectors of the query statements described by the natural language and template vectors of all preset structured query language templates;
respectively calculating cosine similarity of the statement vector and each template vector;
and determining the structured query language template corresponding to the template vector with the maximum cosine similarity of the statement vector as the target template.
3. The method according to claim 1, wherein the filling of the target keywords and the filter item identifiers included in the target template based on the similarity between each word to be queried and each field in the database to be queried comprises:
calculating first similarity between each word to be queried and each field in the database to be queried;
and filling the target keywords and the screening item identifications contained in the target template based on the field with the maximum first similarity with each word to be queried.
4. The method according to claim 3, wherein the calculating a first similarity between each of the terms to be queried and each of the fields in the database to be queried comprises:
respectively obtaining word vectors corresponding to the words to be queried;
acquiring field vectors corresponding to all fields in the database to be queried;
and respectively calculating the first similarity of each field vector and each word vector.
5. The method of claim 1, wherein when an aggregation function is included in the query statement described in the natural language, the method further comprises:
filling target keywords and screening item identifications contained in the target template based on the similarity between each word to be queried and each aggregation function in a database to be queried; the words to be inquired are obtained by segmenting the words of the inquiry sentences described by the natural language.
6. The method according to claim 5, wherein the filling of the target keywords and the filter item identifiers included in the target template based on the similarity between each word to be queried and each aggregation function in the database to be queried comprises:
calculating second similarity of each word to be queried and each aggregation function in the database to be queried;
and filling the target key words and the screening item identifications contained in the target template based on the aggregation function with the maximum second similarity to the words to be inquired.
7. The method of claim 1 or 5, further comprising, prior to said determining a target template:
screening a structured query language template which meets the conditions of the preset template from each preset structured query language template so as to facilitate subsequent filling; wherein the preset template conditions include: the dimension of the structured query language template is less than or equal to 1 and/or the number of aggregation functions contained in the structured query language template is less than or equal to 1.
8. A data query apparatus, comprising:
the determining module is used for determining a target template;
the filling module is used for filling the target keywords and the screening item identifications contained in the target template based on the similarity between each word to be queried and each field in the database to be queried; the word to be queried is obtained by segmenting a query sentence described by a natural language;
and the query module is used for querying the target data from the database to be queried based on the filled target template.
9. An electronic device, comprising: memory, processor and computer program stored on the memory and executable on the processor, which computer program, when being executed by the processor, carries out the steps of the data query method as claimed in any of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the data query method as claimed in any one of claims 1 to 7.
CN201911264283.XA 2019-12-11 2019-12-11 Data query method and device and electronic equipment Pending CN111177180A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911264283.XA CN111177180A (en) 2019-12-11 2019-12-11 Data query method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911264283.XA CN111177180A (en) 2019-12-11 2019-12-11 Data query method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN111177180A true CN111177180A (en) 2020-05-19

Family

ID=70653815

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911264283.XA Pending CN111177180A (en) 2019-12-11 2019-12-11 Data query method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN111177180A (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112765424A (en) * 2021-01-29 2021-05-07 北京字节跳动网络技术有限公司 Data query method, device, equipment and computer readable medium
CN112860725A (en) * 2021-02-02 2021-05-28 浙江大华技术股份有限公司 SQL automatic generation method and device, storage medium and electronic equipment
CN113268537A (en) * 2021-06-23 2021-08-17 北京深度制耀科技有限公司 Genetic resource declaration writing method and device
CN113392124A (en) * 2021-06-15 2021-09-14 中国工商银行股份有限公司 Data query method and device based on structured language
CN113495900A (en) * 2021-08-12 2021-10-12 国家电网有限公司大数据中心 Method and device for acquiring structured query language sentences based on natural language
CN113986954A (en) * 2021-12-30 2022-01-28 深圳市明源云科技有限公司 User event acquisition method and device, intelligent terminal and readable storage medium
WO2022042288A1 (en) * 2020-08-31 2022-03-03 阿里巴巴集团控股有限公司 Data query method and apparatus
CN114253990A (en) * 2021-11-08 2022-03-29 广州广电运通信息科技有限公司 Database query method and device, computer equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180336198A1 (en) * 2017-05-18 2018-11-22 Salesforce.Com, Inc. Neural network based translation of natural language queries to database queries
CN108920543A (en) * 2018-06-13 2018-11-30 珠海格力电器股份有限公司 The method and device of inquiry and interaction, computer installation, storage medium
CN108959631A (en) * 2018-07-24 2018-12-07 北京百度网讯科技有限公司 Method and apparatus for query information
CN109542929A (en) * 2018-11-28 2019-03-29 山东工商学院 Voice inquiry method, device and electronic equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180336198A1 (en) * 2017-05-18 2018-11-22 Salesforce.Com, Inc. Neural network based translation of natural language queries to database queries
CN108920543A (en) * 2018-06-13 2018-11-30 珠海格力电器股份有限公司 The method and device of inquiry and interaction, computer installation, storage medium
CN108959631A (en) * 2018-07-24 2018-12-07 北京百度网讯科技有限公司 Method and apparatus for query information
CN109542929A (en) * 2018-11-28 2019-03-29 山东工商学院 Voice inquiry method, device and electronic equipment

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022042288A1 (en) * 2020-08-31 2022-03-03 阿里巴巴集团控股有限公司 Data query method and apparatus
CN112765424A (en) * 2021-01-29 2021-05-07 北京字节跳动网络技术有限公司 Data query method, device, equipment and computer readable medium
CN112765424B (en) * 2021-01-29 2023-10-10 抖音视界有限公司 Data query method, device, equipment and computer readable medium
CN112860725A (en) * 2021-02-02 2021-05-28 浙江大华技术股份有限公司 SQL automatic generation method and device, storage medium and electronic equipment
CN113392124A (en) * 2021-06-15 2021-09-14 中国工商银行股份有限公司 Data query method and device based on structured language
CN113392124B (en) * 2021-06-15 2024-03-22 中国工商银行股份有限公司 Structured language-based data query method and device
CN113268537A (en) * 2021-06-23 2021-08-17 北京深度制耀科技有限公司 Genetic resource declaration writing method and device
CN113495900A (en) * 2021-08-12 2021-10-12 国家电网有限公司大数据中心 Method and device for acquiring structured query language sentences based on natural language
CN113495900B (en) * 2021-08-12 2024-03-15 国家电网有限公司大数据中心 Method and device for obtaining structured query language statement based on natural language
CN114253990A (en) * 2021-11-08 2022-03-29 广州广电运通信息科技有限公司 Database query method and device, computer equipment and storage medium
CN113986954A (en) * 2021-12-30 2022-01-28 深圳市明源云科技有限公司 User event acquisition method and device, intelligent terminal and readable storage medium
CN113986954B (en) * 2021-12-30 2022-04-08 深圳市明源云科技有限公司 User event acquisition method and device, intelligent terminal and readable storage medium

Similar Documents

Publication Publication Date Title
CN111177180A (en) Data query method and device and electronic equipment
CN110795528B (en) Data query method and device, electronic equipment and storage medium
CN108632658B (en) Bullet screen display method and terminal
CN108494947B (en) Image sharing method and mobile terminal
CN109558512A (en) A kind of personalized recommendation method based on audio, device and mobile terminal
WO2021073478A1 (en) Bullet screen information recognition method, display method, server and electronic device
CN111222063A (en) Rich text rendering method and device, electronic equipment and storage medium
CN111339737B (en) Entity linking method, device, equipment and storage medium
CN111159338A (en) Malicious text detection method and device, electronic equipment and storage medium
CN108492836A (en) A kind of voice-based searching method, mobile terminal and storage medium
CN109495638B (en) Information display method and terminal
CN114357278B (en) Topic recommendation method, device and equipment
CN112269853A (en) Search processing method, search processing device and storage medium
CN110780793B (en) Tree menu construction method and device, electronic equipment and storage medium
CN110688497A (en) Resource information searching method and device, terminal equipment and storage medium
CN111399819A (en) Data generation method and device, electronic equipment and storage medium
WO2021147421A1 (en) Automatic question answering method and apparatus for man-machine interaction, and intelligent device
CN111125307A (en) Chat record query method and electronic equipment
CN113190646A (en) User name sample labeling method and device, electronic equipment and storage medium
CN111553163A (en) Text relevance determining method and device, storage medium and electronic equipment
CN110674294A (en) Similarity determination method and electronic equipment
CN114970562A (en) Semantic understanding method, device, medium and equipment
CN111062200B (en) Speaking generalization method, speaking recognition device and electronic equipment
CN110764668B (en) Comment information acquisition method and electronic equipment
CN108363781B (en) Picture sending method, terminal and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: No.27, 1st floor, building 14, Haidian Road, zhongjiancai District, Beijing 100096

Applicant after: Beijing PERCENT Technology Group Co.,Ltd.

Address before: 100096 101 / F, building 14, 27 Jiancai Middle Road, Haidian District, Beijing

Applicant before: BEIJING BAIFENDIAN INFORMATION SCIENCE & TECHNOLOGY Co.,Ltd.

RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20200519