A temporal RDF storage and query method based on relational database PostgreSQL

By analyzing and storing temporal RDF data in the PostgreSQL database, we solve the problems of temporal information representation object positioning and data management, achieve efficient temporal RDF data storage and query, maintain semantic consistency, and provide temporal knowledge graph management. Possible methods are provided.

CN114579672BActive Publication Date: 2024-10-29NANJING UNIV OF AERONAUTICS & ASTRONAUTICS
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210027086.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-11
Publication Date
2024-10-29
Estimated Expiration
2042-01-11

AI Technical Summary

Technical Problem

Existing temporal RDF models lack accurate positioning of temporal information representation objects, and existing RDF data management solutions are difficult to effectively store and query temporal RDF data.

Method used

Design a temporal RDF storage and query method based on the relational database PostgreSQL. Through the temporal RDF model that selectively adds timestamps to the object type, the management of temporal RDF data is completed in two steps: first, analyze and obtain temporal information. and the specific content of the triple. The second step is to create a temporal database that meets the requirements in PostgreSQL, and use SQL statements for data storage and query.

Benefits of technology

It achieves efficient temporal RDF data storage and query, reduces the space occupied by temporal RDF data, maintains the semantic consistency of temporal RDF, and provides a feasible method for temporal knowledge graph management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114579672B_ABST
    Figure CN114579672B_ABST
Patent Text Reader

Abstract

The present invention discloses a temporal RDF storage and query method based on a relational database PostgreSQL, comprising: for a traditional RDF data, converting it into temporal RDF data, for the obtained temporal RDF data, dividing its subject, predicate and object into prefix, subject without prefix, predicate without prefix, object without prefix and temporal information; constructing a database temporal table; inserting the above data into the constructed database temporal table; using SQL statements to query the data in the database temporal table. The present invention creatively uses the relational database PostgreSQL in combination with the concept of temporal database to store temporal RDF data, and uses mature SQL statements to manage temporal RDF data. The present invention reduces the space occupied by temporal RDF data, maintains the semantic consistency of temporal RDF, and provides a feasible method for managing temporal knowledge graphs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of temporal knowledge graph storage and query, and in particular to a temporal RDF storage and query method based on a relational database PostgreSQL. Background Art

[0002] Everything in the world is in constant motion, and resources on the Web are also changing over time. Therefore, temporal attributes have become an important attribute for describing the dynamic changes of resources during development. Data carrying temporal attributes is called temporal data. With the massive increase of temporal data on the Internet, the concept of temporal knowledge graph has gradually become popular. The RDF model can effectively represent traditional knowledge graphs, but because it can only represent static semantics, it cannot represent and manage temporal knowledge graphs well. Therefore, the temporal RDF model has been widely studied.

[0003] First, there is no unified standard for temporal RDF models at this stage, so choosing an appropriate temporal RDF model is very important for the management of temporal knowledge graphs. Existing temporal RDF models mainly use the time labeling method to add timestamp information to traditional triples to form the corresponding temporal RDF model. The widely used temporal RDF models are divided into the following two types according to the location of the timestamp: (1) the timestamp is attached to the triple; (2) the timestamp is attached to the predicate. Although the existing model can effectively represent temporal RDF, it lacks accurate positioning of the object represented by the temporal information, and there is still room for improvement.

[0004] Secondly, the management of knowledge graphs is the management of their representation form, RDF data. This concept is also applicable in the field of temporal knowledge graphs. Although the storage and query research of traditional RDF data is relatively mature, how to effectively store and query temporal RDF data is still a problem that needs to be solved. The existing RDF data management solutions mainly include the following three methods: (1) memory-based storage; (2) file-based; (3) database-based. Among them, database technology is widely used because of its mature technology and strong data management capabilities. Although existing technologies can already manage RDF data efficiently, temporal RDF is essentially different from traditional RDF data. Temporal RDF attaches temporal information to triples in the form of timestamps. How to process this temporal information becomes a difficulty in managing temporal RDF data. Summary of the invention

