RDF data query optimization method and device based on SPARQL

By converting the mixed query in the sparql query into nested and filtering sparql query, and rewritten into the multi -field results collection set operation of the relationship database, the existing SPARQL query system has low efficiency when processing multiple SPO query, realizing the realization The significant improvement of query speed and several times of performance.

CN119357227APending Publication Date: 2025-01-24TONGFANG KNOWLEDGE NETWORK DIGITAL PUBLISHING TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411565114.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-05
Publication Date
2025-01-24

AI Technical Summary

Technical Problem

When the existing SPARQL query system handles multiple SPO queries, it needs to traverse multiple data sets for connection operations, resulting in a significant reduction in query efficiency.

Method used

By converting the hybrid query in the sparql query into nested filtering sparql query, rewritten the intersection operation of the multi -field result set in the relationship database, and optimize the query process.

Benefits of technology

The query speed has been greatly improved, the performance is several times, and the statistical ability of the use of the relationship database has significantly improved the query efficiency of RDF data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357227A_ABST
    Figure CN119357227A_ABST
Patent Text Reader

Abstract

The invention discloses an SPARQL-based RDF data query optimization method and device, a storage medium and computer equipment, and the method comprises the steps: responding to a query instruction input by a user, analyzing the query instruction, and determining whether the query instruction is a query instruction in a mixed query mode or not; when the query instruction is the query instruction of the mixed query mode, generating an SPARQL query statement and an SQL query statement according to the query instruction; according to the SPARQL query statement, querying a matched target triple from an RDF database, and generating a first result set based on the unique identifier of the target triple; according to a preset mapping table between the RDF database and the relational database, converting the first result set into a second result set comprising a resource unique identifier; and querying from the relational database based on the SQL query statement and the second result set to obtain a resource attribute query result, and determining a final query result corresponding to the query instruction according to the resource attribute query result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a SPARQL-based RDF data query optimization method and device, storage medium, and computer equipment. Background Art

[0002] With the rapid development of information technology, RDF (Resource Description Framework) database has been widely used in knowledge graphs, semantic web and other fields as an effective way to represent and store data. The RDF data model uses triples (subject, predicate, object) to describe the properties and relationships of Web resources. This model can intuitively reflect the association between data. In order to match the RDF data model, W3C has also launched a standardized query language - SPARQL (Simple Protocol and RDF Query Language). SPARQL can be used to effectively query RDF data.

[0003] At present, RDF data is usually stored in relational databases or specialized RDF databases, and SPARQL queries are implemented through join operations. In practical applications, users often need to perform complex queries on data in RDF databases, such as multiple SPO (Subject-Predicate-Object) queries. When the current SPARQL query system handles multiple SPO queries, since the triples describing the attributes and relationships of Web resources may be distributed in different data sets in the database, when the query involves the association of multiple subjects or objects, the system needs to traverse different data sets in the database to find matching results, which usually involves join operations on multiple data sets, which often significantly reduces query efficiency. Summary of the invention

[0004] In view of this, the present application provides a SPARQL-based RDF data query optimization method and device, storage medium, and computer equipment, which optimizes the mixed query involving resource attributes and resource relationships in SPARQL queries by converting them into nested filtering SPARQL queries. This method rewrites SPARQL's multiple connection queries into intersection operations of multi-field result sets in relational databases, greatly improving the query speed and performance by several times. This optimization method first uses the RDF database to query the relationships between resources, and then retrieves the corresponding attributes of the resources from the relational data table based on these relationships. In this way, the powerful grouping and statistical capabilities of the relational database can be used to process the attributes of the target triples, which is several times faster than the native grouping and statistical capabilities of SPARQL, and can greatly improve the query efficiency of RDF data.

[0005] According to one aspect of the present application, a SPARQL-based RDF data query optimization method is provided, comprising:

[0006] In response to a query instruction input by a user, the query instruction is parsed to determine whether the query instruction is a query instruction of a hybrid query mode, wherein the query instruction is generated based on SPARQL, and the hybrid query mode is a query mode that includes both a resource attribute query and a resource relationship query;

[0007] When the query instruction is a query instruction of a mixed query mode, generating a SPARQL query statement and a SQL query statement according to the query instruction;

[0008] According to the SPARQL query statement, a matching target triple is searched from the RDF database, and a first result set is generated based on a unique identifier of the target triple, wherein the triple is used to indicate a resource relationship between different resources;

[0009] According to a preset mapping table between the RDF database and the relational database, converting the first result set into a second result set including a resource unique identifier;

[0010] Based on the SQL query statement and the second result set, a query is performed from the relational database to obtain a resource attribute query result, and a final query result corresponding to the query instruction is determined according to the resource attribute query result.

[0011] According to another aspect of the present application, a SPARQL-based RDF data query optimization device is provided, comprising:

[0012] An instruction parsing module, for parsing a query instruction input by a user, and determining whether the query instruction is a query instruction of a hybrid query mode, wherein the query instruction is generated based on SPARQL, and the hybrid query mode is a query mode that includes both resource attribute query and resource relationship query;

