|
Semantics.Server Developer Guide
Semantics.Server 1.0 is a powerful new component included in RDF Gateway 3.0. Semantics.Server provides scalable RDF storage, query and inference capabilities to Microsoft SQL Server 2005® and Microsoft SQL Server 2008®. Semantics.Server is used by the RDF Gateway Server to handle all of the storage, query and inference requirements for RDF Gateway 3.0. However Semantics.Server can be used without RDF Gateway Server by accessing its capabilities directly through T-SQL. Semantics.Server is a set of assemblies developed in the .NET Framework that provide a suite of stored procedures, functions and data types for integrating semantics into applications based on Microsoft SQL Server®. This developer guide will focus on how to access and utilize these capabilities. InstallationSemantics.Server 1.0 requires that a database on SQL Server® has been properly initialized to contain the tables, stored procedures, functions and custom data type Semantics.Server requires for the storing, querying and inferencing on RDF data. The RDF Gateway Configuration Utility program will perform this action but requires a database connection with administrative privileges. Please refer to the RDF Gateway installation guide for more information on initializing a database for use with Semantics.Server. Executing CommandsSemantics.Server 1.0 runs within Microsoft SQL Server® therefore it's functionality can be accessed using any tool capable of issuing commands to SQL Server®. For the scope of this document it will be assumed that all commands are issued using Microsoft SQL Server Management Studio. Creating A Named Graph
A collection of RDF statements is refered to a graph. A graph that is referenced via a unique URI is known
as a "named graph". In Sematics.Server the stored procedure EXEC sw_CreateGraph 'http://www.intellidimension.com/resources/graph1'; Adding Statements To A Named Graph
Statements are added to a named graph by contructing a simple relational view onto the graph using
the stored procedure EXEC sw_CreateGraphView 'http://www.intellidimension.com/resources/graph1', 'graph1_statements';
In the example above a relational view
INSERT INTO graph1_statements VALUES
('<http://www.intellidimension.com/resources/semantics-server>',
'<http://www.w3.org/2000/01/rdf-schema#label>',
'"Semantics.Server"');
INSERT INTO graph1_statements VALUES
('<http://www.intellidimension.com/resources/semantics-server>',
'<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>',
'<http://www.intellidimension.com/resources/SoftwareProduct>');
INSERT INTO graph1_statements VALUES
('<http://www.intellidimension.com/resources/semantics-server>',
'<http://www.intellidimension.com/resources/SoftwareVersion>',
'"1.0"');
INSERT INTO graph1_statements VALUES
('<http://www.intellidimension.com/resources/semantics-server>',
'<http://www.intellidimension.com/resources/ReleaseDate>',
'"2008-06-15"^^<http://www.w3.org/2001/XMLSchema#date>');
RDF Values via User-Defined Type
Pay close attention to the use of the ntriples syntax within the SQL strings for specifying RDF URI and literal values.
Semantics.Server uses a user-defined type (
For more information about ADO.NET and using Querying A Graph Using SPARQL
SPARQL is the W3C standard for querying RDF data. Semantics.Server allows a SPARQL query to executed from within T-SQL.
This is accomplished through the use of the stored procedure The example below uses SPARQL to query for all the statements in the named graph and returns the values strings.
EXEC sw_Sparql 'SELECT * FROM <http://www.intellidimension.com/resources/graph1> WHERE {?s ?p ?o}', 1;
The results of the SPARQL query are shown below. Note that the string values are encoded using the ntriples syntax. s p o --------------------------------------------------------------- --------------------------------------------------------------- ---------------------------------------------------------------- <http://www.intellidimension.com/resources/semantics-server> <http://www.w3.org/2000/01/rdf-schema#label> "Semantics.Server" <http://www.intellidimension.com/resources/semantics-server> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.intellidimension.com/resources/SoftwareProduct> <http://www.intellidimension.com/resources/semantics-server> <http://www.intellidimension.com/resources/SoftwareVersion> "1.0" <http://www.intellidimension.com/resources/semantics-server> <http://www.intellidimension.com/resources/ReleaseDate> "2008-06-15"^^<http://www.w3.org/2001/XMLSchema#date> Removing Statements From A Named Graph
One method for removing statements from a graph is via a simple SQL DELETE FROM graph1_statements WHERE s = '<http://www.intellidimension.com/resources/semantics-server>' AND p = '<http://www.intellidimension.com/resources/ReleaseDate>'; Using SPARQL Extensions: INSERT And DELETE
Semantics.Server supports several extensions to the SPARQL specification such as the
EXEC sw_Sparql '
PREFIX itd: <http://www.intellidimension.com/resources/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
INSERT INTO <http://www.intellidimension.com/resources/graph1>
{itd:semantics-server rdfs:comment "Cool semantics for SQL"} WHERE {}';
EXEC sw_Sparql '
PREFIX itd: <http://www.intellidimension.com/resources/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
DELETE FROM <http://www.intellidimension.com/resources/graph1>
{itd:semantics-server rdfs:comment "Cool semantics for SQL"} WHERE {}';
Adding Inference Rules to a SPARQL query
Semantics.Server implements inference rules in SPARQL via an extension to the
EXEC sw_Sparql '
PREFIX itd: <http://www.intellidimension.com/resources/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
WITH (
CONSTRUCT {?s rdf:type itd:Product} WHERE {?s rdf:type itd:SoftwareProduct}
)
SELECT ?s FROM <http://www.intellidimension.com/resources/graph1>
WHERE {?s rdf:type itd:Product}', 1;
Incremental Inferencing Via A Derived Graph
Semantics.Server can create a derived graph that maintains a set of inferences over
a set of facts via a very efficient process called incremental inferencing.
Semantics.Server exposes this feature through a stored procedure
EXEC sw_CreateDerivedGraph
'http://www.intellidimension.com/resources/derived-graph1',
'
PREFIX itd: <http://www.intellidimension.com/resources/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
WITH (
CONSTRUCT {?s rdf:type itd:Product} WHERE {?s rdf:type itd:SoftwareProduct}
)
CONSTRUCT {?s ?p ?o} FROM <http://www.intellidimension.com/resources/graph1>
WHERE {?s ?p ?o}';
EXEC sw_Sparql '
PREFIX itd: <http://www.intellidimension.com/resources/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?s FROM <http://www.intellidimension.com/resources/derived-graph1>
WHERE {?s rdf:type itd:Product}', 1;
|