[0005] In view of this, the purpose of the present invention is to provide a temporal RDF storage and query method based on the relational database PostgreSQL to solve the technical problems mentioned in the background technology. The present invention designs temporal RDF model data that selectively adds timestamps based on object types, and uses the mature relational database product PostgreSQL, combined with the concept of temporal database, to complete the management of temporal RDF data in two steps: first, analyze the temporal RDF data to obtain the temporal information and triple specific content therein; then perform temporal expansion on PostgreSQL to create a temporal database that meets the requirements, and store the data obtained in the first step therein. The present invention uses a new temporal RDF model to efficiently represent the temporal knowledge graph, and relies on the powerful data management capabilities of SQL statements to complete the effective storage and query of temporal RDF data, which can be applied to semantic web applications, temporal knowledge graph management and other fields.

[0006] In order to achieve the above object, the present invention adopts the following technical solution:

[0007] A temporal RDF storage and query method based on a relational database PostgreSQL, the method comprising the following steps:

[0008] Step S1: converting a traditional RDF data into temporal RDF data, wherein the object in the triple is judged to be a resource or a literal. If it is a resource, a timestamp is attached to the predicate; if it is a literal, a timestamp is attached to the object.

[0009] Step S2: for the temporal RDF data obtained in step S1, the subject, predicate and object are divided into a prefix, a subject without a prefix, a predicate without a prefix, an object without a prefix and temporal information, wherein the temporal information includes a start time and an end time;

[0010] Step S3, constructing a database temporal table, which includes a namespace table, a subject table, a predicate table, an object table and a declaration table;

[0011] Step S4, inserting the prefix, the subject without the prefix, the predicate without the prefix, the object without the prefix, and the temporal information obtained in step S2 into the database temporal table constructed in step S2;

[0012] Step S5: Use SQL statements to query the data in the temporal table of the database.

[0013] Furthermore, in the step S1, the timestamp is designed based on the closed-open cycle model proposed in SQL:2011, and its format is [Ts, Te)(Ts≤Te), wherein Ts and Te represent the start time and the end time respectively.

[0014] Furthermore, the step S2 specifically includes:

[0015] Step S201: for temporal RDF data, obtain the subject, predicate and object in its temporal RDF triples;

[0016] Step S202, converting the subject, predicate and object into character string formats respectively;

[0017] Step S203, according to the type of the object, respectively separate the tense information Ts and Te from the predicate and the object, which specifically includes:

[0018] When the object is a resource, obtain the predicate after stripping the tense information, then obtain the time interval, and then extract the start time Ts and end time Te of the time interval;

[0019] When the object is a literal quantity, obtain the object after stripping the tense information, then obtain the time interval, and then extract the start time Ts and end time Te of the time interval;

[0020] Step S204: After the tense information is segmented, the prefixes of the subject, predicate and object are segmented to obtain the subject ES, predicate EP and object EO without the prefix, and the corresponding prefixes.

[0021] Further, in the step S3, the namespace table stores prefixes of triples and provides prefix corresponding IDs for the subject table, predicate table and object table;

[0022] The subject table stores subjects without prefixes and corresponding IDs of prefixes, and provides subject corresponding IDs for the declaration table;

[0023] The predicate table stores the predicates without prefixes and the corresponding IDs of the prefixes, and when the object is a resource, stores the start time Ts and the end time Te of the timestamp, and also provides the corresponding IDs of the predicates for the declaration table;

[0024] The object table stores objects without prefixes and corresponding IDs of prefixes, and when the object is a literal, stores the start time Ts and end time Te of the timestamp, and also provides the object corresponding ID for the declaration table;

[0025] The declaration table represents the temporal RDF triples by storing the IDs corresponding to the subject, predicate and object provided by the subject table, the predicate table and the object table.

[0026] Furthermore, the namespace table includes a primary key ID and a Prefix column. The namespace table is linked to the subject table, the predicate table and the object table through the primary key ID, and the prefix is ​​stored in the Prefix column, wherein the Prefix column is allowed to be empty;