[0013] A query statement generating module, used for generating a SPARQL query statement and a SQL query statement according to the query instruction when the query instruction is a query instruction of a mixed query mode;

[0014] A first query module, configured to query a matching target triple from an RDF database according to the SPARQL query statement, and generate a first result set based on a unique identifier of the target triple, wherein the triple is used to indicate a resource relationship between different resources;

[0015] A result set conversion module, configured to convert the first result set into a second result set including a resource unique identifier according to a preset mapping table between the RDF database and the relational database;

[0016] The second query module is used to query the relational database based on the SQL query statement and the second result set to obtain a resource attribute query result, and determine a final query result corresponding to the query instruction according to the resource attribute query result.

[0017] According to another aspect of the present application, a storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the above-mentioned SPARQL-based RDF data query optimization method is implemented.

[0018] According to another aspect of the present application, a computer device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the above-mentioned SPARQL-based RDF data query optimization method when executing the program.

[0019] By means of the above technical scheme, the present application provides a SPARQL-based RDF data query optimization method and device, storage medium, and computer equipment, which, in response to the query instruction input by the user, parses the query instruction to determine whether it is a query instruction of a hybrid query mode. If the query instruction is found to be a query instruction of a hybrid query mode after analysis, then the corresponding SPARQL query statement and SQL query statement can be generated respectively according to the query instruction of the hybrid query mode. Further, the SPARQL query statement can be executed to query the matching target triple from the RDF database, and based on the unique identifier (such as URI, etc.) of the queried target triple, a first result set is generated. In order to further query the resource attributes according to the first result set, after obtaining the first result set, the triple unique identifier in the first result set can be converted into a resource unique identifier according to the preset mapping table to generate a second result set. Then, the SQL query statement can be executed to query the resource attribute data corresponding to the resource unique identifier in the second result set from the relational database, and the final query result corresponding to the query instruction is determined according to the queried resource attribute data. The embodiment of the present application optimizes the mixed query involving resource attributes and resource relationships in SPARQL query by converting it into a nested filtering SPARQL query. This method rewrites the multiple connection query of SPARQL into the intersection operation of multi-field result set in the relational database, which greatly improves the query speed and performance by several times. This optimization method first uses the RDF database to query the relationship between resources, and then retrieves the corresponding attributes of the resources from the relational data table based on these relationships. In this way, the powerful grouping and statistical capabilities of the relational database can be used to process the attributes of the target triples, which is several times faster than the native grouping and statistical capabilities of SPARQL, and can greatly improve the query efficiency of RDF data.

[0020] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0022] Figure 1 A schematic diagram of a process of optimizing a RDF data query based on SPARQL provided in an embodiment of the present application is shown;

[0023] Figure 2A schematic diagram showing a target processing result obtained after statistical grouping provided in an embodiment of the present application;

[0024] Figure 3 A schematic diagram showing a target processing result obtained after a sorting process provided by an embodiment of the present application;

[0025] Figure 4 A schematic diagram showing a target processing result obtained by statistical grouping and then sorting provided in an embodiment of the present application;

[0026] Figure 5 A schematic diagram of the structure of a SPARQL-based RDF data query optimization device provided in an embodiment of the present application is shown;

[0027] Figure 6 A schematic diagram of the device structure of a computer device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0028] The present application will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.

[0029] In this embodiment, a SPARQL-based RDF data query optimization method is provided. Figure 1 As shown, the method includes:

[0030] Step 101, in response to a query instruction input by a user, parse the query instruction to determine whether the query instruction is a hybrid query mode query instruction, wherein the query instruction is generated based on SPARQL, and the hybrid query mode is a query mode that includes both resource attribute query and resource relationship query.

[0031] A SPARQL-based RDF data query optimization method provided in an embodiment of the present application can be applied to an existing RDF database and can greatly improve the query speed of RDF data. When a user performs an RDF data query, he can enter a query requirement and then click a submit button to generate a query instruction. Here, the user can enter a SPARQL-based query requirement through a front-end interface or a command line tool. SPARQL is a standardized query language for RDF data query. Then, in response to the query instruction, the SPARQL query instruction input by the user can be parsed to determine whether it is a query instruction of a mixed query mode. A mixed query mode refers to a query mode that involves both resource attribute query (such as a specific attribute value of a resource) and resource relationship query (such as an association relationship between resources). In one embodiment, the process of parsing the query instruction can be implemented by regular expression matching or a SPARQL parser. If the query instruction contains query statements for querying resource attributes and querying resource relationships at the same time, the query instruction is determined to be a query instruction of a mixed query mode.

[0032] Step 102: When the query instruction is a query instruction in a mixed query mode, a SPARQL query statement and a SQL query statement are generated according to the query instruction.

[0033] In this embodiment, if it is found through analysis that the query instruction is a query instruction of a hybrid query mode, then corresponding SPARQL query statements and SQL query statements can be generated respectively according to the query instruction of the hybrid query mode. Among them, the SPARQL query statement is used to process the resource relationship query part, and the SQL query statement is used to process the resource attribute query part. Specifically, a SPARQL query generator can be used to generate a SPARQL query statement according to the resource relationship query part in the hybrid query instruction; according to the resource attribute query part in the hybrid query instruction, the corresponding SQL query statement is generated in combination with the table structure of the relational database. For example, if the query instruction is to query all attribute values ​​of a resource and other resources associated with it, the generated SPARQL query statement is used to query all triples related to the resource, and the generated SQL query statement is used to query the specific attribute values ​​of the resource in the relational database.

