Magic Sets and Custom Inference Rules in Virtuoso 8.x

Source: http://slideplayer.com/slide/8842504/

The ability to materialize relations (i.e., sets of entity relationships grouped by a predicate) on a deductive basis is a critical feature of the genre of RDBMS application known as Deductive Database Management Systems — i.e., RDBMS equipped with Reasoning & Inference functionality. In recent times, this entire DBMS genre and its functionality have been obscured by the fanfare associated with NoSQL and Graph Databases.

In SQL RDBMS applications, materialized relations take the form of VIEWs which are described by SQL Queries and/or (in modern variants) by SQL Stored Procedures (a/k/a Persistent Stored Modules).

In RDF data management, materialized relations take the form of Inference Rules that inform the process of producing dynamically-materialized relations, colloquially referred to as Magic Sets. Magic Sets are basically the same concept as SQL VIEWs, but significantly enhanced by the semantic fidelity of relations represented as RDF sentence/statement graphs.

What?

Virtuoso supports the use of custom (magic) predicates to produce these Magic Sets or VIEWs or dynamically-materialized relations.

In Virtuoso 7.x and previous releases, the base product included only a few built-in magic predicates such as bif:contains. In those older versions, extending the collection of magic predicates required dropping down to SQL Stored Procedures — unnatural territory for those used to working with data represented as RDF sentence/statement graphs — under the misconception that RDF and SQL representations of structured data are mutually exclusive. (That is, it was thought that some structured data could be represented only as RDF sentence/statement graphs and not as SQL tabular relations; and that other structured data could be represented only as SQL tabular relations and not as RDF sentence/statement graphs. This has now been proven false; any structured data representable as SQL tabular relations may also be represented as RDF sentence/statement graphs, and vice versa.)

Virtuoso 8.0 introduced a simpler approach — an extension of its SPARQL-BI query functionality, implemented via a Macro Library abstraction. A Macro Library comprises custom inference rules that describe how to construct new Magic Sets, subject to conditions defined in those rules. A pragma declaration may now be used in the preamble of a SPARQL query to identify the desired Macro Library.

How?

Commonly used rule definitions can be grouped into Macro Libraries which enable a System’s Administrator to —

  1. Load a macro library into system metadata using a SPARQL CREATE MACRO LIBRARY or SPARQL CREATE SPIN LIBRARY statement, for invocation in SPARQL queries through thedefine input:macro-lib <macro-lib-name> pragma.
  2. Attach a macro library to specific RDF storage using the SPARQL ALTER QUAD STORAGE <storage-name> { ATTACH MACRO LIBRARY <macro-lib-name> } statement, thereby making the custom reasoning and inference context provided by that macro library available to every query without explicit pragma declaration per query.

Given an RDF Named Graph (Document or RDF Statements Container) identified by the IRI urn:spin:rule:geometry:lib, comprising RDF statements that describe a Custom Inference Rule for calculating the area of a rectangle as outline below:

Here’s a one-liner (shown here on multiple lines, just for easier reading; each sequence of line feeds, spaces, tabs, and other whitespace may be collapsed to a single space character) for adding the rule described above to the Virtuoso Macro Library (where Inference Rules are stored):

Basically, the example above leverages a built-in Stored Procedure for reading Rule Definition from an RDF document loaded into a Virtuoso Named Graph identified by the IRI <urn:spin:rule:geometry:lib>, courtesy of the following SPARQL LOAD command.

To reveal the lower-level code generated by Virtuoso using the following SQL command:

That outputs the following lower level Rules Definition using Virtuoso’s Macro Library extension to SPARQL.

Note: the UNION STORAGE clause ensures fusion of calcuated and existing values when inferring objects of the <http://example.org/shapes#area> relation identified by the variable ?area. Thus, if excluded inferred objects of the <http://example.org/shapes#area> relation would only comprise calculated values.

Here are links to Virtuoso SQL scripts for each of the Custom Inference Rules presented below:

SPARQL Query to List Existing Rules across Macro Libraries

Query Results Page

Live Link

SPARQL Query to List Rules

Query Results Page

Live Link

British Royal Family Relationships Rule

Query Demonstrating Usage of British Royal Family Relationships Rule

Query Results Page

Live Link

Rule for Calculating Area of a Rectangle

Query Demonstrating Usage of Rule for Calculating Area of a Rectangle

Query Results Page

Live Link

Rule for Geospatial Data Cleansing

Query Demonstrating Usage of Rule for Geospatial Data Cleansing

Query Results Page

Live Link

Identity Reconciliation Rule

Query Demonstrating Usage of Identity Reconciliation Rule

Query Results Page

Live Link

Conclusion

As a multi-model RDBMS, Virtuoso offers the best of multiple worlds.

Effectively covered by the examples above, the familiar concept of a tabular SQL VIEW has been extended to exploit the fine-grained semantics offered by entity relationship types represented as RDF sentence/statement collections that coalesce around a specific magic-predicate.

Most importantly, Virtuoso delivers all of this functionality — without undue complexity or compromised performance — to any application that supports HTTP, ODBC, JDBC, ADO.NET, or OLE DB.

Related

OpenLink Virtuoso Weblog

News & Articles related to OpenLink Virtuoso & Related…

Kingsley Uyi Idehen

Written by

Founder & CEO, OpenLink Software — provider of Secure, High-Performance, and Cross-Platform Data Access, Integration, Virtualization, and Management Technology.

OpenLink Virtuoso Weblog

News & Articles related to OpenLink Virtuoso & Related Technologies

Kingsley Uyi Idehen

Written by

Founder & CEO, OpenLink Software — provider of Secure, High-Performance, and Cross-Platform Data Access, Integration, Virtualization, and Management Technology.

OpenLink Virtuoso Weblog

News & Articles related to OpenLink Virtuoso & Related Technologies

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store