[0027] The subject table includes a primary key ID, a foreign key NS_ID and a Resource column. The subject table is associated with the declaration table through the primary key ID column, wherein the NS_ID column is used as a foreign key to reference the ID corresponding to the prefix of the subject in the namespace table, and the Resource column is used to store subjects without prefixes;

[0028] The predicate table includes a primary key ID, a foreign key NS_ID, a Property, a PTs and a PTe column. The predicate table is associated with the declaration table through the primary key ID, wherein the NS_ID column is used as a foreign key to reference the ID corresponding to the prefix of the predicate in the namespace table, the Property column stores the predicate without the prefix, and when the object is a resource, the PTs and PTe columns store the start and end time of the temporal information respectively, and when the object is a literal, the PTs and PTe columns are allowed to be empty;

[0029] The object table includes a primary key ID, a foreign key NS_ID, an Object, an OTs and an OTe column. The object table is associated with the declaration table through the primary key ID, wherein the NS_ID column is used as a foreign key to implement a reference to the ID of the prefix of the object in the namespace table, and when the object is a literal, the NS_ID column corresponds to the ID representing an empty prefix in the namespace table, the Object column is used to store objects without prefixes, when the object is a resource, the OTs and OTe columns are allowed to be empty, and when the object is a literal, the OTs and OTe columns represent the start and end time of the temporal information;

[0030] The declaration table includes primary key ID, foreign key Sid, foreign key Pid and foreign key Oid columns. The declaration table uses foreign keys Sid, Pid and Oid to reference the IDs corresponding to the subject, predicate and object in the subject table, predicate table and object table.

[0031] Further, in step S4, the prefix, the subject without the prefix, the predicate without the prefix, the object without the prefix, and the time information are inserted into the database temporal table constructed in step S2 based on a storage mapping method, and the storage mapping method specifically includes:

[0032] Step S401: insert the prefix into the Prefix column of the namespace table, wherein when the object is a literal, the Prefix column is allowed to be empty;

[0033] Step S402: insert the prefix ID and the corresponding subject ES in the namespace table obtained in step S401 into the NS_ID and Resource columns of the subject table respectively, wherein the ID corresponding to each record is referenced by the declaration table as the primary key;

[0034] Step S403, insert the prefix ID and the corresponding predicate EP in the namespace table obtained in step S401 into the NS_ID and Property columns of the predicate table respectively, wherein when the object is a resource, the time information Ts and Te are inserted into the PTs and PTe columns of the predicate table, and the ID corresponding to each record is referenced by the declaration table as the primary key;

[0035] Step S404: insert the prefix ID and the corresponding object EO in the namespace table obtained in step S401 into the NS_ID and Object columns of the object table respectively, wherein when the object is a literal, insert the time information Ts and Te into the OTs and OTe columns of the object table, and the ID corresponding to each record is referenced by the declaration table as the primary key;

[0036] Step S405: insert the corresponding IDs of the subject, predicate and object of each temporal RDF triple obtained in steps S402, S403 and S404 into the Sid, Pid and Oid columns of the declaration table.

[0037] The beneficial effects of the present invention are:

[0038] The present invention creatively uses the relational database PostgreSQL combined with the concept of temporal database to store temporal RDF data, and uses mature SQL statements to manage temporal RDF data. The present invention reduces the space occupied by temporal RDF data, maintains the semantic consistency of temporal RDF, and provides a feasible method for managing temporal knowledge graphs. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 This is a schematic diagram of a model of temporal RDF data provided in Example 1;

[0040] Figure 2 A schematic diagram of a flow chart of a temporal RDF storage and query method based on a relational database PostgreSQL provided in Example 1;

[0041] Figure 3 The temporal database entity relationship diagram provided in Example 1;

[0042] Figure 4 This is a schematic diagram of the result after executing the query operation provided in Example 1. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0044] Example 1