[0034] Step 103: According to the SPARQL query statement, a matching target triple is queried from the RDF database, and a first result set is generated based on a unique identifier of the target triple, wherein the triple is used to indicate a resource relationship between different resources.

[0035] In this embodiment, further, a SPARQL query engine can be used to execute a SPARQL query statement to query the RDF database for a matching target triple, and a first result set is generated based on a unique identifier (such as a URI, etc.) of the queried target triple. It should be noted that the RDF database pre-stores triples for indicating resource relationships between different resources.

[0036] Step 104: convert the first result set into a second result set including a resource unique identifier according to a preset mapping table between the RDF database and the relational database.

[0037] In this embodiment, a mapping table is pre-set between the resource relationship data stored in the RDF database and the resource attribute data stored in the relational database. In order to further query the resource attribute according to the first result set, after obtaining the first result set, the triple unique identifier in the first result set can be converted into a resource unique identifier according to the preset mapping table, and a second result set can be generated for subsequent SQL query.

[0038] Step 105: Based on the SQL query statement and the second result set, query is performed from the relational database to obtain a resource attribute query result, and a final query result corresponding to the query instruction is determined according to the resource attribute query result.

[0039] In this embodiment, the relational database query engine can then be used to execute an SQL query statement to query the resource attribute data corresponding to the resource unique identifier in the second result set from the relational database, and the final query result corresponding to the query instruction is determined based on the queried resource attribute data. Afterwards, the final query result can also be displayed on the front-end interface in a user-friendly manner, or output to the user in other forms (such as JSON, XML, etc.).

[0040] For example, a hybrid query instruction aims to query all books written by a specific author (such as "JK Rowling") and their ISBN numbers. The relationship between books (resource 1) and authors (resource 2) is stored in the RDF database, while the ISBN number (attribute) of books (resource 1) is stored in the relational database. According to the hybrid query instruction, a SPARQL query statement can be generated to query the matching target triples from the RDF database. For example, the SPARQL query statement can be similar to: "SELECT?book WHERE{?book:author'JK Rowling'}". At the same time, an SQL query statement is generated to query the ISBN number of the book from the relational database. Then, the generated SPARQL query statement is used to query the matching target triples from the RDF database. These target triples are used to indicate all books (objects) written (predicate) by the author JK Rowling (subject). Based on the unique identifiers of these target triples, a first result set can be generated. Afterwards, according to the preset mapping table between the RDF database and the relational database, the first result set is converted into a second result set including the unique identifier of the resource. It should be noted that the unique identifier of each target triplet can correspond to the resource unique identifiers of two resources, because each target triplet is used to indicate the relationship between two resources, which must involve two resources. Therefore, in the mapping table, each triplet unique identifier can correspond to the resource unique identifier of two resources. For example, in this embodiment, for a certain target triplet, the two resources are "JK Rowling" and "book p", where p can be any book written by JK Rowling. Then, the unique identifier of the target triplet can correspond to the unique identifier of "JK Rowling" and the unique identifier of "book p" in the mapping table. When executing SQL queries later, the SQL query statement can be used to further filter which resource unique identifier to use. For example, the SQL query statement indicates to query the ISBN number of the books written by JK Rowling. Therefore, the unique identifier of "book p" can be directly used to query the ISBN number of "book p" in the relational database. Finally, according to the results obtained from the query in the relational database, the final query result corresponding to the query instruction can be determined. This final result includes information such as the name and ISBN number of the book written by "JK Rowling".

[0041] By applying the technical solution of this embodiment, in response to the query instruction input by the user, the query instruction is parsed to determine whether it is a query instruction of a hybrid query mode. If it is found through analysis that the query instruction is a query instruction of a hybrid query mode, then the corresponding SPARQL query statement and SQL query statement can be generated respectively according to the query instruction of the hybrid query mode. Further, the SPARQL query statement can be executed to query the matching target triples from the RDF database, and based on the unique identifier (such as URI, etc.) of the queried target triples, a first result set is generated. In order to further query the resource attributes according to the first result set, after obtaining the first result set, the triple unique identifier in the first result set can be converted into a resource unique identifier according to the preset mapping table to generate a second result set. Then, the SQL query statement can be executed to query the resource attribute data corresponding to the resource unique identifier in the second result set from the relational database, and the final query result corresponding to the query instruction is determined according to the queried resource attribute data. The embodiment of the present application optimizes the mixed query involving resource attributes and resource relationships in SPARQL query by converting it into a nested filtering SPARQL query. This method rewrites the multiple connection query of SPARQL into the intersection operation of multi-field result set in the relational database, which greatly improves the query speed and performance by several times. This optimization method first uses the RDF database to query the relationship between resources, and then retrieves the corresponding attributes of the resources from the relational data table based on these relationships. In this way, the powerful grouping and statistical capabilities of the relational database can be used to process the attributes of the target triples, which is several times faster than the native grouping and statistical capabilities of SPARQL, and can greatly improve the query efficiency of RDF data.

