Ontology persistence based on relational database

Source: Internet
Author: User
Tags one table postgresql

Relational database technology is mature, widely used, support tools rich and powerful, data storage, query efficiency, so when the semantic data storage is not mature, no effective tools appear, it is widely used in ontology data storage. Because of the difference between ontology model and relational model, ontology storage based on relational database has many modes (Li Man, 2005):

(1) Horizontal mode
This mode uses only one table in the database to represent the ontology, and the table lists the attributes of the ontology, and one record in the table corresponds to each instance in the ontology. As the ontology is updated and evolved, the number and name of the ontology attributes can change, and not all instances have the same attributes. Therefore, this pattern data table column needs to change frequently, and there are a large number of null values, only applicable to small-scale static ontology.
(2) Vertical mode
This model only contains a ternary table, each record in the table corresponding to a ternary group, the form of ternary groups to describe the entire information. The structure of this mode is stable, but the readability is poor, it is difficult to construct SQL to query, which is disadvantageous to ontology application.

(3) Decomposition mode
The basic idea is to decompose the database into patterns. In the existing decomposition mode method, the first is based on the decomposition mode of the class, that is, the class name is the table name, the Class property is the table column, for each class in the ontology to create a separate table, and the other is a property-based decomposition mode, that is, the property name is the table name, the table contains two columns, respectively, and object to create a separate table for each attribute in the ontology. This mode needs to be updated with the ontology, modified constantly new, delete data tables, inefficient, expensive, also not conducive to the application of the ontology.

(4) Other modes
This includes blending patterns for mixing the above patterns and mapping owl descriptors to data tables to store the ontology resources that exist in this relationship, and to improve query efficiency patterns.

Semantic Web Development Framework Jena SQL Database engine SDB uses a hybrid model that stores ontology content in 4 interconnected data tables: node table nodes, prefix table prefixes, four-tuple table quads, and ternary table triples. SDB treats the ontology as a collection of graphs, subject, predicate, and object in RDF are nodes in the graph, and a dataset can have multiple graphs. Therefore, as the name implies, nodes stores the node in the ontology, its columns record the node data type, language and other basic properties; prefiexes stores the prefix defined in the ontology, quads stores the named graph (Named graph) and the corresponding RDF records; Triples stores RDF Triples, Its value is the primary key value in the nodes table, and the instance properties and relationships are all expressed in s-p-o (subject, predicate, and object). The structure of SDB mode table is stable, and it is an excellent storage mode of ontology relational database to change the efficiency of data adding and deleting at a certain storage space cost.

There are two main table patterns of "Layout2/hash" and "Layout2/index" in SDB, the difference being that the nodes table in "Layout2/index" mode is listed as the primary key with "id" and "hash" as the index; "layout2/ Hash "No" id "column," hash "listed as the primary key. The SDB database connection information, layout mode, and so on can be specified in the SDB configuration file (below).

# Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0# prefix definition @prefix SDB: 2007/sdb#>. @prefix rdfs: 2000/01/rdf-schema#>. @prefix RDF: 1999/02/22-rdf-syntax-ns#>. @prefix ja: 2005/11/assembler#> .< #store > Rdf:type sdb:store;Sdb:layout "Layout2";# "Layout2", "Layout2/hash" or "Layout2/index"Sdb:connection < #conn >;.< #conn > Rdf:type sdb:sdbconnection;Sdb:sdbtype "PostgreSQL";# "Oracle", "PostgreSQL", "MySQL "Sdb:sdbhost "localhost";# "localhost:1521"; # address, add Port:p ortSdb:sdbname "Sdb_test";Sdb:sdbuser "User";Sdb:sdbpassword "PW";Sdb:driver "Org.postgresql.Driver";# "Oracle.jdbc.driver.OracleDriver"; # database-driven

After setting up the database connection information with the configuration file, the following method is used to read the ontology file and store it in the database corresponding data table.

String file = "Src/main/resources/ccs.owl";//Ontology file Address//connecting to a database, using a configuration fileStore store = Sdbfactory.connectstore ("Src/main/resources/sdb-pgsql.ttl");//Create a database tableStore.gettableformatter (). Create (); Model Model=Sdbfactory.connectdefaultmodel (store);//read the owl file into modelTry{filemanager.get (). Readmodel (model, file,"OWL");}Catch(Exception e) {Throw NewIllegalArgumentException ("file does not exist!) ");}//System.out.println (Model.size ());//close connections and storage, freeing up resourcesstore.getconnection (). Close (); Store.close ();

The ternary table in SDB only records the hash or ID value of the node, and the readability is poor, so it is difficult to construct the SQL statement directly for querying. But in fact, the SDB design is not based on the traditional SQL statement ontology query, but as the Jena framework of the relational database engine, the realization of ontology persisted storage. The query of ontology data is realized by using the query component of Jena and the Ontology query Language SPARQL. The specific algorithm for implementing ontology queries using SPARQL statements in SDB is as follows:

 String queryString = "SELECT * {? s" P O} " = Sdbfactory.connectstore (TTL); //  Query query = queryfactory.create (queryString); //  Create query  DataSet DataSet = datasetstore.create (store); Queryexecution QE  = Queryexecutionfactory.create (query, DataSet); ResultSet ResultSet  = Qe.execselect (); Resultsetformatter.out (ResultSet);  //  console format output query result  qe.close (); //  close query  store.getconnection (). Close (); //  close connection  store.close (); 

--An excerpt from the time ontology of geo-data and its application in semantic retrieval--taking the geological period ontology as an example

Ontology persistence based on relational database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.