[0045] See also Figure 1-Figure 4 In this embodiment, a temporal RDF storage and query method based on the relational database PostgreSQL is provided. Specifically, in this embodiment, for example Figure 1 The temporal RDF data shown in FIG. 1 is used to perform the temporal RDF storage and query method based on the relational database PostgreSQL. The specific process is as follows: Figure 2 As shown, the specific process includes three parts: data analysis, data storage and data query. More specifically, first, in the data analysis part, since RDF data cannot be directly stored in PostgreSQL, it is necessary to analyze it to obtain the subject, predicate and object of the temporal RDF triple. Then, the analyzed data is processed separately according to whether the type of the object is a resource or a literal. The subject, predicate and object are divided into a prefix N, a subject ES without a prefix, a predicate EP without a prefix, an object EO without a prefix, and time information Ts and Te. Then, in the data storage part, N, ES, EP, EO, Ts and Te are stored in the database PostgreSQL, where the entity relationships in the database are as shown in the attached figure. Figure 3 Finally, in the data query part, use SQL statements to query the data, and the query results are shown in the attached Figure 4 As shown, it can be seen that the present invention maintains the semantic consistency of data well.

[0046] Specifically, in this embodiment, the above-mentioned temporal RDF storage and query method based on the relational database PostgreSQL specifically includes the following steps:

[0047] Step 1: Construct a temporal RDF data model, including:

[0048] In order to better represent the temporal knowledge graph, the temporal RDF model used in this embodiment is detailed as follows:

[0049] 1. The timestamp is designed based on the closed-open cycle model proposed in SQL:2011. The format is [Ts, Te)(Ts≤Te), where Ts and Te represent the start and end of the valid time respectively. The format is "yyyy-MM-dd", which means a specific year, month and day.

[0050] 2. When Ts = Te, the time interval represents a point in time, as shown in the attached Figure 1 The timestamps corresponding to the personal birth date, birth place, death date and death place of Márton_Garas are all in the format of Ts=Te;

[0051] 3. When the object is a resource, the timestamp is attached to the predicate;

[0052] 4. When the object is a literal, the timestamp is attached to the object.

[0053] Step 2: Analyze the temporal RDF data model constructed in step 1, including:

[0054] For the temporal RDF data used, we first need to analyze it and split the subject, predicate and object obtained from the temporal RDF triple into prefix N, subject ES without prefix, predicate EP without prefix, object EO without prefix and time information Ts and Te.

[0055] The specific implementation algorithm of this process is:

[0056] 1 Input: Temporal RDF dataset

[0057] 2 Output: prefix N, prefix-free subject ES, prefix-free predicate EP, prefix-free object EO, tense information start time Ts and end time Te

[0058] / / First, obtain the subject, predicate and object of each temporal RDF triple through the analysis module.

[0059] 3while(iter.hasNext())do

[0060] 4 String subject = stmt.getSubject().toString(); / / Get the subject and convert it to string format

[0061] 5 Stringpredicate = stmt.getPredicate().toString(); / / Get the predicate and convert it to string format

[0062] 6 RDFNodeobjectN = stmt.getObject(); / / Get the object

[0063] 7 Srting object = objectN.toString(); / / Object converted to string format

[0064] / / Secondly, according to the type of the object, separate the tense information Ts and Te from the predicate and the object respectively.

[0065] / / When the object is a resource

[0066] 8 IfobjectNinstanceofResource then

[0067] 9 String predicate1 = predicate.substring (0, predicate.indexOf ("[")); / / Get the predicate after stripping the tense information

[0068] 10 String T = predicate.substring(predicate.indexOf("[")+1,predicate.length()-1); / / Get the time interval

[0069] 11 ts=T.substring(0,T.indexOf(",")); / / Get the start time of the time interval Ts

[0070] 12 te=T.substring(T.indexOf(",")+1,T.length()); / / Get the end time of the time interval Te

[0071] / / When the object is a literal, the tense information will be stripped from the object. The operation is similar to the above content and will not be repeated here.

[0072] 13 If objectNinstanceof Literal then

[0073] …

[0074] / / Finally, the subject, predicate and object of the temporal RDF triples processed above are segmented to obtain the corresponding prefixes and prefix-free subject ES, predicate EP and object EO. ​​The following takes the subject as an example. The operations on the predicate and object are similar and will not be repeated here.

[0075] 14 String[]S=subject.split(" / ");