[0042] In the embodiment of the present application, optionally, step 103 includes:

[0043] Step 103 - 1 , parsing the SPARQL query statement to determine all resource relationship query conditions contained in the SPARQL query statement.

[0044] In this embodiment, the SPARQL query statement is parsed to identify and extract all resource relationship query conditions. These resource relationship query conditions include a combination of a subject, a predicate, and an object. Each SPARQL query statement includes at least one resource relationship query condition.

[0045] In one embodiment, the SPARQL query statement can be parsed according to the following process. (1) Preprocessing: Preprocess the SPARQL query statement, such as removing blank characters, comments, etc., to ensure the neatness and readability of the statement. (2) Lexical analysis: Split the preprocessed SPARQL query statement into independent vocabulary units, such as keywords (such as SELECT, WHERE, FILTER, etc.), variables (such as ?x, ?y, etc., starting with a question mark), constants (such as strings, numbers, URIs, etc.) and special symbols (such as brackets, commas, etc.). (3) Syntax analysis: According to the grammatical rules of SPARQL, the vocabulary units obtained from the lexical analysis are combined into a grammatical structure to construct a syntax tree for the query statement. In the syntax tree, all basic graph patterns (Basic Graph Pattern, BGP) are identified and extracted. BGP is the core component of SPARQL query and defines the triple pattern that the query needs to match. (4) Extract resource relationship query conditions: Traverse the syntax tree, identify the BGP part, and extract the triples composed of subject, predicate and object from the BGP. These triples define the relationship between resources. (5) Verification and organization: Verify the extracted resource relationship query conditions to ensure that they conform to the syntax and semantic rules of SPARQL. After verification, the extracted resource relationship query conditions are organized to form a structured resource relationship query condition set for subsequent processing and use.

[0046] Step 103-2: for each resource relationship query condition, determine whether there is a first target triple matching the resource relationship query condition in the SPARQL cache space, and if there is a first target triple, add the unique identifier of the first target triple to the first sub-result set; otherwise, mark the resource relationship query condition.

[0047] In this embodiment, each resource relationship query condition is traversed, and the SPARQL cache space is searched to see whether there is a first target triple that completely matches the query condition. If a matching first target triple is found, its unique identifier is added to the first sub-result set; if a matching first target triple is not found, the resource relationship query condition is marked, for example, it is marked as "not cached". In this way, each resource relationship query condition that can determine the first target triple from the SPARQL cache space can add the unique identifier of the corresponding first target triple to the first sub-result set. Here, the cache matching process can significantly improve query efficiency, because reading data directly from the cache is much faster than reading data from the RDF database.

[0048] Step 103 - 3 , according to the marked resource relationship query condition, query the RDF database for a matching second target triple, and generate a second sub-result set based on the unique identifier of the second target triple.

[0049] In this embodiment, for those marked resource relationship query conditions, that is, resource relationship query conditions for which no first target triple is determined in the SPARQL cache space, corresponding query operations can be performed in the RDF database to find matching second target triples. The unique identifier of each found second target triple is added to the second result subset.

[0050] Step 103 - 4 : Generate a first result set according to the first sub-result set and the second sub-result set.

[0051] In this embodiment, further, the first sub-result set and the second sub-result set can be merged to generate a first result set containing all query results. The embodiment of the present application introduces a cache mechanism to cache the query results of historical resource relationship query conditions, and regularly clears the old cache according to the first-in-first-out (FIFO) principle. In this way, when the same resource relationship query condition is queried again, the cached results can be directly used, thereby improving the query performance several times. The embodiment of the present application optimizes the performance of SPARQL queries by combining the use of SPARQL cache space and RDF database, while improving efficiency and maintaining the integrity and accuracy of the query.

[0052] It should be noted that if each resource relationship query condition included in the SPARQL query statement can determine the corresponding first target triple in the SPARQL cache space, then if a resource relationship query condition that has not been marked is subsequently detected, the step of querying the second target triple can be skipped, and the first sub-result set can be directly used as the first result set. Alternatively, if each resource relationship query condition included in the SPARQL query statement cannot determine the corresponding first target triple in the SPARQL cache space, then all resource relationship query conditions are marked, and the first sub-result set is empty. Subsequently, the second target triple corresponding to each resource relationship query condition is queried in the RDF database, and a second sub-result set is generated based on the unique identifiers of these second target triples, and the second sub-result set is directly used as the first result set.

[0053] In the embodiment of the present application, optionally, after "when there is a first target triple", the method further includes: moving the first target triple to the front end of the linked list; after querying the RDF database for a matching second target triple, the method further includes: marking the second target triple using the marked resource relationship query condition, and storing the marked second target triple in the linked list of the SPARQL cache space.

[0054] In this embodiment, the SPARQL cache space is organized in the form of a linked list, and each node stores a triple. When the first target triple matching the resource relationship query condition is found in the linked list, the triple node is moved from its current position to the front of the linked list. The embodiment of the present application moves the most recently accessed triple to the front of the linked list, which can ensure that the most recently used data can be quickly accessed, thereby improving the cache hit efficiency.