[0076] 15 easyS = S[S.length-1]; / / Get the subject without prefix

[0077] 16 regexS = " / " + easyS;

[0078] 17 namespaceS = subject.substring(0, subject.indexOf(regexS)); / / Get the prefix

[0079] …

[0080] End

[0081] Step 3: Build the database temporal table, including:

[0082] Specifically, in this embodiment, the following five tables are established in combination with the temporal table concept proposed in SQL:2011:

[0083] Namespace table: stores the prefix URI of triples; provides prefix corresponding IDs for the subject table, predicate table, and object table.

[0084] Subject table: stores the subjects without prefixes in temporal RDF triples and the corresponding IDs of the prefixes; provides the corresponding IDs of the subjects for the declaration table.

[0085] Predicate table: stores the predicates without prefixes of temporal RDF triples and the corresponding IDs of prefixes; when the object is a resource, it uses its own temporal table characteristics to store the start time Ts and end time Te of the timestamp; provides the corresponding ID of the predicate for the declaration table.

[0086] Object table: stores the object without prefix of temporal RDF triples and the corresponding ID of the prefix; when the object is a literal, it uses its own temporal table characteristics to store the start time Ts and end time Te of the timestamp; provides the corresponding ID of the object for the declaration table.

[0087] Declaration table: represents the temporal RDF triples by storing the IDs corresponding to the subject, predicate and object provided by the subject table, predicate table and object table.

[0088] More specifically, in this embodiment, the specific structures of the above five tables are:

[0089] Namespace table: It consists of the primary key ID and the Prefix column, and is used to store the prefix of the entity resource in the temporal RDF triple. Since there are a large number of repeated URIs in temporal RDF data, separating the URI from the subject, predicate, and object helps save space. The namespace table is linked to the subject table, predicate table, and object table through the primary key ID, and the URI is stored in the Prefix column. The Prefix column can be empty.

[0090] Subject table: It consists of primary key ID, foreign key NS_ID and Resource columns, and is used to store the subject part of the temporal RDF triple. The subject table is associated with the declaration table through the primary key ID column; the NS_ID column is used as a foreign key to reference the ID corresponding to the subject prefix in the namespace table; the Resource column is used to store subjects without prefixes.

[0091] Predicate table: It consists of primary key ID, foreign key NS_ID, Property, PTs and PTe columns, and is used to store the predicate part of the temporal RDF triple. The predicate table is associated with the declaration table through the primary key ID; the NS_ID column is used as a foreign key to reference the ID corresponding to the prefix of the predicate in the namespace table; the Property column stores the predicate without a prefix; when the object is a resource, the PTs and PTe columns store the start and end time of the temporal information respectively; when the object is a literal, the PTs and PTe columns are allowed to be empty.

[0092] Object table: It consists of primary key ID, foreign key NS_ID, Object, OTs and OTe columns. It is used to store the object part of the temporal RDF triple and is associated with the declaration table through the primary key ID. The NS_ID column is used as a foreign key to reference the ID of the object's prefix in the namespace table. When the object is a literal, the NS_ID column corresponds to the ID representing an empty prefix in the namespace table. The Object column is used to store objects without prefixes. When the object is a resource, the OTs and OTe columns are allowed to be empty; when the object is a literal, the OTs and OTe columns represent the start and end time of the temporal information.

[0093] Declaration table: It consists of primary key ID, foreign key Sid, foreign key Pid, ​​and foreign key Oid columns, and uses integers to store declarations of temporal RDF triples. The declaration table uses foreign keys Sid, Pid, ​​and Oid to reference the IDs corresponding to the temporal RDF triple subject, predicate, and object in the subject table, predicate table, and object table.

[0094] Step 4: Use SQL language to implement storage query management, including:

[0095] Specifically, in this embodiment, the data obtained by the analysis in step 2 is inserted into the database table created in (3) according to the following mapping rules using the SQL language, including:

[0096] Rule 1: Insert the prefix N into the Prefix column of the namespace table. Note that when the object is a literal, Prefix is ​​allowed to be empty according to the structure of the namespace table.