[0055] In addition, after searching for matching second target triples from the RDF database, these second target triples can also be marked using the marked resource relationship query conditions. Specifically, the resource relationship query condition that hits the second target triple will mark it. Then, the marked second target triple is stored in the SPARQL cache space, which can be a new node in the linked list or a position that replaces an old node (if the cache space is full). The embodiment of the present application adds the newly queried triples to the cache, which can enable the cache to cover more query scenarios. At the same time, user queries often have the characteristic of periodically repeating the same query multiple times, thereby ensuring that the recently used data can be quickly accessed again, thereby improving the hit rate of future queries.

[0056] In an embodiment of the present application, optionally, the step 105 of "determining the final query result corresponding to the query instruction based on the resource attribute query result" includes: parsing the query instruction to determine whether there is query result processing information; when there is query result processing information, obtaining the target attribute value from the relational database according to the query result processing information and the second result set, and processing the resource attribute query result according to the target attribute value to obtain the target processing result, and using the target processing result as the final query result corresponding to the query instruction; when there is no query result processing information, directly using the resource attribute query result as the final query result corresponding to the query instruction.

[0057] In this embodiment, in step 101, there is already a step of parsing the query instruction, which is used to determine whether the query instruction is a query instruction of a mixed query mode. After obtaining the resource attribute query result, it can be further checked whether the query instruction contains query result processing information. Specifically, after obtaining the resource attribute query result, the query instruction input by the user can be parsed again to determine whether the resource attribute query result needs to be further processed. The query result processing information can be embedded in the query instruction in a specific syntax or tag form to indicate how to perform subsequent processing on the resource attribute query result. For example, the query result processing information can include operations such as sorting, filtering, and aggregation based on XX attributes. After determining that the query instruction contains query result processing information, the target attribute value can be obtained from the relational database based on the query result processing information and the second result set. After obtaining the target attribute value, the resource attribute query result can be processed using the target attribute value to generate a target processing result. The specific processing method depends on the type and content of the query result processing information. For example, assuming that the resource attribute query result includes the name, introduction, and publisher of each book written by author A, and the query result processing information requires that these books be classified according to the year attribute, then each book is classified according to the year, and the book's name, introduction, and publisher are also classified together. That is, after each book is classified, the resource attribute query results such as the book's name, introduction, and publisher are also attached. The result after this classification is the target processing result. After obtaining the target processing result, the target processing result can be used as the final query result.

[0058] If the query instruction does not contain query result processing information, the resource attribute query result is directly returned to the user as the final query result corresponding to the query instruction.

[0059] In an embodiment of the present application, optionally, when the query result processing information includes group statistical information, the "obtaining a target attribute value from the relational database according to the query result processing information and the second result set, and processing the resource attribute query result according to the target attribute value to obtain a target processing result" includes: determining a first target attribute on which the group statistics are based based on the group statistical information, and obtaining a first target attribute value corresponding to the first target attribute from the relational database according to the second result set; performing statistical processing on the resource attribute query result according to the first target attribute value, and using the statistical processing result as the target processing result.

[0060] In this embodiment, the query result processing information may include grouping statistical information. For example, the resource attribute query results of books are classified according to the year of the book, the author, etc. When the query result processing information includes grouping statistical information, the first target attribute, that is, the basis for the user to group, can be determined from the grouping statistical information. Subsequently, the first target attribute value corresponding to the first target attribute can be obtained from the relational database according to the second result set, and the resource attribute query result can be statistically processed according to the first target attribute value, so as to obtain the target processing result.

[0061] For example, suppose the SPARQL query statement indicates to query all products under the AA brand, the SQL query statement indicates to query the price of each of these products, and the query result processing information indicates to group by product category, and display the price of each product after grouping. Here, "product category" is the resource attribute (i.e., the first target attribute) on which the grouping is based, and the second result set includes the unique identifier (i.e., the resource unique identifier) ​​corresponding to each product under the AA brand. The first target attribute value is the specific attribute of the product corresponding to each resource unique identifier in the second result set, such as: clothing, luggage, shoes, hats, etc. Then, according to the first target attribute value, each product under the AA brand can be classified to obtain each product under the clothing, luggage, shoes, hats and other categories. The products under each category can be displayed collectively, and the price of each product is attached, so that the target processing result is obtained. Figure 2 As shown, a target processing result of an embodiment of the present application is shown.

[0062] The SPARQL-based RDF data query optimization method in the embodiment of the present application has significant advantages when processing query requirements containing grouped statistical information. The method can directly process the grouped statistical information during the query process and generate the statistical processing results required by the user, thereby simplifying the processing flow and improving the efficiency and accuracy of data processing. At the same time, the resource attribute query results that have been searched are grouped and counted by the resource attributes in the relational database, which can greatly improve the efficiency of grouped statistics compared to the method of first searching for triples and then performing grouped statistics.

[0063] In an embodiment of the present application, optionally, when the query result processing information includes result sorting information, the "obtaining a target attribute value from the relational database according to the query result processing information and the second result set, and processing the resource attribute query result according to the target attribute value to obtain a target processing result" includes: determining a second target attribute on which result sorting is based based on the result sorting information, and obtaining a second target attribute value corresponding to the second target attribute from the relational database according to the second result set; sorting the resource attribute query result according to the second target attribute value, and using the sorting result as the target processing result.

[0064] In this embodiment, the query result processing information may also include result sorting information. For example, the books are sorted according to the year of the books. When the query result processing information includes result sorting information, the second target attribute, that is, the basis for the user to sort, may be determined from the result sorting information. Subsequently, the second target attribute value corresponding to the second target attribute may be obtained from the relational database according to the second result set, and the resource attribute query result may be sorted according to the second target attribute value, thereby obtaining the target processing result.

[0065] For example, suppose the SPARQL query statement indicates to query all products under the AA brand, the SQL query statement indicates to query the price of each of these products, and the query result processing information indicates to sort by the release time of the products, and display the price of each product after sorting. Here, "product release time" is the attribute based on the sorting (i.e., the second target attribute), and the second result set includes the unique identifier corresponding to each product under the AA brand (i.e., the resource unique identifier). The second target attribute value is the specific attribute of the product corresponding to each resource unique identifier in the second result set, such as: 1990, 2000... and other years. Then, according to the second target attribute value, each product under the AA brand can be sorted, so as to obtain products sorted by year, and the price of each product is attached, so as to obtain the target processing result. Figure 3 As shown, a target processing result of an embodiment of the present application is shown.

[0066] In addition, the query result processing information can also include grouping statistics information and result sorting information. For example, the grouping statistics information indicates that AA brand products are grouped according to product categories, and the result sorting information indicates that the products contained in each group are sorted in order from high to low according to the product price. Then, the grouping statistics operation can be performed first, and then for each group, the result sorting operation can be performed within the group. Finally, the target processing result can be obtained. Figure 4 As shown, a target processing result provided by an embodiment of the present application is shown.

[0067] The SPARQL-based RDF data query optimization method in the embodiment of the present application also has significant advantages when processing query requirements including result sorting information. The method can directly process the result sorting information during the query process and generate the sorting processing results required by the user, thereby simplifying the processing flow and improving the efficiency and accuracy of data processing. At the same time, the resource attribute query results that have been searched are sorted by the resource attributes in the relational database, which can greatly improve the efficiency of result sorting compared to the method of first searching for triples and then sorting the results. The traditional method of first searching for triples and then sorting requires processing a large amount of intermediate data, and the sorting process consumes a large amount of computing resources. However, the present method can reduce the amount of intermediate data to be processed by directly processing the sorting information during the query process, thereby reducing resource consumption.

[0068] In an embodiment of the present application, optionally, before step 101, the method further includes: acquiring original RDF data, parsing the original RDF data, obtaining resource attribute data and resource relationship data corresponding to the original RDF data, storing the resource attribute data in the relational database, storing the resource relationship data in the form of triples in the RDF database, and establishing a mapping table between the resource attribute data and the resource relationship data.

[0069] In this embodiment, before receiving the query instruction input by the user, the original RDF data can be parsed to obtain resource attribute data and resource relationship data, so as to store the resource relationship data in the original RDF data in the RDF database and store the resource attribute data in the relationship database. Then the corresponding RDF data query optimization method is executed. Specifically, the original RDF data can be processed by the following steps. First, the original RDF data can be obtained. Here, the original RDF data can be data in the form of triples, but each resource in the triples also has attribute data. Afterwards, the received original RDF data is parsed and decomposed into resource attribute data and resource relationship data. Resource attribute data describes the specific attributes of resources, such as the name, price, release time, etc. of the product; resource relationship data describes the association relationship between resources, such as the association between products and categories, the association between people and works, etc.

[0070] Next, the parsed resource attribute data can be stored in a relational database. A relational database is a table-based database that can efficiently store and query structured data. In an embodiment of the present application, the resource attribute data is stored in a table in a relational database, where each attribute corresponds to a field and each resource corresponds to a record. For example, for product information, a database table named "Product Table" can be created, which contains fields such as product ID, product name, price, and release time. The parsed product attribute data can be filled into this table.

[0071] At the same time, the resource relationship data obtained by parsing can be stored in the RDF database in the form of triples. Triples are the basic units of RDF data, consisting of a subject, a predicate, and an object, and are used to describe the association relationship between resources. RDF database is a database specifically used to store and query RDF data. In an embodiment of the present application, resource relationship data is stored in a triple table of the RDF database, and each triple corresponds to a record. For example, for the association relationship between a commodity and a category, it can be stored as a triple (commodity ID, is, category ID). The resource relationship data obtained by parsing can be inserted into the RDF database in the form of triples.