[0097] Rule 2: Insert the prefix ID and the corresponding simple subject ES in the namespace table obtained by rule 1 into the NS_ID and Resource columns of the subject table respectively. The ID corresponding to each record is referenced by the declaration table as the primary key.

[0098] Rule 3: Insert the prefix ID and the corresponding simple predicate EP in the namespace table obtained by Rule 1 into the NS_ID and Property columns of the predicate table respectively. When the object is a resource, insert the time information Ts and Te into the PTs and PTe columns of the predicate table. The ID corresponding to each record is referenced by the declaration table as the primary key.

[0099] Rule 4: Insert the prefix ID and the corresponding simple object EO in the namespace table obtained by Rule 1 into the NS_ID and Object columns of the object table respectively. When the object is a literal, insert the time information Ts and Te into the OTs and OTe columns of the object table. The ID corresponding to each record is referenced by the declaration table as the primary key.

[0100] Rule 5: When rules 3 and 4 involve time information operations, SQL:2011 will automatically discard, merge, overwrite, and insert data based on time intervals.

[0101] Rule 6: Insert the corresponding IDs of the subject, predicate, and object of each temporal RDF triple returned by Rules 2, 3, and 4 into the Sid, Pid, ​​and Oid columns of the declaration table.

[0102] More specifically, the specific implementation algorithm of the above process is:

[0103] 1 Input: The parts of the temporal RDF triples obtained by the analysis module (Ns, ES, EP, EO, Ts and Te)

[0104] 2 Output: Data in PostgreSQL database

[0105] / / First, store the subject part of the temporal RDF triple. The first step is to determine whether the subject prefix already exists in the namespace table. If not, store it in the namespace table.

[0106] 3 String sqlQ="select*from namespace where prefix=""+namespace+"'";

[0107] 4 If(resultSet.next()!=true)then

[0108] 5 String sqlInsertNamespace="INSERT INTO namespace(prefix)VALUES(?);";

[0109] 6 String sqlID="select id from namespace where prefix=""+namespace+"'";

[0110] / / The second step is to store the corresponding ID of the prefix in the namespace table and the simple subject ES without a prefix in the NS_ID and Resource columns of the subject table respectively (it is necessary to determine whether the subject table contains the record), and return the ID corresponding to the record for use in the declaration table.

[0111] 7 String sqlR="select*from subject where resource=""+ES+"'and ns_id=""+NS_ID+"'";

[0112] 8 If(resultSet.next()!=true)then

[0113] 9 String sqlInsertsubject="INSERT INTO subject(ns_id,resource)VALUES(?,?);";

[0114] 10 String sqlSID="select id from subject where resource=""+ES+"'andns_id=""+NS_ID+"'";

[0115] / / Secondly, store the predicate part of the temporal RDF triple, which needs to be processed differently according to the type of the object. When the object is a literal, the storage operation of the predicate part is similar to the above subject storage method, which will not be repeated here; when the object is a resource, the temporal information carried by the predicate needs to be stored, and the specific implementation method is as follows.

[0116] 11 Ifobject is resource then

[0117] / / The first step is to store the prefix of the predicate into the namespace table. The specific operation is similar to that of processing the subject prefix, so I will not go into details here.

[0118] / / The second step is to store the corresponding ID of the prefix in the namespace table, the simple predicate EP without prefix, the start time Ts and the end time Te of the temporal information into the NS_ID, Property, PTs and PTe columns of the predicate table respectively (it is necessary to determine whether the predicate table contains the record), and return the ID corresponding to the record for use in the declaration table.

[0119] 12 String sqlP="select*from property where property='"+EP+"'and ns_id='"+P_ID+"'and(pts<='"+Te+"'or pte>='"+Ts+"')";

[0120] 13 If(resultSet.next()!=true)then

[0121] 14 String sqlInsertproperty="INSERT INTO property(ns_id,property,pts,pts)VALUES(?,?,?,?);";

[0122] 15 String sqlPID="select id from property where property="'"+EP+"'and ns_id="'"+P_ID+"'and(pts<='"+Te+"'or pte>="'"+Ts+"')";