[0072] In order to establish the association between resource attribute data and resource relationship data, a mapping table can also be established. The mapping table records the correspondence between the resource unique identifier in the resource attribute data and the triple unique identifier in the resource relationship data. Here, the mapping table can be a simple database table, including the following fields: resource unique identifier and triple unique identifier. It should be noted that each triple unique identifier can correspond to two resource unique identifiers. In one embodiment, the resource attribute data can be traversed to generate a unique identifier for each resource in all resources contained in the resource attribute data, and the resource relationship data can be traversed to generate a unique identifier for each triple in all triples contained in the resource relationship data, and then the resource unique identifier and the triple unique identifier are matched and stored in the mapping table. After obtaining the resource attribute data, the resource relationship data and the mapping table, the query instruction input by the user can be received to perform data query.

[0073] The embodiment of the present application can efficiently process the original RDF data, decompose it into resource attribute data and resource relationship data, and store them in the relational database and the RDF database respectively. At the same time, by establishing a mapping table, it is possible to easily establish the association between resource attribute data and resource relationship data, thereby supporting complex query requirements. This processing method can greatly improve the efficiency of data query and reduce the complexity of data query.

[0074] Further, as Figure 1 The specific implementation of the method, the embodiment of the present application provides an RDF data query optimization device based on SPARQL, such as Figure 5 As shown, the device comprises:

[0075] An instruction parsing module, for parsing a query instruction input by a user, and determining whether the query instruction is a query instruction of a hybrid query mode, wherein the query instruction is generated based on SPARQL, and the hybrid query mode is a query mode that includes both resource attribute query and resource relationship query;

[0076] A query statement generating module, used for generating a SPARQL query statement and a SQL query statement according to the query instruction when the query instruction is a query instruction of a mixed query mode;

[0077] A first query module, configured to query a matching target triple from an RDF database according to the SPARQL query statement, and generate a first result set based on a unique identifier of the target triple, wherein the triple is used to indicate a resource relationship between different resources;

[0078] A result set conversion module, configured to convert the first result set into a second result set including a resource unique identifier according to a preset mapping table between the RDF database and the relational database;

[0079] The second query module is used to query the relational database based on the SQL query statement and the second result set to obtain a resource attribute query result, and determine a final query result corresponding to the query instruction according to the resource attribute query result.

[0080] Optionally, the first query module is used to:

[0081] Parsing the SPARQL query statement to determine all resource relationship query conditions contained in the SPARQL query statement;

[0082] For each resource relationship query condition, determine whether there is a first target triple matching the resource relationship query condition in the SPARQL cache space, and if there is a first target triple, add the unique identifier of the first target triple to the first sub-result set; otherwise, mark the resource relationship query condition;

[0083] According to the marked resource relationship query condition, query the RDF database for a matching second target triple, and generate a second sub-result set based on the unique identifier of the second target triple;

[0084] A first result set is generated according to the first sub-result set and the second sub-result set.

[0085] Optionally, the device further comprises:

[0086] A moving module, used for moving the first target triplet to the front end of the linked list when the first target triplet exists;

[0087] The device also includes:

[0088] The storage module is used for marking the second target triples by using the marked resource relationship query conditions after querying the matching second target triples from the RDF database, and storing the marked second target triples in the linked list of the SPARQL cache space.

[0089] Optionally, the second query module is used to:

[0090] Parsing the query instruction to determine whether there is query result processing information;

[0091] When there is query result processing information, obtaining a target attribute value from the relational database according to the query result processing information and the second result set, and processing the resource attribute query result according to the target attribute value to obtain a target processing result, and using the target processing result as the final query result corresponding to the query instruction;

[0092] When there is no query result processing information, the resource attribute query result is directly used as the final query result corresponding to the query instruction.

[0093] Optionally, when the query result processing information includes group statistical information, the second query module is further used to:

[0094] Based on the grouping statistical information, determine a first target attribute on which the grouping statistics are based, and acquire a first target attribute value corresponding to the first target attribute from the relational database according to the second result set;

[0095] According to the first target attribute value, statistical processing is performed on the resource attribute query result, and the statistical processing result is used as the target processing result.

[0096] Optionally, when the query result processing information includes result sorting information, the second query module is further configured to:

[0097] Based on the result sorting information, determine a second target attribute on which the result sorting is based, and acquire a second target attribute value corresponding to the second target attribute from the relational database according to the second result set;

[0098] According to the second target attribute value, the resource attribute query result is sorted, and the sorting result is used as the target processing result.

[0099] Optionally, the instruction parsing module is further used to:

[0100] In response to a query instruction input by a user, before parsing the query instruction, original RDF data is acquired, the original RDF data is parsed to obtain resource attribute data and resource relationship data corresponding to the original RDF data, the resource attribute data is stored in the relational database, the resource relationship data is stored in the RDF database in the form of triples, and a mapping table between the resource attribute data and the resource relationship data is established.

[0101] It should be noted that for other corresponding descriptions of the functional units involved in the SPARQL-based RDF data query optimization device provided in the embodiment of the present application, please refer to Figures 1 to 4 The corresponding description in the method will not be repeated here.

[0102] The present application also provides a computer device, which may be a personal computer, a server, a network device, etc. Figure 6 As shown, the computer device includes a bus, a processor, a memory and a communication interface, and may also include an input and output interface and a display device. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store location information. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in each method embodiment are implemented.