[0123] / / Next, store the object part of the temporal RDF. This part is similar to the storage operation of the predicate, and also needs to be processed differently according to the type of the object. When the object is a resource, the storage operation of the object part is similar to the above-mentioned subject storage method, which will not be repeated here; when the object is a literal, the storage operation of the object part is similar to the above-mentioned storage method for the predicate carrying tense information, which will not be repeated here.

[0124] / / Finally, store the corresponding IDs of the subject, predicate and object of the temporal RDF triple in the subject table, predicate table and object table into the Sid, Pid and Oid of the declaration table.

[0125] 16 String sqlID="select id from statement where sid="'"+Sid+"'andpid="'"+Pid+"'and oid="'"+Oid+"'";

[0126] 17 if(resultSet.next()!=true)then

[0127] 18 String sqlInsertstatement="INSERT INTO statement(sid,pid,oid)VALUES(?,?,?);";

[0128] Finally, the data in the database can be queried using SQL statements. This method supports traditional database query languages ​​and can also use temporal language queries supported by SQL:2011. The data query results are shown in the attached Figure 4 As shown. Figure 4 It can be seen that this method effectively stores temporal RDF data, retains the original semantics of temporal RDF triples, and ensures data consistency. In addition, this method eliminates the space consumption caused by repeated prefixes and uses integers to save each statement of the temporal RDF model, greatly improving the storage and query efficiency of temporal RDF.

[0129] In summary, the present invention creatively uses the relational database PostgreSQL combined with the concept of temporal database to store temporal RDF data, and uses mature SQL statements to manage temporal RDF data. The present invention reduces the space occupied by temporal RDF data, maintains the semantic consistency of temporal RDF, and provides a feasible method for managing temporal knowledge graphs.

[0130] The matters not described in detail in the present invention are all known technologies to those skilled in the art.

[0131] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.

Claims

1. A temporal RDF storage and query method based on the relational database PostgreSQL, characterized in that: The method comprises the following steps: Step S1: converting a traditional RDF data into temporal RDF data, wherein the object in the triple is judged to be a resource or a literal. If it is a resource, a timestamp is attached to the predicate; if it is a literal, a timestamp is attached to the object. Step S2: for the temporal RDF data obtained in step S1, the subject, predicate and object are divided into a prefix, a subject without a prefix, a predicate without a prefix, an object without a prefix and temporal information, wherein the temporal information includes a start time and an end time; Step S3, constructing a database temporal table, which includes a namespace table, a subject table, a predicate table, an object table and a declaration table; Step S4, inserting the prefix, the subject without the prefix, the predicate without the prefix, the object without the prefix, and the temporal information obtained in step S2 into the database temporal table constructed in step S2; Step S5: Use SQL statements to query the data in the database temporal table; In the step S3, the namespace table stores prefixes of triples and provides prefix corresponding IDs for the subject table, predicate table and object table; The subject table stores subjects without prefixes and corresponding IDs of prefixes, and provides subject corresponding IDs for the declaration table; The predicate table stores the predicates without prefixes and the corresponding IDs of the prefixes, and when the object is a resource, stores the start time Ts and the end time Te of the timestamp, and also provides the corresponding IDs of the predicates for the declaration table; The object table stores objects without prefixes and corresponding IDs of prefixes, and when the object is a literal, stores the start time Ts and end time Te of the timestamp, and also provides the object corresponding ID for the declaration table; The declaration table represents the temporal RDF triples by storing IDs corresponding to the subject, predicate and object provided by the subject table, the predicate table and the object table; The namespace table includes a primary key ID and a Prefix column. The namespace table is linked to the subject table, the predicate table and the object table through the primary key ID, and the prefix is ​​stored in the Prefix column, wherein the Prefix column is allowed to be empty; The subject table includes a primary key ID, a foreign key NS_ID and a Resource column. The subject table is associated with the declaration table through the primary key ID column, wherein the NS_ID column is used as a foreign key to reference the ID corresponding to the prefix of the subject in the namespace table, and the Resource column is used to store subjects without prefixes; The predicate table includes a primary key ID, a foreign key NS_ID, a Property, a PTs and a PTe column. The predicate table is associated with the declaration table through the primary key ID, wherein the NS_ID column is used as a foreign key to reference the ID corresponding to the prefix of the predicate in the namespace table, the Property column stores the predicate without the prefix, and when the object is a resource, the PTs and PTe columns store the start and end time of the temporal information respectively, and when the object is a literal, the PTs and PTe columns are allowed to be empty; The object table includes a primary key ID, a foreign key NS_ID, an Object, an OTs and an OTe column. The object table is associated with the declaration table through the primary key ID, wherein the NS_ID column is used as a foreign key to implement a reference to the ID of the object prefix in the namespace table, and when the object is a literal, the NS_ID column corresponds to the ID representing an empty prefix in the namespace table, the Object column is used to store objects without prefixes, when the object is a resource, the OTs and OTe columns are allowed to be empty, and when the object is a literal, the OTs and OTe columns represent the start and end time of the temporal information; The declaration table includes primary key ID, foreign key Sid, foreign key Pid and foreign key Oid columns, and the declaration table uses foreign keys Sid, Pid and Oid to reference the IDs corresponding to the subject, predicate and object in the subject table, predicate table and object table; In step S4, the prefix, the subject without the prefix, the predicate without the prefix, the object without the prefix, and the time information are inserted into the database temporal table constructed in step S2 based on a storage mapping method, and the storage mapping method specifically includes: Step S401: insert the prefix into the Prefix column of the namespace table, wherein when the object is a literal, the Prefix column is allowed to be empty; Step S402: insert the prefix ID and the corresponding subject ES in the namespace table obtained in step S401 into the NS_ID and Resource columns of the subject table respectively, wherein the ID corresponding to each record is referenced by the declaration table as the primary key; Step S403, insert the prefix ID and the corresponding predicate EP in the namespace table obtained in step S401 into the NS_ID and Property columns of the predicate table respectively, wherein when the object is a resource, the time information Ts and Te are inserted into the PTs and PTe columns of the predicate table, and the ID corresponding to each record is referenced by the declaration table as the primary key; Step S404: insert the prefix ID and the corresponding object EO in the namespace table obtained in step S401 into the NS_ID and Object columns of the object table respectively, wherein when the object is a literal, insert the time information Ts and Te into the OTs and OTe columns of the object table, and the ID corresponding to each record is referenced by the declaration table as the primary key; Step S405: insert the corresponding IDs of the subject, predicate and object of each temporal RDF triple obtained in steps S402, S403 and S404 into the Sid, Pid and Oid columns of the declaration table.

2. A temporal RDF storage and query method based on relational database PostgreSQL according to claim 1, characterized in that: In the step S1, the timestamp is designed based on the closed-open cycle model proposed in SQL:2011, and its format is [Ts,Te) (Ts≤Te), wherein Ts and Te represent the start time and the end time respectively.

3. A temporal RDF storage and query method based on relational database PostgreSQL according to claim 2, characterized in that: The step S2 specifically includes: Step S201: for temporal RDF data, obtain the subject, predicate and object in its temporal RDF triples; Step S202, converting the subject, predicate and object into character string formats respectively; Step S203, according to the type of the object, respectively separate the tense information Ts and Te from the predicate and the object, which specifically includes: When the object is a resource, obtain the predicate after stripping the tense information, then obtain the time interval, and then extract the start time Ts and end time Te of the time interval; When the object is a literal quantity, obtain the object after stripping the tense information, then obtain the time interval, and then extract the start time Ts and end time Te of the time interval; Step S204: After the tense information is segmented, the prefixes of the subject, predicate and object are segmented to obtain the subject ES, predicate EP and object EO without the prefix, and the corresponding prefixes.

Citation Information

Patent Citations

  • Method and device for generation of Chinese general knowledge atlas with timestamps

    CN107391673A

  • Tense expanding and query optimizing method for non-tense JSON data model

    CN108897813A

  • In-memory approach to extend semantic event processing with domain insights

    US20160139969A1