[0103] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0104] In one embodiment, a computer-readable storage medium is provided. The computer-readable storage medium may be non-volatile or volatile, and stores a computer program thereon. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0105] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0106] 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, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.

[0107] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile 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), magnetoresistive 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. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0108] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, 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 specification.

[0109] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A SPARQL-based RDF data query optimization method, characterized in that: include: In response to a query instruction input by a user, the query instruction is parsed to determine whether the query instruction is a query instruction of a hybrid query mode, wherein the query instruction is generated based on SPARQL, and the hybrid query mode is a query mode that includes both a resource attribute query and a resource relationship query; When the query instruction is a query instruction of a mixed query mode, generating a SPARQL query statement and a SQL query statement according to the query instruction; According to the SPARQL query statement, a matching target triple is searched from the RDF database, and a first result set is generated based on a unique identifier of the target triple, wherein the triple is used to indicate a resource relationship between different resources; According to a preset mapping table between the RDF database and the relational database, converting the first result set into a second result set including a resource unique identifier; Based on the SQL query statement and the second result set, a query is performed from the relational database to obtain a resource attribute query result, and a final query result corresponding to the query instruction is determined according to the resource attribute query result.

2. The method according to claim 1, characterized in that The step of querying a matching target triple from an RDF database according to the SPARQL query statement, and generating a first result set based on a unique identifier of the target triple, includes: Parsing the SPARQL query statement to determine all resource relationship query conditions contained in the SPARQL query statement; For each resource relationship query condition, determine whether there is a first target triple matching the resource relationship query condition in the SPARQL cache space, and if there is a first target triple, add the unique identifier of the first target triple to the first sub-result set; otherwise, mark the resource relationship query condition; According to the marked resource relationship query condition, query the RDF database for a matching second target triple, and generate a second sub-result set based on the unique identifier of the second target triple; A first result set is generated according to the first sub-result set and the second sub-result set.

3. The method according to claim 2, characterized in that After the first target triple exists, the method further includes: Move the first target triple to the front end of the linked list; After querying the RDF database for a matching second target triple, the method further includes: The second target triple is marked using the marked resource relationship query condition, and the marked second target triple is stored in a linked list of the SPARQL cache space.

4. The method according to claim 1, characterized in that: The determining, according to the resource attribute query result, a final query result corresponding to the query instruction includes: Parsing the query instruction to determine whether there is query result processing information; When there is query result processing information, obtaining a target attribute value from the relational database according to the query result processing information and the second result set, and processing the resource attribute query result according to the target attribute value to obtain a target processing result, and using the target processing result as the final query result corresponding to the query instruction; When there is no query result processing information, the resource attribute query result is directly used as the final query result corresponding to the query instruction.

5. The method according to claim 4, characterized in that When the query result processing information includes group statistical information, acquiring a target attribute value from the relational database according to the query result processing information and the second result set, and processing the resource attribute query result according to the target attribute value to obtain a target processing result, including: Based on the grouping statistical information, determine a first target attribute on which the grouping statistics are based, and acquire a first target attribute value corresponding to the first target attribute from the relational database according to the second result set; According to the first target attribute value, statistical processing is performed on the resource attribute query result, and the statistical processing result is used as the target processing result.

6. The method according to claim 4 or 5, characterized in that: When the query result processing information includes result sorting information, acquiring a target attribute value from the relational database according to the query result processing information and the second result set, and processing the resource attribute query result according to the target attribute value to obtain a target processing result, including: Based on the result sorting information, determine a second target attribute on which the result sorting is based, and acquire a second target attribute value corresponding to the second target attribute from the relational database according to the second result set; According to the second target attribute value, the resource attribute query result is sorted, and the sorting result is used as the target processing result.

7. The method according to claim 1, characterized in that In response to the query instruction input by the user, before parsing the query instruction, the method further includes: Obtain original RDF data, parse the original RDF data to obtain resource attribute data and resource relationship data corresponding to the original RDF data, store the resource attribute data in the relational database, store the resource relationship data in the form of triples in the RDF database, and establish a mapping table between the resource attribute data and the resource relationship data.

8. A SPARQL-based RDF data query optimization device, characterized in that: include: An instruction parsing module, for parsing a query instruction input by a user, and determining whether the query instruction is a query instruction of a hybrid query mode, wherein the query instruction is generated based on SPARQL, and the hybrid query mode is a query mode that includes both resource attribute query and resource relationship query; A query statement generating module, used for generating a SPARQL query statement and a SQL query statement according to the query instruction when the query instruction is a query instruction of a mixed query mode; A first query module, configured to query a matching target triple from an RDF database according to the SPARQL query statement, and generate a first result set based on a unique identifier of the target triple, wherein the triple is used to indicate a resource relationship between different resources; A result set conversion module, configured to convert the first result set into a second result set including a resource unique identifier according to a preset mapping table between the RDF database and the relational database; The second query module is used to query the relational database based on the SQL query statement and the second result set to obtain a resource attribute query result, and determine a final query result corresponding to the query instruction according to the resource attribute query result.

9. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

10. A computer device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Measurement data query load balancing optimization method and system based on data popularity evaluation

    CN121051276A